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;
114 printf("EED length %d %p\n", length,input);
115 // mag = new double[length];
116 for (i = 0; i < length; ++i)
122 for (j = 0; j < inIncr; ++j)
124 if (j==0) dirx= static_cast<T>(*input);
125 if (j==1) diry= static_cast<T>(*input);
126 if (j==2) dirz= static_cast<T>(*input);
127 tmp = static_cast<T>(*input);
132 *output++ = (unsigned char) abs( (255*dirx/sum) );
133 *output++ = (unsigned char) abs( (255*diry/sum) );
134 *output++ = (unsigned char) abs( (255*dirz/sum) );
136 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
137 // printf(" C %d %f %f %f \n",inIncr,dirx,diry,dirz);
140 // vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
146 //----------------------------------------------------------------------------
147 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input,
148 unsigned char *output,
154 printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d inputDataType=%d\n",inputIncrement,inputDataType);
155 // if (this->UseMagnitude && inputIncrement > 1)
157 switch (inputDataType)
159 vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
160 numberOfValues,inputIncrement,outputFormat);
164 vtkErrorMacro("Cannot comput magnitude of bit array.");
167 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
173 //----------------------------------------------------------------------------
174 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
176 this->Superclass::PrintSelf(os,indent);
182 //----------------------------------
183 //----------------------------------
184 //----------------------------------
185 //----------------------------------
186 //----------------------------------
188 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
198 _LutEED = vtkLookupTableDirectionVector::New();
199 //_LutEED->SetVectorMode(0);
200 //_LutEED->SetVectorModeToMagnitude();
201 //_LutEED->SetVectorModeToComponent();
202 _LutEED->SetVectorModeToRGBColors();
204 _pdm = vtkPolyDataMapper::New();
205 _actor = vtkActor::New();
209 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
213 //------------------------------------------------------------------------
214 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
216 _dataobject = dataobject;
219 //------------------------------------------------------------------------
220 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
225 //------------------------------------------------------------------------
226 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
231 //------------------------------------------------------------------------
232 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
237 //------------------------------------------------------------------------
238 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
240 _scalefactor=scalefactor;
243 //------------------------------------------------------------------------
244 double vtkVectorsTensorsVisuBase::GetScaleFactor()
249 //------------------------------------------------------------------------
250 void vtkVectorsTensorsVisuBase::SetActive(bool active)
255 //------------------------------------------------------------------------
256 bool vtkVectorsTensorsVisuBase::GetActive()
261 //------------------------------------------------------------------------
262 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
267 //------------------------------------------------------------------------
268 double vtkVectorsTensorsVisuBase::GetOpacity()
275 //------------------------------------------------------------------------
276 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
281 //------------------------------------------------------------------------
282 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
288 //------------------------------------------------------------------------
289 int vtkVectorsTensorsVisuBase::GetTypeForm()
294 //------------------------------------------------------------------------
295 void vtkVectorsTensorsVisuBase::Process() // virtual
299 //------------------------------------------------------------------------------
300 void vtkVectorsTensorsVisuBase::VisibilityActor()
303 if ( (_active==true) && (_actorAdded==false) ){
304 if (GetRenderer()!=NULL)
306 GetRenderer()->AddActor(_actor);
309 } // if _active==true
311 if ( (_active==false) && (_actorAdded==true) ){
312 if (GetRenderer()!=NULL)
314 GetRenderer()->RemoveActor(_actor);
317 } // if _active==false
320 //------------------------------------------------------------------------------
321 void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw)
323 _colorlaw = colorlaw;
326 //------------------------------------------------------------------------------
327 void vtkVectorsTensorsVisuBase::SetColor(std::vector<double> rgb)