DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
ctopo-fillContours.cpp File Reference
#include <iostream>
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/topology/SurfelSetPredicate.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/io/boards/Board2D.h"

Go to the source code of this file.

Functions

int main (int, char **)
 

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
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2014/06/16

An example file named ctopo-fillContours.

This file is part of the DGtal library.

Definition in file ctopo-fillContours.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

[ctopoFillContoursInit]

[ctopoFillContoursInit]

[ctopoFillContoursGetSCells]

[ctopoFillContoursGetSCells]

[ctopoFillContoursGetSCellsHole]

[ctopoFillContoursGetSCellsHole]

[ctopoFillContoursFillRegion]

[ctopoFillContoursFillRegion]

[ctopoFillContoursFillRegionHoles]

[ctopoFillContoursFillRegionHoles]

Definition at line 59 of file ctopo-fillContours.cpp.

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}
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:907
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Z3i::SCell SCell
Trace trace
Definition: Common.h:154
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.
ShapeList & insert(const Shape &shape, int depth)
Definition: ShapeList.cpp:184
KSpace K

References DGtal::Trace::beginBlock(), DGtal::Color::Blue, DGtal::KhalimskyCell< dim, TInteger >::className(), DGtal::Trace::endBlock(), DGtal::FreemanChain< TInteger >::getInterPixelLinels(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), LibBoard::ShapeList::insert(), K, DGtal::KhalimskySpaceND< dim, TInteger >::lowerBound(), DGtal::KhalimskySpaceND< dim, TInteger >::lowerCell(), DGtal::Color::None, DGtal::Color::Red, LibBoard::Board::saveEPS(), LibBoard::Board::saveFIG(), DGtal::trace, DGtal::KhalimskySpaceND< dim, TInteger >::upperBound(), and DGtal::KhalimskySpaceND< dim, TInteger >::uSpel().