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