MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/Imath / procrustes1

Function procrustes1

src/python/PyImath/imathmodule.cpp:56–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56IMATH_NAMESPACE::M44d
57procrustes1 (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

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected