DGtal  1.5.beta
testProjection.cpp File Reference
#include <iostream>
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/helpers/BoundaryPredicate.h"
#include "DGtal/topology/SetOfSurfels.h"
#include "DGtal/topology/SCellsFunctors.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtalCatch.h"
Include dependency graph for testProjection.cpp:

Go to the source code of this file.

Functions

double angle (const DGtal::Z2i::RealPoint &point)
 
double angle (const DGtal::Z2i::KSpace &kspace, const DGtal::Z2i::SCell &cell, const double h)
 
template<typename Shape >
void digitize (Shape &shape, std::vector< SCell > &sCells0, std::vector< SCell > &sCells1, KSpace &kspace, const double h)
 
template<typename Shape >
bool test_shape (Shape &shape, const double h, const double epsilon)
 
 TEST_CASE ("Projection test on various shapes")
 

Variables

Domain domain
 

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
Thomas Caissard (thoma.nosp@m.s.ca.nosp@m.issar.nosp@m.d@li.nosp@m.ris.c.nosp@m.nrs..nosp@m.fr )
Date
2016/05/05

Tests of projections functions in starshape.

This file is part of the DGtal library.

Definition in file testProjection.cpp.

Function Documentation

◆ angle() [1/2]

double angle ( const DGtal::Z2i::KSpace kspace,
const DGtal::Z2i::SCell cell,
const double  h 
)

Definition at line 63 of file testProjection.cpp.

64 {
66  return angle(h * emb(cell));
67 }
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
double angle(const DGtal::Z2i::RealPoint &point)

References angle().

◆ angle() [2/2]

double angle ( const DGtal::Z2i::RealPoint point)

Definition at line 56 of file testProjection.cpp.

57 {
58  double angle = atan2(point[1], point[0]);
59  if(angle < 0.) angle += 2. * M_PI;
60  return angle;
61 }

Referenced by angle(), LibBoard::Text::rotate(), and DGtal::NormalCycleFormula< TRealPoint, TRealVector >::twiceMeanCurvature().

◆ digitize()

template<typename Shape >
void digitize ( Shape shape,
std::vector< SCell > &  sCells0,
std::vector< SCell > &  sCells1,
KSpace kspace,
const double  h 
)

Definition at line 91 of file testProjection.cpp.

92 {
93  // -------------------------------------------------------------------------- Type declaring
94  typedef typename DGtal::GaussDigitizer<Space, Shape> Digitizer;
95  typedef SurfelAdjacency<2> SurfelAdj;
96  typedef Surfaces<KSpace> Surf;
97 
98  sCells0.clear();
99  sCells1.clear();
100 
101  // -------------------------------------------------------------------------- Creating the shape
102  Digitizer digitizer;
103  digitizer.attach(shape);
104  digitizer.init(shape.getLowerBound() + Vector(-1,-1), shape.getUpperBound() + Vector(1,1), h);
105  domain = digitizer.getDomain();
106 
107  kspace.init(digitizer.getLowerBound(), digitizer.getUpperBound(), true);
108 
109  const SurfelAdj surfel_adjacency(true);
110  const KSpace::SCell cell_bel = Surf::findABel(kspace, digitizer);
111  Surf::track2DBoundary(sCells1, kspace, surfel_adjacency, digitizer, cell_bel);
112  {
113  typedef std::vector<Point> Points;
114  Points points;
115  Surf::track2DBoundaryPoints(points, kspace, surfel_adjacency, digitizer, cell_bel);
116  const KSpace::SCell point_ref = kspace.sCell(Point(0,0));
117  for(Points::const_iterator pi = points.begin(), pe = points.end(); pi != pe; ++pi) sCells0.push_back(kspace.sCell(*pi, point_ref));
118  }
119 
120  std::sort(sCells0.begin(), sCells0.end(), AngleLessCell(kspace, h));
121  std::sort(sCells1.begin(), sCells1.end(), AngleLessCell(kspace, h));
122 
123  ASSERT(sCells0.size() == sCells1.size());
124 }
RealPoint getLowerBound() const
Definition: Astroid2D.h:122
RealPoint getUpperBound() const
Definition: Astroid2D.h:131
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
SCell sCell(const SPreCell &c) const
From a signed cell, returns a signed cell lying into this Khalismky space.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
MyPointD Point
Definition: testClone2.cpp:383
Domain domain

References domain, DGtal::Astroid2D< TSpace >::getLowerBound(), DGtal::Astroid2D< TSpace >::getUpperBound(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), and DGtal::KhalimskySpaceND< dim, TInteger >::sCell().

Referenced by main(), TEST_CASE(), and test_shape().

◆ TEST_CASE()

TEST_CASE ( "Projection test on various shapes"  )

Definition at line 169 of file testProjection.cpp.

170 {
171  typedef Ball2D<Space> Ball;
172  const Ball ball(Point(0,0), 1.0);
173 
174  typedef Flower2D<Space> Flower2D;
175  const Flower2D flower2D(Point(0,0), 1., 0.3, 5, 0.);
176 
178  const AccFlower2D accFlower2D(Point(0,0), 1., 0.3, 5, 0.);
179 
180  typedef Ellipse2D<Space> Ellipse2D;
181  const Ellipse2D ellipse2D(Point(0,0), 1., 0.4, 0.2);
182 
183  double h = 0.1;
184 
185  SECTION( "Actual test" )
186  {
187  while(h > 0.01)
188  {
189  REQUIRE( test_shape( ball, h, h * 0.01 ) );
190  REQUIRE( test_shape( flower2D, h, h * 0.01 ) );
191  REQUIRE( test_shape( ellipse2D, h, h * 0.01 ) );
192  h /= 1.3;
193  }
194  }
195 }
Aim: Model of the concept StarShaped represents any accelerated flower in the plane.
Definition: AccFlower2D.h:65
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:61
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:65
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
bool test_shape(Shape &shape, const double h, const double epsilon)
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))

References REQUIRE(), SECTION(), and test_shape().

◆ test_shape()

template<typename Shape >
bool test_shape ( Shape shape,
const double  h,
const double  epsilon 
)

Definition at line 127 of file testProjection.cpp.

128 {
129  std::vector<SCell> sCells0, sCells1;
130 
131  KSpace kspace;
132 
133  digitize(shape, sCells0, sCells1, kspace, h);
134 
135  CanonicSCellEmbedder<KSpace> canonicSCellEmbedder(kspace);
136 
137  for(unsigned int i = 0; i < sCells0.size(); i++)
138  {
139  functors::SCellToInnerPoint<KSpace> sCellToInnerPoint(kspace);
140  functors::SCellToOuterPoint<KSpace> sCellToOuterPoint(kspace);
141 
142  auto prev = ( i + sCells0.size() - 3 ) % sCells0.size(), next = (i + 3) % sCells0.size();
143 
144  RealPoint inner_prev = sCellToInnerPoint( sCells0[prev] );
145  RealPoint outer_prev = sCellToOuterPoint( sCells0[prev] );
146 
147  RealPoint inner_next = sCellToInnerPoint( sCells0[next] );
148  RealPoint outer_next = sCellToOuterPoint( sCells0[next] );
149 
150  inner_prev *= h;
151  inner_next *= h;
152 
153  outer_prev *= h;
154  outer_next *= h;
155 
156  RealPoint q_prev = shape.findIntersection(inner_prev, outer_prev, epsilon);
157  RealPoint q_next = shape.findIntersection(inner_next, outer_next, epsilon);
158  RealPoint p = shape.closestPointWithWitnesses(h * canonicSCellEmbedder( sCells0[i] ), q_prev, q_next, 300);
159 
160  const double norm2 = (p - h * canonicSCellEmbedder( sCells0[i]) ).norm();
161 
162  if ( norm2 > sqrt(2.) * h)
163  return false;
164  }
165 
166  return true;
167 }
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
RealPoint closestPointWithWitnesses(const RealPoint &p, const RealPoint &left, const RealPoint &right, const int step) const
RealPoint findIntersection(const RealPoint &inner, const RealPoint &outer, const double epsilon) const
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
void digitize(Shape &shape, std::vector< SCell > &sCells0, std::vector< SCell > &sCells1, KSpace &kspace, const double h)

References DGtal::StarShaped2D< TSpace >::closestPointWithWitnesses(), digitize(), and DGtal::StarShaped2D< TSpace >::findIntersection().

Referenced by TEST_CASE().

Variable Documentation

◆ domain

Domain domain
Examples
arithmetic/lower-integer-convex-hull.cpp, dec/exampleDECSurface.cpp, dec/exampleDiscreteExteriorCalculusChladni.cpp, dec/exampleDiscreteExteriorCalculusSolve.cpp, dec/exampleDiscreteExteriorCalculusUsage.cpp, dec/exampleHeatLaplace.cpp, dec/examplePropagation.cpp, doc-examples/demo-kernel-1.cpp, doc-examples/kernelDomain.cpp, doc-examples/range.cpp, geometry/curves/estimation/exampleCurvature.cpp, geometry/curves/exampleArithmeticalDSL.cpp, geometry/curves/exampleArithmeticalDSS.cpp, geometry/curves/exampleGridCurve2d.cpp, geometry/curves/greedy-dss-decomposition.cpp, geometry/tools/determinant/exampleInHalfPlane.cpp, geometry/tools/exampleAlphaShape.cpp, geometry/tools/exampleConvexHull2D.cpp, geometry/volumes/distance/distancetransform3D.cpp, geometry/volumes/distance/exampleFMM2D.cpp, geometry/volumes/distance/exampleFMM3D.cpp, geometry/volumes/distance/voronoimap2D.cpp, geometry/volumes/dvcm-2d.cpp, geometry/volumes/fullConvexityLUT2D.cpp, geometry/volumes/fullConvexityThinning3D.cpp, geometry/volumes/pConvexity-benchmark.cpp, graph/graphTraversal.cpp, images/exampleConstImageAdapter.cpp, images/extract2DImagesFrom3DandVisu.cpp, images/extract2DSlicesImagesFrom3D.cpp, io/boards/dgtalBoard2D-1-points.cpp, io/boards/dgtalBoard2D-2-sets.cpp, io/boards/dgtalBoard2D-3-custom-classes.cpp, io/boards/dgtalBoard2D-3-custom-points.cpp, io/boards/dgtalBoard2D-4-colormaps.cpp, io/boards/dgtalBoard3D-1-points.cpp, io/boards/dgtalBoard3D-2-ks.cpp, io/boards/dgtalBoard3D-6-clipping.cpp, io/boards/dgtalBoard3DTo2D-1-points.cpp, io/boards/dgtalBoard3DTo2D-2-sets.cpp, io/boards/dgtalBoard3DTo2D-2bis-sets.cpp, io/boards/dgtalBoard3DTo2D-3-objects.cpp, io/boards/dgtalBoard3DTo2D-4-modes.cpp, io/boards/dgtalBoard3DTo2D-5-custom.cpp, io/boards/dgtalBoard3DTo2D-6.cpp, io/boards/dgtalBoard3DTo2D-KSCell.cpp, io/boards/logoDGtal.cpp, io/viewDualSurface.cpp, io/viewers/demo-kernel-2.cpp, io/viewers/viewer3D-1-points.cpp, io/viewers/viewer3D-11-extension.cpp, io/viewers/viewer3D-2-sets.cpp, io/viewers/viewer3D-3-objects.cpp, io/viewers/viewer3D-4-modes.cpp, io/viewers/viewer3D-4bis-illustrationMode.cpp, io/viewers/viewer3D-5-custom.cpp, io/viewers/viewer3D-6-clipping.cpp, io/viewers/viewer3D-7-planes.cpp, io/viewers/viewer3D-7-stdplane.cpp, io/viewers/viewer3D-7bis-planes.cpp, io/viewers/viewer3D-7bis-stdplane.cpp, shapes/exampleMeshVoxelizer.cpp, topology/3dBorderExtraction.cpp, topology/3dKSSurfaceExtraction.cpp, topology/ctopo-1-3d.cpp, topology/ctopo-1.cpp, topology/ctopo-1s-3d.cpp, topology/cubical-complex-illustrations.cpp, topology/frontierAndBoundary.cpp, topology/generateSimplicityTables2D.cpp, topology/homotopicThinning3D.cpp, topology/trackImplicitPolynomialSurfaceToOFF.cpp, tutorial-examples/AreaSurfaceEstimation-final.cpp, and tutorial-examples/FMMErosion.cpp.

Definition at line 88 of file testProjection.cpp.

Referenced by alphaShape(), DGtal::SetFromImage< TSet >::append(), ArrayImageAdapter_example(), basicUsage(), DGtal::ConvexCellComplex< TPoint >::cellLatticePolytope(), checkChordGenericStandardPlaneComputer(), checkCOBAGenericStandardPlaneComputer(), cmpTranslatedFFT(), DGtal::HyperRectDomain< TSpace >::ConstSubRange::ConstSubRange(), convexHull(), digitize(), displayPredicate(), displaySimplicityTable(), drawArithmeticalDSL(), estimatorOnShapeDigitization(), example(), exampleNaiveDSL(), exampleNaiveDSS(), exampleStandardDSL(), exampleStandardDSS(), exampleUpdate(), generateRefImage(), DGtal::functions::generateSimplicityTable(), DGtal::functions::generateVoxelComplexTable(), DGtal::Shortcuts< TKSpace >::getKSpace(), laplace_sphere(), laplacian(), lightBetween(), localDualVolume(), main(), DGtal::Shortcuts< TKSpace >::makeBinaryImage(), DGtal::Shortcuts< TKSpace >::makeDoubleImage(), DGtal::Shortcuts< TKSpace >::makeFloatImage(), DGtal::Shortcuts< TKSpace >::makeGrayScaleImage(), moduleImages_example(), Object3D(), pointsInStandardPlane(), SCENARIO(), showGreedySegmantation(), sum_fn_on_domain(), TEST_CASE(), TEST_CASE_METHOD(), test_g_f_fm1(), test_image(), test_linear_ring(), test_linear_structure(), test_manual_operators_2d(), test_manual_operators_3d(), test_range_constRange(), testAPI(), testBIGINTEGERSpace(), testBoard2D(), testBoard2DCustomStyle(), testBoard3D(), testBreadthFirstPropagation(), testCellDrawOnBoard(), testCombinatorialSurface(), testCompareEstimator(), testCompareExactBruteForce(), testCompareExactInexact(), testCompareInexactBruteForce(), testConsistence(), testCreate(), testDepthFirstPropagation(), testDigitalSetBoardSnippet(), testDigitalSetBoundary(), testDigitalSetDomain(), testDigitalSetDraw(), testDigitalSetSelector(), testDigitalSurface(), testDigitalSurfaceBoostGraphInterface(), testDigitization(), testDistancePropagation(), testDistanceTransformND(), testDraw(), testDSS4drawing(), testDSS8drawing(), testDTFromSet(), testEmbedder(), testExactMetricBalls(), testExpander(), testFindABel(), testHashTree(), testHashTree2D(), testImageCopy(), testImageCopyShort(), testImageOnRef(), testImageScan(), testImplicitShape(), testImplicitShape3D(), testInexactMetricBalls(), testIterator(), testIteratorHelper(), testIteratorHelperImpl(), testITKMethod(), testKanungo2D(), testLayers(), testObject(), testObject3D(), testObjectBorder(), testObjectGraph(), testOrderingDigitalSurfaceFacesAroundVertex(), testProjector(), testRWIssue254(), testScan(), testSetTable(), testSimple(), testSimple2D(), testSimple3D(), testSimple4D(), testSimpleExpander(), testSimplePoints2D(), testSimplePoints3D(), testSimpleRandom2D(), testSimpleRandom3D(), testSurfelAdjacency(), testTrueLocalEstimatorOnShapeDigitization(), testUmbrellaComputer(), testVoronoiCovarianceMeasure(), testVoronoiMap(), testWriteAndRead(), timingsFullConvexity(), timingsFullConvexityFast(), timingsFullConvexityFastNonConvex(), timingsFullConvexityNonConvex(), timingsPConvexity(), and timingsPConvexityNonConvex().