Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #include "cxVolumetricRep.h"
35 
36 #include <vtkPiecewiseFunction.h>
37 #include <vtkColorTransferFunction.h>
38 #include <vtkVolumeProperty.h>
39 
40 #ifndef CX_VTK_OPENGL2
41 #include <vtkVolumeTextureMapper3D.h>
42 #else
43 #include <vtkSmartVolumeMapper.h>
44 #endif
45 
46 //#if VTK_MINOR_VERSION >= 6
47  #include <vtkGPUVolumeRayCastMapper.h>
48 //#endif
49 
50 #include <vtkImageData.h>
51 #include <vtkVolume.h>
52 #include <vtkRenderer.h>
53 #include <vtkMatrix4x4.h>
54 
55 #include "cxView.h"
56 #include "cxImage.h"
57 #include "cxImageTF3D.h"
58 #include "cxSlicePlaneClipper.h"
59 #include "cxTypeConversions.h"
60 #include "vtkForwardDeclarations.h"
61 
62 #include "cxImageMapperMonitor.h"
63 
64 #include "cxVolumeProperty.h"
65 
66 typedef vtkSmartPointer<class vtkGPUVolumeRayCastMapper> vtkGPUVolumeRayCastMapperPtr;
67 
68 namespace cx
69 {
72  mVolume(vtkVolumePtr::New()),
73  mVolumeProperty(cx::VolumeProperty::create()),
74  mMaxVoxels(0)
75 {
77  mVolume->SetProperty(mVolumeProperty->getVolumeProperty());
78 }
79 
81 {}
82 
84 {
85 //#if (( VTK_MINOR_VERSION >= 6 )||( VTK_MAJOR_VERSION >5 ))
86  vtkGPUVolumeRayCastMapperPtr mapper = vtkGPUVolumeRayCastMapperPtr::New();
87  mMapper = mapper;
88  mMapper->SetBlendModeToComposite();
89  mVolume->SetMapper( mMapper );
90 //#endif
91 }
92 
93 //TODO: Use vtkSmartVolumeMapper instead
95 {
96  vtkVolumeTextureMapper3DPtr mapper = vtkVolumeTextureMapper3DPtr::New();
97  mMapper = mapper;
98 
99  // from snws
100 #ifndef CX_VTK_OPENGL2
101  mapper->SetPreferredMethodToNVidia();
102 #endif
103  mMapper->SetBlendModeToComposite();
104 
105  mVolume->SetMapper( mMapper );
106 }
107 
109 {
110  view->getRenderer()->AddVolume(mVolume);
111 }
112 
114 {
115  view->getRenderer()->RemoveVolume(mVolume);
116 }
117 
119 {
120  return mImage;
121 }
122 
124 {
125  if (image==mImage)
126  {
127  return;
128  }
129 
130  if (mImage)
131  {
132  mVolumeProperty->setImage(ImagePtr());
135  mMonitor.reset();
136  mMapper->SetInputData( (vtkImageData*)NULL );
137  }
138 
139  mImage = image;
140 
141  if (mImage)
142  {
145  mVolumeProperty->setImage(mImage);
146  this->vtkImageDataChangedSlot();
148  }
149 }
150 
152 {
153  return (mImage == image);
154 }
155 
160 {
161  this->updateVtkImageDataSlot();
162  this->transformChangedSlot();
163 }
164 
168 {
169  if (!mImage)
170  {
171  return;
172  }
173  mVolume->SetUserMatrix(mImage->get_rMd().getVtkMatrix());
174 }
175 
177 {
178  if (!mImage)
179  return;
180 
181  vtkImageDataPtr volume = mImage->resample(this->mMaxVoxels);
182  mMapper->SetInputData(volume);
183 }
184 
186 {
187  mMaxVoxels = maxVoxels;
188 }
189 
190 
191 //---------------------------------------------------------
192 } // namespace cx
193 //---------------------------------------------------------
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:48
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 setUseVolumeTextureMapper()
void vtkImageDataChanged()
emitted when the vktimagedata are invalidated and must be retrieved anew.
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