Subversion Repositories gelsvn

Rev

Rev 96 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

#include <sstream>
#include <fstream>
#if defined(_MSC_VER)
#include <io.h>
#else
#include <unistd.h>
#endif
#include "CGLA/Mat2x2f.h"
#include "Geometry/Polygonizer.h"
#include "Geometry/TrilinFilter.h"
#include "Geometry/load_raw.h"
#include "HMeshUtil/build_manifold.h"
#include "HMeshUtil/obj_save.h"
#include "Util/ArgExtracter.h"

using namespace HMesh;
using namespace HMeshUtil;
using namespace Geometry;
using namespace CGLA;
using namespace Util;
using namespace std;


/* Create an implicit function: Just union of two spheres */
class TestImplicit: public ImplicitFunction
{
                const Vec3f c0, c1;
public:
                
                TestImplicit(): c0(0,0,0), c1(2,2,2)  {}
                
                float eval(float x,float y,float z) 
                                {
                                                Vec3f p(x,y,z);
                                                return min(length(p-c0)-2.0f,length(p-c1)-2.0f);
                                }
};


int main(int argc, char **argv)
{
        // Create an implicit.
        TestImplicit imp;

        // Create a polygonizer. Cell side length = 0.1 and go up to 50 cells.
        Polygonizer pol(&imp, 0.1f, 50);        

        // Start polygonizer in vicinity of 1,1,1
        pol.march(1,1,1);

        // Build HMesh from triangles
        vector<int> indices;
        vector<Vec3f> verts;
        vector<int> faces;
        
        // Extract vertices
        for(int i=0;i<pol.no_vertices();++i)
        {
                        verts.push_back(*reinterpret_cast<Vec3f*>(&pol.get_vertex(i)));
        }

        // Extract triangles.
        for(int i=0;i<pol.no_triangles();++i)
        {
                        faces.push_back(3);
                        TRIANGLE f = pol.get_triangle(i);
                        indices.push_back(f.v0);
                        indices.push_back(f.v1);
                        indices.push_back(f.v2);
        }
        
        // Build manifold
        Manifold m;
        build_manifold(m, verts.size(), &verts[0], 
                                                                 faces.size(), &faces[0], &indices[0]);

        // Save as obj file
        obj_save("../../data/bloomenthal.obj", m);
        
}