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