Skip to content

Commit 9649062

Browse files
Merge pull request #2 from Siddharth-coder13/3d-geometries
Polyhedral read feature
2 parents ff1f245 + 80442cb commit 9649062

File tree

12 files changed

+278
-2
lines changed

12 files changed

+278
-2
lines changed

example/01_point_example.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ int main()
107107

108108

109109
// Some ways of getting point values
110+
typedef model::point<double, 3, cs::cartesian> point_t;
111+
typedef model::ring<point_t> ring_t;
112+
typedef model::PolyhedralSurface<ring_t> poly_t;
113+
114+
poly_t polyhedron1;
115+
poly_t polyhedron2 = {{{0,0,0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 1, 0}, {0, 1, 1}, {0, 0, 1}, {0, 0, 0}},
116+
{{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}, {0, 0, 0}}, {{1, 1, 1}, {1, 0, 1}, {0, 0, 1}, {0, 1, 1}, {1, 1, 1}}, {{1, 1, 1}, {1, 0, 1}, {1, 0, 0}, {1, 1, 0}, {1, 1, 1}},
117+
{{1, 1, 1}, {1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1, 1}} };
118+
119+
//append(polyhedron1[0], point_t{1, 0, 0});
120+
//append(polyhedron1[0], point_t{0, 0, 0});
121+
//append(polyhedron1[0], point_t{0, 1, 0});
122+
//append(polyhedron1[0], point_t{1, 1, 0});
123+
//append(polyhedron1[0], point_t{0, 0, 0});
124+
read_wkt("POLYHEDRALSURFACE Z(((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)), ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)), ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)))", polyhedron1);
125+
126+
typedef model::polygon<point_2d> poly;
127+
poly polygon1;
128+
read_wkt("POLYGON((0 0, 0 7, 4 2, 2 0, 0 0))", polygon1);
129+
130+
typedef model::linestring<point_2d> lines;
131+
lines line;
132+
read_wkt("LINESTRING(0 0, 2 2, 3 1)", line);
110133

111134
// 1: using the "get" function following the concepts behind
112135
std::cout << get<0>(p2) << "," << get<1>(p2) << std::endl;

include/boost/geometry/algorithms/clear.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ struct clear<Geometry, ring_tag>
123123
: detail::clear::collection_clear<Geometry>
124124
{};
125125

126+
// Clear for Polyhedral surface
127+
template <typename Geometry>
128+
struct clear<Geometry, polyhedral_surface_tag>
129+
: detail::clear::no_action<Geometry>
130+
{};
126131

127132
// Polygon can (indirectly) use std for clear
128133
template <typename Polygon>

include/boost/geometry/core/point_type.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ struct point_type<ring_tag, Ring>
9292
typedef typename boost::range_value<Ring>::type type;
9393
};
9494

95+
// Specialization for PolyhedralSurface: the point-type is the point-type of its rings
96+
template <typename PolyhedralSurface>
97+
struct point_type<polyhedral_surface_tag, PolyhedralSurface>
98+
{
99+
typedef typename point_type
100+
<
101+
ring_tag,
102+
typename ring_type<polyhedral_surface_tag, PolyhedralSurface>::type
103+
>::type type;
104+
};
95105

96106
// Specialization for polygon: the point-type is the point-type of its rings
97107
template <typename Polygon>

include/boost/geometry/core/ring_type.hpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <type_traits>
2424

2525
#include <boost/range/value_type.hpp>
26-
2726
#include <boost/geometry/core/static_assert.hpp>
2827
#include <boost/geometry/core/tag.hpp>
2928
#include <boost/geometry/core/tags.hpp>
@@ -61,6 +60,13 @@ struct ring_mutable_type
6160
Geometry);
6261
};
6362

63+
template <typename Geometry>
64+
struct Poly_ring_type
65+
{
66+
BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
67+
"Not implemented for this Geometry type.",
68+
Geometry);
69+
};
6470

6571
} // namespace traits
6672

@@ -87,6 +93,11 @@ struct ring_return_type<ring_tag, Ring>
8793
typedef Ring& type;
8894
};
8995

96+
template <typename PolyhedralSurface>
97+
struct ring_return_type<polyhedral_surface_tag, PolyhedralSurface>
98+
{
99+
typedef typename traits::Poly_ring_type<PolyhedralSurface>::type type;
100+
};
90101

91102
template <typename Polygon>
92103
struct ring_return_type<polygon_tag, Polygon>
@@ -145,6 +156,15 @@ struct ring_type<ring_tag, Ring>
145156
typedef Ring type;
146157
};
147158

159+
template <typename PolyhedralSurface>
160+
struct ring_type<polyhedral_surface_tag, PolyhedralSurface>
161+
{
162+
typedef typename std::remove_reference
163+
<
164+
typename ring_return_type<polyhedral_surface_tag, PolyhedralSurface>::type
165+
>::type type;
166+
};
167+
148168

149169
template <typename Polygon>
150170
struct ring_type<polygon_tag, Polygon>

include/boost/geometry/core/tags.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct box_tag : single_tag, areal_tag {};
105105
/// Convenience segment (2-points) identifying tag
106106
struct segment_tag : single_tag, linear_tag {};
107107

108+
/// OGC Polyhedral surface identifying tag
109+
struct polyhedral_surface_tag : single_tag, volumetric_tag {};
110+
108111

109112
/// OGC Multi point identifying tag
110113
struct multi_point_tag : multi_tag, pointlike_tag {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#ifndef BOOST_GEOMETRY_GEOMETRIES_POLYHEDRALSURFACE_HPP
2+
#define BOOST_GEOMETRY_GEOMETRIES_POLYHEDRALSURFACE_HPP
3+
4+
#include <memory>
5+
#include <vector>
6+
7+
#include <boost/concept/assert.hpp>
8+
9+
#include <boost/geometry/geometries/concepts/point_concept.hpp>
10+
#include <boost/geometry/geometries/ring.hpp>
11+
#include <boost/geometry/core/tag.hpp>
12+
#include <boost/geometry/core/tags.hpp>
13+
14+
#include <boost/config.hpp>
15+
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
16+
#include <initializer_list>
17+
#endif
18+
19+
namespace boost { namespace geometry
20+
{
21+
22+
namespace model
23+
{
24+
25+
26+
template
27+
<
28+
typename Ring,
29+
template<typename, typename> class Container = std::vector,
30+
template<typename> class Allocator = std::allocator
31+
32+
>
33+
class PolyhedralSurface : public Container<Ring, Allocator<Ring> >
34+
{
35+
BOOST_CONCEPT_ASSERT( (concepts::Ring<Ring>) );
36+
37+
public :
38+
39+
using point_type = model::point<double, 3, boost::geometry::cs::cartesian>;
40+
using ring_type = ring<point_type, true, true>;
41+
using ph = Container<ring_type, Allocator<ring_type> >;
42+
43+
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
44+
45+
/// \constructor_default{polyhedron}
46+
inline PolyhedralSurface()
47+
: ph()
48+
{}
49+
50+
/// \constructor_initialized_list{polyhedron}
51+
inline PolyhedralSurface(std::initializer_list<ring_type> l)
52+
: ph(l.begin(), l.end())
53+
{}
54+
55+
#endif
56+
57+
};
58+
59+
} // namespace model
60+
61+
#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
62+
namespace traits
63+
{
64+
65+
template
66+
<
67+
typename Ring,
68+
template<typename, typename> class Container,
69+
template<typename> class Allocator
70+
>
71+
struct tag
72+
<
73+
model::PolyhedralSurface
74+
<
75+
Ring,
76+
Container, Allocator
77+
>
78+
>
79+
{
80+
typedef polyhedral_surface_tag type;
81+
};
82+
83+
template
84+
<
85+
typename Ring,
86+
template<typename, typename> class Container,
87+
template<typename> class Allocator
88+
>
89+
struct Poly_ring_type
90+
<
91+
model::PolyhedralSurface
92+
<
93+
Ring,
94+
Container, Allocator
95+
>
96+
>
97+
{
98+
typedef typename model::PolyhedralSurface
99+
<
100+
Ring,
101+
Container, Allocator
102+
>::ring_type& type;
103+
};
104+
105+
106+
107+
108+
} // namespace traits
109+
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
110+
111+
}} // namespace boost::geometry
112+
113+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POLYHEDRALSURFACE_HPP
2+
#define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POLYHEDRALSURFACE_HPP
3+
4+
#include <boost/concept_check.hpp>
5+
#include <boost/range/concepts.hpp>
6+
#include <boost/geometry/core/access.hpp>
7+
#include <boost/geometry/core/ring_type.hpp>
8+
#include <boost/geometry/geometries/concepts/ring_concept.hpp>
9+
10+
namespace boost { namespace geometry { namespace concepts
11+
{
12+
13+
14+
template <typename Geometry>
15+
class PolyhedralSurface
16+
{
17+
18+
#ifndef DOXYGEN_NO_CONCEPT_MEMBERS
19+
20+
typedef typename ring_type<Geometry>::type ring_type;
21+
22+
23+
BOOST_CONCEPT_ASSERT( (concepts::Ring<ring_type>) );
24+
25+
public:
26+
27+
BOOST_CONCEPT_USAGE(PolyhedralSurface)
28+
{
29+
30+
}
31+
#endif
32+
33+
};
34+
35+
} // namepspace concepts
36+
37+
} // namespace geometry
38+
39+
} // namespace boost
40+
#endif

include/boost/geometry/geometries/concepts/check.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <boost/geometry/geometries/concepts/polygon_concept.hpp>
4040
#include <boost/geometry/geometries/concepts/ring_concept.hpp>
4141
#include <boost/geometry/geometries/concepts/segment_concept.hpp>
42-
42+
#include <boost/geometry/geometries/concepts/PolyhedralSurface_concept.hpp>
4343
#include <boost/geometry/algorithms/not_implemented.hpp>
4444

4545
namespace boost { namespace geometry
@@ -121,6 +121,10 @@ struct check<Geometry, polygon_tag, false>
121121
: detail::concept_check::check<concepts::Polygon<Geometry> >
122122
{};
123123

124+
template <typename Geometry>
125+
struct check<Geometry, polyhedral_surface_tag, false>
126+
: detail::concept_check::check<concepts::PolyhedralSurface<Geometry> >
127+
{};
124128

125129
template <typename Geometry>
126130
struct check<Geometry, box_tag, true>

include/boost/geometry/geometries/geometries.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
#include <boost/geometry/geometries/polygon.hpp>
3030
#include <boost/geometry/geometries/ring.hpp>
3131
#include <boost/geometry/geometries/segment.hpp>
32+
#include <boost/geometry/geometries/PolyhedralSurface.hpp>
3233

3334
#endif // BOOST_GEOMETRY_GEOMETRIES_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef BOOST_GEOMETRY_GEOMETRIES_REGISTER_POLYHEDRALSURFACE_HPP
2+
#define BOOST_GEOMETRY_GEOMETRIES_REGISTER_POLYHEDRALSURFACE_HPP
3+
4+
5+
#include <boost/geometry/core/tag.hpp>
6+
#include <boost/geometry/core/tags.hpp>
7+
8+
#define BOOST_GEOMETRY_REGISTER_POLYHEDRALSURFACE(PolyhedralSurface) \
9+
namespace boost { namespace geometry { namespace traits { \
10+
template<> struct tag<PolyhedralSurface> { typedef PolyhedralSurface_tag type; }; \
11+
}}}
12+
13+
14+
#define BOOST_GEOMETRY_REGISTER_POLYHEDRALSURFACE_TEMPLATED(PolyhedralSurface) \
15+
namespace boost { namespace geometry { namespace traits { \
16+
template<typename P> struct tag< PolyhedralSurface<P> > { typedef PolyhedralSurface_tag type; }; \
17+
}}}

include/boost/geometry/io/wkt/detail/prefix.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ struct prefix_linestring
4747
static inline const char* apply() { return "LINESTRING"; }
4848
};
4949

50+
struct prefix_polyhedral_surface
51+
{
52+
static inline const char* apply() { return "POLYHEDRALSURFACE Z"; }
53+
};
54+
5055
struct prefix_multipoint
5156
{
5257
static inline const char* apply() { return "MULTIPOINT"; }

include/boost/geometry/io/wkt/read.hpp

+35
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,32 @@ struct polygon_parser
453453
}
454454
};
455455

456+
template<typename PolyhedralSurface>
457+
struct polyhderal_surface_parser
458+
{
459+
typedef typename ring_return_type<PolyhedralSurface>::type ring_return_type;
460+
typedef container_appender<ring_return_type> appender;
461+
462+
static inline void apply(tokenizer::iterator& it,
463+
tokenizer::iterator const& end,
464+
std::string const& wkt,
465+
PolyhedralSurface& Poly)
466+
{
467+
handle_open_parenthesis(it, end, wkt);
468+
typename ring_type<PolyhedralSurface>::type ring;
469+
while(it != end && *it != ")"){
470+
appender::apply(it, end, wkt, ring);
471+
if(it!=end && *it == ",")
472+
{
473+
//skip after ring is parsed
474+
++it;
475+
}
476+
477+
}
478+
handle_close_parenthesis(it, end, wkt);
479+
}
480+
};
481+
456482

457483
inline bool one_of(tokenizer::iterator const& it,
458484
std::string const& value,
@@ -844,6 +870,15 @@ struct read_wkt<polygon_tag, Geometry>
844870
>
845871
{};
846872

873+
template <typename Geometry>
874+
struct read_wkt<polyhedral_surface_tag, Geometry>
875+
: detail::wkt::geometry_parser
876+
<
877+
Geometry,
878+
detail::wkt::polyhderal_surface_parser,
879+
detail::wkt::prefix_polyhedral_surface
880+
>
881+
{};
847882

848883
template <typename MultiGeometry>
849884
struct read_wkt<multi_point_tag, MultiGeometry>

0 commit comments

Comments
 (0)