Add max area k-gon

This commit is contained in:
Andreas Fabri 2010-09-23 15:58:54 +00:00
parent aed79e77ce
commit 818e9909f6
2 changed files with 140 additions and 104 deletions

View File

@ -9,6 +9,7 @@
#include<CGAL/create_straight_skeleton_2.h>
#include<CGAL/create_offset_polygons_2.h>
#include <CGAL/linear_least_squares_fitting_2.h>
#include <CGAL/extremal_polygon_2.h>
// Qt headers
#include <QtGui>
@ -52,7 +53,7 @@ private:
CGAL::Qt::Converter<K> convert;
Polygon poly;
Polygon poly, kgon;
QGraphicsScene scene;
CGAL::Qt::PolygonGraphicsItem<Polygon> * pgi;
@ -65,6 +66,8 @@ private:
std::list<QGraphicsLineItem* > offsetGraphicsItems;
CGAL::Qt::LineGraphicsItem<K>* lgi;
CGAL::Qt::PolygonGraphicsItem<Polygon> * kgongi;
public:
MainWindow();
@ -78,6 +81,7 @@ public slots:
void on_actionSavePolygon_triggered();
void on_actionRecenter_triggered();
void on_actionMaximumAreaKGon_triggered();
void on_actionInnerSkeleton_triggered();
void on_actionOuterOffset_triggered();
void on_actionLinearLeastSquaresFitting_triggered();
@ -116,7 +120,12 @@ MainWindow::MainWindow()
pgi->setVerticesPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
scene.addItem(pgi);
kgongi = new CGAL::Qt::PolygonGraphicsItem<Polygon>(&kgon);
kgongi->setEdgesPen(QPen(Qt::blue, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
kgongi->hide();
scene.addItem(kgongi);
lgi = new CGAL::Qt::LineGraphicsItem<K>();
lgi->setPen(QPen(Qt::blue, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
lgi->hide();
@ -360,6 +369,25 @@ MainWindow::on_actionOuterOffset_triggered()
}
}
void
MainWindow::on_actionMaximumAreaKGon_triggered()
{
if( (poly.size()>2) && poly.is_convex()){
clear();
kgon.clear();
std::vector<Point_2> points(poly.vertices_begin(),
poly.vertices_end());
CGAL::maximum_area_inscribed_k_gon_2(points.begin(),
points.end(),
3,
std::back_inserter(kgon));
kgongi->modelChanged();
kgongi->show();
}
}
void
MainWindow::on_actionLinearLeastSquaresFitting_triggered()
{
@ -484,6 +512,7 @@ MainWindow::clear()
clearSkeleton();
clearOffset();
lgi->hide();
kgongi->hide();
}

View File

@ -1,8 +1,9 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>GeometryFactory</author>
<class>Polygon_2</class>
<widget class="QMainWindow" name="Polygon_2" >
<property name="geometry" >
<widget class="QMainWindow" name="Polygon_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
@ -10,37 +11,37 @@
<height>325</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>CGAL 2D Polygon</string>
</property>
<property name="windowIcon" >
<iconset resource="../resources/CGAL.qrc" >
<property name="windowIcon">
<iconset resource="../resources/CGAL.qrc">
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QHBoxLayout" >
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout">
<item>
<widget class="QSplitter" name="splitter" >
<property name="orientation" >
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QGraphicsView" name="graphicsView" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<widget class="QGraphicsView" name="graphicsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy" >
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="verticalScrollBarPolicy" >
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy" >
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="transformationAnchor" >
<property name="transformationAnchor">
<enum>QGraphicsView::NoAnchor</enum>
</property>
</widget>
@ -48,185 +49,191 @@
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar" />
<widget class="QToolBar" name="fileToolBar" >
<property name="windowTitle" >
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="fileToolBar">
<property name="windowTitle">
<string>File Tools</string>
</property>
<attribute name="toolBarArea" >
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak" >
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionClear" />
<addaction name="actionLoadPolygon" />
<addaction name="actionSavePolygon" />
<addaction name="actionClear"/>
<addaction name="actionLoadPolygon"/>
<addaction name="actionSavePolygon"/>
</widget>
<widget class="QToolBar" name="toolBar" >
<property name="windowTitle" >
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>Visualization Tools</string>
</property>
<attribute name="toolBarArea" >
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak" >
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionRecenter" />
<addaction name="actionRecenter"/>
</widget>
<widget class="QMenuBar" name="menubar" >
<property name="geometry" >
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>568</width>
<height>19</height>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFile" >
<property name="title" >
<widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="separator" />
<addaction name="actionClear" />
<addaction name="actionLoadPolygon" />
<addaction name="actionSavePolygon" />
<addaction name="separator" />
<addaction name="actionQuit" />
<addaction name="separator"/>
<addaction name="actionClear"/>
<addaction name="actionLoadPolygon"/>
<addaction name="actionSavePolygon"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuTools" >
<property name="title" >
<widget class="QMenu" name="menuTools">
<property name="title">
<string>&amp;Algorithms</string>
</property>
<addaction name="separator" />
<addaction name="actionRecenter" />
<addaction name="actionYMonotonePartition" />
<addaction name="actionApproximateConvexPartition" />
<addaction name="actionOptimalConvexPartition" />
<addaction name="actionInnerSkeleton" />
<addaction name="actionOuterOffset" />
<addaction name="actionLinearLeastSquaresFitting" />
<addaction name="actionLinearLeastSquaresFittingOfSegments" />
<addaction name="separator"/>
<addaction name="actionRecenter"/>
<addaction name="actionYMonotonePartition"/>
<addaction name="actionApproximateConvexPartition"/>
<addaction name="actionOptimalConvexPartition"/>
<addaction name="actionInnerSkeleton"/>
<addaction name="actionOuterOffset"/>
<addaction name="actionLinearLeastSquaresFitting"/>
<addaction name="actionLinearLeastSquaresFittingOfSegments"/>
<addaction name="actionMaximumAreaKGon"/>
</widget>
<addaction name="menuFile" />
<addaction name="menuTools" />
<addaction name="menuFile"/>
<addaction name="menuTools"/>
</widget>
<action name="actionAbout" >
<property name="text" >
<action name="actionAbout">
<property name="text">
<string>&amp;About</string>
</property>
</action>
<action name="actionAboutCGAL" >
<property name="text" >
<action name="actionAboutCGAL">
<property name="text">
<string>About &amp;CGAL</string>
</property>
</action>
<action name="actionQuit" >
<property name="text" >
<action name="actionQuit">
<property name="text">
<string>&amp;Quit</string>
</property>
<property name="shortcut" >
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionClear" >
<property name="icon" >
<iconset resource="../icons/File.qrc" >
<action name="actionClear">
<property name="icon">
<iconset resource="../icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileNew.png</normaloff>:/cgal/fileToolbar/fileNew.png</iconset>
</property>
<property name="text" >
<property name="text">
<string>&amp;Clear</string>
</property>
<property name="shortcut" >
<property name="shortcut">
<string>Ctrl+C</string>
</property>
</action>
<action name="actionLoadPolygon" >
<property name="icon" >
<iconset resource="../icons/File.qrc" >
<action name="actionLoadPolygon">
<property name="icon">
<iconset resource="../icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileOpen.png</normaloff>:/cgal/fileToolbar/fileOpen.png</iconset>
</property>
<property name="text" >
<property name="text">
<string>&amp;Load Polygon</string>
</property>
<property name="shortcut" >
<property name="shortcut">
<string>Ctrl+L</string>
</property>
</action>
<action name="actionSavePolygon" >
<property name="icon" >
<iconset resource="../icons/File.qrc" >
<action name="actionSavePolygon">
<property name="icon">
<iconset resource="../icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileSave.png</normaloff>:/cgal/fileToolbar/fileSave.png</iconset>
</property>
<property name="text" >
<property name="text">
<string>&amp;Save Polygon</string>
</property>
<property name="shortcut" >
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionRecenter" >
<property name="icon" >
<iconset resource="../icons/Input.qrc" >
<action name="actionRecenter">
<property name="icon">
<iconset resource="../icons/Input.qrc">
<normaloff>:/cgal/Input/zoom-best-fit</normaloff>:/cgal/Input/zoom-best-fit</iconset>
</property>
<property name="text" >
<property name="text">
<string>Re&amp;center the viewport</string>
</property>
<property name="shortcut" >
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionYMonotonePartition" >
<property name="text" >
<action name="actionYMonotonePartition">
<property name="text">
<string>Y-monotone Partition</string>
</property>
</action>
<action name="actionCreateInputPolygon" >
<property name="checkable" >
<action name="actionCreateInputPolygon">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text" >
<property name="text">
<string>Create Input Polygon</string>
</property>
</action>
<action name="actionInnerSkeleton" >
<property name="text" >
<action name="actionInnerSkeleton">
<property name="text">
<string>Inner Skeleton</string>
</property>
</action>
<action name="actionOuterOffset" >
<property name="text" >
<action name="actionOuterOffset">
<property name="text">
<string>Outer Offset</string>
</property>
</action>
<action name="actionOptimalConvexPartition" >
<property name="text" >
<action name="actionOptimalConvexPartition">
<property name="text">
<string>Optimal Convex Partition</string>
</property>
</action>
<action name="actionApproximateConvexPartition" >
<property name="text" >
<action name="actionApproximateConvexPartition">
<property name="text">
<string>Approximate Convex Partition</string>
</property>
</action>
<action name="actionLinearLeastSquaresFitting" >
<property name="text" >
<action name="actionLinearLeastSquaresFitting">
<property name="text">
<string>Linear Least Squares Fitting of Points</string>
</property>
</action>
<action name="actionLinearLeastSquaresFittingOfSegments" >
<property name="text" >
<action name="actionLinearLeastSquaresFittingOfSegments">
<property name="text">
<string>Linear Least Squares Fitting of Segments</string>
</property>
</action>
<action name="actionMaximumAreaKGon">
<property name="text">
<string>Maximum Area K-gon</string>
</property>
</action>
</widget>
<resources>
<include location="Polygon_2.qrc" />
<include location="../icons/File.qrc" />
<include location="../resources/CGAL.qrc" />
<include location="../icons/Input.qrc" />
<include location="Polygon_2.qrc"/>
<include location="../icons/File.qrc"/>
<include location="../resources/CGAL.qrc"/>
<include location="../icons/Input.qrc"/>
</resources>
<connections/>
</ui>