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