DelaunayHelpers.h

Go to the documentation of this file.
00001 #ifndef DelaunayHelpers_HEADER
00002 #define DelaunayHelpers_HEADER
00003 
00004 /***************************************************************************
00005  * \file
00006  * Benoit Hudson (C) 2007.
00007  *
00008  * A series of helpers for Delaunay meshes.
00009  ***************************************************************************/
00010 
00011 #include <vector>
00012 #include <topology/SimplicialHelpers.h>
00013 
00014 namespace Delaunay {
00015   using namespace std;
00016 
00017   /***************************************************************************
00018    * Print the triangulation to EPS.
00019    *
00020    * The topological triangulation must be in two dimension.  If it is in
00021    * higher ambient dimension, it will project.
00022    ***************************************************************************/
00023   template <class Del> void printToEPS(const Del *del, FILE *out) {
00024     // TODO: take that out of there.
00025     del->printToEPS(out);
00026   }
00027 
00028 
00035 #define printTuple(out, f, d, tup, id) \
00036 do { \
00037   switch(d) { \
00038     case 0: \
00039       fprintf(out, "%lu\n", id); \
00040       break; \
00041     case 1: \
00042       fprintf(out, "%lu "f"\n", id, tup[0]); \
00043       break; \
00044     case 2: \
00045       fprintf(out, "%lu "f" "f"\n", id, tup[0], tup[1]); \
00046       break; \
00047     case 3: \
00048       fprintf(out, "%lu "f" "f" "f"\n", id, tup[0], tup[1], tup[2]); \
00049       break; \
00050     case 4: \
00051       fprintf(out, "%lu "f" "f" "f" "f"\n", id, tup[0], tup[1], tup[2], tup[3]); \
00052       break; \
00053     default: \
00054       /* There must be at least 5, so print them out (no newline). */ \
00055       fprintf(out, "%lu "f" "f" "f" "f" "f, id, \
00056           tup[0], tup[1], tup[2], tup[3], tup[4]); \
00057       /* Excrutiatingly slowly print out the remainder. */ \
00058       for(size_t j = 4; j < d; ++j) { \
00059         fprintf(out, " "f, tup[j]); \
00060       } \
00061       fputs("\n", out); \
00062   } \
00063 } while(0)
00064 
00066   template <class Point> void printPoint(unsigned long id, const Point& p, FILE *out) {
00067     printTuple(out, "%g", Point::dimension, p, id);
00068   }
00069 
00071   template <class IntVect> void printEle(unsigned long id, const IntVect& v, FILE *out) {
00072     size_t len = v.size();
00073     printTuple(out, "%u", len, (unsigned)v, id);
00074   }
00075 #undef printTuple
00076 
00077 
00078 
00081   template <class Vertex> void printToNode(const std::vector<Vertex*>& verts, FILE *out) {
00082     assert(verts.size() > 0);
00083     unsigned d = verts[0]->dim();
00084 
00085     fprintf(out, "%lu %u 0 0\n", (unsigned long)verts.size(), d);
00086     for(unsigned i = 0 ; i < verts.size(); ++i) {
00087       printPoint(i, verts[i]->toPoint(), out);
00088     }
00089   }
00090 
00092   template <class Del> void printToNode(const Del *del, FILE *out) {
00093     vector<typename Del::Vertex*> verts;
00094     Simplicial::collectVertices(del->getComplex(), verts);
00095     printToNode(verts, out);
00096   }
00097 
00099   template <class Del> void printToNodeEle(const Del *del, FILE *node, FILE *ele) {
00100     vector<typename Del::Vertex*> verts;
00101     // TODO: speed this up (don't use vector<vector> )
00102     vector<vector<size_t> > elements;
00103 
00104     Simplicial::serialize(del->getComplex(), verts, elements);
00105     assert(verts.size() > 0);
00106     unsigned d = verts[0]->dim();
00107     printToNode(verts, node);
00108 
00109     fprintf(ele, "%lu %u 0\n", (unsigned long)elements.size(), d + 1);
00110     for(size_t i = 0; i < elements.size(); i++) {
00111       printEle(i, elements[i], ele);
00112     }
00113   }
00114 }
00115 
00116 
00117 #endif

Generated on Thu Mar 27 19:04:12 2008 by  doxygen 1.4.6