Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?
Chronological Thread
- From: Efi Fogel <>
- To:
- Subject: Re: [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?
- Date: Wed, 20 Aug 2014 12:37:38 +0300
If it's 2D, try the 2D Regularized Boolean Set-Operations package (User Manual, Reference Manual).
____ _ ____ _
/_____/_) o /__________ __ //
(____ ( ( ( (_/ (_/-(-'_(/
_/
/_____/_) o /__________ __ //
(____ ( ( ( (_/ (_/-(-'_(/
_/
On Wed, Aug 20, 2014 at 11:38 AM, areslp <> wrote:
Hi, I have two polygons constructed from the contours of image segmentation
results, the shapes of these polygons are arbitary. I need to perform some
boolean operation on these polygons, for example: I want to know whether a
polygon is inside another polygon or not; a point is inside a polygon or
not, etc. I write some simple code to do these things using Nef Polygon, the
code is shown bellow:
#include <CGAL/Gmpz.h>
#include <CGAL/Filtered_extended_homogeneous.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Nef_polyhedron_2.h>
typedef CGAL::Gmpz RT;
typedef CGAL::Filtered_extended_homogeneous<RT> Extended_kernel;
typedef CGAL::Nef_polyhedron_2<Extended_kernel> Nef_polyhedron;
typedef Nef_polyhedron::Point Point_2;
typedef Nef_polyhedron::Line Line;
int main() {
Point_2 p1 ( 0, 0 ), p2 ( 10, 0 ), p3 ( 10, 10 ), p4 ( 0, 10 ), p5 ( 1, 1
), p6 ( 9, 1 ), p7 ( 5, 9 ), p8 ( 20, 0 ), p9 ( 20, 10 );
// 4 3
// 1 2
Point_2 P1[4] = { p1, p2, p3, p4 };
Point_2 P2[3] = { p5, p6, p7 };
std::list<std::pair<Point_2 *, Point_2 *> > polylines;
polylines.push_back ( std::make_pair ( P1, P1 + 1 ) );
polylines.push_back ( std::make_pair ( P1 + 1, P1 + 2 ) );
polylines.push_back ( std::make_pair ( P1 + 2, P1 + 3 ) );
// polylines.push_back(std::make_pair(P1+3,P1));
Nef_polyhedron N1 ( polylines.begin(), polylines.end(),
Nef_polyhedron::POLYLINES );
std::cout << N1 << std::endl;
polylines.clear();
polylines.push_back ( std::make_pair ( P2, P2 + 1 ) );
polylines.push_back ( std::make_pair ( P2 + 1, P2 + 2 ) );
// polylines.push_back(std::make_pair(P2+2,P2));
Nef_polyhedron N2 ( polylines.begin(), polylines.end(),
Nef_polyhedron::POLYLINES );
if ( N2 < N1 ) {
std::cout << "N2<N1" << std::endl;
}
if ( N2 > N1 ) {
std::cout << "N2>N1" << std::endl;
}
Point_2 p ( 5, 5 );
Point_2 P3[1] = {p};
Nef_polyhedron Np ( P3, P3 + 1 );
std::cout << ( Np < N1 ) << std::endl;
return 0;
}
The result is not as I expected, I think it should be "N2<N1" and "true",
but the output is "false", what's wrong with the code and what's the best
way for doing things like this? Thanks in advance!
--
View this message in context: http://cgal-discuss.949826.n4.nabble.com/How-to-do-2D-polygon-boolean-operation-with-CGAL-Nef-polygons-tp4659716.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss
- [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?, areslp, 08/20/2014
- Re: [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?, Efi Fogel, 08/20/2014
- Re: [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?, areslp, 08/20/2014
- Re: [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?, Efi Fogel, 08/20/2014
- Re: [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?, areslp, 08/20/2014
- Re: [cgal-discuss] How to do 2D polygon boolean operation with CGAL Nef polygons?, Efi Fogel, 08/20/2014
Archive powered by MHonArc 2.6.18.