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 # ------------------------------------------------------------------------ */
29 // 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)
31 #include "bbvtkMagnitud.h"
32 #include "bbvtkPackage.h"
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Magnitud)
37 BBTK_BLACK_BOX_IMPLEMENTATION(Magnitud,bbtk::AtomicBlackBox);
39 // 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)
41 void Magnitud::Process()
44 // THE MAIN PROCESSING METHOD BODY
45 // Here we simply set the input 'In' value to the output 'Out'
46 // And print out the output value
47 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
48 // void bbSet{Input|Output}NAME(const TYPE&)
49 // const TYPE& bbGet{Input|Output}NAME() const
51 // * NAME is the name of the input/output
52 // (the one provided in the attribute 'name' of the tag 'input')
53 // * TYPE is the C++ type of the input/output
54 // (the one provided in the attribute 'type' of the tag 'input')
57 if (bbGetInputIn()!=NULL) {
58 vGreenToRedLut->SetHueRange(0.6667,0.0);
59 vGreenToRedLut->Build();
62 //EED 2017-01-01 Migration VTK7
63 #if (VTK_MAJOR_VERSION <= 5)
64 vVecMagnitude->SetInput(bbGetInputIn());
66 #if (VTK_MAJOR_VERSION >= 6)
67 vVecMagnitude->SetInputData(bbGetInputIn());
70 vVecMagnitude->NormalizeOff();
71 vVecMagnitude->Update();
72 vVecMagnitude->GetOutput()->GetScalarRange( range1 );
73 vVecMagnitude->Update();
76 //EED 2017-01-01 Migration VTK7
77 #if (VTK_MAJOR_VERSION <= 5)
78 vMaskPoint->SetInput(bbGetInputIn());
80 #if (VTK_MAJOR_VERSION >= 6)
81 vMaskPoint->SetInputData(bbGetInputIn());
84 vMaskPoint->SetOnRatio(100);
86 vMaskPoint->RandomModeOn();
88 //EED 2017-01-01 Migration VTK7
89 #if (VTK_MAJOR_VERSION <= 5)
90 vGlyph->SetInput(vMaskPoint->GetOutput());
91 vGlyph->SetSource(cone->GetOutput());
93 #if (VTK_MAJOR_VERSION >= 6)
94 vGlyph->SetInputData(vMaskPoint->GetOutput());
95 vGlyph->SetSourceData(cone->GetOutput());
98 vGlyph->SetScaleModeToScaleByVector();
99 vGlyph->SetColorModeToColorByVector();
100 vGlyph->SetScaleFactor(0.20);
102 //EED 2017-01-01 Migration VTK7
103 #if (VTK_MAJOR_VERSION <= 5)
104 vGlyphMapper->SetInput( vGlyph->GetOutput() );
106 #if (VTK_MAJOR_VERSION >= 6)
107 vGlyphMapper->SetInputData( vGlyph->GetOutput() );
110 step = (range1[1]-range1[0])/10;
113 dRangeColorForMultipleContourVelocity[0]=0;
114 dRangeColorForMultipleContourVelocity[1]=1;
115 dRangeColorForGlyphVelocity[0]=0;
116 dRangeColorForGlyphVelocity[1]=1;
117 //EED 2017-01-01 Migration VTK7
118 #if (VTK_MAJOR_VERSION <= 5)
119 vMultipleContourVelocity->SetInput((vtkDataSet *) vVecMagnitude->GetOutput());
121 #if (VTK_MAJOR_VERSION >= 6)
122 vMultipleContourVelocity->SetInputData((vtkDataSet *) vVecMagnitude->GetOutput());
127 step = (range1[1]-range1[0])/10;
129 for( h=range1[0]; h<range1[1]; h+=step )
131 vMultipleContourVelocity->SetValue(index, h);
135 //EED 2017-01-01 Migration VTK7
136 #if (VTK_MAJOR_VERSION <= 5)
137 vMultipleContourMapper->SetInput( vMultipleContourVelocity->GetOutput() );
139 #if (VTK_MAJOR_VERSION >= 6)
140 vMultipleContourMapper->SetInputData( vMultipleContourVelocity->GetOutput() );
143 vMultipleContourMapper->SetScalarRange( range1 );
144 vMultipleContourMapper->SetLookupTable( vGreenToRedLut );
145 vMultipleContourMapper->Update();
146 vMultipleContourActor->SetMapper( vMultipleContourMapper );
147 vMultipleContourActor->GetProperty()->SetOpacity(0.4);
150 vGlyphMapper->SetLookupTable(vGreenToRedLut);
151 vGlyphMapper->SetScalarRange(range1);
152 vGlyphMapper->ImmediateModeRenderingOn();
155 //EED 2017-01-01 Migration VTK7
156 #if (VTK_MAJOR_VERSION <= 5)
157 vOutlineGrid->SetInput( bbGetInputIn() );
158 vOutlineMapper->SetInput(vOutlineGrid->GetOutput());
160 #if (VTK_MAJOR_VERSION >= 6)
161 vOutlineGrid->SetInputData( bbGetInputIn() );
162 vOutlineMapper->SetInputData(vOutlineGrid->GetOutput());
167 vOutlineActor->SetMapper(vOutlineMapper);
170 vGlyphActor->SetMapper( vGlyphMapper );
171 vGlyphActor->GetProperty()->SetOpacity(0);
173 //The Velocity Bar - Indicator (It's Actor is a vtkProper)
174 vScalarBarActor->SetLookupTable (vMultipleContourMapper->GetLookupTable());
175 vScalarBarActor->SetTitle ("Velocity");
176 vScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
177 vScalarBarActor->GetPositionCoordinate()->SetValue( 0.85, 0.25);
178 vScalarBarActor->SetOrientationToVertical();
179 vScalarBarActor->SetWidth (0.1);
180 vScalarBarActor->SetHeight (0.6);
181 vScalarBarActor->GetProperty()->SetOpacity(1); // 1 to Show - 0 to Hide
183 ///////////////////////////////////////////////////////////////////////////////////////////////////
184 //Start: Change values by the user
185 ///////////////////////////////////////////////////////////////////////////////////////////////////
187 vMaskPoint->SetOnRatio( bbGetInputMRatio());
188 vMaskPoint->Update();
191 vGlyphActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
192 vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()-0.1);
194 vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()+0.1);
196 if( (bbGetInputScale()/100)<0 )
198 if( (bbGetInputScale()/100)>1 )
201 //vGlyph->SetScaleFactor(dScale);
202 vGlyph->SetScaleFactor( bbGetInputScale()/100 );
205 //Set Glyph and Contour Colour Range
206 vVecMagnitude->GetOutput()->GetScalarRange( range1 );
207 dRangeColorForGlyphVelocity[0] = bbGetInputValInf()/100;
208 dRangeColorForGlyphVelocity[1] = bbGetInputValSup()/100;
209 dRangeColorForMultipleContourVelocity[0] = bbGetInputValInf()/100;
210 dRangeColorForMultipleContourVelocity[1] = bbGetInputValSup()/100;
211 double dTailleInterval=range1[1]-range1[0];
213 range1[1]=range1[0]+dTailleInterval*(bbGetInputValSup()/100);
214 range1[0]=range1[0]+dTailleInterval*(bbGetInputValInf()/100);
216 vGlyphMapper->SetScalarRange( range1 );
217 vMultipleContourMapper->SetScalarRange( range1 );
219 if( bbGetInputOpactity()/100<0 )
220 bbSetInputOpactity(0);
221 if( bbGetInputOpactity()/100>1 )
222 bbSetInputOpactity(1);
224 //Set Contour Opacity
225 vMultipleContourActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
226 vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()+1);
227 vMultipleContourVelocity->Update();
228 vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()-1);
229 vMultipleContourVelocity->Update();
231 //Set The Number of Contours
232 if( bbGetInputContour()<1)
233 bbSetInputContour(1);
235 step=(range1[1]-range1[0])/bbGetInputContour();
237 for( h=range1[0]; h<range1[1]; h+=step)
239 vMultipleContourVelocity->SetValue(index, h);
242 ///////////////////////////////////////////////////////////////////////////////////////////////////
243 //End: Change values by the user
244 ///////////////////////////////////////////////////////////////////////////////////////////////////
246 //EED 2017-01-01 Migration VTK7
247 #if (VTK_MAJOR_VERSION <= 5)
248 vPlaneWidget->SetInput(bbGetInputIn());
250 #if (VTK_MAJOR_VERSION >= 6)
251 vPlaneWidget->SetInputData(bbGetInputIn());
253 vPlaneWidget->NormalToXAxisOn();
254 vPlaneWidget->NormalToZAxisOn();
255 vPlaneWidget->SetResolution(1);
256 vPlaneWidget->SetRepresentationToOutline();
257 //vPlaneWidget->SetInteractor(vIren);
258 vPlaneWidget->SetPlaceFactor(1); //défini zoom initial
259 vPlaneWidget->PlaceWidget();
262 vPlaneWidget->GetOrigin(p0);
263 vPlaneWidget->GetCenter(c); //These is fromvtkImageMathematics Execute Method
264 vPlaneWidget->GetNormal(n);
265 vPlaneWidget->GetPoint1(p1);
266 vPlaneWidget->GetPoint2(p2);
268 c[0] = c[0]+ bbGetInputMoveX();
269 c[1] = c[1]+ bbGetInputMoveY();
270 c[2] = c[2]+ bbGetInputMoveZ();
272 vPlanSource->SetResolution( sizeIma-1, sizeIma-1);
273 vPlanSource->SetOrigin( p0 );
274 vPlanSource->SetPoint1( p1 );
275 vPlanSource->SetPoint2( p2 );
276 vPlanSource->Update( );
277 vPlanSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
278 vPlanSource->Update( );
279 vPlanSource->SetCenter( c );
280 vPlanSource->Update( );
282 vDiskSourceEED->SetInnerRadius (0);
283 vDiskSourceEED->SetOuterRadius (10);
284 vDiskSourceEED->SetRadialResolution (20);
285 vDiskSourceEED->SetCircumferentialResolution (20);
288 //EED 2017-01-01 Migration VTK7
289 #if (VTK_MAJOR_VERSION <= 5)
290 vPointWidget->SetInput( bbGetInputIn() );
292 #if (VTK_MAJOR_VERSION >= 6)
293 vPointWidget->SetInputData( bbGetInputIn() );
296 vPointWidget->AllOff();
297 vPointWidget->PlaceWidget();
298 //vPointWidget->SetInteractor(vIren);
300 //vPointWidget->GetPolyData(point);
301 vPointWidget->GetPolyData(point);
302 source->SetNumberOfPoints(500);
304 tempc = bbGetInputPlaneCenterSL();
305 slCenter[0] = tempc[0];
306 slCenter[1] = tempc[1];
307 slCenter[2] = tempc[2];
308 source->SetCenter( slCenter );
310 source->SetCenter( c );
311 source->SetRadius(5.0);
313 //EED 2017-01-01 Migration VTK7
314 #if (VTK_MAJOR_VERSION <= 5)
315 streamer->SetInput( bbGetInputIn() );
316 streamer->SetSource(source->GetOutput());
318 #if (VTK_MAJOR_VERSION >= 6)
319 streamer->SetInputData( bbGetInputIn() );
320 streamer->SetSourceData(source->GetOutput());
323 streamer->SetIntegratorTypeToRungeKutta45();
324 streamer->SetMaximumPropagation(500000);
325 //EED streamer->SetMaximumPropagationUnitToTimeUnit ();
326 streamer->SetInitialIntegrationStep (0.001);
327 //EED streamer->SetInitialIntegrationStepUnitToCellLengthUnit();
328 streamer->SetIntegrationDirectionToBoth();
329 //EED streamer->ComputeVorticityOn ();
332 //EED 2017-01-01 Migration VTK7
333 #if (VTK_MAJOR_VERSION <= 5)
334 rf->SetInput(streamer->GetOutput());
336 #if (VTK_MAJOR_VERSION >= 6)
337 rf->SetInputData(streamer->GetOutput());
341 rf->SetNumberOfSides(12);
342 rf->SetVaryRadiusToVaryRadiusOff();
344 streamer->GetOutput()->GetScalarRange( range );
346 //EED 2017-01-01 Migration VTK7
347 #if (VTK_MAJOR_VERSION <= 5)
348 streamMapper2->SetInput(rf->GetOutput());
350 #if (VTK_MAJOR_VERSION >= 6)
351 streamMapper2->SetInputData(rf->GetOutput());
354 streamMapper2->SetLookupTable(vGreenToRedLut);
355 //vStreamlineActor2->SetMapper( streamMapper2 );
357 //////////////////////////////////////////////////////////////////////////////////////
358 //Start: Part of the Execute Method
359 //////////////////////////////////////////////////////////////////////////////////////
363 alfa = atan2(ny,nx) * 180.0 / 3.1416;
364 beta = atan2( nz, sqrt( nx*nx + ny*ny ) ) * 180.0 / 3.1416;
365 transformEED->Identity();
366 transformEED->Translate(c);
367 transformEED->RotateWXYZ(alfa,0,0,1);
368 transformEED->RotateWXYZ(-beta,0,1,0);
369 transformEED->RotateWXYZ(90,0,1,0);
370 transformEED->Update();
371 //////////////////////////////////////////////////////////////////////////////////////
372 //End: Part of the Execute Method
373 //////////////////////////////////////////////////////////////////////////////////////
375 vtransformpolydatafilter->SetTransform( transformEED );
378 //EED 2017-01-01 Migration VTK7
379 #if (VTK_MAJOR_VERSION <= 5)
380 vtransformpolydatafilter->SetInput( vDiskSourceEED->GetOutput() );
381 vProbeslices->SetInput( ( vtkDataSet* )vtransformpolydatafilter->GetOutput());
382 vProbeslices->SetSource( bbGetInputIn() );
383 vGlyphFlowPlane->SetInput(vProbeslices->GetOutput());
384 vGlyphFlowPlane->SetSource(vArrowSource->GetOutput());
386 #if (VTK_MAJOR_VERSION >= 6)
387 vtransformpolydatafilter->SetInputData( vDiskSourceEED->GetOutput() );
388 vProbeslices->SetInputData( ( vtkDataSet* )vtransformpolydatafilter->GetOutput());
389 vProbeslices->SetSourceData( bbGetInputIn() );
390 vGlyphFlowPlane->SetInputData(vProbeslices->GetOutput());
391 vGlyphFlowPlane->SetSourceData(vArrowSource->GetOutput());
394 vtransformpolydatafilter->Update();
395 vProbeslices->Update( );
398 vGlyphFlowPlane->SetScaleModeToScaleByVector();
399 vGlyphFlowPlane->SetColorModeToColorByVector();
400 vGlyphFlowPlane->SetScaleFactor(0.2);
401 vGlyphFlowPlane->Update();
404 //EED 2017-01-01 Migration VTK7
405 #if (VTK_MAJOR_VERSION <= 5)
406 vProbeslicesFlowWidget->SetInput( ( vtkDataSet* )vPlanSource->GetOutput());
407 vProbeslicesFlowWidget->SetSource( vVecMagnitude->GetOutput() );
409 #if (VTK_MAJOR_VERSION >= 6)
410 vProbeslicesFlowWidget->SetInputData( ( vtkDataSet* )vPlanSource->GetOutput());
411 vProbeslicesFlowWidget->SetSourceData( vVecMagnitude->GetOutput() );
414 vProbeslicesFlowWidget->Update( );
416 vVecMagnitude->GetOutput()->GetScalarRange( range );
419 //EED 2017-01-01 Migration VTK7
420 #if (VTK_MAJOR_VERSION <= 5)
421 vAppendDataForFlowWidgetVisualisation->AddInput(vGlyphFlowPlane->GetOutput());
422 vAppendDataForFlowWidgetVisualisation->AddInput(vProbeslicesFlowWidget->GetPolyDataOutput());
423 vSliceMapper->SetInput( vAppendDataForFlowWidgetVisualisation->GetOutput());
425 #if (VTK_MAJOR_VERSION >= 6)
426 vAppendDataForFlowWidgetVisualisation->AddInputData(vGlyphFlowPlane->GetOutput());
427 vAppendDataForFlowWidgetVisualisation->AddInputData(vProbeslicesFlowWidget->GetPolyDataOutput());
428 vSliceMapper->SetInputData( vAppendDataForFlowWidgetVisualisation->GetOutput());
431 vSliceMapper->SetScalarRange( range );
432 vSliceMapper->SetLookupTable( vGreenToRedLut );
434 vSliceActor->SetMapper( vSliceMapper );
436 if(bbGetInputShowPlane() == 1)
438 else if(bbGetInputShowPlane() == 0)
441 vSliceActor->GetProperty()->SetOpacity( bbGetInputShowPlane() );
443 exporter->SetInputConnection( vMultipleContourMapper->GetOutputPort() );
444 exporter->ImageLowerLeftOn();
446 bbSetOutputOut1( vSliceActor );
447 bbSetOutputOut2( vGlyphActor );
448 bbSetOutputOut3( vOutlineActor );
449 bbSetOutputOut4( vMultipleContourActor );
450 //bbSetOutputOut5( vScalarBarActor );
451 if(bbGetInputShowStream() == 1)
452 vStreamlineActor2->SetMapper( streamMapper2 );
454 vStreamlineActor2->SetMapper( NULL );
456 bbSetOutputOut5( vStreamlineActor2 );
457 //bbSetOutputOut5( vStreamlineActor2 );
458 //bbSetOutputOutExport( exporter );
459 //temp->GetData( (vtkInformation*) vMultipleContourVelocity->GetOutput() );
460 //temp->GetData( vMultipleContourMapper->GetOutput() );
461 //bbSetOutputOutTest( temp );
471 // 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)
473 void Magnitud::bbUserSetDefaultValues()
476 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
477 // Here we initialize the input 'In' to 0
485 bbSetInputMRatio(100);
486 bbSetInputOpactity(0.5);
487 bbSetInputScale(0.2);
488 bbSetInputContour(10);
489 bbSetInputShowPlane(1);
490 bbSetInputShowStream(0);
491 //bbSetInputPlaneCenterSL();
495 // 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)
497 void Magnitud::bbUserInitializeProcessing()
500 // THE INITIALIZATION METHOD BODY :
502 // but this is where you should allocate the internal/output pointers
506 cone = vtkArrowSource::New();
507 exporter = vtkImageExport::New();
508 point = vtkPolyData::New();
509 rf = vtkTubeFilter::New();
510 source = vtkPointSource::New();
511 streamer = vtkStreamTracer::New();
512 streamMapper2 = vtkPolyDataMapper::New();
514 transformEED = vtkTransform::New();
515 vAppendDataForFlowWidgetVisualisation = vtkAppendPolyData::New();
516 vArrowSource = vtkArrowSource::New();
517 vDiskSourceEED = vtkDiskSource::New();
518 vGlyph = vtkGlyph3D::New();
519 vGlyphActor = vtkActor::New();
520 vGlyphFlowPlane = vtkGlyph3D::New();
521 vGlyphMapper = vtkPolyDataMapper::New();
522 vGreenToRedLut = vtkLookupTable::New();
523 vIren = vtkRenderWindowInteractor::New();
524 vMaskPoint = vtkMaskPoints::New();
525 vMultipleContourActor = vtkActor::New();
526 vMultipleContourMapper = vtkPolyDataMapper::New();
527 vMultipleContourVelocity = vtkContourFilter::New();
528 vOutlineActor = vtkActor::New();
529 vOutlineGrid = vtkOutlineFilter::New();
530 vOutlineMapper = vtkPolyDataMapper::New();
531 vPlanSource = vtkPlaneSource::New();
532 vPlaneWidget = vtkPlaneWidget::New();
533 vPointWidget = vtkPointWidget::New();
534 vProbeslices = vtkProbeFilter::New();
535 vProbeslicesFlowWidget = vtkProbeFilter::New();
536 vScalarBarActor = vtkScalarBarActor::New();
537 vSliceMapper = vtkPolyDataMapper::New();
538 vSliceActor = vtkActor::New();
539 vStreamlineActor2 = vtkActor::New();
540 vtransformpolydatafilter = vtkTransformPolyDataFilter::New();
541 vVecMagnitude = vtkVectorNorm::New();
543 temp = vtkImageData::New();
545 sizeIma = SIZEPLANWIDGET;
549 // 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)
551 void Magnitud::bbUserFinalizeProcessing()
554 // THE FINALIZATION METHOD BODY :
556 // but this is where you should desallocate the internal/output pointers
559 /// \TODO delete everything no longer needed!
563 // EO namespace bbvtk