Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

polygonize.h

00001 /*
00002   File: polygonize.h
00003 
00004   Ported to C++/STL expression framework by C. Kotterink
00005 
00006   Original file (implicit.c) authored by Jules Bloomenthal, Xerox PARC.
00007   Copyright (c) Xerox Corporation, 1991.  All rights reserved.
00008   Permission is granted to reproduce, use and distribute this code for
00009   any and all purposes, provided that this notice appears in all copies.
00010 */
00011 #ifndef POLYGONIZE_H
00012 #define POLYGONIZE_H
00013 
00014 #include<ImplicitShape.h>
00015 
00016 #include<slist>
00017 #include<vector>
00018 
00019 class polygonize;
00020 
00023 class polygonize
00024 {
00025 public:
00026     polygonize(ImplicitShape *s, float s, int b);
00027     ~polygonize();
00028 
00029     void operator()(float x = 0.0, float y = 0.0, float z = 0.0);
00030     vector<Vertex3> &getVertex() {
00031       return vertex;
00032     }
00033     vector<uint16> &getFace() {
00034       return face;
00035     }
00036 
00037 private:
00038     class Test {
00039     public:
00040         Vertex3 p;
00041         float value;
00042         bool ok;
00043     };
00044     class Corner {
00045     public:
00046         Corner(int ii = 0, int jj = 0, int kk = 0, float v = 0.0)
00047             : i(ii), j(jj), k(kk), value(v) {}
00048         int i, j, k;
00049         float value;
00050     };
00051     typedef slist<Corner> CornerList;
00052     class Cube {
00053     public:
00054         Cube(int ii = 0, int jj = 0, int kk = 0) : i(ii), j(jj), k(kk) {
00055             // Corners not initialized!
00056         }
00057         int i, j, k;
00058         CornerList *corners[8];
00059     };
00060     class Center {
00061     public:
00062         Center(int ii, int jj, int kk) : i(ii), j(jj), k(kk) {}
00063         int i, j, k;
00064     };
00065     class Edge {
00066     public:
00067         Edge(int ii1, int jj1, int kk1, int ii2, int jj2, int kk2, int v) :
00068             i1(ii1), j1(jj1), k1(kk1), i2(ii2), j2(jj2), k2(kk2), vid(v) {}
00069         int i1, j1, k1, i2, j2, k2;
00070         int vid;
00071     };
00072     typedef slist<int> IntList;
00073     typedef slist<Cube> CubeList;
00074     typedef slist<Center> CenterList;
00075     typedef slist<Edge> EdgeList;
00076     typedef slist<IntList> IntLists;
00077 
00078     // testface: given cube at lattice (i, j, k), and four corners of face,
00079     // if surface crosses face, compute other four corners of adjacent cube
00080     // and add new cube to cube stack
00081     void testface (
00082         int i, int j, int k,
00083         Cube &oldCube,
00084         int face, int c1, int c2, int c3, int c4);
00085 
00086     // setpoint: set point location given lattice location
00087     void setpoint(Vertex3 &pt, int i, int j, int k);
00088 
00089     // setcenter: set (i,j,k) entry centers\
00090     // return true if already set; otherwise, set and return false
00091     bool setcenter(int i, int j, int k);
00092 
00093     // setcorner: return corner with the given lattice location
00094     // set (and cache) its function value
00095     CornerList *setcorner(int i, int j, int k);
00096 
00097     // setedge: set vertex id for edge
00098     void setedge(
00099       int i1, int j1, int k1, int i2, int j2, int k2, int vid);
00100 
00101     // getedge: return vertex id for edge; return -1 if not set
00102     int polygonize::getedge(
00103       int i1, int j1, int k1, int i2, int j2, int k2);
00104 
00105     // find: search for point with value of given sign (0: neg, 1: pos)
00106     Test find(int sign, float x, float y, float z);
00107 
00108     // dotet: triangulate the tetrahedron
00109     void dotet(Cube &cube, int c1, int c2, int c3, int c4);
00110 
00111     // converge: from two points of differing sign, converge to surface
00112     void converge(const Vertex3 &p1, const Vertex3 &p2, float v, Vertex3 &p);
00113 
00114     // vertid: return index for vertex on edge
00115     uint16 vertid (Corner &c1, Corner &c2);
00116 
00117     void triproc(uint16 a, uint16 b, uint16 c);
00118 
00119     static const unsigned int convergeDepth = 10;
00120     static const unsigned int hashBit = 5;
00121     static const size_t hashSize = 1<<(3*hashBit);
00122     static const unsigned int hashMask = (1<<hashBit)-1;
00123 
00124     int hashValue(int i,int j,int k) {
00125       return ((((i&hashMask)<<hashBit)|(j&hashMask))<<hashBit)|(k&hashMask);
00126     }
00127     float random() {
00128       return (rand()&32767)/32767.0;
00129     }
00130 
00131     float size;
00132     float delta;
00133     int bounds;
00134     Vertex3 start;
00135     ImplicitShape *shape;
00136 
00137     vector<Vertex3> vertex;
00138     vector<uint16> face;
00139 
00140     CubeList cubes;
00141     CenterList centers[hashSize];
00142     CornerList corners[hashSize]; 
00143     EdgeList edges[2*hashSize];
00144 };
00145 #endif

This documentation was generated using doxygen. If you have any comments or additions please mail me.