CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
Cordic Class Reference

#include <Cordic.h>

Public Member Functions

 Cordic (const uint32_t &aPhiScale, const uint32_t &aMagnitudeBits, const uint32_t &aSteps)
 
int32_t IntegerizeMagnitude (const double &aMagnitude)
 
double NormalizeMagnitude (const uint32_t &aMagnitude)
 
double NormalizePhi (const uint32_t &aPhi)
 
void operator() (int32_t aX, int32_t aY, int32_t &aPhi, uint32_t &aMagnitude)
 
virtual ~Cordic ()
 

Private Member Functions

uint32_t tower (const double &aRadians)
 

Private Attributes

uint32_t mMagnitudeBits
 
uint32_t mMagnitudeRenormalization
 
uint32_t mMagnitudeScale
 
uint32_t mPhiScale
 
const double mPi
 
std::vector< uint32_t > mRotations
 
uint32_t mSteps
 

Detailed Description

Definition at line 7 of file Cordic.h.

Constructor & Destructor Documentation

Cordic::Cordic ( const uint32_t &  aPhiScale,
const uint32_t &  aMagnitudeBits,
const uint32_t &  aSteps 
)

Definition at line 9 of file Cordic.cc.

References mMagnitudeRenormalization, mMagnitudeScale, mRotations, mSteps, funct::pow(), mathSSE::sqrt(), and tower().

9  : mPhiScale( aPhiScale ) , mMagnitudeScale( 1 << aMagnitudeBits ) , mMagnitudeBits( aMagnitudeBits ) , mSteps( aSteps ) , mPi( 3.1415926535897932384626433832795 )
10 {
11  mRotations.reserve( mSteps );
12 
13  double lValue( 1.0 );
14 
15  for( uint32_t lStep( 0 ); lStep!=mSteps ; ++lStep ){
16  lValue /= sqrt( 1.0 + pow( 4.0 , -double(lStep) ) );
17  mRotations.push_back( tower( atan( pow( 2.0 , -double(lStep) ) ) ) );
18  }
19  mMagnitudeRenormalization = uint32_t( round( mMagnitudeScale * lValue ) );
20 }
uint32_t mMagnitudeBits
Definition: Cordic.h:25
uint32_t mPhiScale
Definition: Cordic.h:23
T sqrt(T t)
Definition: SSEVec.h:48
const double mPi
Definition: Cordic.h:30
uint32_t mSteps
Definition: Cordic.h:26
uint32_t tower(const double &aRadians)
Definition: Cordic.cc:39
uint32_t mMagnitudeScale
Definition: Cordic.h:24
std::vector< uint32_t > mRotations
Definition: Cordic.h:28
uint32_t mMagnitudeRenormalization
Definition: Cordic.h:27
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Cordic::~Cordic ( )
virtual

Definition at line 22 of file Cordic.cc.

22 {}

Member Function Documentation

int32_t Cordic::IntegerizeMagnitude ( const double &  aMagnitude)

Definition at line 34 of file Cordic.cc.

References mMagnitudeScale.

35 {
36  return int32_t( aMagnitude * mMagnitudeScale );
37 }
uint32_t mMagnitudeScale
Definition: Cordic.h:24
double Cordic::NormalizeMagnitude ( const uint32_t &  aMagnitude)

Definition at line 29 of file Cordic.cc.

References mMagnitudeScale.

30 {
31  return double( aMagnitude ) / double( mMagnitudeScale );
32 }
uint32_t mMagnitudeScale
Definition: Cordic.h:24
double Cordic::NormalizePhi ( const uint32_t &  aPhi)

Definition at line 24 of file Cordic.cc.

References mPhiScale.

25 {
26  return double( aPhi ) / double( mPhiScale );
27 }
uint32_t mPhiScale
Definition: Cordic.h:23
void Cordic::operator() ( int32_t  aX,
int32_t  aY,
int32_t &  aPhi,
uint32_t &  aMagnitude 
)

Definition at line 44 of file Cordic.cc.

References mMagnitudeBits, mMagnitudeRenormalization, mPi, mRotations, mSteps, and tower().

45 {
46  bool lSign(true);
47 
48  switch( ((aY>=0)?0x0:0x2) | ((aX>=0)?0x0:0x1) ){
49  case 0:
50  aPhi = 0;
51  break;
52  case 1:
53  aPhi = tower( mPi );
54  lSign = false;
55  aX = -aX;
56  break;
57  case 2:
58  aPhi = tower( 2 * mPi );
59  lSign = false;
60  aY = -aY;
61  break;
62  case 3:
63  aPhi = tower( mPi );
64  aX = -aX;
65  aY = -aY;
66  break;
67  default:
68  throw 0;
69  }
70 
71  for( uint32_t lStep( 0 ); lStep!=mSteps ; ++lStep ){
72  if ( (aY < 0) == lSign ){
73  aPhi -= mRotations[ lStep ];
74  }else{
75  aPhi += mRotations[ lStep ];
76  }
77 
78  int32_t lX(aX), lY(aY);
79  if( lY < 0 ){
80  aX = lX - (lY >> lStep);
81  aY = lY + (lX >> lStep);
82  }else{
83  aX = lX + (lY >> lStep);
84  aY = lY - (lX >> lStep);
85  }
86  }
87 
88  aMagnitude = (aX * mMagnitudeRenormalization) >> mMagnitudeBits;
89 }
uint32_t mMagnitudeBits
Definition: Cordic.h:25
const double mPi
Definition: Cordic.h:30
uint32_t mSteps
Definition: Cordic.h:26
uint32_t tower(const double &aRadians)
Definition: Cordic.cc:39
std::vector< uint32_t > mRotations
Definition: Cordic.h:28
uint32_t mMagnitudeRenormalization
Definition: Cordic.h:27
uint32_t Cordic::tower ( const double &  aRadians)
private

Definition at line 39 of file Cordic.cc.

References mPhiScale, and mPi.

Referenced by Cordic(), and operator()().

40 {
41  return uint32_t( round( mPhiScale * 36.0 * aRadians / mPi ) );
42 }
uint32_t mPhiScale
Definition: Cordic.h:23
const double mPi
Definition: Cordic.h:30

Member Data Documentation

uint32_t Cordic::mMagnitudeBits
private

Definition at line 25 of file Cordic.h.

Referenced by operator()().

uint32_t Cordic::mMagnitudeRenormalization
private

Definition at line 27 of file Cordic.h.

Referenced by Cordic(), and operator()().

uint32_t Cordic::mMagnitudeScale
private

Definition at line 24 of file Cordic.h.

Referenced by Cordic(), IntegerizeMagnitude(), and NormalizeMagnitude().

uint32_t Cordic::mPhiScale
private

Definition at line 23 of file Cordic.h.

Referenced by NormalizePhi(), and tower().

const double Cordic::mPi
private

Definition at line 30 of file Cordic.h.

Referenced by operator()(), and tower().

std::vector<uint32_t> Cordic::mRotations
private

Definition at line 28 of file Cordic.h.

Referenced by Cordic(), and operator()().

uint32_t Cordic::mSteps
private

Definition at line 26 of file Cordic.h.

Referenced by Cordic(), and operator()().