SMIL  1.0.4
DQVtkViewer.hpp
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _D_QVTK_IMAGE_VIEWER_HPP
31 #define _D_QVTK_IMAGE_VIEWER_HPP
32 
33 #include <QApplication>
34 
35 #include "QVtkViewerWidget.h"
36 #include "Gui/include/private/DImageViewer.hpp"
37 #include "Core/include/DTypes.h"
38 #include "Base/include/private/DMeasures.hpp"
39 
40 namespace smil
41 {
42  template <class T> class Image;
43 
57  template <class T>
58  class QVtkViewer : public ImageViewer<T>, protected QVtkViewerWidget
59  {
60  public:
63  {
65  imageImport->SetDataScalarTypeToUnsignedChar();
67  imageImport->SetDataScalarTypeToUnsignedShort();
68  else if (is_same<T, INT16>::value)
69  imageImport->SetDataScalarTypeToShort();
70 
71  setAutoRange(false);
72 
73  colorOpacityTransfertFunction->AddSegment(0, 0., 1, 0.);
74  colorOpacityTransfertFunction->AddSegment(1, 1., ImDtTypes<T>::max(),
75  1.0);
76 
77  initLookup(ImDtTypes<T>::max());
78  }
79 
81  {
83  imageImport->SetDataScalarTypeToUnsignedChar();
85  imageImport->SetDataScalarTypeToUnsignedShort();
86  else if (is_same<T, INT16>::value)
87  imageImport->SetDataScalarTypeToShort();
88 
89  setImage(im);
90 
91  setAutoRange(false);
92 
93  colorOpacityTransfertFunction->AddSegment(0, 0., 1, 0.);
94  colorOpacityTransfertFunction->AddSegment(1, 1., ImDtTypes<T>::max(),
95  1.0);
96 
97  initLookup(ImDtTypes<T>::max());
98  }
99 
100  ~QVtkViewer()
101  {
102  }
103 
104  enum RepresentationType { NONE, COMPOSITE, MIP };
105 
106  virtual void setImage(Image<T> &im)
107  {
109 
110  size_t imSize[3];
111  this->image->getSize(imSize);
112  imageImport->SetWholeExtent(0, imSize[0] - 1, 0, imSize[1] - 1, 0,
113  imSize[2] - 1);
114  imageImport->SetDataExtent(0, imSize[0] - 1, 0, imSize[1] - 1, 0,
115  imSize[2] - 1);
116  imageImport->SetImportVoidPointer(this->image->getVoidPointer());
117 
118  cube->SetBounds(0, imSize[0] - 1, 0, imSize[1] - 1, 0, imSize[2] - 1);
119  cube->Update();
120 
121  camera->SetFocalPoint(imSize[0] / 2, imSize[1] / 2, imSize[2] / 2);
122  int d = 2.5 * (imSize[0] > imSize[1] ? imSize[0] : imSize[1]);
123  camera->SetPosition(imSize[0], imSize[1] / 2, -d);
124  }
125 
126  virtual void setAutoRange(bool on)
127  {
128  opacityTransfertFunction->RemoveAllPoints();
129  if (on) {
130  vector<T> r = rangeVal(*this->image);
131  opacityTransfertFunction->AddSegment(r[0], 0., r[1], 1.0);
132  } else
133  opacityTransfertFunction->AddSegment(ImDtTypes<T>::min(), 0.,
134  ImDtTypes<T>::max(), 1.0);
135  }
136 
137  virtual void onSizeChanged(size_t /*width*/, size_t /*height*/,
138  size_t /*depth*/)
139  {
140  }
141 
142  virtual void drawImage()
143  {
144  // T rVals[2];
145  // rangeVal(*this->image, rVals);
146  // opacityTransfertFunction->RemoveAllPoints();
147  // opacityTransfertFunction->AddSegment(rVals[0], 0., rVals[1], 1.0);
148 
149  QVtkViewerWidget::update();
150  }
151 
152  virtual void hide()
153  {
154  QVtkViewerWidget::hide();
155  }
156 
157  virtual void show()
158  {
159  QVtkViewerWidget::showNormal();
160  this->drawImage();
161  }
162 
163  virtual void show(Image<T> &im)
164  {
165  this->setImage(im);
166  this->show();
167  }
168 
169  virtual void showLabel()
170  {
171  QVtkViewerWidget::showLabel();
172  this->drawImage();
173  }
174 
175  virtual bool isVisible()
176  {
177  return QVtkViewerWidget::isVisible();
178  }
179 
180  virtual void setName(const char *_name)
181  {
182  QString buf = _name + QString(" (") +
183  QString(parentClass::image->getTypeAsString()) +
184  QString(")");
185  QVtkViewerWidget::setWindowTitle(buf);
186  }
187 
188  virtual void drawOverlay(const Image<T> & /*im*/)
189  {
190  }
191 
192  virtual void clearOverlay()
193  {
194  }
195 
196  virtual void setCurSlice(int)
197  {
198  }
199 
200  void setRepresentationType(RepresentationType type)
201  {
202  QVtkViewerWidget::setRepresentationType(
203  QVtkViewerWidget::RepresentationType(type));
204  }
205 
206  void showAxes()
207  {
208  QVtkViewerWidget::showAxes();
209  }
210 
211  void hideAxes()
212  {
213  QVtkViewerWidget::hideAxes();
214  }
215 
216  void setInterpolationTypeToLinear()
217  {
218  QVtkViewerWidget::setInterpolationTypeToLinear();
219  }
220 
221  void setInterpolationTypeToNearest()
222  {
223  QVtkViewerWidget::setInterpolationTypeToNearest();
224  }
225 
226  protected:
227  void initLookup(int typeMax)
228  {
229  QVtkViewerWidget::initLookup(typeMax);
230  }
231  };
232 
235 } // namespace smil
236 
237 #endif // _D_QVTK_IMAGE_VIEWER_HPP
Definition: QVtkViewerWidget.h:57
Main Image class.
Definition: DImage.hpp:57
Base image viewer.
Definition: DImageViewer.hpp:52
QVtk image viewer.
Definition: DQVtkViewer.hpp:59
vector< T > rangeVal(const Image< T > &imIn, bool onlyNonZero=false)
rangeVal() - Min and Max values of an image
Definition: DMeasures.hpp:416
Definition: DTypes.hpp:88
Definition: DTraits.hpp:48