Revision: 16708
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16708
Author:   eman
Date:     2008-09-24 00:33:22 +0200 (Wed, 24 Sep 2008)

Log Message:
-----------
Interim commit.
Lots of debug code in here, but reverse compatibility should work with older 
Blender NURBS files.

Modified Paths:
--------------
    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_Base.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/libNurbana.cpp
    branches/nurbs/blender/source/blender/blenloader/intern/readfile.c
    branches/nurbs/blender/source/blender/makesdna/DNA_curve_types.h
    branches/nurbs/blender/source/blender/src/editcurve.c

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp     
2008-09-23 22:11:23 UTC (rev 16707)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Generate.cpp     
2008-09-23 22:33:22 UTC (rev 16708)
@@ -29,7 +29,7 @@
 
 }
 
-void NURBS_Generate::Surface(Object_NURBS *obj, int TessU, int TessV, int dim, 
nbReal *TssPts, nbReal *Sum, int Index, bool Change, bool Update) {
+void NURBS_Generate::Surface(Object_NURBS *obj, int origTessU, int origTessV, 
int dim, nbReal *TssPts, nbReal *Sum, int Index, bool Change, bool Update) {
        int n,k,l,m,j,j0;
        nbReal BasisResult;
        int i, OrderU, OrderV, Unpts, Vnpts, extraPntsU, 
extraPntsV,CyclicU,CyclicV;
@@ -39,6 +39,9 @@
        nbReal3 *TssPts3;
        nbReal4 *TssPts4;
 
+       int TessU = origTessU;
+       int TessV = origTessV;
+
        Unpts = obj -> Length(0);
        Vnpts = obj -> Length(1);
        OrderU = obj -> Order(0);       
@@ -85,6 +88,8 @@
 
        // 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);
@@ -146,6 +151,11 @@
                                else
                                        TssPts3[Index+m].x = 
TssPts3[Index+m].y= TssPts3[Index+m].z= 0;
 
+                               //printf("m=%d\n",Index+m);
+                               //if(Index +m > 6)
+                               //      printf("break - Hammertime!\n");
+               
+
                                //printf("Basis_U[%d][%d]: %.3f\n", i, k, 
BasisU[i][k]);
                                for(l = 0; l < Vnpts + extraPntsV; l++) {
                                        //      
@@ -153,7 +163,7 @@
                                        if(BasisV[n][l]) {
                                                for(k = 0; k < Unpts + 
extraPntsU; k++) {
                                                        //              
-                                                       //      
printf("Basis_U[%d][%d]: %.3f\n", i, k, BasisU[i][k]);
+                                                       //              
printf("Basis_U[%d][%d]: %.3f\n", i, k, BasisU[i][k]);
                                                        if(BasisU[i][k]) {
                                                                // Traverse 
transposed row/column order
                                                                j = 
((l%Vnpts)*Unpts)+(k%Unpts);
@@ -173,16 +183,30 @@
                                                                        
TssPts3[Index+m].x += (obj -> CtlPts()[j].x*BasisResult);
                                                                        
TssPts3[Index+m].y += (obj -> CtlPts()[j].y*BasisResult);
                                                                        
TssPts3[Index+m].z += (obj -> CtlPts()[j].z*BasisResult);
+
+
+                                                                       //float 
cutoff = 0.0001;
+                                                               //      
if(TssPts3[Index+m].x < cutoff && TssPts3[Index+m].y < cutoff && 
TssPts3[Index+m].z > -cutoff && TssPts3[Index+m].x > -cutoff && 
TssPts3[Index+m].y > -cutoff && TssPts3[Index+m].z > -cutoff)
+                                                               //              
printf("Oh NOES!\n");
+                                                               
                                                                }
                                                        }
                                                }
-                                       } //else {
+                                       } else {
                        //                      //j += Unpts;//Vnpts;
-                       //              }
+                                       //      printf("hmmm\n");
+                                       }
                                }
                                //printf(" m %d \n",m);
+                               if(dim != 4)
+                               {
 
-//                             printf(" Index+m %d << %.3f,%.3f,%.3f 
\n",Index+m,TssPts[Index+m].x,TssPts[Index+m].y ,TssPts[Index+m].z);
+                               //      if(TssPts3[Index+m].x < cutoff && 
TssPts3[Index+m].y < cutoff && TssPts3[Index+m].z > -cutoff && 
TssPts3[Index+m].x > -cutoff && TssPts3[Index+m].y > -cutoff && 
TssPts3[Index+m].z > -cutoff)
+                                       //      printf("Oh NOES!\n");
+                               //      printf("Tess[%d] %.3f %.3f 
%.3f\n",Index+m,TssPts3[Index+m].x,TssPts3[Index+m].y ,TssPts3[Index+m].z);
+
+                               }
+                       //      printf(" Index+m %d << %.3f,%.3f,%.3f 
\n",Index+m,TssPts3[Index+m].x,TssPts3[Index+m].y ,TssPts3[Index+m].z);
                                m++;
                        }
                }
@@ -745,7 +769,22 @@
                BasisValues[0] = 1.0;
                return;
        }
+       /*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: ");
+       for(i = 0; i < realPts; i++)
+               printf("%f, ",cp[i]);
+       printf("\n");*/
+       //printf("BasisValues: ");
+       //for(i = 0; i < npts; i++)
+       //      printf("%f, ",BasisValues[i]);
+       //printf("\n");
 
+       //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");
@@ -754,19 +793,22 @@
        //      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("Knotvector: ");
-       //      for(i = 0; i < npts+Order+1; i++)
-       //              printf("%f, ",KnotVector[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++)
+       //      printf("k = %d ::",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;
 
                if(Type) {
@@ -787,10 +829,10 @@
 
                }
 
-               /*      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);
 }

Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp 2008-09-23 
22:11:23 UTC (rev 16707)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp 2008-09-23 
22:33:22 UTC (rev 16708)
@@ -346,25 +346,32 @@
        int orderA = obj -> Order(!UV);
        int orderB = obj -> Order(UV);
        bool cyclic = obj -> Cyclic(UV);
-
+       int newLength = KVLen - orderB;
+       //if(obj->Cyclic(UV))
        if(cyclic){
                printf("-> cyclic\n");
                extraPntsA += orderA - 1;
                extraPntsB += orderB - 1;
+
+                       newLength -= (orderB - 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)*(KVLen - 
orderB)*(pntsA+extraPntsA),"_Insert() NewPts");
+       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");
-       printf("_Insert::NewPts: %d\n",(KVLen - orderB)*pntsA);
+       printf("_Insert::NewPts: %d\n",(newLength)*pntsA);
        
        // Assign the new Control Point Locations
        // Calculate New Control Points through Recursive Oslo Algorithm
-       for (i= 0; i < pntsA + extraPntsA; i++) {
-               for (n= 0; n < KVLen - orderB; n++) {
-                       !UV ? ind1= n+i*(KVLen - orderB) : ind1= i+n*pntsA;
+       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 + extraPntsB; k++) {
-                               !UV ? ind2= (k%pntsB)+i*pntsB : ind2= 
i+(k%pntsB)*pntsA;
+                       for (k= 0; k < pntsB ; k++) {
+                               int k2 = k % pntsB;
+                               !UV ? ind2= (k2%pntsB)+i2*pntsB : ind2= 
i2+(k2%pntsB)*pntsA;
                                oslo= _Oslo(obj -> KnotVector(UV),KV,obj -> 
Order(UV),n,k);
                                //int temp = ind1;
                                //ind1 = ind2;
@@ -380,7 +387,7 @@
                } //eof
        } //eof
 
-       obj -> Length(UV,KVLen - obj -> Order(UV));
+       obj -> Length(UV, newLength);
 
        //FIXME add ReplaceCtlPts() in object_base
        //
@@ -484,10 +491,10 @@
        if (obj -> Length(0) > 1) {
 
                int knotLen;
-               if(obj->Cyclic(0)) { // not cyclic      
+               if(obj->Cyclic(0)) { // cyclic in U
                        knotLen = (obj -> Length(0) + (obj -> Order(0)*2) -1);
                }
-               else {
+               else { // not cyclic in U
                        knotLen = obj -> Length(0) + (obj -> Order(0));
                        
                }
@@ -511,10 +518,12 @@
                        KV= 
(nbReal*)MEM_callocN(sizeof(nbReal)*2*(knotLen),"Subdivide() KVu");
                        for (i= n= 0; i < knotLen - 1; i++) { //FIXME adjust 
for cyclic
                                KV[n++]= obj -> KnotVector(0)[i];
-                               //if(i==kpu)// FIXME  
-                               if (obj -> KnotVector(0)[i+1] - obj -> 
KnotVector(0)[i])
-                                       //if (i < obj -> Length(0) && i > (obj 
-> Order(0)-1) && obj -> KnotVector(0)[i+1] - obj -> KnotVector(0)[i])
-                                       KV[n++]= (obj -> KnotVector(0)[i+1] + 
obj -> KnotVector(0)[i])/2.0;
+                               if(i==kpu)// FIXME  
+                               //if (obj -> KnotVector(0)[i+1] - obj -> 
KnotVector(0)[i])
+                               //if (i < obj -> Length(0) && i > (obj -> 
Order(0)-1) && obj -> KnotVector(0)[i+1] - obj -> KnotVector(0)[i])
+                                       //if (i < obj -> Length(0) && obj -> 
KnotVector(0)[i+1] - obj -> KnotVector(0)[i])
+                               //if (i > 1 && i < knotLen-4)
+                                               KV[n++]= (obj -> 
KnotVector(0)[i+1] + obj -> KnotVector(0)[i])/2.0;
                        } //eof
                        KV[n++]= obj -> KnotVector(0)[i];
                        _Insert(obj,0,KV,n);
@@ -526,10 +535,10 @@
        if (obj -> Length(1) > 1) {
 
                int knotLen;
-               if(obj->Cyclic(1)) { // not cyclic      
+               if(obj->Cyclic(1)) { // cyclic in V     
                        knotLen = (obj -> Length(1) + (obj -> Order(1)*2) -1);
                }
-               else {
+               else { // not cyclic in V
                        knotLen = obj -> Length(1) + (obj -> Order(1));
                }
                if(*obj->_KnotTypeUV[1] == NURBS_KV_Open) { // Open = endtied
@@ -550,9 +559,9 @@
                        KV= 
(nbReal*)MEM_callocN(sizeof(nbReal)*2*(knotLen),"Subdivide() KVu");
                        for (i= n= 0; i < knotLen - 1; i++) { //FIXME adjust 
for cyclic
                                KV[n++]= obj -> KnotVector(1)[i];
-                               //if(i==kpv)// FIXME  
-                               if (obj -> KnotVector(1)[i+1] - obj -> 
KnotVector(1)[i])
-                                       //if (i < obj -> Length(1) && i > obj 
-> Order(1) && obj -> KnotVector(1)[i+1] - obj -> KnotVector(1)[i])
+                               if(i==kpv)// FIXME  
+                               //if (obj -> KnotVector(1)[i+1] - obj -> 
KnotVector(1)[i])
+                               //      if (i < obj -> Length(1) && i > obj -> 
Order(1) && obj -> KnotVector(1)[i+1] - obj -> KnotVector(1)[i])
                                                KV[n++]= (obj -> 
KnotVector(1)[i+1] + obj -> KnotVector(1)[i])/2.0;
                        } //eof
                        KV[n++]= obj -> KnotVector(1)[i];

Modified: branches/nurbs/blender/intern/nurbana/intern/Object_Base.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/Object_Base.h  2008-09-23 
22:11:23 UTC (rev 16707)

@@ 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