Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] compute_intersection_points() prints blank lines

Subject: CGAL users discussion list

List archive

[cgal-discuss] compute_intersection_points() prints blank lines


Chronological Thread 
  • From: phygeeks <>
  • To:
  • Subject: [cgal-discuss] compute_intersection_points() prints blank lines
  • Date: Thu, 2 Jul 2015 16:10:07 -0700 (PDT)

Hi, I installed CGAL 4.6.1 and ran the following code:
====
// Computing intersection points among curves using the sweep line.
#include <CGAL/Cartesian.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>
#include <CGAL/Sweep_line_2_algorithms.h>
#include <vector>
#include <list>

#include "cgal_intersection.h"

typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel> Segment_traits;
typedef CGAL::Arr_polyline_traits_2<Segment_traits> Polyline_traits;
typedef Polyline_traits::Point_2 Point;
typedef Polyline_traits::Curve_2 Polyline;

//extern "C" int find_intersections_of_curves(
int find_intersections_of_curves(
coordinate *curve_1, long curve_1_size,
coordinate *curve_2, long curve_2_size,
coordinate *intersections, int max_num_of_intersections)
{
Polyline_traits polyline_traits;
Polyline_traits::Construct_curve_2 construct_polyline =
polyline_traits.construct_curve_2_object();

int num_of_curves = 2;
coordinate *curves[] = {curve_1, curve_2};
long size_of_curve[] = {curve_1_size, curve_2_size};
std::vector<Polyline> polylines;

std::cout << "Construct polylines.\n";

for(int n = 0; n < num_of_curves; n++){
std::vector<Point> points;
Point p_0 = Point(curves[n][0].x, curves[n][0].y);
points.push_back(p_0);
for(long i = 1; i < size_of_curve[n]; i++){
Point p_i = Point(curves[n][i].x, curves[n][i].y);
if(p_i != points.back()){
points.push_back(p_i);
}
}
polylines.push_back(construct_polyline(points.begin(),
points.end()));
}

std::cout << "Compute intersection points.\n";
std::list<Point> intersection_points;
CGAL::compute_intersection_points(polylines.begin(), polylines.end(),

std::back_inserter(intersection_points),
false, polyline_traits);

int num_of_intersections = intersection_points.size();
Point intersection_point;
std::cout << "Prepare intersection points.\n";
for (int j = 0; j < num_of_intersections; j++){
if (j == max_num_of_intersections)
break;
intersection_point = intersection_points.front();
intersections[j].x = intersection_point.x();
intersections[j].y = intersection_point.y();
intersection_points.pop_front();
}

return num_of_intersections;
}

int main(void){
coordinate c11 = {0.0, 0.0};
coordinate c12 = {1.0, 1.0};
coordinate curve_1[2] = {c11, c12};

coordinate c21 = {0.0, 1.0};
coordinate c22 = {1.0, 0.0};
coordinate curve_2[2] = {c21, c22};

coordinate intersections[1];

std::cout << "Find an intersection using CGAL.\n";

find_intersections_of_curves(curve_1, 2, curve_2, 2, intersections, 1);

std::cout << intersections[0].x << ", " << intersections[0].y << '\n';
}
====
When I run it, I get the following result:
====
Find an intersection using CGAL.
Construct polylines.
Compute intersection points.


Prepare intersection points.
0.5, 0.5
====
As you can see, when compute_intersection_points() is invoked, somehow it
prints out two new lines. This interferes with my logging file so I want to
remove it. Could you tell me what is the problem here?



--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/compute-intersection-points-prints-blank-lines-tp4660967.html
Sent from the cgal-discuss mailing list archive at Nabble.com.


  • [cgal-discuss] compute_intersection_points() prints blank lines, phygeeks, 07/03/2015

Archive powered by MHonArc 2.6.18.

Top of Page