The Parametric Pseudo-Manifold (PPS) Library 1.0
offlib::Writer Class Reference

This class represents a file writer for writing out a triangle surface mesh information to an OFF file. More...

#include <writer.h>

List of all members.

Public Member Functions

 Writer (const std::string &fn)
 Creates an instance of this class.
 Writer (const Writer &w)
 Creates an instance of this class from another instance.
 ~Writer ()
 Destroys an instance of this class.
void write (unsigned nv, double *vset, unsigned nf, unsigned *fset)
 Writes the vertex and face information of a surface mesh to an OFF file.

Private Member Functions

void write_header (unsigned nv, unsigned nf)
 Writes the file header information.
void write_vertices (unsigned nv, double *vset)
 Writes the file header information.
void write_faces (unsigned nf, unsigned *fset)
 Writes the mesh face information.

Private Attributes

std::string _fname
 The name of the output file.
std::fstream _fs
 The output file stream.

Detailed Description

This class represents a file writer for writing out a triangle surface mesh information to an OFF file.

Definition at line 54 of file writer.h.


Constructor & Destructor Documentation

offlib::Writer::Writer ( const std::string &  fn)

Creates an instance of this class.

Parameters:
fnThe name of an OFF input file.

Definition at line 56 of file writer.cpp.

References _fname.

  {
    assert( !fn.empty() ) ;
    
    _fname = fn + std::string( ".off" ) ;

    return ;
  }
offlib::Writer::Writer ( const Writer w)

Creates an instance of this class from another instance.

Parameters:
wAnother instance of this class.

Definition at line 73 of file writer.cpp.

                                  : _fname( w._fname )
  {}

Member Function Documentation

void offlib::Writer::write ( unsigned  nv,
double *  vset,
unsigned  nf,
unsigned *  fset 
)

Writes the vertex and face information of a surface mesh to an OFF file.

Parameters:
nvThe number of vertices of the mesh.
vsetThe Cartesian coordinates of the mesh vertices.
nfThe number of faces of the mesh.
fsetThe set of vertex identifiers of the mesh faces.

Definition at line 89 of file writer.cpp.

References _fname, _fs, write_faces(), write_header(), and write_vertices().

Referenced by main().

  {
    _fs.open( _fname.c_str() , std::ios::out | std::ios::binary ) ;

    assert( _fs != 0 ) ;

    write_header( nv , nf ) ;

    write_vertices( nv , vset ) ;

    write_faces( nf , fset ) ;

    _fs.close() ;

    return ;
  }
void offlib::Writer::write_faces ( unsigned  nf,
unsigned *  fset 
) [private]

Writes the mesh face information.

Parameters:
nfThe number of faces of the mesh.
fsetThe set of vertex identifiers of the mesh faces.

Definition at line 183 of file writer.cpp.

References _fs.

Referenced by write().

  {
    for ( unsigned i = 0 ; i < nf ; i++ ) {

      const unsigned j = 3 * i;

      _fs << "3 "
          << fset[ j ]
          << " "
          << fset[ j + 1 ]
          << " "
          << fset[ j + 2 ]
          << std::endl ;
    }

    return ;
  }
void offlib::Writer::write_header ( unsigned  nv,
unsigned  nf 
) [private]

Writes the file header information.

Parameters:
nvThe number of vertices of the mesh.
nfThe number of faces of the mesh.

Definition at line 121 of file writer.cpp.

References _fs.

Referenced by write().

  {
    //
    // Write first line
    //
    _fs << "OFF" << std::endl ;

    //
    // Write the number of vertices, faces, and edges
    //
    _fs << nv
        << " "
        << nf
        << " 0"
        << std::endl ;
  }
void offlib::Writer::write_vertices ( unsigned  nv,
double *  vset 
) [private]

Writes the file header information.

Writes the mesh vertex information.

Parameters:
nvThe number of vertices of the mesh.
vsetThe Cartesian coordinates of the mesh vertices.

Definition at line 151 of file writer.cpp.

References _fs.

Referenced by write().

  {
    _fs << std::fixed << std::setprecision( 18 ) ;

    for ( unsigned i = 0 ; i < nv ; i++ ) {

      const unsigned j = 3 * i ;

      _fs << vset[ j ]
           << " "
           << vset[ j + 1 ] 
           << " "
           << vset[ j + 2 ]
           << std::endl;
    }

    return ;
  }

The documentation for this class was generated from the following files: