https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Functions
OrientedBoundingBoxTest.C File Reference

Go to the source code of this file.

Functions

 TEST (OrientedBoundingBoxTest, WriteMeshBox3D)
 
 TEST (OrientedBoundingBoxTest, WriteMeshBox2D)
 
 TEST (OrientedBoundingBoxTest, WriteRay)
 
 TEST (OrientedBoundingBoxTest, QueryApiAxisAligned)
 
 TEST (OrientedBoundingBoxTest, QueryApiRotated)
 
 TEST (OrientedBoundingBoxTest, DefaultConstructed)
 

Function Documentation

◆ TEST() [1/6]

TEST ( OrientedBoundingBoxTest  ,
DefaultConstructed   
)

Definition at line 228 of file OrientedBoundingBoxTest.C.

229{
231 EXPECT_NEAR(empty.getMinimalCorner().norm(), 0.0, 1e-12);
232 EXPECT_NEAR(empty.getMaximalCorner().norm(), 0.0, 1e-12);
233 EXPECT_NEAR(empty.centroid().norm(), 0.0, 1e-12);
234}
Point getMinimalCorner() const
Point getMaximalCorner() const
Point centroid() const

◆ TEST() [2/6]

TEST ( OrientedBoundingBoxTest  ,
QueryApiAxisAligned   
)

Definition at line 168 of file OrientedBoundingBoxTest.C.

169{
170 const Point origin(0.0, 0.0, 0.0);
171 const Point d0(1.0, 0.0, 0.0), d1(0.0, 1.0, 0.0), d2(0.0, 0.0, 1.0);
172 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0;
173 const std::vector<std::pair<Point, Point>> axis_pairs{
174 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
175 OrientedBoundingBox obb(axis_pairs);
176
177 EXPECT_NEAR((obb.getMinimalCorner() - origin).norm(), 0.0, 1e-12);
178 EXPECT_NEAR((obb.getMaximalCorner() - Point(2.0, 3.0, 1.0)).norm(), 0.0, 1e-12);
179 EXPECT_NEAR((obb.centroid() - Point(1.0, 1.5, 0.5)).norm(), 0.0, 1e-12);
180
181 EXPECT_NEAR((obb.getAxisDirection(0) - d0).norm(), 0.0, 1e-12);
182 EXPECT_NEAR((obb.getAxisDirection(1) - d1).norm(), 0.0, 1e-12);
183 EXPECT_NEAR((obb.getAxisDirection(2) - d2).norm(), 0.0, 1e-12);
184 EXPECT_NEAR(obb.getAxisLength(0), l0, 1e-12);
185 EXPECT_NEAR(obb.getAxisLength(1), l1, 1e-12);
186 EXPECT_NEAR(obb.getAxisLength(2), l2, 1e-12);
187
188 EXPECT_TRUE(obb.contains(Point(1.0, 1.5, 0.5))); // interior
189 EXPECT_TRUE(obb.contains(origin)); // minimal corner (on boundary)
190 EXPECT_TRUE(obb.contains(Point(2.0, 3.0, 1.0))); // maximal corner
191 EXPECT_FALSE(obb.contains(Point(2.5, 1.5, 0.5))); // beyond axis-0 length
192 EXPECT_FALSE(obb.contains(Point(1.0, -0.1, 0.5))); // below axis-1 origin
193
194 EXPECT_NEAR(obb.getProjectedLength(Point(1.0, 1.5, 0.5), 0), 1.0, 1e-12);
195 EXPECT_NEAR(obb.getProjectedLength(Point(1.0, 1.5, 0.5), 1), 1.5, 1e-12);
196 EXPECT_NEAR(obb.getProjectedLength(Point(1.0, 1.5, 0.5), 2), 0.5, 1e-12);
197}
auto norm(const T &a)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ TEST() [3/6]

TEST ( OrientedBoundingBoxTest  ,
QueryApiRotated   
)

Definition at line 201 of file OrientedBoundingBoxTest.C.

202{
203 const Real s = 1.0 / std::sqrt(2.0);
204 const Point origin(1.0, 2.0, 3.0);
205 const Point d0(s, s, 0.0), d1(-s, s, 0.0), d2(0.0, 0.0, 1.0);
206 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0;
207 const std::vector<std::pair<Point, Point>> axis_pairs{
208 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
209 OrientedBoundingBox obb(axis_pairs);
210
211 EXPECT_NEAR((obb.getAxisDirection(0) - d0).norm(), 0.0, 1e-12);
212 EXPECT_NEAR((obb.getAxisDirection(1) - d1).norm(), 0.0, 1e-12);
213
214 // A point at box-local coordinates (a, b, c) maps to origin + a*d0 + b*d1 + c*d2.
215 const Point inside = origin + 1.5 * d0 + 2.0 * d1 + 0.5 * d2;
216 EXPECT_NEAR(obb.getProjectedLength(inside, 0), 1.5, 1e-12);
217 EXPECT_NEAR(obb.getProjectedLength(inside, 1), 2.0, 1e-12);
218 EXPECT_NEAR(obb.getProjectedLength(inside, 2), 0.5, 1e-12);
219 EXPECT_TRUE(obb.contains(inside));
220
221 const Point outside = origin + 2.5 * d0 + 1.0 * d1 + 0.5 * d2; // 2.5 > l0
222 EXPECT_NEAR(obb.getProjectedLength(outside, 0), 2.5, 1e-12);
223 EXPECT_FALSE(obb.contains(outside));
224}

◆ TEST() [4/6]

TEST ( OrientedBoundingBoxTest  ,
WriteMeshBox2D   
)

Definition at line 90 of file OrientedBoundingBoxTest.C.

91{
92 libMesh::Parallel::Communicator comm(MPI_COMM_SELF);
93 const Real tol = 1e-8;
94
95 const Real s = 1.0 / std::sqrt(2.0);
96 const Point origin(5.0, 6.0, 0.0);
97 const Point d0(s, s, 0.0), d1(-s, s, 0.0);
98 const Real l0 = 2.0, l1 = 3.0;
99
100 const std::vector<std::pair<Point, Point>> axis_pairs{{origin, origin + l0 * d0},
101 {origin, origin + l1 * d1}};
102 OrientedBoundingBox obb(axis_pairs);
103
104 const std::string file = "oriented_bounding_box_test_2d.e";
105 obb.writeMesh(file, comm);
106
107 ReplicatedMesh mesh(comm);
108 mesh.read(file);
109
110 EXPECT_EQ(mesh.n_nodes(), 4u);
111 EXPECT_EQ(mesh.n_elem(), 1u);
112 for (const auto * elem : mesh.active_element_ptr_range())
113 EXPECT_EQ(elem->type(), QUAD4);
114
115 const std::vector<Point> nodes = nodeLocations(mesh);
116 for (unsigned int mask = 0; mask < 4u; ++mask)
117 {
118 Point corner = origin;
119 if (mask & 1u)
120 corner += l0 * d0;
121 if (mask & 2u)
122 corner += l1 * d1;
123 EXPECT_TRUE(containsPoint(nodes, corner, tol)) << "missing corner, mask=" << mask;
124 }
125
126 std::remove(file.c_str());
127}
const double tol
MeshBase & mesh

◆ TEST() [5/6]

TEST ( OrientedBoundingBoxTest  ,
WriteMeshBox3D   
)

Definition at line 47 of file OrientedBoundingBoxTest.C.

48{
49 libMesh::Parallel::Communicator comm(MPI_COMM_SELF);
50 const Real tol = 1e-8;
51
52 // Orthonormal basis rotated 45 deg in the xy-plane, z unchanged.
53 const Real s = 1.0 / std::sqrt(2.0);
54 const Point origin(10.0, 20.0, 30.0);
55 const Point d0(s, s, 0.0), d1(-s, s, 0.0), d2(0.0, 0.0, 1.0);
56 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0;
57
58 const std::vector<std::pair<Point, Point>> axis_pairs{
59 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
60 OrientedBoundingBox obb(axis_pairs);
61
62 const std::string file = "oriented_bounding_box_test_3d.e";
63 obb.writeMesh(file, comm);
64
65 ReplicatedMesh mesh(comm);
66 mesh.read(file);
67
68 EXPECT_EQ(mesh.n_nodes(), 8u);
69 EXPECT_EQ(mesh.n_elem(), 1u);
70 for (const auto * elem : mesh.active_element_ptr_range())
71 EXPECT_EQ(elem->type(), HEX8);
72
73 const std::vector<Point> nodes = nodeLocations(mesh);
74 for (unsigned int mask = 0; mask < 8u; ++mask)
75 {
76 Point corner = origin;
77 if (mask & 1u)
78 corner += l0 * d0;
79 if (mask & 2u)
80 corner += l1 * d1;
81 if (mask & 4u)
82 corner += l2 * d2;
83 EXPECT_TRUE(containsPoint(nodes, corner, tol)) << "missing corner, mask=" << mask;
84 }
85
86 std::remove(file.c_str());
87}

◆ TEST() [6/6]

TEST ( OrientedBoundingBoxTest  ,
WriteRay   
)

Definition at line 130 of file OrientedBoundingBoxTest.C.

131{
132 libMesh::Parallel::Communicator comm(MPI_COMM_SELF);
133 const Real tol = 1e-8;
134
135 const Real s = 1.0 / std::sqrt(2.0);
136 const Point origin(0.0, 0.0, 0.0);
137 const Point d0(s, s, 0.0), d1(-s, s, 0.0), d2(0.0, 0.0, 1.0);
138 const Real l0 = 2.0, l1 = 3.0, l2 = 1.0; // shortest axis is axis 2
139
140 const std::vector<std::pair<Point, Point>> axis_pairs{
141 {origin, origin + l0 * d0}, {origin, origin + l1 * d1}, {origin, origin + l2 * d2}};
142 OrientedBoundingBox obb(axis_pairs);
143
144 const std::string file = "oriented_bounding_box_test_ray.e";
145 obb.writeRayAlongShortestAxis(file, comm);
146
147 ReplicatedMesh mesh(comm);
148 mesh.read(file);
149
150 EXPECT_EQ(mesh.n_nodes(), 2u);
151 EXPECT_EQ(mesh.n_elem(), 1u);
152 for (const auto * elem : mesh.active_element_ptr_range())
153 EXPECT_EQ(elem->type(), EDGE2);
154
155 // Ray starts at the face centre orthogonal to the shortest axis and spans it.
156 const Point start = origin + 0.5 * l0 * d0 + 0.5 * l1 * d1;
157 const Point end = start + l2 * d2;
158
159 const std::vector<Point> nodes = nodeLocations(mesh);
160 EXPECT_TRUE(containsPoint(nodes, start, tol));
161 EXPECT_TRUE(containsPoint(nodes, end, tol));
162
163 std::remove(file.c_str());
164}