mirror of https://github.com/CGAL/cgal
Add max area k-gon
This commit is contained in:
parent
aed79e77ce
commit
818e9909f6
|
|
@ -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,6 +120,11 @@ 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));
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<author>GeometryFactory</author>
|
<author>GeometryFactory</author>
|
||||||
<class>Polygon_2</class>
|
<class>Polygon_2</class>
|
||||||
|
|
@ -26,7 +27,7 @@
|
||||||
</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>
|
||||||
|
|
@ -81,7 +82,7 @@
|
||||||
<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">
|
||||||
|
|
@ -108,6 +109,7 @@
|
||||||
<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"/>
|
||||||
|
|
@ -221,6 +223,11 @@
|
||||||
<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"/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue