DGtal 1.3.0
Loading...
Searching...
No Matches
testBoundedLatticePolytopeCounter.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include <vector>
33#include <algorithm>
34#include "DGtal/base/Common.h"
35#include "DGtal/kernel/SpaceND.h"
36#include "DGtal/geometry/volumes/BoundedLatticePolytope.h"
37#include "DGtal/geometry/volumes/BoundedLatticePolytopeCounter.h"
38#include "DGtalCatch.h"
40
41using namespace std;
42using namespace DGtal;
43
44
46// Functions for testing class BoundedLatticePolytopeCounter.
48
49SCENARIO( "BoundedLatticePolytopeCounter< Z2 > unit tests", "[lattice_polytope][2d]" )
50{
51 typedef SpaceND<2,int> Space;
52 typedef Space::Point Point;
53 typedef BoundedLatticePolytope< Space > Polytope;
55
56 GIVEN( "A triangle P at (0,3), (5,0), (15,7)" ) {
57 Point a( 0, 3 );
58 Point b( 8, 0 );
59 Point c( 15, 7 );
60 Polytope P { a, b, c };
61 int nbInside = P.count();
62 int nbInterior = P.countInterior();
63 Counter C( P );
64 int nb0 = C.countAlongAxis( 0 );
65 int nb1 = C.countAlongAxis( 1 );
66 int nb0_int = C.countInteriorAlongAxis( 0 );
67 int nb1_int = C.countInteriorAlongAxis( 1 );
68 THEN( "Its longest axis is 0" )
69 {
70 REQUIRE( C.longestAxis() == 0 );
71 }
72 THEN( "We can count its points per point or per axis" )
73 {
74 REQUIRE( nbInside == nb0 );
75 REQUIRE( nbInside == nb1 );
76 }
77 THEN( "We can count its interior points per point or per axis" )
78 {
79 REQUIRE( nbInterior == nb0_int );
80 REQUIRE( nbInterior == nb1_int );
81 }
82 }
83}
84
85SCENARIO( "BoundedLatticePolytope< Z3 > unit tests", "[lattice_polytope][3d]" )
86{
87 typedef SpaceND<3,int> Space;
88 typedef Space::Point Point;
89 typedef BoundedLatticePolytope< Space > Polytope;
91
92 GIVEN( "A closed arbitrary simplex P at (0,0,0), (6,3,0), (0,5,-10), (-6,4,8)" ) {
93 Point a( 0, 0, 0 );
94 Point b( 6, 3, 0 );
95 Point c( 0, 5, -10 );
96 Point d( -6, 4, 8 );
97 Polytope P { a, b, c, d };
98 int nbInside = P.count();
99 int nbInterior = P.countInterior();
100 Counter C( P );
101 int nb0 = C.countAlongAxis( 0 );
102 int nb1 = C.countAlongAxis( 1 );
103 int nb2 = C.countAlongAxis( 2 );
104 int nb0_int = C.countInteriorAlongAxis( 0 );
105 int nb1_int = C.countInteriorAlongAxis( 1 );
106 int nb2_int = C.countInteriorAlongAxis( 2 );
107 // std::cout << P << std::endl;
108 THEN( "Its longest axis is 2" )
109 {
110 REQUIRE( C.longestAxis() == 2 );
111 }
112 THEN( "We can count its points per point or per axis" )
113 {
114 REQUIRE( nbInside == nb0 );
115 REQUIRE( nbInside == nb1 );
116 REQUIRE( nbInside == nb2 );
117 }
118 THEN( "We can count its interior points per point or per axis" )
119 {
120 REQUIRE( nbInterior == nb0_int );
121 REQUIRE( nbInterior == nb1_int );
122 REQUIRE( nbInterior == nb2_int );
123 }
124 }
125}
Aim: Useful to compute quickly the lattice points within a polytope, i.e. a convex polyhedron.
Aim: Represents an nD lattice polytope, i.e. a convex polyhedron bounded with vertices with integer c...
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
MyPointD Point
Definition: testClone2.cpp:383
GIVEN("A cubical complex with random 3-cells")
REQUIRE(domain.isInside(aPoint))
SCENARIO("UnorderedSetByBlock< PointVector< 2, int > unit tests with 32 bits blocks", "[unorderedsetbyblock][2d]")