33#include "DGtal/base/Common.h"
34#include "ConfigTest.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/geometry/curves/FreemanChain.h"
37#include "DGtal/topology/KhalimskySpaceND.h"
38#include "DGtal/topology/helpers/Surfaces.h"
39#include "DGtal/topology/SurfelSetPredicate.h"
40#include "DGtal/shapes/Shapes.h"
41#include "DGtal/io/boards/Board2D.h"
42#include "DGtal/io/readers/VolReader.h"
43#include "DGtal/base/ConstAlias.h"
62 unsigned int nbok = 0;
72 trace.
beginBlock (
"Testing computation of interior from a freeman chain ..." );
73 std::string freemanChainFilename = testPath +
"samples/contourS.fc";
74 std::string freemanChainFilename2 = testPath +
"samples/SmallBall.fc";
76 fst.open (freemanChainFilename.c_str(), ios::in);
79 fst.open (freemanChainFilename2.c_str(), ios::in);
82 std::set<SCell> boundaryCell;
83 std::set<SCell> boundaryCell2;
86 int minx, miny, maxx, maxy;
89 BoolImage2D::Domain dom(
Point(minx-5,miny-5),
Point(maxx+5, maxy+5));
90 trace.
info() <<
"Domain defined by :" << dom.lowerBound() <<
" " << dom.upperBound() << std::endl;
91 K.
init(dom.lowerBound(), dom.upperBound(),
true);
92 Ko.
init(dom.lowerBound(), dom.upperBound(),
false);
95 BoolImage2D interiorImage(dom);
97 interiorImage, 1,
false);
98 trace.
info() <<
"Interior size: " << nbInt <<
" (awaited: 3082)" << std::endl;
100 BoolImage2D exteriorImage(dom);
102 exteriorImage, 1,
true);
104 exteriorImage, 1,
true);
105 trace.
info() <<
"Exterior size: (KhalimskySpaceND open) " << nbExto <<
" (awaited: 9182)" << std::endl;
106 trace.
info() <<
"Exterior size: (KhalimskySpaceND close)" << nbExt <<
" (awaited: 9182)" << std::endl;
110 int minx2, miny2, maxx2, maxy2;
112 BoolImage2D::Domain dom2(
Point(minx2-5,miny2-5),
Point(maxx2+5, maxy2+5));
113 K2.
init(dom2.lowerBound(), dom2.upperBound(),
false);
114 K2c.
init(dom2.lowerBound(), dom2.upperBound(),
true);
117 BoolImage2D interiorImage2(dom2);
119 interiorImage2, 1,
false);
120 trace.
info() <<
"Interior size2: (KhalimskySpaceND open) " << nbInt2 <<
" (awaited: 196316)" << std::endl;
122 interiorImage2, 1,
false);
123 trace.
info() <<
"Interior size2: (KhalimskySpaceND closed) " << nbInt2c <<
" (awaited: 196316)" << std::endl;
126 Board2D aBoard, aBoard2, aBoard3;
128 for( BoolImage2D::Domain::ConstIterator it = interiorImage.domain().begin(); it!= interiorImage.domain().end(); ++it){
129 if(interiorImage(*it)){
134 for( BoolImage2D::Domain::ConstIterator it = exteriorImage.domain().begin(); it!= exteriorImage.domain().end(); it++){
135 if(exteriorImage(*it)){
140 for( BoolImage2D::Domain::ConstIterator it = interiorImage2.domain().begin(); it!= interiorImage2.domain().end(); it++){
141 if(interiorImage2(*it)){
146 aBoard<<
CustomStyle( (*(boundaryCell.begin())).className(),
148 aBoard3<<
CustomStyle( (*(boundaryCell.begin())).className(),
150 aBoard2<<
CustomStyle( (*(boundaryCell.begin())).className(),
152 for( std::set<SCell>::const_iterator it= boundaryCell.begin(); it!= boundaryCell.end(); it++){
157 for( std::set<SCell>::const_iterator it= boundaryCell2.begin(); it!= boundaryCell2.end(); it++){
174 aBoard.
saveEPS(
"testSurfaceHelperComputeInterior.eps");
175 aBoard3.
saveEPS(
"testSurfaceHelperComputeExterior.eps");
176 aBoard2.
saveEPS(
"testSurfaceHelperComputeInterior2.eps");
177 nbok += (nbInt == 3082 && nbInt2 == 196316 && nbInt2c == 196316 && nbExt== 9182 && nbExto== 9182)? 1 : 0;
179 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
180 << nbInt <<
" (interiorCell.size()) == 3014 and "
181 << nbInt2 <<
" (interiorCell2.size()) == 60196 "
193 unsigned int nbok = 0;
196 trace.
beginBlock (
"Testing extraction of 3D connected component ..." );
200 Set aSet(image.domain());
201 for(
auto const &p: image.domain())
209 Kc.
init(image.domain().lowerBound(),
210 image.domain().upperBound(),
true);
212 std::vector<std::vector<DGtal::Z3i::SCell> > vectConnectedSCell;
215 nbok += vectConnectedSCell.size()==1;
216 trace.
info() <<
"Connected component :" << vectConnectedSCell.size() <<
" (should be 1) " << std::endl;
219 trace.
beginBlock(
"Test 3D filling interior of surface (in an closed KhalimskySpaceND ) ...");
220 Image3dChar imageFilled(image.domain());
221 std::set<Z3i::SCell> setSCell;
for (
auto const &s: vectConnectedSCell[0]) setSCell.insert(s);
225 trace.
info() <<
"Nb voxel filled:" << nbFilled <<
" (should be " << aSet.size() <<
" )" << std::endl;
227 nbok += nbFilled == aSet.size();
231 trace.
beginBlock(
"Test 3D filling interior of surface (in an open KhalimskySpaceND ) ...");
233 ko.
init(image.domain().lowerBound(),
234 image.domain().upperBound(),
false);
236 trace.
info() <<
"Nb voxel filled:" << nbFilled2 <<
" (should be " << aSet.size() <<
" )" << std::endl;
238 nbok += nbFilled2 == aSet.size();
242 trace.
beginBlock(
"Test 3D filling exterior of surface (in an closed KhalimskySpaceND ) ...");
244 trace.
info() <<
"Nb voxel filled:" << nbFilled3 <<
" (should be " << aSet.size() <<
" )" << std::endl;
246 nbok += nbFilled3 == imageFilled.size()-aSet.size();
251 trace.
beginBlock(
"Test 3D filling exterior of surface (in an open KhalimskySpaceND ) ...");
253 trace.
info() <<
"Nb voxel filled:" << nbFilled4 <<
" (should be " << aSet.size() <<
" )" << std::endl;
255 nbok += nbFilled4 == imageFilled.size()-aSet.size();
270template <
typename KSpace3D>
279 unsigned int nbok = 0;
283 Point p1( -5, -5, -5 );
287 pts[ 2 ] =
Point( 5, -5, -5 );
288 pts[ 3 ] =
Point( -5, 5, -5 );
289 pts[ 4 ] =
Point( 5, 5, -5 );
290 pts[ 5 ] =
Point( -5, -5, 5 );
291 pts[ 6 ] =
Point( 5, -5, 5 );
292 pts[ 7 ] =
Point( -5, 5, 5 );
297 for (
unsigned int i = 0; i < 8; ++i )
300 trace.
info() <<
"- Exterior point is " << pts[ i ] << std::endl;
301 trace.
info() <<
" - Found bel = " << bel << std::endl;
302 ++nb; nbok +=
K.
sDim( bel ) == 2;
303 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
304 <<
" K.sDim( bel ) == " <<
K.
sDim( bel ) <<
" (should be 2)" << std::endl;
307 ++nb; nbok += aSet(
K.
sCoords( vox_in ) ) ? 1 : 0;
308 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
309 <<
" vox_in should be inside the shape." << std::endl;
310 ++nb; nbok += aSet(
K.
sCoords( vox_out ) ) ? 0 : 1;
311 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
312 <<
" vox_out should be outside the shape." << std::endl;
321int main(
int argc,
char** argv )
325 for (
int i = 0; i < argc; ++i )
331 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: A container class for storing sets of digital points within some given domain.
void computeBoundingBox(TInteger &min_x, TInteger &min_y, TInteger &max_x, TInteger &max_y) const
static void getInterPixelLinels(const KhalimskySpaceND< 2, TInteger > &aKSpace, const FreemanChain &fc, typename KhalimskySpaceND< 2, TInteger >::SCellSet &aSCellContour, bool aFlagForAppend=false)
std::string className() const
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.
SCell sIndirectIncident(const SCell &p, Dimension k) const
Return the indirect incident cell of [p] along [k] (the incident cell along [k] whose sign is negativ...
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
Point sCoords(const SCell &c) const
Return its digital coordinates.
SCell sDirectIncident(const SCell &p, Dimension k) const
Return the direct incident cell of [p] along [k] (the incident cell along [k])
Dimension sDim(const SCell &p) const
Return the dimension of the cell [p].
static void addNorm2Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
static void extractAllConnectedSCell(std::vector< std::vector< SCell > > &aVectConnectedSCell, const KSpace &aKSpace, const SurfelAdjacency< KSpace::dimension > &aSurfelAdj, const PointPredicate &pp, bool forceOrientCellExterior=false)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
unsigned static int uFillInterior(const KSpace &aKSpace, const TSurfelPredicate &aSurfPred, TImageContainer &anImage, const typename TImageContainer::Value &aValue, bool empty_is_inside=false, bool incrementMode=true)
unsigned static int uFillExterior(const KSpace &aKSpace, const SurfelPredicate &aSurfPred, TImageContainer &anImage, const typename TImageContainer::Value &aValue, bool empty_is_outside=true, bool incrementMode=true)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Aim: The predicate returning true iff the point is in the domain given at construction.
HyperRectDomain< Space > Domain
bool test3dSurfaceHelper()
bool testComputeInterior()
Z2i::DigitalSet DigitalSet