28 #if defined(NBIJECTIVEREFLECTIONGENERATOR_RECURSES)
29 #error Recursive header files inclusion detected in NBijectiveReflectionGenerator.h
32 #define NBIJECTIVEREFLECTIONGENERATOR_RECURSES
34 #if !defined NBIJECTIVEREFLECTIONGENERATOR_h
36 #define NBIJECTIVEREFLECTIONGENERATOR_h
51 #include "DigitizedReflection.h"
52 #include "CBDR_naiverotation.h"
55 template<
typename TSpace,
typename TInputValue=
typename TSpace::RealPo
int>
59 for(
int k=0; k<
kmax; k++){
63 int x_2kpp_1 = (2*k+1);
68 int y_1_2kpp = (2*k+1);
72 int x_kpp_k_m = (k+1);
75 int x_2kpp_1_m = (2*k+1);
79 int y_k_kpp_m = -(k+1);
80 int y_1_2kpp_m = -(2*k+1);
81 int y_2kpp_1_m = -(1);
104 for(std::pair<std::vector<int>,
GAVector<TSpace>> normalVectorsAndResult : Avector){
105 std::pair<std::vector<int>,
GAVector<TSpace>> resultatCourant = normalVectorsAndResult;
112 resultatCourant.first.push_back(indexB);
113 resultatCourant.second = outVec;
114 result.push_back(resultatCourant);
115 resultatCourant=normalVectorsAndResult;
121 std::sort(result.begin(), result.end(), [](
const std::pair<std::vector<int>,
GAVector<TSpace>>& b1,
const std::pair<std::vector<int>,
GAVector<TSpace>>& b2) {
122 return b1.second < b2.second;});
134 if(fabs(b1.second.angleToXAxis()-b1.second.angleToXAxis())>1e-4){
144 for(
int i =0 ; i<100;++i){
145 for(
int j =0 ; j<100;++j){
149 typename TSpace::Point out1 = reflectionsCompose1(pointCourant);
150 typename TSpace::Point out2 = reflectionsCompose2(pointCourant);
151 if((out1-out2)!= zeroPt ){
161 std::vector<std::pair<std::vector<GAVector<TSpace>>,
GAVector<TSpace>>> vecBijNormalsIndex_GAVector;
162 for(std::pair<std::vector<int>,
GAVector<TSpace>> pairIndexGAVector : vecBijNormalsIndex) {
163 std::vector<GAVector<TSpace>> resGavec;
165 for(
int index : pairIndexGAVector.first) {
168 vecBijNormalsIndex_GAVector.push_back({resGavec,pairIndexGAVector.second});
170 return vecBijNormalsIndex_GAVector;
186 for (
size_t j = 1; j < n; ++j )
191 auto last = std::unique(vecBijNormals.begin(),vecBijNormals.end(),[
this](
const std::pair<std::vector<int>,
GAVector<TSpace>>& b1,
const std::pair<std::vector<int>,
GAVector<TSpace>>& b2) {
192 return sameBijectiveComposition(b1, b2);});
193 vecBijNormals.erase(last,vecBijNormals.end());
197 for(
auto& pairIndicesGAVec : vecBijNormals)
198 pairIndicesGAVec.first.insert(pairIndicesGAVec.first.begin(),0);
201 std::sort(vecBijNormals.begin(), vecBijNormals.end(), [](
const std::pair<std::vector<int>,
GAVector<TSpace>>& b1,
const std::pair<std::vector<int>,
GAVector<TSpace>>& b2) {
202 return b1.second.angleToXAxis() < b2.second.angleToXAxis();});
205 return vecBijNormals;
209 for(
size_t i =0;i<vecBijNormals.size();++i){
210 auto currentIndicesNormalVector=vecBijNormals[i].first;
215 for(
int indexBijective : currentIndicesNormalVector){
218 std::cout <<
"], angle="<<2.0*finalNormalVec.
angleToXAxis()<<std::endl;
225 std::vector<Reflection<TSpace>> normals;
226 for(
auto i : indices){
228 normals.push_back(refi);
234 std::ofstream file(fileName);
236 file <<
"kmax="<<
kmax<<std::endl;
238 for(
size_t i = 0;i<vecBijNormals.size();++i){
239 std::vector<int> gaNormalVecs = vecBijNormals[i].first;
240 for(
auto index :gaNormalVecs)
242 file <<
"("<<vecBijNormals[i].second.my_gavec[0]<<
"," <<vecBijNormals[i].second.my_gavec[1]<<
")"<<std::endl;
252 const double targetAngle)
255 int i = std::lower_bound(vecBijNormals.begin(), vecBijNormals.end(), targetAngle,[](
const std::pair<std::vector<
GAVector<TSpace>>,
GAVector<TSpace>>& b1,
const double b2) {
256 return 2.0*b1.second.angleToXAxis() < b2;
257 }) - vecBijNormals.begin();
263 int numberElements=0;
264 while(numberElements<
K){
265 if (leftCompo < 0 || (rightCompo < vecBijNormals.size() &&
266 fabs(2*vecBijNormals[leftCompo].second.angleToXAxis() - targetAngle) > fabs(2*vecBijNormals[rightCompo].second.angleToXAxis() - targetAngle))) {
274 lowerBound=vecBijNormals.begin()+leftCompo;
275 upperBound=vecBijNormals.begin()+rightCompo;
289 #undef NBIJECTIVEREFLECTIONGENERATOR_RECURSES
DGtal is the top-level namespace which contains all DGtal functions and types.
vec since the parameters are the vectors of digitized reflections
double angleToXAxis() const
void displayNormalVectorsAndAngles(const std::vector< std::pair< std::vector< int >, GAVector< TSpace >>> &vecBijNormals)
void writeBijectiveVectors(const std::string &fileName, const std::vector< std::pair< std::vector< int >, GAVector< TSpace >>> &vecBijNormals)
std::vector< std::pair< std::vector< int >, GAVector< TSpace > > > n_bijectiveReflections_get_NormalVectorsAngles(size_t n)
generate all n =2,4 reflection composition
NBijectiveGenerator(const size_t km)
std::vector< GAVector< TSpace > > BijectiveVectors
bool sameBijectiveComposition(const std::pair< std::vector< int >, GAVector< TSpace >> &b1, const std::pair< std::vector< int >, GAVector< TSpace >> &b2) const
predicate to compare two composition of bijective reflections
std::vector< Reflection< TSpace > > getGAVectorFromIndex(const std::vector< int > &indices) const
getter function used in predicate
std::vector< std::pair< std::vector< int >, GAVector< TSpace > > > composeBijectiveReflections(std::vector< std::pair< std::vector< int >, GAVector< TSpace >>> &Avector)
compose bijective digitized reflections
std::vector< std::pair< std::vector< GAVector< TSpace > >, GAVector< TSpace > > > vecBijNormals_index_2_GAVector(const std::vector< std::pair< std::vector< int >, GAVector< TSpace >>> &vecBijNormalsIndex)
void getKNearestBijectiveComposition(std::vector< std::pair< std::vector< GAVector< TSpace >>, GAVector< TSpace >>> &vecBijNormals, typename std::vector< std::pair< std::vector< GAVector< TSpace >>, GAVector< TSpace >>>::iterator &lowerBound, typename std::vector< std::pair< std::vector< GAVector< TSpace >>, GAVector< TSpace >>>::iterator &upperBound, const int K, const double targetAngle)
unsigned int index(DGtal::uint32_t n, unsigned int b)
PointVector< 3, double > RealPoint