• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/core/math/math_compute_contiguous_angle_interval.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_CORE_MATH_COMPUTE_CONTIGUOUS_ANGLE_INTERVAL_H
00002 #define OPENTISSUE_CORE_MATH_COMPUTE_CONTIGUOUS_ANGLE_INTERVAL_H
00003 //
00004 // OpenTissue Template Library
00005 // - A generic toolbox for physics-based modeling and simulation.
00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen.
00007 //
00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php
00009 //
00010 #include <OpenTissue/configuration.h>
00011 
00012 #include <OpenTissue/core/math/math_value_traits.h>
00013 #include <OpenTissue/core/math/math_is_number.h>
00014 
00015 #include <algorithm>
00016 #include <vector>
00017 #include <stdexcept>
00018 #include <cmath>
00019 
00020 namespace OpenTissue
00021 {
00022   namespace math
00023   {
00024 
00055     template<typename iterator_type>
00056     inline void compute_contiguous_angle_interval( 
00057       iterator_type const & begin
00058       , iterator_type const & end
00059       , typename iterator_type::value_type & theta_min
00060       , typename iterator_type::value_type & theta_max )
00061     {
00062       //using std::cos;
00063       //using std::sin;
00064       //using std::sqrt;
00065       //using std::atan2;
00066 
00067       typedef typename iterator_type::value_type         T;
00068       typedef          OpenTissue::math::ValueTraits<T>  value_traits;
00069 
00070 
00071       T const two_pi = value_traits::pi()*value_traits::two();
00072 
00073       // Determine the number of samples
00074       size_t const N = std::distance( begin, end);
00075 
00076       // Make a copy of the samples and sort them in ascending order
00077       std::vector<T> storage;
00078       storage.resize( N );
00079       std::copy( begin, end, storage.begin() );
00080       std::sort( storage.begin(), storage.end() );
00081 
00082       // Find the two theta values with the largest gap inbetween. That
00083       // is the largest angle difference as measured in a counter-clock-wise manner.
00084       T      max_delta_theta = value_traits::zero();
00085       size_t max_i           = N;
00086 
00087       for(size_t i = 0u;i<N;++i)
00088       {
00089         T const & theta_i = storage[i];
00090         T const & theta_j = storage[(i+1)%N];
00091         T const delta_theta = (theta_j < theta_i) ?  theta_j+two_pi-theta_i : theta_j-theta_i;
00092         if(delta_theta > max_delta_theta)
00093         {
00094           max_i = i;
00095           max_delta_theta = delta_theta;
00096           theta_min = theta_j;
00097           theta_max = theta_i;
00098         }
00099       }
00100 
00103       //T mx = value_traits::zero();
00104       //T my = value_traits::zero();
00105       //for(iterator_type theta = begin; theta != end; ++ theta)
00106       //{        
00107       //  T const c = cos( *theta );
00108       //  T const s = sin( *theta );
00109       //  mx += c;
00110       //  my += s;
00111       //}
00112 
00113       //T norm = sqrt( mx*mx + my*my);
00114       //assert( is_number(norm) || !"compute_contiguous_angle_interval(): NaN encountered");
00115 
00116       //if(norm<= value_traits::zero())
00117       //  throw std::logic_error("insufficient angle samples to determine a mean angle"); 
00118 
00119       //mx /= norm;
00120       //my /= norm;
00121 
00122       //assert( is_number(mx) || !"compute_contiguous_angle_interval(): NaN encountered");
00123       //assert( is_number(my) || !"compute_contiguous_angle_interval(): NaN encountered");
00124 
00125       while(theta_min < value_traits::zero()) 
00126         theta_min += two_pi;
00127 
00128       while(theta_max < theta_min) 
00129         theta_max += two_pi;
00130 
00131       assert( theta_min <= theta_max || !"compute_contiguous_angle_interval(): invalid interval");
00132     }
00133 
00134 
00135   } // namespace math
00136 } // namespace OpenTissue
00137 
00138 //OPENTISSUE_CORE_MATH_COMPUTE_CONTIGUOUS_ANGLE_INTERVAL_H
00139 #endif

Generated on Thu Dec 1 2011 12:52:05 for HUMIM Tracker by  doxygen 1.7.1