1. 完善了轮廓和断层

2. 新增位图,圆形,矩形,比例尺的雏形
main
abc 1 month ago
parent 1486954791
commit 9f2976be43

27
aoi.h

@ -1,27 +0,0 @@
#ifndef AOI_H
#define AOI_H
//
#include "basicgeometryoperator.h"
#include "contour.h"
//std
#include <unordered_map>
#include <vector>
//Qt
#include <QColor>
#include <QLineF>
class aoi : public BasicGeometryOperator
{
public:
aoi();
private:
// Outline outline;
};
#endif // AOI_H

@ -1,36 +0,0 @@
#ifndef BASICGEOMETRY_H
#define BASICGEOMETRY_H
class BasicGeometry
{
public:
BasicGeometry();
virtual void set_color(int red,int green, int blue)=0;
virtual void set_unit(QString unit)=0;
virtual void set_move(bool isMove)=0;
// points
virtual void add_points(int x,int y)=0;
virtual int get_point_id()=0;
virtual void remove_by_id()=0;// 删除一个点之后,是否遍历拓扑表删除和这个点相关的所有数据
// topology
virtual void add_topology()=0;
virtual int get_topology_id()=0;
virtual void remove_by_id()=0;
// rgb
virtual int red()=0;
virtual int green()=0;
virtual int blue()=0;
virtual QString unit()=0;
virtual bool isMove()=0;
};
#endif // BASICGEOMETRY_H

@ -1,14 +0,0 @@
#ifndef BASICGEOMETRYOPERATOR_H
#define BASICGEOMETRYOPERATOR_H
class BasicGeometryOperator
{
public:
virtual void paint()=0;
virtual void saveData()=0;
virtual void pick()=0;// 点、线、单元,区域 四种拾取
virtual void move()=0;
};
#endif // BASICGEOMETRYOPERATOR_H

@ -0,0 +1,122 @@
#ifndef BITMAP_H
#define BITMAP_H
//Qt
#include <QColor>
#include <QPainter>
#include <QPainterPath>
#include <QPaintEvent>
#include <QVector>
#include <QPainterPathStroker>
#include <QPen>
#include <QWidget>
#include <QPaintEngine>
#include <QPoint>
#include <QBitmap>
#include <QPixmap>
#include <QDebug>
#include <QIODevice>
#include <QDir>
#include <QCursor>
class Bitmap
{
public:
Bitmap(const QPoint& topLeft,const QPoint& bottomRight,QString fileName=nullptr){
_topLeft = topLeft;
_bottomRight = bottomRight;
_scaley = 1;
_scalex = 1;
// TODO 需要加入文件检测判断文件是否存在
_pixmap = QPixmap(fileName);
}
Bitmap(){
_scaley = 1;
_scalex = 1;
_pixmap = QPixmap();
}
void paint(QPixmap& w, QPaintEvent *event=nullptr){
QPainter painter;
painter.begin(&w);
QPoint center = QPoint((_topLeft.x()+_bottomRight.x())/2/_scalex,(_topLeft.y()+_bottomRight.y())/2/_scaley);
QPixmap p;
center -= QPoint(_pixmap.width()/2,_pixmap.height()/2);
painter.scale(_scalex,_scaley);
painter.drawPixmap(center,_pixmap);
painter.end();
}
QPoint topLeft() const
{
return _topLeft;
}
void setTopLeft(const QPoint &topLeft)
{
_topLeft = topLeft;
}
QPoint bottomRight() const
{
return _bottomRight;
}
void setBottomRight(const QPoint &bottomRight)
{
_bottomRight = bottomRight;
}
double scalex() const
{
return _scalex;
}
void setScalex(double scalex)
{
_scalex = scalex;
}
double scaley() const
{
return _scaley;
}
void setScaley(double scaley)
{
_scaley = scaley;
}
QPixmap getPixmap() const
{
return _pixmap;
}
void setPixmap(const QPixmap &value)
{
_pixmap = value;
}
void setPixmap(const QString& fileName)
{
_pixmap = QPixmap(fileName);;
}
private:
QPixmap _pixmap;
QPoint _topLeft;
QPoint _bottomRight;
QColor _scaleColor;
// 缩放
double _scalex;
double _scaley;
};
#endif // BITMAP_H

@ -0,0 +1,84 @@
#ifndef CIRCULAR_H
#define CIRCULAR_H
//Qt
#include <QColor>
#include <QPainter>
#include <QPainterPath>
#include <QPaintEvent>
#include <QVector>
#include <QPainterPathStroker>
#include <QPen>
#include <QWidget>
#include <QPaintEngine>
#include <QPoint>
#include <QRect>
#include <QThread>
class Circular
{
public:
Circular(){
_scalex = 1;
_scaley = 1;
}
Circular(const QPointF& center){
_center = center;
_scalex = 1;
_scaley = 1;
}
void paint(QPixmap& w, QPaintEvent* event=nullptr){
QPainter painter;
painter.begin(&w);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.scale(_scalex,_scaley);
painter.setPen(QPen(Qt::black, 0.8));
painter.drawEllipse(_center,_radius,_radius);
painter.end();
}
QPointF center() const
{
return _center;
}
void setCenter(const QPointF &center)
{
_center = center;
}
QColor color() const
{
return _color;
}
void setColor(const QColor &color)
{
_color = color;
}
double radius() const
{
return _radius;
}
void setRadius(double radius)
{
_radius = radius;
}
private:
QPointF _center;
double _radius;
double _scalex;
double _scaley;
QColor _color;
};
#endif // CIRCULAR_H

@ -1,9 +1,6 @@
#ifndef OUTLINE_H
#define OUTLINE_H
//
#include "basicgeometryoperator.h"
//Qt
#include <QDebug>
@ -17,23 +14,27 @@
#include <QWidget>
#include <QPaintEngine>
#include <qmath.h>
#define d(x) qDebug()<<__FUNCTION__<<(x)
#include <QPixmap>
class Contour
{
public:
Contour(double scalex,double scaley,bool bmove,double tolerance, QString title = "Fault_0"):_scalex(scalex),_scaley(scaley),
_move(bmove),_tolerance(tolerance){
Contour(double scalex,double scaley,bool bmove,double tolerance, const QString& title){
_title = title;
_painter = new QPainter();
_scalex = scalex;
_scaley = scaley;
_move = bmove;
_tolerance = tolerance;
}
Contour(QString title = "contour_0"):_scalex(1),_scaley(1),
_move(false),_tolerance(15){
Contour(QString title = "contour_0"){
_title = title;
_painter = new QPainter();
_scalex = 1;
_scaley = 1;
_move = false;
_tolerance = 10;
}
~Contour(){}
void addPoint(qreal x,qreal y){
QPointF f(x,y);
@ -53,8 +54,6 @@ public:
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
if(lineSegmentsIntersect(_points[j],_points[(j+1)%n],_points[i],_points[(i+1)%n])){
qDebug()<<"intersect"<<_points[j]<<_points[(j+1)%n]<<_points[i]<<_points[(i+1)%n];
qDebug()<<j<<(j+1)%n<<i<<(i+1)%n;
return true;
}
}
@ -63,28 +62,18 @@ public:
}
bool lineSegmentsIntersect(const QPointF& a, const QPointF& b, const QPointF& c, const QPointF& d) {
qreal abx = b.x() - a.x();
qreal aby = b.y() - a.y();
qreal cdx = d.x() - c.x();
qreal cdy = d.y() - c.y();
qreal acx = c.x() - a.x();
qreal acy = c.y() - a.y();
QPointF ab = b-a;
QPointF cd = d-c;
QPointF ac = c-a;
QPointF ad = d-a;
QPointF ca = a-c;
QPointF cb = b-c;
qreal adx = d.x() - a.x();
qreal ady = d.y() - a.y();
qreal abac = ab.x()*ac.y()-ab.y()*ac.x();
qreal abad = ab.x()*ad.y()-ab.y()*ad.x();
qreal cdca = cd.x()*ca.y()-cd.y()*ca.x();
qreal cdcb = cd.x()*cb.y()-cd.y()*cb.x();
qreal cax = a.x() - c.x();
qreal cay = a.y() - c.y();
qreal cbx = b.x() - c.x();
qreal cby = b.y() - c.y();
qreal abac = abx*acy-acx*aby;
qreal abad = abx*ady-adx*aby;
qreal cdca = cdx*cay-cdy*cax;
qreal cdcb = cdx*cby-cdy*cbx;
return !(abac*abad >=0 || cdca*cdcb >=0);
}
@ -100,39 +89,10 @@ public:
_points[i] = f;
_points[_rectPath.elementCount()-1] = f;
}
setDotline();
getDotline();
}
}
bool isInside(const QPointF& a){
int n = _points.count();
for(int i=1;i<n-2;++i){
QPointF p1 = a - _points[i];
QPointF p2 = _points[i+1]-_points[i];
QPointF p3 = _points[i-1] - _points[i];
qreal abac = p1.x()*p2.y() - p1.y()*p2.x();
qreal abad = p1.x()*p3.y() - p1.y()*p3.x();
if(abac*abad <=0){
return true;
}
}
return false;
}
bool isInLine(const QPointF& a){
int n = _points.count();
for(int i=0;i<n-2;++i){
QPointF p1 = a - _points[i];
QPointF p2 = _points[i+1]-_points[i];
if(qAbs(p1.x()*p2.y()-p1.y()*p2.x())< 1000){
if(a.x()<=qMax(_points[i].x(),_points[i+1].x()) && a.x()>=qMin(_points[i].x(),_points[i+1].x())){
return true;
}
}
}
return false;
}
int pointCount(){
return _points.count();
}
@ -153,7 +113,7 @@ public:
return _title;
}
void setTitle(QString title){
void setTitle(const QString& title){
_title = title;
}
@ -195,7 +155,7 @@ public:
_rectPath.addPath(rectPath);
}
QVector<QPointF> getPoints() const
QVector<QPointF> Points() const
{
return _points;
}
@ -228,7 +188,7 @@ public:
_rectPath.addPolygon(_points);
_rectPath.closeSubpath();
_rectPath.setFillRule(Qt::OddEvenFill);
setDotline();
getDotline();
}
@ -258,7 +218,7 @@ public:
last = f;
}
void setDotline(){
void getDotline(){
QPainterPathStroker stroker;
stroker.setCapStyle(Qt::RoundCap);
stroker.setDashPattern(Qt::DashLine);
@ -301,28 +261,29 @@ public:
}
void paint(QWidget *w, QPaintEvent *event){
_painter->begin(w);
_painter->scale(_scalex, _scaley);
_painter->setRenderHint(QPainter::Antialiasing);
void paint(QPixmap& w, QPaintEvent *event=nullptr){
QPainter painter;
painter.begin(&w);
painter.scale(_scalex, _scaley);
painter.setRenderHint(QPainter::Antialiasing);
pen.setColor(_contourColor);
pen.setWidth(2);
_painter->setPen(pen);
_painter->setBrush(_contourColor);
painter.setPen(pen);
painter.setBrush(_contourColor);
int n = _points.count();
if(_move){
_painter->save();
painter.save();
for(int i=0;i<n;++i){
_painter->setPen(Qt::NoPen);
_painter->setBrush(_contourColor);
_painter->drawEllipse(QPointF(_rectPath.elementAt(i).x,_rectPath.elementAt(i).y),5,5);
painter.setPen(Qt::NoPen);
painter.setBrush(_contourColor);
painter.drawEllipse(QPointF(_rectPath.elementAt(i).x,_rectPath.elementAt(i).y),5,5);
}
_painter->restore();
_painter->drawPath(_dotPath);
painter.restore();
painter.drawPath(_dotPath);
}else{
_painter->drawPath(_rectPath);
painter.drawPath(_rectPath);
}
_painter->end();
painter.end();
}
private:
@ -331,7 +292,6 @@ private:
// 记录标题比如contour_1
QString _title;
QVector<QPointF> _points;
QPainter *_painter;
QPointF last;

@ -1,8 +1,6 @@
#ifndef FAULT_H
#define FAULT_H
//
#include "basicgeometryoperator.h"
//Qt
@ -15,22 +13,27 @@
#include <QPen>
#include <QWidget>
#include <QPaintEngine>
#include <QPixmap>
class Fault
{
public:
Fault(double scalex,double scaley,bool bmove,double tolerance, QString title = "Fault_0"):_scalex(scalex),_scaley(scaley),
_move(bmove),_tolerance(tolerance){
Fault(double scalex,double scaley,bool bmove,double tolerance, const QString& title){
_title = title;
_isGenerated = false;
_painter = new QPainter();
_scalex = scalex;
_scaley = scaley;
_move = bmove;
_tolerance = tolerance;
}
Fault(QString title = "Fault_0"):_scalex(1),_scaley(1),
_move(false),_tolerance(30){
Fault(QString title = "Fault_0"){
_scalex = 1;
_scaley = 1;
_title = title;
_isGenerated = false;
_painter = new QPainter();
_tolerance = 15;
_move = false;
}
~Fault(){
@ -51,7 +54,7 @@ public:
_points[i] = QPointF(x,y);
if(_move){
setDotline();
getDotline();
setTitle(_title);
}
}
@ -161,6 +164,8 @@ public:
_titlePath.addText(_rectPath.elementAt(_rectPath.elementCount()-1).x+1,
_rectPath.elementAt(_rectPath.elementCount()-1).y+1,
QFont(),_title);
getDotline();
}
void move(QMouseEvent *event){
@ -186,7 +191,7 @@ public:
void pick(QMouseEvent* event){
QPointF f = event->posF();
setDotline();
getDotline();
if(!contains(f)){
return;
}
@ -194,12 +199,12 @@ public:
last = f;
}
void setDotline(){
void getDotline(){
QPainterPathStroker stroker;
stroker.setCapStyle(Qt::RoundCap);
stroker.setDashPattern(Qt::DashLine);
stroker.setJoinStyle(Qt::RoundJoin);
stroker.setWidth(2);
stroker.setWidth(1);
_dotPath = stroker.createStroke(_rectPath);
}
@ -208,8 +213,6 @@ public:
}
bool contains(const QPointF& f){
qreal x = f.x();
qreal y = f.y();
for(int i=0;i<=_tolerance;++i){
if(_dotPath.contains(f+QPointF(i,0))||
_dotPath.contains(f+QPointF(-i,0))||
@ -239,30 +242,31 @@ public:
return -1;
}
void paint(QWidget *w, QPaintEvent *event){
_painter->begin(w);
_painter->scale(_scalex, _scaley);
_painter->setRenderHint(QPainter::Antialiasing);
void paint(QPixmap& w, QPaintEvent *event=nullptr){
QPainter painter;
painter.begin(&w);
painter.scale(_scalex, _scaley);
painter.setRenderHint(QPainter::Antialiasing);
QPen pen;
pen.setWidth(2);
pen.setColor(_faultColor);
_painter->setPen(pen);
painter.setPen(pen);
int n = _points.count();
if(_move){
for(int i=0;i<n;++i){
_painter->drawEllipse(QPointF(_rectPath.elementAt(i).x,_rectPath.elementAt(i).y),3,3);
painter.drawEllipse(QPointF(_rectPath.elementAt(i).x,_rectPath.elementAt(i).y),3,3);
}
_painter->drawPath(_dotPath);
painter.drawPath(_dotPath);
}
else{
_painter->drawPath(_rectPath);
painter.drawPath(_rectPath);
}
if(_titlePath.elementCount()>0){
pen.setWidth(1);
_painter->setPen(pen);
_painter->drawPath(_titlePath);
painter.setPen(pen);
painter.drawPath(_titlePath);
}
_painter->end();
painter.end();
}
private:
@ -271,10 +275,9 @@ private:
// 记录标题比如fault_1
QString _title;
QVector<QPointF> _points;
QPainter *_painter;
// QPainter *_painter;
QPointF last;
QWidget *w;
// 缩放
double _scalex;

@ -2,20 +2,25 @@
#include "ui_mainwindow.h"
#include <QDebug>
#include <QResizeEvent>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setMouseTracking(true);
ui->centralWidget->setMouseTracking(true);
rectPath.moveTo(20.0, 30.0);
rectPath.lineTo(80.0, 30.0);
rectPath.lineTo(80.0, 70.0);
rectPath.lineTo(20.0, 70.0);
scalex = 1;
scaley = 1;
this->setMouseTracking(true);
this->showMaximized();
QPoint p1(100,70);
const QRect& r = this->geometry();
initWidth = r.width();
initHeight = r.height();
QPoint p2(r.width()-100,r.height()-70);
scale = Scale(5,8,4000,3000,p1,p2);
bitmap = Bitmap(p1,p2);
scaleCount = 8;
}
MainWindow::~MainWindow()
@ -24,26 +29,35 @@ MainWindow::~MainWindow()
}
void MainWindow::mousePressEvent(QMouseEvent *event){
for(int i=0;i<vf.size();++i){
Fault&f = vf[i];
if(!f.isGenerated()){
continue;
}
if(f.contains(event->posF())){
isPressed = true;
iPoint = f.dotContains(event->posF());
}else if(c.contains(event->posF())){
isPressed = true;
iPoint = c.dotContains(event->posF());
}
if(event->button()==Qt::RightButton){
f.setMove(false);
c.setMove(false);
}
if(ui->checkBox->checkState()==Qt::Unchecked && event->button()==Qt::LeftButton){
f.pick(event);
if(ui->checkBox4->checkState()==Qt::Checked && event->button()==Qt::LeftButton){
rect.setTopLeft(event->pos());
}
if(ui->checkBox3->checkState()==Qt::Checked && event->button()==Qt::LeftButton){
circular.setCenter(event->posF());
}
if(ui->checkBox->checkState()==Qt::Unchecked){
for(int i=0;i<vf.size();++i){
Fault&f = vf[i];
if(!f.isGenerated()){
continue;
}
if(!isPressed&&f.contains(event->posF())){
isPressed = true;
iPoint = f.dotContains(event->posF());
f.pick(event);
break;
}
if(event->button()==Qt::RightButton){
f.setMove(false);
}
}
}
if(event->button()==Qt::RightButton){
c.setMove(false);
}
if(ui->checkBox->checkState()==Qt::Checked){
// Fault 测试集
int n = f.elementCount();
@ -82,16 +96,65 @@ void MainWindow::mousePressEvent(QMouseEvent *event){
}
}
if(ui->checkBox2->checkState()==Qt::Unchecked && event->button()==Qt::LeftButton){
c.pick(event);
if(!isPressed&&c.contains(event->posF())){
isPressed = true;
iPoint = c.dotContains(event->posF());
c.pick(event);
}
}
if(event->button()==Qt::RightButton){
ui->checkBox4->setCheckState(Qt::Unchecked);
ui->checkBox3->setCheckState(Qt::Unchecked);
}
this->update();
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QPoint p1(100,70);
const QRect& r = this->geometry();
// sx = (double)event->size().width()/initWidth;
// sy = (double)event->size().height()/initHeight;
QPoint p2(r.width()-100,r.height()-70);
scale.setTopLeft(p1);
scale.setBottomRight(p2);
bitmap.setTopLeft(p1);
bitmap.setBottomRight(p2);
this->update();
}
void MainWindow::wheelEvent(QWheelEvent *event)
{
int d = event->delta();
if(d>0){
scaleCount+=2;
}else if(d<0){
scaleCount-=2;
}
scale.setScaleCount(qAbs(scaleCount)%24);
this->update();
}
void MainWindow::mouseReleaseEvent(QMouseEvent *event){
isPressed = false;
this->update();
}
void MainWindow::mouseMoveEvent(QMouseEvent *event){
if(ui->checkBox3->checkState()==Qt::Checked){
QPointF p = circular.center();
QPointF p2 = event->posF();
double r = qSqrt(qPow(p.x()-p2.x(), 2) + qPow(p.y()-p2.y(), 2));
circular.setRadius(r);
}
if(ui->checkBox4->checkState()==Qt::Checked){
rect.setBottomRight(event->pos());
}
if(ui->checkBox->checkState()==Qt::Checked){
int n = f.elementCount();
qreal x1 = event->posF().x();
@ -134,37 +197,21 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event){
}
void MainWindow::paintEvent(QPaintEvent *event){
c.paint(this,event);
f.paint(this,event);
QPixmap mp(size());
mp.fill(Qt::white);
scale.paint(mp,event);
bitmap.paint(mp,event);
c.paint(mp,event);
f.paint(mp,event);
for(int i=0;i<vf.size();++i){
vf[i].paint(this,event);
}
// scalex = this->width() / 100.0;
// scaley = this->height() / 100.0;
// painter.begin(this);
// painter.setRenderHint(QPainter::Antialiasing);
// painter.scale(scalex, scaley);
// QColor color(255,30,1);
// QPen pen;
// pen.setColor(color);
// painter.setPen(pen);
// int n = rectPath.elementCount();
// if(ismove){
// painter.save();
// for(int i=0;i<n;++i){
// painter.setPen(Qt::NoPen);
// painter.setBrush(color);
// painter.drawEllipse(QPointF(rectPath.elementAt(i).x,rectPath.elementAt(i).y),3,3);
// }
// painter.restore();
// painter.drawPath(outline);
// }
// else{
// painter.drawPath(rectPath);
// }
// painter.end();
vf[i].paint(mp,event);
}
circular.paint(mp,event);
rect.paint(mp,event);
QPainter painter(this);
// painter.scale(sx,sx);
painter.drawPixmap(0,0,mp);
}

@ -1,18 +1,28 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
// Qt
#include <QMainWindow>
#include "QtGui"
#include <QPainter>
#include <QPaintEvent>
#include <QPainter>
#include <QPainterPathStroker>
#include <QPen>
#include <QPixmap>
#include <QtConcurrentRun>
#include <functional>
#include <QFuture>
#include <QWheelEvent>
#include <qmath.h>
// oil
#include "fault.h"
#include "contour.h"
#include "scale.h"
#include "bitmap.h"
#include "circular.h"
#include "rectangle.h"
namespace Ui {
class MainWindow;
@ -31,23 +41,42 @@ private:
QPainterPath rectPath;
QPainterPath outline;
QPainter painter;
int x;
int y;
double scalex;
double scaley;
Contour c;
bool isPressed;
int iPoint;
QVector<Fault>vf;
Fault f;
Contour c;
Scale scale;
Bitmap bitmap;
Circular circular;
Rectangle rect;
QPixmap *mp;
int initWidth;
int initHeight;
int scaleCount;
// QWidget interface
protected:
void mouseReleaseEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
// QWidget interface
protected:
void resizeEvent(QResizeEvent *);
// QWidget interface
protected:
void wheelEvent(QWheelEvent *);
};
#endif // MAINWINDOW_H

@ -6,20 +6,42 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>482</height>
<width>1152</width>
<height>800</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>800</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QCheckBox" name="checkBox2">
<property name="geometry">
<rect>
<x>510</x>
<y>20</y>
<width>51</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>轮廓</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>220</x>
<y>10</y>
<width>79</width>
<x>340</x>
<y>20</y>
<width>51</width>
<height>18</height>
</rect>
</property>
@ -33,17 +55,30 @@
<bool>false</bool>
</property>
</widget>
<widget class="QCheckBox" name="checkBox2">
<widget class="QCheckBox" name="checkBox3">
<property name="geometry">
<rect>
<x>370</x>
<y>10</y>
<x>660</x>
<y>20</y>
<width>79</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>轮廓</string>
<string>圆形</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox4">
<property name="geometry">
<rect>
<x>800</x>
<y>20</y>
<width>79</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>矩形</string>
</property>
</widget>
</widget>
@ -61,7 +96,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<width>1152</width>
<height>26</height>
</rect>
</property>

@ -6,7 +6,7 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets concurrent
TARGET = oilpool
TEMPLATE = app
@ -25,17 +25,17 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp \
scalegraphicsview.cpp
mainwindow.cpp
HEADERS += \
mainwindow.h \
basicgeometry.h \
basicgeometryoperator.h \
fault.h \
aoi.h \
contour.h \
scalegraphicsview.h
scale.h \
bitmap.h \
circular.h \
rectangle.h
FORMS += \
mainwindow.ui

@ -0,0 +1,9 @@
1. 几何部分的 fault.h 和contour.h 完成度较高
2. contour.h 画轮廓
fault.h 画断层
bitmap.h 画位图
circular.h 画圆形
rectangle.h 画矩形
scale.h 画比例尺
mainwindow.h和mainwindow.cpp用于测试

@ -0,0 +1,106 @@
#ifndef RECTANGLE_H
#define RECTANGLE_H
//Qt
#include <QDebug>
#include <QColor>
#include <QPainter>
#include <QPainterPath>
#include <QPaintEvent>
#include <QVector>
#include <QPainterPathStroker>
#include <QPen>
#include <QWidget>
#include <QPaintEngine>
#include <qmath.h>
#include <QPixmap>
class Rectangle
{
public:
Rectangle(){
_scalex = 1;
_scaley = 1;
}
Rectangle(double scalex,double scaley){
_scalex = scalex;
_scaley = scaley;
}
void paint(QPixmap&mp, QPaintEvent *event = nullptr){
QPainter painter;
painter.begin(&mp);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.scale(_scalex,_scaley);
painter.setPen(QPen(Qt::black, 0.8));
QRect r(_topLeft,_bottomRight);
_rect = r;
painter.drawRect(_rect);
painter.end();
}
double scalex() const
{
return _scalex;
}
void setScalex(double scalex)
{
_scalex = scalex;
}
double scaley() const
{
return _scaley;
}
void setScaley(double scaley)
{
_scaley = scaley;
}
QPoint topLeft() const
{
return _topLeft;
}
void setTopLeft(const QPoint &topLeft)
{
_topLeft = topLeft;
}
QPoint bottomRight() const
{
return _bottomRight;
}
void setBottomRight(const QPoint &bottomRight)
{
_bottomRight = bottomRight;
}
QColor rectColor() const
{
return _rectColor;
}
void setRectColor(const QColor &rectColor)
{
_rectColor = rectColor;
}
private:
QPoint _topLeft;
QPoint _bottomRight;
QColor _rectColor;
double _scalex;
double _scaley;
QRect _rect;
};
#endif // RECTANGLE_H

@ -0,0 +1,196 @@
#ifndef SCALE_H
#define SCALE_H
//Qt
#include <QColor>
#include <QPainter>
#include <QPainterPath>
#include <QPaintEvent>
#include <QVector>
#include <QPainterPathStroker>
#include <QPen>
#include <QWidget>
#include <QPaintEngine>
#include <QPoint>
#include <QRect>
#include <QThread>
class Scale
{
public:
Scale(int scaleLength,int scaleCount,int width,int height,const QPoint& topleft,const QPoint& bottomright){
_scaleLength = scaleLength;
_scaleCount = scaleCount;
_topLeft = topleft;
_bottomRight = bottomright;
_scaleColor = QColor(192,192,192);
_scalex = 1;
_scaley = 1;
_width = width;
_height = height;
}
Scale(){
_scaleLength = 6;
_scaleCount = 8;
_topLeft = QPoint(90,90);
_bottomRight = QPoint(300,300);
_scaleColor = QColor(192,192,192);
_scalex = 1;
_scaley = 1;
_width = 0;
_height = 0;
}
void paint(QPixmap& w, QPaintEvent* event=nullptr){
_scaleCount = _scaleCount > 8? _scaleCount : 8;
QPainter painter;
painter.begin(&w);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.scale(_scalex,_scaley);
_rect = QRect(QPoint(_topLeft.x()/_scalex,_topLeft.y()/_scaley),QPoint(_bottomRight.x()/_scalex,_bottomRight.y()/_scaley));
painter.setPen(QPen(Qt::black, 0.8));
painter.setBrush(_scaleColor);
painter.drawRect(_rect);
int width = _rect.width();
int height = _rect.height();
int tmp = _scaleCount/2;
if(_width==0){
_width = width;
}
if(_height==0){
_height = height;
}
// 上
for (int i = 1; i < _scaleCount; ++i) {
int x = _rect.left() + (i * width / _scaleCount);
painter.drawLine(x, _rect.y(), x, _rect.y() - _scaleLength);
const QRect rectangle = QRect(QPoint(x-25, _rect.y()-50), QPoint(x+25, _rect.y()- _scaleLength));
painter.drawText(rectangle,Qt::AlignBottom,QString::number((i-tmp) * _width / _scaleCount));
}
// 下
for (int i = 1; i < _scaleCount; ++i) {
int x = _rect.left() + (i * width / _scaleCount);
painter.drawLine(x, _rect.y() + height, x, _rect.y() + height + _scaleLength);
const QRect rectangle = QRect(x, _rect.y() + height + _scaleLength,x, _rect.y() + height + 100);
painter.drawText(rectangle,Qt::AlignTop,QString::number((i-tmp) * _width / _scaleCount));
}
//左
for (int i = 1; i < _scaleCount; ++i) {
int y = _rect.top() + (i * height / _scaleCount);
painter.drawLine(_rect.x() - _scaleLength, y, _rect.x(), y);
const QRect rectangle = QRect(_rect.x() -_scaleLength-100, y, _rect.x() -_scaleLength, y);
painter.drawText(rectangle,Qt::AlignRight,QString::number((i-tmp) * _height / _scaleCount));
}
//右
for (int i = 1; i < _scaleCount; ++i) {
int y = _rect.top() + (i * height / _scaleCount);
painter.drawLine(_rect.x() + width, y, _rect.x() + width + _scaleLength, y);
const QRect rectangle = QRect(_rect.x() + width + _scaleLength, y, _rect.x() + width + _scaleLength+100, y);
painter.drawText(rectangle,Qt::AlignLeft,QString::number((i-tmp) * _height / _scaleCount));
}
painter.end();
}
int scaleLength() const{
return _scaleLength;
}
void setScaleLength(int scaleLength){
_scaleLength = scaleLength;
}
double scalex() const
{
return _scalex;
}
void setScalex(double scalex)
{
_scalex = scalex;
}
double scaley() const
{
return _scaley;
}
void setScaley(double scaley)
{
_scaley = scaley;
}
QRect rect() const{
return _rect;
}
QPoint topLeft() const
{
return _topLeft;
}
void setTopLeft(const QPoint &topLeft)
{
_topLeft = topLeft;
}
QPoint bottomRight() const
{
return _bottomRight;
}
void setBottomRight(const QPoint &bottomRight)
{
_bottomRight = bottomRight;
}
int width() const
{
return _width;
}
void setWidth(int width)
{
_width = width;
}
int height() const
{
return _height;
}
void setHeight(int height)
{
_height = height;
}
int scaleCount() const
{
return _scaleCount;
}
void setScaleCount(int scaleCount)
{
_scaleCount = scaleCount;
}
private:
int _scaleLength;
int _scaleCount;
QPoint _topLeft;
QPoint _bottomRight;
QRect _rect;
QColor _scaleColor;
double _scalex;
double _scaley;
int _width;
int _height;
};
#endif // SCALE_H
Loading…
Cancel
Save