|
Open PaperOpt
|
00001 #ifndef RNDRAY_H 00002 #define RNDRAY_H 00003 00004 #ifndef MAX_THREADS 00005 00006 #define MAX_THREADS 2 //Controlls number of tagslots in render objects 00007 //and thus the maximum number of CPU's that can be 00008 //used simultaniously 00009 #endif 00010 00011 #include "utilities.h" 00012 #include "V3.h" 00013 #include "FiberStatic.h" 00014 #include "Staticsheet.h" 00015 #include "RndFiber.h" 00016 #include "OrientClipBox.h" 00017 #include "RndFiberSeg.h" 00018 #include "RndHitSortTag.h" 00019 #include "RndVolume.h" 00020 00021 00022 namespace p3d{ 00023 00038 #define CURMAT_OUTSIDE 1 //Outside volume 00039 #define CURMAT_AIR 2 //Traced outside fiber 00040 #define CURMAT_FIBER 3 //Traced into fiber 00041 #define CURMAT_LUMEN 4 //Traced into lumen 00042 #define CURMAT_VOID 5 //No hit 00043 00044 00057 class RndRay { 00058 00059 private: 00060 V3 <double> mOrgin; //Position in world. Used only when tracing outside fibers 00061 int mOrginRx,mOrginRy; //What repetition mOrgin is in. 00062 int mLatX,mLatY,mLatZ; //Current lattice point (in range [0..lat-1] 00063 V3 <double> mDir; 00064 00065 double mTtoHit; //accumulated distance traveled since last reset (increased when 00066 //changing lattice boxes, entering lumen, hiting fiber wall) 00067 00068 int mMaterial; //Current material, CURMAT_xxx 00069 00070 //Current and next lattice if mMaterial==CURMAT_AIR 00071 int mNumAccX,mNumAccY,mNumAccZ; //Copied from mVol 00072 int mNextLatX,mNextLatY,mNextLatZ; //Next lattice point 00073 double mNextLatT; //T of swap from current position 00074 00075 00076 //Environment 00077 int mThreadNo; //What slot to use when tagging 00078 int mRayNo; //This ray number (used for tagging) 00079 vector<RndHitSortTag>* mpRaySortVec; //Threads own sort-vector 00080 00081 RndVolume* mpVol; 00082 00083 //HitFlags 00084 int mIntersectType; //Traced into CURMAT_xxx 00085 00086 //Params/vars/retvals used by IntersectPolyFromAir and TraceInsideLumen 00087 RndFiber* mpHitFiber; 00088 double mPolyIntersectLimit; 00089 const RndFiberSeg* mpHitSeg; 00090 int mHitPlane; //0-15 plane, 16-capping begin, 17-capping end 00091 V3 <double> mHitPoint; //Translated to correct fiber position 00092 V3 <double> mHitPlaneNormal; 00093 V3 <double> mHitNormal; 00094 00095 //Lumen & fiber tracing 00096 RndFiber* mpCurFiber; 00097 V3 <double> mTrnOrg; //Translated orgin. Used when tracing inside fibers 00098 V3 <double> mTrnOrgDisp; //Displacement between mTrnOrg and mOrgin 00099 int mTrnOrgRx,mTrnOrgRy; //What repetition mTrnOrg is in. 00100 const RndFiberSeg* mpCurSeg; //Current segment we'r in 00101 00102 public: 00103 00104 RndRay(RndVolume* vol,V3 <double> pos,V3 <double> dir,int threadNo=0); 00105 RndRay(const RndRay& rRay,V3 <double> dir,int* discon); 00106 00107 V3 <double> Test(int level=0,int disp=0); 00108 00109 //=================Accessors============================ 00110 00111 int GetMaterial() const {return mMaterial;} 00112 int GetIntersectType() const {return mIntersectType;} 00113 V3 <double> GetPosition() const {if ((mMaterial==CURMAT_FIBER)||(mMaterial==CURMAT_LUMEN)) 00114 return mTrnOrg-mTrnOrgDisp; 00115 return mOrgin;} 00116 double GetTraceLen() const {return mTtoHit;} 00117 const V3 <double>& GetDirection() const {return mDir;} 00118 00119 const V3 <double>& GetHitNormal() const {return mHitNormal;} 00120 const V3 <double>& GetHitPlaneNormal() const {return mHitPlaneNormal;} 00121 00122 int GetLatZ() const{return mLatZ;} 00123 int GetNumAccZ() const{return mNumAccZ;} 00124 //=================Mutators=============================== 00125 00131 void SetNewDir(V3 <double>& rNdir); 00132 00133 void NormalizeDir() {mDir.Normalize();} 00134 00135 //=================Trace-ops - mode: CURMAT_AIR / CURMAT_OUTSIDE============== 00136 00137 //-----------------Trace-ops, lattice----------------------------------------- 00143 int TraceToLattice(); 00153 int FindNextLatticeExit(); 00162 int MoveToNextLatticePoint(); 00163 00164 //------------------Trace-ops, clipboxes------------------------------------- 00171 inline int TestSingleBox(double dispX,double dispY,OrientClipBox* cb,double& rTHit); 00179 int IntersectRayClipboxes(); 00180 00181 //------------------Trace-ops, pollys-------------------------------------- 00189 int IntersectPolysFromAir(OrientClipBox* box,double dispX,double dispY); 00195 void EstimateFromAirNormal(); 00196 00197 //=================Trace-ops - mode: CURMAT_LUMEN=========================== 00198 00206 void EnterLumenFromAir(); 00215 int TraceInsideLumen(); 00224 void LeaveLumenToAir(); 00232 void EstimateFromLumenNormal(); 00233 00234 //===============Trace-ops - mode: CURMAT_FIBER======================= 00242 void EnterFiberFrom_x(); 00253 int LeaveFiberTo_x(); 00262 int TraceInsideFiber(double* limit=0); 00263 00270 void EstimateFromFiberNormal(); 00271 void FindLatXYFromOrgin(); 00272 }; 00273 } 00274 00275 #endif