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