2 #include "volumerenderermanagerdata.h"
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
8 #include "vtkStripper.h"
9 #include "boxSurfaceObserver.h"
10 #include "vtkProperty.h"
14 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname){
16 Initialize(vol, dataname);
21 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname){
23 Initialize(vol, dataname);
24 render->AddActor(this->getProp3D());
28 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu, std::string dataname){
29 Initialize(vol, dataname, usegpu);
32 void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname, bool usegpu){
36 _tfun = vtkPiecewiseFunction::New();
37 _ctfun = vtkColorTransferFunction::New();
39 _volumePlanes = vtkPlanes::New();
41 _volumeProperty = vtkVolumeProperty::New();
42 _volumeProperty->SetInterpolationTypeToLinear();
43 //_volumeProperty->ShadeOn();
44 _volumeProperty->DisableGradientOpacityOn();
45 _volumeProperty->SetColor(_ctfun);
46 _volumeProperty->SetScalarOpacity(_tfun );
49 _newvol = vtkVolume::New();
50 _newvol->SetProperty(_volumeProperty );
54 _compositeFunction = 0;
58 if(usegpu && _vol->GetDataDimension() > 2){
59 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
60 _volumeMappergpu->SetClippingPlanes( _volumePlanes );
61 _volumeMappergpu->AutoAdjustSampleDistancesOn();
63 _newvol->SetMapper(_volumeMappergpu );
65 _volumeMappergpu->SetInput( _vol );
66 _volumeMappergpu->Update();
68 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
69 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
71 _volumeMapper = vtkVolumeRayCastMapper::New();
72 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
73 _volumeMapper->SetClippingPlanes( _volumePlanes );
74 _volumeMapper->AutoAdjustSampleDistancesOn();
76 _newvol->SetMapper(_volumeMapper );
78 _volumeMapper->SetInput( _vol );
79 _volumeMapper->Update();
86 VolumeRendererManagerData::~VolumeRendererManagerData(){
90 _volumePlanes->Delete();
91 _volumeProperty->Delete();
94 if(_compositeFunction)
95 _compositeFunction->Delete();
97 _MIPFunction->Delete();
99 _volumeMapper->Delete();
101 _volumeMappergpu->Delete();
103 DisableBoundingBox();
108 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor){
109 if(_volumeMappergpu){
110 _boxWidgetS1 = vtkBoxWidget::New();
111 _boxWidgetS1->SetInteractor( interactor );
112 _boxWidgetS1->SetPlaceFactor(1.01);
114 _boxWidgetS1->SetInput( _vol );
115 _boxWidgetS1->InsideOutOn();
116 _boxWidgetS1->PlaceWidget();
118 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
119 callback->SetMapper(_volumeMappergpu);
120 _boxWidgetS1->AddObserver(vtkCommand::InteractionEvent, callback);
122 _boxWidgetS1->EnabledOn();
123 _boxWidgetS1->GetSelectedFaceProperty()->SetOpacity(0.0);
127 void VolumeRendererManagerData::DisableBoundingBox(){
129 _boxWidgetS1->EnabledOff();
130 _boxWidgetS1->Delete();
138 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
139 std::vector<double>& red,
140 std::vector<double>& green,
141 std::vector<double>& blue)
144 _ctfun->RemoveAllPoints();
145 for(unsigned int i = 0; i < greylevelcolors.size();i++){
146 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
147 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
155 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
157 _tfun->RemoveAllPoints();
158 for(unsigned int i = 0; i < greylevel.size();i++){
159 _tfun->AddPoint(greylevel[i], value[i]);
160 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
168 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value){
169 std::vector<double> valuevector;
170 for(unsigned i = 0; i < greylevel.size(); i++){
171 valuevector.push_back(value);
173 setVolumeOpacity(greylevel, valuevector);
177 ** Check if the variables are setted correctly
179 void VolumeRendererManagerData::checkInvariant()throw (char *){
180 if(!_compositeFunction){
181 throw "No composite function initialized";
184 throw "No MIP function initialized";
186 if(!_volumeMapper && !_volumeMappergpu){
187 throw "No volume mapper initialized";
192 ** Check if the variables are setted correctly
194 void VolumeRendererManagerData::Update(){
200 vtkProp3D* VolumeRendererManagerData::getProp3D(){
201 return this->_newvol;
204 ** return the id from the daat
206 int VolumeRendererManagerData::getId(){
212 void VolumeRendererManagerData::setId(int propid){
219 std::string VolumeRendererManagerData::getDataname(){
225 void VolumeRendererManagerData::setDataname(std::string dataname){
226 _dataname = dataname;
229 void VolumeRendererManagerData::changeCompositeMIPFunction(int function) throw (char *){
233 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
235 _volumeMapper->SetVolumeRayCastFunction(_MIPFunction);
241 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
242 _ctfun->RemoveAllPoints();
243 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
244 for(int i = 0; i < colort->GetSize(); i++){
246 colort->GetNodeValue(i, val);
247 //cout<< val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
248 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);