Skip to content

Commit b347d87

Browse files
Added polyhedral concept check
1 parent df052e2 commit b347d87

File tree

9 files changed

+200
-39
lines changed

9 files changed

+200
-39
lines changed

example/01_point_example.cpp

Lines changed: 23 additions & 0 deletions
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/core/point_type.hpp

Lines changed: 10 additions & 0 deletions
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

Lines changed: 21 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct box_tag : single_tag, areal_tag {};
106106
struct segment_tag : single_tag, linear_tag {};
107107

108108
/// OGC Polyhedral surface identifying tag
109-
struct PolyhedralSurface_tag : single_tag, volumetric_tag {};
109+
struct polyhedral_surface_tag : single_tag, volumetric_tag {};
110110

111111

112112
/// OGC Multi point identifying tag

include/boost/geometry/geometries/PolyhedralSurface.hpp

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,31 @@ namespace model
2525

2626
template
2727
<
28-
typename Point,
29-
bool ClockWise = true, bool Closed = true,
30-
template<typename, typename> class PointList = std::vector,
31-
template<typename, typename> class RingList = std::vector,
32-
template<typename> class PointAlloc = std::allocator,
33-
template<typename> class RingAlloc = std::allocator
28+
typename Ring,
29+
template<typename, typename> class Container = std::vector,
30+
template<typename> class Allocator = std::allocator
31+
3432
>
35-
class PolyhedralSurface : public PointList<ring<Point>, RingAlloc<ring<Point> > >
33+
class PolyhedralSurface : public Container<Ring, Allocator<Ring> >
3634
{
37-
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
35+
BOOST_CONCEPT_ASSERT( (concepts::Ring<Ring>) );
3836

3937
public :
4038

41-
//typedef Point point_type;
42-
using point_type = Point;
43-
using ring_type = ring<Point, ClockWise, Closed, PointList, PointAlloc>;
44-
using PolyhedralSurface_type = RingList<ring_type, RingAlloc<ring_type > >;
45-
//typedef RingList<Point, RingAlloc<Point> > base_type;
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> >;
4642

4743
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
4844

4945
/// \constructor_default{polyhedron}
5046
inline PolyhedralSurface()
51-
: PolyhedralSurface_type()
47+
: ph()
5248
{}
5349

5450
/// \constructor_initialized_list{polyhedron}
5551
inline PolyhedralSurface(std::initializer_list<ring_type> l)
56-
: PolyhedralSurface_type(l.begin(), l.end())
52+
: ph(l.begin(), l.end())
5753
{}
5854

5955
#endif
@@ -68,36 +64,71 @@ namespace traits
6864

6965
template
7066
<
71-
typename Point,
72-
bool ClockWise, bool Closed,
73-
template<typename, typename> class PointList,
74-
template<typename, typename> class RingList,
75-
template<typename> class PointAlloc,
76-
template<typename> class RingAlloc
67+
typename Ring,
68+
template<typename, typename> class Container,
69+
template<typename> class Allocator
7770
>
7871
struct tag
7972
<
8073
model::PolyhedralSurface
8174
<
82-
Point,
83-
ClockWise, Closed,
84-
PointList, RingList,
85-
PointAlloc, RingAlloc
75+
Ring,
76+
Container, Allocator
8677
>
8778
>
8879
{
89-
typedef PolyhedralSurface_tag type;
80+
typedef polyhedral_surface_tag type;
9081
};
91-
/*using tag < model::PolyhedralSurface <
92-
Point,
93-
ClockWise, Closed,
94-
PointList, RingList,
95-
PointAlloc, RingAlloc > > = PolyhedralSurface_tag;*/
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+
/*template
106+
<
107+
typename Ring,
108+
template<typename, typename> class Container,
109+
template<typename> class Allocator
110+
>
111+
struct ring_type
112+
<
113+
model::PolyhedralSurface
114+
<
115+
Ring,
116+
Container, Allocator
117+
>
118+
>
119+
{
120+
typedef typename model::PolyhedralSurface
121+
<
122+
Ring,
123+
Container, Allocator
124+
>::ring_type& type;
125+
126+
};*/
96127

97128

98129
} // namespace traits
99130
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
100131

101132
}} // namespace boost::geometry
102133

103-
#endif
134+
#endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
Geometry* polyhedralSurface = 0;
31+
ring_type* ring = 0;
32+
33+
}
34+
#endif
35+
36+
};
37+
38+
} // namepspace concepts
39+
40+
} // namespace geometry
41+
42+
} // namespace boost
43+
#endif

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

Lines changed: 5 additions & 1 deletion
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/io/wkt/detail/prefix.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ struct prefix_linestring
4747
static inline const char* apply() { return "LINESTRING"; }
4848
};
4949

50-
struct prefix_polyhedron
50+
struct prefix_polyhedral_surface
5151
{
52-
static inline const char* apply() { return "POLYHEDRON"; }
52+
static inline const char* apply() { return "POLYHEDRALSURFACE Z"; }
5353
};
5454

5555
struct prefix_multipoint

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,27 @@ 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& ring)
466+
{
467+
handle_open_parenthesis(it, end, wkt);
468+
int i = 0;
469+
while(it != end && *it != ")"){
470+
//appender::apply(it, end, wkt, ring);
471+
i++;
472+
}
473+
handle_close_parenthesis(it, end, wkt);
474+
}
475+
};
476+
456477

457478
inline bool one_of(tokenizer::iterator const& it,
458479
std::string const& value,
@@ -563,7 +584,7 @@ struct geometry_parser
563584
{
564585
static inline void apply(std::string const& wkt, Geometry& geometry)
565586
{
566-
geometry::clear(geometry);
587+
//geometry::clear(geometry);
567588

568589
tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
569590
tokenizer::iterator it, end;
@@ -844,6 +865,15 @@ struct read_wkt<polygon_tag, Geometry>
844865
>
845866
{};
846867

868+
template <typename Geometry>
869+
struct read_wkt<polyhedral_surface_tag, Geometry>
870+
: detail::wkt::geometry_parser
871+
<
872+
Geometry,
873+
detail::wkt::polyhderal_surface_parser,
874+
detail::wkt::prefix_polyhedral_surface
875+
>
876+
{};
847877

848878
template <typename MultiGeometry>
849879
struct read_wkt<multi_point_tag, MultiGeometry>
@@ -903,7 +933,7 @@ struct read_wkt<segment_tag, Segment>
903933
template <typename Geometry>
904934
inline void read_wkt(std::string const& wkt, Geometry& geometry)
905935
{
906-
geometry::concepts::check<Geometry>();
936+
//geometry::concepts::check<Geometry>();
907937
dispatch::read_wkt<typename tag<Geometry>::type, Geometry>::apply(wkt, geometry);
908938
}
909939

0 commit comments

Comments
 (0)