1 /*=========================================================================
4 Module: $RCSfile: CutModel2SaveBinInfo.cxx,v $
6 Date: $Date: 2009/11/19 15:24:57 $
7 Version: $Revision: 1.1 $
9 Copyright: (c) 2002, 2003
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notice for more information.
16 =========================================================================*/
17 #include "CutModel2SaveBinInfo.h"
20 ** Start of the manager class
22 CutModel2SaveBinInfo::CutModel2SaveBinInfo(int id, int currentaction, UNDOTYPE actiontype, std::string path){
27 sprintf(c,"/infounrd_%d_fig_%d.info",currentaction,id);
31 _stdFilename+=".poly";
33 _matrixFilename = path;
35 _actiontype = actiontype;
39 CutModel2SaveBinInfo::~CutModel2SaveBinInfo(){
42 void CutModel2SaveBinInfo::savePolyData(vtkPolyData* polydata){
43 vtkPolyDataWriter * writer = vtkPolyDataWriter ::New();
44 writer->SetFileName(_stdFilename.c_str());
45 writer->SetInput(polydata);
46 writer->SetFileTypeToBinary();
51 vtkTransform* CutModel2SaveBinInfo::getPolyDataTransform()throw( CutModel2Exception){
52 vtkPolyDataReader* reader = vtkPolyDataReader::New();
53 //std::cout<<"filename vtkTransform* CutModel2SaveBinInfo::getPolyDataTransform()"<<this->getSTDFileName()<<std::endl;
54 reader->SetFileName(this->getSTDFileName().c_str());
55 vtkPolyData* poly = reader->GetOutput();
57 vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
58 mapper->SetInput(poly);
59 vtkActor* actor = vtkActor::New();
60 actor->SetMapper(mapper);
61 vtkMatrix4x4* actmatrix = actor->GetMatrix();
63 std::cout<<"tkTransform* CutModel2SaveBinInfo::getPolyDataTransform() Actor "<<actor<<std::endl;
64 std::cout<<"tkTransform* CutModel2SaveBinInfo::getPolyDataTransform() Actor Matrix "<<actmatrix<<std::endl;
68 vtkTransform* transform = vtkTransform::New();
70 transform->Identity();
72 transform->GetMatrix()->SetElement(0,0,actmatrix->GetElement(0,0));
73 transform->GetMatrix()->SetElement(1,0,actmatrix->GetElement(1,0));
74 transform->GetMatrix()->SetElement(2,0,actmatrix->GetElement(2,0));
75 transform->GetMatrix()->SetElement(0,1,actmatrix->GetElement(0,1));
76 transform->GetMatrix()->SetElement(1,1,actmatrix->GetElement(1,1));
77 transform->GetMatrix()->SetElement(2,1,actmatrix->GetElement(2,1));
78 transform->GetMatrix()->SetElement(0,2,actmatrix->GetElement(0,2));
79 transform->GetMatrix()->SetElement(1,2,actmatrix->GetElement(1,2));
80 transform->GetMatrix()->SetElement(2,2,actmatrix->GetElement(2,2));
81 transform->GetMatrix()->SetElement(0,3,actmatrix->GetElement(0,3));
82 transform->GetMatrix()->SetElement(1,3,actmatrix->GetElement(1,3));
83 transform->GetMatrix()->SetElement(2,3,actmatrix->GetElement(2,3));
96 void CutModel2SaveBinInfo::saveMatrix4x4(vtkMatrix4x4* matrix){
97 fstream binary_file(_matrixFilename.c_str(),ios::out|ios::binary);
98 binary_file.write(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
101 vtkTransform* CutModel2SaveBinInfo::getTransformFromMatrixFile()throw( CutModel2Exception){
102 vtkMatrix4x4* matrix = vtkMatrix4x4::New();
103 fstream binary_file(_matrixFilename.c_str(),ios::binary|ios::in);
104 binary_file.read(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
107 vtkTransform* transform = vtkTransform::New();
108 transform->SetMatrix(matrix);