DGtal  1.5.beta
DGtal::OTC< TSpace, TInputValue, TOutputValue > Struct Template Reference

OTC : Optimal Transport through Circle bijective rotation. More...

#include <DGtal/images/bijectiveRotations/OTC.h>

Public Member Functions

 OTC (const std::vector< std::vector< int > > &table, int dr, TOutputValue c, int W, int H)
 
TOutputValue center () const
 
void set_angle (double alpha)
 
int outSize () const
 
TOutputValue rotatePoint (TInputValue p) const
 
TOutputValue operator() (const TInputValue &aInput) const
 
void rotateInput ()
 
template<typename TImage >
TImage rotateImage (const TImage &img) const
 
std::string tostring () const
 

Data Fields

const std::vector< std::vector< int > > & _table
 
int _dr
 
TOutputValue my_center
 
int max_radius
 
RBC_vec< TSpace, TInputValue, TOutputValue > rbc
 
int angle
 
int _W
 
int _H
 
int _outS
 
std::vector< int > _offset
 

Detailed Description

template<typename TSpace, typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
struct DGtal::OTC< TSpace, TInputValue, TOutputValue >

OTC : Optimal Transport through Circle bijective rotation.

Description of template struct OTC

Template Parameters
TSpacea 2 dimensional space.
TInputValuetype of the input point e.g., TSpace::RealPoint.
TOutputValuetype of the output point e.g., TSpace::Point

Definition at line 52 of file OTC.h.

Constructor & Destructor Documentation

◆ OTC()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
DGtal::OTC< TSpace, TInputValue, TOutputValue >::OTC ( const std::vector< std::vector< int > > &  table,
int  dr,
TOutputValue  c,
int  W,
int  H 
)
inline

OTC Constructor.

Parameters
tableprecomputed table thanks to the OT implementation
drwidth of each ring (OTC-2, OTC3)
ccenter of rotation
W,Hsize of the image

Definition at line 71 of file OTC.h.

74  : _table( table ), rbc( 0 )
75  {
76  _W = W;
77  _H = H;
78  _dr = dr;
79  TOutputValue corner00( 0, 0 );
80  TOutputValue cornerW0( W-1, 0 );
81  TOutputValue corner0H( 0, H-1 );
82  TOutputValue cornerWH( W-1, H-1 );
83  int max_radius = int( ceil( sqrt( distance2( c, corner00 ) ) ) );
84 
85  max_radius = std::max( max_radius, int( ceil( sqrt( distance2( c, cornerW0 ) ) ) ) );
86  max_radius = std::max( max_radius, int( ceil( sqrt( distance2( c, corner0H ) ) ) ) );
87  max_radius = std::max( max_radius, int( ceil( sqrt( distance2( c, cornerWH ) ) ) ) );
88  rbc.init( max_radius, false );
89  my_center = c;
90  rbc.center() = c;
91  _outS = 2*max_radius+1;
92 
93  // Precompute offset table
94  _offset.resize( max_radius );
95  int n = 0;
96  for ( auto r = 0; r < max_radius; r++ )
97  {
98  _offset[ r ] = n;
99  n += rbc.circle( r ).size();
100  }
101  }
TPointType::Coordinate distance2(TPointType p, TPointType q)
Definition: PointUtils.h:92
int _dr
Definition: OTC.h:54
int _outS
Definition: OTC.h:61
int _H
Definition: OTC.h:60
RBC_vec< TSpace, TInputValue, TOutputValue > rbc
Definition: OTC.h:57
int max_radius
Definition: OTC.h:56
TOutputValue my_center
Definition: OTC.h:55
int _W
Definition: OTC.h:59
std::vector< int > _offset
Definition: OTC.h:62
const std::vector< std::vector< int > > & _table
Definition: OTC.h:53
int max(int a, int b)

References DGtal::OTC< TSpace, TInputValue, TOutputValue >::_dr, DGtal::OTC< TSpace, TInputValue, TOutputValue >::_H, DGtal::OTC< TSpace, TInputValue, TOutputValue >::_offset, DGtal::OTC< TSpace, TInputValue, TOutputValue >::_outS, DGtal::OTC< TSpace, TInputValue, TOutputValue >::_W, DGtal::distance2(), DGtal::H, max(), DGtal::OTC< TSpace, TInputValue, TOutputValue >::max_radius, DGtal::OTC< TSpace, TInputValue, TOutputValue >::my_center, and DGtal::OTC< TSpace, TInputValue, TOutputValue >::rbc.

Member Function Documentation

◆ center()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
TOutputValue DGtal::OTC< TSpace, TInputValue, TOutputValue >::center ( ) const
inline
Returns
the centre of rotation

Definition at line 105 of file OTC.h.

105 {return my_center;}

References DGtal::OTC< TSpace, TInputValue, TOutputValue >::my_center.

◆ operator()()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
TOutputValue DGtal::OTC< TSpace, TInputValue, TOutputValue >::operator() ( const TInputValue &  aInput) const
inline

Definition at line 161 of file OTC.h.

162  {
163  return this->rotatePoint(aInput);
164  }
TOutputValue rotatePoint(TInputValue p) const
Definition: OTC.h:117

References DGtal::OTC< TSpace, TInputValue, TOutputValue >::rotatePoint().

◆ outSize()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
int DGtal::OTC< TSpace, TInputValue, TOutputValue >::outSize ( ) const
inline

◆ rotateImage()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
template<typename TImage >
TImage DGtal::OTC< TSpace, TInputValue, TOutputValue >::rotateImage ( const TImage &  img) const
inline

Definition at line 176 of file OTC.h.

177  {
178  typedef typename TImage::Domain TDomain;
180  typedef std::pair < typename TSpace::Point, typename TSpace::Point > Bounds;
181  typename TSpace::Point bottomLeft(-1,-1);
182  typename TSpace::Point topRight(1,1);
183 
184 
185 
186  MyDomainTransformer domainTransformer ( *this );
187  Bounds bounds = domainTransformer ( img.domain() );
188  TDomain transformedDomain ( bounds.first+bottomLeft, bounds.second+topRight );
189  TImage rotatedImage ( transformedDomain );
190 
191  for (typename TDomain::ConstIterator it = img.domain().begin(); it != img.domain().end(); ++it ) {
192  rotatedImage.setValue((*this).operator()(*it),img(*it));
193  }
194  return rotatedImage;
195 
196 
197 
198  return img;
199  }
Aim: implements bounds of transformed domain.
MyDigitalSurface::ConstIterator ConstIterator
MyPointD Point
Definition: testClone2.cpp:383
HyperRectDomain< Space > Domain

◆ rotateInput()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
void DGtal::OTC< TSpace, TInputValue, TOutputValue >::rotateInput ( )
inline

Definition at line 166 of file OTC.h.

167  {
168  for ( int y = 0; y < _H; y++ )
169  for ( int x = 0; x < _W; x++ )
170  {
171  rotatePoint( TOutputValue( x, y ) );
172  }
173  }

References DGtal::OTC< TSpace, TInputValue, TOutputValue >::_H, DGtal::OTC< TSpace, TInputValue, TOutputValue >::_W, and DGtal::OTC< TSpace, TInputValue, TOutputValue >::rotatePoint().

◆ rotatePoint()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
TOutputValue DGtal::OTC< TSpace, TInputValue, TOutputValue >::rotatePoint ( TInputValue  p) const
inline

Definition at line 117 of file OTC.h.

118  {
119 
120  // We must find the correct ring.
121  auto pc0 = static_cast<TOutputValue>(p - my_center);
122 
123  //std::cout <<"pc0="<<pc0<<std::endl;
124  //TOutputValue pc( pc0[ 0 ], -pc0[ 1 ] );// sb comment
125  TOutputValue pc( pc0[ 0 ], pc0[ 1 ] );
126  //std::cout <<"pc="<<pc<<std::endl;
127  // Table is for angles in [0°,90°], rotate input points to take
128  // care of higher angles.
129  TOutputValue rpc = ( angle < 90 ) ? pc
130  : ( angle < 180 ) ? TOutputValue( -pc[ 1 ], pc[ 0 ] )
131  : ( angle < 270 ) ? TOutputValue( -pc[ 0 ], -pc[ 1 ] )
132  : TOutputValue( pc[ 1 ], -pc[ 0 ] );
133 
134  auto it = rbc.point2circle.find( rpc );
135  if ( it == rbc.point2circle.end() ) return static_cast<TOutputValue>(p);
136  int in_r = it->second[ 0 ];
137  int in_i = it->second[ 1 ];
138 
139 
140 
141  int in_ring = in_r <= 0 ? 0 : 1 + ( (in_r - 1) / _dr ) * _dr;
142  int in_ri = in_i;
143  int offset = _offset[ in_ring ];
144  for ( auto k = in_ring; k < in_r; k++ ) in_ri += rbc.circle( k ).size();
145  const auto& I = _table[ angle % 90 ];
146  int out_ri = I[ offset + in_ri ];
147  auto out_r = in_ring;
148  int out_i = out_ri;
149  while ( out_i >= rbc.circle( out_r ).size() )
150  {
151  out_i -= rbc.circle( out_r ).size();
152  out_r += 1;
153  }
154  TOutputValue q = rbc.circle( out_r )[ out_i ];
155  TOutputValue r = TOutputValue( q[ 0 ] + outSize()/2, -q[ 1 ] + outSize()/2 );
156  //unsigned char* pInput = &input[ 0 ] + 3*( p[ 1 ] * _W + p[ 0 ] );
157  return TOutputValue( q[ 0 ] + my_center[0] , q[ 1 ] + my_center[1]);
158 
159  }
int outSize() const
Definition: OTC.h:115

References DGtal::OTC< TSpace, TInputValue, TOutputValue >::_dr, DGtal::OTC< TSpace, TInputValue, TOutputValue >::_offset, DGtal::OTC< TSpace, TInputValue, TOutputValue >::_table, DGtal::OTC< TSpace, TInputValue, TOutputValue >::my_center, DGtal::OTC< TSpace, TInputValue, TOutputValue >::outSize(), and DGtal::OTC< TSpace, TInputValue, TOutputValue >::rbc.

Referenced by DGtal::OTC< TSpace, TInputValue, TOutputValue >::operator()(), and DGtal::OTC< TSpace, TInputValue, TOutputValue >::rotateInput().

◆ set_angle()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
void DGtal::OTC< TSpace, TInputValue, TOutputValue >::set_angle ( double  alpha)
inline

Definition at line 108 of file OTC.h.

109  {
110  angle = std::round((alpha*180.0)/M_PI);
111  rbc.setAngle() = alpha;
112  std::cout <<"OTC angle="<<rbc.angle()<<std::endl;
113  }

References DGtal::OTC< TSpace, TInputValue, TOutputValue >::rbc.

◆ tostring()

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
std::string DGtal::OTC< TSpace, TInputValue, TOutputValue >::tostring ( ) const
inline

Definition at line 201 of file OTC.h.

201  {
202  return {"OTC"};
203  }

Field Documentation

◆ _dr

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
int DGtal::OTC< TSpace, TInputValue, TOutputValue >::_dr

◆ _H

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
int DGtal::OTC< TSpace, TInputValue, TOutputValue >::_H

◆ _offset

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
std::vector< int > DGtal::OTC< TSpace, TInputValue, TOutputValue >::_offset

◆ _outS

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
int DGtal::OTC< TSpace, TInputValue, TOutputValue >::_outS

◆ _table

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
const std::vector< std::vector< int > >& DGtal::OTC< TSpace, TInputValue, TOutputValue >::_table

Definition at line 53 of file OTC.h.

Referenced by DGtal::OTC< TSpace, TInputValue, TOutputValue >::rotatePoint().

◆ _W

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
int DGtal::OTC< TSpace, TInputValue, TOutputValue >::_W

◆ angle

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
int DGtal::OTC< TSpace, TInputValue, TOutputValue >::angle

Definition at line 58 of file OTC.h.

◆ max_radius

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
int DGtal::OTC< TSpace, TInputValue, TOutputValue >::max_radius

Definition at line 56 of file OTC.h.

Referenced by DGtal::OTC< TSpace, TInputValue, TOutputValue >::OTC().

◆ my_center

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
TOutputValue DGtal::OTC< TSpace, TInputValue, TOutputValue >::my_center

◆ rbc

template<typename TSpace , typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point>
RBC_vec<TSpace,TInputValue,TOutputValue> DGtal::OTC< TSpace, TInputValue, TOutputValue >::rbc

The documentation for this struct was generated from the following file: