Fraxinus  17.12-rc1
An IGT application
cxMultiVolume3DRepProducer.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 
34 
35 #include "cxVolumetricRep.h"
36 #include <vtkImageData.h>
37 #include "cxImage2DRep3D.h"
38 #include "cxView.h"
39 #include "cxTypeConversions.h"
40 
42 #include "cxConfig.h"
43 #include "cxRepManager.h"
44 #include "cxLogger.h"
45 
46 namespace cx
47 {
48 
49 
51 {
52  mMaxRenderSize = 10 * pow(10.0,6);
53 }
54 
56 {
57 }
58 
60 {
61  if (view==mView)
62  return;
63  this->clearReps();
64  mView = view;
65  this->fillReps();
66 }
67 
68 //QStringList MultiVolume3DRepProducer::getAvailableVisualizers()
69 //{
70 // QStringList retval;
71 // retval << "vtkVolumeTextureMapper3D";
72 // retval << "vtkGPUVolumeRayCastMapper";
73 //#ifdef CX_BUILD_MEHDI_VTKMULTIVOLUME
74 // retval << "vtkOpenGLGPUMultiVolumeRayCastMapper";
75 //#endif //CX_BUILD_MEHDI_VTKMULTIVOLUME
76 
77 // return retval;
78 //}
79 
80 //std::map<QString, QString> MultiVolume3DRepProducer::getAvailableVisualizerDisplayNames()
81 //{
82 // std::map<QString, QString> names;
83 // names["vtkVolumeTextureMapper3D"] = "Texture (single volume)";
84 // names["vtkGPUVolumeRayCastMapper"] = "Raycast GPU (single volume)";
85 // names["vtkOpenGLGPUMultiVolumeRayCastMapper"] = "Mehdi Raycast GPU (multi volume)";
86 // return names;
87 //}
88 
90 {
91  mMaxRenderSize = voxels;
92  if (mMaxRenderSize<1)
93  mMaxRenderSize = 10 * pow(10.0,6);
94 
95  this->updateRepsInView();
96 }
97 
99 {
100  return mMaxRenderSize;
101 }
102 
104 {
105  mVisualizerType = type;
106 
107  this->updateRepsInView();
108 }
109 
110 bool MultiVolume3DRepProducer::contains(ImagePtr image) const
111 {
112  if (std::count(m2DImages.begin(), m2DImages.end(), image))
113  return true;
114  if (std::count(m3DImages.begin(), m3DImages.end(), image))
115  return true;
116  return false;
117 }
118 
120 {
121  if (this->contains(image))
122  return;
123 
124  if (image)
125  {
126  connect(image.get(), SIGNAL(clipPlanesChanged()), this, SIGNAL(imagesChanged()));
127  connect(image.get(), SIGNAL(cropBoxChanged()), this, SIGNAL(imagesChanged()));
128  }
129  else
130  return;
131 
132  if(image && image->is2D())
133  m2DImages.push_back(image);
134  else
135  m3DImages.push_back(image);
136  emit imagesChanged();
137 
138  this->updateRepsInView();
139 }
140 
142 {
143  ImagePtr removedImage;
144  removedImage = this->removeImageFromVector(uid, m2DImages);
145  if(!removedImage)
146  removedImage = this->removeImageFromVector(uid, m3DImages);
147 
148  if (removedImage)
149  {
150  disconnect(removedImage.get(), SIGNAL(clipPlanesChanged()), this, SIGNAL(imagesChanged()));
151  disconnect(removedImage.get(), SIGNAL(cropBoxChanged()), this, SIGNAL(imagesChanged()));
152  }
153 
154  emit imagesChanged();
155  this->updateRepsInView();
156 }
157 
158 ImagePtr MultiVolume3DRepProducer::removeImageFromVector(QString uid, std::vector<ImagePtr> &images)
159 {
160  ImagePtr retval;
161  for (unsigned i=0; i<images.size(); ++i)
162  {
163  if (images[i]->getUid()!=uid)
164  continue;
165  retval = images[i];
166  images.erase(images.begin()+i);
167  break;
168  }
169  return retval;
170 }
171 
173 {
174  return mReps;
175 }
176 
177 void MultiVolume3DRepProducer::updateRepsInView()
178 {
179  this->clearReps();
180  this->fillReps();
181 }
182 
183 void MultiVolume3DRepProducer::clearReps()
184 {
185  this->removeRepsFromView();
186  mReps.clear();
187 }
188 
190 {
191  if (!mView)
192  return;
193 
194  for (unsigned i=0; i<mReps.size(); ++i)
195  mView->removeRep(mReps[i]);
196 }
197 
198 void MultiVolume3DRepProducer::fillReps()
199 {
200  this->rebuildReps();
201  this->addRepsToView();
202 }
203 
204 void MultiVolume3DRepProducer::addRepsToView()
205 {
206  if (!mView)
207  return;
208 
209  for (unsigned i=0; i<mReps.size(); ++i)
210  mView->addRep(mReps[i]);
211 }
212 
213 void MultiVolume3DRepProducer::rebuildReps()
214 {
215  if(!m2DImages.empty())
216  this->rebuild2DReps();
217  if(!m3DImages.empty())
218  this->rebuild3DReps();
219 }
220 
221 void MultiVolume3DRepProducer::rebuild2DReps()
222 {
223  for (unsigned i=0; i<m2DImages.size(); ++i)
224  this->buildSscImage2DRep3D(m2DImages[i]);
225 }
226 
227 void MultiVolume3DRepProducer::rebuild3DReps()
228 {
229  if (this->isSingleVolumeRenderer())
230  {
231  for (unsigned i=0; i<m3DImages.size(); ++i)
232  this->buildSingleVolumeRenderer(m3DImages[i]);
233  }
234  else if (mVisualizerType=="vtkOpenGLGPUMultiVolumeRayCastMapper")
235  {
236  this->buildVtkOpenGLGPUMultiVolumeRayCastMapper();
237  }
238  else
239  {
240  reportError(QString("No visualizer found for string=%1").arg(mVisualizerType));
241  }
242 }
243 
244 void MultiVolume3DRepProducer::buildVtkOpenGLGPUMultiVolumeRayCastMapper()
245 {
246 #ifdef CX_BUILD_MEHDI_VTKMULTIVOLUME
247  MehdiGPURayCastMultiVolumeRepPtr rep = MehdiGPURayCastMultiVolumeRep::New("");
248  rep->setMaxVolumeSize(this->getMaxRenderSize());
249  rep->setImages(m3DImages);
250  mReps.push_back(rep);
251 #endif //CX_BUILD_MEHDI_VTKMULTIVOLUME
252 }
253 
254 void MultiVolume3DRepProducer::buildSingleVolumeRenderer(ImagePtr image)
255 {
256  if (mVisualizerType=="vtkVolumeTextureMapper3D")
257  {
258  this->buildVtkVolumeTextureMapper3D(image);
259  }
260  else if (mVisualizerType=="vtkGPUVolumeRayCastMapper")
261  {
262  this->buildVtkGPUVolumeRayCastMapper(image);
263  }
264  else
265  {
266  reportError(QString("No visualizer found for string=%1").arg(mVisualizerType));
267  return;
268  }
269 }
270 
271 bool MultiVolume3DRepProducer::isSingleVolumeRenderer() const
272 {
273  QStringList singleTypes;
274  singleTypes << "vtkVolumeTextureMapper3D" << "vtkGPUVolumeRayCastMapper";
275  return singleTypes.count(mVisualizerType);
276 }
277 
278 void MultiVolume3DRepProducer::buildSscImage2DRep3D(ImagePtr image)
279 {
281  rep->setImage(image);
282  mReps.push_back(rep);
283 }
284 
285 void MultiVolume3DRepProducer::buildVtkVolumeTextureMapper3D(ImagePtr image)
286 {
287  // attempt to reuse this time-consuming rep:
288 // VolumetricRepPtr rep = RepManager::getInstance()->getCachedRep<VolumetricRep>(image->getUid());
289 
291  rep->setUseVolumeTextureMapper();
292 
293  rep->setMaxVolumeSize(this->getMaxRenderSize());
294  rep->setImage(image);
295  mReps.push_back(rep);
296 }
297 
298 void MultiVolume3DRepProducer::buildVtkGPUVolumeRayCastMapper(ImagePtr image)
299 {
301  rep->setUseGPUVolumeRayCastMapper();
302 
303  rep->setMaxVolumeSize(this->getMaxRenderSize());
304  rep->setImage(image);
305  mReps.push_back(rep);
306 }
307 
308 } // namespace cx
void reportError(QString msg)
Definition: cxLogger.cpp:92
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
boost::shared_ptr< class View > ViewPtr
boost::shared_ptr< class MehdiGPURayCastMultiVolumeRep > MehdiGPURayCastMultiVolumeRepPtr
boost::shared_ptr< class Image2DRep3D > Image2DRep3DPtr
static VolumetricRepPtr New(QString uid="")
static Image2DRep3DPtr New(QString uid="")
boost::shared_ptr< class VolumetricRep > VolumetricRepPtr
Namespace for all CustusX production code.