Commit 9c6364ab authored by Mike Kremer's avatar Mike Kremer

Added option to specify default property value for all properties.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@217 66977474-1d4b-4f09-8fe9-267525286df2
parent 110a223b
......@@ -58,7 +58,7 @@ template <class ColT>
class ColorAttrib {
public:
ColorAttrib(TopologyKernel& _kernel);
ColorAttrib(TopologyKernel& _kernel, const ColT _def = ColT());
virtual ~ColorAttrib();
......
......@@ -47,13 +47,13 @@
namespace OpenVolumeMesh {
template <class ColT>
ColorAttrib<ColT>::ColorAttrib(TopologyKernel& _kernel) :
vcolor_prop_(_kernel.request_vertex_property<ColT>("vertex_color")),
ecolor_prop_(_kernel.request_edge_property<ColT>("edge_color")),
hecolor_prop_(_kernel.request_halfedge_property<ColT>("halfedge_color")),
fcolor_prop_(_kernel.request_face_property<ColT>("face_color")),
hfcolor_prop_(_kernel.request_halfface_property<ColT>("halfface_color")),
ccolor_prop_(_kernel.request_cell_property<ColT>("cell_color")),
ColorAttrib<ColT>::ColorAttrib(TopologyKernel& _kernel, const ColT _def) :
vcolor_prop_(_kernel.request_vertex_property<ColT>("vertex_color", _def)),
ecolor_prop_(_kernel.request_edge_property<ColT>("edge_color", _def)),
hecolor_prop_(_kernel.request_halfedge_property<ColT>("halfedge_color", _def)),
fcolor_prop_(_kernel.request_face_property<ColT>("face_color", _def)),
hfcolor_prop_(_kernel.request_halfface_property<ColT>("halfface_color", _def)),
ccolor_prop_(_kernel.request_cell_property<ColT>("cell_color", _def)),
kernel_(_kernel) {
}
......
......@@ -81,13 +81,16 @@ public:
public:
/// Default constructor
OpenVolumeMeshPropertyT(const std::string& _name = "<unknown>") :
OpenVolumeMeshBaseProperty(_name) {
OpenVolumeMeshPropertyT(const std::string& _name = "<unknown>", const T _def = T()) :
OpenVolumeMeshBaseProperty(_name),
def_(_def) {
}
/// Copy constructor
OpenVolumeMeshPropertyT(const OpenVolumeMeshPropertyT& _rhs) :
OpenVolumeMeshBaseProperty(_rhs), data_(_rhs.data_) {
OpenVolumeMeshBaseProperty(_rhs),
data_(_rhs.data_),
def_(_rhs.def_) {
}
public:
......@@ -96,14 +99,14 @@ public:
data_.reserve(_n);
}
virtual void resize(size_t _n) {
data_.resize(_n, Value());
data_.resize(_n, def_);
}
virtual void clear() {
data_.clear();
vector_type().swap(data_);
}
virtual void push_back() {
data_.push_back(T());
data_.push_back(def_);
}
virtual void swap(size_t _i0, size_t _i1) {
std::swap(data_[_i0], data_[_i1]);
......@@ -190,7 +193,7 @@ public:
/// Make a copy of self.
OpenVolumeMeshPropertyT<T>* clone() const {
OpenVolumeMeshPropertyT<T>* p = new OpenVolumeMeshPropertyT<T> (*this);
OpenVolumeMeshPropertyT<T>* p = new OpenVolumeMeshPropertyT<T>(*this);
return p;
}
......@@ -223,6 +226,8 @@ protected:
private:
vector_type data_;
const T def_;
};
//-----------------------------------------------------------------------------
......@@ -244,8 +249,9 @@ public:
public:
OpenVolumeMeshPropertyT(const std::string& _name = "<unknown>") :
OpenVolumeMeshBaseProperty(_name) {
OpenVolumeMeshPropertyT(const std::string& _name = "<unknown>", const bool _def = bool()) :
OpenVolumeMeshBaseProperty(_name),
def_(_def) {
}
public:
......@@ -255,14 +261,14 @@ public:
data_.reserve(_n);
}
virtual void resize(size_t _n) {
data_.resize(_n);
data_.resize(_n, def_);
}
virtual void clear() {
data_.clear();
vector_type().swap(data_);
}
virtual void push_back() {
data_.push_back(bool());
data_.push_back(def_);
}
virtual void swap(size_t _i0, size_t _i1) {
bool t(data_[_i0]);
......@@ -339,6 +345,8 @@ protected:
private:
vector_type data_;
const bool def_;
};
//-----------------------------------------------------------------------------
......@@ -361,8 +369,9 @@ public:
public:
OpenVolumeMeshPropertyT(const std::string& _name = "<unknown>") :
OpenVolumeMeshBaseProperty(_name) {
OpenVolumeMeshPropertyT(const std::string& _name = "<unknown>", const std::string _def = std::string()) :
OpenVolumeMeshBaseProperty(_name),
def_(_def) {
}
public:
......@@ -372,14 +381,14 @@ public:
data_.reserve(_n);
}
virtual void resize(size_t _n) {
data_.resize(_n);
data_.resize(_n, def_);
}
virtual void clear() {
data_.clear();
vector_type().swap(data_);
}
virtual void push_back() {
data_.push_back(std::string());
data_.push_back(def_);
}
virtual void swap(size_t _i0, size_t _i1) {
std::swap(data_[_i0], data_[_i1]);
......@@ -469,6 +478,7 @@ private:
vector_type data_;
const std::string def_;
};
} // Namespace OpenVolumeMesh
......
......@@ -63,7 +63,7 @@ class ResourceManager;
template<class T>
class VertexPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle> {
public:
VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle);
VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle, const T _def = T());
~VertexPropertyT() {}
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
......@@ -71,7 +71,7 @@ public:
template<class T>
class EdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle> {
public:
EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle);
EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle, const T _def = T());
~EdgePropertyT() {}
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
......@@ -79,7 +79,7 @@ public:
template<class T>
class HalfEdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle> {
public:
HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle);
HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle, const T _def = T());
~HalfEdgePropertyT() {}
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
......@@ -87,7 +87,7 @@ public:
template<class T>
class FacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle> {
public:
FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle);
FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle, const T _def = T());
~FacePropertyT() {}
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
......@@ -95,7 +95,7 @@ public:
template<class T>
class HalfFacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle> {
public:
HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle);
HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle, const T _def = T());
~HalfFacePropertyT() {}
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
......@@ -103,7 +103,7 @@ public:
template<class T>
class CellPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle> {
public:
CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle);
CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle, const T _def = T());
~CellPropertyT() {}
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
......@@ -111,7 +111,7 @@ public:
template<class T>
class MeshPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle> {
public:
MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle);
MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle, const T _def = T());
~MeshPropertyT() {}
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
......
......@@ -49,8 +49,8 @@ namespace OpenVolumeMesh {
/// Property classes for the different entity types
template<class T>
VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
......@@ -67,8 +67,8 @@ void VertexPropertyT<T>::deserialize(std::istream& _istr) {
}
template<class T>
EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
......@@ -85,8 +85,8 @@ void EdgePropertyT<T>::deserialize(std::istream& _istr) {
}
template<class T>
HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
......@@ -103,8 +103,8 @@ void HalfEdgePropertyT<T>::deserialize(std::istream& _istr) {
}
template<class T>
FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
......@@ -121,8 +121,8 @@ void FacePropertyT<T>::deserialize(std::istream& _istr) {
}
template<class T>
HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
......@@ -139,8 +139,8 @@ void HalfFacePropertyT<T>::deserialize(std::istream& _istr) {
}
template<class T>
CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
......@@ -157,8 +157,8 @@ void CellPropertyT<T>::deserialize(std::istream& _istr) {
}
template<class T>
MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
......
......@@ -128,19 +128,19 @@ public:
/// Get number of cells in mesh
virtual unsigned int n_cells() const = 0;
template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string());
template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string(), const T _def = T());
template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string());
template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string(), const T _def = T());
template<class T> HalfEdgePropertyT<T> request_halfedge_property(const std::string& _name = std::string());
template<class T> HalfEdgePropertyT<T> request_halfedge_property(const std::string& _name = std::string(), const T _def = T());
template<class T> FacePropertyT<T> request_face_property(const std::string& _name = std::string());
template<class T> FacePropertyT<T> request_face_property(const std::string& _name = std::string(), const T _def = T());
template<class T> HalfFacePropertyT<T> request_halfface_property(const std::string& _name = std::string());
template<class T> HalfFacePropertyT<T> request_halfface_property(const std::string& _name = std::string(), const T _def = T());
template<class T> CellPropertyT<T> request_cell_property(const std::string& _name = std::string());
template<class T> CellPropertyT<T> request_cell_property(const std::string& _name = std::string(), const T _def = T());
template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name = std::string());
template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name = std::string(), const T _def = T());
private:
......@@ -291,8 +291,8 @@ private:
template<class StdVecT>
void remove_property(StdVecT& _vec, size_t _idx);
template<class StdVecT, class PropT, class HandleT>
PropT request_property(StdVecT& _vec, const std::string& _name, size_t _size);
template<class StdVecT, class PropT, class HandleT, class T>
PropT request_property(StdVecT& _vec, const std::string& _name, size_t _size, const T _def = T());
template<class PropT>
void set_persistentT(PropT& _prop, bool _flag);
......
......@@ -51,49 +51,49 @@
namespace OpenVolumeMesh {
template<class T>
VertexPropertyT<T> ResourceManager::request_vertex_property(const std::string& _name) {
VertexPropertyT<T> ResourceManager::request_vertex_property(const std::string& _name, const T _def) {
return request_property<std::vector<BaseProperty*>,VertexPropertyT<T>,VertexPropHandle>(vertex_props_, _name, n_vertices());
return request_property<std::vector<BaseProperty*>,VertexPropertyT<T>,VertexPropHandle,T>(vertex_props_, _name, n_vertices(), _def);
}
template<class T>
EdgePropertyT<T> ResourceManager::request_edge_property(const std::string& _name) {
EdgePropertyT<T> ResourceManager::request_edge_property(const std::string& _name, const T _def) {
return request_property<std::vector<BaseProperty*>,EdgePropertyT<T>,EdgePropHandle>(edge_props_, _name, n_edges());
return request_property<std::vector<BaseProperty*>,EdgePropertyT<T>,EdgePropHandle,T>(edge_props_, _name, n_edges(), _def);
}
template<class T>
HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(const std::string& _name) {
HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(const std::string& _name, const T _def) {
return request_property<std::vector<BaseProperty*>,HalfEdgePropertyT<T>,HalfEdgePropHandle>(halfedge_props_, _name, n_edges()*2u);
return request_property<std::vector<BaseProperty*>,HalfEdgePropertyT<T>,HalfEdgePropHandle,T>(halfedge_props_, _name, n_edges()*2u, _def);
}
template<class T>
FacePropertyT<T> ResourceManager::request_face_property(const std::string& _name) {
FacePropertyT<T> ResourceManager::request_face_property(const std::string& _name, const T _def) {
return request_property<std::vector<BaseProperty*>,FacePropertyT<T>,FacePropHandle>(face_props_, _name, n_faces());
return request_property<std::vector<BaseProperty*>,FacePropertyT<T>,FacePropHandle,T>(face_props_, _name, n_faces(), _def);
}
template<class T>
HalfFacePropertyT<T> ResourceManager::request_halfface_property(const std::string& _name) {
HalfFacePropertyT<T> ResourceManager::request_halfface_property(const std::string& _name, const T _def) {
return request_property<std::vector<BaseProperty*>,HalfFacePropertyT<T>,HalfFacePropHandle>(halfface_props_, _name, n_faces()*2u);
return request_property<std::vector<BaseProperty*>,HalfFacePropertyT<T>,HalfFacePropHandle,T>(halfface_props_, _name, n_faces()*2u, _def);
}
template<class T>
CellPropertyT<T> ResourceManager::request_cell_property(const std::string& _name) {
CellPropertyT<T> ResourceManager::request_cell_property(const std::string& _name, const T _def) {
return request_property<std::vector<BaseProperty*>,CellPropertyT<T>,CellPropHandle>(cell_props_, _name, n_cells());
return request_property<std::vector<BaseProperty*>,CellPropertyT<T>,CellPropHandle,T>(cell_props_, _name, n_cells(), _def);
}
template<class T>
MeshPropertyT<T> ResourceManager::request_mesh_property(const std::string& _name) {
MeshPropertyT<T> ResourceManager::request_mesh_property(const std::string& _name, const T _def) {
return request_property<std::vector<BaseProperty*>,MeshPropertyT<T>,MeshPropHandle>(mesh_props_, _name, 1);
return request_property<std::vector<BaseProperty*>,MeshPropertyT<T>,MeshPropHandle,T>(mesh_props_, _name, 1, _def);
}
template<class StdVecT, class PropT, class HandleT>
PropT ResourceManager::request_property(StdVecT& _vec, const std::string& _name, size_t _size) {
template<class StdVecT, class PropT, class HandleT, class T>
PropT ResourceManager::request_property(StdVecT& _vec, const std::string& _name, size_t _size, const T _def) {
if(!_name.empty()) {
for(typename StdVecT::iterator it = _vec.begin();
......@@ -108,7 +108,7 @@ PropT ResourceManager::request_property(StdVecT& _vec, const std::string& _name,
HandleT handle(_vec.size());
PropT* prop = new PropT(_name, *this, handle);
PropT* prop = new PropT(_name, *this, handle, _def);
prop->resize(_size);
// Store property pointer
......
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