2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbvtkMIPCreator.cxx,v $
32 Date: $Date: 2012/11/16 08:51:58 $
33 Version: $Revision: 1.12 $
34 =========================================================================*/
43 #include <vtkVolumeProperty.h>
44 #include <vtkPiecewiseFunction.h>
46 #include "bbvtkMIPCreator.h"
47 #include "bbvtkPackage.h"
51 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MIPCreator)
52 BBTK_BLACK_BOX_IMPLEMENTATION(MIPCreator,bbtk::AtomicBlackBox);
54 //---------------------------------------------------------------------
55 void MIPCreator::bbUserSetDefaultValues()
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);
69 opacityTransferFunction = vtkPiecewiseFunction::New();
70 grayTransferFunction = vtkPiecewiseFunction::New();
79 //---------------------------------------------------------------------
80 void MIPCreator::bbUserInitializeProcessing()
84 // Create the pipeline
85 mCast = vtkImageShiftScale::New();
86 mCast->SetOutputScalarTypeToUnsignedChar();
87 mCast->ClampOverflowOn();
92 //---------------------------------------------------------------------
93 void MIPCreator::bbUserFinalizeProcessing()
119 //---------------------------------------------------------------------
121 void MIPCreator::Process()
127 vtkImageData *image = bbGetInputIn();
129 image->GetScalarRange(ranges);
131 scale = 255/(ranges[1]/100);
133 mCast->SetInput( bbGetInputIn() );
134 mCast->SetScale( scale / 100.0 );
135 //mCast->SetShift( -bbGetInputShift() );
145 DensityPoints = bbGetInputDensityPoints();
147 //We assign by default the values of density by regarding at range from the image
148 if(DensityPoints.size()==0)
150 DensityPoints.push_back(ranges[0]);
151 DensityPoints.push_back(ranges[1]);
155 OpacityValues = bbGetInputOpacityValues();
157 while(DensityPoints.size()>OpacityValues.size())
159 OpacityValues.push_back(1.0);
164 double factor = scale/ 100.0 ;
166 double minCF = bbGetInputMinColorWindow();
167 double maxCF = bbGetInputMaxColorWindow();
169 grayTransferFunction->AddSegment( minCF , 0.0 , maxCF , 1.0 );
174 for(int i =0; i< DensityPoints.size(); i++)
176 cout<<"MIPCreator::Process::dPoint"<<i<<"::"<<DensityPoints.at(i)<<endl;
177 cout<<"MIPCreator::Process::oPoint"<<i<<"::"<<OpacityValues.at(i)<<endl;
179 opacityTransferFunction->AddPoint(DensityPoints.at(i)*factor, OpacityValues.at(i));
181 //opacityTransferFunction = vtkPiecewiseFunction::New();
182 // opacityTransferFunction->AddPoint( 0 , 0.0/100.0 );
183 // opacityTransferFunction->AddPoint( 85 , 2.0/100.0 );
184 // opacityTransferFunction->AddPoint( 160 , 25.0/100.0 );
185 // opacityTransferFunction->AddPoint( 210 , 50.0/100.0 );
186 // opacityTransferFunction->AddPoint( 255 , 90.0/100.0 );
190 // Create a set of properties for mip
191 vtkVolumeProperty *mipProperty;
192 mipProperty = vtkVolumeProperty::New();
193 mipProperty->SetScalarOpacity( opacityTransferFunction );
194 mipProperty->SetColor( grayTransferFunction );
196 // mipProperty->SetInterpolationTypeToLinear();
197 mipProperty->SetInterpolationTypeToNearest();
199 // mipProperty->ShadeOff();
200 mipProperty->ShadeOn();
202 // mipProperty->SetAmbient(0.9);
203 // mipProperty->SetDiffuse(0.9);
204 // mipProperty->SetSpecular(0.9);
210 mMIP = vtkVolumeRayCastMIPFunction::New();
211 mMIP->SetMaximizeMethodToScalarValue();
213 mMapper = vtkVolumeRayCastMapper::New();
214 mMapper->SetVolumeRayCastFunction(mMIP);
215 mMapper->SetInput(mCast->GetOutput()); // (smoother.GetOutput())
217 mVolume = vtkVolume::New();
218 mVolume->SetMapper(mMapper);
219 mVolume->SetProperty( mipProperty );
225 bbSetOutputOut(mVolume);
226 // mVolume->GetProperty()->SetColor( bbGetInputColour()[0], bbGetInputColour()[1], bbGetInputColour()[2] );
227 // mVolume->GetProperty()->SetOpacity( bbGetInputOpacity() );