DGtal 1.4.0
Loading...
Searching...
No Matches
ctopo-fillContours.cpp
Go to the documentation of this file.
1
42#include <iostream>
43#include "ConfigExamples.h"
44#include "DGtal/helpers/StdDefs.h"
45#include "DGtal/base/Common.h"
46#include "DGtal/topology/helpers/Surfaces.h"
47#include "DGtal/topology/SurfelSetPredicate.h"
48#include "DGtal/geometry/curves/FreemanChain.h"
49#include "DGtal/io/boards/Board2D.h"
50#include "DGtal/images/ImageContainerBySTLMap.h"
51
53
54using namespace std;
55using namespace DGtal;
56
58
59int main( int /*argc*/, char** /*argv*/ )
60{
61 trace.beginBlock ( "Example ctopo-fillContours" );
63 K.init(Z2i::Point(0, 10), Z2i::Point(20, 30), false);
64
65 // We choose a direct and indirect oriented contour.
67 FreemanChain<int> fc1 ("001001001001001111101111011222222223222222322233333330301033333003", 6, 14);
68 FreemanChain<int> fc2 ("1111000033332222", 6, 20);
70
71 Board2D aBoard;
72 Board2D aBoard2;
73 aBoard << K.lowerBound() << K.upperBound() ;
74 aBoard2 << K.lowerBound() << K.upperBound() ;
75
76 //From the FreemanChain we can get a vector of SCell wrapped in a SurfelSetPredicate with sign defined from the FreemanChain orientation:
78
80 std::set<DGtal::KhalimskySpaceND< 2, int >::SCell> boundarySCell;
81 FreemanChain<int>::getInterPixelLinels(K, fc1, boundarySCell, false);
83
84 aBoard << CustomStyle((*boundarySCell.begin()).className(), new CustomColors(DGtal::Color::Red, DGtal::Color::Red) );
85 for( std::set<DGtal::KhalimskySpaceND< 2, int >::SCell>::const_iterator it= boundarySCell.begin();
86 it!= boundarySCell.end(); it++){
87 aBoard << *it;
88 }
89
90 // We can also add other freeman chains with indirect orientation to construct a hole in interior of the shape:
92 std::set<DGtal::KhalimskySpaceND< 2, int >::SCell> boundarySCellhole;
93 FreemanChain<int>::getInterPixelLinels(K, fc2, boundarySCellhole, false);
95
96
97 aBoard << CustomStyle((*boundarySCell.begin()).className(), new CustomColors(DGtal::Color::Blue, DGtal::Color::Blue) );
98 aBoard2 << CustomStyle((*boundarySCell.begin()).className(), new CustomColors(DGtal::Color::Blue, DGtal::Color::Blue) );
99
100
101
102 for( std::set<DGtal::KhalimskySpaceND< 2, int >::SCell>::const_iterator it= boundarySCellhole.begin(); it!= boundarySCellhole.end(); it++){
103 aBoard << *it;
104 aBoard2 << *it;
105 boundarySCell.insert(*it);
106 }
107
108
109 // Now we can compute the unsigned cell associated to interior pixels:
110
113 BoolImage2D::Domain imageDomain( Z2i::Point(0,10), Z2i::Point(20,30) );
114 BoolImage2D interiorCellImage( imageDomain );
115 Surfaces<DGtal::KhalimskySpaceND< 2, int > >::uFillInterior(K, functors::SurfelSetPredicate<std::set<SCell>,SCell>(boundarySCell),
116 interiorCellImage, 1, false);
118
119 aBoard << CustomStyle(K.lowerCell().className(), new CustomColors(DGtal::Color::None, Color(200, 200, 200)) );
120 for(BoolImage2D::Domain::ConstIterator it = interiorCellImage.domain().begin();
121 it!=interiorCellImage.domain().end(); it++){
122 if(interiorCellImage(*it)){
123 aBoard << K.uSpel(*it);
124 }
125 }
126
127
128 // We can also compute the unsigned cell associated to interior and exterior pixels:
130 BoolImage2D interiorCellHoleImage( imageDomain );
131 BoolImage2D exteriorCellHoleImage( imageDomain );
132
133
134 Surfaces<DGtal::KhalimskySpaceND< 2, int > >::uFillInterior(K, functors::SurfelSetPredicate<std::set<SCell>, SCell>(boundarySCellhole),
135 interiorCellHoleImage, 1, true);
136 Surfaces<DGtal::KhalimskySpaceND< 2, int > >::uFillExterior(K, functors::SurfelSetPredicate<std::set<SCell>, SCell>(boundarySCellhole),
137 exteriorCellHoleImage, 1, false);
139
140 aBoard2 << CustomStyle(K.lowerCell().className(),
141 new CustomColors(DGtal::Color::None, Color(200, 200, 200)) );
142 for(BoolImage2D::Domain::ConstIterator it = interiorCellHoleImage.domain().begin();
143 it!=interiorCellHoleImage.domain().end(); it++){
144 if(interiorCellHoleImage(*it)){
145 aBoard2 << K.uSpel(*it);
146 }
147 }
148 aBoard2 << CustomStyle(K.lowerCell().className(),
149 new CustomColors(DGtal::Color::None, Color(100, 100, 100)) );
150 for(BoolImage2D::Domain::ConstIterator it = exteriorCellHoleImage.domain().begin();
151 it!=exteriorCellHoleImage.domain().end(); it++){
152 if(exteriorCellHoleImage(*it)){
153 aBoard2 << K.uSpel(*it);
154 }
155 }
156
157 aBoard.saveEPS("example_ctopo-fillContours.eps");
158 aBoard.saveFIG("example_ctopo-fillContours.fig");
159
160 aBoard2.saveEPS("example_ctopo-fillContours2.eps");
161 aBoard2.saveFIG("example_ctopo-fillContours2.fig");
162 trace.endBlock();
163 return 0;
164}
165// //
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
static const Color None
Definition Color.h:412
static const Color Red
Definition Color.h:416
static const Color Blue
Definition Color.h:419
static void getInterPixelLinels(const KhalimskySpaceND< 2, TInteger > &aKSpace, const FreemanChain &fc, typename KhalimskySpaceND< 2, TInteger >::SCellSet &aSCellContour, bool aFlagForAppend=false)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Cell uSpel(Point p) const
From the digital coordinates of a point in Zn, builds the corresponding spel (cell of maximal dimensi...
const Point & lowerBound() const
Return the lower bound for digital points in this space.
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
const Cell & lowerCell() const
Return the lower bound for cells in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition Surfaces.h:79
void beginBlock(const std::string &keyword="")
double endBlock()
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition Board.cpp:906
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
Z3i::SCell SCell
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition Board2D.h:279
std::string className() const
Return the style name used for drawing this object.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: The predicate returning true iff the point is in the domain given at construction.
int main()
Definition testBits.cpp:56
KSpace K