4. Draw Spectral curve Qgraphicsview class

Source: Internet
Author: User

First, preface

QT's Qgraphicsview class has powerful view capabilities, along with the Qgraphicsscene class and the Qgraphicsitem class. The general idea is to construct the scene class, then add various elements to the scene object, and finally use the Qgraphicsview class to display the scene.

Second, draw the spectral curve

The main implementation features are:

1 Pass Click on the image line number, then draw the curve, the code is as follows:

1 voidSpectralprofiledialog::addpressslot ()2 {3     //setmodal (0);4Hyperprocess *ptr = (hyperprocess*) Parentwidget ();5Curfilename = ptr->Curfilename;6CurrentRow = ptr->Currow;7Currentcol = ptr->Curcol;8 9     if(Curfilename = ="")Ten     { OneQmessagebox::information ( This,"Message Error","Current Scene is null!"); A         return; -     } -  the     if(Currentcol = =-1|| CurrentRow = =-1) -     { -Qmessagebox::information ( This,"Message Error","Please Select A Pixel"); -         return; +     } -  +Cv::mat curimg =Gdalopencv::gdal2mat (curfilename); A     if(Currentcol > Curimg.cols | | currentrow >curimg.rows) at         return; -  -     intCount =curimg.channels (); -  -Std::vector<cv::mat>Curimgmat (count); - Cv::split (Curimg,curimgmat); in  -Qvector<qpointf>Pixspectraldata (count); to     DoubleTmpmaxvalue; +     DoubleTmpminvalue; -     DoubleMaxValue =0; the      for(intc =0; c<count;c++) *     { $Cv::minmaxidx (curimgmat[c],&tmpminvalue,&tmpmaxvalue);Panax Notoginseng         if(MaxValue <tmpmaxvalue) -MaxValue =Tmpmaxvalue; thePixspectraldata[c].setx (curimgmat[c].at<float>(Currentcol,currentrow)); +Pixspectraldata[c].sety (c+1); A     } the  +     floatX_scale =1.0* (Ui->spectralgraphicsview->height ()-1)/MaxValue; -     floatY_scale =1.0* (Ui->spectralgraphicsview->width ()-1)/count; $  $ Qpen pen; -Pen.setwidth (2); -Qcolor QC=QCOLOR::FROMHSL (rand ()% the, rand ()% the, rand ()% $); the Pen.setcolor (Qcolor (qc.red (), Qc.green (), Qc.blue ()); - Wuyi      for(intc =0; C<curimg.channels ()-1; C + +) the     { -Myscene->addline (PIXSPECTRALDATA[C].Y () *y_scale,-1.0* (pixspectraldata[c].x () *X_scale), Wupixspectraldata[c+1].Y () *y_scale,-1.0* (pixspectraldata[c+1].x () *X_scale), pen); -     } AboutUi->spectralgraphicsview->Setscene (myScene); $}

Three

4. Draw Spectral curve Qgraphicsview class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.