PeriDyno 1.0.0
Loading...
Searching...
No Matches
TetraMeshWriter.cpp
Go to the documentation of this file.
1#include "TetraMeshWriter.h"
3
4#include <sstream>
5#include <iostream>
6#include <fstream>
7
8namespace dyno
9{
11
12 template<typename TDataType>
17
18 template<typename TDataType>
22
23
24 template<typename TDataType>
26 {
27 if (this->ptr_TetrahedronSet == nullptr) {
28 return false;
29 }
30 this->ptr_triangles = &( this->ptr_TetrahedronSet->getTriangles() );
31 this->ptr_tri2tet = &( this->ptr_TetrahedronSet->getTri2Tet() );
32 this->ptr_vertices = &( this->ptr_TetrahedronSet->getPoints() );
33 this->ptr_tets = &( this->ptr_TetrahedronSet->getTetrahedrons() );
34 }
35
36 template<typename TDataType>
38 {
39 if (this->ptr_tri2tet == nullptr || this->ptr_triangles == nullptr || this->ptr_vertices == nullptr) {
40 printf("------Tetra Mesh Writer: array nullptr \n");
41 return;
42 }
43
44 std::string filename = this->constructFileName() + this->file_postfix;
45 std::ofstream output(filename.c_str(), std::ios::out);
46
47 if (!output.is_open()) {
48 printf("------Tetra Mesh Writer: open file failed \n");
49 return;
50 }
51
52 printf("Output Surface!!!!!!!!\n");
53
54 this->updatePtr();
55
56 CArray<Coord> host_vertices;
57 CArray<Triangle> host_triangles;
58 CArray<Tri2Tet> host_tri2tet;
59 CArray<Tetrahedron> host_tets;
60
61 host_vertices.resize( (*(this->ptr_vertices)).size() );
62 host_triangles.resize( (*(this->ptr_triangles)).size() );
63 host_tri2tet.resize( (*(this->ptr_tri2tet)).size() );
64 host_tets.resize((*(this->ptr_tets)).size());
65
66 host_vertices.assign(*(this->ptr_vertices));
67 host_triangles.assign(*(this->ptr_triangles));
68 host_tri2tet.assign(*(this->ptr_tri2tet));
69 host_tets.assign(*(this->ptr_tets));
70
71 for (uint i = 0; i < host_vertices.size(); ++i) {
72 output << "v " << host_vertices[i][0] << " " << host_vertices[i][1] << " " << host_vertices[i][2] << std::endl;
73 }
74 for (int i = 0; i < host_tri2tet.size(); ++i) {
75 Tri2Tet tmp = host_tri2tet[i];
76 bool isOnSurface = false;
77 if (tmp[0] < 0 || tmp[1] < 0) { isOnSurface = true; }
78 if (isOnSurface) {
79 int idx_vertex;
80 bool reverse = false;
81 int idx_tet = tmp[0] < 0 ? tmp[1] : tmp[0];
82 for (idx_vertex = 0; idx_vertex < 4; idx_vertex++)
83 {
84
85 if (host_tets[idx_tet][idx_vertex] != host_triangles[i][0]
86 && host_tets[idx_tet][idx_vertex] != host_triangles[i][1]
87 && host_tets[idx_tet][idx_vertex] != host_triangles[i][2]
88 )
89 break;
90 }
91 idx_vertex = host_tets[idx_tet][idx_vertex];
92 if (
93 ((host_vertices[host_triangles[i][1]] - host_vertices[host_triangles[i][0]]).cross
94 (host_vertices[host_triangles[i][2]] - host_vertices[host_triangles[i][1]]))
95 .dot
96 (host_vertices[idx_vertex] - host_vertices[host_triangles[i][0]]) > 0
97 )
98 reverse = true;
99 if(!reverse)
100 output << "f " << host_triangles[i][0] + 1 << " " << host_triangles[i][1] + 1 << " " << host_triangles[i][2] + 1 << std::endl;
101 else
102 output << "f " << host_triangles[i][0] + 1<< " " << host_triangles[i][2] + 1<< " " << host_triangles[i][1] + 1<< std::endl;
103 }
104 }
105
106 host_vertices.clear();
107 host_triangles.clear();
108 host_tri2tet.clear();
109
110 return;
111 }
112
113
114
116}
#define DEFINE_CLASS(name)
Definition Object.h:140
#define IMPLEMENT_TCLASS(name, T1)
Definition Object.h:103
std::string constructFileName()
std::shared_ptr< TetrahedronSet< TDataType > > ptr_TetrahedronSet
DArray< Coord > * ptr_vertices
DArray< Triangle > * ptr_triangles
DArray< Tri2Tet > * ptr_tri2tet
TopologyModule::Tri2Tet Tri2Tet
DArray< Tetrahedron > * ptr_tets
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC Vector< T, 3 > cross(Vector< T, 3 > const &U, Vector< T, 3 > const &V)
Definition SimpleMath.h:211
DYN_FUNC T dot(Vector< T, 2 > const &U, Vector< T, 2 > const &V)
Definition SimpleMath.h:199
Array< T, DeviceType::CPU > CArray
Definition Array.h:151
unsigned int uint
Definition VkProgram.h:14