+++ /dev/null
-#ifndef __CPM__IO__WAVEFRONTOBJREADER__HXX__
-#define __CPM__IO__WAVEFRONTOBJREADER__HXX__
-
-#include <cstdlib>
-#include <fstream>
-#include <sstream>
-
-// -------------------------------------------------------------------------
-template< typename M >
-cpm::IO::WaveFrontOBJReader< M >::
-WaveFrontOBJReader( )
- : Superclass( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< typename M >
-cpm::IO::WaveFrontOBJReader< M >::
-~WaveFrontOBJReader( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< typename M >
-void cpm::IO::WaveFrontOBJReader< M >::
-GenerateData( )
-{
- typedef typename PointType::ValueType TScalar;
- typename M::Pointer out = this->GetOutput( );
-
- out->SetCellsAllocationMethod( M::CellsAllocatedDynamicallyCellByCell );
- if( this->m_FileName == "" )
- {
- itkExceptionMacro( << "No input FileName" );
-
- } // fi
-
- std::ifstream in( this->m_FileName.c_str( ) );
- if( !in.is_open( ) )
- {
- itkExceptionMacro(
- << "Unable to open file" << std::endl
- << "\"" << m_FileName << "\""
- );
-
- } // fi
-
- in.imbue( std::locale::classic( ) );
- std::string buffer;
-
- while( !in.eof( ) )
- {
- std::getline( in, buffer, '\n' );
-
- // Tokenize
- std::stringstream ss( buffer );
- std::istream_iterator< std::string > it( ss );
- std::istream_iterator< std::string > end;
- std::vector< std::string > line( it, end );
- if( line.size( ) == 0 )
- continue;
-
- // Now, we are talking...
- if( line[ 0 ] == "v" || line[ 0 ] == "V" )
- {
- // Add points
- PointType pnt;
- pnt.Fill( TScalar( 0 ) );
-
- if( line.size( ) > 1 && M::PointDimension >= 1 )
- pnt[ 0 ] = TScalar( std::atof( line[ 1 ].c_str( ) ) );
- if( line.size( ) > 2 && M::PointDimension >= 2 )
- pnt[ 1 ] = TScalar( std::atof( line[ 2 ].c_str( ) ) );
- if( line.size( ) > 3 && M::PointDimension >= 3 )
- pnt[ 2 ] = TScalar( std::atof( line[ 3 ].c_str( ) ) );
- if( M::PointDimension >= 4 )
- {
- if( line.size( ) > 4 )
- pnt[ 3 ] = TScalar( std::atof( line[ 4 ].c_str( ) ) );
- else
- pnt[ 4 ] = TScalar( 1 );
-
- } // fi
- out->SetPoint( out->GetNumberOfPoints( ), pnt );
- }
- else if( line[ 0 ] == "f" || line[ 0 ] == "F" )
- {
- if( line.size( ) > 3 )
- {
- // Add a face
- CellAutoPointer cell;
- TPolygonCell* face = new TPolygonCell( );
-
- for( unsigned int k = 1; k < line.size( ); ++k )
- {
- PointIdentifier pId =
- PointIdentifier(
- std::atoi(
- line[ k ].
- substr( 0, line[ k ].find_first_of( "/" ) ).c_str( )
- )
- );
-
- // In OBJ files, vertices are numbered from 1
- face->AddPointId( pId - 1 );
-
- } // rof
- cell.TakeOwnership( face );
- out->SetCell( out->GetNumberOfCells( ), cell );
-
- } // fi
-
- } // fi
-
- } // elihw
-
- // Finish the job
- in.close( );
-}
-
-#endif // __CPM__IO__WAVEFRONTOBJREADER__HXX__
-
-// eof - $RCSfile$