Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] What's the minimal requirement to use the Constructive Solid Geometry (CSG) module of CGAL?

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] What's the minimal requirement to use the Constructive Solid Geometry (CSG) module of CGAL?


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] What's the minimal requirement to use the Constructive Solid Geometry (CSG) module of CGAL?
  • Date: Wed, 25 Jan 2012 08:53:32 +0100

When you provide a face to nef polyhedron, it assumes that the points of the face lies exactly on a plane. In you example, you have quad-faces with non coplanar vertices.
To solve this issue, you can for example triangulate the faces of each
of your models (see attachement).

Sebastien.




On 01/25/2012 06:26 AM, Zhanghong Tang wrote:
Dear all,

With the following code, I'd like to add multiple objects into one and
then output the union to an OFF file, however, the code crashed in the line
Nef_polyhedron nef_obj(obj);

how to modify the code to let it works? I will be very appericate if
anyone help me to check the code.

Thanks


PS: the code

typedef struct object
{
void *obj;
}myobj;

void UnionObject(myobj *object, void *unionobj, int nobject)
{
Polyhedron obj, UnitedObj;
Nef_polyhedron nef_uni;
for (int i=0;i<nobject;i++)
{
obj=*(Polyhedron *)object[i].obj;
Nef_polyhedron nef_obj(obj);
if(i==0)
nef_uni = nef_obj;
else
nef_uni = nef_uni + nef_obj;

}
nef_uni.convert_to_polyhedron(UnitedObj);
}

There are totally 6 objects to be added, the off files generated from
object[i].obj (i=0,1,2,3,4,5) are attached.




------------------------------------------------------------------------
From:

To:

Date: Wed, 25 Jan 2012 15:11:04 +1200
Subject: RE: [cgal-discuss] What's the minimal requirement to use the
Constructive Solid Geometry (CSG) module of CGAL?

Hi Guillaume,

Thank you very much for your kindly reply. Now I have the following code
to unite many objects into one:

typedef struct object
{
void *obj;
}myobj;

void UnionObject(myobj *object, void *unionobj, int nobject)
{
Polyhedron obj, UnitedObj;
Nef_polyhedron nef_uni;
for (int i=0;i<nobject;i++)
{
obj=*(Polyhedron *)object[i].obj;
Nef_polyhedron nef_obj(obj);
if(i==0)
nef_uni = nef_obj;
else
nef_uni = nef_uni + nef_obj;

}
nef_uni.convert_to_polyhedron(UnitedObj);
}

However, the program crash in the line
Nef_polyhedron nef_obj(obj);

Is there any missing to do this? How to modify the code to let the
multiple objects be united correctly?

I checked the polyhedron obj of every object[i].obj and output them to
OFF file and they are all correct (under Guillaume's help).

Thanks



------------------------------------------------------------------------
From:

To:

Subject: RE: [cgal-discuss] What's the minimal requirement to use the
Constructive Solid Geometry (CSG) module of CGAL?
Date: Wed, 25 Jan 2012 14:00:22 +1200

Hi Guillaume,

Thank you very much for your kindly reply. Now I have the following code
to unite many objects into one:

typedef struct object
{
void *obj;
}myobj;

void UnionObject(myobj *object, void *unionobj, int nobject)
{
Polyhedron obj, UnitedObj;
Nef_polyhedron nef_uni;
for (int i=0;i<nobject;i++)
{
obj=*(Polyhedron *)object[i].obj;
Nef_polyhedron nef_obj(obj);
if(i==0)
nef_uni = nef_obj;
else
nef_uni = nef_uni + nef_obj;

}
nef_uni.convert_to_polyhedron(UnitedObj);
}

However, the program crash in the line
Nef_polyhedron nef_obj(obj);

Is there any missing to do this?
I checked the polyhedron obj of every object[i].obj and output them to
OFF file and they are all correct (under Guillaume's help).

Thanks



------------------------------------------------------------------------
Date: Tue, 24 Jan 2012 10:20:05 +0100
From:

To:

Subject: Re: [cgal-discuss] What's the minimal requirement to use the
Constructive Solid Geometry (CSG) module of CGAL?

Hi,

Hi Guillaume,

Thank you very much for your encouragement. I don't understand the
benefit to wirte like this: the very complex class, constructor, and
so on.


The benefit is genericity.


Is it possible to write just what need to be executed, or the
process of execute can be see naturaly. For example:

the function:

Polyhedron Build_triangle(int nVertices0, double *Vertices0, int
nTri0, int *Tri0)
{
...
}

the caller:
...
Polyhedron P;
P=Build_triangle(nVertices,Vertices,nTri,Tri);


No this is not possible: you have to use the format required by the
incremental builder class...


...

By the way, the following code can output the polyhedron to OFF
format to the screen (from the example 'polyhedron_prog_cut_cube.cpp'):
std::cout << P;

how to modify the code to let it output to a file 'filename' with
the definition:
char *filename;


Use ofstream. Cf for example http://www.cplusplus.com/doc/tutorial/files/

Guillaume





Thanks


------------------------------------------------------------------------
Date: Tue, 24 Jan 2012 08:28:50 +0100
From:


<mailto:>
To:


<mailto:>
Subject: Re: [cgal-discuss] What's the minimal requirement to use
the Constructive Solid Geometry (CSG) module of CGAL?


Hi Guillaume,

Thank you very much for your kindly reply. Now the problem is
solved. I should modify the code like this:


Perfect.


class Build_triangle : public CGAL::Modifier_base<HDS> {
public:
int nVertices;
double *Vertices;
int nTri;
int *Tri;
Build_triangle(int nVertices0, double *Vertices0, int nTri0, int
*Tri0)
{
nVertices=nVertices0;
Vertices=Vertices0;
nTri=nTri0;
Tri=Tri0;
}


Now my question is: can I pass parameters as a more simple and
understandable way, just like the 'Fortran' subroutine?


What do you mean by "more simple and understandable way" ?



Thanks



------------------------------------------------------------------------
From:


<mailto:>
To:


<mailto:>
Date: Tue, 24 Jan 2012 19:02:57 +1200
Subject: RE: [cgal-discuss] What's the minimal requirement to
use the Constructive Solid Geometry (CSG) module of CGAL?

Hi Guillaume,

Thank you very much for your kindly reply. I am new to C++ class
and the complex operators and don't know how to modify the code
to pass the parameters to the operator. Is there any simple way
to read the input vertices and facets from other functions to
form the polyhedron of CGAL? To let the CGAL do boolean
operations, should I do like the example? What's the simplest
way? I need to generate polyhedron from CSG and then let CGAL to
do the boolean opearations and then output the results to OFF file.

Thanks



------------------------------------------------------------------------
Date: Tue, 24 Jan 2012 07:09:53 +0100
From:


<mailto:>
To:


<mailto:>
Subject: Re: [cgal-discuss] What's the minimal requirement to
use the Constructive Solid Geometry (CSG) module of CGAL?

The variables nVertices,Vertices,nTri,nTri are parameters of the
constructor of your class.
Thus they are not defined in the operator(). You need to define
variables in your class in order to store them.
Guillaume


Dear Dr. Loriot,

Thank you very much for your kindly reply. I am trying to
study the example 'polyhedron_prog_incr_builder' and tried
to modify the file 'polyhedron_prog_incr_builder.cpp' as
follows:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Polyhedron_3.h>

// A modifier creating a triangle with the incremental builder.
template <class HDS>
class Build_triangle : public CGAL::Modifier_base<HDS> {
public:
Build_triangle(int nVertices, double *Vertices, int nTri,
int *Tri) {}
void operator()( HDS& hds) {
// Postcondition: `hds' is a valid polyhedral surface.
CGAL::Polyhedro n_incremental_builder_3<HDS> B( hds, true);
B.begin_surface( 3, 1, 6);
typedef typename HDS::Vertex Vertex;
typedef typename Vertex::Point Point;
double *v=Vertices;
for (int i=0;i<nVertices;i++)
B.add_vertex( Point( *v++, *v++, *v++));
for (int i=0;i<nTri;i++)
{
B.begin_facet();
B.add_vertex_to_facet( *Tri++);
B.add_vertex_to_facet( *Tri++);
B.add_vertex_to_facet( *Tri++);
B.end_facet();
}
B.end_surface();
}
};

typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::HalfedgeDS HalfedgeDS;

int main() {
; Polyhedron P;
int nVertices=3;
double Vertices[]={0, 0, 0,1, 0, 0,0, 1, 0};
int nTri=1;
int Tri[]={0,1,2};
Build_triangle<HalfedgeDS>
triangle(nVertices,Vertices,nTri,Tri);
P.delegate( triangle);
//CGAL_assertion( P.is_triangle( P.halfedges_begin()));
return 0;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


The following errors displayed:
1>------ Build started: Project:
polyhedron_prog_incr_builder, Configuration: Debug Win32 ------
1>Build started 2012/1/24 11:50:26.
1>InitializeBuildStatus:
1> Touching

"polyhedron_prog_incr_builder.dir\Debug\polyhedron_prog_incr_builder
.unsuccessfulbuild".
1>CustomBuild:
1> All outputs are up-to-date.
1>ClCompile:
1> polyhedron_prog_incr_builder.cpp

1>D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\polyhedron_prog_incr_builder.cpp(16):
error C2065: 'Vertices' : undeclared identifier
1>

D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\polyhedron_prog_incr_builder.cpp(10)
: while compiling class template member function 'void
Build_triangle<HDS>::operator ()(HDS &)'
1> with
1> [
1> HDS=HalfedgeDS
1> ]
1>

D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\polyhedron_prog_incr_builder.cpp(41)
: see reference to class template instantiation
'Build_triangle<HDS>' being compiled
1> with
1> [
1> HDS=HalfedgeDS
1> ]

1>D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\polyhedron_prog_incr_builder.cpp(17):
error C2065: 'nVertices' : undeclared identifier

1>D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\polyhedron_prog_incr_builder.cpp(19):
error C2065: 'nTri' : undeclared identifier

1>D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\polyhedron_prog_incr_builder.cpp(22):
error C2065: 'Tri' : undeclared identifier

1>D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\polyhedron_prog_incr_builder.cpp(23):
error C2065: 'Tri' : undeclared identifier
1>D:\CGAL\CGAL3.9\CGAL-3.9\examples\Polyhedron\poly
hedron_prog_incr_builder.cpp(24): error C2065: 'Tri' :
undeclared identifier
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.53
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0
skipped ==========


Could you please help me to check the problem?



Thanks



> Date: Wed, 18 Jan 2012 11:55:11 +0100
> From:


<mailto:>
> To:


<mailto:>
> Subject: Re: [cgal-discuss] What's the minimal
requirement to use the Constructive Solid Geometry (CSG)
module of CGAL?
>
> CGAL cannot handle directly cylinders but only discrete
polyhedral models.
>
> See the documentation of Nef package for more details:
>

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html
>
> Sebastien.
>
> On 01/18/2012 10:41 AM, Zhanghong Tang wrote:
> > Dear Dr. Loriot,
> >
> > Thank you very much for your kindly reply.
> >
> > My requirement is as follows:
> > 1) read the geometries to do the operations;
> > for example, two cylinders with both radius 1 and
length 10, the center
> > of top and bottom facet of two cylinders are:
> > cylinder 1:
> > top facet: (0,0,5)
> > bottom facet: (0,0,-5)
> > cylinder 2:
> > top facet (5,0,0)
> > bottom facet: (-5,0,0)
> >
> > 2) find the 3D Boolean operations of input objects and
output the
> > presentation by OFF file format.
> > for example, find the unite of two crossed cylinders
and output the
> > presentation by OFF file format.
> >
> >
> > How to implement this with mimimal code?
> >
> >
> > Thanks,
> > Zhanghong Tang
> >
> >
> > P.S.:
> > I notice that the mesher 'NetGen' takes the CSG format
as its input
> > file, however, it can't handle the simplest example (it
works when the
> > radius of two cylinders are not equal), I guess that
the CGAL can handle
> > it easily.
> >
> >
> >
> > > Date: Wed, 18 Jan 2012 08:25:30 +0100
> > > From:


<mailto:>
> > > To:


<mailto:>
> > > Subject: Re: [cgal-discuss] What's the minimal
requirement to use the
> > Constructive Solid Geometry (CSG) module of CGAL?
> > >
> > > Zhanghong Tang wrote:
> > > > Dear all,
> > > >
> > > > I would like use the CSG module of CGAL, what's the
minimal
> > requirement
> > > > to use this module? I want to build it to a
blockbox with CSG module
> > > > data input and another format data output (for
example, piecewise
> > linear
> > > > complex format, Geomview's polyhedral file format
(OFF)), which files
> > > > should I select to compile and is there any
interface to use this
> > module?
> > > >
> > > > Thanks,
> > > > Zhanghong Tang
> > > >
> > > Your question is not clear to me. Could you explain
what you are looking
> > > for exactly?
> > &g t;
> > > For 3D Boolean operations, you need to use Nef_3:
> > >
> >

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html
> > > For simple polyhedron manipulation, you can use
Polyhedron_3:
> > >
> >

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Polyhedron/Chapter_main.html
> > >
> > > Sebastien.
> > > ;
> > > --
> > > 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
>



--
===================================================================
Guillaume DAMIAND

CNRS, LIRIS UMR 5205
Université Claude Bernard
Bâtiment Nautibus (710)
43 Boulevard du 11 Novembre 1918
69622 Villeurbanne Cedex (France)
-------------------------------------------------------------------
Phone: +33 (0)4.72.43.26.62 Fax: +33 (0)4.72.43.15.36

Mail:

<mailto:>
===================================================================



--
===================================================================
Guillaume DAMIAND

CNRS, LIRIS UMR 5205
Université Claude Bernard
Bâtiment Nautibus (710)
43 Boulevard du 11 Novembre 1918
69622 Villeurbanne Cedex (France)
-------------------------------------------------------------------
Phone: +33 (0)4.72.43.26.62 Fax: +33 (0)4.72.43.15.36

Mail:

<mailto:>
===================================================================



--
===================================================================
Guillaume DAMIAND

CNRS, LIRIS UMR 5205
Université Claude Bernard
Bâtiment Nautibus (710)
43 Boulevard du 11 Novembre 1918
69622 Villeurbanne Cedex (France)
-------------------------------------------------------------------
Phone: +33 (0)4.72.43.26.62 Fax: +33 (0)4.72.43.15.36
Mail:

<mailto:>
===================================================================


Attachment: test-tri.zip
Description: Zip archive




Archive powered by MHonArc 2.6.16.

Top of Page