| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
// clang-format off |
| 7 |
|
| 8 |
#include <Python.h> |
| 9 |
#define BOOST_BIND_GLOBAL_PLACEHOLDERS |
| 10 |
#include <boost/python.hpp> |
| 11 |
#include <boost/python/make_constructor.hpp> |
| 12 |
#include <boost/format.hpp> |
| 13 |
#include <ImathVec.h> |
| 14 |
#include <ImathQuat.h> |
| 15 |
#include <ImathEuler.h> |
| 16 |
#include <ImathFun.h> |
| 17 |
#include <ImathMatrixAlgo.h> |
| 18 |
|
| 19 |
#include "PyImathFixedArray.h" |
| 20 |
#include "PyImath.h" |
| 21 |
#include "PyImathExport.h" |
| 22 |
#include "PyImathBasicTypes.h" |
| 23 |
#include "PyImathVec.h" |
| 24 |
#include "PyImathMatrix.h" |
| 25 |
#include "PyImathBox.h" |
| 26 |
#include "PyImathFun.h" |
| 27 |
#include "PyImathQuat.h" |
| 28 |
#include "PyImathEuler.h" |
| 29 |
#include "PyImathColor.h" |
| 30 |
#include "PyImathFrustum.h" |
| 31 |
#include "PyImathPlane.h" |
| 32 |
#include "PyImathLine.h" |
| 33 |
#include "PyImathRandom.h" |
| 34 |
#include "PyImathShear.h" |
| 35 |
#include "PyImathMathExc.h" |
| 36 |
#include "PyImathAutovectorize.h" |
| 37 |
#include "PyImathStringArrayRegister.h" |
| 38 |
#include "PyImathBufferProtocol.h" |
| 39 |
|
| 40 |
using namespace boost::python; |
| 41 |
using namespace PyImath; |
| 42 |
|
| 43 |
namespace { |
| 44 |
|
| 45 |
template <typename T> |
| 46 |
IMATH_NAMESPACE::Box<IMATH_NAMESPACE::Vec3<T> > |
| 47 |
computeBoundingBox(const FixedArray<IMATH_NAMESPACE::Vec3<T> >& position) |
| 48 |
{ |
| 49 |
IMATH_NAMESPACE::Box<IMATH_NAMESPACE::Vec3<T> > bounds; |
| 50 |
int len = position.len(); |
| 51 |
for (int i = 0; i < len; ++i) |
| 52 |
bounds.extendBy(position[i]); |
| 53 |
return bounds; |
| 54 |
} |
| 55 |
|
| 56 |
IMATH_NAMESPACE::M44d |
| 57 |
procrustes1 (PyObject* from_input, |
| 58 |
PyObject* to_input, |
| 59 |
PyObject* weights_input = 0, |
| 60 |
bool doScale = false) |
| 61 |
{ |
| 62 |
// Verify the sequences: |
| 63 |
if (!PySequence_Check (from_input)) |
| 64 |
{ |
| 65 |
PyErr_SetString (PyExc_TypeError, "Expected a sequence type for 'from'"); |
| 66 |
throw_error_already_set(); |
| 67 |
} |
| 68 |
|
| 69 |
if (!PySequence_Check (to_input)) |
| 70 |
{ |
| 71 |
PyErr_SetString (PyExc_TypeError, "Expected a sequence type for 'to'"); |
| 72 |
throw_error_already_set(); |
| 73 |
} |
| 74 |
|
| 75 |
bool useWeights = PySequence_Check (weights_input); |
| 76 |
|
| 77 |
// Now verify the lengths: |
| 78 |
const Py_ssize_t n = PySequence_Length (from_input); |
| 79 |
if (n != PySequence_Length (to_input) || |
| 80 |
(useWeights && n != PySequence_Length (weights_input))) |
| 81 |
{ |
| 82 |
PyErr_SetString (PyExc_TypeError, "'from, 'to', and 'weights' should all have the same lengths."); |
| 83 |
throw_error_already_set(); |
| 84 |
} |
| 85 |
|
| 86 |
std::vector<IMATH_NAMESPACE::V3d> from; from.reserve (n); |
| 87 |
std::vector<IMATH_NAMESPACE::V3d> to; to.reserve (n); |
| 88 |
std::vector<double> weights; weights.reserve (n); |
| 89 |
|
| 90 |
for (Py_ssize_t i = 0; i < n; ++i) |
| 91 |
{ |
| 92 |
PyObject* f = PySequence_GetItem (from_input, i); |
| 93 |
PyObject* t = PySequence_GetItem (to_input, i); |
| 94 |
PyObject* w = 0; |
| 95 |
if (useWeights) |
| 96 |
w = PySequence_GetItem (weights_input, i); |
| 97 |
|
| 98 |
if (f == 0 || t == 0 || (useWeights && w == 0)) |
| 99 |
{ |
| 100 |
PyErr_SetString (PyExc_TypeError, |
| 101 |
"Missing element in array"); |
| 102 |
throw_error_already_set(); |
| 103 |
} |
| 104 |
|
| 105 |
from.push_back (extract<IMATH_NAMESPACE::V3d> (f)); |
| 106 |
to.push_back (extract<IMATH_NAMESPACE::V3d> (t)); |
| 107 |
if (useWeights) |
| 108 |
weights.push_back (extract<double> (w)); |
| 109 |
} |
| 110 |
|
| 111 |
if (useWeights) |
| 112 |
return IMATH_NAMESPACE::procrustesRotationAndTranslation (&from[0], &to[0], &weights[0], n, doScale); |
| 113 |
else |
| 114 |
return IMATH_NAMESPACE::procrustesRotationAndTranslation (&from[0], &to[0], n, doScale); |
| 115 |
} |
| 116 |
|
| 117 |
template <typename T> |
| 118 |
const T* |
| 119 |
flatten(const PyImath::FixedArray<T>& q, std::unique_ptr<T[]>& handle) |
| 120 |
{ |
| 121 |
if (q.isMaskedReference()) |
| 122 |
{ |
| 123 |
const size_t len = q.len(); |
| 124 |
handle.reset(new T[len]); |
| 125 |
for (size_t i = 0; i < len; ++i) |
| 126 |
handle[i] = q[i]; |
| 127 |
|
| 128 |
return handle.get(); |
| 129 |
} |
| 130 |
|
| 131 |
return &q[0]; |
| 132 |
} |
| 133 |
|
| 134 |
template <typename T> |
| 135 |
IMATH_NAMESPACE::M44d |
| 136 |
procrustesRotationAndTranslation(const FixedArray<IMATH_NAMESPACE::Vec3<T> >& from, |
| 137 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> >& to, |
| 138 |
const FixedArray<T>* weights = 0, |
| 139 |
bool doScale = false) |
| 140 |
{ |
| 141 |
const size_t len = from.match_dimension(to); |
| 142 |
if (len == 0) |
| 143 |
return IMATH_NAMESPACE::M44d(); |
| 144 |
|
| 145 |
std::unique_ptr<IMATH_NAMESPACE::Vec3<T>[]> fromHandle; |
| 146 |
const Imath::Vec3<T>* fromPtr = flatten(from, fromHandle); |
| 147 |
|
| 148 |
std::unique_ptr<IMATH_NAMESPACE::Vec3<T>[]> toHandle; |
| 149 |
const Imath::Vec3<T>* toPtr = flatten(to, toHandle); |
| 150 |
|
| 151 |
std::unique_ptr<T[]> weightsHandle; |
| 152 |
const T* weightsPtr = nullptr; |
| 153 |
if (weights) |
| 154 |
{ |
| 155 |
weights->match_dimension(from); |
| 156 |
flatten(*weights, weightsHandle); |
| 157 |
} |
| 158 |
|
| 159 |
if (weightsPtr) |
| 160 |
return IMATH_NAMESPACE::procrustesRotationAndTranslation(fromPtr, toPtr, weightsPtr, len, doScale); |
| 161 |
else |
| 162 |
return IMATH_NAMESPACE::procrustesRotationAndTranslation(fromPtr, toPtr, len, doScale); |
| 163 |
} |
| 164 |
|
| 165 |
BOOST_PYTHON_FUNCTION_OVERLOADS(procrustesRotationAndTranslationf_overloads, procrustesRotationAndTranslation<float>, 2, 4); |
| 166 |
BOOST_PYTHON_FUNCTION_OVERLOADS(procrustesRotationAndTranslationd_overloads, procrustesRotationAndTranslation<double>, 2, 4); |
| 167 |
|
| 168 |
|
| 169 |
FixedArray2D<int> rangeX(int sizeX, int sizeY) |
| 170 |
{ |
| 171 |
FixedArray2D<int> f(sizeX, sizeY); |
| 172 |
for (int j=0; j<sizeY; j++) |
| 173 |
for (int i=0; i<sizeX; i++) |
| 174 |
f(i,j) = i; |
| 175 |
return f; |
| 176 |
} |
| 177 |
|
| 178 |
FixedArray2D<int> rangeY(int sizeX, int sizeY) |
| 179 |
{ |
| 180 |
FixedArray2D<int> f(sizeX, sizeY); |
| 181 |
for (int j=0; j<sizeY; j++) |
| 182 |
for (int i=0; i<sizeX; i++) |
| 183 |
f(i,j) = j; |
| 184 |
return f; |
| 185 |
} |
| 186 |
|
| 187 |
} // anonymous-namespace |
| 188 |
|
| 189 |
|
| 190 |
BOOST_PYTHON_MODULE(imath) |
| 191 |
{ |
| 192 |
scope().attr("__doc__") = "Imath module"; |
| 193 |
scope().attr("__version__") = IMATH_VERSION_STRING; |
| 194 |
|
| 195 |
register_basicTypes(); |
| 196 |
|
| 197 |
class_<IntArray2D> iclass2D = IntArray2D::register_("IntArray2D","Fixed length array of ints"); |
| 198 |
add_arithmetic_math_functions(iclass2D); |
| 199 |
add_mod_math_functions(iclass2D); |
| 200 |
add_comparison_functions(iclass2D); |
| 201 |
add_ordered_comparison_functions(iclass2D); |
| 202 |
add_explicit_construction_from_type<float>(iclass2D); |
| 203 |
add_explicit_construction_from_type<double>(iclass2D); |
| 204 |
|
| 205 |
class_<IntMatrix> imclass = IntMatrix::register_("IntMatrix","Fixed size matrix of ints"); |
| 206 |
add_arithmetic_math_functions(imclass); |
| 207 |
|
| 208 |
class_<FloatArray2D> fclass2D = FloatArray2D::register_("FloatArray2D","Fixed length 2D array of floats"); |
| 209 |
add_arithmetic_math_functions(fclass2D); |
| 210 |
add_pow_math_functions(fclass2D); |
| 211 |
add_comparison_functions(fclass2D); |
| 212 |
add_ordered_comparison_functions(fclass2D); |
| 213 |
add_explicit_construction_from_type<int>(fclass2D); |
| 214 |
add_explicit_construction_from_type<double>(fclass2D); |
| 215 |
|
| 216 |
class_<FloatMatrix> fmclass = FloatMatrix::register_("FloatMatrix","Fixed size matrix of floats"); |
| 217 |
add_arithmetic_math_functions(fmclass); |
| 218 |
add_pow_math_functions(fmclass); |
| 219 |
|
| 220 |
class_<DoubleArray2D> dclass2D = DoubleArray2D::register_("DoubleArray2D","Fixed length array of doubles"); |
| 221 |
add_arithmetic_math_functions(dclass2D); |
| 222 |
add_pow_math_functions(dclass2D); |
| 223 |
add_comparison_functions(dclass2D); |
| 224 |
add_ordered_comparison_functions(dclass2D); |
| 225 |
add_explicit_construction_from_type<int>(dclass2D); |
| 226 |
add_explicit_construction_from_type<float>(dclass2D); |
| 227 |
|
| 228 |
class_<DoubleMatrix> dmclass = DoubleMatrix::register_("DoubleMatrix","Fixed size matrix of doubles"); |
| 229 |
add_arithmetic_math_functions(dmclass); |
| 230 |
add_pow_math_functions(dmclass); |
| 231 |
|
| 232 |
def("rangeX", &rangeX); |
| 233 |
def("rangeY", &rangeY); |
| 234 |
|
| 235 |
def("IntArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<int> >, |
| 236 |
return_value_policy<manage_new_object>(), |
| 237 |
args("bufferObject"), |
| 238 |
"Construct an IntArray from a buffer object"); |
| 239 |
|
| 240 |
def("FloatArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<float> >, |
| 241 |
return_value_policy<manage_new_object>(), |
| 242 |
args("bufferObject"), |
| 243 |
"Construct a FloatArray from a buffer object"); |
| 244 |
|
| 245 |
def("DoubleArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<double> >, |
| 246 |
return_value_policy<manage_new_object>(), |
| 247 |
args("bufferObject"), |
| 248 |
"Construct a DoubleArray from a buffer object"); |
| 249 |
|
| 250 |
// |
| 251 |
// Vec2 |
| 252 |
// |
| 253 |
register_Vec2<short>(); |
| 254 |
register_Vec2<int>(); |
| 255 |
register_Vec2<int64_t>(); |
| 256 |
register_Vec2<float>(); |
| 257 |
register_Vec2<double>(); |
| 258 |
class_<FixedArray<IMATH_NAMESPACE::V2s> > v2s_class = register_Vec2Array<short>(); |
| 259 |
class_<FixedArray<IMATH_NAMESPACE::V2i> > v2i_class = register_Vec2Array<int>(); |
| 260 |
class_<FixedArray<IMATH_NAMESPACE::V2i64> > v2i64_class = register_Vec2Array<int64_t>(); |
| 261 |
class_<FixedArray<IMATH_NAMESPACE::V2f> > v2f_class = register_Vec2Array<float>(); |
| 262 |
class_<FixedArray<IMATH_NAMESPACE::V2d> > v2d_class = register_Vec2Array<double>(); |
| 263 |
|
| 264 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2s>(v2i_class); |
| 265 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2s>(v2i64_class); |
| 266 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2s>(v2f_class); |
| 267 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2s>(v2d_class); |
| 268 |
|
| 269 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i>(v2s_class); |
| 270 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i>(v2i64_class); |
| 271 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i>(v2f_class); |
| 272 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i>(v2d_class); |
| 273 |
|
| 274 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i64>(v2s_class); |
| 275 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i64>(v2i_class); |
| 276 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i64>(v2f_class); |
| 277 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2i64>(v2d_class); |
| 278 |
|
| 279 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2f>(v2s_class); |
| 280 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2f>(v2i_class); |
| 281 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2f>(v2i64_class); |
| 282 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2f>(v2d_class); |
| 283 |
|
| 284 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2d>(v2s_class); |
| 285 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2d>(v2i_class); |
| 286 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2d>(v2i64_class); |
| 287 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V2d>(v2f_class); |
| 288 |
|
| 289 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V2s> > (v2s_class); |
| 290 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V2i> > (v2i_class); |
| 291 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V2i64> > (v2i64_class); |
| 292 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V2f> > (v2f_class); |
| 293 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V2d> > (v2d_class); |
| 294 |
|
| 295 |
def("V2iArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec2<int> > >, |
| 296 |
return_value_policy<manage_new_object>(), |
| 297 |
args("bufferObject"), |
| 298 |
"Construct a V2iArray from a buffer object"); |
| 299 |
|
| 300 |
def("V2fArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec2<float> > >, |
| 301 |
return_value_policy<manage_new_object>(), |
| 302 |
args("bufferObject"), |
| 303 |
"Construct a V2fArray from a buffer object"); |
| 304 |
|
| 305 |
def("V2dArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec2<double> > >, |
| 306 |
return_value_policy<manage_new_object>(), |
| 307 |
args("bufferObject"), |
| 308 |
"Construct a V2dArray from a buffer object"); |
| 309 |
|
| 310 |
// |
| 311 |
// Vec3 |
| 312 |
// |
| 313 |
register_Vec3<unsigned char>(); |
| 314 |
register_Vec3<short>(); |
| 315 |
register_Vec3<int>(); |
| 316 |
register_Vec3<int64_t>(); |
| 317 |
register_Vec3<float>(); |
| 318 |
register_Vec3<double>(); |
| 319 |
class_<FixedArray<IMATH_NAMESPACE::V3s> > v3s_class = register_Vec3Array<short>(); |
| 320 |
class_<FixedArray<IMATH_NAMESPACE::V3i> > v3i_class = register_Vec3Array<int>(); |
| 321 |
class_<FixedArray<IMATH_NAMESPACE::V3i64> > v3i64_class = register_Vec3Array<int64_t>(); |
| 322 |
class_<FixedArray<IMATH_NAMESPACE::V3f> > v3f_class = register_Vec3Array<float>(); |
| 323 |
class_<FixedArray<IMATH_NAMESPACE::V3d> > v3d_class = register_Vec3Array<double>(); |
| 324 |
|
| 325 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3s>(v3i_class); |
| 326 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3s>(v3i64_class); |
| 327 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3s>(v3f_class); |
| 328 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3s>(v3d_class); |
| 329 |
|
| 330 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i>(v3s_class); |
| 331 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i>(v3i64_class); |
| 332 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i>(v3f_class); |
| 333 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i>(v3d_class); |
| 334 |
|
| 335 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i64>(v3s_class); |
| 336 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i64>(v3i_class); |
| 337 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i64>(v3f_class); |
| 338 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3i64>(v3d_class); |
| 339 |
|
| 340 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3f>(v3s_class); |
| 341 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3f>(v3i_class); |
| 342 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3f>(v3i64_class); |
| 343 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3f>(v3d_class); |
| 344 |
|
| 345 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3d>(v3s_class); |
| 346 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3d>(v3i_class); |
| 347 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3d>(v3i64_class); |
| 348 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3d>(v3f_class); |
| 349 |
|
| 350 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V3s> > (v3s_class); |
| 351 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V3i> > (v3i_class); |
| 352 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V3i64> > (v3i64_class); |
| 353 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V3f> > (v3f_class); |
| 354 |
add_buffer_protocol<FixedArray<IMATH_NAMESPACE::V3d> > (v3d_class); |
| 355 |
|
| 356 |
def("V3iArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec3<int> > >, |
| 357 |
return_value_policy<manage_new_object>(), |
| 358 |
args("bufferObject"), |
| 359 |
"Construct a V3iArray from a buffer object"); |
| 360 |
|
| 361 |
def("V3fArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec3<float> > >, |
| 362 |
return_value_policy<manage_new_object>(), |
| 363 |
args("bufferObject"), |
| 364 |
"Construct a V3fArray from a buffer object"); |
| 365 |
|
| 366 |
def("V3dArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec3<double> > >, |
| 367 |
return_value_policy<manage_new_object>(), |
| 368 |
args("bufferObject"), |
| 369 |
"Construct a V3dArray from a buffer object"); |
| 370 |
|
| 371 |
// |
| 372 |
// Vec4 |
| 373 |
// |
| 374 |
register_Vec4<unsigned char>(); |
| 375 |
register_Vec4<short>(); |
| 376 |
register_Vec4<int>(); |
| 377 |
register_Vec4<int64_t>(); |
| 378 |
register_Vec4<float>(); |
| 379 |
register_Vec4<double>(); |
| 380 |
class_<FixedArray<IMATH_NAMESPACE::V4s> > v4s_class = register_Vec4Array<short>(); |
| 381 |
class_<FixedArray<IMATH_NAMESPACE::V4i> > v4i_class = register_Vec4Array<int>(); |
| 382 |
class_<FixedArray<IMATH_NAMESPACE::V4i64> > v4i64_class = register_Vec4Array<int64_t>(); |
| 383 |
class_<FixedArray<IMATH_NAMESPACE::V4f> > v4f_class = register_Vec4Array<float>(); |
| 384 |
class_<FixedArray<IMATH_NAMESPACE::V4d> > v4d_class = register_Vec4Array<double>(); |
| 385 |
|
| 386 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4s>(v4i_class); |
| 387 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4s>(v4i64_class); |
| 388 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4s>(v4f_class); |
| 389 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4s>(v4d_class); |
| 390 |
|
| 391 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i>(v4s_class); |
| 392 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i>(v4i64_class); |
| 393 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i>(v4f_class); |
| 394 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i>(v4d_class); |
| 395 |
|
| 396 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i64>(v4s_class); |
| 397 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i64>(v4i_class); |
| 398 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i64>(v4f_class); |
| 399 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4i64>(v4d_class); |
| 400 |
|
| 401 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4f>(v4s_class); |
| 402 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4f>(v4i_class); |
| 403 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4f>(v4i64_class); |
| 404 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4f>(v4d_class); |
| 405 |
|
| 406 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4d>(v4s_class); |
| 407 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4d>(v4i_class); |
| 408 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4d>(v4i64_class); |
| 409 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V4d>(v4f_class); |
| 410 |
|
| 411 |
def("V4iArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec4<int> > >, |
| 412 |
return_value_policy<manage_new_object>(), |
| 413 |
args("bufferObject"), |
| 414 |
"Construct a V4iArray from a buffer object"); |
| 415 |
|
| 416 |
def("V4fArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec4<float> > >, |
| 417 |
return_value_policy<manage_new_object>(), |
| 418 |
args("bufferObject"), |
| 419 |
"Construct a V4fArray from a buffer object"); |
| 420 |
|
| 421 |
def("V4dArrayFromBuffer", &fixedArrayFromBuffer<FixedArray<Imath::Vec4<double> > >, |
| 422 |
return_value_policy<manage_new_object>(), |
| 423 |
args("bufferObject"), |
| 424 |
"Construct a V4dArray from a buffer object"); |
| 425 |
|
| 426 |
// |
| 427 |
// Quat |
| 428 |
// |
| 429 |
register_Quat<float>(); |
| 430 |
register_Quat<double>(); |
| 431 |
class_<FixedArray<IMATH_NAMESPACE::Quatf> > quatf_class = register_QuatArray<float>(); |
| 432 |
class_<FixedArray<IMATH_NAMESPACE::Quatd> > quatd_class = register_QuatArray<double>(); |
| 433 |
add_explicit_construction_from_type<IMATH_NAMESPACE::Quatd>(quatf_class); |
| 434 |
add_explicit_construction_from_type<IMATH_NAMESPACE::Quatf>(quatd_class); |
| 435 |
|
| 436 |
// |
| 437 |
// Euler |
| 438 |
// |
| 439 |
register_Euler<float>(); |
| 440 |
register_Euler<double>(); |
| 441 |
class_<FixedArray<IMATH_NAMESPACE::Eulerf> > eulerf_class = register_EulerArray<float>(); |
| 442 |
class_<FixedArray<IMATH_NAMESPACE::Eulerd> > eulerd_class = register_EulerArray<double>(); |
| 443 |
add_explicit_construction_from_type<IMATH_NAMESPACE::Eulerd>(eulerf_class); |
| 444 |
add_explicit_construction_from_type<IMATH_NAMESPACE::Eulerf>(eulerd_class); |
| 445 |
|
| 446 |
// |
| 447 |
// Box2 |
| 448 |
// |
| 449 |
register_Box2<IMATH_NAMESPACE::V2s>(); |
| 450 |
register_Box2<IMATH_NAMESPACE::V2i>(); |
| 451 |
register_Box2<IMATH_NAMESPACE::V2i64>(); |
| 452 |
register_Box2<IMATH_NAMESPACE::V2f>(); |
| 453 |
register_Box2<IMATH_NAMESPACE::V2d>(); |
| 454 |
class_<FixedArray<IMATH_NAMESPACE::Box2s> > b2s_class = register_BoxArray<IMATH_NAMESPACE::V2s>(); |
| 455 |
class_<FixedArray<IMATH_NAMESPACE::Box2i> > b2i_class = register_BoxArray<IMATH_NAMESPACE::V2i>(); |
| 456 |
class_<FixedArray<IMATH_NAMESPACE::Box2i64> > b2i64_class = register_BoxArray<IMATH_NAMESPACE::V2i64>(); |
| 457 |
class_<FixedArray<IMATH_NAMESPACE::Box2f> > b2f_class = register_BoxArray<IMATH_NAMESPACE::V2f>(); |
| 458 |
class_<FixedArray<IMATH_NAMESPACE::Box2d> > b2d_class = register_BoxArray<IMATH_NAMESPACE::V2d>(); |
| 459 |
|
| 460 |
// |
| 461 |
// Box3 |
| 462 |
// |
| 463 |
register_Box3<IMATH_NAMESPACE::V3s>(); |
| 464 |
register_Box3<IMATH_NAMESPACE::V3i>(); |
| 465 |
register_Box3<IMATH_NAMESPACE::V3i64>(); |
| 466 |
register_Box3<IMATH_NAMESPACE::V3f>(); |
| 467 |
register_Box3<IMATH_NAMESPACE::V3d>(); |
| 468 |
class_<FixedArray<IMATH_NAMESPACE::Box3s> > b3s_class = register_BoxArray<IMATH_NAMESPACE::V3s>(); |
| 469 |
class_<FixedArray<IMATH_NAMESPACE::Box3i> > b3i_class = register_BoxArray<IMATH_NAMESPACE::V3i>(); |
| 470 |
class_<FixedArray<IMATH_NAMESPACE::Box3i64> > b3i64_class = register_BoxArray<IMATH_NAMESPACE::V3i64>(); |
| 471 |
class_<FixedArray<IMATH_NAMESPACE::Box3f> > b3f_class = register_BoxArray<IMATH_NAMESPACE::V3f>(); |
| 472 |
class_<FixedArray<IMATH_NAMESPACE::Box3d> > b3d_class = register_BoxArray<IMATH_NAMESPACE::V3d>(); |
| 473 |
|
| 474 |
// |
| 475 |
// Matrix22/33/44 |
| 476 |
// |
| 477 |
register_Matrix22<float>(); |
| 478 |
register_Matrix22<double>(); |
| 479 |
register_Matrix33<float>(); |
| 480 |
register_Matrix33<double>(); |
| 481 |
register_Matrix44<float>(); |
| 482 |
register_Matrix44<double>(); |
| 483 |
|
| 484 |
// |
| 485 |
// M22/M33/44Array |
| 486 |
// |
| 487 |
class_<FixedArray<IMATH_NAMESPACE::M44d> > m44d_class = register_M44Array<double>(); |
| 488 |
class_<FixedArray<IMATH_NAMESPACE::M44f> > m44f_class = register_M44Array<float>(); |
| 489 |
add_explicit_construction_from_type< IMATH_NAMESPACE::Matrix44<double> >(m44d_class); |
| 490 |
add_explicit_construction_from_type< IMATH_NAMESPACE::Matrix44<float> > (m44f_class); |
| 491 |
|
| 492 |
class_<FixedArray<IMATH_NAMESPACE::M33d> > m33d_class = register_M33Array<double>(); |
| 493 |
class_<FixedArray<IMATH_NAMESPACE::M33f> > m33f_class = register_M33Array<float>(); |
| 494 |
add_explicit_construction_from_type< IMATH_NAMESPACE::Matrix33<double> >(m33d_class); |
| 495 |
add_explicit_construction_from_type< IMATH_NAMESPACE::Matrix33<float> > (m33f_class); |
| 496 |
|
| 497 |
class_<FixedArray<IMATH_NAMESPACE::M22d> > m22d_class = register_M22Array<double>(); |
| 498 |
class_<FixedArray<IMATH_NAMESPACE::M22f> > m22f_class = register_M22Array<float>(); |
| 499 |
add_explicit_construction_from_type< IMATH_NAMESPACE::Matrix22<double> >(m22d_class); |
| 500 |
add_explicit_construction_from_type< IMATH_NAMESPACE::Matrix22<float> > (m22f_class); |
| 501 |
|
| 502 |
// |
| 503 |
// String Array |
| 504 |
// |
| 505 |
register_StringArrays(); |
| 506 |
|
| 507 |
// |
| 508 |
// Color3/4 |
| 509 |
// |
| 510 |
register_Color3<unsigned char>(); |
| 511 |
register_Color3<float>(); |
| 512 |
register_Color4<unsigned char>(); |
| 513 |
register_Color4<float>(); |
| 514 |
|
| 515 |
// |
| 516 |
// C3/4Array |
| 517 |
// |
| 518 |
class_<FixedArray<IMATH_NAMESPACE::Color3f> > c3f_class = register_Color3Array<float>(); |
| 519 |
class_<FixedArray<IMATH_NAMESPACE::Color3c> > c3c_class = register_Color3Array<unsigned char>(); |
| 520 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3f>(c3f_class); |
| 521 |
add_explicit_construction_from_type<IMATH_NAMESPACE::V3d>(c3f_class); |
| 522 |
|
| 523 |
class_<FixedArray<IMATH_NAMESPACE::Color4f> > c4f_class = register_Color4Array<float>(); |
| 524 |
class_<FixedArray<IMATH_NAMESPACE::Color4c> > c4c_class = register_Color4Array<unsigned char>(); |
| 525 |
|
| 526 |
// |
| 527 |
// Color4Array |
| 528 |
// |
| 529 |
register_Color4Array2D<float>(); |
| 530 |
register_Color4Array2D<unsigned char>(); |
| 531 |
|
| 532 |
// |
| 533 |
// Frustum |
| 534 |
// |
| 535 |
register_Frustum<float>(); |
| 536 |
register_Frustum<double>(); |
| 537 |
register_FrustumTest<float>(); |
| 538 |
register_FrustumTest<double>(); |
| 539 |
|
| 540 |
// |
| 541 |
// Plane |
| 542 |
// |
| 543 |
register_Plane<float>(); |
| 544 |
register_Plane<double>(); |
| 545 |
|
| 546 |
// |
| 547 |
// Line |
| 548 |
// |
| 549 |
register_Line<float>(); |
| 550 |
register_Line<double>(); |
| 551 |
|
| 552 |
// |
| 553 |
// Shear |
| 554 |
// |
| 555 |
register_Shear<float>(); |
| 556 |
register_Shear<double>(); |
| 557 |
|
| 558 |
// |
| 559 |
// Utility Functions |
| 560 |
// |
| 561 |
register_functions(); |
| 562 |
|
| 563 |
|
| 564 |
def("procrustesRotationAndTranslation", procrustes1, |
| 565 |
args("fromPts", "toPts", "weights", "doScale"), // Can't use 'from' and 'to' because 'from' is a reserved keywork in Python |
| 566 |
"Computes the orthogonal transform (consisting only of rotation and translation) mapping the " |
| 567 |
"'fromPts' points as close as possible to the 'toPts' points in the least squares norm. The 'fromPts' and " |
| 568 |
"'toPts' lists must be the same length or the function will error out. If weights " |
| 569 |
"are provided, then the points are weighted (that is, some points are considered more important " |
| 570 |
"than others while computing the transform). If the 'doScale' parameter is True, then " |
| 571 |
"the resulting matrix is also allowed to have a uniform scale."); |
| 572 |
|
| 573 |
def("procrustesRotationAndTranslation", &procrustesRotationAndTranslation<float>, procrustesRotationAndTranslationf_overloads( |
| 574 |
args("fromPts", "toPts", "weights", "doScale"), |
| 575 |
"Computes the orthogonal transform (consisting only of rotation and translation) mapping the " |
| 576 |
"'fromPts' points as close as possible to the 'toPts' points in the least squares norm. The 'fromPts' and " |
| 577 |
"'toPts' lists must be the same length or the function will error out. If weights " |
| 578 |
"are provided, then the points are weighted (that is, some points are considered more important " |
| 579 |
"than others while computing the transform). If the 'doScale' parameter is True, then " |
| 580 |
"the resulting matrix is also allowed to have a uniform scale.")); |
| 581 |
|
| 582 |
def("procrustesRotationAndTranslation", &procrustesRotationAndTranslation<double>, procrustesRotationAndTranslationd_overloads( |
| 583 |
args("fromPts", "toPts", "weights", "doScale"), |
| 584 |
"Computes the orthogonal transform (consisting only of rotation and translation) mapping the " |
| 585 |
"'fromPts' points as close as possible to the 'toPts' points in the least squares norm. The 'fromPts' and " |
| 586 |
"'toPts' lists must be the same length or the function will error out. If weights " |
| 587 |
"are provided, then the points are weighted (that is, some points are considered more important " |
| 588 |
"than others while computing the transform). If the 'doScale' parameter is True, then " |
| 589 |
"the resulting matrix is also allowed to have a uniform scale.")); |
| 590 |
|
| 591 |
// |
| 592 |
// Rand |
| 593 |
// |
| 594 |
register_Rand32(); |
| 595 |
register_Rand48(); |
| 596 |
|
| 597 |
// |
| 598 |
// Initialize constants |
| 599 |
// |
| 600 |
|
| 601 |
scope().attr("EULER_XYZ") = IMATH_NAMESPACE::Eulerf::XYZ; |
| 602 |
scope().attr("EULER_XZY") = IMATH_NAMESPACE::Eulerf::XZY; |
| 603 |
scope().attr("EULER_YZX") = IMATH_NAMESPACE::Eulerf::YZX; |
| 604 |
scope().attr("EULER_YXZ") = IMATH_NAMESPACE::Eulerf::YXZ; |
| 605 |
scope().attr("EULER_ZXY") = IMATH_NAMESPACE::Eulerf::ZXY; |
| 606 |
scope().attr("EULER_ZYX") = IMATH_NAMESPACE::Eulerf::ZYX; |
| 607 |
scope().attr("EULER_XZX") = IMATH_NAMESPACE::Eulerf::XZX; |
| 608 |
scope().attr("EULER_XYX") = IMATH_NAMESPACE::Eulerf::XYX; |
| 609 |
scope().attr("EULER_YXY") = IMATH_NAMESPACE::Eulerf::YXY; |
| 610 |
scope().attr("EULER_YZY") = IMATH_NAMESPACE::Eulerf::YZY; |
| 611 |
scope().attr("EULER_ZYZ") = IMATH_NAMESPACE::Eulerf::ZYZ; |
| 612 |
scope().attr("EULER_ZXZ") = IMATH_NAMESPACE::Eulerf::ZXZ; |
| 613 |
scope().attr("EULER_XYZr") = IMATH_NAMESPACE::Eulerf::XYZr; |
| 614 |
scope().attr("EULER_XZYr") = IMATH_NAMESPACE::Eulerf::XZYr; |
| 615 |
scope().attr("EULER_YZXr") = IMATH_NAMESPACE::Eulerf::YZXr; |
| 616 |
scope().attr("EULER_YXZr") = IMATH_NAMESPACE::Eulerf::YXZr; |
| 617 |
scope().attr("EULER_ZXYr") = IMATH_NAMESPACE::Eulerf::ZXYr; |
| 618 |
scope().attr("EULER_ZYXr") = IMATH_NAMESPACE::Eulerf::ZYXr; |
| 619 |
scope().attr("EULER_XZXr") = IMATH_NAMESPACE::Eulerf::XZXr; |
| 620 |
scope().attr("EULER_XYXr") = IMATH_NAMESPACE::Eulerf::XYXr; |
| 621 |
scope().attr("EULER_YXYr") = IMATH_NAMESPACE::Eulerf::YXYr; |
| 622 |
scope().attr("EULER_YZYr") = IMATH_NAMESPACE::Eulerf::YZYr; |
| 623 |
scope().attr("EULER_ZYZr") = IMATH_NAMESPACE::Eulerf::ZYZr; |
| 624 |
scope().attr("EULER_ZXZr") = IMATH_NAMESPACE::Eulerf::ZXZr; |
| 625 |
scope().attr("EULER_X_AXIS") = IMATH_NAMESPACE::Eulerf::X; |
| 626 |
scope().attr("EULER_Y_AXIS") = IMATH_NAMESPACE::Eulerf::Y; |
| 627 |
scope().attr("EULER_Z_AXIS") = IMATH_NAMESPACE::Eulerf::Z; |
| 628 |
|
| 629 |
scope().attr("INT_MIN") = std::numeric_limits<int>::min(); |
| 630 |
scope().attr("INT_MAX") = std::numeric_limits<int>::max(); |
| 631 |
scope().attr("INT_LOWEST") = std::numeric_limits<int>::lowest(); |
| 632 |
scope().attr("INT_EPS") = std::numeric_limits<int>::epsilon(); |
| 633 |
|
| 634 |
scope().attr("FLT_MIN") = std::numeric_limits<float>::min(); |
| 635 |
scope().attr("FLT_MAX") = std::numeric_limits<float>::max(); |
| 636 |
scope().attr("FLT_LOWEST") = std::numeric_limits<float>::lowest(); |
| 637 |
scope().attr("FLT_EPS") = std::numeric_limits<float>::epsilon(); |
| 638 |
|
| 639 |
scope().attr("DBL_MIN") = std::numeric_limits<double>::min(); |
| 640 |
scope().attr("DBL_MAX") = std::numeric_limits<double>::max(); |
| 641 |
scope().attr("DBL_LOWEST") = std::numeric_limits<double>::lowest(); |
| 642 |
scope().attr("DBL_EPS") = std::numeric_limits<double>::epsilon(); |
| 643 |
|
| 644 |
def("computeBoundingBox", &computeBoundingBox<float>, |
| 645 |
"computeBoundingBox(position) -- computes the bounding box from the position array."); |
| 646 |
|
| 647 |
def("computeBoundingBox", &computeBoundingBox<double>, |
| 648 |
"computeBoundingBox(position) -- computes the bounding box from the position array."); |
| 649 |
} |
| 650 |
|