Revision: 18172
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18172
Author:   eman
Date:     2008-12-30 12:10:59 +0100 (Tue, 30 Dec 2008)

Log Message:
-----------
Another patch from Laurynas, thanks!

His commit message:

Fixes in curve primitives: default V order and default cp radius and weight 
values.
Curve extrusion code is removed. It was the same functionality as in surface 
case when v line is selected.

Methods setRecalculateKnotVector and getRecalculateKnotVector are added to 
Object_NURBS to avoid knot recalculation.

Temp buffer allocation is moved form NURBS_Generate::NURBSBasis to calling 
functions.
>From NURBS_Generate::KnotVector function redundant code is removed.

Weights are fixed in elevate/reduce degree.

Modified Paths:
--------------
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp
    branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.h
    branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp
    branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.h
    branches/nurbs/blender/intern/nurbana/intern/Object_Primitives.cpp
    branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp
    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-12-30 10:37:52 UTC (rev 18171)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp       
2008-12-30 11:10:59 UTC (rev 18172)
@@ -96,6 +96,12 @@
                                                Pts[i].y = 
ctlPts[i*pntsU+Curve].y;
                                                Pts[i].z = 
ctlPts[i*pntsU+Curve].z;
                                                Pts[i].H = 
ctlPts[i*pntsU+Curve].H;
+                                               if (1.0 != Pts[i].H) {
+                                   nbReal w = Pts[i].H;
+                                   Pts[i].x *= w;
+                                   Pts[i].y *= w;
+                                   Pts[i].z *= w;
+                                               }
                                        } //eof
                                } else {
                                        // U Directional Curves
@@ -104,6 +110,12 @@
                                                Pts[i].y = 
ctlPts[i+pntsU*Curve].y;
                                                Pts[i].z = 
ctlPts[i+pntsU*Curve].z;
                                                Pts[i].H = 
ctlPts[i+pntsU*Curve].H;
+                                               if (1.0 != Pts[i].H) {
+                                   nbReal w = Pts[i].H;
+                                   Pts[i].x *= w;
+                                   Pts[i].y *= w;
+                                   Pts[i].z *= w;
+                                               }
                                        } //eof
                                } //fi
 
@@ -298,6 +310,12 @@
                                                FnlPts[indx].y = Pts[i].y;
                                                FnlPts[indx].z = Pts[i].z;
                                                FnlPts[indx].H = Pts[i].H;
+                                               if (1.0 != FnlPts[indx].H) {
+                                   nbReal w = 1 / FnlPts[indx].H;
+                                   FnlPts[indx].x *= w;
+                                   FnlPts[indx].y *= w;
+                                   FnlPts[indx].z *= w;
+                                               }
 
                                                ctlPts = newCtlPts; //HMMM 
FIXME CHECKME eman - moot for now since only allowing increase in one dir per 
call
                                                // Update Original because we 
know V is just tacked onto the end of the array and
@@ -316,6 +334,12 @@
                                                FnlPts[indx].y = Pts[i].y;
                                                FnlPts[indx].z = Pts[i].z;
                                                FnlPts[indx].H = Pts[i].H;
+                                               if (1.0 != FnlPts[indx].H) {
+                                                       nbReal w = 1 / 
FnlPts[indx].H;
+                                                       FnlPts[indx].x *= w;
+                                                       FnlPts[indx].y *= w;
+                                                       FnlPts[indx].z *= w;
+                                               }
                                                //printf("U FnlPts[%d]: 
%.3f,%.3f,%.3f:%.3f\n",indx,FnlPts[indx].x,FnlPts[indx].y,FnlPts[indx].z,FnlPts[indx].H);
                                        } //eof
                                } //fi
@@ -538,6 +562,12 @@
                                                Pts[i].y= obj -> 
CtlPts()[indx].y;
                                                Pts[i].z= obj -> 
CtlPts()[indx].z;
                                                Pts[i].H= obj -> 
CtlPts()[indx].H;
+                                               if (1.0 != Pts[i].H) {
+                                                       nbReal w = Pts[i].H;
+                                                       Pts[i].x *= w;
+                                                       Pts[i].y *= w;
+                                                       Pts[i].z *= w;
+                                               }
                                        } //eof
                                } else {
                                        // U Directional Curves
@@ -547,6 +577,12 @@
                                                Pts[i].y= obj -> 
CtlPts()[indx].y;
                                                Pts[i].z= obj -> 
CtlPts()[indx].z;
                                                Pts[i].H= obj -> 
CtlPts()[indx].H;
+                                               if (1.0 != Pts[i].H) {
+                                                       nbReal w = Pts[i].H;
+                                                       Pts[i].x *= w;
+                                                       Pts[i].y *= w;
+                                                       Pts[i].z *= w;
+                                               }
                                        } //eof
                                } //fi
                                for(i= 0; i < obj -> Length(UV) + obj -> 
Order(UV); i++)
@@ -769,6 +805,12 @@
                                                FnlPts[indx].y= Pts[i].y;
                                                FnlPts[indx].z= Pts[i].z;
                                                FnlPts[indx].H= Pts[i].H;
+                                               if (1.0 != FnlPts[indx].H) {
+                                                       nbReal w = 1 / 
FnlPts[indx].H;
+                                                       FnlPts[indx].x *= w;
+                                                       FnlPts[indx].y *= w;
+                                                       FnlPts[indx].z *= w;
+                                               }
                                        } //eof
                                } else {
                                        // U Directional Curves
@@ -778,6 +820,12 @@
                                                FnlPts[indx].y= Pts[i].y;
                                                FnlPts[indx].z= Pts[i].z;
                                                FnlPts[indx].H= Pts[i].H;
+                                               if (1.0 != FnlPts[indx].H) {
+                                                       nbReal w = 1 / 
FnlPts[indx].H;
+                                                       FnlPts[indx].x *= w;
+                                                       FnlPts[indx].y *= w;
+                                                       FnlPts[indx].z *= w;
+                                               }
                                                //printf("U FnlPts[%d]: 
%.3f,%.3f,%.3f:%.3f\n",indx,FnlPts[indx].x,FnlPts[indx].y,FnlPts[indx].z,FnlPts[indx].H);
 
                                                // will need to do something 
like this if we allow simultaenous reduction in U and V

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp     
2008-12-30 10:37:52 UTC (rev 18171)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp     
2008-12-30 11:10:59 UTC (rev 18172)
@@ -74,6 +74,9 @@
                recalc = (obj -> Change(Change) != 
Unpts+Vnpts+OrderU+OrderV+TessU+TessV+CyclicU+CyclicV);
        obj -> 
Change(Change,Unpts+Vnpts+OrderU+OrderV+TessU+TessV+CyclicU+CyclicV);
 
+       // Allocate memory for temp
+       int tempSize = NurbanaMath::Max(OrderU + Unpts + extraPntsU, OrderV + 
Vnpts + extraPntsV);
+       nbReal *tempForBasis = (nbReal *) MEM_callocN(sizeof(nbReal) * 
tempSize, "Surface() tempForBasis");
        // Recalculate Basis Functions
        if(recalc) {
 
@@ -84,7 +87,7 @@
                nbReal t = startU;
 
                for(i = 0; i <= TessU; i++) { 
-                       NURBSBasis(OrderU, t, (Unpts+extraPntsU),Unpts, obj -> 
KnotVector(0), obj -> CtlPts(), BasisU[i], 1);
+                       NURBSBasis(OrderU, t, (Unpts+extraPntsU),Unpts, obj -> 
KnotVector(0), obj -> CtlPts(), BasisU[i], 1, tempForBasis);
                        t += stepU;
                }
 
@@ -99,7 +102,7 @@
                        tv = startV;
                }
                for(i = 0; i <= TessV; i++) { 
-                       NURBSBasis(OrderV, tv, (Vnpts+extraPntsV), Vnpts,obj -> 
KnotVector(1), obj -> CtlPts(), BasisV[i], 1);
+                       NURBSBasis(OrderV, tv, (Vnpts+extraPntsV), Vnpts,obj -> 
KnotVector(1), obj -> CtlPts(), BasisV[i], 1, tempForBasis);
                        tv += stepV;
                }
        } else {
@@ -110,7 +113,7 @@
                nbReal t = startU;
 
                for(i = 0; i <= TessU; i++) { 
-                       NURBSBasis(OrderU, t, (Unpts+extraPntsU),Unpts, obj -> 
KnotVector(0), obj -> CtlPtsOld(), BasisU[i], 1);
+                       NURBSBasis(OrderU, t, (Unpts+extraPntsU),Unpts, obj -> 
KnotVector(0), obj -> CtlPtsOld(), BasisU[i], 1, tempForBasis);
                        t += stepU;
                }
 
@@ -121,10 +124,12 @@
                nbReal tv = startV;
 
                for(i = 0; i <= TessV; i++) { 
-                       NURBSBasis(OrderV, tv, (Vnpts+extraPntsV), Vnpts,obj -> 
KnotVector(1), obj -> CtlPtsOld(), BasisV[i], 1);
+                       NURBSBasis(OrderV, tv, (Vnpts+extraPntsV), Vnpts,obj -> 
KnotVector(1), obj -> CtlPtsOld(), BasisV[i], 1, tempForBasis);
                        tv += stepV;
                }
        }
+       MEM_freeN(tempForBasis);
+       
 
        // Compute Surface
        if(recalc) {
@@ -336,45 +341,23 @@
        //#define       NURBS_KV_Open                   1 // endpoints tied
        //#define       NURBS_KV_Bezier         2
 
-       if(uv == 0)
-       {
-               if(obj -> KnotType(0) == NURBS_KV_Periodic) {
-                       if(obj -> Cyclic(0))
-                               PeriodicKnot(obj -> Length(0) + obj -> Order(0) 
-1,obj -> Order(0),obj -> KnotVector(0));
-                       else
-                               PeriodicKnot(obj -> Length(0),obj -> 
Order(0),obj -> KnotVector(0));
+       if(obj -> KnotType(uv) == NURBS_KV_Periodic) {
+               if(obj -> Cyclic(uv))
+                       PeriodicKnot(obj -> Length(uv) + obj -> Order(uv) - 1, 
obj -> Order(uv), obj -> KnotVector(uv));
+               else
+                       PeriodicKnot(obj -> Length(uv), obj -> Order(uv), obj 
-> KnotVector(uv));
 
-               } else if(obj -> KnotType(0) == NURBS_KV_Open) {
-                       if(obj -> Cyclic(0))
-                               OpenKnot(obj -> Length(0)-1 + obj ->Order(0) 
-1,obj -> Order(0),obj -> KnotVector(0));
-                       else    
-                               OpenKnot(obj -> Length(0)-1,obj -> Order(0),obj 
-> KnotVector(0));
-               } else if(obj -> KnotType(0) == NURBS_KV_Bezier) {
-                       if(obj -> Cyclic(0))
-                               BezierKnot(obj -> Length(0) + obj ->Order(0) 
-1,obj -> Order(0),obj -> KnotVector(0));
-                       else    
-                               BezierKnot(obj -> Length(0),obj -> Order(0),obj 
-> KnotVector(0));
-               }
+       } else if(obj -> KnotType(uv) == NURBS_KV_Open) {
+               if(obj -> Cyclic(uv))
+                       OpenKnot(obj -> Length(uv) - 1 + obj ->Order(uv) - 1, 
obj -> Order(uv), obj -> KnotVector(uv));
+               else    
+                       OpenKnot(obj -> Length(uv) - 1, obj -> Order(uv), obj 
-> KnotVector(uv));
+       } else if(obj -> KnotType(uv) == NURBS_KV_Bezier) {
+               if(obj -> Cyclic(uv))
+                       BezierKnot(obj -> Length(uv) + obj -> Order(uv) - 1, 
obj -> Order(uv), obj -> KnotVector(uv));
+               else    
+                       BezierKnot(obj -> Length(uv), obj -> Order(uv), obj -> 
KnotVector(uv));
        }
-       else
-       {
-               if(obj -> KnotType(1) == NURBS_KV_Periodic) { //FIXME check for 
curve no knotV
-                       if(obj -> Cyclic(1))
-                               PeriodicKnot(obj -> Length(1) + obj -> Order(1) 
-1,obj -> Order(1),obj -> KnotVector(1));
-                       else
-                               PeriodicKnot(obj -> Length(1),obj -> 
Order(1),obj -> KnotVector(1));
-               } else if(obj -> KnotType(1) == NURBS_KV_Open) {
-                       if(obj -> Cyclic(1))
-                               OpenKnot(obj -> Length(1)-1 + obj -> Order(1) 
-1,obj -> Order(1),obj -> KnotVector(1));
-                       else
-                               OpenKnot(obj -> Length(1)-1,obj -> Order(1),obj 
-> KnotVector(1));
-               } else if(obj -> KnotType(1) == NURBS_KV_Bezier) {
-                       if(obj -> Cyclic(1))
-                               BezierKnot(obj -> Length(1) + obj ->Order(1) 
-1,obj -> Order(1),obj -> KnotVector(1));
-                       else    
-                               BezierKnot(obj -> Length(1),obj -> Order(1),obj 
-> KnotVector(1));
-               }
-       }
 }
 
 
@@ -660,9 +643,9 @@
        //              KnotVector[i] = i;
 }
 
-void NURBS_Generate::NURBSBasis(int Order, nbReal t, int npts, int realPts, 
nbReal *KnotVector, Point3d *cp, nbReal *BasisValues, bool Type) {
+void NURBS_Generate::NURBSBasis(int Order, nbReal t, int npts, int realPts, 
nbReal *KnotVector, Point3d *cp, nbReal *BasisValues, bool Type, nbReal *temp) {
        int i, k;
-       nbReal *temp, sum, d, e;
+       nbReal sum, d, e;
 
        /* For Curves */
        if(npts == 1) {
@@ -675,9 +658,6 @@
        else if(t > KnotVector[Order+npts-1]) 
                t= KnotVector[Order+npts-1];
 
-       // Allocate memory for temp
-       temp = (nbReal *)MEM_callocN(sizeof(nbReal)*(npts+Order),"NURBSBasis() 
temp");
-
        /* this part is order '1' */
        int o2 = Order + 1;
        int orderpluspnts= Order+npts;
@@ -735,8 +715,6 @@
        //for(i =0;i<npts;i++)
        //printf(" %f,",BasisValues[i]);
        //printf("\n");
-
-       MEM_freeN(temp);
 }
 
 //

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.h       
2008-12-30 10:37:52 UTC (rev 18171)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.h       
2008-12-30 11:10:59 UTC (rev 18172)
@@ -62,7 +62,7 @@
     static     void            PeriodicKnot(int npts, int Order, nbReal 
*KnotVector);
     static     void            OpenKnot(int npts, int Order, nbReal 
*KnotVector);
 
-        static void            NURBSBasis(int Order, nbReal t, int npts, int 
realPts, nbReal *KnotVector, Point3d *cp, nbReal *BasisValues, bool Type);
+        static void            NURBSBasis(int Order, nbReal t, int npts, int 
realPts, nbReal *KnotVector, Point3d *cp, nbReal *BasisValues, bool Type, 
nbReal *temp);
 
 //    static   void            NURBSBasis(int Order, nbReal t, int npts, 
nbReal *KnotVector, Point3d *cp, nbReal *BasisValues, bool Type);
     static     void            NURBSBasisDer1(int Order, nbReal t, int npts, 
nbReal *KnotVector, Point3d *cp, nbReal *BasisValues, bool Type);

Modified: branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp
===================================================================

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to