0

I am interested in implementing my computational geometry algorithms using the CGAL library. Ideally, I am also interested in being able to animate my algorithm.CGAL has an interface to geomview built in which I am interested in using for illustrating these algorithms.

Based on what I little I understand of the CGAL geomview interface (from this example), below is a very simple code I wrote, which inserts 5 random points, and segments between some of the points.

However, once I render the objects to the screen, I don't know how unrender them or delete them from the geomview window, if they need to be deleted at the next iteration(say) of my algorithm. So how would I modify the code below to do just that?

If someone knows of a better way than using geomview to animate geometry algorithms with CGAL that would also be helpful.

#include <iostream>
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 
#include <unistd.h> 
#include <CGAL/IO/Geomview_stream.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2; 
typedef K::Segment_2 Segment_2; 
using namespace std;

int main(int argc, char *argv[])
{

  Point_2 points[5] = { Point_2(0.,0.), Point_2(10.,0.),Point_2(10.,10.),Point_2(6.,5.),Point_2(4.,1.) }; 

  CGAL::Geomview_stream gv(CGAL::Bbox_3(-12, -12, -0.1, 12,12,0.1));

  gv << CGAL::RED; // red points
  for (int i = 0; i <= 2; ++i)
    {
       gv << points[i]; 
    }

  gv << CGAL::BLUE;// bluepoints
  for (int i = 3; i <= 4; ++i)
    {
      gv << points[i];  
    }

  // segments between some points
  gv << CGAL::BLACK;
  Segment_2 AB = Segment_2(points[0],points[1]); 
  gv << CGAL::YELLOW << AB ; 
  Segment_2 CD = Segment_2(points[1],points[2]);
  gv << CGAL::BLUE <<   CD ; 

  sleep(300);
  return 0;
}
smilingbuddha
  • 14,334
  • 33
  • 112
  • 189

1 Answers1

1

The current trend among CGAL developers is to use Qt framework and associated visualisation tools such as QGLViewer rather than Geomview which are more recent, fully portative and allows you to do much more (especially if you want to make a demo for your algorithms with user interactions).

If you want to do 3D visualisation with CGAL I will advise you to use QGLViewer as they are already a lot of demos in CGAL that uses that library. For instance as an entry point, I will suggest you to have a look to Alpha_shape_3 demo. The code of this demo is quite light and straightforward, you can easily add new features without understanding the whole Qt framework first (you may have to eventually but that way the learning curve will be less steep and you can quickly start implementing stuff).

If you want to do 2D visualisation, you may have a look to the Alpha_shape_2 demo and use QPainter from Qt (note that you can combine both 3d and 2d viewer in QGL viewer as shown in this example.

geoalgo
  • 678
  • 3
  • 11