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