Added retrieval of points and segments for voronoi diagram

This commit is contained in:
Markus Lampert
2020-09-09 21:30:45 -07:00
committed by sliptonic
parent 6d43d75028
commit 7777e0f265
3 changed files with 69 additions and 1 deletions

View File

@@ -293,7 +293,7 @@ void Voronoi::colorColinear(Voronoi::color_type color, double degree) {
void Voronoi::resetColor(Voronoi::color_type color) {
for (auto it = vd->cells().begin(); it != vd->cells().end(); ++it) {
if (color == -1 || it->color() == color) {
if (color == 0 || it->color() == color) {
it->color(0);
}
}

View File

@@ -83,5 +83,25 @@
<UserDocu>assign color 0 to all elements with the given color</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPoints" Const="true">
<Documentation>
<UserDocu>Get list of all input points.</UserDocu>
</Documentation>
</Methode>
<Methode Name="numPoints" Const="true">
<Documentation>
<UserDocu>Return number of input points</UserDocu>
</Documentation>
</Methode>
<Methode Name="getSegments" Const="true">
<Documentation>
<UserDocu>Get list of all input segments.</UserDocu>
</Documentation>
</Methode>
<Methode Name="numSegments" Const="true">
<Documentation>
<UserDocu>Return number of input segments</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -253,6 +253,54 @@ PyObject* VoronoiPy::resetColor(PyObject *args) {
return Py_None;
}
PyObject* VoronoiPy::getPoints(PyObject *args) {
double z = 0;
if (!PyArg_ParseTuple(args, "|d", &z)) {
throw Py::RuntimeError("Optional z argument (double) accepted");
}
Voronoi *vo = getVoronoiPtr();
Py::List list;
for (auto it = vo->vd->points.begin(); it != vo->vd->points.end(); ++it) {
list.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(vo->vd->scaledVector(*it, z)))));
}
return Py::new_reference_to(list);
}
PyObject* VoronoiPy::getSegments(PyObject *args) {
double z = 0;
if (!PyArg_ParseTuple(args, "|d", &z)) {
throw Py::RuntimeError("Optional z argument (double) accepted");
}
Voronoi *vo = getVoronoiPtr();
Py::List list;
for (auto it = vo->vd->segments.begin(); it != vo->vd->segments.end(); ++it) {
PyObject *p0 = new Base::VectorPy(new Base::Vector3d(vo->vd->scaledVector(low(*it), z)));
PyObject *p1 = new Base::VectorPy(new Base::Vector3d(vo->vd->scaledVector(high(*it), z)));
PyObject *tp = PyTuple_New(2);
PyTuple_SetItem(tp, 0, p0);
PyTuple_SetItem(tp, 1, p1);
list.append(Py::asObject(tp));
}
return Py::new_reference_to(list);
}
PyObject* VoronoiPy::numPoints(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) {
throw Py::RuntimeError("no arguments accepted");
}
return PyLong_FromLong(getVoronoiPtr()->vd->points.size());
}
PyObject* VoronoiPy::numSegments(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) {
throw Py::RuntimeError("no arguments accepted");
}
return PyLong_FromLong(getVoronoiPtr()->vd->segments.size());
}
// custom attributes get/set
PyObject *VoronoiPy::getCustomAttributes(const char* /*attr*/) const