]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/CutModule2/kernel/CutModel2SaveBinInfo.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule2 / kernel / CutModel2SaveBinInfo.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: CutModel2SaveBinInfo.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/11/19 15:24:57 $
7   Version:   $Revision: 1.1 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
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.
15
16 =========================================================================*/
17 #include "CutModel2SaveBinInfo.h"
18
19 /**
20 **      Start of the manager class
21 **/
22 CutModel2SaveBinInfo::CutModel2SaveBinInfo(int id, int currentaction, UNDOTYPE actiontype, std::string path){
23
24         _id = id;
25
26         char c[100];
27         sprintf(c,"/infounrd_%d_fig_%d.info",currentaction,id);
28
29         _stdFilename = path;    
30     _stdFilename+=c;
31         _stdFilename+=".poly";
32
33         _matrixFilename = path; 
34         _matrixFilename+=c;
35         _actiontype = actiontype;       
36
37         
38 }
39 CutModel2SaveBinInfo::~CutModel2SaveBinInfo(){
40         
41 }
42 void CutModel2SaveBinInfo::savePolyData(vtkPolyData* polydata){
43         vtkPolyDataWriter * writer = vtkPolyDataWriter ::New();
44         writer->SetFileName(_stdFilename.c_str());      
45         writer->SetInput(polydata);
46         writer->SetFileTypeToBinary();
47         writer->Write();
48         writer->Delete();
49 }
50
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();
56
57         vtkPolyDataMapper* mapper       = vtkPolyDataMapper::New();     
58         mapper->SetInput(poly);
59         vtkActor* actor = vtkActor::New();
60         actor->SetMapper(mapper);
61         vtkMatrix4x4* actmatrix = actor->GetMatrix();
62
63         std::cout<<"tkTransform* CutModel2SaveBinInfo::getPolyDataTransform() Actor "<<actor<<std::endl;
64         std::cout<<"tkTransform* CutModel2SaveBinInfo::getPolyDataTransform() Actor Matrix "<<actmatrix<<std::endl;
65
66         mapper->Update();
67
68         vtkTransform* transform = vtkTransform::New();
69
70         transform->Identity();
71
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));
84
85         actor->Delete();
86         mapper->Delete();
87         reader->Delete();
88         //poly->Delete();
89         
90
91         return transform;
92         
93 }
94
95
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));
99         binary_file.close();
100 }
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));
105         binary_file.close();
106
107         vtkTransform* transform = vtkTransform::New();
108         transform->SetMatrix(matrix);
109
110         return transform;
111 }
112