Chi-Tech
chi_surfacemesh_extractopenedges.cc
Go to the documentation of this file.
1#include "chi_surfacemesh.h"
2
3#include "chi_runtime.h"
4#include "chi_log.h"
5
6#include <set>
7#include <fstream>
8
9//###################################################################
10/**Extract open edges to wavefront obj format.*/
12{
13 std::vector<std::pair<int,int>> edges;
14 for (auto face : poly_faces_)
15 {
16 for (auto edge : face->edges)
17 {
18 if (edge[2]<0)
19 {
20 edges.push_back(std::pair<int,int>(edge[0],edge[1]));
21 }
22 }//for edge
23 }//for face
24
25 std::ofstream outfile;
26 outfile.open(fileName);
27
28 if (!outfile.is_open())
29 {
31 << "In call to chi_mesh::SurfaceMesh::ExtractOpenEdgesToObj. Failed"
32 << " to open file: " << std::string(fileName);
33 Chi::Exit(EXIT_FAILURE);
34 }
35
36 outfile << "# ChiTech open edges file\n";
37 outfile << "# Single surface mesh\n";
38
39 for (auto vert_pair : edges)
40 {
41 chi_mesh::Vertex& v0 = vertices_[vert_pair.first];
42 chi_mesh::Vertex& v1 = vertices_[vert_pair.second];
43 outfile
44 << "v " << v0.x << " " << v0.y << " " << v0.z << "\n"
45 << "v " << v1.x << " " << v1.y << " " << v1.z << "\n";
46 }
47
48 for (size_t e = 0; e < edges.size(); ++e)
49 {
50 const auto v_count = 2 * e + 1;
51 outfile << "l " << v_count << " " << v_count + 1 << "\n";
52 }
53
54
55 outfile.close();
56}
static void Exit(int error_code)
Definition: chi_runtime.cc:342
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream LogAllError()
Definition: chi_log.h:239
std::vector< chi_mesh::PolyFace * > poly_faces_
Polygonal faces.
std::vector< chi_mesh::Vertex > vertices_
void ExtractOpenEdgesToObj(const char *fileName)
double x
Element-0.
double y
Element-1.
double z
Element-2.