gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] libvob include/vob/geom/Fillets2.hxx include/vo...


From: Janne V. Kujala
Subject: [Gzz-commits] libvob include/vob/geom/Fillets2.hxx include/vo...
Date: Fri, 04 Jul 2003 08:49:54 -0400

CVSROOT:        /cvsroot/libvob
Module name:    libvob
Branch:         
Changes by:     Janne V. Kujala <address@hidden>        03/07/04 08:49:53

Modified files:
        include/vob/geom: Fillets2.hxx 
        include/vob/vobs: Fillet.hxx 
        vob/fillet     : light3d.py 

Log message:
        try one more approach to blending

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/geom/Fillets2.hxx.diff?tr1=1.27&tr2=1.28&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/vobs/Fillet.hxx.diff?tr1=1.43&tr2=1.44&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/fillet/light3d.py.diff?tr1=1.28&tr2=1.29&r1=text&r2=text

Patches:
Index: libvob/include/vob/geom/Fillets2.hxx
diff -u libvob/include/vob/geom/Fillets2.hxx:1.27 
libvob/include/vob/geom/Fillets2.hxx:1.28
--- libvob/include/vob/geom/Fillets2.hxx:1.27   Thu Jul  3 16:21:04 2003
+++ libvob/include/vob/geom/Fillets2.hxx        Fri Jul  4 08:49:53 2003
@@ -722,18 +722,21 @@
        Fillet f;
        ZVec dir;
 
+       float a0;
        float da;
+       float sin_da;
        vector<float> rtbl;
 
        Filletoid(const CircularNode &node,
-            float d,
-            float th,
-            float a,
-            ZVec dir) :
+                 float d,
+                 float th,
+                 float a,
+                 ZVec dir,
+                 int tblsize = 0) :
            node(node),
            c(node, 0, d, th, -1, 0), 
            f(node, c, a), dir(dir) {
-           compute_rtbl(100);
+           if (tblsize) compute_rtbl(tblsize);
        }
 
        Vec trans(ZVec v) const {
@@ -760,29 +763,45 @@
 
        void compute_rtbl(int n) {
            rtbl.resize(n + 1);
-           for (int i = 0; i < n; i++) {
+           
+           a0 = atan(0.5 * c.t / c.d);
+
+           da = (f.tangentAngle - a0) / n;
+           sin_da = sin(da);
+
+           for (int i = 1; i < n; i++) {
                float t = i * (1.0 / n);
-               float a = (t * t) * f.tangentAngle;
+               float a = a0 + t * (f.tangentAngle - a0);
                bool success;
                float fract;
-               ZVec pt = f.point(dirVec(a), success, &fract, .001);
-               if (success)
-                   rtbl[i] = pt.length();
-               else
-                   rtbl[i] = c.d / cos(a);
+               ZVec pt = f.point(dirVec(a), success, &fract, .0001);
+               if (!success) {
+                   cout << "ERROR: Point failed for angle "
+                        << a << " (" << i << ")" << std::endl;
+               }
+               rtbl[i] = pt.length();
                //cout << i << ": " << rtbl[i] << pt << fract << std::endl;
            }
+           rtbl[0] = c.d / cos(a0);
            rtbl[n] = node.r;
        }
 
        float rad_rtbl(Vec v) const {
            int n = rtbl.size() - 1;
            float a = v.atan();
-           float t = sqrt(a / f.tangentAngle);
+           float t = (a - a0) / (f.tangentAngle - a0);
            int i = (int)(t * n);
-           float fract = t * n - i;
+           if (t < 0) return rtbl[0];
            if (i >= n) return rtbl[n];
-           return (1 - fract) * rtbl[i] + fract * rtbl[i + 1];
+
+           float fract = t * n - i;
+           float r0 = rtbl[i];
+           float r1 = rtbl[i + 1];
+
+           return r0 * r1 / (r0 * fract + r1 * (1-fract));
+           return (1 - fract) * r0 + fract * r1;
+           return r0 * r1 * sin_da / (r0 * sin(fract * da) +
+                                      r1 * sin((1-fract) * da)) >? r1;
        }
     };
 
Index: libvob/include/vob/vobs/Fillet.hxx
diff -u libvob/include/vob/vobs/Fillet.hxx:1.43 
libvob/include/vob/vobs/Fillet.hxx:1.44
--- libvob/include/vob/vobs/Fillet.hxx:1.43     Thu Jul  3 16:21:04 2003
+++ libvob/include/vob/vobs/Fillet.hxx  Fri Jul  4 08:49:53 2003
@@ -608,7 +608,7 @@
        
        ZVec ref = t0.transform(ZVec(0,0,1)) - t0.transform(ZVec(0,0,0));
        ZVec e0 = (p1 - p0).normalized();
-       ZVec e1 = e0.crossp(ref).normalized();
+       ZVec e1 = ref.crossp(e0).normalized();
        ZVec e2 = e0.crossp(e1);
 
        float mat[16] = {
@@ -670,9 +670,10 @@
 
     int ndice;
     float dicelen;
+    int tblsize;
 
     template<class F> void params(F &f) {
-       f(ndice, dicelen);
+       f(ndice, dicelen, tblsize);
     }
 
     template<class T> float crad(const T &t) const {
@@ -681,31 +682,45 @@
 
     typedef Filletoid<StretchedCircleFillet> Conn;
 
-    ZVec blend(Conn *conns[], int N, float r, ZVec pt) const {
+    ZVec blend(Conn *conns[], int N, float r, ZVec pt, 
+              int *maxi = NULL) const {
        int i, num = 0;
-       float sum = 0;
+       double sum = 0;
        float x[N];
+       float maxt = 0;
 
        pt = pt.normalized();
 
+       //cout << "Blending " << pt << ": ";
        // Compute distances from the node for each fillet surface
        for (i = 0; i < N; i++) {
            bool success;
            float t = conns[i]->rad(pt, success);
-           if (success)
-               sum += x[num++] = t - r;
+           if (success) {
+               //cout << t << " "; 
+               sum += x[num++] = (t - r) / r;
+               if (maxi) {
+                   if (t > maxt) maxt = t, *maxi = i;
+               }
+           }
        }
 
        // Compute p for an l^p norm to be used as the blending function
        // p == 1: sum of distances, 
        // p == \infty: maximum of distances
-       float p = 1.0 + sum / r;
+       float p = 1.0 + sum;
+       if (p > 100) p = 100;
+
+       //cout << "p=" << p << " ";
 
        sum = 0;
-       for (i = 0; i < num; i++) 
+       for (i = 0; i < num; i++) {
            sum += pow(x[i], p);
+       }
        
-       return pt * (r + pow(sum, 1 / p));
+       //cout << "->" << pow(sum, 1 / p) << std::endl;
+
+       return pt * (r + r * pow(sum, 1 / p));
 
     }
 
@@ -787,7 +802,7 @@
        
     }
 
-    void renderGrid(const std::vector<ZVec> &pt, int n, int m) const {
+    void renderCylinder(const std::vector<ZVec> &pt, int n, int m) const {
        std::vector<ZVec> norm(n * m);
        int i, j;
 
@@ -795,8 +810,8 @@
            for (j = 0; j < m; j++) {
                ZVec px0 = pt[(i==  0 ?   0 : i-1) * m + j];
                ZVec px1 = pt[(i==n-1 ? n-1 : i+1) * m + j];
-               ZVec py0 = pt[i * m + (j==  0 ?   0 : j-1)];
-               ZVec py1 = pt[i * m + (j==m-1 ? m-1 : j+1)];
+               ZVec py0 = pt[i * m + (j==  0 ? m-1 : j-1)];
+               ZVec py1 = pt[i * m + (j==m-1 ?   0 : j+1)];
 
                norm[i * m + j] = (px1 - px0).crossp(py1 - py0).normalized();
            }
@@ -820,6 +835,40 @@
        }
     }
 
+    void renderCylinder2(const std::vector<ZVec> &pt, 
+                    const std::vector<bool> &clip, 
+                    int n, int m) const {
+       std::vector<ZVec> norm(n * m);
+       int i, j;
+
+       for (i = 0; i < n; i++) {
+           for (j = 0; j < m; j++) {
+               ZVec px0 = pt[(i==  0 ?   0 : i-1) * m + j];
+               ZVec px1 = pt[(i==n-1 ? n-1 : i+1) * m + j];
+               ZVec py0 = pt[i * m + (j==  0 ? m-1 : j-1)];
+               ZVec py1 = pt[i * m + (j==m-1 ?   0 : j+1)];
+
+               norm[i * m + j] = (px1 - px0).crossp(py1 - py0).normalized();
+           }
+       }
+
+       for (j = 0; j < m; j++) {
+
+           glBegin(GL_QUAD_STRIP);
+           for (i = 0; i < n; i++) {
+               glNormal(norm[i * m + j]);
+               glVertex(pt[i * m + j]);
+               
+               glNormal(norm[i * m + (j + 1) % m]);
+               glVertex(pt[i * m + (j + 1) % m]);
+
+               if (clip[i * m + j] &&
+                   clip[i * m + (j + 1)]) break;
+           }
+           glEnd();
+       }
+    }
+
     void render(const Transform **t, int n) const {
        const Transform &thick_t = *t[0];
        const Transform &angle_t = *t[1];
@@ -844,24 +893,25 @@
            FilletSpan2::Conn conn(thick_t, angle_t, t0, t1, d);
            
            conns[i] = new Conn(node, d, conn.th, conn.a, 
-                               (p1 - p0).normalized());
+                               (p1 - p0).normalized(), tblsize);
 
            dirs.push_back((p1 - p0).normalized());
        }
 
-#if 0
+#if 1
 
        for (int k = 0; k < N; k++) {
            std::vector<ZVec> pt((ndice + 1) * ndice);
 
+           ZVec ref = t0.transform(ZVec(0,0,1)) - t0.transform(ZVec(0,0,0));
+           ZVec e0 = conns[k]->dir;
+           ZVec e1 = ref.crossp(e0).normalized();
+           ZVec e2 = e0.crossp(e1);
+
            for (i = 0; i <= ndice; i++) {
                float f = (float)i / ndice;
                
                Vec v = conns[k]->f.point(f);
-               
-               ZVec e0 = conns[k]->dir;
-               ZVec e1 = e0.crossp(ref).normalized();
-               ZVec e2 = e0.crossp(e1);
 
                for (j = 0; j < ndice; j++) {
                    float a = j * 2 * M_PI / ndice;
@@ -873,10 +923,37 @@
                }
            }
 
-           for (i = 0; i < (ndice + 1) * ndice; i++)
-               pt[i] = blend(conns, N, r, pt[i]) + p0;
+           std::vector<bool> clip(pt.size());
+           for (i = 0; i <= ndice; i++) {
+               for (j = 0; j < ndice; j++) {
+                   int ind = i * ndice + j;
+                   int maxi;
+                   pt[ind] = blend(conns, N, r, pt[ind], &maxi) + p0;
+                   clip[ind] = (maxi != k);
+               }
+           }
            
-           renderGrid(pt, ndice + 1, ndice);
+           renderCylinder2(pt, clip, ndice + 1, ndice);
+
+           if (k == 0) {
+               for (i = 0; i <= ndice; i++) {
+                   float f = (float)i / ndice;
+               
+                   float a = lerp(conns[k]->f.tangentAngle, M_PI, f);
+                   Vec v(r * cos(a), r * sin(a));
+
+                   for (j = 0; j < ndice; j++) {
+                       float a = j * 2 * M_PI / ndice;
+                       
+                       pt[i * ndice + j] = p0 + 
+                           v.x * e0
+                           + v.y * cos(a) * e1 
+                           + v.y * sin(a) * e2;
+                   }
+               }
+
+               renderCylinder(pt, ndice + 1, ndice);
+           }
        }
 
 #elif 1 // Old  version without Dicer
@@ -901,7 +978,7 @@
        for (i = 0; i < (ndice + 1) * (ndice * 2); i++)
            pt[i] = blend(conns, N, r, pt[i]) + p0;
 
-       renderGrid(pt, ndice + 1, ndice * 2);
+       renderCylinder(pt, ndice + 1, ndice * 2);
                
 
 #else // use Dicer
@@ -961,7 +1038,7 @@
 
            ZVec ref = t0.transform(ZVec(0,0,1)) - t0.transform(ZVec(0,0,0));
            ZVec e0 = conns[i]->dir;
-           ZVec e1 = e0.crossp(ref).normalized();
+           ZVec e1 = ref.crossp(e0).normalized();
            ZVec e2 = e0.crossp(e1);
 
            ZVec p0 = d * e0;
Index: libvob/vob/fillet/light3d.py
diff -u libvob/vob/fillet/light3d.py:1.28 libvob/vob/fillet/light3d.py:1.29
--- libvob/vob/fillet/light3d.py:1.28   Thu Jul  3 11:06:45 2003
+++ libvob/vob/fillet/light3d.py        Fri Jul  4 08:49:53 2003
@@ -201,6 +201,7 @@
            Toggle("perspective", 0, "perspective", "F"),
            Toggle("texture", 0, "texture", "x"),
            SlideLin("dicelen", 100, 5, "Dice length", "G", "g"),
+           SlideLin("tblsize", 100, 1, "Table size", "<", ">"),
 ]
 
 width = 0
@@ -282,7 +283,7 @@
            GLRen.createFillet3D(border, self.dice, 1),
            2)
 
-        conns3dblend = GLRen.createFillet3DBlend(self.dice, self.dicelen);
+        conns3dblend = GLRen.createFillet3DBlend(self.dice, self.dicelen, 
self.tblsize);
 
         thick = vs.coords.rational1D22(0, self.thick, 0, 0,  1, 1, 0);
         angle = vs.coords.rational1D22(0, self.angle, 0, 0,  1, 0, 0);
@@ -327,11 +328,10 @@
                 uLookAt 400 400 -1000 400 400 400 0 -1 0
                 """))
 
-            if self.drawInside:
-                pc(conns3d, [thick, angle])
-
             if self.blend3d:
                 pc(conns3dblend, [thick, angle])
+            elif self.drawInside:
+                pc(conns3d, [thick, angle])
 
             vs.put(getDListNocoords("""
             MatrixMode PROJECTION




reply via email to

[Prev in Thread] Current Thread [Next in Thread]