Revision: 51695
          http://brlcad.svn.sourceforge.net/brlcad/?rev=51695&view=rev
Author:   phoenixyjll
Date:     2012-07-28 04:25:05 +0000 (Sat, 28 Jul 2012)
Log Message:
-----------
Calculate the intersection curves in UV parameter spaces, and test them with 
the brep command.

Modified Paths:
--------------
    brlcad/trunk/src/librt/opennurbs_ext.cpp
    brlcad/trunk/src/librt/opennurbs_ext.h
    brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp

Modified: brlcad/trunk/src/librt/opennurbs_ext.cpp
===================================================================
--- brlcad/trunk/src/librt/opennurbs_ext.cpp    2012-07-27 23:54:26 UTC (rev 
51694)
+++ brlcad/trunk/src/librt/opennurbs_ext.cpp    2012-07-28 04:25:05 UTC (rev 
51695)
@@ -2971,14 +2971,19 @@
            m_children[i] = new Subsurface();
        ON_Surface *temp_surf1 = NULL, *temp_surf2 = NULL;
        ON_BOOL32 ret = true;
-       ret = ((ON_NurbsSurface*)m_surf)->Split(0, m_u.Mid(), temp_surf1, 
temp_surf2);
-       if (!ret)
+       ret = m_surf->Split(0, m_u.Mid(), temp_surf1, temp_surf2);
+       if (!ret) {
+           delete temp_surf1;
+           delete temp_surf2;
            return -1;
+       }
 
        ret = temp_surf1->Split(1, m_v.Mid(), m_children[0]->m_surf, 
m_children[1]->m_surf);
        delete temp_surf1;
-       if (!ret)
+       if (!ret) {
+           delete temp_surf2;
            return -1;
+       }
        m_children[0]->m_u = ON_Interval(m_u.Min(), m_u.Mid());
        m_children[0]->m_v = ON_Interval(m_v.Min(), m_v.Mid());
        m_children[0]->SetBBox(m_children[0]->m_surf->BoundingBox());
@@ -3026,7 +3031,9 @@
 int
 surface_surface_intersection(const ON_Surface* surfA,
                             const ON_Surface* surfB,
-                            ON_SimpleArray<ON_NurbsCurve*> &intersect,
+                            ON_SimpleArray<ON_NurbsCurve*> &intersect3d,
+                            ON_SimpleArray<ON_NurbsCurve*> &intersect_uv2d,
+                            ON_SimpleArray<ON_NurbsCurve*> &intersect_st2d,
                             double max_dis,
                             double)
 {
@@ -3249,7 +3256,7 @@
     }
     std::sort(ptpairs.begin(), ptpairs.end());
 
-    std::vector<ON_Polyline*> polylines(curvept.Count());
+    std::vector<ON_SimpleArray<int>*> polylines(curvept.Count());
     int *index = (int*)bu_malloc(curvept.Count() * sizeof(int), "int");
     // index[i] = j means curvept[i] is a startpoint/endpoint of polylines[j]
     int *startpt = (int*)bu_malloc(curvept.Count() * sizeof(int), "int");
@@ -3258,14 +3265,14 @@
 
     // Initialize each polyline with only one point.
     for (int i = 0; i < curvept.Count(); i++) {
-       ON_3dPointArray single;
-       single.Append(curvept[i]);
-       polylines[i] = new ON_Polyline(single);
+       ON_SimpleArray<int> *single = new ON_SimpleArray<int>();
+       single->Append(i);
+       polylines[i] = single;
        index[i] = i;
        startpt[i] = i;
        endpt[i] = i;
     }
-
+    
     // Merge polylines with distance less than max_dis.
     for (unsigned int i = 0; i < ptpairs.size(); i++) {
        int index1 = index[ptpairs[i].indexA], index2 = 
index[ptpairs[i].indexB];
@@ -3273,12 +3280,12 @@
            continue;
        index[startpt[index1]] = index[endpt[index1]] = index1;
        index[startpt[index2]] = index[endpt[index2]] = index1;
-       ON_Polyline *line1 = polylines[index1];
-       ON_Polyline *line2 = polylines[index2];
+       ON_SimpleArray<int> *line1 = polylines[index1];
+       ON_SimpleArray<int> *line2 = polylines[index2];
        if (line1 != NULL && line2 != NULL && line1 != line2) {
-           ON_Polyline *unionline = new ON_Polyline();
-           if ((*line1)[0] == curvept[ptpairs[i].indexA]) {
-               if ((*line2)[0] == curvept[ptpairs[i].indexB]) {
+           ON_SimpleArray<int> *unionline = new ON_SimpleArray<int>();
+           if ((*line1)[0] == ptpairs[i].indexA) {
+               if ((*line2)[0] == ptpairs[i].indexB) {
                    // Case 1: endA -- startA -- startB -- endB
                    line1->Reverse();
                    unionline->Append(line1->Count(), line1->Array());
@@ -3293,7 +3300,7 @@
                    endpt[index1] = endpt[index1];
                }
            } else {
-               if ((*line2)[0] == curvept[ptpairs[i].indexB]) {
+               if ((*line2)[0] == ptpairs[i].indexB) {
                    // Case 3: startA -- endA -- startB -- endB
                    unionline->Append(line1->Count(), line1->Array());
                    unionline->Append(line2->Count(), line2->Array());
@@ -3310,10 +3317,10 @@
            }
            polylines[index1] = unionline;
            polylines[index2] = NULL;
-           if (line1->PointCount() >= 2) {
+           if (line1->Count() >= 2) {
                index[ptpairs[i].indexA] = -1;
            }
-           if (line2->PointCount() >= 2) {
+           if (line2->Count() >= 2) {
                index[ptpairs[i].indexB] = -1;
            }
            delete line1;
@@ -3324,23 +3331,53 @@
     // Generate NURBS curves from the polylines.
     for (unsigned int i = 0; i < polylines.size(); i++) {
        if (polylines[i] != NULL) {
-           ON_3dPoint *startpoint = polylines[i]->At(0);
-           ON_3dPoint *endpoint = polylines[i]->At(polylines[i]->Count() - 1);
-           if (startpoint->DistanceTo(*endpoint) < max_dis) {
-               polylines[i]->Append(*startpoint);
+           int startpoint = (*polylines[i])[0];
+           int endpoint = (*polylines[i])[polylines[i]->Count() - 1];
+           if (curvept[startpoint].DistanceTo(curvept[endpoint]) < max_dis) {
+               polylines[i]->Append(startpoint);
            }
+
+           // The intersection curves in the 3d space
            ON_3dPointArray ptarray;
-           ptarray.Append(polylines[i]->Count(), polylines[i]->Array());
+           for (int j = 0; j < polylines[i]->Count(); j++)
+               ptarray.Append(curvept[(*polylines[i])[j]]);
            ON_PolylineCurve curve(ptarray);
            ON_NurbsCurve *nurbscurve = ON_NurbsCurve::New();
            if (curve.GetNurbForm(*nurbscurve)) {
-               intersect.Append(nurbscurve);
+               intersect3d.Append(nurbscurve);
            }
+
+           // The intersection curves in the 2d UV parameter space (surfA)
+           ptarray.Empty();
+           for (int j = 0; j < polylines[i]->Count(); j++) {
+               ON_2dPoint &pt2d = curveuv[(*polylines[i])[j]];
+               ptarray.Append(ON_3dPoint(pt2d.x, pt2d.y, 0.0));
+           }
+           curve = ON_PolylineCurve(ptarray);
+           curve.ChangeDimension(2);
+           nurbscurve = ON_NurbsCurve::New();
+           if (curve.GetNurbForm(*nurbscurve)) {
+               intersect_uv2d.Append(nurbscurve);
+           }
+
+           // The intersection curves in the 2d UV parameter space (surfB)
+           ptarray.Empty();
+           for (int j = 0; j < polylines[i]->Count(); j++) {
+               ON_2dPoint &pt2d = curvest[(*polylines[i])[j]];
+               ptarray.Append(ON_3dPoint(pt2d.x, pt2d.y, 0.0));
+           }
+           curve = ON_PolylineCurve(ptarray);
+           curve.ChangeDimension(2);
+           nurbscurve = ON_NurbsCurve::New();
+           if (curve.GetNurbForm(*nurbscurve)) {
+               intersect_st2d.Append(nurbscurve);
+           }
+
            delete polylines[i];
        }
     }
-
-    bu_log("Segments: %d\n", intersect.Count());
+    
+    bu_log("Segments: %d\n", intersect3d.Count());
     bu_free(index, "int");
     bu_free(startpt, "int");
     bu_free(endpt, "int");

Modified: brlcad/trunk/src/librt/opennurbs_ext.h
===================================================================
--- brlcad/trunk/src/librt/opennurbs_ext.h      2012-07-27 23:54:26 UTC (rev 
51694)
+++ brlcad/trunk/src/librt/opennurbs_ext.h      2012-07-28 04:25:05 UTC (rev 
51695)
@@ -1570,7 +1570,9 @@
 
 extern int surface_surface_intersection(const ON_Surface* surfA,
                                        const ON_Surface* surfB,
-                                       ON_SimpleArray<ON_NurbsCurve*> 
&intersect,
+                                       ON_SimpleArray<ON_NurbsCurve*> 
&intersect3dy,
+                                       ON_SimpleArray<ON_NurbsCurve*> 
&intersect_uv2d,
+                                       ON_SimpleArray<ON_NurbsCurve*> 
&intersect_st2d,
                                        double max_dis = 0.0,
                                        double tolerance = 1.0e-3);
 

Modified: brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp       2012-07-27 
23:54:26 UTC (rev 51694)
+++ brlcad/trunk/src/librt/primitives/brep/brep_debug.cpp       2012-07-28 
04:25:05 UTC (rev 51695)
@@ -2567,6 +2567,8 @@
     ON_NurbsSurface surf1;
     ON_NurbsSurface surf2;
     ON_SimpleArray<ON_NurbsCurve*> curve;
+    ON_SimpleArray<ON_NurbsCurve*> curve_uv;
+    ON_SimpleArray<ON_NurbsCurve*> curve_st;
 
     if (i < 0 || i >= brep1->m_S.Count() || j < 0 || j >= brep2->m_S.Count()) {
        bu_log("Out of range: \n");
@@ -2578,7 +2580,7 @@
     brep1->m_S[i]->GetNurbForm(surf1);
     brep2->m_S[j]->GetNurbForm(surf2);
 
-    if (brlcad::surface_surface_intersection(&surf1, &surf2, curve, max_dis)) {
+    if (brlcad::surface_surface_intersection(&surf1, &surf2, curve, curve_uv, 
curve_st, max_dis)) {
        bu_log("Intersection failed\n");
        return -1;
     }
@@ -2590,6 +2592,34 @@
        delete curve[k];
     }
 
+    /* plot the returned 2d curves in UV parameter spaces */
+    for (int k = 0; k < curve_uv.Count(); k++) {
+       ON_3dPointArray ptarray3d;
+       for (int l = 0; l < 1000; l++) {
+           ON_3dPoint pt2d = 
curve_uv[k]->PointAt(curve_uv[k]->Domain().ParameterAt(l/1000.0));
+           ON_3dPoint pt3d = surf1.PointAt(pt2d.x, pt2d.y);
+           ptarray3d.Append(ON_3dPoint(pt3d));
+       }
+       ON_PolylineCurve polycurve(ptarray3d);
+       ON_NurbsCurve nurbscurve;
+       polycurve.GetNurbForm(nurbscurve);
+       plotcurve(nurbscurve, vbp, 1000, PEACH);
+       delete curve_uv[k];
+    }
+    for (int k = 0; k < curve_st.Count(); k++) {
+       ON_3dPointArray ptarray3d;
+       for (int l = 0; l < 1000; l++) {
+           ON_3dPoint pt2d = 
curve_st[k]->PointAt(curve_st[k]->Domain().ParameterAt(l/1000.0));
+           ON_3dPoint pt3d = surf2.PointAt(pt2d.x, pt2d.y);
+           ptarray3d.Append(ON_3dPoint(pt3d));
+       }
+       ON_PolylineCurve polycurve(ptarray3d);
+       ON_NurbsCurve nurbscurve;
+       polycurve.GetNurbForm(nurbscurve);
+       plotcurve(nurbscurve, vbp, 1000, DARKVIOLET);
+       delete curve_st[k];
+    }
+
     return 0;
 }
 

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to