#ifndef CGAL_USE_QT
#include <iostream>
int main(int, char*){
  std::cout << "Sorry, this demo needs QT..." << std::endl; return 0;}
#else
#include <iostream>
#include <vector>
#include <CGAL/Cartesian.h>
#include <CGAL/Filtered_kernel.h>
#include <CGAL/Point_2.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_hierarchy_2.h>
#include <CGAL/IO/Qt_widget_Delaunay_triangulation_2.h>
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/IO/Qt_widget_layer.h>
#include <CGAL/Random.h>
#include <qapplication.h>
#include <CGAL/Timer.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Quotient.h>
#include <CGAL/Gmpq.h>

//typedef float                               Number_type;
typedef double                               Number_type;
//typedef CGAL::Quotient<CGAL::MP_Float>      Number_type;
//typedef CGAL::MP_Float      Number_type;
//typedef CGAL::Gmpq    Number_type;

typedef CGAL::Cartesian<Number_type>        KK;

//typedef KK                                  K;
typedef CGAL::Filtered_kernel<KK >          K;



typedef CGAL::Point_2<K> 		    Point;
typedef CGAL::Triangulation_vertex_base_2<K>             Vbb;
typedef CGAL::Triangulation_hierarchy_vertex_base_2<Vbb> Vb;
typedef CGAL::Triangulation_face_base_2<K>               Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb>      Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds>            Delaunay;
//typedef CGAL::Triangulation_hierarchy_2<Dt>              Delaunay;




class My_layer : public CGAL::Qt_widget_layer{
  void draw(){
    ;
  }
};

class My_window : public CGAL::Qt_widget {
public:
  My_window(int x, int y)
  {
    resize(x,y);
    attach(&layer);
  };
private:
  //this method is called when the user presses the mouse
  void mousePressEvent(QMouseEvent *e)
  {
    Qt_widget::mousePressEvent(e);

    /////////////////////////////////////////////////////////////
    //  C'EST ICI QUE CA SE PASSE QUAND ON CLIQUE !
    //
      exit(1);
    /////////////////////////////////////////////////////////////

    redraw();
  }
  My_layer layer;
};

int main( int argc, char **argv )
{
    QApplication app( argc, argv );
    My_window *W = new My_window(400,400);
    app.setMainWidget(W);
    W->show();
    W->set_window(-1.1, 1.1, -1.1, 1.1);

    Delaunay dt1;

    int Nb_points;
    CGAL::Timer cost;


    std::cout<<" Nombre de points ? "<<std::endl;
    std::cin>>Nb_points;
    CGAL::Random random(0);

    Delaunay dt2;cost.reset();cost.start();    
    for( int i = 0 ; i<Nb_points;++i) {
      Number_type x = random.get_double(-0.9,0.9);
      Number_type y = random.get_double(-0.9,0.9);
      dt2.insert( Point( x, y ) );
      std::cout<<"\b\b\b\b\b\b\b\b\b"<<i<<" ";
    }    
    *W << CGAL::RED<<dt2;
    std::cout<<std::endl<<Nb_points<<" points dans un carre en "
             <<cost.time()<<" secondes"<<std::endl;



    cost.stop();cost.reset();cost.start();
    Number_type drte_a = random.get_double()/2;
    Number_type drte_b = random.get_double()/2;

    //    dt1.insert( Point( random.get_double(), random.get_double()) );
    dt1.insert( Point( -1, -1) );
    dt1.insert( Point(  1, -1) );
    dt1.insert( Point(  1,  1) );
    dt1.insert( Point( -1,  1) );
    
    for( int i = 0 ; i<Nb_points;++i) {
      Number_type x = random.get_double(-0.9,0.9);
      Number_type y = drte_a * x + drte_b;
      dt1.insert( Point( x, y ) );
      std::cout<<"\b\b\b\b\b\b\b\b\b"<<i<<" ";
    }
    *W << CGAL::GREEN<<dt1;
    std::cout<<std::endl<<Nb_points<<" points sur un segments en "
             <<cost.time()<<" secondes"<<std::endl;




    return app.exec();
}
#endif
