├── ComboBox ├── CComboBox.cpp ├── CComboBox.h ├── CLCheckBox.cpp ├── CLCheckBox.h ├── CListWidget.cpp └── CListWidget.h ├── DataManageMent ├── CAllocVBOandVAO.cpp ├── CAllocVBOandVAO.h ├── CDataRAW.cpp └── CDataRAW.h ├── GridAndAxis ├── Anix.cpp ├── Anix.h ├── CGrid.cpp ├── CGrid.h └── textureindex.h ├── Img ├── decimal_point.png ├── digit.png ├── digit1.png ├── labels.png └── minus.png ├── MyOpenglWidget ├── Chart.cpp ├── Chart.h ├── Clines.cpp ├── Clines.h ├── QOpenglMain.cpp └── QOpenglMain.h ├── QOpenglMainProgram.pro ├── QOpenglMainProgram.pro.user ├── QOpenglMainProgram.pro.user.adb313d ├── QOpenglMainProgram_linux.pro ├── QOpenglMainProgram_linux.pro.user ├── QOpenglMainProgram_linux.pro.user.ns4637 ├── QOpenglMainProgram_mingw.pro ├── QOpenglMainProgram_mingw.pro.user ├── README.md ├── Renders ├── CGridRender.cpp ├── CGridRender.h ├── CLinesRender.cpp ├── CLinesRender.h ├── Crender.cpp └── Crender.h ├── Result ├── 示波器第一版1.png ├── 示波器第一版2.png └── 示波器第一版3.png ├── Shaders ├── basic.Frag ├── basic.vert ├── coord.frag ├── coord.vert ├── lines.Frag ├── lines.geo └── lines.vert ├── UDPServer ├── CAsioAsyncServer.cpp └── CAsioAsyncServer.h ├── Widgets ├── CCopyQOpenglWidget.cpp ├── CCopyQOpenglWidget.h ├── CLLOpenglWidget.cpp ├── CLLOpenglWidget.h ├── COFFOpenglwidget.cpp └── COFFOpenglwidget.h ├── mainWidget ├── Widget.cpp ├── Widget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h └── tools.h └── ui ├── mainwindow.ui └── widget.ui /ComboBox/CComboBox.cpp: -------------------------------------------------------------------------------- 1 | #include "CComboBox.h" 2 | #include 3 | 4 | CComboBox::CComboBox(QOpenglMain* _qOpenglMain, QWidget *parent) 5 | : QComboBox(parent), 6 | m_qOpenglMain(_qOpenglMain), 7 | m_tableWidget(new QTableWidget), 8 | m_colorDialog(new QColorDialog) 9 | { 10 | //m_colorDialog->setWindowFlags(Qt::WindowStaysOnTopHint); 11 | setModel(m_tableWidget->model()); 12 | setView(m_tableWidget); 13 | setEditable(false); 14 | setMinimumWidth(150); 15 | 16 | m_tableWidget->verticalHeader()->setVisible(false); 17 | m_tableWidget->horizontalHeader()->setVisible(false); 18 | m_tableWidget->setShowGrid(false); 19 | 20 | m_tableWidget->setColumnCount(2); 21 | m_tableWidget->setRowCount(0); 22 | } 23 | 24 | CComboBox::~CComboBox() 25 | { 26 | 27 | delete m_colorDialog; 28 | for(QList::iterator it = m_checkBoxs.begin(); it != m_checkBoxs.end(); ++it) 29 | { 30 | delete (*it); 31 | } 32 | for(QList::iterator it = m_pushButtons.begin(); it != m_pushButtons.end(); ++it) 33 | { 34 | delete (*it); 35 | } 36 | delete m_tableWidget; 37 | } 38 | 39 | void CComboBox::addNewItemFromOpenglMain(QString _name, QVariant _data, vector3f _color) 40 | { 41 | m_bchecked.append(false); 42 | m_data.append(_data); 43 | 44 | // qDebug() << m_tableWidget->rowCount()+1; 45 | m_tableWidget->setRowCount(m_tableWidget->rowCount()+1); 46 | QCheckBox* checkBox = new QCheckBox(_name); 47 | checkBox->setStyleSheet("QCheckBox{color:rgb(" + QString::number(static_cast(_color._x * 255.0)) + ", " + QString::number(static_cast(_color._y * 255.0)) + ", " + QString::number(static_cast(_color._z * 255.0)) + ")}"); 48 | checkBox->setChecked(true); 49 | m_checkBoxs.append(checkBox); 50 | QPushButton* pushButton = new QPushButton("调色"); 51 | QString tmpIndex = QString::number(_data.value()); 52 | pushButton->setObjectName(tmpIndex); 53 | m_pushButtons.append(pushButton); 54 | 55 | // qDebug() << m_tableWidget->rowCount(); 56 | m_tableWidget->setCellWidget(m_tableWidget->rowCount()-1, 0, checkBox); 57 | m_tableWidget->setCellWidget(m_tableWidget->rowCount()-1, 1, pushButton); 58 | 59 | QObject::connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(setLineEnabled(int))); 60 | QObject::connect(pushButton, SIGNAL(clicked(bool)), this, SLOT(onColorDialog()));\ 61 | 62 | } 63 | 64 | void CComboBox::setLineEnabled(int state) 65 | { 66 | QCheckBox* box = qobject_cast(sender()); 67 | if(box) 68 | { 69 | for(int off = 0; off < m_checkBoxs.size(); ++off) 70 | { 71 | 72 | if(m_checkBoxs.at(off) == box) 73 | { 74 | 75 | m_bchecked[off] = (box->checkState() == Qt::Checked) ? true : false; 76 | 77 | size_t tmpLineIndex = m_data[off].value(); 78 | m_qOpenglMain->setLinesEnabled(tmpLineIndex, m_bchecked[off]); 79 | } 80 | } 81 | } 82 | } 83 | 84 | void CComboBox::onColorDialog() 85 | { 86 | // QColor color = m_colorDialog->getColor(Qt::white, nullptr); 87 | // m_colorDialog->raise(); 88 | QColor color = QColorDialog::getColor(Qt::white, qobject_cast(parent())); 89 | 90 | QPushButton* button = qobject_cast(sender()); 91 | if(button) 92 | { 93 | GLint indexInt = button->objectName().toInt(); 94 | size_t indexUshort = 0; 95 | if (indexInt >= 0) 96 | { 97 | indexUshort = static_cast(indexInt); 98 | } 99 | vector4f tmpColor = {color.redF(), color.greenF(), color.blueF(), 1.0f}; 100 | 101 | m_qOpenglMain->setColor(indexUshort, tmpColor); 102 | QVariant dataIndex = QVariant::fromValue(indexUshort); 103 | for(int off(0); off < m_checkBoxs.size(); ++off) 104 | { 105 | if(m_data.at(off) == dataIndex) 106 | { 107 | m_checkBoxs.at(off)->setStyleSheet("QCheckBox{color:rgb(" + QString::number(static_cast(tmpColor._r * 255.0)) + ", " + QString::number(static_cast(tmpColor._g * 255.0)) + ", " + QString::number(static_cast(tmpColor._b * 255.0)) + ")}"); 108 | } 109 | } 110 | } 111 | else 112 | { 113 | 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /ComboBox/CComboBox.h: -------------------------------------------------------------------------------- 1 | #ifndef CCOMBOBOX_H 2 | #define CCOMBOBOX_H 3 | 4 | #include "MyOpenglWidget/Clines.h" 5 | #include "MyOpenglWidget/QOpenglMain.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class CComboBox : public QComboBox 14 | { 15 | Q_OBJECT 16 | public: 17 | //构造函数,传入与其相关的openglwidget的指针 18 | explicit CComboBox(QOpenglMain* _qOpenglMain, QWidget *parent = 0); 19 | //析构函数 20 | ~CComboBox(); 21 | //添加新线条的索引checkbox和调色按钮的函数 22 | void addNewItemFromOpenglMain(QString _name, QVariant _data, vector3f _color); 23 | private slots: 24 | //点击checkbox后的槽函数 25 | void setLineEnabled(int state); 26 | //点击调色的pushbutton后的槽函数 27 | void onColorDialog(); 28 | 29 | private: 30 | //由外部传来的openglwidget指针,不能在本类中删除 31 | QOpenglMain *m_qOpenglMain; 32 | //tableWidget类 33 | QTableWidget *m_tableWidget; 34 | //checkbox类的list 35 | QList m_checkBoxs; 36 | //QPushButton类的list 37 | QList m_pushButtons; 38 | //QString类的list,保存的是checkbox类的text内容 39 | QList m_fslist; 40 | //QVariant类的list,保存的是checkbox类的线段索引号(size_t) 41 | QList m_data; 42 | //checkbox的bool状态 43 | QList m_bchecked; 44 | //QColorDialog,用于更改线条的颜色 45 | QColorDialog* m_colorDialog; 46 | }; 47 | 48 | #endif // CCOMBOBOX_H 49 | -------------------------------------------------------------------------------- /ComboBox/CLCheckBox.cpp: -------------------------------------------------------------------------------- 1 | #include "clcombobox.h" 2 | 3 | CLComboBox::CLComboBox() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /ComboBox/CLCheckBox.h: -------------------------------------------------------------------------------- 1 | #ifndef CLCOMBOBOX_H 2 | #define CLCOMBOBOX_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class CLCheckBox : public QWidget 10 | { 11 | public: 12 | explicit CLCheckBox(QString _name, QWidget *parent = 0); 13 | void setCheckBoxStyleSheet(QString _style); 14 | void setChecked(bool _b); 15 | QCheckBox *getCheckBox() const; 16 | protected: 17 | QCheckBox *m_checkBox; 18 | QPushButton *m_color; 19 | QHBoxLayout *m_hbox; 20 | }; 21 | 22 | #endif // CLCOMBOBOX_H 23 | -------------------------------------------------------------------------------- /ComboBox/CListWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "ComboBox/CListWidget.h" 2 | CListWidget::CListWidget(QOpenglMain *_qOpenglMain, QComboBox *cmb, QWidget *parent) 3 | : QListWidget(parent), 4 | m_cmbox(cmb), 5 | m_qOpenglMain(_qOpenglMain) 6 | { 7 | setViewMode(QListWidget::ListMode); 8 | setSelectionMode(QAbstractItemView::SingleSelection); 9 | m_cmbox = cmb; 10 | } 11 | 12 | void CListWidget::addNewItemFromOpenglMain(QString _name, QVariant _data, vector3f _color) 13 | { 14 | m_bchecked.append(false); 15 | m_data.append(_data); 16 | QTableWidgetItem * tableWidget = new QTableWidget(1, 1); 17 | 18 | QListWidgetItem *item = new QListWidgetItem(); 19 | item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); 20 | item->setData(Qt::UserRole, _data); 21 | insertItem(model()->rowCount(), item); 22 | 23 | QCheckBox* box = new QCheckBox(_name); 24 | box->setStyleSheet("QCheckBox{color:rgb(" + QString::number(static_cast(_color._x * 255.0)) + ", " + QString::number(static_cast(_color._y * 255.0)) + ", " + QString::number(static_cast(_color._z * 255.0)) + ")}"); 25 | box->setChecked(true); 26 | 27 | //tableWidget->set 28 | 29 | 30 | setItemWidget(item, box); 31 | m_listItems.append(item); 32 | m_checklist.append(box); 33 | m_fslist.append(_name); 34 | QObject::connect(box, SIGNAL(stateChanged(int)), this, SLOT(setLinesEnable(int))); 35 | 36 | } 37 | 38 | void CListWidget::setLinesEnable(int state) 39 | { 40 | QCheckBox* box = qobject_cast(sender()); 41 | if(box) 42 | { 43 | for(int off = 0; off < m_checklist.size(); ++off) 44 | { 45 | 46 | if(m_checklist.at(off) == box) 47 | { 48 | 49 | m_bchecked[off] = (box->checkState() == Qt::Checked) ? true : false; 50 | qDebug() << "1"; 51 | size_t tmpLineIndex = m_listItems[off]->data(Qt::UserRole).value(); 52 | qDebug() << tmpLineIndex << " " << m_bchecked[off]; 53 | //qDebug() << m_qOpenglMain; 54 | m_qOpenglMain->setLinesEnabled(tmpLineIndex, m_bchecked[off]); 55 | qDebug() << "2"; 56 | // break; 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ComboBox/CListWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef CLISTWIDGET_H 2 | #define CLISTWIDGET_H 3 | 4 | #include "MyOpenglWidget/Clines.h" 5 | #include "MyOpenglWidget/QOpenglMain.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class CListWidget : public QListWidget 14 | { 15 | Q_OBJECT //自定义信号槽时需加上该宏,否则链接信号槽将会失败 16 | 17 | 18 | public: 19 | /* 20 | columnlabels QCheckBox名称 21 | data QListWidgetItem的用户自定义数据 22 | cmb 添加列表项的QComboBox,此处主要用于及时的将用户选择的结果显示出来 23 | */ 24 | CListWidget(QOpenglMain* _qOpenglMain, QComboBox* cmb=NULL, QWidget* parent=0); 25 | void addNewItemFromOpenglMain(QString _name, QVariant _data, vector3f _color); 26 | 27 | 28 | 29 | private slots: 30 | void setLinesEnable(int state); 31 | //public: 32 | // //返回用户选择项的用户自定义数据 33 | // void get_select_data(QList &data); 34 | 35 | //private slots: 36 | // //QCheckBox复选消息处理 37 | // void set_select_item(int state); 38 | 39 | 40 | 41 | private: 42 | QComboBox *m_cmbox; 43 | QOpenglMain *m_qOpenglMain; 44 | QList m_bchecked; 45 | QList m_data; 46 | QList m_checklist; 47 | QList m_listItems; 48 | QList m_fslist; 49 | QList m_buttonlist; 50 | QList m_tableItems; 51 | 52 | }; 53 | 54 | #endif //CLISTWIDGET_H 55 | -------------------------------------------------------------------------------- /DataManageMent/CAllocVBOandVAO.cpp: -------------------------------------------------------------------------------- 1 | #include "DataManageMent/CAllocVBOandVAO.h" 2 | 3 | CAllocVBOandVAO::CAllocVBOandVAO() 4 | { 5 | //initializeOpenGLFunctions(); 6 | } 7 | 8 | CAllocVBOandVAO::~CAllocVBOandVAO() 9 | { 10 | for(vector::iterator it = m_vaos.begin(); it != m_vaos.end(); ++it ) 11 | { 12 | glDeleteVertexArrays(1, &(*it)); 13 | } 14 | for(vector::iterator it = m_vbos.begin(); it != m_vbos.end(); ++it) 15 | { 16 | glDeleteBuffers(1, &(*it)); 17 | } 18 | } 19 | 20 | // create Vertex Array Buffer Object; 21 | GLuint CAllocVBOandVAO::allocVAO() 22 | { 23 | GLuint vao; 24 | glGenVertexArrays(1, &vao); 25 | 26 | if(vao <= 0) 27 | return -1; 28 | m_vaos.push_back(vao); 29 | return (GLuint)vao; 30 | } 31 | // create Vertex Buffer Object; 32 | GLuint CAllocVBOandVAO::allocVBO() 33 | { 34 | GLuint vbo; 35 | glGenBuffers(1, &vbo); 36 | 37 | if(vbo <= 0) 38 | return -1; 39 | m_vbos.push_back(vbo); 40 | return (GLuint)vbo; 41 | } 42 | 43 | // prepare for the initial environment; 44 | void CAllocVBOandVAO::prepare() 45 | { 46 | //_tmpContext->makeCurrent(_tmpContext->surface()); 47 | // QOpenGLFunctions_4_3_Core* m_funcs = _tmpContext->versionFunctions(); 48 | // m_funcs->initializeOpenGLFunctions(); 49 | initializeOpenGLFunctions(); 50 | } 51 | -------------------------------------------------------------------------------- /DataManageMent/CAllocVBOandVAO.h: -------------------------------------------------------------------------------- 1 | #ifndef CALLOCVBOANDVAO_H 2 | #define CALLOCVBOANDVAO_H 3 | /* Class Name: CAllocVBOandVAO; 4 | * Description: 5 | * This class is for creating the VAO and VBO, so the generated buffer object can be organized and deleted in the same time; 6 | * Function: 7 | * 1. create VAO by allocVAO() which returns the unused name(GLuint) 8 | * 2. create VBO by allocVBO() which returns the unused name(GLuint) 9 | * Tips: this class must be prepared by using prepare(); 10 | */ 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | class CAllocVBOandVAO : protected QOpenGLFunctions_4_3_Core 16 | { 17 | public: 18 | CAllocVBOandVAO(); 19 | ~CAllocVBOandVAO(); 20 | void prepare(/*QOpenGLContext *_tmpContext*/); 21 | GLuint allocVAO(); 22 | GLuint allocVBO(); 23 | private: 24 | vector m_vaos; //vaos 25 | vector m_vbos; //vbos 26 | }; 27 | 28 | #endif // CALLOCVBOANDVAO_H 29 | -------------------------------------------------------------------------------- /DataManageMent/CDataRAW.cpp: -------------------------------------------------------------------------------- 1 | #include "DataManageMent/CDataRAW.h" 2 | #include 3 | 4 | //模板函数:将string类型变量转换为常用的数值类型(此方法具有普遍适用性) 5 | template 6 | Type stringToNum(const string& str) 7 | { 8 | istringstream iss(str); 9 | Type num; 10 | iss >> num; 11 | return num; 12 | } 13 | 14 | CDataRAW::CDataRAW() 15 | { 16 | // system("mkdir data"); 17 | QString tmpDir = QDir::currentPath(); 18 | QDir dir(tmpDir + QString("/data")); 19 | bool ok = false; 20 | if(!dir.exists()) 21 | { 22 | ok = dir.mkdir(tmpDir + QString("/data")); 23 | } 24 | m_fPointsNames.clear(); 25 | m_fColorNames.clear(); 26 | m_fRangeNames.clear(); 27 | } 28 | 29 | void CDataRAW::setDir() 30 | { 31 | QString tmpDir = QDir::currentPath(); 32 | 33 | QDateTime currentTime = QDateTime::currentDateTime(); 34 | m_currentTimeS = currentTime.toString("yyyy_MM_dd_hh_mm_ss_zzz"); 35 | m_dir = tmpDir + QString("/data/") + m_currentTimeS + "/"; 36 | QDir dir(m_dir); 37 | bool ok = false; 38 | if(!dir.exists()) 39 | { 40 | ok = dir.mkdir(m_dir); 41 | } 42 | 43 | 44 | // string mkdir = (QString("mkdir ") + m_dir).toStdString(); 45 | // system(mkdir.c_str()); 46 | } 47 | 48 | void CDataRAW::addNewImage(u_short _imgNumber) 49 | { 50 | // QDateTime currentTime = QDateTime::currentDateTime(); 51 | // m_currentTimeS = currentTime.toString("yyyy_MM_dd_hh_mm_ss_zzz_ddd"); 52 | // m_dir = QString("data/") + m_currentTimeS + "/"; 53 | // string mkdir = (QString("mkdir ") + m_dir).toStdString(); 54 | // system(mkdir.c_str()); 55 | QString tmpFileName = m_dir + "img_" + QString::number(_imgNumber) + ".dat"; 56 | m_fPointsNames.insert(std::pair(_imgNumber, tmpFileName)); 57 | m_fout.open(m_fPointsNames.at(_imgNumber).toStdString(), ios_base::out /*| ios_base::binary*/); 58 | m_fout << m_currentTimeS.toStdString() << std::endl; 59 | m_fout << "数据描述:点数据索引号,帧数,x,y,z" << std::endl; 60 | m_fout << "points: " << std::endl; 61 | m_fout.close(); 62 | 63 | 64 | 65 | tmpFileName = m_dir + "img_" + QString::number(_imgNumber) + "_lineColor.datColor"; 66 | m_fColorNames.insert(std::pair(_imgNumber, tmpFileName)); 67 | m_fout.open(m_fColorNames.at(_imgNumber).toStdString(), ios_base::out); 68 | m_fout << "数据描述:线条索引号,颜色rgba值" << std::endl; 69 | m_fout << "line index and line color:" << std::endl; 70 | m_fout.close(); 71 | 72 | 73 | tmpFileName = m_dir + "img_" + QString::number(_imgNumber) + "_lineRange.datRange"; 74 | m_fRangeNames.insert(std::pair(_imgNumber, tmpFileName)); 75 | // m_fout.open(m_fRangeNames.at(_imgNumber).toStdString(), ios_base::out); 76 | // m_fout << "range:" << std::endl; 77 | // m_fout.close(); 78 | } 79 | 80 | void CDataRAW::addNewLineColor(u_short _imgNumber, u_short _lineNumber, vector4f _linecolor) 81 | { 82 | m_fout.open(m_fColorNames.at(_imgNumber).toStdString(), ios_base::out | ios_base::app); 83 | m_fout << _lineNumber << " " << _linecolor._r << " " << _linecolor._g << " " << _linecolor._b << " " << _linecolor._a << endl; 84 | m_fout.close(); 85 | } 86 | 87 | void CDataRAW::addNewLineRange(u_short _imgNumber, u_char _frameType, vector2f _xrange, vector2f _yrange, vector2f _zrange) 88 | { 89 | m_fout.open(m_fRangeNames.at(_imgNumber).toStdString(), ios_base::out); 90 | m_fout << "数据描述:图像类型(3D:0/ 2D: 1), x坐标上限,x坐标下限,y坐标上限,y坐标下限,z坐标上限,z坐标下限" << std::endl; 91 | m_fout << "range:" << std::endl; 92 | m_fout << _frameType << " " << _xrange._x << " " << _xrange._y << " " << _yrange._x << " " << _yrange._y << " " << _zrange._x << " " << _zrange._y << std::endl; 93 | m_fout.close(); 94 | } 95 | 96 | void CDataRAW::writeDataToFile(u_short _imgNumber, u_short _lineNumber, float _frame, float _x, float _y, float _z) 97 | { 98 | m_fout.open(m_fPointsNames.at(_imgNumber).toStdString(), ios_base::out | ios_base::app/* | ios_base::binary*/); 99 | if(!m_fout.is_open()) 100 | { 101 | QMessageBox::information(NULL, m_fPointsNames.at(_imgNumber), 102 | "文件打开失败", 103 | QMessageBox::Yes | QMessageBox::No, 104 | QMessageBox::Yes); 105 | } 106 | else 107 | { 108 | //tmpFin 109 | m_fout << _lineNumber << " " << _frame << " " << _x << " " << _y << " " << _z << std::endl; 110 | } 111 | m_fout.close(); 112 | } 113 | 114 | void CDataRAW::readDataFromFile(u_int _imgNumber, list >& _linesVbo, vector& _linesAmount, map& _lineColors) 115 | { 116 | map> tmpLineVbos; 117 | m_fin.open(m_fPointsNames.at(_imgNumber).toStdString(), ios_base::in); 118 | if(!m_fin.is_open()) 119 | { 120 | QMessageBox::information(NULL, m_fPointsNames.at(_imgNumber), 121 | "文件打开失败", 122 | QMessageBox::Yes | QMessageBox::No, 123 | QMessageBox::Yes); 124 | } 125 | string ch; 126 | string mark1Sta = "points:"; 127 | 128 | bool mark1 = 0; 129 | 130 | u_short lineNumber = 0; 131 | float x = 0.0f; 132 | float y = 0.0f; 133 | float z = 0.0f; 134 | float num = 0.0f; 135 | 136 | while(getline(m_fin, ch)) 137 | { 138 | if((string::npos != ch.find(mark1Sta)) && (!mark1)) 139 | { 140 | mark1 = true; 141 | continue; 142 | } 143 | 144 | if(mark1) 145 | { 146 | stringstream ss(ch); 147 | string subStr; 148 | getline(ss, subStr, ' '); 149 | lineNumber = stringToNum(subStr); 150 | for(int i(0); i < 4; ++i) 151 | { 152 | getline(ss, subStr, ' '); 153 | num = stringToNum(subStr); 154 | switch (i) { 155 | case 0: 156 | break; 157 | case 1: 158 | x = num; 159 | break; 160 | case 2: 161 | y = num; 162 | break; 163 | case 3: 164 | z = num; 165 | break; 166 | } 167 | } 168 | if(tmpLineVbos.find(lineNumber) == tmpLineVbos.end()) 169 | { 170 | vector tmpLineVbo; 171 | tmpLineVbos.insert(std::pair>(lineNumber, tmpLineVbo)); 172 | } 173 | tmpLineVbos.at(lineNumber).push_back(x); 174 | tmpLineVbos.at(lineNumber).push_back(y); 175 | tmpLineVbos.at(lineNumber).push_back(z); 176 | } 177 | } 178 | 179 | size_t tmpLineAmount; 180 | for(map>::iterator it = tmpLineVbos.begin(); it != tmpLineVbos.end(); ++it) 181 | { 182 | _linesVbo.push_back(it->second); 183 | tmpLineAmount = it->second.size() / 3; 184 | _linesAmount.push_back(tmpLineAmount); 185 | } 186 | 187 | m_fin.close(); 188 | 189 | 190 | // map tmpLineColors; 191 | m_fin.open(m_fColorNames.at(_imgNumber).toStdString(), ios_base::in); 192 | if(!m_fin.is_open()) 193 | { 194 | QMessageBox::information(NULL, m_fColorNames.at(_imgNumber), 195 | "文件打开失败", 196 | QMessageBox::Yes | QMessageBox::No, 197 | QMessageBox::Yes); 198 | } 199 | 200 | ch.clear(); 201 | mark1Sta = "line index and line color:"; 202 | 203 | mark1 = 0; 204 | 205 | lineNumber = 0; 206 | float r = 0.0f; 207 | float g = 0.0f; 208 | float b = 0.0f; 209 | float a = 0.0f; 210 | _lineColors.clear(); 211 | 212 | while(getline(m_fin, ch)) 213 | { 214 | if((string::npos != ch.find(mark1Sta)) && (!mark1)) 215 | { 216 | mark1 = true; 217 | continue; 218 | } 219 | 220 | if(mark1) 221 | { 222 | stringstream ss(ch); 223 | string subStr; 224 | getline(ss, subStr, ' '); 225 | lineNumber = stringToNum(subStr); 226 | for(int i(0); i < 4; ++i) 227 | { 228 | getline(ss, subStr, ' '); 229 | num = stringToNum(subStr); 230 | switch (i) { 231 | case 0: 232 | r = num; 233 | break; 234 | case 1: 235 | g = num; 236 | break; 237 | case 2: 238 | b = num; 239 | break; 240 | case 3: 241 | a = num; 242 | break; 243 | } 244 | } 245 | if(_lineColors.find(lineNumber) == _lineColors.end()) 246 | { 247 | vector4f tmpColor; 248 | tmpColor._r = r; tmpColor._g = g; 249 | tmpColor._b = b; tmpColor._a = a; 250 | _lineColors.insert(std::pair(lineNumber, tmpColor)); 251 | } 252 | } 253 | } 254 | 255 | m_fin.close(); 256 | 257 | } 258 | 259 | void CDataRAW::readLineRangeFromFile(u_short _imgNumber, u_char& _frameType, vector2f& _xrange, vector2f& _yrange, vector2f& _zrange) 260 | { 261 | m_fin.open(m_fRangeNames.at(_imgNumber).toStdString(), ios_base::in); 262 | if(!m_fin.is_open()) 263 | { 264 | QMessageBox::information(NULL, m_fRangeNames.at(_imgNumber), 265 | "文件打开失败", 266 | QMessageBox::Yes | QMessageBox::No, 267 | QMessageBox::Yes); 268 | } 269 | string ch; 270 | string mark1Sta = "range:"; 271 | 272 | bool mark1 = 0; 273 | 274 | float num = 0.0f; 275 | 276 | while(getline(m_fin, ch)) 277 | { 278 | if((string::npos != ch.find(mark1Sta)) && (!mark1)) 279 | { 280 | mark1 = true; 281 | continue; 282 | } 283 | 284 | if(mark1) 285 | { 286 | stringstream ss(ch); 287 | string subStr; 288 | getline(ss, subStr, ' '); 289 | num = stringToNum(subStr); 290 | _frameType = num; 291 | for(int i(0); i < 6; ++i) 292 | { 293 | getline(ss, subStr, ' '); 294 | num = stringToNum(subStr); 295 | switch (i) { 296 | case 0: 297 | _xrange._x = num; 298 | break; 299 | case 1: 300 | _xrange._y = num; 301 | break; 302 | case 2: 303 | _yrange._x = num; 304 | break; 305 | case 3: 306 | _yrange._y = num; 307 | break; 308 | case 4: 309 | _zrange._x = num; 310 | break; 311 | case 5: 312 | _zrange._y = num; 313 | break; 314 | } 315 | } 316 | } 317 | } 318 | 319 | m_fin.close(); 320 | } 321 | 322 | void CDataRAW::setDir(QString _fileName) 323 | { 324 | m_dirFile = _fileName.split("img_").at(0); 325 | } 326 | 327 | void CDataRAW::writeDataToFileNoName(u_short _imgNumber, u_short _lineNumber, float _frame, float _x, float _y, float _z) 328 | { 329 | QString fileName = m_dirFile + "img_" + QString::number(_imgNumber) + ".dat"; 330 | m_fout.open(fileName.toStdString(), ios_base::out | ios_base::app/* | ios_base::binary*/); 331 | if(!m_fout.is_open()) 332 | { 333 | QMessageBox::information(NULL, fileName, 334 | "文件打开失败", 335 | QMessageBox::Yes | QMessageBox::No, 336 | QMessageBox::Yes); 337 | } 338 | else 339 | { 340 | //tmpFin 341 | m_fout << _lineNumber << " " << _frame << " " << _x << " " << _y << " " << _z << std::endl; 342 | } 343 | m_fout.close(); 344 | } 345 | 346 | void CDataRAW::readDataFromFileNoName(u_int _imgNumber, list > &_linesVbo, vector &_linesAmount, map &_lineColors) 347 | { 348 | QString fileName = m_dirFile + "img_" + QString::number(_imgNumber) + ".dat"; 349 | map> tmpLineVbos; 350 | m_fin.open(fileName.toStdString(), ios_base::in); 351 | if(!m_fin.is_open()) 352 | { 353 | QMessageBox::information(NULL, fileName, 354 | "文件打开失败", 355 | QMessageBox::Yes | QMessageBox::No, 356 | QMessageBox::Yes); 357 | } 358 | string ch; 359 | string mark1Sta = "points:"; 360 | 361 | bool mark1 = 0; 362 | 363 | u_short lineNumber = 0; 364 | float x = 0.0f; 365 | float y = 0.0f; 366 | float z = 0.0f; 367 | float num = 0.0f; 368 | 369 | while(getline(m_fin, ch)) 370 | { 371 | if((string::npos != ch.find(mark1Sta)) && (!mark1)) 372 | { 373 | mark1 = true; 374 | continue; 375 | } 376 | 377 | if(mark1) 378 | { 379 | stringstream ss(ch); 380 | string subStr; 381 | getline(ss, subStr, ' '); 382 | lineNumber = stringToNum(subStr); 383 | for(int i(0); i < 4; ++i) 384 | { 385 | getline(ss, subStr, ' '); 386 | num = stringToNum(subStr); 387 | switch (i) { 388 | case 0: 389 | break; 390 | case 1: 391 | x = num; 392 | break; 393 | case 2: 394 | y = num; 395 | break; 396 | case 3: 397 | z = num; 398 | break; 399 | } 400 | } 401 | if(tmpLineVbos.find(lineNumber) == tmpLineVbos.end()) 402 | { 403 | vector tmpLineVbo; 404 | tmpLineVbos.insert(std::pair>(lineNumber, tmpLineVbo)); 405 | } 406 | tmpLineVbos.at(lineNumber).push_back(x); 407 | tmpLineVbos.at(lineNumber).push_back(y); 408 | tmpLineVbos.at(lineNumber).push_back(z); 409 | } 410 | } 411 | 412 | size_t tmpLineAmount; 413 | for(map>::iterator it = tmpLineVbos.begin(); it != tmpLineVbos.end(); ++it) 414 | { 415 | _linesVbo.push_back(it->second); 416 | tmpLineAmount = it->second.size() / 3; 417 | _linesAmount.push_back(tmpLineAmount); 418 | } 419 | 420 | m_fin.close(); 421 | 422 | 423 | // map tmpLineColors; 424 | fileName = m_dirFile + "img_" + QString::number(_imgNumber) + "_lineColor.datColor"; 425 | m_fin.open(fileName.toStdString(), ios_base::in); 426 | if(!m_fin.is_open()) 427 | { 428 | QMessageBox::information(NULL, fileName, 429 | "文件打开失败", 430 | QMessageBox::Yes | QMessageBox::No, 431 | QMessageBox::Yes); 432 | } 433 | 434 | ch.clear(); 435 | mark1Sta = "line index and line color:"; 436 | 437 | mark1 = 0; 438 | 439 | lineNumber = 0; 440 | float r = 0.0f; 441 | float g = 0.0f; 442 | float b = 0.0f; 443 | float a = 0.0f; 444 | _lineColors.clear(); 445 | 446 | while(getline(m_fin, ch)) 447 | { 448 | if((string::npos != ch.find(mark1Sta)) && (!mark1)) 449 | { 450 | mark1 = true; 451 | continue; 452 | } 453 | 454 | if(mark1) 455 | { 456 | stringstream ss(ch); 457 | string subStr; 458 | getline(ss, subStr, ' '); 459 | lineNumber = stringToNum(subStr); 460 | for(int i(0); i < 4; ++i) 461 | { 462 | getline(ss, subStr, ' '); 463 | num = stringToNum(subStr); 464 | switch (i) { 465 | case 0: 466 | r = num; 467 | break; 468 | case 1: 469 | g = num; 470 | break; 471 | case 2: 472 | b = num; 473 | break; 474 | case 3: 475 | a = num; 476 | break; 477 | } 478 | } 479 | if(_lineColors.find(lineNumber) == _lineColors.end()) 480 | { 481 | vector4f tmpColor; 482 | tmpColor._r = r; tmpColor._g = g; 483 | tmpColor._b = b; tmpColor._a = a; 484 | _lineColors.insert(std::pair(lineNumber, tmpColor)); 485 | } 486 | } 487 | } 488 | 489 | m_fin.close(); 490 | } 491 | 492 | void CDataRAW::readLineRangeFromFileNoName(u_short _imgNumber, u_char& _frameType, vector2f &_xrange, vector2f &_yrange, vector2f &_zrange) 493 | { 494 | QString fileName = m_dirFile + "img_" + QString::number(_imgNumber) + "_lineRange.datRange"; 495 | m_fin.open(fileName.toStdString(), ios_base::in); 496 | if(!m_fin.is_open()) 497 | { 498 | QMessageBox::information(NULL, fileName, 499 | "文件打开失败", 500 | QMessageBox::Yes | QMessageBox::No, 501 | QMessageBox::Yes); 502 | } 503 | string ch; 504 | string mark1Sta = "range:"; 505 | 506 | bool mark1 = 0; 507 | 508 | float num = 0.0f; 509 | 510 | while(getline(m_fin, ch)) 511 | { 512 | if((string::npos != ch.find(mark1Sta)) && (!mark1)) 513 | { 514 | mark1 = true; 515 | continue; 516 | } 517 | 518 | if(mark1) 519 | { 520 | stringstream ss(ch); 521 | string subStr; 522 | getline(ss, subStr, ' '); 523 | num = stringToNum(subStr); 524 | _frameType = num; 525 | for(int i(0); i < 6; ++i) 526 | { 527 | getline(ss, subStr, ' '); 528 | num = stringToNum(subStr); 529 | switch (i) { 530 | case 0: 531 | _xrange._x = num; 532 | break; 533 | case 1: 534 | _xrange._y = num; 535 | break; 536 | case 2: 537 | _yrange._x = num; 538 | break; 539 | case 3: 540 | _yrange._y = num; 541 | break; 542 | case 4: 543 | _zrange._x = num; 544 | break; 545 | case 5: 546 | _zrange._y = num; 547 | break; 548 | } 549 | } 550 | } 551 | } 552 | 553 | m_fin.close(); 554 | } 555 | -------------------------------------------------------------------------------- /DataManageMent/CDataRAW.h: -------------------------------------------------------------------------------- 1 | #ifndef CDATARAW_H 2 | #define CDATARAW_H 3 | #include "MyOpenglWidget/Clines.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | class CDataRAW 16 | { 17 | public: 18 | CDataRAW(); 19 | void setDir(); 20 | void addNewImage(u_short _imgNumber); 21 | void addNewLineColor(u_short _imgNumber, u_short _lineNumber, vector4f _linecolor); 22 | void addNewLineRange(u_short _imgNumber, u_char _frameType, vector2f _xrange, vector2f _yrange, vector2f _zrange); 23 | void writeDataToFile(u_short _imgNumber, u_short _lineNumber, float _frame, float _x, float _y, float _z); 24 | void readDataFromFile(u_int _imgNumber, list > &_linesVbo, vector &_linesAmount, map &_lineColors); 25 | void readLineRangeFromFile(u_short _imgNumber, u_char &_frameType, vector2f &_xrange, vector2f &_yrange, vector2f &_zrange); 26 | 27 | //从文件读取 28 | void setDir(QString _fileName); 29 | void writeDataToFileNoName(u_short _imgNumber, u_short _lineNumber, float _frame, float _x, float _y, float _z); 30 | void readDataFromFileNoName(u_int _imgNumber, list > &_linesVbo, vector &_linesAmount, map &_lineColors); 31 | void readLineRangeFromFileNoName(u_short _imgNumber, u_char &_frameType, vector2f &_xrange, vector2f &_yrange, vector2f &_zrange); 32 | private: 33 | ifstream m_fin; 34 | ofstream m_fout; 35 | map m_fPointsNames; 36 | map m_fColorNames; 37 | map m_fRangeNames; 38 | 39 | QString m_currentTimeS; 40 | QString m_dir; 41 | 42 | //从文件读取 43 | QString m_dirFile; 44 | }; 45 | 46 | #endif // CDATARAW_H 47 | -------------------------------------------------------------------------------- /GridAndAxis/Anix.cpp: -------------------------------------------------------------------------------- 1 | #include "GridAndAxis/Anix.h" 2 | //#include 3 | #include 4 | 5 | const float pi = 3.1415926; 6 | #define MAX_CHAR 1024 7 | void CAnix::initial(Crender* _render, QOpenGLContext *context, QSurface *surface) 8 | { 9 | //glClear(GL_CLEAR_BUFFER); 10 | initializeOpenGLFunctions(); 11 | m_context = context; 12 | m_surface = surface; 13 | m_therender = _render; 14 | m_context->makeCurrent(m_context->surface()); 15 | //m_vao = _render->allocVao(); 16 | m_vao = m_allocVBOandVAO->allocVAO(); 17 | //创建缓冲区VBO 18 | m_vbo = m_allocVBOandVAO->allocVBO(); 19 | m_vboIndex = m_allocVBOandVAO->allocVBO(); 20 | 21 | // if(m_notCopyFromOtherOpenGLWidget) 22 | // { 23 | genAnix(); 24 | genCord(); //ll 20170714 25 | //qDebug() << "createTheForm"; 26 | // } 27 | // else if(m_copyCompleted) 28 | // { 29 | // copyBufferFromOthers(); 30 | // //qDebug() << "createfromCopy"; 31 | // } 32 | // else 33 | // { 34 | // //qDebug() << "createNothing"; 35 | // } 36 | } 37 | 38 | void CAnix::draw() 39 | { 40 | m_context->makeCurrent(m_surface); 41 | 42 | m_therender->bindShader(); 43 | glBindVertexArray(m_vao); 44 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 45 | m_vboIndex); 46 | glDrawElements(GL_TRIANGLES,m_arrowIndex.size()-18, GL_UNSIGNED_INT, 0); 47 | glLineWidth(1.5); 48 | glDrawElements(GL_LINES, 18, GL_UNSIGNED_INT, (char*)((m_arrowIndex.size() - 18)*4)); 49 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //ll 50 | glBindVertexArray(0); 51 | 52 | m_therender->releaseShader(); 53 | } 54 | 55 | void CAnix::clearUp() 56 | { 57 | 58 | } 59 | 60 | void CAnix::setCordi(vector2f _x, vector2f _y, vector2f _z) 61 | { 62 | m_x._x = 0; 63 | m_x._y = _x._y - _x._x; 64 | m_y._x = 0; 65 | m_y._y = _y._y - _y._x; 66 | m_z._x = 0; 67 | m_z._y = _z._y - _z._x; 68 | genAnix(); //�������� 69 | updataCord(); 70 | } 71 | 72 | void CAnix::setCordiAlone() 73 | { 74 | genAnix(); //�������� 75 | updataCord(); 76 | } 77 | 78 | void CAnix::setCordiAlone(vector2f _x, vector2f _y, vector2f _z) 79 | { 80 | m_x._x = 0; 81 | m_x._y = _x._y - _x._x; 82 | m_y._x = 0; 83 | m_y._y = _y._y - _y._x; 84 | m_z._x = 0; 85 | m_z._y = _z._y - _z._x; 86 | } 87 | 88 | CAnix::CAnix() 89 | { 90 | } 91 | 92 | 93 | CAnix::~CAnix() 94 | { 95 | } 96 | 97 | void CAnix::setAlloc(CAllocVBOandVAO *allocVBOandVAO) 98 | { 99 | m_allocVBOandVAO = allocVBOandVAO; 100 | } 101 | 102 | void CAnix::setCopyFromOtherOpenWidgetMark(GLboolean _b) 103 | { 104 | m_notCopyFromOtherOpenGLWidget = _b; 105 | } 106 | 107 | GLuint CAnix::getAnixVao() 108 | { 109 | return m_vao; 110 | } 111 | 112 | GLuint CAnix::getAnixVbo() 113 | { 114 | return m_vbo; 115 | } 116 | 117 | GLuint CAnix::getAnixVboIndex() 118 | { 119 | return m_vboIndex; 120 | } 121 | 122 | 123 | void CAnix::setAnixVboBuffer(vector& _anixVboBuffer) 124 | { 125 | m_vboBuffer = _anixVboBuffer; 126 | } 127 | 128 | void CAnix::setAnixVboIndexBuffer(vector& _anixVboIndexBuffer) 129 | { 130 | //该函数在调用完成后将会置m_copyCompleted为true,在初始化anix过程中,会将拷贝来的数据作为缓冲区的数据 131 | m_vboIndexBuffer = _anixVboIndexBuffer; 132 | m_copyCompleted = true; 133 | } 134 | 135 | void CAnix::copyBufferFromOthers() 136 | { 137 | m_context->makeCurrent(m_surface); 138 | glBindVertexArray(m_vao); 139 | GLuint _persize = sizeof(vector3f) + sizeof(vector4f); 140 | glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 141 | glBufferData(GL_ARRAY_BUFFER, 142 | m_vboBuffer.size() * sizeof(GLfloat), 143 | m_vboBuffer.data(), 144 | GL_DYNAMIC_DRAW); 145 | 146 | glEnableVertexAttribArray(0); 147 | glVertexAttribPointer(0, 148 | 3, 149 | GL_FLOAT, 150 | GL_FALSE, 151 | _persize, 152 | 0); 153 | glEnableVertexAttribArray(1); 154 | glVertexAttribPointer(1, 155 | 4, 156 | GL_FLOAT, 157 | GL_FALSE, 158 | _persize, 159 | (char*)(sizeof(vector3f))); 160 | glBindBuffer(GL_ARRAY_BUFFER, 0); 161 | 162 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 163 | m_vboIndex); 164 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, 165 | m_vboIndexBuffer.size() * sizeof(GLuint), 166 | m_vboIndexBuffer.data(), 167 | GL_DYNAMIC_DRAW); 168 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 169 | 170 | glBindVertexArray(0); 171 | } 172 | 173 | void CAnix::genCord() 174 | { 175 | m_context->makeCurrent(m_surface); 176 | glBindVertexArray(m_vao); 177 | GLuint _persize = sizeof(vector3f) + sizeof(vector4f);//λ��3+��ɫ3 178 | glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 179 | glBufferData(GL_ARRAY_BUFFER, 180 | m_arrowpoint.size() * sizeof(GLfloat), 181 | m_arrowpoint.data(), 182 | GL_DYNAMIC_DRAW); 183 | // GLint size = 0; 184 | // glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 185 | glEnableVertexAttribArray(0); 186 | glVertexAttribPointer(0, 187 | 3, 188 | GL_FLOAT, 189 | GL_FALSE, 190 | _persize, 191 | 0); 192 | glEnableVertexAttribArray(1); 193 | glVertexAttribPointer(1, 194 | 4, 195 | GL_FLOAT, 196 | GL_FALSE, 197 | _persize, 198 | (char*)(sizeof(vector3f))); 199 | glBindBuffer(GL_ARRAY_BUFFER, 0); 200 | 201 | 202 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 203 | m_vboIndex); 204 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, 205 | m_arrowIndex.size() * sizeof(GLuint), 206 | m_arrowIndex.data(), 207 | GL_DYNAMIC_DRAW); 208 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 209 | 210 | glBindVertexArray(0); 211 | //ll 2017714 212 | // glBindVertexArray(m_vao); 213 | // GLint size = 0; 214 | // glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 215 | // glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 216 | //// glBindBuffer(GL_ARRAY_BUFFER, m_vboIndex); 217 | //// glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 218 | // GLfloat tmpData[size] = {0}; 219 | // glGetBufferSubData(GL_ARRAY_BUFFER, 0, size, tmpData); 220 | // size = 793; 221 | // glCopyBufferSubData(m_vbo, m_vboIndex, 0, 0, size); 222 | // glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 223 | 224 | } 225 | 226 | void CAnix::updataCord() 227 | { 228 | m_context->makeCurrent(m_surface); 229 | glBindVertexArray(m_vao); 230 | glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 231 | //GLboolean b = glIsVertexArray(m_vao); 232 | glBufferSubData(GL_ARRAY_BUFFER, 233 | 0, 234 | m_arrowpoint.size() * sizeof(GLfloat), 235 | m_arrowpoint.data()); 236 | glBindBuffer(GL_ARRAY_BUFFER, 0); 237 | 238 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 239 | m_vboIndex); 240 | glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 241 | 0, 242 | m_arrowIndex.size() * sizeof(GLuint), 243 | m_arrowIndex.data()); 244 | // glBindBuffer(GL_ARRAY_BUFFER, 0); 245 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 246 | glBindVertexArray(0); 247 | 248 | } 249 | 250 | void CAnix::genAnix() 251 | { 252 | m_context->makeCurrent(m_surface); 253 | //vector _indexarrow; 254 | //vector _arrordata; 255 | m_arrowIndex.clear(); 256 | m_arrowpoint.clear(); 257 | size_t anglenum = 20; //��Ⱦ������Ҫ��������20�� 258 | 259 | int offsite = 0; 260 | for (size_t index = 0; index < anglenum; ++index) //�������� 261 | { 262 | if (index < (anglenum - 1)) 263 | { 264 | m_arrowIndex.push_back(0); 265 | m_arrowIndex.push_back(index + 1); 266 | m_arrowIndex.push_back(index + 2); 267 | } 268 | else { 269 | m_arrowIndex.push_back(0); 270 | m_arrowIndex.push_back(index + 1); 271 | m_arrowIndex.push_back(1); 272 | } 273 | } 274 | offsite = anglenum + 1; 275 | for (size_t index = 0; index < anglenum; ++index) //�������� 276 | { 277 | if (index < (anglenum - 1)) 278 | { 279 | m_arrowIndex.push_back(0 + offsite); 280 | m_arrowIndex.push_back(index + 1 + offsite); 281 | m_arrowIndex.push_back(index + 2 + offsite); 282 | } 283 | else { 284 | m_arrowIndex.push_back(0 + offsite); 285 | m_arrowIndex.push_back(index + 1 + offsite); 286 | m_arrowIndex.push_back(1 + offsite); 287 | } 288 | } 289 | offsite = 2 * (anglenum + 1); 290 | for (size_t index = 0; index < anglenum; ++index) //�������� 291 | { 292 | if (index < (anglenum - 1)) 293 | { 294 | m_arrowIndex.push_back(0 + offsite); 295 | m_arrowIndex.push_back(index + 1 + offsite); 296 | m_arrowIndex.push_back(index + 2 + offsite); 297 | } 298 | else { 299 | m_arrowIndex.push_back(0 + offsite); 300 | m_arrowIndex.push_back(index + 1 + offsite); 301 | m_arrowIndex.push_back(1 + offsite); 302 | } 303 | } 304 | offsite = 3 * (anglenum + 1); 305 | for (size_t index = 0; index < 6 * 3; ++index) //���������� 306 | { 307 | m_arrowIndex.push_back(offsite + index); 308 | } 309 | 310 | 311 | //X�����ͷ 312 | m_arrowpoint.push_back(m_x._y); //x��� 313 | m_arrowpoint.push_back(m_y._x); //y��С 314 | m_arrowpoint.push_back(m_z._x); //z��С 315 | m_arrowpoint.push_back(m_xcolor._r);//��ɫ 316 | m_arrowpoint.push_back(m_xcolor._g);//��ɫ 317 | m_arrowpoint.push_back(m_xcolor._b);//��ɫ 318 | m_arrowpoint.push_back(m_xcolor._a);//��ɫ 319 | for (size_t index = 0; index < anglenum; ++index) 320 | { 321 | m_arrowpoint.push_back(m_x._y - m_arrowbase._y); 322 | m_arrowpoint.push_back(m_y._x+m_arrowbase._x*cos(index * 2 * pi / anglenum)); 323 | m_arrowpoint.push_back(m_z._x+m_arrowbase._x*sin(index * 2 * pi / anglenum)); 324 | 325 | m_arrowpoint.push_back(m_xcolor._r);//��ɫ 326 | m_arrowpoint.push_back(m_xcolor._g);//��ɫ 327 | m_arrowpoint.push_back(m_xcolor._b);//��ɫ 328 | m_arrowpoint.push_back(m_xcolor._a);//��ɫ 329 | } 330 | 331 | //Y���� ��ͷ 332 | m_arrowpoint.push_back(m_x._x); //x��� 333 | m_arrowpoint.push_back(m_y._y); //y��С 334 | m_arrowpoint.push_back(m_z._x); //z��С 335 | m_arrowpoint.push_back(m_ycolor._r);//��ɫ 336 | m_arrowpoint.push_back(m_ycolor._g);//��ɫ 337 | m_arrowpoint.push_back(m_ycolor._b);//��ɫ 338 | m_arrowpoint.push_back(m_ycolor._a);//��ɫ 339 | for (size_t index = 0; index < anglenum; ++index) 340 | { 341 | m_arrowpoint.push_back(m_x._x + m_arrowbase._x*cos(index * 2 * pi / anglenum)); 342 | m_arrowpoint.push_back(m_y._y - m_arrowbase._y); 343 | m_arrowpoint.push_back(m_z._x + m_arrowbase._x*sin(index * 2 * pi / anglenum)); 344 | 345 | m_arrowpoint.push_back(m_ycolor._r);//��ɫ 346 | m_arrowpoint.push_back(m_ycolor._g);//��ɫ 347 | m_arrowpoint.push_back(m_ycolor._b);//��ɫ 348 | m_arrowpoint.push_back(m_ycolor._a);//��ɫ 349 | } 350 | 351 | //Z���� ��ͷ 352 | m_arrowpoint.push_back(m_x._x); 353 | m_arrowpoint.push_back(m_y._x); 354 | m_arrowpoint.push_back(m_z._y); 355 | m_arrowpoint.push_back(m_zcolor._r);//��ɫ 356 | m_arrowpoint.push_back(m_zcolor._g);//��ɫ 357 | m_arrowpoint.push_back(m_zcolor._b);//��ɫ 358 | m_arrowpoint.push_back(m_zcolor._a);//��ɫ 359 | for (size_t index = 0; index < anglenum; ++index) 360 | { 361 | m_arrowpoint.push_back(m_x._x + m_arrowbase._x*cos(index * 2 * pi / anglenum)); 362 | m_arrowpoint.push_back(m_y._x - m_arrowbase._x*sin(index * 2 * pi / anglenum)); 363 | m_arrowpoint.push_back(m_z._y - m_arrowbase._y); 364 | m_arrowpoint.push_back(m_zcolor._r);//��ɫ 365 | m_arrowpoint.push_back(m_zcolor._g);//��ɫ 366 | m_arrowpoint.push_back(m_zcolor._b);//��ɫ 367 | m_arrowpoint.push_back(m_zcolor._a);//��ɫ 368 | } 369 | 370 | //X�� 371 | m_arrowpoint.push_back(m_x._x); m_arrowpoint.push_back(m_y._x); m_arrowpoint.push_back(m_z._x); 372 | m_arrowpoint.push_back(m_xcolor._r); m_arrowpoint.push_back(m_xcolor._g); m_arrowpoint.push_back(m_xcolor._b); m_arrowpoint.push_back(m_xcolor._a); 373 | 374 | m_arrowpoint.push_back(m_x._y); m_arrowpoint.push_back(m_y._x); m_arrowpoint.push_back(m_z._x); 375 | m_arrowpoint.push_back(m_xcolor._r); m_arrowpoint.push_back(m_xcolor._g); m_arrowpoint.push_back(m_xcolor._b); m_arrowpoint.push_back(m_xcolor._a); 376 | //Y�� 377 | m_arrowpoint.push_back(m_x._x); m_arrowpoint.push_back(m_y._x); m_arrowpoint.push_back(m_z._x); 378 | m_arrowpoint.push_back(m_ycolor._r); m_arrowpoint.push_back(m_ycolor._g); m_arrowpoint.push_back(m_ycolor._b); m_arrowpoint.push_back(m_ycolor._a); 379 | 380 | m_arrowpoint.push_back(m_x._x); m_arrowpoint.push_back(m_y._y); m_arrowpoint.push_back(m_z._x); 381 | m_arrowpoint.push_back(m_ycolor._r); m_arrowpoint.push_back(m_ycolor._g); m_arrowpoint.push_back(m_ycolor._b); m_arrowpoint.push_back(m_ycolor._a); 382 | //Z�� 383 | m_arrowpoint.push_back(m_x._x); m_arrowpoint.push_back(m_y._x); m_arrowpoint.push_back(m_z._x); 384 | m_arrowpoint.push_back(m_zcolor._r); m_arrowpoint.push_back(m_zcolor._g); m_arrowpoint.push_back(m_zcolor._b); m_arrowpoint.push_back(m_zcolor._a); 385 | 386 | m_arrowpoint.push_back(m_x._x); m_arrowpoint.push_back(m_y._x); m_arrowpoint.push_back(m_z._y); 387 | m_arrowpoint.push_back(m_zcolor._r); m_arrowpoint.push_back(m_zcolor._g); m_arrowpoint.push_back(m_zcolor._b); m_arrowpoint.push_back(m_zcolor._a); 388 | 389 | } 390 | -------------------------------------------------------------------------------- /GridAndAxis/Anix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "MyOpenglWidget/Clines.h" 7 | #include "Renders/Crender.h" 8 | #include "DataManageMent/CAllocVBOandVAO.h" 9 | 10 | //#include 11 | //#include 12 | 13 | #include 14 | using namespace std; 15 | class CAnix : protected QOpenGLFunctions_4_3_Core 16 | { 17 | public: 18 | void initial(Crender* _render, QOpenGLContext* context, QSurface* surface); 19 | void draw(); 20 | void clearUp(); 21 | void setCordi(vector2f _x, vector2f _y, vector2f _z); 22 | void setCordiAlone(vector2f _x, vector2f _y, vector2f _z); 23 | vector2f getXCord(); 24 | vector2f getYCord(); 25 | vector2f getZCord(); 26 | CAnix(); 27 | ~CAnix(); 28 | void setAlloc(CAllocVBOandVAO* allocVBOandVAO); 29 | public: 30 | /*---------复制窗口时调用start-----------*/ 31 | void setCopyFromOtherOpenWidgetMark(GLboolean _b); 32 | GLuint getAnixVao(); 33 | GLuint getAnixVbo(); 34 | GLuint getAnixVboIndex(); 35 | //Anix 36 | void setAnixVboBuffer(vector &_anixVboBuffer); 37 | void setAnixVboIndexBuffer(vector& _anixVboIndexBuffer); 38 | void copyBufferFromOthers(); 39 | void setCordiAlone(); 40 | /*---------复制窗口时调用end-----------*/ 41 | private: 42 | void genCord(); 43 | void updataCord(); 44 | void genAnix(); //生成坐标轴和箭头buffer(参数为坐标线位置) 45 | private: 46 | Crender* m_therender; 47 | 48 | private: 49 | QOpenGLContext* m_context; 50 | QSurface* m_surface; 51 | vector2f m_x = {0,1}; //坐标X 52 | vector2f m_y = {0,1}; //坐标Y 53 | vector2f m_z = {0,1}; //坐标Z 54 | vector2f m_arrowbase = {0.01f,0.05f}; //箭头底半径 箭头长度 55 | vector m_arrowIndex; //箭头检索 56 | vector m_arrowpoint; //箭头的点 57 | vector4f m_xcolor = {1, 0, 0, 1};//{45/255.0f,57/255.0f,227/255.0f,1}; //x轴颜色 58 | vector4f m_ycolor = {0, 1, 0, 1};//{45/255.0f,57/255.0f,227/255.0f,1}; //y轴颜色 59 | vector4f m_zcolor = {0, 0, 1, 1};//{45/255.0f,57/255.0f,227/255.0f,1}; //z轴颜色 60 | float* m_arrow; //线段的点 61 | CAllocVBOandVAO* m_allocVBOandVAO; 62 | private: 63 | GLuint m_vao; 64 | GLuint m_vbo; 65 | GLuint m_vboIndex; //索引 66 | GLuint m_copyVao = -1; 67 | GLuint m_copyVbo = -1; 68 | GLuint m_copyVboIndex = -1; 69 | GLboolean m_notCopyFromOtherOpenGLWidget = true; 70 | GLboolean m_copyCompleted = false; 71 | vector m_vboBuffer; 72 | vector m_vboIndexBuffer; 73 | }; 74 | 75 | -------------------------------------------------------------------------------- /GridAndAxis/CGrid.h: -------------------------------------------------------------------------------- 1 | #ifndef CGRID_H 2 | #define CGRID_H 3 | #include "textureindex.h" 4 | #include "MyOpenglWidget/Clines.h" 5 | #include "Renders/Crender.h" 6 | #include "Renders/CGridRender.h" 7 | #include "DataManageMent/CAllocVBOandVAO.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | class CGrid : protected QOpenGLFunctions_4_3_Core 17 | { 18 | public: //functional functions 19 | enum RangeChange { 20 | NotChange, 21 | Change 22 | }; 23 | enum Range{ 24 | xRange, 25 | yRange, 26 | zRange 27 | }; 28 | enum DRAWTYPE { 29 | XZY = 0, 30 | XY, 31 | XZ, 32 | YZ 33 | }; 34 | CGrid(); 35 | ~CGrid(); 36 | void setPrecision(GLint precision); 37 | void setFontSize(GLfloat _fontSize = 6.0f); 38 | void setGridColor(vector4f color); 39 | bool setRot(QMatrix4x4 _rot); 40 | void setGridOff(); 41 | void setGridOn(); 42 | void setAnixLabelOff(); 43 | void setAnixLabelOn(); 44 | void createAndUpdateAnixnumberWithPnt(); 45 | void setDrawType(int drawtype); 46 | public: //functions must be called 47 | void initial(Crender* _render, CGridRender *_gridRender, QOpenGLContext* context, QSurface* surface); 48 | void setAlloc(CAllocVBOandVAO* allocVBOandVAO); //this function should be called at first, for memory management 49 | void draw(); 50 | void setCordi(vector2f _x, vector2f _y, vector2f _z); 51 | void setCordiAlone(vector2f _x, vector2f _y, vector2f _z); 52 | void getGridNumber(int & _xGridNumPerAnix, int & _yGridNumPerAnix, int & _zGridNumPerAnix); 53 | void setGridNumber(int _xGridNumPerAnix, int _yGridNumPerAnix, int _zGridNumPerAnix); 54 | void adjustGridNumber(vector2f _x, vector2f _y, vector2f _z, RangeChange xChange, RangeChange yChange, RangeChange zChange); 55 | public: 56 | /*---------复制窗口时调用start-----------*/ 57 | void setCopyFromOtherOpenWidgetMark(GLboolean _b); 58 | GLuint getVaoGridAnixnumDgt(); 59 | GLuint getVboGridAnixnumDgt(); 60 | GLuint getVboGridAnixnumDgtTexture(); 61 | 62 | GLuint getVaoGridAnixnumPnt(); 63 | GLuint getVboGridAnixnumPnt(); 64 | GLuint getVboGridAnixnumPntTexture(); 65 | 66 | GLuint getVaoGridAnixnumMinus(); 67 | GLuint getVboGridAnixnumMinus(); 68 | GLuint getVboGridAnixnumMinusTexture(); 69 | 70 | GLuint getVaoGridAnixnumLabel(); 71 | GLuint getVboGridAnixnumLabel(); 72 | GLuint getVboGridAnixnumLabelTexture(); 73 | 74 | //Grid 75 | void setVaoGridAnixnumDgt(GLuint _gridVaoGridAnixnumDgt); 76 | void setVboGridAnixnumDgt(GLuint _gridVboGridAnixnumDgt); 77 | void setVboGridAnixnumDgtTexture(GLuint _gridVboGridAnixnumDgtTexture); 78 | 79 | void setVaoGridAnixnumPnt(GLuint _gridVaoGridAnixnumPnt); 80 | void setVboGridAnixnumPnt(GLuint _gridVboGridAnixnumPnt); 81 | void setVboGridAnixnumPntTexture(GLuint _gridVboGridAnixnumPntTexture); 82 | 83 | void setVaoGridAnixnumMinus(GLuint _gridVaoGridAnixnumMinus); 84 | void setVboGridAnixnumMinus(GLuint _gridVboGridAnixnumMinus); 85 | void setVboGridAnixnumMinusTexture(GLuint _gridVboGridAnixnumMinusTexture); 86 | 87 | void setVaoGridAnixnumLabel(GLuint _gridVaoGridAnixnumLabel); 88 | void setVboGridAnixnumLabel(GLuint _gridVboGridAnixnumLabel); 89 | void setVboGridAnixnumLabelTexture(GLuint _gridVboGridAnixnumLabelTexture); 90 | void getCordRangei(vector2f &_x, vector2f &_y, vector2f &_z); 91 | void setCordRangei(vector2f &_x, vector2f &_y, vector2f &_z); 92 | /*---------复制窗口时调用end-----------*/ 93 | private: 94 | void drawGrid(); 95 | void drawAnixNumber(); 96 | void drawAnixPoint(); 97 | void drawAnixMinus(); 98 | void drawAnixLabel(); 99 | /*getAnxiIntRange: 100 | * 函数描述:将网格坐标归为整数 101 | * 根据更改后的坐标范围[m_*range._y, m_*range._x]来调整网格数 102 | * PS:后期经过更改,去除了边界上的上边界和下边界的判断,即让MinUpper == Minf, MaxLower == Maxf. 103 | * 参数描述: 104 | * Maxf: 坐标上限 105 | * Minf: 坐标下限 106 | * MaxLower: 坐标上限 第一位非0整数部分 107 | * MinUpper: 坐标下限 第一位非0整数部分+1 108 | * front: MinUpper归一化到[0,1] 109 | * back: MaxLower归一化到[0,1] 110 | */ 111 | bool getAnxiIntRange(GLfloat Maxf, GLfloat Minf, GLfloat &MaxLower, GLfloat &MinUpper, GLfloat &front, GLfloat &back); 112 | bool getAnxiIntRange(GLfloat Maxf, GLfloat Minf, GLfloat &MaxLower, GLfloat &MinUpper); 113 | 114 | /* createAndUpdateGrid: 115 | * 函数描述: 调用createAndUpdateGrid(), createGrid(); 116 | */ 117 | void createAndUpdateGrid(); 118 | /* createGrid: 119 | * 函数描述: 创建网格数组,包含坐标和颜色; 120 | * 初始化和每次调整坐标范围后会调用该函数 121 | */ 122 | void createGrid(); 123 | /* end */ 124 | 125 | /* createGrid: 126 | * 函数描述:创建缓冲区(动态的),包含坐标和颜色 127 | * 初始化和每次调整坐标范围后会调用该函数 128 | */ 129 | void updataGrid(); 130 | /* end */ 131 | 132 | /*adjustGridNumber: 133 | * 函数描述:根据更改后的坐标范围[m_*range._y, m_*range._x]来调整网格数 134 | * 参数描述:anixGridNumberPerAnix: 需要更改的m_*GridNumPerAnix 135 | * range: 确定的坐标类型的参数 136 | */ 137 | bool adjustGridNumber(Range range, int &anixGridNumberPerAnix); 138 | /* end */ 139 | 140 | /* createAndUpdateAnixnumberWithPnt: 141 | * 函数描述:1. 根据更改后的坐标范围[m_*range._y, m_*range._x]来调整坐标值, 通过顺序调用 142 | * createAnixnumber(), updateAnixnumber(), updateAnixDecimalPnt()实现; 143 | * 2. adjustGridNumber()中会调用 144 | * 参数描述:NULL; 145 | */ 146 | void createAnixnumber(); //调用addAnxisNumber 147 | void updateAnixnumber(); 148 | void updateAnixDecimalPnt(); 149 | void updateAnixMinus(); 150 | void updateAnixLabel(); 151 | /* end */ 152 | GLboolean getIntvaluePointposOffsetForXAnix(GLfloat xAnix, GLint& xAnixValue, GLfloat& xAnixOffset, GLboolean& greaterThanOneMark); 153 | GLboolean getIntvaluePointposOffsetForYAnix(GLfloat yAnix, GLint& yAnixValue, GLfloat& yAnixOffset, GLboolean& greaterThanOneMark); 154 | GLboolean getIntvaluePointposOffsetForZAnix(GLfloat zAnix, GLint& zAnixValue, GLfloat& zAnixOffset, GLboolean& greaterThanOneMark); 155 | void addAnxisNumber(GLfloat anixNumber, Range range, GLfloat anixOffset, GLfloat size); 156 | void addAxisLabel(Range range, GLfloat axisOffset, GLfloat size); 157 | // 158 | void clearGridVector(); 159 | 160 | private: 161 | Crender* m_therender; 162 | 163 | private: 164 | DRAWTYPE m_drawtype = DRAWTYPE::XZY; 165 | CAllocVBOandVAO* m_allocVBOandVAO; //must be set at first; 166 | QOpenGLContext* m_context; 167 | QSurface* m_surface; 168 | vector2f m_x = {0,1}; //坐标X, 该参数与坐标轴有关 169 | vector2f m_y = {0,1}; //坐标Y, 该参数与坐标轴有关 170 | vector2f m_z = {0,1}; //坐标Z, 该参数与坐标轴有关 171 | vector2f m_xRange = {0.01,-0.01}; //坐标XRange 172 | vector2f m_yRange = {0.01,-0.01}; //坐标YRange 173 | vector2f m_zRange = {0.01,-0.01}; //坐标ZRange 174 | bool m_isFirstRange = true; 175 | QMatrix4x4 m_rot = { 176 | 1.0f, 0.0f, 0.0f, 0.0f, 177 | 0.0f, 1.0f, 0.0f, 0.0f, 178 | 0.0f, 0.0f, 1.0f, 0.0f, 179 | 0.0f, 0.0f, 0.0f, 1.0f, 180 | }; 181 | 182 | //建立网格 183 | vector m_gridPositions; 184 | int m_xGridNumPerAnix = 4; //x !!!Note: 生成缓冲区时应该注意当网格点数增加后,可能会导致缓冲区超界 185 | int m_yGridNumPerAnix = 4; //y 186 | int m_zGridNumPerAnix = 4; //z 187 | vector4f m_gridColor = {200/255.0f,200/255.0f,200/255.0f,1}; 188 | GLfloat m_viewScale = 1.0f;//0.7; 189 | GLuint m_vaoGrid; 190 | GLuint m_vboGrid; 191 | //建立坐标值 192 | QOpenGLTexture* m_textureDgt; //数字贴图 193 | QOpenGLTexture* m_texturePnt; //小数点贴图 194 | QOpenGLTexture* m_textureMinus; //负号贴图 195 | QOpenGLTexture* m_textureLabel; 196 | 197 | GLuint m_vaoGridAnixnumDgt; //数字VAO 198 | GLuint m_vboGridAnixnumDgt; //VBO 199 | GLuint m_vboGridAnixnumDgtTexture; //texture vbo 200 | vector m_gridAnixnumDgtPositions; //数字位置容器 201 | vector m_gridAnixnumDgtTexture; //数字Texture位置容器 202 | GLint m_DigPositionSize = -1; 203 | 204 | GLuint m_vaoGridAnixnumPnt; //小数点VAO 205 | GLuint m_vboGridAnixnumPnt; //VBO 206 | GLuint m_vboGridAnixnumPntTexture; //texture vbo 207 | vector m_gridAnixnumPntPositions; //小数点位置容器 208 | vector m_gridAnixnumPntTexture; //小数点Texture位置容器 209 | GLint m_PntPositionSize = -1; 210 | 211 | GLuint m_vaoGridAnixnumMinus; //负号VAO 212 | GLuint m_vboGridAnixnumMinus; //VBO 213 | GLuint m_vboGridAnixnumMinusTexture; //texture vbo 214 | vector m_gridAnixnumMinusPositions; //负号位置容器 215 | vector m_gridAnixnumMinusTexture; //负号Texture位置容器 216 | GLint m_MinusPositionSize = -1; 217 | 218 | GLuint m_vaoGridAnixnumLabel; //"xyz/" 219 | GLuint m_vboGridAnixnumLabel; //VBO 220 | GLuint m_vboGridAnixnumLabelTexture; //texture vbo 221 | vector m_gridAnixnumLabelPositions; //"xyz/"位置容器 222 | vector m_gridAnixnumLabelTexture; //"xyz/"Texture位置容器 223 | GLint m_LabelPositionSize = -1; 224 | 225 | 226 | 227 | CGridRender* m_gridRender; //网格的坐标值,xyz符号由该人render渲染,由外部传入 228 | 229 | vector3f m_xAnixBase = {1, 0, 0}; 230 | vector3f m_yAnixBase = {1, 0, 0}; 231 | GLfloat m_fontSize = 0.10; 232 | GLfloat m_xSize = 0.06; //0.01 233 | GLfloat m_xOffsetBits = 0; //x坐标在x轴方向的最大偏移位数 234 | GLfloat m_ySize = 0.06; //0.01 235 | GLfloat m_yOffsetBits = 0; //y坐标在x轴方向的最大偏移位数 236 | GLfloat m_zSize = 0.06; //0.01 237 | GLfloat m_offset = 0.02; 238 | vector4f m_color = {51/255.0f,221/255.0f,255/255.0f,1}; 239 | GLint m_precision = 3; 240 | vector m_anixNumber; 241 | GLint m_tensNumber; 242 | //开关 243 | GLboolean m_gridOn = true; 244 | GLboolean m_anixLabelOn = true; 245 | GLboolean m_anixLabelNotEmpty = true; 246 | //PosisitonChange 247 | GLfloat m_zOffsetForDrawType = 0; // x,z 248 | 249 | GLboolean m_notCopyFromOtherOpenGLWidget = true; 250 | 251 | }; 252 | 253 | #endif // CGRID_H 254 | -------------------------------------------------------------------------------- /GridAndAxis/textureindex.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTUREINDEX_H 2 | #define TEXTUREINDEX_H 3 | //保存网格数字,小数点,负号,xyz的texture索引信息 4 | //数字Index 5 | const float digitsIndex[80] = 6 | { 7 | //0 8 | 0.734375, 0.265625, 9 | 0.734375, 0.015625, 10 | 0.921875, 0.015625, 11 | 0.921875, 0.265625, 12 | //1 13 | 0.1875, 0.984375, 14 | 0.1875, 0.734375, 15 | 0.375, 0.734375, 16 | 0.375, 0.984375, 17 | //2 18 | 0.421875, 0.984375, 19 | 0.421875, 0.734375, 20 | 0.609375, 0.734375, 21 | 0.609375, 0.984375, 22 | //3 23 | 0.640625, 0.984375, 24 | 0.640625, 0.734375, 25 | 0.828125, 0.734375, 26 | 0.828125, 0.984375, 27 | //4 28 | 0.1875, 0.625, 29 | 0.1875, 0.375, 30 | 0.375, 0.375, 31 | 0.375, 0.625, 32 | //5 33 | 0.421875, 0.625, 34 | 0.421875, 0.375, 35 | 0.609375, 0.375, 36 | 0.609375, 0.625, 37 | //6 38 | 0.640625, 0.625, 39 | 0.640625, 0.3755, 40 | 0.828125, 0.375, 41 | 0.828125, 0.625, 42 | //7 43 | 0.078125, 0.265625, 44 | 0.078125, 0.015625, 45 | 0.265625, 0.015625, 46 | 0.265625, 0.265625, 47 | //8 48 | 0.296875, 0.265625, 49 | 0.296875, 0.015625, 50 | 0.484375, 0.015625, 51 | 0.484375, 0.265625, 52 | //9 53 | 0.515625, 0.265625, 54 | 0.515625, 0.015625, 55 | 0.703125, 0.015625, 56 | 0.703125, 0.265625 57 | }; 58 | //小数点, 负号索引 59 | const float pointIndex[8] = { 60 | 0, 1, 61 | 0, 0, 62 | 1, 0, 63 | 1, 1 64 | }; 65 | //xyz的texture索引信息 66 | const float labelIndex[32] = { 67 | //x 68 | 0.0, 1.0, 69 | 0.0, 0.5, 70 | 0.33, 0.5, 71 | 0.33, 1.0, 72 | //y 73 | 0.33, 1.0, 74 | 0.33, 0.5, 75 | 0.66, 0.5, 76 | 0.66, 1.0, 77 | //z 78 | 0.66, 1.0, 79 | 0.66, 0.5, 80 | 1.0, 0.5, 81 | 1.0, 1.0, 82 | //"/" 83 | 0.0, 0.5, 84 | 0.0, 0.0, 85 | 0.35, 0.0, 86 | 0.35, 0.5 87 | }; 88 | 89 | #endif // TEXTUREINDEX_H 90 | -------------------------------------------------------------------------------- /Img/decimal_point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Img/decimal_point.png -------------------------------------------------------------------------------- /Img/digit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Img/digit.png -------------------------------------------------------------------------------- /Img/digit1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Img/digit1.png -------------------------------------------------------------------------------- /Img/labels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Img/labels.png -------------------------------------------------------------------------------- /Img/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Img/minus.png -------------------------------------------------------------------------------- /MyOpenglWidget/Chart.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define u_short ushort 3 | #include "MyOpenglWidget/Clines.h" 4 | #include "DataManageMent/CAllocVBOandVAO.h" 5 | #include "Renders/Crender.h" 6 | #include "Renders/CGridRender.h" 7 | #include "Renders/CLinesRender.h" 8 | 9 | #include "GridAndAxis/Anix.h" 10 | #include "GridAndAxis/CGrid.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace std; 19 | class CChart : protected QOpenGLFunctions_4_3_Core 20 | { 21 | public: 22 | enum DRAWTYPE { 23 | XZY = 0, 24 | XY, 25 | XZ, 26 | YZ 27 | }; 28 | CChart(); 29 | ~CChart(); 30 | void initial(vector3f _location, QOpenGLContext* _context, QSurface* _surface); 31 | 32 | void draw(); 33 | void clearUp(); 34 | size_t addLine(size_t _lineIndex, size_t _pointsize); 35 | bool addPoint(size_t _lineindex, const vector3f& _position/*, QOpenGLContext *_context*/); 36 | void updateChart(); //????chart 37 | void setAlloc(CAllocVBOandVAO* allocVBOandVAO); 38 | void setRot(float _x, float _y/*, float _z*/); //旋转 39 | void setRotAlone(float _x, float _y, float _z); 40 | // void setXrange(float _max, float _min); 41 | // void setYrange(float _max, float _min); 42 | // void setZrange(float _max, float _min); 43 | void setZoom(float _zoom); 44 | void setMove(float _x,float _y); //平移 45 | void setDrawType(DRAWTYPE _type); 46 | void setColor(size_t _lineIndex, vector4f _color); 47 | void setGridOnOrOff(); 48 | void setGridOnOrOff(bool _b); 49 | void setAnixLabelOnOrOff(); 50 | void setAxisPrecision(GLint _precision); 51 | 52 | void setLineXYPlaneOn(/*GLboolean _b*/); 53 | void setLineXZPlaneOn(); 54 | void setLineYZPlaneOn(); 55 | 56 | void setWidthAndHeight(size_t width, size_t height); 57 | 58 | void setFontSize(GLfloat _fontSize = 6.0f); 59 | 60 | /*---------复制窗口时调用start-----------*/ 61 | void setCopyFromOtherOpenWidgetMark(GLboolean _b); 62 | //Anix 63 | GLuint getAnixVao(); 64 | GLuint getAnixVbo(); 65 | GLuint getAnixVboIndex(); 66 | //Grid 67 | GLuint getVaoGridAnixnumDgt(); 68 | GLuint getVboGridAnixnumDgt(); 69 | GLuint getVboGridAnixnumDgtTexture(); 70 | 71 | GLuint getVaoGridAnixnumPnt(); 72 | GLuint getVboGridAnixnumPnt(); 73 | GLuint getVboGridAnixnumPntTexture(); 74 | 75 | GLuint getVaoGridAnixnumMinus(); 76 | GLuint getVboGridAnixnumMinus(); 77 | GLuint getVboGridAnixnumMinusTexture(); 78 | 79 | GLuint getVaoGridAnixnumLabel(); 80 | GLuint getVboGridAnixnumLabel(); 81 | GLuint getVboGridAnixnumLabelTexture(); 82 | //lines 83 | list getLinesVao(); 84 | list getLinesVbo(); 85 | 86 | //Anix 87 | void setAnixVboBuffer(vector &_anixVboBuffer); 88 | void setAnixVboIndexBuffer(vector &_anixVboIndexBuffer); 89 | //Grid 90 | void setVaoGridAnixnumDgt(GLuint _gridVaoGridAnixnumDgt); 91 | void setVboGridAnixnumDgt(GLuint _gridVboGridAnixnumDgt); 92 | void setVboGridAnixnumDgtTexture(GLuint _gridVboGridAnixnumDgtTexture); 93 | 94 | void setVaoGridAnixnumPnt(GLuint _gridVaoGridAnixnumPnt); 95 | void setVboGridAnixnumPnt(GLuint _gridVboGridAnixnumPnt); 96 | void setVboGridAnixnumPntTexture(GLuint _gridVboGridAnixnumPntTexture); 97 | 98 | void setVaoGridAnixnumMinus(GLuint _gridVaoGridAnixnumMinus); 99 | void setVboGridAnixnumMinus(GLuint _gridVboGridAnixnumMinus); 100 | void setVboGridAnixnumMinusTexture(GLuint _gridVboGridAnixnumMinusTexture); 101 | 102 | void setVaoGridAnixnumLabel(GLuint _gridVaoGridAnixnumLabel); 103 | void setVboGridAnixnumLabel(GLuint _gridVboGridAnixnumLabel); 104 | void setVboGridAnixnumLabelTexture(GLuint _gridVboGridAnixnumLabelTexture); 105 | //lines 106 | void setLinesVao(list _linesVaos); 107 | void setLinesVbo(list _linesVbos); 108 | 109 | void getCordRangei(vector2f &_x, vector2f &_y, vector2f &_z); 110 | void setCordRangei(vector2f &_x, vector2f &_y, vector2f &_z); 111 | void getRotation(QMatrix4x4 & _rotation); 112 | void setRotation(QMatrix4x4 & _rotation); 113 | void getMove(QMatrix4x4 & _move); 114 | void setMove(QMatrix4x4 & _move); 115 | void setDrawTypeAlone(CChart::DRAWTYPE &_type); 116 | //void setDrawTypeFo(CChart::DRAWTYPE &_type); 117 | void getDrawType(DRAWTYPE & _type); 118 | void getGridNumer(int & _xGridNumPerAnix, int & _yGridNumPerAnix, int & _zGridNumPerAnix); 119 | void setGridNumer(int _xGridNumPerAnix, int _yGridNumPerAnix, int _zGridNumPerAnix); 120 | void setLinesVboBufferData(list > & _linesBuffer, vector &_linesAmount); 121 | map getLineColor(); 122 | void setLineColor(map &_lineColors); 123 | vector getLinesPointsAmount(); 124 | 125 | void updateLines(); 126 | /*---------复制窗口时调用end-----------*/ 127 | 128 | bool checkRangeChange(vector2f& _xRange, vector2f& _yRange, vector2f& _zRange); 129 | 130 | void setLinesEnabled(size_t _lineIndex, bool _b); 131 | protected: 132 | void setDrawAnx(); 133 | void setDrawLine(vector4f &_lineColor); 134 | DRAWTYPE m_drawtype = XZY; 135 | float m_zoom = 1; 136 | QMatrix4x4 m_rotation = { 137 | 1, 0, 0, 0, 138 | 0, 1, 0, 0, 139 | 0, 0, 1, 0, 140 | 0, 0, 0, 1 141 | }; 142 | vector2f m_xRange = {1,0}; 143 | vector2f m_yRange = {1,0}; 144 | vector2f m_zRange = {1,0}; 145 | CGrid::RangeChange m_xRanChange = CGrid::RangeChange::NotChange; 146 | CGrid::RangeChange m_yRanChange = CGrid::RangeChange::NotChange; 147 | CGrid::RangeChange m_zRanChange = CGrid::RangeChange::NotChange; 148 | 149 | QMatrix4x4 m_move = { 150 | 1, 0, 0, 0, 151 | 0, 1, 0, 0, 152 | 0, 0, 1, 0, 153 | 0, 0, 0, 1 154 | }; 155 | vector3f m_basecord = {0.0f, 0.0f, 0.0f}; //被遗弃了 156 | 157 | QMatrix4x4 m_projection = { 158 | 1, 0, 0, 0, 159 | 0, 1, 0, 0, 160 | 0, 0, 1, 0, 161 | 0, 0, 0, 1 162 | }; 163 | float m_viewLineFactor = 1.0f; 164 | vector4f m_lineColor = {1.0f, 0.0f, 0.0f, 1.0f}; 165 | 166 | map m_isFirstPoint; 167 | //vector* m_isFirstPoint = new vector; 168 | 169 | 170 | 171 | private: 172 | CGrid m_grid; 173 | GLboolean m_gridOn = true; 174 | GLboolean m_anixLabelOn = true; 175 | QSurface* m_surface; 176 | QOpenGLContext* m_context; 177 | bool m_isfirstdata; 178 | vector3f m_cordOrigin = {0,0,0}; //??????? 179 | Crender m_therender; 180 | CGridRender m_gridRender; 181 | CLinesRender m_linesRender; 182 | 183 | CAnix m_anix; 184 | map m_lines; 185 | map m_linesEnabled; 186 | //vector m_lines; 187 | vector3f m_scale = { 0,0,0 }; 188 | vector3f m_maxpoints = { 0,0,0 }; //????��?????(????????) 189 | vector3f m_minpoints = { 0,0,0 }; //????��???��??(????????) 190 | bool m_scalechange = false; 191 | int m_shadermin; //????uniform 192 | int m_shadermax; //??��??uniform 193 | GLuint m_vao; 194 | GLuint m_lineBuffer; //???????? 195 | CAllocVBOandVAO* m_allocVBOandVAO; 196 | 197 | protected: 198 | //CRender 199 | GLuint m_uniformIndexChosePntAnixGrid; 200 | GLuint m_uniformIndexRangeXPntAnixGrid; 201 | GLuint m_uniformIndexRangeYPntAnixGrid; 202 | GLuint m_uniformIndexRangeZPntAnixGrid; 203 | GLuint m_uniformIndexScalePntAnixGrid; 204 | GLuint m_uniformIndexRotPntAnixGrid; 205 | GLuint m_uniformIndexMovePntAnixGrid; //??????????? 206 | GLuint m_uniformIndexBasecordPntAnixGrid; 207 | GLuint m_uniformIndexDrawtypePntAnixGrid; //????????? 208 | GLuint m_uniformIndexProjectionPntAnixGrid; 209 | GLuint m_uniformIndexViewLinefactorPntAnixGrid; 210 | GLuint m_uniformIndexLineColorPntAnixGrid; 211 | //CLinesRender 212 | GLuint m_uniformIndexChosePntAnixGridForLines; 213 | GLuint m_uniformIndexRangeXPntAnixGridForLines; 214 | GLuint m_uniformIndexRangeYPntAnixGridForLines; 215 | GLuint m_uniformIndexRangeZPntAnixGridForLines; 216 | GLuint m_uniformIndexScalePntAnixGridForLines; 217 | GLuint m_uniformIndexRotPntAnixGridForLines; 218 | GLuint m_uniformIndexMovePntAnixGridForLines; //??????????? 219 | GLuint m_uniformIndexBasecordPntAnixGridForLines; 220 | GLuint m_uniformIndexDrawtypePntAnixGridForLines; //????????? 221 | GLuint m_uniformIndexProjectionPntAnixGridForLines; 222 | GLuint m_uniformIndexViewLinefactorPntAnixGridForLines; 223 | GLuint m_uniformIndexLineColorPntAnixGridForLines; 224 | GLuint m_uniformIndexXyPlaneMarkForLines; 225 | GLuint m_uniformIndexXzPlaneMarkForLines; 226 | GLuint m_uniformIndexYzPlaneMarkForLines; 227 | GLuint m_uniformIndexXLowerForLines; 228 | GLuint m_uniformIndexYLowerForLines; 229 | GLuint m_uniformIndexZLowerForLines; 230 | //GridRender for texture; 231 | GLuint m_uniformIndexScaleAnixtexture; 232 | GLuint m_uniformIndexMoveAnixtexture; 233 | GLuint m_uniformIndexBasecordAnixtexture; 234 | GLuint m_uniformIndexProjectionAnixtexture; 235 | GLuint m_uniformIndexRotAnixtexture; 236 | GLuint m_uniformIndexDrawtypeAnixtexture; 237 | GLuint m_uniformIndexRangeXAnixtexture; 238 | GLuint m_uniformIndexRangeYAnixtexture; 239 | GLuint m_uniformIndexRangeZAnixtexture; 240 | // GLuint m_uniformIndexRotAnixtexture; 241 | 242 | bool m_stataChange=true; //???????? 243 | bool m_RangeChange = false; 244 | GLboolean m_notCopyFromOtherOpenGLWidget = true; 245 | list m_lineVaos; 246 | list m_lineVbos; 247 | //GLboolean m_isFirstData = true; 248 | GLboolean m_first2Two = false; 249 | GLfloat sdfsfsfsd = 1/ 3.0f; 250 | size_t m_width; 251 | size_t m_height; 252 | }; 253 | 254 | -------------------------------------------------------------------------------- /MyOpenglWidget/Clines.cpp: -------------------------------------------------------------------------------- 1 | #include "MyOpenglWidget/Clines.h" 2 | 3 | 4 | 5 | Clines::Clines(CAllocVBOandVAO *allocVBOandVAO) 6 | : m_shadermin(0), 7 | m_shadermax(0) 8 | { 9 | m_allocVBOandVAO = allocVBOandVAO; 10 | } 11 | 12 | 13 | Clines::~Clines() 14 | { 15 | this->clearUp(); 16 | } 17 | 18 | void Clines::initial(CLinesRender * _render, size_t _pointsize, QOpenGLContext* _context) 19 | { 20 | initializeOpenGLFunctions(); 21 | 22 | m_linesRender = _render; 23 | m_pointSize = _pointsize; 24 | m_context = _context; 25 | m_context->makeCurrent(m_context->surface()); 26 | m_persize = sizeof(vector3f);//位置3+颜色4 27 | 28 | //顶点坐标绑定 29 | m_vao = m_allocVBOandVAO->allocVAO(); 30 | glBindVertexArray(m_vao); 31 | m_vbo = m_allocVBOandVAO->allocVBO(); 32 | glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 33 | glBufferData(GL_ARRAY_BUFFER, 34 | m_pointSize * m_persize, //颜色和位置 35 | nullptr, 36 | GL_DYNAMIC_DRAW); 37 | 38 | //glEnableVertexAttribArray(2); //法相坐标 39 | glVertexAttribPointer(0, 40 | 3, 41 | GL_FLOAT, 42 | GL_FALSE, 43 | m_persize, 44 | nullptr); 45 | glEnableVertexAttribArray(0); //顶点坐标属性 46 | 47 | glBindBuffer(GL_ARRAY_BUFFER, 0); 48 | glBindVertexArray(0); 49 | //glColor3f(1, 1, 0); 50 | 51 | if(!m_notCopyFromOtherOpenGLWidget) 52 | { //updateLines(); 53 | setLinesVboBufferData(); 54 | //drawOnce(); 55 | } 56 | 57 | } 58 | 59 | void Clines::setRenderParam(GLuint _uniformIndexXyPlaneMarkForLines, GLuint _uniformIndexXzPlaneMarkForLines, GLuint _uniformIndexYzPlaneMarkForLines, GLuint _uniformIndexXLowerForLines, GLuint _uniformIndexYLowerForLines, GLuint _uniformIndexZLowerForLines) 60 | { 61 | m_uniformIndexXyPlaneMarkForLines = _uniformIndexXyPlaneMarkForLines; 62 | m_uniformIndexXzPlaneMarkForLines = _uniformIndexXzPlaneMarkForLines; 63 | m_uniformIndexYzPlaneMarkForLines = _uniformIndexYzPlaneMarkForLines; 64 | m_uniformIndexXLowerForLines = _uniformIndexXLowerForLines; 65 | m_uniformIndexYLowerForLines = _uniformIndexYLowerForLines; 66 | m_uniformIndexZLowerForLines = _uniformIndexZLowerForLines; 67 | } 68 | 69 | 70 | void Clines::addLine(const vector3f & _posion, GLfloat _xLower, GLfloat _yLower, GLfloat _zLower) 71 | { 72 | m_xLower = _xLower; 73 | m_yLower = _yLower; 74 | m_zLower = _zLower; 75 | m_context->makeCurrent(m_context->surface()); 76 | 77 | if (m_pointCount >= m_pointSize) 78 | { 79 | QMessageBox::information(NULL, "points", 80 | "存储点数到达最大值", 81 | QMessageBox::Yes | QMessageBox::No, 82 | QMessageBox::Yes); 83 | m_pointCount = 0; 84 | return; 85 | } 86 | glBindVertexArray(m_vao); 87 | glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 88 | glBufferSubData(GL_ARRAY_BUFFER, 89 | m_pointCount * m_persize, 90 | sizeof(vector3f), 91 | (GLvoid*)&_posion); 92 | //qDebug() << "1: " << (m_pointCount) * m_persize; 93 | glBindBuffer(GL_ARRAY_BUFFER, 0); 94 | glBindVertexArray(0); 95 | 96 | ++m_pointCount; 97 | 98 | } 99 | 100 | void Clines::setXYPlaneOn(/*GLboolean _b*/) 101 | { 102 | if(m_XYPlaneOn) 103 | { 104 | m_XYPlaneOn = false; 105 | } 106 | else 107 | { 108 | m_XYPlaneOn = true; 109 | } 110 | // m_XYPlaneOn = _b; 111 | } 112 | 113 | void Clines::setXZPlaneOn(/*GLboolean _b*/) 114 | { 115 | if(m_XZPlaneOn) 116 | { 117 | m_XZPlaneOn = false; 118 | } 119 | else 120 | { 121 | m_XZPlaneOn = true; 122 | } 123 | //m_XZPlaneOn = _b; 124 | } 125 | 126 | void Clines::setYZPlaneOn(/*GLboolean _b*/) 127 | { 128 | if(m_YZPlaneOn) 129 | { 130 | m_YZPlaneOn = false; 131 | } 132 | else 133 | { 134 | m_YZPlaneOn = true; 135 | } 136 | // m_YZPlaneOn = _b; 137 | } 138 | 139 | void Clines::setLinesVboBufferData() 140 | { 141 | // if(m_copyVboBuffer.size() != 0) 142 | // qDebug() << m_copyVboBuffer.at(0) << " " << m_copyVboBuffer.size(); 143 | // qDebug() << m_context; 144 | m_context->makeCurrent(m_context->surface()); 145 | glBindVertexArray(m_vao); 146 | glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 147 | glBufferSubData(GL_ARRAY_BUFFER, 148 | 0, 149 | m_pointCount * sizeof(vector3f), 150 | m_copyVboBuffer.data()); 151 | glBindBuffer(GL_ARRAY_BUFFER, 0); 152 | glBindVertexArray(0); 153 | 154 | //qDebug() << m_pointCount; 155 | } 156 | 157 | 158 | 159 | GLuint Clines::getLinesVao() 160 | { 161 | return m_vao; 162 | } 163 | 164 | GLuint Clines::getLinesVbo() 165 | { 166 | return m_vbo; 167 | } 168 | 169 | size_t Clines::getPointsAmout() const 170 | { 171 | return m_pointCount; 172 | } 173 | 174 | void Clines::setLinesVao(GLuint _linesVaos) 175 | { 176 | m_vao = _linesVaos; 177 | } 178 | 179 | void Clines::setLinesVbo(GLuint _linesVbos) 180 | { 181 | m_vbo = _linesVbos; 182 | } 183 | 184 | void Clines::setLinesVboBufferData(vector &_linesBuffer, size_t _linesAmount) 185 | { 186 | m_notCopyFromOtherOpenGLWidget = false; 187 | m_copyVboBuffer = _linesBuffer; 188 | m_pointCount = _linesAmount; 189 | //setLinesVboBufferData(); 190 | //qDebug() << m_copyVboBuffer.size(); 191 | } 192 | 193 | void Clines::updateLines() 194 | { 195 | setLinesVboBufferData(); 196 | } 197 | 198 | void Clines::setLowers(GLfloat _xLower, GLfloat _yLower, GLfloat _zLower) 199 | { 200 | m_xLower = _xLower; 201 | m_yLower = _yLower; 202 | m_zLower = _zLower; 203 | } 204 | 205 | void Clines::draw() 206 | { 207 | //qDebug() << "m_pointCount: " << m_pointCount; 208 | m_context->makeCurrent(m_context->surface()); 209 | m_linesRender->bindShader(); 210 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXyPlaneMarkForLines, false); 211 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXzPlaneMarkForLines, false); 212 | m_linesRender->getShader()->setUniformValue(m_uniformIndexYzPlaneMarkForLines, false); 213 | glBindVertexArray(m_vao); 214 | glLineWidth(1.5); 215 | glDrawArrays(GL_LINE_STRIP, 0, m_pointCount); 216 | glBindVertexArray(0); 217 | 218 | if(m_XYPlaneOn) 219 | { 220 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXyPlaneMarkForLines, true); 221 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXzPlaneMarkForLines, false); 222 | m_linesRender->getShader()->setUniformValue(m_uniformIndexYzPlaneMarkForLines, false); 223 | m_linesRender->getShader()->setUniformValue(m_uniformIndexZLowerForLines, m_zLower); 224 | glBindVertexArray(m_vao); 225 | glLineWidth(1); 226 | glDrawArrays(GL_LINE_STRIP, 0, m_pointCount); 227 | glBindVertexArray(0); 228 | } 229 | 230 | if(m_XZPlaneOn) 231 | { 232 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXyPlaneMarkForLines, false); 233 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXzPlaneMarkForLines, true); 234 | m_linesRender->getShader()->setUniformValue(m_uniformIndexYzPlaneMarkForLines, false); 235 | m_linesRender->getShader()->setUniformValue(m_uniformIndexYLowerForLines, m_yLower); 236 | glBindVertexArray(m_vao); 237 | glLineWidth(1); 238 | glDrawArrays(GL_LINE_STRIP, 0, m_pointCount); 239 | glBindVertexArray(0); 240 | } 241 | 242 | if(m_YZPlaneOn) 243 | { 244 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXyPlaneMarkForLines, false); 245 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXzPlaneMarkForLines, false); 246 | m_linesRender->getShader()->setUniformValue(m_uniformIndexYzPlaneMarkForLines, true); 247 | m_linesRender->getShader()->setUniformValue(m_uniformIndexXLowerForLines, m_xLower); 248 | glBindVertexArray(m_vao); 249 | glLineWidth(1); 250 | glDrawArrays(GL_LINE_STRIP, 0, m_pointCount); 251 | glBindVertexArray(0); 252 | } 253 | 254 | 255 | m_linesRender->releaseShader(); 256 | } 257 | 258 | void Clines::drawOnce() 259 | { 260 | m_context->makeCurrent(m_context->surface()); 261 | m_linesRender->bindShader(); 262 | glBindVertexArray(m_vao); 263 | glLineWidth(1.5); 264 | glDrawArrays(GL_LINE_STRIP, 0, m_pointCount); 265 | glBindVertexArray(0); 266 | m_linesRender->releaseShader(); 267 | } 268 | 269 | void Clines::clearUp() 270 | { 271 | } 272 | 273 | void Clines::setColor(vector4f color) 274 | { 275 | m_color._r = color._r; 276 | m_color._g = color._g; 277 | m_color._b = color._b; 278 | m_color._a = color._a; 279 | } 280 | 281 | vector4f Clines::getColor() const 282 | { 283 | return m_color; 284 | } 285 | 286 | 287 | 288 | -------------------------------------------------------------------------------- /MyOpenglWidget/Clines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Renders/CLinesRender.h" 3 | #include "Renders/Crender.h" 4 | #include "DataManageMent/CAllocVBOandVAO.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | //#include 13 | 14 | typedef float SPFLOAT; 15 | class Crender; 16 | struct vector2f 17 | { 18 | SPFLOAT _x, _y; 19 | }; 20 | struct vector3f 21 | { 22 | SPFLOAT _x, _y, _z; 23 | }; 24 | struct vector4f 25 | { 26 | SPFLOAT _r, _g, _b, _a; 27 | public: 28 | void operator =(vector4f b) 29 | { 30 | _r = b._r; 31 | _g = b._g; 32 | _b = b._b; 33 | _a = b._a; 34 | } 35 | }; 36 | struct vector4b 37 | { 38 | GLubyte _r, _g, _b, _a; 39 | }; 40 | 41 | class Clines:private QOpenGLFunctions_4_3_Core 42 | { 43 | public: 44 | enum Attribute 45 | { 46 | LINE_POSITION, 47 | LINE_COLOUR, 48 | LINE_INDEX 49 | }; 50 | Clines(CAllocVBOandVAO* allocVBOandVAO); //必须获取一个渲染环境 51 | ~Clines(); 52 | void initial(CLinesRender* _render, size_t _pointsize, QOpenGLContext *_context); 53 | //setRenderParam 在initial执行后立刻调用,为了能在draw阶段使用geometry shader 54 | void setRenderParam(GLuint _uniformIndexXyPlaneMarkForLines, GLuint _uniformIndexXzPlaneMarkForLines, GLuint _uniformIndexYzPlaneMarkForLines, GLuint _uniformIndexXLowerForLines, GLuint _uniformIndexYLowerForLines, GLuint _uniformIndexZLowerForLines); 55 | void draw(); 56 | void drawOnce(); 57 | void clearUp(); 58 | void setColor(vector4f color); 59 | vector4f getColor() const; 60 | void addLine(const vector3f& _posion, GLfloat _xLower, GLfloat _yLower, GLfloat _zLower); 61 | void setXYPlaneOn(); 62 | void setXZPlaneOn(); 63 | void setYZPlaneOn(); 64 | 65 | /*---------复制窗口时调用start-----------*/ 66 | void setLinesVboBufferData(); 67 | GLuint getLinesVao(); 68 | GLuint getLinesVbo(); 69 | //lines 70 | size_t getPointsAmout() const; 71 | void setLinesVao(GLuint _linesVaos); 72 | void setLinesVbo(GLuint _linesVbos); 73 | void setLinesVboBufferData(vector & _linesBuffer, size_t _linesAmount); 74 | void updateLines(); 75 | void setLowers(GLfloat _xLower, GLfloat _yLower, GLfloat _zLower); 76 | /*---------复制窗口时调用end-----------*/ 77 | private: 78 | 79 | GLboolean xyMark = true; 80 | GLboolean xzMark = true; 81 | GLboolean yzMark = true; 82 | 83 | private: 84 | 85 | //Crender* m_therender; 86 | CLinesRender* m_linesRender; 87 | int m_shadermin; //最大点uniform 88 | int m_shadermax; //最小点uniform 89 | private : 90 | GLuint m_vao; 91 | vector4f m_color = {1, 0, 0, 1}; 92 | GLuint m_vbo; //顶点数组 93 | size_t m_pointCount = 0; //记录顶点数据个数 94 | size_t m_pointSize; 95 | size_t m_persize; //每一个内存段大小 96 | //size_t m_draws = 0; //已经画了的点 97 | CAllocVBOandVAO* m_allocVBOandVAO; 98 | QOpenGLContext* m_context; 99 | 100 | //线段在三个方向上的分量 101 | 102 | GLfloat m_xLower = 0.0f; 103 | GLfloat m_yLower = 0.0f; 104 | GLfloat m_zLower = 0.0f; 105 | 106 | GLfloat m_zeroGate = 0.00000001f; 107 | 108 | GLboolean m_XYPlaneOn = false; 109 | GLboolean m_XZPlaneOn = false; 110 | GLboolean m_YZPlaneOn = false; 111 | 112 | GLuint m_uniformIndexXyPlaneMarkForLines; 113 | GLuint m_uniformIndexXzPlaneMarkForLines; 114 | GLuint m_uniformIndexYzPlaneMarkForLines; 115 | 116 | GLuint m_uniformIndexXLowerForLines; 117 | GLuint m_uniformIndexYLowerForLines; 118 | GLuint m_uniformIndexZLowerForLines; 119 | 120 | //复制窗口时用到的数据 121 | GLboolean m_notCopyFromOtherOpenGLWidget = true; 122 | vector m_copyVboBuffer; //复制的缓冲区数据 123 | }; 124 | 125 | -------------------------------------------------------------------------------- /MyOpenglWidget/QOpenglMain.cpp: -------------------------------------------------------------------------------- 1 | #include "MyOpenglWidget/QOpenglMain.h" 2 | 3 | QOpenglMain::QOpenglMain(u_char _frameType, CAllocVBOandVAO *callocVBOandVAO, CChart::DRAWTYPE drawType, QWidget *parent) 4 | : QOpenGLWidget(parent), 5 | m_frameType(_frameType), 6 | m_allocVBOandVAO(callocVBOandVAO) 7 | { 8 | //QOpenGLContext* tmp = context(); 9 | m_chart.setAlloc(m_allocVBOandVAO); 10 | m_drawtype = drawType; 11 | setFocusPolicy(Qt::FocusPolicy::ClickFocus); 12 | setMinimumSize(QSize(200, 200)); 13 | } 14 | 15 | size_t flushtime = 0; 16 | 17 | QOpenglMain::~QOpenglMain() 18 | { 19 | 20 | } 21 | 22 | void QOpenglMain::setColor(size_t _lineIndex, vector4f _color) 23 | { 24 | m_chart.setColor(_lineIndex, _color); 25 | this->update(); 26 | } 27 | 28 | bool QOpenglMain::addPoint(size_t _lineindex, const vector3f & _posion) 29 | { 30 | if(m_notCopyFromOtherOpenGLWidget) 31 | return m_chart.addPoint(_lineindex, _posion/*, context()*/); 32 | 33 | } 34 | 35 | void QOpenglMain::setGridOnOrOff() 36 | { 37 | m_chart.setGridOnOrOff(); 38 | this->update(); 39 | } 40 | 41 | void QOpenglMain::setGridOnOrOff(bool _b) 42 | { 43 | m_chart.setGridOnOrOff(_b); 44 | this->update(); 45 | } 46 | 47 | void QOpenglMain::setAnixLabelOnOrOff() 48 | { 49 | m_chart.setAnixLabelOnOrOff(); 50 | this->update(); 51 | } 52 | 53 | void QOpenglMain::setAxisPrecision(GLint _precision) 54 | { 55 | m_chart.setAxisPrecision(_precision); 56 | } 57 | 58 | void QOpenglMain::setLineXYPlaneOn(/*GLboolean _b*/) 59 | { 60 | m_chart.setLineXYPlaneOn(/*_b*/); 61 | this->update(); 62 | } 63 | 64 | void QOpenglMain::setLineXZPlaneOn(/*GLboolean _b*/) 65 | { 66 | m_chart.setLineXZPlaneOn(/*_b*/); 67 | this->update(); 68 | } 69 | 70 | void QOpenglMain::setLineYZPlaneOn(/*GLboolean _b*/) 71 | { 72 | m_chart.setLineYZPlaneOn(/*_b*/); 73 | this->update(); 74 | } 75 | 76 | void QOpenglMain::setLinesEnabled(size_t _lineIndex, bool _b) 77 | { 78 | m_chart.setLinesEnabled(_lineIndex, _b); 79 | this->update(); 80 | } 81 | 82 | void QOpenglMain::setCopyFromOtherOpenWidgetMark(GLboolean _b) 83 | { 84 | m_notCopyFromOtherOpenGLWidget = _b; 85 | m_chart.setCopyFromOtherOpenWidgetMark(_b); 86 | } 87 | 88 | void QOpenglMain::getAllVaoAndVboAndVboIndex() 89 | { 90 | //anix 91 | getAnixVao(); 92 | getAnixVbo(); 93 | getAnixVboIndex(); 94 | //grid 95 | getVaoGridAnixnumDgt(); 96 | getVboGridAnixnumDgt(); 97 | getVboGridAnixnumDgtTexture(); 98 | 99 | getVaoGridAnixnumPnt(); 100 | getVboGridAnixnumPnt(); 101 | getVboGridAnixnumPntTexture(); 102 | 103 | getVaoGridAnixnumMinus(); 104 | getVboGridAnixnumMinus(); 105 | getVboGridAnixnumMinusTexture(); 106 | 107 | getVaoGridAnixnumLabel(); 108 | getVboGridAnixnumLabel(); 109 | getVboGridAnixnumLabelTexture(); 110 | //lines 111 | getLinesVao(); 112 | getLinesVbo(); 113 | } 114 | 115 | VaoVbos QOpenglMain::getVaoAndVbos() 116 | { 117 | return m_vaoVbos; 118 | } 119 | 120 | void QOpenglMain::setVaoAndVbosBuffer(vector& _anixVboBuffer, vector& _anixVboIndexBuffer) 121 | { 122 | if(!m_notCopyFromOtherOpenGLWidget) 123 | { 124 | m_chart.setAnixVboBuffer(_anixVboBuffer); 125 | m_chart.setAnixVboIndexBuffer(_anixVboIndexBuffer); 126 | } 127 | else 128 | { 129 | QMessageBox::information(NULL, "QOpenGLMain", 130 | "必须先设置窗口拷贝标志m_notCopyFromOtherOpenGLWidget=false", 131 | QMessageBox::Yes | QMessageBox::No, 132 | QMessageBox::Yes); 133 | } 134 | } 135 | 136 | vector &QOpenglMain::getAnixVboIndexBufferData() 137 | { 138 | glBindVertexArray(m_vaoVbos.m_anixVao); 139 | glBindBuffer(GL_ARRAY_BUFFER, m_vaoVbos.m_anixVboIndex); 140 | GLint size = 0; 141 | glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 142 | m_vboIndexData.resize(size / sizeof(GLuint)); 143 | glGetBufferSubData(GL_ARRAY_BUFFER, 0, size, m_vboIndexData.data()); 144 | return m_vboIndexData; 145 | } 146 | 147 | void QOpenglMain::getLinesVboBufferData(list > & _linesBuffer, vector & _linesPointAmout) 148 | { 149 | _linesPointAmout = m_chart.getLinesPointsAmount(); 150 | vector tmpVboBuffer; 151 | list::iterator itVaos = m_vaoVbos.m_linesVaos.begin(); 152 | //GLint size = 0; 153 | int count = 0; 154 | for(list >::iterator it = _linesBuffer.begin(); it != _linesBuffer.end(); ++it) 155 | { 156 | (*it).clear(); 157 | } 158 | _linesBuffer.clear(); 159 | int size = 0; 160 | for(list::iterator it = m_vaoVbos.m_linesVbos.begin(); it != m_vaoVbos.m_linesVbos.end(); ++it) 161 | { 162 | glBindVertexArray(*itVaos); 163 | glBindBuffer(GL_ARRAY_BUFFER, *it); 164 | size = _linesPointAmout.at(count); 165 | tmpVboBuffer.resize(size * 3); 166 | glGetBufferSubData(GL_ARRAY_BUFFER, 0, size * sizeof(vector3f), tmpVboBuffer.data()); 167 | _linesBuffer.push_back(tmpVboBuffer); 168 | ++itVaos; 169 | count++; 170 | } 171 | } 172 | 173 | void QOpenglMain::setLinesVboBufferData(list > &_linesBuffer, vector & _linesAmount) 174 | { 175 | m_chart.setLinesVboBufferData(_linesBuffer, _linesAmount); 176 | 177 | } 178 | 179 | void QOpenglMain::getCordRangei(vector2f &_x, vector2f &_y, vector2f &_z) 180 | { 181 | m_chart.getCordRangei(_x, _y, _z); 182 | } 183 | 184 | void QOpenglMain::setCordRangei(vector2f &_x, vector2f &_y, vector2f &_z) 185 | { 186 | m_chart.setCordRangei(_x, _y, _z); 187 | } 188 | 189 | void QOpenglMain::getRotation(QMatrix4x4 &_rotation) 190 | { 191 | m_chart.getRotation(_rotation); 192 | } 193 | 194 | void QOpenglMain::setRotation(QMatrix4x4 &_rotation) 195 | { 196 | m_chart.setRotation(_rotation); 197 | } 198 | 199 | void QOpenglMain::getMove(QMatrix4x4 &_move) 200 | { 201 | m_chart.getMove(_move); 202 | } 203 | 204 | void QOpenglMain::setMove(QMatrix4x4 &_move) 205 | { 206 | m_chart.setMove(_move); 207 | } 208 | 209 | void QOpenglMain::setDrawType(CChart::DRAWTYPE _type) 210 | { 211 | m_drawtype = _type; 212 | m_chart.setDrawTypeAlone(_type); 213 | } 214 | 215 | void QOpenglMain::getDrawType(CChart::DRAWTYPE &_type) 216 | { 217 | m_chart.getDrawType(_type); 218 | } 219 | 220 | void QOpenglMain::getGridNumer(int &_xGridNumPerAnix, int &_yGridNumPerAnix, int &_zGridNumPerAnix) 221 | { 222 | m_chart.getGridNumer(_xGridNumPerAnix, _yGridNumPerAnix, _zGridNumPerAnix); 223 | } 224 | 225 | void QOpenglMain::setGridNumer(int _xGridNumPerAnix, int _yGridNumPerAnix, int _zGridNumPerAnix) 226 | { 227 | m_chart.setGridNumer(_xGridNumPerAnix, _yGridNumPerAnix, _zGridNumPerAnix); 228 | } 229 | 230 | void QOpenglMain::getLineColor(map &_lineColor) 231 | { 232 | _lineColor = m_chart.getLineColor(); 233 | } 234 | 235 | void QOpenglMain::setLineColor(map &_lineColor) 236 | { 237 | m_chart.setLineColor(_lineColor); 238 | } 239 | 240 | vector &QOpenglMain::getAnixVboBufferData() 241 | { 242 | glBindVertexArray(m_vaoVbos.m_anixVao); 243 | glBindBuffer(GL_ARRAY_BUFFER, m_vaoVbos.m_anixVbo); 244 | GLint size = 0; 245 | glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 246 | 247 | m_vboData.resize(size / sizeof(GLfloat)); 248 | 249 | glGetBufferSubData(GL_ARRAY_BUFFER, 0, size, m_vboData.data()); 250 | 251 | return m_vboData; 252 | } 253 | 254 | void QOpenglMain::getAnixVao() 255 | { 256 | m_vaoVbos.m_anixVao = m_chart.getAnixVao(); 257 | } 258 | 259 | void QOpenglMain::getAnixVbo() 260 | { 261 | m_vaoVbos.m_anixVbo = m_chart.getAnixVbo(); 262 | } 263 | 264 | void QOpenglMain::getAnixVboIndex() 265 | { 266 | m_vaoVbos.m_anixVboIndex = m_chart.getAnixVboIndex(); 267 | } 268 | 269 | void QOpenglMain::getVaoGridAnixnumDgt() 270 | { 271 | m_vaoVbos.m_gridVaoGridAnixnumDgt = m_chart.getVaoGridAnixnumDgt(); 272 | } 273 | 274 | void QOpenglMain::getVboGridAnixnumDgt() 275 | { 276 | m_vaoVbos.m_gridVboGridAnixnumDgt = m_chart.getVboGridAnixnumDgt(); 277 | } 278 | 279 | void QOpenglMain::getVboGridAnixnumDgtTexture() 280 | { 281 | m_vaoVbos.m_gridVboGridAnixnumDgtTexture = m_chart.getVboGridAnixnumDgtTexture(); 282 | } 283 | 284 | void QOpenglMain::getVaoGridAnixnumPnt() 285 | { 286 | m_vaoVbos.m_gridVaoGridAnixnumPnt = m_chart.getVaoGridAnixnumPnt(); 287 | } 288 | 289 | void QOpenglMain::getVboGridAnixnumPnt() 290 | { 291 | m_vaoVbos.m_gridVboGridAnixnumPnt = m_chart.getVboGridAnixnumPnt(); 292 | } 293 | 294 | void QOpenglMain::getVboGridAnixnumPntTexture() 295 | { 296 | m_vaoVbos.m_gridVboGridAnixnumPntTexture = m_chart.getVboGridAnixnumPntTexture(); 297 | } 298 | 299 | void QOpenglMain::getVaoGridAnixnumMinus() 300 | { 301 | m_vaoVbos.m_gridVaoGridAnixnumMinus = m_chart.getVaoGridAnixnumMinus(); 302 | } 303 | 304 | void QOpenglMain::getVboGridAnixnumMinus() 305 | { 306 | m_vaoVbos.m_gridVboGridAnixnumMinus = m_chart.getVboGridAnixnumMinus(); 307 | } 308 | 309 | void QOpenglMain::getVboGridAnixnumMinusTexture() 310 | { 311 | m_vaoVbos.m_gridVboGridAnixnumMinusTexture = m_chart.getVboGridAnixnumMinusTexture(); 312 | } 313 | 314 | void QOpenglMain::getVaoGridAnixnumLabel() 315 | { 316 | m_vaoVbos.m_gridVaoGridAnixnumLabel = m_chart.getVaoGridAnixnumLabel(); 317 | } 318 | 319 | void QOpenglMain::getVboGridAnixnumLabel() 320 | { 321 | m_vaoVbos.m_gridVboGridAnixnumLabel = m_chart.getVboGridAnixnumLabel(); 322 | } 323 | 324 | void QOpenglMain::getVboGridAnixnumLabelTexture() 325 | { 326 | m_vaoVbos.m_gridVboGridAnixnumLabelTexture = m_chart.getVboGridAnixnumLabelTexture(); 327 | } 328 | 329 | void QOpenglMain::getLinesVao() 330 | { 331 | m_vaoVbos.m_linesVaos.clear(); 332 | m_vaoVbos.m_linesVaos = m_chart.getLinesVao(); 333 | } 334 | 335 | void QOpenglMain::getLinesVbo() 336 | { 337 | m_vaoVbos.m_linesVbos.clear(); 338 | m_vaoVbos.m_linesVbos = m_chart.getLinesVbo(); 339 | } 340 | 341 | void QOpenglMain::updateLines() 342 | { 343 | m_chart.updateLines(); 344 | } 345 | 346 | void QOpenglMain::drawOnce() 347 | { 348 | if(!m_notCopyFromOtherOpenGLWidget) 349 | { 350 | m_chart.draw(); 351 | } 352 | } 353 | 354 | bool QOpenglMain::checkRangeChange(vector2f& _xRange, vector2f& _yRange, vector2f& _zRange) 355 | { 356 | 357 | return m_chart.checkRangeChange(_xRange, _yRange, _zRange); 358 | } 359 | 360 | void QOpenglMain::initializeGL() 361 | { 362 | initializeOpenGLFunctions(); 363 | m_chart.setWidthAndHeight(width(), height()); 364 | m_chart.initial({0,0,0}, context(),context()->surface()); //��ʼ��chart 365 | 366 | if(m_notCopyFromOtherOpenGLWidget) 367 | m_chart.setDrawType(CChart::DRAWTYPE(m_drawtype)); 368 | } 369 | 370 | void QOpenglMain::paintGL() 371 | { 372 | glViewport(0, 0, width(), height()); 373 | 374 | m_chart.draw(); 375 | } 376 | 377 | void QOpenglMain::mouseDoubleClickEvent(QMouseEvent * event) 378 | { 379 | if(0 == m_frameType) 380 | { 381 | if (event->button()==Qt::LeftButton) 382 | { 383 | m_drawtype += 1; 384 | if (m_drawtype > CChart::YZ) 385 | { 386 | m_drawtype = CChart::XZY; 387 | } 388 | m_chart.setDrawType(CChart::DRAWTYPE(m_drawtype)); 389 | } 390 | update(); 391 | } 392 | } 393 | 394 | void QOpenglMain::mousePressEvent(QMouseEvent * event) 395 | { 396 | if (event->button() == Qt::LeftButton) 397 | { 398 | m_leftPushDown = true; 399 | m_mouseCordx = event->x(); 400 | m_mouseCordy = event->y(); 401 | } 402 | if (event->button() == Qt::RightButton) 403 | { 404 | m_rightPushDown = true; 405 | m_mouseCordx = event->x(); 406 | m_mouseCordy = event->y(); 407 | } 408 | 409 | } 410 | 411 | void QOpenglMain::mouseMoveEvent(QMouseEvent * event) 412 | { 413 | if(0 == m_frameType) 414 | { 415 | if (m_leftPushDown) 416 | { 417 | float _roatx = m_mouseCordx - event->x(); 418 | float _roaty = m_mouseCordy - event->y(); 419 | m_mouseCordx = event->x(); 420 | m_mouseCordy = event->y(); 421 | switch (m_drawtype) { 422 | case CChart::DRAWTYPE::XZY: 423 | m_chart.setRot(_roaty / 200, _roatx/ 200/*,0*/); 424 | break; 425 | default: 426 | break; 427 | } 428 | 429 | } 430 | } 431 | if (m_rightPushDown) 432 | { 433 | float _movex = ((float)m_mouseCordx - event->x())/width(); 434 | float _movey = ((float)m_mouseCordy - event->y())/height(); 435 | m_mouseCordx = event->x(); 436 | m_mouseCordy = event->y(); 437 | m_chart.setMove(-_movex, _movey); 438 | } 439 | update(); 440 | } 441 | 442 | void QOpenglMain::mouseReleaseEvent(QMouseEvent * event) 443 | { 444 | if (event->button() == Qt::LeftButton) 445 | { 446 | m_leftPushDown = false; 447 | } 448 | if (event->button() == Qt::RightButton) 449 | { 450 | m_rightPushDown = false; 451 | } 452 | } 453 | 454 | void QOpenglMain::wheelEvent(QWheelEvent * event) 455 | { 456 | if (event->delta()>0) 457 | { 458 | m_zoom *= 1.1; 459 | } 460 | else { 461 | m_zoom *= 0.9; 462 | } 463 | m_chart.setZoom(m_zoom); 464 | update(); 465 | } 466 | 467 | void QOpenglMain::keyPressEvent(QKeyEvent *event) 468 | { 469 | if (Qt::Key_G==event->key()) 470 | { 471 | //setGridOnOrOff(); 472 | } 473 | if (Qt::Key_L==event->key()) 474 | { 475 | //setAnixLabelOnOrOff(); 476 | } 477 | } 478 | 479 | void QOpenglMain::onSetGridState() 480 | { 481 | setGridOnOrOff(); 482 | } 483 | 484 | void QOpenglMain::onSetAnixState() 485 | { 486 | setAnixLabelOnOrOff(); 487 | } 488 | 489 | void QOpenglMain::onXYPlaneState() 490 | { 491 | setLineXYPlaneOn(); 492 | } 493 | 494 | void QOpenglMain::onXZPlaneState() 495 | { 496 | setLineXZPlaneOn(); 497 | } 498 | 499 | void QOpenglMain::onYZPlaneState() 500 | { 501 | setLineYZPlaneOn(); 502 | } 503 | -------------------------------------------------------------------------------- /MyOpenglWidget/QOpenglMain.h: -------------------------------------------------------------------------------- 1 | //utf8 2 | #pragma once 3 | #define u_char uchar 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "Chart.h" 15 | #include "Renders/Crender.h" 16 | #include 17 | 18 | struct VaoVbos { 19 | //anix 20 | GLuint m_anixVao; 21 | GLuint m_anixVbo; 22 | GLuint m_anixVboIndex; //索引 23 | //grid 24 | GLuint m_gridVaoGridAnixnumDgt; //数字VAO 25 | GLuint m_gridVboGridAnixnumDgt; //VBO 26 | GLuint m_gridVboGridAnixnumDgtTexture; //texture vbo 27 | 28 | GLuint m_gridVaoGridAnixnumPnt; //小数点VAO 29 | GLuint m_gridVboGridAnixnumPnt; //VBO 30 | GLuint m_gridVboGridAnixnumPntTexture; //texture vbo 31 | 32 | GLuint m_gridVaoGridAnixnumMinus; //负号VAO 33 | GLuint m_gridVboGridAnixnumMinus; //VBO 34 | GLuint m_gridVboGridAnixnumMinusTexture; //texture vbo 35 | 36 | GLuint m_gridVaoGridAnixnumLabel; //"xyz/" 37 | GLuint m_gridVboGridAnixnumLabel; //VBO 38 | GLuint m_gridVboGridAnixnumLabelTexture; //texture vbo 39 | 40 | //clines 41 | list m_linesVaos; 42 | list m_linesVbos; 43 | }; 44 | class QOpenglMain : public QOpenGLWidget, protected QOpenGLFunctions_4_3_Core 45 | { 46 | Q_OBJECT 47 | 48 | public: 49 | //构造函数 50 | explicit QOpenglMain(u_char _frameType, CAllocVBOandVAO* callocVBOandVAO, CChart::DRAWTYPE drawType, QWidget *parent = 0); 51 | //析构函数 52 | ~QOpenglMain(); 53 | 54 | //设置线条的颜色 55 | void setColor(size_t _lineIndex, vector4f _color); 56 | 57 | //添加线条的点 58 | bool addPoint(size_t _lineindex, const vector3f& _posion); 59 | //设置网格开关 60 | void setGridOnOrOff(); 61 | void setGridOnOrOff(bool _b); 62 | 63 | //设置坐标轴开关 64 | void setAnixLabelOnOrOff(); 65 | 66 | //设置坐标轴精度 67 | void setAxisPrecision(GLint _precision); 68 | 69 | void setLineXYPlaneOn(); 70 | void setLineXZPlaneOn(); 71 | void setLineYZPlaneOn(); 72 | 73 | //设置线条显示或隐藏 74 | void setLinesEnabled(size_t _lineIndex, bool _b); 75 | 76 | 77 | //获取cchart类吗m_chart 78 | //CChart *getChart(); 79 | 80 | /*--------------------------------------start--------------------------------------------*/ 81 | /*以下public函数都是为了单独显示选定窗口来使用的*/ 82 | //首先执行setCopyFromOtherOpenWidgetMark(false)来将该窗口类设置为复制类窗口 83 | void setCopyFromOtherOpenWidgetMark(GLboolean _b); 84 | //调用 getAllVaoAndVboAndVboIndex来提取所有的Opengl VAO和VBO索引号码。实际上是想在该上下文中提取出opengl缓冲区中数据 85 | void getAllVaoAndVboAndVboIndex(); 86 | //getVaoAndVbos()并未被调用 87 | VaoVbos getVaoAndVbos(); 88 | //setVaoAndVbosBuffer并未被调用 89 | void setVaoAndVbosBuffer(vector &_anixVboBuffer, vector &_anixVboIndexBuffer); 90 | //getAnixVboBufferData,getAnixVboIndexBufferData函数可以不被调用,但必须保证坐标轴anix被正常绘制; 91 | vector& getAnixVboBufferData(); 92 | vector& getAnixVboIndexBufferData(); 93 | //getLinesVboBufferData,在被复制类中调用,得到其缓冲区数据 94 | //setLinesVboBufferData,在复制类中调用,设置其缓冲区数据 95 | void getLinesVboBufferData(list > & _linesBuffer, vector &_linesPointAmout); 96 | void setLinesVboBufferData(list > & _linesBuffer, vector &_linesAmount); 97 | //getCordRangei,在被复制类中调用,得到其坐标轴上下限 98 | //setCordRangei,在复制类中调用,设置其坐标轴上下限 99 | void getCordRangei(vector2f &_x, vector2f &_y, vector2f &_z); 100 | void setCordRangei(vector2f &_x, vector2f &_y, vector2f &_z); 101 | //getRotation, getMove, 在被复制类中调用,得到其旋转、平移矩阵值 102 | //setRotation, setMove, 在复制类中调用,设置其旋转、平移矩阵值 103 | void getRotation(QMatrix4x4 & _rotation); 104 | void setRotation(QMatrix4x4 & _rotation); 105 | void getMove(QMatrix4x4 & _move); 106 | void setMove(QMatrix4x4 & _move); 107 | //setDrawType, 在复制类中调用,设定该窗口的显示类型 108 | //getRotation, 在被复制类中调用,得到该窗口的显示类型 109 | void setDrawType(CChart::DRAWTYPE _type); 110 | void getDrawType(CChart::DRAWTYPE & _type); 111 | //getGridNumer, 在被复制类中调用,得到该窗口的网格数 112 | //setGridNumer, 在复制类中调用,设定该窗口的网格数 113 | void getGridNumer(int & _xGridNumPerAnix, int & _yGridNumPerAnix, int & _zGridNumPerAnix); 114 | void setGridNumer(int _xGridNumPerAnix, int _yGridNumPerAnix, int _zGridNumPerAnix); 115 | //getLineColor, 在被复制类中调用,得到该窗口中线条的颜色 116 | //setLineColor, 在复制类中调用,设定该窗口中线条的颜色 117 | void getLineColor(map &_lineColor); 118 | void setLineColor(map &_lineColor); 119 | void updateLines(); 120 | void drawOnce(); 121 | /*-----------------------------------------------end------------------------------------------*/ 122 | //检查坐标上下限是否变化,true是变化,false是无变化 123 | bool checkRangeChange(vector2f &_xRange, vector2f &_yRange, vector2f &_zRange); 124 | 125 | protected: 126 | //初始化窗口,在paintGL执行前自行调用 127 | void initializeGL(); 128 | //绘制窗口 129 | void paintGL(); 130 | 131 | /*-------当复制窗口时调用start------*/ 132 | //anix 133 | void getAnixVao(); 134 | void getAnixVbo(); 135 | void getAnixVboIndex(); 136 | //grid 137 | void getVaoGridAnixnumDgt(); 138 | void getVboGridAnixnumDgt(); 139 | void getVboGridAnixnumDgtTexture(); 140 | 141 | void getVaoGridAnixnumPnt(); 142 | void getVboGridAnixnumPnt(); 143 | void getVboGridAnixnumPntTexture(); 144 | 145 | void getVaoGridAnixnumMinus(); 146 | void getVboGridAnixnumMinus(); 147 | void getVboGridAnixnumMinusTexture(); 148 | 149 | void getVaoGridAnixnumLabel(); 150 | void getVboGridAnixnumLabel(); 151 | void getVboGridAnixnumLabelTexture(); 152 | //lines 153 | void getLinesVao(); 154 | void getLinesVbo(); 155 | /*-------当复制窗口时调用end------*/ 156 | private: 157 | 158 | CChart m_chart; 159 | double m_time = 0; 160 | float m_zoom = 1.0; 161 | bool m_leftPushDown = false; //左键按下 162 | bool m_rightPushDown = false; //右键按下 163 | int m_mouseCordx = 0; //左键鼠标位置x 164 | int m_mouseCordy = 0; //左键鼠标位置y 165 | int m_drawtype = 0; 166 | CAllocVBOandVAO* m_allocVBOandVAO; 167 | VaoVbos m_vaoVbos; 168 | //非复制窗口标志, 当为复制窗口是为false 169 | GLboolean m_notCopyFromOtherOpenGLWidget = true; 170 | 171 | /*-------当复制窗口时调用start------*/ 172 | vector m_vboData; 173 | vector m_vboIndexData; 174 | list > m_linesVboData; 175 | /*-------当复制窗口时调用end------*/ 176 | 177 | u_char m_frameType = 0; 178 | 179 | private slots: 180 | void mouseDoubleClickEvent(QMouseEvent *event); 181 | void mousePressEvent(QMouseEvent *event); 182 | void mouseMoveEvent(QMouseEvent *event); 183 | void mouseReleaseEvent(QMouseEvent *event); 184 | void wheelEvent(QWheelEvent *event); 185 | void keyPressEvent(QKeyEvent* event); 186 | void onSetGridState(); 187 | void onSetAnixState(); 188 | void onXYPlaneState(); 189 | void onXZPlaneState(); 190 | void onYZPlaneState(); 191 | 192 | }; 193 | -------------------------------------------------------------------------------- /QOpenglMainProgram.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-07-10T00:26:30 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui opengl 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = QOpenglMainProgram 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS _LLMINGW32_ u_short=ushort u_char=uchar u_int=uint WIN32_LEAN_AND_MEAN 19 | # In order to do so, uncomment the following line. 20 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 21 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 22 | #CONFIG +=precompile_header 23 | 24 | SOURCES += \ 25 | Widgets/COFFOpenglwidget.cpp \ 26 | Widgets/CLLOpenglWidget.cpp \ 27 | Widgets/CCopyQOpenglWidget.cpp \ 28 | UDPServer/CAsioAsyncServer.cpp \ 29 | Renders/Crender.cpp \ 30 | Renders/CLinesRender.cpp \ 31 | Renders/CGridRender.cpp \ 32 | MyOpenglWidget/QOpenglMain.cpp \ 33 | MyOpenglWidget/Clines.cpp \ 34 | MyOpenglWidget/Chart.cpp \ 35 | mainWidget/Widget.cpp \ 36 | mainWidget/mainwindow.cpp \ 37 | mainWidget/main.cpp \ 38 | GridAndAxis/CGrid.cpp \ 39 | GridAndAxis/Anix.cpp \ 40 | DataManageMent/CDataRAW.cpp \ 41 | DataManageMent/CAllocVBOandVAO.cpp \ 42 | ComboBox/CComboBox.cpp 43 | 44 | 45 | HEADERS += \ 46 | Widgets/COFFOpenglwidget.h \ 47 | Widgets/CCopyQOpenglWidget.h \ 48 | UDPServer/CAsioAsyncServer.h \ 49 | Renders/Crender.h \ 50 | Renders/CLinesRender.h \ 51 | Renders/CGridRender.h \ 52 | MyOpenglWidget/QOpenglMain.h \ 53 | MyOpenglWidget/Clines.h \ 54 | MyOpenglWidget/Chart.h \ 55 | mainWidget/Widget.h \ 56 | mainWidget/mainwindow.h \ 57 | GridAndAxis/textureindex.h \ 58 | GridAndAxis/CGrid.h \ 59 | GridAndAxis/Anix.h \ 60 | DataManageMent/CDataRAW.h \ 61 | DataManageMent/CAllocVBOandVAO.h \ 62 | ComboBox/CComboBox.h \ 63 | Widgets/CLLOpenglWidget.h \ 64 | mainWidget/tools.h 65 | 66 | 67 | FORMS += \ 68 | ui/mainwindow.ui \ 69 | ui/widget.ui 70 | 71 | DISTFILES += \ 72 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.geo \ 73 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.Frag \ 74 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/coord.frag \ 75 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/basic.Frag \ 76 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.vert \ 77 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/coord.vert \ 78 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/basic.vert 79 | #INCLUDEPATH += C:\msys64\mingw64\include 80 | #PRECOMPILED_HEADER = C:\msys64\mingw64\include\boost\asio.hpp 81 | #LIBS += -lboost_system-mt.dll \ 82 | # -lboost_thread-mt.dll \ 83 | # -lwsock32 \ 84 | # -lws2_32 85 | #LIBS += C:/msys64/mingw64/lib/libboost_system-mt.a C:/msys64/mingw64/lib/libboost_thread-mt.a 86 | #INCLUDEPATH +=/usr/include 87 | #LIBS += /usr/lib/x86_64-linux-gnu/libboost_system.so /usr/lib/x86_64-linux-gnu/libboost_thread.so /usr/lib/x86_64-linux-gnu/libGLU.so 88 | 89 | 90 | #win32:CONFIG(release, debug|release): \ 91 | # LIBS += -lboost_system-mt.dll -lboost_thread-mt.dll -lwsock32 -lws2_32 \ 92 | # DEFINES += QT_DEPRECATED_WARNINGS _LLMINGW32_ u_short=ushort u_char=uchar u_int=uint WIN32_LEAN_AND_MEAN 93 | #else:win32:CONFIG(debug, debug|release): \ 94 | LIBS += -lboost_system-mt.dll -lboost_thread-mt.dll -lwsock32 -lws2_32 95 | #else:unix: \ 96 | # QMAKE_CXXFLAGS += -g \ 97 | # LIBS += /usr/lib/x86_64-linux-gnu/libboost_system.so /usr/lib/x86_64-linux-gnu/libboost_thread.so /usr/lib/x86_64-linux-gnu/libGLU.so \ 98 | # INCLUDEPATH +=/usr/include \ 99 | # DEFINES += QT_DEPRECATED_WARNINGS _LLMINGW32_ u_short=ushort u_char=uchar u_int=uint WIN32_LEAN_AND_MEAN 100 | -------------------------------------------------------------------------------- /QOpenglMainProgram_linux.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-07-10T00:26:30 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui opengl 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = QOpenglMainProgram 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | # In order to do so, uncomment the following line. 20 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 21 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 22 | 23 | SOURCES += \ 24 | Widgets/COFFOpenglwidget.cpp \ 25 | Widgets/CLLOpenglWidget.cpp \ 26 | Widgets/CCopyQOpenglWidget.cpp \ 27 | UDPServer/CAsioAsyncServer.cpp \ 28 | Renders/Crender.cpp \ 29 | Renders/CLinesRender.cpp \ 30 | Renders/CGridRender.cpp \ 31 | MyOpenglWidget/QOpenglMain.cpp \ 32 | MyOpenglWidget/Clines.cpp \ 33 | MyOpenglWidget/Chart.cpp \ 34 | mainWidget/Widget.cpp \ 35 | mainWidget/mainwindow.cpp \ 36 | mainWidget/main.cpp \ 37 | GridAndAxis/CGrid.cpp \ 38 | GridAndAxis/Anix.cpp \ 39 | DataManageMent/CDataRAW.cpp \ 40 | DataManageMent/CAllocVBOandVAO.cpp \ 41 | ComboBox/CComboBox.cpp 42 | 43 | 44 | HEADERS += \ 45 | Widgets/COFFOpenglwidget.h \ 46 | Widgets/CCopyQOpenglWidget.h \ 47 | UDPServer/CAsioAsyncServer.h \ 48 | Renders/Crender.h \ 49 | Renders/CLinesRender.h \ 50 | Renders/CGridRender.h \ 51 | MyOpenglWidget/QOpenglMain.h \ 52 | MyOpenglWidget/Clines.h \ 53 | MyOpenglWidget/Chart.h \ 54 | mainWidget/Widget.h \ 55 | mainWidget/mainwindow.h \ 56 | GridAndAxis/textureindex.h \ 57 | GridAndAxis/CGrid.h \ 58 | GridAndAxis/Anix.h \ 59 | DataManageMent/CDataRAW.h \ 60 | DataManageMent/CAllocVBOandVAO.h \ 61 | ComboBox/CComboBox.h \ 62 | Widgets/CLLOpenglWidget.h \ 63 | mainWidget/tools.h 64 | 65 | 66 | FORMS += \ 67 | ui/mainwindow.ui \ 68 | ui/widget.ui 69 | 70 | DISTFILES += \ 71 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.geo \ 72 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.Frag \ 73 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/coord.frag \ 74 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/basic.Frag \ 75 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.vert \ 76 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/coord.vert \ 77 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/basic.vert \ 78 | Shaders/lines.geo \ 79 | Shaders/lines.Frag \ 80 | Shaders/coord.frag \ 81 | Shaders/basic.Frag \ 82 | Shaders/lines.vert \ 83 | Shaders/coord.vert \ 84 | Shaders/basic.vert 85 | 86 | INCLUDEPATH +=/usr/include 87 | LIBS += /usr/lib/x86_64-linux-gnu/libboost_system.so /usr/lib/x86_64-linux-gnu/libboost_thread.so /usr/lib/x86_64-linux-gnu/libGLU.so 88 | 89 | -------------------------------------------------------------------------------- /QOpenglMainProgram_mingw.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-07-10T00:26:30 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui opengl 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = QOpenglMainProgram 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS _LLMINGW32_ u_short=ushort u_char=uchar u_int=uint WIN32_LEAN_AND_MEAN 19 | # In order to do so, uncomment the following line. 20 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 21 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 22 | #CONFIG +=precompile_header 23 | 24 | SOURCES += \ 25 | Widgets/COFFOpenglwidget.cpp \ 26 | Widgets/CLLOpenglWidget.cpp \ 27 | Widgets/CCopyQOpenglWidget.cpp \ 28 | UDPServer/CAsioAsyncServer.cpp \ 29 | Renders/Crender.cpp \ 30 | Renders/CLinesRender.cpp \ 31 | Renders/CGridRender.cpp \ 32 | MyOpenglWidget/QOpenglMain.cpp \ 33 | MyOpenglWidget/Clines.cpp \ 34 | MyOpenglWidget/Chart.cpp \ 35 | mainWidget/Widget.cpp \ 36 | mainWidget/mainwindow.cpp \ 37 | mainWidget/main.cpp \ 38 | GridAndAxis/CGrid.cpp \ 39 | GridAndAxis/Anix.cpp \ 40 | DataManageMent/CDataRAW.cpp \ 41 | DataManageMent/CAllocVBOandVAO.cpp \ 42 | ComboBox/CComboBox.cpp 43 | 44 | 45 | HEADERS += \ 46 | Widgets/COFFOpenglwidget.h \ 47 | Widgets/CCopyQOpenglWidget.h \ 48 | UDPServer/CAsioAsyncServer.h \ 49 | Renders/Crender.h \ 50 | Renders/CLinesRender.h \ 51 | Renders/CGridRender.h \ 52 | MyOpenglWidget/QOpenglMain.h \ 53 | MyOpenglWidget/Clines.h \ 54 | MyOpenglWidget/Chart.h \ 55 | mainWidget/Widget.h \ 56 | mainWidget/mainwindow.h \ 57 | GridAndAxis/textureindex.h \ 58 | GridAndAxis/CGrid.h \ 59 | GridAndAxis/Anix.h \ 60 | DataManageMent/CDataRAW.h \ 61 | DataManageMent/CAllocVBOandVAO.h \ 62 | ComboBox/CComboBox.h \ 63 | Widgets/CLLOpenglWidget.h \ 64 | mainWidget/tools.h 65 | 66 | 67 | FORMS += \ 68 | ui/mainwindow.ui \ 69 | ui/widget.ui 70 | 71 | DISTFILES += \ 72 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.geo \ 73 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.Frag \ 74 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/coord.frag \ 75 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/basic.Frag \ 76 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/lines.vert \ 77 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/coord.vert \ 78 | ../build-QOpenglMainProgram-Desktop_Qt_5_9_0_GCC_64bit-Debug/Shaders/basic.vert 79 | #INCLUDEPATH += C:\msys64\mingw64\include 80 | #PRECOMPILED_HEADER = C:\msys64\mingw64\include\boost\asio.hpp 81 | #LIBS += -lboost_system-mt.dll \ 82 | # -lboost_thread-mt.dll \ 83 | # -lwsock32 \ 84 | # -lws2_32 85 | #LIBS += C:/msys64/mingw64/lib/libboost_system-mt.a C:/msys64/mingw64/lib/libboost_thread-mt.a 86 | #INCLUDEPATH +=/usr/include 87 | #LIBS += /usr/lib/x86_64-linux-gnu/libboost_system.so /usr/lib/x86_64-linux-gnu/libboost_thread.so /usr/lib/x86_64-linux-gnu/libGLU.so 88 | 89 | 90 | #win32:CONFIG(release, debug|release): \ 91 | # LIBS += -lboost_system-mt.dll -lboost_thread-mt.dll -lwsock32 -lws2_32 \ 92 | # DEFINES += QT_DEPRECATED_WARNINGS _LLMINGW32_ u_short=ushort u_char=uchar u_int=uint WIN32_LEAN_AND_MEAN 93 | #else:win32:CONFIG(debug, debug|release): \ 94 | LIBS += -lboost_system-mt.dll -lboost_thread-mt.dll -lwsock32 -lws2_32 95 | #else:unix: \ 96 | # QMAKE_CXXFLAGS += -g \ 97 | # LIBS += /usr/lib/x86_64-linux-gnu/libboost_system.so /usr/lib/x86_64-linux-gnu/libboost_thread.so /usr/lib/x86_64-linux-gnu/libGLU.so \ 98 | # INCLUDEPATH +=/usr/include \ 99 | # DEFINES += QT_DEPRECATED_WARNINGS _LLMINGW32_ u_short=ushort u_char=uchar u_int=uint WIN32_LEAN_AND_MEAN 100 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # oscilloscopeQt 2 | In this application, I just use QOpenGLWidget and Qt's other widgets to implement a oscilloscope. And I use boost::asio to communicate, use boost::cicular_buffer to store the received data and use QOpenGLWidget to visualize the sentific data. 3 | ![image](https://github.com/liulangx/oscilloscopeQt/blob/master/Result/%E7%A4%BA%E6%B3%A2%E5%99%A8%E7%AC%AC%E4%B8%80%E7%89%881.png) 4 | ![image](https://github.com/liulangx/oscilloscopeQt/blob/master/Result/%E7%A4%BA%E6%B3%A2%E5%99%A8%E7%AC%AC%E4%B8%80%E7%89%882.png) 5 | ![image](https://github.com/liulangx/oscilloscopeQt/blob/master/Result/%E7%A4%BA%E6%B3%A2%E5%99%A8%E7%AC%AC%E4%B8%80%E7%89%883.png) 6 | -------------------------------------------------------------------------------- /Renders/CGridRender.cpp: -------------------------------------------------------------------------------- 1 | #include "Renders/CGridRender.h" 2 | 3 | 4 | CGridRender::CGridRender() 5 | { 6 | 7 | } 8 | 9 | CGridRender::~CGridRender() 10 | { 11 | 12 | } 13 | 14 | void CGridRender::prepare() 15 | { 16 | initializeOpenGLFunctions(); 17 | initialShader(); 18 | } 19 | 20 | void CGridRender::bindShader() 21 | { 22 | m_shaderprogram.bind(); 23 | } 24 | 25 | void CGridRender::bindAttributes() 26 | { 27 | m_shaderprogram.bindAttributeLocation("Position", 0); 28 | m_shaderprogram.bindAttributeLocation("textureCoords", 1); 29 | } 30 | 31 | void CGridRender::setBackGround(vector4f &_color) 32 | { 33 | glClearColor(_color._r, _color._g, _color._b, _color._a); 34 | glFlush(); 35 | } 36 | 37 | void CGridRender::releaseShader() 38 | { 39 | m_shaderprogram.release(); 40 | } 41 | 42 | QGLShaderProgram *CGridRender::getShader() 43 | { 44 | return &m_shaderprogram; 45 | } 46 | 47 | void CGridRender::initialShader() 48 | { 49 | if (!m_shaderprogram.addShaderFromSourceFile(QGLShader::Vertex, "Shaders/coord.vert")) 50 | { 51 | QMessageBox::information(NULL, "vert", 52 | m_shaderprogram.log(), 53 | QMessageBox::Yes | QMessageBox::No, 54 | QMessageBox::Yes); 55 | } 56 | if (!m_shaderprogram.addShaderFromSourceFile(QGLShader::Fragment, "Shaders/coord.frag")) 57 | { 58 | QMessageBox::information(NULL, "Frag", 59 | m_shaderprogram.log(), 60 | QMessageBox::Yes | QMessageBox::No, 61 | QMessageBox::Yes); 62 | } 63 | if (!m_shaderprogram.link()) 64 | { 65 | QMessageBox::information(NULL, "Frag", 66 | m_shaderprogram.log(), 67 | QMessageBox::Yes | QMessageBox::No, 68 | QMessageBox::Yes); 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Renders/CGridRender.h: -------------------------------------------------------------------------------- 1 | #ifndef CGRIDRENDER_H 2 | #define CGRIDRENDER_H 3 | #include "MyOpenglWidget/Clines.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | class CGridRender :protected QOpenGLFunctions_4_3_Core 11 | { 12 | public: 13 | CGridRender(); 14 | ~CGridRender(); 15 | void prepare(); 16 | void bindShader(); 17 | virtual void bindAttributes(); 18 | void setBackGround(vector4f& _color); 19 | void releaseShader(); 20 | QGLShaderProgram *getShader(); 21 | void initialShader(); 22 | protected: 23 | 24 | QGLShaderProgram m_shaderprogram; //shader程序 25 | vector m_vaos; //vba 26 | }; 27 | 28 | #endif // CGRIDRENDER_H 29 | -------------------------------------------------------------------------------- /Renders/CLinesRender.cpp: -------------------------------------------------------------------------------- 1 | #include "Renders/CLinesRender.h" 2 | 3 | CLinesRender::CLinesRender() 4 | { 5 | } 6 | 7 | 8 | CLinesRender::~CLinesRender() 9 | { 10 | } 11 | 12 | void CLinesRender::prepare() 13 | { 14 | initializeOpenGLFunctions(); 15 | QOpenGLFunctions_4_3_Core::glClearColor(1,1,1,0.2); 16 | glEnable(GL_DEPTH_TEST); 17 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 18 | initialShader(); 19 | } 20 | 21 | void CLinesRender::bindShader() 22 | { 23 | m_shaderprogram.bind(); 24 | } 25 | 26 | void CLinesRender::releaseShader() 27 | { 28 | m_shaderprogram.release(); 29 | } 30 | 31 | GLuint CLinesRender::getUniformDataIndex(const char * _name) 32 | { 33 | return GLuint(m_shaderprogram.uniformLocation(_name)); 34 | } 35 | 36 | QGLShaderProgram * CLinesRender::getShader() 37 | { 38 | return &m_shaderprogram; 39 | } 40 | 41 | void CLinesRender::initialShader() 42 | { 43 | //shader程序 44 | if (!m_shaderprogram.addShaderFromSourceFile(QGLShader::Vertex, "Shaders/lines.vert")) 45 | { 46 | QMessageBox::information(NULL, "vert", 47 | m_shaderprogram.log(), 48 | QMessageBox::Yes | QMessageBox::No, 49 | QMessageBox::Yes); 50 | } 51 | if (!m_shaderprogram.addShaderFromSourceFile(QGLShader::Geometry, "Shaders/lines.geo")) 52 | { 53 | QMessageBox::information(NULL, "geo", 54 | m_shaderprogram.log(), 55 | QMessageBox::Yes | QMessageBox::No, 56 | QMessageBox::Yes); 57 | } 58 | if (!m_shaderprogram.addShaderFromSourceFile(QGLShader::Fragment, "Shaders/lines.Frag")) 59 | { 60 | QMessageBox::information(NULL, "Frag", 61 | m_shaderprogram.log(), 62 | QMessageBox::Yes | QMessageBox::No, 63 | QMessageBox::Yes); 64 | } 65 | if (!m_shaderprogram.link()) 66 | { 67 | QMessageBox::information(NULL, "Link", 68 | m_shaderprogram.log(), 69 | QMessageBox::Yes | QMessageBox::No, 70 | QMessageBox::Yes); 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /Renders/CLinesRender.h: -------------------------------------------------------------------------------- 1 | #ifndef CLINESRENDER_H 2 | #define CLINESRENDER_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | class CLinesRender:protected QOpenGLFunctions_4_3_Core 8 | { 9 | public: 10 | CLinesRender(); 11 | ~CLinesRender(); 12 | void prepare(); 13 | void bindShader(); 14 | void releaseShader(); 15 | GLuint getUniformDataIndex(const char* _name); //获取uniform数据 16 | QGLShaderProgram* getShader(); 17 | protected: 18 | void initialShader(); 19 | QGLShaderProgram m_shaderprogram; //shader程序管理 20 | }; 21 | 22 | #endif // CLINESRENDER_H 23 | -------------------------------------------------------------------------------- /Renders/Crender.cpp: -------------------------------------------------------------------------------- 1 | #include "Renders/Crender.h" 2 | 3 | #define ATTRIB_VERTEX 1 4 | 5 | Crender::Crender() 6 | { 7 | } 8 | 9 | 10 | Crender::~Crender() 11 | { 12 | } 13 | 14 | void Crender::prepare() 15 | { 16 | initializeOpenGLFunctions(); 17 | QOpenGLFunctions_4_3_Core::glClearColor(1,1,1,0.2); 18 | glEnable(GL_DEPTH_TEST); 19 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 20 | initialShader(); 21 | } 22 | 23 | void Crender::bindShader() 24 | { 25 | m_shaderprogram.bind(); 26 | } 27 | 28 | void Crender::releaseShader() 29 | { 30 | m_shaderprogram.release(); 31 | } 32 | 33 | GLuint Crender::getUniformDataIndex(const char * _name) 34 | { 35 | return GLuint(m_shaderprogram.uniformLocation(_name)); 36 | } 37 | 38 | QGLShaderProgram * Crender::getShader() 39 | { 40 | return &m_shaderprogram; 41 | } 42 | 43 | void Crender::initialShader() 44 | { 45 | //shader程序 46 | if (!m_shaderprogram.addShaderFromSourceFile(QGLShader::Vertex, "Shaders/basic.vert")) 47 | { 48 | QMessageBox::information(NULL, "vert", 49 | m_shaderprogram.log(), 50 | QMessageBox::Yes | QMessageBox::No, 51 | QMessageBox::Yes); 52 | } 53 | if (!m_shaderprogram.addShaderFromSourceFile(QGLShader::Fragment, "Shaders/basic.Frag")) 54 | { 55 | QMessageBox::information(NULL, "Frag", 56 | m_shaderprogram.log(), 57 | QMessageBox::Yes | QMessageBox::No, 58 | QMessageBox::Yes); 59 | } 60 | if (!m_shaderprogram.link()) 61 | { 62 | QMessageBox::information(NULL, "Link", 63 | m_shaderprogram.log(), 64 | QMessageBox::Yes | QMessageBox::No, 65 | QMessageBox::Yes); 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /Renders/Crender.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | class Crender:protected QOpenGLFunctions_4_3_Core 7 | { 8 | public: 9 | Crender(); 10 | ~Crender(); 11 | void prepare(); 12 | void bindShader(); 13 | void releaseShader(); 14 | 15 | GLuint getUniformDataIndex(const char* _name); //获取uniform数据 16 | QGLShaderProgram* getShader(); 17 | protected: 18 | void initialShader(); 19 | QGLShaderProgram m_shaderprogram; //shader程序管理 20 | }; 21 | -------------------------------------------------------------------------------- /Result/示波器第一版1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Result/示波器第一版1.png -------------------------------------------------------------------------------- /Result/示波器第一版2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Result/示波器第一版2.png -------------------------------------------------------------------------------- /Result/示波器第一版3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liulangx/oscilloscopeQt/b244bea6080f7acd8ba2eb85b5f9319d2e03f68f/Result/示波器第一版3.png -------------------------------------------------------------------------------- /Shaders/basic.Frag: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | in vec4 outcolor; 4 | 5 | void main(void) 6 | { 7 | gl_FragColor = outcolor; 8 | }; 9 | 10 | //#version 420 core 11 | 12 | //in layout(location=1) vec4 Color; 13 | 14 | ////in vec4 outcolor; 15 | ////in vec4 finalcolor; 16 | 17 | ////layout(location = 1) out vec4 Color; 18 | ////out vec4 out_color; 19 | //uniform int chose; 20 | //uniform vec4 lineColor; 21 | ////out vec4 out_color; 22 | 23 | //void main(void) 24 | //{ 25 | // if(chose == 1) 26 | // gl_FragColor = lineColor; 27 | // else if(chose == 0) 28 | // gl_FragColor = Color; 29 | //// Color = finalcolor; 30 | 31 | //}; 32 | -------------------------------------------------------------------------------- /Shaders/basic.vert: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | in layout(location=0) vec3 Position; 3 | in layout(location=1) vec4 Color; 4 | 5 | uniform int chose; 6 | uniform vec4 lineColor; 7 | uniform int drawtype; 8 | uniform float scale; //zoom 9 | uniform mat4 rot; //view matrix 10 | uniform vec2 rangeX; //X range 11 | uniform vec2 rangeY; //Y range 12 | uniform vec2 rangeZ; //Z range 13 | uniform mat4 move; //移动 14 | uniform vec3 basecord; //基准坐标 15 | uniform mat4 projection; 16 | uniform float viewScale; 17 | 18 | out vec4 outcolor; 19 | void main() 20 | { 21 | vec4 _tmpposition; 22 | mat4 _rightHandChange = mat4( 23 | 1.0f, 0.0f, 0.0f, 0.0f, 24 | 0.0f, 1.0f, 0.0f, 0.0f, 25 | 0.0f, 0.0f, -1.0f, 0.0f, 26 | 0.0f,0.0f,0.0f,1.0f 27 | ); //转为右手坐标系 28 | //mat4 _tmpRot; 29 | 30 | if(1==chose) //point 31 | { 32 | outcolor = lineColor; 33 | float X = rangeX.x-rangeX.y; 34 | float Y = rangeY.x-rangeY.y; 35 | float Z = rangeZ.x-rangeZ.y; 36 | switch(drawtype) 37 | { 38 | case 0: //xyz 39 | { 40 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale,viewScale * (Position.y-rangeY.y)/Y*scale, viewScale * (Position.z-rangeZ.y)/Z*scale,1); 41 | _tmpposition -=vec4(basecord,0); 42 | break; 43 | } 44 | case 1: //xy 45 | { 46 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale*1.8,viewScale * (Position.y-rangeY.y)/Y*scale*1.8, 0,1); 47 | _tmpposition -=vec4(basecord,0); 48 | break; 49 | } 50 | case 2: //xz 51 | { 52 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale*1.8,0, viewScale * (Position.z-rangeZ.y)/Z*scale*1.8,1); 53 | _tmpposition -=vec4(basecord,0); 54 | 55 | break; 56 | } 57 | case 3: //yz 58 | { 59 | _tmpposition = vec4(0,viewScale * (Position.y-rangeY.y)/Y*scale*1.8, viewScale * (Position.z-rangeZ.y)/Z*scale*1.8,1); 60 | _tmpposition -=vec4(basecord,0); 61 | 62 | break; 63 | } 64 | } 65 | } 66 | if(0==chose) 67 | { 68 | _tmpposition = vec4(Position.x, Position.y, Position.z, 1); 69 | outcolor = Color; 70 | } 71 | vec4 _tmpsiztion1; 72 | if(drawtype == 0) 73 | { 74 | _tmpsiztion1 = move * rot * _tmpposition; 75 | _tmpsiztion1.z -= 15; 76 | gl_Position = /*_rightHandChange **/ projection * _tmpsiztion1; 77 | } 78 | else 79 | { 80 | _tmpsiztion1 = move * rot * _tmpposition; 81 | gl_Position = /*_rightHandChange **/ projection * _tmpsiztion1; 82 | } 83 | 84 | 85 | //gl_Position = move * rot * _tmpposition; 86 | }; 87 | -------------------------------------------------------------------------------- /Shaders/coord.frag: -------------------------------------------------------------------------------- 1 | #version 430 core 2 | 3 | //in vec4 outcolor; 4 | in vec2 pass_texture; 5 | 6 | out vec4 out_color; 7 | 8 | uniform sampler2D texture0; 9 | uniform sampler2D texture1; 10 | 11 | void main(void) 12 | { 13 | //gl_FragColor = outcolor; 14 | vec4 textureColor = texture(texture0, pass_texture); 15 | if(textureColor.a < 0.5) 16 | { 17 | discard; 18 | } 19 | out_color = textureColor; 20 | //out_color = mix(texture(texture1, pass_texture),texture(texture0,pass_texture),0); 21 | //out_color = outcolor; 22 | }; 23 | -------------------------------------------------------------------------------- /Shaders/coord.vert: -------------------------------------------------------------------------------- 1 | #version 430 core 2 | //in layout(location=0) vec3 Position; 3 | in layout(location=0) vec3 Position; 4 | //in layout(location=1) vec4 Color; 5 | //in vec4 Color; 6 | in layout(location=1) vec2 textureCoords; 7 | 8 | uniform mat4 _rot; 9 | uniform mat4 _projection; 10 | uniform mat4 _move; 11 | uniform int _drawtype; 12 | uniform vec2 _rangeX; //X range 13 | uniform vec2 _rangeY; //Y range 14 | uniform vec2 _rangeZ; //Z range 15 | 16 | //out vec4 outcolor; 17 | out vec2 pass_texture; 18 | void main(void) 19 | { 20 | vec4 _tmpposition; 21 | mat4 _rightHandChange = mat4( 22 | 1.0f, 0.0f, 0.0f, 0.0f, 23 | 0.0f, 1.0f, 0.0f, 0.0f, 24 | 0.0f, 0.0f, -1.0f, 0.0f, 25 | 0.0f,0.0f,0.0f,1.0f 26 | ); //转为右手坐标系 27 | float X = _rangeX.x-_rangeX.y; 28 | float Y = _rangeY.x-_rangeY.y; 29 | float Z = _rangeZ.x-_rangeZ.y; 30 | // switch(_drawtype) 31 | // { 32 | // case 0: //xyz 33 | // { 34 | // _tmpposition = vec4(Position.x, Position.y, Position.z, 1); 35 | // //_tmpposition -=vec4(basecord,0); 36 | // gl_Position = /*_rightHandChange **/ _projection * _move * _rot * _tmpposition; 37 | // break; 38 | // } 39 | // case 1: //xy 40 | // { 41 | // _tmpposition = vec4(Position.x, Position.y, Position.z, 1); 42 | // //_tmpposition -=vec4(basecord,0); 43 | // gl_Position = /*_rightHandChange **/ _projection * _move * _tmpposition; 44 | // break; 45 | // } 46 | // case 2: //xz 47 | // { 48 | // _tmpposition = vec4(Position.x, Position.y, Position.z - 0.1*Y, 1); 49 | // //_tmpposition -=vec4(basecord,0); 50 | // gl_Position = /*_rightHandChange **/ _projection * _move * _tmpposition; 51 | // break; 52 | // } 53 | // case 3: //yz 54 | // { 55 | // _tmpposition = vec4(Position.x, Position.y - 0.1*Z, Position.z, 1); 56 | // //_tmpposition -=vec4(basecord,0); 57 | // gl_Position = /*_rightHandChange **/ _projection * _move * _tmpposition; 58 | // break; 59 | // } 60 | // } 61 | vec4 _tmpsiztion1; 62 | if(0 == _drawtype) 63 | { 64 | _tmpsiztion1 = _move * _rot * vec4(Position, 1); 65 | _tmpsiztion1.z -= 15; 66 | gl_Position = /*_rightHandChange **/ _projection * _tmpsiztion1; 67 | } 68 | else 69 | { 70 | _tmpsiztion1 = _move * _rot * vec4(Position, 1); 71 | gl_Position = /*_rightHandChange **/ _projection * _tmpsiztion1; 72 | } 73 | pass_texture = textureCoords; 74 | 75 | }; 76 | -------------------------------------------------------------------------------- /Shaders/lines.Frag: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | uniform vec4 lineColor; 4 | void main(void) 5 | { 6 | gl_FragColor = lineColor; 7 | }; 8 | -------------------------------------------------------------------------------- /Shaders/lines.geo: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | layout(lines) in ; 3 | layout(line_strip, max_vertices = 2) out; 4 | 5 | uniform int drawtype; 6 | uniform float scale; //zoom 7 | uniform mat4 rot; //view matrix 8 | uniform vec2 rangeX; //X range 9 | uniform vec2 rangeY; //Y range 10 | uniform vec2 rangeZ; //Z range 11 | uniform mat4 move; //移动 12 | uniform vec3 basecord; //基准坐标 13 | uniform mat4 projection; 14 | uniform float viewScale; 15 | 16 | uniform bool xyPlaneMark; 17 | uniform bool xzPlaneMark; 18 | uniform bool yzPlaneMark; 19 | 20 | uniform float xLower; 21 | uniform float yLower; 22 | uniform float zLower; 23 | 24 | void main() 25 | { 26 | vec4 _tmpposition; 27 | mat4 _rightHandChange = mat4( 28 | 1.0f, 0.0f, 0.0f, 0.0f, 29 | 0.0f, 1.0f, 0.0f, 0.0f, 30 | 0.0f, 0.0f, -1.0f, 0.0f, 31 | 0.0f,0.0f,0.0f,1.0f 32 | ); //转为右手坐标系 33 | //mat4 _tmpRot; 34 | 35 | float X = rangeX.x-rangeX.y; 36 | float Y = rangeY.x-rangeY.y; 37 | float Z = rangeZ.x-rangeZ.y; 38 | vec3 Position; 39 | if(xyPlaneMark) 40 | { 41 | Position = vec3(gl_in[0].gl_Position.x, gl_in[0].gl_Position.y, zLower); 42 | } 43 | else if(xzPlaneMark) 44 | { 45 | Position = vec3(gl_in[0].gl_Position.x, yLower, gl_in[0].gl_Position.z); 46 | } 47 | else if(yzPlaneMark) 48 | { 49 | Position = vec3(xLower, gl_in[0].gl_Position.y, gl_in[0].gl_Position.z); 50 | } 51 | else { 52 | Position = vec3(gl_in[0].gl_Position.x, gl_in[0].gl_Position.y, gl_in[0].gl_Position.z); 53 | } 54 | switch(drawtype) 55 | { 56 | case 0: //xyz 57 | { 58 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale,viewScale * (Position.y-rangeY.y)/Y*scale, viewScale * (Position.z-rangeZ.y)/Z*scale,1); 59 | _tmpposition -=vec4(basecord,0); 60 | break; 61 | } 62 | case 1: //xy 63 | { 64 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale*1.8,viewScale * (Position.y-rangeY.y)/Y*scale*1.8, 0,1); 65 | _tmpposition -=vec4(basecord,0); 66 | break; 67 | } 68 | case 2: //xz 69 | { 70 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale*1.8,0, viewScale * (Position.z-rangeZ.y)/Z*scale*1.8,1); 71 | _tmpposition -=vec4(basecord,0); 72 | 73 | break; 74 | } 75 | case 3: //yz 76 | { 77 | _tmpposition = vec4(0,viewScale * (Position.y-rangeY.y)/Y*scale*1.8, viewScale * (Position.z-rangeZ.y)/Z*scale*1.8,1); 78 | _tmpposition -=vec4(basecord,0); 79 | 80 | break; 81 | } 82 | } 83 | 84 | vec4 _tmpPosition1; 85 | if(drawtype == 0) 86 | { 87 | _tmpPosition1 = move * rot * _tmpposition; 88 | _tmpPosition1.z -= 15; 89 | gl_Position = /*_rightHandChange **/ projection * _tmpPosition1; 90 | } 91 | else 92 | { 93 | _tmpPosition1 = move * rot * _tmpposition; 94 | gl_Position = /*_rightHandChange */ projection * _tmpPosition1; 95 | } 96 | 97 | EmitVertex(); 98 | 99 | _rightHandChange = mat4( 100 | 1.0f, 0.0f, 0.0f, 0.0f, 101 | 0.0f, 1.0f, 0.0f, 0.0f, 102 | 0.0f, 0.0f, -1.0f, 0.0f, 103 | 0.0f,0.0f,0.0f,1.0f 104 | ); //转为右手坐标系 105 | 106 | if(xyPlaneMark) 107 | { 108 | Position = vec3(gl_in[1].gl_Position.x, gl_in[1].gl_Position.y, zLower); 109 | } 110 | else if(xzPlaneMark) 111 | { 112 | Position = vec3(gl_in[1].gl_Position.x, yLower, gl_in[1].gl_Position.z); 113 | } 114 | else if(yzPlaneMark) 115 | { 116 | Position = vec3(xLower, gl_in[1].gl_Position.y, gl_in[1].gl_Position.z); 117 | } 118 | else { 119 | Position = vec3(gl_in[1].gl_Position.x, gl_in[1].gl_Position.y, gl_in[1].gl_Position.z); 120 | } 121 | 122 | switch(drawtype) 123 | { 124 | case 0: //xyz 125 | { 126 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale,viewScale * (Position.y-rangeY.y)/Y*scale, viewScale * (Position.z-rangeZ.y)/Z*scale,1); 127 | _tmpposition -=vec4(basecord,0); 128 | break; 129 | } 130 | case 1: //xy 131 | { 132 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale*1.8,viewScale * (Position.y-rangeY.y)/Y*scale*1.8, 0,1); 133 | _tmpposition -=vec4(basecord,0); 134 | break; 135 | } 136 | case 2: //xz 137 | { 138 | _tmpposition = vec4(viewScale * (Position.x-rangeX.y)/X*scale*1.8,0, viewScale * (Position.z-rangeZ.y)/Z*scale*1.8,1); 139 | _tmpposition -=vec4(basecord,0); 140 | 141 | break; 142 | } 143 | case 3: //yz 144 | { 145 | _tmpposition = vec4(0,viewScale * (Position.y-rangeY.y)/Y*scale*1.8, viewScale * (Position.z-rangeZ.y)/Z*scale*1.8,1); 146 | _tmpposition -=vec4(basecord,0); 147 | 148 | break; 149 | } 150 | } 151 | if(drawtype == 0) 152 | { 153 | _tmpPosition1 = move * rot * _tmpposition; 154 | _tmpPosition1.z -= 15; 155 | gl_Position = /*_rightHandChange **/ projection * _tmpPosition1; 156 | } 157 | else 158 | { 159 | _tmpPosition1 = move * rot * _tmpposition; 160 | gl_Position = /*_rightHandChange */ projection * _tmpPosition1; 161 | } 162 | 163 | 164 | EmitVertex(); 165 | 166 | EndPrimitive(); 167 | } 168 | -------------------------------------------------------------------------------- /Shaders/lines.vert: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | in layout(location=0) vec3 Position; 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(Position.xyz, 1); 7 | }; 8 | -------------------------------------------------------------------------------- /UDPServer/CAsioAsyncServer.cpp: -------------------------------------------------------------------------------- 1 | #include "UDPServer/CAsioAsyncServer.h" 2 | #include 3 | const long int queueSize = 5000; 4 | CAsioAsyncServer::CAsioAsyncServer(boost::asio::io_service &io_service, unsigned short port) 5 | : m_socketRecv(io_service, udp::endpoint(udp::v4(), port)), 6 | m_messageRecv(new Message), 7 | m_lastFrame(0), 8 | m_coutlost(0), 9 | m_recvMsgs(new boost::circular_buffer(queueSize)) 10 | { 11 | if(false == m_socketRecv.is_open()) 12 | m_socketRecv.open(udp::v4()); 13 | bool isconnect = connect(this, SIGNAL(asioClose()), this, SLOT(onAsioClose())); 14 | 15 | } 16 | 17 | CAsioAsyncServer::~CAsioAsyncServer() 18 | { 19 | m_socketRecv.close(); 20 | delete m_messageRecv; 21 | } 22 | 23 | void CAsioAsyncServer::run() 24 | { 25 | startRecv(); 26 | } 27 | 28 | //void CAsioAsyncServer::convertMessageToQopenglMainWidget(list thecharts) 29 | //{ 30 | // float x = 0; 31 | // float y = 0; 32 | // float z = 0; 33 | // vector4f _color; 34 | // boost::mutex::scoped_lock lock(m_mutex); 35 | // for(boost::circular_buffer::iterator it = m_recvMsgs->begin(); it != m_recvMsgs->end(); ) 36 | // { 37 | // x = it->mData.dataX; 38 | // y = it->mData.dataY; 39 | // z = it->mData.dataZ; 40 | // for (auto obj : thecharts) 41 | // { 42 | // //QOpenglMain.addPoint(); 43 | // obj->addPoint(0, { x, y, z}); // 44 | // _color._r = 1; _color._g = 0; 45 | // _color._b = 1; _color._a = 1; 46 | // obj->setColor(0, _color); 47 | // //obj->GetChart()->addLine(4320000); 48 | // obj->addPoint(1, { x + 1, y + 1, z + 1}); //{ 0,0,1,1 } 49 | //// //obj->GetChart()->addLine(4320000); 50 | // _color._r = 0; _color._g = 0; 51 | // _color._b = 1; _color._a = 1; 52 | // obj->setColor(1, _color); 53 | // obj->addPoint(2, { x + 2, y + 2, z + 2}); //{ 0,1,0,1 } 54 | // _color._r = 0; _color._g = 1; 55 | // _color._b = 0; _color._a = 1; 56 | // obj->setColor(2, _color); 57 | // obj->addPoint(3, { x + 3, y + 3, z + 3}); //{ 0,1,1,1 } 58 | // _color._r = 1; _color._g = 0; 59 | // _color._b = 0; _color._a = 1; 60 | // obj->setColor(3, _color); 61 | // } 62 | // ++it; 63 | // if(m_recvMsgs->size() != 0) 64 | // m_recvMsgs->pop_front(); 65 | // } 66 | // lock.unlock(); 67 | //} 68 | 69 | void CAsioAsyncServer::getCirBuffer(CirBufferLL *cirBuffer) 70 | { 71 | boost::mutex::scoped_lock lock(m_mutex); 72 | for(boost::circular_buffer::iterator it = m_recvMsgs->begin(); it != m_recvMsgs->end(); ++it) 73 | { 74 | qDebug() << cirBuffer->size(); 75 | cirBuffer->push_back(*it); 76 | qDebug() << cirBuffer->size(); 77 | qDebug() << it->mData.dataX << " " << it->mData.dataY << " " << it->mData.dataZ; 78 | } 79 | m_recvMsgs->clear(); 80 | lock.unlock(); 81 | } 82 | 83 | void CAsioAsyncServer::startRecv() 84 | { 85 | m_socketRecv.async_receive_from( 86 | boost::asio::buffer(m_messageRecv, sizeof(Message)), m_recvEp, 87 | boost::bind(&CAsioAsyncServer::handleRecv, this, 88 | boost::asio::placeholders::error, 89 | boost::asio::placeholders::bytes_transferred)); 90 | } 91 | 92 | void CAsioAsyncServer::handleRecv(const boost::system::error_code &error, std::size_t recvSize) 93 | { 94 | if(closeMark) 95 | return; 96 | m_socketRecv.async_receive_from( 97 | boost::asio::buffer(m_messageRecv, sizeof(Message)), m_recvEp, 98 | boost::bind(&CAsioAsyncServer::handleRecv, this, 99 | boost::asio::placeholders::error, 100 | boost::asio::placeholders::bytes_transferred)); 101 | if((0x18 == m_messageRecv->frameSyn[0]) && (0x52 == m_messageRecv->frameSyn[1])) 102 | { 103 | if((int)m_messageRecv->frame > (m_lastFrame + 1)) 104 | { 105 | m_coutlost += ((int)m_messageRecv->frame - m_lastFrame); 106 | m_lastFrame = (int)m_messageRecv->frame; 107 | boost::mutex::scoped_lock lock(m_mutex); 108 | m_recvMsgs->push_back(*m_messageRecv); 109 | lock.unlock(); 110 | } 111 | else if((int)m_messageRecv->frame == (m_lastFrame + 1)) 112 | { 113 | m_lastFrame ++; 114 | boost::mutex::scoped_lock lock(m_mutex); 115 | m_recvMsgs->push_back(*m_messageRecv); 116 | lock.unlock(); 117 | } 118 | else 119 | { 120 | //throw; 121 | } 122 | } 123 | } 124 | 125 | void CAsioAsyncServer::close() 126 | { 127 | emit asioClose(); 128 | closeMark = true; 129 | } 130 | 131 | 132 | void CAsioAsyncServer::onAsioClose() 133 | { 134 | closeMark = true; 135 | } 136 | -------------------------------------------------------------------------------- /UDPServer/CAsioAsyncServer.h: -------------------------------------------------------------------------------- 1 | #ifndef CASIOASYNCSERVER_H 2 | #define CASIOASYNCSERVER_H 3 | 4 | /* Class Name: CAsioAsyncServer; 5 | * Description: 6 | * This class is for receiving Message using ASIO's async UDP protocol; 7 | * The Message is defined as bellow: 8 | * struct MData 9 | * { 10 | * u_short imageNumber; 11 | * float dataX; 12 | * float dataY; 13 | * float dataZ; 14 | * }; 15 | * struct Message { 16 | * u_char frameSyn[2];//= 0x5218; 17 | * u_short frameLength; 18 | * u_char frameType; 19 | * u_short messageCount; 20 | * u_char checkByte; 21 | * u_int frame; 22 | * MData mData; 23 | * }; 24 | * Function: 25 | * 1. Define the port(e.g. 8001) to receive data; 26 | * 2. Convert the cirbuffer's pointer to receive data; 27 | * Tips: No 28 | */ 29 | #include 30 | #include 31 | //#include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | //class QOpenglMain; 42 | using boost::asio::ip::udp; 43 | using namespace std; 44 | 45 | struct MData 46 | { 47 | u_short imageNumber; 48 | u_short lineNumber; 49 | float dataX; 50 | float dataY; 51 | float dataZ; 52 | }; 53 | struct Message { 54 | u_char frameSyn[2];//= 0x5218; 55 | u_short frameLength; 56 | u_char frameType; 57 | u_short messageCount; 58 | u_char checkByte; 59 | u_int frame; 60 | MData mData; 61 | }; 62 | typedef boost::circular_buffer CirBufferLL; 63 | 64 | class CAsioAsyncServer : public QObject 65 | { 66 | Q_OBJECT 67 | public : 68 | void close(); 69 | signals: 70 | void asioClose(); 71 | private slots: 72 | void onAsioClose(); 73 | public: 74 | CAsioAsyncServer(boost::asio::io_service &io_service, unsigned short port); 75 | ~CAsioAsyncServer(); 76 | /* 函数: run 77 | * 函数描述: 开始监听,将数据保存在CirBufferLL中, 调用startRecv; 78 | */ 79 | void run(); 80 | /* 函数: virtual Message getMessage(list thecharts) 81 | * 函数描述:该函数被定义来对数据进行处理,在读取数据过程中,使用互斥锁来对数据进行锁定,可以被重新写; 82 | */ 83 | // virtual void convertMessageToQopenglMainWidget(list thecharts); 84 | void getCirBuffer(CirBufferLL* cirBuffer); 85 | protected: 86 | void startRecv(); 87 | virtual void handleRecv(const boost::system::error_code &error, std::size_t recvSize); 88 | 89 | 90 | 91 | private: 92 | bool closeMark = false; 93 | udp::socket m_socketRecv; //socket for receiving 94 | udp::endpoint m_recvEp; // 95 | Message* m_messageRecv; //storage for the receiving Message; 96 | int m_lastFrame; //for couting lost rate; 97 | int m_coutlost; 98 | CirBufferLL* m_recvMsgs; //the cirbuffer's pointer 99 | boost::mutex m_mutex; //lock for seperating the reading and writing process; 100 | CirBufferLL m_cirBuffer; 101 | }; 102 | 103 | #endif // CASIOASYNCSERVER_H 104 | -------------------------------------------------------------------------------- /Widgets/CCopyQOpenglWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "Widgets/CCopyQOpenglWidget.h" 2 | 3 | 4 | CopyQOpenglWidget::CopyQOpenglWidget(u_char _frameType, CChart::DRAWTYPE _drawType, CAllocVBOandVAO *_allocVBOandVAO, Widget *_mainWidget, QString _checkBoxSenderName, QWidget *parent) 5 | : QWidget(parent), 6 | m_allocVBOandVAO(/*new CAllocVBOandVAO*/_allocVBOandVAO), 7 | m_chart(new QOpenglMain(_frameType, _allocVBOandVAO, _drawType)), 8 | m_mainVLayout(new QVBoxLayout), 9 | m_hBoxLayout(new QHBoxLayout), 10 | m_mainWidget(_mainWidget), 11 | m_checkBoxSenderName(_checkBoxSenderName), 12 | m_checkBoxAnix(new QCheckBox(this)), 13 | m_checkBoxGrid(new QCheckBox(this)), 14 | m_checkBoxXyPlane(new QCheckBox(this)), 15 | m_checkBoxXzPlane(new QCheckBox(this)), 16 | m_checkBoxYzPlane(new QCheckBox(this)), 17 | m_comboBox(new CComboBox(m_chart, this)) 18 | { 19 | 20 | } 21 | 22 | CopyQOpenglWidget::~CopyQOpenglWidget() 23 | { 24 | LLDELETE(m_checkBoxAnix) 25 | LLDELETE(m_checkBoxGrid) 26 | LLDELETE(m_checkBoxXyPlane) 27 | LLDELETE(m_checkBoxXzPlane) 28 | LLDELETE(m_checkBoxYzPlane) 29 | LLDELETE(m_comboBox) 30 | LLDELETE(m_hBoxLayout) 31 | LLDELETE(m_mainVLayout) 32 | LLDELETE(m_chart) 33 | } 34 | 35 | void CopyQOpenglWidget::setChartObjectName(QString _title) 36 | { 37 | m_chart->setObjectName(_title); 38 | } 39 | 40 | void CopyQOpenglWidget::setChartCopyFromOtherOpenWidgetMark(bool _notCopyMark) 41 | { 42 | m_chart->setCopyFromOtherOpenWidgetMark(_notCopyMark); 43 | } 44 | 45 | void CopyQOpenglWidget::setChartVaoAndVbosBuffer(vector& _tmpVBO, vector& _tmpVBOIndex) 46 | { 47 | m_chart->setVaoAndVbosBuffer(_tmpVBO, _tmpVBOIndex); 48 | } 49 | 50 | void CopyQOpenglWidget::setChartCordRangei(vector2f _xRange, vector2f _yRange, vector2f _zRange) 51 | { 52 | m_chart->setCordRangei(_xRange, _yRange, _zRange); 53 | } 54 | 55 | void CopyQOpenglWidget::setChartDrawType(CChart::DRAWTYPE _drawType) 56 | { 57 | m_chart->setDrawType(_drawType); 58 | } 59 | 60 | void CopyQOpenglWidget::setChartMove(QMatrix4x4 _move) 61 | { 62 | m_chart->setMove(_move); 63 | } 64 | 65 | void CopyQOpenglWidget::setChartRotation(QMatrix4x4 _rotation) 66 | { 67 | m_chart->setRotation(_rotation); 68 | } 69 | 70 | void CopyQOpenglWidget::setChartGridNumer(int _xGridNumber, int _yGridNumber, int _zGridNumber) 71 | { 72 | m_chart->setGridNumer(_xGridNumber, _yGridNumber, _zGridNumber); 73 | } 74 | 75 | void CopyQOpenglWidget::setChartLinesVboBufferData(list >& _tmpLinesVbo, vector& _tmpLinesAmount) 76 | { 77 | m_chart->setLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 78 | } 79 | 80 | void CopyQOpenglWidget::setChartLineColor(map _lineColors) 81 | { 82 | m_chart->setLineColor(_lineColors); 83 | for(map::iterator it = _lineColors.begin(); it != _lineColors.end(); ++it) 84 | { 85 | m_chart->setLinesEnabled(it->first, true); 86 | QString name = "— " + QString::number(it->first); 87 | vector3f color = {it->second._r, it->second._g, it->second._b}; 88 | QVariant data1 = QVariant::fromValue(it->first); 89 | m_comboBox->addNewItemFromOpenglMain(name, data1, color); 90 | } 91 | } 92 | 93 | void CopyQOpenglWidget::setLinesEnabled(size_t _lineIndex, bool _b) 94 | { 95 | m_chart->setLinesEnabled(_lineIndex, _b); 96 | } 97 | 98 | void CopyQOpenglWidget::setTitle(QString _title) 99 | { 100 | setWindowTitle(_title); 101 | } 102 | 103 | void CopyQOpenglWidget::setMainLayout() 104 | { 105 | m_hBoxLayout->addWidget(m_checkBoxGrid, 0); 106 | m_hBoxLayout->addWidget(m_checkBoxAnix, 0); 107 | m_hBoxLayout->addWidget(m_checkBoxXyPlane, 0); 108 | m_hBoxLayout->addWidget(m_checkBoxXzPlane, 0); 109 | m_hBoxLayout->addWidget(m_checkBoxYzPlane, 0); 110 | m_hBoxLayout->addWidget(m_comboBox, 1); 111 | m_hBoxLayout->addStretch(); 112 | m_checkBoxAnix->setText("坐标"); 113 | m_checkBoxAnix->setChecked(true); 114 | m_checkBoxGrid->setText("网格"); 115 | m_checkBoxGrid->setChecked(true); 116 | m_checkBoxXyPlane->setText("XY"); 117 | m_checkBoxXyPlane->setChecked(false); 118 | m_checkBoxXzPlane->setText("XZ"); 119 | m_checkBoxXzPlane->setChecked(false); 120 | m_checkBoxYzPlane->setText("YZ"); 121 | m_checkBoxYzPlane->setChecked(false); 122 | 123 | 124 | 125 | m_checkBoxAnix->setMaximumHeight(15); 126 | m_checkBoxGrid->setMaximumHeight(15); 127 | m_checkBoxXyPlane->setMaximumHeight(15); 128 | m_checkBoxXzPlane->setMaximumHeight(15); 129 | m_checkBoxYzPlane->setMaximumHeight(15); 130 | 131 | connect(m_checkBoxAnix, SIGNAL(stateChanged(int)), m_chart, SLOT(onSetAnixState())); 132 | connect(m_checkBoxGrid, SIGNAL(stateChanged(int)), m_chart, SLOT(onSetGridState())); 133 | connect(m_checkBoxXyPlane, SIGNAL(stateChanged(int)), m_chart, SLOT(onXYPlaneState())); 134 | connect(m_checkBoxXzPlane, SIGNAL(stateChanged(int)), m_chart, SLOT(onXZPlaneState())); 135 | connect(m_checkBoxYzPlane, SIGNAL(stateChanged(int)), m_chart, SLOT(onYZPlaneState())); 136 | 137 | 138 | m_mainVLayout->addLayout(m_hBoxLayout); 139 | m_mainVLayout->addWidget(m_chart); 140 | setLayout(m_mainVLayout); 141 | } 142 | 143 | void CopyQOpenglWidget::update() 144 | { 145 | if(m_chart) 146 | m_chart->update(); 147 | } 148 | 149 | 150 | void CopyQOpenglWidget::closeEvent(QCloseEvent *event) 151 | { 152 | //使用了友元类对原widget中的qcheckbutton的状态进行更改 153 | // int r = QMessageBox::question(this, tr("警告"), tr("确定要退出么?"), QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape); 154 | // if(r == QMessageBox::Yes) 155 | // { 156 | event->accept(); 157 | QCheckBox* tmpCheckBox = m_mainWidget->findChild(m_checkBoxSenderName); 158 | QString tmpName = tmpCheckBox->objectName(); 159 | QString indexS = tmpName.split(' ')[1]; 160 | u_int indexUint = indexS.toUInt(); 161 | 162 | // qDebug() << "tmpName: " << tmpName; 163 | // qDebug() << "tmpName: " << indexS; 164 | // qDebug() << "tmpName: " << indexUint; 165 | tmpCheckBox->setChecked(false); 166 | tmpCheckBox->setEnabled(true); 167 | 168 | //m_mainWidget->m_charts.at(indexUint); 169 | // } 170 | // else 171 | // { 172 | // event->ignore(); 173 | // } 174 | } 175 | -------------------------------------------------------------------------------- /Widgets/CCopyQOpenglWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef COPYQOPENGLWIDGET_H 2 | #define COPYQOPENGLWIDGET_H 3 | #include "mainWidget/tools.h" 4 | #include "MyOpenglWidget/QOpenglMain.h" 5 | #include "DataManageMent/CAllocVBOandVAO.h" 6 | #include "ComboBox/CComboBox.h" 7 | #include 8 | #include 9 | //#include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class Widget; 17 | 18 | class CopyQOpenglWidget : public QWidget, public QOpenGLFunctions_4_3_Core 19 | { 20 | public: 21 | explicit CopyQOpenglWidget(u_char _frameType, CChart::DRAWTYPE _drawType, CAllocVBOandVAO* _allocVBOandVAO, Widget* _mainWidget, QString _checkBoxSenderName, QWidget *parent = 0); 22 | ~CopyQOpenglWidget(); 23 | void setChartObjectName(QString _title); 24 | void setChartCopyFromOtherOpenWidgetMark(bool _notCopyMark); 25 | void setChartVaoAndVbosBuffer(vector &_tmpVBO, vector &_tmpVBOIndex); 26 | void setChartCordRangei(vector2f _xRange, vector2f _yRange, vector2f _zRange); 27 | void setChartDrawType(CChart::DRAWTYPE _drawType); 28 | void setChartMove(QMatrix4x4 _move); 29 | void setChartRotation(QMatrix4x4 _rotation); 30 | void setChartGridNumer(int _xGridNumber, int _yGridNumber, int _zGridNumber); 31 | void setChartLinesVboBufferData(list > &_tmpLinesVbo, vector &_tmpLinesAmount); 32 | void setChartLineColor(map _lineColors); 33 | 34 | void setLinesEnabled(size_t _lineIndex, bool _b); 35 | 36 | void setTitle(QString _title); 37 | void setMainLayout(); 38 | void update(); 39 | //public: 40 | 41 | // QOpenglMain* m_chart; 42 | private: 43 | // friend class CComboBox; 44 | 45 | QOpenglMain* m_chart; 46 | void closeEvent(QCloseEvent *event); 47 | QCheckBox* m_checkBoxAnix; 48 | QCheckBox* m_checkBoxGrid; 49 | QCheckBox* m_checkBoxXyPlane; 50 | QCheckBox* m_checkBoxXzPlane; 51 | QCheckBox* m_checkBoxYzPlane; 52 | CComboBox* m_comboBox; 53 | 54 | QVBoxLayout* m_mainVLayout; 55 | QHBoxLayout* m_hBoxLayout; 56 | 57 | CAllocVBOandVAO* m_allocVBOandVAO; 58 | QString m_checkBoxSenderName; 59 | Widget* m_mainWidget; 60 | }; 61 | 62 | #endif // COPYQOPENGLWIDGET_H 63 | -------------------------------------------------------------------------------- /Widgets/CLLOpenglWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "Widgets/CLLOpenglWidget.h" 2 | 3 | CLLOpenglWidget::CLLOpenglWidget(u_char _frameType, Widget *_mainWidget, CAllocVBOandVAO *_callocVBOandVAO, CChart::DRAWTYPE _drawType, u_short _imageNumber, QWidget *_parent) 4 | : QWidget(_parent), 5 | m_frameType(_frameType), 6 | m_qOpenglMain(new QOpenglMain(_frameType, _callocVBOandVAO, _drawType)), 7 | m_imageNumber(_imageNumber), 8 | m_mainWidget(_mainWidget), 9 | m_mainLayout(new QGridLayout), 10 | m_hBoxLayout(new QHBoxLayout), 11 | m_label(new QLabel), 12 | m_buttonGrid(new QCheckBox(this)), 13 | m_buttonAnix(new QCheckBox(this)), 14 | m_buttonHideOtherWidget(new QCheckBox(this)), 15 | m_buttonOutWidget(new QCheckBox(this)), 16 | m_buttonXYPlane(new QCheckBox(this)), 17 | m_buttonXZPlane(new QCheckBox(this)), 18 | m_buttonYZPlane(new QCheckBox(this)), 19 | m_buttonOFF(new QCheckBox(this)), 20 | m_comboBox(new CComboBox(m_qOpenglMain, this)) 21 | { 22 | QString title = QString("图像 ") + QString::number(m_imageNumber); 23 | m_label->setText(title); 24 | m_label->setMaximumHeight(15); 25 | 26 | m_mainLayout->addWidget(m_label, 0, 0, Qt::AlignHCenter); 27 | 28 | m_buttonGrid->setText("网格"); 29 | m_buttonGrid->setChecked(true); 30 | m_buttonGrid->setStatusTip("显示/隐藏网格"); 31 | m_buttonAnix->setText("坐标"); 32 | m_buttonAnix->setChecked(true); 33 | m_buttonAnix->setStatusTip("显示/隐藏坐标"); 34 | m_buttonHideOtherWidget->setText("隐藏其他"); 35 | m_buttonHideOtherWidget->setChecked(false); 36 | m_buttonHideOtherWidget->setStatusTip("隐藏其他窗口"); 37 | m_buttonHideOtherWidget->setObjectName(QString("buttonHideOtherWidget ") + QString::number(m_imageNumber)); 38 | m_buttonOutWidget->setText("复制"); 39 | m_buttonOutWidget->setStatusTip("从opengl缓冲区读取当前选中的窗口,并绘制和当前窗口一致的新窗口"); 40 | m_buttonOutWidget->setChecked(false); 41 | m_buttonOutWidget->setObjectName(QString("buttonOutWidget ") + QString::number(m_imageNumber)); 42 | m_buttonXYPlane->setText("XY"); 43 | m_buttonXYPlane->setChecked(false); 44 | m_buttonXYPlane->setStatusTip("显示/隐藏XY平面的投影"); 45 | m_buttonXZPlane->setText("XZ"); 46 | m_buttonXZPlane->setChecked(false); 47 | m_buttonXZPlane->setStatusTip("显示/隐藏XZ平面的投影"); 48 | m_buttonYZPlane->setText("YZ"); 49 | m_buttonYZPlane->setChecked(false); 50 | m_buttonYZPlane->setStatusTip("显示/隐藏YZ平面的投影"); 51 | 52 | m_buttonOFF->setText("提取"); 53 | m_buttonOFF->setStatusTip("该按钮从当前保存的文件中提取数据,并绘制和当前窗口数据一样的新窗口"); 54 | m_buttonOFF->setChecked(false); 55 | m_buttonOFF->setObjectName(QString("m_buttonOFF ") + QString::number(m_imageNumber)); 56 | 57 | connect(m_buttonGrid, SIGNAL(stateChanged(int)), m_qOpenglMain, SLOT(onSetGridState())); 58 | connect(m_buttonAnix, SIGNAL(stateChanged(int)), m_qOpenglMain, SLOT(onSetAnixState())); 59 | connect(m_buttonHideOtherWidget, SIGNAL(stateChanged(int)), m_mainWidget, SLOT(onHideOtherOpenGLWidget())); 60 | connect(m_buttonOutWidget, SIGNAL(stateChanged(int)), m_mainWidget, SLOT(onSetOutDisplayState())); 61 | connect(m_buttonXYPlane, SIGNAL(stateChanged(int)), m_qOpenglMain, SLOT(onXYPlaneState())); 62 | connect(m_buttonXZPlane, SIGNAL(stateChanged(int)), m_qOpenglMain, SLOT(onXZPlaneState())); 63 | connect(m_buttonYZPlane, SIGNAL(stateChanged(int)), m_qOpenglMain, SLOT(onYZPlaneState())); 64 | connect(m_buttonOFF, SIGNAL(stateChanged(int)), m_mainWidget, SLOT(onReadFromFileOutDisplayState())); 65 | 66 | m_hBoxLayout->addWidget(m_buttonGrid); 67 | m_hBoxLayout->addWidget(m_buttonAnix); 68 | m_hBoxLayout->addWidget(m_buttonHideOtherWidget); 69 | m_hBoxLayout->addWidget(m_buttonOutWidget); 70 | m_hBoxLayout->addWidget(m_buttonXYPlane); 71 | m_hBoxLayout->addWidget(m_buttonXZPlane); 72 | m_hBoxLayout->addWidget(m_buttonYZPlane); 73 | m_hBoxLayout->addWidget(m_buttonOFF); 74 | m_hBoxLayout->addWidget(m_comboBox, 1); 75 | m_hBoxLayout->addStretch(); 76 | 77 | m_mainLayout->addLayout(m_hBoxLayout, 1, 0); 78 | m_mainLayout->addWidget(m_qOpenglMain, 2, 0); 79 | setLayout(m_mainLayout); 80 | } 81 | 82 | CLLOpenglWidget::~CLLOpenglWidget() 83 | { 84 | LLDELETE(m_qOpenglMain) 85 | LLDELETE(m_hBoxLayout) 86 | LLDELETE(m_mainLayout) 87 | LLDELETE(m_buttonAnix) 88 | LLDELETE(m_buttonGrid) 89 | LLDELETE(m_buttonHideOtherWidget) 90 | LLDELETE(m_buttonOutWidget) 91 | LLDELETE(m_buttonXYPlane) 92 | LLDELETE(m_buttonXZPlane) 93 | LLDELETE(m_buttonYZPlane) 94 | LLDELETE(m_comboBox) 95 | LLDELETE(m_buttonOFF) 96 | LLDELETE(m_label) 97 | } 98 | 99 | bool CLLOpenglWidget::addPoint(size_t _lineindex, const vector3f &_posion) 100 | { 101 | return m_qOpenglMain->addPoint(_lineindex, _posion); 102 | } 103 | 104 | void CLLOpenglWidget::setColor(size_t _lineIndex, vector4f _color) 105 | { 106 | m_qOpenglMain->setColor(_lineIndex, _color); 107 | QString name = "— " + QString::number(_lineIndex); 108 | vector3f color = {_color._r, _color._g, _color._b}; 109 | QVariant data1 = QVariant::fromValue(_lineIndex); 110 | // size_t x = data1.value(); 111 | m_comboBox->addNewItemFromOpenglMain(name, data1, color); 112 | } 113 | 114 | bool CLLOpenglWidget::checkRangeChange(vector2f &_xRange, vector2f &_yRange, vector2f &_zRange) 115 | { 116 | return m_qOpenglMain->checkRangeChange(_xRange, _yRange, _zRange); 117 | } 118 | 119 | u_char CLLOpenglWidget::getFrameType() const 120 | { 121 | return m_frameType; 122 | } 123 | 124 | void CLLOpenglWidget::update() 125 | { 126 | m_qOpenglMain->update(); 127 | } 128 | 129 | void CLLOpenglWidget::setLinesEnabled(size_t _lineIndex, bool _b) 130 | { 131 | m_qOpenglMain->setLinesEnabled(_lineIndex, _b); 132 | } 133 | 134 | QOpenglMain *CLLOpenglWidget::getQOpenglMain() const 135 | { 136 | return m_qOpenglMain; 137 | } 138 | 139 | -------------------------------------------------------------------------------- /Widgets/CLLOpenglWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef CLLOPENGLWIDGET_H 2 | #define CLLOPENGLWIDGET_H 3 | #include "mainWidget/tools.h" 4 | #include "MyOpenglWidget/QOpenglMain.h" 5 | #include "mainWidget/Widget.h" 6 | #include "ComboBox/CComboBox.h" 7 | #include 8 | #include 9 | 10 | class Widget; 11 | 12 | class CLLOpenglWidget : public QWidget 13 | { 14 | public: 15 | explicit CLLOpenglWidget(u_char _frameType, Widget *_mainWidget, CAllocVBOandVAO *_callocVBOandVAO, CChart::DRAWTYPE _drawType, u_short _imageNumber,QWidget *_parent = nullptr); 16 | ~CLLOpenglWidget(); 17 | 18 | bool addPoint(size_t _lineindex, const vector3f & _posion); 19 | void setColor(size_t _lineIndex, vector4f _color); 20 | bool checkRangeChange(vector2f& _xRange, vector2f& _yRange, vector2f& _zRange); 21 | 22 | u_char getFrameType() const; 23 | 24 | void update(); 25 | 26 | void setLinesEnabled(size_t _lineIndex, bool _b); 27 | 28 | QOpenglMain *getQOpenglMain() const; 29 | 30 | //public: 31 | // QOpenglMain *m_qOpenglMain; 32 | private: 33 | // friend class CComboBox; 34 | QOpenglMain *m_qOpenglMain; 35 | Widget *m_mainWidget; 36 | 37 | QGridLayout *m_mainLayout; 38 | QLabel *m_label; 39 | QHBoxLayout *m_hBoxLayout; 40 | QCheckBox *m_buttonGrid; 41 | QCheckBox *m_buttonAnix; 42 | QCheckBox *m_buttonHideOtherWidget; 43 | QCheckBox *m_buttonOutWidget; 44 | QCheckBox *m_buttonXYPlane; 45 | QCheckBox *m_buttonXZPlane; 46 | QCheckBox *m_buttonYZPlane; 47 | CComboBox *m_comboBox; 48 | 49 | QCheckBox *m_buttonOFF; 50 | 51 | u_short m_imageNumber; 52 | u_char m_frameType = 0; 53 | }; 54 | 55 | #endif // CLLOPENGLWIDGET_H 56 | -------------------------------------------------------------------------------- /Widgets/COFFOpenglwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "Widgets/COFFOpenglwidget.h" 2 | 3 | COFFOpenglWidget::COFFOpenglWidget(u_char _frameType, CAllocVBOandVAO *_allocVBOandVAO, Widget *_mainWidget, QString _checkBoxSenderName, QWidget *parent) 4 | : QWidget(parent), 5 | m_allocVBOandVAO(/*new CAllocVBOandVAO*/_allocVBOandVAO), 6 | m_mainVLayout(new QVBoxLayout(this)), 7 | m_hBoxLayout(new QHBoxLayout(this)), 8 | m_mainWidget(_mainWidget), 9 | m_checkBoxSenderName(_checkBoxSenderName), 10 | m_checkBoxAnix(new QCheckBox(this)), 11 | m_checkBoxGrid(new QCheckBox(this)), 12 | m_checkBoxXyPlane(new QCheckBox(this)), 13 | m_checkBoxXzPlane(new QCheckBox(this)), 14 | m_checkBoxYzPlane(new QCheckBox(this)) 15 | 16 | { 17 | if(0 == _frameType) 18 | { 19 | m_chart = new QOpenglMain(_frameType, _allocVBOandVAO, CChart::DRAWTYPE::XZY); 20 | } 21 | else 22 | { 23 | m_chart = new QOpenglMain(_frameType, _allocVBOandVAO, CChart::DRAWTYPE::XY); 24 | } 25 | 26 | m_comboBox = new CComboBox(m_chart, this); 27 | 28 | } 29 | 30 | COFFOpenglWidget::COFFOpenglWidget(u_char _frameType, CAllocVBOandVAO *_allocVBOandVAO, QString _checkBoxSenderName, QWidget *parent) 31 | : QWidget(parent), 32 | m_allocVBOandVAO(/*new CAllocVBOandVAO*/_allocVBOandVAO), 33 | m_chart(new QOpenglMain(_frameType, _allocVBOandVAO, CChart::DRAWTYPE::XZY)), 34 | m_mainVLayout(new QVBoxLayout(this)), 35 | m_hBoxLayout(new QHBoxLayout(this)), 36 | m_checkBoxSenderName(_checkBoxSenderName), 37 | m_checkBoxAnix(new QCheckBox(this)), 38 | m_checkBoxGrid(new QCheckBox(this)), 39 | m_checkBoxXyPlane(new QCheckBox(this)), 40 | m_checkBoxXzPlane(new QCheckBox(this)), 41 | m_checkBoxYzPlane(new QCheckBox(this)), 42 | m_label(new QLabel(this)) 43 | 44 | { 45 | if(0 == _frameType) 46 | { 47 | m_chart = new QOpenglMain(_frameType, _allocVBOandVAO, CChart::DRAWTYPE::XZY); 48 | } 49 | else 50 | { 51 | m_chart = new QOpenglMain(_frameType, _allocVBOandVAO, CChart::DRAWTYPE::XY); 52 | } 53 | m_comboBox = new CComboBox(m_chart, this); 54 | } 55 | 56 | COFFOpenglWidget::~COFFOpenglWidget() 57 | { 58 | LLDELETE(m_checkBoxAnix) 59 | LLDELETE(m_checkBoxGrid) 60 | LLDELETE(m_checkBoxXyPlane) 61 | LLDELETE(m_checkBoxXzPlane) 62 | LLDELETE(m_checkBoxYzPlane) 63 | LLDELETE(m_comboBox) 64 | LLDELETE(m_label) 65 | LLDELETE(m_hBoxLayout) 66 | LLDELETE(m_mainVLayout) 67 | LLDELETE(m_chart) 68 | } 69 | 70 | void COFFOpenglWidget::setChartObjectName(QString _title) 71 | { 72 | m_chart->setObjectName(_title); 73 | } 74 | 75 | void COFFOpenglWidget::setChartCopyFromOtherOpenWidgetMark(bool _notCopyMark) 76 | { 77 | m_chart->setCopyFromOtherOpenWidgetMark(_notCopyMark); 78 | } 79 | 80 | void COFFOpenglWidget::setChartVaoAndVbosBuffer(vector& _tmpVBO, vector& _tmpVBOIndex) 81 | { 82 | m_chart->setVaoAndVbosBuffer(_tmpVBO, _tmpVBOIndex); 83 | } 84 | 85 | void COFFOpenglWidget::setChartCordRangei(vector2f _xRange, vector2f _yRange, vector2f _zRange) 86 | { 87 | m_chart->setCordRangei(_xRange, _yRange, _zRange); 88 | } 89 | 90 | void COFFOpenglWidget::setChartDrawType(CChart::DRAWTYPE _drawType) 91 | { 92 | m_chart->setDrawType(_drawType); 93 | } 94 | 95 | void COFFOpenglWidget::setChartMove(QMatrix4x4 _move) 96 | { 97 | m_chart->setMove(_move); 98 | } 99 | 100 | void COFFOpenglWidget::setChartRotation(QMatrix4x4 _rotation) 101 | { 102 | m_chart->setRotation(_rotation); 103 | } 104 | 105 | void COFFOpenglWidget::setChartGridNumer(int _xGridNumber, int _yGridNumber, int _zGridNumber) 106 | { 107 | m_chart->setGridNumer(_xGridNumber, _yGridNumber, _zGridNumber); 108 | } 109 | 110 | void COFFOpenglWidget::setChartLinesVboBufferData(list >& _tmpLinesVbo, vector& _tmpLinesAmount) 111 | { 112 | m_chart->setLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 113 | } 114 | 115 | void COFFOpenglWidget::setChartLineColor(map _lineColors) 116 | { 117 | for(map::iterator it = _lineColors.begin(); it != _lineColors.end(); ++it) 118 | { 119 | m_chart->setColor(it->first, it->second); 120 | 121 | m_chart->setLinesEnabled(it->first, true); 122 | 123 | QString name = "— " + QString::number(it->first); 124 | vector3f color = {it->second._r, it->second._g, it->second._b}; 125 | QVariant data1 = QVariant::fromValue(it->first); 126 | m_comboBox->addNewItemFromOpenglMain(name, data1, color); 127 | } 128 | // m_chart->setLineColor(_lineColors); 129 | } 130 | 131 | void COFFOpenglWidget::setTitle(QString _title) 132 | { 133 | setWindowTitle(_title); 134 | } 135 | 136 | void COFFOpenglWidget::setMainLayout() 137 | { 138 | m_hBoxLayout->addWidget(m_checkBoxGrid, 0); 139 | m_hBoxLayout->addWidget(m_checkBoxAnix, 0); 140 | m_hBoxLayout->addWidget(m_checkBoxXyPlane, 0); 141 | m_hBoxLayout->addWidget(m_checkBoxXzPlane, 0); 142 | m_hBoxLayout->addWidget(m_checkBoxYzPlane, 0); 143 | m_hBoxLayout->addWidget(m_comboBox, 1); 144 | m_hBoxLayout->addStretch(); 145 | m_checkBoxAnix->setText("坐标"); 146 | m_checkBoxAnix->setChecked(true); 147 | m_checkBoxGrid->setText("网格"); 148 | m_checkBoxGrid->setChecked(true); 149 | m_checkBoxXyPlane->setText("XY"); 150 | m_checkBoxXyPlane->setChecked(false); 151 | m_checkBoxXzPlane->setText("XZ"); 152 | m_checkBoxXzPlane->setChecked(false); 153 | m_checkBoxYzPlane->setText("YZ"); 154 | m_checkBoxYzPlane->setChecked(false); 155 | 156 | m_checkBoxAnix->setMaximumHeight(15); 157 | m_checkBoxGrid->setMaximumHeight(15); 158 | m_checkBoxXyPlane->setMaximumHeight(15); 159 | m_checkBoxXzPlane->setMaximumHeight(15); 160 | m_checkBoxYzPlane->setMaximumHeight(15); 161 | 162 | connect(m_checkBoxAnix, SIGNAL(stateChanged(int)), m_chart, SLOT(onSetAnixState())); 163 | connect(m_checkBoxGrid, SIGNAL(stateChanged(int)), m_chart, SLOT(onSetGridState())); 164 | connect(m_checkBoxXyPlane, SIGNAL(stateChanged(int)), m_chart, SLOT(onXYPlaneState())); 165 | connect(m_checkBoxXzPlane, SIGNAL(stateChanged(int)), m_chart, SLOT(onXZPlaneState())); 166 | connect(m_checkBoxYzPlane, SIGNAL(stateChanged(int)), m_chart, SLOT(onYZPlaneState())); 167 | QStringList x; 168 | if(m_markForFile) 169 | { 170 | x = m_checkBoxSenderName.split("/"); 171 | //m_label->setText(m_checkBoxSenderName.split("/").last()); 172 | QString tmpName = x.last(); 173 | m_label->setText(tmpName); 174 | m_mainVLayout->addWidget(m_label, 0, Qt::AlignHCenter); 175 | m_label->setMaximumHeight(20); 176 | } 177 | m_mainVLayout->addLayout(m_hBoxLayout); 178 | m_mainVLayout->addWidget(m_chart); 179 | setLayout(m_mainVLayout); 180 | } 181 | 182 | void COFFOpenglWidget::update() 183 | { 184 | if(m_chart) 185 | m_chart->update(); 186 | } 187 | 188 | void COFFOpenglWidget::setMarkForFile(bool _b) 189 | { 190 | m_markForFile = _b; 191 | } 192 | 193 | 194 | void COFFOpenglWidget::closeEvent(QCloseEvent *event) 195 | { 196 | //使用了友元类对原widget中的qcheckbutton的状态进行更改 197 | // int r = QMessageBox::question(this, tr("警告"), tr("确定要退出么?"), QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape); 198 | // if(r == QMessageBox::Yes) 199 | // { 200 | if(!m_markForFile) 201 | { 202 | event->accept(); 203 | QCheckBox* tmpCheckBox = m_mainWidget->findChild(m_checkBoxSenderName); 204 | // QString tmpName = tmpCheckBox->objectName(); 205 | // QString indexS = tmpName.split(' ')[1]; 206 | // u_int indexUint = indexS.toUInt(); 207 | 208 | // qDebug() << "tmpName: " << tmpName; 209 | // qDebug() << "tmpName: " << indexS; 210 | // qDebug() << "tmpName: " << indexUint; 211 | tmpCheckBox->setChecked(false); 212 | tmpCheckBox->setEnabled(true); 213 | } 214 | 215 | // } 216 | // else 217 | // { 218 | // event->ignore(); 219 | // } 220 | } 221 | -------------------------------------------------------------------------------- /Widgets/COFFOpenglwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef COFFOPENGLWIDGET_H 2 | #define COFFOPENGLWIDGET_H 3 | //Open From Files == OFF 4 | 5 | #include "mainWidget/tools.h" 6 | #include "MyOpenglWidget/QOpenglMain.h" 7 | #include "DataManageMent/CAllocVBOandVAO.h" 8 | #include "ComboBox/CComboBox.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | class Widget; 18 | 19 | class COFFOpenglWidget : public QWidget, public QOpenGLFunctions_4_3_Core 20 | { 21 | public: 22 | explicit COFFOpenglWidget(u_char _frameType, CAllocVBOandVAO* _allocVBOandVAO, Widget* _mainWidget, QString _checkBoxSenderName, QWidget *parent = 0); 23 | explicit COFFOpenglWidget(u_char _frameType, CAllocVBOandVAO* _allocVBOandVAO, QString _checkBoxSenderName, QWidget *parent = 0); 24 | ~COFFOpenglWidget(); 25 | void setChartObjectName(QString _title); 26 | void setChartCopyFromOtherOpenWidgetMark(bool _notCopyMark); 27 | void setChartVaoAndVbosBuffer(vector &_tmpVBO, vector &_tmpVBOIndex); 28 | void setChartCordRangei(vector2f _xRange, vector2f _yRange, vector2f _zRange); 29 | void setChartDrawType(CChart::DRAWTYPE _drawType); 30 | void setChartMove(QMatrix4x4 _move); 31 | void setChartRotation(QMatrix4x4 _rotation); 32 | void setChartGridNumer(int _xGridNumber, int _yGridNumber, int _zGridNumber); 33 | void setChartLinesVboBufferData(list > &_tmpLinesVbo, vector &_tmpLinesAmount); 34 | void setChartLineColor(map _lineColors); 35 | 36 | void setTitle(QString _title); 37 | void setMainLayout(); 38 | void update(); 39 | void setMarkForFile(bool _b); 40 | 41 | //void show(); 42 | //public: 43 | // QOpenglMain* m_chart; 44 | private: 45 | // friend class CComboBox; 46 | QOpenglMain* m_chart; 47 | 48 | void closeEvent(QCloseEvent *event); 49 | QLabel * m_label = nullptr; 50 | QCheckBox* m_checkBoxAnix; 51 | QCheckBox* m_checkBoxGrid; 52 | QCheckBox* m_checkBoxXyPlane; 53 | QCheckBox* m_checkBoxXzPlane; 54 | QCheckBox* m_checkBoxYzPlane; 55 | CComboBox* m_comboBox; 56 | 57 | QVBoxLayout* m_mainVLayout; 58 | QHBoxLayout* m_hBoxLayout; 59 | 60 | 61 | CAllocVBOandVAO* m_allocVBOandVAO; 62 | QString m_checkBoxSenderName; 63 | Widget* m_mainWidget; 64 | 65 | bool m_markForFile = false; 66 | 67 | }; 68 | 69 | #endif // COFFOPENGLWIDGET_H 70 | -------------------------------------------------------------------------------- /mainWidget/Widget.cpp: -------------------------------------------------------------------------------- 1 | #include "mainWidget/Widget.h" 2 | #include "ui_widget.h" 3 | 4 | #ifdef _LLMINGW32_ 5 | #define random rand 6 | #endif 7 | 8 | 9 | const long int queueSize = 5000; 10 | Widget::Widget(QWidget *parent) : 11 | QWidget(parent), 12 | m_cirBuffer(queueSize), 13 | m_allocVBOandVAO(new CAllocVBOandVAO) 14 | { 15 | //qDebug() << "main: " << thread()->currentThreadId(); 16 | //setFocusPolicy(Qt::FocusPolicy::TabFocus); 17 | this->setObjectName("Widget"); 18 | m_thebaselayout = new QGridLayout(this); 19 | this->setLayout(m_thebaselayout); 20 | ui->setupUi(this); 21 | //connect(this, SIGNAL(buildOpenGLWidget()), this, SLOT(onBuildOpenGLWidget()), Qt::ConnectionType::DirectConnection); 22 | m_dataRAW.setDir(); 23 | } 24 | Widget::~Widget() 25 | { 26 | for(map::iterator it = m_copyQOpenglWidgets.begin(); it != m_copyQOpenglWidgets.end(); ++it) 27 | { 28 | LLDELETE(it->second) 29 | } 30 | m_copyQOpenglWidgets.clear(); 31 | 32 | if(m_thebaselayout) 33 | LLDELETE(m_thebaselayout) 34 | for (map::iterator it = m_llOpengglWidgets.begin(); it != m_llOpengglWidgets.end(); ++it) 35 | { 36 | LLDELETE(it->second) 37 | } 38 | m_llOpengglWidgets.clear(); 39 | 40 | for (map::iterator it = m_OFFOpenglWidgets.begin(); it != m_OFFOpenglWidgets.end(); ++it) 41 | { 42 | LLDELETE(it->second) 43 | } 44 | m_OFFOpenglWidgets.clear(); 45 | 46 | 47 | LLDELETE(m_allocVBOandVAO) 48 | } 49 | 50 | //void Widget::addPoint(float x, float y, float z) 51 | //{ 52 | //// for (map::iterator it = m_charts.begin(); it != m_charts.end(); ++it) 53 | //// { 54 | //// it->second->addPoint(0, { x, y, z}); 55 | //// } 56 | // for (map::iterator it = m_llOpengglWidgets.begin(); it != m_llOpengglWidgets.end(); ++it) 57 | // { 58 | // it->second->addPoint(0, { x, y, z}); 59 | // } 60 | 61 | //} 62 | 63 | void Widget::update() 64 | { 65 | // for (map::iterator it = m_charts.begin(); it != m_charts.end(); ++it) 66 | // { 67 | // it->second->update(); 68 | // } 69 | for (map::iterator it = m_llOpengglWidgets.begin(); it != m_llOpengglWidgets.end(); ++it) 70 | { 71 | if(it->second) 72 | it->second->update(); 73 | } 74 | //开启后显示为空白 75 | 76 | //外显窗口的刷新是专门从另外一个线程中进行的 77 | 78 | } 79 | 80 | void Widget::recvMessage() 81 | { 82 | try{ 83 | 84 | boost::asio::io_service io_server; 85 | unsigned short port = 8003; 86 | 87 | m_server = new CAsioAsyncServer(io_server, port); 88 | m_server->run(); 89 | 90 | //boost::thread t(boost::bind(&boost::asio::io_service::run, &io_server)); 91 | io_server.run(); 92 | //t.join(); 93 | } 94 | catch(std::exception& e) 95 | { 96 | std::cerr << e.what() << std::endl; 97 | } 98 | } 99 | 100 | //void Widget::updateOutWidget() 101 | //{ 102 | // while(1) 103 | // { 104 | // //当在主线程中开启复制窗口的刷新时,会导致opengl缓冲区复制过程出错,全部变量被重置为0,所以采用新开启一个线程去刷新复制窗口,同时,在删除复制窗口类的位置使用互斥锁进行保护。 105 | // usleep(50000); //50ms刷新一次。 106 | // for (map::iterator it = m_copyQOpenglWidgets.begin(); it != m_copyQOpenglWidgets.end(); ++it) 107 | // { 108 | // it->second->update(); 109 | // } 110 | // for (map::iterator it = m_OFFOpenglWidgets.begin(); it != m_OFFOpenglWidgets.end(); ++it) 111 | // { 112 | // it->second->update(); 113 | // } 114 | //// for (map::iterator it = m_OFFOpenglWidgetsFile.begin(); it != m_OFFOpenglWidgetsFile.end(); ++it) 115 | //// { 116 | //// it->second->update(); 117 | //// } 118 | // } 119 | //} 120 | 121 | void Widget::run() 122 | { 123 | m_timer.start(20); 124 | 125 | //recvMessage(); 126 | m_threadRecv = new boost::thread(std::bind(&Widget::recvMessage, this));//开启数据读取线程 127 | // boost::thread(std::bind(&Widget::updateOutWidget, this)); //开启复制窗口刷新线程 128 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(onTimeOut())); 129 | } 130 | 131 | void Widget::closeTimer() 132 | { 133 | m_timer.destroyed(); 134 | m_server->close(); 135 | // m_threadRecv->join(); 136 | } 137 | 138 | //void Widget::keyPressEvent(QKeyEvent* event) 139 | //{ 140 | // if (Qt::Key_A==event->key()) 141 | // { 142 | // //onBuildOpenGLWidget(); 143 | // emit buildOpenGLWidget(); 144 | // } 145 | //} 146 | int drawType = CChart::XZY; 147 | void Widget::readCirBufToCreateOpenGLImages() 148 | { 149 | //清空并重新读取CirBuffer中的数据 150 | m_cirBuffer.clear(); 151 | m_server->getCirBuffer(&m_cirBuffer); 152 | 153 | float x = 0; 154 | float y = 0; 155 | float z = 0; 156 | vector4f _color; 157 | // QOpenglMain* _tmpCurrent; 158 | u_short imgNumber; 159 | u_short lineNumber; 160 | //u_short lastNumber = -1; 161 | bool createLineMark = false; 162 | vector2f xRange = {1.0f, 0.0f}; 163 | vector2f yRange = {1.0f, 0.0f}; 164 | vector2f zRange = {1.0f, 0.0f}; 165 | 166 | 167 | for(boost::circular_buffer::iterator it = m_cirBuffer.begin(); it != m_cirBuffer.end(); ) 168 | { 169 | imgNumber = it->mData.imageNumber; 170 | lineNumber = it->mData.lineNumber; 171 | 172 | vector::iterator itFind = ::find(m_imageNumbers.begin(), m_imageNumbers.end(), imgNumber); 173 | if(m_imageNumbers.end() == itFind) 174 | { 175 | m_imageNumbers.push_back(imgNumber); 176 | onBuildOpenGLWidget(it->frameType); 177 | m_dataRAW.addNewImage(imgNumber); 178 | continue; 179 | } 180 | else 181 | { 182 | x = it->mData.dataX; 183 | y = it->mData.dataY; 184 | z = it->mData.dataZ; 185 | //_tmpCurrent = m_charts.at(imgNumber); 186 | //_tmpCurrent = m_llOpengglWidgets.at(imgNumber)->getQOpenglMain(); 187 | 188 | 189 | if(m_llOpengglWidgets.at(imgNumber)) 190 | { 191 | createLineMark = m_llOpengglWidgets.at(imgNumber)->addPoint(lineNumber, { x, y, z}); 192 | //_tmpCurrent->addPoint(0, { x, y, z}); 193 | if(m_llOpengglWidgets.at(imgNumber)->checkRangeChange(xRange, yRange, zRange)) 194 | { 195 | m_dataRAW.addNewLineRange(imgNumber, m_llOpengglWidgets.at(imgNumber)->getFrameType(), xRange, yRange, zRange); 196 | } 197 | //_tmpCurrent->setColor(0, _color); 198 | if(createLineMark) 199 | { 200 | _color._r = float(random()) / float(RAND_MAX); _color._g = float(random()) / float(RAND_MAX); 201 | _color._b = float(random()) / float(RAND_MAX); _color._a = float(random()) / float(RAND_MAX); 202 | m_llOpengglWidgets.at(imgNumber)->setColor(lineNumber, _color); 203 | m_dataRAW.addNewLineColor(imgNumber, lineNumber, _color); 204 | } 205 | } 206 | 207 | m_dataRAW.writeDataToFile(imgNumber, lineNumber, it->frame, x, y, z); 208 | } 209 | ++it; 210 | if(m_cirBuffer.size() != 0) 211 | m_cirBuffer.pop_front(); 212 | //lastNumber = imgNumber; 213 | } 214 | } 215 | 216 | void Widget::removeLayout(QWidget *_widget) 217 | { 218 | QLayout* layout = _widget->layout (); 219 | if (layout != 0) 220 | { 221 | QLayoutItem *item; 222 | while ((item = layout->takeAt(0)) != 0) 223 | { 224 | //qDebug() << layout->objectName(); 225 | layout->removeItem (item); 226 | 227 | delete item; 228 | } 229 | delete layout; 230 | m_thebaselayout = nullptr; 231 | } 232 | } 233 | 234 | void Widget::deleteOutWidget(u_int _indexCopy) 235 | { 236 | //写了一个临界区或者说互斥锁来保护删除过程 237 | boost::mutex::scoped_lock lock(m_mutexOutWidget); 238 | //delete m_copyQOpenglWidgets.at(_indexCopy); 239 | //m_copyQOpenglWidgets.at(_indexCopy) = nullptr; 240 | m_copyQOpenglWidgets.erase(m_copyQOpenglWidgets.find(_indexCopy)); 241 | lock.unlock(); 242 | } 243 | 244 | void Widget::deleteOFFOutWidget(u_int _indexCopy) 245 | { 246 | //写了一个临界区或者说互斥锁来保护删除过程 247 | boost::mutex::scoped_lock lock(m_mutexOutWidget); 248 | // delete m_OFFOpenglWidgets.at(_indexCopy); 249 | // m_OFFOpenglWidgets.at(_indexCopy) = nullptr; 250 | m_OFFOpenglWidgets.erase(m_OFFOpenglWidgets.find(_indexCopy)); 251 | lock.unlock(); 252 | } 253 | 254 | //void Widget::deleteOFFOutWidgetFile(u_int _indexCopy) 255 | //{ 256 | 257 | //} 258 | 259 | void Widget::createOutWidget() 260 | { 261 | 262 | } 263 | 264 | //void Widget::onReadFromFileOutDisplayState(QString fileName) 265 | //{ 266 | 267 | //} 268 | 269 | 270 | void Widget::onTimeOut() 271 | { 272 | //将cirbuf中的数据读出并赋给opengl窗口 273 | readCirBufToCreateOpenGLImages(); 274 | //刷新opengl窗口内容 275 | update(); 276 | } 277 | void Widget::onBuildOpenGLWidget(u_char _frameType) 278 | { 279 | QString title = QString("newchart ") + QString::number((*(m_imageNumbers.end()-1))); 280 | CLLOpenglWidget* newOpenglWidget = nullptr; 281 | if(0 == _frameType) 282 | { 283 | drawType = CChart::DRAWTYPE::XZY; 284 | newOpenglWidget = new CLLOpenglWidget(_frameType, this, m_allocVBOandVAO, CChart::DRAWTYPE(drawType), (u_short)(*(m_imageNumbers.end()-1)), this); 285 | } 286 | else if(1 == _frameType) 287 | { 288 | drawType = CChart::DRAWTYPE::XY; 289 | newOpenglWidget = new CLLOpenglWidget(_frameType, this, m_allocVBOandVAO, CChart::DRAWTYPE(drawType), (u_short)(*(m_imageNumbers.end()-1)), this); 290 | } 291 | newOpenglWidget->setObjectName(title); 292 | 293 | m_thebaselayout->addWidget(newOpenglWidget, m_llOpengglWidgets.size() / 3, m_llOpengglWidgets.size() % 3); 294 | if(newOpenglWidget) 295 | m_llOpengglWidgets.insert(std::pair((u_short)(*(m_imageNumbers.end()-1)), newOpenglWidget)); 296 | } 297 | void Widget::onHideOtherOpenGLWidget() 298 | { 299 | QCheckBox* checkSender = qobject_cast(sender()); 300 | QString title = checkSender->objectName(); 301 | QStringList titleList = title.split(' '); 302 | QString index = titleList.at(1); 303 | GLint indexInt = index.toInt(); 304 | 305 | u_short indexUshort = 0; 306 | if (indexInt >= 0) 307 | { 308 | indexUshort = static_cast(indexInt); 309 | } 310 | GLboolean isChecked = GL_TRUE; 311 | if(checkSender->isChecked()) 312 | { 313 | isChecked = GL_TRUE; 314 | } 315 | else 316 | { 317 | isChecked = GL_FALSE; 318 | } 319 | for(map::iterator it = m_llOpengglWidgets.begin(); it != m_llOpengglWidgets.end(); ++it) 320 | { 321 | if(it->first != indexUshort) 322 | { 323 | if(isChecked) 324 | { 325 | it->second->hide(); 326 | } 327 | else 328 | { 329 | it->second->show(); 330 | } 331 | } 332 | } 333 | } 334 | 335 | void Widget::onSetOutDisplayState() 336 | { 337 | QCheckBox* checkSender = qobject_cast(sender()); 338 | //当勾选按键属于非勾选状态时,直接退出该函数。 339 | if(!checkSender->isChecked()) 340 | return; 341 | //在勾选成功后禁用勾选按键功能。 342 | if(checkSender) 343 | { 344 | if(checkSender->isEnabled()) 345 | checkSender->setEnabled(false); 346 | // for(map::iterator it = m_buttonOutWidgets.begin(); it != m_buttonOutWidgets.end(); ++it) 347 | // { 348 | // it->second->setEnabled(false); 349 | // } 350 | // QMessageBox msgBox; 351 | // msgBox.setText(QString("找到信号发射源")); 352 | // msgBox.exec(); 353 | } 354 | else 355 | { 356 | QMessageBox msgBox; 357 | msgBox.setText(QString("未找到信号发射源")); 358 | msgBox.exec(); 359 | } 360 | 361 | QString title = checkSender->objectName(); 362 | QStringList titleList = title.split(' '); 363 | QString index = titleList.at(1); 364 | QString winTitle = QString("图像 ") + index; 365 | GLint indexInt = index.toInt(); 366 | u_short indexUshort = 0; 367 | if (indexInt >= 0) 368 | { 369 | indexUshort = static_cast(indexInt); 370 | } 371 | 372 | title = QString("newchart ") + index; 373 | m_tmpOpenglMain = m_llOpengglWidgets.at(indexUshort)->getQOpenglMain(); 374 | 375 | // vector _tmpVbo; 376 | // vector _tmpVboIndex; 377 | list > _tmpLinesVbo; 378 | vector _tmpLinesAmount; 379 | vector2f _xRange = {0, 1}; 380 | vector2f _yRange = {0, 1}; 381 | vector2f _zRange = {0, 1}; 382 | QMatrix4x4 _rotation = { 383 | 1.0f, 0.0f, 0.0f, 0.0f, 384 | 0.0f, 1.0f, 0.0f, 0.0f, 385 | 0.0f, 0.0f, 1.0f, 0.0f, 386 | 0.0f, 0.0f, 0.0f, 1.0f, 387 | }; 388 | QMatrix4x4 _move = { 389 | 1.0f, 0.0f, 0.0f, 0.0f, 390 | 0.0f, 1.0f, 0.0f, 0.0f, 391 | 0.0f, 0.0f, 1.0f, 0.0f, 392 | 0.0f, 0.0f, 0.0f, 1.0f, 393 | }; 394 | CChart::DRAWTYPE _drawType = CChart::DRAWTYPE::XZY; 395 | int xGridNumber = 4; 396 | int yGridNumber = 4; 397 | int zGridNumber = 4; 398 | map lineColors; 399 | 400 | u_char frameType = 0; 401 | if(m_tmpOpenglMain) 402 | { 403 | m_tmpOpenglMain->getAllVaoAndVboAndVboIndex(); 404 | // _tmpVbo = m_tmpOpenglMain->getAnixVboBufferData(); 405 | // _tmpVboIndex = m_tmpOpenglMain->getAnixVboIndexBufferData(); 406 | m_tmpOpenglMain->getLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 407 | m_tmpOpenglMain->getCordRangei(_xRange, _yRange, _zRange); 408 | m_tmpOpenglMain->getMove(_move); 409 | m_tmpOpenglMain->getRotation(_rotation); 410 | m_tmpOpenglMain->getDrawType(_drawType); 411 | // m_tmpOpenglMain->getGridNumer(xGridNumber, yGridNumber, zGridNumber); 412 | m_tmpOpenglMain->getLineColor(lineColors); 413 | frameType = m_llOpengglWidgets.at(indexUshort)->getFrameType(); 414 | } 415 | // if(_tmpVbo.size() != 0) 416 | // qDebug() << "1: " << _tmpVbo.at(0) << " " << _tmpVbo.size(); 417 | 418 | 419 | 420 | if(m_copyQOpenglWidgets.find(indexUshort) == m_copyQOpenglWidgets.end()) 421 | { 422 | CopyQOpenglWidget* _copyQOpenglWidget; 423 | if(0 == frameType) 424 | { 425 | _copyQOpenglWidget = new CopyQOpenglWidget(frameType, CChart::DRAWTYPE::XZY, m_allocVBOandVAO, this, checkSender->objectName()); 426 | } 427 | else 428 | { 429 | _copyQOpenglWidget = new CopyQOpenglWidget(frameType, CChart::DRAWTYPE::XY, m_allocVBOandVAO, this, checkSender->objectName()); 430 | } 431 | _copyQOpenglWidget->setGeometry(40,40,400,400); 432 | 433 | _copyQOpenglWidget->setWindowTitle(winTitle); 434 | _copyQOpenglWidget->setChartObjectName(title); 435 | _copyQOpenglWidget->setChartCopyFromOtherOpenWidgetMark(false); 436 | // _copyQOpenglWidget->setChartVaoAndVbosBuffer(_tmpVbo, _tmpVboIndex);; 437 | _copyQOpenglWidget->setChartCordRangei(_xRange, _yRange, _zRange);; 438 | _copyQOpenglWidget->setChartDrawType(_drawType); 439 | _copyQOpenglWidget->setChartMove(_move); 440 | _copyQOpenglWidget->setChartRotation(_rotation); 441 | // _copyQOpenglWidget->setChartGridNumer(xGridNumber, yGridNumber, zGridNumber); 442 | _copyQOpenglWidget->setChartLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 443 | _copyQOpenglWidget->setChartLineColor(lineColors); 444 | _copyQOpenglWidget->setMainLayout(); 445 | _copyQOpenglWidget->show(); 446 | _copyQOpenglWidget->raise(); 447 | 448 | m_copyQOpenglWidgets.insert(std::pair(indexUshort, _copyQOpenglWidget)); 449 | } 450 | else{ 451 | deleteOutWidget(indexUshort); 452 | // delete m_copyQOpenglWidgets.at(indexUshort); 453 | //m_copyQOpenglWidgets.erase(m_copyQOpenglWidgets.find(indexUshort)); 454 | CopyQOpenglWidget* _copyQOpenglWidget; 455 | if(0 == frameType) 456 | { 457 | _copyQOpenglWidget = new CopyQOpenglWidget(frameType, CChart::DRAWTYPE::XZY, m_allocVBOandVAO, this, checkSender->objectName()); 458 | } 459 | else 460 | { 461 | _copyQOpenglWidget = new CopyQOpenglWidget(frameType, CChart::DRAWTYPE::XY, m_allocVBOandVAO, this, checkSender->objectName()); 462 | } 463 | _copyQOpenglWidget->setGeometry(40,40,400,400); 464 | 465 | _copyQOpenglWidget->setWindowTitle(winTitle); 466 | _copyQOpenglWidget->setChartObjectName(title); 467 | _copyQOpenglWidget->setChartCopyFromOtherOpenWidgetMark(false); 468 | // _copyQOpenglWidget->setChartVaoAndVbosBuffer(_tmpVbo, _tmpVboIndex);; 469 | _copyQOpenglWidget->setChartCordRangei(_xRange, _yRange, _zRange);; 470 | _copyQOpenglWidget->setChartDrawType(_drawType); 471 | _copyQOpenglWidget->setChartMove(_move); 472 | _copyQOpenglWidget->setChartRotation(_rotation); 473 | _copyQOpenglWidget->setChartGridNumer(xGridNumber, yGridNumber, zGridNumber); 474 | _copyQOpenglWidget->setChartLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 475 | _copyQOpenglWidget->setChartLineColor(lineColors); 476 | _copyQOpenglWidget->setMainLayout(); 477 | _copyQOpenglWidget->show(); 478 | _copyQOpenglWidget->raise(); 479 | 480 | m_copyQOpenglWidgets.insert(std::pair(indexUshort, _copyQOpenglWidget)); 481 | } 482 | } 483 | 484 | void Widget::onReadFromFileOutDisplayState() 485 | { 486 | QCheckBox* checkSender = qobject_cast(sender()); 487 | //当勾选按键属于非勾选状态时,直接退出该函数。 488 | if(!checkSender->isChecked()) 489 | return; 490 | //在勾选成功后禁用勾选按键功能。 491 | if(checkSender) 492 | { 493 | if(checkSender->isEnabled()) 494 | checkSender->setEnabled(false); 495 | } 496 | else 497 | { 498 | QMessageBox msgBox; 499 | msgBox.setText(QString("未找到信号发射源")); 500 | msgBox.exec(); 501 | } 502 | 503 | QString title = checkSender->objectName(); 504 | QStringList titleList = title.split(' '); 505 | QString index = titleList.at(1); 506 | QString winTitle = QString("图像 ") + index; 507 | GLint indexInt = index.toInt(); 508 | u_short indexUshort = 0; 509 | if (indexInt >= 0) 510 | { 511 | indexUshort = static_cast(indexInt); 512 | } 513 | 514 | list > _tmpLinesVbo; 515 | vector _tmpLinesAmount; 516 | vector2f _xRange = {1, 0}; 517 | vector2f _yRange = {1, 0}; 518 | vector2f _zRange = {1, 0}; 519 | map lineColors; 520 | u_char frameType = 0; 521 | 522 | m_dataRAW.readDataFromFile(indexUshort, _tmpLinesVbo, _tmpLinesAmount, lineColors); 523 | m_dataRAW.readLineRangeFromFile(indexUshort, frameType, _xRange, _yRange, _zRange); 524 | 525 | 526 | 527 | if(m_OFFOpenglWidgets.find(indexUshort) == m_OFFOpenglWidgets.end()) 528 | { 529 | COFFOpenglWidget* _OFFOpenglWidget = new COFFOpenglWidget(frameType, m_allocVBOandVAO, this, checkSender->objectName()); 530 | _OFFOpenglWidget->setGeometry(40,40,400,400); 531 | _OFFOpenglWidget->setWindowTitle(winTitle); 532 | _OFFOpenglWidget->setChartObjectName(title); 533 | _OFFOpenglWidget->setChartCopyFromOtherOpenWidgetMark(false); 534 | _OFFOpenglWidget->setChartCordRangei(_xRange, _yRange, _zRange); 535 | _OFFOpenglWidget->setChartLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 536 | if(0 == frameType) 537 | _OFFOpenglWidget->setChartDrawType(CChart::DRAWTYPE::XZY); 538 | else 539 | _OFFOpenglWidget->setChartDrawType(CChart::DRAWTYPE::XY); 540 | _OFFOpenglWidget->setChartLineColor(lineColors); 541 | _OFFOpenglWidget->setMainLayout(); 542 | _OFFOpenglWidget->show(); 543 | _OFFOpenglWidget->raise(); 544 | 545 | m_OFFOpenglWidgets.insert(std::pair(indexUshort, _OFFOpenglWidget)); 546 | } 547 | else{ 548 | deleteOFFOutWidget(indexUshort); 549 | COFFOpenglWidget* _OFFOpenglWidget = new COFFOpenglWidget(frameType, m_allocVBOandVAO, this, checkSender->objectName()); 550 | _OFFOpenglWidget->setGeometry(40,40,400,400); 551 | 552 | _OFFOpenglWidget->setWindowTitle(winTitle); 553 | _OFFOpenglWidget->setChartObjectName(title); 554 | _OFFOpenglWidget->setChartCopyFromOtherOpenWidgetMark(false); 555 | _OFFOpenglWidget->setChartCordRangei(_xRange, _yRange, _zRange); 556 | _OFFOpenglWidget->setChartLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 557 | if(0 == frameType) 558 | _OFFOpenglWidget->setChartDrawType(CChart::DRAWTYPE::XZY); 559 | else 560 | _OFFOpenglWidget->setChartDrawType(CChart::DRAWTYPE::XY); 561 | _OFFOpenglWidget->setChartLineColor(lineColors); 562 | 563 | _OFFOpenglWidget->setMainLayout(); 564 | _OFFOpenglWidget->show(); 565 | _OFFOpenglWidget->raise(); 566 | 567 | m_OFFOpenglWidgets.insert(std::pair(indexUshort, _OFFOpenglWidget)); 568 | } 569 | } 570 | 571 | -------------------------------------------------------------------------------- /mainWidget/Widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | #include "mainWidget/tools.h" 4 | #include "UDPServer/CAsioAsyncServer.h" 5 | #include "MyOpenglWidget/QOpenglMain.h" 6 | #include "Widgets/CCopyQOpenglWidget.h" 7 | #include "Widgets/CLLOpenglWidget.h" 8 | #include "Widgets/COFFOpenglwidget.h" 9 | #include "DataManageMent/CDataRAW.h" 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | class CopyQOpenglWidget; 29 | class CLLOpenglWidget; 30 | class COFFOpenglWidget; 31 | 32 | namespace Ui { 33 | class Widget; 34 | } 35 | 36 | class Widget : public QWidget 37 | { 38 | Q_OBJECT 39 | 40 | public: 41 | explicit Widget(QWidget *parent = Q_NULLPTR); 42 | ~Widget(); 43 | // void addPoint(float x, float y, float z); 44 | void update(); 45 | void recvMessage(); 46 | // void updateOutWidget(); 47 | void run(); 48 | void closeTimer(); 49 | 50 | //signals: 51 | // void buildOpenGLWidget(); 52 | private slots: 53 | void onTimeOut(); 54 | void onHideOtherOpenGLWidget(); 55 | void onSetOutDisplayState(); 56 | void onReadFromFileOutDisplayState(); 57 | 58 | private: 59 | void onBuildOpenGLWidget(u_char _frameType); 60 | void readCirBufToCreateOpenGLImages(); 61 | void removeLayout(QWidget* _widget); 62 | void deleteOutWidget(u_int _indexCopy); 63 | void deleteOFFOutWidget(u_int _indexCopy); 64 | 65 | void createOutWidget(); 66 | private: 67 | Ui::Widget *ui; 68 | //boost circularBuffer类 69 | CirBufferLL m_cirBuffer; 70 | //asio收发类 71 | CAsioAsyncServer* m_server; 72 | //收到信号后建立的Opengl窗口类的map, 后期应当将list修改为map 73 | map m_charts; //窗口编号和类 74 | map m_llOpengglWidgets; 75 | 76 | /* 复制窗口实现描述: 77 | * 1. 以下指针都是为了给单独弹窗的小窗口提供临时指针的类,后期将会改为list,不再对放大的窗口进行每次删除; 78 | * 2. 实际上复制该窗口是直接将点击的对应窗口进行的数据拷贝,由于上下文环境改变,单纯的复制该窗口类是不可行的, 79 | * 3. 此处采用将数据、网格设置和坐标轴设置进行拷贝后,直接新建一个QOpenglMain类,将前面的数据传递进去后,利用新的widget进行显示的。 80 | */ 81 | QOpenglMain* m_tmpOpenglMain = nullptr; //将选定的窗口的临时指针读取出来 82 | 83 | map m_copyQOpenglWidgets; 84 | QString m_outIndex = ""; //传递其标号 85 | 86 | QGridLayout* m_thebaselayout; 87 | CAllocVBOandVAO* m_allocVBOandVAO; 88 | QTimer m_timer; 89 | boost::thread* m_threadRecv; 90 | vector m_imageNumbers; 91 | 92 | boost::mutex m_mutexOutWidget; //为生成的复制窗口进行读写保护 93 | 94 | //以下是用来存储和读取文件信息的。 95 | map m_fins; 96 | map m_fNames; 97 | CDataRAW m_dataRAW; 98 | //读取文件信息后生成的窗口, 从窗口提取 99 | map m_OFFOpenglWidgets; 100 | 101 | 102 | protected: 103 | friend class CopyQOpenglWidget; 104 | friend class CLLOpenglWidget; 105 | }; 106 | 107 | #endif // WIDGET_H 108 | -------------------------------------------------------------------------------- /mainWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainWidget/mainwindow.h" 2 | //#include "widget.h" 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.setWindowTitle("飞行器数据可视化平台"); 10 | w.show(); 11 | w.showMaximized(); 12 | w.showMinimized(); 13 | a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); 14 | return a.exec(); 15 | } 16 | -------------------------------------------------------------------------------- /mainWidget/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainWidget/mainwindow.h" 2 | 3 | #include "ui_mainwindow.h" 4 | 5 | MainWindow::MainWindow(QWidget *parent) : 6 | QMainWindow(parent), 7 | m_allocVBOandVAO(new CAllocVBOandVAO), 8 | ui(new Ui::MainWindow) 9 | { 10 | ui->setupUi(this); 11 | m_widgetCentral = new Widget(this); 12 | m_widgetCentral->setStatusTip("本窗口采用opengl实时渲染"); 13 | 14 | createActions(); 15 | createMenus(); 16 | 17 | m_widgetCentral->run(); 18 | setCentralWidget(m_widgetCentral); 19 | show(); 20 | raise(); 21 | } 22 | 23 | MainWindow::~MainWindow() 24 | { 25 | boost::mutex::scoped_lock lock(m_mutexOutWidget); 26 | for (vector::iterator it = m_OFFOpenglWidgetsFile.begin(); it != m_OFFOpenglWidgetsFile.end(); ++it) 27 | { 28 | delete (*it); 29 | } 30 | m_OFFOpenglWidgetsFile.clear(); 31 | lock.unlock(); 32 | 33 | LLDELETE(separatorAction) 34 | LLDELETE(openAction) 35 | LLDELETE(fileMenu) 36 | LLDELETE(m_widgetCentral) 37 | LLDELETE(m_allocVBOandVAO) 38 | LLDELETE(ui) 39 | } 40 | 41 | void MainWindow::onReadFromFileOutDisplayState(QString fileName) 42 | { 43 | m_dataRAW.setDir(fileName); 44 | QStringList titleList = fileName.split('/'); 45 | QString title = titleList.last(); 46 | QString index = title.split(".").at(0).split("_").at(1); 47 | QString winTitle = fileName.split("img_").at(0) + "图像" + index; 48 | GLint indexInt = index.toInt(); 49 | u_short indexUshort = 0; 50 | if (indexInt >= 0) 51 | { 52 | indexUshort = static_cast(indexInt); 53 | } 54 | 55 | list > _tmpLinesVbo; 56 | vector _tmpLinesAmount; 57 | vector2f _xRange = {1, 0}; 58 | vector2f _yRange = {1, 0}; 59 | vector2f _zRange = {1, 0}; 60 | 61 | map lineColors; 62 | u_char frameType = 0; 63 | 64 | m_dataRAW.readDataFromFileNoName(indexUshort, _tmpLinesVbo, _tmpLinesAmount, lineColors); 65 | m_dataRAW.readLineRangeFromFileNoName(indexUshort, frameType, _xRange, _yRange, _zRange); 66 | 67 | 68 | COFFOpenglWidget* _OFFOpenglWidget = new COFFOpenglWidget(frameType, m_allocVBOandVAO, winTitle); 69 | _OFFOpenglWidget->setMarkForFile(true); 70 | _OFFOpenglWidget->setGeometry(40,40,400,400); 71 | _OFFOpenglWidget->show(); 72 | _OFFOpenglWidget->setWindowTitle(winTitle); 73 | _OFFOpenglWidget->setChartObjectName(title); 74 | _OFFOpenglWidget->setChartCopyFromOtherOpenWidgetMark(false); 75 | _OFFOpenglWidget->setChartCordRangei(_xRange, _yRange, _zRange); 76 | _OFFOpenglWidget->setChartLinesVboBufferData(_tmpLinesVbo, _tmpLinesAmount); 77 | _OFFOpenglWidget->setChartLineColor(lineColors); 78 | _OFFOpenglWidget->setMainLayout(); 79 | _OFFOpenglWidget->raise(); 80 | 81 | m_OFFOpenglWidgetsFile.push_back(_OFFOpenglWidget); 82 | } 83 | 84 | void MainWindow::open() 85 | { 86 | //QString fileName = QFileDialog::getOpenFileName(this, tr("打开已有的图像"), ".", tr("数据文件(*.dat)")); 87 | QStringList fileName = QFileDialog::getOpenFileNames(this, tr("打开已有的图像"), ".", tr("数据文件(*.dat)")); 88 | for(QStringList::iterator it = fileName.begin(); it != fileName.end(); ++it) 89 | { 90 | if(!((*it).isEmpty())) 91 | onReadFromFileOutDisplayState(*it); 92 | } 93 | // system("pwd >> text.txt"); 94 | } 95 | 96 | void MainWindow::closeEvent(QCloseEvent *event) 97 | { 98 | m_widgetCentral->closeTimer(); 99 | event->accept(); 100 | } 101 | 102 | void MainWindow::createActions() 103 | { 104 | openAction = new QAction(tr("&Open"), this); 105 | // openAction->setIcon(QIcon("")); 106 | openAction->setShortcut(QKeySequence::Open); 107 | openAction->setStatusTip("打开一个现有文件"); 108 | connect(openAction, SIGNAL(triggered()), this, SLOT(open())); 109 | } 110 | 111 | void MainWindow::createMenus() 112 | { 113 | fileMenu = menuBar()->addMenu(tr("文件(&F)")); 114 | fileMenu->addAction(openAction); 115 | separatorAction = fileMenu->addSeparator(); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /mainWidget/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include "mainWidget/tools.h" 5 | #include "Widget.h" 6 | #include "DataManageMent/CDataRAW.h" 7 | #include "Widgets/COFFOpenglwidget.h" 8 | #include "DataManageMent/CAllocVBOandVAO.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Ui { 16 | class MainWindow; 17 | } 18 | 19 | class MainWindow : public QMainWindow 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | explicit MainWindow(QWidget *parent = 0); 25 | ~MainWindow(); 26 | 27 | void onReadFromFileOutDisplayState(QString fileName); 28 | private slots: 29 | void open(); 30 | void closeEvent(QCloseEvent* event); 31 | 32 | private: 33 | void createActions(); 34 | void createMenus(); 35 | 36 | 37 | Ui::MainWindow *ui; 38 | QMenu *fileMenu; 39 | 40 | QAction *separatorAction; 41 | QAction *openAction; 42 | 43 | Widget *m_widgetCentral; 44 | 45 | //读取文件信息后生成的窗口, 从文件提取 46 | vector m_OFFOpenglWidgetsFile; 47 | 48 | CDataRAW m_dataRAW; 49 | CAllocVBOandVAO* m_allocVBOandVAO; 50 | boost::mutex m_mutexOutWidget; 51 | }; 52 | 53 | #endif // MAINWINDOW_H 54 | -------------------------------------------------------------------------------- /mainWidget/tools.h: -------------------------------------------------------------------------------- 1 | #ifndef TOOLS_H 2 | #define TOOLS_H 3 | 4 | #define LLDELETE(x) {if(x){delete x; x = nullptr;}} 5 | 6 | #endif // TOOLS_H 7 | -------------------------------------------------------------------------------- /ui/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | TopToolBarArea 20 | 21 | 22 | false 23 | 24 | 25 | 26 | 27 | 28 | 网格开/关 29 | 30 | 31 | 32 | 33 | 坐标开/关 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /ui/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 714 10 | 612 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | --------------------------------------------------------------------------------