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_straight_skeleton_2.h>
#include<CGAL/create_offset_polygons_2.h> #include<CGAL/create_offset_polygons_2.h>
#include <CGAL/linear_least_squares_fitting_2.h> #include <CGAL/linear_least_squares_fitting_2.h>
#include <CGAL/extremal_polygon_2.h>
// Qt headers // Qt headers
#include <QtGui> #include <QtGui>
@ -52,7 +53,7 @@ private:
CGAL::Qt::Converter<K> convert; CGAL::Qt::Converter<K> convert;
Polygon poly; Polygon poly, kgon;
QGraphicsScene scene; QGraphicsScene scene;
CGAL::Qt::PolygonGraphicsItem<Polygon> * pgi; CGAL::Qt::PolygonGraphicsItem<Polygon> * pgi;
@ -65,6 +66,8 @@ private:
std::list<QGraphicsLineItem* > offsetGraphicsItems; std::list<QGraphicsLineItem* > offsetGraphicsItems;
CGAL::Qt::LineGraphicsItem<K>* lgi; CGAL::Qt::LineGraphicsItem<K>* lgi;
CGAL::Qt::PolygonGraphicsItem<Polygon> * kgongi;
public: public:
MainWindow(); MainWindow();
@ -78,6 +81,7 @@ public slots:
void on_actionSavePolygon_triggered(); void on_actionSavePolygon_triggered();
void on_actionRecenter_triggered(); void on_actionRecenter_triggered();
void on_actionMaximumAreaKGon_triggered();
void on_actionInnerSkeleton_triggered(); void on_actionInnerSkeleton_triggered();
void on_actionOuterOffset_triggered(); void on_actionOuterOffset_triggered();
void on_actionLinearLeastSquaresFitting_triggered(); void on_actionLinearLeastSquaresFitting_triggered();
@ -116,7 +120,12 @@ MainWindow::MainWindow()
pgi->setVerticesPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); pgi->setVerticesPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
scene.addItem(pgi); 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 = new CGAL::Qt::LineGraphicsItem<K>();
lgi->setPen(QPen(Qt::blue, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); lgi->setPen(QPen(Qt::blue, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
lgi->hide(); 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 void
MainWindow::on_actionLinearLeastSquaresFitting_triggered() MainWindow::on_actionLinearLeastSquaresFitting_triggered()
{ {
@ -484,6 +512,7 @@ MainWindow::clear()
clearSkeleton(); clearSkeleton();
clearOffset(); clearOffset();
lgi->hide(); 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> <author>GeometryFactory</author>
<class>Polygon_2</class> <class>Polygon_2</class>
<widget class="QMainWindow" name="Polygon_2" > <widget class="QMainWindow" name="Polygon_2">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -10,37 +11,37 @@
<height>325</height> <height>325</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>CGAL 2D Polygon</string> <string>CGAL 2D Polygon</string>
</property> </property>
<property name="windowIcon" > <property name="windowIcon">
<iconset resource="../resources/CGAL.qrc" > <iconset resource="../resources/CGAL.qrc">
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset> <normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
</property> </property>
<widget class="QWidget" name="centralwidget" > <widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" > <layout class="QHBoxLayout">
<item> <item>
<widget class="QSplitter" name="splitter" > <widget class="QSplitter" name="splitter">
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QGraphicsView" name="graphicsView" > <widget class="QGraphicsView" name="graphicsView">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" > <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch> <horstretch>2</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy" > <property name="focusPolicy">
<enum>Qt::StrongFocus</enum> <enum>Qt::StrongFocus</enum>
</property> </property>
<property name="verticalScrollBarPolicy" > <property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum> <enum>Qt::ScrollBarAlwaysOn</enum>
</property> </property>
<property name="horizontalScrollBarPolicy" > <property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum> <enum>Qt::ScrollBarAlwaysOn</enum>
</property> </property>
<property name="transformationAnchor" > <property name="transformationAnchor">
<enum>QGraphicsView::NoAnchor</enum> <enum>QGraphicsView::NoAnchor</enum>
</property> </property>
</widget> </widget>
@ -48,185 +49,191 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QStatusBar" name="statusbar" /> <widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="fileToolBar" > <widget class="QToolBar" name="fileToolBar">
<property name="windowTitle" > <property name="windowTitle">
<string>File Tools</string> <string>File Tools</string>
</property> </property>
<attribute name="toolBarArea" > <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
</attribute> </attribute>
<attribute name="toolBarBreak" > <attribute name="toolBarBreak">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionClear" /> <addaction name="actionClear"/>
<addaction name="actionLoadPolygon" /> <addaction name="actionLoadPolygon"/>
<addaction name="actionSavePolygon" /> <addaction name="actionSavePolygon"/>
</widget> </widget>
<widget class="QToolBar" name="toolBar" > <widget class="QToolBar" name="toolBar">
<property name="windowTitle" > <property name="windowTitle">
<string>Visualization Tools</string> <string>Visualization Tools</string>
</property> </property>
<attribute name="toolBarArea" > <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
</attribute> </attribute>
<attribute name="toolBarBreak" > <attribute name="toolBarBreak">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionRecenter" /> <addaction name="actionRecenter"/>
</widget> </widget>
<widget class="QMenuBar" name="menubar" > <widget class="QMenuBar" name="menubar">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>568</width> <width>568</width>
<height>19</height> <height>26</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile" > <widget class="QMenu" name="menuFile">
<property name="title" > <property name="title">
<string>&amp;File</string> <string>&amp;File</string>
</property> </property>
<addaction name="separator" /> <addaction name="separator"/>
<addaction name="actionClear" /> <addaction name="actionClear"/>
<addaction name="actionLoadPolygon" /> <addaction name="actionLoadPolygon"/>
<addaction name="actionSavePolygon" /> <addaction name="actionSavePolygon"/>
<addaction name="separator" /> <addaction name="separator"/>
<addaction name="actionQuit" /> <addaction name="actionQuit"/>
</widget> </widget>
<widget class="QMenu" name="menuTools" > <widget class="QMenu" name="menuTools">
<property name="title" > <property name="title">
<string>&amp;Algorithms</string> <string>&amp;Algorithms</string>
</property> </property>
<addaction name="separator" /> <addaction name="separator"/>
<addaction name="actionRecenter" /> <addaction name="actionRecenter"/>
<addaction name="actionYMonotonePartition" /> <addaction name="actionYMonotonePartition"/>
<addaction name="actionApproximateConvexPartition" /> <addaction name="actionApproximateConvexPartition"/>
<addaction name="actionOptimalConvexPartition" /> <addaction name="actionOptimalConvexPartition"/>
<addaction name="actionInnerSkeleton" /> <addaction name="actionInnerSkeleton"/>
<addaction name="actionOuterOffset" /> <addaction name="actionOuterOffset"/>
<addaction name="actionLinearLeastSquaresFitting" /> <addaction name="actionLinearLeastSquaresFitting"/>
<addaction name="actionLinearLeastSquaresFittingOfSegments" /> <addaction name="actionLinearLeastSquaresFittingOfSegments"/>
<addaction name="actionMaximumAreaKGon"/>
</widget> </widget>
<addaction name="menuFile" /> <addaction name="menuFile"/>
<addaction name="menuTools" /> <addaction name="menuTools"/>
</widget> </widget>
<action name="actionAbout" > <action name="actionAbout">
<property name="text" > <property name="text">
<string>&amp;About</string> <string>&amp;About</string>
</property> </property>
</action> </action>
<action name="actionAboutCGAL" > <action name="actionAboutCGAL">
<property name="text" > <property name="text">
<string>About &amp;CGAL</string> <string>About &amp;CGAL</string>
</property> </property>
</action> </action>
<action name="actionQuit" > <action name="actionQuit">
<property name="text" > <property name="text">
<string>&amp;Quit</string> <string>&amp;Quit</string>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+Q</string> <string>Ctrl+Q</string>
</property> </property>
</action> </action>
<action name="actionClear" > <action name="actionClear">
<property name="icon" > <property name="icon">
<iconset resource="../icons/File.qrc" > <iconset resource="../icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileNew.png</normaloff>:/cgal/fileToolbar/fileNew.png</iconset> <normaloff>:/cgal/fileToolbar/fileNew.png</normaloff>:/cgal/fileToolbar/fileNew.png</iconset>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Clear</string> <string>&amp;Clear</string>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+C</string> <string>Ctrl+C</string>
</property> </property>
</action> </action>
<action name="actionLoadPolygon" > <action name="actionLoadPolygon">
<property name="icon" > <property name="icon">
<iconset resource="../icons/File.qrc" > <iconset resource="../icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileOpen.png</normaloff>:/cgal/fileToolbar/fileOpen.png</iconset> <normaloff>:/cgal/fileToolbar/fileOpen.png</normaloff>:/cgal/fileToolbar/fileOpen.png</iconset>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Load Polygon</string> <string>&amp;Load Polygon</string>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+L</string> <string>Ctrl+L</string>
</property> </property>
</action> </action>
<action name="actionSavePolygon" > <action name="actionSavePolygon">
<property name="icon" > <property name="icon">
<iconset resource="../icons/File.qrc" > <iconset resource="../icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileSave.png</normaloff>:/cgal/fileToolbar/fileSave.png</iconset> <normaloff>:/cgal/fileToolbar/fileSave.png</normaloff>:/cgal/fileToolbar/fileSave.png</iconset>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Save Polygon</string> <string>&amp;Save Polygon</string>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+S</string> <string>Ctrl+S</string>
</property> </property>
</action> </action>
<action name="actionRecenter" > <action name="actionRecenter">
<property name="icon" > <property name="icon">
<iconset resource="../icons/Input.qrc" > <iconset resource="../icons/Input.qrc">
<normaloff>:/cgal/Input/zoom-best-fit</normaloff>:/cgal/Input/zoom-best-fit</iconset> <normaloff>:/cgal/Input/zoom-best-fit</normaloff>:/cgal/Input/zoom-best-fit</iconset>
</property> </property>
<property name="text" > <property name="text">
<string>Re&amp;center the viewport</string> <string>Re&amp;center the viewport</string>
</property> </property>
<property name="shortcut" > <property name="shortcut">
<string>Ctrl+R</string> <string>Ctrl+R</string>
</property> </property>
</action> </action>
<action name="actionYMonotonePartition" > <action name="actionYMonotonePartition">
<property name="text" > <property name="text">
<string>Y-monotone Partition</string> <string>Y-monotone Partition</string>
</property> </property>
</action> </action>
<action name="actionCreateInputPolygon" > <action name="actionCreateInputPolygon">
<property name="checkable" > <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="text" > <property name="text">
<string>Create Input Polygon</string> <string>Create Input Polygon</string>
</property> </property>
</action> </action>
<action name="actionInnerSkeleton" > <action name="actionInnerSkeleton">
<property name="text" > <property name="text">
<string>Inner Skeleton</string> <string>Inner Skeleton</string>
</property> </property>
</action> </action>
<action name="actionOuterOffset" > <action name="actionOuterOffset">
<property name="text" > <property name="text">
<string>Outer Offset</string> <string>Outer Offset</string>
</property> </property>
</action> </action>
<action name="actionOptimalConvexPartition" > <action name="actionOptimalConvexPartition">
<property name="text" > <property name="text">
<string>Optimal Convex Partition</string> <string>Optimal Convex Partition</string>
</property> </property>
</action> </action>
<action name="actionApproximateConvexPartition" > <action name="actionApproximateConvexPartition">
<property name="text" > <property name="text">
<string>Approximate Convex Partition</string> <string>Approximate Convex Partition</string>
</property> </property>
</action> </action>
<action name="actionLinearLeastSquaresFitting" > <action name="actionLinearLeastSquaresFitting">
<property name="text" > <property name="text">
<string>Linear Least Squares Fitting of Points</string> <string>Linear Least Squares Fitting of Points</string>
</property> </property>
</action> </action>
<action name="actionLinearLeastSquaresFittingOfSegments" > <action name="actionLinearLeastSquaresFittingOfSegments">
<property name="text" > <property name="text">
<string>Linear Least Squares Fitting of Segments</string> <string>Linear Least Squares Fitting of Segments</string>
</property> </property>
</action> </action>
<action name="actionMaximumAreaKGon">
<property name="text">
<string>Maximum Area K-gon</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="Polygon_2.qrc" /> <include location="Polygon_2.qrc"/>
<include location="../icons/File.qrc" /> <include location="../icons/File.qrc"/>
<include location="../resources/CGAL.qrc" /> <include location="../resources/CGAL.qrc"/>
<include location="../icons/Input.qrc" /> <include location="../icons/Input.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>