1 /*=========================================================================
3 Module: $RCSfile: bbvtkMIPCreator.cxx,v $
5 Date: $Date: 2011/03/23 15:26:55 $
6 Version: $Revision: 1.9 $
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()
54 std::vector<double> denPoints;
55 std::vector<double> opaValues;
56 denPoints.push_back(0.0);
57 denPoints.push_back(255.0);
58 opaValues.push_back(0.0);
59 opaValues.push_back(1.0);
60 bbSetInputDensityPoints(denPoints);
61 bbSetInputOpacityValues(opaValues);
62 bbSetInputMinColorWindow(0.0);
63 bbSetInputMaxColorWindow(255.0);
65 opacityTransferFunction = vtkPiecewiseFunction::New();
66 grayTransferFunction = vtkPiecewiseFunction::New();
75 //---------------------------------------------------------------------
76 void MIPCreator::bbUserInitializeProcessing()
80 // Create the pipeline
81 mCast = vtkImageShiftScale::New();
82 mCast->SetOutputScalarTypeToUnsignedChar();
83 mCast->ClampOverflowOn();
85 DensityPoints = bbGetInputDensityPoints();
86 OpacityValues = bbGetInputOpacityValues();
88 while(DensityPoints.size()>OpacityValues.size())
90 OpacityValues.push_back(1.0);
95 //---------------------------------------------------------------------
96 void MIPCreator::bbUserFinalizeProcessing()
122 //---------------------------------------------------------------------
124 void MIPCreator::Process()
130 vtkImageData *image = bbGetInputIn();
132 image->GetScalarRange(ranges);
134 scale = 255/(ranges[1]/100);
136 mCast->SetInput( bbGetInputIn() );
137 mCast->SetScale( scale / 100.0 );
138 //mCast->SetShift( -bbGetInputShift() );
141 double factor = scale/ 100.0 ;
144 double minCF = bbGetInputMinColorWindow();
145 double maxCF = bbGetInputMaxColorWindow();
146 cout<<"MIPCreator::Process::minCF"<<minCF <<endl;
147 cout<<"MIPCreator::Process::maxCF"<<maxCF <<endl;
148 grayTransferFunction->AddSegment( minCF , 0.0 , maxCF , 1.0 );
152 for(int i =0; i< DensityPoints.size(); i++)
155 opacityTransferFunction->AddPoint(DensityPoints.at(i)*factor, OpacityValues.at(i));
157 //opacityTransferFunction = vtkPiecewiseFunction::New();
158 // opacityTransferFunction->AddPoint( 0 , 0.0/100.0 );
159 // opacityTransferFunction->AddPoint( 85 , 2.0/100.0 );
160 // opacityTransferFunction->AddPoint( 160 , 25.0/100.0 );
161 // opacityTransferFunction->AddPoint( 210 , 50.0/100.0 );
162 // opacityTransferFunction->AddPoint( 255 , 90.0/100.0 );
166 // Create a set of properties for mip
167 vtkVolumeProperty *mipProperty;
168 mipProperty = vtkVolumeProperty::New();
169 mipProperty->SetScalarOpacity( opacityTransferFunction );
170 mipProperty->SetColor( grayTransferFunction );
172 // mipProperty->SetInterpolationTypeToLinear();
173 mipProperty->SetInterpolationTypeToNearest();
175 // mipProperty->ShadeOff();
176 mipProperty->ShadeOn();
178 // mipProperty->SetAmbient(0.9);
179 // mipProperty->SetDiffuse(0.9);
180 // mipProperty->SetSpecular(0.9);
186 mMIP = vtkVolumeRayCastMIPFunction::New();
187 mMIP->SetMaximizeMethodToScalarValue();
189 mMapper = vtkVolumeRayCastMapper::New();
190 mMapper->SetVolumeRayCastFunction(mMIP);
191 mMapper->SetInput(mCast->GetOutput()); // (smoother.GetOutput())
193 mVolume = vtkVolume::New();
194 mVolume->SetMapper(mMapper);
195 mVolume->SetProperty( mipProperty );
201 bbSetOutputOut(mVolume);
202 // mVolume->GetProperty()->SetColor( bbGetInputColour()[0], bbGetInputColour()[1], bbGetInputColour()[2] );
203 // mVolume->GetProperty()->SetOpacity( bbGetInputOpacity() );