DGtal 1.4.0
Loading...
Searching...
No Matches
fullConvexityLUT2D.cpp File Reference
#include <vector>
#include <fstream>
#include "DGtal/shapes/Shapes.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/geometry/volumes/DigitalConvexity.h"
#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
#include "DGtal/helpers/Shortcuts.h"
#include "ConfigExamples.h"
Include dependency graph for fullConvexityLUT2D.cpp:

Go to the source code of this file.

Typedefs

typedef std::vector< bool > ConfigMap
 
typedef DigitalConvexity< KSpaceDConv
 
typedef Shortcuts< KSpaceSH2
 
typedef NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA1
 

Functions

void outputTableAsArray (ostream &out, const string &tableName, const ConfigMap &map)
 
void displaySimplicityTable (Board2D &board, const ConfigMap &map, bool complement, bool with)
 
int main (int argc, char **argv)
 

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
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2021/06/22

An example file named fullConvexityLUT2D.

This file is part of the DGtal library.

Definition in file fullConvexityLUT2D.cpp.

Typedef Documentation

◆ ConfigMap

typedef std::vector<bool> ConfigMap

◆ DConv

Definition at line 77 of file fullConvexityLUT2D.cpp.

◆ NCA1

Definition at line 79 of file fullConvexityLUT2D.cpp.

◆ SH2

typedef Shortcuts<KSpace> SH2

Definition at line 78 of file fullConvexityLUT2D.cpp.

Function Documentation

◆ displaySimplicityTable()

void displaySimplicityTable ( Board2D & board,
const ConfigMap & map,
bool complement,
bool with )
Examples
geometry/volumes/fullConvexityLUT2D.cpp, and topology/generateSimplicityTables2D.cpp.

Definition at line 102 of file fullConvexityLUT2D.cpp.

106{
107 Point p1 = Point::diagonal( -1 );
108 Point p2 = Point::diagonal( 1 );
109 Point c = Point::diagonal( 0 );
110 Domain domain( p1, p2 );
111
112 Point q1 = Point::diagonal( -1 );
113 Point q2 = Point::diagonal( 4*16-1 );
114 Domain fullDomain( q1, q2 );
115 board << SetMode( fullDomain.className(), "Paving" );
116 unsigned int cfg = 0;
117 for ( unsigned int y = 0; y < 16; ++y )
118 for ( unsigned int x = 0; x < 16; ++x, ++cfg )
119 {
120 bool simple = map[ cfg ];
121 Point base( x*4, y*4 );
122 unsigned int mask = 1;
123 for ( auto it = domain.begin();
124 it != domain.end(); ++it )
125 {
126 Point q = base + (*it);
127 if ( *it == c ) {
128 if ( with )
129 board << CustomStyle( q.className(),
130 simple
131 ? new CustomColors( Color( 0, 0, 0 ),
132 Color( 30, 128, 30 ) )
133 : new CustomColors( Color( 0, 0, 0 ),
134 Color( 128, 30, 30 ) ) );
135 else
136 board << CustomStyle( q.className(),
137 simple
138 ? new CustomColors( Color( 0, 0, 0 ),
139 Color( 200, 255, 200 ) )
140 : new CustomColors( Color( 0, 0, 0 ),
141 Color( 255, 200, 200 ) ) );
142
143 } else {
144 bool in_cfg = cfg & mask;
145 bool display = complement ? ( ! in_cfg ) : in_cfg;
146 if ( display )
147 board <<
148 CustomStyle( q.className(),
149 simple
150 ? new CustomColors( Color( 0, 0, 0 ),
151 Color( 10, 255, 10 ) )
152 : new CustomColors( Color( 0, 0, 0 ),
153 Color( 255, 10, 10 ) ) );
154 else
155 board <<
156 CustomStyle( q.className(),
157 simple
158 ? new CustomColors( Color( 0, 0, 0 ),
159 Color( 245, 255, 245 ) )
160 : new CustomColors( Color( 0, 0, 0 ),
161 Color( 255, 245, 245 ) ) );
162 mask <<= 1;
163 }
164 board << q;
165 }
166 }
167}
Structure representing an RGB triple with alpha component.
Definition Color.h:68
const ConstIterator & begin() const
const ConstIterator & end() const
static Self diagonal(Component val=1)
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition Board2D.h:279
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
void display(ostream &out, const AContainer &C)
Domain domain

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::HyperRectDomain< TSpace >::className(), DGtal::PointVector< dim, Integer >::diagonal(), display(), domain, and DGtal::HyperRectDomain< TSpace >::end().

Referenced by main().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 170 of file fullConvexityLUT2D.cpp.

171{
172 DConv dconv( Point::diagonal( -5 ), Point::diagonal( 5 ) );
173
174 trace.beginBlock ( "Generate 2d tables" );
175 ConfigMap table_with ( 256, false );
176 ConfigMap table_without ( 256, false );
177 ConfigMap table_cwith ( 256, false );
178 ConfigMap table_cwithout( 256, false );
179 Point p1 = Point::diagonal( -1 );
180 Point p2 = Point::diagonal( 1 );
181 Point c = Point::diagonal( 0 );
182 Domain domain( p1, p2 );
183 unsigned int cfg = 0;
184 KSpace K;
185 K.init( p1, p2, true );
188 for ( unsigned int y = 0; y < 16; ++y )
189 for ( unsigned int x = 0; x < 16; ++x )
190 {
191 // Building a configuration.
192 std::vector< Point > Xwith;
193 std::vector< Point > Xwithout;
194 Point base( x, y );
195 unsigned int mask = 1;
196 for ( auto it = domain.begin(); it != domain.end(); ++it )
197 {
198 const Point p = *it;
199 if ( p != c )
200 {
201 image.setValue( p, cfg & mask );
202 mask <<= 1;
203 }
204 }
205 // Checking full convexity.
206 LCA.setCenter( c, image );
207 bool full_with = LCA.isFullyConvex( true );
208 bool full_without = LCA.isFullyConvex( false );
209 bool full_cwith = LCA.isComplementaryFullyConvex( true );
210 bool full_cwithout = LCA.isComplementaryFullyConvex( false );
211 table_with [ cfg ] = full_with;
212 table_without [ cfg ] = full_without;
213 table_cwith [ cfg ] = full_cwith;
214 table_cwithout[ cfg ] = full_cwithout;
215 cfg += 1;
216 }
217 trace.endBlock();
218 trace.beginBlock ( "Computing topology-related tables" );
219 ConfigMap table_regular ( 256, false );
220 for ( cfg = 0; cfg < 256; cfg++ )
221 table_regular[ cfg ] = table_with[ cfg ] && table_without[ 255 - cfg ];
222 ConfigMap table_collapsible( 256, false );
223 for ( cfg = 0; cfg < 256; cfg++ )
224 table_collapsible[ cfg ] = table_with[ cfg ] && table_without[ cfg ]
225 && ( cfg != 0 );
226 trace.endBlock();
227 trace.beginBlock ( "Display 2d tables" );
228 {
229 Board2D board;
230 displaySimplicityTable( board, table_with, false, true );
231 board.saveEPS( "table-fcvx-with-center.eps" );
232 }
233 {
234 Board2D board;
235 displaySimplicityTable( board, table_without, false, false );
236 board.saveEPS( "table-fcvx-without-center.eps" );
237 }
238 {
239 Board2D board;
240 displaySimplicityTable( board, table_cwith, true, true );
241 board.saveEPS( "table-complementary-fcvx-with-center.eps" );
242 }
243 {
244 Board2D board;
245 displaySimplicityTable( board, table_cwithout, true, false );
246 board.saveEPS( "table-complementary-fcvx-without-center.eps" );
247 }
248 {
249 Board2D board;
250 displaySimplicityTable( board, table_regular, false, true );
251 board.saveEPS( "table-fcvx-regular.eps" );
252 }
253 {
254 Board2D board;
255 displaySimplicityTable( board, table_collapsible, false, true );
256 board.saveEPS( "table-fcvx-collapsible.eps" );
257 }
258 trace.endBlock();
259 trace.beginBlock ( "Output 2d tables as C arrays" );
260 ofstream out( "table-fcvx.cpp" );
261 outputTableAsArray( out, "table-fcvx-with-center",
262 table_with );
263 outputTableAsArray( out, "table-fcvx-without-center",
264 table_without );
265 outputTableAsArray( out, "table-complementary-fcvx-with-center",
266 table_cwith );
267 outputTableAsArray( out, "table-complementary-fcvx-without-center",
268 table_cwithout );
269 outputTableAsArray( out, "table-fcvx-regular",
270 table_regular );
271 outputTableAsArray( out, "table-fcvx-collapsible",
272 table_collapsible );
273 out.close();
274 trace.endBlock();
275 return 0;
276}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A class that models a neighborhood and that provides services to analyse the convexity properti...
void beginBlock(const std::string &keyword="")
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
std::vector< bool > ConfigMap
void displaySimplicityTable(Board2D &board, const ConfigMap &map, bool complement, bool with)
void outputTableAsArray(ostream &out, const string &tableName, const ConfigMap &map)
Trace trace
Definition Common.h:153
KSpace K

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::PointVector< dim, Integer >::diagonal(), displaySimplicityTable(), domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::NeighborhoodConvexityAnalyzer< TKSpace, K >::isComplementaryFullyConvex(), DGtal::NeighborhoodConvexityAnalyzer< TKSpace, K >::isFullyConvex(), K, outputTableAsArray(), LibBoard::Board::saveEPS(), DGtal::NeighborhoodConvexityAnalyzer< TKSpace, K >::setCenter(), and DGtal::trace.

◆ outputTableAsArray()

void outputTableAsArray ( ostream & out,
const string & tableName,
const ConfigMap & map )

Output simplicity configuration table as a C array.

Examples
geometry/volumes/fullConvexityLUT2D.cpp, and topology/generateSimplicityTables2D.cpp.

Definition at line 86 of file fullConvexityLUT2D.cpp.

89{
90 out << "const bool " << tableName << "[ " << map.size() << " ] = { ";
91 for ( auto it = map.cbegin(), it_end = map.cend();
92 it != it_end; )
93 {
94 out << (int) *it;
95 ++it;
96 if ( it != it_end ) out << ", ";
97 }
98 out << " };" << std::endl;
99}

Referenced by main().