]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuVolumeRendering.cxx
5cfc7e9eec0e107200ff51193803b658c672b3fd
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuVolumeRendering.cxx
1 #include "bbcreaMaracasVisuVolumeRendering.h"
2 #include "bbcreaMaracasVisuPackage.h"
3 namespace bbcreaMaracasVisu
4 {
5
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,VolumeRendering)
7 BBTK_BLACK_BOX_IMPLEMENTATION(VolumeRendering,bbtk::AtomicBlackBox);
8 void VolumeRendering::Process()
9 {
10  
11 // THE MAIN PROCESSING METHOD BODY 
12 //   Here we simply set the input 'In' value to the output 'Out' 
13 //   And print out the output value 
14 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM : 
15 //    void bbSet{Input|Output}NAME(const TYPE&) 
16 //    const TYPE& bbGet{Input|Output}NAME() const  
17 //    Where : 
18 //    * NAME is the name of the input/output 
19 //      (the one provided in the attribute 'name' of the tag 'input') 
20 //    * TYPE is the C++ type of the input/output 
21 //      (the one provided in the attribute 'type' of the tag 'input') 
22     
23         
24         vtkImageData* _img = bbGetInputIn();
25
26         if(_img!=NULL){
27                 double range[2];
28                 _img->GetScalarRange(range);
29                 double max = range[1];
30                 _tfun->AddPoint(max * 0/2 , 0.0);
31                 _tfun->AddPoint(max * 1/2 , 1.0);
32                 _tfun->AddPoint(max * 2/2 , 1.0);
33                 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
34                 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
35                 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
36                 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
37                 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);          
38
39                 _volumeMapper->SetInput( _img );
40
41                 _volumeMapper->Update();
42                 _newvol->Update();
43
44                 bbSetOutputOut(_newvol);
45         }
46         
47
48   
49 }
50 void VolumeRendering::bbUserSetDefaultValues()
51 {
52  
53 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX  
54 //    Here we initialize the input 'In' to 0 
55    bbSetInputIn(0); 
56    bbSetOutputOut(0); 
57   
58 }
59 void VolumeRendering::bbUserInitializeProcessing()
60 {
61         _tfun = vtkPiecewiseFunction::New();
62         _ctfun = vtkColorTransferFunction::New();    
63
64         _volumePlanes  = vtkPlanes::New();
65         _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
66         _volumeMapper = vtkVolumeRayCastMapper::New();  
67         _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
68         _volumeMapper->SetClippingPlanes( _volumePlanes );
69         _volumeMapper->AutoAdjustSampleDistancesOn();
70         _volumeProperty = vtkVolumeProperty::New();     
71         _volumeProperty->SetInterpolationTypeToLinear();
72         _volumeProperty->ShadeOn();
73         _volumeProperty->DisableGradientOpacityOn();
74         _volumeProperty->SetColor(_ctfun);
75         _volumeProperty->SetScalarOpacity( _tfun );
76         _newvol = vtkVolume::New();
77         _newvol->SetMapper(_volumeMapper );
78         _newvol->SetProperty(_volumeProperty );
79   
80 }
81 void VolumeRendering::bbUserFinalizeProcessing()
82 {
83  
84 //  THE FINALIZATION METHOD BODY : 
85 //    Here does nothing  
86 //    but this is where you should desallocate the internal/output pointers  
87 //    if any 
88   
89 }
90 }
91 // EO namespace bbcreaMaracasVisu
92
93