Added method CheckLoops for finding loops in equidistant. Can find loops and delete them.

This commit is contained in:
dismine 2013-09-17 20:11:43 +03:00
parent 2edb62eb9b
commit ba1433e83f
5 changed files with 49 additions and 14 deletions

View File

@ -258,7 +258,7 @@ QPainterPath VContainer::ContourPath(qint64 idDetail) const{
} }
break; break;
default: default:
qWarning()<<"Get wrong tool type. Ignore."; qWarning()<<"Get wrong tool type. Ignore."<<detail[i].getTypeTool();
break; break;
} }
} }
@ -315,6 +315,7 @@ QPainterPath VContainer::Equidistant(QVector<QPointF> points, const Detail::Equi
//точка яка не лежить ні на початку ні в кінці //точка яка не лежить ні на початку ні в кінці
ekvPoints<<EkvPoint(QLineF(points[i-1], points[i]), QLineF(points[i+1], points[i]), width); ekvPoints<<EkvPoint(QLineF(points[i-1], points[i]), QLineF(points[i+1], points[i]), width);
} }
ekvPoints = CheckLoops(ekvPoints);
ekv.moveTo(ekvPoints[0]); ekv.moveTo(ekvPoints[0]);
for (qint32 i = 1; i < ekvPoints.count(); ++i){ for (qint32 i = 1; i < ekvPoints.count(); ++i){
ekv.lineTo(ekvPoints[i]); ekv.lineTo(ekvPoints[i]);
@ -378,6 +379,52 @@ QVector<QPointF> VContainer::EkvPoint(const QLineF &line1, const QLineF &line2,
return points; return points;
} }
QVector<QPointF> VContainer::CheckLoops(const QVector<QPointF> &points) const{
QVector<QPointF> ekvPoints;
/*If we got less than 4 points no need seek loops.*/
if(points.size() < 4){
return ekvPoints;
}
bool closed = false;
if(points.at(0) == points.at(points.size()-1)){
closed = true;
}
qint32 i, j;
for(i = 0; i < points.size(); ++i){
/*Last three points no need check.*/
if(i >= points.size()-3){
ekvPoints.append(points.at(i));
continue;
}
QPointF crosPoint;
QLineF::IntersectType intersect = QLineF::NoIntersection;
QLineF line1(points.at(i),points.at(i+1));
for(j = i+2; j < points.size()-1; ++j){
QLineF line2(points.at(j),points.at(j+1));
intersect = line1.intersect(line2, &crosPoint);
if(intersect == QLineF::BoundedIntersection){
break;
}
}
if(intersect == QLineF::BoundedIntersection){
if(i == 0 && j+1 == points.size()-1 && closed){
/*We got closed contour.*/
ekvPoints.append(points.at(i));
} else {
/*We found loop.*/
ekvPoints.append(points.at(i));
ekvPoints.append(crosPoint);
ekvPoints.append(points.at(j+1));
i = j + 2;
}
} else {
/*We did not found loop.*/
ekvPoints.append(points.at(i));
}
}
return ekvPoints;
}
void VContainer::PrepareDetails(QVector<VItem *> &list) const{ void VContainer::PrepareDetails(QVector<VItem *> &list) const{
QMapIterator<qint64, VDetail> iDetail(details); QMapIterator<qint64, VDetail> iDetail(details);
while (iDetail.hasNext()) { while (iDetail.hasNext()) {

View File

@ -127,6 +127,7 @@ public:
static QLineF ParallelLine(const QLineF &line, qreal width ); static QLineF ParallelLine(const QLineF &line, qreal width );
static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width); static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width);
QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width)const; QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width)const;
QVector<QPointF> CheckLoops(const QVector<QPointF> &points) const;
void PrepareDetails(QVector<VItem*> & list)const; void PrepareDetails(QVector<VItem*> & list)const;
private: private:
static qint64 _id; static qint64 _id;

View File

@ -4,7 +4,6 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include "options.h" #include "options.h"
class VMainGraphicsScene : public QGraphicsScene class VMainGraphicsScene : public QGraphicsScene

View File

@ -1,13 +1,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
#include "vmaingraphicsview.h" #include "vmaingraphicsview.h"
#include <QApplication> #include <QApplication>
#include <QWheelEvent> #include <QWheelEvent>
#include <QScrollBar> #include <QScrollBar>
#pragma GCC diagnostic pop
VMainGraphicsView::VMainGraphicsView(QWidget *parent) : VMainGraphicsView::VMainGraphicsView(QWidget *parent) :
QGraphicsView(parent){ QGraphicsView(parent){

View File

@ -1,13 +1,7 @@
#ifndef VMAINGRAPHICSVIEW_H #ifndef VMAINGRAPHICSVIEW_H
#define VMAINGRAPHICSVIEW_H #define VMAINGRAPHICSVIEW_H
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
#include <QGraphicsView> #include <QGraphicsView>
#pragma GCC diagnostic pop
class VMainGraphicsView : public QGraphicsView class VMainGraphicsView : public QGraphicsView
{ {