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 printf("EED Magnitud::Process Start\n");
46 // THE MAIN PROCESSING METHOD BODY
47 // Here we simply set the input 'In' value to the output 'Out'
48 // And print out the output value
49 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
50 // void bbSet{Input|Output}NAME(const TYPE&)
51 // const TYPE& bbGet{Input|Output}NAME() const
53 // * NAME is the name of the input/output
54 // (the one provided in the attribute 'name' of the tag 'input')
55 // * TYPE is the C++ type of the input/output
56 // (the one provided in the attribute 'type' of the tag 'input')
59 if (bbGetInputIn()!=NULL)
61 vGreenToRedLut->SetHueRange(0.6667,0.0);
62 vGreenToRedLut->Build();
65 //EED 2017-01-01 Migration VTK7
66 #if (VTK_MAJOR_VERSION <= 5)
67 vVecMagnitude->SetInput(bbGetInputIn());
69 #if (VTK_MAJOR_VERSION >= 6)
70 vVecMagnitude->SetInputData(bbGetInputIn());
73 vVecMagnitude->NormalizeOff();
74 vVecMagnitude->Update();
75 vVecMagnitude->GetOutput()->GetScalarRange( range1 );
76 vVecMagnitude->Update();
79 //EED 2017-01-01 Migration VTK7
80 #if (VTK_MAJOR_VERSION <= 5)
81 vMaskPoint->SetInput(bbGetInputIn());
83 #if (VTK_MAJOR_VERSION >= 6)
84 vMaskPoint->SetInputData(bbGetInputIn());
87 vMaskPoint->SetOnRatio(100);
89 vMaskPoint->RandomModeOn();
91 vGlyph->SetScaleModeToScaleByVector();
92 vGlyph->SetColorModeToColorByVector();
93 vGlyph->SetScaleFactor(0.20);
95 //EED 2017-01-01 Migration VTK7
96 #if (VTK_MAJOR_VERSION <= 5)
97 vGlyph->SetInput(vMaskPoint->GetOutput());
98 vGlyph->SetSource(cone->GetOutput());
100 #if (VTK_MAJOR_VERSION >= 6)
101 vGlyph->SetInputData(vMaskPoint->GetOutput());
103 vGlyph->SetSourceData(cone->GetOutput());
107 //EED 2017-01-01 Migration VTK7
108 #if (VTK_MAJOR_VERSION <= 5)
109 vGlyphMapper->SetInput( vGlyph->GetOutput() );
111 #if (VTK_MAJOR_VERSION >= 6)
112 vGlyphMapper->SetInputData( vGlyph->GetOutput() );
115 step = (range1[1]-range1[0])/10;
118 dRangeColorForMultipleContourVelocity[0] = 0;
119 dRangeColorForMultipleContourVelocity[1] = 1;
120 dRangeColorForGlyphVelocity[0] = 0;
121 dRangeColorForGlyphVelocity[1] = 1;
122 //EED 2017-01-01 Migration VTK7
123 #if (VTK_MAJOR_VERSION <= 5)
124 vMultipleContourVelocity->SetInput((vtkDataSet *) vVecMagnitude->GetOutput());
126 #if (VTK_MAJOR_VERSION >= 6)
127 vMultipleContourVelocity->SetInputData((vtkDataSet *) vVecMagnitude->GetOutput());
132 step = (range1[1]-range1[0])/10;
134 for( h=range1[0]; h<range1[1]; h+=step )
136 vMultipleContourVelocity->SetValue(index, h);
140 //EED 2017-01-01 Migration VTK7
141 #if (VTK_MAJOR_VERSION <= 5)
142 vMultipleContourMapper->SetInput( vMultipleContourVelocity->GetOutput() );
144 #if (VTK_MAJOR_VERSION >= 6)
145 vMultipleContourMapper->SetInputData( vMultipleContourVelocity->GetOutput() );
148 vMultipleContourMapper->SetScalarRange( range1 );
149 vMultipleContourMapper->SetLookupTable( vGreenToRedLut );
150 vMultipleContourMapper->Update();
151 vMultipleContourActor->SetMapper( vMultipleContourMapper );
152 vMultipleContourActor->GetProperty()->SetOpacity(0.4);
155 vGlyphMapper->SetLookupTable(vGreenToRedLut);
156 vGlyphMapper->SetScalarRange(range1);
157 //EED 2020-04-21 vtk8 deprecated
158 // vGlyphMapper->ImmediateModeRenderingOn();
161 //EED 2017-01-01 Migration VTK7
162 #if (VTK_MAJOR_VERSION <= 5)
163 vOutlineGrid->SetInput( bbGetInputIn() );
164 vOutlineMapper->SetInput(vOutlineGrid->GetOutput());
166 #if (VTK_MAJOR_VERSION >= 6)
167 vOutlineGrid->SetInputData( bbGetInputIn() );
168 vOutlineGrid->Update();
169 vOutlineMapper->SetInputData( vOutlineGrid->GetOutput() );
174 vOutlineActor->SetMapper(vOutlineMapper);
177 vGlyphActor->SetMapper( vGlyphMapper );
178 vGlyphActor->GetProperty()->SetOpacity(0);
180 //The Velocity Bar - Indicator (It's Actor is a vtkProper)
181 vScalarBarActor->SetLookupTable (vMultipleContourMapper->GetLookupTable());
182 vScalarBarActor->SetTitle ("Velocity");
183 vScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
184 vScalarBarActor->GetPositionCoordinate()->SetValue( 0.85, 0.25);
185 vScalarBarActor->SetOrientationToVertical();
186 vScalarBarActor->SetWidth (0.1);
187 vScalarBarActor->SetHeight (0.6);
188 vScalarBarActor->GetProperty()->SetOpacity(1); // 1 to Show - 0 to Hide
190 ///////////////////////////////////////////////////////////////////////////////////////////////////
191 //Start: Change values by the user
192 ///////////////////////////////////////////////////////////////////////////////////////////////////
194 vMaskPoint->SetOnRatio( bbGetInputMRatio());
195 vMaskPoint->Update();
198 vGlyphActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
199 vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()-0.1);
201 vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()+0.1);
203 if( (bbGetInputScale()/100)<0 )
207 if( (bbGetInputScale()/100)>1 )
212 //vGlyph->SetScaleFactor(dScale);
213 vGlyph->SetScaleFactor( bbGetInputScale()/100 );
216 //Set Glyph and Contour Colour Range
217 vVecMagnitude->GetOutput()->GetScalarRange( range1 );
218 dRangeColorForGlyphVelocity[0] = bbGetInputValInf()/100;
219 dRangeColorForGlyphVelocity[1] = bbGetInputValSup()/100;
220 dRangeColorForMultipleContourVelocity[0] = bbGetInputValInf()/100;
221 dRangeColorForMultipleContourVelocity[1] = bbGetInputValSup()/100;
222 double dTailleInterval=range1[1]-range1[0];
224 range1[1]=range1[0]+dTailleInterval*(bbGetInputValSup()/100);
225 range1[0]=range1[0]+dTailleInterval*(bbGetInputValInf()/100);
227 vGlyphMapper->SetScalarRange( range1 );
228 vMultipleContourMapper->SetScalarRange( range1 );
230 if( bbGetInputOpactity()/100<0 )
232 bbSetInputOpactity(0);
235 if( bbGetInputOpactity()/100>1 )
237 bbSetInputOpactity(1);
240 //Set Contour Opacity
241 vMultipleContourActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
242 vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()+1);
243 vMultipleContourVelocity->Update();
244 vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()-1);
245 vMultipleContourVelocity->Update();
247 //Set The Number of Contours
248 if( bbGetInputContour()<1)
250 bbSetInputContour(1);
253 step=(range1[1]-range1[0])/bbGetInputContour();
255 for( h=range1[0]; h<range1[1]; h+=step)
257 vMultipleContourVelocity->SetValue(index, h);
260 ///////////////////////////////////////////////////////////////////////////////////////////////////
261 //End: Change values by the user
262 ///////////////////////////////////////////////////////////////////////////////////////////////////
264 //EED 2017-01-01 Migration VTK7
265 #if (VTK_MAJOR_VERSION <= 5)
266 vPlaneWidget->SetInput(bbGetInputIn());
268 #if (VTK_MAJOR_VERSION >= 6)
269 vPlaneWidget->SetInputData(bbGetInputIn());
271 vPlaneWidget->NormalToXAxisOn();
272 vPlaneWidget->NormalToZAxisOn();
273 vPlaneWidget->SetResolution(1);
274 vPlaneWidget->SetRepresentationToOutline();
275 //vPlaneWidget->SetInteractor(vIren);
276 vPlaneWidget->SetPlaceFactor(1); //déæini zoom initial
277 vPlaneWidget->PlaceWidget();
280 vPlaneWidget->GetOrigin(p0);
281 vPlaneWidget->GetCenter(c); //These is fromvtkImageMathematics Execute Method
282 vPlaneWidget->GetNormal(n);
283 vPlaneWidget->GetPoint1(p1);
284 vPlaneWidget->GetPoint2(p2);
286 c[0] = c[0]+ bbGetInputMoveX();
287 c[1] = c[1]+ bbGetInputMoveY();
288 c[2] = c[2]+ bbGetInputMoveZ();
290 vPlanSource->SetResolution( sizeIma-1, sizeIma-1);
291 vPlanSource->SetOrigin( p0 );
292 vPlanSource->SetPoint1( p1 );
293 vPlanSource->SetPoint2( p2 );
294 vPlanSource->Update( );
295 vPlanSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
296 vPlanSource->Update( );
297 vPlanSource->SetCenter( c );
298 vPlanSource->Update( );
300 vDiskSourceEED->SetInnerRadius (0);
301 vDiskSourceEED->SetOuterRadius (10);
302 vDiskSourceEED->SetRadialResolution (20);
303 vDiskSourceEED->SetCircumferentialResolution (20);
306 //EED 2017-01-01 Migration VTK7
307 #if (VTK_MAJOR_VERSION <= 5)
308 vPointWidget->SetInput( bbGetInputIn() );
310 #if (VTK_MAJOR_VERSION >= 6)
311 vPointWidget->SetInputData( bbGetInputIn() );
314 vPointWidget->AllOff();
315 vPointWidget->PlaceWidget();
316 //vPointWidget->SetInteractor(vIren);
318 //vPointWidget->GetPolyData(point);
319 vPointWidget->GetPolyData(point);
320 source->SetNumberOfPoints(500);
322 tempc = bbGetInputPlaneCenterSL();
323 slCenter[0] = tempc[0];
324 slCenter[1] = tempc[1];
325 slCenter[2] = tempc[2];
326 source->SetCenter( slCenter );
328 source->SetCenter( c );
329 source->SetRadius(5.0);
331 //EED 2017-01-01 Migration VTK7
332 #if (VTK_MAJOR_VERSION <= 5)
333 streamer->SetInput( bbGetInputIn() );
334 streamer->SetSource(source->GetOutput());
336 #if (VTK_MAJOR_VERSION >= 6)
337 streamer->SetInputData( bbGetInputIn() );
338 streamer->SetSourceData( source->GetOutput() );
341 streamer->SetIntegratorTypeToRungeKutta45();
342 streamer->SetMaximumPropagation(500000);
343 //EED streamer->SetMaximumPropagationUnitToTimeUnit ();
344 streamer->SetInitialIntegrationStep (0.001);
345 //EED streamer->SetInitialIntegrationStepUnitToCellLengthUnit();
346 streamer->SetIntegrationDirectionToBoth();
347 //EED streamer->ComputeVorticityOn ();
350 //EED 2017-01-01 Migration VTK7
351 #if (VTK_MAJOR_VERSION <= 5)
352 rf->SetInput(streamer->GetOutput());
354 #if (VTK_MAJOR_VERSION >= 6)
355 rf->SetInputData(streamer->GetOutput());
359 rf->SetNumberOfSides(12);
360 rf->SetVaryRadiusToVaryRadiusOff();
362 streamer->GetOutput()->GetScalarRange( range );
364 //EED 2017-01-01 Migration VTK7
365 #if (VTK_MAJOR_VERSION <= 5)
366 streamMapper2->SetInput(rf->GetOutput());
368 #if (VTK_MAJOR_VERSION >= 6)
369 streamMapper2->SetInputData(rf->GetOutput());
372 streamMapper2->SetLookupTable(vGreenToRedLut);
373 //vStreamlineActor2->SetMapper( streamMapper2 );
375 //////////////////////////////////////////////////////////////////////////////////////
376 //Start: Part of the Execute Method
377 //////////////////////////////////////////////////////////////////////////////////////
381 alfa = atan2(ny,nx) * 180.0 / 3.1416;
382 beta = atan2( nz, sqrt( nx*nx + ny*ny ) ) * 180.0 / 3.1416;
383 transformEED->Identity();
384 transformEED->Translate(c);
385 transformEED->RotateWXYZ(alfa,0,0,1);
386 transformEED->RotateWXYZ(-beta,0,1,0);
387 transformEED->RotateWXYZ(90,0,1,0);
388 transformEED->Update();
389 //////////////////////////////////////////////////////////////////////////////////////
390 //End: Part of the Execute Method
391 //////////////////////////////////////////////////////////////////////////////////////
393 vtransformpolydatafilter->SetTransform( transformEED );
396 //EED 2017-01-01 Migration VTK7
397 #if (VTK_MAJOR_VERSION <= 5)
398 vtransformpolydatafilter->SetInput( vDiskSourceEED->GetOutput() );
399 vProbeslices->SetInput( ( vtkDataSet* )vtransformpolydatafilter->GetOutput());
400 vProbeslices->SetSource( bbGetInputIn() );
401 vGlyphFlowPlane->SetInput( vProbeslices->GetOutput() );
402 vGlyphFlowPlane->SetSource( vArrowSource->GetOutput() );
404 #if (VTK_MAJOR_VERSION >= 6)
405 vtransformpolydatafilter->SetInputData( vDiskSourceEED->GetOutput() );
406 vProbeslices->SetInputData( ( vtkDataSet* )vtransformpolydatafilter->GetOutput());
407 vProbeslices->SetSourceData( bbGetInputIn() );
408 vGlyphFlowPlane->SetInputData( vProbeslices->GetOutput() );
409 vArrowSource->Update();
410 vGlyphFlowPlane->SetSourceData( vArrowSource->GetOutput() );
413 vtransformpolydatafilter->Update();
414 vProbeslices->Update( );
417 vGlyphFlowPlane->SetScaleModeToScaleByVector();
418 vGlyphFlowPlane->SetColorModeToColorByVector();
419 vGlyphFlowPlane->SetScaleFactor(0.2);
420 vGlyphFlowPlane->Update();
423 //EED 2017-01-01 Migration VTK7
424 #if (VTK_MAJOR_VERSION <= 5)
425 vProbeslicesFlowWidget->SetInput( ( vtkDataSet* )vPlanSource->GetOutput());
426 vProbeslicesFlowWidget->SetSource( vVecMagnitude->GetOutput() );
428 #if (VTK_MAJOR_VERSION >= 6)
429 vProbeslicesFlowWidget->SetInputData( ( vtkDataSet* )vPlanSource->GetOutput());
430 vVecMagnitude->Update();
431 vProbeslicesFlowWidget->SetSourceData( vVecMagnitude->GetOutput() );
434 vProbeslicesFlowWidget->Update( );
436 vVecMagnitude->GetOutput()->GetScalarRange( range );
439 //EED 2017-01-01 Migration VTK7
440 #if (VTK_MAJOR_VERSION <= 5)
441 vAppendDataForFlowWidgetVisualisation->AddInput(vGlyphFlowPlane->GetOutput());
442 vAppendDataForFlowWidgetVisualisation->AddInput(vProbeslicesFlowWidget->GetPolyDataOutput());
443 vSliceMapper->SetInput( vAppendDataForFlowWidgetVisualisation->GetOutput());
445 #if (VTK_MAJOR_VERSION >= 6)
446 vGlyphFlowPlane->Update();
447 vProbeslicesFlowWidget->Update();
448 vAppendDataForFlowWidgetVisualisation->AddInputData( vGlyphFlowPlane->GetOutput() );
449 vAppendDataForFlowWidgetVisualisation->AddInputData( vProbeslicesFlowWidget->GetPolyDataOutput() );
450 vSliceMapper->SetInputData( vAppendDataForFlowWidgetVisualisation->GetOutput() );
453 vSliceMapper->SetScalarRange( range );
454 vSliceMapper->SetLookupTable( vGreenToRedLut );
456 vSliceActor->SetMapper( vSliceMapper );
458 if(bbGetInputShowPlane() == 1)
461 } else if(bbGetInputShowPlane() == 0) {
465 vSliceActor->GetProperty()->SetOpacity( bbGetInputShowPlane() );
467 exporter->SetInputConnection( vMultipleContourMapper->GetOutputPort() );
468 exporter->ImageLowerLeftOn();
470 bbSetOutputOut1( vSliceActor );
471 bbSetOutputOut2( vGlyphActor );
472 bbSetOutputOut3( vOutlineActor );
473 bbSetOutputOut4( vMultipleContourActor );
475 // bbSetOutputOut5( vScalarBarActor );
477 if(bbGetInputShowStream() == 1)
479 vStreamlineActor2->SetMapper( streamMapper2 );
481 vStreamlineActor2->SetMapper( NULL );
483 bbSetOutputOut5( vStreamlineActor2 );
484 //bbSetOutputOut5( vStreamlineActor2 );
485 //bbSetOutputOutExport( exporter );
486 //temp->GetData( (vtkInformation*) vMultipleContourVelocity->GetOutput() );
487 //temp->GetData( vMultipleContourMapper->GetOutput() );
488 //bbSetOutputOutTest( temp );
491 printf("EED Magnitud::Process End\n");
499 // 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)
501 void Magnitud::bbUserSetDefaultValues()
504 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
505 // Here we initialize the input 'In' to 0
513 bbSetInputMRatio(100);
514 bbSetInputOpactity(0.5);
515 bbSetInputScale(0.2);
516 bbSetInputContour(10);
517 bbSetInputShowPlane(1);
518 bbSetInputShowStream(0);
519 //bbSetInputPlaneCenterSL();
523 // 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)
525 void Magnitud::bbUserInitializeProcessing()
528 // THE INITIALIZATION METHOD BODY :
530 // but this is where you should allocate the internal/output pointers
534 cone = vtkArrowSource::New();
535 exporter = vtkImageExport::New();
536 point = vtkPolyData::New();
537 rf = vtkTubeFilter::New();
538 source = vtkPointSource::New();
539 streamer = vtkStreamTracer::New();
540 streamMapper2 = vtkPolyDataMapper::New();
542 transformEED = vtkTransform::New();
543 vAppendDataForFlowWidgetVisualisation = vtkAppendPolyData::New();
544 vArrowSource = vtkArrowSource::New();
545 vDiskSourceEED = vtkDiskSource::New();
546 vGlyph = vtkGlyph3D::New();
547 vGlyphActor = vtkActor::New();
548 vGlyphFlowPlane = vtkGlyph3D::New();
549 vGlyphMapper = vtkPolyDataMapper::New();
550 vGreenToRedLut = vtkLookupTable::New();
551 // vIren = vtkRenderWindowInteractor::New();
552 vMaskPoint = vtkMaskPoints::New();
553 vMultipleContourActor = vtkActor::New();
554 vMultipleContourMapper = vtkPolyDataMapper::New();
555 vMultipleContourVelocity = vtkContourFilter::New();
556 vOutlineActor = vtkActor::New();
557 vOutlineGrid = vtkOutlineFilter::New();
558 vOutlineMapper = vtkPolyDataMapper::New();
559 vPlanSource = vtkPlaneSource::New();
560 vPlaneWidget = vtkPlaneWidget::New();
561 vPointWidget = vtkPointWidget::New();
562 vProbeslices = vtkProbeFilter::New();
563 vProbeslicesFlowWidget = vtkProbeFilter::New();
564 vScalarBarActor = vtkScalarBarActor::New();
565 vSliceMapper = vtkPolyDataMapper::New();
566 vSliceActor = vtkActor::New();
567 vStreamlineActor2 = vtkActor::New();
568 vtransformpolydatafilter = vtkTransformPolyDataFilter::New();
569 vVecMagnitude = vtkVectorNorm::New();
571 temp = vtkImageData::New();
573 sizeIma = SIZEPLANWIDGET;
577 // 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)
579 void Magnitud::bbUserFinalizeProcessing()
582 // THE FINALIZATION METHOD BODY :
584 // but this is where you should desallocate the internal/output pointers
587 /// \TODO delete everything no longer needed!
591 // EO namespace bbvtk