]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkMIPCreator.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[bbtk.git] / packages / vtk / src / bbvtkMIPCreator.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   Program:   bbtk
30   Module:    $RCSfile: bbvtkMIPCreator.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:58 $
33   Version:   $Revision: 1.12 $
34 =========================================================================*/
35
36 /**
37  *  \file
38  *  \brief
39  */
40
41 #ifdef _USE_VTK_
42
43 #include <vtkVolumeProperty.h>
44 #include <vtkPiecewiseFunction.h>
45
46 #include "bbvtkMIPCreator.h"
47 #include "bbvtkPackage.h"
48
49 namespace bbvtk
50 {
51    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MIPCreator)
52    BBTK_BLACK_BOX_IMPLEMENTATION(MIPCreator,bbtk::AtomicBlackBox);
53
54         //---------------------------------------------------------------------
55    void MIPCreator::bbUserSetDefaultValues()
56    {
57
58
59
60        std::vector<double> opaValues;
61        std::vector<double> denPoints;
62        opaValues.push_back(0.0);
63        opaValues.push_back(1.0);
64        bbSetInputDensityPoints(denPoints);
65        bbSetInputOpacityValues(opaValues);
66        bbSetInputMinColorWindow(0.0);
67        bbSetInputMaxColorWindow(255.0);
68
69        opacityTransferFunction = vtkPiecewiseFunction::New();
70        grayTransferFunction = vtkPiecewiseFunction::New();
71
72            mCast        = NULL;
73            mMIP         = NULL;
74            mMapper      = NULL;
75            mVolume      = NULL;
76
77
78    }
79         //---------------------------------------------------------------------
80    void MIPCreator::bbUserInitializeProcessing()
81    {
82
83
84     // Create the pipeline
85     mCast = vtkImageShiftScale::New();
86     mCast->SetOutputScalarTypeToUnsignedChar();
87     mCast->ClampOverflowOn();
88
89
90 }
91
92 //---------------------------------------------------------------------
93    void MIPCreator::bbUserFinalizeProcessing()
94    {
95            if (mCast!=NULL)
96            {
97                    mCast->Delete();
98                    mCast=NULL;
99            }
100
101            if (mMIP!=NULL)
102            {
103                    mMIP->Delete();
104                    mMIP=NULL;
105            }
106
107            if (mMapper!=NULL)
108            {
109                    mMapper->Delete();
110                    mMapper=NULL;
111            }
112
113            if (mVolume!=NULL)
114            {
115                    mVolume->Delete();
116                    mVolume=NULL;
117            }
118    }
119 //---------------------------------------------------------------------
120
121    void MIPCreator::Process()
122    {
123
124
125
126         double ranges[2];
127         vtkImageData *image =  bbGetInputIn();
128 //EED 2017-01-01 Migration VTK7
129 #if (VTK_MAJOR_VERSION <= 5) 
130         image->Update();
131 #endif
132 #if (VTK_MAJOR_VERSION >= 6) 
133         // ..
134 #endif
135         image->GetScalarRange(ranges);
136
137            scale = 255/(ranges[1]/100);
138
139 //EED 2017-01-01 Migration VTK7
140 #if (VTK_MAJOR_VERSION <= 5) 
141        mCast->SetInput( bbGetInputIn() );
142 #endif
143 #if (VTK_MAJOR_VERSION >= 6) 
144        mCast->SetInputData( bbGetInputIn() );
145 #endif
146        mCast->SetScale( scale / 100.0 );
147      //mCast->SetShift( -bbGetInputShift() );
148
149
150
151
152
153
154
155
156
157      DensityPoints = bbGetInputDensityPoints();
158
159      //We assign by default the values of density by regarding at range from the image
160      if(DensityPoints.size()==0)
161      {
162             DensityPoints.push_back(ranges[0]);
163             DensityPoints.push_back(ranges[1]);
164      }
165
166
167      OpacityValues = bbGetInputOpacityValues();
168
169      while(DensityPoints.size()>OpacityValues.size())
170      {
171          OpacityValues.push_back(1.0);
172      }
173
174
175
176       double factor = scale/ 100.0 ;
177
178        double minCF = bbGetInputMinColorWindow();
179        double maxCF = bbGetInputMaxColorWindow();
180
181        grayTransferFunction->AddSegment( minCF , 0.0 , maxCF , 1.0 );
182
183
184
185
186         for(int i =0; i< DensityPoints.size(); i++)
187         {
188          cout<<"MIPCreator::Process::dPoint"<<i<<"::"<<DensityPoints.at(i)<<endl;
189          cout<<"MIPCreator::Process::oPoint"<<i<<"::"<<OpacityValues.at(i)<<endl;
190
191             opacityTransferFunction->AddPoint(DensityPoints.at(i)*factor, OpacityValues.at(i));
192         }
193            //opacityTransferFunction = vtkPiecewiseFunction::New();
194 //         opacityTransferFunction->AddPoint(   0 ,    0.0/100.0 );
195 //         opacityTransferFunction->AddPoint(  85 ,    2.0/100.0 );
196 //         opacityTransferFunction->AddPoint( 160 ,   25.0/100.0 );
197 //         opacityTransferFunction->AddPoint( 210 ,   50.0/100.0 );
198 //         opacityTransferFunction->AddPoint( 255 ,   90.0/100.0 );
199
200
201
202            // Create a set of properties for mip
203            vtkVolumeProperty *mipProperty;
204            mipProperty = vtkVolumeProperty::New();
205            mipProperty->SetScalarOpacity( opacityTransferFunction );
206            mipProperty->SetColor( grayTransferFunction );
207
208 //         mipProperty->SetInterpolationTypeToLinear();
209            mipProperty->SetInterpolationTypeToNearest();
210
211 //         mipProperty->ShadeOff();
212            mipProperty->ShadeOn();
213
214 //         mipProperty->SetAmbient(0.9);
215 //         mipProperty->SetDiffuse(0.9);
216 //         mipProperty->SetSpecular(0.9);
217
218
219
220
221
222         mMIP = vtkVolumeRayCastMIPFunction::New();
223         mMIP->SetMaximizeMethodToScalarValue();
224
225         mMapper = vtkVolumeRayCastMapper::New();
226         mMapper->SetVolumeRayCastFunction(mMIP);
227
228 //EED 2017-01-01 Migration VTK7
229 #if (VTK_MAJOR_VERSION <= 5) 
230         mMapper->SetInput(mCast->GetOutput()); // (smoother.GetOutput())
231 #endif
232 #if (VTK_MAJOR_VERSION >= 6) 
233         mMapper->SetInputData(mCast->GetOutput()); // (smoother.GetOutput())
234 #endif
235
236         mVolume = vtkVolume::New();
237         mVolume->SetMapper(mMapper);
238         mVolume->SetProperty( mipProperty );
239
240
241
242         mMapper->Update();
243
244       bbSetOutputOut(mVolume);
245      //     mVolume->GetProperty()->SetColor( bbGetInputColour()[0],  bbGetInputColour()[1], bbGetInputColour()[2] );
246      //     mVolume->GetProperty()->SetOpacity( bbGetInputOpacity() );
247
248    }
249 }//namespace bbtk
250
251 #endif // _USE_VTK_
252