#include #include #include #include #include #include // ------------------------------------------------------------------------- cpPluginsIO::MeshWriter:: MeshWriter( ) : Superclass( ) { this->_AddInput( "Input" ); this->m_Parameters.Clear( ); this->m_Parameters.ConfigureAsSaveFileName( "FileName" ); this->m_Parameters.SetAcceptedFileExtensions( "FileName", "Mesh files (*.stl *.vtk)" ); } // ------------------------------------------------------------------------- cpPluginsIO::MeshWriter:: ~MeshWriter( ) { } // ------------------------------------------------------------------------- void cpPluginsIO::MeshWriter:: _GenerateData( ) { auto mesh = this->GetInputData< vtkPolyData >( "Input" ); if( mesh == NULL ) this->_Error( "No suitable input." ); // Get file extension auto fname = this->m_Parameters.GetSaveFileName( "FileName" ); std::istringstream fname_str( fname ); std::string token, ext; while( std::getline( fname_str, token, '.' ) ) ext = token; std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower ); // Real read if( ext == "stl" ) { vtkSTLWriter* stlw = this->_CreateVTK< vtkSTLWriter >( ); stlw->SetInputData( mesh ); stlw->SetFileName( fname.c_str( ) ); stlw->Update( ); if( stlw->GetErrorCode( ) != 0 ) this->_Error( "Someting wrong happened." ); } else if( ext == "vtk" ) { vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( ); pdw->SetInputData( mesh ); pdw->SetFileName( fname.c_str( ) ); pdw->Update( ); if( pdw->GetErrorCode( ) != 0 ) this->_Error( "Someting wrong happened." ); } else this->_Error( "Input file format not recognized." ); } // eof - $RCSfile$