[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16757] branches/nurbs/blender: Added separate tesselation functions for Curves, as they use different resolution (res*length).

Emmanuel Stone emmanuel.stone at gmail.com
Sat Sep 27 00:49:56 CEST 2008


Revision: 16757
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16757
Author:   eman
Date:     2008-09-27 00:49:54 +0200 (Sat, 27 Sep 2008)

Log Message:
-----------
Added separate tesselation functions for Curves, as they use different resolution (res*length).
Fixed bug that was stopping knottype from being updated immediately with incremental optimisation on.
Modified tesselation function to cache selectively (Bevel code is 4D and was causing problems with curves which are 3D)

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_Generate.h
    branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp
    branches/nurbs/blender/source/blender/blenkernel/intern/curve.c

Modified: branches/nurbs/blender/intern/nurbana/extern/nurbana.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/extern/nurbana.h	2008-09-26 21:49:26 UTC (rev 16756)
+++ branches/nurbs/blender/intern/nurbana/extern/nurbana.h	2008-09-26 22:49:54 UTC (rev 16757)
@@ -135,6 +135,8 @@
 extern nbReal* NRB_getIsoPoints(NurbanaObj_ptr nop, nbReal* buffer);
 
 extern nbReal* NRB_GenerateSurface(NurbanaObj_ptr nop, nbReal* buffer, int dim );
+nbReal* NRB_GenerateCurve(NurbanaObj_ptr nop, nbReal* buffer, int dim, int res);
+
 extern nbReal3_ptr NRB_GenerateNormals(NurbanaObj_ptr nop);
 
 extern void NRB_Subdivide(NurbanaObj_ptr nop,nbReal subdividePositionU, nbReal subdividePositionV);

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp	2008-09-26 21:49:26 UTC (rev 16756)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp	2008-09-26 22:49:54 UTC (rev 16757)
@@ -1,6 +1,10 @@
 #include "NURBS_Generate.h"
 //NurbData	NURBS_Generate::nurbData;
 
+void NURBS_Generate::Curve(Object_NURBS *obj, nbReal* buffer, int dim, int res, bool update) {
+	Surface(obj, res * obj-> Length(0) , 1 , dim, buffer, obj -> Sum(), 0, 0, update);
+}
+
 void NURBS_Generate::Surface(Object_NURBS *obj, nbReal* buffer, int dim) {
 	int Vnpts;
 
@@ -34,10 +38,10 @@
 	nbReal BasisResult;
 	int i, OrderU, OrderV, Unpts, Vnpts, extraPntsU, extraPntsV,CyclicU,CyclicV;
 	bool recalc;
-	nbReal **BasisU;
-	nbReal **BasisV;
-	nbReal3 *TssPts3;
-	nbReal4 *TssPts4;
+	nbReal **BasisU = NULL;
+	nbReal **BasisV = NULL;
+	nbReal3 *TssPts3 = NULL;
+	nbReal4 *TssPts4 = NULL;
 
 	int TessU = origTessU;
 	int TessV = origTessV;
@@ -72,13 +76,13 @@
 	TessU--;
 	TessV--;
 
-	if(Change==1) 
+	if(Update == false || Change==1) 
 		recalc = 1;
 	else 
 		recalc = (obj -> Change(Change) != Unpts+Vnpts+OrderU+OrderV+TessU+TessV+CyclicU+CyclicV);
 	obj -> Change(Change,Unpts+Vnpts+OrderU+OrderV+TessU+TessV+CyclicU+CyclicV);
 
-	// recalc = 1;//FIXME
+	 //recalc = 1;//FIXME
 	// ("recalc: %d\n",recalc);
 
 	// Recalculate Basis Functions
@@ -147,12 +151,20 @@
 		else
 			TssPts3 = (nbReal3*)(TssPts);
 
-		// Copy B into Bold -- FIXME memcpy
+/*		// Copy B into Bold -- FIXME memcpy
 		for(i = 0; i < Unpts * Vnpts; i++) {
 			//obj -> CtlPtsOld()[i] = obj -> H()[i];
 			obj -> CtlPtsOld()[i] = obj -> CtlPts()[i];
 		}
+*/
 
+		if(Update) {
+			for(i = 0; i < Unpts*Vnpts; i++) {
+				// Update Old with New
+				obj -> CtlPtsOld()[i] = obj -> CtlPts()[i];
+			}
+		}
+
 		m = 0;
 
 		for(i = 0; i <= TessU; i++) {
@@ -239,20 +251,16 @@
 		nbReal dh, dx, dy, dz, da;
 		nbReal *sumold, sumratio;
 		int m0;
-		//sumold = (nbReal *)malloc(sizeof(nbReal)*(TessU+1)*(TessV+1));
 		sumold = (nbReal *)MEM_callocN(sizeof(nbReal)*(TessU+1)*(TessV+1),"sumold");
 
 		m = 0;
-		//	for(k = 0; k < Unpts; k++) {
 			for(k = 0; k < Unpts + extraPntsU; k++) {
 				for(l = 0; l < Vnpts+ extraPntsV; l++) {
 
-			//	m0 = ((k%Unpts)*Vnpts)+(l%Vnpts);
-				m0 = ((l%Vnpts)*Unpts)+(k%Unpts);//((k%Unpts)*Vnpts)+(l%Vnpts);
+				m0 = ((l%Vnpts)*Unpts)+(k%Unpts);
 				printf("incremental m: %d %d\n",m,m0);			
 				m = m0;
 			
-				//dh = obj -> H()[m] - obj -> Hold()[m];
 				dx = obj -> CtlPts()[m].x - obj -> CtlPtsOld()[m].x;
 				dy = obj -> CtlPts()[m].y - obj -> CtlPtsOld()[m].y;
 				dz = obj -> CtlPts()[m].z - obj -> CtlPtsOld()[m].z;
@@ -276,13 +284,12 @@
 
 					// Calculate the change in the surface for each u,w
 					j = 0;
-	for(i = 0; i <= TessU; i++) {
-								if(BasisU[i][k]) {						
+					for(i = 0; i <= TessU; i++) {
+						if(BasisU[i][k]) {						
+							for(n = 0; n <= TessV; n++) {
+								if(BasisV[n][l]) {
 
-									for(n = 0; n <= TessV; n++) {
-										if(BasisV[n][l]) {
-
-											printf("J: %i\n",j);
+								//			printf("J: %i\n",j);
 									if(dh) {
 										// Homogeneous coordinate changed
 										BasisResult = dh*BasisU[i][k]*BasisV[n][l]/Sum[j];
@@ -319,10 +326,10 @@
 										}
 									}
 								}
-								j++;//j += TessU+1;//j++;
+								j++;
 							}
 						} else {
-							j += TessV+1;//TessV+1;
+							j += TessV+1;
 						}
 					}
 				}
@@ -340,7 +347,6 @@
 	if(Update) {
 		for(i = 0; i < Unpts*Vnpts; i++) {
 			// Update Old with New
-			//obj -> Hold()[i] = obj -> H()[i];
 			obj -> CtlPtsOld()[i] = obj -> CtlPts()[i];
 		}
 	}
@@ -374,7 +380,6 @@
 					temp[k].y= obj -> CtlPts()[i*obj -> Length(1)+n].y;
 					temp[k].z= obj -> CtlPts()[i*obj -> Length(1)+n].z;
 					temp[k].H= obj -> CtlPts()[i*obj -> Length(1)+n].H;
-					//Htemp[k]= obj -> H()[i*obj -> Length(1)+n];
 					k++;
 				}
 
@@ -383,7 +388,6 @@
 					temp[k].y= obj -> CtlPts()[l+i*obj -> Length(1)].y;
 					temp[k].z= obj -> CtlPts()[l+i*obj -> Length(1)].z;
 					temp[k].H= obj -> CtlPts()[l+i*obj -> Length(1)].H;
-					//Htemp[k]= obj -> H()[l+i*obj -> Length(1)];
 					k++;
 				}
 			}
@@ -394,7 +398,6 @@
 				temp[i].y= obj -> CtlPts()[i].y;
 				temp[i].z= obj -> CtlPts()[i].z;
 				temp[i].H= obj -> CtlPts()[i].H;
-				//Htemp[i]= obj -> H()[i];
 				k++;
 			}
 		}
@@ -407,7 +410,6 @@
 					temp[k].y= temp[n+i*obj -> Length(1)].y;
 					temp[k].z= temp[n+i*obj -> Length(1)].z;
 					temp[k].H= temp[n+i*obj -> Length(1)].H;
-					//Htemp[k]= Htemp[n+i*obj -> Length(1)];
 					k++;
 				}
 			}
@@ -420,11 +422,9 @@
 		obj -> CtlPts()[i].y= temp[i].y;
 		obj -> CtlPts()[i].z= temp[i].z;
 		obj -> CtlPts()[i].H= temp[i].H;
-		//obj -> H()[i]= Htemp[i];
 	}
 
 	MEM_freeN(temp);
-	//MEM_freeN(Htemp);
 }
 
 
@@ -806,9 +806,8 @@
 
 	//printf("KnotVector, Point3d *cp, nbReal *BasisValues,", nbReal *KnotVector, Point3d *cp, nbReal *BasisValues
 	//printf("t=%.3f\n",t);
+
 	// Allocate memory for temp
-	//temp = (nbReal *)malloc(sizeof(nbReal)*(npts+Order));
-	//temp = (nbReal *)MEM_callocN(sizeof(nbReal)*(npts+Order),"NURBSBasis() temp");
 	temp = (nbReal *)MEM_callocN(sizeof(nbReal)*(npts+Order),"NURBSBasis() temp");
 
 	/* this part is order '1' */
@@ -835,23 +834,6 @@
 	}
 	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]);
-		//printf("\n");
-
-	// Populate N(i,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;

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.h	2008-09-26 21:49:26 UTC (rev 16756)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.h	2008-09-26 22:49:54 UTC (rev 16757)
@@ -37,8 +37,8 @@
 
 class NURBS_Generate {
   public:
-    static	void		Surface(Object_NURBS *obj, nbReal* buffer, int dim = 3);
-
+    static void		Surface(Object_NURBS *obj, nbReal* buffer, int dim = 3);
+	static void			Curve(Object_NURBS *obj, nbReal* buffer, int dim, int res, bool update);
     static void 		IsoLines(Object_NURBS *obj, nbReal* buffer); 
 
  //   static	void		TrimSurface(Object_NURBS *obj);

Modified: branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp	2008-09-26 21:49:26 UTC (rev 16756)
+++ branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp	2008-09-26 22:49:54 UTC (rev 16757)
@@ -184,7 +184,8 @@
 	//	on->KnotType(uv,NURBS_KV_Custom);
 
 	NURBS_Generate::KnotVector(on,uv);
-
+	on->Change(1,1);
+	on->Change(0,1);
 	// Turn off recalc flag flag
 	on->RecalculateKnotVector(0);
 	NRB_Print(on);	
@@ -234,7 +235,17 @@
 	NURBS_Generate::Surface(on,buffer, dim);
 	return buffer;
 }
+nbReal* NRB_GenerateCurve(NurbanaObj_ptr nop, nbReal* buffer, int dim, int res) {
+	Object_NURBS *on;
+	on = reinterpret_cast<Object_NURBS*>(nop);
+	if(on->RecalculateKnotVector()) {
+		NURBS_Generate::KnotVector(on);
+		on->RecalculateKnotVector(0);
+	}	
 
+	NURBS_Generate::Curve(on,buffer, dim, res, false);
+	return buffer;
+}
 nbReal3* NRB_GenerateNormals(NurbanaObj_ptr nop) {
 	Object_NURBS *on;
 	on = reinterpret_cast<Object_NURBS*>(nop);

Modified: branches/nurbs/blender/source/blender/blenkernel/intern/curve.c
===================================================================
--- branches/nurbs/blender/source/blender/blenkernel/intern/curve.c	2008-09-26 21:49:26 UTC (rev 16756)
+++ branches/nurbs/blender/source/blender/blenkernel/intern/curve.c	2008-09-26 22:49:54 UTC (rev 16757)
@@ -813,7 +813,9 @@
 
 numTess = nu->pntsu * NRB_getNumTessPoints(nu->nurbanaPtr);// FIXME check that this number is correct
 
-tsspts = NRB_GenerateSurface(nu->nurbanaPtr,data, dim);
+//tsspts = NRB_GenerateSurface(nu->nurbanaPtr,data, dim);
+tsspts = NRB_GenerateCurve(nu->nurbanaPtr,data, dim, resolu);
+
 //
 //printf("numTess: %d, resolu: %d",numTess,resolu);
 //for(i=0;i<numTess;i++)





More information about the Bf-blender-cvs mailing list