SMIL  0.9.1
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'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
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 
43 
44  template <class T> class Image;
45 
60  template <class T>
61  class QVtkViewer : public ImageViewer<T>, protected QVtkViewerWidget
62  {
63  public:
65  QVtkViewer()
66  : ImageViewer<T>(),
68  {
70  imageImport->SetDataScalarTypeToUnsignedChar();
71  else if (is_same<T,UINT16>::value)
72  imageImport->SetDataScalarTypeToUnsignedShort();
73  else if (is_same<T,INT16>::value)
74  imageImport->SetDataScalarTypeToShort();
75 
76  setAutoRange(false);
77 
78  colorOpacityTransfertFunction->AddSegment(0, 0., 1, 0.);
79  colorOpacityTransfertFunction->AddSegment(1, 1., ImDtTypes<T>::max(), 1.0);
80 
81  initLookup(ImDtTypes<T>::max());
82  }
83  QVtkViewer(Image<T> &im)
84  : ImageViewer<T>(),
86  {
88  imageImport->SetDataScalarTypeToUnsignedChar();
89  else if (is_same<T,UINT16>::value)
90  imageImport->SetDataScalarTypeToUnsignedShort();
91  else if (is_same<T,INT16>::value)
92  imageImport->SetDataScalarTypeToShort();
93 
94  setImage(im);
95 
96  setAutoRange(false);
97 
98  colorOpacityTransfertFunction->AddSegment(0, 0., 1, 0.);
99  colorOpacityTransfertFunction->AddSegment(1, 1., ImDtTypes<T>::max(), 1.0);
100 
101  initLookup(ImDtTypes<T>::max());
102  }
103  ~QVtkViewer()
104  {
105  }
106 
107  enum RepresentationType { NONE, COMPOSITE, MIP };
108 
109  virtual void setImage(Image<T> &im)
110  {
112 
113  size_t imSize[3];
114  this->image->getSize(imSize);
115  imageImport->SetWholeExtent(0, imSize[0]-1, 0, imSize[1]-1, 0, imSize[2]-1);
116  imageImport->SetDataExtent(0, imSize[0]-1, 0, imSize[1]-1, 0, imSize[2]-1);
117  imageImport->SetImportVoidPointer(this->image->getVoidPointer());
118 
119  cube->SetBounds(0, imSize[0]-1, 0, imSize[1]-1, 0, imSize[2]-1);
120  cube->Update();
121 
122  camera->SetFocalPoint(imSize[0]/2, imSize[1]/2, imSize[2]/2);
123  int d = 2.5 * (imSize[0] > imSize[1] ? imSize[0] : imSize[1]);
124  camera->SetPosition(imSize[0], imSize[1]/2, -d);
125  }
126 
127  virtual void setAutoRange(bool on)
128  {
129  opacityTransfertFunction->RemoveAllPoints();
130  if (on)
131  {
132  vector<T> r = rangeVal(*this->image);
133  opacityTransfertFunction->AddSegment(r[0], 0., r[1], 1.0);
134  }
135  else
136  opacityTransfertFunction->AddSegment(ImDtTypes<T>::min(), 0., ImDtTypes<T>::max(), 1.0);
137  }
138 
139  virtual void onSizeChanged(size_t /*width*/, size_t /*height*/, size_t /*depth*/)
140  {
141  }
142 
143  virtual void drawImage()
144  {
145 // T rVals[2];
146 // rangeVal(*this->image, rVals);
147 // opacityTransfertFunction->RemoveAllPoints();
148 // opacityTransfertFunction->AddSegment(rVals[0], 0., rVals[1], 1.0);
149 
150  QVtkViewerWidget::update();
151  }
152 
153  virtual void hide()
154  {
155  QVtkViewerWidget::hide();
156  }
157  virtual void show()
158  {
159  QVtkViewerWidget::showNormal();
160  this->drawImage();
161  }
162  virtual void show(Image<T> &im)
163  {
164  this->setImage(im);
165  this->show();
166  }
167  virtual void showLabel()
168  {
169  QVtkViewerWidget::showLabel();
170  this->drawImage();
171  }
172  virtual bool isVisible()
173  {
174  return QVtkViewerWidget::isVisible();
175  }
176  virtual void setName(const char *_name)
177  {
178  QString buf = _name + QString(" (") + QString(parentClass::image->getTypeAsString()) + QString(")");
179  QVtkViewerWidget::setWindowTitle(buf);
180  }
181  virtual void drawOverlay(const Image<T> &/*im*/)
182  {
183  }
184  virtual void clearOverlay() { }
185 
186  virtual void setCurSlice(int)
187  {
188  }
189 
190 
191  void setRepresentationType(RepresentationType type)
192  {
193  QVtkViewerWidget::setRepresentationType(QVtkViewerWidget::RepresentationType(type));
194  }
195 
196  void showAxes()
197  {
198  QVtkViewerWidget::showAxes();
199  }
200 
201  void hideAxes()
202  {
203  QVtkViewerWidget::hideAxes();
204  }
205 
206  void setInterpolationTypeToLinear()
207  {
208  QVtkViewerWidget::setInterpolationTypeToLinear();
209  }
210 
211  void setInterpolationTypeToNearest()
212  {
213  QVtkViewerWidget::setInterpolationTypeToNearest();
214  }
215 
216  protected:
217  void initLookup(int typeMax)
218  {
219  QVtkViewerWidget::initLookup(typeMax);
220  }
221  };
222 
225 } // namespace smil
226 
227 
228 #endif // _D_QVTK_IMAGE_VIEWER_HPP
QVtk image viewer.
Definition: DQVtkViewer.hpp:61
Definition: QVtkViewerWidget.h:57
Definition: DColorConvert.h:38
Definition: DTraits.hpp:47
vector< T > rangeVal(const Image< T > &imIn, bool onlyNonZero=false)
Min and Max values of an image.
Definition: DMeasures.hpp:313
Base image viewer.
Definition: DBaseImage.h:45
Definition: DTypes.hpp:78
Main Image class.
Definition: DQVtkViewer.hpp:44