/[libvob]/libvob/include/vob/vobs/Paper.hxx
ViewVC logotype

Diff of /libvob/include/vob/vobs/Paper.hxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by tjl, Thu Apr 24 17:49:53 2003 UTC revision 1.7 by tjl, Wed May 7 12:00:42 2003 UTC
# Line 32  namespace PaperPriv { Line 32  namespace PaperPriv {
32    
33  struct Verts {  struct Verts {
34      const Transform &t;      const Transform &t;
     Verts(const Transform &t) : t(t) { }  
35    
36      struct T2V3Vert {      struct T2V3Vert {
37          Pt orig;          Pt orig;
# Line 43  struct Verts { Line 42  struct Verts {
42      };      };
43      vector<T2V3Vert> points;      vector<T2V3Vert> points;
44    
45        Verts(const Transform &t) : t(t) {
46            points.reserve(1000);
47        }
48    
49        unsigned int size() {
50            return points.size();
51        }
52    
53      int append(Pt p) {      int append(Pt p) {
54          DBG(dbg_paperquad) << "DiceTester append "<<p<<"\n";          DBG(dbg_paperquad) << "DiceTester append "<<p<<"\n";
55          int ind = points.size();          int ind = points.size();
# Line 109  inline float split(Verts &v, float dicel Line 116  inline float split(Verts &v, float dicel
116      return ret;      return ret;
117  }  }
118    
119    /** Whether the i-j stretch should be split again
120     * @return 1 = yes, 0 = no, -1 = j should be dropped
121     */
122    inline int split3(Verts &v, float dicelen1, float dicelen2, int i, int j, int k) {
123        Pt o1 = (Pt)v.points[i].final - (Pt)v.points[j].final;
124        Pt o2 = (Pt)v.points[j].final - (Pt)v.points[k].final;
125        float x1, x2;
126        if(fabs(o1.x) > fabs(o1.y)) {
127            x1 = o1.x; x2 = o2.x;
128        } else {
129            x1 = o1.y; x2 = o2.y;
130        }
131        Pt v1 = (Pt)v.points[i].final - (Pt)v.points[j].final;
132        Pt v2 = (Pt)v.points[j].final - (Pt)v.points[k].final;
133    
134        float v1l = v1.length();
135        float v2l = v2.length();
136    
137        if(v1l > dicelen1) return 1;
138    
139        Pt v2_mapped = v2 * (x1 / x2);
140    
141        float area = (v1 - v2_mapped).length();
142    
143        float carea = area * v1l / (v1l + v2l);
144        DBG(dbg_paperquad) << "Split3 "<<i<<" "<<j<<" "<<
145                v.points[i].final<<" "<<v.points[j].final<<" "
146                << v.points[k].final<< " " <<area<<" "<<carea<<"\n";
147        if(area < dicelen2 / 2) return -1;
148        // The portion that is v1's worry
149        if(carea < dicelen2) return 0;
150        return 1;
151    }
152    
153    inline int splitTri(Verts &v, float dicelen1, float dicelen2, int i, int j, int k) {
154        DBG(dbg_paperquad) << "SplitTri "<<i<<" "<<j<<" "<<
155                v.points[i].final<<" "<<v.points[j].final<<" "
156                << v.points[k].final<< "\n";
157        Pt ctr = 1/3. * (
158                    v.points[i].orig +
159                    v.points[j].orig +
160                    v.points[k].orig );
161        ZPt ctrt = 1/3. * (
162                    v.points[i].final +
163                    v.points[j].final +
164                    v.points[k].final );
165        ZPt tc = v.t.transform(ctr);
166        if( (tc-ctrt).xylength() < dicelen1) {
167            DBG(dbg_paperquad) << "NO SPLIT\n";
168            return -1;
169        }
170        float l0 = (v.points[i].orig - v.points[j].orig).length();
171        float l1 = (v.points[j].orig - v.points[k].orig).length();
172        float l2 = (v.points[k].orig - v.points[i].orig).length();
173        DBG(dbg_paperquad) << "SPLIT "<<l0<<" "<<l1<<" "<<l2<<"\n";
174        if(l0 > l1 && l0 > l2) return 0;
175        if(l1 > l2) return 1;
176        return 2;
177    }
178    
179  }  }
180    
181    
# Line 116  class DiceTester { Line 183  class DiceTester {
183  public:  public:
184      enum { NTrans = 1 };      enum { NTrans = 1 };
185    
186      float dicelen;      float dicelen1;
187        float dicelen2;
188      int flags;      int flags;
189      int maxdepth;      int maxdepth;
190    
191      template<class F> void params(F &f) {      template<class F> void params(F &f) {
192          f(dicelen, flags, maxdepth);          f(dicelen1, dicelen2, flags, maxdepth);
193      }      }
194    
195      template<class T> void render(const T &coords) const {      template<class T> void render(const T &coords) const {
196          using namespace PaperPriv;          using namespace PaperPriv;
         ::Vob::Dicer::InitialDicedTriangle<__gnu_cxx::slist<int> > tri;  
         Triangler triangler;  
197          Verts verts(coords);          Verts verts(coords);
198            ::Vob::Dicer::Triangles<Verts> triangler(verts);
199          verts.append(Pt(0,0));          verts.append(Pt(0,0));
200          verts.append(Pt(1,0));          verts.append(Pt(1,0));
201            verts.append(Pt(0,1));
202          verts.append(Pt(1,1));          verts.append(Pt(1,1));
203          using namespace boost;          using namespace boost;
204          using namespace boost::lambda;          using namespace boost::lambda;
205          DBG(dbg_paperquad) << "Set_and_initial\n";          DBG(dbg_paperquad) << "Set_and_initial\n";
206          tri.set_and_initial_dice(verts,          triangler.add(0,1,3);
207                       0, 1, 2, bind(split, ref(verts), dicelen, _1, _2), maxdepth);          triangler.add(0,3,2);
208          DBG(dbg_paperquad) << "dice\n";          triangler.dice(bind(splitTri, ref(verts), dicelen1, dicelen2, _1, _2, _3));
         tri.dice(verts, triangler,  
                       bind(split, ref(verts), dicelen, _1, _2), maxdepth);  
209    
210          verts.startT2V3Operation();          verts.startT2V3Operation();
211              triangler.draw();              triangler.draw();
# Line 164  public: Line 230  public:
230      float x0,y0,x1,y1;      float x0,y0,x1,y1;
231      int flags;      int flags;
232    
233      float diceLength;      float diceLength, diceLength2;
234      int diceDepth;      int diceDepth;
235    
236      template<class F> void params(F &f) {      template<class F> void params(F &f) {
237          f(paper, x0, y0, x1, y1, flags, diceLength, diceDepth);          f(paper, x0, y0, x1, y1, flags, diceLength, diceLength2, diceDepth);
238      }      }
239    
240    
# Line 176  public: Line 242  public:
242          GLERR          GLERR
243    
244          using namespace PaperPriv;          using namespace PaperPriv;
         Triangler triangler;  
245          Verts verts(coords);          Verts verts(coords);
246            ::Vob::Dicer::Triangles<Verts> triangler(verts);
247          verts.append(Pt(x0,y0));          verts.append(Pt(x0,y0));
248          verts.append(Pt(x1,y0));          verts.append(Pt(x1,y0));
249          verts.append(Pt(x0,y1));          verts.append(Pt(x0,y1));
# Line 187  public: Line 253  public:
253          DBG(dbg_paperquad) << "Set_and_initial\n";          DBG(dbg_paperquad) << "Set_and_initial\n";
254    
255          {          {
256              ::Vob::Dicer::InitialDicedTriangle<__gnu_cxx::slist<int> > tri;                  triangler.add(0, 1, 3);
257              tri.set_and_initial_dice(verts,                  triangler.add(0, 3, 2);
                      0, 1, 3, bind(split, ref(verts), diceLength, _1, _2), diceDepth);  
258              DBG(dbg_paperquad) << "dice\n";              DBG(dbg_paperquad) << "dice\n";
259              tri.dice(verts, triangler,              triangler.dice(bind(splitTri, ref(verts), diceLength, diceLength2, _1, _2, _3));
260                            bind(split, ref(verts), diceLength, _1, _2), diceDepth);              DBG(dbg_paperquad) << "diced\n";
261          }          }
262    
   
         {  
             ::Vob::Dicer::InitialDicedTriangle<__gnu_cxx::slist<int> > tri;  
             tri.set_and_initial_dice(verts,  
                      0, 3, 2, bind(split, ref(verts), diceLength, _1, _2), diceDepth);  
             DBG(dbg_paperquad) << "dice\n";  
             tri.dice(verts, triangler,  
                           bind(split, ref(verts), diceLength, _1, _2), diceDepth);  
         }  
   
   
263          Paper::LightParam lightParam;          Paper::LightParam lightParam;
264          lightParam.orig = ZPt(0,0,0);          lightParam.orig = ZPt(0,0,0);
265          lightParam.e0 = ZPt(0,0,0);          lightParam.e0 = ZPt(0,0,0);
# Line 234  public: Line 288  public:
288    
289                  glBegin(GL_TRIANGLES);                  glBegin(GL_TRIANGLES);
290    
291                  for(unsigned i=0; i<triangler.tris.size(); i++) {                  for(::Vob::Dicer::Triangles<Verts>::Titer i=triangler.tris.begin();
292                                i != triangler.tris.end(); i++) {
293                       for(int v = 0; v < 3; v++) {                       for(int v = 0; v < 3; v++) {
294                           int ind = triangler.tris[i].v[v];                           int ind = (*i).v[v];
295                           float tmp[4] = {                           float tmp[4] = {
296                               verts.points[ind].orig.x,                               verts.points[ind].orig.x,
297                               verts.points[ind].orig.y,                               verts.points[ind].orig.y,

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26