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 vVecMagnitude->SetInput(bbGetInputIn());
63 vVecMagnitude->NormalizeOff();
64 vVecMagnitude->Update();
65 vVecMagnitude->GetOutput()->GetScalarRange( range1 );
66 vVecMagnitude->Update();
69 vMaskPoint->SetInput(bbGetInputIn());
70 vMaskPoint->SetOnRatio(100);
72 vMaskPoint->RandomModeOn();
74 vGlyph->SetInput(vMaskPoint->GetOutput());
75 vGlyph->SetSource(cone->GetOutput());
76 vGlyph->SetScaleModeToScaleByVector();
77 vGlyph->SetColorModeToColorByVector();
78 vGlyph->SetScaleFactor(0.20);
79 vGlyphMapper->SetInput( vGlyph->GetOutput() );
80 step = (range1[1]-range1[0])/10;
83 dRangeColorForMultipleContourVelocity[0]=0;
84 dRangeColorForMultipleContourVelocity[1]=1;
85 dRangeColorForGlyphVelocity[0]=0;
86 dRangeColorForGlyphVelocity[1]=1;
87 vMultipleContourVelocity->SetInput((vtkDataSet *) vVecMagnitude->GetOutput());
91 step = (range1[1]-range1[0])/10;
93 for( h=range1[0]; h<range1[1]; h+=step )
95 vMultipleContourVelocity->SetValue(index, h);
99 vMultipleContourMapper->SetInput( vMultipleContourVelocity->GetOutput() );
100 vMultipleContourMapper->SetScalarRange( range1 );
101 vMultipleContourMapper->SetLookupTable( vGreenToRedLut );
102 vMultipleContourMapper->Update();
103 vMultipleContourActor->SetMapper( vMultipleContourMapper );
104 vMultipleContourActor->GetProperty()->SetOpacity(0.4);
107 vGlyphMapper->SetLookupTable(vGreenToRedLut);
108 vGlyphMapper->SetScalarRange(range1);
109 vGlyphMapper->ImmediateModeRenderingOn();
112 vOutlineGrid->SetInput( bbGetInputIn() );
113 vOutlineMapper->SetInput(vOutlineGrid->GetOutput());
116 vOutlineActor->SetMapper(vOutlineMapper);
119 vGlyphActor->SetMapper( vGlyphMapper );
120 vGlyphActor->GetProperty()->SetOpacity(0);
122 //The Velocity Bar - Indicator (It's Actor is a vtkProper)
123 vScalarBarActor->SetLookupTable (vMultipleContourMapper->GetLookupTable());
124 vScalarBarActor->SetTitle ("Velocity");
125 vScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
126 vScalarBarActor->GetPositionCoordinate()->SetValue( 0.85, 0.25);
127 vScalarBarActor->SetOrientationToVertical();
128 vScalarBarActor->SetWidth (0.1);
129 vScalarBarActor->SetHeight (0.6);
130 vScalarBarActor->GetProperty()->SetOpacity(1); // 1 to Show - 0 to Hide
132 ///////////////////////////////////////////////////////////////////////////////////////////////////
133 //Start: Change values by the user
134 ///////////////////////////////////////////////////////////////////////////////////////////////////
136 vMaskPoint->SetOnRatio( bbGetInputMRatio());
137 vMaskPoint->Update();
140 vGlyphActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
141 vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()-0.1);
143 vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()+0.1);
145 if( (bbGetInputScale()/100)<0 )
147 if( (bbGetInputScale()/100)>1 )
150 //vGlyph->SetScaleFactor(dScale);
151 vGlyph->SetScaleFactor( bbGetInputScale()/100 );
154 //Set Glyph and Contour Colour Range
155 vVecMagnitude->GetOutput()->GetScalarRange( range1 );
156 dRangeColorForGlyphVelocity[0] = bbGetInputValInf()/100;
157 dRangeColorForGlyphVelocity[1] = bbGetInputValSup()/100;
158 dRangeColorForMultipleContourVelocity[0] = bbGetInputValInf()/100;
159 dRangeColorForMultipleContourVelocity[1] = bbGetInputValSup()/100;
160 double dTailleInterval=range1[1]-range1[0];
162 range1[1]=range1[0]+dTailleInterval*(bbGetInputValSup()/100);
163 range1[0]=range1[0]+dTailleInterval*(bbGetInputValInf()/100);
165 vGlyphMapper->SetScalarRange( range1 );
166 vMultipleContourMapper->SetScalarRange( range1 );
168 if( bbGetInputOpactity()/100<0 )
169 bbSetInputOpactity(0);
170 if( bbGetInputOpactity()/100>1 )
171 bbSetInputOpactity(1);
173 //Set Contour Opacity
174 vMultipleContourActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
175 vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()+1);
176 vMultipleContourVelocity->Update();
177 vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()-1);
178 vMultipleContourVelocity->Update();
180 //Set The Number of Contours
181 if( bbGetInputContour()<1)
182 bbSetInputContour(1);
184 step=(range1[1]-range1[0])/bbGetInputContour();
186 for( h=range1[0]; h<range1[1]; h+=step)
188 vMultipleContourVelocity->SetValue(index, h);
191 ///////////////////////////////////////////////////////////////////////////////////////////////////
192 //End: Change values by the user
193 ///////////////////////////////////////////////////////////////////////////////////////////////////
195 vPlaneWidget->SetInput(bbGetInputIn());
196 vPlaneWidget->NormalToXAxisOn();
197 vPlaneWidget->NormalToZAxisOn();
198 vPlaneWidget->SetResolution(1);
199 vPlaneWidget->SetRepresentationToOutline();
200 //vPlaneWidget->SetInteractor(vIren);
201 vPlaneWidget->SetPlaceFactor(1); //défini zoom initial
202 vPlaneWidget->PlaceWidget();
205 vPlaneWidget->GetOrigin(p0);
206 vPlaneWidget->GetCenter(c); //These is from Execute Method
207 vPlaneWidget->GetNormal(n);
208 vPlaneWidget->GetPoint1(p1);
209 vPlaneWidget->GetPoint2(p2);
211 c[0] = c[0]+ bbGetInputMoveX();
212 c[1] = c[1]+ bbGetInputMoveY();
213 c[2] = c[2]+ bbGetInputMoveZ();
215 vPlanSource->SetResolution( sizeIma-1, sizeIma-1);
216 vPlanSource->SetOrigin( p0 );
217 vPlanSource->SetPoint1( p1 );
218 vPlanSource->SetPoint2( p2 );
219 vPlanSource->Update( );
220 vPlanSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
221 vPlanSource->Update( );
222 vPlanSource->SetCenter( c );
223 vPlanSource->Update( );
225 vDiskSourceEED->SetInnerRadius (0);
226 vDiskSourceEED->SetOuterRadius (10);
227 vDiskSourceEED->SetRadialResolution (20);
228 vDiskSourceEED->SetCircumferentialResolution (20);
231 vPointWidget->SetInput( bbGetInputIn() );
232 vPointWidget->AllOff();
233 vPointWidget->PlaceWidget();
234 //vPointWidget->SetInteractor(vIren);
236 //vPointWidget->GetPolyData(point);
237 vPointWidget->GetPolyData(point);
238 source->SetNumberOfPoints(500);
240 tempc = bbGetInputPlaneCenterSL();
241 slCenter[0] = tempc[0];
242 slCenter[1] = tempc[1];
243 slCenter[2] = tempc[2];
244 source->SetCenter( slCenter );
246 source->SetCenter( c );
247 source->SetRadius(5.0);
249 streamer->SetInput( bbGetInputIn() );
250 streamer->SetSource(source->GetOutput());
251 streamer->SetIntegratorTypeToRungeKutta45();
252 streamer->SetMaximumPropagation(500000);
253 //EED streamer->SetMaximumPropagationUnitToTimeUnit ();
254 streamer->SetInitialIntegrationStep (0.001);
255 //EED streamer->SetInitialIntegrationStepUnitToCellLengthUnit();
256 streamer->SetIntegrationDirectionToBoth();
257 //EED streamer->ComputeVorticityOn ();
260 rf->SetInput(streamer->GetOutput());
262 rf->SetNumberOfSides(12);
263 rf->SetVaryRadiusToVaryRadiusOff();
265 streamer->GetOutput()->GetScalarRange( range );
266 streamMapper2->SetInput(rf->GetOutput());
267 streamMapper2->SetLookupTable(vGreenToRedLut);
268 //vStreamlineActor2->SetMapper( streamMapper2 );
270 //////////////////////////////////////////////////////////////////////////////////////
271 //Start: Part of the Execute Method
272 //////////////////////////////////////////////////////////////////////////////////////
276 alfa = atan2(ny,nx) * 180.0 / 3.1416;
277 beta = atan2( nz, sqrt( nx*nx + ny*ny ) ) * 180.0 / 3.1416;
278 transformEED->Identity();
279 transformEED->Translate(c);
280 transformEED->RotateWXYZ(alfa,0,0,1);
281 transformEED->RotateWXYZ(-beta,0,1,0);
282 transformEED->RotateWXYZ(90,0,1,0);
283 transformEED->Update();
284 //////////////////////////////////////////////////////////////////////////////////////
285 //End: Part of the Execute Method
286 //////////////////////////////////////////////////////////////////////////////////////
288 vtransformpolydatafilter->SetInput( vDiskSourceEED->GetOutput() );
289 vtransformpolydatafilter->SetTransform( transformEED );
290 vtransformpolydatafilter->Update();
292 vProbeslices->SetInput( ( vtkDataSet* )vtransformpolydatafilter->GetOutput());
293 vProbeslices->SetSource( bbGetInputIn() );
294 vProbeslices->Update( );
296 vGlyphFlowPlane->SetInput(vProbeslices->GetOutput());
297 vGlyphFlowPlane->SetSource(vArrowSource->GetOutput());
298 vGlyphFlowPlane->SetScaleModeToScaleByVector();
299 vGlyphFlowPlane->SetColorModeToColorByVector();
300 vGlyphFlowPlane->SetScaleFactor(0.2);
301 vGlyphFlowPlane->Update();
303 vProbeslicesFlowWidget->SetInput( ( vtkDataSet* )vPlanSource->GetOutput());
304 vProbeslicesFlowWidget->SetSource( vVecMagnitude->GetOutput() );
305 vProbeslicesFlowWidget->Update( );
307 vVecMagnitude->GetOutput()->GetScalarRange( range );
309 vAppendDataForFlowWidgetVisualisation->AddInput(vGlyphFlowPlane->GetOutput());
310 vAppendDataForFlowWidgetVisualisation->AddInput(vProbeslicesFlowWidget->GetPolyDataOutput());
312 vSliceMapper->SetInput( vAppendDataForFlowWidgetVisualisation->GetOutput());
313 vSliceMapper->SetScalarRange( range );
314 vSliceMapper->SetLookupTable( vGreenToRedLut );
316 vSliceActor->SetMapper( vSliceMapper );
318 if(bbGetInputShowPlane() == 1)
320 else if(bbGetInputShowPlane() == 0)
323 vSliceActor->GetProperty()->SetOpacity( bbGetInputShowPlane() );
325 exporter->SetInputConnection( vMultipleContourMapper->GetOutputPort() );
326 exporter->ImageLowerLeftOn();
328 bbSetOutputOut1( vSliceActor );
329 bbSetOutputOut2( vGlyphActor );
330 bbSetOutputOut3( vOutlineActor );
331 bbSetOutputOut4( vMultipleContourActor );
332 //bbSetOutputOut5( vScalarBarActor );
333 if(bbGetInputShowStream() == 1)
334 vStreamlineActor2->SetMapper( streamMapper2 );
336 vStreamlineActor2->SetMapper( NULL );
338 bbSetOutputOut5( vStreamlineActor2 );
339 //bbSetOutputOut5( vStreamlineActor2 );
340 //bbSetOutputOutExport( exporter );
341 //temp->GetData( (vtkInformation*) vMultipleContourVelocity->GetOutput() );
342 //temp->GetData( vMultipleContourMapper->GetOutput() );
343 //bbSetOutputOutTest( temp );
353 // 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)
355 void Magnitud::bbUserSetDefaultValues()
358 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
359 // Here we initialize the input 'In' to 0
367 bbSetInputMRatio(100);
368 bbSetInputOpactity(0.5);
369 bbSetInputScale(0.2);
370 bbSetInputContour(10);
371 bbSetInputShowPlane(1);
372 bbSetInputShowStream(0);
373 //bbSetInputPlaneCenterSL();
377 // 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)
379 void Magnitud::bbUserInitializeProcessing()
382 // THE INITIALIZATION METHOD BODY :
384 // but this is where you should allocate the internal/output pointers
388 cone = vtkArrowSource::New();
389 exporter = vtkImageExport::New();
390 point = vtkPolyData::New();
391 rf = vtkTubeFilter::New();
392 source = vtkPointSource::New();
393 streamer = vtkStreamTracer::New();
394 streamMapper2 = vtkPolyDataMapper::New();
396 transformEED = vtkTransform::New();
397 vAppendDataForFlowWidgetVisualisation = vtkAppendPolyData::New();
398 vArrowSource = vtkArrowSource::New();
399 vDiskSourceEED = vtkDiskSource::New();
400 vGlyph = vtkGlyph3D::New();
401 vGlyphActor = vtkActor::New();
402 vGlyphFlowPlane = vtkGlyph3D::New();
403 vGlyphMapper = vtkPolyDataMapper::New();
404 vGreenToRedLut = vtkLookupTable::New();
405 vIren = vtkRenderWindowInteractor::New();
406 vMaskPoint = vtkMaskPoints::New();
407 vMultipleContourActor = vtkActor::New();
408 vMultipleContourMapper = vtkPolyDataMapper::New();
409 vMultipleContourVelocity = vtkContourFilter::New();
410 vOutlineActor = vtkActor::New();
411 vOutlineGrid = vtkOutlineFilter::New();
412 vOutlineMapper = vtkPolyDataMapper::New();
413 vPlanSource = vtkPlaneSource::New();
414 vPlaneWidget = vtkPlaneWidget::New();
415 vPointWidget = vtkPointWidget::New();
416 vProbeslices = vtkProbeFilter::New();
417 vProbeslicesFlowWidget = vtkProbeFilter::New();
418 vScalarBarActor = vtkScalarBarActor::New();
419 vSliceMapper = vtkPolyDataMapper::New();
420 vSliceActor = vtkActor::New();
421 vStreamlineActor2 = vtkActor::New();
422 vtransformpolydatafilter = vtkTransformPolyDataFilter::New();
423 vVecMagnitude = vtkVectorNorm::New();
425 temp = vtkImageData::New();
427 sizeIma = SIZEPLANWIDGET;
431 // 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)
433 void Magnitud::bbUserFinalizeProcessing()
436 // THE FINALIZATION METHOD BODY :
438 // but this is where you should desallocate the internal/output pointers
441 /// \TODO delete everything no longer needed!
445 // EO namespace bbvtk