Skip to content

File TypeForDimension.h

File List > detail > TypeForDimension.h

Go to the documentation of this file

// Copyright (c) 2012-2013, IGN France.
// Copyright (c) 2012-2022, Oslandia.
// SPDX-License-Identifier: LGPL-2.0-or-later

#ifndef SFCGAL_DETAIL_TYPE_FOR_DIMENSION_H
#define SFCGAL_DETAIL_TYPE_FOR_DIMENSION_H

#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Segment_2.h>
#include <CGAL/Segment_3.h>
#include <CGAL/Triangle_2.h>
#include <CGAL/Triangle_3.h>

namespace SFCGAL {
namespace detail {

struct SFCGAL_API NoVolume {};

template <int Dim>
struct TypeForDimension {
  typedef CGAL::Bbox_2                       Bbox;
  typedef Kernel::Point_2                    Point;
  typedef Kernel::Segment_2                  Segment;
  typedef Kernel::Triangle_2                 Triangle;
  typedef CGAL::Polygon_with_holes_2<Kernel> Surface;
  typedef NoVolume                           Volume;
};

template <class Refs>
struct Halfedge_with_mark : public CGAL::HalfedgeDS_halfedge_base<Refs> {
  Halfedge_with_mark() : CGAL::HalfedgeDS_halfedge_base<Refs>(), mark(false) {}

  bool mark; // A boundary marker for faces with different status
  void
  set_mark()
  { // this will be called by Intersection_of_Polyhedra_3
    mark = true;
  }
};

// An items type using my halfedge.
struct SFCGAL_API Items_with_mark_on_hedge : public CGAL::Polyhedron_items_3 {
  template <class Refs, class Traits>
  struct Halfedge_wrapper {
    typedef Halfedge_with_mark<Refs> Halfedge;
  };
};

typedef CGAL::Polyhedron_3<Kernel, Items_with_mark_on_hedge> MarkedPolyhedron;

template <>
struct TypeForDimension<3> {
  typedef CGAL::Bbox_3       Bbox;
  typedef Kernel::Point_3    Point;
  typedef Kernel::Segment_3  Segment;
  typedef Kernel::Triangle_3 Triangle;
  typedef Kernel::Triangle_3 Surface;
  typedef MarkedPolyhedron   Volume;
};

template <int Dim>
struct Point_d {
  typedef typename TypeForDimension<Dim>::Point Type;
};
template <int Dim>
struct Segment_d {
  typedef typename TypeForDimension<Dim>::Segment Type;
};
template <int Dim>
struct Surface_d {
  typedef typename TypeForDimension<Dim>::Surface Type;
};
template <int Dim>
struct Volume_d {
  typedef typename TypeForDimension<Dim>::Volume Type;
};

template <int N>
struct dim_t {
  enum { v = N };
};

template <class T>
struct PrimitiveDimension {
  static const int value = 0;
};

template <>
struct PrimitiveDimension<TypeForDimension<2>::Segment> {
  static const int value = 1;
};
template <>
struct PrimitiveDimension<TypeForDimension<3>::Segment> {
  static const int value = 1;
};
template <>
struct PrimitiveDimension<TypeForDimension<2>::Surface> {
  static const int value = 2;
};
template <>
struct PrimitiveDimension<TypeForDimension<3>::Surface> {
  static const int value = 2;
};
template <>
struct PrimitiveDimension<TypeForDimension<2>::Volume> {
  static const int value = 3;
};
template <>
struct PrimitiveDimension<TypeForDimension<3>::Volume> {
  static const int value = 3;
};

template <class X, class Y>
struct IsPrimitiveLarger {
  static const bool value =
      PrimitiveDimension<X>::value > PrimitiveDimension<Y>::value;
};

} // namespace detail
} // namespace SFCGAL

#endif