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 {
41using namespace std;
42
43template<typename T>
45public:
46 std::vector<Array<T,3> > vertexList;
47 std::vector<plint> emanatingEdgeList;
48 std::vector<Edge> edgeList;
49};
50
51template<typename T>
52TriangularSurfaceMesh<T> * copyTriangularSurfaceMesh(TriangularSurfaceMesh<T> const& mesh, ElementsOfTriangularSurfaceMesh<T> & emptyEoTSM) {
53 emptyEoTSM.vertexList = mesh.vertices();
54 emptyEoTSM.emanatingEdgeList = mesh.emanatingEdges();
55 emptyEoTSM.edgeList= mesh.edges();
56 TriangularSurfaceMesh<T> * newMesh = new TriangularSurfaceMesh<T>(emptyEoTSM.vertexList, emptyEoTSM.emanatingEdgeList, emptyEoTSM.edgeList);
57 return newMesh;
58}
59
60
61template<typename T>
63{
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() { plb_ofstream meshQualityFile((global::directories().getLogOutDir() + "plbMeshQuality.log").c_str()); this->write(meshQualityFile); } ;
72 void set_dx(T dx_) { dx = dx_; } ;
73 void set_dt(T dt_) { dt = dt_; } ;
74 void set_dm(T dm_) { dm = dm_; } ;
75 void set_dxdtdm(T dx_, T dt_, T dm_) { dx = dx_; dt = dt_; dm = dm_;} ;
76 TriangularSurfaceMesh<T> const& getMesh() { return mesh; }
77 T getMeanLength() { return length; }
78 T getMaxLength() { return maxLength; }
79 T getMinLength() { return minLength; }
80
81 T getMeanAngle() { return angle; }
82 T getMaxAngle() { return maxAngle; }
83 T getMinAngle() { return minAngle; }
84
85 T getMeanArea() { return area; }
86 T getMaxArea() { return maxArea; }
87 T getMinArea() { return minArea; }
88 // Computed as the maximum dimension from the BoundingBox
89 T getRadius() { return cellRadius; }
90 T getSurface() { return Nt*area; }
91 T getVolume() { return volume; }
93
94 T getNumVertices() { return Nv; }
95 T getNumTriangles() { return Nt; }
96
97private:
98 TriangularSurfaceMesh<T> const& mesh;
99 T Nv, Nt, Nn, Nn6, Nn5, Nn7;
107};
108
109template<typename T>
110MeshMetrics<T>::MeshMetrics(MeshMetrics<T> const& rhs) : mesh(rhs.mesh) {
111 init();
112}
113
114
115template<typename T>
116MeshMetrics<T>::MeshMetrics(TriangleBoundary3D<T> const& Cells) : mesh(Cells.getMesh()) {
117 init();
118}
119
120
121template<typename T>
122MeshMetrics<T>::MeshMetrics(TriangularSurfaceMesh<T> const& mesh_) : mesh(mesh_) {
123 init();
124}
125
126template<typename T>
128 minArea=std::numeric_limits<T>::max(); minLength=std::numeric_limits<T>::max();
129 minAngle=std::numeric_limits<T>::max(); minNn=std::numeric_limits<T>::max();
130 maxArea=0; maxLength=0; maxAngle=0; maxNn=0;
131 meanVertexPosition.resetToZero();
132
133 Nv = mesh.getNumVertices();
134 Nt = mesh.getNumTriangles();
135 plb::Array<T,2> xRange;
136 plb::Array<T,2> yRange;
137 plb::Array<T,2> zRange;
138 mesh.computeBoundingBox (xRange, yRange, zRange);
139 cellRadius = max(xRange[1] - xRange[0], yRange[1] - yRange[0]);
140 cellRadius = max(cellRadius , zRange[1] - zRange[0]) * 0.5;
141
142 Nn=0; Nn6=0; Nn5=0; Nn7=0;
143 area=0; length=0; angle=0;
144 T varArea=0, varLength=0, varAngle=0, varNn=0;
145 T tmp;
146 // Vertices
147 pluint NEdges = 0;
148 volume = 0.0;
149 for (int iV = 0; iV < Nv; ++iV) {
150 meanVertexPosition += mesh.getVertex(iV);
151 std::vector<plint> nvid = mesh.getNeighborVertexIds(iV);
152 T NumNeighbors = nvid.size();
153 Nn += nvid.size();
154 minNn = minNn>NumNeighbors?NumNeighbors:minNn;
155 maxNn = maxNn<NumNeighbors?NumNeighbors:maxNn;
156 for (int ijV = 0; ijV < NumNeighbors; ++ijV) {
157 int jV = nvid[ijV];
158 tmp = mesh.computeEdgeLength(iV, jV);
159 minLength = minLength>tmp?tmp:minLength;
160 maxLength = maxLength<tmp?tmp:maxLength;
161 length += tmp;
162 tmp = calculateSignedAngle(mesh, iV, jV);
163 minAngle = minAngle>tmp?tmp:minAngle;
164 maxAngle = maxAngle<tmp?tmp:maxAngle;
165 angle += tmp;
166 NEdges++;
167 }
168 if (NumNeighbors == 5) {
169 Nn5 += 1.0;
170 } else if (NumNeighbors == 6) {
171 Nn6 += 1.0;
172 } else if (NumNeighbors == 7) {
173 Nn7 += 1.0;
174 }
175 std::vector<plint> neighborTriangleIds = mesh.getNeighborTriangleIds(iV);
176 for (pluint iB = 0; iB < neighborTriangleIds.size(); ++iB) {
177 plint iTriangle = neighborTriangleIds[iB];
178 hemo::Array<T,3> v0 = mesh.getVertex(iTriangle, 0);
179 hemo::Array<T,3> v1 = mesh.getVertex(iTriangle, 1);
180 hemo::Array<T,3> v2 = mesh.getVertex(iTriangle, 2);
182 crossProduct(v1, v2, tmp);
183 T triangleVolumeT6 = dot(v0,tmp);
184 volume += triangleVolumeT6/6.0/3.0; // every volume is evaluated 3 times
185 }
186 }
187 Nn /= Nv; length /= NEdges; angle /= NEdges;
188 meanVertexPosition /= Nv;
189
190// Compute vars
191 for (int iV = 0; iV < Nv; ++iV) {
192 std::vector<plint> nvid = mesh.getNeighborVertexIds(iV);
193 T NumNeighbors = nvid.size();
194 tmp = nvid.size()-Nn;
195 varNn += tmp*tmp;
196 for (int ijV = 0; ijV < NumNeighbors; ++ijV) {
197 int jV = nvid[ijV];
198 tmp=(mesh.computeEdgeLength(iV, jV)-length);
199 varLength += tmp*tmp;
200 tmp = (calculateSignedAngle(mesh, iV, jV) - angle);
201 varAngle += tmp*tmp;
202 }
203 }
204// Triangles
205 area=0;
206 for (int iT = 0; iT < Nt; ++iT) {
207 tmp = mesh.computeTriangleArea(iT);
208 minArea = minArea>tmp?tmp:minArea;
209 maxArea = maxArea<tmp?tmp:maxArea;
210 area += tmp;
211 }
212 area /= Nt;
213 for (int iT = 0; iT < Nt; ++iT) {
214 tmp = mesh.computeTriangleArea(iT) - area;
215 varArea += tmp*tmp;
216 }
217 sigmaNn = sqrt(varNn/Nv);
218 sigmaArea = sqrt(varArea/Nt);
219 sigmaLength = sqrt(varLength/NEdges);
220 sigmaAngle = sqrt(varAngle/NEdges);
221}
222
223template<typename T>
227
228template<typename T>
229void MeshMetrics<T>::write(plb_ofstream & meshFile) {
230 meshFile << "# Deviation in %, defined as 100*sigma(l)/mean(l), sl = 0" << std::endl;
231
232 meshFile << "Number of vertices, Nv = " << Nv << std::endl;
233 meshFile << "Number of triangles, Nt = " << Nt << std::endl;
234 meshFile << "Surface, S = " << getSurface() << std::endl;
235 meshFile << "Volume, V = " << getVolume() << std::endl;
236 meshFile << std::endl;
237 meshFile << "Mean Area per face, A = " << area << std::endl;
238 meshFile << "Deviation of Area %, sA = " << 100*sigmaArea/area << std::endl;
239 meshFile << "Max Area of face, maxA = " << maxArea << std::endl;
240 meshFile << "Min Area of face, minA = " << minArea << std::endl;
241 meshFile << std::endl;
242 meshFile << "Mean Length per vertex, L = " << length << std::endl;
243 meshFile << "Deviation of Length %, sL = " << 100*sigmaLength/length << std::endl;
244 meshFile << "Max Length of edge, maxA = " << maxLength << std::endl;
245 meshFile << "Min Length of edge, minA = " << minLength << std::endl;
246 meshFile << std::endl;
247 meshFile << "Mean Angle per vertex, theta = " << angle << std::endl;
248 meshFile << "Deviation of Angle %, sTheta = " << fabs(100*sigmaAngle/angle) << std::endl;
249 meshFile << "Max Angle of edge, maxA = " << maxAngle << std::endl;
250 meshFile << "Min Angle of edge, minA = " << minAngle << std::endl;
251 meshFile << std::endl;
252 meshFile << "Mean number of neighbours, Nn = " << Nn << std::endl;
253 meshFile << "Deviation for number of Neighbours %, sNn = " << 100*sigmaNn/Nn << std::endl;
254 meshFile << "Number of 5 neighbour in %, Nn5 = " << 100*Nn5/Nv << std::endl;
255 meshFile << "Number of 6 neighbour in %, Nn6 = " << 100*Nn6/Nv << std::endl;
256 meshFile << "Number of 7 neighbour in %, Nn7 = " << 100*Nn7/Nv << std::endl;
257};
258
259template<typename T>
260void writeSurfaceMeshAsciiSTL(TriangularSurfaceMesh<T> const& mesh, std::string fname);
261
262
263}
264#include "meshMetrics.hh"
265
266#endif // MESH_METRICS_H
Definition meshMetrics.h:44
std::vector< plint > emanatingEdgeList
Definition meshMetrics.h:47
std::vector< Array< T, 3 > > vertexList
Definition meshMetrics.h:46
std::vector< Edge > edgeList
Definition meshMetrics.h:48
Definition meshMetrics.h:63
T angle
Definition meshMetrics.h:100
T Nn
Definition meshMetrics.h:99
T maxAngle
Definition meshMetrics.h:104
T getMinArea()
Definition meshMetrics.h:87
T getMeanLength()
Definition meshMetrics.h:77
T Nn7
Definition meshMetrics.h:99
hemo::Array< T, 3 > meanVertexPosition
Definition meshMetrics.h:101
void write()
Definition meshMetrics.h:71
TriangularSurfaceMesh< T > const & mesh
Definition meshMetrics.h:98
T getNumTriangles()
Definition meshMetrics.h:95
T Nt
Definition meshMetrics.h:99
T maxArea
Definition meshMetrics.h:104
T sigmaNn
Definition meshMetrics.h:102
T Nn5
Definition meshMetrics.h:99
T getMinLength()
Definition meshMetrics.h:79
TriangularSurfaceMesh< T > const & getMesh()
Definition meshMetrics.h:76
void set_dx(T dx_)
Definition meshMetrics.h:72
T sigmaArea
Definition meshMetrics.h:102
T getSurface()
Definition meshMetrics.h:90
T minNn
Definition meshMetrics.h:103
T dm
Definition meshMetrics.h:105
T getMeanAngle()
Definition meshMetrics.h:81
T getMinAngle()
Definition meshMetrics.h:83
hemo::Array< T, 3 > getMeanVertexPosition()
Definition meshMetrics.h:92
T dx
Definition meshMetrics.h:105
T sigmaAngle
Definition meshMetrics.h:102
T minLength
Definition meshMetrics.h:103
T getMaxLength()
Definition meshMetrics.h:78
void init()
Definition meshMetrics.h:127
MeshMetrics(MeshMetrics< T > const &rhs)
Definition meshMetrics.h:110
T getMeanArea()
Definition meshMetrics.h:85
T maxLength
Definition meshMetrics.h:104
T Nn6
Definition meshMetrics.h:99
T volume
Definition meshMetrics.h:100
void set_dxdtdm(T dx_, T dt_, T dm_)
Definition meshMetrics.h:75
T minArea
Definition meshMetrics.h:103
T getMaxAngle()
Definition meshMetrics.h:82
void set_dt(T dt_)
Definition meshMetrics.h:73
T getRadius()
Definition meshMetrics.h:89
T area
Definition meshMetrics.h:100
T getMaxArea()
Definition meshMetrics.h:86
T getNumVertices()
Definition meshMetrics.h:94
T sigmaLength
Definition meshMetrics.h:102
T length
Definition meshMetrics.h:100
T dt
Definition meshMetrics.h:105
T minAngle
Definition meshMetrics.h:103
void set_dm(T dm_)
Definition meshMetrics.h:74
T cellRadius
Definition meshMetrics.h:106
T maxNn
Definition meshMetrics.h:104
T Nv
Definition meshMetrics.h:99
T getVolume()
Definition meshMetrics.h:91
~MeshMetrics()
Definition meshMetrics.h:224
double T
Definition constant_defaults.h:118
long int plint
Definition constant_defaults.h:127
long unsigned int pluint
Definition constant_defaults.h:130
Definition meshGeneratingFunctions.cpp:28
void writeSurfaceMeshAsciiSTL(TriangularSurfaceMesh< T > const &mesh, std::string fname)
Definition meshMetrics.hh:83
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:52
Definition array.h:39