Blender V2.61 - r43446

subd_mesh.h

Go to the documentation of this file.
00001 /*
00002  * Original code in the public domain -- castanyo@yahoo.es
00003  *
00004  * Modifications copyright (c) 2011, Blender Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  * * Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * * Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00017  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00018  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00019  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00020  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00021  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #ifndef __SUBD_MESH_H__
00030 #define __SUBD_MESH_H__
00031 
00032 #include "util_map.h"
00033 #include "util_types.h"
00034 #include "util_vector.h"
00035 
00036 CCL_NAMESPACE_BEGIN
00037 
00038 class SubdFace;
00039 class SubdVert;
00040 class SubdEdge;
00041 
00042 class DiagSplit;
00043 class Mesh;
00044 
00045 /* Subd Mesh, half edge based for dynamic mesh manipulation */
00046 
00047 class SubdMesh
00048 {
00049 public:
00050     vector<SubdVert*> verts;
00051     vector<SubdEdge*> edges;
00052     vector<SubdFace*> faces;
00053 
00054     SubdMesh();
00055     ~SubdMesh();
00056 
00057     SubdVert *add_vert(const float3& co);
00058     
00059     SubdFace *add_face(int v0, int v1, int v2);
00060     SubdFace *add_face(int v0, int v1, int v2, int v3);
00061     SubdFace *add_face(int *index, int num);
00062 
00063     bool link_boundary();
00064     void tesselate(DiagSplit *split, bool linear,
00065         Mesh *mesh, int shader, bool smooth);
00066 
00067 protected:
00068     bool can_add_face(int *index, int num);
00069     bool can_add_edge(int i, int j);
00070     SubdEdge *add_edge(int i, int j);
00071     SubdEdge *find_edge(int i, int j);
00072     void link_boundary_edge(SubdEdge *edge);
00073     
00074     struct Key {
00075         Key() {}
00076         Key(int v0, int v1) : p0(v0), p1(v1) {}
00077 
00078         bool operator<(const Key& k) const
00079         { return (p0 < k.p0 || (p0 == k.p0 && p1 < k.p1)); }
00080 
00081         int p0, p1;
00082     };
00083 
00084     map<Key, SubdEdge *> edge_map;
00085 };
00086 
00087 CCL_NAMESPACE_END
00088 
00089 #endif /* __SUBD_MESH_H__ */
00090