PeriDyno 1.0.0
Loading...
Searching...
No Matches
TriangleMeshWriter.cpp
Go to the documentation of this file.
3
4#include <sstream>
5#include <iostream>
6#include <fstream>
7
8namespace dyno
9{
11
12 template<typename TDataType>
16
17 template<typename TDataType>
21
22
23
24 template<typename TDataType>
26 {
27 auto mode = this->varOutputType()->getValue();
28
29 if (mode == OutputType::TriangleMesh)
30 {
31 auto triSet = TypeInfo::cast<TriangleSet<TDataType>>(this->inTopology()->getDataPtr());
32 outputSurfaceMesh(triSet);
33 }
34 else if (mode == OutputType::PointCloud)
35 {
36 auto ptSet = TypeInfo::cast<PointSet<TDataType>>(this->inTopology()->getDataPtr());
37 outputPointCloud(ptSet);
38 }
39
40 }
41
42 template<typename TDataType>
44 {
45 std::string filename = this->constructFileName() + this->file_postfix;;
46 std::ofstream output(filename.c_str(), std::ios::out);
47
48 std::cout << filename << std::endl;
49
50 if (!output.is_open()) {
51 printf("------Triangle Mesh Writer: open file failed \n");
52 return;
53 }
54
55 std::cout << "------Triangle Mesh Writer Action!------ " << std::endl;
56
57
58 CArray<Coord> host_vertices;
60
61
62 if (triangleset->getPoints().size())
63 {
64 host_vertices.assign(triangleset->getPoints());
65 }
66 if (triangleset->getTriangles().size())
67 {
68 host_triangles.assign(triangleset->getTriangles());
69 }
70
71
72 for (uint i = 0; i < host_vertices.size(); ++i) {
73 output << "v " << host_vertices[i][0] << " " << host_vertices[i][1] << " " << host_vertices[i][2] << std::endl;
74 }
75 for (uint i = 0; i < host_triangles.size(); ++i) {
76 output << "f " << host_triangles[i][0] + 1 << " " << host_triangles[i][1] + 1 << " " << host_triangles[i][2] + 1 << std::endl;
77 }
78 output.close();
79
80
81 host_vertices.clear();
82 host_triangles.clear();
83
84
85 return;
86 }
87
88 template<typename TDataType>
90 {
91 std::string filename = this->constructFileName() + this->file_postfix;//
92 std::ofstream output(filename.c_str(), std::ios::out);
93
94 std::cout << filename << std::endl;
95
96 if (!output.is_open()) {
97 printf("------Triangle Mesh Writer: open file failed \n");
98 return;
99 }
100
101 std::cout << "------Pointcloud Writer Action!------ " << std::endl;
102
103 CArray<Coord> host_vertices;
104
105 if (pointset->getPoints().size())
106 {
107 host_vertices.assign(pointset->getPoints());
108 }
109
110 for (uint i = 0; i < host_vertices.size(); ++i) {
111 output << "v " << host_vertices[i][0] << " " << host_vertices[i][1] << " " << host_vertices[i][2] << std::endl;
112 }
113
114 output.close();
115
116 host_vertices.clear();
117
118
119 return;
120 }
121
122
123
124
126}
#define DEFINE_CLASS(name)
Definition Object.h:140
#define IMPLEMENT_TCLASS(name, T1)
Definition Object.h:103
std::string constructFileName()
A PointSet stores the coordinates for a set of independent points.
Definition PointSet.h:8
void outputPointCloud(std::shared_ptr< PointSet< TDataType > > pointset)
void outputSurfaceMesh(std::shared_ptr< TriangleSet< TDataType > > triangleset)
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::CPU > CArray
Definition Array.h:151
unsigned int uint
Definition VkProgram.h:14