DGtal  1.5.beta
testBijectiveRotation.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ConstImageAdapter.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/PGMReader.h"
#include "DGtal/io/writers/GenericWriter.h"
#include "DGtal/images/RigidTransformation2D.h"
#include "DGtal/images/bijectiverotations/QSH.h"
#include "DGtal/images/bijectiverotations/CDLR.h"
#include "DGtal/images/bijectiverotations/RBC.h"
#include "DGtal/images/bijectiverotations/OTC.h"
#include "DGtal/images/bijectiverotations/CBDR.h"
#include "DGtal/images/bijectiverotations/Rotationtables.h"
Include dependency graph for testBijectiveRotation.cpp:

Go to the source code of this file.

Functions

template<typename TBijectiveRotation >
bool testBijectiveRotations (TBijectiveRotation &bijectiveRot)
 
bool testCDLRPolicy (const Point &c, const double angle)
 check that RDSL with a Linf error results in the same domain as RDSL with a mix of 1*Linf and 0*Lcontinuity More...
 
bool testCBDRPolicy (const Point &c, const double angle)
 check that CBDR with a Linf error results in the same domain as RDSL with a mix of 1*Linf and 0*Lcontinuity More...
 
int main ()
 

Variables

std::vector< std::string > supportedBijectiveRotation
 

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
Stephane Breuils, David Coeurjolly, Jacques-Olivier Lachaud
Date
2024/08

This file is part of the DGtal library

Definition in file testBijectiveRotation.cpp.

Function Documentation

◆ main()

int main ( void  )

[def]

init

QSH

Linf DSL

Linf CBDR

RBC

OTC

Definition at line 161 of file testBijectiveRotation.cpp.

161  {
164  typedef ForwardRigidTransformation2D < Space > ForwardTrans;
165  typedef DomainRigidTransformation2D < Domain, ForwardTrans > MyDomainTransformer;
166  typedef MyDomainTransformer::Bounds Bounds;
167 
169  double angle = M_PI_4;
170  Point c = {100,100};
171  const int W=200; const int H=200;
172  trace.beginBlock ( "Testing bijective rotations" );
173 
176 
178  auto linf = std::make_shared<DGtal::LinfPolicy<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::HyperRectDomain< DGtal::SpaceND< 2, DGtal::int32_t >>,DGtal::CDLR_naiverotation<DGtal::SpaceND< 2, DGtal::int32_t >>>>();
179  DGtal::CDLR<DGtal::SpaceND<2, DGtal::int32_t> > rot_RDSL(angle, c, linf);
180 
182  auto linfCBDR = std::make_shared<DGtal::LinfPolicy<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::HyperRectDomain< DGtal::SpaceND< 2, DGtal::int32_t >>,DGtal::CBDR_naiverotation<DGtal::SpaceND< 2, DGtal::int32_t >>>>();
183  const int n = 3;const int kmax=15;
185 
188  rot_rbcvec.setAngle() = angle;
189  rot_rbcvec.center() = c;
191 
193  int rwidth = 2;
194  std::vector< std::vector< int > > tableOTC = DGtal::functions::loadOTCTable<DGtal::SpaceND< 2, DGtal::int32_t >>("../tables/",rwidth);
195  DGtal::OTC<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::Z2i::RealPoint> rot_OTC( tableOTC, rwidth, c, W, H );
196 
197 
198  bool res = testBijectiveRotations<OTC<DGtal::SpaceND< 2, DGtal::int32_t >>>(rot_OTC) &&
200  testBijectiveRotations<CBDR<DGtal::SpaceND< 2, DGtal::int32_t >>>(rot_CBDR) &&
202  testBijectiveRotations<QSH<DGtal::SpaceND< 2, DGtal::int32_t >>>(rot_QSH);
203 
204 
205  // equal domain
206  res = res&& testCDLRPolicy({100,100}, M_PI_4);
207  res = res && testCBDRPolicy({100,100}, M_PI_4);
208 
209  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
210  trace.endBlock();
211 
212 
213  return 0;
214 }
CDLR : Rotation with Discrete Line Reflections,.
Definition: CDLR.h:53
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Trace trace
Definition: Common.h:153
vec since the parameters are the vectors of digitized reflections
CBDR : Composition of Bijective Digitized Reflections,.
Definition: CBDR.h:57
Aim: Automatically defines an adequate image type according to the hints given by the user.
Definition: ImageSelector.h:70
OTC : Optimal Transport through Circle bijective rotation.
Definition: OTC.h:52
QSH : Quasi Shears represents a bijective rotation through shears.
Definition: QSH.h:50
RBC : Bijective Rotation through Circles.
Definition: RBC_vec.h:56
RBC : Bijective Rotation through Circles.
Definition: RBC.h:55
int max(int a, int b)
bool testCBDRPolicy(const Point &c, const double angle)
check that CBDR with a Linf error results in the same domain as RDSL with a mix of 1*Linf and 0*Lcont...
bool testBijectiveRotations(TBijectiveRotation &bijectiveRot)
bool testCDLRPolicy(const Point &c, const double angle)
check that RDSL with a Linf error results in the same domain as RDSL with a mix of 1*Linf and 0*Lcont...
double angle(const DGtal::Z2i::RealPoint &point)
ImageContainerBySTLVector< Domain, Value > Image

References angle(), DGtal::Trace::beginBlock(), DGtal::RBC_vec< TSpace, TInputValue, TOutputValue >::center(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::H, max(), DGtal::RBC_vec< TSpace, TInputValue, TOutputValue >::setAngle(), testBijectiveRotations(), testCBDRPolicy(), testCDLRPolicy(), and DGtal::trace.

◆ testBijectiveRotations()

template<typename TBijectiveRotation >
bool testBijectiveRotations ( TBijectiveRotation &  bijectiveRot)

Definition at line 68 of file testBijectiveRotation.cpp.

68  {
71 
72  typedef ForwardRigidTransformation2D < Space > ForwardTrans;
73  typedef DomainRigidTransformation2D < Domain, ForwardTrans > MyDomainTransformer;
74  typedef MyDomainTransformer::Bounds Bounds;
75 
76  Point A(0,0);
77  Point B(200,200);
78  HyperRectDomain<Space> my_domain(A,B);
79 
80  GrayImage imgGray( my_domain );
81  ColorImage imgColor( my_domain );
82 
83  std::string structName = bijectiveRot.tostring();
84 
85  if (std::find(supportedBijectiveRotation.begin(), supportedBijectiveRotation.end(), structName) != supportedBijectiveRotation.end()) {
86  trace.beginBlock ( "Bijective Rotation : "+ structName);
87  trace.info() << bijectiveRot.tostring() << std::endl;
88 
89  auto rotatedImgGray = bijectiveRot.rotateImage(imgGray);
90  auto rotatedImgColor = bijectiveRot.rotateImage(imgColor);
91  trace.endBlock ();
92  } else {
93  return false;
94  }
95 
96  return true;
97 }
std::ostream & info()
std::vector< std::string > supportedBijectiveRotation

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), supportedBijectiveRotation, and DGtal::trace.

Referenced by main().

◆ testCBDRPolicy()

bool testCBDRPolicy ( const Point c,
const double  angle 
)

check that CBDR with a Linf error results in the same domain as RDSL with a mix of 1*Linf and 0*Lcontinuity

Definition at line 130 of file testBijectiveRotation.cpp.

130  {
133 
134  typedef ForwardRigidTransformation2D < Space > ForwardTrans;
135  typedef DomainRigidTransformation2D < Domain, ForwardTrans > MyDomainTransformer;
136  typedef MyDomainTransformer::Bounds Bounds;
137  int kmax = 10; int n = 2;
138 
139 
140  auto linf = std::make_shared<DGtal::LinfPolicy<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::HyperRectDomain< DGtal::SpaceND< 2, DGtal::int32_t >>,DGtal::CBDR_naiverotation<DGtal::SpaceND< 2, DGtal::int32_t >>>>();
141  auto linfWithMix = std::make_shared<DGtal::MixedPolicy<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::HyperRectDomain< DGtal::SpaceND< 2, DGtal::int32_t >>,DGtal::CBDR_naiverotation<DGtal::SpaceND< 2, DGtal::int32_t >>>>(1.0,0.0);
143  DGtal::CBDR<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::Z2i::RealPoint> rotCBDRLinf_withMix(angle, c,n,kmax, linfWithMix);
144 
145  Point A(0,0);
146  Point B(200,200);
147  HyperRectDomain<Space> my_domain(A,B);
148  GrayImage imgGray( my_domain );
149 
150  bool isSameTransformedDomain = true;
151  for (typename Domain::ConstIterator it = imgGray.domain().begin(); it != imgGray.domain().end(); ++it )
152  {
153  Point cbdrLinf = rotCBDRLinf(*it);
154  Point cbdrLinf_withMix = rotCBDRLinf_withMix(*it);
155  isSameTransformedDomain *= (cbdrLinf_withMix==cbdrLinf);
156  }
157  return isSameTransformedDomain;
158 }
Iterator for HyperRectDomain.

Referenced by main().

◆ testCDLRPolicy()

bool testCDLRPolicy ( const Point c,
const double  angle 
)

check that RDSL with a Linf error results in the same domain as RDSL with a mix of 1*Linf and 0*Lcontinuity

Definition at line 100 of file testBijectiveRotation.cpp.

100  {
103 
104  typedef ForwardRigidTransformation2D < Space > ForwardTrans;
105  typedef DomainRigidTransformation2D < Domain, ForwardTrans > MyDomainTransformer;
106  typedef MyDomainTransformer::Bounds Bounds;
107 
108 
109  auto linf = std::make_shared<DGtal::LinfPolicy<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::HyperRectDomain< DGtal::SpaceND< 2, DGtal::int32_t >>,DGtal::CDLR_naiverotation<DGtal::SpaceND< 2, DGtal::int32_t >>>>();
110  auto linfWithMix = std::make_shared<DGtal::MixedPolicy<DGtal::SpaceND< 2, DGtal::int32_t >,DGtal::HyperRectDomain< DGtal::SpaceND< 2, DGtal::int32_t >>,DGtal::CDLR_naiverotation<DGtal::SpaceND< 2, DGtal::int32_t >>>>(0.0,1.0);
111  DGtal::CDLR<DGtal::SpaceND<2, DGtal::int32_t> > rotCDLRLinf(angle, c, linf);
112  DGtal::CDLR<DGtal::SpaceND<2, DGtal::int32_t> > rotCDLRLinf_withMix(angle, c, linfWithMix);
113 
114  Point A(0,0);
115  Point B(200,200);
116  HyperRectDomain<Space> my_domain(A,B);
117  GrayImage imgGray( my_domain );
118 
119  bool isSameTransformedDomain = true;
120  for (typename Domain::ConstIterator it = imgGray.domain().begin(); it != imgGray.domain().end(); ++it )
121  {
122  Point cdlrLinf = rotCDLRLinf(*it);
123  Point cdlrLinf_withMix = rotCDLRLinf_withMix(*it);
124  isSameTransformedDomain *= (cdlrLinf_withMix==cdlrLinf);
125  }
126  return isSameTransformedDomain;
127 }

Referenced by main().

Variable Documentation

◆ supportedBijectiveRotation

std::vector<std::string> supportedBijectiveRotation
Initial value:
= {
"OTC", "CBDR", "CDLR", "QSH" , "RBC"
}

Definition at line 62 of file testBijectiveRotation.cpp.

Referenced by testBijectiveRotations().