#include #include "vtkObjectFactory.h" #include #include #include #include #include #include #include #include // #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkMetaVolumeMesh ); vtkCxxRevisionMacro(vtkMetaVolumeMesh, "$Revision: 1.3 $"); //---------------------------------------------------------------------------- vtkMetaVolumeMesh::vtkMetaVolumeMesh() { this->Type = vtkMetaDataSet::VTK_META_VOLUME_MESH; } //---------------------------------------------------------------------------- vtkMetaVolumeMesh::~vtkMetaVolumeMesh() { } //---------------------------------------------------------------------------- void vtkMetaVolumeMesh::Initialize (void) { this->Superclass::Initialize(); if (!this->DataSet) return; vtkProperty* property = vtkProperty::SafeDownCast(this->GetProperty()); if (!property) { property = vtkProperty::New(); this->SetProperty (property); property->Delete(); } } //---------------------------------------------------------------------------- vtkUnstructuredGrid* vtkMetaVolumeMesh::GetUnstructuredGrid (void) const { if (!this->DataSet) return NULL; return vtkUnstructuredGrid::SafeDownCast (this->DataSet); } //---------------------------------------------------------------------------- void vtkMetaVolumeMesh::ReadVtkFile (const char* filename) { vtkUnstructuredGridReader* reader = vtkUnstructuredGridReader::New(); reader->SetFileName (filename); try { reader->Update(); this->SetDataSet (reader->GetOutput()); } catch (vtkErrorCode::ErrorIds error) { reader->Delete(); throw error; } reader->Delete(); } //---------------------------------------------------------------------------- void vtkMetaVolumeMesh::Read (const char* filename) { unsigned long format = vtkMetaVolumeMesh::CanReadFile (filename); try { std::cout << "Reading " << filename << "... "; switch (format) { case vtkMetaVolumeMesh::FILE_IS_VTK : this->ReadVtkFile (filename); break; default : vtkErrorMacro(<<"unknown dataset type : "<SetFilePath ((vtksys::SystemTools::GetFilenamePath (filename)).c_str()); } //---------------------------------------------------------------------------- void vtkMetaVolumeMesh::WriteVtkFile (const char* filename) { if (!this->DataSet) { vtkErrorMacro(<<"No DataSet to write"<DataSet); if (!c_mesh) { vtkErrorMacro(<<"DataSet is not a polydata object"<SetFileName (filename); try { writer->SetInput (c_mesh); writer->Write(); writer->Delete(); } catch (vtkErrorCode::ErrorIds error) { writer->Delete(); throw error; } this->SetFilePath ((vtksys::SystemTools::GetFilenamePath (filename)).c_str()); } //---------------------------------------------------------------------------- void vtkMetaVolumeMesh::Write (const char* filename) { try { std::cout << "writing " << filename << "... "; this->WriteVtkFile (filename); std::cout << "done." << std::endl; } catch (vtkErrorCode::ErrorIds error) { throw error; } } //---------------------------------------------------------------------------- bool vtkMetaVolumeMesh::IsVtkExtension (const char* ext) { if (strcmp (ext, ".vtk") == 0 || strcmp (ext, ".vtu") == 0) return true; return false; } // //---------------------------------------------------------------------------- // bool vtkMetaVolumeMesh::IsMeshExtension (const char* ext) // { // if (strcmp (ext, ".mesh") == 0) // return true; // return false; // } //---------------------------------------------------------------------------- unsigned int vtkMetaVolumeMesh::CanReadFile (const char* filename) { // if (vtkMetaVolumeMesh::IsMeshExtension(vtksys::SystemTools::GetFilenameLastExtension(filename).c_str())) // return vtkMetaVolumeMesh::FILE_IS_MESH; if (!vtkMetaVolumeMesh::IsVtkExtension(vtksys::SystemTools::GetFilenameLastExtension(filename).c_str())) return 0; // Here we can only read vtk unstructuredgrid files vtkUnstructuredGridReader* reader = vtkUnstructuredGridReader::New(); reader->SetFileName (filename); if (reader->IsFileUnstructuredGrid ()) { reader->Delete(); return vtkMetaVolumeMesh::FILE_IS_VTK; } reader->Delete(); return 0; }