Revision: 69060
          http://sourceforge.net/p/brlcad/code/69060
Author:   starseeker
Date:     2016-10-14 15:05:55 +0000 (Fri, 14 Oct 2016)
Log Message:
-----------
Normally this isn't a good idea, but given how embedded rt_in_rpp is in the 
core shotlining logic we break the nmg/librt coupling here by making an nmg 
version of this function to minimize any unintended side effects of things like 
the previous attempt to move rt_in_rpp to libbg.  Once libnmg is a separate 
library we can revisit this, but for now go with the least risk minimal impact 
solution.

Modified Paths:
--------------
    brlcad/trunk/src/librt/primitives/nmg/nmg_inter.c

Modified: brlcad/trunk/src/librt/primitives/nmg/nmg_inter.c
===================================================================
--- brlcad/trunk/src/librt/primitives/nmg/nmg_inter.c   2016-10-14 14:56:02 UTC 
(rev 69059)
+++ brlcad/trunk/src/librt/primitives/nmg/nmg_inter.c   2016-10-14 15:05:55 UTC 
(rev 69060)
@@ -65,9 +65,7 @@
 #include "bn/plot3.h"
 #include "nmg.h"
 #include "rt/nmg.h"
-#include "raytrace.h" /* for rt/calc.h - rt_in_rpp */
 
-
 #define ISECT_NONE 0
 #define ISECT_SHARED_V 1
 #define ISECT_SPLIT1 2
@@ -2002,7 +2000,98 @@
     return discards;
 }
 
+struct nmg_ray {
+    point_t             r_pt;           /**< @brief Point at which ray starts 
*/
+    vect_t              r_dir;          /**< @brief Direction of ray (UNIT 
Length) */
+    fastf_t             r_min;          /**< @brief entry dist to bounding 
sphere */
+    fastf_t             r_max;          /**< @brief exit dist from bounding 
sphere */
+};
 
+
+HIDDEN int
+ray_in_rpp(struct nmg_ray *rp,
+          register const fastf_t *invdir,       /* inverses of rp->r_dir[] */
+          register const fastf_t *min,
+          register const fastf_t *max)
+{
+    register const fastf_t *pt = &rp->r_pt[0];
+    register fastf_t sv;
+#define st sv                   /* reuse the register */
+    register fastf_t rmin = -MAX_FASTF;
+    register fastf_t rmax =  MAX_FASTF;
+
+    /* Start with infinite ray, and trim it down */
+
+    /* X axis */
+    if (*invdir < -SMALL_FASTF) {
+        /* Heading towards smaller numbers */
+        /* if (*min > *pt) miss */
+        if (rmax > (sv = (*min - *pt) * *invdir))
+            rmax = sv;
+        if (rmin < (st = (*max - *pt) * *invdir))
+            rmin = st;
+    }  else if (*invdir > SMALL_FASTF) {
+        /* Heading towards larger numbers */
+        /* if (*max < *pt) miss */
+        if (rmax > (st = (*max - *pt) * *invdir))
+            rmax = st;
+        if (rmin < ((sv = (*min - *pt) * *invdir)))
+            rmin = sv;
+    } else {
+        /*
+         * Direction cosines along this axis is NEAR 0,
+         * which implies that the ray is perpendicular to the axis,
+         * so merely check position against the boundaries.
+         */
+        if ((*min > *pt) || (*max < *pt))
+            return 0;   /* MISS */
+    }
+
+    /* Y axis */
+    pt++; invdir++; max++; min++;
+    if (*invdir < -SMALL_FASTF) {
+        if (rmax > (sv = (*min - *pt) * *invdir))
+            rmax = sv;
+        if (rmin < (st = (*max - *pt) * *invdir))
+            rmin = st;
+    }  else if (*invdir > SMALL_FASTF) {
+        if (rmax > (st = (*max - *pt) * *invdir))
+            rmax = st;
+        if (rmin < ((sv = (*min - *pt) * *invdir)))
+            rmin = sv;
+    } else {
+        if ((*min > *pt) || (*max < *pt))
+            return 0;   /* MISS */
+    }
+
+    /* Z axis */
+    pt++; invdir++; max++; min++;
+    if (*invdir < -SMALL_FASTF) {
+        if (rmax > (sv = (*min - *pt) * *invdir))
+            rmax = sv;
+        if (rmin < (st = (*max - *pt) * *invdir))
+            rmin = st;
+    }  else if (*invdir > SMALL_FASTF) {
+        if (rmax > (st = (*max - *pt) * *invdir))
+            rmax = st;
+        if (rmin < ((sv = (*min - *pt) * *invdir)))
+            rmin = sv;
+    } else {
+        if ((*min > *pt) || (*max < *pt))
+            return 0;   /* MISS */
+    }
+
+    /* If equal, RPP is actually a plane */
+    if (rmin > rmax)
+        return 0;       /* MISS */
+
+    /* HIT.  Only now do rp->r_min and rp->r_max have to be written */
+    rp->r_min = rmin;
+    rp->r_max = rmax;
+    return 1;           /* HIT */
+}
+
+
 /**
  * Construct a nice ray for is->pt, is->dir
  * which contains the line of intersection, is->on_eg.
@@ -2027,7 +2116,7 @@
 int
 nmg_isect_construct_nice_ray(struct nmg_inter_struct *is, struct faceuse *fu2)
 {
-    struct xray line;
+    struct nmg_ray line;
     vect_t invdir;
 
     NMG_CK_INTER_STRUCT(is);
@@ -2039,7 +2128,7 @@
     VINVDIR(invdir, line.r_dir);
 
     /* nmg_loop_g() makes sure there are no 0-thickness faces */
-    if (!rt_in_rpp(&line, invdir, fu2->f_p->min_pt, fu2->f_p->max_pt)) {
+    if (!ray_in_rpp(&line, invdir, fu2->f_p->min_pt, fu2->f_p->max_pt)) {
        /* The edge ray missed the face RPP, nothing to do. */
        if (nmg_debug & DEBUG_POLYSECT) {
            VPRINT("r_pt ", line.r_pt);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to