Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added python bindings for voronoi diagram construction and accessing …
…the resulting vertices.
- Loading branch information
Showing
10 changed files
with
734 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*************************************************************************** | ||
* Copyright (c) sliptonic (shopinthewoods@gmail.com) 2020 * | ||
* * | ||
* This file is part of the FreeCAD CAx development system. * | ||
* * | ||
* This library is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU Library General Public * | ||
* License as published by the Free Software Foundation; either * | ||
* version 2 of the License, or (at your option) any later version. * | ||
* * | ||
* This library is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU Library General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Library General Public * | ||
* License along with this library; see the file COPYING.LIB. If not, * | ||
* write to the Free Software Foundation, Inc., 59 Temple Place, * | ||
* Suite 330, Boston, MA 02111-1307, USA * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#include "PreCompiled.h" | ||
|
||
#ifndef _PreComp_ | ||
# include <cinttypes> | ||
# include <iomanip> | ||
# include <boost/algorithm/string.hpp> | ||
# include <boost/lexical_cast.hpp> | ||
#endif | ||
|
||
#include <Base/Vector3D.h> | ||
#include <Base/Writer.h> | ||
#include <Base/Reader.h> | ||
#include <Base/Exception.h> | ||
#include "Voronoi.h" | ||
|
||
using namespace Base; | ||
using namespace Path; | ||
|
||
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) { | ||
// end recursion | ||
return; | ||
} | ||
edge->color(EXTERNAL_COLOR); | ||
edge->twin()->color(EXTERNAL_COLOR); | ||
auto v = edge->vertex1(); | ||
if (v == NULL || !edge->is_primary()) { | ||
return; | ||
} | ||
v->color(EXTERNAL_COLOR); | ||
auto e = v->incident_edge(); | ||
do { | ||
color_exterior(e); | ||
e = e->rot_next(); | ||
} while (e != v->incident_edge()); | ||
} | ||
#endif | ||
|
||
// Constructors & destructors | ||
|
||
Voronoi::Voronoi() | ||
:vd(new diagram_type) | ||
{ | ||
} | ||
|
||
Voronoi::~Voronoi() | ||
{ | ||
} | ||
|
||
|
||
void Voronoi::addPoint(const Voronoi::point_type &p) { | ||
points.push_back(p); | ||
} | ||
|
||
void Voronoi::addSegment(const Voronoi::segment_type &s) { | ||
segments.push_back(s); | ||
} | ||
|
||
|
||
long Voronoi::numCells() const { | ||
return vd->num_cells(); | ||
} | ||
|
||
long Voronoi::numEdges() const { | ||
return vd->num_edges(); | ||
} | ||
|
||
long Voronoi::numVertices() const { | ||
return vd->num_vertices(); | ||
} | ||
|
||
void Voronoi::construct() | ||
{ | ||
vd->clear(); | ||
construct_voronoi(points.begin(), points.end(), segments.begin(), segments.end(), (voronoi_diagram_type*)vd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*************************************************************************** | ||
* Copyright (c) sliptonic (shopinthewoods@gmail.com) 2020 * | ||
* * | ||
* This file is part of the FreeCAD CAx development system. * | ||
* * | ||
* This library is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU Library General Public * | ||
* License as published by the Free Software Foundation; either * | ||
* version 2 of the License, or (at your option) any later version. * | ||
* * | ||
* This library is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU Library General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Library General Public * | ||
* License along with this library; see the file COPYING.LIB. If not, * | ||
* write to the Free Software Foundation, Inc., 59 Temple Place, * | ||
* Suite 330, Boston, MA 02111-1307, USA * | ||
* * | ||
***************************************************************************/ | ||
#ifndef PATH_VORONOI_H | ||
#define PATH_VORONOI_H | ||
|
||
#include <map> | ||
#include <string> | ||
#include <Base/BaseClass.h> | ||
#include <Base/Handle.h> | ||
#include <Base/Vector3D.h> | ||
|
||
#include <vector> | ||
#include <boost/polygon/point_concept.hpp> | ||
#include <boost/polygon/polygon.hpp> | ||
#include <boost/polygon/segment_concept.hpp> | ||
#include <boost/polygon/voronoi.hpp> | ||
|
||
namespace Path | ||
{ | ||
class PathExport Voronoi | ||
: public Base::BaseClass | ||
{ | ||
TYPESYSTEM_HEADER(); | ||
|
||
public: | ||
//constructors | ||
Voronoi(); | ||
~Voronoi(); | ||
|
||
// types | ||
typedef double coordinate_type; | ||
typedef boost::polygon::point_data<coordinate_type> point_type; | ||
typedef boost::polygon::segment_data<coordinate_type> segment_type; | ||
typedef boost::polygon::voronoi_diagram<coordinate_type> voronoi_diagram_type; | ||
class diagram_type | ||
: public voronoi_diagram_type | ||
, public Base::Handled | ||
{ }; | ||
|
||
// specific methods | ||
void addPoint(const point_type &p); | ||
void addSegment(const segment_type &p); | ||
|
||
void construct(); | ||
long numCells() const; | ||
long numEdges() const; | ||
long numVertices() const; | ||
|
||
// attributes | ||
std::vector<point_type> points; | ||
std::vector<segment_type> segments; | ||
Base::Reference<diagram_type> vd; | ||
}; | ||
|
||
} //namespace Path | ||
|
||
#endif // PATH_VORONOI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd"> | ||
<PythonExport | ||
Father="BaseClassPy" | ||
Name="VoronoiPy" | ||
Twin="Voronoi" | ||
TwinPointer="Voronoi" | ||
Include="Mod/Path/App/Voronoi.h" | ||
Namespace="Path" | ||
FatherInclude="Base/BaseClassPy.h" | ||
FatherNamespace="Base" | ||
Constructor="true" | ||
Delete="true"> | ||
<Documentation> | ||
<Author Licence="LGPL" Name="sliptonic" EMail="shopinthewoods@gmail.com" /> | ||
<UserDocu>Voronoi([segments]): Create voronoi for given collection of line segments</UserDocu> | ||
</Documentation> | ||
<!-- | ||
<Attribute Name="Cells" ReadOnly="true"> | ||
<Documentation> | ||
<UserDocu>List of all cells of the voronoi diagram</UserDocu> | ||
</Documentation> | ||
<Parameter Name="Cells" Type="List"/> | ||
</Attribute> | ||
<Attribute Name="Edges" ReadOnly="true"> | ||
<Documentation> | ||
<UserDocu>List of all edges of the voronoi diagram</UserDocu> | ||
</Documentation> | ||
<Parameter Name="Edges" Type="List"/> | ||
</Attribute> | ||
--> | ||
<Attribute Name="Vertices" ReadOnly="true"> | ||
<Documentation> | ||
<UserDocu>List of all vertices of the voronoi diagram</UserDocu> | ||
</Documentation> | ||
<Parameter Name="Vertices" Type="List"/> | ||
</Attribute> | ||
<Methode Name="numCells" Const="true"> | ||
<Documentation> | ||
<UserDocu>Return number of cells</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="numEdges" Const="true"> | ||
<Documentation> | ||
<UserDocu>Return number of edges</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="numVertices" Const="true"> | ||
<Documentation> | ||
<UserDocu>Return number of vertices</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="addPoint"> | ||
<Documentation> | ||
<UserDocu>addPoint(vector|vector2d) add given point to input collection</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="addSegment"> | ||
<Documentation> | ||
<UserDocu>addSegment(vector|vector2d, vector|vector2d) add given segment to input collection</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="construct"> | ||
<Documentation> | ||
<UserDocu>constructs the voronoi diagram from the input collections</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
</PythonExport> | ||
</GenerateModel> |
Oops, something went wrong.