#include <stdlib.h>
#include <cmath>
#include <list>

#include <CGAL/Filtered_kernel.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_3.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/IO/Color.h>

#include "CGAL/Delaunay_triangulation_3.h"
#include "CGAL/IO/Geomview_stream.h"


typedef CGAL::Filtered_kernel<CGAL::Cartesian<double> >	K;
typedef CGAL::Point_3<K>		                Point;
typedef Delaunay_triangulation_3<K>                     Delaunay;





/////////////////////////////////////////////////////////
//  Fonction main

int main( int argc, char **argv )
{
  std::list<Point> input;
  int n;

  std::cout << "Nombre de sommets : ";
  std::cin >> n;

  Geomview_stream gv (CGAL::Bbox_3 (-1, -1, -1, 1, 1, 1));
  gv.set_bg_color (CGAL::WHITE);
  gv.clear();

  getchar();


  // Creation de l'ensemble de points 
  n /=2 ;
  for (int i = 0; i < n; ++i) {
    double x = (double)i/n;
    input.push_back (Point (std::cos(4*x), std::sin(4*x), x));
    if (x != 0)
      input.push_back (Point (std::cos(4*x), -std::sin(4*x), -x));
  }

  // Affichage de l'ensemble de points
  gv.set_vertex_color (CGAL::BLACK);
  gv.draw_points (input.begin(), input.end());

  getchar();


  // Creation de la triangulation de Delaunay
  Delaunay dt;
  dt.insert (input.begin(), input.end());

  // Affichage de la triangulation de Delaunay
  gv.set_wired(true);
  gv << dt;

  getchar();

 /////////////////////////////////////////////////////////
  //  Entrer un point avec la souris et afficher le resultat
  
  gv.pickplane();  // le point est donne avec le bouton droit
  
  while (true) {
    Point p;
    gv >> p;
   std::cout << p  << std::endl;
   // Point p selectionne
    gv.set_vertex_color(CGAL::BLUE);
    gv << p;
 }

  exit(0);
}






