1 #ifndef __CPPLUGINS__EXTENSIONS__IO__WAVEFRONTOBJREADER__HXX__
2 #define __CPPLUGINS__EXTENSIONS__IO__WAVEFRONTOBJREADER__HXX__
8 // -------------------------------------------------------------------------
10 cpPlugins::Extensions::IO::WaveFrontOBJReader< M >::
16 // -------------------------------------------------------------------------
17 template< typename M >
18 cpPlugins::Extensions::IO::WaveFrontOBJReader< M >::
19 ~WaveFrontOBJReader( )
23 // -------------------------------------------------------------------------
24 template< typename M >
25 void cpPlugins::Extensions::IO::WaveFrontOBJReader< M >::
28 typedef typename PointType::ValueType TScalar;
29 typename M::Pointer out = this->GetOutput( );
31 out->SetCellsAllocationMethod( M::CellsAllocatedDynamicallyCellByCell );
32 if( this->m_FileName == "" )
34 itkExceptionMacro( << "No input FileName" );
38 std::ifstream in( this->m_FileName.c_str( ) );
42 << "Unable to open file" << std::endl
43 << "\"" << m_FileName << "\""
48 in.imbue( std::locale::classic( ) );
53 std::getline( in, buffer, '\n' );
56 std::stringstream ss( buffer );
57 std::istream_iterator< std::string > it( ss );
58 std::istream_iterator< std::string > end;
59 std::vector< std::string > line( it, end );
60 if( line.size( ) == 0 )
63 // Now, we are talking...
64 if( line[ 0 ] == "v" || line[ 0 ] == "V" )
68 pnt.Fill( TScalar( 0 ) );
70 if( line.size( ) > 1 && M::PointDimension >= 1 )
71 pnt[ 0 ] = TScalar( std::atof( line[ 1 ].c_str( ) ) );
72 if( line.size( ) > 2 && M::PointDimension >= 2 )
73 pnt[ 1 ] = TScalar( std::atof( line[ 2 ].c_str( ) ) );
74 if( line.size( ) > 3 && M::PointDimension >= 3 )
75 pnt[ 2 ] = TScalar( std::atof( line[ 3 ].c_str( ) ) );
76 if( M::PointDimension >= 4 )
78 if( line.size( ) > 4 )
79 pnt[ 3 ] = TScalar( std::atof( line[ 4 ].c_str( ) ) );
81 pnt[ 4 ] = TScalar( 1 );
84 out->SetPoint( out->GetNumberOfPoints( ), pnt );
86 else if( line[ 0 ] == "f" || line[ 0 ] == "F" )
88 if( line.size( ) > 3 )
92 TPolygonCell* face = new TPolygonCell( );
94 for( unsigned int k = 1; k < line.size( ); ++k )
100 substr( 0, line[ k ].find_first_of( "/" ) ).c_str( )
104 // In OBJ files, vertices are numbered from 1
105 face->AddPointId( pId - 1 );
108 cell.TakeOwnership( face );
109 out->SetCell( out->GetNumberOfCells( ), cell );
121 #endif // __CPPLUGINS__EXTENSIONS__IO__WAVEFRONTOBJREADER__HXX__