43 #define FILEOPENVOLUMEMESHT_CC 45 #include "FileOpenVolumeMesh.hh" 49 template <
typename MeshT>
50 void FileOpenVolumeMeshPlugin::loadMesh(
const char* _filename, MeshT& _mesh,
bool _comp,
bool _topCheck) {
53 bool edges_in_file =
false;
55 typedef typename MeshT::PointT Vertex;
58 std::ifstream iff(_filename, std::ios::in);
64 if (s !=
"Vertices") {
65 std::cerr <<
"ERROR reading OpenVolumeMesh (Vertex Section Failed)\n";
73 for (
int i = 0; i < nv; ++i) {
85 std::cerr <<
"No edges found" << std::endl;
90 for (
int e = 0; e < ne; ++e) {
103 std::cerr <<
"ERROR reading OpenVolumeMesh (Face Section Failed)\n";
114 for (
int f = 0; f < nf; ++f) {
117 std::vector<OpenVolumeMesh::VertexHandle> vhs;
118 for (
int v = 0; v < nfv; ++v) {
123 int pos_cell, neg_cell;
133 for (
int f = 0; f < nf; ++f) {
136 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes;
137 for (
int he = 0; he < nfhe; ++he) {
143 _mesh.add_face(hes, _topCheck);
149 if(s !=
"Polyhedra") {
150 std::cerr <<
"ERROR reading OpenVolumeMesh (Polyhedra Section Failed)\n";
160 for(
int i = 0; i < nc; ++i) {
164 std::vector< OpenVolumeMesh::FaceHandle > faces;
166 for(
int f = 0; f < ncf; ++f) {
176 unsigned int num_faces = faces.size();
180 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes = _mesh.face(fh).halfedges();
181 unsigned int val = hes.size();
183 for(std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator p_it = hes.begin();
184 p_it != hes.end(); ++p_it) {
185 f_mid += (_mesh.vertex(_mesh.halfedge(*p_it).to_vertex()) / (
double)val);
187 c += f_mid / (double)num_faces;
192 std::vector<OpenVolumeMesh::HalfFaceHandle> hfhandles;
197 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes = _mesh.face(fh).halfedges();
198 unsigned int val = hes.size();
200 for(std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator p_it = hes.begin();
201 p_it != hes.end(); ++p_it) {
202 f_mid += (_mesh.vertex(_mesh.halfedge(*p_it).to_vertex()) / (
double)val);
206 if(hes.size() < 2)
continue;
207 ACG::Vec3d p0 = _mesh.vertex(_mesh.halfedge(hes[0]).from_vertex());
208 ACG::Vec3d p1 = _mesh.vertex(_mesh.halfedge(hes[0]).to_vertex());
209 ACG::Vec3d p2 = _mesh.vertex(_mesh.halfedge(hes[1]).to_vertex());
213 if(((c - f_mid) | n) >= 0.0) hfhandles.push_back(_mesh.halfface_handle(fh, 0));
214 else hfhandles.push_back(_mesh.halfface_handle(fh, 1));
217 if(hfhandles.size() > 3) {
223 hm->add_cell(hfhandles, _topCheck);
225 _mesh.add_cell(hfhandles, _topCheck);
228 std::cerr <<
"Could not determine corresponding halffaces!" << std::endl;
236 for (
int c = 0; c < nc; ++c) {
240 std::vector<OpenVolumeMesh::HalfFaceHandle> hfs;
241 for (
int hf = 0; hf < nhf; ++hf) {
252 hm->add_cell(hfs, _topCheck);
254 _mesh.add_cell(hfs, _topCheck);
260 std::cerr <<
"######## openvolumemesh info #########\n";
261 std::cerr <<
"#vertices: " << _mesh.n_vertices() << std::endl;
262 std::cerr <<
"#edges : " << _mesh.n_edges() << std::endl;
263 std::cerr <<
"#faces : " << _mesh.n_faces() << std::endl;
264 std::cerr <<
"#cells : " << _mesh.n_cells() << std::endl;
269 template <
typename MeshT>
270 void FileOpenVolumeMeshPlugin::saveMesh(
const char* _filename, MeshT& _mesh,
bool _comp) {
273 std::ofstream off(_filename, std::ios::out);
275 int n_vertices(_mesh.n_vertices());
276 off <<
"Vertices" << std::endl;
277 off << n_vertices << std::endl;
283 off << v[0] <<
" " << v[1] <<
" " << v[2] << std::endl;
286 int n_edges(_mesh.n_edges());
287 off <<
"Edges" << std::endl;
288 off << n_edges << std::endl;
295 off << from_vertex <<
" " << to_vertex << std::endl;
298 int n_faces(_mesh.n_faces());
299 off <<
"Faces" << std::endl;
300 off << n_faces << std::endl;
305 off << _mesh.face(*f_it).halfedges().size() <<
" ";
307 std::vector<OpenVolumeMesh::HalfEdgeHandle> halfedges = _mesh.face(*f_it).halfedges();
309 for (std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator it = halfedges.begin();
310 it != halfedges.end(); ++it) {
313 off << _mesh.halfedge(*it).from_vertex();
318 if((it+1) != halfedges.end()) off <<
" ";
325 int n_cells(_mesh.n_cells());
326 off <<
"Polyhedra" << std::endl;
327 off << n_cells << std::endl;
331 off << _mesh.cell(*c_it).halffaces().size() <<
" ";
333 std::vector<OpenVolumeMesh::HalfFaceHandle> halffaces = _mesh.cell(*c_it).halffaces();
335 for (std::vector<OpenVolumeMesh::HalfFaceHandle>::const_iterator it = halffaces.begin();
336 it != halffaces.end(); ++it) {
339 off << _mesh.face_handle(*it);
344 if((it+1) != halffaces.end()) off <<
" ";
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())