Results 1 to 5 of 5

Thread: Rendering a qwt plot spectrogram

  1. #1
    Join Date
    Feb 2013
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rendering a qwt plot spectrogram

    Hi,

    I am trying to render a QwtPlotSpectrogram into a PDF file using a QwtPlotRenderer.

    Here some code that does not get the result I expected :

    Qt Code:
    1. int main()
    2. {
    3. QwtPlot *plot;
    4. plot = new QwtPlot();
    5. plot->setTitle("Plot");
    6. plot->setAxisScale(QwtPlot::xBottom, 0, 10);
    7. plot->setAxisScale(QwtPlot::yLeft, 0, 10);
    8. plot->enableAxis(QwtPlot::yRight);
    9. plot->setAxisScale(QwtPlot::yRight, 0, 100*100);
    10. plot->show();
    11.  
    12. QVector<double> xData;
    13. QVector<double> zData;
    14. for(int i = 0; i < 100; i++)
    15. {
    16. zData.push_back(i*i);
    17. xData.push_back(i);
    18. }
    19.  
    20. QwtMatrixRasterData *matrix;
    21. matrix = new QwtMatrixRasterData();
    22. matrix->setValueMatrix(zData, 10);
    23. matrix->setInterval(
    24. Qt::XAxis,
    25. QwtInterval(0, 10)
    26. );
    27. matrix->setInterval(
    28. Qt::YAxis,
    29. QwtInterval(0, 10)
    30. );
    31.  
    32. matrix->setInterval(
    33. Qt::ZAxis,
    34. QwtInterval(0, 100*100)
    35. );
    36.  
    37. QwtPlotSpectrogram *spectrogram;
    38. spectrogram = new QwtPlotSpectrogram();
    39. spectrogram->setData(
    40. matrix
    41. );
    42. spectrogram->attach(plot);
    43.  
    44. QwtPlotCurve *curve;
    45. curve = new QwtPlotCurve();
    46. curve->setSamples(xData, zData);
    47. curve->attach(plot);
    48.  
    49. QwtPlotRenderer *plotRenderer;
    50. plotRenderer = new QwtPlotRenderer();
    51. plotRenderer->setDiscardFlag(QwtPlotRenderer::DiscardBackground);
    52. plotRenderer->setDiscardFlag(QwtPlotRenderer::DiscardCanvasBackground);
    53. plotRenderer->setDiscardFlag(QwtPlotRenderer::DiscardCanvasFrame);
    54.  
    55. plot->replot();
    56.  
    57. QPrinter printer;
    58. printer.setOutputFormat(QPrinter::PdfFormat);
    59. printer.setOutputFileName("test01.pdf");
    60. printer.setResolution(QPrinter::HighResolution);
    61. printer.setColorMode(QPrinter::Color);
    62. printer.setDuplex(QPrinter::DuplexAuto);
    63. printer.setFullPage(true);
    64. printer.setOrientation(QPrinter::Landscape);
    65. printer.setPageMargins(0, 0, 0, 0, QPrinter::Millimeter);
    66. printer.setPageOrder(QPrinter::FirstPageFirst);
    67.  
    68. QPainter *painter;
    69. painter = new QPainter();
    70. painter->begin(&printer);
    71.  
    72. plotRenderer->render(plot, painter, painter->viewport());
    73.  
    74. painter->end();
    75.  
    76. return 0;
    77. }
    To copy to clipboard, switch view to plain text mode 

    Please see attachments to understand.

    Thanks !


    Added after 16 minutes:


    Qt Code:
    1. printer.setResolution(QPrinter::HighResolution);
    To copy to clipboard, switch view to plain text mode 

    was the problem.

    I removed it. And I guess I should prefer QPrinter::setResolution instead, if I want to increase the quality of the document.
    Attached Images Attached Images
    • File Type: jpg w.jpg (42.4 KB, 40 views)
    • File Type: jpg p.jpg (31.6 KB, 36 views)
    Last edited by moijhd; 22nd July 2013 at 16:18.

  2. #2
    Join Date
    Feb 2013
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rendering a qwt plot spectrogram

    This is quite not the end : the result is a JPG picture : how to get a vectoriel picture ?

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rendering a qwt plot spectrogram

    The renderer should always create a correct image - even with a very low resolution. So the seconds screenshot looks like a bug to me - in Qwt or in your code. Please upload a small compilable demo, that shows the issue, that I can have a look at it.

    Qt offers 2 types of scalable vector graphic formats: SVG and PDF. I recommend PDF as the SVG renderer ignores painter clipping and because of this not all plots are rendered properly. But even when using SVG or PDF - drawing a raster graphic ( a spectrogram is one ) to a format that is able to handle vector graphics doesn't make it a vector graphic.

    Also note, that the resolution of the resulting image also depends on the resolution of your data !

    Have a look at QwtPlotRenderer::renderDocument() or QwtPlotRenderer::exportTo(). These high level APIs should be more convenient for your use case.

    Uwe

  4. #4
    Join Date
    Feb 2013
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rendering a qwt plot spectrogram

    The second screenshot bug was due to "printer.setResolution(QPrinter::HighResolution);" . I don't know why. I removed it and it rendered fine. The code I provided is compilable.

    Regarding the raster graphic, there is no way to make it a vector graphic ?

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Rendering a qwt plot spectrogram

    Quote Originally Posted by moijhd View Post
    Regarding the raster graphic, there is no way to make it a vector graphic ?
    The reason why it is a raster graphic is because you are displaying raster data. "Vectorizing" data pixels to rectangles won't change anything.

    What you could try to do is to enable QwtMatrixRasterData::BilinearInterpolation. It doesn't make your output scalable, but the image will always be rendered in device resolution ( not limited by the resolution of your data ). But note, that rendering the image will be slower then.

    Uwe

    PS: try to use "spectrogram->setRenderThreadCount( 0 );" to enable multithreaded rendering

Similar Threads

  1. Replies: 23
    Last Post: 9th January 2013, 07:27
  2. Rendering a Raw Image into a Qwt Plot
    By CaveTroll in forum Qwt
    Replies: 1
    Last Post: 20th July 2012, 07:53
  3. Replies: 2
    Last Post: 12th October 2009, 21:17
  4. Spectrogram Plot Hints
    By shargath in forum Qwt
    Replies: 2
    Last Post: 25th February 2009, 11:11
  5. Plot rendering in thread
    By viridis in forum Qwt
    Replies: 4
    Last Post: 3rd October 2008, 10:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.