Commit 304b29b4 authored by Mike Kremer's avatar Mike Kremer

Introduced some performance improvements.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@186 66977474-1d4b-4f09-8fe9-267525286df2
parent e12840c0
......@@ -42,6 +42,7 @@
#include <iostream>
#include <set>
#include <algorithm>
#include "Iterators.hh"
#include "TopologyKernel.hh"
......@@ -322,10 +323,14 @@ BaseIter(_mesh, _ref_h) {
for(; hf_iter != BaseIter::mesh()->cell(_ref_h).halffaces().end(); ++hf_iter) {
std::vector<HalfEdgeHandle> hes = BaseIter::mesh()->halfface(*hf_iter).halfedges();
for(std::vector<HalfEdgeHandle>::const_iterator he_iter = hes.begin(); he_iter != hes.end(); ++he_iter) {
incident_vertices_.insert(BaseIter::mesh()->halfedge(*he_iter).to_vertex());
incident_vertices_.push_back(BaseIter::mesh()->halfedge(*he_iter).to_vertex());
}
}
// Remove all duplcate entries
std::sort(incident_vertices_.begin(), incident_vertices_.end());
incident_vertices_.resize(std::unique(incident_vertices_.begin(), incident_vertices_.end()) - incident_vertices_.begin());
v_iter_ = incident_vertices_.begin();
BaseIter::valid(v_iter_ != incident_vertices_.end());
......
......@@ -433,8 +433,8 @@ public:
CellVertexIter& operator--();
private:
std::set<VertexHandle> incident_vertices_;
std::set<VertexHandle>::const_iterator v_iter_;
std::vector<VertexHandle> incident_vertices_;
std::vector<VertexHandle>::const_iterator v_iter_;
};
//===========================================================================
......
......@@ -91,19 +91,24 @@ VertexHandle TopologyKernel::add_vertex() {
/// Add edge
EdgeHandle TopologyKernel::add_edge(const VertexHandle& _fromVertex,
const VertexHandle& _toVertex) {
const VertexHandle& _toVertex,
bool _allowDuplicates) {
#ifndef NDEBUG
if((unsigned int)_fromVertex.idx() >= n_vertices() || (unsigned int)_toVertex.idx() >= n_vertices()) {
std::cerr << "Vertex handle is out of bounds!" << std::endl;
return InvalidEdgeHandle;
}
#endif
// Test if edge does not exist, yet
for(unsigned int i = 0; i < n_edges_; ++i) {
if(edge(EdgeHandle(i)).from_vertex() == _fromVertex && edge(EdgeHandle(i)).to_vertex() == _toVertex) {
return EdgeHandle(i);
} else if(edge(EdgeHandle(i)).from_vertex() == _toVertex && edge(EdgeHandle(i)).to_vertex() == _fromVertex) {
return EdgeHandle(i);
if(!_allowDuplicates) {
for(unsigned int i = 0; i < n_edges_; ++i) {
if(edge(EdgeHandle(i)).from_vertex() == _fromVertex && edge(EdgeHandle(i)).to_vertex() == _toVertex) {
return EdgeHandle(i);
} else if(edge(EdgeHandle(i)).from_vertex() == _toVertex && edge(EdgeHandle(i)).to_vertex() == _fromVertex) {
return EdgeHandle(i);
}
}
}
......@@ -141,6 +146,7 @@ EdgeHandle TopologyKernel::add_edge(const VertexHandle& _fromVertex,
/// Add face via incident edges
FaceHandle TopologyKernel::add_face(const std::vector<HalfEdgeHandle>& _halfedges, bool _topologyCheck) {
#ifndef NDEBUG
// Test if all edges are valid
for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
end = _halfedges.end(); it != end; ++it) {
......@@ -149,6 +155,7 @@ FaceHandle TopologyKernel::add_face(const std::vector<HalfEdgeHandle>& _halfedge
return InvalidFaceHandle;
}
}
#endif
// Perform topology check
if(_topologyCheck) {
......@@ -225,6 +232,7 @@ FaceHandle TopologyKernel::add_face(const std::vector<HalfEdgeHandle>& _halfedge
/// Define the _vertices in counter-clockwise order (from the "outside")
FaceHandle TopologyKernel::add_face(const std::vector<VertexHandle>& _vertices) {
#ifndef NDEBUG
// Test if all vertices exist
for(std::vector<VertexHandle>::const_iterator it = _vertices.begin(),
end = _vertices.end(); it != end; ++it) {
......@@ -233,6 +241,7 @@ FaceHandle TopologyKernel::add_face(const std::vector<VertexHandle>& _vertices)
return InvalidFaceHandle;
}
}
#endif
// Add edge for each pair of vertices
std::vector<HalfEdgeHandle> halfedges;
......@@ -349,6 +358,7 @@ void TopologyKernel::reorder_incident_halffaces(const EdgeHandle& _eh) {
/// Add cell via incident halffaces
CellHandle TopologyKernel::add_cell(const std::vector<HalfFaceHandle>& _halffaces, bool _topologyCheck) {
#ifndef NDEBUG
// Test if halffaces have valid indices
for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
end = _halffaces.end(); it != end; ++it) {
......@@ -357,6 +367,7 @@ CellHandle TopologyKernel::add_cell(const std::vector<HalfFaceHandle>& _halfface
return InvalidCellHandle;
}
}
#endif
// Perform topology check
if(_topologyCheck) {
......@@ -409,7 +420,15 @@ CellHandle TopologyKernel::add_cell(const std::vector<HalfFaceHandle>& _halfface
for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
end = _halffaces.end(); it != end; ++it) {
assert(incident_cell_per_hf_.size() > (unsigned int)it->idx());
assert(incident_cell_per_hf_[it->idx()] == InvalidCellHandle);
if(_topologyCheck) {
assert(incident_cell_per_hf_[it->idx()] == InvalidCellHandle);
if(incident_cell_per_hf_[it->idx()] != InvalidCellHandle) {
std::cerr << "Warning: One of the specified half-face is already incident to another cell!" << std::endl;
}
}
// Overwrite incident cell for current half-face
incident_cell_per_hf_[it->idx()] = ch;
// Collect all edges of cell
......@@ -1115,9 +1134,11 @@ const HalfEdgeHandle TopologyKernel::prev_halfedge_in_halfface(const HalfEdgeHan
HalfFaceHandle
TopologyKernel::adjacent_halfface_in_cell(const HalfFaceHandle& _halfFaceHandle, const HalfEdgeHandle& _halfEdgeHandle) const {
#ifndef NDEBUG
if((unsigned int)_halfFaceHandle.idx() >= incident_cell_per_hf_.size() || _halfFaceHandle.idx() < 0) {
return InvalidHalfFaceHandle;
}
#endif
if(!has_face_bottom_up_adjacencies()) {
return InvalidHalfFaceHandle;
}
......
......@@ -235,16 +235,16 @@ public:
//=======================================================================
/// Add edge
virtual EdgeHandle add_edge(const VertexHandle& _fromVertex, const VertexHandle& _toHandle);
virtual EdgeHandle add_edge(const VertexHandle& _fromVertex, const VertexHandle& _toHandle, bool _allowDuplicates = false);
/// Add face via incident edges
virtual FaceHandle add_face(const std::vector<HalfEdgeHandle>& _halfedges, bool _topologyCheck = true);
virtual FaceHandle add_face(const std::vector<HalfEdgeHandle>& _halfedges, bool _topologyCheck = false);
/// Add face via incident vertices
virtual FaceHandle add_face(const std::vector<VertexHandle>& _vertices);
/// Add cell via incident halffaces
virtual CellHandle add_cell(const std::vector<HalfFaceHandle>& _halffaces, bool _topologyCheck = true);
virtual CellHandle add_cell(const std::vector<HalfFaceHandle>& _halffaces, bool _topologyCheck = false);
/*
* Non-virtual functions
......
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