CustusX  18.04-rc1
An IGT application
cxVolumetricRep.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxVolumetricRep.h"
14 
15 #include <vtkPiecewiseFunction.h>
16 #include <vtkColorTransferFunction.h>
17 #include <vtkVolumeProperty.h>
18 
19 #include <vtkSmartVolumeMapper.h>
20 
21 //#if VTK_MINOR_VERSION >= 6
22  #include <vtkGPUVolumeRayCastMapper.h>
23 //#endif
24 
25 #include <vtkImageData.h>
26 #include <vtkVolume.h>
27 #include <vtkRenderer.h>
28 #include <vtkMatrix4x4.h>
29 
30 #include "cxView.h"
31 #include "cxImage.h"
32 #include "cxImageTF3D.h"
33 #include "cxSlicePlaneClipper.h"
34 #include "cxTypeConversions.h"
35 #include "vtkForwardDeclarations.h"
36 
37 #include "cxImageMapperMonitor.h"
38 
39 #include "cxVolumeProperty.h"
40 
41 typedef vtkSmartPointer<class vtkGPUVolumeRayCastMapper> vtkGPUVolumeRayCastMapperPtr;
42 
43 namespace cx
44 {
47  mVolume(vtkVolumePtr::New()),
48  mVolumeProperty(cx::VolumeProperty::create()),
49  mMaxVoxels(0)
50 {
52  mVolume->SetProperty(mVolumeProperty->getVolumeProperty());
53 }
54 
56 {}
57 
59 {
60 //#if (( VTK_MINOR_VERSION >= 6 )||( VTK_MAJOR_VERSION >5 ))
61  vtkGPUVolumeRayCastMapperPtr mapper = vtkGPUVolumeRayCastMapperPtr::New();
62  mMapper = mapper;
63  mMapper->SetBlendModeToComposite();
64  mVolume->SetMapper( mMapper );
65 //#endif
66 }
67 
68 //TODO: Use vtkSmartVolumeMapper instead
70 {
71  vtkVolumeTextureMapper3DPtr mapper = vtkVolumeTextureMapper3DPtr::New();
72  mMapper = mapper;
73 
74  // from snws
75 #ifndef CX_VTK_OPENGL2
76  mapper->SetPreferredMethodToNVidia();
77 #endif
78  mMapper->SetBlendModeToComposite();
79 
80  mVolume->SetMapper( mMapper );
81 }
82 
84 {
85  view->getRenderer()->AddVolume(mVolume);
86 }
87 
89 {
90  view->getRenderer()->RemoveVolume(mVolume);
91 }
92 
94 {
95  return mImage;
96 }
97 
99 {
100  if (image==mImage)
101  {
102  return;
103  }
104 
105  if (mImage)
106  {
107  mVolumeProperty->setImage(ImagePtr());
110  mMonitor.reset();
111  mMapper->SetInputData( (vtkImageData*)NULL );
112  }
113 
114  mImage = image;
115 
116  if (mImage)
117  {
120  mVolumeProperty->setImage(mImage);
121  this->vtkImageDataChangedSlot();
123  }
124 }
125 
127 {
128  return (mImage == image);
129 }
130 
135 {
136  this->updateVtkImageDataSlot();
137  this->transformChangedSlot();
138 }
139 
143 {
144  if (!mImage)
145  {
146  return;
147  }
148  mVolume->SetUserMatrix(mImage->get_rMd().getVtkMatrix());
149 }
150 
152 {
153  if (!mImage)
154  return;
155 
156  vtkImageDataPtr volume = mImage->resample(this->mMaxVoxels);
157  mMapper->SetInputData(volume);
158 }
159 
161 {
162  mMaxVoxels = maxVoxels;
163 }
164 
165 
166 //---------------------------------------------------------
167 } // namespace cx
168 //---------------------------------------------------------
vtkSmartPointer< class vtkGPUVolumeRayCastMapper > vtkGPUVolumeRayCastMapperPtr
vtkSmartPointer< class vtkVolume > vtkVolumePtr
virtual void addRepActorsToViewRenderer(ViewPtr view)
vtkVolumeMapperPtr mMapper
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
static ImageMapperMonitorPtr create(vtkVolumePtr volume, ImagePtr image)
void transformChanged()
emitted when transform is changed
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
long mMaxVoxels
always resample volume below this size.
boost::shared_ptr< class View > ViewPtr
cx::VolumePropertyPtr mVolumeProperty
virtual ImagePtr getImage()
get the reps image
Display a volume in 3D.
virtual bool hasImage(ImagePtr image) const
check if the reps has the image
virtual void setImage(ImagePtr image)
set the reps image
vtkVolumePtr mVolume
void setUseGPUVolumeRayCastMapper()
void vtkImageDataChanged(QString uid=QString())
emitted when the vktimagedata are invalidated and must be retrieved anew.
void setUseVolumeTextureMapper()
vtkSmartPointer< class vtkVolumeTextureMapper3D > vtkVolumeTextureMapper3DPtr
void setMaxVolumeSize(long maxVoxels)
set max volume size for rendering. Must be set before setImage()
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
cx::ImageMapperMonitorPtr mMonitor
helper object for visualizing clipping/cropping
Namespace for all CustusX production code.