Added the demo

This commit is contained in:
Andreas Fabri 2006-03-29 08:21:25 +00:00
parent ea43a393c4
commit c1c0b1906e
6 changed files with 594 additions and 0 deletions

3
.gitattributes vendored
View File

@ -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

View File

@ -0,0 +1,126 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>Principal Component Analysis</title>
</head>
<body>
<P align="center"><FONT size="5">Principal Component analysis</FONT></P>
<br>
Main Functionality
<UL>
<LI><A href="#new">Reset application</A></LI>
<LI><A href="#new_window">Creating a new window</A></LI>
<LI><A href="#print">Print</A></LI>
<LI><A href="#close_window">Close the current window</A></LI>
<LI><A href="#quit">Quit the application</A></LI>
</UL><br>
Editing
<UL>
<LI><A href="#gen_p">Generate points</A></LI>
<LI><A href="#ins_p">Insert new points in the list</A></LI>
</UL>
<P align="left"><STRONG><FONT size="5"></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT size="5"></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT size="5"></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT size="5"></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"><A name="new"></A>
</FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="3">
Reset application</FONT></STRONG></P>
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)
<P align="left"><STRONG><FONT color="#3300cc" size="4">
<A name="new_window"></A></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="3">
Create a new window</FONT></STRONG></P>
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.
<P align="left"><STRONG><FONT color="#3300cc" size="4"><A name="print">
</A></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="3">Print</FONT>
</STRONG></P>
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.
<P align="left"><STRONG><FONT color="#3300cc" size="4">
<A name="close_window"></A></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="3">
Close the current window</FONT></STRONG></P>
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.
<P align="left"><STRONG><FONT color="#3300cc" size="4">
<A name="quit"></A></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="3">
Quit the application</FONT></STRONG></P>
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.
<P align="left"><STRONG><FONT color="#3300cc" size="4"><A name="gen_p">
</A></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="3">Generate points
</FONT></STRONG></P>
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.
<P align="left"><STRONG><FONT color="#3300cc" size="4"><A name="ins_p">
</A></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="3">
Insert new points in the list</FONT></STRONG></P>
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.
<P align="left"><STRONG><FONT color="#3300cc" size="4"><A name="rem_p">
</A></FONT></STRONG>&nbsp;</P>
<P align="left"><STRONG><FONT color="#3300cc" size="4"></FONT>
</STRONG>&nbsp;</P>
<br>
<hr>
<!-- Created: Mon Jan 13 15:27:00 MET 2003 -->
<!-- hhmts start -->
Last modified: Mon Mar 13 14:53:31 MEST 2006
<!-- hhmts end -->
</body>
</html>

View File

@ -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 <CGAL/basic.h>
// if QT is not installed, a message will be issued in runtime.
#ifndef CGAL_USE_QT
#include <iostream>
int main(int, char*){
std::cout << "Sorry, this demo needs QT...";
std::cout << std::endl; return 0;
}
#else
#include <fstream>
#include <stack>
#include <set>
#include <string>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/linear_least_squares_fitting_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/IO/Qt_widget_standard_toolbar.h>
#include <CGAL/IO/Qt_help_window.h>
#include <CGAL/IO/Qt_widget_layer.h>
#include <CGAL/IO/pixmaps/demoicon.xpm>
#include "linear_least_squares_fitting_toolbar.h"
#include <qplatinumstyle.h>
#include <qapplication.h>
#include <qmainwindow.h>
#include <qstatusbar.h>
#include <qfiledialog.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qtoolbutton.h>
#include <qtoolbar.h>
#include <qfiledialog.h>
#include <qtimer.h>
typedef double Coord_type;
typedef CGAL::Cartesian<Coord_type> Rep;
typedef CGAL::Point_2<Rep> Point_2;
typedef CGAL::Line_2<Rep> Line_2;
//global flags and variables
int current_state;
std::list<Point_2> 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<Point_2>::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<Point_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

View File

@ -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 <CGAL/basic.h>
#ifdef CGAL_USE_QT
#include <CGAL/IO/Qt_widget.h>
#include "linear_least_squares_fitting_toolbar.h"
// icons
#include <CGAL/IO/pixmaps/point.xpm>
#include <CGAL/IO/pixmaps/arrow.xpm>
#include <qiconset.h>
Tools_toolbar::Tools_toolbar(CGAL::Qt_widget *w,
QMainWindow *mw, std::list<Point_2> *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; i<nr_of_buttons; i++) {
button_group->insert(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

View File

@ -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 <CGAL/Cartesian.h>
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/IO/Qt_widget_get_point.h>
#include <qobject.h>
#include <qtoolbutton.h>
#include <qtoolbar.h>
#include <qbuttongroup.h>
#include <qmainwindow.h>
typedef CGAL::Cartesian<double> 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<Point_2> *l1);
~Tools_toolbar(){};
private:
QToolButton *but[10];
QButtonGroup *button_group;
CGAL::Qt_widget *widget;
int nr_of_buttons;
CGAL::Qt_widget_get_point<Rp> pointbut;
};//end class
#endif

View File

@ -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 <cgalroot>/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) $<