]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkMIPCreator.cxx
no message
[bbtk.git] / packages / vtk / src / bbvtkMIPCreator.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkMIPCreator.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/03/17 15:49:14 $
6   Version:   $Revision: 1.8 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35
36 #ifdef _USE_VTK_
37
38 #include <vtkVolumeProperty.h>
39 #include <vtkPiecewiseFunction.h>
40
41 #include "bbvtkMIPCreator.h"
42 #include "bbvtkPackage.h"
43
44 namespace bbvtk
45 {
46    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MIPCreator)
47    BBTK_BLACK_BOX_IMPLEMENTATION(MIPCreator,bbtk::AtomicBlackBox);
48    
49         //---------------------------------------------------------------------
50    void MIPCreator::bbUserSetDefaultValues() 
51    { 
52            bbSetInputShift(0);
53            bbSetInputScale(1.0);
54            mCast        = NULL;  
55            mMIP         = NULL;  
56            mMapper      = NULL;  
57            mVolume      = NULL;  
58    }
59         //---------------------------------------------------------------------
60    void MIPCreator::bbUserInitializeProcessing() 
61    {   
62     // Create the pipeline
63     mCast = vtkImageShiftScale::New();
64     mCast->SetOutputScalarTypeToUnsignedChar();
65     mCast->ClampOverflowOn();
66
67            
68            
69            
70            //define range of values
71            vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
72            opacityTransferFunction->AddPoint(   0 ,    0.0/100.0 );
73 //         opacityTransferFunction->AddPoint(  85 ,    2.0/100.0 );
74 //         opacityTransferFunction->AddPoint( 160 ,   25.0/100.0 );
75 //         opacityTransferFunction->AddPoint( 210 ,   50.0/100.0 );
76            opacityTransferFunction->AddPoint( 255 ,   90.0/100.0 );
77            
78            
79            //Create a transfer function mapping scalar value to color (grey)
80            vtkPiecewiseFunction *grayTransferFunction = vtkPiecewiseFunction::New();
81            grayTransferFunction->AddSegment( 0 , 0.0 , 255 , 1.0 );
82            
83            // Create a set of properties for mip
84            vtkVolumeProperty *mipProperty;
85            mipProperty = vtkVolumeProperty::New();
86            mipProperty->SetScalarOpacity( opacityTransferFunction );
87            mipProperty->SetColor( grayTransferFunction );
88            
89 //         mipProperty->SetInterpolationTypeToLinear();
90            mipProperty->SetInterpolationTypeToNearest();                  
91
92 //         mipProperty->ShadeOff();
93            mipProperty->ShadeOn();
94
95            mipProperty->SetAmbient(0.9);           
96            mipProperty->SetDiffuse(0.9);           
97            mipProperty->SetSpecular(0.9);          
98            
99            
100     mMIP = vtkVolumeRayCastMIPFunction::New();
101     mMIP->SetMaximizeMethodToScalarValue();
102 //    mMIP->SetMaximizeMethodToOpacity();
103     
104     mMapper = vtkVolumeRayCastMapper::New();
105     mMapper->SetVolumeRayCastFunction(mMIP);
106     mMapper->SetInput(mCast->GetOutput()); // (smoother.GetOutput())
107     
108     mVolume = vtkVolume::New();
109     mVolume->SetMapper(mMapper);
110         mVolume->SetProperty( mipProperty );
111            
112     //  mMapper->ScalarVisibilityOff();
113     //  mMapper->ImmediateModeRenderingOn();
114
115     bbSetOutputOut(mVolume);
116 }
117
118 //---------------------------------------------------------------------
119    void MIPCreator::bbUserFinalizeProcessing() 
120    { 
121            if (mCast!=NULL)
122            {
123                    mCast->Delete();
124                    mCast=NULL;
125            }
126
127            if (mMIP!=NULL)
128            {
129                    mMIP->Delete();
130                    mMIP=NULL;
131            }
132
133            if (mMapper!=NULL)
134            {
135                    mMapper->Delete();
136                    mMapper=NULL;
137            }
138
139            if (mVolume!=NULL)
140            {
141                    mVolume->Delete();
142                    mVolume=NULL;
143            }
144    }
145 //---------------------------------------------------------------------
146
147    void MIPCreator::Process()
148    {
149      mCast->SetInput( bbGetInputIn() );
150      mCast->SetScale( bbGetInputScale() / 100.0 );
151      mCast->SetShift( -bbGetInputShift() );
152
153      mMapper->Update();
154      
155      //     mVolume->GetProperty()->SetColor( bbGetInputColour()[0],  bbGetInputColour()[1], bbGetInputColour()[2] );
156      //     mVolume->GetProperty()->SetOpacity( bbGetInputOpacity() );
157      
158    }
159 }//namespace bbtk
160
161 #endif // _USE_VTK_
162