2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
4 #include "bbcreaVtkScalarsToColors.h"
5 #include "bbcreaVtkPackage.h"
7 #include "vtkLookupTable.h"
8 #include "vtkObjectFactory.h"
13 class /*VTK_COMMON_EXPORT*/ vtkLookupTableDirectionVector2 : public vtkScalarsToColors
17 // Construct with range=[0,1]; and hsv ranges set up for rainbow color table
18 // (from red to blue).
19 static vtkLookupTableDirectionVector2 *New();
20 vtkTypeMacro(vtkLookupTableDirectionVector2,vtkScalarsToColors);
21 void PrintSelf(ostream& os, vtkIndent indent);
22 double *GetRange() { return this->GetTableRange(); };
23 void SetRange(double min, double max) { this->SetTableRange(min, max); };
24 void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
25 void SetTableRange(double r[2]);
26 virtual void SetTableRange(double min, double max);
27 vtkGetVectorMacro(TableRange,double,2);
28 unsigned char *MapValue(double v);
29 void GetColor(double x, double rgb[3]);
30 void MapScalarsThroughTable2(void *input, unsigned char *output,
31 int inputDataType, int numberOfValues,
32 int inputIncrement, int outputIncrement);
33 void SetTypeTable( int typetable );
36 vtkLookupTableDirectionVector2(int sze=256, int ext=256);
37 ~vtkLookupTableDirectionVector2();
40 vtkLookupTableDirectionVector2(const vtkLookupTableDirectionVector2&); // Not implemented.
41 void operator=(const vtkLookupTableDirectionVector2&); // Not implemented.
47 vtkStandardNewMacro(vtkLookupTableDirectionVector2);
49 // Construct with range=(0,1); and hsv ranges set up for rainbow color table
50 // (from red to blue).
51 vtkLookupTableDirectionVector2::vtkLookupTableDirectionVector2(int sze, int ext)
53 this->TableRange[0] = 0.0;
54 this->TableRange[1] = 1.0;
58 //----------------------------------------------------------------------------
59 vtkLookupTableDirectionVector2::~vtkLookupTableDirectionVector2()
63 unsigned char *vtkLookupTableDirectionVector2::MapValue(double v)
66 //int idx = this->GetIndex(v);
67 //return (this->Table->GetPointer(0) + 4*idx);
71 void vtkLookupTableDirectionVector2::GetColor(double v, double rgb[3])
73 // unsigned char *rgb8 = this->MapValue(v);
74 // rgb[0] = rgb8[0]/255.0;
75 // rgb[1] = rgb8[1]/255.0;
76 // rgb[2] = rgb8[2]/255.0;
84 void vtkLookupTableDirectionVector2::SetTableRange(double r[2])
86 this->SetTableRange(r[0],r[1]);
89 void vtkLookupTableDirectionVector2::SetTypeTable( int typetable )
94 //----------------------------------------------------------------------------
95 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
96 // less than minimum range value are clamped to minimum range value.
97 // Scalar values greater than maximum range value are clamped to maximum
99 void vtkLookupTableDirectionVector2::SetTableRange(double rmin, double rmax)
103 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
107 if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
112 this->TableRange[0] = rmin;
113 this->TableRange[1] = rmax;
120 //----------------------------------------------------------------------------
121 // Although this is a relatively expensive calculation,
122 // it is only done on the first render. Colors are cached
123 // for subsequent renders.
125 void vtkLookupTableMapDirVectorEED2(vtkLookupTableDirectionVector2 *self, T *input,
126 unsigned char *output, int length,
127 int inIncr, int outFormat,int TypeTable)
134 double dirx,diry,dirz;
135 for (i = 0; i < length; ++i)
137 dirx = static_cast<T>(input[0]);
138 diry = static_cast<T>(input[1]);
139 dirz = static_cast<T>(input[2]);
140 input = input+inIncr;
141 sum = sqrt( dirx*dirx + diry*diry + dirz*dirz );
142 *output++ = (unsigned char) abs( (255*dirx/sum) );
143 *output++ = (unsigned char) abs( (255*diry/sum) );
144 *output++ = (unsigned char) abs( (255*dirz/sum) );
146 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
147 // printf(" C %d %f %f %f \n",inIncr,dirx,diry,dirz);
155 for (i = 0; i < length; ++i)
157 *output++ = static_cast<T>(input[0]); // red
158 *output++ = static_cast<T>(input[1]); // green
159 *output++ = static_cast<T>(input[2]); // blue
161 input = input+inIncr;
169 //----------------------------------------------------------------------------
170 void vtkLookupTableDirectionVector2::MapScalarsThroughTable2(void *input,
171 unsigned char *output,
177 // if (this->UseMagnitude && inputIncrement > 1)
179 switch (inputDataType)
181 vtkTemplateMacro( vtkLookupTableMapDirVectorEED2(this,static_cast<VTK_TT*>(input),output,
182 numberOfValues,inputIncrement,outputFormat,TypeTable);
186 vtkErrorMacro("Cannot comput magnitude of bit array.");
189 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
195 //----------------------------------------------------------------------------
196 void vtkLookupTableDirectionVector2::PrintSelf(ostream& os, vtkIndent indent)
198 this->Superclass::PrintSelf(os,indent);
206 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ScalarsToColors)
207 BBTK_BLACK_BOX_IMPLEMENTATION(ScalarsToColors,bbtk::AtomicBlackBox);
209 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
211 void ScalarsToColors::Process()
214 // THE MAIN PROCESSING METHOD BODY
215 // Here we simply set the input 'In' value to the output 'Out'
216 // And print out the output value
217 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
218 // void bbSet{Input|Output}NAME(const TYPE&)
219 // const TYPE& bbGet{Input|Output}NAME() const
221 // * NAME is the name of the input/output
222 // (the one provided in the attribute 'name' of the tag 'input')
223 // * TYPE is the C++ type of the input/output
224 // (the one provided in the attribute 'type' of the tag 'input')
226 // bbSetOutputOut( bbGetInputIn() );
227 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
230 printf("EED ScalarsToColors::Process Start\n");
235 // Create the color map
236 if (bbGetInputType()==0)
238 vtkLookupTable *colorLookupTable = vtkLookupTable::New();
239 if (bbGetInputRange().size()==2)
241 colorLookupTable->SetRange( bbGetInputRange()[0],bbGetInputRange()[1]);
242 // colorLookupTable->SetTableRange( bbGetInputRange()[0],bbGetInputRange()[1]);
244 colorLookupTable->SetRange(0,255);
246 colorLookupTable->SetNumberOfTableValues(1000);
247 colorLookupTable->Build();
251 for (iLookTable = 0; iLookTable<500; iLookTable++)
253 colorLookupTable->GetTableValue( iLookTable, rgba1);
254 colorLookupTable->GetTableValue(1000-1-iLookTable, rgba2);
255 colorLookupTable->SetTableValue(1000-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
256 colorLookupTable->SetTableValue( iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
259 colorLookupTable->GetTableValue(0,rgba);
261 colorLookupTable->SetTableValue(0,rgba);
266 colorLookupTable->GetTableValue(500+i, rgba);
267 rgba[3]=(double)i/(double)iMax;
268 colorLookupTable->SetTableValue(500+i,rgba);
269 colorLookupTable->GetTableValue(500-i, rgba);
270 rgba[3]=(double)i/(double)iMax;
271 colorLookupTable->SetTableValue(500-i,rgba);
278 _colorLookupTable->GetTableValue(500+100+i, rgba);
279 rgba[3]=(double)i/(double)iMax;
280 _colorLookupTable->SetTableValue(500+100+i,rgba);
281 _colorLookupTable->GetTableValue(500-100-i, rgba);
282 rgba[3]=(double)i/(double)iMax;
283 _colorLookupTable->SetTableValue(500-100-i,rgba);
290 _colorLookupTable->GetTableValue(500+i, rgba);
292 _colorLookupTable->SetTableValue(500+i,rgba);
293 _colorLookupTable->GetTableValue(500-i, rgba);
295 _colorLookupTable->SetTableValue(500-i,rgba);
298 colorLookupTable->Modified();
299 _scalarstocolors = colorLookupTable;
302 //EED 2018-06-8 ***********************ARDS Projet***********************************************
303 if (bbGetInputType()==1)
305 vtkLookupTable *colorLookupTable = vtkLookupTable::New();
306 if (bbGetInputRange().size()==2)
308 colorLookupTable->SetRange( bbGetInputRange()[0],bbGetInputRange()[1]);
309 // colorLookupTable->SetTableRange( bbGetInputRange()[0],bbGetInputRange()[1]);
311 colorLookupTable->SetRange(0,255);
313 colorLookupTable->SetValueRange(0.0, 1.0); // from black to white
314 colorLookupTable->SetSaturationRange(0.0, 0.0); // no color saturation
315 colorLookupTable->SetRampToLinear();
316 colorLookupTable->Build();
318 colorLookupTable->GetTableValue(0,rgba);
320 colorLookupTable->SetTableValue(0,rgba);
321 _scalarstocolors = colorLookupTable;
325 if (bbGetInputType()==2) // Direction Color Vector
327 vtkLookupTableDirectionVector2 *_LutEED = vtkLookupTableDirectionVector2::New();
328 _LutEED->SetVectorModeToRGBColors();
329 _LutEED->SetTypeTable(0);
330 _scalarstocolors = _LutEED;
333 if (bbGetInputType()==3) // Componets image rgb [0 255]
335 vtkLookupTableDirectionVector2 *_LutEED = vtkLookupTableDirectionVector2::New();
336 _LutEED->SetVectorModeToRGBColors();
337 _LutEED->SetTypeTable(1); // for components image
338 _scalarstocolors = _LutEED;
344 std::vector<double>colorRGB;
345 _scalarstocolors->GetColor( bbGetInputScalarValue() , rgb );
346 colorRGB.push_back( rgb[0] );
347 colorRGB.push_back( rgb[1] );
348 colorRGB.push_back( rgb[2] );
349 bbSetOutputColor( colorRGB );
350 bbSetOutputLookupTable( _scalarstocolors );
352 printf("EED ScalarsToColors::Process End\n");
357 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
359 void ScalarsToColors::bbUserSetDefaultValues()
362 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
363 // Here we initialize the input 'In' to 0
365 std::vector<double>range;
366 range.push_back( 0 );
367 range.push_back( 1 );
368 bbSetInputRange(range);
369 bbSetInputScalarValue(0);
371 _scalarstocolors = NULL;
374 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
376 void ScalarsToColors::bbUserInitializeProcessing()
379 // THE INITIALIZATION METHOD BODY :
381 // but this is where you should allocate the internal/output pointers
387 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
389 void ScalarsToColors::bbUserFinalizeProcessing()
392 // THE FINALIZATION METHOD BODY :
394 // but this is where you should desallocate the internal/output pointers
399 // EO namespace bbcreaVtk