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)
109 double dirx,diry,dirz;
111 for (i = 0; i < length; ++i)
113 dirx = static_cast<T>(input[0]);
114 diry = static_cast<T>(input[1]);
115 dirz = static_cast<T>(input[2]);
116 input = input+inIncr;
117 sum = sqrt( dirx*dirx + diry*diry + dirz*dirz );
118 *output++ = (unsigned char) abs( (255*dirx/sum) );
119 *output++ = (unsigned char) abs( (255*diry/sum) );
120 *output++ = (unsigned char) abs( (255*dirz/sum) );
122 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
123 // printf(" C %d %f %f %f \n",inIncr,dirx,diry,dirz);
129 //----------------------------------------------------------------------------
130 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input,
131 unsigned char *output,
137 // if (this->UseMagnitude && inputIncrement > 1)
139 switch (inputDataType)
141 vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
142 numberOfValues,inputIncrement,outputFormat);
146 vtkErrorMacro("Cannot comput magnitude of bit array.");
149 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
155 //----------------------------------------------------------------------------
156 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
158 this->Superclass::PrintSelf(os,indent);
164 //----------------------------------
165 //----------------------------------
166 //----------------------------------
167 //----------------------------------
168 //----------------------------------
170 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
181 _LutEED = vtkLookupTableDirectionVector::New();
183 //_LutEED->SetVectorMode(0);
184 //_LutEED->SetVectorModeToMagnitude();
185 //_LutEED->SetVectorModeToComponent();
186 _LutEED->SetVectorModeToRGBColors();
188 _pdm = vtkPolyDataMapper::New();
189 _actor = vtkActor::New();
193 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
197 //------------------------------------------------------------------------
198 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
200 _dataobject = dataobject;
203 //------------------------------------------------------------------------
204 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
209 //------------------------------------------------------------------------
210 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
215 //------------------------------------------------------------------------
216 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
221 //------------------------------------------------------------------------
222 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
224 _scalefactor=scalefactor;
227 //------------------------------------------------------------------------
228 double vtkVectorsTensorsVisuBase::GetScaleFactor()
233 //------------------------------------------------------------------------
234 void vtkVectorsTensorsVisuBase::SetActive(bool active)
239 //------------------------------------------------------------------------
240 bool vtkVectorsTensorsVisuBase::GetActive()
245 //------------------------------------------------------------------------
246 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
251 //------------------------------------------------------------------------
252 double vtkVectorsTensorsVisuBase::GetOpacity()
259 //------------------------------------------------------------------------
260 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
265 //------------------------------------------------------------------------
266 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
272 //------------------------------------------------------------------------
273 int vtkVectorsTensorsVisuBase::GetTypeForm()
278 //------------------------------------------------------------------------
279 void vtkVectorsTensorsVisuBase::Process() // virtual
283 //------------------------------------------------------------------------------
284 void vtkVectorsTensorsVisuBase::VisibilityActor()
286 if ( (_active==true) && (_actorAdded==false) ){
287 if (GetRenderer()!=NULL)
289 GetRenderer()->AddActor(_actor);
292 } // if _active==true
294 if ( (_active==false) && (_actorAdded==true) ){
295 if (GetRenderer()!=NULL)
297 GetRenderer()->RemoveActor(_actor);
300 } // if _active==false
303 //------------------------------------------------------------------------------
304 void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw)
306 _colorlaw = colorlaw;
309 //------------------------------------------------------------------------------
310 void vtkVectorsTensorsVisuBase::SetColor(std::vector<double> rgb)
324 //------------------------------------------------------------------------------
325 void vtkVectorsTensorsVisuBase::SetOrientation(int orientation)
327 _orientation = orientation;
330 //------------------------------------------------------------------------------
331 int vtkVectorsTensorsVisuBase::GetOrientation()
336 //------------------------------------------------------------------------------
337 void vtkVectorsTensorsVisuBase::SetExternalLut(vtkScalarsToColors* lut)