Plotting a mesh: Geom_traits with Triangulation_data_structure_2

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting a mesh: Geom_traits with Triangulation_data_structure_2

Yoann LE BARS

Hello everybody out there!

        Well, I have yet another problem. Thanks to Chris Marsh (thread from
October 8th to October 9th on this mailing list), I have been able to
load a 2D mesh with CGAL, actually making it a 3D mesh with z component
set to 0. Now, I need to plot it and as the code I am working on use Qt
(version 5), I try to use “CGAL::Qt::TriangulationGraphicsItem”.

        Here are the definitions I use:

/// \brief Allows for using 2D algorithms on the 3D points.
typedef CGAL::Projection_traits_xy_3<K> Gt;
/// \brief Vertex class.
typedef CGAL::Triangulation_vertex_base_2<Gt> Vb;
/// \brief Custom face class, use default face and vertex as required.
typedef CGAL::Constrained_triangulation_face_base_2<Gt> Fb;
/// \brief Type for 2D triangulation with CGAL.
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Triangulation;

        I try to create a “TriangulationGraphicsItem”:

p = new CGAL::Qt::TriangulationGraphicsItem<Triangulation> (mesh);

        The “mesh” object being an instantiation of “Triangulation”.

        But I obtain this error while compiling:

/usr/include/CGAL/Qt/TriangulationGraphicsItem.h:44:35: error: no type
named ‘Geom_traits’ in ‘class
CGAL::Triangulation_data_structure_2<CGAL::Triangulation_vertex_base_2<CGAL::Projection_traits_xy_3<CGAL::Epick>
>,
CGAL::Constrained_triangulation_face_base_2<CGAL::Projection_traits_xy_3<CGAL::Epick>
> >’

        So it turned out the classes I use do not have a “Geom_traits” type. In
a way or another, I need to provide this type. I cannot find more clue
on the documentation: maybe should I use some other classes? Does anyone
have some documentation for drawing with CGAL and Qt5, beside the
following, which did not gave me enough information to solve my problem?

https://doc.cgal.org/latest/GraphicsView/index.html

        Best regards.

--
Yoann LE BARS
http://le-bars.net/yoann
*Diaspora : [hidden email]

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


Reply | Threaded
Open this post in threaded view
|

Re: Plotting a mesh: Geom_traits with Triangulation_data_structure_2

Yoann LE BARS

Hello everybody out there!

        If I understand the documentation, CGAL does not provide any way to
draw a “Triangulation_data_structure_2”. I think I should use my
“Triangulation_data_structure_2” to build a “Delaunay_triangulation_2”.
The thing is, I do not find any way in the documentation to do such thing.

        Does somebody have some example on building a
“Delaunay_triangulation_2” using an existing “Triangulation_data_structure”?

        Best regards.

--
Yoann LE BARS
http://le-bars.net/yoann
*Diaspora : [hidden email]

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


Reply | Threaded
Open this post in threaded view
|

Re: Plotting a mesh: Geom_traits with Triangulation_data_structure_2

Yoann LE BARS

Hello everybody out there!

        Well, I think I have been able to create a “CGAl::Triangulation_2” with
a given existing mesh (see the code attached to this message). Now, I am
still trying to draw it using “TriangulationGraphicsItem”, but I still
obtain a quite long compiling error. Here is the first line of error I get:

main.cpp:70:59: error: no matching function for call to
‘CGAL::Qt::TriangulationGraphicsItem<CGAL::Triangulation_2<CGAL::Epick,
CGAL::Triangulation_data_structure_2<CGAL::Triangulation_vertex_base_2<CGAL::Projection_traits_xy_3<CGAL::Epick>
>,
CGAL::Constrained_triangulation_face_base_2<CGAL::Projection_traits_xy_3<CGAL::Epick>
> > > >::TriangulationGraphicsItem(Triangulation&)’
  CGAL::Qt::TriangulationGraphicsItem<Triangulation> p (tri);
                                                           ^

        The code attached is a minimal complete example, which shows how I try
to draw a mesh. Now, still, I cannot find a way to draw a mesh. Is there
any example available on how to draw a “Triangulation_2” using
“TriangulationGraphicsItem” anywhere? I cannot find any.

        Best regards.

--
Yoann LE BARS
http://le-bars.net/yoann
*Diaspora : [hidden email]

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



cgal-triangulation.zip (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Plotting a mesh: Geom_traits with Triangulation_data_structure_2

chrism
Hi,

I've never used the Qt functionality of CGAL, but I think you need to use just CGAL::draw(tri), as per

If I add

#include <CGAL/draw_triangulation_2.h>
<.. snip ..>
// Painter tool.
CGAL::draw (tri);

It compiles successfully. However, I get:

./src/bin/triangulation
Number of vertices = 3
Number of faces = 2
Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined.

I'm on MacOS and my Qt library through brew causes me nothing but problems, so it might be related to that. Otherwise this might solve it for you (didn't for me)

Everything I've read over the years suggests the viz in cgal is for quick and dirty visualization.
e.g.,

Depending on what your needs are, you might want to consider writing to a format that is easily visualized in another software. If you're interested in visualizing simulation output, might I suggest writing to a Paraview (paraview.org) format (vtu)? This approach has treated me very well. It's pretty straightforward format to write to (VTK library does the hard part), and Paraview is immensely useful for visualizing simulation outputs  and exploring a mesh. I can send you a paraview file that is an exported CGAL mesh if you're interested.

Cheers

Chris Marsh
PhD Candidate
chrismarsh.ca

On Tue, 13 Nov 2018 at 10:06, Yoann LE BARS <[hidden email]> wrote:

Hello everybody out there!

        Well, I think I have been able to create a “CGAl::Triangulation_2” with
a given existing mesh (see the code attached to this message). Now, I am
still trying to draw it using “TriangulationGraphicsItem”, but I still
obtain a quite long compiling error. Here is the first line of error I get:

main.cpp:70:59: error: no matching function for call to
‘CGAL::Qt::TriangulationGraphicsItem<CGAL::Triangulation_2<CGAL::Epick,
CGAL::Triangulation_data_structure_2<CGAL::Triangulation_vertex_base_2<CGAL::Projection_traits_xy_3<CGAL::Epick>
>,
CGAL::Constrained_triangulation_face_base_2<CGAL::Projection_traits_xy_3<CGAL::Epick>
> > > >::TriangulationGraphicsItem(Triangulation&)’
  CGAL::Qt::TriangulationGraphicsItem<Triangulation> p (tri);
                                                           ^

        The code attached is a minimal complete example, which shows how I try
to draw a mesh. Now, still, I cannot find a way to draw a mesh. Is there
any example available on how to draw a “Triangulation_2” using
“TriangulationGraphicsItem” anywhere? I cannot find any.

        Best regards.

--
Yoann LE BARS
http://le-bars.net/yoann
*Diaspora : [hidden email]

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


Reply | Threaded
Open this post in threaded view
|

Re: Plotting a mesh: Geom_traits with Triangulation_data_structure_2

Yoann LE BARS

Hello everybody out there!

        Thank you for your answer, Chris, and my apologies to have sent this
message to you alone rather to the list. I repost it.

Le 13/11/2018 à 17:31, Chris Marsh a écrit :
> I've never used the Qt functionality of CGAL, but I think you need to
> use just CGAL::draw(tri), as per
> https://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2draw_triangulation_2_8cpp-example.html

        Well, it turned out CGAL version on Ubuntu has not been compiled with
“draw”. As it is one of the systems I have to support, I cannot use it.
Anyway, I am working on an application with an interface made with Qt,
therefore the visualisation should be embedded in the interface and I
have to use Qt. As a consequence, “draw” is not a good option in my case.

> I'm on MacOS and my Qt library through brew causes me nothing but
> problems, so it might be related to that.

        This is not the question, but I do not really understand why mac people
tend to prefer Homebrew to Macport. My tests show you have better
control with Macport, it is more coherent with a Unix system and you can
solve things more easily and more efficiently when something goes wrong.
Also, there are much more applications available in Macports.

        Anyway …

> Everything I've read over the years suggests the viz in cgal is for
> quick and dirty visualization.
> e.g.,
> http://cgal-discuss.949826.n4.nabble.com/Tutorial-for-visualisation-in-CGAL-using-QT-td4656057.html

        Then, it turns out I should use CGAL only for mesh manipulation and
computation, then something else for visualisation.

> Depending on what your needs are, you might want to consider writing to
> a format that is easily visualized in another software. If you're
> interested in visualizing simulation output, might I suggest writing to
> a Paraview (paraview.org <http://paraview.org>) format (vtu)? This
> approach has treated me very well. It's pretty straightforward format to
> write to (VTK library does the hard part), and Paraview is immensely
> useful for visualizing simulation outputs  and exploring a mesh. I can
> send you a paraview file that is an exported CGAL mesh if you're interested.

        Using Paraview does not seem a good option to me, as I need to do
several treatments either on my meshes or using my meshes.

        Paraview uses Vtk library, which can be embedded in Qt applications. It
may be a good way to do visualisation I need to do.

        However, I am interested in the code you use for visualisation with
Paraview.

        Moreover, I am interested on any information to use CGAL with Vtk.

        Best regards.

--
Yoann LE BARS
http://le-bars.net/yoann/
Diaspora* : [hidden email]

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


Reply | Threaded
Open this post in threaded view
|

Re: Plotting a mesh: Geom_traits with Triangulation_data_structure_2

chrism
Hi,
My apologizes for the slow response. Please find attach a minimum working example to initialize a vtk unstructured mesh from CGAL. It then writes to a vtu you can load into paraview, but you can do whatever you want with this datastructue (eg use with Qt+VTK).
The 2 parameter on l 71-73 and 77 to 79 is the point id, which is really the only bookeeping. I store the vertex id (I start at 0 and increment as I read in vertices) using the vertex_with_info data vertex class. The idea is you just need a way to index into the points array to  say which vertices the triangle cell is using.
e.g., in my code
tri->GetPointIds()->SetId(0, face->vertex(0)->get_id());
tri->GetPointIds()->SetId(1, face->vertex(1)->get_id());
tri->GetPointIds()->SetId(2, face->vertex(2)->get_id());
but really any way of tracking which vertices are where will work. It's just book keeping.

You can then use CellData to embed further information onto the triangles in VTK, so you can display numerical results.
For example, this is a mesh I generate with CGAL to fit topography in a dynamic way, and then I display it in paraview (but that's really just vtk) using cell data to hold, in this case, elevations.

I find homebrew to consistently work. I've had more issues with macports, but I'll admit it's been probably 10 years since I used it. I think the Qt issues are just my inexperience with the library.

>As a consequence, “draw” is not a good option in my case.
You could always build and link against a new CGAL version. It's pretty easy to compile.

Cheers

Chris Marsh
PhD Candidate
chrismarsh.ca

On Tue, 13 Nov 2018 at 19:30, Yoann LE BARS <[hidden email]> wrote:

Hello everybody out there!

        Thank you for your answer, Chris, and my apologies to have sent this
message to you alone rather to the list. I repost it.

Le 13/11/2018 à 17:31, Chris Marsh a écrit :
> I've never used the Qt functionality of CGAL, but I think you need to
> use just CGAL::draw(tri), as per
> https://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2draw_triangulation_2_8cpp-example.html

        Well, it turned out CGAL version on Ubuntu has not been compiled with
“draw”. As it is one of the systems I have to support, I cannot use it.
Anyway, I am working on an application with an interface made with Qt,
therefore the visualisation should be embedded in the interface and I
have to use Qt. As a consequence, “draw” is not a good option in my case.

> I'm on MacOS and my Qt library through brew causes me nothing but
> problems, so it might be related to that.

        This is not the question, but I do not really understand why mac people
tend to prefer Homebrew to Macport. My tests show you have better
control with Macport, it is more coherent with a Unix system and you can
solve things more easily and more efficiently when something goes wrong.
Also, there are much more applications available in Macports.

        Anyway …

> Everything I've read over the years suggests the viz in cgal is for
> quick and dirty visualization.
> e.g.,
> http://cgal-discuss.949826.n4.nabble.com/Tutorial-for-visualisation-in-CGAL-using-QT-td4656057.html

        Then, it turns out I should use CGAL only for mesh manipulation and
computation, then something else for visualisation.

> Depending on what your needs are, you might want to consider writing to
> a format that is easily visualized in another software. If you're
> interested in visualizing simulation output, might I suggest writing to
> a Paraview (paraview.org <http://paraview.org>) format (vtu)? This
> approach has treated me very well. It's pretty straightforward format to
> write to (VTK library does the hard part), and Paraview is immensely
> useful for visualizing simulation outputs  and exploring a mesh. I can
> send you a paraview file that is an exported CGAL mesh if you're interested.

        Using Paraview does not seem a good option to me, as I need to do
several treatments either on my meshes or using my meshes.

        Paraview uses Vtk library, which can be embedded in Qt applications. It
may be a good way to do visualisation I need to do.

        However, I am interested in the code you use for visualisation with
Paraview.

        Moreover, I am interested on any information to use CGAL with Vtk.

        Best regards.

--
Yoann LE BARS
http://le-bars.net/yoann/
Diaspora* : [hidden email]

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



CMakeLists.txt (612 bytes) Download Attachment
main.cpp (4K) Download Attachment
out.vtu (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Plotting a mesh: Geom_traits with Triangulation_data_structure_2

Yoann LE BARS

Hello everybody out there!

On 2018/11/15 at 05:08 am, Chris Marsh wrote:
> Please find attach a minimum
> working example to initialize a vtk unstructured mesh from CGAL.

        Thank you, I will use it.

> I find homebrew to consistently work. I've had more issues with
> macports, but I'll admit it's been probably 10 years since I used it. I
> think the Qt issues are just my inexperience with the library.

        To be honest, I do not use MacOS on a daily basis, but it is an OS I am
targetting for any of my development works. Still, my in my tests it
turns out you need to take a little longer to learn MacPort than
Hombrew, but then the system is more coherent. By the way, I already new
Ports from Free BSD before using MacPort.

        Anyway, I should not have mention that, as it is not the point. My
apologies.

>>As a consequence, “draw” is not a good option in my case.
> You could always build and link against a new CGAL version. It's pretty
> easy to compile.

        Well, yes, but as a long time Unix user, I do not like codes that embed
third part libraries. The code become bigger and you need to keep track
to the evolution of the third parts. And some times the embedded
versions cannot be compiled on a given architecture.

        Then again, as you mentioned, it seems that viewing possibility of CGAL
are really much for quick and dirty visualisation, while I need to
manipulate my meshes and use them for field visualisation. Also, looking
to your code it seems quite simple to use VTK to visualise CGAL meshes.
So it seems much more reasonable to use VTK.

        Best regards.

--
Yoann LE BARS
http://le-bars.net/yoann
*Diaspora : [hidden email]

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