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