gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] libvob include/vob/Transform.hxx include/vob/Ve...


From: Tuomas J. Lukka
Subject: [Gzz-commits] libvob include/vob/Transform.hxx include/vob/Ve...
Date: Fri, 06 Jun 2003 04:31:00 -0400

CVSROOT:        /cvsroot/libvob
Module name:    libvob
Branch:         
Changes by:     Tuomas J. Lukka <address@hidden>        03/06/06 04:31:00

Modified files:
        include/vob    : Transform.hxx Vec23.hxx 
        include/vob/geom: Fillets2.hxx 
        include/vob/opt: Zero1D.hxx 
        include/vob/trans: Primitives.hxx 
        include/vob/vobs: Fillet.hxx 
        src/geom       : Quadrics.cxx 
        src/jni        : Makefile-Gen Modules 
        src/trans      : Transform.cxx 
        vob/demo/multifil: multifil.py 
Added files:
        include/vob/trans: ScalarFuncs.hxx 

Log message:
        Ellipse work

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/Transform.hxx.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/Vec23.hxx.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/geom/Fillets2.hxx.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/opt/Zero1D.hxx.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/trans/ScalarFuncs.hxx?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/trans/Primitives.hxx.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/vobs/Fillet.hxx.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/src/geom/Quadrics.cxx.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/src/jni/Makefile-Gen.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/src/jni/Modules.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/src/trans/Transform.cxx.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/demo/multifil/multifil.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: libvob/include/vob/Transform.hxx
diff -u libvob/include/vob/Transform.hxx:1.12 
libvob/include/vob/Transform.hxx:1.13
--- libvob/include/vob/Transform.hxx:1.12       Fri Apr  4 07:34:59 2003
+++ libvob/include/vob/Transform.hxx    Fri Jun  6 04:30:59 2003
@@ -128,6 +128,7 @@
      */
     class RootCoords : public Transform {
     public:
+       RootCoords();
        virtual ZPt transform(const ZPt &p) const {
            return p;
        }
Index: libvob/include/vob/Vec23.hxx
diff -u libvob/include/vob/Vec23.hxx:1.9 libvob/include/vob/Vec23.hxx:1.10
--- libvob/include/vob/Vec23.hxx:1.9    Mon Jun  2 14:18:41 2003
+++ libvob/include/vob/Vec23.hxx        Fri Jun  6 04:30:59 2003
@@ -64,6 +64,12 @@
         */
        Vector(T *v) : x(v[0]), y(v[1]) { }
 
+       template<class F>
+           Vector &operator=(const Vector<F> &v) { x = v.x; y = v.y; return 
*this; }
+
+       template<class F>
+           operator Vector<F>() const { return Vector<F>(x, y); }
+
        /** Making all components finite.
         */
        Vector finitized() const {
@@ -83,7 +89,7 @@
 
        /** Vector negation.
         */
-       Vector<T> operator-() { return Vector<T>(-x, -y); }
+       Vector<T> operator-() const { return Vector<T>(-x, -y); }
        /** Vector addition.
         */
        Vector operator+(const Vector<T>&v) const { return Vector(x+v.x, 
y+v.y); }
@@ -287,10 +293,28 @@
      */
     typedef Vector3<float> ZVec;
 
+    /** Shorthand.
+     */
+    typedef Vector<double> PtD;
+    /** Shorthand.
+     */
+    typedef Vector3<double> ZPtD;
+    /** Shorthand.
+     */
+    typedef Vector<double> VecD;
+    /** Shorthand.
+     */
+    typedef Vector3<double> ZVecD;
+
+
+
     /** Linear interpolation.
      * Returns a + fract*(b-a)
      */
-    template<class X, class Y> inline X lerp(X a, Y b, double fract) {
+    template<class X> inline X lerp(X a, X b, double fract) {
+       return a + fract * (b-a);
+    }
+    inline float lerp(double a, double b, double fract) {
        return a + fract * (b-a);
     }
 
@@ -383,6 +407,10 @@
 using Vec23::ZVec;
 using Vec23::Pt;
 using Vec23::Vec;
+using Vec23::ZPtD;
+using Vec23::ZVecD;
+using Vec23::PtD;
+using Vec23::VecD;
 using Vec23::lerp;
 using Vec23::dirVec;
 }
Index: libvob/include/vob/geom/Fillets2.hxx
diff -u libvob/include/vob/geom/Fillets2.hxx:1.7 
libvob/include/vob/geom/Fillets2.hxx:1.8
--- libvob/include/vob/geom/Fillets2.hxx:1.7    Thu Jun  5 06:37:22 2003
+++ libvob/include/vob/geom/Fillets2.hxx        Fri Jun  6 04:30:59 2003
@@ -1,11 +1,14 @@
 // (c) Tuomas J. Lukka
 
+#include <boost/format.hpp>
+
 #include <vob/Vec23.hxx>
 #include <vob/geom/Quadrics.hxx>
 
 namespace Vob {
 namespace Geom {
     PREDBGVAR(dbg_fillets);
+    using boost::format;
 
     /** Concept: a span of edge.
      * Usually, the 0-side is the connection and 1 is
@@ -125,11 +128,29 @@
     };
 
     /** An elliptical fillet meeting a circle.
+     * All the parameters that specify the shape come from outside.
      */
     struct EllipseCircleFillet {
        const CircularNode &node;
        const LinearConnectionHalf &conn;
        float tangentAngle;
+
+       Vec dirTang;
+       float dtSign;
+
+       Vec ept, eno;
+
+       Vec elli;
+
+       Vec ey;
+       Vec eydir;
+       Vec ex;
+       Vec exdir;
+
+       Vec ecenter;
+
+       float eangle;
+
        /** Make a new fillet.
         * @param ta The tangent angle, i.e. always positive angle between
         *      connection line and tangent line.
@@ -140,11 +161,95 @@
                float ta
                ) : node(node), conn(conn), tangentAngle(ta)
                    {
-           Vec pt = Vec(conn.d, 0) - dirVec(-tangentAngle);
-           Vec no = dirVec(-tangentAngle);
+           eno = Vec(-cos(tangentAngle), sin(tangentAngle));
+           ept = Vec(conn.d, -conn.t/2) + node.r * eno;
+
+           elli = Geom::symmellipse__point_norm(ept, eno);
+
+           ex = -conn.norm * elli.y;
+           exdir = ex.normalized();
+           ey = -conn.dir * elli.x;
+           eydir = ey.normalized();
+
+           ecenter = conn.endPoint - ex;
+
+           dirTang = dirVec(conn.a + conn.sign * tangentAngle);
+           dtSign = conn.sign;
+
+           /* Now, the ellipse always starts at angle 0. Find 
+            * the other angle.
+            */
+           Vec pt2 = ept;
+           pt2.x *= elli.y / elli.x;
+           pt2.y = elli.y - pt2.y;
+
+           eangle = pt2.atan();
+
+           DBG(dbg_fillets) << format("Ellipse: ept: %s, eno: %s, elli: %s, 
ecenter: %s, "
+                               "dirtang: %s, dtsign: %s, eangle: %s\n") %
+                       ept % eno % elli % ecenter % dirTang % dtSign % eangle;
+       }
+
+       float iAngle(Vec dir, bool &succ) const {
+           Vec pt = dir * node.r;
+           Vec ptRel = ecenter - pt;
+           Vec ptC;
+           ptC.x = exdir.dot(ptRel) / elli.y;
+           ptC.y = eydir.dot(ptRel) / elli.x;
+
+           Vec norm;
+           norm.x = dir.x * elli.y;
+           norm.y = dir.y * elli.x;
+
+           ZVec proj = project2circle(ptC + norm, ptC, Vec(0,0), 1, -1, &succ);
+
+           return Vec(proj).atan();
+       }
+
+       ZVec point(float fract, ZVec *intern = 0) const {
+           float angle = lerp(0, eangle, fract);
+           Vec v(cos(angle), sin(angle));
+           ZVec pt = ecenter + v.x * ex + v.y * ey;
+           ZVec proj = conn.projectToConnLine(pt);
+           pt.z = proj.z;
+           if(intern) {
+               if(fract > .94)
+                   *intern = node.ctr;
+               else
+                   *intern = proj;
+           }
+           return pt;
+
+       }
+       void cutEnd(Vec dir) {
+           bool s;
+           eangle = iAngle(dir, s);
+       }
+       ZVec point(Vec dir, bool &success) const {
+           if(dirTang.cross(dir) * dtSign < 0) {
+               success = false;
+               return ZVec(0,0,0);
+           }
+
+           float an = iAngle(dir, success);
+           if(!success) return ZVec(0,0,0);
 
-           Vec elli = Geom::symmellipse__point_norm(pt, no);
+           return point(an / eangle);
        }
+       bool infillet(Vec dir) const {
+           return dirTang.cross(conn.dir) * dirTang.cross(dir) >= 0 &&
+               conn.dir.cross(dirTang) * conn.dir.cross(dir) >= 0;
+       }
+       /** Returns true if either of the directions where the circles
+        * are tangent is inside the other fillet area.
+        * This is not *quite* the same as the trivial definition
+        * of overlapping: it returns false if the tangent points are 
+        * past the connections.
+        */
+       bool overlaps(const EllipseCircleFillet &other) const {
+           return infillet(other.dirTang) || other.infillet(dirTang);
+       }
+
     };
 
     /** A circular fillet edge span, for a circular node.
@@ -167,9 +272,9 @@
         * to the point where
         * the two circles are tangent.
         */
-       Vec dirtang;
+       Vec dirTang;
 
-       /** The sign: calculate cross product of a vector with dirtang,
+       /** The sign: calculate cross product of a vector with dirTang,
         * if sign is same as here, then we it is on the same side as the 
         * arc.
         */
@@ -189,8 +294,8 @@
                circle__point_norm_circle(conn.endPoint, conn.norm, node.ctr, 
node.r);
            this->frad = 
                (fcenter - conn.endPoint).length();
-           this->dirtang = (fcenter - node.ctr) . normalized();
-           this->dtsign = dirtang.cross(conn.dir);
+           this->dirTang = (fcenter - node.ctr) . normalized();
+           this->dtsign = dirTang.cross(conn.dir);
            this->astart = Vec(conn.endPoint - fcenter).atan();
            this->aend = Vec(node.ctr - fcenter).atan();
            while(aend - astart >= M_PI) aend -= 2 * M_PI;
@@ -224,7 +329,7 @@
        }
 
        ZVec point(Vec dir, bool &success) const {
-           if(dirtang.cross(dir) * dtsign < 0) {
+           if(dirTang.cross(dir) * dtsign < 0) {
                success = false;
                return ZVec(0,0,0);
            }
@@ -242,8 +347,8 @@
         * naturally does not.
         */
        bool infillet(Vec dir) const {
-           return dirtang.cross(conn.dir) * dirtang.cross(dir) >= 0 &&
-               conn.dir.cross(dirtang) * conn.dir.cross(dir) >= 0;
+           return dirTang.cross(conn.dir) * dirTang.cross(dir) >= 0 &&
+               conn.dir.cross(dirTang) * conn.dir.cross(dir) >= 0;
        }
        /** Returns true if either of the directions where the circles
         * are tangent is inside the other fillet area.
@@ -252,7 +357,7 @@
         * past the connections.
         */
        bool overlaps(const CircleCircleFillet &other) const {
-           return infillet(other.dirtang) || other.infillet(dirtang);
+           return infillet(other.dirTang) || other.infillet(dirTang);
        }
 
     };
@@ -260,14 +365,14 @@
     /** A blend of two fillets.
      * Note that this is only one side of the blend!
      */
-    struct FilletBlend {
-       CircleCircleFillet main;
-       const CircleCircleFillet &other;
+    template<class S1, class S2> struct FilletBlend {
+       S1 main;
+       const S2 &other;
 
-       FilletBlend(const CircleCircleFillet &main0, 
-                   const CircleCircleFillet &other) :
+       FilletBlend(const S1 &main0, 
+                   const S2 &other) :
                main(main0), other(other) {
-           Vec cutdir = (main.dirtang + other.dirtang).normalized();
+           Vec cutdir = (main.dirTang + other.dirTang).normalized();
            main.cutEnd(cutdir);
        }
 
@@ -287,6 +392,10 @@
            return res;
        }
     };
+    template<class S1, class S2> FilletBlend<S1, S2> makeFilletBlend(
+               const S1 &s1, const S2 &s2) {
+       return FilletBlend<S1,S2>(s1, s2);
+    }
 
     /** A linearly interpolated fillet span between two given 
      * ones.
Index: libvob/include/vob/opt/Zero1D.hxx
diff -u libvob/include/vob/opt/Zero1D.hxx:1.2 
libvob/include/vob/opt/Zero1D.hxx:1.3
--- libvob/include/vob/opt/Zero1D.hxx:1.2       Thu Jun  5 03:57:05 2003
+++ libvob/include/vob/opt/Zero1D.hxx   Fri Jun  6 04:30:59 2003
@@ -6,17 +6,17 @@
     /** A simple 1D zero finder that starts with two points where the function 
must
      * have a different sign.
      */
-    template<class F> float findZero1D(const F &f, float low, float high, 
float epsx, float epsf,
+    template<class F> double findZero1D(const F &f, double low, double high, 
int nrounds,
                bool &success) {
-       float fl = f(low);
-       float fh = f(high);
+       double fl = f(low);
+       double fh = f(high);
        if(fl * fh >= 0) {
            success = false;
            return low;
        }
-       while(fabs(high - low) >= epsx && fabs(fh - fl) >= epsf) {
-           float mid = lerp(low, high, .5);
-           float fm = f(mid);
+       for(int i=0; i<nrounds; i++) {
+           double mid = lerp(low, high, .5);
+           double fm = f(mid);
            if(fm * fl >= 0) {
                low = mid;
                fl = fm;
Index: libvob/include/vob/trans/Primitives.hxx
diff -u libvob/include/vob/trans/Primitives.hxx:1.4 
libvob/include/vob/trans/Primitives.hxx:1.5
--- libvob/include/vob/trans/Primitives.hxx:1.4 Wed May 14 18:03:30 2003
+++ libvob/include/vob/trans/Primitives.hxx     Fri Jun  6 04:31:00 2003
@@ -138,6 +138,12 @@
     class BoxPrimitiveTransform { };
 
 
+    /** A tag for a transform that is not invertible.
+     * This is done this way because the non-invertible 
+     * transforms are rightly in a minority.
+     */
+    class NonInvertiblePrimitiveTransform { };
+
     /** A tag for a primitive transform that can print out
      * stuff.
      * Implies
@@ -388,6 +394,24 @@
            t.setParams(p);
        }
 
+       Transform *getInverse(const void *___) const {
+           InverseHierarchicalTransform<
+               typename Primitive::InverseType, 
+               Primitive> *inv 
+                       = new InverseHierarchicalTransform<
+                           typename Primitive::InverseType,
+                           Primitive >(
+                                   &(super->getInverse()), this);
+           t.inverse(inv->t);
+           return inv;
+       }
+
+       Transform *getInverse(const NonInvertiblePrimitiveTransform *t) const {
+           // XXX Warn?
+           return new RootCoords();
+       }
+
+
        void dumpParams(const DumpingPrimitiveTransform *__, std::ostream &out) 
const {
            t.dump(out);
        }
@@ -449,16 +473,8 @@
  
        virtual const Transform &getInverse() const {
            if(!this->inverse)  {
-               InverseHierarchicalTransform<
-                   typename Primitive::InverseType, 
-                   Primitive> *inv 
-                           = new InverseHierarchicalTransform<
-                               typename Primitive::InverseType,
-                               Primitive >(
-                                       &(super->getInverse()), this);
-               t.inverse(inv->t);
                ((PrimitiveHierarchicalTransform<Primitive> *)this)
-                       ->inverse = inv;
+                       ->inverse = getInverse(&t);
            }
            return *inverse;
        }
Index: libvob/include/vob/vobs/Fillet.hxx
diff -u libvob/include/vob/vobs/Fillet.hxx:1.9 
libvob/include/vob/vobs/Fillet.hxx:1.10
--- libvob/include/vob/vobs/Fillet.hxx:1.9      Thu Jun  5 00:56:12 2003
+++ libvob/include/vob/vobs/Fillet.hxx  Fri Jun  6 04:31:00 2003
@@ -54,13 +54,19 @@
 
     PREDBGVAR(dbg_vfillets);
 
+/** A vob which is used for graph rendering: given a number of coordinate 
systems,
+ * it *sorts* them to angle order and calls its child vob for each pair.
+ * @param single The child vob to call
+ * @param nconst The number of constant coordinate systems to pass forth to 
the child.
+ */
 struct SortedConnections {
     enum { NTrans = -1 };
 
-    Vob3 *single;
+    Vob *single;
+    int nconst;
 
     template<class F> void params(F &f) {
-       f(single);
+       f(single, nconst);
     }
 
     struct AngleInd {
@@ -72,33 +78,43 @@
     void render(const Transform **t, int n) const {
        DBG(dbg_vfillets) << "Sortedconns: start "<<n<<"\n";
        Vec v[n];
-       for(int i=0; i<n; i++)
+       for(int i=nconst; i<n; i++)
            v[i] = t[i]->transform(.5 * t[i]->getSqSize());
 
        AngleInd a[n];
-       a[0].angle = -1000;
-       a[0].ind = 0;
-       for(int i=1; i<n; i++)  {
+       a[nconst].angle = -1000;
+       a[nconst].ind = 0;
+       for(int i=nconst + 1; i<n; i++)  {
            a[i].angle = (v[i] - v[0]).atan();
            a[i].ind = i;
        }
 
-       std::sort(a, a+n);
+       std::sort(a + nconst, a+n);
 
        // Render the circle
+       const Transform *ct[nconst + 3];
+       for(int i=0; i<nconst; i++)
+           ct[i] = t[i];
 
-       for(int i=1; i<n-1; i++) {
+       ct[nconst] = t[nconst + 0]; 
+
+       for(int i=nconst + 1; i<n-1; i++) {
            DBG(dbg_vfillets) << "Sortedconns: "<< i <<" "
                    << a[i].ind << " "
                    << a[i+1].ind <<"\n";
                    
-           single->render3(*t[0], *t[a[i].ind], *t[a[i+1].ind]);
+           ct[nconst + 1] = t[a[i].ind], 
+           ct[nconst + 2] = t[a[i+1].ind];
+           single->render(ct, nconst + 3);
        }
-       
-       single->render3(*t[0], *t[a[n-1].ind], *t[a[1].ind]);
-           DBG(dbg_vfillets) << "Sortedconns final: "
-                   << a[n-1].ind << " "
-                   << a[1].ind <<"\n";
+
+       DBG(dbg_vfillets) << "Sortedconns final: "
+               << a[n-1].ind << " "
+               << a[nconst+1].ind <<"\n";
+
+       ct[nconst + 1] = t[a[n-1].ind], 
+       ct[nconst + 2] = t[a[nconst+1].ind];
+       single->render(ct, nconst + 3);
        
     }
 
@@ -106,161 +122,8 @@
 
 VOB_DEFINED(SortedConnections);
 
-struct FilletSpan1 {
-    enum { NTrans = 3 };
-
-    int ndice;
-    int flags;
-
-    template<class T> float crad(const T &t) const {
-       return t.getSqSize().x;
-    }
-    template<class T> float th(const T &t0, const T &t1, float d) const {
-       float r0 = crad(t0);
-       float r1 = crad(t1);
-       float rmax = r0 >? r1;
-       float rmin = r0 <? r1;
-       if(d <= rmax - rmin) return .96 * rmin;
-       float dr = (d - (rmax-rmin)) / (r0 + r1);
-       return .96 * rmin *  1 / (1 + dr);
-    }
-    
-    template<class F> void params(F &f) {
-       f(ndice, flags);
-    }
-
-    void v(ZVec p) const {
-       if(flags & 4) {
-           glColor3f(1, p.z / 100, p.z / 100);
-       }
-       glVertex(p);
-    }
-
-    void vl(ZVec p) const {
-       if(flags & 4) {
-           glColor3f(0,p.z / 100, p.z / 100);
-       }
-       glVertex(p);
-    }
-
-    template<class T> void render(const T &t0, const T &t1, const T &t2) 
-           const {
-       ZVec p0 = t0.transform(t0.getSqSize());
-       ZVec p1 = t1.transform(t1.getSqSize()) ;
-       ZVec p2 = t2.transform(t2.getSqSize()) ;
-
-       ZVec ctr = p0;
-       Vec v1 = p1 - ctr;
-       Vec v2 = p2 - ctr;
-
-       DBG(dbg_vfillets) << "FilletSpan "<<ctr<<" "<<v1<<" "<<v2<<"\n";
-
-       float a1 = v1.atan();
-       float a2 = v2.atan();
-       if(a2 < a1 || &t1 == &t2) a2 += 2*M_PI;
-
-       float d1 = v1.length() / 2;
-       float d2 = v2.length() / 2;
-
-       float th1 = th(t0, t1, d1);
-       float th2 = th(t0, t2, d2);
-
-       float csize = crad(t0);
-
-       DBG(dbg_vfillets) << "P: "<<ctr<<" "<<csize<<" "<<
-                   a1<<" "<<d1<<" "<<th1<<" "<<
-                   a2<<" "<<d2<<" "<<th2<<" "<<
-                   "\n";
-
-       FilletSpan sp(ctr, csize,
-               a1, d1, th1, lerp(p0.z, p1.z, .5),
-               a2, d2, th2, lerp(p0.z, p2.z, .5));
-       if(!(flags & 8)) {
-           if(sp.split()) {
-               if(flags & 1) {
-                   ZVec intern;
-                   glBegin(GL_QUAD_STRIP); 
-                   for(float f = 0; f < .5; f+= 1.0 / ndice) {
-                       ZVec p = sp.point(f, BlendSimply(), &intern);
-                       v(p);
-                       v(intern);
-                   }
-                   glEnd();
-                   glBegin(GL_QUAD_STRIP);
-                   for(float f = 1; f > .5; f-= 1.0 / ndice) {
-                       ZVec p = sp.point(f, BlendSimply(), &intern);
-                       v(p);
-                       v(intern);
-                   }
-                   glEnd();
-               }
-               if(flags & 2) {
-                   glBegin(GL_LINE_STRIP); 
-                   for(float f = 0; f < .5; f+= 1.0 / ndice) {
-                       ZVec p = sp.point(f, BlendSimply());
-                       vl(p);
-                   }
-                   glEnd();
-                   glBegin(GL_LINE_STRIP);
-                   for(float f = 1; f > .5; f-= 1.0 / ndice) {
-                       ZVec p = sp.point(f, BlendSimply());
-                       vl(p);
-                   }
-                   glEnd();
-               }
-           } else {
-               if(flags & 1) {
-                   ZVec intern;
-                   glBegin(GL_QUAD_STRIP); 
-                   for(float f = 0; f < 1; f+= 1.0 / ndice) {
-                       ZVec p = sp.point(f, BlendSimply(), &intern);
-                       v(p);
-                       v(intern);
-                   }
-                   glEnd();
-               } 
-               if(flags & 2) {
-                   glBegin(GL_LINE_STRIP); 
-                   for(float f = 0; f < 1; f+= 1.0 / ndice) {
-                       ZVec p = sp.point(f, BlendSimply(), 0);
-                       vl(p);
-                   }
-                   glEnd();
-               }
-           }
-       } else {
-           // Render non-filleted connection
-           if(flags & 1) {
-               glBegin(GL_TRIANGLE_FAN); 
-               v(ctr);
-               for(float f = 0; f <= 1; f+= 1.0 / ndice) {
-                   float a = lerp(a1, a2, f);
-                   ZVec p = ctr + dirVec(a) * csize;
-                   v(p);
-               }
-               glEnd();
-           }
-           if (flags & 2) {
-               glBegin(GL_LINE_STRIP); 
-               ZVec p = 0.5 * (p0 + p1);
-               vl(p);
-               for(float f = 0; f <= 1.0; f+= 1.0 / ndice) {
-                   float a = lerp(a1, a2, f);
-                   ZVec p = ctr + dirVec(a) * csize;
-                   vl(p);
-               }
-               glEnd();
-           }
-           
-       }
-    }
-};
-
-
-VOB_DEFINED(FilletSpan1);
-
 struct FilletSpan2 {
-    enum { NTrans = 3 };
+    enum { NTrans = -1 };
 
     float border;
     int ndice;
@@ -273,15 +136,36 @@
     template<class T> float crad(const T &t) const {
        return t.getSqSize().x;
     }
-    template<class T> float th(const T &t0, const T &t1, float d) const {
-       float r0 = crad(t0);
-       float r1 = crad(t1);
+
+    struct Conn {
+       template<class T> float crad(const T &t) const {
+           return t.getSqSize().x;
+       }
+       float th;
+       float a;
+
+       Conn(const Transform &thick_t, const Transform &angle_t,
+               const Transform &t0, const Transform &t1, float d) {
+           float r0 = crad(t0);
+           float r1 = crad(t1);
+           float r = lerp(r0, r1, .5);
+           th = r * thick_t.transform(ZVec(d / r, 0, 0)).x;
+
+           a = angle_t.transform(ZVec(d / r, 0, 0)).x;
+           DBG(dbg_vfillets) << 
+               format("FilletSpan CONN: r: %s d: %s  th: %s a: %s") %
+                   r% d% th% a;
+       }
+    };
+
+       /*
        float rmax = r0 >? r1;
        float rmin = r0 <? r1;
        if(d <= rmax - rmin) return .96 * rmin;
        float dr = (d - (rmax-rmin)) / (r0 + r1);
        return .96 * rmin *  1 / (1 + dr);
-    }
+       */
+
 
     void v(ZVec p) const {
        if(flags & 4) {
@@ -297,28 +181,6 @@
        glVertex(p);
     }
 
-    template<class G> void renderSpanSolid(const G &g) const {
-       glBegin(GL_QUAD_STRIP); 
-       for(int i=0; i<ndice; i++) {
-           float fract = i / (ndice-1.0);
-           ZVec intern;
-           ZVec pt = g.point(fract, &intern);
-           v(pt);
-           v(intern);
-       }
-       glEnd();
-    }
-
-    template<class G> void renderSpanLine(const G &g) const {
-       glBegin(GL_LINE_STRIP); 
-       for(int i=0; i<ndice; i++) {
-           float fract = i / (ndice-1.0);
-           ZVec pt = g.point(fract, 0);
-           vl(pt);
-       }
-       glEnd();
-    }
-
     void pointInternNormal(ZVec p, ZVec intern, ZVec normal) const {
        if(flags & 1) {
            // solid 
@@ -365,14 +227,7 @@
     }
 
     template<class G> void renderSpan(const G &g, int sign) const {
-       if(flags & 8) {
-           renderSpanPolyedged(g, -sign);
-       } else {
-           if(flags & 1) 
-               renderSpanSolid(g);
-           if(flags & 2) 
-               renderSpanLine(g);
-       }
+       renderSpanPolyedged(g, -sign);
     }
 
 
@@ -383,8 +238,14 @@
        return a;
     }
 
-    template<class T> void render(const T &t0, const T &t1, const T &t2) 
-           const {
+    void render(const Transform **t, int n) const {
+       const Transform &thick_t = *t[0];
+       const Transform &angle_t = *t[1];
+
+       const Transform &t0 = *t[2];
+       const Transform &t1 = *t[3];
+       const Transform &t2 = *t[4];
+
        ZVec p0 = t0.transform(t0.getSqSize());
        ZVec p1 = t1.transform(t1.getSqSize()) ;
        ZVec p2 = t2.transform(t2.getSqSize()) ;
@@ -402,11 +263,14 @@
        float d1 = v1.length() / 2;
        float d2 = v2.length() / 2;
 
-       float th1 = th(t0, t1, d1);
-       float th2 = th(t0, t2, d2);
-
        float csize = crad(t0);
 
+       Conn conn1(thick_t, angle_t, t0, t1, d1);
+       Conn conn2(thick_t, angle_t, t0, t2, d2);
+
+       float th1 = conn1.th;
+       float th2 = conn2.th;
+
        DBG(dbg_vfillets) << "P: "<<ctr<<" "<<csize<<" "<<
                    a1<<" "<<d1<<" "<<th1<<" "<<
                    a2<<" "<<d2<<" "<<th2<<" "<<
@@ -416,63 +280,118 @@
        LinearConnectionHalf c1(node, a1, d1, th1, 1, lerp(p0.z, p1.z, .5));
        LinearConnectionHalf c2(node, a2, d2, th2, -1, lerp(p0.z, p2.z, .5));
 
-       CircleCircleFillet f1(node, c1);
-       CircleCircleFillet f2(node, c2);
+       // Ellipses
+       if(flags & 16) {
+           // For now, fix angle of attachment to the given angle
+           EllipseCircleFillet f1(node, c1, conn1.a);
+           EllipseCircleFillet f2(node, c2, conn2.a);
+
+           // Find out how close they are.
+           if(a2-a1 < M_PI &&
+                   (f1.infillet(f2.conn.dir) ||
+                    f2.infillet(f1.conn.dir))) {
+               // Cleaved case
+               // Need to construct virtual second connection, with only angle 
changed
+
+               // Width of fillet in radians
+               float w1 = normAngle(f1.dirTang.atan() - a1);
+               float w2 = normAngle(a2 - f2.dirTang.atan());
+               float maxw = w1 >? w2;
+               // Angle between connections
+               float ab = a2 - a1;
+
+               float fract = (maxw - ab) / maxw;
+               float va1 = a2 - maxw;
+               float va2 = a1 + maxw;
+
+               LinearConnectionHalf vc2(node, va2, d2, th2, -1, lerp(p0.z, 
p2.z, .5));
+               EllipseCircleFillet vf2(node, vc2, conn2.a);
+
+               LinearConnectionHalf vc1(node, va1, d1, th1, 1, lerp(p0.z, 
p1.z, .5));
+               EllipseCircleFillet vf1(node, vc1, conn1.a);
+
+               DBG(dbg_vfillets) << "P cleave: "<< w1<<" "<<w2<<" "
+                       << ab<<" "<<fract<<" "<<va1<<" "<<va2<<
+                           "\n";
+               renderSpan(
+                       makeLerpFilletSpan(
+                           makeFilletBlend(f1, vf2),
+                           f1,
+                           fract), 1
+                       );
+
+               renderSpan(
+                       makeLerpFilletSpan(
+                           makeFilletBlend(f2, vf1),
+                           f2,
+                           fract), -1
+                       );
+           } else 
+               renderNormalOrBlend(node, f1, f2);
+       } else {
+
+           CircleCircleFillet f1(node, c1);
+           CircleCircleFillet f2(node, c2);
 
-       // Find out how close they are.
-       if(a2-a1 < M_PI &&
-               (f1.infillet(f2.conn.dir) ||
-                f2.infillet(f1.conn.dir))) {
-           // Cleaved case
-           // Need to construct virtual second connection, with only angle 
changed
-
-           // Width of fillet in radians
-           float w1 = normAngle(f1.dirtang.atan() - a1);
-           float w2 = normAngle(a2 - f2.dirtang.atan());
-           float maxw = w1 >? w2;
-           // Angle between connections
-           float ab = a2 - a1;
-
-           float fract = (maxw - ab) / maxw;
-           float va1 = a2 - maxw;
-           float va2 = a1 + maxw;
-
-           LinearConnectionHalf vc2(node, va2, d2, th2, -1, lerp(p0.z, p2.z, 
.5));
-           CircleCircleFillet vf2(node, vc2);
-
-           LinearConnectionHalf vc1(node, va1, d1, th1, 1, lerp(p0.z, p1.z, 
.5));
-           CircleCircleFillet vf1(node, vc1);
-
-           DBG(dbg_vfillets) << "P cleave: "<< w1<<" "<<w2<<" "
-                   << ab<<" "<<fract<<" "<<va1<<" "<<va2<<
-                       "\n";
-           renderSpan(
-                   makeLerpFilletSpan(
-                       FilletBlend(f1, vf2),
-                       f1,
-                       fract), 1
-                   );
-
-           renderSpan(
-                   makeLerpFilletSpan(
-                       FilletBlend(f2, vf1),
-                       f2,
-                       fract), -1
-                   );
-       } else if(f1.overlaps(f2)) {
-           renderSpan(FilletBlend(f1, f2), 1);
-           renderSpan(FilletBlend(f2, f1), -1);
+           // Find out how close they are.
+           if(a2-a1 < M_PI &&
+                   (f1.infillet(f2.conn.dir) ||
+                    f2.infillet(f1.conn.dir))) {
+               // Cleaved case
+               // Need to construct virtual second connection, with only angle 
changed
+
+               // Width of fillet in radians
+               float w1 = normAngle(f1.dirTang.atan() - a1);
+               float w2 = normAngle(a2 - f2.dirTang.atan());
+               float maxw = w1 >? w2;
+               // Angle between connections
+               float ab = a2 - a1;
+
+               float fract = (maxw - ab) / maxw;
+               float va1 = a2 - maxw;
+               float va2 = a1 + maxw;
+
+               LinearConnectionHalf vc2(node, va2, d2, th2, -1, lerp(p0.z, 
p2.z, .5));
+               CircleCircleFillet vf2(node, vc2);
+
+               LinearConnectionHalf vc1(node, va1, d1, th1, 1, lerp(p0.z, 
p1.z, .5));
+               CircleCircleFillet vf1(node, vc1);
+
+               DBG(dbg_vfillets) << "P cleave: "<< w1<<" "<<w2<<" "
+                       << ab<<" "<<fract<<" "<<va1<<" "<<va2<<
+                           "\n";
+               renderSpan(
+                       makeLerpFilletSpan(
+                           makeFilletBlend(f1, vf2),
+                           f1,
+                           fract), 1
+                       );
+
+               renderSpan(
+                       makeLerpFilletSpan(
+                           makeFilletBlend(f2, vf1),
+                           f2,
+                           fract), -1
+                       );
+           } else 
+               renderNormalOrBlend(node, f1, f2);
+       }
+
+    }
+
+    template<class F> void renderNormalOrBlend(const CircularNode &node, const 
F &f1, const F &f2) const {
+       if(f1.overlaps(f2)) {
+           renderSpan(makeFilletBlend(f1, f2), 1);
+           renderSpan(makeFilletBlend(f2, f1), -1);
        } else {
            renderSpan(f1, 1);
-           float ta1 = f1.dirtang.atan();
-           float ta2 = f2.dirtang.atan();
+           float ta1 = f1.dirTang.atan();
+           float ta2 = f2.dirTang.atan();
            if(ta2 < ta1) ta2 += 2*M_PI;
            renderSpan(CircularNodeSpan(node, ta1, ta2), 1);
            renderSpan(f2, -1);
        }
-
     }
-
 
 };
 VOB_DEFINED(FilletSpan2);
Index: libvob/src/geom/Quadrics.cxx
diff -u libvob/src/geom/Quadrics.cxx:1.2 libvob/src/geom/Quadrics.cxx:1.3
--- libvob/src/geom/Quadrics.cxx:1.2    Thu Jun  5 03:57:05 2003
+++ libvob/src/geom/Quadrics.cxx        Fri Jun  6 04:31:00 2003
@@ -1,5 +1,8 @@
 // (c) Tuomas J. Lukka
 
+#include <boost/format.hpp>
+
+#include <vob/Debug.hxx>
 #include <vob/opt/Zero1D.hxx>
 #include <vob/geom/Quadrics.hxx>
 
@@ -7,20 +10,27 @@
 
 namespace Geom {
 
+    DBGVAR(dbg_quadrics, "Quadrics");
+
+    using boost::format;
+
     struct SymEllProblem {
-       Vec point;
-       Vec normal;
+       VecD point;
+       VecD normal;
 
-       Vec centerPoint(float s) const {
+       VecD centerPoint(double s) const {
            // Point and normal in this scaled problem
-           Vec p(s * point.x, point.y);
-           Vec n(normal.x / s, normal.y);
+           VecD p(s * point.x, point.y);
+           VecD n(normal.x / s, normal.y);
            n = n.normalized();
 
            // Find point on x==0
-           float m = - p.x / normal.x;
-           Vec p0 = p + m * n;
+           double m = - p.x / n.x;
+           VecD p0 = p + m * n;
            // Invariant: p0.x == 0
+           DBG(dbg_quadrics) << 
+               format("sep: p: %s, n:%s, m:%s, p0:%s\n") 
+                   % p % n % m % p0;
            return p0;
 
        }
@@ -28,12 +38,16 @@
        /** Calculate the discrepancy: a number that is zero when 
         * the s given to us is right and positive and negative otherwise.
         */
-       float operator()(float s) const {
+       double operator()(double s) const {
            // Point in the scaled problem
-           Vec p(s * point.x, point.y);
+           VecD p(s * point.x, point.y);
 
-           Vec p0 = centerPoint(s);
-           return (p0.length() - (p0-p).length());
+           VecD p0 = centerPoint(s);
+           double ret = (p0.length() - (p0-p).length());
+           DBG(dbg_quadrics) << 
+               format("s: %s, p:%s, p0:%s ret::%s\n") 
+                   % s % p % p0 % ret;
+           return ret;
        }
 
     };
@@ -44,9 +58,9 @@
        prob.normal = normal;
 
        bool succ;
-       float scale = Opt::findZero1D(prob, .00001, 10000, .0001, .0001, succ);
+       double scale = Opt::findZero1D(prob, .001, 1000, 35, succ);
 
-       Vec res = prob.centerPoint(scale);
+       VecD res = prob.centerPoint(scale);
        res.x = res.y / scale;
        return res;
     }
Index: libvob/src/jni/Makefile-Gen
diff -u libvob/src/jni/Makefile-Gen:1.7 libvob/src/jni/Makefile-Gen:1.8
--- libvob/src/jni/Makefile-Gen:1.7     Mon May 19 05:13:00 2003
+++ libvob/src/jni/Makefile-Gen Fri Jun  6 04:31:00 2003
@@ -41,7 +41,7 @@
 
 
 Generator: GeneratorMain.o $(VOB_OBJS) $(TRANS_OBJS)
-       $(CXX) -o Generator $(CXXFLAGS) $(EXTRAINCLUDE) GeneratorMain.cxx 
$(VOB_OBJS) $(TRANS_OBJS) ../util/Debug.o ../util/intersect.o $(LIBS)
+       $(CXX) -o Generator $(CXXFLAGS) $(EXTRAINCLUDE) GeneratorMain.cxx 
$(VOB_OBJS) $(TRANS_OBJS) ../util/Debug.o ../util/intersect.o 
../trans/Transform.o $(LIBS)
 
 .PHONY: javahs
 
Index: libvob/src/jni/Modules
diff -u libvob/src/jni/Modules:1.5 libvob/src/jni/Modules:1.6
--- libvob/src/jni/Modules:1.5  Thu May 29 04:00:20 2003
+++ libvob/src/jni/Modules      Fri Jun  6 04:31:00 2003
@@ -4,7 +4,8 @@
        LinearPrimitives                \
        FunctionalPrimitives            \
        DisablablePrimitives            \
-       FisheyePrimitives
+       FisheyePrimitives               \
+       ScalarFuncs
 VOBS=          \
        Trivial                         \
        Pixel                           \
Index: libvob/src/trans/Transform.cxx
diff -u libvob/src/trans/Transform.cxx:1.3 libvob/src/trans/Transform.cxx:1.4
--- libvob/src/trans/Transform.cxx:1.3  Fri Feb 28 08:56:08 2003
+++ libvob/src/trans/Transform.cxx      Fri Jun  6 04:31:00 2003
@@ -28,7 +28,9 @@
 #include <vob/Transform.hxx>
 
 namespace Vob {
-       void RootCoords::vertex(const ZPt &p) const {
-           glVertex3f(p.x, p.y, p.z);
-       }
+    RootCoords::RootCoords() {
+    }
+    void RootCoords::vertex(const ZPt &p) const {
+       glVertex3f(p.x, p.y, p.z);
+    }
 }
Index: libvob/vob/demo/multifil/multifil.py
diff -u libvob/vob/demo/multifil/multifil.py:1.7 
libvob/vob/demo/multifil/multifil.py:1.8
--- libvob/vob/demo/multifil/multifil.py:1.7    Thu Jun  5 00:56:12 2003
+++ libvob/vob/demo/multifil/multifil.py        Fri Jun  6 04:31:00 2003
@@ -17,11 +17,13 @@
             self, 
            SlideLin("x", 200, 20, "x", "Left", "Right"),
            SlideLin("y", 300, 20, "y", "Up", "Down"),
+           SlideLin("angle", math.pi/4, .05, "meet angle", "+", "-"),
+           SlideLin("thick", .1, .01, "thickness", "T", "t"),
            Toggle("drawEdge", 1, "Draw edge", "e"),
            Toggle("drawInside", 1, "Draw inside", "i"),
            Toggle("depthColor", 0, "Color from depth", "d"),
            Toggle("lines", 0, "Toggle showing lines", "l"),
-           Toggle("fillets", 1, "Toggle filleting", "f"),
+           Toggle("ellipses", 1, "Toggle ellipses", "s"),
        )
     def scene(self, vs):
        putnoc(vs, background((.5,1,.2)))
@@ -37,12 +39,20 @@
        if self.lines:
            vs.put(getDListNocoords("PolygonMode FRONT_AND_BACK LINE"))
 
+       angle = vs.orthoCS(0, "Ang", 0, self.angle, 0, 0, 0);
+
+       thick = vs.orthoCS(0, "Thi", 0, self.thick, 0, 0, 0);
+
        dice = 20
        border = 2
        conns = GLRen.createSortedConnections(
-           GLRen.createFilletSpan2(border, dice, 1 + 4*self.depthColor + 
8*(1-self.fillets)))
+           GLRen.createFilletSpan2(border, dice, 
+                           1 + 4*self.depthColor + 16 * self.ellipses),
+           2)
        conns_l = GLRen.createSortedConnections(
-           GLRen.createFilletSpan2(border, dice, 2 + 4*self.depthColor + 
8*(1-self.fillets)))
+           GLRen.createFilletSpan2(border, dice, 
+                           2 + 4*self.depthColor + 16 * self.ellipses),
+           2)
 
        size = 50
        
@@ -53,15 +63,20 @@
        e = vs.orthoBoxCS(0, "E", 100, 500, 500, 1, 1, size, size);
 
        def pc(conns):
-           vs.put(conns, [a,  b, c, d])
-           vs.put(GLRen.createDebugSwitch("Fillets", 1));
+           # vs.put(conns, [a,  b, c, d])
+           # vs.put(conns, [b,  a, d, e]);
+           # vs.put(conns, [c,  a]);
+           # vs.put(conns, [d,  a, b]);
+
+           vs.put(conns, [thick, angle, b,  e]);
+
+#          vs.put(GLRen.createDebugSwitch("Fillets", 1));
            vs.put(GLRen.createDebugSwitch("VFillets", 1));
-           vs.put(conns, [b,  a, d, e]);
-           vs.put(GLRen.createDebugSwitch("Fillets", 0));
+           #vs.put(GLRen.createDebugSwitch("Quadrics", 1));
+           vs.put(conns, [thick, angle, e,  b]);
+#          vs.put(GLRen.createDebugSwitch("Fillets", 0));
            vs.put(GLRen.createDebugSwitch("VFillets", 0));
-           vs.put(conns, [c,  a]);
-           vs.put(conns, [d,  a, b]);
-           vs.put(conns, [e,  b]);
+           #vs.put(GLRen.createDebugSwitch("Quadrics", 0));
 
 
 




reply via email to

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