SMIL  0.9.1
DImageViewer.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_IMAGE_VIEWER_HPP
31 #define _D_IMAGE_VIEWER_HPP
32 
33 #include "Gui/include/DBaseImageViewer.h"
34 #include "Core/include/DColor.h"
35 
36 namespace smil
37 {
38 
39  template <class T> class Image;
40 
50  template <class T>
51  class ImageViewer : public BaseImageViewer
52  {
53  public:
54  typedef BaseImageViewer parentClass;
55  friend class Image<T>;
56 
57  ImageViewer()
58  : BaseImageViewer("ImageViewer"),
59  image(NULL),
60  labelImage(false)
61  {
62  onOverlayModified = Signal(this);
63  imSize[0] = imSize[1] = imSize[2] = 0;
64  }
65 
66  ImageViewer(Image<T> &im)
67  : BaseImageViewer("ImageViewer"),
68  image(NULL),
69  labelImage(false)
70  {
71  onOverlayModified = Signal(this);
72  imSize[0] = imSize[1] = imSize[2] = 0;
73  setImage(im);
74  }
75 
76  virtual void setImage(Image<T> &im)
77  {
78  if (image)
79  disconnect();
80 
81  image = &im;
82  image->getSize(imSize);
83  this->setName(image->getName());
84 
85  if (image)
86  image->onModified.connect(&this->updateSlot);
87  }
88  virtual Image<T> *getImage()
89  {
90  return this->image;
91  }
92  virtual void disconnect()
93  {
94  if (image)
95  image->onModified.disconnect(&this->updateSlot);
96  image = NULL;
97  }
98 
99  virtual void show() {}
100  virtual void showLabel() {}
101  virtual void hide() {}
102  virtual bool isVisible() { return false; }
103  virtual void setName(const char *_name) { parentClass::setName(_name); }
104  virtual void update()
105  {
106  if (!this->image)
107  return;
108 
109  size_t newSize[3];
110  this->image->getSize(newSize);
111  if (imSize[0]!=newSize[0] || imSize[1]!=newSize[1] || imSize[2]!=newSize[2])
112  {
113  this->setImage(*this->image);
114  }
115  this->setName(image->getName());
116 
117  if (this->isVisible())
118  this->drawImage();
119  }
120  virtual void drawOverlay(const Image<T> &) {}
121  virtual void clearOverlay() {}
122  virtual RES_T getOverlay(Image<T> &/*img*/) { return RES_ERR; }
123 
124  Signal onOverlayModified;
125 
127  virtual void setLookup(const map<UINT8,RGB> &/*lut*/) {}
128  virtual void resetLookup() {}
129 
130  protected:
131  virtual void drawImage() {}
132  virtual void onSizeChanged(size_t /*width*/, size_t /*height*/, size_t /*depth*/) {}
133  Image<T> *image;
134  bool labelImage;
135 
136  private:
137  size_t imSize[3];
138  };
139 
142 } // namespace smil
143 
144 
145 #endif // _D_BASE_IMAGE_VIEWER_H
virtual void setLookup(const map< UINT8, RGB > &)
Set the color table as a 8bits RGB map (keys between 0 and 255)
Definition: DImageViewer.hpp:127
Definition: DColorConvert.h:38
Main Image class.
Definition: DQVtkViewer.hpp:44