Revision: 16904
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16904
Author: eman
Date: 2008-10-03 22:39:15 +0200 (Fri, 03 Oct 2008)
Log Message:
-----------
- Added weights into bezier reduce function for Degree Reduction.
- Fixed and enabled Non-descructive Degree reduction
- Works for Clamped curves and surfaces
Modified Paths:
--------------
branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.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/intern/NURBS_Degree.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp
2008-10-03 20:17:05 UTC (rev 16903)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp
2008-10-03 20:39:15 UTC (rev 16904)
@@ -51,7 +51,6 @@
int fnlPtsSize =
(pntsU+(pntsU-(orderU-1))*Uinc)*(pntsV+(pntsV-(orderV-1))*Vinc);
FnlPts =
(Point3d*)MEM_callocN(sizeof(Point3d)*fnlPtsSize,"NURBS_Degree::Elevate
FnlPts");
-// FnlPts =
(Point3d*)MEM_callocN(sizeof(Point3d)*(pntsU+(pntsU-(orderU-1))*Uinc)*(pntsV+(pntsV-(orderV-1))*Vinc),"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");
@@ -384,7 +383,7 @@
newCtlPts[i].y= FnlPts[i].y;
newCtlPts[i].z= FnlPts[i].z;
newCtlPts[i].H= FnlPts[i].H;
- printf("newCtlPts[%d]:
%.3f,%.3f,%.3f:%.3f\n",i,newCtlPts[i].z,newCtlPts[i].y,newCtlPts[i].z,newCtlPts[i].H);
+ printf("newCtlPts[%d]:
%.3f,%.3f,%.3f:%.3f\n",i,newCtlPts[i].x,newCtlPts[i].y,newCtlPts[i].z,newCtlPts[i].H);
}
obj -> ReplaceCtlPts(newCtlPts);
@@ -420,17 +419,19 @@
void NURBS_Degree::BezDegReduce(Point3d *bpts, Point3d *rbpts, int Degree,
nbReal &MaxErr) {
// Reduce Bezier segment and store in rbpts
int i,r;
- nbReal a,a2,x,y,z;
+ nbReal a,a2,x,y,z,H;
r= (Degree-1)/2;
rbpts[0].x= bpts[0].x;
rbpts[0].y= bpts[0].y;
rbpts[0].z= bpts[0].z;
+ rbpts[0].H= bpts[0].H;
rbpts[Degree-1].x= bpts[Degree].x;
rbpts[Degree-1].y= bpts[Degree].y;
rbpts[Degree-1].z= bpts[Degree].z;
+ rbpts[Degree-1].H= bpts[Degree].H;
// Two cases, Even or Odd
if(Degree%2) {
@@ -440,25 +441,30 @@
rbpts[i].x= (bpts[i].x-a*rbpts[i-1].x)/(1.0-a);
rbpts[i].y= (bpts[i].y-a*rbpts[i-1].y)/(1.0-a);
rbpts[i].z= (bpts[i].z-a*rbpts[i-1].z)/(1.0-a);
+ rbpts[i].H= (bpts[i].H-a*rbpts[i-1].H)/(1.0-a);
} //eof
for(i= Degree-2; i >= r+1; i--) {
a= nbReal(i+1)/nbReal(Degree);
rbpts[i].x= (bpts[i+1].x-(1.0-a)*rbpts[i+1].x)/a;
rbpts[i].y= (bpts[i+1].y-(1.0-a)*rbpts[i+1].y)/a;
rbpts[i].z= (bpts[i+1].z-(1.0-a)*rbpts[i+1].z)/a;
+ rbpts[i].H= (bpts[i+1].H-(1.0-a)*rbpts[i+1].H)/a;
} //eof
a= nbReal(r)/(nbReal(Degree));
rbpts[r].x= (bpts[r].x - a*rbpts[r-1].x)/(1.0-a);
rbpts[r].y= (bpts[r].y - a*rbpts[r-1].y)/(1.0-a);
rbpts[r].z= (bpts[r].z - a*rbpts[r-1].z)/(1.0-a);
+ rbpts[r].H= (bpts[r].H - a*rbpts[r-1].H)/(1.0-a);
a= nbReal(r+1)/(nbReal(Degree));
rbpts[r].x+= (bpts[r+1].x-(1.0-a)*rbpts[r+1].x)/a;
rbpts[r].y+= (bpts[r+1].y-(1.0-a)*rbpts[r+1].y)/a;
rbpts[r].z+= (bpts[r+1].z-(1.0-a)*rbpts[r+1].z)/a;
+ rbpts[r].H+= (bpts[r+1].H-(1.0-a)*rbpts[r+1].H)/a;
rbpts[r].x*= 0.5;
rbpts[r].y*= 0.5;
rbpts[r].z*= 0.5;
+ rbpts[r].H*= 0.5;
} else {
// Even
for(i= 1; i <= r; i++) {
@@ -466,16 +472,18 @@
rbpts[i].x= (bpts[i].x-a*rbpts[i-1].x)/(1.0-a);
rbpts[i].y= (bpts[i].y-a*rbpts[i-1].y)/(1.0-a);
rbpts[i].z= (bpts[i].z-a*rbpts[i-1].z)/(1.0-a);
+ rbpts[i].H= (bpts[i].H-a*rbpts[i-1].H)/(1.0-a);
} //eof
for(i= Degree-2; i >= r+1; i--) {
a= nbReal(i+1)/nbReal(Degree);
rbpts[i].x= (bpts[i+1].x - (1.0-a)*rbpts[i+1].x)/a;
rbpts[i].y= (bpts[i+1].y - (1.0-a)*rbpts[i+1].y)/a;
rbpts[i].z= (bpts[i+1].z - (1.0-a)*rbpts[i+1].z)/a;
+ rbpts[i].H= (bpts[i+1].H - (1.0-a)*rbpts[i+1].H)/a;
} //eof
} //fi
- // Error Calculation
+ // Error Calculation // TODO -eman cache _Basis calls
if(Degree%2) {
// Odd
a= nbReal(r)/(nbReal(Degree));
@@ -483,15 +491,17 @@
x=
(0.5)*(1.0-a)*((_Basis(r,Degree,0.5)-_Basis(r+1,Degree,0.5))*(((bpts[r].x-a*rbpts[r-1].x)/(1.0-a))-((bpts[r+1].x-(1.0-a2)*rbpts[r+1].x)/(a2))));
y=
(0.5)*(1.0-a)*((_Basis(r,Degree,0.5)-_Basis(r+1,Degree,0.5))*(((bpts[r].y-a*rbpts[r-1].y)/(1.0-a))-((bpts[r+1].y-(1.0-a2)*rbpts[r+1].y)/(a2))));
z=
(0.5)*(1.0-a)*((_Basis(r,Degree,0.5)-_Basis(r+1,Degree,0.5))*(((bpts[r].z-a*rbpts[r-1].z)/(1.0-a))-((bpts[r+1].z-(1.0-a2)*rbpts[r+1].z)/(a2))));
+ H=
(0.5)*(1.0-a)*((_Basis(r,Degree,0.5)-_Basis(r+1,Degree,0.5))*(((bpts[r].H-a*rbpts[r-1].H)/(1.0-a))-((bpts[r+1].H-(1.0-a2)*rbpts[r+1].H)/(a2))));
} else {
// Even
x=
_Basis(r+1,Degree,0.5)*(bpts[r+1].x-0.5*(rbpts[r].x+rbpts[r+1].x));
y=
_Basis(r+1,Degree,0.5)*(bpts[r+1].y-0.5*(rbpts[r].y+rbpts[r+1].y));
z=
_Basis(r+1,Degree,0.5)*(bpts[r+1].z-0.5*(rbpts[r].z+rbpts[r+1].z));
+ H=
_Basis(r+1,Degree,0.5)*(bpts[r+1].H-0.5*(rbpts[r].H+rbpts[r+1].H));
} //fi
// Assumption, take the length of the error vector???
// printf("Ex: %f, Ey: %f, Ez: %f\n",x,y,z);
- MaxErr= sqrt(x*x+y*y+z*z);
+ MaxErr= sqrt(x*x+y*y+z*z+H*H);
}
@@ -536,16 +546,20 @@
if(UV) {
// V Directional Curves
for(i= 0; i < obj -> Length(1); i++) {
- Pts[i].x= obj -> CtlPts()[i+obj
-> Length(1)*Curve].x;
- Pts[i].y= obj -> CtlPts()[i+obj
-> Length(1)*Curve].y;
- Pts[i].z= obj -> CtlPts()[i+obj
-> Length(1)*Curve].z;
+ int indx = i*obj ->
Length(0)+Curve;
+ Pts[i].x= obj ->
CtlPts()[indx].x;
+ Pts[i].y= obj ->
CtlPts()[indx].y;
+ Pts[i].z= obj ->
CtlPts()[indx].z;
+ Pts[i].H= obj ->
CtlPts()[indx].H;
} //eof
} else {
// U Directional Curves
for(i= 0; i < obj -> Length(0); i++) {
- Pts[i].x= obj -> CtlPts()[i*obj
-> Length(1)+Curve].x;
- Pts[i].y= obj -> CtlPts()[i*obj
-> Length(1)+Curve].y;
- Pts[i].z= obj -> CtlPts()[i*obj
-> Length(1)+Curve].z;
+ int indx = i+obj ->
Length(0)*Curve;
+ Pts[i].x= obj ->
CtlPts()[indx].x;
+ Pts[i].y= obj ->
CtlPts()[indx].y;
+ Pts[i].z= obj ->
CtlPts()[indx].z;
+ Pts[i].H= obj ->
CtlPts()[indx].H;
} //eof
} //fi
for(i= 0; i < obj -> Length(UV) + obj ->
Order(UV); i++)
@@ -571,6 +585,7 @@
Temp[0].x= Pts[0].x;
Temp[0].y= Pts[0].y;
Temp[0].z= Pts[0].z;
+ Temp[0].H= Pts[0].H;
// Compute left end of knot vector
for(i= 0; i <= ph; i++)
@@ -581,6 +596,7 @@
bpts[i].x= Pts[i].x;
bpts[i].y= Pts[i].y;
bpts[i].z= Pts[i].z;
+ bpts[i].H= Pts[i].H;
} //eof
// Initialize Error Vector
@@ -620,11 +636,13 @@
bpts[k].x= alphas[k-s]*bpts[k].x + (1.0-alphas[k-s])*bpts[k-1].x;
bpts[k].y= alphas[k-s]*bpts[k].y + (1.0-alphas[k-s])*bpts[k-1].y;
bpts[k].z= alphas[k-s]*bpts[k].z + (1.0-alphas[k-s])*bpts[k-1].z;
+
bpts[k].H= alphas[k-s]*bpts[k].H + (1.0-alphas[k-s])*bpts[k-1].H;
} //eof
Nextbpts[save].x= bpts[Degree].x;
Nextbpts[save].y= bpts[Degree].y;
Nextbpts[save].z= bpts[Degree].z;
+
Nextbpts[save].H= bpts[Degree].H;
} //eof
} //fi
@@ -652,10 +670,12 @@
Temp[i-1].x= (Temp[i-1].x-(1.0-alfa)*Temp[i-2].x)/alfa;
Temp[i-1].y= (Temp[i-1].y-(1.0-alfa)*Temp[i-2].y)/alfa;
Temp[i-1].z= (Temp[i-1].z-(1.0-alfa)*Temp[i-2].z)/alfa;
+
Temp[i-1].z= (Temp[i-1].H-(1.0-alfa)*Temp[i-2].H)/alfa;
rbpts[kj].x= (rbpts[kj].x-beta*rbpts[kj+1].x)/(1.0-beta);
rbpts[kj].y= (rbpts[kj].y-beta*rbpts[kj+1].y)/(1.0-beta);
rbpts[kj].z= (rbpts[kj].z-beta*rbpts[kj+1].z)/(1.0-beta);
+
rbpts[kj].z= (rbpts[kj].H-beta*rbpts[kj+1].H)/(1.0-beta);
i++;
j--;
@@ -669,6 +689,7 @@
A.x=
delta*rbpts[kj+1].x+(1.0-delta)*Temp[i-2].x;
A.y=
delta*rbpts[kj+1].y+(1.0-delta)*Temp[i-2].y;
A.z=
delta*rbpts[kj+1].z+(1.0-delta)*Temp[i-2].z;
+ A.z=
delta*rbpts[kj+1].H+(1.0-delta)*Temp[i-2].H;
Br=
NurbanaMath::Dist4d(Temp[i-1],A);
} //fi
@@ -705,6 +726,7 @@
Temp[cind].x=
rbpts[i].x;
Temp[cind].y=
rbpts[i].y;
Temp[cind].z=
rbpts[i].z;
+ Temp[cind].H=
rbpts[i].H;
cind++;
} //eof
@@ -713,6 +735,7 @@
bpts[i].x=
Nextbpts[i].x;
bpts[i].y=
Nextbpts[i].y;
bpts[i].z=
Nextbpts[i].z;
+ bpts[i].H=
Nextbpts[i].H;
} //eof
for(i= r; i <= Degree; i++) {
@@ -720,6 +743,7 @@
bpts[i].x=
Pts[b-Degree+i].x;
bpts[i].y=
Pts[b-Degree+i].y;
bpts[i].z=
Pts[b-Degree+i].z;
+ bpts[i].H=
Pts[b-Degree+i].H;
} //fi
} //eof
@@ -738,6 +762,7 @@
Pts[i].x= Temp[i].x;
Pts[i].y= Temp[i].y;
Pts[i].z= Temp[i].z;
+ Pts[i].H= Temp[i].H;
} //eof
for(i= 0; i < Npts+Order; i++)
@@ -754,6 +779,7 @@
FnlPts[indx].x= Pts[i].x;
FnlPts[indx].y= Pts[i].y;
FnlPts[indx].z= Pts[i].z;
+ FnlPts[indx].H= Pts[i].H;
} //eof
} else {
// U Directional Curves
@@ -762,6 +788,7 @@
FnlPts[indx].x= Pts[i].x;
FnlPts[indx].y= Pts[i].y;
FnlPts[indx].z= Pts[i].z;
+ FnlPts[indx].H= Pts[i].H;
printf("U FnlPts[%d]:
%.3f,%.3f,%.3f:%.3f\n",indx,FnlPts[indx].x,FnlPts[indx].y,FnlPts[indx].z,FnlPts[indx].H);
//// Update Original because we
know U is just tacked onto the end of the array and
@@ -807,6 +834,7 @@
obj -> CtlPts()[i].x= FnlPts[i].x;
obj -> CtlPts()[i].y= FnlPts[i].y;
obj -> CtlPts()[i].z= FnlPts[i].z;
+ obj -> CtlPts()[i].H= FnlPts[i].H;
} //eof
//obj->ReplaceCtlPts(FnlPts);
// Copy Final Points into Original Points
Modified: branches/nurbs/blender/source/blender/include/butspace.h
===================================================================
--- branches/nurbs/blender/source/blender/include/butspace.h 2008-10-03
20:17:05 UTC (rev 16903)
+++ branches/nurbs/blender/source/blender/include/butspace.h 2008-10-03
20:39:15 UTC (rev 16904)
@@ -495,9 +495,10 @@
#define B_ISOLINES 2130
#define B_DEGREEELEVATEU 2131
#define B_DEGREEELEVATEV 2132
-#define B_DEGREEREDUCE 2133
-#define B_REFINECURVE 2134
-#define B_SETRESOL 2135
+#define B_DEGREEREDUCEU 2133
+#define B_DEGREEREDUCEV 2134
+#define B_REFINECURVE 2135
+#define B_SETRESOL 2136
/* *********************** */
#define B_FONTBUTS 2300
Modified: branches/nurbs/blender/source/blender/src/buttons_editing.c
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs