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