GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/Geometry/Polygonizer.h
00001 /**********************************************************************
00002 
00003 polygonizer.h
00004 
00005 This is Jules Bloomenthal's implicit surface polygonizer from GRAPHICS 
00006 GEMS IV. Bloomenthal's polygonizer is still used and the present code
00007 is simply the original code morphed into C++.
00008 
00009 J. Andreas Brentzen 2003.
00010 
00011 **********************************************************************/
00012 
00013 #ifndef __GEOMETRY_POLYGONIZER_H
00014 #define __GEOMETRY_POLYGONIZER_H
00015 
00016 #include <vector>
00017 
00018 namespace Geometry
00019 {
00020 
00021         enum ToTetraHedralize
00022                 {
00023                         TET = 0,  // use tetrahedral decomposition 
00024                         NOTET = 1  // no tetrahedral decomposition  */
00025                 };
00026 
00035         class ImplicitFunction
00036                 {
00037                 public:
00038                         virtual float eval(float,float,float) = 0;
00039                 };
00040 
00041         struct POINT { float x, y, z;   };
00042 
00043         typedef POINT VERTEX;
00044         typedef POINT NORMAL;
00045 
00048         struct TRIANGLE
00049         {
00050                 int v0,v1,v2;
00051         };
00052 
00054         class Polygonizer
00055                 {
00056                         std::vector<NORMAL> gnormals;  
00057                         std::vector<VERTEX> gvertices;  
00058                         std::vector<TRIANGLE> gtriangles;
00059   
00060                         ImplicitFunction* func;
00061                         float size;
00062                         int bounds;
00063                         
00064                         bool use_tetra;
00065                         bool use_normals;
00066 
00067                 public: 
00068         
00078                         Polygonizer(ImplicitFunction* _func, float _size, int _bounds,
00079                                                                         bool _use_tetra=false,
00080                                                                         bool _use_normals=false):
00081                                 func(_func), size(_size), bounds(_bounds),
00082                                 use_tetra(_use_tetra),
00083                                 use_normals(_use_normals) {}
00084 
00088                         void march(float x, float y, float z);
00089 
00092                         int no_triangles() const
00093                                 {
00094                                         return gtriangles.size();
00095                                 }
00096 
00099                         int no_vertices() const
00100                                 {
00101                                         return gvertices.size();
00102                                 }
00103         
00108                         int no_normals() const
00109                                 {
00110                                         return gnormals.size();
00111                                 }
00112         
00114                                 TRIANGLE& get_triangle(int i) 
00115                                         {
00116                                                 return gtriangles[i];
00117                                         }
00118 
00120                                         VERTEX& get_vertex(int i) 
00121                                                 {
00122                                                         return gvertices[i];
00123                                                 }
00124         
00125         
00127                                                 NORMAL& get_normal(int i) 
00128                                                         {
00129                                                                 return gnormals[i];
00130                                                         }
00131 
00132 
00133                 };
00134 }
00135 
00136 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations