Revision: 55823
          http://sourceforge.net/p/brlcad/code/55823
Author:   starseeker
Date:     2013-06-24 16:16:32 +0000 (Mon, 24 Jun 2013)
Log Message:
-----------
Pull the quad surface split out into its own function.

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp
    brlcad/trunk/src/libbrep/libbrep_brep_tools.h
    brlcad/trunk/src/libbrep/opennurbs_ext.cpp

Modified: brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp
===================================================================
--- brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp     2013-06-24 15:38:39 UTC 
(rev 55822)
+++ brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp     2013-06-24 16:16:32 UTC 
(rev 55823)
@@ -26,6 +26,7 @@
 #include <iostream>
 
 #include "opennurbs.h"
+#include "bu.h"
 
 bool ON_NearZero(double val, double epsilon) {
     return (val > -epsilon) && (val < epsilon);
@@ -259,7 +260,66 @@
     return split;
 }
 
+bool ON_Surface_Quad_Split(
+       const ON_Surface *surf,
+       const ON_Interval& u,
+       const ON_Interval& v,
+       double upt,
+       double vpt,
+       ON_Surface **q0,
+       ON_Surface **q1,
+       ON_Surface **q2,
+       ON_Surface **q3)
+{
+    bool split_success = true;
+    ON_Surface *north = NULL;
+    ON_Surface *south = NULL;
 
+    // upt and vpt must be within their respective domains
+    if (!u.Includes(upt, true) || !v.Includes(vpt, true)) return false;
+
+    // All four output surfaces should be NULL - the point of this function is 
to create them
+    if ((*q0) || (*q1) || (*q2) || (*q3)) {
+       bu_log("ON_Surface_Quad_Split was supplied non-NULL surfaces as output 
targets: q0: %p, q1: %p, q2: %p, q3: %p\n", (*q0), (*q1), (*q2), (*q3));
+       return false;
+    }
+
+    // First, get the north and south pieces
+    split_success = surf->Split(1, vpt, south, north);
+    if (!split_success || !south || !north) {
+       delete south;
+       delete north;
+       return false;
+    }
+
+    // Split the south pieces to get q0 and q1 
+    split_success = south->Split(0, upt, (*q0), (*q1));
+    if (!split_success || !(*q0) || !(*q1)) {
+       delete south;
+       delete north;
+       if (*q0) delete (*q0);
+       if (*q1) delete (*q1);
+       return false;
+    }
+
+    // Split the north pieces to get q2 and q3 
+    split_success = north->Split(0, upt, (*q3), (*q2));
+    if (!split_success || !(*q3) || !(*q2)) {
+       delete south;
+       delete north;
+       if (*q0) delete (*q0);
+       if (*q1) delete (*q1);
+       if (*q2) delete (*q2);
+       if (*q3) delete (*q3);
+       return false;
+    }
+
+    delete south;
+    delete north;
+
+    return true;
+}
+
 // Local Variables:
 // tab-width: 8
 // mode: C++

Modified: brlcad/trunk/src/libbrep/libbrep_brep_tools.h
===================================================================
--- brlcad/trunk/src/libbrep/libbrep_brep_tools.h       2013-06-24 15:38:39 UTC 
(rev 55822)
+++ brlcad/trunk/src/libbrep/libbrep_brep_tools.h       2013-06-24 16:16:32 UTC 
(rev 55823)
@@ -213,6 +213,59 @@
        ON_Surface **result
        );
 
+/**
+  \brief Create four sub-surfaces from a parent surface
+
+  Create four NURBS surfaces that corresponds to subsets
+  of an input surface, as defined by UV intervals and a
+  point within the U and V intervals. 
+ 
+  \verbatim
+     *---------------------*
+     |          |          |
+     |    q3    |    q2    |
+     |          |          |
+   V |----------+----------|
+     |          |          |
+     |    q0    |    q1    |
+     |          |          |
+     *---------------------*
+               U
+
+  + is the point (upt, vpt) that defines the quads
+  * points represent the mins and maxes of the U and V domains
+   
+  \endverbatim
+  
+
+  @param srf parent ON_Surface
+  @param u U interval of parent surface 
+  @param v V interval of parent surface 
+  @param upt U interval point for quad definition 
+  @param upt U interval point for quad definition 
+  @param q0 surface calculated by split algorithm
+  @param q1 surface calculated by split algorithm
+  @param q2 surface calculated by split algorithm
+  @param q3 surface calculated by split algorithm
+
+  @return @c true if surfaces are successfully created, @c false if one or 
more split
+  operations failed, the q* containers are not NULL, or the upt,vpt 
coordinates are
+  not contained within the UV interval.
+*/
+NURBS_EXPORT
+bool ON_Surface_Quad_Split(
+       const ON_Surface *srf,
+       const ON_Interval& u,
+       const ON_Interval& v,
+       double upt,
+       double vpt,
+       ON_Surface **q0,
+       ON_Surface **q1,
+       ON_Surface **q2,
+       ON_Surface **q3
+       );
+
+
 #endif /* __LIBBREP_BREP_TOOLS */
 /** @} */
 

Modified: brlcad/trunk/src/libbrep/opennurbs_ext.cpp
===================================================================
--- brlcad/trunk/src/libbrep/opennurbs_ext.cpp  2013-06-24 15:38:39 UTC (rev 
55822)
+++ brlcad/trunk/src/libbrep/opennurbs_ext.cpp  2013-06-24 16:16:32 UTC (rev 
55823)
@@ -1013,63 +1013,24 @@
        ON_Interval secondu(usplit, u.Max());
        ON_Interval firstv(v.Min(), vsplit);
        ON_Interval secondv(vsplit, v.Max());
+       ON_BoundingBox box = localsurf->BoundingBox();
 
-       ON_Surface *north = NULL;
-       ON_Surface *south = NULL;
        ON_Surface *q2surf = NULL;
        ON_Surface *q3surf = NULL;
        ON_Surface *q1surf = NULL;
        ON_Surface *q0surf = NULL;
 
-       ON_BoundingBox box = localsurf->BoundingBox();
+        bool split = ON_Surface_Quad_Split(localsurf, u, v, usplit, vsplit, 
&q0surf, &q1surf, &q2surf, &q3surf);
 
-       int dir = 1;
-       bool split = localsurf->Split(dir, localsurf->Domain(dir).Mid(), south, 
north);
-
        /* FIXME: this needs to be handled more gracefully */
-       if (!split || !south || !north) {
-           bu_log("DEBUG: Split failure (split:%d, surf1:%p, surf2:%p)\n", 
split, (void *)south, (void *)north);
+       if (!split) {
            delete parent;
            return NULL;
        }
-
-       split = localsurf->Split(dir, vsplit, south, north);
-
-       /* FIXME: this needs to be handled more gracefully */
-       if (!split || !south || !north) {
-           bu_log("DEBUG: Split failure (split:%d, surf1:%p, surf2:%p)\n", 
split, (void *)south, (void *)north);
-           delete parent;
-           return NULL;
-       }
-
-       south->ClearBoundingBox();
-       north->ClearBoundingBox();
-
-       dir = 0;
-       split = south->Split(dir, usplit, q0surf, q1surf);
-
-       /* FIXME: this needs to be handled more gracefully */
-       if (!split || !q0surf || !q1surf) {
-           bu_log("DEBUG: Split failure (split:%d, surf1:%p, surf2:%p)\n", 
split, (void *)q0surf, (void *)q1surf);
-           delete parent;
-           return NULL;
-       }
-
-       delete south;
        q0surf->ClearBoundingBox();
        q1surf->ClearBoundingBox();
-       split = north->Split(dir, usplit, q3surf, q2surf);
-
-       /* FIXME: this needs to be handled more gracefully */
-       if (!split || !q3surf || !q2surf) {
-           bu_log("DEBUG: Split failure (split:%d, surf1:%p, surf2:%p)\n", 
split, (void *)q3surf, (void *)q2surf);
-           delete parent;
-           return NULL;
-       }
-
-       delete north;
+       q2surf->ClearBoundingBox();
        q3surf->ClearBoundingBox();
-       q2surf->ClearBoundingBox();
 
        /*********************************************************************
         * In order to avoid fairly expensive re-calculation of 3d points at

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


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to