]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/CutModule/kernel/CutModelSaveBinInfo.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / kernel / CutModelSaveBinInfo.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: CutModelSaveBinInfo.cxx,v $
30   Language:  C++
31   Date:      $Date: 2012/11/15 14:15:48 $
32   Version:   $Revision: 1.3 $
33
34   Copyright: (c) 2002, 2003
35   License:
36
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42 #include "CutModelSaveBinInfo.h"
43
44 /**
45 **      Start of the manager class
46 **/
47 CutModelSaveBinInfo::CutModelSaveBinInfo(int id, int currentaction, UNDOTYPE actiontype, std::string path){
48
49         _id = id;
50
51         char c[100];
52         sprintf(c,"/infounrd_%d_fig_%d.info",currentaction,id);
53
54         _stdFilename = path;    
55     _stdFilename+=c;
56         _stdFilename+=".poly";
57
58         _matrixFilename = path; 
59         _matrixFilename+=c;
60         _actiontype = actiontype;       
61
62         
63 }
64 CutModelSaveBinInfo::~CutModelSaveBinInfo(){
65         
66 }
67 void CutModelSaveBinInfo::savePolyData(vtkPolyData* polydata){
68         vtkPolyDataWriter * writer = vtkPolyDataWriter ::New();
69         writer->SetFileName(_stdFilename.c_str());      
70
71 //EED 2017-01-01 Migration VTK7
72 #if VTK_MAJOR_VERSION <= 5
73         writer->SetInput(polydata);
74 #else
75         writer->SetInputData(polydata);
76 #endif
77
78         writer->SetFileTypeToBinary();
79         writer->Write();
80         writer->Delete();
81 }
82
83 vtkTransform* CutModelSaveBinInfo::getPolyDataTransform()throw( CutModelException){
84         vtkPolyDataReader* reader = vtkPolyDataReader::New();
85         //std::cout<<"filename vtkTransform* CutModelSaveBinInfo::getPolyDataTransform()"<<this->getSTDFileName()<<std::endl;
86         reader->SetFileName(this->getSTDFileName().c_str());
87         vtkPolyData* poly = reader->GetOutput();
88
89         vtkPolyDataMapper* mapper       = vtkPolyDataMapper::New();     
90 //EED 2017-01-01 Migration VTK7
91 #if VTK_MAJOR_VERSION <= 5
92         mapper->SetInput(poly);
93 #else
94         mapper->SetInputData(poly);
95 #endif
96         vtkActor* actor = vtkActor::New();
97         actor->SetMapper(mapper);
98         vtkMatrix4x4* actmatrix = actor->GetMatrix();
99
100         std::cout<<"tkTransform* CutModelSaveBinInfo::getPolyDataTransform() Actor "<<actor<<std::endl;
101         std::cout<<"tkTransform* CutModelSaveBinInfo::getPolyDataTransform() Actor Matrix "<<actmatrix<<std::endl;
102
103         mapper->Update();
104
105         vtkTransform* transform = vtkTransform::New();
106
107         transform->Identity();
108
109         transform->GetMatrix()->SetElement(0,0,actmatrix->GetElement(0,0));
110         transform->GetMatrix()->SetElement(1,0,actmatrix->GetElement(1,0));
111         transform->GetMatrix()->SetElement(2,0,actmatrix->GetElement(2,0));
112         transform->GetMatrix()->SetElement(0,1,actmatrix->GetElement(0,1));
113         transform->GetMatrix()->SetElement(1,1,actmatrix->GetElement(1,1));
114         transform->GetMatrix()->SetElement(2,1,actmatrix->GetElement(2,1));
115         transform->GetMatrix()->SetElement(0,2,actmatrix->GetElement(0,2));
116         transform->GetMatrix()->SetElement(1,2,actmatrix->GetElement(1,2));
117         transform->GetMatrix()->SetElement(2,2,actmatrix->GetElement(2,2));             
118         transform->GetMatrix()->SetElement(0,3,actmatrix->GetElement(0,3));
119         transform->GetMatrix()->SetElement(1,3,actmatrix->GetElement(1,3));
120         transform->GetMatrix()->SetElement(2,3,actmatrix->GetElement(2,3));
121
122         actor->Delete();
123         mapper->Delete();
124         reader->Delete();
125         //poly->Delete();
126         
127
128         return transform;
129         
130 }
131
132
133 void CutModelSaveBinInfo::saveMatrix4x4(vtkMatrix4x4* matrix){
134         fstream binary_file(_matrixFilename.c_str(),ios::out|ios::binary);
135         binary_file.write(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
136         binary_file.close();
137 }
138 vtkTransform* CutModelSaveBinInfo::getTransformFromMatrixFile()throw( CutModelException){
139         vtkMatrix4x4* matrix = vtkMatrix4x4::New();
140         fstream binary_file(_matrixFilename.c_str(),ios::binary|ios::in);
141         binary_file.read(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
142         binary_file.close();
143
144         vtkTransform* transform = vtkTransform::New();
145         transform->SetMatrix(matrix);
146
147         return transform;
148 }
149