Commit b6e308ec authored by Mike Kremer's avatar Mike Kremer

Added function to add hexahedral cells via incident vertices.

Also added a bunch of unit tests.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@176 66977474-1d4b-4f09-8fe9-267525286df2
parent bf1fb456
......@@ -239,6 +239,126 @@ HexahedralMeshTopologyKernel::add_cell(const std::vector<HalfFaceHandle>& _halff
//========================================================================================
CellHandle
HexahedralMeshTopologyKernel::add_cell(const std::vector<VertexHandle>& _vertices) {
assert(_vertices.size() == 8);
if(!TopologyKernel::has_full_bottom_up_adjacencies()) {
std::cerr << "Error: This function needs bottom-up adjacencies to be enabled!" << std::endl;
return CellHandle(-1);
}
if(_vertices.size() != 8) {
std::cerr << "The number of vertices is not eight!" << std::endl;
return CellHandle(-1);
}
HalfFaceHandle hf0, hf1, hf2, hf3, hf4, hf5, hf6, hf7;
std::vector<VertexHandle> vs;
// Half-face XF
vs.push_back(_vertices[2]);
vs.push_back(_vertices[1]);
vs.push_back(_vertices[0]);
hf0 = TopologyKernel::halfface(vs); vs.clear();
// Half-face XB
vs.push_back(_vertices[6]);
vs.push_back(_vertices[5]);
vs.push_back(_vertices[4]);
hf1 = TopologyKernel::halfface(vs); vs.clear();
// Half-face YF
vs.push_back(_vertices[1]);
vs.push_back(_vertices[2]);
vs.push_back(_vertices[6]);
hf2 = TopologyKernel::halfface(vs); vs.clear();
// Half-face YB
vs.push_back(_vertices[5]);
vs.push_back(_vertices[3]);
vs.push_back(_vertices[0]);
hf3 = TopologyKernel::halfface(vs); vs.clear();
// Half-face ZF
vs.push_back(_vertices[7]);
vs.push_back(_vertices[4]);
vs.push_back(_vertices[0]);
hf4 = TopologyKernel::halfface(vs); vs.clear();
// Half-face ZB
vs.push_back(_vertices[3]);
vs.push_back(_vertices[5]);
vs.push_back(_vertices[6]);
hf5 = TopologyKernel::halfface(vs);
if(!hf0.is_valid()) {
vs.clear();
vs.push_back(_vertices[3]); vs.push_back(_vertices[2]);
vs.push_back(_vertices[1]); vs.push_back(_vertices[0]);
FaceHandle fh = TopologyKernel::add_face(vs);
hf0 = halfface_handle(fh, 0);
}
if(!hf1.is_valid()) {
vs.clear();
vs.push_back(_vertices[7]); vs.push_back(_vertices[6]);
vs.push_back(_vertices[5]); vs.push_back(_vertices[4]);
FaceHandle fh = TopologyKernel::add_face(vs);
hf1 = halfface_handle(fh, 0);
}
if(!hf2.is_valid()) {
vs.clear();
vs.push_back(_vertices[1]); vs.push_back(_vertices[2]);
vs.push_back(_vertices[6]); vs.push_back(_vertices[7]);
FaceHandle fh = TopologyKernel::add_face(vs);
hf2 = halfface_handle(fh, 0);
}
if(!hf3.is_valid()) {
vs.clear();
vs.push_back(_vertices[4]); vs.push_back(_vertices[5]);
vs.push_back(_vertices[3]); vs.push_back(_vertices[0]);
FaceHandle fh = TopologyKernel::add_face(vs);
hf3 = halfface_handle(fh, 0);
}
if(!hf4.is_valid()) {
vs.clear();
vs.push_back(_vertices[1]); vs.push_back(_vertices[7]);
vs.push_back(_vertices[4]); vs.push_back(_vertices[0]);
FaceHandle fh = TopologyKernel::add_face(vs);
hf4 = halfface_handle(fh, 0);
}
if(!hf5.is_valid()) {
vs.clear();
vs.push_back(_vertices[2]); vs.push_back(_vertices[3]);
vs.push_back(_vertices[5]); vs.push_back(_vertices[6]);
FaceHandle fh = TopologyKernel::add_face(vs);
hf5 = halfface_handle(fh, 0);
}
assert(hf0.valid()); assert(hf1.valid()); assert(hf2.valid());
assert(hf3.valid()); assert(hf4.valid()); assert(hf5.valid());
std::vector<HalfFaceHandle> hfs;
hfs.push_back(hf0); hfs.push_back(hf1); hfs.push_back(hf2);
hfs.push_back(hf3); hfs.push_back(hf4); hfs.push_back(hf5);
return TopologyKernel::add_cell(hfs,false);
}
//========================================================================================
const HalfFaceHandle&
HexahedralMeshTopologyKernel::get_adjacent_halfface(const HalfFaceHandle& _hfh, const HalfEdgeHandle& _heh,
......
......@@ -112,6 +112,27 @@ public:
virtual CellHandle add_cell(const std::vector<HalfFaceHandle>& _halffaces, bool _topologyCheck = true,
bool _reorderFaces = false);
/** \brief Add cell via incident vertices
*
* Test whether all required faces are already defined
* and, if not, create them.
* Give vertices in the following order:
*
* 5-------6
* /| /|
* / | / |
* 3-------2 |
* | 4----|--7
* | / | /
* |/ |/
* 0-------1
*
* @param: _vertices A list of vertices in the correct order
*
* @return The new hexahedron's cell handle
*/
CellHandle add_cell(const std::vector<VertexHandle>& _vertices);
// ======================= Specialized Iterators =============================
friend class CellSheetCellIter;
......
......@@ -1137,4 +1137,79 @@ TEST_F(HexahedralMeshBase, HalfFaceFetchFunction2) {
EXPECT_EQ(HexahedralMesh::InvalidHalfFaceHandle, hfInv1);
}
TEST_F(HexahedralMeshBase, AddCellViaVerticesFunction1) {
generateHexahedralMesh(mesh_);
StatusAttrib status(mesh_);
status[FaceHandle(0)].set_deleted(true);
status.garbage_collection(false);
EXPECT_EQ(1u, mesh_.n_cells());
EXPECT_EQ(10u, mesh_.n_faces());
EXPECT_EQ(20u, mesh_.n_edges());
EXPECT_EQ(12u, mesh_.n_vertices());
std::vector<VertexHandle> vs;
vs.push_back(VertexHandle(0));
vs.push_back(VertexHandle(1));
vs.push_back(VertexHandle(2));
vs.push_back(VertexHandle(3));
vs.push_back(VertexHandle(4));
vs.push_back(VertexHandle(7));
vs.push_back(VertexHandle(6));
vs.push_back(VertexHandle(5));
CellHandle ch = mesh_.add_cell(vs);
EXPECT_NE(HexahedralMesh::InvalidCellHandle, ch);
EXPECT_EQ(2u, mesh_.n_cells());
EXPECT_EQ(11u, mesh_.n_faces());
EXPECT_EQ(20u, mesh_.n_edges());
EXPECT_EQ(12u, mesh_.n_vertices());
}
TEST_F(HexahedralMeshBase, AddCellViaVerticesFunction2) {
generateHexahedralMesh(mesh_);
StatusAttrib status(mesh_);
status[FaceHandle(0)].set_deleted(true);
status.garbage_collection(true);
EXPECT_EQ(1u, mesh_.n_cells());
EXPECT_EQ(6u, mesh_.n_faces());
EXPECT_EQ(12u, mesh_.n_edges());
EXPECT_EQ(8u, mesh_.n_vertices());
VertexHandle v0 = mesh_.add_vertex(Vec3d(0.0, 0.0, 0.0));
VertexHandle v1 = mesh_.add_vertex(Vec3d(1.0, 0.0, 0.0));
VertexHandle v2 = mesh_.add_vertex(Vec3d(1.0, 1.0, 0.0));
VertexHandle v3 = mesh_.add_vertex(Vec3d(0.0, 1.0, 0.0));
std::vector<VertexHandle> vs;
vs.push_back(v0);
vs.push_back(v1);
vs.push_back(v2);
vs.push_back(v3);
vs.push_back(VertexHandle(0));
vs.push_back(VertexHandle(3));
vs.push_back(VertexHandle(2));
vs.push_back(VertexHandle(1));
CellHandle ch = mesh_.add_cell(vs);
EXPECT_NE(HexahedralMesh::InvalidCellHandle, ch);
EXPECT_EQ(2u, mesh_.n_cells());
EXPECT_EQ(11u, mesh_.n_faces());
EXPECT_EQ(20u, mesh_.n_edges());
EXPECT_EQ(12u, mesh_.n_vertices());
}
#endif // INCLUDE GUARD
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment