]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkMagnitud.cxx
Feature #1774
[bbtk.git] / packages / vtk / src / bbvtkMagnitud.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la Santé)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 //=====
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)
30 //===== 
31 #include "bbvtkMagnitud.h"
32 #include "bbvtkPackage.h"
33 namespace bbvtk
34 {
35
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Magnitud)
37 BBTK_BLACK_BOX_IMPLEMENTATION(Magnitud,bbtk::AtomicBlackBox);
38 //===== 
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)
40 //===== 
41 void Magnitud::Process()
42 {
43
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 
50 //    Where :
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')
55
56 // ---------- 
57  if (bbGetInputIn()!=NULL) {
58    vGreenToRedLut->SetHueRange(0.6667,0.0);
59    vGreenToRedLut->Build();
60   
61   //Input Data
62    vVecMagnitude->SetInput(bbGetInputIn());
63    vVecMagnitude->NormalizeOff();
64    vVecMagnitude->Update();
65    vVecMagnitude->GetOutput()->GetScalarRange( range1 );
66    vVecMagnitude->Update();
67    
68    //Glyph
69    vMaskPoint->SetInput(bbGetInputIn());
70    vMaskPoint->SetOnRatio(100);
71    vMaskPoint->Update();
72    vMaskPoint->RandomModeOn();
73    
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;
81       
82    //Contour
83    dRangeColorForMultipleContourVelocity[0]=0;
84    dRangeColorForMultipleContourVelocity[1]=1;
85    dRangeColorForGlyphVelocity[0]=0;
86    dRangeColorForGlyphVelocity[1]=1;
87    vMultipleContourVelocity->SetInput((vtkDataSet *) vVecMagnitude->GetOutput()); 
88    
89    index = 0;
90    double h;
91    step = (range1[1]-range1[0])/10;
92
93    for( h=range1[0]; h<range1[1]; h+=step )
94    {
95       vMultipleContourVelocity->SetValue(index, h);
96       index+=1;
97    }
98    
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);
105
106    //Glyph Mapper
107    vGlyphMapper->SetLookupTable(vGreenToRedLut);
108    vGlyphMapper->SetScalarRange(range1);
109    vGlyphMapper->ImmediateModeRenderingOn();
110  
111    //Outline Grid
112    vOutlineGrid->SetInput( bbGetInputIn() );
113    vOutlineMapper->SetInput(vOutlineGrid->GetOutput());
114    
115    //Outline Grid Actor
116    vOutlineActor->SetMapper(vOutlineMapper);
117  
118    //Glyph Actor
119    vGlyphActor->SetMapper( vGlyphMapper ); 
120    vGlyphActor->GetProperty()->SetOpacity(0); 
121   
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
131    
132    ///////////////////////////////////////////////////////////////////////////////////////////////////
133    //Start: Change values by the user
134    ///////////////////////////////////////////////////////////////////////////////////////////////////
135    //Glyph Mask
136    vMaskPoint->SetOnRatio( bbGetInputMRatio());
137    vMaskPoint->Update();
138
139    //Glyph Opacity
140    vGlyphActor->GetProperty()->SetOpacity( bbGetInputOpactity()/100 );
141    vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()-0.1);
142    vGlyph->Update();
143    vGlyph->SetScaleFactor(vGlyph->GetScaleFactor()+0.1);
144    vGlyph->Update();
145    if( (bbGetInputScale()/100)<0 ) 
146       bbSetInputScale(0);
147    if( (bbGetInputScale()/100)>1 ) 
148       bbSetInputScale(1);
149    
150    //vGlyph->SetScaleFactor(dScale);
151    vGlyph->SetScaleFactor( bbGetInputScale()/100 );
152    vGlyph->Update();
153
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];
161    
162    range1[1]=range1[0]+dTailleInterval*(bbGetInputValSup()/100);
163    range1[0]=range1[0]+dTailleInterval*(bbGetInputValInf()/100);
164    
165    vGlyphMapper->SetScalarRange( range1 );
166    vMultipleContourMapper->SetScalarRange( range1 );
167
168    if( bbGetInputOpactity()/100<0 ) 
169       bbSetInputOpactity(0);
170    if( bbGetInputOpactity()/100>1 ) 
171       bbSetInputOpactity(1);
172
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();
179
180    //Set The Number of Contours
181    if( bbGetInputContour()<1) 
182       bbSetInputContour(1);
183
184    step=(range1[1]-range1[0])/bbGetInputContour();
185    index=0;
186    for( h=range1[0]; h<range1[1]; h+=step)
187    {
188       vMultipleContourVelocity->SetValue(index, h);
189      index+=1;
190    }
191    ///////////////////////////////////////////////////////////////////////////////////////////////////
192    //End: Change values by the user
193    ///////////////////////////////////////////////////////////////////////////////////////////////////
194    //The Plane Widget
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();
203    vPlaneWidget->On();
204
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);
210
211    c[0] = c[0]+ bbGetInputMoveX();
212    c[1] = c[1]+ bbGetInputMoveY();
213    c[2] = c[2]+ bbGetInputMoveZ();
214
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( );
224    
225    vDiskSourceEED->SetInnerRadius (0);
226    vDiskSourceEED->SetOuterRadius (10);
227    vDiskSourceEED->SetRadialResolution (20);
228    vDiskSourceEED->SetCircumferentialResolution (20);
229
230    //Stream Lines
231    vPointWidget->SetInput( bbGetInputIn() );
232    vPointWidget->AllOff();
233    vPointWidget->PlaceWidget();
234    //vPointWidget->SetInteractor(vIren);
235    vPointWidget->On();
236    //vPointWidget->GetPolyData(point);
237    vPointWidget->GetPolyData(point);
238    source->SetNumberOfPoints(500);
239    /*
240    tempc = bbGetInputPlaneCenterSL();
241    slCenter[0] = tempc[0];
242    slCenter[1] = tempc[1];
243    slCenter[2] = tempc[2];
244    source->SetCenter(  slCenter );
245    */
246    source->SetCenter(  c );
247    source->SetRadius(5.0);
248    
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 ();
258    streamer->Update();
259
260    rf->SetInput(streamer->GetOutput());
261    rf->SetRadius(.5);
262    rf->SetNumberOfSides(12);
263    rf->SetVaryRadiusToVaryRadiusOff();
264    
265    streamer->GetOutput()->GetScalarRange( range );
266    streamMapper2->SetInput(rf->GetOutput());
267    streamMapper2->SetLookupTable(vGreenToRedLut);
268    //vStreamlineActor2->SetMapper( streamMapper2 );
269    
270    //////////////////////////////////////////////////////////////////////////////////////
271    //Start: Part of the Execute Method
272    //////////////////////////////////////////////////////////////////////////////////////
273    nx=n[0];
274    ny=n[1];
275    nz=n[2];
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    //////////////////////////////////////////////////////////////////////////////////////
287
288    vtransformpolydatafilter->SetInput( vDiskSourceEED->GetOutput() );
289    vtransformpolydatafilter->SetTransform( transformEED );
290    vtransformpolydatafilter->Update();
291    
292    vProbeslices->SetInput( ( vtkDataSet* )vtransformpolydatafilter->GetOutput());
293    vProbeslices->SetSource( bbGetInputIn() ); 
294    vProbeslices->Update( );
295
296    vGlyphFlowPlane->SetInput(vProbeslices->GetOutput());
297    vGlyphFlowPlane->SetSource(vArrowSource->GetOutput());
298    vGlyphFlowPlane->SetScaleModeToScaleByVector();
299    vGlyphFlowPlane->SetColorModeToColorByVector();
300    vGlyphFlowPlane->SetScaleFactor(0.2);
301    vGlyphFlowPlane->Update();
302
303    vProbeslicesFlowWidget->SetInput( ( vtkDataSet* )vPlanSource->GetOutput());
304    vProbeslicesFlowWidget->SetSource( vVecMagnitude->GetOutput() ); 
305    vProbeslicesFlowWidget->Update( );
306       
307    vVecMagnitude->GetOutput()->GetScalarRange( range );
308
309    vAppendDataForFlowWidgetVisualisation->AddInput(vGlyphFlowPlane->GetOutput());
310    vAppendDataForFlowWidgetVisualisation->AddInput(vProbeslicesFlowWidget->GetPolyDataOutput());
311
312    vSliceMapper->SetInput( vAppendDataForFlowWidgetVisualisation->GetOutput());
313    vSliceMapper->SetScalarRange( range );
314    vSliceMapper->SetLookupTable( vGreenToRedLut );
315    
316    vSliceActor->SetMapper( vSliceMapper );
317
318    if(bbGetInputShowPlane() == 1)
319       vPlaneWidget->On();
320    else if(bbGetInputShowPlane() == 0)
321       vPlaneWidget->Off();
322
323    vSliceActor->GetProperty()->SetOpacity( bbGetInputShowPlane() );
324
325    exporter->SetInputConnection( vMultipleContourMapper->GetOutputPort() );
326    exporter->ImageLowerLeftOn();
327
328    bbSetOutputOut1( vSliceActor );
329    bbSetOutputOut2( vGlyphActor );
330    bbSetOutputOut3( vOutlineActor );
331    bbSetOutputOut4( vMultipleContourActor );
332    //bbSetOutputOut5( vScalarBarActor );
333    if(bbGetInputShowStream() == 1)
334       vStreamlineActor2->SetMapper( streamMapper2 );
335    else 
336       vStreamlineActor2->SetMapper( NULL );
337
338    bbSetOutputOut5( vStreamlineActor2 );
339    //bbSetOutputOut5( vStreamlineActor2 );
340    //bbSetOutputOutExport( exporter );
341    //temp->GetData( (vtkInformation*) vMultipleContourVelocity->GetOutput() );
342    //temp->GetData( vMultipleContourMapper->GetOutput() );
343    //bbSetOutputOutTest( temp );
344
345
346  } // if
347
348 } // process
349
350
351
352 //===== 
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)
354 //===== 
355 void Magnitud::bbUserSetDefaultValues()
356 {
357
358 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
359 //    Here we initialize the input 'In' to 0
360 // --------- [
361    bbSetInputIn(NULL);
362    bbSetInputMoveX(0);
363    bbSetInputMoveY(0);
364    bbSetInputMoveZ(0);
365    bbSetInputValSup(1);
366    bbSetInputValInf(0);
367    bbSetInputMRatio(100);
368    bbSetInputOpactity(0.5);
369    bbSetInputScale(0.2);
370    bbSetInputContour(10);
371    bbSetInputShowPlane(1);
372    bbSetInputShowStream(0);
373    //bbSetInputPlaneCenterSL();
374 // --------- ]  
375 }
376 //===== 
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)
378 //===== 
379 void Magnitud::bbUserInitializeProcessing()
380 {
381
382 //  THE INITIALIZATION METHOD BODY :
383 //    Here does nothing 
384 //    but this is where you should allocate the internal/output pointers 
385 //    if any 
386
387 // ---------- [
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();
395    
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();
424
425    temp                     = vtkImageData::New();
426
427    sizeIma = SIZEPLANWIDGET;
428 // ---------- }  
429 }
430 //===== 
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)
432 //===== 
433 void Magnitud::bbUserFinalizeProcessing()
434 {
435
436 //  THE FINALIZATION METHOD BODY :
437 //    Here does nothing 
438 //    but this is where you should desallocate the internal/output pointers 
439 //    if any
440
441 /// \TODO delete everything no longer needed!
442   
443 }
444 }
445 // EO namespace bbvtk
446
447