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 "vtkLinearTransform.h"
45 #include "vtkCleanPolyData.h"
46 #include "vtkFieldData.h"
49 #include <vtkGlyph3D.h>
50 #include <vtkArrowSource.h>
51 #include <vtkPolyDataNormals.h>
54 #include "bbvtkPolyDataToActor.h"
55 #include "bbvtkPackage.h"
57 #include "vtkRenderWindow.h"
61 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataToActor)
62 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataToActor,bbtk::AtomicBlackBox);
64 void PolyDataToActor::bbUserSetDefaultValues()
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);
74 bbSetInputRenderer(NULL);
75 bbSetInputTransform(NULL);
77 bbSetInputRepresentation(2);
78 bbSetInputLineWidth(1);
79 bbSetInputScalarVisibility(false);
80 polydatamapper = NULL;
83 bbSetInputScalarVisibilityOn_LookupTable(NULL);
84 bbSetInputScalarVisibilityOn_NameColorArray("");
89 //---------------------------------------------------------------------
90 void PolyDataToActor::bbUserInitializeProcessing()
92 polydatamapper = vtkPolyDataMapper::New();
93 vtkactor = vtkActor::New();
94 backfaceproperty = vtkProperty::New();
96 // polydatamapper->SetInput(marchingcubes->GetOutput());
97 vtkactor->SetMapper(polydatamapper);
99 //EED 2020-04-21 vtk8 deprecated
100 // polydatamapper->ImmediateModeRenderingOn();
103 //---------------------------------------------------------------------
104 void PolyDataToActor::bbUserFinalizeProcessing()
106 if (polydatamapper!=NULL)
108 polydatamapper->Delete();
123 -----------------------------------------------
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
129 vtkSmartPointer<vtkFloatArray> scalars = vtkSmartPointer<vtkFloatArray>::New();
130 scalars set value ....
131 poly->GetPointData()->SetScalars(scalars); or poly->GetPointData()->SetActiveScalars("<NameArray>");
133 vtkSmartPointer<vtkLookupTable> hueLut = vtkSmartPoint | ^~
134 er<vtkLookupTable>::New();
137 mapper->SetInputData(poly);
138 mapper->ScalarVisibilityOn();
139 mapper->SetScalarModeToUsePointData(); Point of Cell ...
141 default: mapper->SetColorModeToDirectScalars() Busca scalars 3 componentes [R,G,B] float 0..1 or integer 0..255
143 mapper->SetColorModeToMapScalars() El vector scalar solo tiene un componente
144 mapper->SetLookupTable( hueLut );
147 mapper->SelectColorArray("<NameVector>");
149 mapper->SetUseLookupTableScalarRange( true/false ) true:Para compartir lookuptable con otros mappers
151 mapper->SetScalarRange( min, max); Range especifico este mapper
152 mapper->SetScalarRange( tubePolyData->GetScalarRange() );
154 ------------------------------------------
156 mapper->ScalarVisibilityOff(); -> SetScalarModeToDefault()
157 Utiliza el color del actor
159 ----------------------------------------
164 //---------------------------------------------------------------------
166 void PolyDataToActor::DoProcess()
168 bool ok_removeActor=false;
169 if (bbGetInputRenderer()==NULL)
171 printf("EED Warnning! PolyDataToActor::DoProcess missing Renderer.\n");
173 if (bbGetInputActive()==true)
175 if (bbGetInputIn()!=NULL)
177 //EED 2017-01-01 Migration VTK7
178 #if VTK_MAJOR_VERSION <= 5
179 polydatamapper->SetInput( bbGetInputIn() );
181 polydatamapper->SetInputData( bbGetInputIn() );
183 vtkactor->GetProperty()->SetRepresentation( bbGetInputRepresentation() );
184 if (bbGetInputRepresentation()==0)
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)
192 vtkactor->GetProperty()->SetAmbient(1);
193 vtkactor->GetProperty()->SetDiffuse(1);
194 vtkactor->GetProperty()->SetSpecular(0);
195 } else if (bbGetInputRepresentation()==2)
197 vtkactor->GetProperty()->SetAmbient(0);
198 vtkactor->GetProperty()->SetDiffuse(1);
199 vtkactor->GetProperty()->SetSpecular(0);
201 vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
202 vtkactor->GetProperty()->SetColor( bbGetInputColour()[0], bbGetInputColour()[1], bbGetInputColour()[2] );
203 vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
206 if (bbGetInputBackFaceColour().size()==3)
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 );
216 vtkactor->SetBackfaceProperty( NULL );
219 if ( bbGetInputTransform()!=NULL )
221 vtkactor->SetUserTransform( bbGetInputTransform() );
223 bbSetOutputOut( vtkactor );
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);
247 if ((actorAdded==false) && (bbGetInputRenderer()!=NULL ))
250 bbGetInputRenderer()->AddActor( vtkactor );
252 // bbGetInputRenderer()->AddActor( actor2 );
257 if (bbGetInputScalarVisibility()==true )
259 polydatamapper->ScalarVisibilityOn();
260 if (bbGetInputScalarVisibilityOn_LookupTable()!=NULL)
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()!="")
272 polydatamapper->SelectColorArray( bbGetInputScalarVisibilityOn_NameColorArray().c_str() );
274 if (bbGetInputScalarVisibilityOn_ScalarRange().size()==2)
276 polydatamapper->SetScalarRange( bbGetInputScalarVisibilityOn_ScalarRange()[0] , bbGetInputScalarVisibilityOn_ScalarRange()[1] );
278 } // if ScalarVisibilityOn_LookupTable
280 polydatamapper->ScalarVisibilityOff();
281 } // ScalarVisibility
284 // printf("EED Warnning! PolyDataToActor::DoProcess In (PolyData) not defined. \n" );
290 if (ok_removeActor==true)
293 if ((actorAdded==true) && (bbGetInputRenderer()!=NULL ))
296 bbGetInputRenderer()->RemoveActor( vtkactor );
298 } // if ok_removeActor
302 } // EO namespace bbtk