py3: ported Mesh to python3
This commit is contained in:
@@ -82,8 +82,18 @@ int MeshPy::PyInit(PyObject* args, PyObject*)
|
||||
Py_XDECREF(ret);
|
||||
if (!ok) return -1;
|
||||
}
|
||||
else if (PyUnicode_Check(pcObj)) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
getMeshObjectPtr()->load(PyUnicode_AsUTF8(pcObj));
|
||||
#else
|
||||
PyObject* unicode = PyUnicode_AsEncodedString(pcObj, "utf-8", 0);
|
||||
char* pItem = PyString_AsString(unicode);
|
||||
Py_DECREF(unicode);
|
||||
getMeshObjectPtr()->load(pItem);
|
||||
}
|
||||
else if (PyString_Check(pcObj)) {
|
||||
getMeshObjectPtr()->load(PyString_AsString(pcObj));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError, "Cannot create a mesh out of a '%s'",
|
||||
@@ -686,9 +696,15 @@ PyObject* MeshPy::addFacets(PyObject *args)
|
||||
for (Py::List::iterator it = list_f.begin(); it != list_f.end(); ++it) {
|
||||
Py::Tuple f(*it);
|
||||
MeshCore::MeshFacet face;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
face._aulPoints[0] = (long)Py::Long(f.getItem(0));
|
||||
face._aulPoints[1] = (long)Py::Long(f.getItem(1));
|
||||
face._aulPoints[2] = (long)Py::Long(f.getItem(2));
|
||||
#else
|
||||
face._aulPoints[0] = (long)Py::Int(f.getItem(0));
|
||||
face._aulPoints[1] = (long)Py::Int(f.getItem(1));
|
||||
face._aulPoints[2] = (long)Py::Int(f.getItem(2));
|
||||
#endif
|
||||
faces.push_back(face);
|
||||
}
|
||||
|
||||
@@ -712,7 +728,11 @@ PyObject* MeshPy::removeFacets(PyObject *args)
|
||||
std::vector<unsigned long> indices;
|
||||
Py::Sequence ary(list);
|
||||
for (Py::Sequence::iterator it = ary.begin(); it != ary.end(); ++it) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py::Long f(*it);
|
||||
#else
|
||||
Py::Int f(*it);
|
||||
#endif
|
||||
indices.push_back((long)f);
|
||||
}
|
||||
|
||||
@@ -816,7 +836,11 @@ PyObject* MeshPy::getSegment(PyObject *args)
|
||||
Py::List ary;
|
||||
const std::vector<unsigned long>& segm = getMeshObjectPtr()->getSegment(index).getIndices();
|
||||
for (std::vector<unsigned long>::const_iterator it = segm.begin(); it != segm.end(); ++it) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
ary.append(Py::Long((int)*it));
|
||||
#else
|
||||
ary.append(Py::Int((int)*it));
|
||||
#endif
|
||||
}
|
||||
|
||||
return Py::new_reference_to(ary);
|
||||
@@ -846,7 +870,11 @@ PyObject* MeshPy::getFacetSelection(PyObject *args)
|
||||
std::vector<unsigned long> facets;
|
||||
getMeshObjectPtr()->getFacetsFromSelection(facets);
|
||||
for (std::vector<unsigned long>::const_iterator it = facets.begin(); it != facets.end(); ++it) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
ary.append(Py::Long((int)*it));
|
||||
#else
|
||||
ary.append(Py::Int((int)*it));
|
||||
#endif
|
||||
}
|
||||
|
||||
return Py::new_reference_to(ary);
|
||||
@@ -861,7 +889,11 @@ PyObject* MeshPy::getPointSelection(PyObject *args)
|
||||
std::vector<unsigned long> points;
|
||||
getMeshObjectPtr()->getPointsFromSelection(points);
|
||||
for (std::vector<unsigned long>::const_iterator it = points.begin(); it != points.end(); ++it) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
ary.append(Py::Long((int)*it));
|
||||
#else
|
||||
ary.append(Py::Int((int)*it));
|
||||
#endif
|
||||
}
|
||||
|
||||
return Py::new_reference_to(ary);
|
||||
@@ -876,7 +908,11 @@ PyObject* MeshPy::meshFromSegment(PyObject *args)
|
||||
std::vector<unsigned long> segment;
|
||||
Py::Sequence ary(list);
|
||||
for (Py::Sequence::iterator it = ary.begin(); it != ary.end(); ++it) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py::Long f(*it);
|
||||
#else
|
||||
Py::Int f(*it);
|
||||
#endif
|
||||
segment.push_back((long)f);
|
||||
}
|
||||
|
||||
@@ -1441,8 +1477,13 @@ PyObject* MeshPy::collapseFacets(PyObject *args)
|
||||
std::vector<unsigned long> facets;
|
||||
for (int i = 0; i < PyList_Size(pcObj); i++) {
|
||||
PyObject *idx = PyList_GetItem(pcObj, i);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyLong_Check(idx)){
|
||||
unsigned long iIdx = PyLong_AsLong(idx);
|
||||
#else
|
||||
if (PyInt_Check(idx)){
|
||||
unsigned long iIdx = PyInt_AsLong(idx);
|
||||
#endif
|
||||
facets.push_back(iIdx);
|
||||
}
|
||||
else {
|
||||
@@ -1487,7 +1528,11 @@ PyObject* MeshPy::foraminate(PyObject *args)
|
||||
tuple.setItem(0, Py::Float(res.x));
|
||||
tuple.setItem(1, Py::Float(res.y));
|
||||
tuple.setItem(2, Py::Float(res.z));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
dict.setItem(Py::Long(index), tuple);
|
||||
#else
|
||||
dict.setItem(Py::Int(index), tuple);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1615,7 +1660,11 @@ PyObject* MeshPy::nearestFacetOnRay(PyObject *args)
|
||||
tuple.setItem(0, Py::Float(res.x));
|
||||
tuple.setItem(1, Py::Float(res.y));
|
||||
tuple.setItem(2, Py::Float(res.z));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
dict.setItem(Py::Long((int)index), tuple);
|
||||
#else
|
||||
dict.setItem(Py::Int((int)index), tuple);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0 // for testing only
|
||||
@@ -1660,7 +1709,11 @@ PyObject* MeshPy::getPlanarSegments(PyObject *args)
|
||||
const std::vector<unsigned long>& segm = it->getIndices();
|
||||
Py::List ary;
|
||||
for (std::vector<unsigned long>::const_iterator jt = segm.begin(); jt != segm.end(); ++jt) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
ary.append(Py::Long((int)*jt));
|
||||
#else
|
||||
ary.append(Py::Int((int)*jt));
|
||||
#endif
|
||||
}
|
||||
s.append(ary);
|
||||
}
|
||||
@@ -1687,7 +1740,11 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
|
||||
float c2 = (float)Py::Float(t[1]);
|
||||
float tol1 = (float)Py::Float(t[2]);
|
||||
float tol2 = (float)Py::Float(t[3]);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
int num = (int)Py::Long(t[4]);
|
||||
#else
|
||||
int num = (int)Py::Int(t[4]);
|
||||
#endif
|
||||
segm.push_back(new MeshCore::MeshCurvatureFreeformSegment(meshCurv.GetCurvature(), num, tol1, tol2, c1, c2));
|
||||
}
|
||||
|
||||
@@ -1699,7 +1756,11 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
|
||||
for (std::vector<MeshCore::MeshSegment>::const_iterator it = data.begin(); it != data.end(); ++it) {
|
||||
Py::List ary;
|
||||
for (MeshCore::MeshSegment::const_iterator jt = it->begin(); jt != it->end(); ++jt) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
ary.append(Py::Long((int)*jt));
|
||||
#else
|
||||
ary.append(Py::Int((int)*jt));
|
||||
#endif
|
||||
}
|
||||
list.append(ary);
|
||||
}
|
||||
@@ -1708,7 +1769,22 @@ PyObject* MeshPy::getSegmentsByCurvature(PyObject *args)
|
||||
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py::Long MeshPy::getCountPoints(void) const
|
||||
{
|
||||
return Py::Long((long)getMeshObjectPtr()->countPoints());
|
||||
}
|
||||
|
||||
Py::Long MeshPy::getCountEdges(void) const
|
||||
{
|
||||
return Py::Long((long)getMeshObjectPtr()->countEdges());
|
||||
}
|
||||
|
||||
Py::Long MeshPy::getCountFacets(void) const
|
||||
{
|
||||
return Py::Long((long)getMeshObjectPtr()->countFacets());
|
||||
}
|
||||
#else
|
||||
Py::Int MeshPy::getCountPoints(void) const
|
||||
{
|
||||
return Py::Int((long)getMeshObjectPtr()->countPoints());
|
||||
@@ -1723,6 +1799,7 @@ Py::Int MeshPy::getCountFacets(void) const
|
||||
{
|
||||
return Py::Int((long)getMeshObjectPtr()->countFacets());
|
||||
}
|
||||
#endif
|
||||
|
||||
Py::Float MeshPy::getArea(void) const
|
||||
{
|
||||
@@ -1780,9 +1857,15 @@ Py::Tuple MeshPy::getTopology(void) const
|
||||
for (std::vector<Data::ComplexGeoData::Facet>::const_iterator
|
||||
it = Facets.begin(); it != Facets.end(); ++it) {
|
||||
Py::Tuple f(3);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
f.setItem(0,Py::Long((int)it->I1));
|
||||
f.setItem(1,Py::Long((int)it->I2));
|
||||
f.setItem(2,Py::Long((int)it->I3));
|
||||
#else
|
||||
f.setItem(0,Py::Int((int)it->I1));
|
||||
f.setItem(1,Py::Int((int)it->I2));
|
||||
f.setItem(2,Py::Int((int)it->I3));
|
||||
#endif
|
||||
facet.append(f);
|
||||
}
|
||||
tuple.setItem(1, facet);
|
||||
|
||||
Reference in New Issue
Block a user