NorMIT-nav  22.09
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 //---------------------------------------------------------
cx::VolumetricRep::updateVtkImageDataSlot
void updateVtkImageDataSlot()
Definition: cxVolumetricRep.cpp:151
cx::VolumetricRep::VolumetricRep
VolumetricRep()
Definition: cxVolumetricRep.cpp:45
cxVolumeProperty.h
cx::ImageMapperMonitor::create
static ImageMapperMonitorPtr create(vtkVolumePtr volume, ImagePtr image)
Definition: cxImageMapperMonitor.cpp:27
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Image::vtkImageDataChanged
void vtkImageDataChanged(QString uid=QString())
emitted when the vktimagedata are invalidated and must be retrieved anew.
cxVolumetricRep.h
cxImage.h
cx::VolumetricRep::setMaxVolumeSize
void setMaxVolumeSize(long maxVoxels)
set max volume size for rendering. Must be set before setImage()
Definition: cxVolumetricRep.cpp:160
cx::VolumetricRep::mImage
ImagePtr mImage
Definition: cxVolumetricRep.h:95
cx::VolumetricRep::setUseVolumeTextureMapper
void setUseVolumeTextureMapper()
Definition: cxVolumetricRep.cpp:69
cx::VolumetricRep::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxVolumetricRep.cpp:88
vtkImageDataPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
Definition: cxVideoConnectionWidget.h:30
cx::VolumetricRep::mMapper
vtkVolumeMapperPtr mMapper
Definition: cxVolumetricRep.h:91
vtkVolumePtr
vtkSmartPointer< class vtkVolume > vtkVolumePtr
Definition: vtkForwardDeclarations.h:152
cxSlicePlaneClipper.h
cx::VolumetricRep::hasImage
virtual bool hasImage(ImagePtr image) const
check if the reps has the image
Definition: cxVolumetricRep.cpp:126
vtkVolumeTextureMapper3DPtr
vtkSmartPointer< class vtkVolumeTextureMapper3D > vtkVolumeTextureMapper3DPtr
Definition: vtkForwardDeclarations.h:156
cx::Data::transformChanged
void transformChanged()
emitted when transform is changed
cx::VolumetricRep::vtkImageDataChangedSlot
void vtkImageDataChangedSlot()
Definition: cxVolumetricRep.cpp:134
cx::VolumetricRep::transformChangedSlot
void transformChangedSlot()
Definition: cxVolumetricRep.cpp:142
cxTypeConversions.h
cxView.h
vtkForwardDeclarations.h
cx::VolumetricRep::setImage
virtual void setImage(ImagePtr image)
set the reps image
Definition: cxVolumetricRep.cpp:98
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cxImageMapperMonitor.h
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::VolumetricRep::setUseGPUVolumeRayCastMapper
void setUseGPUVolumeRayCastMapper()
Definition: cxVolumetricRep.cpp:58
cx::VolumetricRep::~VolumetricRep
virtual ~VolumetricRep()
Definition: cxVolumetricRep.cpp:55
cx::VolumetricRep::getImage
virtual ImagePtr getImage()
get the reps image
Definition: cxVolumetricRep.cpp:93
cx::VolumetricRep::mMaxVoxels
long mMaxVoxels
always resample volume below this size.
Definition: cxVolumetricRep.h:93
cx::VolumetricRep::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxVolumetricRep.cpp:83
cxImageTF3D.h
vtkGPUVolumeRayCastMapperPtr
vtkSmartPointer< class vtkGPUVolumeRayCastMapper > vtkGPUVolumeRayCastMapperPtr
Definition: cxVolumetricRep.cpp:41
cx::VolumeProperty
Definition: cxVolumeProperty.h:34
cx::VolumetricRep::mVolume
vtkVolumePtr mVolume
Definition: cxVolumetricRep.h:92
cx::VolumetricRep::mVolumeProperty
cx::VolumePropertyPtr mVolumeProperty
Definition: cxVolumetricRep.h:90
cx::VolumetricBaseRep
Display a volume in 3D.
Definition: cxVolumetricRep.h:42
cx::VolumetricRep::mMonitor
cx::ImageMapperMonitorPtr mMonitor
helper object for visualizing clipping/cropping
Definition: cxVolumetricRep.h:96