proj home

Files   Classes   Functions   Hierarchy  

triangleuniformsubdivision< T > Class Template Reference

Uniform triangle subdivision on indexed triangles. More...

#include <triangleuniformsubdivision.h>

Collaboration diagram for triangleuniformsubdivision< T >:

List of all members.

Public Member Functions

 triangleuniformsubdivision (vector< point3< uint > > &vi_, vector< T > &pts_)
 Pass where to write the new triangles and points too.
void divide (point3< uint > const &ti)
 Divide a triangle one depth into 4 triangles adding the new geometry to vi.
void divide (vector< point3< uint > > const &v2)
 Divide each triangle in v2 one depth into 4 triangles adding the new geometry to vi.
void divide (point3< uint > const &ti, uintc depth)
 Divide a triangle depth times by dividing one triangle into four adding the new geometry to vi.
void divide (vector< point3< uint > > const &v2, uintc depth)
 Divide each triangle in v2 depth times dividing on triangle into 4 triangles adding the new geometry to vi.

Public Attributes

vector< point3< uint > > & vi
 Newly created triangles are appended to vi.
vector< T > & pts
 Newly created points are appended to pts.


Detailed Description

template<typename T>
class triangleuniformsubdivision< T >

Uniform triangle subdivision on indexed triangles.

The references get where to write the triangles and points too when the division functions are called. The are the output. The division functions are the input.

This class is non-destructive in the sense that geometry is only added to vi and not deleted from it. So if vi already contains geometry this is not destroyed.

Definition at line 22 of file triangleuniformsubdivision.h.


Constructor & Destructor Documentation

template<typename T>
triangleuniformsubdivision< T >::triangleuniformsubdivision ( vector< point3< uint > > &  vi_,
vector< T > &  pts_ 
) [inline]

Pass where to write the new triangles and points too.

Definition at line 33 of file triangleuniformsubdivision.h.

00036     : vi(vi_), pts(pts_) {}


Member Function Documentation

template<typename T>
void triangleuniformsubdivision< T >::divide ( vector< point3< uint > > const &  v2,
uintc  depth 
) [inline]

Divide each triangle in v2 depth times dividing on triangle into 4 triangles adding the new geometry to vi.

Definition at line 53 of file triangleuniformsubdivision.h.

References triangleuniformsubdivision< T >::divide().

Referenced by triangleuniformsubdivision< T >::divide().

00054     { uintc sz(v2.size()); for (uint i=0; i<sz; ++i) divide(v2[i],depth); } 

template<typename T >
void triangleuniformsubdivision< T >::divide ( point3< uint > const &  ti,
uintc  depth 
) [inline]

Divide a triangle depth times by dividing one triangle into four adding the new geometry to vi.

Definition at line 64 of file triangleuniformsubdivision.h.

References triangleuniformsubdivision< T >::divide(), and pts.

00068 {
00069   static vector< point3<uint> > v0;
00070   static vector< point3<uint> > v1;
00071   static vector< point3<uint> >* pv[2];
00072 
00073   v0.clear();
00074   v1.clear();
00075 
00076   pv[0] = & v0;
00077   pv[1] = & v1;
00078 
00079   static triangleuniformsubdivision<T> v0d(v0,pts);
00080   static triangleuniformsubdivision<T> v1d(v1,pts);
00081 
00082   static triangleuniformsubdivision<T>* vd[2];
00083   vd[0] = & v0d;
00084   vd[1] = & v1d;
00085 
00086   uint current=0;
00087   pv[1]->push_back(ti);
00088 
00089   uint c2;
00090   for (uint i=0; i<depth; ++i)
00091   {
00092     c2 = (current+1)%2;
00093     pv[current]->clear();
00094     vd[current]->divide(*pv[c2]);
00095     current = (current+1)%2;
00096   }
00097 
00098   // Point to where the current geometry is.
00099   current = (current+1)%2;
00100   uintc sz = pv[current]->size();
00101   for (uint i=0; i<sz; ++i)
00102     vi.push_back( (*pv[current])[i] );
00103 }

template<typename T>
void triangleuniformsubdivision< T >::divide ( vector< point3< uint > > const &  v2  )  [inline]

Divide each triangle in v2 one depth into 4 triangles adding the new geometry to vi.

Definition at line 44 of file triangleuniformsubdivision.h.

References triangleuniformsubdivision< T >::divide().

Referenced by triangleuniformsubdivision< T >::divide().

00045     { uintc sz(v2.size()); for (uint i=0; i<sz; ++i) divide(v2[i]); } 

template<typename T >
void triangleuniformsubdivision< T >::divide ( point3< uint > const &  ti  )  [inline]

Divide a triangle one depth into 4 triangles adding the new geometry to vi.

Definition at line 106 of file triangleuniformsubdivision.h.

References triangleuniformsubdivision< T >::pts, triangleuniformsubdivision< T >::vi, point3< T >::x, point3< T >::y, and point3< T >::z.

Referenced by triangleuniformsubdivision< T >::divide(), and meshpatchtest::test03().

00107 {
00108   uint i[6];
00109   i[0] = ti.x;
00110   i[1] = ti.y;
00111   i[2] = ti.z;
00112   i[3] = pts.size(); 
00113   i[4] = i[3]+1;
00114   i[5] = i[4]+1;
00115     
00116   vi.push_back( point3<uint>(i[3],i[1],i[4]) );
00117   vi.push_back( point3<uint>(i[5],i[3],i[4]) );
00118   vi.push_back( point3<uint>(i[5],i[4],i[2]) );
00119   vi.push_back( point3<uint>(i[0],i[3],i[5]) );
00120     
00121   T const & p0( pts[i[0]] );
00122   T const & p1( pts[i[1]] );
00123   T const & p2( pts[i[2]] );
00124 
00125 // Problem with temporaries, explicit code because
00126 //   compiler generated crap.
00127 
00128   T q0(p0);
00129   q0 += p1;
00130   q0 *= 0.5;
00131   T q1(p1);
00132   q1 += p2;
00133   q1 *= 0.5;
00134   T q2(p2);
00135   q2 += p0;
00136   q2 *= 0.5;
00137 
00138   pts.push_back(q0);
00139   pts.push_back(q1);
00140   pts.push_back(q2);
00141 
00142 /*
00143 cout << SHOW(q0) << endl;
00144 cout << SHOW(q1) << endl;
00145 cout << SHOW(q2) << endl;
00146 */
00147 
00148     
00149 /*
00150 cout << SHOW(p0) << endl;
00151 cout << SHOW(p1) << endl;
00152 cout << SHOW(p2) << endl;
00153 
00154     pts.push_back((p0+p1)*0.5);
00155     pts.push_back((p1+p2)*0.5);
00156     pts.push_back((p2+p0)*0.5);
00157 
00158 cout << SHOW(p0+p1) << endl;
00159 cout << SHOW(p1+p2) << endl;
00160 cout << SHOW(p2+p0) << endl;
00161 
00162 cout << SHOW(p0) << endl;
00163 cout << SHOW(p1) << endl;
00164 cout << SHOW(p2) << endl;
00165 */
00166 
00167 }


Member Data Documentation

template<typename T>
vector< T >& triangleuniformsubdivision< T >::pts

Newly created points are appended to pts.

Definition at line 29 of file triangleuniformsubdivision.h.

Referenced by triangleuniformsubdivision< T >::divide().

template<typename T>
vector< point3<uint> >& triangleuniformsubdivision< T >::vi

Newly created triangles are appended to vi.

Definition at line 27 of file triangleuniformsubdivision.h.

Referenced by triangleuniformsubdivision< T >::divide().


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:50:22 2011 for Chelton Evans Source by  doxygen 1.5.8