VPTissue Reference Manual
MeshGeometry.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "MeshGeometry.h"
21 
22 #include "bio/Cell.h"
23 #include "bio/Node.h"
24 #include "bio/Mesh.h"
25 #include "math/ChainHull.h"
26 
27 #include <memory>
28 #include <string>
29 #include <vector>
30 
31 using namespace std;
32 using namespace SimPT_Sim::Util;
33 
34 namespace SimPT_Sim {
35 
36 tuple<array<double, 3>, array<double, 3>> MeshGeometry::BoundingBox(shared_ptr<Mesh> mesh)
37 {
38  const auto& nodes = mesh->GetBoundaryPolygon()->GetNodes();
39  array<double, 3> lower_left = **(nodes.begin());
40  array<double, 3> upper_right(lower_left);
41 
42  for (auto const& node : nodes) {
43  array<double, 3> a(*node);
44  lower_left[0] = min(lower_left[0], a[0]);
45  lower_left[1] = min(lower_left[1], a[1]);
46  lower_left[2] = min(lower_left[2], a[2]);
47  upper_right[0] = max(upper_right[0], a[0]);
48  upper_right[1] = max(upper_right[1], a[1]);
49  upper_right[2] = max(upper_right[2], a[2]);
50  }
51  return make_tuple(lower_left, upper_right);
52 }
53 
54 tuple<double, double, double> MeshGeometry::Compactness(const Mesh* mesh)
55 {
56  // Calculate compactness using the convex hull of the cells
57  // We use Andrew's Monotone Chain Algorithm (see hull.cpp)
58 
59  // Step 1: Prepare data for 2D hull code: get boundary
60  std::vector<std::array<double, 2> > boundary;
61  const Cell* bp = mesh->GetBoundaryPolygon();
62  for (auto const& node : bp->GetNodes()) {
63  boundary.push_back({ {(*node)[0], (*node)[1]} });
64  }
65 
66  // Step 2: call 2D Hull code
67  std::vector<std::array<double, 2> > hull = ChainHull::Compute(boundary);
68 
69  // Step 3: calculate area and circumference of convex hull
70  double hull_area = 0.;
71  double hull_circumference = 0.;
72  for (unsigned int i = 0; i < hull.size() - 1; i++) {
73  hull_area += hull[i][0] * hull[i + 1][1] - hull[i + 1][0] * hull[i][1];
74  double s_dx = (hull[i + 1][0] - hull[i][0]);
75  double s_dy = (hull[i + 1][1] - hull[i][1]);
76  double l = sqrt(s_dx * s_dx + s_dy * s_dy);
77  hull_circumference += l;
78  }
79  hull_area /= 2.;
80 
81  // Step 4: get area of boundary polygon
82  const double boundary_pol_area = bp->GetArea();
83 
84  return make_tuple(boundary_pol_area / hull_area, hull_area, hull_circumference);
85 }
86 
87 } // namespace
STL namespace.
A cell contains walls and nodes.
Definition: Cell.h:48
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Interface for MeshGeometry.
Interface for ChainHull.
Namespace for the core simulator.
Interface for Cell.
const std::vector< Node * > & GetNodes() const
Access the nodes of cell's polygon.
Definition: Cell.h:79
Cell * GetBoundaryPolygon() const
Get the boundary polygon of the mesh.
Definition: Mesh.h:105
Interface for Node.
Structure of cells; key data structure.
Definition: Mesh.h:62
double GetArea() const
Return the area of the cell.
Definition: Cell.cpp:178
Interface for Mesh.