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