Commit 944dbb4a authored by Max Lyon's avatar Max Lyon

Added Tetrahedral Mesh classes

parent 9de4e5ef
/*===========================================================================*\
* *
* OpenVolumeMesh *
* Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
* www.openvolumemesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenVolumeMesh. *
* *
* OpenVolumeMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenVolumeMesh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenVolumeMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#ifndef TETRAHEDRALGEOMETRYKERNEL_HH_
#define TETRAHEDRALGEOMETRYKERNEL_HH_
#include <cassert>
#include <iostream>
#include "../Geometry/VectorT.hh"
#include "../Core/GeometryKernel.hh"
#include "TetrahedralMeshTopologyKernel.hh"
namespace OpenVolumeMesh {
template <class VecT, class TopologyKernelT = TetrahedralMeshTopologyKernel>
class TetrahedralGeometryKernel : public GeometryKernel<VecT, TopologyKernelT> {
public:
typedef VecT PointT;
typedef TopologyKernelT KernelT;
typedef GeometryKernel<VecT, TopologyKernelT> ParentT;
/// Constructor
TetrahedralGeometryKernel() {}
/// Destructor
~TetrahedralGeometryKernel() {}
VertexHandle split_edge(HalfEdgeHandle heh, double alpha = 0.5)
{
OpenVolumeMeshEdge e = TopologyKernelT::halfedge(heh);
PointT newPos = alpha*ParentT::vertex(e.from_vertex()) + (1.0-alpha)*ParentT::vertex(e.to_vertex());
VertexHandle splitVertex = ParentT::add_vertex(newPos);
TopologyKernelT::split_edge(heh, splitVertex);
return splitVertex;
}
VertexHandle split_edge(EdgeHandle eh)
{
return split_edge(TopologyKernelT::halfedge_handle(eh,0));
}
VertexHandle split_face(FaceHandle fh, PointT pos)
{
VertexHandle splitVertex = ParentT::add_vertex(pos);
TopologyKernelT::split_face(fh, splitVertex);
return splitVertex;
}
VertexHandle split_face(FaceHandle fh)
{
VertexHandle splitVertex = ParentT::add_vertex(ParentT::barycenter(fh));
TopologyKernelT::split_face(fh, splitVertex);
return splitVertex;
}
protected:
};
} // Namespace OpenVolumeMesh
#endif /* TETRAHEDRALGEOMETRYKERNEL_HH_ */
/*===========================================================================*\
* *
* OpenVolumeMesh *
* Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
* www.openvolumemesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenVolumeMesh. *
* *
* OpenVolumeMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenVolumeMesh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenVolumeMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#ifndef TETRAHEDRALMESH_HH_
#define TETRAHEDRALMESH_HH_
#include "TetrahedralMeshTopologyKernel.hh"
#include "../Core/GeometryKernel.hh"
namespace OpenVolumeMesh {
/*
* Predefines for most common mesh types
*/
typedef GeometryKernel<Geometry::Vec2i, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV2i;
typedef GeometryKernel<Geometry::Vec2ui, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV2ui;
typedef GeometryKernel<Geometry::Vec2f, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV2f;
typedef GeometryKernel<Geometry::Vec2d, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV2d;
typedef GeometryKernel<Geometry::Vec2c, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV2c;
typedef GeometryKernel<Geometry::Vec2uc, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV2uc;
typedef GeometryKernel<Geometry::Vec3i, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV3i;
typedef GeometryKernel<Geometry::Vec3ui, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV3ui;
typedef GeometryKernel<Geometry::Vec3f, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV3f;
typedef GeometryKernel<Geometry::Vec3d, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV3d;
typedef GeometryKernel<Geometry::Vec3c, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV3c;
typedef GeometryKernel<Geometry::Vec3uc, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV3uc;
typedef GeometryKernel<Geometry::Vec4i, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV4i;
typedef GeometryKernel<Geometry::Vec4ui, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV4ui;
typedef GeometryKernel<Geometry::Vec4f, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV4f;
typedef GeometryKernel<Geometry::Vec4d, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV4d;
typedef GeometryKernel<Geometry::Vec4c, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV4c;
typedef GeometryKernel<Geometry::Vec4uc, TetrahedralMeshTopologyKernel> GeometricTetrahedralMeshV4uc;
typedef TetrahedralMeshTopologyKernel TopologicTetrahedralMesh;
} // Namespace OpenVolumeMesh
#endif /* TETRAHEDRALMESH_HH_ */
/*===========================================================================*\
* *
* OpenVolumeMesh *
* Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
* www.openvolumemesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenVolumeMesh. *
* *
* OpenVolumeMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenVolumeMesh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenVolumeMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#include <set>
#include "TetrahedralMeshIterators.hh"
#include "TetrahedralMeshTopologyKernel.hh"
#include "../Core/Iterators.hh"
namespace OpenVolumeMesh {
//================================================================================================
// TetVertexIter
//================================================================================================
TetVertexIter::TetVertexIter(const CellHandle& _ref_h,
const TetrahedralMeshTopologyKernel* _mesh, int _max_laps) :
BaseIter(_mesh, _ref_h, _max_laps) {
assert(_ref_h.is_valid());
assert(_mesh->cell(_ref_h).halffaces().size() == 4);
// Get first half-face
HalfFaceHandle curHF = *_mesh->cell(_ref_h).halffaces().begin();
assert(curHF.is_valid());
// Get first half-edge
assert(_mesh->halfface(curHF).halfedges().size() == 3);
HalfEdgeHandle curHE = *_mesh->halfface(curHF).halfedges().begin();
assert(curHE.is_valid());
vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
curHF = _mesh->adjacent_halfface_in_cell(curHF, curHE);
curHE = _mesh->opposite_halfedge_handle(curHE);
curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
cur_index_ = 0;
BaseIter::valid(vertices_.size() > 0);
if(BaseIter::valid()) {
BaseIter::cur_handle(vertices_[cur_index_]);
}
}
TetVertexIter& TetVertexIter::operator--() {
if (cur_index_ == 0) {
cur_index_ = vertices_.size() - 1;
--lap_;
if (lap_ < 0)
BaseIter::valid(false);
} else {
--cur_index_;
}
BaseIter::cur_handle(vertices_[cur_index_]);
return *this;
}
TetVertexIter& TetVertexIter::operator++() {
++cur_index_;
if(cur_index_ == vertices_.size()) {
cur_index_ = 0;
++lap_;
if (lap_ >= max_laps_)
BaseIter::valid(false);
}
BaseIter::cur_handle(vertices_[cur_index_]);
return *this;
}
} // Namespace OpenVolumeMesh
/*===========================================================================*\
* *
* OpenVolumeMesh *
* Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
* www.openvolumemesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenVolumeMesh. *
* *
* OpenVolumeMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenVolumeMesh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenVolumeMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#ifndef TETRAHEDRALMESHITERATORS_HH
#define TETRAHEDRALMESHITERATORS_HH
#include "../Core/Iterators.hh"
namespace OpenVolumeMesh {
class TetrahedralMeshTopologyKernel;
/** \brief Iterate over all vertices of a hexahedron in a specific order
*
* Vertices are addressed in the following order: vertices of one halfface in ccw order, then the remaining vertex
*
*/
class TetVertexIter : public BaseCirculator<CellHandle,
VertexHandle> {
private:
typedef BaseCirculator<CellHandle,
VertexHandle> BaseIter;
public:
TetVertexIter(const CellHandle& _ref_h,
const TetrahedralMeshTopologyKernel* _mesh,
int _max_laps = 1);
// Post increment/decrement operator
TetVertexIter operator++(int) {
TetVertexIter cpy = *this;
++(*this);
return cpy;
}
TetVertexIter operator--(int) {
TetVertexIter cpy = *this;
--(*this);
return cpy;
}
TetVertexIter operator+(int _n) {
TetVertexIter cpy = *this;
for(int i = 0; i < _n; ++i) {
++cpy;
}
return cpy;
}
TetVertexIter operator-(int _n) {
TetVertexIter cpy = *this;
for(int i = 0; i < _n; ++i) {
--cpy;
}
return cpy;
}
TetVertexIter& operator+=(int _n) {
for(int i = 0; i < _n; ++i) {
++(*this);
}
return *this;
}
TetVertexIter& operator-=(int _n) {
for(int i = 0; i < _n; ++i) {
--(*this);
}
return *this;
}
TetVertexIter& operator++();
TetVertexIter& operator--();
private:
std::vector<VertexHandle> vertices_;
size_t cur_index_;
};
} // Namespace OpenVolumeMesh
#endif /* TETRAHEDRALMESHITERATORS_HH */
This diff is collapsed.
/*===========================================================================*\
* *
* OpenVolumeMesh *
* Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
* www.openvolumemesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenVolumeMesh. *
* *
* OpenVolumeMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenVolumeMesh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenVolumeMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#ifndef TETRAHEDRALMESHTOPOLOGYKERNEL_HH
#define TETRAHEDRALMESHTOPOLOGYKERNEL_HH
#ifndef NDEBUG
#include <iostream>
#endif
#include <set>
#include "../Core/TopologyKernel.hh"
#include "TetrahedralMeshIterators.hh"
namespace OpenVolumeMesh {
/**
* \class TetrahedralMeshTopologyKernel
*
* \brief A data structure based on PolyhedralMesh with specializations for tetrahedra.
*
*/
class TetrahedralMeshTopologyKernel : public TopologyKernel {
public:
// Constructor
TetrahedralMeshTopologyKernel();
// Destructor
~TetrahedralMeshTopologyKernel();
// Overridden function
virtual FaceHandle add_face(const std::vector<HalfEdgeHandle>& _halfedges, bool _topologyCheck = false);
// Overridden function
virtual FaceHandle add_face(const std::vector<VertexHandle>& _vertices);
// Overridden function
virtual CellHandle add_cell(const std::vector<HalfFaceHandle>& _halffaces, bool _topologyCheck = false);
CellHandle add_cell(const std::vector<VertexHandle>& _vertices, bool _topologyCheck = false);
CellHandle add_cell(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2, VertexHandle _vh3, bool _topologyCheck = false);
HalfFaceHandle add_halfface(const std::vector<HalfEdgeHandle>& _halfedges, bool _topologyCheck = false);
HalfFaceHandle add_halfface(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2, bool _topologyCheck = false);
HalfEdgeHandle add_halfedge(const VertexHandle& _fromVertex, const VertexHandle& _toVertex);
std::vector<VertexHandle> get_cell_vertices(CellHandle ch) const;
std::vector<VertexHandle> get_cell_vertices(CellHandle ch, VertexHandle vh) const;
std::vector<VertexHandle> get_cell_vertices(HalfFaceHandle hfh) const;
std::vector<VertexHandle> get_cell_vertices(HalfFaceHandle hfh, HalfEdgeHandle heh) const;
std::vector<VertexHandle> get_halfface_vertices(HalfFaceHandle hfh) const;
std::vector<VertexHandle> get_halfface_vertices(HalfFaceHandle hfh, VertexHandle vh) const;
std::vector<VertexHandle> get_halfface_vertices(HalfFaceHandle hfh, HalfEdgeHandle heh) const;
VertexHandle collapse_edge(HalfEdgeHandle _heh);
protected:
void split_edge(HalfEdgeHandle _heh, VertexHandle _vh);
void split_face(FaceHandle _fh, VertexHandle _vh);
public:
// ======================= Specialized Iterators =============================
friend class TetVertexIter;
typedef class TetVertexIter TetVertexIter;
TetVertexIter tv_iter(const CellHandle& _ref_h, int _max_laps = 1) const {
return TetVertexIter(_ref_h, this, _max_laps);
}
std::pair<TetVertexIter,TetVertexIter> tet_vertices(const CellHandle& _ref_h, int _max_laps = 1) const {
TetVertexIter begin = tv_iter(_ref_h, _max_laps);
TetVertexIter end = make_end_circulator(begin);
return std::make_pair(begin, end);
}
private:
// void replaceHalfFace(CellHandle ch, HalfFaceHandle hf_del, HalfFaceHandle hf_ins);
// void replaceHalfEdge(HalfFaceHandle hfh, HalfEdgeHandle he_del, HalfEdgeHandle he_ins);
template <typename PropIterator, typename Handle>
void swapPropertyElements(PropIterator begin, PropIterator end, Handle source, Handle destination)
{
PropIterator p_iter = begin;
for (; p_iter != end; ++p_iter)
(*p_iter)->swap_elements(source, destination);
}
};
} // Namespace OpenVolumeMesh
#endif /* TETRAHEDRALMESHTOPOLOGYKERNEL_HH */
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