Results 1 to 10 of 10

Thread: Any examples of different color tables with Qwt?

  1. #1
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Any examples of different color tables with Qwt?

    Hello all,

    Has anyone done a GUI for Qwt and making/setting new color tables with Qwt plots such as spectrograms?

    Ideally, I'd like to default to a "standard" color bar and let the user switch it to some other predefined ones and/or modify the color table somehow to add more blue/red/purple/etc.

    I'd like to match IDL's color tables somehow if possible if you are familiar with that piece of software.

    I'm not sure where to start so I thought if anyone had an example of something they've done or seen somewhere, that would help!

    Thanks!

  2. #2
    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: Any examples of different color tables with Qwt?

    You could have a look at the rasterview example - but in the end setting the color steps is so simple, that I'm not sure if this is all you are looking for.

    Uwe

  3. #3
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Any examples of different color tables with Qwt?

    I saw that, and I use a similar color bar; however, how did you know what color stops to add where?

    That plus, designing a reasonable GUI for creating/changing color tables seems outside my expertise... I was thinking sliders above/below a color bar which changes on the fly based on user interaction, and then apply that to the existing spectrogram?

    If you have other suggestions, I'm open!

    Joey

  4. #4
    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: Any examples of different color tables with Qwt?

    Quote Originally Posted by bigjoeystud View Post
    I saw that, and I use a similar color bar; however, how did you know what color stops to add where?
    The range of a color map is - independent from any data - always from 0.0->1.0. Like percentage (%) is always 0-100.
    So when the color map is used for diplaying raster data with a given range of 0-2000 ( = QwtRasterData::interval( Qt::ZAxis ) ) a value of 1000 would be mapped to the color at 0.5 in the color map.

    Uwe

  5. #5
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Any examples of different color tables with Qwt?

    Yes, I get this; but I was asking more about the color tables themselves.

    Say I want a black and white color table and/or a "hot" color table (different shades of red), a "cold" color tables (different shades of blue). Then you have to add color stops. I was wanting a selection of different color bars. Could I mix/match them?

    Initially, someone was complaining that the color bar I use (identical to the color spectrogram example) didn't have enough contrast at the low end, and honestly, I had no idea how to fix that!

    Thanks,
    Joey

  6. #6
    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: Any examples of different color tables with Qwt?

    Quote Originally Posted by bigjoeystud View Post
    Initially, someone was complaining that the color bar I use (identical to the color spectrogram example) didn't have enough contrast at the low end, and honestly, I had no idea how to fix that!
    This color map interpolates for the lower 10% of the values between dark cyan to cyan - what are indeed colors with almost no contrast. In the example this is done intentionally as this range is considered as "noise" - instead this color map is using high contrasting colors for the top most 5% for emphasizing them.

    When having too many stops with contrasting colors you will be able to identify the value of each position easily, but the over all readability might get lost. F.e when when 60° is a significant temperature, where something gets damaged, you probably want to have a color map with several stops with high contrasts between 40°-60° not distracted by many colors for values between 0°-10°.

    But often you can't know in advance what information a user is interested in, when inspecting a particular survey, and it might be best to offer a small editor, where the user can modify the color map himself.

    Uwe

  7. #7
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Any examples of different color tables with Qwt?

    Quote Originally Posted by Uwe View Post
    But often you can't know in advance what information a user is interested in, when inspecting a particular survey, and it might be best to offer a small editor, where the user can modify the color map himself.
    This is a case where I wish I had an example color bar editor to model from! I'm not sure what would be good.

    In the mean time, how could I develop a color bar like the one attached? This comes from the GMT documentation. Right now, I would just guess how much color I have where and add a stop for that color, but that seems wrong?

    In their code, they are go over the entire HSV spectrum but I'm not sure how to convert that to a colorStop.

    Joey
    Attached Images Attached Images

  8. #8
    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: Any examples of different color tables with Qwt?

    Quote Originally Posted by bigjoeystud View Post
    In their code, they are go over the entire HSV spectrum but I'm not sure how to convert that to a colorStop.
    If you need to do the same and you already have the code, why trying to emulate it with something else.

    Derive from QwtColorMap ( not using QwtLinearColorMap ! ) and implement HSVColorMap::rgb() using the code you have.
    When you don't have to deal with QImage::Format_Indexed8 images HSVColorMap:colorIndex() can be implemented as a no operation.

    If all you need to do is to interpolate between hsv instead of rgb you could also overload QwtLinearColorMap::rgb() replacing the 3 lines interpolating rgb by doing the same with hsv. ( I would be interested in your patch adding HSV interpolation as an option of QwtLinearColorMap ). Guess in your case min/max of the color map would cover the complete HSV spectrum - without having any other color stops.

    But be careful as HSVColorMap::rgb() will be called very often and needs to implemented as fast as possible !

    Uwe

  9. The following user says thank you to Uwe for this useful post:

    bigjoeystud (3rd October 2014)

  10. #9
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Any examples of different color tables with Qwt?

    I got somewhere... Not sure how I did since I'm not sure I totally understand color scales. Anyway, I modified the spectrogram example and got something interesting.

    Thanks!
    Joey

    Qt Code:
    1. Index: plot.cpp
    2. ===================================================================
    3. --- plot.cpp (revision 2046)
    4. +++ plot.cpp (working copy)
    5. @@ -8,6 +8,8 @@
    6. #include <qwt_plot_panner.h>
    7. #include <qwt_plot_layout.h>
    8. #include <qwt_plot_renderer.h>
    9. +#include <qnumeric.h> // for qIsNan
    10. +#include <qglobal.h> // for qAbs
    11. #include "plot.h"
    12.  
    13. class MyZoomer: public QwtPlotZoomer
    14. @@ -63,13 +65,43 @@
    15. }
    16. };
    17.  
    18. +class HSVColorMap : public QwtColorMap
    19. +{
    20. +public:
    21. + HSVColorMap( QwtColorMap::Format format = QwtColorMap::RGB ) : QwtColorMap (format), _from (Qt::blue), _to (Qt::red) {}
    22. + HSVColorMap( const QColor &from, const QColor &to, QwtColorMap::Format format = QwtColorMap::RGB ) : QwtColorMap (format), _from (from), _to (to) {}
    23. + ~HSVColorMap () {}
    24. + QRgb rgb( const QwtInterval &interval, double value ) const
    25. + {
    26. + if (qIsNaN (value)) return qRgba (0, 0, 0, 0);
    27. +
    28. + const double width = interval.width();
    29. +
    30. + double ratio = 0.0;
    31. + if ( width > 0.0 )
    32. + ratio = ( value - interval.minValue() ) / width;
    33. +
    34. + if ( ratio < 0.0 ) ratio = 0.0; // under lowest end of min!
    35. + if ( ratio > 1.0 ) ratio = 1.0; // over highest end of max!
    36. +
    37. + if (_from.hsvHueF () > _to.hsvHueF ())
    38. + return QColor::fromHsvF ((_from.hsvHueF () - _to.hsvHueF ()) * (1.0 - ratio), 1.0, 1.0).rgb ();
    39. + else return QColor::fromHsvF ((_to.hsvHueF () - _from.hsvHueF ()) * ratio, 1.0, 1.0).rgb ();
    40. + }
    41. +
    42. + void setColorInterval( const QColor &from, const QColor &to )
    43. + {
    44. + _from = from;
    45. + _to = to;
    46. + }
    47. + unsigned char colorIndex (const QwtInterval &, double) const { return 0; } // nop
    48. +
    49. +private:
    50. + QColor _from;
    51. + QColor _to;
    52. +};
    53. +
    54. Plot::Plot( QWidget *parent ):
    55. QwtPlot( parent )
    56. {
    57. d_spectrogram = new QwtPlotSpectrogram();
    58. d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
    59.  
    60. - d_spectrogram->setColorMap( new ColorMap() );
    61. + d_spectrogram->setColorMap( new HSVColorMap(QColor::fromHsv (300, 255, 255), QColor::fromHsv (1, 255, 255)));
    62. d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );
    63.  
    64. d_spectrogram->setData( new SpectrogramData() );
    65. @@ -85,7 +117,7 @@
    66. QwtScaleWidget *rightAxis = axisWidget( QwtPlot::yRight );
    67. rightAxis->setTitle( "Intensity" );
    68. rightAxis->setColorBarEnabled( true );
    69. - rightAxis->setColorMap( zInterval, new ColorMap() );
    70. + rightAxis->setColorMap( zInterval, new HSVColorMap(QColor::fromHsv (300, 255, 255), QColor::fromHsv (1, 255, 255)) );
    71.  
    72. setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
    73. enableAxis( QwtPlot::yRight );
    To copy to clipboard, switch view to plain text mode 
    Last edited by bigjoeystud; 3rd October 2014 at 17:11. Reason: Oops, fixed a major bug!

  11. #10
    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: Any examples of different color tables with Qwt?

    As was interested myself I implemented a color map that interpolates between hue values. The implementation can be found in the spectrogram example in the 6.1 branch - in trunk it can be found as QwtHueColorMap.
    Note that this implementation is way faster than yours, as it calculates the rgb values, that correspond with the possible 360 hue values, in advance.

    I will also play with color maps that interpolate value or saturation if something useful can be done with them.

    Uwe
    Last edited by Uwe; 26th October 2014 at 09:50.

Similar Threads

  1. Replies: 1
    Last Post: 7th March 2013, 00:30
  2. Replies: 4
    Last Post: 13th July 2010, 05:17
  3. Replies: 1
    Last Post: 16th May 2010, 19:25
  4. tables
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 15:17

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.