This commit is contained in:
Efi Fogel 2020-09-08 19:50:30 +03:00
parent 7cd3a2663b
commit f332cf00f7
4 changed files with 124 additions and 41 deletions

View File

@ -5111,8 +5111,8 @@ instantiate the curve-data traits:
At this point we do not expose the topology traits concept. The
package contains one topology traits, namely,
`Arr_spherical_topology_traits_2`. It can be served as a topology
traits for an arrangement embeded on a sphere. More precisely, for an
`Arr_spherical_topology_traits_2`. It can serve as a topology traits
for an arrangement embeded on a sphere. More precisely, for an
arrangement embeded on a sphere defined over a parameter space the
left and right boundary sides of which are identified and the top and
bottom boundary sides are contracted.

View File

@ -0,0 +1,104 @@
namespace CGAL {
/*! \ingroup PkgArrangementOnSurface2Ref
*
* \anchor arr_ref_spherical_topology_traits
*
* This class handles the topology for arrangements of great spherical
* arcs on the sphere embedded on 2D parametric surdace.
*
* The `Arr_spherical_topology_traits_2` template has two parameters:
* <UL>
* <LI>The `GeometryTraits_2` template-parameter should be instantiated with
* a model of the `ArrangementBasicTraits_2` concept. The traits
* class defines the types of \f$x\f$-monotone curves and two-dimensional
* points, namely `ArrangementBasicTraits_2::X_monotone_curve_2` and
* `ArrangementBasicTraits_2::Point_2`,
* respectively, and supports basic geometric predicates on them.
* <LI>The `Dcel` template-parameter should be instantiated with
* a class that is a model of the `ArrangementDcel` concept. The
* value of this parameter is by default
* `Arr_default_dcel<Traits>`.
* </UL>
*
* \sa `Arr_default_dcel<Traits>`
* \sa `CGAL::Arr_geodesic_arc_on_sphere_traits_2<Kernel,x,y>`
*/
template <typename GeometryTraits_2,
typename Dcel = Arr_default_dcel<GeometryTraits_2> >
class Arr_spherical_topology_traits_2 {
public:
/// \name Types
/// @{
typedef typename GeometryTraits_2::Point_2 Point_2;
typedef typename GeometryTraits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef typename Dcel::Size Size;
typedef typename Dcel::Vertex Vertex;
typedef typename Dcel::Halfedge Halfedge;
typedef typename Dcel::Face Face;
typedef typename Dcel::Outer_ccb Outer_ccb;
typedef typename Dcel::Inner_ccb Inner_ccb;
typedef typename Dcel::Isolated_vertex Isolated_vertex;
/// @}
/// \name Creation
/// @{
/*! Default constructor. */
Arr_spherical_topology_traits_2();
/*! Constructor from a geometry-traits object.
* \param traits the traits.
*/
Arr_spherical_topology_traits_2(const GeometryTraits_2* traits);
/// @}
/// \name Accessors
/// @{
/*! Obtain the DCEL (const version). */
const Dcel& dcel() const;
/*! Obtain the DCEL (non-const version). */
Dcel& dcel();
/*! Obtain the spherical face (const version). */
const Face* spherical_face() const;
/*! Obtain the spherical face (non-const version). */
Face* spherical_face();
/*! Obtain the south pole (const version). */
const Vertex* south_pole() const;
/*! Obtain the south pole (non-const version). */
Vertex* south_pole();
/*! Obtain the north pole (const version). */
const Vertex* north_pole() const;
/*! Obtain the north pole (non-const version). */
Vertex* north_pole();
/*! Obtain a vertex on the line of discontinuity that corresponds to
* the given point (or return NULL if no such vertex exists).
*/
const Vertex* discontinuity_vertex(const Point_2& pt) const;
/*! Obtain a vertex on the line of discontinuity that corresponds to
* the given point (or return NULL if no such vertex exists).
*/
Vertex* discontinuity_vertex(const Point_2& pt);
/// @}
/// \name Modifiers
/// @{
/// @}
};
}

View File

@ -225,6 +225,7 @@ implemented as peripheral classes or as free (global) functions.
- `CGAL::Arr_vertex_index_map<Arrangement>`
- `CGAL::Arr_face_index_map<Arrangement>`
- `CGAL::Arr_point_location_result<Arrangement>`
- `CGAL::Arr_spherical_topology_traits_2<GeometryTraits_2,Dcel>`
\cgalCRPSection{Macros}
- \link CGAL_ARR_POINT_LOCATION_VERSION `CGAL_ARR_POINT_LOCATION_VERSION` \endlink

View File

@ -2,12 +2,16 @@
// Checking whether there are three collinear points in a given input set
// using the arrangement of the dual lines.
#include <algorithm>
#include <CGAL/Cartesian.h>
#include <CGAL/Exact_rational.h>
#include <CGAL/Arr_linear_traits_2.h>
#include <CGAL/Arr_curve_data_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include "read_objects.h"
typedef CGAL::Cartesian<CGAL::Exact_rational> Kernel;
typedef CGAL::Arr_linear_traits_2<Kernel> Linear_traits_2;
typedef Linear_traits_2::Point_2 Point_2;
@ -21,56 +25,30 @@ int main(int argc, char *argv[])
{
// Get the name of the input file from the command line, or use the default
// points.dat file if no command-line parameters are given.
const char * filename = (argc > 1) ? argv[1] : "coll_points.dat";
const char* filename = (argc > 1) ? argv[1] : "coll_points.dat";
// Open the input file.
std::ifstream in_file(filename);
std::vector<Point_2> points;
if (! in_file.is_open()) {
std::cerr << "Failed to open " << filename << " ..." << std::endl;
return (1);
}
// Read the points from the file, and construct their dual lines.
std::vector<Point_2> points;
std::list<X_monotone_curve_2> dual_lines;
unsigned int n;
in_file >> n;
points.resize(n);
unsigned int k;
for (k = 0; k < n; ++k) {
int px, py;
in_file >> px >> py;
points[k] = Point_2(px, py);
// The line dual to the point (p_x, p_y) is y = p_x*x - p_y,
// or: p_x*x - y - p_y = 0:
Line_2 dual_line = Line_2(CGAL::Exact_rational(px),
CGAL::Exact_rational(-1),
CGAL::Exact_rational(-py));
// Generate the x-monotone curve based on the line and the point index.
dual_lines.push_back(X_monotone_curve_2(dual_line, k));
}
in_file.close();
read_objects<Point_2>(filename, std::back_inserter(points));
std::vector<X_monotone_curve_2> dual_lines(points.size());
size_t k{0};
std::transform(points.begin(), points.end(), dual_lines.begin(),
[&](const Point_2& p) {
Line_2 dual_line(p.x(), CGAL::Exact_rational(-1), -(p.y()));
return X_monotone_curve_2(dual_line, k++);
});
// Construct the dual arrangement by aggregately inserting the lines.
Arrangement_2 arr;
insert(arr, dual_lines.begin(), dual_lines.end());
// Look for vertices whose degree is greater than 4.
Arrangement_2::Vertex_const_iterator vit;
Arrangement_2::Halfedge_around_vertex_const_circulator circ;
size_t d;
for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) {
for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) {
if (vit->degree() > 4) {
// There should be vit->degree()/2 lines intersecting at the current
// vertex. We print their primal points and their indices.
circ = vit->incident_halfedges();
for (d = 0; d < vit->degree() / 2; d++) {
auto circ = vit->incident_halfedges();
for (auto d = 0; d < vit->degree() / 2; ++d) {
k = circ->curve().data(); // The index of the primal point.
std::cout << "Point no. " << k+1 << ": (" << points[k] << "), ";
++circ;