]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkMIPCreator.cxx
*** empty log 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/23 15:26:55 $
6   Version:   $Revision: 1.9 $
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
53
54            std::vector<double> denPoints;
55        std::vector<double> opaValues;
56        denPoints.push_back(0.0);
57        denPoints.push_back(255.0);
58        opaValues.push_back(0.0);
59        opaValues.push_back(1.0);
60        bbSetInputDensityPoints(denPoints);
61        bbSetInputOpacityValues(opaValues);
62        bbSetInputMinColorWindow(0.0);
63        bbSetInputMaxColorWindow(255.0);
64
65        opacityTransferFunction = vtkPiecewiseFunction::New();
66        grayTransferFunction = vtkPiecewiseFunction::New();
67
68            mCast        = NULL;
69            mMIP         = NULL;
70            mMapper      = NULL;
71            mVolume      = NULL;
72
73
74    }
75         //---------------------------------------------------------------------
76    void MIPCreator::bbUserInitializeProcessing()
77    {
78
79
80     // Create the pipeline
81     mCast = vtkImageShiftScale::New();
82     mCast->SetOutputScalarTypeToUnsignedChar();
83     mCast->ClampOverflowOn();
84
85      DensityPoints = bbGetInputDensityPoints();
86      OpacityValues = bbGetInputOpacityValues();
87
88      while(DensityPoints.size()>OpacityValues.size())
89      {
90          OpacityValues.push_back(1.0);
91      }
92
93 }
94
95 //---------------------------------------------------------------------
96    void MIPCreator::bbUserFinalizeProcessing()
97    {
98            if (mCast!=NULL)
99            {
100                    mCast->Delete();
101                    mCast=NULL;
102            }
103
104            if (mMIP!=NULL)
105            {
106                    mMIP->Delete();
107                    mMIP=NULL;
108            }
109
110            if (mMapper!=NULL)
111            {
112                    mMapper->Delete();
113                    mMapper=NULL;
114            }
115
116            if (mVolume!=NULL)
117            {
118                    mVolume->Delete();
119                    mVolume=NULL;
120            }
121    }
122 //---------------------------------------------------------------------
123
124    void MIPCreator::Process()
125    {
126
127
128
129         double ranges[2];
130         vtkImageData *image =  bbGetInputIn();
131         image->Update();
132         image->GetScalarRange(ranges);
133
134            scale = 255/(ranges[1]/100);
135
136        mCast->SetInput( bbGetInputIn() );
137        mCast->SetScale( scale / 100.0 );
138      //mCast->SetShift( -bbGetInputShift() );
139
140
141         double factor = scale/ 100.0 ;
142
143
144        double minCF = bbGetInputMinColorWindow();
145        double maxCF = bbGetInputMaxColorWindow();
146         cout<<"MIPCreator::Process::minCF"<<minCF <<endl;
147         cout<<"MIPCreator::Process::maxCF"<<maxCF <<endl;
148        grayTransferFunction->AddSegment( minCF , 0.0 , maxCF , 1.0 );
149
150
151
152         for(int i =0; i< DensityPoints.size(); i++)
153         {
154
155             opacityTransferFunction->AddPoint(DensityPoints.at(i)*factor, OpacityValues.at(i));
156         }
157            //opacityTransferFunction = vtkPiecewiseFunction::New();
158 //         opacityTransferFunction->AddPoint(   0 ,    0.0/100.0 );
159 //         opacityTransferFunction->AddPoint(  85 ,    2.0/100.0 );
160 //         opacityTransferFunction->AddPoint( 160 ,   25.0/100.0 );
161 //         opacityTransferFunction->AddPoint( 210 ,   50.0/100.0 );
162 //         opacityTransferFunction->AddPoint( 255 ,   90.0/100.0 );
163
164
165
166            // Create a set of properties for mip
167            vtkVolumeProperty *mipProperty;
168            mipProperty = vtkVolumeProperty::New();
169            mipProperty->SetScalarOpacity( opacityTransferFunction );
170            mipProperty->SetColor( grayTransferFunction );
171
172 //         mipProperty->SetInterpolationTypeToLinear();
173            mipProperty->SetInterpolationTypeToNearest();
174
175 //         mipProperty->ShadeOff();
176            mipProperty->ShadeOn();
177
178 //         mipProperty->SetAmbient(0.9);
179 //         mipProperty->SetDiffuse(0.9);
180 //         mipProperty->SetSpecular(0.9);
181
182
183
184
185
186         mMIP = vtkVolumeRayCastMIPFunction::New();
187         mMIP->SetMaximizeMethodToScalarValue();
188
189         mMapper = vtkVolumeRayCastMapper::New();
190         mMapper->SetVolumeRayCastFunction(mMIP);
191         mMapper->SetInput(mCast->GetOutput()); // (smoother.GetOutput())
192
193         mVolume = vtkVolume::New();
194         mVolume->SetMapper(mMapper);
195         mVolume->SetProperty( mipProperty );
196
197
198
199         mMapper->Update();
200
201       bbSetOutputOut(mVolume);
202      //     mVolume->GetProperty()->SetColor( bbGetInputColour()[0],  bbGetInputColour()[1], bbGetInputColour()[2] );
203      //     mVolume->GetProperty()->SetOpacity( bbGetInputOpacity() );
204
205
206    }
207 }//namespace bbtk
208
209 #endif // _USE_VTK_
210