8 #ifndef MESHGENERATOR_HH_
9 #define MESHGENERATOR_HH_
16 #include <boost/shared_ptr.hpp>
17 #include <boost/progress.hpp>
18 #include <boost/tuple/tuple.hpp>
19 #include <boost/tuple/tuple_comparison.hpp>
21 #include <OpenVolumeMesh/Mesh/PolyhedralMesh.hh>
22 #include <OpenVolumeMesh/Geometry/VectorT.hh>
34 typedef boost::tuple<VertexHandle, VertexHandle, VertexHandle> FaceTuple;
42 MeshGenerator(PolyhedralMesh& _mesh) : v_component_(0), mesh_(_mesh), progress_() {}
44 v_component_(_cpy.v_component_),
45 vertex_(0.0, 0.0, 0.0),
51 void add_vertex_component(
double _comp) {
53 if(v_component_ > 2) {
54 std::cerr <<
"Vertices of dimension higher than three not supported!" << std::endl;
57 vertex_[v_component_] = _comp;
59 if(v_component_ == 3) {
71 void add_cell_vertex(
unsigned int _idx) {
76 if(c_vertices_.size() == 4) {
78 add_tetrahedral_cell();
85 void set_num_cells(
unsigned int _n) {
87 if(progress_.get() == NULL) {
88 progress_.reset(
new boost::progress_display(_n));
92 void add_tetrahedral_cell() {
94 if(c_vertices_.size() != 4) {
95 std::cerr <<
"The specified cell is not incident to four vertices!" << std::endl;
100 Vec3d midP(0.0, 0.0, 0.0);
101 double valence = 0.0;
102 for(std::vector<OpenVolumeMesh::VertexHandle>::const_iterator it = c_vertices_.begin();
103 it != c_vertices_.end(); ++it) {
104 midP += mesh_.
vertex(*it);
110 std::sort(c_vertices_.begin(), c_vertices_.end());
112 std::vector<FaceTuple> tuples;
115 tuples.push_back(FaceTuple(c_vertices_[0], c_vertices_[1], c_vertices_[2]));
116 tuples.push_back(FaceTuple(c_vertices_[1], c_vertices_[2], c_vertices_[3]));
117 tuples.push_back(FaceTuple(c_vertices_[0], c_vertices_[2], c_vertices_[3]));
118 tuples.push_back(FaceTuple(c_vertices_[0], c_vertices_[1], c_vertices_[3]));
121 std::vector<HalfFaceHandle> cell_halffaces;
123 for(std::vector<FaceTuple>::const_iterator it = tuples.begin();
124 it != tuples.end(); ++it) {
127 FaceMap::iterator f = faceMap_.find(*it);
128 if(f == faceMap_.end()) {
134 Vec3d e1 = mesh_.
vertex(it->get<1>()) - mesh_.
vertex(it->get<0>());
135 Vec3d e2 = mesh_.
vertex(it->get<2>()) - mesh_.
vertex(it->get<1>());
138 Vec3d n = (e1 % e2).normalize();
140 std::vector<VertexHandle> v_vec;
141 v_vec.push_back(it->get<0>());
142 v_vec.push_back(it->get<1>());
143 v_vec.push_back(it->get<2>());
144 FaceHandle fh = mesh_.add_face(v_vec);
150 if(((midP - mesh_.
vertex(it->get<0>())) | n) > 0.0) {
154 cell_halffaces.push_back(mesh_.halfface_handle(fh, 0));
160 cell_halffaces.push_back(mesh_.halfface_handle(fh, 1));
166 FaceHandle fh = f->second;
168 std::vector<HalfEdgeHandle> hes = mesh_.face(fh).halfedges();
170 assert(hes.size() == 3);
172 Vec3d e1 = mesh_.
vertex(mesh_.halfedge(hes[0]).to_vertex()) -
173 mesh_.
vertex(mesh_.halfedge(hes[0]).from_vertex());
174 Vec3d e2 = mesh_.
vertex(mesh_.halfedge(hes[1]).to_vertex()) -
175 mesh_.
vertex(mesh_.halfedge(hes[1]).from_vertex());
177 Vec3d n = (e1 % e2).normalize();
179 if(((midP - mesh_.
vertex(mesh_.halfedge(hes[0]).from_vertex())) | n) > 0.0) {
181 cell_halffaces.push_back(mesh_.halfface_handle(fh, 0));
184 cell_halffaces.push_back(mesh_.halfface_handle(fh, 1));
190 assert(cell_halffaces.size() == 4);
194 mesh_.add_cell(cell_halffaces,
true);
196 mesh_.add_cell(cell_halffaces,
false);
200 if((progress_.get() != NULL) && (progress_->expected_count() != 0))
206 typedef std::map<FaceTuple, OpenVolumeMesh::FaceHandle> FaceMap;
208 unsigned int v_component_;
211 std::vector<VertexHandle> c_vertices_;
215 PolyhedralMesh& mesh_;
217 boost::shared_ptr<boost::progress_display> progress_;
const VecT & vertex(const VertexHandle &_vh) const
Get point _vh's coordinates.
virtual VertexHandle add_vertex()
Override of empty add_vertex function.