]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkMagnitud.cxx
000320e775f8a59e8007e2fe949414f693ebc45a
[bbtk.git] / packages / vtk / src / bbvtkMagnitud.cxx
1 //===== 
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)
3 //===== 
4 #include "bbvtkMagnitud.h"
5 #include "bbvtkPackage.h"
6 namespace bbvtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Magnitud)
10 BBTK_BLACK_BOX_IMPLEMENTATION(Magnitud,bbtk::AtomicBlackBox);
11 //===== 
12 // 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)
13 //===== 
14 void Magnitud::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28
29 // ---------- 
30    vGreenToRedLut->SetHueRange(0.6667,0.0);
31    vGreenToRedLut->Build();
32   
33   //Input Data
34    vVecMagnitude->SetInput(bbGetInputIn());
35    vVecMagnitude->NormalizeOff();
36    vVecMagnitude->Update();
37    vVecMagnitude->GetOutput()->GetScalarRange( range1 );
38    vVecMagnitude->Update();
39    
40    //Glyph
41    vMaskPoint->SetInput(bbGetInputIn());
42    vMaskPoint->SetOnRatio(100);
43    vMaskPoint->Update();
44    vMaskPoint->RandomModeOn();
45    
46    vGlyph->SetInput(vMaskPoint->GetOutput());
47    vGlyph->SetSource(cone->GetOutput());
48    vGlyph->SetScaleModeToScaleByVector();
49    vGlyph->SetColorModeToColorByVector();
50    vGlyph->SetScaleFactor(0.20);
51    vGlyphMapper->SetInput( vGlyph->GetOutput() );
52    step = (range1[1]-range1[0])/10;
53       
54    //Contour
55    dRangeColorForMultipleContourVelocity[0]=0;
56    dRangeColorForMultipleContourVelocity[1]=1;
57    dRangeColorForGlyphVelocity[0]=0;
58    dRangeColorForGlyphVelocity[1]=1;
59    vMultipleContourVelocity->SetInput((vtkDataSet *) vVecMagnitude->GetOutput()); 
60    
61    index = 0;
62    double h;
63    step = (range1[1]-range1[0])/10;
64
65    for( h=range1[0]; h<range1[1]; h+=step )
66    {
67       vMultipleContourVelocity->SetValue(index, h);
68       index+=1;
69    }
70    
71    vMultipleContourMapper->SetInput( vMultipleContourVelocity->GetOutput() );
72    vMultipleContourMapper->SetScalarRange( range1 );
73    vMultipleContourMapper->SetLookupTable( vGreenToRedLut );
74    vMultipleContourMapper->Update();
75    vMultipleContourActor->SetMapper( vMultipleContourMapper );
76    vMultipleContourActor->GetProperty()->SetOpacity(0.4);
77
78    //Glyph Mapper
79    vGlyphMapper->SetLookupTable(vGreenToRedLut);
80    vGlyphMapper->SetScalarRange(range1);
81    vGlyphMapper->ImmediateModeRenderingOn();
82  
83    //Outline Grid
84    vOutlineGrid->SetInput( bbGetInputIn() );
85    vOutlineMapper->SetInput(vOutlineGrid->GetOutput());
86    
87    //Outline Grid Actor
88    vOutlineActor->SetMapper(vOutlineMapper);
89  
90    //Glyph Actor
91    vGlyphActor->SetMapper( vGlyphMapper ); 
92    vGlyphActor->GetProperty()->SetOpacity(0); 
93   
94    //The Velocity Bar - Indicator (It's Actor is a vtkProper)
95    vScalarBarActor->SetLookupTable (vMultipleContourMapper->GetLookupTable());
96    vScalarBarActor->SetTitle ("Velocity");
97    vScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
98    vScalarBarActor->GetPositionCoordinate()->SetValue( 0.85, 0.25);
99    vScalarBarActor->SetOrientationToVertical();
100    vScalarBarActor->SetWidth (0.1);
101    vScalarBarActor->SetHeight (0.6);
102    vScalarBarActor->GetProperty()->SetOpacity(1); // 1 to Show - 0 to Hide
103    
104    ///////////////////////////////////////////////////////////////////////////////////////////////////
105    //Start: Change values by the user
106    ///////////////////////////////////////////////////////////////////////////////////////////////////
107    //Glyph Mask
108    vMaskPoint->SetOnRatio( bbGetInputMRatio());
109    vMaskPoint->Update();
110
111    //Glyph Opacity
112    vGlyphActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
113    vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()-0.1);
114    vGlyph->Update();
115    vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()+0.1);
116    vGlyph->Update();
117    if( (bbGetInputScale()/100)<0 ) 
118       bbSetInputScale(0);
119    if( (bbGetInputScale()/100)>1 ) 
120       bbSetInputScale(1);
121    
122    //vGlyph->SetScaleFactor(dScale);
123    vGlyph->SetScaleFactor( bbGetInputScale()/100 );
124    vGlyph->Update();
125
126    //Set Glyph and Contour Colour Range
127    vVecMagnitude->GetOutput()->GetScalarRange( range1 );
128    dRangeColorForGlyphVelocity[0] = bbGetInputValInf()/100;
129    dRangeColorForGlyphVelocity[1] = bbGetInputValSup()/100;
130    dRangeColorForMultipleContourVelocity[0] = bbGetInputValInf()/100;
131    dRangeColorForMultipleContourVelocity[1] = bbGetInputValSup()/100;
132    double dTailleInterval=range1[1]-range1[0];
133    
134    range1[1]=range1[0]+dTailleInterval*(bbGetInputValSup()/100);
135    range1[0]=range1[0]+dTailleInterval*(bbGetInputValInf()/100);
136    
137    vGlyphMapper->SetScalarRange( range1 );
138    vMultipleContourMapper->SetScalarRange( range1 );
139
140    if( bbGetInputOpactity()/100<0 ) 
141       bbSetInputOpactity(0);
142    if( bbGetInputOpactity()/100>1 ) 
143       bbSetInputOpactity(1);
144
145    //Set Contour Opacity
146    vMultipleContourActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
147    vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()+1);
148    vMultipleContourVelocity->Update();
149    vMultipleContourVelocity->SetNumberOfContours(vMultipleContourVelocity->GetNumberOfContours()-1);
150    vMultipleContourVelocity->Update();
151
152    //Set The Number of Contours
153    if( bbGetInputContour()<1) 
154       bbSetInputContour(1);
155
156    step=(range1[1]-range1[0])/bbGetInputContour();
157    index=0;
158    for( h=range1[0]; h<range1[1]; h+=step)
159    {
160       vMultipleContourVelocity->SetValue(index, h);
161      index+=1;
162    }
163    ///////////////////////////////////////////////////////////////////////////////////////////////////
164    //End: Change values by the user
165    ///////////////////////////////////////////////////////////////////////////////////////////////////
166    //The Plane Widget
167    vPlaneWidget->SetInput(bbGetInputIn());
168    vPlaneWidget->NormalToXAxisOn();
169    vPlaneWidget->NormalToZAxisOn();
170    vPlaneWidget->SetResolution(1);
171    vPlaneWidget->SetRepresentationToOutline();
172    //vPlaneWidget->SetInteractor(vIren);
173    vPlaneWidget->SetPlaceFactor(1); //défini zoom initial
174    vPlaneWidget->PlaceWidget();
175    vPlaneWidget->On();
176
177    vPlaneWidget->GetOrigin(p0);
178    vPlaneWidget->GetCenter(c); //These is from Execute Method
179    vPlaneWidget->GetNormal(n);
180    vPlaneWidget->GetPoint1(p1);
181    vPlaneWidget->GetPoint2(p2);
182
183    c[0] = c[0]+ bbGetInputMoveX();
184    c[1] = c[1]+ bbGetInputMoveY();
185    c[2] = c[2]+ bbGetInputMoveZ();
186
187    vPlanSource->SetResolution( sizeIma-1,  sizeIma-1);
188    vPlanSource->SetOrigin( p0 );
189    vPlanSource->SetPoint1( p1 );
190    vPlanSource->SetPoint2( p2 );
191    vPlanSource->Update( );
192    vPlanSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
193    vPlanSource->Update( );
194    vPlanSource->SetCenter( c );
195    vPlanSource->Update( );
196    
197    vDiskSourceEED->SetInnerRadius (0);
198    vDiskSourceEED->SetOuterRadius (10);
199    vDiskSourceEED->SetRadialResolution (20);
200    vDiskSourceEED->SetCircumferentialResolution (20);
201
202    //Stream Lines
203    vPointWidget->SetInput( bbGetInputIn() );
204    vPointWidget->AllOff();
205    vPointWidget->PlaceWidget();
206    //vPointWidget->SetInteractor(vIren);
207    vPointWidget->On();
208    //vPointWidget->GetPolyData(point);
209    vPointWidget->GetPolyData(point);
210    source->SetNumberOfPoints(500);
211    /*
212    tempc = bbGetInputPlaneCenterSL();
213    slCenter[0] = tempc[0];
214    slCenter[1] = tempc[1];
215    slCenter[2] = tempc[2];
216    source->SetCenter(  slCenter );
217    */
218    source->SetCenter(  c );
219    source->SetRadius(5.0);
220    
221    streamer->SetInput( bbGetInputIn() );
222    streamer->SetSource(source->GetOutput());
223    streamer->SetIntegratorTypeToRungeKutta45();
224    streamer->SetMaximumPropagation(500000);
225 //EED    streamer->SetMaximumPropagationUnitToTimeUnit ();
226    streamer->SetInitialIntegrationStep (0.001);
227 //EED    streamer->SetInitialIntegrationStepUnitToCellLengthUnit();
228    streamer->SetIntegrationDirectionToBoth();
229 //EED   streamer->ComputeVorticityOn ();
230    streamer->Update();
231
232    rf->SetInput(streamer->GetOutput());
233    rf->SetRadius(.5);
234    rf->SetNumberOfSides(12);
235    rf->SetVaryRadiusToVaryRadiusOff();
236    
237    streamer->GetOutput()->GetScalarRange( range );
238    streamMapper2->SetInput(rf->GetOutput());
239    streamMapper2->SetLookupTable(vGreenToRedLut);
240    //vStreamlineActor2->SetMapper( streamMapper2 );
241    
242    //////////////////////////////////////////////////////////////////////////////////////
243    //Start: Part of the Execute Method
244    //////////////////////////////////////////////////////////////////////////////////////
245    nx=n[0];
246    ny=n[1];
247    nz=n[2];
248    alfa = atan2(ny,nx) * 180.0 / 3.1416;
249    beta = atan2( nz, sqrt( nx*nx + ny*ny )  ) * 180.0 / 3.1416;
250    transformEED->Identity();  
251    transformEED->Translate(c);
252    transformEED->RotateWXYZ(alfa,0,0,1);
253    transformEED->RotateWXYZ(-beta,0,1,0);
254    transformEED->RotateWXYZ(90,0,1,0);
255    transformEED->Update();
256    //////////////////////////////////////////////////////////////////////////////////////
257    //End: Part of the Execute Method
258    //////////////////////////////////////////////////////////////////////////////////////
259
260    vtransformpolydatafilter->SetInput( vDiskSourceEED->GetOutput() );
261    vtransformpolydatafilter->SetTransform( transformEED );
262    vtransformpolydatafilter->Update();
263    
264    vProbeslices->SetInput( ( vtkDataSet* )vtransformpolydatafilter->GetOutput());
265    vProbeslices->SetSource( bbGetInputIn() ); 
266    vProbeslices->Update( );
267
268    vGlyphFlowPlane->SetInput(vProbeslices->GetOutput());
269    vGlyphFlowPlane->SetSource(vArrowSource->GetOutput());
270    vGlyphFlowPlane->SetScaleModeToScaleByVector();
271    vGlyphFlowPlane->SetColorModeToColorByVector();
272    vGlyphFlowPlane->SetScaleFactor(0.2);
273    vGlyphFlowPlane->Update();
274
275    vProbeslicesFlowWidget->SetInput( ( vtkDataSet* )vPlanSource->GetOutput());
276    vProbeslicesFlowWidget->SetSource( vVecMagnitude->GetOutput() ); 
277    vProbeslicesFlowWidget->Update( );
278       
279    vVecMagnitude->GetOutput()->GetScalarRange( range );
280
281    vAppendDataForFlowWidgetVisualisation->AddInput(vGlyphFlowPlane->GetOutput());
282    vAppendDataForFlowWidgetVisualisation->AddInput(vProbeslicesFlowWidget->GetPolyDataOutput());
283
284    vSliceMapper->SetInput( vAppendDataForFlowWidgetVisualisation->GetOutput());
285    vSliceMapper->SetScalarRange( range );
286    vSliceMapper->SetLookupTable( vGreenToRedLut );
287    
288    vSliceActor->SetMapper( vSliceMapper );
289
290    if(bbGetInputShowPlane() == 1)
291       vPlaneWidget->On();
292    else if(bbGetInputShowPlane() == 0)
293       vPlaneWidget->Off();
294
295    vSliceActor->GetProperty()->SetOpacity( bbGetInputShowPlane() );
296
297    exporter->SetInputConnection( vMultipleContourMapper->GetOutputPort() );
298    exporter->ImageLowerLeftOn();
299
300    bbSetOutputOut1( vSliceActor );
301    bbSetOutputOut2( vGlyphActor );
302    bbSetOutputOut3( vOutlineActor );
303    bbSetOutputOut4( vMultipleContourActor );
304    //bbSetOutputOut5( vScalarBarActor );
305    if(bbGetInputShowStream() == 1)
306       vStreamlineActor2->SetMapper( streamMapper2 );
307    else 
308       vStreamlineActor2->SetMapper( NULL );
309
310    bbSetOutputOut5( vStreamlineActor2 );
311    //bbSetOutputOut5( vStreamlineActor2 );
312    //bbSetOutputOutExport( exporter );
313    //temp->GetData( (vtkInformation*) vMultipleContourVelocity->GetOutput() );
314    //temp->GetData( vMultipleContourMapper->GetOutput() );
315    //bbSetOutputOutTest( temp );
316
317 // ---------- ]  
318 }
319 //===== 
320 // 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)
321 //===== 
322 void Magnitud::bbUserSetDefaultValues()
323 {
324
325 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
326 //    Here we initialize the input 'In' to 0
327 // --------- [
328    bbSetInputIn(NULL);
329    bbSetInputMoveX(0);
330    bbSetInputMoveY(0);
331    bbSetInputMoveZ(0);
332    bbSetInputValSup(1);
333    bbSetInputValInf(0);
334    bbSetInputMRatio(100);
335    bbSetInputOpactity(0.5);
336    bbSetInputScale(0.2);
337    bbSetInputContour(10);
338    bbSetInputShowPlane(1);
339    bbSetInputShowStream(0);
340    //bbSetInputPlaneCenterSL();
341 // --------- ]  
342 }
343 //===== 
344 // 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)
345 //===== 
346 void Magnitud::bbUserInitializeProcessing()
347 {
348
349 //  THE INITIALIZATION METHOD BODY :
350 //    Here does nothing 
351 //    but this is where you should allocate the internal/output pointers 
352 //    if any 
353
354 // ---------- [
355    cone = vtkArrowSource::New();
356    exporter = vtkImageExport::New();
357    point = vtkPolyData::New();
358    rf = vtkTubeFilter::New();
359    source = vtkPointSource::New();
360    streamer = vtkStreamTracer::New();
361    streamMapper2 = vtkPolyDataMapper::New();
362    
363    transformEED             = vtkTransform::New();
364    vAppendDataForFlowWidgetVisualisation = vtkAppendPolyData::New();
365    vArrowSource             = vtkArrowSource::New();
366    vDiskSourceEED           = vtkDiskSource::New();
367    vGlyph                   = vtkGlyph3D::New();
368    vGlyphActor              = vtkActor::New();
369    vGlyphFlowPlane          = vtkGlyph3D::New();
370    vGlyphMapper             = vtkPolyDataMapper::New();
371    vGreenToRedLut           = vtkLookupTable::New();
372    vIren                    = vtkRenderWindowInteractor::New();
373    vMaskPoint               = vtkMaskPoints::New();
374    vMultipleContourActor    = vtkActor::New();
375    vMultipleContourMapper   = vtkPolyDataMapper::New();
376    vMultipleContourVelocity = vtkContourFilter::New();
377    vOutlineActor            = vtkActor::New();
378    vOutlineGrid             = vtkOutlineFilter::New();
379    vOutlineMapper           = vtkPolyDataMapper::New();
380    vPlanSource              = vtkPlaneSource::New();
381    vPlaneWidget             = vtkPlaneWidget::New();
382    vPointWidget             = vtkPointWidget::New();
383    vProbeslices             = vtkProbeFilter::New();
384    vProbeslicesFlowWidget   = vtkProbeFilter::New();
385    vScalarBarActor          = vtkScalarBarActor::New();
386    vSliceMapper             = vtkPolyDataMapper::New();
387    vSliceActor              = vtkActor::New();
388    vStreamlineActor2        = vtkActor::New();
389    vtransformpolydatafilter = vtkTransformPolyDataFilter::New();
390    vVecMagnitude            = vtkVectorNorm::New();
391
392    temp                     = vtkImageData::New();
393
394    sizeIma = SIZEPLANWIDGET;
395 // ---------- }  
396 }
397 //===== 
398 // 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)
399 //===== 
400 void Magnitud::bbUserFinalizeProcessing()
401 {
402
403 //  THE FINALIZATION METHOD BODY :
404 //    Here does nothing 
405 //    but this is where you should desallocate the internal/output pointers 
406 //    if any
407
408 /// \TODO delete everything no longer needed!
409   
410 }
411 }
412 // EO namespace bbvtk
413
414