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;
122 printf("EED length %d %p\n", length,input);
123 // mag = new double[length];
124 for (i = 0; i < length; ++i)
130 for (j = 0; j < inIncr; ++j)
132 if (j==0) dirx= static_cast<T>(*input);
133 if (j==1) diry= static_cast<T>(*input);
134 if (j==2) dirz= static_cast<T>(*input);
135 tmp = static_cast<T>(*input);
140 *output++ = (unsigned char) abs( (255*dirx/sum) );
141 *output++ = (unsigned char) abs( (255*diry/sum) );
142 *output++ = (unsigned char) abs( (255*dirz/sum) );
144 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
145 // printf(" C %d %f %f %f \n",inIncr,dirx,diry,dirz);
148 // vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
155 //----------------------------------------------------------------------------
156 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input,
157 unsigned char *output,
163 printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d inputDataType=%d\n",inputIncrement,inputDataType);
164 // if (this->UseMagnitude && inputIncrement > 1)
166 switch (inputDataType)
168 vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
169 numberOfValues,inputIncrement,outputFormat);
173 vtkErrorMacro("Cannot comput magnitude of bit array.");
176 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
182 //----------------------------------------------------------------------------
183 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
185 this->Superclass::PrintSelf(os,indent);
191 //----------------------------------
192 //----------------------------------
193 //----------------------------------
194 //----------------------------------
195 //----------------------------------
197 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
207 _LutEED = vtkLookupTableDirectionVector::New();
208 // _LutEED->SetVectorMode(0);
209 //_LutEED->SetVectorModeToMagnitude();
210 //_LutEED->SetVectorModeToComponent();
211 _LutEED->SetVectorModeToRGBColors();
213 _pdm = vtkPolyDataMapper::New();
214 _actor = vtkActor::New();
218 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
222 //------------------------------------------------------------------------
223 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
225 _dataobject = dataobject;
228 //------------------------------------------------------------------------
229 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
234 //------------------------------------------------------------------------
235 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
240 //------------------------------------------------------------------------
241 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
246 //------------------------------------------------------------------------
247 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
249 _scalefactor=scalefactor;
252 //------------------------------------------------------------------------
253 double vtkVectorsTensorsVisuBase::GetScaleFactor()
258 //------------------------------------------------------------------------
259 void vtkVectorsTensorsVisuBase::SetActive(bool active)
264 //------------------------------------------------------------------------
265 bool vtkVectorsTensorsVisuBase::GetActive()
270 //------------------------------------------------------------------------
271 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
276 //------------------------------------------------------------------------
277 double vtkVectorsTensorsVisuBase::GetOpacity()
284 //------------------------------------------------------------------------
285 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
290 //------------------------------------------------------------------------
291 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
297 //------------------------------------------------------------------------
298 int vtkVectorsTensorsVisuBase::GetTypeForm()
303 //------------------------------------------------------------------------
304 void vtkVectorsTensorsVisuBase::Process() // virtual
310 //------------------------------------------------------------------------------
311 void vtkVectorsTensorsVisuBase::VisibilityActor()
314 if ( (_active==true) && (_actorAdded==false) ){
315 if (GetRenderer()!=NULL)
317 GetRenderer()->AddActor(_actor);
320 } // if _active==true
322 if ( (_active==false) && (_actorAdded==true) ){
323 if (GetRenderer()!=NULL)
325 GetRenderer()->RemoveActor(_actor);
328 } // if _active==false
332 //------------------------------------------------------------------------------
333 void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw)
335 _colorlaw = colorlaw;
338 //------------------------------------------------------------------------------
339 void vtkVectorsTensorsVisuBase::SetColor(std::vector<double> rgb)