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