Added api calls for coloring all twins and coloring exterior edges and vertices.
This commit is contained in:
committed by
sliptonic
parent
5ad3bb17fd
commit
926d254849
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user