PeriDyno 0.8.2
PLYexporter.cpp
Go to the documentation of this file.
1#pragma once
2#include "PLYexporter.h"
3#include <fstream>
4#include<iomanip>
5
6
7
8
9namespace dyno
10{
11 IMPLEMENT_TCLASS(PlyExporter, TDataType)
12 template <typename TDataType> class TriangleSet;
13
14 template<typename TDataType>
16 {
17 this->inVec3f()->tagOptional(true);
18 this->inMatrix1()->tagOptional(true);
19 this->inMatrix2()->tagOptional(true);
20
21 }
22
23
24
25 template<typename TDataType>
27 {
28 if (this->stateFrameNumber()->getData() % this->varFrameStep()->getData() != 0)
29 {
30 return;
31 }
33 trilist.copyFrom(this->inTriangleSet()->getData());
34
37 c_triangle.assign(d_triangle);
38 trilist.getVer2Edge();
39 trilist.getVertex2Triangles();
40
41
42 DArray<Coord> d_point = trilist.getPoints();
43 CArray<Coord> c_point;
44 c_point.assign(d_point);
45
46 DArray<Coord> d_color;
47 CArray<Coord> c_color;
48 DArray<Matrix> d_strain;
49 CArray<Matrix> c_strain;
50 DArray<Matrix> d_stress;
51 CArray<Matrix> c_stress;
52
53 if (!this->inVec3f()->isEmpty())
54 {
55 d_color = this->inVec3f()->getData();
56 c_color.assign(d_color);
57 }
58 if (!this->inMatrix1()->isEmpty())
59 {
60 d_strain = this->inMatrix1()->getData();
61 c_strain.assign(d_strain);
62 }
63 if (!this->inMatrix2()->isEmpty())
64 {
65 d_stress = this->inMatrix2()->getData();
66 c_stress.assign(d_stress);
67 }
68
69 int n_point = this->inTriangleSet()->getData().getVertex2Triangles().size();
70 int n_triangle = this->inTriangleSet()->getData().getTriangles().size();
71 int stw = 3;
72 int num = 6;
73
74 unsigned out_number;
75 if (this->varReCount()->getData())
76 {
77 out_number = this->stateFrameNumber()->getData() / this->varFrameStep()->getData();
78 }
79 else
80 {
81 out_number = this->stateFrameNumber()->getData();
82 }
83
84 std::stringstream ss; ss << out_number;
85 std::string filename = this->varOutputPath()->getData() + ss.str() + this->file_postfix;//
86 std::ofstream out4(filename.c_str(), std::ios::out);
87
88 out4 << "ply" << std::endl;
89 out4 << "format ascii 1.0" << std::endl;
90 out4 << "comment created by Peridyno" << std::endl;
91 out4 << "element vertex " << n_point << std::endl;
92
93 out4 << "property float x" << std::endl;
94 out4 << "property float y" << std::endl;
95 out4 << "property float z" << std::endl;
96
97 if (!this->inVec3f()->isEmpty())
98 {
99 out4 << "property uchar vec3f01" << std::endl;
100 out4 << "property uchar vec3f02" << std::endl;
101 out4 << "property uchar vec3f03" << std::endl;
102 }
103
104 if (!this->inMatrix1()->isEmpty())
105 {
106 out4 << "property float MatrixOne00" << std::endl;
107 out4 << "property float MatrixOne01" << std::endl;
108 out4 << "property float MatrixOne02" << std::endl;
109 out4 << "property float MatrixOne10" << std::endl;
110 out4 << "property float MatrixOne11" << std::endl;
111 out4 << "property float MatrixOne12" << std::endl;
112 out4 << "property float MatrixOne20" << std::endl;
113 out4 << "property float MatrixOne21" << std::endl;
114 out4 << "property float MatrixOne22" << std::endl;
115 }
116
117 if (!this->inMatrix2()->isEmpty())
118 {
119 out4 << "property float MatrixTwo00" << std::endl;
120 out4 << "property float MatrixTwo01" << std::endl;
121 out4 << "property float MatrixTwo02" << std::endl;
122 out4 << "property float MatrixTwo10" << std::endl;
123 out4 << "property float MatrixTwo11" << std::endl;
124 out4 << "property float MatrixTwo12" << std::endl;
125 out4 << "property float MatrixTwo20" << std::endl;
126 out4 << "property float MatrixTwo21" << std::endl;
127 out4 << "property float MatrixTwo22" << std::endl;
128 }
129
130 out4 << "element face " << n_triangle << std::endl;
131 out4 << "property list uchar int vertex_indices" << std::endl;
132 out4 << "end_header" << std::endl;
133
134
135
136 for (int i = 0; i < n_point; i++)
137 {
138 //输出顶点坐标
139 out4 << std::fixed << std::setw(stw) << std::setprecision(num) << c_point[i][0] << " "
140 << std::fixed << std::setw(stw) << std::setprecision(num) << c_point[i][1] << " "
141 << std::fixed << std::setw(stw) << std::setprecision(num) << c_point[i][2] << " ";
142
143 //输出颜色
144 if (!this->inVec3f()->isEmpty()) {
145 out4 << std::fixed << std::setw(stw) << std::setprecision(num) << c_color[i][0] << " "
146 << std::fixed << std::setw(stw) << std::setprecision(num) << c_color[i][1] << " "
147 << std::fixed << std::setw(stw) << std::setprecision(num) << c_color[i][2] << " ";
148
149 }
150
151 //输出应变
152 if (!this->inMatrix1()->isEmpty())
153 {
154 for (int j = 0; j < 3; j++)
155 {
156 for (int k = 0; k < 3; k++)
157 {
158 out4 << std::fixed << std::setw(stw) << std::setprecision(num) << c_strain[i](j, k) << " ";
159 }
160 }
161 }
162 //输出应力
163 if (!this->inMatrix2()->isEmpty())
164 {
165 for (int j = 0; j < 3; j++)
166 {
167 for (int k = 0; k < 3; k++)
168 {
169 out4 << std::fixed << std::setw(stw) << std::setprecision(num) << c_stress[i](j, k) << " ";
170 }
171 }
172 }
173 out4 << std::endl;
174 }
175
176 for (int i = 0; i < n_triangle; i++)
177 {
178 out4 << "3 " << std::fixed << std::setw(stw) << std::setprecision(num) << c_triangle[i][2] << " ";
179 out4 << std::fixed << std::setw(stw) << std::setprecision(num) << c_triangle[i][1] << " ";
180 out4 << std::fixed << std::setw(stw) << std::setprecision(num) << c_triangle[i][0]
181 <<std::endl;
182 }
183 out4.close();
184
185
186 }
187
188
189 template<typename TDataType>
191 {
192
193 }
194
195
197}
void assign(const T &val)
Definition: Array.h:128
DArrayList< int > & getVer2Edge()
void resetStates() override
void updateStates() override
Definition: PLYexporter.cpp:26
DArray< Coord > & getPoints()
Definition: PointSet.h:25
DArrayList< int > & getVertex2Triangles()
void copyFrom(TriangleSet< TDataType > &triangleSet)
DArray< Triangle > & getTriangles()
return all triangle indices
Definition: TriangleSet.h:98
This is an implementation of AdditiveCCD based on peridyno.
Definition: Array.h:24
IMPLEMENT_TCLASS(FloatingNumber, TDataType)
DEFINE_CLASS(CircularEmitter)