]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataToActor.cxx
#3507 BackFace in PolyDataToActor Box
[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], bbGetInputColour()[1], bbGetInputColour()[2] );
202             vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
203
204             vtkProperty *backfaceproperty = vtkProperty::New();
205             backfaceproperty->SetColor(0.5, 0.5, 1);
206             backfaceproperty->SetOpacity( bbGetInputOpacity() );
207             vtkactor->SetBackfaceProperty( backfaceproperty );
208
209              if ( bbGetInputTransform()!=NULL )
210              {
211                 vtkactor->SetUserTransform( bbGetInputTransform() );
212              }
213              bbSetOutputOut( vtkactor );
214             
215             
216 /*  /  >>>>
217  AAAAA
218             vtkArrowSource *arrow = vtkArrowSource::New();
219             vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
220             normals->SetInputData( bbGetInputIn() );
221             vtkGlyph3D *glyph = vtkGlyph3D::New();
222             glyph->SetInputData(normals->GetOutput() );
223             glyph->SetSourceData(arrow->GetOutput() );
224             glyph->SetVectorModeToUseNormal();
225             glyph->SetScaleModeToScaleByVector();
226             glyph->SetScaleFactor(10);
227             vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
228             mapper2->SetInputData( glyph->GetOutput() );
229             vtkActor *actor2 = vtkActor::New();
230             actor2->SetMapper(mapper2);
231             actor2->GetProperty()->SetColor(1, 0, 0);
232 */
233
234             
235             
236              // Interface Update
237              if ((actorAdded==false) && (bbGetInputRenderer()!=NULL ))
238              {
239                actorAdded=true;
240                bbGetInputRenderer()->AddActor( vtkactor );
241 //--
242 //                 bbGetInputRenderer()->AddActor( actor2 );
243 //--
244                  
245                  
246              }  // actorAdded
247              if (bbGetInputScalarVisibility()==true )
248              {
249                 polydatamapper->ScalarVisibilityOn();
250                 if (bbGetInputScalarVisibilityOn_LookupTable()!=NULL)
251                 {
252 //                                      polydatamapper->SetScalarModeToDefault();
253 //                                      polydatamapper->SetScalarModeToUseCellData();
254 //                                      polydatamapper->SetScalarModeToUseCellFieldData();
255 //                                      polydatamapper->SetScalarModeToUseFieldData();    //    1/2     hausdorff->SetTargetDistanceMethodToPointToCell();
256 //                                      polydatamapper->SetScalarModeToUsePointData();   // *
257                     polydatamapper->SetScalarModeToUsePointFieldData();
258                     polydatamapper->SetColorModeToMapScalars();
259                     polydatamapper->SetLookupTable( bbGetInputScalarVisibilityOn_LookupTable() );
260                     if (bbGetInputScalarVisibilityOn_NameColorArray()!="")
261                     {
262                         polydatamapper->SelectColorArray( bbGetInputScalarVisibilityOn_NameColorArray().c_str() );
263                     }
264                     if (bbGetInputScalarVisibilityOn_ScalarRange().size()==2)
265                     {
266                         polydatamapper->SetScalarRange(  bbGetInputScalarVisibilityOn_ScalarRange()[0] , bbGetInputScalarVisibilityOn_ScalarRange()[1]   );
267                     }
268                  } // if ScalarVisibilityOn_LookupTable
269              } else {
270                  polydatamapper->ScalarVisibilityOff();
271              } // ScalarVisibility
272         } else {
273             ok_removeActor=true;
274 //            printf("EED Warnning! PolyDataToActor::DoProcess   In (PolyData) not defined. \n"  );
275         }// if In !=NULL
276     } else {
277          ok_removeActor=true;
278     } // Active
279     
280     if (ok_removeActor==true)
281     {
282         // Interface Update
283         if ((actorAdded==true) && (bbGetInputRenderer()!=NULL ))
284         {
285           actorAdded=false;
286           bbGetInputRenderer()->RemoveActor( vtkactor );
287         }  // actorAdded
288     } // if ok_removeActor
289     
290 }
291
292 } // EO namespace bbtk
293
294 #endif //_USE_VTK_
295