Revision: 51766
http://brlcad.svn.sourceforge.net/brlcad/?rev=51766&view=rev
Author: phoenixyjll
Date: 2012-08-06 10:30:22 +0000 (Mon, 06 Aug 2012)
Log Message:
-----------
continue working on dividing trimmed surfaces.
Modified Paths:
--------------
brlcad/trunk/src/librt/primitives/brep/brep.cpp
Modified: brlcad/trunk/src/librt/primitives/brep/brep.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/brep/brep.cpp 2012-08-06 01:20:13 UTC
(rev 51765)
+++ brlcad/trunk/src/librt/primitives/brep/brep.cpp 2012-08-06 10:30:22 UTC
(rev 51766)
@@ -3228,7 +3228,11 @@
int
-curve_intersect(const ON_NurbsCurve *curveA, const ON_NurbsCurve *curveB,
ON_3dPointArray *intersect)
+curve_intersect(const ON_NurbsCurve *curveA,
+ const ON_NurbsCurve *curveB,
+ ON_3dPointArray *intersect,
+ ON_SimpleArray<std::pair<int, int> > *CV,
+ ON_2dPointArray *parameter)
{
int countA = curveA->CVCount();
int countB = curveB->CVCount();
@@ -3247,6 +3251,8 @@
continue;
if (tA >= 0.0 && tA <= 1.0 && tB >= 0.0 && tB <= 1.0) {
intersect->Append(lineA.PointAt(tA));
+ CV->Append(std::make_pair(i, j));
+ parameter->Append(ON_2dPoint(tA, tB));
}
}
}
@@ -3254,6 +3260,38 @@
}
+int
+split_curve(ON_NurbsCurve *out1, ON_NurbsCurve *out2, const ON_NurbsCurve
*curve, const int CVindex, const double t)
+{
+ if (out1 == NULL || out2 == NULL)
+ return -1;
+
+ // Split the curve using polyline curves.
+ ON_3dPointArray pts1, pts2;
+ for (int i = 0; i <= CVindex; i++) {
+ ON_3dPoint point;
+ curve->GetCV(i, point);
+ pts1.Append(point);
+ }
+ ON_3dPoint start, end;
+ curve->GetCV(CVindex, start);
+ curve->GetCV(CVindex + 1, end);
+ ON_Line line(start, end);
+ pts1.Append(line.PointAt(t));
+ pts2.Append(line.PointAt(t));
+ for (int i = CVindex + 1; i < curve->CVCount(); i++) {
+ ON_3dPoint point;
+ curve->GetCV(i, point);
+ pts2.Append(point);
+ }
+
+ ON_PolylineCurve poly1(pts1), poly2(pts2);
+ poly1.GetNurbForm(*out1);
+ poly2.GetNurbForm(*out2);
+ return 0;
+}
+
+
struct TrimmedFace {
ON_SimpleArray<ON_NurbsCurve> outerloop;
ON_SimpleArray<ON_NurbsCurve> innerloop;
@@ -3273,9 +3311,11 @@
split_trimmed_face(ON_SimpleArray<TrimmedFace*> &out, const TrimmedFace *in,
const ON_NurbsCurve* curve)
{
ON_SimpleArray<ON_3dPointArray> intersect(in->outerloop.Count());
+ ON_SimpleArray<ON_SimpleArray<std::pair<int, int> > >
CV(in->outerloop.Count());
+ ON_SimpleArray<ON_2dPointArray> parameter(in->outerloop.Count());
int sum = 0;
for (int i = 0; i < in->outerloop.Count(); i++) {
- curve_intersect(&(in->outerloop[i]), curve, &(intersect[i]));
+ curve_intersect(&(in->outerloop[i]), curve, &(intersect[i]), &(CV[i]),
&(parameter[i]));
sum += intersect[i].Count();
}
if (sum == 0) {
@@ -3289,11 +3329,53 @@
TrimmedFace *newface = in->Duplicate();
newface->innerloop.Append(*curve);
out.Append(newface);
+ newface = new TrimmedFace();
+ newface->face = in->face;
+ newface->outerloop.Append(*curve);
+ out.Append(newface);
return 0;
}
}
} else if (sum >= 2) {
// intersect the outerloop (TODO)
+ // Now we only consider sum == 2 and the two intersection points are
+ // not on the same curve of the outer loop.
+ int start = -1;
+ for (int i = 0; i < intersect.Count(); i++) {
+ if (intersect[i].Count() != 0) {
+ start = i;
+ break;
+ }
+ }
+ TrimmedFace *newface = new TrimmedFace();
+ newface->face = in->face;
+ ON_NurbsCurve curve1, curve2;
+ split_curve(&curve1, &curve2, &(in->outerloop[start]),
CV[start][0].first, parameter[start][0][0]);
+ newface->outerloop.Append(curve2);
+ int i;
+ for (i = start + 1; i != start; i = (i+1)%intersect.Count()) {
+ if (intersect[i].Count() == 0) {
+ newface->outerloop.Append(in->outerloop[i]);
+ } else {
+ break;
+ }
+ }
+ ON_NurbsCurve curve3, curve4;
+ split_curve(&curve3, &curve4, &(in->outerloop[i]), CV[i][0].first,
parameter[i][0][0]);
+ newface->outerloop.Append(curve3);
+ newface->outerloop.Append(*curve);
+ out.Append(newface);
+ newface = new TrimmedFace();
+ newface->face = in->face;
+ newface->outerloop.Append(curve4);
+ for (; i != start; i = (i+1)%intersect.Count()) {
+ if (intersect[i].Count() == 0) {
+ newface->outerloop.Append(in->outerloop[i]);
+ }
+ }
+ newface->outerloop.Append(curve1);
+ newface->outerloop.Append(*curve);
+ out.Append(newface);
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