31 #include <QTextStream>
40 if (ifstream(file_path).good()) {
43 QFile::remove(QString::fromStdString(file_path));
50 QFile file(QString::fromStdString(file_path));
51 if (file.open(QIODevice::WriteOnly)) {
52 const auto mesh = sim->GetCoreData().m_mesh;
53 QTextStream stream(&file);
54 StreamHeader(*mesh, stream);
55 StreamBody(*mesh, stream);
67 void PlyExporter::StreamHeader(
const Mesh& mesh, QTextStream& stream)
69 stream <<
"ply" << endl;
70 stream <<
"format ascii 1.0" << endl;
71 stream <<
"element vertex " << mesh.
GetNodes().size() << endl;
72 stream <<
"property double x" << endl;
73 stream <<
"property double y" << endl;
74 stream <<
"property double z" << endl;
75 stream <<
"property uint attributes.fixed" << endl;
76 stream <<
"element face " << mesh.
GetCells().size() << endl;
77 stream <<
"property list uchar int vertex_indices" << endl;
78 stream <<
"property list uchar int wall_indices" << endl;
79 stream <<
"property list uchar double attributes.chemical_array" << endl;
80 stream <<
"element boundary 1" << endl;
81 stream <<
"property list uchar int vertex_indices" << endl;
82 stream <<
"property list uchar int wall_indices" << endl;
83 stream <<
"element wall " << mesh.
GetWalls().size() << endl;
84 stream <<
"property int node1" << endl;
85 stream <<
"property int node2" << endl;
86 stream <<
"property int cell1" << endl;
87 stream <<
"property int cell2" << endl;
88 stream <<
"property double attributes.rest_length" << endl;
89 stream <<
"property double attributes.rest_length_init" << endl;
90 stream <<
"element edge " << mesh.
GetCells().size() + mesh.
GetNodes().size() - 1 << endl;
91 stream <<
"property int vertex1" << endl;
92 stream <<
"property int vertex2" << endl;
93 stream <<
"end_header" << endl;
96 void PlyExporter::StreamBody(
const Mesh& mesh, QTextStream& stream)
99 for (
const auto& n : mesh.
GetNodes()) {
100 stream << (*n)[0] <<
" " << (*n)[1] <<
" " << (*n)[2] <<
" " << (
unsigned int)n->IsFixed() << endl;
105 stream << c->GetNodes().size();
106 for (
Node* n : c->GetNodes()) {
107 stream <<
" " << n->GetIndex();
109 stream <<
" " << c->GetWalls().size();
110 for (
Wall* w : c->GetWalls()) {
111 stream <<
" " << w->GetIndex();
113 auto chemicals = c->GetChemicals();
114 stream <<
" " << chemicals.size();
115 for (
double chemical : chemicals) {
116 stream <<
" " << chemical;
124 stream <<
" " << n->GetIndex();
128 stream <<
" " << w->GetIndex();
133 std::list<Edge> edges;
134 for (
const auto& w : mesh.
GetWalls()) {
135 stream << w->GetN1()->GetIndex() <<
" " << w->GetN2()->GetIndex() <<
" ";
136 stream << w->GetC1()->GetIndex() <<
" " << w->GetC2()->GetIndex() <<
" ";
137 stream << w->GetRestLength() << endl;
139 auto newEdges = w->GetEdges();
140 edges.insert(edges.end(), newEdges.begin(), newEdges.end());
145 for (
const auto& e : edges) {
146 stream << e.GetFirst()->GetIndex() <<
" " << e.GetSecond()->GetIndex() << endl;
Core data used during model execution.
const std::list< Wall * > & GetWalls() const
Access the cell's walls.
Namespace for SimPT shell package.
const std::vector< Cell * > & GetCells() const
The cells of this mesh, EXCLUDING the boundary polygon.
Namespace for the core simulator.
const std::vector< Node * > & GetNodes() const
Access the nodes of cell's polygon.
Cell * GetBoundaryPolygon() const
Get the boundary polygon of the mesh.
static std::string GetFileExtension()
File extension associated with this export format.
Interface for PlyExporter.
const std::vector< Node * > & GetNodes() const
The nodes of the mesh.
Structure of cells; key data structure.
const std::vector< Wall * > & GetWalls() const
The walls of this mesh.
static bool Export(std::shared_ptr< SimPT_Sim::SimInterface > sim, std::string const &file_path, bool overwrite=true)
Export sim state to ply format.
A cell wall, runs between cell corner points and consists of wall elements.