SMIL  0.9.1
DMorphMImage.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_MORPHM_IMAGE_HPP
31 #define _D_MORPHM_IMAGE_HPP
32 
33 #include "Core/include/private/DImage.hxx"
34 #include "Core/include/private/DSharedImage.hpp"
35 
36 #include <morphee/image/include/private/image_T.hpp>
37 #include <morphee/image/include/imageInterface.hpp>
38 #include <morphee/image/include/imageUtils.hpp>
39 
40 #ifdef SWIGPYTHON
41  #include <boost/python.hpp>
42 #endif // SWIGPYTHON
43 
44 namespace smil
45 {
57  template <class T>
58  class MorphmInt : public SharedImage<T>
59  {
60  public:
62 
63  MorphmInt(morphee::Image<T> &img)
64  {
65  BaseObject::className = "MorphmInt";
66  parentClass::init();
67  if (!img.isAllocated())
68  ERR_MSG("Source image isn't allocated");
69  else
70  {
71  typename morphee::Image<T>::i_coordinate_system s = img.getSize();
72 
73  this->attach(img.rawPointer(), s[0], s[1], s[2]);
74  }
75  }
76  MorphmInt(morphee::ImageInterface &imgInt)
77  {
78  BaseObject::className = "MorphmInt";
79  parentClass::init();
80  if (!imgInt.isAllocated())
81  ERR_MSG("Source image isn't allocated");
82  else
83  {
84  morphee::Image<T> *mIm = dynamic_cast< morphee::Image<T>* >(&imgInt);
85  if (!mIm)
86  ERR_MSG("Error in morphM dynamic_cast");
87  else
88  {
89  typename morphee::Image<T>::i_coordinate_system s = mIm->getSize();
90  this->attach(mIm->rawPointer(), s[0], s[1], s[2]);
91  }
92  }
93  }
94  #if defined Py_PYCONFIG_H || defined SWIGPYTHON
95  MorphmInt(PyObject *obj)
96  {
97  BaseObject::className = "MorphmInt";
98  parentClass::init();
99  morphee::ImageInterface *imgInt = boost::python::extract<morphee::ImageInterface *>(obj);
100  if (imgInt)
101  {
102  if (!imgInt->isAllocated())
103  ERR_MSG("Source image isn't allocated");
104  else
105  {
106  morphee::Image<T> *mIm = dynamic_cast< morphee::Image<T>* >(imgInt);
107  if (!mIm)
108  ERR_MSG("Error in morphM dynamic_cast");
109  else
110  {
111  typename morphee::Image<T>::i_coordinate_system s = mIm->getSize();
112  this->attach(mIm->rawPointer(), s[0], s[1], s[2]);
113  }
114  }
115  }
116  }
117  #endif // Py_PYCONFIG_H
118  };
119 
122 } // namespace smil
123 
124 #endif // _D_MORPHM_IMAGE_HPP
Definition: DColorConvert.h:38
Image that uses an existing (1D) data pointer.
Definition: DImage.hpp:53
MorphM Image Interface.
Definition: DMorphMImage.hpp:58