1 /*=========================================================================
3 Module: $RCSfile: bbvtkMIPCreator.cxx,v $
5 Date: $Date: 2011/05/04 12:23:55 $
6 Version: $Revision: 1.11 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
38 #include <vtkVolumeProperty.h>
39 #include <vtkPiecewiseFunction.h>
41 #include "bbvtkMIPCreator.h"
42 #include "bbvtkPackage.h"
46 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MIPCreator)
47 BBTK_BLACK_BOX_IMPLEMENTATION(MIPCreator,bbtk::AtomicBlackBox);
49 //---------------------------------------------------------------------
50 void MIPCreator::bbUserSetDefaultValues()
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);
64 opacityTransferFunction = vtkPiecewiseFunction::New();
65 grayTransferFunction = vtkPiecewiseFunction::New();
74 //---------------------------------------------------------------------
75 void MIPCreator::bbUserInitializeProcessing()
79 // Create the pipeline
80 mCast = vtkImageShiftScale::New();
81 mCast->SetOutputScalarTypeToUnsignedChar();
82 mCast->ClampOverflowOn();
87 //---------------------------------------------------------------------
88 void MIPCreator::bbUserFinalizeProcessing()
114 //---------------------------------------------------------------------
116 void MIPCreator::Process()
122 vtkImageData *image = bbGetInputIn();
124 image->GetScalarRange(ranges);
126 scale = 255/(ranges[1]/100);
128 mCast->SetInput( bbGetInputIn() );
129 mCast->SetScale( scale / 100.0 );
130 //mCast->SetShift( -bbGetInputShift() );
140 DensityPoints = bbGetInputDensityPoints();
142 //We assign by default the values of density by regarding at range from the image
143 if(DensityPoints.size()==0)
145 DensityPoints.push_back(ranges[0]);
146 DensityPoints.push_back(ranges[1]);
150 OpacityValues = bbGetInputOpacityValues();
152 while(DensityPoints.size()>OpacityValues.size())
154 OpacityValues.push_back(1.0);
159 double factor = scale/ 100.0 ;
161 double minCF = bbGetInputMinColorWindow();
162 double maxCF = bbGetInputMaxColorWindow();
164 grayTransferFunction->AddSegment( minCF , 0.0 , maxCF , 1.0 );
169 for(int i =0; i< DensityPoints.size(); i++)
171 cout<<"MIPCreator::Process::dPoint"<<i<<"::"<<DensityPoints.at(i)<<endl;
172 cout<<"MIPCreator::Process::oPoint"<<i<<"::"<<OpacityValues.at(i)<<endl;
174 opacityTransferFunction->AddPoint(DensityPoints.at(i)*factor, OpacityValues.at(i));
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 );
185 // Create a set of properties for mip
186 vtkVolumeProperty *mipProperty;
187 mipProperty = vtkVolumeProperty::New();
188 mipProperty->SetScalarOpacity( opacityTransferFunction );
189 mipProperty->SetColor( grayTransferFunction );
191 // mipProperty->SetInterpolationTypeToLinear();
192 mipProperty->SetInterpolationTypeToNearest();
194 // mipProperty->ShadeOff();
195 mipProperty->ShadeOn();
197 // mipProperty->SetAmbient(0.9);
198 // mipProperty->SetDiffuse(0.9);
199 // mipProperty->SetSpecular(0.9);
205 mMIP = vtkVolumeRayCastMIPFunction::New();
206 mMIP->SetMaximizeMethodToScalarValue();
208 mMapper = vtkVolumeRayCastMapper::New();
209 mMapper->SetVolumeRayCastFunction(mMIP);
210 mMapper->SetInput(mCast->GetOutput()); // (smoother.GetOutput())
212 mVolume = vtkVolume::New();
213 mVolume->SetMapper(mMapper);
214 mVolume->SetProperty( mipProperty );
220 bbSetOutputOut(mVolume);
221 // mVolume->GetProperty()->SetColor( bbGetInputColour()[0], bbGetInputColour()[1], bbGetInputColour()[2] );
222 // mVolume->GetProperty()->SetOpacity( bbGetInputOpacity() );