Skip to content

Commit

Permalink
Added api calls for coloring all twins and coloring exterior edges an…
Browse files Browse the repository at this point in the history
…d vertices.
  • Loading branch information
mlampert authored and sliptonic committed Sep 28, 2020
1 parent 5ad3bb1 commit 926d254
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/Mod/Path/App/Voronoi.cpp
Expand Up @@ -43,28 +43,24 @@ TYPESYSTEM_SOURCE(Path::Voronoi , Base::BaseClass);

// Helpers

#if 0
static const std::size_t EXTERNAL_COLOR = 1;

static void color_exterior(const Voronoi::diagram_type::edge_type *edge) {
if (edge->color() == EXTERNAL_COLOR) {
static void colorExterior(const Voronoi::diagram_type::edge_type *edge, std::size_t colorValue) {
if (edge->color() == colorValue) {
// end recursion
return;
}
edge->color(EXTERNAL_COLOR);
edge->twin()->color(EXTERNAL_COLOR);
edge->color(colorValue);
edge->twin()->color(colorValue);
auto v = edge->vertex1();
if (v == NULL || !edge->is_primary()) {
return;
}
v->color(EXTERNAL_COLOR);
v->color(colorValue);
auto e = v->incident_edge();
do {
color_exterior(e);
colorExterior(e, colorValue);
e = e->rot_next();
} while (e != v->incident_edge());
}
#endif

// Constructors & destructors

Expand Down Expand Up @@ -147,3 +143,22 @@ void Voronoi::construct()
construct_voronoi(vd->points.begin(), vd->points.end(), vd->segments.begin(), vd->segments.end(), (voronoi_diagram_type*)vd);
vd->reIndex();
}

void Voronoi::colorExterior(int color) {
for (diagram_type::const_edge_iterator it = vd->edges().begin(); it != vd->edges().end(); ++it) {
if (!it->is_finite()) {
::colorExterior(&(*it), color);
}
}
}

void Voronoi::colorTwins(int color) {
for (diagram_type::const_edge_iterator it = vd->edges().begin(); it != vd->edges().end(); ++it) {
if (!it->color()) {
auto twin = it->twin();
if (!twin->color()) {
twin->color(color);
}
}
}
}
5 changes: 5 additions & 0 deletions src/Mod/Path/App/Voronoi.h
Expand Up @@ -89,8 +89,13 @@ namespace Path
long numEdges() const;
long numVertices() const;

void colorExterior(int color);
void colorTwins(int color);

private:
// attributes
Base::Reference<diagram_type> vd;
friend class VoronoiPy;
};

} //namespace Path
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/Path/App/VoronoiPy.xml
Expand Up @@ -63,5 +63,15 @@
<UserDocu>constructs the voronoi diagram from the input collections</UserDocu>
</Documentation>
</Methode>
<Methode Name="colorExterior">
<Documentation>
<UserDocu>assign given color to all exterior edges and vertices</UserDocu>
</Documentation>
</Methode>
<Methode Name="colorTwins">
<Documentation>
<UserDocu>assign given color to all twins of edges (which one is considered a twin is arbitrary)</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
22 changes: 22 additions & 0 deletions src/Mod/Path/App/VoronoiPyImp.cpp
Expand Up @@ -169,6 +169,28 @@ Py::List VoronoiPy::getCells(void) const {
return list;
}

PyObject* VoronoiPy::colorExterior(PyObject *args) {
int color = 0;
if (!PyArg_ParseTuple(args, "i", &color)) {
throw Py::RuntimeError("colorExterior requires an integer (color) argument");
}
getVoronoiPtr()->colorExterior(color);

Py_INCREF(Py_None);
return Py_None;
}

PyObject* VoronoiPy::colorTwins(PyObject *args) {
int color = 0;
if (!PyArg_ParseTuple(args, "i", &color)) {
throw Py::RuntimeError("colorTwins requires an integer (color) argument");
}
getVoronoiPtr()->colorTwins(color);

Py_INCREF(Py_None);
return Py_None;
}

// custom attributes get/set

PyObject *VoronoiPy::getCustomAttributes(const char* /*attr*/) const
Expand Down

0 comments on commit 926d254

Please sign in to comment.