50 #define FILEOPENVOLUMEMESHT_CC 52 #include "FileOpenVolumeMesh.hh" 56 template <
typename MeshT>
57 void FileOpenVolumeMeshPlugin::loadMesh(
const char* _filename, MeshT& _mesh,
bool _comp,
bool _topCheck) {
60 bool edges_in_file =
false;
62 typedef typename MeshT::PointT Vertex;
65 std::ifstream iff(_filename, std::ios::in);
71 if (s !=
"Vertices") {
72 std::cerr <<
"ERROR reading OpenVolumeMesh (Vertex Section Failed)\n";
80 for (
int i = 0; i < nv; ++i) {
92 std::cerr <<
"No edges found" << std::endl;
97 for (
int e = 0; e < ne; ++e) {
110 std::cerr <<
"ERROR reading OpenVolumeMesh (Face Section Failed)\n";
121 for (
int f = 0; f < nf; ++f) {
124 std::vector<OpenVolumeMesh::VertexHandle> vids;
125 for (
int v = 0; v < nfv; ++v) {
130 int pos_cell, neg_cell;
133 _mesh.add_face(vids);
140 for (
int f = 0; f < nf; ++f) {
143 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes;
144 for (
int he = 0; he < nfhe; ++he) {
150 _mesh.add_face(hes, _topCheck);
156 if(s !=
"Polyhedra") {
157 std::cerr <<
"ERROR reading OpenVolumeMesh (Polyhedra Section Failed)\n";
167 for(
int i = 0; i < nc; ++i) {
171 std::vector< int > faceids;
173 for(
int f = 0; f < ncf; ++f) {
177 faceids.push_back(fidx);
183 unsigned int num_faces = faceids.size();
184 for(std::vector<int>::const_iterator it = faceids.begin();
185 it != faceids.end(); ++it) {
187 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes = _mesh.face(*it).halfedges();
188 unsigned int val = hes.size();
190 for(std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator p_it = hes.begin();
191 p_it != hes.end(); ++p_it) {
192 f_mid += (_mesh.vertex(_mesh.halfedge(*p_it).to_vertex()) / (
double)val);
194 c += f_mid / (double)num_faces;
199 std::vector<OpenVolumeMesh::HalfFaceHandle> hfhandles;
200 for(std::vector<int>::const_iterator it = faceids.begin();
201 it != faceids.end(); ++it) {
204 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes = _mesh.face(*it).halfedges();
205 unsigned int val = hes.size();
207 for(std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator p_it = hes.begin();
208 p_it != hes.end(); ++p_it) {
209 f_mid += (_mesh.vertex(_mesh.halfedge(*p_it).to_vertex()) / (
double)val);
213 if(hes.size() < 2)
continue;
214 ACG::Vec3d p0 = _mesh.vertex(_mesh.halfedge(hes[0]).from_vertex());
215 ACG::Vec3d p1 = _mesh.vertex(_mesh.halfedge(hes[0]).to_vertex());
216 ACG::Vec3d p2 = _mesh.vertex(_mesh.halfedge(hes[1]).to_vertex());
220 if(((c - f_mid) | n) >= 0.0) hfhandles.push_back(_mesh.halfface_handle(*it, 0));
221 else hfhandles.push_back(_mesh.halfface_handle(*it, 1));
224 if(hfhandles.size() > 3) {
230 hm->add_cell(hfhandles, _topCheck);
232 _mesh.add_cell(hfhandles, _topCheck);
235 std::cerr <<
"Could not determine corresponding halffaces!" << std::endl;
243 for (
int c = 0; c < nc; ++c) {
247 std::vector<OpenVolumeMesh::HalfFaceHandle> hfs;
248 for (
int hf = 0; hf < nhf; ++hf) {
259 hm->add_cell(hfs, _topCheck);
261 _mesh.add_cell(hfs, _topCheck);
267 std::cerr <<
"######## openvolumemesh info #########\n";
268 std::cerr <<
"#vertices: " << _mesh.n_vertices() << std::endl;
269 std::cerr <<
"#edges : " << _mesh.n_edges() << std::endl;
270 std::cerr <<
"#faces : " << _mesh.n_faces() << std::endl;
271 std::cerr <<
"#cells : " << _mesh.n_cells() << std::endl;
276 template <
typename MeshT>
277 void FileOpenVolumeMeshPlugin::saveMesh(
const char* _filename, MeshT& _mesh,
bool _comp) {
280 std::ofstream off(_filename, std::ios::out);
282 int n_vertices(_mesh.n_vertices());
283 off <<
"Vertices" << std::endl;
284 off << n_vertices << std::endl;
290 off << v[0] <<
" " << v[1] <<
" " << v[2] << std::endl;
293 int n_edges(_mesh.n_edges());
294 off <<
"Edges" << std::endl;
295 off << n_edges << std::endl;
302 off << from_vertex <<
" " << to_vertex << std::endl;
305 int n_faces(_mesh.n_faces());
306 off <<
"Faces" << std::endl;
307 off << n_faces << std::endl;
312 off << _mesh.face(*f_it).halfedges().size() <<
" ";
314 std::vector<OpenVolumeMesh::HalfEdgeHandle> halfedges = _mesh.face(*f_it).halfedges();
316 for (std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator it = halfedges.begin();
317 it != halfedges.end(); ++it) {
320 off << _mesh.halfedge(*it).from_vertex();
325 if((it+1) != halfedges.end()) off <<
" ";
332 int n_cells(_mesh.n_cells());
333 off <<
"Polyhedra" << std::endl;
334 off << n_cells << std::endl;
338 off << _mesh.cell(*c_it).halffaces().size() <<
" ";
340 std::vector<OpenVolumeMesh::HalfFaceHandle> halffaces = _mesh.cell(*c_it).halffaces();
342 for (std::vector<OpenVolumeMesh::HalfFaceHandle>::const_iterator it = halffaces.begin();
343 it != halffaces.end(); ++it) {
346 off << _mesh.face_handle(*it);
351 if((it+1) != halffaces.end()) off <<
" ";
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())