py3: ported Mesh to python3
This commit is contained in:
parent
f6b6e62a57
commit
3803896ff2
|
@ -50,7 +50,7 @@ Returns true if the facet is degenerated, otherwise false.
|
|||
<Documentation>
|
||||
<UserDocu>The index of this facet in the MeshObject</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Index" Type="Int"/>
|
||||
<Parameter Name="Index" Type="Long"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Bound" ReadOnly="true">
|
||||
<Documentation>
|
||||
|
|
|
@ -76,10 +76,15 @@ PyObject* FacetPy::unbound(PyObject *args)
|
|||
getFacetPtr()->Mesh = 0;
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py::Long FacetPy::getIndex(void) const
|
||||
{
|
||||
return Py::Long((long) getFacetPtr()->Index);
|
||||
#else
|
||||
Py::Int FacetPy::getIndex(void) const
|
||||
{
|
||||
return Py::Int((long) getFacetPtr()->Index);
|
||||
#endif
|
||||
}
|
||||
|
||||
Py::Boolean FacetPy::getBound(void) const
|
||||
|
|
|
@ -1465,7 +1465,11 @@ MeshObject* MeshObject::createSphere(float radius, int sampling)
|
|||
Py::Callable call(dict.getItem("Sphere"));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::Float(radius));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
args.setItem(1, Py::Long(sampling));
|
||||
#else
|
||||
args.setItem(1, Py::Int(sampling));
|
||||
#endif
|
||||
Py::List list(call.apply(args));
|
||||
return createMeshFromList(list);
|
||||
}
|
||||
|
@ -1487,7 +1491,11 @@ MeshObject* MeshObject::createEllipsoid(float radius1, float radius2, int sampli
|
|||
Py::Tuple args(3);
|
||||
args.setItem(0, Py::Float(radius1));
|
||||
args.setItem(1, Py::Float(radius2));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
args.setItem(2, Py::Long(sampling));
|
||||
#else
|
||||
args.setItem(2, Py::Int(sampling));
|
||||
#endif
|
||||
Py::List list(call.apply(args));
|
||||
return createMeshFromList(list);
|
||||
}
|
||||
|
@ -1509,9 +1517,15 @@ MeshObject* MeshObject::createCylinder(float radius, float length, int closed, f
|
|||
Py::Tuple args(5);
|
||||
args.setItem(0, Py::Float(radius));
|
||||
args.setItem(1, Py::Float(length));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
args.setItem(2, Py::Long(closed));
|
||||
args.setItem(3, Py::Float(edgelen));
|
||||
args.setItem(4, Py::Long(sampling));
|
||||
#else
|
||||
args.setItem(2, Py::Int(closed));
|
||||
args.setItem(3, Py::Float(edgelen));
|
||||
args.setItem(4, Py::Int(sampling));
|
||||
#endif
|
||||
Py::List list(call.apply(args));
|
||||
return createMeshFromList(list);
|
||||
}
|
||||
|
@ -1534,9 +1548,15 @@ MeshObject* MeshObject::createCone(float radius1, float radius2, float len, int
|
|||
args.setItem(0, Py::Float(radius1));
|
||||
args.setItem(1, Py::Float(radius2));
|
||||
args.setItem(2, Py::Float(len));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
args.setItem(3, Py::Long(closed));
|
||||
args.setItem(4, Py::Float(edgelen));
|
||||
args.setItem(5, Py::Long(sampling));
|
||||
#else
|
||||
args.setItem(3, Py::Int(closed));
|
||||
args.setItem(4, Py::Float(edgelen));
|
||||
args.setItem(5, Py::Int(sampling));
|
||||
#endif
|
||||
Py::List list(call.apply(args));
|
||||
return createMeshFromList(list);
|
||||
}
|
||||
|
@ -1558,7 +1578,11 @@ MeshObject* MeshObject::createTorus(float radius1, float radius2, int sampling)
|
|||
Py::Tuple args(3);
|
||||
args.setItem(0, Py::Float(radius1));
|
||||
args.setItem(1, Py::Float(radius2));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
args.setItem(2, Py::Long(sampling));
|
||||
#else
|
||||
args.setItem(2, Py::Int(sampling));
|
||||
#endif
|
||||
Py::List list(call.apply(args));
|
||||
return createMeshFromList(list);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ have self intersections!
|
|||
<Documentation>
|
||||
<UserDocu>The index of this point in the MeshObject</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Index" Type="Int"/>
|
||||
<Parameter Name="Index" Type="Long"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Bound" ReadOnly="true">
|
||||
<Documentation>
|
||||
|
|
|
@ -100,9 +100,15 @@ PyObject* MeshPointPy::move(PyObject *args)
|
|||
Py_Return;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py::Long MeshPointPy::getIndex(void) const
|
||||
{
|
||||
return Py::Long((long) getMeshPointPtr()->Index);
|
||||
#else
|
||||
Py::Int MeshPointPy::getIndex(void) const
|
||||
{
|
||||
return Py::Int((long) getMeshPointPtr()->Index);
|
||||
#endif
|
||||
}
|
||||
|
||||
Py::Boolean MeshPointPy::getBound(void) const
|
||||
|
|
|
@ -459,13 +459,13 @@ for p in mesh.Points:
|
|||
<Documentation>
|
||||
<UserDocu>Return the number of vertices of the mesh object.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="CountPoints" Type="Int" />
|
||||
<Parameter Name="CountPoints" Type="Long" />
|
||||
</Attribute>
|
||||
<Attribute Name="CountEdges" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Return the number of edges of the mesh object.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="CountEdges" Type="Int" />
|
||||
<Parameter Name="CountEdges" Type="Long" />
|
||||
</Attribute>
|
||||
<Attribute Name="Facets" ReadOnly="true">
|
||||
<Documentation>
|
||||
|
@ -480,7 +480,7 @@ for p in mesh.Facets:
|
|||
<Documentation>
|
||||
<UserDocu>Return the number of facets of the mesh object.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="CountFacets" Type="Int" />
|
||||
<Parameter Name="CountFacets" Type="Long" />
|
||||
</Attribute>
|
||||
<Attribute Name="Topology" ReadOnly="true">
|
||||
<Documentation>
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user