2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbvtkPolyDataToActor.cxx,v $
32 Date: $Date: 2009/05/28 08:55:44 $
33 Version: $Revision: 1.15 $
34 =========================================================================*/
44 #include "vtkProperty.h"
45 #include "vtkLinearTransform.h"
46 #include "vtkCleanPolyData.h"
47 #include "vtkFieldData.h"
50 #include <vtkGlyph3D.h>
51 #include <vtkArrowSource.h>
52 #include <vtkPolyDataNormals.h>
55 #include "bbvtkPolyDataToActor.h"
56 #include "bbvtkPackage.h"
58 #include "vtkRenderWindow.h"
62 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataToActor)
63 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataToActor,bbtk::AtomicBlackBox);
65 void PolyDataToActor::bbUserSetDefaultValues()
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);
75 bbSetInputRenderer(NULL);
76 bbSetInputTransform(NULL);
78 bbSetInputRepresentation(2);
79 bbSetInputLineWidth(1);
80 bbSetInputScalarVisibility(false);
81 polydatamapper = NULL;
84 bbSetInputScalarVisibilityOn_LookupTable(NULL);
85 bbSetInputScalarVisibilityOn_NameColorArray("");
90 //---------------------------------------------------------------------
91 void PolyDataToActor::bbUserInitializeProcessing()
93 polydatamapper = vtkPolyDataMapper::New();
94 vtkactor = vtkActor::New();
95 // polydatamapper->SetInput(marchingcubes->GetOutput());
96 vtkactor->SetMapper(polydatamapper);
98 //EED 2020-04-21 vtk8 deprecated
99 // polydatamapper->ImmediateModeRenderingOn();
102 //---------------------------------------------------------------------
103 void PolyDataToActor::bbUserFinalizeProcessing()
105 if (polydatamapper!=NULL)
107 polydatamapper->Delete();
122 -----------------------------------------------
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
128 vtkSmartPointer<vtkFloatArray> scalars = vtkSmartPointer<vtkFloatArray>::New();
129 scalars set value ....
130 poly->GetPointData()->SetScalars(scalars); or poly->GetPointData()->SetActiveScalars("<NameArray>");
132 vtkSmartPointer<vtkLookupTable> hueLut = vtkSmartPoint | ^~
133 er<vtkLookupTable>::New();
136 mapper->SetInputData(poly);
137 mapper->ScalarVisibilityOn();
138 mapper->SetScalarModeToUsePointData(); Point of Cell ...
140 default: mapper->SetColorModeToDirectScalars() Busca scalars 3 componentes [R,G,B] float 0..1 or integer 0..255
142 mapper->SetColorModeToMapScalars() El vector scalar solo tiene un componente
143 mapper->SetLookupTable( hueLut );
146 mapper->SelectColorArray("<NameVector>");
148 mapper->SetUseLookupTableScalarRange( true/false ) true:Para compartir lookuptable con otros mappers
150 mapper->SetScalarRange( min, max); Range especifico este mapper
151 mapper->SetScalarRange( tubePolyData->GetScalarRange() );
153 ------------------------------------------
155 mapper->ScalarVisibilityOff(); -> SetScalarModeToDefault()
156 Utiliza el color del actor
158 ----------------------------------------
163 //---------------------------------------------------------------------
165 void PolyDataToActor::DoProcess()
167 bool ok_removeActor=false;
168 if (bbGetInputRenderer()==NULL)
170 printf("EED Warnning! PolyDataToActor::DoProcess missing Renderer.\n");
172 if (bbGetInputActive()==true)
174 if (bbGetInputIn()!=NULL)
176 //EED 2017-01-01 Migration VTK7
177 #if VTK_MAJOR_VERSION <= 5
178 polydatamapper->SetInput( bbGetInputIn() );
180 polydatamapper->SetInputData( bbGetInputIn() );
182 vtkactor->GetProperty()->SetRepresentation( bbGetInputRepresentation() );
183 if (bbGetInputRepresentation()==0)
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)
191 vtkactor->GetProperty()->SetAmbient(1);
192 vtkactor->GetProperty()->SetDiffuse(1);
193 vtkactor->GetProperty()->SetSpecular(0);
194 } else if (bbGetInputRepresentation()==2)
196 vtkactor->GetProperty()->SetAmbient(0);
197 vtkactor->GetProperty()->SetDiffuse(1);
198 vtkactor->GetProperty()->SetSpecular(0);
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 )
207 vtkactor->SetUserTransform( bbGetInputTransform() );
209 bbSetOutputOut( vtkactor );
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);
233 if ((actorAdded==false) && (bbGetInputRenderer()!=NULL ))
236 bbGetInputRenderer()->AddActor( vtkactor );
238 // bbGetInputRenderer()->AddActor( actor2 );
243 if (bbGetInputScalarVisibility()==true )
245 polydatamapper->ScalarVisibilityOn();
246 if (bbGetInputScalarVisibilityOn_LookupTable()!=NULL)
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()!="")
258 polydatamapper->SelectColorArray( bbGetInputScalarVisibilityOn_NameColorArray().c_str() );
260 if (bbGetInputScalarVisibilityOn_ScalarRange().size()==2)
262 polydatamapper->SetScalarRange( bbGetInputScalarVisibilityOn_ScalarRange()[0] , bbGetInputScalarVisibilityOn_ScalarRange()[1] );
264 } // if ScalarVisibilityOn_LookupTable
266 polydatamapper->ScalarVisibilityOff();
267 } // ScalarVisibility
270 // printf("EED Warnning! PolyDataToActor::DoProcess In (PolyData) not defined. \n" );
276 if (ok_removeActor==true)
279 if ((actorAdded==true) && (bbGetInputRenderer()!=NULL ))
282 bbGetInputRenderer()->RemoveActor( vtkactor );
284 } // if ok_removeActor
288 } // EO namespace bbtk