CustusX  15.8
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 #include <vtkVolumeTextureMapper3D.h>
40 
41 //#if VTK_MINOR_VERSION >= 6
42  #include <vtkGPUVolumeRayCastMapper.h>
43 //#endif
44 
45 #include <vtkImageData.h>
46 #include <vtkVolume.h>
47 #include <vtkRenderer.h>
48 #include <vtkMatrix4x4.h>
49 
50 #include "cxView.h"
51 #include "cxImage.h"
52 #include "cxImageTF3D.h"
53 #include "cxSlicePlaneClipper.h"
54 #include "cxTypeConversions.h"
55 #include "vtkForwardDeclarations.h"
56 
57 #include "cxImageMapperMonitor.h"
58 
59 #include "cxVolumeProperty.h"
60 
61 typedef vtkSmartPointer<class vtkGPUVolumeRayCastMapper> vtkGPUVolumeRayCastMapperPtr;
62 
63 namespace cx
64 {
67  mVolume(vtkVolumePtr::New()),
68  mVolumeProperty(cx::VolumeProperty::create()),
69  mMaxVoxels(0)
70 {
72  mVolume->SetProperty(mVolumeProperty->getVolumeProperty());
73 }
74 
76 {}
77 
79 {
80 //#if (( VTK_MINOR_VERSION >= 6 )||( VTK_MAJOR_VERSION >5 ))
81  vtkGPUVolumeRayCastMapperPtr mapper = vtkGPUVolumeRayCastMapperPtr::New();
82  mMapper = mapper;
83  mMapper->SetBlendModeToComposite();
84  mVolume->SetMapper( mMapper );
85 //#endif
86 }
87 
89 {
90  vtkVolumeTextureMapper3DPtr mapper = vtkVolumeTextureMapper3DPtr::New();
91  mMapper = mapper;
92 
93  // from snws
94  mapper->SetPreferredMethodToNVidia();
95  mMapper->SetBlendModeToComposite();
96 
97  mVolume->SetMapper( mMapper );
98 }
99 
101 {
102  view->getRenderer()->AddVolume(mVolume);
103 }
104 
106 {
107  view->getRenderer()->RemoveVolume(mVolume);
108 }
109 
111 {
112  return mImage;
113 }
114 
116 {
117  if (image==mImage)
118  {
119  return;
120  }
121 
122  if (mImage)
123  {
124  mVolumeProperty->setImage(ImagePtr());
127  mMonitor.reset();
128  mMapper->SetInputData( (vtkImageData*)NULL );
129  }
130 
131  mImage = image;
132 
133  if (mImage)
134  {
137  mVolumeProperty->setImage(mImage);
138  this->vtkImageDataChangedSlot();
140  }
141 }
142 
144 {
145  return (mImage == image);
146 }
147 
152 {
153  this->updateVtkImageDataSlot();
154  this->transformChangedSlot();
155 }
156 
160 {
161  if (!mImage)
162  {
163  return;
164  }
165  mVolume->SetUserMatrix(mImage->get_rMd().getVtkMatrix());
166 }
167 
169 {
170  if (!mImage)
171  return;
172 
173  vtkImageDataPtr volume = mImage->resample(this->mMaxVoxels);
174  mMapper->SetInputData(volume);
175 }
176 
178 {
179  mMaxVoxels = maxVoxels;
180 }
181 
182 
183 //---------------------------------------------------------
184 } // namespace cx
185 //---------------------------------------------------------
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