From 691995400e1fb610e22bcf6326a92fe85cf3abcd Mon Sep 17 00:00:00 2001 From: Enguerrand DE SMET Date: Tue, 9 Jun 2020 15:18:54 +0200 Subject: [PATCH] [matching] build fix for MSVC 2019 Update src/aliceVision/matching/kvld/kvld.cpp Update src/aliceVision/matching/kvld/kvld.h Update src/aliceVision/matching/kvld/algorithm.cpp Update src/aliceVision/matching/kvld/algorithm.h Co-authored-by: Simone Gasparini --- src/aliceVision/matching/kvld/algorithm.cpp | 46 ++++++++++++++++++--- src/aliceVision/matching/kvld/algorithm.h | 31 +------------- src/aliceVision/matching/kvld/kvld.cpp | 20 ++++++--- src/aliceVision/matching/kvld/kvld.h | 10 +---- 4 files changed, 60 insertions(+), 47 deletions(-) diff --git a/src/aliceVision/matching/kvld/algorithm.cpp b/src/aliceVision/matching/kvld/algorithm.cpp index 9a5d95577d..231332c6ee 100644 --- a/src/aliceVision/matching/kvld/algorithm.cpp +++ b/src/aliceVision/matching/kvld/algorithm.cpp @@ -13,6 +13,8 @@ #include "algorithm.h" +#include + IntegralImages::IntegralImages(const aliceVision::image::Image< float >& I) { map.resize( I.Width() + 1, I.Height() + 1 ); @@ -26,12 +28,9 @@ IntegralImages::IntegralImages(const aliceVision::image::Image< float >& I) } } -float getRange( - const aliceVision::image::Image< float >& I, - int a, - const float p ) +float getRange( const aliceVision::image::Image< float >& I, int a, const float p ) { - float range = sqrt( float( 3.f * I.Height() * I.Width() ) / ( p * a * PI_ ) ); + float range = sqrt(float(3.f * I.Height() * I.Width()) / (p * a * boost::math::constants::pi())); return range; } @@ -55,3 +54,40 @@ std::ifstream& readDetector( std::ifstream& in, aliceVision::feature::PointFeatu >> point.orientation(); return in; } + +bool anglefrom( float x, float y, float& angle ) +{ + using namespace boost::math; + + if(x != 0) + angle = std::atan(y / x); + else if(y > 0) + angle = constants::pi() / 2; + else if(y < 0) + angle = -constants::pi() / 2; + else + return false; + + if(x < 0) + angle += constants::pi(); + while(angle < 0) + angle += 2 * constants::pi(); + while(angle >= 2 * constants::pi()) + angle -= 2 * constants::pi(); + assert(angle >= 0 && angle < 2 * constants::pi()); + return true; +} + +double angle_difference( double angle1, double angle2 ) +{ + using namespace boost::math; + + double angle = angle1 - angle2; + while(angle < 0) + angle += 2 * constants::pi(); + while(angle >= 2 * constants::pi()) + angle -= 2 * constants::pi(); + + assert(angle <= 2 * constants::pi() && angle >= 0); + return std::min(angle, 2 * constants::pi() - angle); +} diff --git a/src/aliceVision/matching/kvld/algorithm.h b/src/aliceVision/matching/kvld/algorithm.h index b583f71002..8bd9784a0e 100644 --- a/src/aliceVision/matching/kvld/algorithm.h +++ b/src/aliceVision/matching/kvld/algorithm.h @@ -30,7 +30,6 @@ #include -const float PI_ = 4.0 * atan( 1.0f ); //============================== simplified structure of a point=============================// //if you set KVLD geometry verification to false, you only need to fill x and y in a point structure @@ -108,35 +107,9 @@ inline bool inside( int w, int h, int x,int y, double radius ) return( x - radius >= 0 && y - radius >= 0 && x + radius < w && y + radius < h ); } -inline bool anglefrom( const float& x, const float& y, float& angle ) -{ - if( x != 0 ) - angle = atan( y / x ); - else if( y > 0 ) - angle = PI_ / 2; - else if( y < 0 ) - angle =- PI_ / 2; - else return false; - - if( x < 0 ) - angle += PI_; - while( angle < 0 ) - angle += 2 * PI_; - while( angle >= 2 * PI_ ) - angle -= 2 * PI_; - assert( angle >= 0 && angle < 2 * PI_ ); - return true; -} +bool anglefrom(float x, float y, float& angle); -inline double angle_difference( const double angle1, const double angle2 ) -{ - double angle = angle1 - angle2; - while( angle < 0 ) angle += 2 * PI_; - while( angle >= 2 * PI_ ) angle -= 2 * PI_; - - assert(angle <= 2 * PI_ && angle >= 0 ); - return std::min( angle, 2 * PI_ - angle ); -} +double angle_difference(double angle1, double angle2); inline void max( double* list,double& weight, int size, int& index, int& second_index ) { diff --git a/src/aliceVision/matching/kvld/kvld.cpp b/src/aliceVision/matching/kvld/kvld.cpp index 7c3a289770..77f640488a 100644 --- a/src/aliceVision/matching/kvld/kvld.cpp +++ b/src/aliceVision/matching/kvld/kvld.cpp @@ -103,6 +103,8 @@ int ImageScale::getIndex( const double r )const template< typename T > VLD::VLD( const ImageScale& series, T const& P1, T const& P2 ) : contrast( 0.0 ) { + using namespace boost::math; + //============== initializing============// principleAngle.fill( 0 ); descriptor.fill( 0 ); @@ -161,12 +163,12 @@ VLD::VLD( const ImageScale& series, T const& P1, T const& P2 ) : contrast( 0.0 ) //cout<= 2 * PI_) - angle -= 2 * PI_; + angle += 2 * constants::pi(); + while(angle >= 2 * constants::pi()) + angle -= 2 * constants::pi(); //===============principle angle==============================// - const int index = int( angle * binNum / ( 2 * PI_ ) + 0.5 ); + const int index = int(angle * binNum / (2 * constants::pi()) + 0.5); double Gweight = exp( -d * d / 4.5 / sigma2 ) * ( m( y, x ) ); if( index < binNum ) @@ -175,7 +177,7 @@ VLD::VLD( const ImageScale& series, T const& P1, T const& P2 ) : contrast( 0.0 ) statistic[ 0 ] += Gweight; //==============the descriptor===============================// - const int index2 = int( angle * subdirection / ( 2 * PI_ ) + 0.5 ); + const int index2 = int(angle * subdirection / (2 * constants::pi()) + 0.5); assert( index2 >= 0 && index2 <= subdirection ); if( index2 < subdirection ) @@ -431,3 +433,11 @@ float KVLD( const Image< float >& I1, return float( matchesFiltered.size() ) / matches.size(); } +double VLD::get_orientation() const +{ + const float dy = end_point[1] - begin_point[1]; + const float dx = end_point[0] - begin_point[0]; + float angle; + anglefrom(dx, dy, angle); + return angle; +} diff --git a/src/aliceVision/matching/kvld/kvld.h b/src/aliceVision/matching/kvld/kvld.h index ccd80d9375..3242465262 100644 --- a/src/aliceVision/matching/kvld/kvld.h +++ b/src/aliceVision/matching/kvld/kvld.h @@ -95,14 +95,8 @@ class VLD template< typename T > VLD( const ImageScale& series, T const& P1, T const& P2 ); //=========================================class functions==============================================// - inline double get_orientation()const - { - float dy = end_point[ 1 ] - begin_point[ 1 ]; - float dx = end_point[ 0 ] - begin_point[ 0 ]; - float angle; - anglefrom( dx, dy, angle ); - return angle; - } + double get_orientation() const; + inline double difference( const VLD& vld2 )const { double diff[ 2 ];