]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataToActor.cxx
fefe8eb5887febd3cfed5989061091eaf8c4a70e
[bbtk.git] / packages / vtk / src / bbvtkPolyDataToActor.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 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbvtkPolyDataToActor.cxx,v $
31   Language:  C++
32   Date:      $Date: 2009/05/28 08:55:44 $
33   Version:   $Revision: 1.15 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41
42 #ifdef _USE_VTK_
43
44 #include "vtkProperty.h"
45 #include "vtkLinearTransform.h"
46 #include "vtkCleanPolyData.h"
47 #include "vtkFieldData.h"
48
49 //--
50 #include <vtkGlyph3D.h>
51 #include <vtkArrowSource.h>
52 #include <vtkPolyDataNormals.h>
53 //--
54
55 #include "bbvtkPolyDataToActor.h"
56 #include "bbvtkPackage.h"
57
58 #include "vtkRenderWindow.h"
59
60 namespace bbvtk
61 {
62    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataToActor)
63    BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataToActor,bbtk::AtomicBlackBox);
64
65    void PolyDataToActor::bbUserSetDefaultValues() 
66    { 
67            actorAdded=false;
68            std::vector<double> colour;
69            colour.push_back(1.0);
70            colour.push_back(1.0);
71            colour.push_back(0.5);
72            bbSetInputColour(colour);
73            bbSetInputActive(true);
74            bbSetInputIn(NULL);
75            bbSetInputRenderer(NULL);
76            bbSetInputTransform(NULL);
77            bbSetInputOpacity(1);
78            bbSetInputRepresentation(2);
79            bbSetInputLineWidth(1);
80            bbSetInputScalarVisibility(false);
81            polydatamapper = NULL;
82            vtkactor       = NULL;
83            
84            bbSetInputScalarVisibilityOn_LookupTable(NULL);
85            bbSetInputScalarVisibilityOn_NameColorArray("");
86        bbSetInputIn(NULL);
87    }
88
89
90         //---------------------------------------------------------------------
91    void PolyDataToActor::bbUserInitializeProcessing() 
92    {     
93      polydatamapper = vtkPolyDataMapper::New();
94      vtkactor       = vtkActor::New();
95 //     polydatamapper->SetInput(marchingcubes->GetOutput());
96      vtkactor->SetMapper(polydatamapper);
97
98 //EED 2020-04-21 vtk8 deprecated
99 //     polydatamapper->ImmediateModeRenderingOn();
100    }
101
102         //---------------------------------------------------------------------
103         void PolyDataToActor::bbUserFinalizeProcessing() 
104         { 
105                 if (polydatamapper!=NULL)
106                 {
107                         polydatamapper->Delete();
108                         polydatamapper=NULL;
109                 }
110                 if (vtkactor!=NULL)
111                 {
112                         vtkactor->Delete();
113                         vtkactor=NULL;
114                 }               
115         }
116         
117         
118         
119         
120 /*
121
122 -----------------------------------------------
123
124 https://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ScalarBarActor
125 https://vtk.org/Wiki/VTK/Examples/Cxx/VisualizationAlgorithms/TubesFromSplines
126 https://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ElevationBandsWithGlyphs
127
128 vtkSmartPointer<vtkFloatArray> scalars = vtkSmartPointer<vtkFloatArray>::New();
129   scalars  set value ....
130 poly->GetPointData()->SetScalars(scalars);  or   poly->GetPointData()->SetActiveScalars("<NameArray>");
131
132 vtkSmartPointer<vtkLookupTable> hueLut =    vtkSmartPoint      |                                                 ^~
133 er<vtkLookupTable>::New();  
134   hueLut Build ....
135  
136   mapper->SetInputData(poly);
137   mapper->ScalarVisibilityOn();
138         mapper->SetScalarModeToUsePointData();   Point of Cell ...
139           
140     default: mapper->SetColorModeToDirectScalars() Busca scalars  3 componentes [R,G,B]  float  0..1  or  integer 0..255
141     else:
142       mapper->SetColorModeToMapScalars()  El vector scalar solo tiene un componente
143       mapper->SetLookupTable( hueLut );  
144           
145                 To change Array
146                 mapper->SelectColorArray("<NameVector>");   
147    
148         mapper->SetUseLookupTableScalarRange( true/false )    true:Para compartir lookuptable con otros mappers 
149                 si false then
150                 mapper->SetScalarRange( min, max);    Range especifico este mapper
151             mapper->SetScalarRange( tubePolyData->GetScalarRange() );
152
153 ------------------------------------------
154    
155      mapper->ScalarVisibilityOff();      ->  SetScalarModeToDefault()
156         Utiliza el color del actor
157   
158 ----------------------------------------
159
160 */      
161         
162         
163 //---------------------------------------------------------------------
164
165 void PolyDataToActor::DoProcess()
166 {
167     bool ok_removeActor=false;
168     if (bbGetInputRenderer()==NULL)
169     {
170         printf("EED Warnning! PolyDataToActor::DoProcess  missing Renderer.\n");
171     }
172     if (bbGetInputActive()==true)
173     {
174         if (bbGetInputIn()!=NULL)
175         {
176 //EED 2017-01-01 Migration VTK7
177 #if VTK_MAJOR_VERSION <= 5
178              polydatamapper->SetInput( bbGetInputIn() );
179 #else
180              polydatamapper->SetInputData( bbGetInputIn() );
181 #endif
182              vtkactor->GetProperty()->SetRepresentation( bbGetInputRepresentation() );
183             if (bbGetInputRepresentation()==0)
184             {
185                  vtkactor->GetProperty()->SetAmbient(1);
186                  vtkactor->GetProperty()->SetDiffuse(1);
187                  vtkactor->GetProperty()->SetSpecular(0);
188 printf("EED WARNNING!  PolyDataToActor::DoProcess  which is the default values of Ambient, Diffuse, Specular for points option? \n");
189             } else if (bbGetInputRepresentation()==1)
190             {
191                  vtkactor->GetProperty()->SetAmbient(1);
192                  vtkactor->GetProperty()->SetDiffuse(1);
193                  vtkactor->GetProperty()->SetSpecular(0);
194             } else if (bbGetInputRepresentation()==2)
195             {
196                  vtkactor->GetProperty()->SetAmbient(0);
197                  vtkactor->GetProperty()->SetDiffuse(1);
198                  vtkactor->GetProperty()->SetSpecular(0);
199             }
200              vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
201              vtkactor->GetProperty()->SetColor( bbGetInputColour()[0],
202                             bbGetInputColour()[1],
203                             bbGetInputColour()[2] );
204              vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
205              if ( bbGetInputTransform()!=NULL )
206              {
207                 vtkactor->SetUserTransform( bbGetInputTransform() );
208              }
209              bbSetOutputOut( vtkactor );
210             
211             
212 /*  /  >>>>
213  AAAAA
214             vtkArrowSource *arrow = vtkArrowSource::New();
215             vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
216             normals->SetInputData( bbGetInputIn() );
217             vtkGlyph3D *glyph = vtkGlyph3D::New();
218             glyph->SetInputData(normals->GetOutput() );
219             glyph->SetSourceData(arrow->GetOutput() );
220             glyph->SetVectorModeToUseNormal();
221             glyph->SetScaleModeToScaleByVector();
222             glyph->SetScaleFactor(10);
223             vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
224             mapper2->SetInputData( glyph->GetOutput() );
225             vtkActor *actor2 = vtkActor::New();
226             actor2->SetMapper(mapper2);
227             actor2->GetProperty()->SetColor(1, 0, 0);
228 */
229
230             
231             
232              // Interface Update
233              if ((actorAdded==false) && (bbGetInputRenderer()!=NULL ))
234              {
235                actorAdded=true;
236                bbGetInputRenderer()->AddActor( vtkactor );
237 //--
238 //                 bbGetInputRenderer()->AddActor( actor2 );
239 //--
240                  
241                  
242              }  // actorAdded
243              if (bbGetInputScalarVisibility()==true )
244              {
245                 polydatamapper->ScalarVisibilityOn();
246                 if (bbGetInputScalarVisibilityOn_LookupTable()!=NULL)
247                 {
248 //                                      polydatamapper->SetScalarModeToDefault();
249 //                                      polydatamapper->SetScalarModeToUseCellData();
250 //                                      polydatamapper->SetScalarModeToUseCellFieldData();
251 //                                      polydatamapper->SetScalarModeToUseFieldData();    //    1/2     hausdorff->SetTargetDistanceMethodToPointToCell();
252 //                                      polydatamapper->SetScalarModeToUsePointData();   // *
253                     polydatamapper->SetScalarModeToUsePointFieldData();
254                     polydatamapper->SetColorModeToMapScalars();
255                     polydatamapper->SetLookupTable( bbGetInputScalarVisibilityOn_LookupTable() );
256                     if (bbGetInputScalarVisibilityOn_NameColorArray()!="")
257                     {
258                         polydatamapper->SelectColorArray( bbGetInputScalarVisibilityOn_NameColorArray().c_str() );
259                     }
260                     if (bbGetInputScalarVisibilityOn_ScalarRange().size()==2)
261                     {
262                         polydatamapper->SetScalarRange(  bbGetInputScalarVisibilityOn_ScalarRange()[0] , bbGetInputScalarVisibilityOn_ScalarRange()[1]   );
263                     }
264                  } // if ScalarVisibilityOn_LookupTable
265              } else {
266                  polydatamapper->ScalarVisibilityOff();
267              } // ScalarVisibility
268         } else {
269             ok_removeActor=true;
270 //            printf("EED Warnning! PolyDataToActor::DoProcess   In (PolyData) not defined. \n"  );
271         }// if In !=NULL
272     } else {
273          ok_removeActor=true;
274     } // Active
275     
276     if (ok_removeActor==true)
277     {
278         // Interface Update
279         if ((actorAdded==true) && (bbGetInputRenderer()!=NULL ))
280         {
281           actorAdded=false;
282           bbGetInputRenderer()->RemoveActor( vtkactor );
283         }  // actorAdded
284     } // if ok_removeActor
285     
286 }
287
288 } // EO namespace bbtk
289
290 #endif //_USE_VTK_
291