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"
29 #include "vtkObjectFactory.h"
31 vtkStandardNewMacro(vtkLookupTableDirectionVector);
33 // Construct with range=(0,1); and hsv ranges set up for rainbow color table
34 // (from red to blue).
35 vtkLookupTableDirectionVector::vtkLookupTableDirectionVector(int sze, int ext)
37 this->TableRange[0] = 0.0;
38 this->TableRange[1] = 1.0;
41 //----------------------------------------------------------------------------
42 vtkLookupTableDirectionVector::~vtkLookupTableDirectionVector()
46 unsigned char *vtkLookupTableDirectionVector::MapValue(double v)
49 //int idx = this->GetIndex(v);
50 //return (this->Table->GetPointer(0) + 4*idx);
54 void vtkLookupTableDirectionVector::GetColor(double v, double rgb[3])
56 // unsigned char *rgb8 = this->MapValue(v);
57 // rgb[0] = rgb8[0]/255.0;
58 // rgb[1] = rgb8[1]/255.0;
59 // rgb[2] = rgb8[2]/255.0;
67 void vtkLookupTableDirectionVector::SetTableRange(double r[2])
69 this->SetTableRange(r[0],r[1]);
72 //----------------------------------------------------------------------------
73 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
74 // less than minimum range value are clamped to minimum range value.
75 // Scalar values greater than maximum range value are clamped to maximum
77 void vtkLookupTableDirectionVector::SetTableRange(double rmin, double rmax)
81 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
85 if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
90 this->TableRange[0] = rmin;
91 this->TableRange[1] = rmax;
98 //----------------------------------------------------------------------------
99 // Although this is a relatively expensive calculation,
100 // it is only done on the first render. Colors are cached
101 // for subsequent renders.
103 void vtkLookupTableMapDirVectorEED(vtkLookupTableDirectionVector *self, T *input,
104 unsigned char *output, int length,
105 int inIncr, int outFormat)
110 double dirx,diry,dirz;
113 printf("EED vtkLookupTableMapDirVectorEED inIncr=%d \n", inIncr);
116 // mag = new double[length];
117 for (i = 0; i < length; ++i)
122 dirx = static_cast<T>(input[0]);
123 diry = static_cast<T>(input[1]);
124 dirz = static_cast<T>(input[2]);
125 input = input+inIncr;
126 sum = sqrt( dirx*dirx + diry*diry + dirz*dirz );
133 for (j = 0; j < inIncr; ++j)
135 if (j==0) dirx= static_cast<T>(*input);
136 if (j==1) diry= static_cast<T>(*input);
137 if (j==2) dirz= static_cast<T>(*input);
138 tmp = static_cast<T>(*input);
145 *output++ = (unsigned char) abs( (255*dirx/sum) );
146 *output++ = (unsigned char) abs( (255*diry/sum) );
147 *output++ = (unsigned char) abs( (255*dirz/sum) );
149 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
150 // printf(" C %d %f %f %f \n",inIncr,dirx,diry,dirz);
152 } // type 1 color vector by direction
156 angle = static_cast<T>(input[0]);
157 input = input+inIncr;
159 *output++ = (unsigned char) abs( 255*angle/90 );
160 *output++ = (unsigned char) abs( 0 );
161 *output++ = (unsigned char) abs( 0 );
163 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
164 // printf(" C %d %f %f %f \n",inIncr,dirx,diry,dirz);
166 }// type 2 color vector by scalar
171 // vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
179 //----------------------------------------------------------------------------
180 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input,
181 unsigned char *output,
187 printf("vtkLookupTableEED::MapScalarsThroughTable2 \n");
188 // if (this->UseMagnitude && inputIncrement > 1)
190 switch (inputDataType)
192 vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
193 numberOfValues,inputIncrement,outputFormat);
197 vtkErrorMacro("Cannot comput magnitude of bit array.");
200 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
206 //----------------------------------------------------------------------------
207 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
209 this->Superclass::PrintSelf(os,indent);
215 //----------------------------------
216 //----------------------------------
217 //----------------------------------
218 //----------------------------------
219 //----------------------------------
221 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
232 _LutEED = vtkLookupTableDirectionVector::New();
234 //_LutEED->SetVectorMode(0);
235 //_LutEED->SetVectorModeToMagnitude();
236 //_LutEED->SetVectorModeToComponent();
237 _LutEED->SetVectorModeToRGBColors();
239 _pdm = vtkPolyDataMapper::New();
240 _actor = vtkActor::New();
244 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
248 //------------------------------------------------------------------------
249 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
251 _dataobject = dataobject;
254 //------------------------------------------------------------------------
255 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
260 //------------------------------------------------------------------------
261 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
266 //------------------------------------------------------------------------
267 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
272 //------------------------------------------------------------------------
273 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
275 _scalefactor=scalefactor;
278 //------------------------------------------------------------------------
279 double vtkVectorsTensorsVisuBase::GetScaleFactor()
284 //------------------------------------------------------------------------
285 void vtkVectorsTensorsVisuBase::SetActive(bool active)
290 //------------------------------------------------------------------------
291 bool vtkVectorsTensorsVisuBase::GetActive()
296 //------------------------------------------------------------------------
297 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
302 //------------------------------------------------------------------------
303 double vtkVectorsTensorsVisuBase::GetOpacity()
310 //------------------------------------------------------------------------
311 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
316 //------------------------------------------------------------------------
317 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
323 //------------------------------------------------------------------------
324 int vtkVectorsTensorsVisuBase::GetTypeForm()
329 //------------------------------------------------------------------------
330 void vtkVectorsTensorsVisuBase::Process() // virtual
334 //------------------------------------------------------------------------------
335 void vtkVectorsTensorsVisuBase::VisibilityActor()
338 if ( (_active==true) && (_actorAdded==false) ){
339 if (GetRenderer()!=NULL)
341 GetRenderer()->AddActor(_actor);
344 } // if _active==true
346 if ( (_active==false) && (_actorAdded==true) ){
347 if (GetRenderer()!=NULL)
349 GetRenderer()->RemoveActor(_actor);
352 } // if _active==false
355 //------------------------------------------------------------------------------
356 void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw)
358 _colorlaw = colorlaw;
361 //------------------------------------------------------------------------------
362 void vtkVectorsTensorsVisuBase::SetColor(std::vector<double> rgb)
376 //------------------------------------------------------------------------------
377 void vtkVectorsTensorsVisuBase::SetOrientation(int orientation)
379 _orientation = orientation;
382 //------------------------------------------------------------------------------
383 int vtkVectorsTensorsVisuBase::GetOrientation()
388 //------------------------------------------------------------------------------
389 void vtkVectorsTensorsVisuBase::SetExternalLut(vtkScalarsToColors* lut)
391 printf("EED vtkVectorsTensorsVisuBase::SetExternalLut C ptrlut %p this:%p\n",lut, this);
393 printf("EED vtkVectorsTensorsVisuBase::SetExternalLut D ptrlut %p \n",_externalLut);