DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleAffineGeometry.cpp
Go to the documentation of this file.
1
16
29
57
58
#include <iostream>
59
#include <vector>
60
#include <random>
61
#include "DGtal/base/Common.h"
63
#include "DGtal/geometry/tools/AffineGeometry.h"
65
#include "ConfigExamples.h"
66
67
using namespace
DGtal
;
68
69
std::random_device
rd
;
70
std::mt19937
g
(
rd
());
71
72
template
<
typename
Po
int
>
73
std::vector< Point >
74
makeRandomLatticePointsFromDirVectors
(
int
nb,
const
std::vector< Point>& V )
75
{
76
std::uniform_int_distribution<int> U(-10, 10);
77
std::vector< Point > P;
78
int
n = V[0].size();
79
int
m = V.size();
80
Point
A
;
81
for
(
auto
i = 0; i < n; i++ )
82
A
[ i ] = U(
g
);
83
P.push_back(
A
);
84
for
(
auto
k = 0; k < nb; k++ )
85
{
86
Point
B
=
A
;
87
for
(
auto
i = 0; i < m; i++ )
88
{
89
int
l = U(
g
);
90
B
+= l * V[ i ];
91
}
92
P.push_back(
B
);
93
}
94
std::shuffle( P.begin(), P.end(),
g
);
95
return
P;
96
}
97
98
template
<
typename
T>
99
std::ostream&
100
operator<<
( std::ostream& out,
const
std::vector< T >&
object
)
101
{
102
out <<
"["
;
103
for
(
auto
t :
object
) out <<
" "
<< t;
104
out <<
" ]"
;
105
return
out;
106
}
107
108
template
<
typename
Po
int
>
109
bool
checkAffineGeometry
(
int
nb,
const
std::vector< Point>& V )
110
{
111
auto
X =
makeRandomLatticePointsFromDirVectors
( nb, V );
112
std::cout <<
"Dimension is "
<< Point::dimension <<
"\n"
;
113
std::cout <<
"X = "
<< X <<
"\n"
;
114
std::cout <<
"Expected dimension of affine set of points X is "
115
<< (Point::dimension-1) <<
"\n"
;
116
std::cout <<
"AffineDim(X) = "
<<
functions::computeAffineDimension
( X ) <<
"\n"
;
117
auto
I =
functions::computeAffineSubset
( X );
118
std::cout <<
"AffineSubset(X) = "
<< I <<
"\n"
;
119
Point
o;
120
std::vector<Point>
B
;
121
functions::getAffineBasis
( o,
B
, X, I );
122
std::cout <<
"AffineBasis(X) =: p+B = "
<< o <<
" + "
<<
B
<<
"\n"
;
123
auto
e =
functions::computeIndependentVector
(
B
);
124
std::cout <<
"Independent(X) =: e = "
<< e <<
"\n"
;
125
Point
n = functions::computeOrthogonalVectorToBasis(
B
);
126
std::cout <<
"Orthogonal(X) =: n = "
<< n <<
"\n"
;
127
Point
ns =
functions::computeSimplifiedVector
( n );
128
std::cout <<
"Orthogonal(X)/gcd =: ns = "
<< ns <<
"\n"
;
129
for
(
auto
i = 0; i <
B
.size(); i++ )
130
std::cout <<
"B["
<< i <<
"] . ns = "
<<
B
[i] <<
" . "
<< ns
131
<<
" == "
<<
B
[i].dot(ns) <<
" (should be 0)\n"
;
132
return
true
;
133
}
134
135
136
int
main
(
int
argc,
char
* argv[] )
137
{
138
int
dim
= argc > 1 ? atoi( argv[ 1 ] ) : 3;
// dimension of the space
139
if
(
dim
> 5 )
dim
= 5;
140
if
(
dim
< 2 )
dim
= 2;
141
int
nb = argc > 2 ? atoi( argv[ 2 ] ) : 10;
// number of points
142
if
(
dim
== 2 )
143
{
144
typedef
PointVector< 2, int64_t>
Point
;
145
std::vector< Point > X = {
Point
{3,1} };
146
return
checkAffineGeometry
( nb, X );
147
}
148
if
(
dim
== 3 )
149
{
150
typedef
PointVector< 3, int64_t>
Point
;
151
std::vector< Point > X = {
Point
{3,1,-1},
Point
{-1,4,2} };
152
return
checkAffineGeometry
( nb, X );
153
}
154
if
(
dim
== 4 )
155
{
156
typedef
PointVector< 4, int64_t>
Point
;
157
std::vector< Point > X = {
Point
{3,1,-1,2},
Point
{-1,4,2,0},
Point
{0,5,3,1} };
158
return
checkAffineGeometry
( nb, X );
159
}
160
if
(
dim
== 5 )
161
{
162
typedef
PointVector< 5, int64_t>
Point
;
163
std::vector< Point > X = {
Point
{3,1,-1,2,3},
Point
{-1,4,2,0,-2},
Point
{0,5,3,1,-1},
Point
{-4,-3,2,1,0} };
164
return
checkAffineGeometry
( nb, X );
165
}
166
}
B
Definition
testPartialTemplateSpecialization.cpp:63
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition
PointVector.h:593
DGtal::Point
checkAffineGeometry
bool checkAffineGeometry(int nb, const std::vector< Point > &V)
Definition
exampleAffineGeometry.cpp:109
DGtal::functions::computeAffineDimension
DGtal::int64_t computeAffineDimension(const std::vector< TPoint > &X, const double tolerance=1e-12)
Definition
AffineGeometry.h:1068
DGtal::functions::getAffineBasis
void getAffineBasis(TInputPoint &o, std::vector< TPoint > &basis, const std::vector< TInputPoint > &X, const double tolerance=1e-12)
Definition
AffineGeometry.h:1145
DGtal::functions::computeIndependentVector
TPoint computeIndependentVector(const std::vector< TPoint > &basis, const double tolerance=1e-12)
Definition
AffineGeometry.h:1202
DGtal::functions::computeAffineSubset
std::vector< std::size_t > computeAffineSubset(const std::vector< TPoint > &X, const double tolerance=1e-12)
Definition
AffineGeometry.h:1089
DGtal::functions::computeSimplifiedVector
TPoint computeSimplifiedVector(const TPoint &v)
Definition
AffineGeometry.h:1394
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
A
Definition
testCountedConstPtrOrConstPtr.cpp:43
g
std::mt19937 g(rd())
rd
std::random_device rd
Definition
testAffineBasis.cpp:45
makeRandomLatticePointsFromDirVectors
std::vector< Point > makeRandomLatticePointsFromDirVectors(int nb, const vector< Point > &V)
Definition
testAffineBasis.cpp:66
dim
#define dim
Definition
testImageContainerByHashTree.cpp:40
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
examples
geometry
tools
exampleAffineGeometry.cpp
Generated on
for DGtal by
1.18.0