DGtal  1.5.beta
testBijectiveRotation.cpp
Go to the documentation of this file.
1 
31 #include <cstdio>
32 #include <cmath>
33 #include <iostream>
34 
35 #include <iostream>
36 #include <cmath>
37 #include "DGtal/images/ImageSelector.h"
38 #include "DGtal/images/ImageContainerBySTLVector.h"
39 #include "DGtal/images/ConstImageAdapter.h"
40 #include "DGtal/helpers/StdDefs.h"
41 #include "DGtal/base/Common.h"
42 #include "DGtal/io/readers/PGMReader.h"
43 #include "DGtal/io/writers/GenericWriter.h"
45 #include "DGtal/images/RigidTransformation2D.h"
49 #include "DGtal/images/bijectiverotations/QSH.h"
50 #include "DGtal/images/bijectiverotations/CDLR.h"
51 #include "DGtal/images/bijectiverotations/RBC.h"
52 #include "DGtal/images/bijectiverotations/OTC.h"
53 #include "DGtal/images/bijectiverotations/CBDR.h"
54 #include "DGtal/images/bijectiverotations/Rotationtables.h"
55 
56 
57 using namespace std;
58 using namespace DGtal;
59 using namespace functors;
60 using namespace Z2i;
61 
62 std::vector<std::string> supportedBijectiveRotation = {
63  "OTC", "CBDR", "CDLR", "QSH" , "RBC"
64 };
65 
66 
67 template <typename TBijectiveRotation>
68 bool testBijectiveRotations(TBijectiveRotation& bijectiveRot) {
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 }
98 
100 bool testCDLRPolicy(const Point& c, const double angle) {
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 }
128 
130 bool testCBDRPolicy(const Point& c, const double angle) {
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 }
159 
160 
161 int main() {
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
Iterator for HyperRectDomain.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
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
double & setAngle()
Definition: RBC_vec.h:142
TOutputValue center() const
Definition: RBC_vec.h:146
RBC : Bijective Rotation through Circles.
Definition: RBC.h:55
int max(int a, int b)
std::vector< std::string > supportedBijectiveRotation
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)
int main()
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