[1520] | 1 | #include "IntelRayCaster.h"
|
---|
| 2 | #include "VssRay.h"
|
---|
| 3 | #include "Preprocessor.h"
|
---|
[1942] | 4 | #include "SceneGraph.h"
|
---|
[1520] | 5 |
|
---|
| 6 | #ifdef GTP_INTERNAL
|
---|
| 7 | #include "ArchModeler2MLRT.hxx"
|
---|
| 8 |
|
---|
[1952] | 9 | #define DEBUG_RAYCAST 0
|
---|
[1520] | 10 |
|
---|
| 11 |
|
---|
| 12 | namespace GtpVisibilityPreprocessor {
|
---|
| 13 |
|
---|
| 14 |
|
---|
[1960] | 15 | IntelRayCaster::IntelRayCaster(const Preprocessor &preprocessor,
|
---|
| 16 | const string externKdTree):
|
---|
[1520] | 17 | RayCaster(preprocessor)
|
---|
| 18 | {
|
---|
| 19 | InitRayCast(externKdTree);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | IntelRayCaster::~IntelRayCaster()
|
---|
| 24 | {
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | bool IntelRayCaster::InitRayCast(const string externKdTree)
|
---|
| 29 | {
|
---|
[1984] | 30 | cout<<"Ray Cast file: " << externKdTree << endl;
|
---|
| 31 | return mlrtaLoadAS(externKdTree.c_str());
|
---|
[1520] | 32 | }
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | int IntelRayCaster::CastRay(
|
---|
[1528] | 36 | const SimpleRay &simpleRay,
|
---|
[1520] | 37 | VssRayContainer &vssRays,
|
---|
| 38 | const AxisAlignedBox3 &box,
|
---|
[1528] | 39 | const bool castDoubleRay,
|
---|
[1996] | 40 | const bool pruneInvalidRays
|
---|
[1520] | 41 | )
|
---|
| 42 | {
|
---|
| 43 | //cout << "intel ray" << endl;
|
---|
| 44 | VssRay *vssRay = NULL;
|
---|
| 45 | int hits = 0;
|
---|
| 46 | int hittriangle;
|
---|
[1533] | 47 | Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
|
---|
[1528] | 48 |
|
---|
[1520] | 49 | float dist;
|
---|
| 50 | double normal[3];
|
---|
| 51 |
|
---|
| 52 | hittriangle = mlrtaIntersectAS(
|
---|
[1984] | 53 | &simpleRay.mOrigin.x,
|
---|
| 54 | &simpleRay.mDirection.x,
|
---|
| 55 | normal,
|
---|
| 56 | dist);
|
---|
| 57 |
|
---|
[1520] | 58 | if (hittriangle != -1 ) {
|
---|
[1786] | 59 | Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
|
---|
| 60 |
|
---|
| 61 | if (intersect)
|
---|
| 62 | {
|
---|
| 63 | hitA.mObject = intersect;
|
---|
[1528] | 64 | hitA.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
[1520] | 65 | // Get the normal of that face
|
---|
| 66 | // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();
|
---|
| 67 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
| 68 | //-rays[index+i].mDirection; // $$ temporary
|
---|
[1528] | 69 | hitA.mPoint = simpleRay.Extrap(dist);
|
---|
[1520] | 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if (castDoubleRay)
|
---|
| 74 | {
|
---|
[1999] | 75 | //cerr<<"HERE"<<endl;
|
---|
[1984] | 76 | Vector3 dir = -simpleRay.mDirection;
|
---|
[1520] | 77 | hittriangle = mlrtaIntersectAS(
|
---|
[1960] | 78 | &simpleRay.mOrigin.x,
|
---|
| 79 | &dir.x,
|
---|
| 80 | normal,
|
---|
| 81 | dist);
|
---|
[1520] | 82 |
|
---|
[1786] | 83 | Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
|
---|
| 84 |
|
---|
| 85 | if (intersect)
|
---|
| 86 | {
|
---|
| 87 | hitB.mObject = intersect;
|
---|
| 88 | hitB.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
| 89 | // Get the normal of that face
|
---|
| 90 | // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();
|
---|
| 91 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
| 92 | //-rays[index+i].mDirection; // $$ temporary
|
---|
| 93 | hitB.mPoint = simpleRay.Extrap(dist);
|
---|
[1520] | 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | return ProcessRay(
|
---|
[1867] | 98 | simpleRay,
|
---|
| 99 | hitA,
|
---|
| 100 | hitB,
|
---|
| 101 | vssRays,
|
---|
| 102 | box,
|
---|
| 103 | castDoubleRay,
|
---|
[1996] | 104 | pruneInvalidRays
|
---|
[1867] | 105 | );
|
---|
[1520] | 106 | }
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | void IntelRayCaster::CastRays16(
|
---|
| 110 | SimpleRayContainer &rays,
|
---|
| 111 | VssRayContainer &vssRays,
|
---|
| 112 | const AxisAlignedBox3 &sbox,
|
---|
[1528] | 113 | const bool castDoubleRay,
|
---|
[1996] | 114 | const bool pruneInvalidRays)
|
---|
[1520] | 115 | {
|
---|
| 116 | int i;
|
---|
| 117 | const int num = 16;
|
---|
[1972] | 118 |
|
---|
[1520] | 119 | #if DEBUG_RAYCAST
|
---|
| 120 | Debug<<"C16 "<<flush;
|
---|
[1983] | 121 | static int counter=0;
|
---|
| 122 | Debug<<counter++<<endl;
|
---|
[1520] | 123 | #endif
|
---|
| 124 |
|
---|
[1984] | 125 | static int forward_hit_triangles[16];
|
---|
| 126 | static float forward_dist[16];
|
---|
[1520] | 127 |
|
---|
[1984] | 128 | static int backward_hit_triangles[16];
|
---|
| 129 | static float backward_dist[16];
|
---|
[1520] | 130 |
|
---|
[1942] | 131 |
|
---|
| 132 | Vector3 min = mPreprocessor.mSceneGraph->GetBox().Min();
|
---|
| 133 | Vector3 max = mPreprocessor.mSceneGraph->GetBox().Max();
|
---|
[1520] | 134 |
|
---|
| 135 | for (i=0; i < num; i++) {
|
---|
[1983] | 136 | #if DEBUG_RAYCAST
|
---|
| 137 | if (counter == 43964) {
|
---|
| 138 | Debug<<rays[i].mOrigin<<" "<<rays[i].mDirection<<endl;
|
---|
| 139 | }
|
---|
| 140 | #endif
|
---|
[1972] | 141 | mlrtaStoreRayAS16(&rays[i].mOrigin.x,
|
---|
| 142 | &rays[i].mDirection.x,
|
---|
[1757] | 143 | i);
|
---|
[1520] | 144 | }
|
---|
| 145 |
|
---|
[1757] | 146 | #if DEBUG_RAYCAST
|
---|
[1983] | 147 | Debug<<"TA\n"<<flush;
|
---|
[1757] | 148 | #endif
|
---|
| 149 |
|
---|
[1520] | 150 | mlrtaTraverseGroupAS16(&min.x,
|
---|
[1757] | 151 | &max.x,
|
---|
| 152 | forward_hit_triangles,
|
---|
| 153 | forward_dist);
|
---|
[1520] | 154 |
|
---|
[1757] | 155 | #if DEBUG_RAYCAST
|
---|
[1983] | 156 | Debug<<"TAB\n"<<flush;
|
---|
[1757] | 157 | #endif
|
---|
| 158 |
|
---|
[1983] | 159 | if (castDoubleRay) {
|
---|
| 160 | for (i=0; i < num; i++) {
|
---|
| 161 | Vector3 dir = -rays[i].mDirection;
|
---|
| 162 | mlrtaStoreRayAS16(&rays[i].mOrigin.x,
|
---|
| 163 | &dir.x,
|
---|
| 164 | i);
|
---|
[1757] | 165 | }
|
---|
[1983] | 166 |
|
---|
[1757] | 167 | #if DEBUG_RAYCAST
|
---|
[1983] | 168 | Debug<<"TB\n"<<flush;
|
---|
| 169 | #endif
|
---|
| 170 |
|
---|
| 171 | mlrtaTraverseGroupAS16(&min.x,
|
---|
| 172 | &max.x,
|
---|
| 173 | backward_hit_triangles,
|
---|
| 174 | backward_dist);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | #if DEBUG_RAYCAST
|
---|
[1757] | 178 | Debug<<"BBB\n"<<flush;
|
---|
| 179 | #endif
|
---|
| 180 |
|
---|
[1520] | 181 | for (i=0; i < num; i++)
|
---|
[1786] | 182 | {
|
---|
[1533] | 183 | Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
|
---|
[1757] | 184 |
|
---|
| 185 | #if DEBUG_RAYCAST
|
---|
[1786] | 186 | Debug<<"FH\n"<<flush;
|
---|
[1757] | 187 | #endif
|
---|
[1984] | 188 |
|
---|
[1786] | 189 | Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]);
|
---|
| 190 |
|
---|
| 191 | if (intersect)
|
---|
| 192 | {
|
---|
| 193 | hitA.mObject = intersect;
|
---|
[1757] | 194 | // Get the normal of that face
|
---|
[1786] | 195 | hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]);
|
---|
| 196 |
|
---|
[1757] | 197 | //-rays[index+i].mDirection; // $$ temporary
|
---|
[1972] | 198 | hitA.mPoint = rays[i].Extrap(forward_dist[i]);
|
---|
[1786] | 199 | }
|
---|
| 200 |
|
---|
[1757] | 201 | #if DEBUG_RAYCAST
|
---|
[1786] | 202 | Debug<<"BH\n"<<flush;
|
---|
[1757] | 203 | #endif
|
---|
[1786] | 204 |
|
---|
| 205 | if (castDoubleRay)
|
---|
| 206 | {
|
---|
| 207 | Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]);
|
---|
| 208 |
|
---|
| 209 | if (intersect)
|
---|
| 210 | {
|
---|
| 211 | hitB.mObject = intersect;
|
---|
| 212 | hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]);
|
---|
| 213 |
|
---|
[1972] | 214 | // normalB = rays[i].mDirection; // $$ temporary
|
---|
| 215 | hitB.mPoint = rays[i].Extrap(-backward_dist[i]);
|
---|
[1786] | 216 | }
|
---|
[1520] | 217 | }
|
---|
[1786] | 218 |
|
---|
[1757] | 219 | #if DEBUG_RAYCAST
|
---|
[1786] | 220 | Debug<<"PR\n"<<flush;
|
---|
[1757] | 221 | #endif
|
---|
[1786] | 222 |
|
---|
[1972] | 223 | ProcessRay(rays[i],
|
---|
[1786] | 224 | hitA,
|
---|
| 225 | hitB,
|
---|
| 226 | vssRays,
|
---|
| 227 | sbox,
|
---|
| 228 | castDoubleRay,
|
---|
[1996] | 229 | pruneInvalidRays
|
---|
[1786] | 230 | );
|
---|
[1520] | 231 | }
|
---|
[1786] | 232 |
|
---|
[1520] | 233 | #if DEBUG_RAYCAST
|
---|
| 234 | Debug<<"C16F\n"<<flush;
|
---|
| 235 | #endif
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | #endif
|
---|