DGtal  1.5.beta
testTickedColorMap.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/io/colormaps/TickedColorMap.h"
36 #include "DGtal/io/colormaps/HueShadeColorMap.h"
37 #include "DGtal/io/colormaps/GradientColorMap.h"
38 #include "DGtal/io/boards/Board2D.h"
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 // Functions for testing class TickedColorMap.
47 
52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
55 
56  trace.beginBlock ( "Testing TickedCMAP..." );
57 
59 
60  ticked.addTick(5.0, 1.0);
61  ticked.addTick(9.0, 1.0);
62  ticked.finalize();
63  trace.info()<<ticked<<std::endl;
64 
65  Color c = ticked(4.5);
66  nbok += (c == Color::White) ? 1 : 0;
67  nb++;
68  trace.info() << "(" << nbok << "/" << nb << ") "
69  << "c == white on tick inf.."<< std::endl;
70 
71  c = ticked(5.5);
72  nbok += (c == Color::White) ? 1 : 0;
73  nb++;
74  trace.info() << "(" << nbok << "/" << nb << ") "
75  << "c == white on tick sup.."<< std::endl;
76 
77  c = ticked(9.5);
78  nbok += (c == Color::White) ? 1 : 0;
79  nb++;
80  trace.info() << "(" << nbok << "/" << nb << ") "
81  << "c == white on tick sup.. "<< std::endl;
82 
83  c = ticked(8.5);
84  nbok += (c == Color::White) ? 1 : 0;
85  nb++;
86  trace.info() << "(" << nbok << "/" << nb << ") "
87  << "c == white on tick sup.. "<< std::endl;
88 
89 
90  c = ticked(20.0);
91  nbok += (c != Color::White) ? 1 : 0;
92  nb++;
93  trace.info() << "(" << nbok << "/" << nb << ") "
94  << "c != white outside.. "<< std::endl;
95  trace.endBlock();
96 
97  return nbok == nb;
98 }
99 
100 bool testCMAP()
101 {
102  Board2D board;
104  ticked.addTick(5.0,1.2);
105  ticked.addTick(19.0,3);
106  ticked.addTick(69.0,3.0);
107  ticked.finalize();
108  trace.info() << ticked<<std::endl;
109  Z2i::Point p;
110 
111  for(unsigned int i=0; i < 100; i++)
112  board<< CustomStyle(p.className(),new CustomColors(ticked(i),ticked(i)))
113  << Z2i::Point(i,0);
114  board.saveEPS("testTicked.eps");
115 
116  board.clear();
118  ticked2.addRegularTicks(10, 1.0);
119  ticked2.finalize();
120  for(unsigned int i=0; i < 100; i++)
121  board<< CustomStyle(p.className(),new CustomColors(ticked2(i),ticked2(i)))
122  << Z2i::Point(i,0);
123  board.saveEPS("testTicked-regular.eps");
124 
125  //same with gradient colormap (and ticked.colormap() accessor)
126  board.clear();
128  ticked3.addRegularTicks(10, 1.0);
129  ticked3.finalize();
130  ticked3.colormap()->addColor( Color::Black );
131  ticked3.colormap()->addColor( Color::Red );
132  for(unsigned int i=0; i < 100; i++)
133  board<< CustomStyle(p.className(),new CustomColors(ticked3(i),ticked3(i)))
134  << Z2i::Point(i,0);
135  board.saveEPS("testTicked-gradient-regular.eps");
136 
137  return true;
138 }
139 
141 // Standard services - public :
142 
143 int main( int argc, char** argv )
144 {
145  trace.beginBlock ( "Testing class TickedColorMap" );
146  trace.info() << "Args:";
147  for ( int i = 0; i < argc; ++i )
148  trace.info() << " " << argv[ i ];
149  trace.info() << endl;
150 
151  bool res = testTickedColorMap() && testCMAP(); // && ... other tests
152  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
153  trace.endBlock();
154  return res ? 0 : 1;
155 }
156 // //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
void addTick(const Value position, const Value thickness)
ColorMap * colormap() const
void addRegularTicks(const unsigned int nbTicks, const Value thickness)
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:151
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
MyPointD Point
Definition: testClone2.cpp:383
int main(int argc, char **argv)
bool testCMAP()
bool testTickedColorMap()