DGtal 1.3.0
Loading...
Searching...
No Matches
testColorMaps.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/io/Color.h"
34#include "DGtal/io/colormaps/CColorMap.h"
35#include "DGtal/io/colormaps/GrayscaleColorMap.h"
36#include "DGtal/io/colormaps/HueShadeColorMap.h"
37#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
38#include "DGtal/io/colormaps/SimpleDistanceColorMap.h"
39#include "DGtal/io/colormaps/GradientColorMap.h"
40#include "DGtal/io/colormaps/RandomColorMap.h"
41#include "DGtal/io/boards/Board2D.h"
42#include "Board/PSFonts.h"
44
45using namespace std;
46using namespace DGtal;
47using namespace LibBoard;
48
50// Function template for testing ColorMap classes.
52template <typename TColorMap>
53void addColorMapSample( const char * name,
54 const TColorMap & aColorMap,
55 const typename TColorMap::Value step,
56 Board & board )
57{
58 BOOST_CONCEPT_ASSERT(( concepts::CColorMap<TColorMap> ));
59
60 typedef typename TColorMap::Value Value;
61 board.translate( 0, 15 );
63 board.setFont( LibBoard::Fonts::Courier, 12 ); // todo with Cairo
64 board.drawText( -250, 0, name ); // todo with Cairo
66 for ( Value x = aColorMap.min(); x <= aColorMap.max(); x += step ) {
67 board.setFillColor( aColorMap( x ) );
68 board.drawRectangle( static_cast<double>( x ),
69 10,
70 static_cast<double>( step ),
71 10 );
72 }
73}
74
76{
77 unsigned int nbok = 0;
78 unsigned int nb = 6;
79
80 trace.beginBlock("Colormap 0..255");
81 {
83
84 Color c0 = cmap(0);
85 trace.info();
86 cerr << int(c0.red())
87 << "," << int(c0.green()) << "," << int(c0.blue()) << std::endl;
88 nbok += ( c0 == Color::Black );
89
90 Color c128 = cmap(128);
91 trace.info();
92 cerr << int(c128.red())
93 << "," << int(c128.green()) << "," << int(c128.blue()) << std::endl;
94 nbok += ( c128 == Color(128,128,128) );
95
96 Color c255 = cmap(255);
97 trace.info();
98 cerr << int(c255.red())
99 << "," << int(c255.green()) << "," << int(c255.blue()) << std::endl;
100 nbok += ( c255 == Color::White );
101 }
102 trace.endBlock();
103
104 trace.beginBlock("Colormap 64..128");
105 {
107 Color c0 = cmap(64);
108 trace.info();
109 cerr << int(c0.red())
110 << "," << int(c0.green()) << "," << int(c0.blue()) << std::endl;
111 nbok += ( c0 == Color::Black );
112
113 Color c255 = cmap(128);
114 trace.info();
115 cerr << int(c255.red())
116 << "," << int(c255.green()) << "," << int(c255.blue()) << std::endl;
117 nbok += ( c255 == Color::White );
118 }
119 trace.endBlock();
120
121 trace.beginBlock("Static method");
122 {
124 trace.info() << "Should be white: ";
125 cerr << int(c.red())
126 << "," << int(c.green()) << "," << int(c.blue()) << std::endl;
127 nbok += (c == Color::White);
128
130 trace.info() << "Should be around 127,127,127: ";
131 cerr << int(c.red())
132 << "," << int(c.green()) << "," << int(c.blue()) << std::endl;
133
134 trace.endBlock();
135 }
136 return nbok == nb;
137}
138
139int main()
140{
141 Board board;
142 trace.beginBlock ( "Testing GrayscaleColorMap" );
143 bool res1 = testGrayscaleColorMap();
144 trace.emphase() << ( res1 ? "Passed." : "Error." ) << endl;
145 trace.endBlock();
146
147 GrayscaleColorMap<int> cmap_gray( 0, 500);
148 addColorMapSample( "Grayscale", cmap_gray, 1, board );
149
150 ColorBrightnessColorMap<int> cmap_red( 0, 500, Color::Red );
151 addColorMapSample( "Brightness", cmap_red, 1, board );
152
153 ColorBrightnessColorMap<int, DGTAL_RGB2INT(0,0,255) > cmap_blue( 0, 500 );
154 addColorMapSample( "Bright (Blue)", cmap_blue, 1, board );
155
156 HueShadeColorMap<int,2> cmap_hsv( 0, 500);
157 addColorMapSample( "HueShade", cmap_hsv, 1, board );
158
159 HueShadeColorMap<int,2> cmap_cyclic5( 0, 500 );
160 addColorMapSample( "HueShade (2x)", cmap_cyclic5, 1, board );
161
162 HueShadeColorMap<int, 10> cmap_cyclic10( 0, 500 );
163 addColorMapSample( "HueShade (10x)", cmap_cyclic10, 1, board );
164
165 RandomColorMap cmap_random(0,500, Color::Green, Color::Red);
166 cmap_random.addColor(Color::Red);
167 cmap_random.addColor(Color::Blue);
168 cmap_random.addColor(Color::Yellow);
169
170 const int yellow = DGTAL_RGB2INT(255,255,0);
171 const int red = DGTAL_RGB2INT(255,0,0);
173 addColorMapSample( "Gradient (Y->R)", cmap_gradient, 1, board );
174
175 GradientColorMap<int> cmap_grad3( 0, 500 );
176 cmap_grad3.addColor( Color::Green );
177 cmap_grad3.addColor( Color::Yellow );
178 cmap_grad3.addColor( Color::Red );
179 addColorMapSample( "Gradient (G->Y->R)", cmap_grad3, 1, board );
180
181 cmap_grad3.clearColors();
182 cmap_grad3.addColor( Color::Blue );
183 cmap_grad3.addColor( Color::White );
184 cmap_grad3.addColor( Color::Red );
185 addColorMapSample( "Gradient (B->W->R)", cmap_grad3, 1, board );
186
187 GradientColorMap<int> cool_gradient( 0, 500, CMAP_COOL );
188 addColorMapSample( "Gradient (Cool)", cool_gradient, 1, board );
189
190 GradientColorMap<int> copper_gradient( 0, 500, CMAP_COPPER );
191 addColorMapSample( "Gradient (Copper)", copper_gradient, 1, board );
192
193 GradientColorMap<int> hot_gradient( 0, 500, CMAP_HOT );
194 addColorMapSample( "Gradient (Hot)", hot_gradient, 1, board );
195
196 GradientColorMap<int,CMAP_JET> jet_gradient( 0, 500 );
197 addColorMapSample( "Gradient (Jet)", jet_gradient, 1, board );
198
199 addColorMapSample( "Gradient (Spring)",
201 1,
202 board );
203 addColorMapSample( "Gradient (Summer)",
205 1,
206 board );
207 addColorMapSample( "Gradient (Autumn)",
209 1,
210 board );
211 addColorMapSample( "Gradient (Winter)",
213 1,
214 board );
215 addColorMapSample( "Random", cmap_random, 1, board );
216
217 SimpleDistanceColorMap<int> dt(0,500, false);
218 addColorMapSample( "SimpleDistanceColorMap", dt, 1, board );
219
220 SimpleDistanceColorMap<int> dtticks(0,500, true);
221 addColorMapSample( "SimpleDistanceColorMap (ticks)", dtticks, 1, board );
222
223
224 board.saveEPS( "colormaps.eps" );
225 board.saveSVG( "colormaps.svg" );
226 board.saveTikZ( "colormaps.tikz" );
227
228#ifdef WITH_CAIRO
229 board.saveCairo("colormaps-cairo.pdf", Board2D::CairoPDF);
230#endif
231
232 return ( res1 ) ? 0 : 1;
233}
234// //
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color Yellow
Definition: Color.h:422
static const Color None
Definition: Color.h:412
void green(const unsigned char aGreenValue)
static const Color Green
Definition: Color.h:417
void red(const unsigned char aRedValue)
static const Color Red
Definition: Color.h:416
static const Color White
Definition: Color.h:415
static const Color Blue
Definition: Color.h:419
static const Color Black
Definition: Color.h:413
void blue(const unsigned char aBlueValue)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
static Color getColor(const PValue &min, const PValue &max, const PValue &value)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: access to random color from a gradientColorMap.
void addColor(const Color &aColor)
Aim: simple blue to red colormap for distance information for instance.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Class for EPS, FIG or SVG drawings.
Definition: Board.h:35
void drawRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition: Board.cpp:417
Board & setFont(const Fonts::Font font, double fontSize)
Definition: Board.cpp:336
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
Shape & translate(double dx, double dy)
Definition: Board.cpp:176
void drawText(double x, double y, const char *text, int depthValue=-1)
Definition: Board.cpp:693
Board & setFillColor(const DGtal::Color &color)
Definition: Board.cpp:322
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Aim: Defines the concept describing a color map. A color map converts a value within a given range in...
Definition: CColorMap.h:94
bool testGrayscaleColorMap()
void addColorMapSample(const char *name, const TColorMap &aColorMap, const typename TColorMap::Value step, Board &board)
int main()