hemocell
Loading...
Searching...
No Matches
meshMetrics.hh
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_HH
25#define MESH_METRICS_HH
26
27#include "meshMetrics.h"
28
29namespace plb {
30
31/*
32 * Helper function, calculates the angle between -pi and pi.
33 * The edge is iVertex-jVertex.
34 */
35template <typename T>
36T calculateSignedAngle(TriangularSurfaceMesh<T> const & mesh, plint iVertex, plint jVertex, plint & kVertex,
37 plint & lVertex) {
38 hemo::Array<T, 3> x1 = mesh.getVertex(iVertex), x2({0., 0., 0.}), x3({0., 0., 0.}), x4({0., 0., 0.});
39
40 std::vector<plint> adjacentTriangles = mesh.getAdjacentTriangleIds(iVertex, jVertex);
41 plint iTriangle = adjacentTriangles[0], jTriangle = adjacentTriangles[1];
42 x3 = mesh.getVertex(jVertex);
43 T foundVertices = 0;
44 for (pluint id = 0; id < 3; ++id) {
45 kVertex = mesh.getVertexId(iTriangle, id);
46 if ((kVertex != iVertex) && (kVertex != jVertex)) {
47 x2 = mesh.getVertex(kVertex);
48 foundVertices += 1;
49 break;
50 }
51 }
52 for (pluint id = 0; id < 3; ++id) {
53 lVertex = mesh.getVertexId(jTriangle, id);
54 if ((lVertex != iVertex) && (lVertex != jVertex)) {
55 x4 = mesh.getVertex(lVertex);
56 foundVertices += 1;
57 break;
58 }
59 }
60 PLB_ASSERT(foundVertices == 2); //Assert if some particles are outside of the domain
61
62 hemo::Array<T, 3> V1 = mesh.computeTriangleNormal(iTriangle);
63 hemo::Array<T, 3> V2 = mesh.computeTriangleNormal(jTriangle);
64 T angle = angleBetweenVectors(V1, V2);
65 plint sign = dot(x2 - x1, V2) >= 0 ? 1 : -1;
66 if (sign <= 0) { angle = 2 * PI - angle; }
67 angle = (angle > PI) ? angle - 2 * PI : angle;
68 return angle;
69}
70
71
72/*
73 * * Helper function, calculates the angle between -pi and pi
74 * */
75template <typename T>
76T calculateSignedAngle(TriangularSurfaceMesh<T> const & mesh, plint iVertex, plint jVertex) {
77 plint kVertex, lVertex;
78 return calculateSignedAngle(mesh, iVertex, jVertex, kVertex, lVertex);
79}
80
81template <typename T>
82void writeSurfaceMeshAsciiSTL(TriangularSurfaceMesh<T> const & mesh, std::string fname) {
83 T dx = 1;
84 // Output only from one MPI process.
85
86 FILE * fp = fopen(fname.c_str(), "w");
87 PLB_ASSERT(fp != NULL);
88
89 char fmt1[64] = " facet normal ";
90 char fmt2[64] = " vertex ";
91 if (sizeof(T) == sizeof(long double)) {
92 strcat(fmt1, "% Le % Le % Le\n");
93 strcat(fmt2, "% Le % Le % Le\n");
94 } else if (sizeof(T) == sizeof(float) || sizeof(T) == sizeof(double)) {
95 strcat(fmt1, "% e % e % e\n");
96 strcat(fmt2, "% e % e % e\n");
97 } else {
98 PLB_ASSERT(false);
99 }
100
101 fprintf(fp, "solid surface\n");
102 for (plint i = 0; i < mesh.getNumTriangles(); i++) {
103 hemo::Array<T, 3> n = mesh.computeTriangleNormal(i);
105 fprintf(fp, fmt1, n[0], n[1], n[2]);
106 fprintf(fp, " outer loop\n");
107 v = dx * mesh.getVertex(i, 0);
108 fprintf(fp, fmt2, v[0], v[1], v[2]);
109 v = dx * mesh.getVertex(i, 1);
110 fprintf(fp, fmt2, v[0], v[1], v[2]);
111 v = dx * mesh.getVertex(i, 2);
112 fprintf(fp, fmt2, v[0], v[1], v[2]);
113 fprintf(fp, " endloop\n");
114 fprintf(fp, " endfacet\n");
115 }
116 fprintf(fp, "endsolid surface\n");
117
118 fclose(fp);
119}
120
121}
122#endif // MESH_METRICS_HH
#define PI
Definition constant_defaults.h:144
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
Definition array.h:40