Itasca C++ Interface
Toggle main menu visibility
Loading...
Searching...
No Matches
hexahedron.h
1
#pragma once
2
3
#include "
base/src/cube.h
"
4
#include "
base/src/vect.h
"
5
6
// Assumptions: 1) Faces are planar; 2) face normals are oriented inward; Hexahedron is convex
7
// Class used to create a grid. This grid is generated by a user and used to import data (see function readDepletionGridFile
8
// Convex hexahedron. Expecting points to be added in the following order: clockwise from top left closest corner (top-southwest corner)
9
class
Hexahedron
10
{
11
public
:
12
Hexahedron():ext_(DCube::nothing()),vSum_(0.0) {}
13
void
addPoint(
const
DVect3 &v)
14
{
15
points_.push_back(v);
16
ext_ = ext_.expandToInclude(v);
17
vSum_ +=v;
18
}
19
const
std::vector<DVect3> &points()
const
{
return
points_; }
20
const
DCube &extent()
const
{
return
ext_; }
21
22
bool
isInConvex(DVect3
const
& point)
const
23
{
24
static
const
int
faceGpIndex[6][4] = {{4,7,3,0} ,
/* Hexahefron Face front */
25
{5,1,2,6} ,
/* back */
26
{4,0,1,5} ,
/* left */
27
{7,6,2,3} ,
/* rigth */
28
{0,3,2,1} ,
/* top */
29
{4,5,6,7}};
/* bottom */
30
31
assert(points_.size() == 8);
32
33
if
(ext_.isIn(point)==
false
)
return
false
;
34
35
for
(
int
i = 0; i < 6; ++i)
36
{
37
const
DVect3 &v0 = points_[faceGpIndex[i][0]];
38
const
DVect3 &v1 = points_[faceGpIndex[i][1]];
39
const
DVect3 &v2 = points_[faceGpIndex[i][2]];
40
41
DVect3 point2face = v0 - point;
// use an arbitrary point on face
42
// calculate face normal vector
43
const
DVect3 &dir1 = v1 - v0;
44
const
DVect3 &dir2 = v2 - v0;
45
const
DVect3 &nV = (dir1&dir2).unit();
// cross prodcut
46
47
const
double
d = point2face|nV;
// dot product of the normal face vector, face distance to the point
48
/*
49
d /= point2face.mag(); // for numeric stability
50
//static const double bound = -1e-16; // use 1e16 to exclude boundaries
51
if (d < bound)
52
*/
53
if
(d < 1e-16)
// negative dot prodcut indicates point outside
54
return
false
;
55
}
56
return
true
;
57
}
58
59
bool
isRegular()
const
60
{
61
assert(points_.size()==8);
62
DVect3 v1 = (points_[0]-points_[4]);
//.unit();
63
DVect3 v2 = (points_[0]-points_[1]);
//.unit();
64
DVect3 v3 = (points_[0]-points_[3]);
//.unit();
65
66
double
dotP = v1|v2;
67
if
(fabs(dotP) > 1e-14)
return
false
;
68
dotP = v1|v3;
69
if
(fabs(dotP) > 1e-14)
return
false
;
70
dotP = v2|v3;
71
if
(fabs(dotP) > 1e-14)
return
false
;
72
return
true
;
73
}
74
75
DVect3 geometricCenter()
const
76
{
77
int
nPoints =
to<int>
(points_.size());
78
if
(nPoints == 0)
return
DVect3(0.0);
79
return
vSum_/nPoints;
80
}
81
82
DVect3 maxEdges()
83
{
84
assert(points_.size() == 8);
85
DVect3 maxEdges(ext_.width(),ext_.height(),ext_.depth());
86
return
maxEdges;
87
}
88
89
private
:
90
std::vector<DVect3> points_;
91
DCube ext_;
92
DVect3 vSum_;
93
};
cube.h
Three dimensional extent aligned with cartesian axes.
to
constexpr D to(const T &t)
This template function serves as an alternative to static_cast<T>().
Definition
to.h:28
vect.h
2D and 3D vector utility classes.
common
base
src
hexahedron.h
Generated by
1.18.0