CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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(this->is2DImage(image))
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 bool MultiVolume3DRepProducer::is2DImage(ImagePtr image) const
255 {
256  if(image)
257  return image->getBaseVtkImageData()->GetDimensions()[2]==1;
258  return false;
259 }
260 
261 void MultiVolume3DRepProducer::buildSingleVolumeRenderer(ImagePtr image)
262 {
263  if (mVisualizerType=="vtkVolumeTextureMapper3D")
264  {
265  this->buildVtkVolumeTextureMapper3D(image);
266  }
267  else if (mVisualizerType=="vtkGPUVolumeRayCastMapper")
268  {
269  this->buildVtkGPUVolumeRayCastMapper(image);
270  }
271  else
272  {
273  reportError(QString("No visualizer found for string=%1").arg(mVisualizerType));
274  return;
275  }
276 }
277 
278 bool MultiVolume3DRepProducer::isSingleVolumeRenderer() const
279 {
280  QStringList singleTypes;
281  singleTypes << "vtkVolumeTextureMapper3D" << "vtkGPUVolumeRayCastMapper";
282  return singleTypes.count(mVisualizerType);
283 }
284 
285 void MultiVolume3DRepProducer::buildSscImage2DRep3D(ImagePtr image)
286 {
288  rep->setImage(image);
289  mReps.push_back(rep);
290 }
291 
292 void MultiVolume3DRepProducer::buildVtkVolumeTextureMapper3D(ImagePtr image)
293 {
294  // attempt to reuse this time-consuming rep:
295 // VolumetricRepPtr rep = RepManager::getInstance()->getCachedRep<VolumetricRep>(image->getUid());
296 
298  rep->setUseVolumeTextureMapper();
299 
300  rep->setMaxVolumeSize(this->getMaxRenderSize());
301  rep->setImage(image);
302  mReps.push_back(rep);
303 }
304 
305 void MultiVolume3DRepProducer::buildVtkGPUVolumeRayCastMapper(ImagePtr image)
306 {
308  rep->setUseGPUVolumeRayCastMapper();
309 
310  rep->setMaxVolumeSize(this->getMaxRenderSize());
311  rep->setImage(image);
312  mReps.push_back(rep);
313 }
314 
315 } // 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