GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/Geometry/IndexedFaceSet.h
00001 #ifndef __GEOMETRY_GEOMETRY_INDEXED_FACE_SET_H__
00002 #define __GEOMETRY_GEOMETRY_INDEXED_FACE_SET_H__
00003 
00004 #include <vector>
00005 #include "CGLA/Vec3f.h"
00006 #include "CGLA/Vec3i.h"
00007 
00008 namespace Geometry
00009 {
00010         const CGLA::Vec3i NULL_FACE(-1,-1,-1);
00011         
00017         class IndexedFaceSet
00018         {
00020     std::vector<CGLA::Vec3f> verts;
00021                         
00023     std::vector<CGLA::Vec3i> faces;
00024                                 
00025         public:
00026 
00027                 IndexedFaceSet(): verts(0), faces(0) {}
00028 
00029                 // ----------------------------------------
00030                 // Functions that operate on faces
00031                 // ----------------------------------------
00032                                 
00037                 int add_face(const CGLA::Vec3i& f, int idx=-1) 
00038                 {
00039                         if(idx < 0)
00040                                 idx = static_cast<int>(faces.size());
00041                         faces.resize(idx+1,NULL_FACE);
00042                         faces[idx] = f;
00043                         return idx;
00044                 }
00045 
00047                 int no_faces() const {return static_cast<int>(faces.size());}
00048 
00052                 const CGLA::Vec3i& face(size_t idx) const
00053                 {
00054                         if(idx<faces.size())
00055                                 return faces[idx];
00056                         return NULL_FACE;
00057                 }
00058 
00060                 CGLA::Vec3i& face_rw(int idx) 
00061                 {
00062                         return faces[idx];
00063                 }
00064 
00065                 // ----------------------------------------
00066                 // Functions that operate on vertices
00067                 // ----------------------------------------
00068 
00070                 int add_vertex(const CGLA::Vec3f& v)
00071                 {
00072                         int idx= static_cast<int>(verts.size());
00073                         verts.push_back(v);
00074                         return idx;
00075                 }
00076 
00078                 int no_vertices() const {return static_cast<int>(verts.size());}
00079 
00083                 const CGLA::Vec3f& vertex(int idx) const
00084                 {
00085                         return verts[idx];
00086                 }
00087 
00089                 CGLA::Vec3f& vertex_rw(int idx)
00090                 {
00091                         return verts[idx];
00092                 }
00093 
00094         };
00095 }
00096 
00097 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations