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