Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rocprop/src/ray-triangle.C File Reference
#include "CSEMesh.h"
#include <math.h>
Include dependency graph for Rocprop/src/ray-triangle.C:

Go to the source code of this file.

Classes

struct  RAYTRI
 
struct  RAYTRI::PLANE
 

Macros

#define EPSILON   0.000001
 
#define CROSS(dest, v1, v2)
 
#define DOT(v1, v2)   (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2])
 
#define SUB(dest, v1, v2)
 
#define PLUCKER(pline, pt1, pt2)
 
#define SIDE(p, q)   (p[0]*q[4]+p[1]*q[5]+p[2]*q[3]+p[3]*q[2]+p[4]*q[0]+p[5]*q[1])
 
#define RAYPOINT(result, start, end, dist)   { result[0]=start[0]+d*(end[0]-start[0]); result[1]=start[1]+d*(end[1]-start[1]); result[2]=start[2]+d*(end[2]-start[2]); }
 
#define SMALL_NUM   0.00000001
 

Functions

int P_triRay (double *p, double *d, double *v0, double *v1, double *v2, Vec3D &I)
 
int c2005 (const RAYTRI *rt)
 
int intersect_ray_triangle (const Vec3D &RP0, const Vec3D &dir, Vec3D &TV0, Vec3D &TV1, Vec3D &TV2, Vec3D &I)
 
int intersect_triangle (double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v)
 
int intersect_triangle1 (double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v)
 
int intersect_triangle2 (double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v)
 
int intersect_triangle3 (double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v)
 
bool rayIntersectsTriangle (double *p, double *d, double *v0, double *v1, double *v2, Vec3D &I)
 

Macro Definition Documentation

#define CROSS (   dest,
  v1,
  v2 
)
Value:
dest[0]=v1[1]*v2[2]-v1[2]*v2[1]; \
dest[1]=v1[2]*v2[0]-v1[0]*v2[2]; \
dest[2]=v1[0]*v2[1]-v1[1]*v2[0];

Definition at line 11 of file Rocprop/src/ray-triangle.C.

Referenced by c2005(), intersect_triangle(), intersect_triangle1(), intersect_triangle2(), and intersect_triangle3().

#define DOT (   v1,
  v2 
)    (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2])
#define EPSILON   0.000001
#define PLUCKER (   pline,
  pt1,
  pt2 
)
Value:
pline[0] = pt1[0]*pt2[1] - pt2[0]*pt1[1]; \
pline[1] = pt1[0]*pt2[2] - pt2[0]*pt1[2]; \
pline[2] = pt1[0] - pt2[0]; \
pline[3] = pt1[1]*pt2[2] - pt2[1]*pt1[2]; \
pline[4] = pt1[2] - pt2[2]; \
pline[5] = pt2[1] - pt1[1];

Definition at line 20 of file Rocprop/src/ray-triangle.C.

Referenced by P_triRay().

#define RAYPOINT (   result,
  start,
  end,
  dist 
)    { result[0]=start[0]+d*(end[0]-start[0]); result[1]=start[1]+d*(end[1]-start[1]); result[2]=start[2]+d*(end[2]-start[2]); }

Definition at line 28 of file Rocprop/src/ray-triangle.C.

Referenced by c2005().

#define SIDE (   p,
  q 
)    (p[0]*q[4]+p[1]*q[5]+p[2]*q[3]+p[3]*q[2]+p[4]*q[0]+p[5]*q[1])

Definition at line 27 of file Rocprop/src/ray-triangle.C.

Referenced by P_triRay().

#define SMALL_NUM   0.00000001

Definition at line 268 of file Rocprop/src/ray-triangle.C.

Referenced by intersect_ray_triangle().

#define SUB (   dest,
  v1,
  v2 
)
Value:
dest[0]=v1[0]-v2[0]; \
dest[1]=v1[1]-v2[1]; \
dest[2]=v1[2]-v2[2];

Definition at line 16 of file Rocprop/src/ray-triangle.C.

Referenced by c2005(), intersect_triangle(), intersect_triangle1(), intersect_triangle2(), and intersect_triangle3().

Function Documentation

int c2005 ( const RAYTRI rt)

Definition at line 210 of file Rocprop/src/ray-triangle.C.

References CROSS, d, DOT, RAYTRI::end, nvc::norm(), RAYTRI::org, RAYPOINT, SUB, v, RAYTRI::v0, RAYTRI::v1, and RAYTRI::v2.

211 {
212  float e0[3],e1[3],e2[3],norm[3],point[3],v[3],av[3],vb[3],vc[3];
213  SUB(e0, rt->v1, rt->v0);
214  SUB(e1, rt->v2, rt->v0);
215  CROSS(norm,e0,e1);
216 
217  float pd = DOT(norm, rt->v0);
218 
219  float signSrc = DOT(norm, rt->org) -pd;
220  float signDst = DOT(norm, rt->end) -pd;
221 
222  if(signSrc*signDst > 0.0) return 0;
223 
224  float d = signSrc/(signSrc - signDst);
225 
226  RAYPOINT(point, rt->org, rt->end,d);
227  SUB(v, point, rt->v0);
228  CROSS(av,e0,v);
229  CROSS(vb,v,e1);
230 
231  if(DOT(av,vb) >= 0.0)
232  {
233  SUB(e2, rt->v1, rt->v2);
234  SUB(v, point, rt->v1);
235  CROSS(vc,v,e2);
236  if(DOT(av,vc) >= 0.0) return 1;
237  }
238  return 0;
239 }
const NT & d
T norm(const NVec< DIM, T > &v)
#define DOT(v1, v2)
#define SUB(dest, v1, v2)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
#define RAYPOINT(result, start, end, dist)
#define CROSS(dest, v1, v2)

Here is the call graph for this function:

int intersect_ray_triangle ( const Vec3D &  RP0,
const Vec3D &  dir,
Vec3D &  TV0,
Vec3D &  TV1,
Vec3D &  TV2,
Vec3D &  I 
)

Definition at line 278 of file Rocprop/src/ray-triangle.C.

References nvc::cross(), n, s, SMALL_NUM, and v.

280 {
281  Vec3D u, v, n; // triangle vectors
282  Vec3D w0, w; // ray vectors
283  double r, a, b; // params to calc ray-plane intersect
284 
285  // get triangle edge vectors and plane normal
286  u = TV1 - TV0;
287  v = TV2 - TV0;
288  n = cross(u,v); // cross product
289  if (n == Vec3D(0,0,0)) // triangle is degenerate
290  return 0; // do not deal with this case
291 
292  //dir = RP1 - RP0; // ray direction vector
293  w0 = RP0 - TV0;
294  a = -1.0*(n*w0);
295  b = n*dir;
296  if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane
297  if (a != 0) // ray lies in triangle plane
298  //return 1;
299  //else
300  return 0; // ray disjoint from plane
301  }
302 
303  // get intersect point of ray with triangle plane
304  r = a / b;
305  if (r < 0.0) // ray goes away from triangle
306  return 0; // => no intersect
307  if (r > 1.0) // ray goes away from triangle
308  return 0; //change by prateek, 0 instead of 3
309  // for a segment, also test if (r > 1.0) => no intersect
310 
311  I = RP0 + (r * dir); // intersect point of ray and plane
312 
313  // is I inside T?
314  float uu, uv, vv, wu, wv, D;
315  uu = (u*u);
316  uv = (u*v);
317  vv = (v*v);
318  w = I - TV0;
319  wu = w*u;
320  wv = w*v;
321  D = (uv * uv) -( uu * vv);
322 
323  // get and test parametric coords
324  float s, t;
325  s = (uv * wv - vv * wu) / D;
326  if (s < 0.0 || s > 1.0) // I is outside T
327  return 0;
328  t = (uv * wu - uu * wv) / D;
329  if (t < 0.0 || (s + t) > 1.0) // I is outside T
330  return 0;
331 
332  return 1; // I is in T
333 }
NVec< 3, T > cross(const NVec< 3, T > &u, const NVec< 3, T > &v)
double s
Definition: blastest.C:80
NVec< 3, double > Vec3D
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
const NT & n
#define SMALL_NUM

Here is the call graph for this function:

int intersect_triangle ( double  orig[3],
double  dir[3],
double  vert0[3],
double  vert1[3],
double  vert2[3],
double *  t,
double *  u,
double *  v 
)

Definition at line 339 of file Rocprop/src/ray-triangle.C.

References CROSS, Mesquite::det(), DOT, EPSILON, and SUB.

Referenced by rayIntersectsTriangle().

342 {
343  double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3];
344  double det,inv_det;
345 
346  /* find vectors for two edges sharing vert0 */
347  SUB(edge1, vert1, vert0);
348  SUB(edge2, vert2, vert0);
349 
350  /* begin calculating determinant - also used to calculate U parameter */
351  CROSS(pvec, dir, edge2);
352 
353  /* if determinant is near zero, ray lies in plane of triangle */
354  det = DOT(edge1, pvec);
355 
356  if (det > -EPSILON && det < EPSILON)
357  return 0;
358  inv_det = 1.0 / det;
359 
360  /* calculate distance from vert0 to ray origin */
361  SUB(tvec, orig, vert0);
362 
363  /* calculate U parameter and test bounds */
364  *u = DOT(tvec, pvec) * inv_det;
365  if (*u < 0.0 || *u > 1.0)
366  return 0;
367 
368  /* prepare to test V parameter */
369  CROSS(qvec, tvec, edge1);
370 
371  /* calculate V parameter and test bounds */
372  *v = DOT(dir, qvec) * inv_det;
373  if (*v < 0.0 || *u + *v > 1.0)
374  return 0;
375 
376  /* calculate t, ray intersects triangle */
377  *t = DOT(edge2, qvec) * inv_det;
378 
379  if(*t<0 || *t>1)
380  return 0; //enforce that ray is line segment
381 
382  return 1;
383 }
#define DOT(v1, v2)
#define SUB(dest, v1, v2)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
#define EPSILON
double det(const Matrix3D &A)
#define CROSS(dest, v1, v2)

Here is the call graph for this function:

Here is the caller graph for this function:

int intersect_triangle1 ( double  orig[3],
double  dir[3],
double  vert0[3],
double  vert1[3],
double  vert2[3],
double *  t,
double *  u,
double *  v 
)

Definition at line 388 of file Rocprop/src/ray-triangle.C.

References CROSS, Mesquite::det(), DOT, EPSILON, and SUB.

391 {
392  double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3];
393  double det,inv_det;
394 
395  /* find vectors for two edges sharing vert0 */
396  SUB(edge1, vert1, vert0);
397  SUB(edge2, vert2, vert0);
398 
399  /* begin calculating determinant - also used to calculate U parameter */
400  CROSS(pvec, dir, edge2);
401 
402  /* if determinant is near zero, ray lies in plane of triangle */
403  det = DOT(edge1, pvec);
404 
405  if (det > EPSILON)
406  {
407  /* calculate distance from vert0 to ray origin */
408  SUB(tvec, orig, vert0);
409 
410  /* calculate U parameter and test bounds */
411  *u = DOT(tvec, pvec);
412  if (*u < 0.0 || *u > det)
413  return 0;
414 
415  /* prepare to test V parameter */
416  CROSS(qvec, tvec, edge1);
417 
418  /* calculate V parameter and test bounds */
419  *v = DOT(dir, qvec);
420  if (*v < 0.0 || *u + *v > det)
421  return 0;
422 
423  }
424  else if(det < -EPSILON)
425  {
426  /* calculate distance from vert0 to ray origin */
427  SUB(tvec, orig, vert0);
428 
429  /* calculate U parameter and test bounds */
430  *u = DOT(tvec, pvec);
431 /* printf("*u=%f\n",(float)*u); */
432 /* printf("det=%f\n",det); */
433  if (*u > 0.0 || *u < det)
434  return 0;
435 
436  /* prepare to test V parameter */
437  CROSS(qvec, tvec, edge1);
438 
439  /* calculate V parameter and test bounds */
440  *v = DOT(dir, qvec) ;
441  if (*v > 0.0 || *u + *v < det)
442  return 0;
443  }
444  else return 0; /* ray is parallell to the plane of the triangle */
445 
446 
447  inv_det = 1.0 / det;
448 
449  /* calculate t, ray intersects triangle */
450  *t = DOT(edge2, qvec) * inv_det;
451  (*u) *= inv_det;
452  (*v) *= inv_det;
453 
454  return 1;
455 }
#define DOT(v1, v2)
#define SUB(dest, v1, v2)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
#define EPSILON
double det(const Matrix3D &A)
#define CROSS(dest, v1, v2)

Here is the call graph for this function:

int intersect_triangle2 ( double  orig[3],
double  dir[3],
double  vert0[3],
double  vert1[3],
double  vert2[3],
double *  t,
double *  u,
double *  v 
)

Definition at line 459 of file Rocprop/src/ray-triangle.C.

References CROSS, Mesquite::det(), DOT, EPSILON, and SUB.

462 {
463  double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3];
464  double det,inv_det;
465 
466  /* find vectors for two edges sharing vert0 */
467  SUB(edge1, vert1, vert0);
468  SUB(edge2, vert2, vert0);
469 
470  /* begin calculating determinant - also used to calculate U parameter */
471  CROSS(pvec, dir, edge2);
472 
473  /* if determinant is near zero, ray lies in plane of triangle */
474  det = DOT(edge1, pvec);
475 
476  /* calculate distance from vert0 to ray origin */
477  SUB(tvec, orig, vert0);
478  inv_det = 1.0 / det;
479 
480  if (det > EPSILON)
481  {
482  /* calculate U parameter and test bounds */
483  *u = DOT(tvec, pvec);
484  if (*u < 0.0 || *u > det)
485  return 0;
486 
487  /* prepare to test V parameter */
488  CROSS(qvec, tvec, edge1);
489 
490  /* calculate V parameter and test bounds */
491  *v = DOT(dir, qvec);
492  if (*v < 0.0 || *u + *v > det)
493  return 0;
494 
495  }
496  else if(det < -EPSILON)
497  {
498  /* calculate U parameter and test bounds */
499  *u = DOT(tvec, pvec);
500  if (*u > 0.0 || *u < det)
501  return 0;
502 
503  /* prepare to test V parameter */
504  CROSS(qvec, tvec, edge1);
505 
506  /* calculate V parameter and test bounds */
507  *v = DOT(dir, qvec) ;
508  if (*v > 0.0 || *u + *v < det)
509  return 0;
510  }
511  else return 0; /* ray is parallell to the plane of the triangle */
512 
513  /* calculate t, ray intersects triangle */
514  *t = DOT(edge2, qvec) * inv_det;
515  (*u) *= inv_det;
516  (*v) *= inv_det;
517 
518  return 1;
519 }
#define DOT(v1, v2)
#define SUB(dest, v1, v2)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
#define EPSILON
double det(const Matrix3D &A)
#define CROSS(dest, v1, v2)

Here is the call graph for this function:

int intersect_triangle3 ( double  orig[3],
double  dir[3],
double  vert0[3],
double  vert1[3],
double  vert2[3],
double *  t,
double *  u,
double *  v 
)

Definition at line 524 of file Rocprop/src/ray-triangle.C.

References CROSS, Mesquite::det(), DOT, EPSILON, and SUB.

527 {
528  double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3];
529  double det,inv_det;
530 
531  /* find vectors for two edges sharing vert0 */
532  SUB(edge1, vert1, vert0);
533  SUB(edge2, vert2, vert0);
534 
535  /* begin calculating determinant - also used to calculate U parameter */
536  CROSS(pvec, dir, edge2);
537 
538  /* if determinant is near zero, ray lies in plane of triangle */
539  det = DOT(edge1, pvec);
540 
541  /* calculate distance from vert0 to ray origin */
542  SUB(tvec, orig, vert0);
543  inv_det = 1.0 / det;
544 
545  CROSS(qvec, tvec, edge1);
546 
547  if (det > EPSILON)
548  {
549  *u = DOT(tvec, pvec);
550  if (*u < 0.0 || *u > det)
551  return 0;
552 
553  /* calculate V parameter and test bounds */
554  *v = DOT(dir, qvec);
555  if (*v < 0.0 || *u + *v > det)
556  return 0;
557 
558  }
559  else if(det < -EPSILON)
560  {
561  /* calculate U parameter and test bounds */
562  *u = DOT(tvec, pvec);
563  if (*u > 0.0 || *u < det)
564  return 0;
565 
566  /* calculate V parameter and test bounds */
567  *v = DOT(dir, qvec) ;
568  if (*v > 0.0 || *u + *v < det)
569  return 0;
570  }
571  else return 0; /* ray is parallell to the plane of the triangle */
572 
573  *t = DOT(edge2, qvec) * inv_det;
574  (*u) *= inv_det;
575  (*v) *= inv_det;
576 
577  return 1;
578 }
#define DOT(v1, v2)
#define SUB(dest, v1, v2)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
#define EPSILON
double det(const Matrix3D &A)
#define CROSS(dest, v1, v2)

Here is the call graph for this function:

int P_triRay ( double *  p,
double *  d,
double *  v0,
double *  v1,
double *  v2,
Vec3D &  I 
)

Definition at line 56 of file Rocprop/src/ray-triangle.C.

References i, intersect(), PLUCKER, q, SIDE, and x.

58 {
59  int flag = 0;
60  double *q,*L,*e1,*e2,*e3, s1, s2,s3;
61  q = new double[3];
62  for(int i=0;i<3;++i)q[i] = p[i]+d[i];
63 
64  L = new double[6];
65  e1 = new double[6];
66  e2 = new double[6];
67  e3 = new double[6];
68 
69  PLUCKER(L,p,q);
70  PLUCKER(e1,v0,v1);
71  PLUCKER(e2,v1,v2);
72  PLUCKER(e3,v2,v0);
73 
74  s1 = SIDE(L,e1);
75  s2 = SIDE(L,e2);
76  s3 = SIDE(L,e3);
77 
78  if(s1==0.0 && s2==0.0 && s3==0.0)
79  { // co-planar
80  int pts[4][3] = {{0,0,0},{0,1,0},{0,0,1},{1,0,0}};
81  int edge[3] = {0,0,0};
82  int vertex[3] = {0,0,0};
83  int *x,i,intersect=0;
84  double cs1,cs2,cs3;
85  for(i=0;i<4;++i)
86  {
87  PLUCKER(e1,v0,v1);
88  PLUCKER(e2,v1,pts[i]);
89  PLUCKER(e3,pts[i],v0);
90  cs1 = SIDE(L,e1);
91  cs2 = SIDE(L,e2);
92  cs3 = SIDE(L,e3);
93  if(!(cs1==0 && cs2==0 && cs3==0)) break;
94  }
95 
96  x = pts[i];
97 
98  for(i=0;i<3;++i)
99  {
100  if(i==0){
101  PLUCKER(e2,v1,x);
102  PLUCKER(e3,x,v0);
103  cs2 = SIDE(L,e2);
104  cs3 = SIDE(L,e3);
105  } else if(i==1){
106  PLUCKER(e2,v2,x);
107  PLUCKER(e3,x,v1);
108  cs2 = SIDE(L,e2);
109  cs3 = SIDE(L,e3);
110  } else {
111  PLUCKER(e2,v0,x);
112  PLUCKER(e3,x,v2);
113  cs2 = SIDE(L,e2);
114  cs3 = SIDE(L,e3);
115  }
116 
117  if(cs2*cs3<0);
118  else if(cs2*cs3>0)
119  { intersect++;
120  edge[i]++;
121  }
122  else if(cs2==0 && cs3==0)
123  { intersect+=2;
124  edge[i]+=2;
125  break;}
126  else if (cs2==0)
127  {intersect++;
128  vertex[(i+1)-3*((i+1)/3)]++;
129  }
130  else if (cs3==0)
131  {intersect++;
132  vertex[i]++;
133  }
134  }
135  // implement line-line intersect
136  // implement vertex-line intersect
137  if(intersect!=0)
138  {
139  if(intersect<=3){
140  if(vertex[0]!=0 && !flag)
141  {
142  I[0] = v0[0]; I[1]=v0[1]; I[2]=v0[2];
143  flag = 1;
144  }
145  if(vertex[1]!=0 && !flag)
146  {
147  I[0] = v1[0]; I[1]=v1[1]; I[2]=v1[2];
148  flag = 1;
149  }
150  if(vertex[2]!=0 && !flag)
151  {
152  I[0] = v2[0]; I[1]=v2[1]; I[2]=v2[2];
153  flag = 1;
154  }
155  }
156  if(!flag && (edge[0]==1||edge[0]==2) )
157  {
158  I[0]=(v0[0]+v1[0])/2;I[1]=(v0[1]+v1[1])/2;I[2]=(v0[2]+v1[2])/2;
159  flag = 1;
160  }
161  if(!flag && (edge[1]==1||edge[1]==2) )
162  {
163  I[0]=(v1[0]+v2[0])/2;I[1]=(v1[1]+v2[1])/2;I[2]=(v1[2]+v2[2])/2;
164  flag = 1;
165  }
166  if(!flag && (edge[2]==1||edge[2]==2) )
167  {
168  I[0]=(v2[0]+v0[0])/2;I[1]=(v0[1]+v2[1])/2;I[2]=(v0[2]+v2[2])/2;
169  flag = 1;
170  }
171  }
172  } else if ((s1>0 && s2>0 && s3>0) || (s1<0 && s2<0 && s3<0)){
173  double al,be,ga;
174  al = s1/(s1+s2+s3);
175  be = s2/(s1+s2+s3);
176  ga = s3/(s1+s2+s3);
177  for(int i=0;i<3;++i)
178  I[i] = al*v2[i] + be*v0[i] + ga*v1[i];
179  flag = 1;
180  } else if ( s1==0 && s2*s3>0){
181  I[0]=(v0[0]+v1[0])/2;I[1]=(v0[1]+v1[1])/2;I[2]=(v0[2]+v1[2])/2;
182  flag = 1;
183  } else if ( s2==0 && s1*s3>0){
184  I[0]=(v1[0]+v2[0])/2;I[1]=(v1[1]+v2[1])/2;I[2]=(v1[2]+v2[2])/2;
185  flag = 1;
186  } else if ( s3==0 && s1*s2>0){
187  I[0]=(v2[0]+v0[0])/2;I[1]=(v0[1]+v2[1])/2;I[2]=(v0[2]+v2[2])/2;
188  flag = 1;
189  } else if ( s1==0 && s2==0){
190  I[0]=v1[0];I[1]=v1[1];I[2]=v1[2];
191  flag = 1;
192  } else if ( s1==0 && s3==0){
193  I[0]=v0[0];I[1]=v0[1];I[2]=v0[2];
194  flag = 1;
195  } else if ( s2==0 && s3==0){
196  I[0]=v2[0];I[1]=v2[1];I[2]=v2[2];
197  flag = 1;
198  } else
199  flag = 0;
200 
201  delete [] q;
202  delete [] L;
203  delete [] e1;
204  delete [] e2;
205  delete [] e3;
206 
207  return flag;
208 }
const NT & d
void intersect(T_VertexSet s1, T_VertexSet s2, T_VertexSet *inter)
#define SIDE(p, q)
#define PLUCKER(pline, pt1, pt2)
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
NT q

Here is the call graph for this function:

bool rayIntersectsTriangle ( double *  p,
double *  d,
double *  v0,
double *  v1,
double *  v2,
Vec3D &  I 
)

Definition at line 581 of file Rocprop/src/ray-triangle.C.

References intersect_triangle(), j, P_triRay(), and v.

583 {
584  /*Vec3D org(p[0],p[1],p[2]);
585  Vec3D dir(d[0],d[1],d[2]);
586  Vec3D ver0(v0[0],v0[1],v0[2]);
587  Vec3D ver1(v1[0],v1[1],v1[2]);
588  Vec3D ver2(v2[0],v2[1],v2[2]);
589  int result = intersect_ray_triangle(org,dir,ver0,ver1,ver2,I);*/
590 
591  /*RAYTRI * input = new RAYTRI;
592  for(int i =0;i<3;++i)
593  {
594  input->org[i] = p[i];
595  input->dir[i] = d[i];
596  input->v0[i] = v0[i];
597  input->v1[i] = v1[i];
598  input->v2[i] = v2[i];
599  input->end[i] = p[i]+d[i];
600  }
601  int result = c2005(input);*/
602 
603  /*double *t,*u,*v;
604  t = new double;
605  u = new double;
606  v = new double;
607  *t = *u = *v = 0;
608  int result = intersect_triangle(p,d,v0,v1,v2,t,u,v);
609  for(int j=0;j<3;j++)
610  {
611  I[j]=p[j]+ (*t)*d[j];//I[j]=v0[j]+ (*u)*v1[j] + (*v)*v2[j];
612  }*/
613 
614  int result = P_triRay(p,d,v0,v1,v2,I);
615 
616  if(result)
617  { double *t,*u,*v;
618  t = new double;
619  u = new double;
620  v = new double;
621  *t = *u = *v = 0;
622  result = intersect_triangle(p,d,v0,v1,v2,t,u,v);
623  for(int j=0;j<3;j++)
624  {
625  I[j]=p[j]+ (*t)*d[j];
626  }
627  delete t;
628  delete u;
629  delete v;
630  }
631  return result;
632 }
const NT & d
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
j indices j
Definition: Indexing.h:6
int P_triRay(double *p, double *d, double *v0, double *v1, double *v2, Vec3D &I)
int intersect_triangle(double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v)

Here is the call graph for this function: