Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Offset Plane

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Offset Plane


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Offset Plane
  • Date: Mon, 30 May 2011 08:21:51 +0200

If you provide a complete minimal working example showing the
problem I can have a look at it.

S.


Max Harris wrote:
OK, your suggestion worked for that case, but I want to write a function that finds the correct Halfedge_handle for a given cutting plane. What follows is my attempt, which doesn't work. What's wrong with it?

Halfedge_handle FindUsableHandle(Polyhedron P, Plane pl)
{
Halfedge_iterator hi;

for (hi = P.halfedges_begin(); hi != P.halfedges_end(); hi++) {
CGAL::Oriented_side test = pl.oriented_side(hi->vertex()->point());
if (test == CGAL::ON_POSITIVE_SIDE)
{ cout << "point on positive side" << endl; }
else if (test == CGAL::ON_NEGATIVE_SIDE)
{ cout << "point on negative side" << endl;
return hi;
}
else
{ cout << "point over line" << endl; }
}


return hi;
}

Polyhedron result;
Halfedge_handle he = make_cube_3(result);


CGAL::polyhedron_cut_plane_3(result, he->opposite()->next(), pl3); // works
CGAL::polyhedron_cut_plane_3(result, FindUsableHandle(P, pl3), pl3); // does not work. see output below
output: **
*Facet number: 0*
*Plane: -0 -1 -0 -0*
**
*Normal: -0 -1 -0*
**
*Scaled normal: -0 0.1 -0*
**
*Transformed plane: -0 -1 -0 0.1*
*point on positive side*
*point on positive side*
*point on positive side*
*point on positive side*
*point on positive side*
*point on positive side*
*point on negative side*
*terminate called after throwing an instance of 'CGAL::Postcondition_exception'*
* what(): CGAL ERROR: postcondition violation!*
*Expr: D.is_valid(false,3)*
*File: /usr/local/include/CGAL/halfedgeDS_cut_component.h*
*Line: 126*
*(gdb) *


On May 27, 2011, at 2:29 AM, Sebastien Loriot (GeometryFactory) wrote:

Try with

CGAL::polyhedron_cut_plane_3(result, he->opposite(), pl3);
instead of
CGAL::polyhedron_cut_plane_3(result, he, pl3);

he->vertex() need to be on the negative side of the plane.

S.

Max Harris wrote:
polyhedron_cut_plane_3() breaks when I try running the code below. What am I doing wrong?
Here's the output:
*Plane: -0 -1 -0 -0*
**
*Normal: -0 -1 -0*
**
*Scaled normal: -0 0.1 -0*
**
*Transformed plane: -0 -1 -0 0.1*
*terminate called after throwing an instance of 'CGAL::Precondition_exception'*
* what(): CGAL ERROR: precondition violation!*
*Expr: pred( h->vertex())*
*File: /usr/local/include/CGAL/polyhedron_cut_plane_3.h*
*Line: 120*
Root::Root()
{
Polyhedron P;
make_cube_3(P);
Facet_iterator f = P.facets_begin(); Plane pl2 = f->plane(); // plane equation of the facet
cout << "Plane: " << pl2 << endl;
CGAL::Vector_3<Kernel> normal = pl2.orthogonal_vector();
cout << "\nNormal: " << normal << endl;
Vector sn = normal.transform(Transformation(CGAL::SCALING, -0.1));
cout << "\nScaled normal: " << sn << endl;
Plane pl3 = pl2.transform(Transformation(CGAL::TRANSLATION, sn));
cout << "\nTransformed plane: " << pl3 << endl;
Polyhedron result;
Halfedge_handle he = make_cube_3(result);
CGAL::polyhedron_cut_plane_3(result, he, pl3);
}
template <class Poly>
typename Poly::Halfedge_handle Root::make_cube_3(Poly& P)
{
// appends a cube of size [0,1]^3 to the polyhedron P.
CGAL_precondition( P.is_valid());
typedef typename Poly::Point_3 Point;
typedef typename Poly::Plane_3 Plane;
typedef typename Poly::Halfedge_handle Halfedge_handle;
Halfedge_handle h = P.make_tetrahedron(Point( 1, 0, 0),
Point( 0, 0, 1),
Point( 0, 0, 0),
Point( 0, 1, 0));
Halfedge_handle g = h->next()->opposite()->next();
P.split_edge( h->next());
P.split_edge( g->next());
P.split_edge( g);
h->next()->vertex()->point() = Point( 1, 0, 1);
g->next()->vertex()->point() = Point( 0, 1, 1);
g->opposite()->vertex()->point() = Point( 1, 1, 0);
Halfedge_handle f = P.split_facet( g->next(), g->next()->next()->next());
Halfedge_handle e = P.split_edge( f);
e->vertex()->point() = Point( 1, 1, 1);
P.split_facet( e, f->next()->next());
CGAL_postcondition( P.is_valid());
g = h;
g->facet()->plane() = Plane( g->vertex()->point(),
g->next()->vertex()->point(),
g->next()->next()->vertex()->point());
g = h->opposite();
g->facet()->plane() = Plane( g->vertex()->point(),
g->next()->vertex()->point(),
g->next()->next()->vertex()->point());
g = h->next()->opposite();
g->facet()->plane() = Plane( g->vertex()->point(),
g->next()->vertex()->point(),
g->next()->next()->vertex()->point());
g = h->next()->next()->opposite();
g->facet()->plane() = Plane( g->vertex()->point(),
g->next()->vertex()->point(),
g->next()->next()->vertex()->point());
g = h->next()->next()->next()->opposite();
g->facet()->plane() = Plane( g->vertex()->point(),
g->next()->vertex()->point(),
g->next()->next()->vertex()->point());
g = g->next()->next()->opposite();
g->facet()->plane() = Plane( g->vertex()->point(),
g->next()->vertex()->point(),
g->next()->next()->vertex()->point());
return h;
}
On May 25, 2011, at 12:47 AM, Marc Glisse wrote:
On Wed, 25 May 2011, harris.max wrote:

I'm trying to get CGAL to generate a plane that's offset by some specifiable
distance from an existing plane, but everything I've tried so far isn't
working. What's the best way to do this?

What did you try that isn't working?

There doesn't seem to be any function to do that directly, but you could for instance use Construct_orthogonal_vector_3 to get a normal vector, scale it to whatever distance you want, then translate the plane?

--
Marc Glisse

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss



--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss






Archive powered by MHonArc 2.6.16.

Top of Page