4. 繪製光譜曲線QGraphicsView類

來源:互聯網
上載者:User

標籤:

一、前言

Qt的QGraphicsView類具有強大的視圖功能,與其一起使用的還有QGraphicsScene類和QGraphicsItem類。大體思路就是通過構建情境類,然後向情境對象中增加各種圖元,最後利用QGraphicsView類對情境進行顯示。

二、繪製光譜曲線

實現功能主要有:

1 傳遞點擊映像行列號,然後繪製曲線,代碼如下:

 1 void SpectralProfileDialog::AddPressSlot() 2 { 3     //setModal(0); 4     HyperProcess *ptr = (HyperProcess*)parentWidget(); 5     curFileName = ptr->curFileName; 6     currentRow = ptr->curRow; 7     currentCol = ptr->curCol; 8  9     if(curFileName == "")10     {11         QMessageBox::information(this,"Message Error","Current Scene IS NULL!");12         return;13     }14 15     if(currentCol == -1 || currentRow == -1)16     {17         QMessageBox::information(this,"Message Error","please Select A Pixel");18         return;19     }20 21     cv::Mat curImg = GDALOpenCV::GDAL2Mat(curFileName);22     if(currentCol > curImg.cols || currentRow > curImg.rows)23         return;24 25     int count  = curImg.channels();26 27     std::vector<cv::Mat> curImgMat(count);28     cv::split(curImg,curImgMat);29 30     QVector<QPointF> pixSpectralData(count);31     double tmpMaxValue;32     double tmpMinValue;33     double maxValue = 0;34     for(int c = 0;c<count;c++)35     {36         cv::minMaxIdx(curImgMat[c],&tmpMinValue,&tmpMaxValue);37         if(maxValue < tmpMaxValue)38             maxValue = tmpMaxValue;39         pixSpectralData[c].setX(curImgMat[c].at<float>(currentCol,currentRow));40         pixSpectralData[c].setY(c+1);41     }42 43     float x_scale = 1.0*(ui->spectralGraphicsView->height()-1)/maxValue;44     float y_scale = 1.0*(ui->spectralGraphicsView->width()-1)/count;45 46     QPen pen;47     pen.setWidth(2);48     QColor qc=QColor::fromHsl(rand()%360,rand()%256,rand()%200);49     pen.setColor(QColor(qc.red(),qc.green(),qc.blue()));50 51     for(int c = 0;c<curImg.channels()-1;c++)52     {53         myScene->addLine(pixSpectralData[c].y()*y_scale,-1.0*(pixSpectralData[c].x()*x_scale),54                          pixSpectralData[c+1].y()*y_scale,-1.0*(pixSpectralData[c+1].x()*x_scale),pen);55     }56     ui->spectralGraphicsView->setScene(myScene);57 }

三、

4. 繪製光譜曲線QGraphicsView類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.