[1520] | 1 | #include "IntelRayCaster.h"
|
---|
| 2 | #include "VssRay.h"
|
---|
| 3 | #include "Preprocessor.h"
|
---|
| 4 |
|
---|
| 5 | #ifdef GTP_INTERNAL
|
---|
| 6 | #include "ArchModeler2MLRT.hxx"
|
---|
| 7 |
|
---|
| 8 | #define DEBUG_RAYCAST 0
|
---|
| 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 ) {
|
---|
| 57 | if (hittriangle >= mPreprocessor.mFaceParents.size())
|
---|
| 58 | cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
|
---|
| 59 | else {
|
---|
[1528] | 60 | hitA.mObject = mPreprocessor.mFaceParents[hittriangle].mObject;
|
---|
| 61 | hitA.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
[1520] | 62 | // Get the normal of that face
|
---|
| 63 | // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();
|
---|
| 64 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
| 65 | //-rays[index+i].mDirection; // $$ temporary
|
---|
[1528] | 66 | hitA.mPoint = simpleRay.Extrap(dist);
|
---|
[1520] | 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | if (castDoubleRay)
|
---|
| 71 | {
|
---|
[1528] | 72 | Vector3 dir = -simpleRay.mDirection;
|
---|
[1520] | 73 | hittriangle = mlrtaIntersectAS(
|
---|
[1528] | 74 | &simpleRay.mOrigin.x,
|
---|
[1520] | 75 | &dir.x,
|
---|
| 76 | normal,
|
---|
| 77 | dist);
|
---|
| 78 |
|
---|
| 79 | if (hittriangle != -1 ) {
|
---|
| 80 | if (hittriangle >= mPreprocessor.mFaceParents.size())
|
---|
| 81 | cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
|
---|
| 82 | else
|
---|
| 83 | {
|
---|
[1528] | 84 | hitB.mObject = mPreprocessor.mFaceParents[hittriangle].mObject;
|
---|
| 85 | hitB.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
[1520] | 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
|
---|
[1528] | 90 | hitB.mPoint = simpleRay.Extrap(dist);
|
---|
[1520] | 91 | }
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | return ProcessRay(
|
---|
[1528] | 96 | simpleRay,
|
---|
| 97 | hitA,
|
---|
| 98 | hitB,
|
---|
[1520] | 99 | vssRays,
|
---|
[1528] | 100 | box,
|
---|
| 101 | castDoubleRay,
|
---|
| 102 | pruneInvalidRays
|
---|
[1520] | 103 | );
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | void IntelRayCaster::CastRays16(
|
---|
| 108 | const int index,
|
---|
| 109 | SimpleRayContainer &rays,
|
---|
| 110 | VssRayContainer &vssRays,
|
---|
| 111 | const AxisAlignedBox3 &sbox,
|
---|
[1528] | 112 | const bool castDoubleRay,
|
---|
| 113 | const bool pruneInvalidRays)
|
---|
[1520] | 114 | {
|
---|
| 115 | int i;
|
---|
| 116 | const int num = 16;
|
---|
| 117 |
|
---|
| 118 | #if DEBUG_RAYCAST
|
---|
| 119 | Debug<<"C16 "<<flush;
|
---|
| 120 | #endif
|
---|
| 121 |
|
---|
| 122 | int forward_hit_triangles[16];
|
---|
| 123 | float forward_dist[16];
|
---|
| 124 |
|
---|
| 125 | int backward_hit_triangles[16];
|
---|
| 126 | float backward_dist[16];
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | Vector3 min = sbox.Min();
|
---|
| 130 | Vector3 max = sbox.Max();
|
---|
| 131 |
|
---|
| 132 | for (i=0; i < num; i++) {
|
---|
| 133 | mlrtaStoreRayAS16(&rays[index + i].mOrigin.x,
|
---|
| 134 | &rays[index + i].mDirection.x,
|
---|
| 135 | i);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | mlrtaTraverseGroupAS16(&min.x,
|
---|
| 139 | &max.x,
|
---|
| 140 | forward_hit_triangles,
|
---|
| 141 | forward_dist);
|
---|
| 142 |
|
---|
| 143 | if (castDoubleRay)
|
---|
| 144 | {
|
---|
| 145 | for (i=0; i < num; i++)
|
---|
| 146 | {
|
---|
| 147 | Vector3 dir = -rays[index + i].mDirection;
|
---|
| 148 | mlrtaStoreRayAS16(&rays[index+i].mOrigin.x,
|
---|
| 149 | &dir.x,
|
---|
| 150 | i);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | mlrtaTraverseGroupAS16(&min.x,
|
---|
| 154 | &max.x,
|
---|
| 155 | backward_hit_triangles,
|
---|
| 156 | backward_dist);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | for (i=0; i < num; i++)
|
---|
| 160 | {
|
---|
[1533] | 161 | Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
|
---|
[1528] | 162 |
|
---|
[1520] | 163 | if (forward_hit_triangles[i] != -1 ) {
|
---|
| 164 | if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
|
---|
| 165 | cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl;
|
---|
| 166 | else {
|
---|
[1528] | 167 | hitA.mObject = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject;
|
---|
[1520] | 168 | // Get the normal of that face
|
---|
[1528] | 169 | hitA.mNormal = hitA.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);
|
---|
[1520] | 170 | //-rays[index+i].mDirection; // $$ temporary
|
---|
[1528] | 171 | hitA.mPoint = rays[index+i].Extrap(forward_dist[i]);
|
---|
[1520] | 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | if (castDoubleRay && (backward_hit_triangles[i] != -1)) {
|
---|
| 176 | if (backward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
|
---|
| 177 | cerr<<"Warning: triangle index out of range! "<<backward_hit_triangles[i]<<endl;
|
---|
| 178 | else {
|
---|
[1528] | 179 | hitB.mObject = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject;
|
---|
| 180 | hitB.mNormal = hitB.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);
|
---|
[1520] | 181 |
|
---|
| 182 | // normalB = rays[index+i].mDirection; // $$ temporary
|
---|
[1528] | 183 | hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]);
|
---|
[1520] | 184 | }
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | ProcessRay(
|
---|
[1528] | 188 | rays[index + i],
|
---|
| 189 | hitA,
|
---|
| 190 | hitB,
|
---|
[1520] | 191 | vssRays,
|
---|
[1528] | 192 | sbox,
|
---|
| 193 | castDoubleRay,
|
---|
| 194 | pruneInvalidRays
|
---|
[1520] | 195 | );
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | #if DEBUG_RAYCAST
|
---|
| 199 | Debug<<"C16F\n"<<flush;
|
---|
| 200 | #endif
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | #endif
|
---|