[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16737] branches/nurbs/blender: Interim commit, please avert your eyes from the mess ( I promise to clean this all up soon).

Emmanuel Stone emmanuel.stone at gmail.com
Fri Sep 26 06:10:13 CEST 2008


Revision: 16737
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16737
Author:   eman
Date:     2008-09-26 06:10:13 +0200 (Fri, 26 Sep 2008)

Log Message:
-----------
Interim commit, please avert your eyes from the mess (I promise to clean this all up soon).

- Non destructive subdivision mostly working,slight bug in open knots I need to fix
- Re-enabled caching optimisation, surface is only recalculated for portions that could have changed
- Start of dynamic reallocation of tessellation buffer cache (not complete)
- Fixed a problem with Basis function generation for cyclic curves/surfaces

Modified Paths:
--------------
    branches/nurbs/blender/intern/nurbana/extern/nurbana.h
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp
    branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp
    branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp
    branches/nurbs/blender/source/blender/include/butspace.h
    branches/nurbs/blender/source/blender/src/buttons_editing.c
    branches/nurbs/blender/source/blender/src/editcurve.c

Modified: branches/nurbs/blender/intern/nurbana/extern/nurbana.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/extern/nurbana.h	2008-09-26 02:27:59 UTC (rev 16736)
+++ branches/nurbs/blender/intern/nurbana/extern/nurbana.h	2008-09-26 04:10:13 UTC (rev 16737)
@@ -108,6 +108,7 @@
 
 
 
+extern void NRB_ResChanged(NurbanaObj_ptr nop, short tessU, short tessV);
 extern void NRB_SizeChanged(NurbanaObj_ptr nop, int newU, int newV);
 
 extern void NRB_ConvertToPrimitive(NurbanaObj_ptr nop,unsigned char type);

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp	2008-09-26 02:27:59 UTC (rev 16736)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp	2008-09-26 04:10:13 UTC (rev 16737)
@@ -77,37 +77,53 @@
 	else 
 		recalc = (obj -> Change(Change) != Unpts+Vnpts+OrderU+OrderV+TessU+TessV+CyclicU+CyclicV);
 	obj -> Change(Change,Unpts+Vnpts+OrderU+OrderV+TessU+TessV+CyclicU+CyclicV);
-	/*	if(Change)
-	recalc = 1;
-	else
-	recalc = 0;
-	 
-	*/		
-	 recalc = 1;//FIXME
+
+	// recalc = 1;//FIXME
 	// ("recalc: %d\n",recalc);
 
 	// Recalculate Basis Functions
 	if(recalc) {
-//		NURBSBasis(int Order, nbReal t, int npts, int realPts, nbReal *KnotVector, Point3d *cp, nbReal *BasisValues, bool Type) {
-		//printf("obj->tessU=%d, TessU = %d, Order=%d, t=%.3f,npts=%d, realPts=%d, \n",*obj->_TessUV[0], TessU,OrderU, (OrderU-1)*nbReal((Unpts+extraPntsU)-(OrderU-1)) / nbReal(TessU), (Unpts+extraPntsU),Unpts);
-		for(i = 0; i <= TessU; i++) { // FIXME test for Cyclic instead of Periodic?
-			if(obj -> KnotType(0) == NURBS_KV_Periodic) {
-				NURBSBasis(OrderU, (OrderU-1)+i*nbReal((Unpts+extraPntsU)-(OrderU-1)) / nbReal(TessU), (Unpts+extraPntsU),Unpts, obj -> KnotVector(0), obj -> CtlPts(), BasisU[i], 1);
-			} else {//if(obj -> KnotType(0) == NURBS_KV_Open) {
-				NURBSBasis(OrderU, i*nbReal(obj -> KnotVector(0)[(Unpts+extraPntsU)-1+OrderU]) / nbReal(TessU), (Unpts+extraPntsU),Unpts, obj -> KnotVector(0), obj -> CtlPts(), BasisU[i], 1);
-			}
+
+		nbReal endU = (obj -> KnotVector(0)[Unpts + extraPntsU]);
+		nbReal startU = (obj -> KnotVector(0)[(OrderU-1)]);
+		nbReal stepU = (endU - startU)/TessU;
+		nbReal t = startU;
+
+		for(i = 0; i <= TessU; i++) { 
+			NURBSBasis(OrderU, t, (Unpts+extraPntsU),Unpts, obj -> KnotVector(0), obj -> CtlPts(), BasisU[i], 1);
+			t += stepU;
 		}
 
-		for(i = 0; i <= TessV; i++) {
-			if(obj -> KnotType(1) == NURBS_KV_Periodic) {
-				NURBSBasis(OrderV, (OrderV-1)+i*nbReal((Vnpts+extraPntsV)-(OrderV-1)) / nbReal(TessV), (Vnpts+extraPntsV), Vnpts,obj -> KnotVector(1), obj -> CtlPts(), BasisV[i], 1);
-			} else {//if(obj -> KnotType(1) == NURBS_KV_Open) {
-				NURBSBasis(OrderV, i*nbReal(obj -> KnotVector(1)[(Vnpts+extraPntsV)-1+OrderV]) / nbReal(TessV), (Vnpts+extraPntsV), Vnpts,obj -> KnotVector(1), obj -> CtlPts(), BasisV[i], 1);
-			}
+		nbReal endV = (obj -> KnotVector(1)[Vnpts + extraPntsV]);
+		nbReal startV = (obj -> KnotVector(1)[(OrderV-1)]);
+		nbReal stepV = (endV - startV)/TessV;
+		nbReal tv = startV;
+
+		for(i = 0; i <= TessV; i++) { 
+			NURBSBasis(OrderV, tv, (Vnpts+extraPntsV), Vnpts,obj -> KnotVector(1), obj -> CtlPts(), BasisV[i], 1);
+			tv += stepV;
 		}
 	} else {
+		nbReal endU = (obj -> KnotVector(0)[Unpts + extraPntsU]);
+		nbReal startU = (obj -> KnotVector(0)[(OrderU-1)]);
+		nbReal stepU = (endU - startU)/TessU;
+		nbReal t = startU;
 
-		for(i = 0; i <= TessU; i++) {
+		for(i = 0; i <= TessU; i++) { 
+			NURBSBasis(OrderU, t, (Unpts+extraPntsU),Unpts, obj -> KnotVector(0), obj -> CtlPtsOld(), BasisU[i], 1);
+			t += stepU;
+		}
+
+		nbReal endV = (obj -> KnotVector(1)[Vnpts + extraPntsV]);
+		nbReal startV = (obj -> KnotVector(1)[(OrderV-1)]);
+		nbReal stepV = (endV - startV)/TessV;
+		nbReal tv = startV;
+
+		for(i = 0; i <= TessV; i++) { 
+			NURBSBasis(OrderV, tv, (Vnpts+extraPntsV), Vnpts,obj -> KnotVector(1), obj -> CtlPtsOld(), BasisV[i], 1);
+			tv += stepV;
+		}
+		/*for(i = 0; i <= TessU; i++) {
 			if(obj -> KnotType(0) == NURBS_KV_Periodic) { // FIXME eman new is this correct, new and old CtlPts?
 				NURBSBasis(OrderU, (OrderU-1)+i*nbReal((Unpts+extraPntsU)-(OrderU-1))/nbReal(TessU), (Unpts+extraPntsU),Unpts, obj -> KnotVector(0), obj -> CtlPtsOld(), BasisU[i], 1);
 			} else {// if(obj -> KnotType(0) == NURBS_KV_Open) {
@@ -121,7 +137,7 @@
 			} else {// if(obj -> KnotType(1) == NURBS_KV_Open) {
 				NURBSBasis(OrderV, i*nbReal(obj -> KnotVector(1)[(Vnpts+extraPntsV)-1+OrderV])/nbReal(TessV),(Vnpts+extraPntsV), Vnpts, obj -> KnotVector(1), obj -> CtlPts(), BasisV[i], 1);
 			}
-		}
+		}*/
 	}
 
 	// Compute Surface
@@ -769,12 +785,15 @@
 		BasisValues[0] = 1.0;
 		return;
 	}
+	/* this is for float inaccuracy */
+	if(t < KnotVector[0]) t= KnotVector[0];
+	else if(t > KnotVector[Order+npts-1]) t= KnotVector[Order+npts-1];
 	/*printf("int Order=%d, nbReal t=%.5f, int npts=%d, int realPts=%d,  bool Type=%d", Order,  t,  npts,  realPts,Type);
 	printf("Knotvector: ");
 	for(i = 0; i < npts+Order+1; i++)
 		printf("%f, ",KnotVector[i]);
-	printf("\n");
-	printf("CP: ");
+	printf("\n");*/
+	/*printf("CP: ");
 	for(i = 0; i < realPts; i++)
 		printf("%f, ",cp[i]);
 	printf("\n");*/
@@ -790,9 +809,40 @@
 	//temp = (nbReal *)MEM_callocN(sizeof(nbReal)*(npts+Order),"NURBSBasis() temp");
 	temp = (nbReal *)MEM_callocN(sizeof(nbReal)*(npts+Order),"NURBSBasis() temp");
 
-	//	for(i = 0; i < npts+Order-1; i++)
-	for(i = 0; i < npts+Order; i++)
-		temp[i] = (t >= KnotVector[i]) && (t < KnotVector[i+1]) ? 1 : 0;
+	/* this part is order '1' */
+	int o2 = Order + 1;
+	int orderpluspnts= Order+npts;
+	int opp2 = orderpluspnts-1;
+	int i1 = 0;
+	int i2 = 0;
+//	int i;
+	for(i=0;i<opp2;i++) {
+		if(KnotVector[i]!=KnotVector[i+1] && t>= KnotVector[i] && t<=KnotVector[i+1]) {
+			temp[i]= 1.0;
+			i1= i-o2;
+			if(i1<0) i1= 0;
+			i2= i;
+			i++;
+			while(i<opp2) {
+				temp[i]= 0.0;
+				i++;
+			}
+			break;
+		}
+		else temp[i]= 0.0;
+	}
+	temp[i]= 0.0;
+
+	//for(i = 0; i <= npts+Order-1; i++)
+	////for(i = 0; i < npts+Order; i++)
+	//	temp[i] = (t >= KnotVector[i]) && (t < KnotVector[i+1]) ? 1 : 0;
+
+	//printf("temp: ");
+	//for(i = 0; i < npts+Order+1; i++)
+	//	printf("%.2f, ",temp[i]);
+	//printf("\n");
+
+
 		//printf("Knotvector: ");
 		//for(i = 0; i < npts+Order+1; i++)
 		//	printf("%f, ",KnotVector[i]);
@@ -800,41 +850,41 @@
 
 	// Populate N(i,k)
 	
-	for(k = 1; k < Order; k++)
-	//	printf("k = %d ::",k);
+	for(k = 1; k < Order; k++) {
 		for(i = 0; i < (npts+Order)-k; i++) {
 			d = temp[i] ? ((t-KnotVector[i])*temp[i]) / (KnotVector[i+k]-KnotVector[i]) : 0;
 			e = temp[i+1] ? ((KnotVector[i+k+1]-t)*temp[i+1]) / (KnotVector[i+k+1]-KnotVector[i+1]) : 0;
 			temp[i]= d+e;
 			//printf(" %.3f,",i,temp[i]);
 		}
-		//printf("\n");
-		if(t == KnotVector[npts+Order-1]) temp[npts-1] = 1;
+	}
+	//printf("\n");
+	if(t == KnotVector[npts+Order-1]) temp[npts-1] = 1;
 
-		if(Type) {
-			for(i = 0; i < npts; i++)
-				BasisValues[i] = temp[i];
-		} else {
-			sum = 0;
-			for(i = 0; i < npts; i++)
-				//if(i>=realPts)	
-				sum += temp[i]*cp[i%realPts].H;
-			//			else
-			//			sum += temp[i]*cp[i].H;
-			for(i = 0; i < npts ; i++)
-				//	if(i>=realPts)	
-				BasisValues[i] = sum ? (temp[i]*cp[i%realPts].H) / sum : 0;
-			//else
-			//BasisValues[i] = sum ? (temp[i]*cp[i].H) / sum : 0;
+	if(Type) {
+		for(i = 0; i < npts; i++)
+			BasisValues[i] = temp[i];
+	} else {
+		sum = 0;
+		for(i = 0; i < npts; i++)
+			//if(i>=realPts)	
+			sum += temp[i]*cp[i%realPts].H;
+		//			else
+		//			sum += temp[i]*cp[i].H;
+		for(i = 0; i < npts ; i++)
+			//	if(i>=realPts)	
+			BasisValues[i] = sum ? (temp[i]*cp[i%realPts].H) / sum : 0;
+		//else
+		//BasisValues[i] = sum ? (temp[i]*cp[i].H) / sum : 0;
 
-		}
+	}
 
-		//printf("Basis[i]: ");
-		//for(i =0;i<npts;i++)
-		//printf(" %f,",BasisValues[i]);
-		//printf("\n");
+	//printf("Basis[i]: ");
+	//for(i =0;i<npts;i++)
+	//printf(" %f,",BasisValues[i]);
+	//printf("\n");
 
-		MEM_freeN(temp);
+	MEM_freeN(temp);
 }
 
 //

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp	2008-09-26 02:27:59 UTC (rev 16736)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp	2008-09-26 04:10:13 UTC (rev 16737)
@@ -345,16 +345,21 @@
 	int pntsB = obj -> Length(UV);
 	int orderA = obj -> Order(!UV);
 	int orderB = obj -> Order(UV);
-	bool cyclic = obj -> Cyclic(UV);
-	int newLength = KVLen - orderB;
+
+	bool cyclicA = obj -> Cyclic(!UV);
+	bool cyclicB = obj -> Cyclic(UV);
+	int newLength = KVLen - orderB ; // not sure about the -1, but it seems to fix it
+//	int newLengthReal = newLength;
 	//if(obj->Cyclic(UV))
-	if(cyclic){
-		printf("-> cyclic\n");
-		extraPntsA += orderA - 1;
+	if(cyclicB){
+		//extraPntsA += orderA - 1;
 		extraPntsB += orderB - 1;
 
 			newLength -= (orderB - 1);
 	}
+	if(cyclicA){
+		extraPntsA += orderA - 1;
+	}
 	// FIXME UV ? obj -> SetLength(obj -> Length(0),KVLen - obj -> Order(1)) : obj -> SetLength(KVLen - obj -> Order(0),obj -> Length(1));
 	NewPts= (Point3d*)MEM_callocN(sizeof(Point3d)*(newLength)*(pntsA),"_Insert() NewPts");
 	//NewPts= (Point3d*)MEM_callocN(sizeof(Point3d)*(KVLen - obj -> Order(UV))*obj -> Length(!UV),"_Insert() NewPts");
@@ -365,23 +370,28 @@
 	for (i= 0; i < pntsA ; i++) {
 		int i2 = i%pntsA;
 
-		for (n= 0; n < newLength; n++) {
-		//	!UV ? ind1= n+i*(KVLen - orderB) : ind1= i+n*pntsA;
-			!UV ? ind1= n+i2*(newLength) : ind1= i2+n*pntsA;
-			NewPts[ind1].x= NewPts[ind1].y= NewPts[ind1].z= 0;
-			for (k= 0; k < pntsB ; k++) {
+		for (n= 0; n < newLength + extraPntsB; n++) {
+			int ind1normal;
+			int n2 = n % newLength;
+			//!UV ? ind1= n+i*(newLength) : ind1= i+n*(pntsA+extraPntsA);
+			!UV ? ind1normal= n2+i2*(newLength) : ind1normal= i2+n2*(pntsA);
+			//!UV ? ind1= n+i2*(newLength) : ind1= i2+n*pntsA;
+		//	ind1normal = ind1 % newLength;
+			NewPts[ind1normal].x= NewPts[ind1normal].y= NewPts[ind1normal].z= 0;
+			for (k= 0; k < pntsB +extraPntsB; k++) {
 				int k2 = k % pntsB;
-				!UV ? ind2= (k2%pntsB)+i2*pntsB : ind2= i2+(k2%pntsB)*pntsA;
+				int ind2normal;
+				!UV ? ind2normal= k2+i2*pntsB : ind2normal= i2+k2*pntsA;
+				//!UV ? ind2= k+i*(pntsB+extraPntsB) : ind2= i+(k)*(pntsA+extraPntsA);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list