diff --git a/.gitattributes b/.gitattributes index 49f6362f9d5..eed314c6508 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1357,6 +1357,9 @@ Polytope_distance_d/test/Polytope_distance_d/test_PD_data/two_cubes_shifted.data Polytope_distance_d/test/Polytope_distance_d/test_PD_data/two_numbers.data -text Polytope_distance_d/test/Polytope_distance_d/test_PD_data/two_squares.data -text Polytope_distance_d/test/Polytope_distance_d/test_andreas_example.C -text +Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting.C -text +Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting_toolbar.C -text +Principal_component_analysis/demo/Principal_component_analysis/makefile -text Principal_component_analysis/demo/Principal_component_analysis/windows/2d/res/pca.ico -text svneol=unset#unset Principal_component_analysis/demo/Principal_component_analysis/windows/2d/res/pca.rc2 -text Principal_component_analysis/demo/Principal_component_analysis/windows/3d/res/Mesh.ico -text svneol=unset#unset diff --git a/Principal_component_analysis/demo/Principal_component_analysis/help/index.html b/Principal_component_analysis/demo/Principal_component_analysis/help/index.html new file mode 100644 index 00000000000..f0fb9d6c057 --- /dev/null +++ b/Principal_component_analysis/demo/Principal_component_analysis/help/index.html @@ -0,0 +1,126 @@ + + + + Principal Component Analysis + + + +

Principal Component analysis

+
+ Main Functionality +
+ Editing + +

 

+

 

+

 

+

 

+ +

+  

+

+  

+

+ Reset application

+ Press Ctrl+N combination keys or go to File menu and choose "New". The + points list will be erased, the window's visible area will be set to + default. (-1, 1, -1, 1) + +

+  

+

+  

+

+ Create a new window

+ Press Ctrl+W combination keys or go to File menu and choose "New Window". + A new window will appear, modifying the visible area to make the points + list fit in the new window. + +

+  

+

+  

+

Print +

+ Press Ctrl+P combination keys or go to File menu and choose "Print". The + visible area on the screen will be outputed to the print device of your + choice. + + +

+  

+

+  

+

+ Close the current window

+ Press Ctrl+X combination keys or go to File menu and choose "Close". You + may do it for any window other than the initial one, this operation will + close only the one you have choosen. If you do this for the initial parent + window, it will close the others too. + +

+  

+

+  

+

+ Quit the application

+ Press Ctrl+Q combination keys or go to File menu and choose "Quit". When + you quit the application, all the windows you have created will be + destroyed. + +

+  

+

+  

+

Generate points +

+ To generate points, go to Draw menu and choose "Generate points" or press + Ctrl+G combination keys. This action will generate random points uniformly + distributed in the open disc with radius 1. Each time you do this action, + new points will be added to the list, the old set of point being updated + and not erased. + +

+  

+

+  

+

+ Insert new points in the list

+ Left click on the "Input point" layer. Be sure there is no layer activated + in standard toolbar that eat events. To be sure, press the arrow button + situated on the standard toolbar. Left Click anywhere on the application's + drawing area (the black rectangle) to insert the point. The new point is + inserted in the list and the least squares fitting line is recomputed. To insert more + than one point, keep clicking on the rectangle without deactivating the + "Input point" layer. To deactivate this layer, just press the arrow button + situated on the same toolbar. + + +

+  

+

+  

+ + + + + + + +
+
+ + +Last modified: Mon Mar 13 14:53:31 MEST 2006 + + + diff --git a/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting.C b/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting.C new file mode 100644 index 00000000000..1c6858f6324 --- /dev/null +++ b/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting.C @@ -0,0 +1,280 @@ +// Copyright (c) 2002 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/trunk/Min_circle_2/demo/Min_circle_2/min_circle_2.C $ +// $Id: min_circle_2.C 28567 2006-02-16 14:30:13Z lsaboret $ +// +// +// Author(s) : Andreas Fabri + +#include + +// if QT is not installed, a message will be issued in runtime. +#ifndef CGAL_USE_QT +#include +int main(int, char*){ + std::cout << "Sorry, this demo needs QT..."; + std::cout << std::endl; return 0; +} +#else + +#include +#include +#include +#include + +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include "linear_least_squares_fitting_toolbar.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef double Coord_type; +typedef CGAL::Cartesian Rep; + +typedef CGAL::Point_2 Point_2; +typedef CGAL::Line_2 Line_2; + +//global flags and variables +int current_state; +std::list list_of_points; + +const QString my_title_string("Principal Component Analysis"); + + +class Qt_layer_show_ch : public CGAL::Qt_widget_layer +{ +public: + + Qt_layer_show_ch(){}; + + + void draw() + { + widget->lock(); + *widget << CGAL::PointSize(3); + *widget << CGAL::BLUE; + std::list::iterator itp = list_of_points.begin(); + while(itp!=list_of_points.end()) + { + *widget << (*itp++); + } + *widget << CGAL::PointSize(2);// << CGAL::PointStyle(CGAL::PIXEL); + *widget << CGAL::RED; + + + if(list_of_points.size()>1){ + Line_2 line; + double quality = linear_least_squares_fitting_2(list_of_points.begin(), + list_of_points.end(), + line); + + *widget << line; + } + widget->unlock(); + }; + +};//end class + +class MyWindow : public QMainWindow +{ + Q_OBJECT +public: + MyWindow(int w, int h){ + widget = new CGAL::Qt_widget(this); + setCentralWidget(widget); + + //create a timer for checking if somthing changed + QTimer *timer = new QTimer( this ); + connect( timer, SIGNAL(timeout()), + this, SLOT(timer_done()) ); + timer->start( 200, FALSE ); + + // file menu + QPopupMenu * file = new QPopupMenu( this ); + menuBar()->insertItem( "&File", file ); + file->insertItem("&New", this, SLOT(new_instance()), CTRL+Key_N); + file->insertItem("New &Window", this, SLOT(new_window()), CTRL+Key_W); + file->insertSeparator(); + file->insertItem("Print", widget, SLOT(print_to_ps()), CTRL+Key_P); + file->insertSeparator(); + file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_X ); + file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); + + // drawing menu + QPopupMenu * draw = new QPopupMenu( this ); + menuBar()->insertItem( "&Draw", draw ); + draw->insertItem("&Generate points", this, + SLOT(gen_points()), CTRL+Key_G ); + + // help menu + QPopupMenu * help = new QPopupMenu( this ); + menuBar()->insertItem( "&Help", help ); + help->insertItem("How To", this, SLOT(howto()), Key_F1); + help->insertSeparator(); + help->insertItem("&About", this, SLOT(about()), CTRL+Key_A ); + help->insertItem("About &Qt", this, SLOT(aboutQt()) ); + + //the standard toolbar + stoolbar = new CGAL::Qt_widget_standard_toolbar (widget, this, "ST"); + //the new tools toolbar + newtoolbar = new Tools_toolbar(widget, this, &list_of_points); + + *widget << CGAL::LineWidth(2) << CGAL::BackgroundColor (CGAL::WHITE); + + resize(w,h); + widget->set_window(-1, 1, -1, 1); + widget->setMouseTracking(TRUE); + + //connect the widget to the main function that receives the objects + connect(widget, SIGNAL(new_cgal_object(CGAL::Object)), + this, SLOT(get_new_object(CGAL::Object))); + + //application flag stuff + old_state = 0; + + //layers + widget->attach(&testlayer); + }; + +private: + void something_changed(){current_state++;}; + +public slots: + void new_instance() + { + widget->lock(); + list_of_points.clear(); + widget->clear_history(); + widget->set_window(-1.1, 1.1, -1.1, 1.1); + // set the Visible Area to the Interval + widget->unlock(); + something_changed(); + } + +private slots: + void get_new_object(CGAL::Object obj) + { + Point_2 p; + if(CGAL::assign(p,obj)) { + list_of_points.push_back(p); + something_changed(); + } + }; + + void about() + { + QMessageBox::about( this, my_title_string, + "This is a demo for linear least squares fitting\n" + "Copyright CGAL @2006"); + }; + + void aboutQt() + { + QMessageBox::aboutQt( this, my_title_string ); + } + + void howto(){ + QString home; + home = "help/index.html"; + CGAL::Qt_help_window *help = new + CGAL::Qt_help_window(home, ".", 0, "help viewer"); + help->resize(400, 400); + help->setCaption("Demo HowTo"); + help->show(); + } + + void new_window(){ + MyWindow *ed = new MyWindow(500, 500); + ed->setCaption("Layer"); + ed->widget->clear_history(); + ed->widget->set_window(-1.1, 1.1, -1.1, 1.1); + ed->show(); + something_changed(); + } + + void timer_done() + { + if(old_state!=current_state){ + widget->redraw(); + old_state = current_state; + } + } + + void gen_points() + { + widget->clear_history(); + widget->set_window(-1.1, 1.1, -1.1, 1.1); + // set the Visible Area to the Interval + + // send resizeEvent only on show. + CGAL::Random_points_in_disc_2 g(1); + for(int count=0; count<200; count++) { + list_of_points.push_back(*g++); + } + something_changed(); + } + + + +private: + CGAL::Qt_widget *widget; + CGAL::Qt_widget_standard_toolbar + *stoolbar; + Tools_toolbar *newtoolbar; + int old_state; + Qt_layer_show_ch testlayer; +}; + +#include "linear_least_squares_fitting.moc" + + +int +main(int argc, char **argv) +{ + std::cout.precision(50); + QApplication app( argc, argv ); + MyWindow widget(500,500); // physical window size + app.setMainWidget(&widget); + widget.setCaption(my_title_string); + widget.setMouseTracking(TRUE); +#if !defined (__POWERPC__) + QPixmap cgal_icon = QPixmap((const char**)demoicon_xpm); + widget.setIcon(cgal_icon); +#endif + widget.show(); + current_state = -1; + return app.exec(); +} + +#endif // CGAL_USE_QT diff --git a/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting_toolbar.C b/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting_toolbar.C new file mode 100644 index 00000000000..b7333eef67b --- /dev/null +++ b/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting_toolbar.C @@ -0,0 +1,67 @@ +// Copyright (c) 2002 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/trunk/Min_circle_2/demo/Min_circle_2/min_circle_2_toolbar.C $ +// $Id: min_circle_2_toolbar.C 28567 2006-02-16 14:30:13Z lsaboret $ +// +// +// Author(s) : Andreas Fabri + +#include + +#ifdef CGAL_USE_QT + +#include +#include "linear_least_squares_fitting_toolbar.h" + +// icons +#include +#include + +#include + +Tools_toolbar::Tools_toolbar(CGAL::Qt_widget *w, + QMainWindow *mw, std::list *l1) : + QToolBar(mw, "NT") + { + w->attach(&pointbut); + //set the widget + widget = w; + + QIconSet set0(QPixmap( (const char**)arrow_small_xpm ), + QPixmap( (const char**)arrow_xpm )); + QIconSet set1(QPixmap( (const char**)point_small_xpm ), + QPixmap( (const char**)point_xpm )); + + but[0] = new QToolButton(this, "deactivate layer"); + but[0]->setIconSet(set0); + but[0]->setTextLabel("Deactivate Layer"); + but[1] = new QToolButton(this, "pointtool"); + but[1]->setIconSet(set1); + but[1]->setTextLabel("Input Point"); + + nr_of_buttons = 2; + button_group = new QButtonGroup(0, "My_group"); + for(int i = 0; iinsert(but[i]); + but[i]->setToggleButton(true); + } + button_group->setExclusive(true); + + connect(but[1], SIGNAL(stateChanged(int)), + &pointbut, SLOT(stateChanged(int))); +}; + +#include "linear_least_squares_fitting_toolbar.moc" + +#endif diff --git a/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting_toolbar.h b/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting_toolbar.h new file mode 100644 index 00000000000..32336d24b0c --- /dev/null +++ b/Principal_component_analysis/demo/Principal_component_analysis/linear_least_squares_fitting_toolbar.h @@ -0,0 +1,55 @@ +// Copyright (c) 2002 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Andreas Fabri + + +#ifndef MIN_CIRCLE_2_TOOLBAR_H +#define MIN_CIRCLE_2_TOOLBAR_H + +#include + + +#include +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Cartesian Rp; +typedef Rp::Point_2 Point_2; + +class Tools_toolbar : public QToolBar +{ + Q_OBJECT +public: + Tools_toolbar(CGAL::Qt_widget *w, QMainWindow *mw, std::list *l1); + ~Tools_toolbar(){}; +private: + QToolButton *but[10]; + QButtonGroup *button_group; + CGAL::Qt_widget *widget; + int nr_of_buttons; + + CGAL::Qt_widget_get_point pointbut; + +};//end class + +#endif diff --git a/Principal_component_analysis/demo/Principal_component_analysis/makefile b/Principal_component_analysis/demo/Principal_component_analysis/makefile new file mode 100644 index 00000000000..8ede3b13e4a --- /dev/null +++ b/Principal_component_analysis/demo/Principal_component_analysis/makefile @@ -0,0 +1,63 @@ +# Created by the script create_makefile +# This is the makefile for compiling a CGAL application. + +#---------------------------------------------------------------------# +# include platform specific settings +#---------------------------------------------------------------------# +# Choose the right include file from the /make directory. + +#CGAL_MAKEFILE = Enter your makefile here +include $(CGAL_MAKEFILE) + +#---------------------------------------------------------------------# +# compiler flags +#---------------------------------------------------------------------# + +CXXFLAGS = -I../../../include/ \ + $(CGAL_CXXFLAGS) \ + $(LONG_NAME_PROBLEM_CXXFLAGS) \ + $(DEBUG_OPT) + +#---------------------------------------------------------------------# +# linker flags +#---------------------------------------------------------------------# + +LIBPATH = \ + $(CGAL_LIBPATH) + +LDFLAGS = \ + $(LONG_NAME_PROBLEM_LDFLAGS) \ + $(CGAL_QT_LDFLAGS) \ + + +#---------------------------------------------------------------------# +# target entries +#---------------------------------------------------------------------# + +all: linear_least_squares_fitting + +linear_least_squares_fitting_toolbar$(OBJ_EXT): linear_least_squares_fitting_toolbar.C linear_least_squares_fitting_toolbar.moc + $(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) linear_least_squares_fitting_toolbar.C + +linear_least_squares_fitting_toolbar.moc: linear_least_squares_fitting_toolbar.h + $(QT_MOC) -o linear_least_squares_fitting_toolbar.moc linear_least_squares_fitting_toolbar.h + +linear_least_squares_fitting.moc: linear_least_squares_fitting.C linear_least_squares_fitting_toolbar$(OBJ_EXT) + ${QT_MOC} -o linear_least_squares_fitting.moc linear_least_squares_fitting.C + +linear_least_squares_fitting$(OBJ_EXT): linear_least_squares_fitting.C linear_least_squares_fitting.moc + $(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) linear_least_squares_fitting.C + +linear_least_squares_fitting$(EXE_EXT): linear_least_squares_fitting$(OBJ_EXT) + $(CGAL_CXX) $(EXE_OPT)linear_least_squares_fitting linear_least_squares_fitting$(OBJ_EXT) \ + linear_least_squares_fitting_toolbar$(OBJ_EXT) \ + $(LDFLAGS) + +clean: linear_least_squares_fitting.clean linear_least_squares_fitting_toolbar.clean + +#---------------------------------------------------------------------# +# suffix rules +#---------------------------------------------------------------------# + +.C$(OBJ_EXT): + $(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<