Skip to content

Commit

Permalink
Compatibility with 6.0 and 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sloriot authored and lbartoletti committed Jul 26, 2024
1 parent a976da3 commit 08a8704
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 29 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ message( STATUS "CGAL ${CGAL_VERSION} found" )
include_directories( ${CMAKE_BINARY_DIR}/include )

#-- BOOST --------------------------------------------------
if( NOT CGAL_USE_GMPXX )
add_definitions( "-DCGAL_DO_NOT_USE_BOOST_MP" )
endif()

option( Boost_USE_AUTO_LINK "boost use autolink" OFF )
if( NOT ${Boost_USE_AUTO_LINK} )
add_definitions( "-DBOOST_ALL_NO_LIB" )
Expand Down
8 changes: 8 additions & 0 deletions src/algorithm/offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ circleToPolygon(const Kernel::Circle_2 &circle) -> Offset_polygon_2
Gps_traits_2 const traits;
Offset_curve_2 const curve(circle);

#if CGAL_VERSION_MAJOR < 6
std::list<CGAL::Object> parts;
traits.make_x_monotone_2_object()(curve, std::back_inserter(parts));
BOOST_ASSERT(parts.size() == 2U);
Expand All @@ -181,6 +182,13 @@ circleToPolygon(const Kernel::Circle_2 &circle) -> Offset_polygon_2
CGAL::assign(arc, part);
result.push_back(arc);
}
#else
Offset_polygon_2 result;

traits.make_x_monotone_2_object()(
curve, CGAL::dispatch_or_drop_output<Offset_x_monotone_curve_2>(
std::back_inserter(result)));
#endif

return result;
}
Expand Down
31 changes: 18 additions & 13 deletions src/algorithm/straightSkeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<Kernel>;
using Straight_skeleton_2 = CGAL::Straight_skeleton_2<Kernel>;
using Mesh = CGAL::Surface_mesh<Point_3>;

#if CGAL_VERSION_MAJOR < 6
template <class T>
using SHARED_PTR = boost::shared_ptr<T>;
#else
template <class T>
using SHARED_PTR = std::shared_ptr<T>;
#endif

namespace { // anonymous

template <class K, bool outputDistanceInM>
Expand Down Expand Up @@ -181,14 +189,14 @@ straightSkeletonToMedialAxis(const CGAL::Straight_skeleton_2<K> &ss,

auto
straightSkeleton(const Polygon_with_holes_2 &poly)
-> boost::shared_ptr<Straight_skeleton_2>
-> SHARED_PTR<Straight_skeleton_2>
{
boost::shared_ptr<CGAL::Straight_skeleton_2<CGAL::Epick>> const sk =
SHARED_PTR<CGAL::Straight_skeleton_2<CGAL::Epick>> const sk =
CGAL::create_interior_straight_skeleton_2(
poly.outer_boundary().vertices_begin(),
poly.outer_boundary().vertices_end(), poly.holes_begin(),
poly.holes_end(), CGAL::Epick());
boost::shared_ptr<Straight_skeleton_2> ret;
SHARED_PTR<Straight_skeleton_2> ret;
if (sk) {
ret = CGAL::convert_straight_skeleton_2<Straight_skeleton_2>(*sk);
}
Expand Down Expand Up @@ -316,10 +324,9 @@ straightSkeleton(const Polygon &g, bool /*autoOrientation*/, bool innerOnly,
return result;
}

Kernel::Vector_2 trans;
Polygon_with_holes_2 const polygon = preparePolygon(g, trans);
boost::shared_ptr<Straight_skeleton_2> const skeleton =
straightSkeleton(polygon);
Kernel::Vector_2 trans;
Polygon_with_holes_2 const polygon = preparePolygon(g, trans);
SHARED_PTR<Straight_skeleton_2> const skeleton = straightSkeleton(polygon);

if (skeleton == nullptr) {
BOOST_THROW_EXCEPTION(Exception("CGAL failed to create straightSkeleton"));
Expand Down Expand Up @@ -348,8 +355,7 @@ straightSkeleton(const MultiPolygon &g, bool /*autoOrientation*/,
for (size_t i = 0; i < g.numGeometries(); i++) {
Kernel::Vector_2 trans;
Polygon_with_holes_2 const polygon = preparePolygon(g.polygonN(i), trans);
boost::shared_ptr<Straight_skeleton_2> const skeleton =
straightSkeleton(polygon);
SHARED_PTR<Straight_skeleton_2> const skeleton = straightSkeleton(polygon);

if (skeleton == nullptr) {
BOOST_THROW_EXCEPTION(
Expand Down Expand Up @@ -379,10 +385,9 @@ approximateMedialAxis(const Geometry &g) -> std::unique_ptr<MultiLineString>
extractPolygons(g, polys);

for (auto &poly : polys) {
Kernel::Vector_2 trans;
Polygon_with_holes_2 const polygon = preparePolygon(poly, trans);
boost::shared_ptr<Straight_skeleton_2> const skeleton =
straightSkeleton(polygon);
Kernel::Vector_2 trans;
Polygon_with_holes_2 const polygon = preparePolygon(poly, trans);
SHARED_PTR<Straight_skeleton_2> const skeleton = straightSkeleton(polygon);

if (skeleton == nullptr) {
BOOST_THROW_EXCEPTION(
Expand Down
32 changes: 25 additions & 7 deletions src/algorithm/visibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ visibility(const Geometry &polygon, const Geometry &point,
}

// Find the face
Arrangement_2::Face_const_handle *face;
CGAL::Arr_naive_point_location<Arrangement_2> const pl(arr);
CGAL::Arr_point_location_result<Arrangement_2>::Type obj =
pl.locate(queryPoint);
Expand All @@ -108,9 +107,13 @@ visibility(const Geometry &polygon, const Geometry &point,

// Create Triangular Expansion Visibility object.
TEV const tev(arr);

if (obj.which() == 0) {

#if CGAL_VERSION_MAJOR < 6
switch (obj.which())
#else
switch (obj.index())
#endif
{
case 0: {
Halfedge_const_handle he = Halfedge_const_handle();

// If the point is in a boundary segment, find the corresponding half edge
Expand All @@ -135,23 +138,38 @@ visibility(const Geometry &polygon, const Geometry &point,

// Use the half edge to compute the visibility
fh = tev.compute_visibility(queryPoint, he, output_arr);

} else if (obj.which() == 1) {
break;
}
case 1: {
Halfedge_const_handle *he =
#if CGAL_VERSION_MAJOR < 6
boost::get<Arrangement_2::Halfedge_const_handle>(&obj);
#else
std::get_if<Arrangement_2::Halfedge_const_handle>(&obj);
#endif
if (he != nullptr) {
fh = tev.compute_visibility(queryPoint, *he, output_arr);
} else {
BOOST_THROW_EXCEPTION(Exception("Can not find corresponding hedge."));
}
} else if (obj.which() == 2) {
break;
}
case 2: {
Face_const_handle *face =
#if CGAL_VERSION_MAJOR < 6
boost::get<Arrangement_2::Face_const_handle>(&obj);
#else
std::get_if<Arrangement_2::Face_const_handle>(&obj);
#endif
if ((face != nullptr) && !((*face)->is_unbounded())) {
fh = tev.compute_visibility(queryPoint, *face, output_arr);
} else {
BOOST_THROW_EXCEPTION(Exception("Can not find corresponding face."));
}
break;
}
default:
break;
}

return query_visibility(fh, fh->outer_ccb());
Expand Down
10 changes: 6 additions & 4 deletions src/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
* 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; if not, see <http://www.gnu.org/licenses/>.
* License along with this library; if not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _SFCGAL_CONFIG_H_
#define _SFCGAL_CONFIG_H_

#define CGAL_DO_NOT_USE_BOOST_MP 1
#ifndef CGAL_USE_GMPXX
#define CMAKE_OVERRIDDEN_DEFAULT_ENT_BACKEND 0 // GMP
#endif

#include "SFCGAL/export.h"

Expand All @@ -30,4 +33,3 @@
#cmakedefine SFCGAL_WITH_OSG

#endif

5 changes: 4 additions & 1 deletion src/detail/generator/building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ building(const Polygon &g, const Kernel::FT &wallHeight,

// fix orientation
algorithm::makeValidOrientation(polygon);

#if CGAL_VERSION_MAJOR < 6
boost::shared_ptr<Straight_skeleton_2> const skeleton =
#else
std::shared_ptr<Straight_skeleton_2> const skeleton =
#endif
create_interior_straight_skeleton_2(
polygon.outer_boundary().vertices_begin(),
polygon.outer_boundary().vertices_end(), polygon.holes_begin(),
Expand Down

0 comments on commit 08a8704

Please sign in to comment.