]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkVecIsoSurfaceExtractor.cxx
Clean code
[bbtk.git] / packages / vtk / src / bbvtkVecIsoSurfaceExtractor.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 #include "bbvtkVecIsoSurfaceExtractor.h"
29 #include "bbvtkPackage.h"
30
31 #include "vtkProperty.h"
32 #include "vtkLinearTransform.h"
33
34 namespace bbvtk
35 {
36
37 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,VecIsoSurfaceExtractor)
38 BBTK_BLACK_BOX_IMPLEMENTATION(VecIsoSurfaceExtractor,bbtk::AtomicBlackBox);
39         
40         //-----------------------------------------------------------   
41         void VecIsoSurfaceExtractor::bbUserSetDefaultValues()
42         {
43 //EED std::cout << "================================VecIsoSurfaceExtractor::bbUserSetDefaultValues()" << std::endl;
44                 std::vector<double> colour;
45                 // 1- red
46                 colour.push_back(1.0);
47                 colour.push_back(0.0);
48                 colour.push_back(0.0);
49                 // 2- blue
50                 colour.push_back(0.0);
51                 colour.push_back(0.0);
52                 colour.push_back(1.0);
53                 // 3- yellow
54                 colour.push_back(1.0);
55                 colour.push_back(1.0);
56                 colour.push_back(0.0);
57                 // 4- green
58                 colour.push_back(0.0);
59                 colour.push_back(1.0);
60                 colour.push_back(0.0);
61                 // 5- 
62                 colour.push_back(0.0);
63                 colour.push_back(1.0);
64                 colour.push_back(1.0);
65                 
66                 // 6- 
67                 colour.push_back(0.5);
68                 colour.push_back(0.5);
69                 colour.push_back(0.5);
70                 
71                 bbSetInputColour(colour);
72                 bbSetInputTransform(NULL);
73                 bbSetInputOpacity(1);
74                 
75                 bbSetInputRenderer(NULL);
76                 bbSetInputIsovalue(128);
77                 bbSetInputOpacity(1);
78         }
79         
80         //-----------------------------------------------------------   
81         void VecIsoSurfaceExtractor::bbUserInitializeProcessing() 
82         
83         { 
84                 //    bbSetInputIn(NULL);
85                 //    bbSetInputInVtkObject(NULL);
86 //EED std::cout << "================================VecIsoSurfaceExtractor::bbUserInitializeProcessing()" << std::endl; 
87         }
88         
89         //-----------------------------------------------------------   
90         void VecIsoSurfaceExtractor::bbUserFinalizeProcessing()
91         {
92 //EED std::cout << "================================VecIsoSurfaceExtractor::bbUserFinalizeProcessing()" << std::endl;
93                 int i,size = VecMarchingcubes.size();
94                 for (i=0;i<size;i++)
95                 {
96                         VecMarchingcubes[i]->Delete();
97                         VecPolydatamapper[i]->Delete();
98                         VecVtkactor[i]->Delete();
99                 }
100                 VecMarchingcubes.clear();
101                 VecPolydatamapper.clear();
102                 VecVtkactor.clear();
103         }
104         
105         //-----------------------------------------------------------   
106         void VecIsoSurfaceExtractor::Process()
107         {
108 //EED std::cout <<"================================VecIsoSurfaceExtractor::Process()" << std::endl;
109                 double r,g,b;
110                 vtkMarchingCubes  *marchingcubes;
111                 vtkPolyDataMapper *polydatamapper;
112                 vtkActor          *vtkactor;
113
114                  int i,size;
115
116                 size = VecVtkactor.size();
117                 for( i=0 ; i<size ; i++)
118                 {
119                         if (bbGetInputRenderer()!=NULL )
120                         {
121                                 bbGetInputRenderer()->RemoveActor( VecVtkactor[i] );
122                                 VecMarchingcubes[i]->Delete();
123                                 VecPolydatamapper[i]->Delete();
124                                 VecVtkactor[i]->Delete();
125                         }
126                 }
127                 VecMarchingcubes.clear();
128                 VecPolydatamapper.clear();
129                 VecVtkactor.clear();
130
131                 size = bbGetInputIn().size();
132                 for( i=0 ; i<size ; i++){
133                         marchingcubes  = vtkMarchingCubes::New();
134                         polydatamapper = vtkPolyDataMapper::New();
135                         vtkactor       = vtkActor::New();
136
137 //EED 2017-01-01 Migration VTK7
138 #if VTK_MAJOR_VERSION <= 5
139                         polydatamapper->SetInput(marchingcubes->GetOutput());
140 #else
141                         polydatamapper->SetInputData(marchingcubes->GetOutput());
142 #endif
143
144                         vtkactor->SetMapper(polydatamapper);
145
146                         polydatamapper->ScalarVisibilityOff();
147 //EED 2020-04-21 vtk8 deprecated
148 //                      polydatamapper->ImmediateModeRenderingOn();
149
150                         VecMarchingcubes.push_back(marchingcubes);
151                         VecPolydatamapper.push_back(polydatamapper);
152                         VecVtkactor.push_back(vtkactor);
153                 } // for i
154
155                 for( i=0 ; i<size ; i++){
156                         // Visualisation - result volume
157                         marchingcubes=VecMarchingcubes[i];
158                         vtkactor=(vtkActor*)VecVtkactor[i];
159
160 //EED 2017-01-01 Migration VTK7
161 #if VTK_MAJOR_VERSION <= 5
162                         marchingcubes->SetInput( bbGetInputIn()[i] );
163 #else
164                         marchingcubes->SetInputData( bbGetInputIn()[i] );
165 #endif
166
167                         marchingcubes->SetValue(0, bbGetInputIsovalue() );
168                         marchingcubes->Update();
169                          
170                         if ( (i*3+1)<(int)(bbGetInputColour().size()) ){
171                                 r = bbGetInputColour()[0+i*3];
172                                 g = bbGetInputColour()[1+i*3]; 
173                                 b = bbGetInputColour()[2+i*3];
174                         } else {
175                                 r = bbGetInputColour()[0];
176                                 g = bbGetInputColour()[1]; 
177                                 b = bbGetInputColour()[2];
178                         }
179                         vtkactor->GetProperty()->SetColor( r,g,b );
180  
181                         vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
182                         
183                         if ( bbGetInputTransform()!=NULL )
184                         {
185                                 vtkactor->SetUserTransform( bbGetInputTransform() );
186                         }
187
188                         // Interface Update
189                         if (bbGetInputRenderer()!=NULL )
190                         {
191                                 bbGetInputRenderer()->AddActor( vtkactor );
192                         }
193                 } // for i
194
195                  bbSetOutputOut( VecVtkactor );
196         }
197 }
198 // EO namespace bbvtk