[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 | {
|
---|
| 30 | cout<<"Ray Cast file: " << externKdTree << endl;
|
---|
| 31 | return mlrtaLoadAS(externKdTree.c_str());
|
---|
| 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,
|
---|
| 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(
|
---|
[1528] | 53 | &simpleRay.mOrigin.x,
|
---|
| 54 | &simpleRay.mDirection.x,
|
---|
[1520] | 55 | normal,
|
---|
| 56 | dist);
|
---|
| 57 |
|
---|
| 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 | {
|
---|
[1528] | 75 | Vector3 dir = -simpleRay.mDirection;
|
---|
[1520] | 76 | hittriangle = mlrtaIntersectAS(
|
---|
[1960] | 77 | &simpleRay.mOrigin.x,
|
---|
| 78 | &dir.x,
|
---|
| 79 | normal,
|
---|
| 80 | dist);
|
---|
[1520] | 81 |
|
---|
[1786] | 82 | Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
|
---|
| 83 |
|
---|
| 84 | if (intersect)
|
---|
| 85 | {
|
---|
| 86 | hitB.mObject = intersect;
|
---|
| 87 | hitB.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
| 88 | // Get the normal of that face
|
---|
| 89 | // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();
|
---|
| 90 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
| 91 | //-rays[index+i].mDirection; // $$ temporary
|
---|
| 92 | hitB.mPoint = simpleRay.Extrap(dist);
|
---|
[1520] | 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | return ProcessRay(
|
---|
[1867] | 97 | simpleRay,
|
---|
| 98 | hitA,
|
---|
| 99 | hitB,
|
---|
| 100 | vssRays,
|
---|
| 101 | box,
|
---|
| 102 | castDoubleRay,
|
---|
| 103 | pruneInvalidRays
|
---|
| 104 | );
|
---|
[1520] | 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | void IntelRayCaster::CastRays16(
|
---|
| 109 | const int index,
|
---|
| 110 | SimpleRayContainer &rays,
|
---|
| 111 | VssRayContainer &vssRays,
|
---|
| 112 | const AxisAlignedBox3 &sbox,
|
---|
[1528] | 113 | const bool castDoubleRay,
|
---|
| 114 | const bool pruneInvalidRays)
|
---|
[1520] | 115 | {
|
---|
| 116 | int i;
|
---|
| 117 | const int num = 16;
|
---|
| 118 |
|
---|
| 119 | #if DEBUG_RAYCAST
|
---|
| 120 | Debug<<"C16 "<<flush;
|
---|
| 121 | #endif
|
---|
| 122 |
|
---|
| 123 | int forward_hit_triangles[16];
|
---|
| 124 | float forward_dist[16];
|
---|
| 125 |
|
---|
| 126 | int backward_hit_triangles[16];
|
---|
| 127 | float backward_dist[16];
|
---|
| 128 |
|
---|
[1942] | 129 |
|
---|
| 130 | Vector3 min = mPreprocessor.mSceneGraph->GetBox().Min();
|
---|
| 131 | Vector3 max = mPreprocessor.mSceneGraph->GetBox().Max();
|
---|
[1520] | 132 |
|
---|
| 133 | for (i=0; i < num; i++) {
|
---|
[1757] | 134 | mlrtaStoreRayAS16(&rays[index + i].mOrigin.x,
|
---|
| 135 | &rays[index + i].mDirection.x,
|
---|
| 136 | i);
|
---|
[1520] | 137 | }
|
---|
| 138 |
|
---|
[1757] | 139 | #if DEBUG_RAYCAST
|
---|
| 140 | Debug<<"TA\n"<<flush;
|
---|
| 141 | #endif
|
---|
| 142 |
|
---|
[1520] | 143 | mlrtaTraverseGroupAS16(&min.x,
|
---|
[1757] | 144 | &max.x,
|
---|
| 145 | forward_hit_triangles,
|
---|
| 146 | forward_dist);
|
---|
| 147 |
|
---|
[1520] | 148 | if (castDoubleRay)
|
---|
[1757] | 149 | {
|
---|
[1520] | 150 | for (i=0; i < num; i++)
|
---|
[1757] | 151 | {
|
---|
[1520] | 152 | Vector3 dir = -rays[index + i].mDirection;
|
---|
| 153 | mlrtaStoreRayAS16(&rays[index+i].mOrigin.x,
|
---|
[1757] | 154 | &dir.x,
|
---|
| 155 | i);
|
---|
| 156 | }
|
---|
[1520] | 157 |
|
---|
[1757] | 158 | #if DEBUG_RAYCAST
|
---|
| 159 | Debug<<"TB\n"<<flush;
|
---|
| 160 | #endif
|
---|
| 161 |
|
---|
[1520] | 162 | mlrtaTraverseGroupAS16(&min.x,
|
---|
[1757] | 163 | &max.x,
|
---|
| 164 | backward_hit_triangles,
|
---|
| 165 | backward_dist);
|
---|
| 166 | }
|
---|
[1520] | 167 |
|
---|
[1757] | 168 | #if DEBUG_RAYCAST
|
---|
| 169 | Debug<<"BBB\n"<<flush;
|
---|
| 170 | #endif
|
---|
| 171 |
|
---|
[1520] | 172 | for (i=0; i < num; i++)
|
---|
[1786] | 173 | {
|
---|
[1533] | 174 | Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
|
---|
[1757] | 175 |
|
---|
| 176 | #if DEBUG_RAYCAST
|
---|
[1786] | 177 | Debug<<"FH\n"<<flush;
|
---|
[1757] | 178 | #endif
|
---|
[1786] | 179 | Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]);
|
---|
| 180 |
|
---|
| 181 | if (intersect)
|
---|
| 182 | {
|
---|
| 183 | hitA.mObject = intersect;
|
---|
[1757] | 184 | // Get the normal of that face
|
---|
[1786] | 185 | hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]);
|
---|
| 186 |
|
---|
[1757] | 187 | //-rays[index+i].mDirection; // $$ temporary
|
---|
| 188 | hitA.mPoint = rays[index+i].Extrap(forward_dist[i]);
|
---|
[1786] | 189 | }
|
---|
| 190 |
|
---|
[1757] | 191 | #if DEBUG_RAYCAST
|
---|
[1786] | 192 | Debug<<"BH\n"<<flush;
|
---|
[1757] | 193 | #endif
|
---|
[1786] | 194 |
|
---|
| 195 | if (castDoubleRay)
|
---|
| 196 | {
|
---|
| 197 | Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]);
|
---|
| 198 |
|
---|
| 199 | if (intersect)
|
---|
| 200 | {
|
---|
| 201 | hitB.mObject = intersect;
|
---|
| 202 | hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]);
|
---|
| 203 |
|
---|
| 204 | // normalB = rays[index+i].mDirection; // $$ temporary
|
---|
| 205 | hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]);
|
---|
| 206 | }
|
---|
[1520] | 207 | }
|
---|
[1786] | 208 |
|
---|
[1757] | 209 | #if DEBUG_RAYCAST
|
---|
[1786] | 210 | Debug<<"PR\n"<<flush;
|
---|
[1757] | 211 | #endif
|
---|
[1786] | 212 |
|
---|
| 213 | ProcessRay(rays[index + i],
|
---|
| 214 | hitA,
|
---|
| 215 | hitB,
|
---|
| 216 | vssRays,
|
---|
| 217 | sbox,
|
---|
| 218 | castDoubleRay,
|
---|
| 219 | pruneInvalidRays
|
---|
| 220 | );
|
---|
[1520] | 221 | }
|
---|
[1786] | 222 |
|
---|
[1520] | 223 | #if DEBUG_RAYCAST
|
---|
| 224 | Debug<<"C16F\n"<<flush;
|
---|
| 225 | #endif
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | #endif
|
---|