Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add triangulation model and delaunay triangulation algorithm. #684

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/example/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ project boost-geometry-examples-extensions
;

build-project gis ;
build-project triangulation ;
11 changes: 11 additions & 0 deletions extensions/example/triangulation/Jamfile.v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Boost.Geometry (aka GGL, Generic Geometry Library)
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

project boost-geometry-example-extensions-triangulation
: # requirements
;

exe triangulation_example : triangulation_example.cpp ;
56 changes: 56 additions & 0 deletions extensions/example/triangulation/triangulation_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// Triangulation Example - computes a delaunay triangulation and draws the
// triangulation and the corresponding finite voronoi edges

#include <fstream>
#include <random>
#include <vector>

#include <boost/geometry.hpp>
#include <boost/geometry/extensions/triangulation/triangulation.hpp>
#include <boost/geometry/extensions/triangulation/geometries/voronoi_adaptor.hpp>

const int samples = 100;

int main()
{
namespace bg = boost::geometry;
typedef bg::model::point<double, 2, bg::cs::cartesian> point;
typedef bg::model::triangulation<point> triangulation;

std::default_random_engine gen(1);
std::uniform_real_distribution<> dist(0.0, 1.0);
std::vector<point> in;
for (int i = 0 ; i < samples ; ++i)
{
in.push_back(point(dist(gen), dist(gen)));
}
triangulation out(samples);
bg::delaunay_triangulation(in, out);

std::ofstream svg("triangulation.svg");
bg::svg_mapper<point> mapper(svg, 720, 720);
mapper.add(point(0, 0));
mapper.add(point(1, 1));

for (auto const& f : bg::face_range(out))
{
mapper.map(f, "fill-opacity:0.3;fill:rgb(102,102,201);stroke:rgb(51,51,152);");
}

typedef bg::model::voronoi_face_view<triangulation> voronoi_face_view;
for (auto it = out.vertices_begin() ; it != out.vertices_end() ; ++it)
{
voronoi_face_view vfv(out, it);
mapper.map(voronoi_face_view(out, it), "opacity:1.0;fill:none;stroke:rgb(255,0,0);stroke-width:1");
}

return 0;
}
1 change: 1 addition & 0 deletions extensions/test/triangulation/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ test-suite boost-geometry-extensions-triangulation
:
[ run side_robust.cpp ]
[ run in_circle_robust.cpp ]
[ run triangulation.cpp ]
;

45 changes: 45 additions & 0 deletions extensions/test/triangulation/triangulation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test

// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.

// Contributed and/or modified by Tinko Bartels,
// as part of Google Summer of Code 2019 program.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <geometry_test_common.hpp>

#include <vector>

#include <boost/geometry.hpp>
#include <boost/geometry/extensions/triangulation/triangulation.hpp>

namespace bg = boost::geometry;

template <typename P>
void test_all()
{
typedef bg::model::triangulation<P, false> triangulation;
std::vector<P> in;
in.push_back(P(-1, -2));
in.push_back(P(1, -2));
in.push_back(P(-2, 0));
in.push_back(P(2, 0));
in.push_back(P(1, 2));
in.push_back(P(-1, 2));
in.push_back(P(0, 0));
in.push_back(P(0, 1));
triangulation t(8);
bg::delaunay_triangulation(in, t);
BOOST_CHECK( t.valid() );
}


int test_main(int, char* [])
{
test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.

// Contributed and/or modified by Tinko Bartels,
// as part of Google Summer of Code 2019 program.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_GEOMETRY_EXTENSIONS_TRIANGULATION_ALGORITHMS_DELAUNAY_TRIANGULATION_HPP
#define BOOST_GEOMETRY_EXTENSIONS_TRIANGULATION_ALGORITHMS_DELAUNAY_TRIANGULATION_HPP

#include <vector>
#include <utility>
#include <tuple>
#include <iterator>
#include <algorithm>

#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>


#include <boost/geometry/algorithms/make.hpp>
#include <boost/geometry/algorithms/comparable_distance.hpp>
#include <boost/geometry/extensions/triangulation/geometries/triangulation.hpp>
#include <boost/geometry/extensions/triangulation/strategies/cartesian/in_circle_robust.hpp>
#include <boost/geometry/extensions/triangulation/strategies/delaunay_triangulation.hpp>
#include <boost/geometry/extensions/triangulation/strategies/cartesian/accelerated_shull.hpp>
#include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>

namespace boost { namespace geometry
{

template
<
typename PointContainer,
typename Triangulation,
typename SideStrategy = strategy::side::side_by_triangle<>,
typename InCircleStrategy = strategy::in_circle::in_circle_robust<>,
typename ConstructionStrategy =
typename strategy::delaunay_triangulation::services::default_strategy
<
typename tag<typename PointContainer::value_type>::type,
typename cs_tag<typename PointContainer::value_type>::type,
dimension<typename PointContainer::value_type>::value
>::type
>
inline void delaunay_triangulation(PointContainer const & in,
Triangulation& out,
bool legalize = true)
{
ConstructionStrategy::template apply
<
PointContainer,
Triangulation,
SideStrategy,
InCircleStrategy
>(in, out, legalize);
}

}} // namespace boost::geometry

#endif // BOOST_GEOMETRY_EXTENSIONS_TRIANGULATION_ALGORITHMS_DELAUNAY_TRIANGULATION_HPP
Loading