00001
00002
00003
00004
00005 #include "geometry/Track.h"
00006 #include "geometry/Ray.h"
00007
00008
00009 Ray* Track::currentRay;
00010 double Track::currentArcLength;
00011
00012
00013 float Track::maxKink = 0.2f;
00014
00015 Track::Track( Ray* first, bool charged)
00016 : m_charged(charged)
00017 {
00018 rayList.push_back( first);
00019 arclength = first->getArcLength();
00020 currentRay = first;
00021 }
00022
00023 Track::~Track()
00024 {
00025 Raylist::iterator rayptr = rayList.begin();
00026 while( rayptr < rayList.end() )
00027 delete *rayptr++;
00028 }
00029
00030 GeomObject&
00031 Track::transform(const CoordTransform& T)
00032 {
00033 for(unsigned i=0; i< rayList.size(); i++)
00034 rayList[i]->transform(T);
00035 return *this;
00036 }
00037 void Track::findSegment( double s )
00038 { unsigned i=0;
00039 currentRay = rayList[0];
00040 currentArcLength = 0.;
00041 double ds = currentRay->getArcLength();
00042 while ( i<rayList.size() && s > currentArcLength+ds) {
00043 currentArcLength += ds;
00044 currentRay =rayList[++i];
00045 ds = currentRay->getArcLength();
00046 }
00047 }
00048
00049 void Track::addSegment( Ray* next )
00050 {
00051 float ds = next->getArcLength();
00052 arclength += ds;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 rayList.push_back( next );
00070 currentRay = next;
00071
00072 }
00073
00074 void Track::printOn(std::ostream& os) const
00075 {
00076 os << "Track: total arclength = "<< arclength << '\n';
00077 for( unsigned i=0; i<rayList.size(); i++ )
00078 rayList[i]->printOn(os);
00079 }
00080
00081 Point
00082 Track::position( double s ) const
00083 {
00084 Track* self = (Track*)this;
00085 self->findSegment(s);
00086 return currentRay->position(s-currentArcLength);
00087 }
00088
00089 Vector Track::direction( double s ) const
00090 {
00091 Track* self = const_cast<Track*>(this);
00092 self->findSegment(s);
00093 return currentRay->direction(s-currentArcLength);
00094 }
00095
00096
00097