Skip to content
Snippets Groups Projects
Commit 73baf218 authored by Julien Malik's avatar Julien Malik
Browse files

COMP: use OTB constants instead of M_PI

parent 19348943
No related branches found
No related tags found
No related merge requests found
......@@ -89,7 +89,7 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
std::vector<TOutputPrecision> globalOrientationHistogram(m_NumberOfOrientationBins, 0.);
// Compute the orientation bin width
double orientationBinWidth = 2 * M_PI / m_NumberOfOrientationBins;
double orientationBinWidth = otb::CONST_2PI / m_NumberOfOrientationBins;
// Build the global orientation histogram
for(int i = -(int)m_NeighborhoodRadius; i< (int)m_NeighborhoodRadius; ++i)
......@@ -102,7 +102,7 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
{
// If so, compute the gaussian weighting (this could be
// computed once for all for the sake of optimisation)
double gWeight = (1/vcl_sqrt(2*M_PI*squaredSigma)) * vcl_exp(- currentSquaredRadius/(2*squaredSigma));
double gWeight = (1/vcl_sqrt(otb::CONST_2PI*squaredSigma)) * vcl_exp(- currentSquaredRadius/(2*squaredSigma));
// Compute pixel location
offset[0]=i;
......@@ -117,9 +117,9 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
// Also compute its magnitude
TOutputPrecision magnitude = vcl_sqrt(gradient[0]*gradient[0]+gradient[1]*gradient[1]);
// Determine the bin index (shift of M_PI since atan2 values
// Determine the bin index (shift of otb::CONST_PI since atan2 values
// lies in [-pi, pi]
unsigned int binIndex = vcl_floor((M_PI + angle)/orientationBinWidth);
unsigned int binIndex = vcl_floor((otb::CONST_PI + angle)/orientationBinWidth);
// Cumulate values
globalOrientationHistogram[binIndex]+= magnitude * gWeight;
......@@ -146,7 +146,7 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
}
// Derive principal orientation
double principalOrientation = maxOrientationHistogramBin * orientationBinWidth - M_PI;
double principalOrientation = maxOrientationHistogramBin * orientationBinWidth - otb::CONST_PI;
// Initialize the five spatial bins
std::vector<TOutputPrecision> centerHistogram(m_NumberOfOrientationBins, 0.);
......@@ -166,7 +166,7 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
{
// If so, compute the gaussian weighting (this could be
// computed once for all for the sake of optimisation)
double gWeight = (1/vcl_sqrt(2*M_PI*squaredSigma)) * vcl_exp(- currentSquaredRadius/(2*squaredSigma));
double gWeight = (1/vcl_sqrt(otb::CONST_2PI * squaredSigma)) * vcl_exp(- currentSquaredRadius/(2*squaredSigma));
// Compute pixel location
offset[0]=i;
......@@ -180,34 +180,34 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
// Angle is supposed to lie with [-pi, pi], so we ensure that
// compenstation did not introduce out-of-range values
if(angle > M_PI)
if(angle > otb::CONST_PI)
{
angle -= 2*M_PI;
angle -= otb::CONST_2PI;
}
else if(angle < -M_PI)
else if(angle < -otb::CONST_PI)
{
angle += 2*M_PI;
angle += otb::CONST_2PI;
}
// Also compute its magnitude
TOutputPrecision magnitude = vcl_sqrt(gradient[0]*gradient[0]+gradient[1]*gradient[1]);
// Determine the bin index (shift of M_PI since atan2 values
// Determine the bin index (shift of otb::CONST_PI since atan2 values
// lies in [-pi, pi]
unsigned int binIndex = vcl_floor((M_PI + angle)/orientationBinWidth);
unsigned int binIndex = vcl_floor((otb::CONST_PI + angle)/orientationBinWidth);
// Compute the angular position
double angularPosition = vcl_atan2((double)j, (double)i) - principalOrientation;
// Angle is supposed to lie within [-pi, pi], so we ensure that
// the compensation did not introduce out-of-range values
if(angularPosition > M_PI)
if(angularPosition > otb::CONST_PI)
{
angularPosition -= 2*M_PI;
angularPosition -= otb::CONST_2PI;
}
else if(angularPosition < -M_PI)
else if(angularPosition < -otb::CONST_PI)
{
angularPosition += 2*M_PI;
angularPosition += otb::CONST_2PI;
}
// Check if we lie in center bin
......@@ -217,7 +217,7 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
}
else if(angularPosition > 0)
{
if(angularPosition < M_PI/2)
if(angularPosition < otb::CONST_PI_2)
{
upperRightHistogram[binIndex]+= magnitude * gWeight;
}
......@@ -228,7 +228,7 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision,
}
else
{
if(angularPosition > -M_PI/2)
if(angularPosition > -otb::CONST_PI_2)
{
lowerRightHistogram[binIndex]+= magnitude * gWeight;
}
......
......@@ -112,7 +112,7 @@ LocalHistogramImageFunction<TInputImage, TCoordRep>
double gWeight = 1.;
if(m_GaussianSmoothing)
{
gWeight = (1/vcl_sqrt(2*M_PI*squaredSigma)) * vcl_exp(- currentSquaredRadius/(2*squaredSigma));
gWeight = (1/vcl_sqrt(otb::CONST_2PI*squaredSigma)) * vcl_exp(- currentSquaredRadius/(2*squaredSigma));
}
// Compute pixel location
......
......@@ -675,7 +675,7 @@ double ShapeAttributesLabelObjectFunctor<TLabelObject, TLabelImage>
}
else
{
return vcl_sqrt(M_PI) * doubleFactorial(n) / vcl_pow(2, (n + 1) / 2.0);
return otb::CONST_SQRTPI * doubleFactorial(n) / vcl_pow(2, (n + 1) / 2.0);
}
}
......@@ -684,7 +684,7 @@ template <class TLabelObject, class TLabelImage>
double ShapeAttributesLabelObjectFunctor<TLabelObject, TLabelImage>
::hyperSphereVolume(double radius)
{
return vcl_pow(M_PI, LabelObjectType::ImageDimension /
return vcl_pow(otb::CONST_PI, LabelObjectType::ImageDimension /
2.0) * vcl_pow(radius, LabelObjectType::ImageDimension) / gammaN2p1(LabelObjectType::ImageDimension);
}
......@@ -702,7 +702,7 @@ double ShapeAttributesLabelObjectFunctor<TLabelObject, TLabelImage>
::hyperSphereRadiusFromVolume(double volume)
{
return vcl_pow(volume * gammaN2p1(LabelObjectType::ImageDimension) /
vcl_pow(M_PI, LabelObjectType::ImageDimension / 2.0), 1.0 / LabelObjectType::ImageDimension);
vcl_pow(otb::CONST_PI, LabelObjectType::ImageDimension / 2.0), 1.0 / LabelObjectType::ImageDimension);
}
} // End namespace Functor
......
......@@ -285,7 +285,7 @@ TerraSarCalibrationImageFilter<TInputImage, TOutputImage>
}
// Set the offset to the mean angle
m_IncidenceAngleOffset /= m_IncidenceAngleRecords.size();
m_IncidenceAngleOffset *= M_PI / 180.;
m_IncidenceAngleOffset *= otb::CONST_PI_180;
return;
}
......@@ -300,7 +300,7 @@ TerraSarCalibrationImageFilter<TInputImage, TOutputImage>
a(i, 0) = m_IncidenceAngleRecords.at(i).first[0];
a(i, 1) = m_IncidenceAngleRecords.at(i).first[1];
a(i, 2) = 1.;
b[i] = m_IncidenceAngleRecords.at(i).second * M_PI / 180.;
b[i] = m_IncidenceAngleRecords.at(i).second * otb::CONST_PI_180;
}
// Create the linear system
......
......@@ -83,7 +83,7 @@ int main(int argc, char *argv[])
// mode is s (synthetic)
double test_scale = atof(argv[6]);
float test_rotate = atof(argv[7]) * M_PI * 2.0 / 360.0;
float test_rotate = atof(argv[7]) * otb::CONST_PI_180;
double test_crop = atof(argv[8]);
int rotate_middle = atoi(argv[9]);
int mode = 's';
......
......@@ -62,7 +62,7 @@ int itk2DScaleInvariantFeatureImageFilterTest( int argc, char *argv[])
// mode is s (synthetic)
double test_scale = atof(argv[6]);
float test_rotate = static_cast<float>(atof(argv[7])* otb::CONST_PI_180); //M_PI * 2.0 / 360.0;
float test_rotate = static_cast<float>(atof(argv[7])* otb::CONST_PI_180);
double test_crop = atof(argv[8]);
int rotate_middle= atoi(argv[9]);
int mode = 's';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment