]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkVecIsoSurfaceExtractor.cxx
Feature #1774
[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                         polydatamapper->SetInput(marchingcubes->GetOutput());
138                         vtkactor->SetMapper(polydatamapper);
139
140                         polydatamapper->ScalarVisibilityOff();
141                         polydatamapper->ImmediateModeRenderingOn();
142
143                         VecMarchingcubes.push_back(marchingcubes);
144                         VecPolydatamapper.push_back(polydatamapper);
145                         VecVtkactor.push_back(vtkactor);
146                 } // for i
147
148                 for( i=0 ; i<size ; i++){
149                         // Visualisation - result volume
150                         marchingcubes=VecMarchingcubes[i];
151                         vtkactor=(vtkActor*)VecVtkactor[i];
152
153                         marchingcubes->SetInput( bbGetInputIn()[i] );
154                         marchingcubes->SetValue(0, bbGetInputIsovalue() );
155                         marchingcubes->Update();
156                          
157                         if ( (i*3+1)<(int)(bbGetInputColour().size()) ){
158                                 r = bbGetInputColour()[0+i*3];
159                                 g = bbGetInputColour()[1+i*3]; 
160                                 b = bbGetInputColour()[2+i*3];
161                         } else {
162                                 r = bbGetInputColour()[0];
163                                 g = bbGetInputColour()[1]; 
164                                 b = bbGetInputColour()[2];
165                         }
166                         vtkactor->GetProperty()->SetColor( r,g,b );
167  
168                         vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
169                         
170                         if ( bbGetInputTransform()!=NULL )
171                         {
172                                 vtkactor->SetUserTransform( bbGetInputTransform() );
173                         }
174
175                         // Interface Update
176                         if (bbGetInputRenderer()!=NULL )
177                         {
178                                 bbGetInputRenderer()->AddActor( vtkactor );
179                         }
180                 } // for i
181
182                  bbSetOutputOut( VecVtkactor );
183         }
184 }
185 // EO namespace bbvtk