hemocell
Loading...
Searching...
No Matches
meshMetrics.h
Go to the documentation of this file.
1/*
2This file is part of the HemoCell library
3
4HemoCell is developed and maintained by the Computational Science Lab
5in the University of Amsterdam. Any questions or remarks regarding this library
6can be sent to: info@hemocell.eu
7
8When using the HemoCell library in scientific work please cite the
9corresponding paper: https://doi.org/10.3389/fphys.2017.00563
10
11The HemoCell library is free software: you can redistribute it and/or
12modify it under the terms of the GNU Affero General Public License as
13published by the Free Software Foundation, either version 3 of the
14License, or (at your option) any later version.
15
16The library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU Affero General Public License for more details.
20
21You should have received a copy of the GNU Affero General Public License
22along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24#ifndef MESH_METRICS_H
25#define MESH_METRICS_H
26
27namespace plb {
28template <typename T>
29class MeshMetrics;
30}
31
32#include <map>
33#include <vector>
34
35#include "core/array.h"
36#include "offLattice/triangularSurfaceMesh.hh"
37#include "offLattice/triangleBoundary3D.hh"
38#include "array.h"
39
40namespace plb {
41
42template <typename T>
44public:
45 std::vector<Array<T, 3>> vertexList;
46 std::vector<plint> emanatingEdgeList;
47 std::vector<Edge> edgeList;
48};
49
50template <typename T>
51TriangularSurfaceMesh<T> * copyTriangularSurfaceMesh(TriangularSurfaceMesh<T> const & mesh,
53 emptyEoTSM.vertexList = mesh.vertices();
54 emptyEoTSM.emanatingEdgeList = mesh.emanatingEdges();
55 emptyEoTSM.edgeList = mesh.edges();
56 TriangularSurfaceMesh<T> * newMesh =
57 new TriangularSurfaceMesh<T>(emptyEoTSM.vertexList, emptyEoTSM.emanatingEdgeList, emptyEoTSM.edgeList);
58 return newMesh;
59}
60
61
62template <typename T>
64public:
65 MeshMetrics(MeshMetrics<T> const & rhs);
66 MeshMetrics(TriangleBoundary3D<T> const & Cells);
67 MeshMetrics(TriangularSurfaceMesh<T> const & mesh_);
69 void write(plb_ofstream & meshFile);
70 void init();
71 void write() {
72 plb_ofstream meshQualityFile((global::directories().getLogOutDir() + "plbMeshQuality.log").c_str());
73 this->write(meshQualityFile);
74 };
75 void set_dx(T dx_) { dx = dx_; };
76 void set_dt(T dt_) { dt = dt_; };
77 void set_dm(T dm_) { dm = dm_; };
78 void set_dxdtdm(T dx_, T dt_, T dm_) {
79 dx = dx_;
80 dt = dt_;
81 dm = dm_;
82 };
83 TriangularSurfaceMesh<T> const & getMesh() { return mesh; }
84 T getMeanLength() { return length; }
85 T getMaxLength() { return maxLength; }
86 T getMinLength() { return minLength; }
87
88 T getMeanAngle() { return angle; }
89 T getMaxAngle() { return maxAngle; }
90 T getMinAngle() { return minAngle; }
91
92 T getMeanArea() { return area; }
93 T getMaxArea() { return maxArea; }
94 T getMinArea() { return minArea; }
95 // Computed as the maximum dimension from the BoundingBox
96 T getRadius() { return cellRadius; }
97 T getSurface() { return Nt * area; }
98 T getVolume() { return volume; }
100
101 T getNumVertices() { return Nv; }
102 T getNumTriangles() { return Nt; }
103
104private:
105 TriangularSurfaceMesh<T> const & mesh;
114};
115
116template <typename T>
117MeshMetrics<T>::MeshMetrics(MeshMetrics<T> const & rhs) : mesh(rhs.mesh) {
118 init();
119}
120
121
122template <typename T>
123MeshMetrics<T>::MeshMetrics(TriangleBoundary3D<T> const & Cells) : mesh(Cells.getMesh()) {
124 init();
125}
126
127
128template <typename T>
129MeshMetrics<T>::MeshMetrics(TriangularSurfaceMesh<T> const & mesh_) : mesh(mesh_) {
130 init();
131}
132
133template <typename T>
135 minArea = std::numeric_limits<T>::max();
136 minLength = std::numeric_limits<T>::max();
137 minAngle = std::numeric_limits<T>::max();
138 minNn = std::numeric_limits<T>::max();
139 maxArea = 0;
140 maxLength = 0;
141 maxAngle = 0;
142 maxNn = 0;
143 meanVertexPosition.resetToZero();
144
145 Nv = mesh.getNumVertices();
146 Nt = mesh.getNumTriangles();
147 plb::Array<T, 2> xRange;
148 plb::Array<T, 2> yRange;
149 plb::Array<T, 2> zRange;
150 mesh.computeBoundingBox(xRange, yRange, zRange);
151 cellRadius = std::max(xRange[1] - xRange[0], yRange[1] - yRange[0]);
152 cellRadius = std::max(cellRadius, zRange[1] - zRange[0]) * 0.5;
153
154 Nn = 0;
155 Nn6 = 0;
156 Nn5 = 0;
157 Nn7 = 0;
158 area = 0;
159 length = 0;
160 angle = 0;
161 T varArea = 0, varLength = 0, varAngle = 0, varNn = 0;
162 T tmp;
163 // Vertices
164 pluint NEdges = 0;
165 volume = 0.0;
166 for (int iV = 0; iV < Nv; ++iV) {
167 meanVertexPosition += mesh.getVertex(iV);
168 std::vector<plint> nvid = mesh.getNeighborVertexIds(iV);
169 T NumNeighbors = nvid.size();
170 Nn += nvid.size();
171 minNn = minNn > NumNeighbors ? NumNeighbors : minNn;
172 maxNn = maxNn < NumNeighbors ? NumNeighbors : maxNn;
173 for (int ijV = 0; ijV < NumNeighbors; ++ijV) {
174 int jV = nvid[ijV];
175 tmp = mesh.computeEdgeLength(iV, jV);
176 minLength = minLength > tmp ? tmp : minLength;
177 maxLength = maxLength < tmp ? tmp : maxLength;
178 length += tmp;
179 tmp = calculateSignedAngle(mesh, iV, jV);
180 minAngle = minAngle > tmp ? tmp : minAngle;
181 maxAngle = maxAngle < tmp ? tmp : maxAngle;
182 angle += tmp;
183 NEdges++;
184 }
185 if (NumNeighbors == 5) {
186 Nn5 += 1.0;
187 } else if (NumNeighbors == 6) {
188 Nn6 += 1.0;
189 } else if (NumNeighbors == 7) {
190 Nn7 += 1.0;
191 }
192 std::vector<plint> neighborTriangleIds = mesh.getNeighborTriangleIds(iV);
193 for (pluint iB = 0; iB < neighborTriangleIds.size(); ++iB) {
194 plint iTriangle = neighborTriangleIds[iB];
195 hemo::Array<T, 3> v0 = mesh.getVertex(iTriangle, 0);
196 hemo::Array<T, 3> v1 = mesh.getVertex(iTriangle, 1);
197 hemo::Array<T, 3> v2 = mesh.getVertex(iTriangle, 2);
199 crossProduct(v1, v2, tmp);
200 T triangleVolumeT6 = dot(v0, tmp);
201 volume += triangleVolumeT6 / 6.0 / 3.0; // every volume is evaluated 3 times
202 }
203 }
204 Nn /= Nv;
205 length /= NEdges;
206 angle /= NEdges;
207 meanVertexPosition /= Nv;
208
209 // Compute vars
210 for (int iV = 0; iV < Nv; ++iV) {
211 std::vector<plint> nvid = mesh.getNeighborVertexIds(iV);
212 T NumNeighbors = nvid.size();
213 tmp = nvid.size() - Nn;
214 varNn += tmp * tmp;
215 for (int ijV = 0; ijV < NumNeighbors; ++ijV) {
216 int jV = nvid[ijV];
217 tmp = (mesh.computeEdgeLength(iV, jV) - length);
218 varLength += tmp * tmp;
219 tmp = (calculateSignedAngle(mesh, iV, jV) - angle);
220 varAngle += tmp * tmp;
221 }
222 }
223 // Triangles
224 area = 0;
225 for (int iT = 0; iT < Nt; ++iT) {
226 tmp = mesh.computeTriangleArea(iT);
227 minArea = minArea > tmp ? tmp : minArea;
228 maxArea = maxArea < tmp ? tmp : maxArea;
229 area += tmp;
230 }
231 area /= Nt;
232 for (int iT = 0; iT < Nt; ++iT) {
233 tmp = mesh.computeTriangleArea(iT) - area;
234 varArea += tmp * tmp;
235 }
236 sigmaNn = sqrt(varNn / Nv);
237 sigmaArea = sqrt(varArea / Nt);
238 sigmaLength = sqrt(varLength / NEdges);
239 sigmaAngle = sqrt(varAngle / NEdges);
240}
241
242template <typename T>
246
247template <typename T>
248void MeshMetrics<T>::write(plb_ofstream & meshFile) {
249 meshFile << "# Deviation in %, defined as 100*sigma(l)/mean(l), sl = 0" << std::endl;
250
251 meshFile << "Number of vertices, Nv = " << Nv << std::endl;
252 meshFile << "Number of triangles, Nt = " << Nt << std::endl;
253 meshFile << "Surface, S = " << getSurface() << std::endl;
254 meshFile << "Volume, V = " << getVolume() << std::endl;
255 meshFile << std::endl;
256 meshFile << "Mean Area per face, A = " << area << std::endl;
257 meshFile << "Deviation of Area %, sA = " << 100 * sigmaArea / area << std::endl;
258 meshFile << "Max Area of face, maxA = " << maxArea << std::endl;
259 meshFile << "Min Area of face, minA = " << minArea << std::endl;
260 meshFile << std::endl;
261 meshFile << "Mean Length per vertex, L = " << length << std::endl;
262 meshFile << "Deviation of Length %, sL = " << 100 * sigmaLength / length << std::endl;
263 meshFile << "Max Length of edge, maxA = " << maxLength << std::endl;
264 meshFile << "Min Length of edge, minA = " << minLength << std::endl;
265 meshFile << std::endl;
266 meshFile << "Mean Angle per vertex, theta = " << angle << std::endl;
267 meshFile << "Deviation of Angle %, sTheta = " << fabs(100 * sigmaAngle / angle) << std::endl;
268 meshFile << "Max Angle of edge, maxA = " << maxAngle << std::endl;
269 meshFile << "Min Angle of edge, minA = " << minAngle << std::endl;
270 meshFile << std::endl;
271 meshFile << "Mean number of neighbours, Nn = " << Nn << std::endl;
272 meshFile << "Deviation for number of Neighbours %, sNn = " << 100 * sigmaNn / Nn << std::endl;
273 meshFile << "Number of 5 neighbour in %, Nn5 = " << 100 * Nn5 / Nv << std::endl;
274 meshFile << "Number of 6 neighbour in %, Nn6 = " << 100 * Nn6 / Nv << std::endl;
275 meshFile << "Number of 7 neighbour in %, Nn7 = " << 100 * Nn7 / Nv << std::endl;
276};
277
278template <typename T>
279void writeSurfaceMeshAsciiSTL(TriangularSurfaceMesh<T> const & mesh, std::string fname);
280
281
282}
283#include "meshMetrics.hh"
284
285#endif // MESH_METRICS_H
Definition meshMetrics.h:43
std::vector< plint > emanatingEdgeList
Definition meshMetrics.h:46
std::vector< Array< T, 3 > > vertexList
Definition meshMetrics.h:45
std::vector< Edge > edgeList
Definition meshMetrics.h:47
Definition meshMetrics.h:63
T angle
Definition meshMetrics.h:107
T Nn
Definition meshMetrics.h:106
T maxAngle
Definition meshMetrics.h:111
T getMinArea()
Definition meshMetrics.h:94
T getMeanLength()
Definition meshMetrics.h:84
T Nn7
Definition meshMetrics.h:106
void write()
Definition meshMetrics.h:71
TriangularSurfaceMesh< T > const & mesh
Definition meshMetrics.h:105
T getNumTriangles()
Definition meshMetrics.h:102
T Nt
Definition meshMetrics.h:106
T maxArea
Definition meshMetrics.h:111
T sigmaNn
Definition meshMetrics.h:109
T Nn5
Definition meshMetrics.h:106
T getMinLength()
Definition meshMetrics.h:86
TriangularSurfaceMesh< T > const & getMesh()
Definition meshMetrics.h:83
void set_dx(T dx_)
Definition meshMetrics.h:75
T sigmaArea
Definition meshMetrics.h:109
T getSurface()
Definition meshMetrics.h:97
T minNn
Definition meshMetrics.h:110
T dm
Definition meshMetrics.h:112
T getMeanAngle()
Definition meshMetrics.h:88
T getMinAngle()
Definition meshMetrics.h:90
hemo::Array< T, 3 > getMeanVertexPosition()
Definition meshMetrics.h:99
T dx
Definition meshMetrics.h:112
T sigmaAngle
Definition meshMetrics.h:109
T minLength
Definition meshMetrics.h:110
T getMaxLength()
Definition meshMetrics.h:85
void init()
Definition meshMetrics.h:134
MeshMetrics(MeshMetrics< T > const &rhs)
Definition meshMetrics.h:117
T getMeanArea()
Definition meshMetrics.h:92
T maxLength
Definition meshMetrics.h:111
T Nn6
Definition meshMetrics.h:106
T volume
Definition meshMetrics.h:107
hemo::Array< T, 3 > meanVertexPosition
Definition meshMetrics.h:108
void set_dxdtdm(T dx_, T dt_, T dm_)
Definition meshMetrics.h:78
T minArea
Definition meshMetrics.h:110
T getMaxAngle()
Definition meshMetrics.h:89
void set_dt(T dt_)
Definition meshMetrics.h:76
T getRadius()
Definition meshMetrics.h:96
T area
Definition meshMetrics.h:107
T getMaxArea()
Definition meshMetrics.h:93
T getNumVertices()
Definition meshMetrics.h:101
T sigmaLength
Definition meshMetrics.h:109
T length
Definition meshMetrics.h:107
T dt
Definition meshMetrics.h:112
T minAngle
Definition meshMetrics.h:110
void set_dm(T dm_)
Definition meshMetrics.h:77
T cellRadius
Definition meshMetrics.h:113
T maxNn
Definition meshMetrics.h:111
T Nv
Definition meshMetrics.h:106
T getVolume()
Definition meshMetrics.h:98
~MeshMetrics()
Definition meshMetrics.h:243
double T
Definition constant_defaults.h:137
long int plint
Definition constant_defaults.h:149
long unsigned int pluint
Definition constant_defaults.h:152
Definition meshGeneratingFunctions.cpp:28
void writeSurfaceMeshAsciiSTL(TriangularSurfaceMesh< T > const &mesh, std::string fname)
Definition meshMetrics.hh:82
T calculateSignedAngle(TriangularSurfaceMesh< T > const &mesh, plint iVertex, plint jVertex, plint &kVertex, plint &lVertex)
Definition meshMetrics.hh:36
TriangularSurfaceMesh< T > * copyTriangularSurfaceMesh(TriangularSurfaceMesh< T > const &mesh, ElementsOfTriangularSurfaceMesh< T > &emptyEoTSM)
Definition meshMetrics.h:51
Definition array.h:40