Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Create a correct arrangement with lines processed with linear_least_squares_fitting_2 function

Subject: CGAL users discussion list

List archive

[cgal-discuss] Create a correct arrangement with lines processed with linear_least_squares_fitting_2 function


Chronological Thread 
  • From: DamienDous <>
  • To:
  • Subject: [cgal-discuss] Create a correct arrangement with lines processed with linear_least_squares_fitting_2 function
  • Date: Tue, 1 Dec 2015 09:58:08 -0800 (PST)
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=SoftFail ; spf=None
  • Ironport-phdr: 9a23:P7xb1BZ/eCpM7v3Qx7Vbu6D/LSx+4OfEezUN459isYplN5qZpcm5bnLW6fgltlLVR4KTs6sC0LqI9fi4Ejxaqb+681k8M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJPK/jvHcaK1oLsh770o8WYM18ArQH+SI0xBS3+lR/WuMgSjNkqAYcK4TyNnEF1ff9Lz3hjP1OZkkW0zM6x+Jl+73YY4Kp5pIZ2eP6kLuFhFfQYV2x+cjN92Mq+vhbKSU6D52AXT34NuhtOGQnMqh/gDbnrtS6vmuN42SScEcrrVvhgVT2n7qptDhPAkyEOLz049ifZkJoj3+pgvBu9qkkmkMbva4aPOa8lJvvQ

Hi,

I need to create an arrangement with lines fitted by
linear_least_squares_fitting_2 function.

I have a problem when I fit lines on points by using
linear_least_squares_fitting_2 function and after put the obtained lines in
an arrangement using an Exact_predicates_exact_constructions_kernel. The
face number processed is incorrect.

The following example fit three lines intersecting at the same point using
Line_2 with Exact_predicates_inexact_constructions_kernel (the
linear_least_squares_fitting_2 can't take line with
Exact_predicates_exact_constructions_kernel because the function processes
square root). To put the obtained lines in an arrangement using
Exact_predicates_exact_constructions_kernel , I convert the lines in
Segment_2 with Exact_predicates_exact_constructions_kernel and I understand
that the problem come from this transformation but I don't know how to use
linear_least_squares_fitting_2 function and then put the result in an
arrangement using Exact_predicates_exact_constructions_kernel.

Also, I tried to use an arrangement with
Exact_predicates_inexact_constructions_kernel but that doesn't work given
that the precision problem.


Here is my code :

#include <CGAL/Arrangement_2.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_linear_traits_2.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Arr_extended_dcel.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel
Kernel1;
typedef CGAL::Exact_predicates_exact_constructions_kernel
Kernel2;
typedef CGAL::Arr_linear_traits_2<Kernel2>
Traits;
typedef CGAL::Arr_face_extended_dcel<Traits, bool>
Dcel_2;
typedef CGAL::Arrangement_2<Traits, Dcel_2>
Arrangement;


int main()
{
// Initialize segments distance and segments number of points
double distance = 1;
size_t nbPoints = 100;

// Fill the three points vectors representing the three lines
std::vector<std::vector&lt;CGAL::Point_2&lt;Kernel1>>> lines_points;
lines_points.resize(3);
double x = 0;
for (size_t i = 0; i < nbPoints; i++, x += distance / nbPoints) {
lines_points.at(0).push_back(CGAL::Point_2<Kernel1>(distance
- x, x));
lines_points.at(1).push_back(CGAL::Point_2<Kernel1>(x, x));
lines_points.at(2).push_back(CGAL::Point_2<Kernel1>(x,
distance / 2));
}

// Fit for each points vector a line using
linear_least_squares_fitting_2
// and transform this line in segment with
Exact_predicates_exact_constructions_kernel
CGAL::Line_2<Kernel1> line;
std::vector<CGAL::Segment_2&lt;Kernel2>>
segments(lines_points.size());
for (size_t i = 0; i < lines_points.size(); i++) {

CGAL::linear_least_squares_fitting_2(lines_points.at(i).begin(),
lines_points.at(i).end(), line, CGAL::Dimension_tag<0>());
segments.at(i) =
CGAL::Segment_2<Kernel2>(CGAL::Point_2<Kernel2>(0,
-line.c() / line.b()),
CGAL::Point_2<Kernel2>(distance, -(distance *
line.a() + line.c()) /
line.b()));
}

// Put the processed segment in an arrangement
Arrangement arr;
CGAL::insert(arr, segments.begin(), segments.end());

// Print the number of bounded face
std::cout << arr.number_of_faces() - arr.number_of_unbounded_faces()
<<
std::endl;

// Print the bounded face of the arrangement
Arrangement::Ccb_halfedge_const_circulator curr;
for (Arrangement::Face_const_handle fit = arr.faces_begin(); fit !=
arr.faces_end(); ++fit) {
if (!fit->is_unbounded()) {
curr = fit->outer_ccb();
do {
std::cout << curr->source()->point() << " - ";
} while (++curr != fit->outer_ccb());
}
}
}



Is there a Kernel that provide against this problem?

Thank you very much.
Regards.




--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Create-a-correct-arrangement-with-lines-processed-with-linear-least-squares-fitting-2-function-tp4661426.html
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.18.

Top of Page