[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18655] branches/nurbs/blender: A large patch from Laurynas.

Emmanuel Stone emmanuel.stone at gmail.com
Sat Jan 24 22:13:38 CET 2009


Revision: 18655
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18655
Author:   eman
Date:     2009-01-24 22:13:38 +0100 (Sat, 24 Jan 2009)

Log Message:
-----------
A large patch from Laurynas.
Adds support for cyclic surfaces and weights to Degree Elevate.
This is not yet fully hooked up to the UI, still using extra buttons.

Modified Paths:
--------------
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Construct.cpp
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.h
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.h
    branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.cpp
    branches/nurbs/blender/intern/nurbana/intern/NurbanaMath.h
    branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp
    branches/nurbs/blender/source/blender/src/buttons_editing.c
    branches/nurbs/blender/source/blender/src/editcurve.c

Added Paths:
-----------
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Utils.h

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Construct.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Construct.cpp	2009-01-24 18:09:03 UTC (rev 18654)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Construct.cpp	2009-01-24 21:13:38 UTC (rev 18655)
@@ -40,8 +40,10 @@
 
   // Raise Degree of Curves with Lower Order than Max Order
   for (i= 1; i < N; i++)
-    if (objs[i] -> Order(0) < MaxOrder)
-      NURBS_Degree::Elevate(objs[i],MaxOrder-objs[i] -> Order(0),0);
+    if (objs[i] -> Order(0) < MaxOrder) {
+      int inc[] = {MaxOrder-objs[i] -> Order(0), 0};
+      NURBS_Degree::Elevate(objs[i], inc);
+    }
 
   // Determine largest Knot value in each Curves Knot Vector
   MaxKnot= 0;
@@ -73,7 +75,7 @@
   for (i= 1; i < N; i++) {
     NURBS_Knot::Difference(objs[i] -> KnotVector(0), objs[i] -> Length(0)+objs[i] -> Order(0),KVfnl,KVlen,Diff,Difflen);
     if (Difflen)
-      NURBS_Knot::Insert(objs[i],Diff,Difflen,0);
+      NURBS_Knot::Refine(objs[i],Diff,Difflen,0);
   } //eof
 
   // Copy new Points, KnotVector, etc... into obj1
@@ -81,8 +83,8 @@
   objs[0] -> Order(0,objs[1] -> Order(0));
   objs[0] -> Order(1,V);
 
-  objs[0] -> Length(0,objs[1] -> Length(0));
-  objs[0] -> Length(1,N-1);
+  objs[0] -> Length(0, objs[1] -> Length(0));
+  objs[0] -> Length(1, N - 1);
 
 
   // Assign new KnotVector

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp	2009-01-24 18:09:03 UTC (rev 18654)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp	2009-01-24 21:13:38 UTC (rev 18655)
@@ -1,241 +1,237 @@
 #include "NURBS_Degree.h"
 
 
-void NURBS_Degree::Elevate(Object_NURBS *obj, int Uinc, int Vinc) {
-	int		Npts,Order,Degree,Curve,UV,Inc,ph,mpi,mh,kind,r,a,b,cind,mul,oldr,lbz,rbz,s,save;
-	int		i,j,k,first,last,tr,kj,FnlLU,FnlLV,Length;
+void NURBS_Degree::Elevate(Object_NURBS *obj, int inc[]) {
+	int newLength[2];
+	const int maxOrder = NurbanaMath::Max(obj -> Order(0), obj -> Order(1));
+	for (int uv = 0; uv <= 1; uv++) {
+		newLength[uv] = obj -> Length(uv) + inc[uv] * NURBS_Knot::countNonZeroKnots(obj -> KnotVector(uv), obj -> Length(uv), obj -> Order(uv), obj -> Cyclic(uv));
+		//order must be set before setting new lengths to get buffers of right size 
+		obj -> Order(uv, obj -> Order(uv) + inc[uv]);
+	}
+	obj -> SetLengthRef(newLength[0], newLength[1]);
 
-	nbReal		ua,ub,alf,gam,bet,temp;
-	nbReal		*Uh,*Coef,*Coefb,*FnlKVU,*FnlKVV;
+	const int maxT = NurbanaMath::Max(inc[0], inc[1]);
+	const int maxCurveLength = NurbanaMath::Max(newLength[0], newLength[1]);
+	const int uhSize = maxCurveLength + maxOrder + 3 * (maxOrder + maxT);
+	nbReal *const bufferUh = (nbReal* ) MEM_callocN(sizeof(*bufferUh) * uhSize, "NURBS_Degree::Elevate Uh"); 
+	nbReal *Uh = NULL;
+	//TODO next three could be stack arrays as max order in blender is 6
+	nbReal4 *const bpts = (nbReal4*) MEM_callocN(sizeof(*bpts) * maxOrder, "NURBS_Degree::Elevate bpts");
+	nbReal4 *const ebpts = (nbReal4*) MEM_callocN(sizeof(*ebpts) * (maxOrder + 1), "NURBS_Degree::Elevate ebpts");
+	nbReal4 *const nextbpts = (nbReal4*)MEM_callocN(sizeof(*nextbpts) * maxOrder,"NURBS_Degree::Elevate Nextbpts");
 
-	Point3d	*Nextbpts,*Qw,*Pts,*FnlPts,*bpts,*ebpts,*ctlPts,*newCtlPts;
+	nbReal *const coef = (nbReal*) MEM_callocN(sizeof(*coef) * (maxOrder + maxT) * maxOrder, "NURBS_Degree::Elevate coef");
+	// 2 * order are for clamping(in case it is needed) or for cyclics (one for clamping second for unwrapping)
+	const int maxKnotVectSize = NurbanaMath::Max(newLength[0], newLength[1]) + 3 * maxOrder;
+	nbReal *const bufferKnots = (nbReal*) MEM_callocN(sizeof(*bufferKnots) * maxKnotVectSize, "NURBS_Degree::Elevate bufferknots");
+	nbReal *const unwrappedKnots = (nbReal*) MEM_callocN(sizeof(*bufferKnots) * maxKnotVectSize, "NURBS_Degree::Elevate bufferUnwrappedKnots");
+	nbReal *const Coefb = (nbReal*)MEM_callocN(sizeof(*Coefb) * maxOrder,"NURBS_Degree::Elevate Coefb");
+	//
+	nbReal4 *const bufferQw = (nbReal4*) MEM_callocN(sizeof(nbReal4) * (maxCurveLength + maxOrder * 4),"NURBS_Degree::Elevate Qw");
+	nbReal4 *const bufferPts = (nbReal4*) MEM_callocN(sizeof(nbReal4) * (maxCurveLength + maxOrder * 2),"NURBS_Degree::Elevate Pts");
+	Point3d *const ctlPts = obj -> CtlPts();
 
-	int pntsU, pntsV, orderU, orderV, newPntsU, newPntsV;
+	for(int uv = 1; uv >= 0; uv--) {
+		const int t = inc[uv];
 
-	ctlPts = obj->CtlPts();
-	pntsU = obj->Length(0);
-	pntsV = obj->Length(1);
-	orderU = obj->Order(0);
-	orderV = obj->Order(1);
+		if(t) {
+			nbReal4 *initPts = bufferPts;
+        	nbReal *const originalKnts = obj -> KnotVector(uv), *refinedKnts = originalKnts;
+			const bool cyclic = obj -> Cyclic(uv);
+			const int curveCount = obj -> Length(!uv);
+			const int Npts = obj -> Length(uv);
+			const int order = obj -> Order(uv) - t;
+			const int degree = order - 1;
+			const int ph = degree + t;
+			const int nextCp = uv ? newLength[0] : 1;
+			const int nextCurve = uv ? 1 : newLength[0];
+			nbReal *const Uh = bufferUh + order;
+			int pointsInBuffer = Npts;
 
-	// Memory Allocation
-	int newCtlPtsSize = (pntsU+(pntsU-(orderU-1))*Uinc)*(pntsV+(pntsV-(orderV-1)));
+			genBezElevationCoefs(degree, t, coef);
 
-	newPntsU = obj -> Length(0)+(obj -> Length(0)-(orderU-1))*Uinc;
-	newPntsV = pntsV+(pntsV-(orderV-1))*Vinc;
-	newCtlPts = (Point3d*)MEM_callocN(sizeof(Point3d)*newPntsU*newPntsV,"NURBS_Degree::Elevate newCtlPts");
+			//Knots that will be inserted to clamp curves 
+			nbReal frstInsKnot, lastInsKnot;
+			int frstInsIndex = degree;/* value is assingned to affect inicialization of "knots" bellow for clamped(for these knot vect doesnt change)*/
+			int frstInsNum = 0;
+			int lastInsNum = 0;
+            int unclOffset = 0;
 
-	// memcpy FIXME eman
-	for(i=0;i<pntsU;i++)
-		for(j=0;j<pntsV;j++)
-			newCtlPts[i+(j*pntsU)] = ctlPts[i+(j*pntsU)];
 
-	UV = (orderU > orderV) ? orderU : orderV;
-	bpts = (Point3d*)MEM_callocN(sizeof(Point3d)*64,"NURBS_Degree::Elevate bpts"); //FIXME CHECKME 64???
-	Coefb = (nbReal*)MEM_callocN(sizeof(nbReal)*UV,"NURBS_Degree::Elevate Coefb");
-	Nextbpts = (Point3d*)MEM_callocN(sizeof(Point3d)*UV,"NURBS_Degree::Elevate Nextbpts");
+			int knotMult = NURBS_Knot::getFwdKnotMultiplicity(originalKnts, 0, Npts, order, cyclic);
+			if (cyclic) {
+				if (knotMult < degree) {
+					frstInsNum = degree - knotMult;
+					refinedKnts = bufferKnots + degree;// shift beginning of buffer to reserve space for unwrapping
+					frstInsKnot = originalKnts[0];
+					frstInsIndex = degree - frstInsNum - 1;
+					NURBS_Knot::insertKnot(originalKnts, refinedKnts, frstInsKnot, frstInsIndex, frstInsNum, Npts, order, cyclic);
+					pointsInBuffer += frstInsNum;
+				}
+			} else {
+				if (knotMult < order) {
+					frstInsNum = degree;
+//					int scndKnot = degree - frstInsNum;
+//					scndKnot = degree - NURBS_Knot::getFwdKnotMultiplicity(originalKnts, scndKnot, Npts, order, false);
+//					frstInsNum++;
+					refinedKnts = bufferKnots;// shift beginning of buffer to reserve space for clamping
+					//copy hidden knots before knot vector
+					for (int i = 0; i < frstInsNum; i++)
+						refinedKnts[i] = originalKnts[0];
+					memcpy(refinedKnts + frstInsNum, originalKnts, sizeof(*refinedKnts) * (Npts + order));
+					initPts += frstInsNum;
+					frstInsIndex = degree - frstInsNum;
+					unclOffset = order + 2 * t;
+					pointsInBuffer += frstInsNum;
+				}
+			}
 
-	UV = (orderU+Uinc > orderV+Vinc) ? orderU+Uinc : orderV+Vinc;
-	ebpts = (Point3d*)MEM_callocN(sizeof(Point3d)*64,"NURBS_Degree::Elevate ebpts");
-	UV *= (orderU > orderV) ? orderU : orderV;
-	Coef = (nbReal*)MEM_callocN(sizeof(nbReal)*(UV),"NURBS_Degree::Elevate Coef");
-	
-	UV = (pntsU+(pntsU-(orderU-1))*Uinc) > (pntsV+(pntsV-(orderV-1))*Vinc) ? pntsU+(pntsU-(orderU-1))*Uinc : pntsV+(pntsV-(orderV-1))*Vinc;
-	Qw = (Point3d*)MEM_callocN(sizeof(Point3d)*UV,"NURBS_Degree::Elevate Qw");
-	Pts = (Point3d*)MEM_callocN(sizeof(Point3d)*UV,"NURBS_Degree::Elevate Pts");
+			//fix last curve point to be clamped (if cyclic it will be fixed in following "if")
+			if (!cyclic) {
+				knotMult = NURBS_Knot::getKnotMultiplicity(originalKnts, Npts + degree, Npts, order, cyclic);
+				if (knotMult < degree) {
+					lastInsNum = degree - knotMult;
+					if (refinedKnts == originalKnts) {
+					    refinedKnts = bufferKnots;
+					    memcpy(refinedKnts + frstInsNum, originalKnts, sizeof(*refinedKnts) * (Npts + order + frstInsNum));
+					}
+					pointsInBuffer += lastInsNum;
+					//copy hidden knots after knot vector
+					for (int i = 0; i < lastInsNum; i++)
+						refinedKnts[Npts + order + frstInsNum + i] = originalKnts[Npts + degree];
+				}
+			}
 
-	int fnlPtsSize = (pntsU+(pntsU-(orderU-1))*Uinc)*(pntsV+(pntsV-(orderV-1))*Vinc);
-	FnlPts = (Point3d*)MEM_callocN(sizeof(Point3d)*fnlPtsSize,"NURBS_Degree::Elevate FnlPts");
-	FnlKVU = (nbReal*)MEM_callocN(sizeof(nbReal)*(pntsU+(pntsU-(orderU-1))*Uinc+Uinc+orderU),"NURBS_Degree::Elevate FnlKVU");
-	FnlKVV = (nbReal*)MEM_callocN(sizeof(nbReal)*(pntsV+(pntsV-(orderV-1))*Vinc+Vinc+orderV),"NURBS_Degree::Elevate FnlKVV");
-	Uh = (nbReal*)MEM_callocN(sizeof(nbReal)*((pntsU+(pntsU-(orderU-1))*Uinc+Uinc+orderU) > (pntsV+(pntsV-(orderV-1))*Vinc+Vinc+orderV) ? pntsU+(pntsU-(orderU-1))*Uinc+Uinc+orderU : pntsV+(pntsV-(orderV-1))*Vinc+Vinc+orderV),"NURBS_Degree::Elevate Uh");
+			if (cyclic) {
+				NURBS_Knot::unwrapCyclicKnotV(refinedKnts, refinedKnts, Npts + frstInsNum + lastInsNum, order);
+				NURBS_Knot::unwrapCyclicKnotV(originalKnts, unwrappedKnots + degree, Npts, order);
+				pointsInBuffer += degree;
+				initPts += degree;
+			}
 
-	for(UV = 1; UV >= 0; UV--) { 
-			Inc = UV ? Vinc : Uinc;
+            // Curve loop
+			int curve = 0;
+			for(Point3d* curveStart = ctlPts; curve < curveCount; curve++, curveStart += nextCurve) {
+				int curveLength = Npts;
+				nbReal4* pts = initPts;
+				nbReal4* Qw = bufferQw;
+				const nbReal *const knots = refinedKnts + frstInsIndex - (degree - frstInsNum);
+				int kIndex = ph + 1; 
+				int r = -1;
+				int oldr;
+				int a = degree;
+				int b = a + 1;
+				int cind = 1;
+				nbReal ua = knots[a];
+				nbReal ub;
 
-		if(Inc) {
-			Npts = obj -> Length(UV);
-			Order = obj -> Order(UV);
-			Degree = Order-1;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list