The Parametric Pseudo-Manifold (PPS) Library 1.0
sampler.cpp File Reference

Samples a PPS built from a PN triangle surface. More...

#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include "surface.h"
#include "pps.h"
#include "ppssampler.h"
#include "ppsfrompnt.h"
#include "reader.h"
#include "writer.h"
#include "vertex_attribute.h"
#include "halfedge_attribute.h"
#include "face_attribute.h"
Include dependency graph for sampler.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Creates a PPS from a PN triangle. The underlying mesh of the PPS is given by an input OFF file, and a PL approximation to the PPS is written out to another OFF file.

Detailed Description

Samples a PPS built from a PN triangle surface.

Author:
Marcelo Ferreira Siqueira
Universidade Federal do Rio Grande do Norte,
Departamento de Informatica e Matematica Aplicada,
marcelo at dimap (dot) ufrn (dot) br
Version:
2.0
Date:
July 2009
Attention:
This program is distributed WITHOUT ANY WARRANTY, and it may be freely redistributed under the condition that the copyright notices are not removed, and no compensation is received. Private, research, and institutional use is free. Distribution of this code as part of a commercial system is permissible ONLY BY DIRECT ARRANGEMENT WITH THE AUTHOR.

Definition in file sampler.cpp.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Creates a PPS from a PN triangle. The underlying mesh of the PPS is given by an input OFF file, and a PL approximation to the PPS is written out to another OFF file.

Parameters:
argcThe number of command-line arguments.
argvThe command-line arguments.

The first command-line argument is the name of the file describing the underlying mesh of the PPS, while the second is the level of detail of the PL approximation to the PPS computed here.

Definition at line 53 of file sampler.cpp.

References pps::PPS< Mesh >::build(), offlib::Reader::read(), pps::PPSsampler< Mesh >::sample(), and offlib::Writer::write().

{
  using std::cout ;
  using std::endl ;

  using ppsfrompnt::VertexAttribute ;
  using ppsfrompnt::HalfedgeAttribute ;
  using ppsfrompnt::FaceAttribute ;

  //
  // typedef Surface
  //
  typedef dcel::Surface< VertexAttribute , FaceAttribute , int ,
      HalfedgeAttribute > Surface ;

  //
  // This program expects two command-line arguments.
  //
  if ( argc != 3 ) {
    cout << endl ;
    cout << "Usage: sampler-pnt <arg 1> <arg 2>" << endl ;
    cout << endl ;
    cout << "arg1: the filename of an OFF file without extension." << endl ;
    cout << "arg2: the level-of-detail of the output triangular mesh." << endl ;
    cout << endl ;
    cout << "For instance:" << endl ;
    cout << "sampler-pnt star 3" << endl ;
    cout << endl ;
    return 0 ;
  }

  std::string fn1( argv[ 1 ] ) ;
  unsigned lod = unsigned( atoi( argv[ 2 ] ) ) ;

  //
  // Read in the underlying mesh information.
  //

  cout << "Reading input file..." << endl ;

  unsigned nv, nf ;
  double* vset ;
  unsigned* fset ;

  offlib::Reader reader( fn1 ) ;

  reader.read( nv , vset , nf , fset ) ;

  //
  // Creates the underlyng mesh and stores it in a DCEL.
  //

  cout << "Creating surface..." << endl ;

  Surface* mesh = new Surface( nv , vset , nf , fset ) ;

  //
  // Release memory.
  //

  cout << "Releasing memory..." << endl ;

  if ( vset != 0 ) {
    delete[] vset ;
  }

  if ( fset != 0 ) {
    delete[] fset ;
  }

  //
  // Creates a PPS that approximates the PN triangle surface.
  //

  cout << "Creating the PPS..." << endl ;

  ppsfrompnt::PPSfromPNT* pps = new ppsfrompnt::PPSfromPNT( mesh ) ;

  pps->build() ;

  //
  // Sample the PN triangle surface and the PPS.
  //

  cout << "Sampling the PN triangle surface and the PPS ..." << endl ;

  pps::PPSsampler< Surface >* sampler = 
    new pps::PPSsampler< Surface >( pps ) ;

  double* lv1 ;
  double* lv2 ;

  unsigned* lf ;

  sampler->sample( lod , nv , lv1 , lv2 , nf , lf ) ;

  //
  // Writing out the output files.
  //

  cout << "Generating the output files..." << endl ;

  std::string fn2( fn1 + std::string( "-pnt-pps-" ) 
                   + std::string( argv[ 2 ] ) ) ;

  std::string fn3( fn1 + std::string( "-pnt-" ) 
                   + std::string( argv[ 2 ] ) ) ;

  nv /= 3 ;
  nf /= 3 ;

  offlib::Writer writer1( fn2 ) ;
  writer1.write( nv , &lv1[ 0 ] , nf , &lf[ 0 ] ) ;

  if ( lv1 != 0 ) delete lv1 ;

  offlib::Writer writer2( fn3 ) ;
  writer2.write( nv , &lv2[ 0 ] , nf , &lf[ 0 ] ) ;

  if ( lv2 != 0 ) delete lv2 ;

  if ( lf != 0 ) delete lf ;

  //
  // Release memory.
  //

  cout << "Releasing memory..." << endl ;

  if ( sampler != 0 ) {
    delete sampler ;
  }

  if ( pps != 0 ) {
    delete pps ;
  }

  if ( mesh != 0 ) {
    delete mesh ;
  }

  return 0 ;
}