Documentation


picking.h

Go to the documentation of this file.
00001 #ifndef animal_picking_h
00002 #define animal_picking_h
00003 
00004 #include <animal/linear.h>
00005 #include <animal/container_traits.h>
00006 //#include <iostream>
00007 
00008 namespace animal {
00009 
00013 class ConstrainedItem
00014 {
00015 public:
00017     virtual void getPoint( float&, float&, float& ) const {}    
00018     
00021     virtual void moveTo( float, float, float ) {}   
00022     
00024     virtual ~ConstrainedItem(){}    
00025     
00027     virtual void print() const {}
00028     
00031     virtual bool operator == ( const ConstrainedItem* ) const =0;
00032     
00033     virtual void draw() {};
00034 };
00035 
00036 
00037 
00046 template<class Int, class Real, class Points, class Vec>
00047 inline bool findClosestPointToLine( Int& index, Real& distance, const Points& coords, const Vec& lineOrigin, const Vec& lineDirection, Real threshold )
00048 {
00049     //std::cout << "findClosestPointToLine, origin = "<<lineOrigin<<", direction = "<<lineDirection<<std::endl;
00050     distance = threshold + 1;
00051     for( Int i=0; i<static_cast<Int>(size(coords)); ++i  )
00052     {
00053         Vec gap = coords[i];
00054         v_meq( gap,lineOrigin );
00055         // gap == coords[i]-origin
00056         Real gapnorm = v_norm(gap);
00057         if( gapnorm < 1.0e-9 ) {  // too close for normalization, take it as closest point
00058             distance=gapnorm;
00059             index = i;
00060             return true;
00061         }
00062         else {
00063             Real cosine = v_dot(gap,lineDirection) / gapnorm;
00064             //std::cout<<"point "<<i<<": "<< coords[i] <<", distance = "<< cosine << std::endl;
00065             if( cosine>1-distance )
00066             {
00067                 distance = 1-cosine;
00068                 index = i;
00069             }
00070         }
00071     }
00072     if( distance<threshold ) return true;
00073     else return false;
00074 } 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 }//animal
00083 
00084 #endif

Generated on Thu Dec 23 13:52:27 2004 by doxygen 1.3.6