#ifndef PointList_INC #define PointList_INC #include struct LBPM_Point { LBPM_Point() : x(0.0), y(0.0), z(0.0) {} LBPM_Point(double xv,double yv,double zv) : x(xv), y(yv), z(zv) {} LBPM_Point(const LBPM_Point& rhs): x(rhs.x), y(rhs.y), z(rhs.z) {} //Point& operator=(const Point& rhs) { this->x=rhs.x; this->y=rhs.y; this->z=rhs.z; return *this; } //~Point() {} double x,y,z; }; typedef LBPM_Point Point; inline Point operator+(const Point &A,const Point &B) {return Point(A.x+B.x,A.y+B.y,A.z+B.z);} inline Point operator-(const Point &A,const Point &B) {return Point(A.x-B.x,A.y-B.y,A.z-B.z);} inline Point operator*(const Point &A,double v) {return Point(A.x*v,A.y*v,A.z*v);} inline Point operator*(double v,const Point &A) {return Point(A.x*v,A.y*v,A.z*v);} inline Point operator/(const Point &A,double v) {return Point(A.x/v,A.y/v,A.z/v);} inline Point operator-(const Point &A) {return Point(-A.x,-A.y,-A.z);} inline bool operator==(const Point &A,const Point &B) {return (A.x==B.x && A.y==B.y && A.z==B.z);} inline bool operator!=(const Point &A,const Point &B) {return (A.x!=B.x || A.y!=B.y || A.z!=B.z);} inline double Norm(const Point &A) {return sqrt(A.x*A.x+A.y*A.y+A.z*A.z);} inline Point Cross(const Point &A,const Point &B) {return Point(A.y*B.z-A.z*B.y,B.x*A.z-A.x*B.z,A.x*B.y-A.y*B.x);} inline double Dot(const Point &A,const Point &B) {return (A.x*B.x+A.y*B.y+A.z*B.z);} inline double Distance(const Point &A,const Point &B) {return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z));} /* class PointList{ public: int length; int m; int index; Point pt; double *data; PointList(); PointList(int size); ~PointList(); void New(int size); Point & operator()(int idx) { index = idx; pt.x = data[3*index]; pt.y = data[3*index+1]; pt.z = data[3*index+2]; return pt; } Point &operator=(Point &P){ pt.x = P.x; pt.y = P.y; pt.z = P.z; data[3*index]=pt.x; data[3*index+1]=pt.y; data[3*index+2]=pt.z; } }; // ***************************************** // ******** class PointList ************** // ***************************************** PointList::PointList() { m=length=0; } PointList::PointList(int size) { m=size; data = new double [3*size]; length = size; } void PointList::New(int size) { m=size; data = new double [3*size]; length = size; } PointList::~PointList() { delete data; } */ template class DTList { public: DTList() : Data(0), length(0), refCount(new size_t(1)), outOfRange() {} DTList(const DTList &A) : Data(A.Data), length(A.length), refCount(A.refCount), outOfRange() {++(*refCount);} protected: DTList(size_t len) : Data(len<=0 ? 0 : new T[len]), length(len<=0 ? 0 : len), refCount(new size_t(1)), outOfRange() {} public: virtual ~DTList() { --(*refCount); if (*refCount==0) {delete [] Data; delete refCount;} Data = 0; refCount = 0; length=0; } DTList &operator=(const DTList &A) { if (A.refCount!=refCount) { // Otherwise doing A=A. --(*refCount); if (*refCount==0) {delete [] Data; delete refCount;} refCount = A.refCount; ++(*refCount); length = A.length; Data = A.Data; } return *this; } size_t MemoryUsed(void) const {return length*sizeof(T);} const T *Pointer(void) const {return Data;} size_t IsEmpty(void) const {return (Data==0);} size_t Length(void) const {return length;} const T operator()(size_t i) const {return Data[i];} protected: T *Data; size_t length; size_t *refCount; // Should be static. T outOfRange; }; template class DTMutableList : public DTList { public: DTMutableList() : DTList() {} DTMutableList(size_t len) : DTList(len) {} DTMutableList(const DTMutableList &A) : DTList(A) {} DTMutableList &operator=(const DTMutableList &A) {DTList::operator=(A); return *this;} T *Pointer(void) {return DTList::Data;} const T *Pointer(void) const {return DTList::Data;} T &operator()(size_t i) {return DTList::Data[i];} T operator()(size_t i) const {return DTList::Data[i];} DTMutableList &operator=(T v) {for (size_t i=0;i::length;i++) DTList::Data[i] = v; return *this;} }; template DTMutableList TruncateSize(const DTList &A,size_t length) { if (length>A.Length()) length = A.Length(); DTMutableList toReturn(length); const T *fromP = A.Pointer(); T *toP = toReturn.Pointer(); for (size_t i=0;i DTMutableList IncreaseSize(const DTList &A,size_t addLength) { DTMutableList toReturn(A.Length()+(addLength>=0 ? addLength : 0)); size_t len = A.Length(); const T *fromP = A.Pointer(); T *toP = toReturn.Pointer(); for (size_t i=0;i