DGtal 2.1.0
Loading...
Searching...
No Matches
exampleAffineGeometry.cpp File Reference
#include <iostream>
#include <vector>
#include <random>
#include "DGtal/base/Common.h"
#include "DGtal/geometry/tools/AffineGeometry.h"
#include "ConfigExamples.h"
Include dependency graph for exampleAffineGeometry.cpp:

Go to the source code of this file.

Functions

std::mt19937 g (rd())
 
template<typename Point >
std::vector< PointmakeRandomLatticePointsFromDirVectors (int nb, const std::vector< Point > &V)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const std::vector< T > &object)
 
template<typename Point >
bool checkAffineGeometry (int nb, const std::vector< Point > &V)
 
int main (int argc, char *argv[])
 

Variables

std::random_device rd
 

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
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2025/08/28

An example file named exampleAffineGeometry.

This file is part of the DGtal library.

Definition in file exampleAffineGeometry.cpp.

Function Documentation

◆ checkAffineGeometry()

template<typename Point >
bool checkAffineGeometry ( int  nb,
const std::vector< Point > &  V 
)
Examples
geometry/tools/exampleAffineGeometry.cpp.

Definition at line 109 of file exampleAffineGeometry.cpp.

110{
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";
124 std::cout << "Independent(X) =: e = " << e << "\n";
126 std::cout << "Orthogonal(X) =: n = " << n << "\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}
std::vector< Point > makeRandomLatticePointsFromDirVectors(int nb, const std::vector< Point > &V)
DGtal::int64_t computeAffineDimension(const std::vector< TPoint > &X, const double tolerance=1e-12)
void getAffineBasis(TInputPoint &o, std::vector< TPoint > &basis, const std::vector< TInputPoint > &X, const double tolerance=1e-12)
TPoint computeIndependentVector(const std::vector< TPoint > &basis, const double tolerance=1e-12)
static TPoint computeOrthogonalVectorToBasis(const std::vector< TPoint > &basis)
std::vector< std::size_t > computeAffineSubset(const std::vector< TPoint > &X, const double tolerance=1e-12)
TPoint computeSimplifiedVector(const TPoint &v)

References DGtal::functions::computeAffineDimension(), DGtal::functions::computeAffineSubset(), DGtal::functions::computeIndependentVector(), DGtal::functions::computeOrthogonalVectorToBasis(), DGtal::functions::computeSimplifiedVector(), DGtal::functions::getAffineBasis(), and makeRandomLatticePointsFromDirVectors().

Referenced by main().

◆ g()

std::mt19937 g ( rd()  )

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 136 of file exampleAffineGeometry.cpp.

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 {
145 std::vector< Point > X = { Point{3,1} };
146 return checkAffineGeometry( nb, X );
147 }
148 if ( dim == 3 )
149 {
151 std::vector< Point > X = { Point{3,1,-1}, Point{-1,4,2} };
152 return checkAffineGeometry( nb, X );
153 }
154 if ( dim == 4 )
155 {
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 {
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}
Aim: Implements basic operations that will be used in Point and Vector classes.
bool checkAffineGeometry(int nb, const std::vector< Point > &V)
MyPointD Point

References checkAffineGeometry(), and dim.

◆ makeRandomLatticePointsFromDirVectors()

template<typename Point >
std::vector< Point > makeRandomLatticePointsFromDirVectors ( int  nb,
const std::vector< Point > &  V 
)

Definition at line 74 of file exampleAffineGeometry.cpp.

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}
std::mt19937 g(rd())

References g().

Referenced by checkAffineGeometry().

◆ operator<<()

template<typename T >
std::ostream & operator<< ( std::ostream &  out,
const std::vector< T > &  object 
)

Definition at line 99 of file exampleAffineGeometry.cpp.

101{
102 out << "[";
103 for ( auto t : object ) out << " " << t;
104 out << " ]";
105 return out;
106}

Variable Documentation

◆ rd

std::random_device rd

Definition at line 69 of file exampleAffineGeometry.cpp.