/*========================================================================= Program: wxMaracas Module: $RCSfile: CutModel2SaveBinInfo.cxx,v $ Language: C++ Date: $Date: 2009/11/19 15:24:57 $ Version: $Revision: 1.1 $ Copyright: (c) 2002, 2003 License: This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "CutModel2SaveBinInfo.h" /** ** Start of the manager class **/ CutModel2SaveBinInfo::CutModel2SaveBinInfo(int id, int currentaction, UNDOTYPE actiontype, std::string path){ _id = id; char c[100]; sprintf(c,"/infounrd_%d_fig_%d.info",currentaction,id); _stdFilename = path; _stdFilename+=c; _stdFilename+=".poly"; _matrixFilename = path; _matrixFilename+=c; _actiontype = actiontype; } CutModel2SaveBinInfo::~CutModel2SaveBinInfo(){ } void CutModel2SaveBinInfo::savePolyData(vtkPolyData* polydata){ vtkPolyDataWriter * writer = vtkPolyDataWriter ::New(); writer->SetFileName(_stdFilename.c_str()); writer->SetInput(polydata); writer->SetFileTypeToBinary(); writer->Write(); writer->Delete(); } vtkTransform* CutModel2SaveBinInfo::getPolyDataTransform()throw( CutModel2Exception){ vtkPolyDataReader* reader = vtkPolyDataReader::New(); //std::cout<<"filename vtkTransform* CutModel2SaveBinInfo::getPolyDataTransform()"<getSTDFileName()<SetFileName(this->getSTDFileName().c_str()); vtkPolyData* poly = reader->GetOutput(); vtkPolyDataMapper* mapper = vtkPolyDataMapper::New(); mapper->SetInput(poly); vtkActor* actor = vtkActor::New(); actor->SetMapper(mapper); vtkMatrix4x4* actmatrix = actor->GetMatrix(); std::cout<<"tkTransform* CutModel2SaveBinInfo::getPolyDataTransform() Actor "<Update(); vtkTransform* transform = vtkTransform::New(); transform->Identity(); transform->GetMatrix()->SetElement(0,0,actmatrix->GetElement(0,0)); transform->GetMatrix()->SetElement(1,0,actmatrix->GetElement(1,0)); transform->GetMatrix()->SetElement(2,0,actmatrix->GetElement(2,0)); transform->GetMatrix()->SetElement(0,1,actmatrix->GetElement(0,1)); transform->GetMatrix()->SetElement(1,1,actmatrix->GetElement(1,1)); transform->GetMatrix()->SetElement(2,1,actmatrix->GetElement(2,1)); transform->GetMatrix()->SetElement(0,2,actmatrix->GetElement(0,2)); transform->GetMatrix()->SetElement(1,2,actmatrix->GetElement(1,2)); transform->GetMatrix()->SetElement(2,2,actmatrix->GetElement(2,2)); transform->GetMatrix()->SetElement(0,3,actmatrix->GetElement(0,3)); transform->GetMatrix()->SetElement(1,3,actmatrix->GetElement(1,3)); transform->GetMatrix()->SetElement(2,3,actmatrix->GetElement(2,3)); actor->Delete(); mapper->Delete(); reader->Delete(); //poly->Delete(); return transform; } void CutModel2SaveBinInfo::saveMatrix4x4(vtkMatrix4x4* matrix){ fstream binary_file(_matrixFilename.c_str(),ios::out|ios::binary); binary_file.write(reinterpret_cast(matrix),sizeof(vtkMatrix4x4)); binary_file.close(); } vtkTransform* CutModel2SaveBinInfo::getTransformFromMatrixFile()throw( CutModel2Exception){ vtkMatrix4x4* matrix = vtkMatrix4x4::New(); fstream binary_file(_matrixFilename.c_str(),ios::binary|ios::in); binary_file.read(reinterpret_cast(matrix),sizeof(vtkMatrix4x4)); binary_file.close(); vtkTransform* transform = vtkTransform::New(); transform->SetMatrix(matrix); return transform; }