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