00001 #ifndef _3DMANIP_H_ 00002 #define _3DMANIP_H_ 00003 #include <math.h> 00004 #define QFLOAT float 00005 #define XSQRT sqrtf 00006 #define XVector Vector 00007 #define YVector QVector 00008 #include "xvector.h" 00009 #undef QFLOAT 00010 #undef XVector 00011 #undef YVector 00012 #undef XSQRT 00013 #define QFLOAT double 00014 #define XSQRT sqrt 00015 #define XVector QVector 00016 #define YVector Vector 00017 00018 #include "xvector.h" 00019 #undef XSQRT 00020 #undef QFLOAT 00021 #undef XVector 00022 #undef YVector 00023 00024 inline Vector QVector::operator =(const Vector &a) { 00025 i=a.i; 00026 j=a.j; 00027 k=a.k; 00028 return a; 00029 } 00030 inline QVector::QVector (const Vector &a) { 00031 i=a.i; 00032 j=a.j; 00033 k=a.k; 00034 } 00035 inline QVector Vector::operator = (const QVector &a) { 00036 i=a.i; 00037 j=a.j; 00038 k=a.k; 00039 return a; 00040 } 00041 inline Vector::Vector (const QVector &a) { 00042 i=a.i; 00043 j=a.j; 00044 k=a.k; 00045 } 00046 inline QVector Vector::Cast() const{ 00047 return QVector (i,j,k); 00048 } 00049 inline Vector QVector::Cast() const{ 00050 return Vector (i,j,k); 00051 } 00053 00059 template <class XVector, class DoItType> inline void forEach3dVector (XVector first, XVector last, DoItType DoIt, XVector increment) { 00060 first.Set(floor(first.i/increment.i)*increment.i, 00061 floor(first.j/increment.j)*increment.j, 00062 floor(first.k/increment.k)*increment.k); 00063 last.Set(ceil(last.i/increment.i)*increment.i, 00064 ceil(last.j/increment.j)*increment.j, 00065 ceil(last.k/increment.k)*increment.k); 00066 XVector xvec (first); 00067 for (first.k=xvec.k;first.k<last.k;first.k+=increment.k) { 00068 for (first.j=xvec.j;first.j<last.j;first.j+=increment.j) { 00069 for (first.i=xvec.i;first.i<last.i;first.i+=increment.i) { 00070 DoIt(first); 00071 } 00072 } 00073 } 00074 } 00075 00077 00083 template <class XVector, class DoItType> inline void forEach2dVector (XVector first, XVector last, DoItType DoIt, XVector increment) { 00084 first.Set(floor(first.i/increment.i)*increment.i, 00085 floor(first.j/increment.j)*increment.j, 00086 first.k); 00087 last.Set(ceil(last.i/increment.i)*increment.i, 00088 ceil(last.j/increment.j)*increment.j, 00089 last.k); 00090 XVector xvec (first); 00091 for (first.j=xvec.j;first.j<last.j;first.j+=increment.j) { 00092 for (first.i=xvec.i;first.i<last.i;first.i+=increment.i) { 00093 DoIt(first); 00094 } 00095 } 00096 } 00097 00098 #endif 00099