DGtal  0.9.3
Functions
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/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 52 of file testColorMaps.cpp.

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

Referenced by main().

56 {
57  BOOST_CONCEPT_ASSERT(( concepts::CColorMap<TColorMap> ));
58 
59  typedef typename TColorMap::Value Value;
60  board.translate( 0, 15 );
61  board.setPenColor(Color::Black);
62  board.setFont( LibBoard::Fonts::Courier, 12 ); // todo with Cairo
63  board.drawText( -150, 0, name ); // todo with Cairo
64  board.setPenColor(Color::None);
65  for ( Value x = aColorMap.min(); x <= aColorMap.max(); x += step ) {
66  board.setFillColor( aColorMap( x ) );
67  board.drawRectangle( static_cast<double>( x ),
68  10,
69  static_cast<double>( step ),
70  10 );
71  }
72 }
void drawText(double x, double y, const char *text, int depthValue=-1)
Definition: Board.cpp:693
void drawRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition: Board.cpp:417
Board & setFillColor(const DGtal::Color &color)
Definition: Board.cpp:322
Shape & translate(double dx, double dy)
Definition: Board.cpp:176
Board & setFont(const Fonts::Font font, double fontSize)
Definition: Board.cpp:336
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
Aim: Defines the concept describing a color map. A color map converts a value within a given range in...
Definition: CColorMap.h:93

◆ main()

int main ( )

Definition at line 138 of file testColorMaps.cpp.

References DGtal::RandomColorMap::addColor(), DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), addColorMapSample(), DGtal::Trace::beginBlock(), 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, DGtal::Trace::emphase(), DGtal::Trace::endBlock(), LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), LibBoard::Board::saveTikZ(), testGrayscaleColorMap(), and DGtal::trace.

139 {
140  Board board;
141  trace.beginBlock ( "Testing GrayscaleColorMap" );
142  bool res1 = testGrayscaleColorMap();
143  trace.emphase() << ( res1 ? "Passed." : "Error." ) << endl;
144  trace.endBlock();
145 
146  GrayscaleColorMap<int> cmap_gray( 0, 500);
147  addColorMapSample( "Grayscale", cmap_gray, 1, board );
148 
149  ColorBrightnessColorMap<int> cmap_red( 0, 500, Color::Red );
150  addColorMapSample( "Brightness", cmap_red, 1, board );
151 
153  addColorMapSample( "Bright (Blue)", cmap_blue, 1, board );
154 
155  HueShadeColorMap<int,2> cmap_hsv( 0, 500);
156  addColorMapSample( "HueShade", cmap_hsv, 1, board );
157 
158  HueShadeColorMap<int,2> cmap_cyclic5( 0, 500 );
159  addColorMapSample( "HueShade (2x)", cmap_cyclic5, 1, board );
160 
161  HueShadeColorMap<int, 10> cmap_cyclic10( 0, 500 );
162  addColorMapSample( "HueShade (10x)", cmap_cyclic10, 1, board );
163 
164  RandomColorMap cmap_random(0,500, Color::Green, Color::Red);
165  cmap_random.addColor(Color::Red);
166  cmap_random.addColor(Color::Blue);
167  cmap_random.addColor(Color::Yellow);
168 
169  const int yellow = DGTAL_RGB2INT(255,255,0);
170  const int red = DGTAL_RGB2INT(255,0,0);
171  GradientColorMap<int, CMAP_CUSTOM, yellow, red> cmap_gradient( 0, 500 );
172  addColorMapSample( "Gradient (Y->R)", cmap_gradient, 1, board );
173 
174  GradientColorMap<int> cmap_grad3( 0, 500 );
175  cmap_grad3.addColor( Color::Green );
176  cmap_grad3.addColor( Color::Yellow );
177  cmap_grad3.addColor( Color::Red );
178  addColorMapSample( "Gradient (G->Y->R)", cmap_grad3, 1, board );
179 
180  cmap_grad3.clearColors();
181  cmap_grad3.addColor( Color::Blue );
182  cmap_grad3.addColor( Color::White );
183  cmap_grad3.addColor( Color::Red );
184  addColorMapSample( "Gradient (B->W->R)", cmap_grad3, 1, board );
185 
186  GradientColorMap<int> cool_gradient( 0, 500, CMAP_COOL );
187  addColorMapSample( "Gradient (Cool)", cool_gradient, 1, board );
188 
189  GradientColorMap<int> copper_gradient( 0, 500, CMAP_COPPER );
190  addColorMapSample( "Gradient (Copper)", copper_gradient, 1, board );
191 
192  GradientColorMap<int> hot_gradient( 0, 500, CMAP_HOT );
193  addColorMapSample( "Gradient (Hot)", hot_gradient, 1, board );
194 
195  GradientColorMap<int,CMAP_JET> jet_gradient( 0, 500 );
196  addColorMapSample( "Gradient (Jet)", jet_gradient, 1, board );
197 
198  addColorMapSample( "Gradient (Spring)",
200  1,
201  board );
202  addColorMapSample( "Gradient (Summer)",
203  GradientColorMap<int>( 0, 500, CMAP_SUMMER ),
204  1,
205  board );
206  addColorMapSample( "Gradient (Autumn)",
207  GradientColorMap<int>( 0, 500, CMAP_AUTUMN ),
208  1,
209  board );
210  addColorMapSample( "Gradient (Winter)",
211  GradientColorMap<int>( 0, 500, CMAP_WINTER ),
212  1,
213  board );
214  addColorMapSample( "Random", cmap_random, 1, board );
215 
216  board.saveEPS( "colormaps.eps" );
217  board.saveSVG( "colormaps.svg" );
218  board.saveTikZ( "colormaps.tikz" );
219 
220 #ifdef WITH_CAIRO
221  board.saveCairo("colormaps-cairo.ps", Board2D::CairoPS);
222 #endif
223 
224  return ( res1 ) ? 0 : 1;
225 }
void beginBlock(const std::string &keyword="")
void addColorMapSample(const char *name, const TColorMap &aColorMap, const typename TColorMap::Value step, Board &board)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Trace trace
Definition: Common.h:137
Class for EPS, FIG or SVG drawings.
Definition: Board.h:35
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.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
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
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
std::ostream & emphase()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
bool testGrayscaleColorMap()

◆ testGrayscaleColorMap()

bool testGrayscaleColorMap ( )

Definition at line 74 of file testColorMaps.cpp.

References DGtal::Trace::beginBlock(), DGtal::Color::blue(), DGtal::Trace::endBlock(), DGtal::Color::green(), DGtal::Trace::info(), DGtal::Color::red(), and DGtal::trace.

Referenced by main().

75 {
76  unsigned int nbok = 0;
77  unsigned int nb = 6;
78 
79  trace.beginBlock("Colormap 0..255");
80  {
82 
83  Color c0 = cmap(0);
84  trace.info();
85  cerr << int(c0.red())
86  << "," << int(c0.green()) << "," << int(c0.blue()) << std::endl;
87  nbok += ( c0 == Color::Black );
88 
89  Color c128 = cmap(128);
90  trace.info();
91  cerr << int(c128.red())
92  << "," << int(c128.green()) << "," << int(c128.blue()) << std::endl;
93  nbok += ( c128 == Color(128,128,128) );
94 
95  Color c255 = cmap(255);
96  trace.info();
97  cerr << int(c255.red())
98  << "," << int(c255.green()) << "," << int(c255.blue()) << std::endl;
99  nbok += ( c255 == Color::White );
100  }
101  trace.endBlock();
102 
103  trace.beginBlock("Colormap 64..128");
104  {
106  Color c0 = cmap(64);
107  trace.info();
108  cerr << int(c0.red())
109  << "," << int(c0.green()) << "," << int(c0.blue()) << std::endl;
110  nbok += ( c0 == Color::Black );
111 
112  Color c255 = cmap(128);
113  trace.info();
114  cerr << int(c255.red())
115  << "," << int(c255.green()) << "," << int(c255.blue()) << std::endl;
116  nbok += ( c255 == Color::White );
117  }
118  trace.endBlock();
119 
120  trace.beginBlock("Static method");
121  {
123  trace.info() << "Should be white: ";
124  cerr << int(c.red())
125  << "," << int(c.green()) << "," << int(c.blue()) << std::endl;
126  nbok += (c == Color::White);
127 
129  trace.info() << "Should be around 127,127,127: ";
130  cerr << int(c.red())
131  << "," << int(c.green()) << "," << int(c.blue()) << std::endl;
132 
133  trace.endBlock();
134  }
135  return nbok == nb;
136 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)