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 vobs/Fille...


From: Janne V. Kujala
Subject: [Gzz-commits] libvob/include/vob geom/Fillets2.hxx vobs/Fille...
Date: Wed, 02 Jul 2003 09:23:51 -0400

CVSROOT:        /cvsroot/libvob
Module name:    libvob
Branch:         
Changes by:     Janne V. Kujala <address@hidden>        03/07/02 09:23:51

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

Log message:
        start Delaunay triangulation based filleted node topology

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/geom/Fillets2.hxx.diff?tr1=1.24&tr2=1.25&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/vobs/Fillet.hxx.diff?tr1=1.37&tr2=1.38&r1=text&r2=text

Patches:
Index: libvob/include/vob/geom/Fillets2.hxx
diff -u libvob/include/vob/geom/Fillets2.hxx:1.24 
libvob/include/vob/geom/Fillets2.hxx:1.25
--- libvob/include/vob/geom/Fillets2.hxx:1.24   Wed Jun 25 09:15:21 2003
+++ libvob/include/vob/geom/Fillets2.hxx        Wed Jul  2 09:23:51 2003
@@ -1,7 +1,7 @@
 /*
 Fillets2.hxx
  *    
- *    Copyright (c) 2003, Tuomas J. Lukka
+ *    Copyright (c) 2003, Tuomas J. Lukka and Janne V. Kujala
  *    This file is part of Libvob.
  *    
  *    Libvob is free software; you can redistribute it and/or modify it under
@@ -21,7 +21,7 @@
  *    
  */
 /*
- * Written by Tuomas J. Lukka
+ * Written by Tuomas J. Lukka and Janne V. Kujala
  */
 
 #include <boost/format.hpp>
@@ -645,5 +645,72 @@
 
     };
 
+    struct int3 {
+       int v[3];
+       int3(int a, int b, int c) { v[0] = a; v[1] = b; v[2] = c; }
+       
+       int operator[](int i) const { return v[i]; }
+    };
+
+    /** Spherical delaunay triangulation
+     * Naive O(n^4) implementation,
+     * probably has problems with more than three coplanar vertices
+     */
+    template <class ZVecArray>
+    void Triangulate(ZVecArray v, int n, 
+                    std::vector<int3> &tri) {
+       int i, j, k, l;
+       
+       for (i = 0; i < n; i++)
+           for (j = i + 1; j < n; j++)
+               for (k = j + 1; k < n; k++) {
+                   ZVec d = (v[i] - v[k]).crossp(v[j] - v[k]).normalized();
+                   d /= d.dot(v[k]);
+                   for (l = 0; l < n; l++) {
+                       if (l == i || l == j || l == k) continue;
+                       if (d.dot(v[l]) >= 1) break;
+                   }
+                   if (l == n)
+                       tri.push_back(int3(i,j,k));
+               }
+       
+    }
+
+    /** Build a matrix of the number of triangles using each edge
+     */
+    template <class IntArray>
+    void FindEdges(IntArray edge, int n, 
+                  std::vector<int3> &tri) {
+       int i, j;
+       int m = tri.size();
+
+       for (i = 0; i < n; i++)
+           for (j = 0; j < n; j++)
+               edge[n * i + j] = 0;
+
+       for (i = 0; i < m; i++) {
+           edge[n * tri[i][0] + tri[i][1]]++;
+           edge[n * tri[i][1] + tri[i][2]]++;
+           edge[n * tri[i][0] + tri[i][2]]++;
+       }
+    }
+
+    /** Mark vertices whose edges belong to only one triangle 
+     */
+    template <class IntArray1, class IntArray2>
+    void FindEdgeVertices(IntArray1 vert, IntArray2 edge, int n) {
+       int i, j;
+       
+       for (i = 0; i < n; i++)
+           vert[i] = 0;
+       
+       for (i = 0; i < n; i++)
+           for (j = i + 1; j < n; j++)
+               if (edge[n * i + j] == 1)
+                   vert[i] = vert[j] = 1;
+    }
+
+
+    
 }
 }
Index: libvob/include/vob/vobs/Fillet.hxx
diff -u libvob/include/vob/vobs/Fillet.hxx:1.37 
libvob/include/vob/vobs/Fillet.hxx:1.38
--- libvob/include/vob/vobs/Fillet.hxx:1.37     Tue Jul  1 10:52:30 2003
+++ libvob/include/vob/vobs/Fillet.hxx  Wed Jul  2 09:23:51 2003
@@ -725,7 +725,7 @@
        }
 
        // Compute p for an l^p norm to be used as the blending function
-       // p == 1: sum of distance, 
+       // p == 1: sum of distances, 
        // p == \infty: maximum of distances
        float p = 1.0 + sum;
 
@@ -737,6 +737,52 @@
 
     }
 
+    struct Vert : ZVec {
+       bool bound;
+       ZVec norm;
+       Vert(const ZVec &v, bool b = false) : ZVec(v), bound(b) {}
+    };
+
+    struct Verts : std::vector<Vert> {
+       const Fillet3DBlend &f;
+       Conn **conns;
+       int N;
+       float r;
+
+       int operator() (int i, int j, float fract = .5) {
+           int ind = size();
+           push_back(f.blend(conns, N, r,
+                             lerp(operator[](i), operator[](j), fract)));
+           return ind;
+       }
+
+       Verts(const Fillet3DBlend &f, Conn **conns, int N, float r) : 
+           f(f), conns(conns), N(N), r(r) {}
+    };
+
+    struct DiceCrit {
+       const Verts &v;
+       float dicelen;
+
+       DiceCrit(const Verts &v, float dicelen) : v(v), dicelen(dicelen) {}
+
+       int operator()(int i, int j, int k) {
+           float l0 = (v[i] - v[j]).length() * !(v[i].bound && v[j].bound);
+           float l1 = (v[j] - v[k]).length() * !(v[j].bound && v[k].bound);
+           float l2 = (v[k] - v[i]).length() * !(v[k].bound && v[i].bound);
+
+           if (l0 < dicelen && l1 < dicelen && l2 < dicelen)
+               return -1;
+
+           if(l0 > l1 && l0 > l2) return 0;
+           if(l1 > l2) return 1;
+           return 2;
+       }
+    };
+
+
+    
+
     void render(const Transform **t, int n) const {
        const Transform &thick_t = *t[0];
        const Transform &angle_t = *t[1];
@@ -750,6 +796,9 @@
 
        Conn* conns[N];
 
+       std::vector<ZVec> dirs;
+       std::vector<int3> tri;
+
        int i, j;
        for (i = 0; i < N; i++) {
            const Transform &t1 = *t[3 + i];
@@ -760,6 +809,50 @@
 
            conns[i] = new Conn(node, d, conn.th, conn.a, 
                                (p1 - p0).normalized());
+
+           dirs.push_back((p1 - p0).normalized());
+       }
+
+       if (dirs.size() == 2) {
+           ZVec sum = dirs[0] + dirs[1];
+           ZVec dif = dirs[1] - dirs[0];
+
+           ZVec v0 = -sum.normalized();
+           ZVec v1 = sum.crossp(dif).normalized();
+           dirs.push_back((v0 - v1).normalized());
+           dirs.push_back((v0 + v1).normalized());
+       }
+
+       Triangulate(dirs, dirs.size(), tri);
+
+       {
+           int edge[dirs.size() * dirs.size()];
+           int vert[dirs.size()];
+           FindEdges(edge, dirs.size(), tri);
+           FindEdgeVertices(vert, edge, dirs.size());
+           ZVec sum(0,0,0);
+           bool incomplete = false;
+           for (i = 0; i < (int)dirs.size(); i++) {
+               if (vert[i]) {
+                   sum += dirs[i];
+                   incomplete = true;
+               }
+           }
+           if (incomplete) {
+               dirs.push_back(-sum.normalized());
+               tri.clear();
+               Triangulate(dirs, dirs.size(), tri);
+           }
+       }
+           
+
+
+       for (i = 0; i < (int)tri.size(); i++) {
+           glBegin(GL_LINE_LOOP);
+           glVertex(p0 + 3 * r * dirs[tri[i][0]]);
+           glVertex(p0 + 3 * r * dirs[tri[i][1]]);
+           glVertex(p0 + 3 * r * dirs[tri[i][2]]);
+           glEnd();
        }
 
 




reply via email to

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