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 #include "vtkVectorsTensorsVisuBase.h"
31 #include "vtkObjectFactory.h"
36 vtkStandardNewMacro(vtkLookupTableDirectionVector);
38 // Construct with range=(0,1); and hsv ranges set up for rainbow color table
39 // (from red to blue).
40 vtkLookupTableDirectionVector::vtkLookupTableDirectionVector(int sze, int ext)
42 this->TableRange[0] = 0.0;
43 this->TableRange[1] = 1.0;
46 //----------------------------------------------------------------------------
47 vtkLookupTableDirectionVector::~vtkLookupTableDirectionVector()
53 unsigned char *vtkLookupTableDirectionVector::MapValue(double v)
56 //int idx = this->GetIndex(v);
57 //return (this->Table->GetPointer(0) + 4*idx);
62 void vtkLookupTableDirectionVector::GetColor(double v, double rgb[3])
64 // unsigned char *rgb8 = this->MapValue(v);
65 // rgb[0] = rgb8[0]/255.0;
66 // rgb[1] = rgb8[1]/255.0;
67 // rgb[2] = rgb8[2]/255.0;
75 void vtkLookupTableDirectionVector::SetTableRange(double r[2])
77 this->SetTableRange(r[0],r[1]);
80 //----------------------------------------------------------------------------
81 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
82 // less than minimum range value are clamped to minimum range value.
83 // Scalar values greater than maximum range value are clamped to maximum
85 void vtkLookupTableDirectionVector::SetTableRange(double rmin, double rmax)
89 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
93 if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
98 this->TableRange[0] = rmin;
99 this->TableRange[1] = rmax;
106 //----------------------------------------------------------------------------
107 // Although this is a relatively expensive calculation,
108 // it is only done on the first render. Colors are cached
109 // for subsequent renders.
111 void vtkLookupTableMapDirVectorEED(vtkLookupTableDirectionVector *self, T *input,
112 unsigned char *output, int length,
113 int inIncr, int outFormat)
118 double dirx,diry,dirz;
121 printf("EED length %d %p\n", length,input);
122 // mag = new double[length];
123 for (i = 0; i < length; ++i)
129 for (j = 0; j < inIncr; ++j)
131 if (j==0) dirx= static_cast<double>(*input);
132 if (j==1) diry= static_cast<double>(*input);
133 if (j==2) dirz= static_cast<double>(*input);
134 tmp = static_cast<double>(*input);
139 *output++ = (unsigned char) abs( (255*dirx/sum) );
140 *output++ = (unsigned char) abs( (255*diry/sum) );
141 *output++ = (unsigned char) abs( (255*dirz/sum) );
143 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
146 // vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
153 //----------------------------------------------------------------------------
154 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input,
155 unsigned char *output,
161 printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d inputDataType=%d\n",inputIncrement,inputDataType);
162 // if (this->UseMagnitude && inputIncrement > 1)
164 switch (inputDataType)
166 vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
167 numberOfValues,inputIncrement,outputFormat);
171 vtkErrorMacro("Cannot comput magnitude of bit array.");
174 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
180 //----------------------------------------------------------------------------
181 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
183 this->Superclass::PrintSelf(os,indent);
189 //----------------------------------
190 //----------------------------------
191 //----------------------------------
192 //----------------------------------
193 //----------------------------------
202 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
212 _LutEED = vtkLookupTableDirectionVector::New();
213 // _LutEED->SetVectorMode(0);
214 //_LutEED->SetVectorModeToMagnitude();
215 //_LutEED->SetVectorModeToComponent();
216 _LutEED->SetVectorModeToRGBColors();
220 _pdm = vtkPolyDataMapper::New();
221 _actor = vtkActor::New();
225 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
229 //------------------------------------------------------------------------
230 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
232 _dataobject = dataobject;
235 //------------------------------------------------------------------------
236 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
241 //------------------------------------------------------------------------
242 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
247 //------------------------------------------------------------------------
248 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
253 //------------------------------------------------------------------------
254 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
256 _scalefactor=scalefactor;
259 //------------------------------------------------------------------------
260 double vtkVectorsTensorsVisuBase::GetScaleFactor()
265 //------------------------------------------------------------------------
266 void vtkVectorsTensorsVisuBase::SetActive(bool active)
271 //------------------------------------------------------------------------
272 bool vtkVectorsTensorsVisuBase::GetActive()
277 //------------------------------------------------------------------------
278 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
283 //------------------------------------------------------------------------
284 double vtkVectorsTensorsVisuBase::GetOpacity()
291 //------------------------------------------------------------------------
292 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
297 //------------------------------------------------------------------------
298 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
304 //------------------------------------------------------------------------
305 int vtkVectorsTensorsVisuBase::GetTypeForm()
310 //------------------------------------------------------------------------
311 void vtkVectorsTensorsVisuBase::Process() // virtual
317 //------------------------------------------------------------------------------
318 void vtkVectorsTensorsVisuBase::VisibilityActor()
321 if ( (_active==true) && (_actorAdded==false) ){
322 if (GetRenderer()!=NULL)
324 GetRenderer()->AddActor(_actor);
327 } // if _active==true
329 if ( (_active==false) && (_actorAdded==true) ){
330 if (GetRenderer()!=NULL)
332 GetRenderer()->RemoveActor(_actor);
335 } // if _active==false