SMIL  0.9.1
DNumpyInterface.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_NUMPY_INTERFACE_HPP
31 #define _D_NUMPY_INTERFACE_HPP
32 
33 
34 #include "Core/include/DNumpy.h"
35 #include "Core/include/private/DImage.hxx"
36 #include "Core/include/private/DSharedImage.hpp"
37 
38 
39 
40 namespace smil
41 {
42 
52  template <class T>
53  class NumpyInt : public SharedImage<T>
54  {
55  public:
57 
59  NumpyInt(PyObject *obj)
60  {
61  BaseObject::className = "NumpyInt";
62  parentClass::init();
63 
64  PyArrayObject *arr = (PyArrayObject *)(obj);
65 
66  int dim = PyArray_NDIM(arr);
67  npy_intp *dims = PyArray_DIMS(arr);
68 
69  T* data = (T*)PyArray_DATA(arr);
70 
71  PyArray_Descr *descr = PyArray_DESCR(arr);
72  if (descr->type_num!=getNumpyType(*this))
73  {
74  ERR_MSG("Wrong data type");
75  return;
76  }
77 
78  if (dim==3)
79  this->attach(data, dims[0], dims[1], dims[2]);
80  else if (dim==2)
81  this->attach(data, dims[0], dims[1]);
82  else if (dim==1)
83  this->attach(data, dims[0], 1);
84 
85  }
86  };
87 
90 } // namespace smil
91 
92 #endif // _D_NUMPY_INTERFACE_HPP
Definition: DColorConvert.h:38
Numpy Array Interface.
Definition: DNumpyInterface.hpp:53
Image that uses an existing (1D) data pointer.
Definition: DImage.hpp:53
NumpyInt(PyObject *obj)
Constructor.
Definition: DNumpyInterface.hpp:59
Base Smil Object.
Definition: DBaseObject.h:53