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

Defined a geometry for polyhedron #789

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
8 changes: 6 additions & 2 deletions example/01_point_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,22 @@ int main()
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}},
{{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}} };

std::cout<<wkt(polyhedron2)<<std::endl;
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved

//append(polyhedron1[0], point_t{1, 0, 0});
//append(polyhedron1[0], point_t{0, 0, 0});
//append(polyhedron1[0], point_t{0, 1, 0});
//append(polyhedron1[0], point_t{1, 1, 0});
//append(polyhedron1[0], point_t{0, 0, 0});
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
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);
read_wkt("POLYHEDRALSURFACE(((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);

std::cout<<wkt(polyhedron1)<<std::endl;

Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
typedef model::polygon<point_2d> poly;
poly polygon1;
read_wkt("POLYGON((0 0, 0 7, 4 2, 2 0, 0 0))", polygon1);

std::cout<<wkt(polygon1)<<std::endl;
typedef model::linestring<point_2d> lines;
lines line;
read_wkt("LINESTRING(0 0, 2 2, 3 1)", line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ class PolyhedralSurface

};

//polyhedral surface(constant version)
template <typename Geometry>
class ConstPolyhedral
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
{
#ifndef DOXYGEN_NO_CONCEPT_MEMBERS

typedef typename std::remove_const<Geometry>::type const_polyhedral_type;
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved

Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
typedef typename ring_type<const_polyhedral_type>::type ring_type;

BOOST_CONCEPT_ASSERT( (concepts::ConstRing<ring_type>) );

public:

Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
BOOST_CONCEPT_USAGE(ConstPolyhedral)
{

Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
}

#endif
};

Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
} // namepspace concepts

} // namespace geometry
Expand Down
5 changes: 5 additions & 0 deletions include/boost/geometry/geometries/concepts/check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ struct check<Geometry, polyhedral_surface_tag, false>
: detail::concept_check::check<concepts::PolyhedralSurface<Geometry> >
{};

template <typename Geometry>
struct check<Geometry, polyhedral_surface_tag, true>
: detail::concept_check::check<concepts::ConstPolyhedral<Geometry> >
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
{};

template <typename Geometry>
struct check<Geometry, box_tag, true>
: detail::concept_check::check<concepts::ConstBox<Geometry> >
Expand Down
2 changes: 1 addition & 1 deletion include/boost/geometry/io/wkt/detail/prefix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct prefix_linestring

struct prefix_polyhedral_surface
{
static inline const char* apply() { return "POLYHEDRALSURFACE Z"; }
static inline const char* apply() { return "POLYHEDRALSURFACE"; }
};

struct prefix_multipoint
Expand Down
16 changes: 14 additions & 2 deletions include/boost/geometry/io/wkt/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,23 @@ struct polyhderal_surface_parser
PolyhedralSurface& Poly)
{
handle_open_parenthesis(it, end, wkt);
typename ring_type<PolyhedralSurface>::type ring;
while(it != end && *it != ")"){
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
handle_open_parenthesis(it, end, wkt);

typename ring_type<PolyhedralSurface>::type ring;

appender::apply(it, end, wkt, ring);
traits::push_back
<
typename std::remove_reference
<
PolyhedralSurface
>::type
>::apply(Poly, ring);
handle_close_parenthesis(it, end, wkt);
if(it!=end && *it == ",")
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
{
//skip after ring is parsed
//skip "," after ring is parsed
++it;
}

Expand Down Expand Up @@ -549,6 +560,7 @@ inline bool initialize(tokenizer const& tokens,
it = tokens.begin();
end = tokens.end();

//std::cout<<*it<<" "<<geometry_name<<std::endl;
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
if (it == end || ! boost::iequals(*it++, geometry_name))
{
BOOST_THROW_EXCEPTION(read_wkt_exception(std::string("Should start with '") + geometry_name + "'", wkt));
Expand Down
38 changes: 38 additions & 0 deletions include/boost/geometry/io/wkt/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,35 @@ struct wkt_poly

};

template <typename Polyhedral_surface, typename PrefixPolicy>
struct wkt_polyhedral
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Polyhedral_surface const& polyhedral, bool force_closure)
{
typedef typename std::remove_const<Polyhedral_surface>::type const_polyhedral_type;
typedef typename ring_type<const_polyhedral_type>::type ring;
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved

os << PrefixPolicy::apply();

os << "(";
for( typename boost::range_iterator<Polyhedral_surface const>::type
Siddharth-coder13 marked this conversation as resolved.
Show resolved Hide resolved
it = boost::begin(polyhedral); it != boost::end(polyhedral); ++it)
{
if(it != boost::begin(polyhedral))
{
os << ",";
}
os << "(";

wkt_sequence<ring>::apply(os, *it, force_closure);
os << ")";
}
os << ")";
}
};

template <typename Multi, typename StreamPolicy, typename PrefixPolicy>
struct wkt_multi
{
Expand Down Expand Up @@ -409,6 +438,15 @@ struct wkt<Polygon, polygon_tag>
>
{};

template <typename Polyhedral_surface>
struct wkt<Polyhedral_surface, polyhedral_surface_tag>
: detail::wkt::wkt_polyhedral
<
Polyhedral_surface,
detail::wkt::prefix_polyhedral_surface
>
{};

template <typename Multi>
struct wkt<Multi, multi_point_tag>
: detail::wkt::wkt_multi
Expand Down