DGtal 1.4.0
Loading...
Searching...
No Matches
testColorMaps.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/CColorMap.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
#include "DGtal/io/colormaps/SimpleDistanceColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/RandomColorMap.h"
#include "DGtal/io/boards/Board2D.h"
#include "Board/PSFonts.h"
Include dependency graph for testColorMaps.cpp:

Go to the source code of this file.

Functions

template<typename TColorMap >
void addColorMapSample (const char *name, const TColorMap &aColorMap, const typename TColorMap::Value step, Board &board)
 
bool testGrayscaleColorMap ()
 
int main ()
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Sebastien Fourey (Sebas.nosp@m.tien.nosp@m..Four.nosp@m.ey@g.nosp@m.reyc..nosp@m.ensi.nosp@m.caen..nosp@m.fr ) Groupe de Recherche en Informatique, Image, Automatique et Instrumentation de Caen - GREYC (CNRS, UMR 6072), ENSICAEN, France
Date
2010/07/16

Functions for testing the ColorMap classes.

This file is part of the DGtal library.

Definition in file testColorMaps.cpp.

Function Documentation

◆ addColorMapSample()

template<typename TColorMap >
void addColorMapSample ( const char * name,
const TColorMap & aColorMap,
const typename TColorMap::Value step,
Board & board )

Definition at line 53 of file testColorMaps.cpp.

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}
static const Color None
Definition Color.h:412
static const Color Black
Definition Color.h:413
void drawRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition Board.cpp:416
Board & setFont(const Fonts::Font font, double fontSize)
Definition Board.cpp:335
Board & setPenColor(const DGtal::Color &color)
Definition Board.cpp:297
Shape & translate(double dx, double dy)
Definition Board.cpp:175
void drawText(double x, double y, const char *text, int depthValue=-1)
Definition Board.cpp:692
Board & setFillColor(const DGtal::Color &color)
Definition Board.cpp:321
Aim: Defines the concept describing a color map. A color map converts a value within a given range in...
Definition CColorMap.h:94

References DGtal::Color::Black, LibBoard::Fonts::Courier, LibBoard::Board::drawRectangle(), LibBoard::Board::drawText(), DGtal::Color::None, LibBoard::Board::setFillColor(), LibBoard::Board::setFont(), LibBoard::Board::setPenColor(), and LibBoard::Board::translate().

Referenced by main().

◆ main()

int main ( void )

Definition at line 139 of file testColorMaps.cpp.

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}
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
static const Color Yellow
Definition Color.h:422
static const Color Green
Definition Color.h:417
static const Color Red
Definition Color.h:416
static const Color White
Definition Color.h:415
static const Color Blue
Definition Color.h:419
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
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.
Aim: simple blue to red colormap for distance information for instance.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Class for EPS, FIG or SVG drawings.
Definition Board.h:35
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1218
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1138
Trace trace
Definition Common.h:153
bool testGrayscaleColorMap()
void addColorMapSample(const char *name, const TColorMap &aColorMap, const typename TColorMap::Value step, Board &board)

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::RandomColorMap::addColor(), addColorMapSample(), DGtal::Trace::beginBlock(), DGtal::Color::Blue, DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::clearColors(), DGtal::CMAP_AUTUMN, DGtal::CMAP_COOL, DGtal::CMAP_COPPER, DGtal::CMAP_HOT, DGtal::CMAP_SUMMER, DGtal::CMAP_WINTER, dt, DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Color::Green, DGtal::Color::Red, LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), LibBoard::Board::saveTikZ(), testGrayscaleColorMap(), DGtal::trace, DGtal::Color::White, and DGtal::Color::Yellow.

◆ testGrayscaleColorMap()

bool testGrayscaleColorMap ( )

Definition at line 75 of file testColorMaps.cpp.

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}
Structure representing an RGB triple with alpha component.
Definition Color.h:68
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
static Color getColor(const PValue &min, const PValue &max, const PValue &value)
std::ostream & info()

References DGtal::Trace::beginBlock(), DGtal::Color::Black, DGtal::Color::blue(), DGtal::Trace::endBlock(), DGtal::GrayscaleColorMap< PValue >::getColor(), DGtal::Color::green(), DGtal::Trace::info(), DGtal::Color::red(), DGtal::trace, and DGtal::Color::White.

Referenced by main().