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;
60 if(usegpu && _vol->GetDataDimension() > 2){
61 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
62 _volumeMappergpu->SetClippingPlanes( _volumePlanes );
63 _volumeMappergpu->AutoAdjustSampleDistancesOn();
65 _newvol->SetMapper(_volumeMappergpu );
67 _volumeMappergpu->SetInput( _vol );
68 _volumeMappergpu->Update();
70 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
71 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
73 _volumeMapper = vtkVolumeRayCastMapper::New();
74 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
75 _volumeMapper->SetClippingPlanes( _volumePlanes );
76 _volumeMapper->AutoAdjustSampleDistancesOn();
78 _newvol->SetMapper(_volumeMapper );
80 _volumeMapper->SetInput( _vol );
81 _volumeMapper->Update();
85 vtkVolumeMapper *volMapperTmp;
86 if(usegpu && _vol->GetDataDimension() > 2){
87 #if (VTK_MAYOR_VERSION>=5 && VTK_MINOR_VERSION>=6)
88 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
89 _volumeMappergpu->AutoAdjustSampleDistancesOn();
90 volMapperTmp = _volumeMappergpu;
92 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
93 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
94 _volumeMapper = vtkVolumeRayCastMapper::New();
95 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
96 _volumeMapper->AutoAdjustSampleDistancesOn();
97 volMapperTmp = _volumeMapper;
100 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
101 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
102 _volumeMapper = vtkVolumeRayCastMapper::New();
103 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
104 _volumeMapper->AutoAdjustSampleDistancesOn();
105 volMapperTmp = _volumeMapper;
108 volMapperTmp->SetClippingPlanes( _volumePlanes );
109 _newvol->SetMapper(volMapperTmp );
110 volMapperTmp->SetInput( _vol );
111 volMapperTmp->Update();
116 VolumeRendererManagerData::~VolumeRendererManagerData()
121 _volumePlanes->Delete();
122 _volumeProperty->Delete();
125 if(_compositeFunction)
126 _compositeFunction->Delete();
128 _MIPFunction->Delete();
130 _volumeMapper->Delete();
132 _volumeMappergpu->Delete();
134 DisableBoundingBox();
139 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
141 //EED9Juin2011 if(_volumeMappergpu){
142 if(_boxWidgetS1==NULL){
143 _boxWidgetS1 = vtkBoxWidget::New();
144 _boxWidgetS1->SetInteractor( interactor );
145 _boxWidgetS1->SetPlaceFactor(1.01);
147 _boxWidgetS1->SetInput( _vol );
148 _boxWidgetS1->InsideOutOn();
149 _boxWidgetS1->PlaceWidget();
151 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
153 if (_volumeMapper!=0){
154 callback->SetMapper(_volumeMapper);
156 callback->SetMapper(_volumeMappergpu);
159 _boxWidgetS1->AddObserver(vtkCommand::InteractionEvent, callback);
161 _boxWidgetS1->EnabledOn();
162 _boxWidgetS1->GetSelectedFaceProperty()->SetOpacity(0.0);
163 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<<endl;
165 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<<endl;
166 _boxWidgetS1->EnabledOn();
171 void VolumeRendererManagerData::DisableBoundingBox(){
173 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
174 _boxWidgetS1->EnabledOff();
175 //_boxWidgetS1->Delete();
183 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
184 std::vector<double>& red,
185 std::vector<double>& green,
186 std::vector<double>& blue)
189 _ctfun->RemoveAllPoints();
190 for(unsigned int i = 0; i < greylevelcolors.size();i++){
191 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
192 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
200 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
202 _tfun->RemoveAllPoints();
203 for(unsigned int i = 0; i < greylevel.size();i++){
204 _tfun->AddPoint(greylevel[i], value[i]);
205 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
213 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value){
214 std::vector<double> valuevector;
215 for(unsigned i = 0; i < greylevel.size(); i++){
216 valuevector.push_back(value);
218 setVolumeOpacity(greylevel, valuevector);
222 ** Check if the variables are setted correctly
224 void VolumeRendererManagerData::checkInvariant()throw (char *){
225 if(!_compositeFunction){
226 throw "No composite function initialized";
229 throw "No MIP function initialized";
231 if(!_volumeMapper && !_volumeMappergpu){
232 throw "No volume mapper initialized";
237 ** Check if the variables are setted correctly
239 void VolumeRendererManagerData::Update(){
245 vtkProp3D* VolumeRendererManagerData::getProp3D(){
246 return this->_newvol;
249 ** return the id from the daat
251 int VolumeRendererManagerData::getId(){
257 void VolumeRendererManagerData::setId(int propid){
264 std::string VolumeRendererManagerData::getDataname(){
270 void VolumeRendererManagerData::setDataname(std::string dataname){
271 _dataname = dataname;
274 void VolumeRendererManagerData::changeCompositeMIPFunction(int function){
278 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
280 _volumeMapper->SetVolumeRayCastFunction(_MIPFunction);
286 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
287 _ctfun->RemoveAllPoints();
288 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
289 for(int i = 0; i < colort->GetSize(); i++){
291 colort->GetNodeValue(i, val);
292 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
293 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);