28 #if defined(RBC_vec_RECURSES)
29 #error Recursive header files inclusion detected in RBC_vec.h
32 #define RBC_vec_RECURSES
34 #if !defined RBC_vec_h
39 #include "DGtal/base/Common.h"
40 #include "DGtal/kernel/BasicPointFunctors.h"
41 #include <DGtal/helpers/StdDefs.h>
42 #include "PointUtils.h"
43 #include <DGtal/kernel/CSpace.h>
44 #include <DGtal/io/readers/GenericReader.h>
45 #include <DGtal/images/ImageSelector.h>
55 template<
typename TSpace,
typename TInputValue =
typename TSpace::RealPo
int,
typename TOutputValue =
typename TSpace::Po
int>
57 typedef std::vector< TOutputValue >
Circle;
72 RBC_vec(
int max_radius,
bool smart =
false ) {
73 init( max_radius, smart );
85 void init(
int R,
bool smart ) {
86 TOutputValue c( 0, 0 );
92 std::vector< TOutputValue > points;
93 for (
int r = 1; r <= R; r++ )
96 for (
int i = 0; i <
circles[ r ].size(); i++, N++ )
99 points.push_back(
circles[ r ][ i ] );
102 if ( ! smart )
return;
103 struct DistanceComparator {
104 bool operator()( TOutputValue p, TOutputValue q )
const
106 return p.squaredNorm() < q.squaredNorm();
109 struct AngleComparator {
110 bool operator()( TOutputValue p, TOutputValue q )
const
112 double ap = atan2( p[ 1 ], p[ 0 ] );
113 double aq = atan2( q[ 1 ], q[ 0 ] );
121 double a = 2.0 * double( N - 1 ) / double(R*(R+1));
122 DistanceComparator dcomp;
123 AngleComparator acomp;
124 std::sort( points.begin(), points.end(), dcomp );
126 for (
int r = 1; r <= R; r++ )
128 int n = int( round( a * r / 8.0 ) * 8.0 );
130 for (
int i = 0; i < n; i++ )
131 circles[ r ][ i ] = points[ current++ ];
157 TOutputValue
rotate( TInputValue p )
const {
158 auto cp =
static_cast<TOutputValue
>((p -
my_center));
160 if ( it ==
point2circle.end() )
return static_cast<TOutputValue
>(p);
161 TOutputValue polar = it->second;
163 int idx = polar[ 1 ];
165 const int N = C.size();
166 int shift = int( round( -
my_angle * N / ( 2.0 * M_PI ) ) );
167 int jdx = ( N + idx - shift ) % N;
173 return this->
rotate(aInput);
192 int d2_up = (r+1)*(r+1);
193 TOutputValue start( r, 0 );
195 TOutputValue current = start;
197 circle.push_back( current );
198 auto V = nextNeighbors<TOutputValue>( current );
199 std::vector<TOutputValue> P;
201 int d2 = p.squaredNorm();
203 if ( d2_lo <= d2 && d2 < d2_up ) P.push_back( p );
205 if ( P.empty() ) std::cerr <<
"Error ! " << std::endl;
206 TOutputValue b = P[ 0 ];
207 for (
int i = 1; i < P.size(); i++ )
208 if ( less<TOutputValue>( P[ i ], b ) ) b = P[ i ];
210 }
while ( current != start );
227 #undef RBC_vec_RECURSES
DGtal is the top-level namespace which contains all DGtal functions and types.
RBC : Bijective Rotation through Circles.
double my_angle
The angle of rotation.
void init(int R, bool smart)
TOutputValue rotate(TInputValue p) const
TOutputValue operator()(const TInputValue &aInput) const
const Circle & circle(int r) const
std::vector< TOutputValue > Circle
RBC_vec(int max_radius, bool smart=false)
static Circle computeCircle(int r)
std::map< TOutputValue, TOutputValue > point2circle
TOutputValue center() const
TOutputValue my_center
The center of rotation.
std::vector< Circle > circles