2 #include "volumerenderermanagerdata.h"
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
8 #include "vtkStripper.h"
9 #include "boxSurfaceObserver.h"
10 #include "vtkProperty.h"
15 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname){
17 Initialize(vol, dataname);
22 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname){
24 Initialize(vol, dataname);
25 render->AddActor(this->getProp3D());
29 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu, std::string dataname){
30 Initialize(vol, dataname, usegpu);
33 void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname, bool usegpu){
37 _tfun = vtkPiecewiseFunction::New();
38 _ctfun = vtkColorTransferFunction::New();
40 _volumePlanes = vtkPlanes::New();
42 _volumeProperty = vtkVolumeProperty::New();
43 _volumeProperty->SetInterpolationTypeToLinear();
44 //_volumeProperty->ShadeOn();
45 _volumeProperty->DisableGradientOpacityOn();
46 _volumeProperty->SetColor(_ctfun);
47 _volumeProperty->SetScalarOpacity(_tfun );
50 _newvol = vtkVolume::New();
51 _newvol->SetProperty(_volumeProperty );
55 _compositeFunction = 0;
62 if(usegpu && _vol->GetDataDimension() > 2){
63 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
64 _volumeMappergpu->SetClippingPlanes( _volumePlanes );
65 _volumeMappergpu->AutoAdjustSampleDistancesOn();
67 _newvol->SetMapper(_volumeMappergpu );
69 _volumeMappergpu->SetInput( _vol );
70 _volumeMappergpu->Update();
72 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
73 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
75 _volumeMapper = vtkVolumeRayCastMapper::New();
76 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
77 _volumeMapper->SetClippingPlanes( _volumePlanes );
78 _volumeMapper->AutoAdjustSampleDistancesOn();
80 _newvol->SetMapper(_volumeMapper );
82 _volumeMapper->SetInput( _vol );
83 _volumeMapper->Update();
87 vtkVolumeMapper *volMapperTmp;
88 if(usegpu && _vol->GetDataDimension() > 2){
89 #if (VTK_MAYOR_VERSION>=5 && VTK_MINOR_VERSION>=6)
90 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
91 _volumeMappergpu->AutoAdjustSampleDistancesOn();
92 volMapperTmp = _volumeMappergpu;
94 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
95 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
96 _volumeMapper = vtkVolumeRayCastMapper::New();
97 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
98 _volumeMapper->AutoAdjustSampleDistancesOn();
99 volMapperTmp = _volumeMapper;
102 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
103 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
104 _volumeMapper = vtkVolumeRayCastMapper::New();
105 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
106 _volumeMapper->AutoAdjustSampleDistancesOn();
107 volMapperTmp = _volumeMapper;
110 volMapperTmp->SetClippingPlanes( _volumePlanes );
111 _newvol->SetMapper(volMapperTmp );
112 volMapperTmp->SetInput( _vol );
113 volMapperTmp->Update();
118 VolumeRendererManagerData::~VolumeRendererManagerData()
123 _volumePlanes->Delete();
124 _volumeProperty->Delete();
127 if(_compositeFunction)
128 _compositeFunction->Delete();
130 _MIPFunction->Delete();
132 _volumeMapper->Delete();
134 _volumeMappergpu->Delete();
136 DisableBoundingBox();
141 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
143 //EED9Juin2011 if(_volumeMappergpu){
144 if(_boxWidgetS1==NULL){
145 _boxWidgetS1 = vtkBoxWidget::New();
146 _boxWidgetS1->SetInteractor( interactor );
147 _boxWidgetS1->SetPlaceFactor(1.01);
149 _boxWidgetS1->SetInput( _vol );
150 _boxWidgetS1->InsideOutOn();
151 _boxWidgetS1->PlaceWidget();
153 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
155 if (_volumeMapper!=0){
156 callback->SetMapper(_volumeMapper);
158 callback->SetMapper(_volumeMappergpu);
161 _boxWidgetS1->AddObserver(vtkCommand::InteractionEvent, callback);
163 _boxWidgetS1->EnabledOn();
164 _boxWidgetS1->GetSelectedFaceProperty()->SetOpacity(0.0);
165 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<<endl;
167 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<<endl;
168 _boxWidgetS1->EnabledOn();
173 void VolumeRendererManagerData::DisableBoundingBox(){
175 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
176 _boxWidgetS1->EnabledOff();
177 //_boxWidgetS1->Delete();
185 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
186 std::vector<double>& red,
187 std::vector<double>& green,
188 std::vector<double>& blue)
191 _ctfun->RemoveAllPoints();
192 for(unsigned int i = 0; i < greylevelcolors.size();i++){
193 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
194 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
202 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
204 _tfun->RemoveAllPoints();
205 for(unsigned int i = 0; i < greylevel.size();i++){
206 _tfun->AddPoint(greylevel[i], value[i]);
207 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
215 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value){
216 std::vector<double> valuevector;
217 for(unsigned i = 0; i < greylevel.size(); i++){
218 valuevector.push_back(value);
220 setVolumeOpacity(greylevel, valuevector);
224 ** Check if the variables are setted correctly
226 void VolumeRendererManagerData::checkInvariant()throw (char *){
227 if(!_compositeFunction){
228 throw "No composite function initialized";
231 throw "No MIP function initialized";
233 if(!_volumeMapper && !_volumeMappergpu){
234 throw "No volume mapper initialized";
239 ** Check if the variables are setted correctly
241 void VolumeRendererManagerData::Update(){
247 vtkProp3D* VolumeRendererManagerData::getProp3D(){
248 return this->_newvol;
251 ** return the id from the daat
253 int VolumeRendererManagerData::getId(){
259 void VolumeRendererManagerData::setId(int propid){
266 std::string VolumeRendererManagerData::getDataname(){
272 void VolumeRendererManagerData::setDataname(std::string dataname){
273 _dataname = dataname;
276 void VolumeRendererManagerData::changeCompositeMIPFunction(int function){
280 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
282 _volumeMapper->SetVolumeRayCastFunction(_MIPFunction);
288 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
289 _ctfun->RemoveAllPoints();
290 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
291 for(int i = 0; i < colort->GetSize(); i++){
293 colort->GetNodeValue(i, val);
294 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
295 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);