Commit ca8c4c24 authored by Jan Möbius's avatar Jan Möbius
Browse files

Revert Skeleton part

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13052 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4fc0fc94
#include "SkeletonBaseKernel.hh"
void SkeletonBaseKernel::property_stats(std::ostream& _ostr) const {
const SkeletonPropertyContainer::Properties& jps =
jprops_.properties();
const SkeletonPropertyContainer::Properties& sps =
sprops_.properties();
SkeletonPropertyContainer::Properties::const_iterator it;
_ostr << jprops_.size() << " jprops:\n";
for (it = jps.begin(); it != jps.end(); ++it) {
*it == NULL ? (void) (_ostr << "[deleted]" << "\n") : (*it)->stats(
_ostr);
}
_ostr << sprops_.size() << " sprops:\n";
for (it = sps.begin(); it != sps.end(); ++it) {
*it == NULL ? (void) (_ostr << "[deleted]" << "\n") : (*it)->stats(
_ostr);
}
}
void SkeletonBaseKernel::jprop_stats(std::string& _string) const {
_string.clear();
SkeletonPropertyContainer::Properties::const_iterator it;
const SkeletonPropertyContainer::Properties& jps =
jprops_.properties();
for (it = jps.begin(); it != jps.end(); ++it)
if (*it == NULL)
_string += "[deleted] \n";
else {
_string += (*it)->name();
_string += "\n";
}
}
void SkeletonBaseKernel::sprop_stats(std::string& _string) const {
_string.clear();
SkeletonPropertyContainer::Properties::const_iterator it;
const SkeletonPropertyContainer::Properties& sps =
sprops_.properties();
for (it = sps.begin(); it != sps.end(); ++it)
if (*it == NULL)
_string += "[deleted] \n";
else {
_string += (*it)->name();
_string += "\n";
}
}
void SkeletonBaseKernel::jprop_stats(std::ostream& _ostr) const {
SkeletonPropertyContainer::Properties::const_iterator it;
const SkeletonPropertyContainer::Properties& jps =
jprops_.properties();
for (it = jps.begin(); it != jps.end(); ++it)
*it == NULL ? (void) (_ostr << "[deleted]" << "\n") : (*it)->stats(
_ostr);
}
void SkeletonBaseKernel::sprop_stats(std::ostream& _ostr) const {
SkeletonPropertyContainer::Properties::const_iterator it;
const SkeletonPropertyContainer::Properties& sps =
sprops_.properties();
for (it = sps.begin(); it != sps.end(); ++it)
*it == NULL ? (void) (_ostr << "[deleted]" << "\n") : (*it)->stats(
_ostr);
}
//=============================================================================
//
// CLASS SkeletonBaseKernel
//
//=============================================================================
#ifndef SKELETONBASEKERNEL_HH
#define SKELETONBASEKERNEL_HH
//== INCLUDES =================================================================
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
// --------------------
#include "SkeletonProperty.hh"
#include "SkeletonPropertyContainer.hh"
//== CLASS DEFINITION =========================================================
/// This class provides the basic property management like adding/removing
/// properties and access to properties.
/// All operations provided by %SkeletonBaseKernel need at least a property handle
/// (JPropHandleT, SPropHandleT) which keeps the data type of the property, too.
class SkeletonBaseKernel {
public:
//-------------------------------------------- constructor / destructor
SkeletonBaseKernel() {
}
virtual ~SkeletonBaseKernel() {
jprops_.clear();
sprops_.clear();
}
public:
//-------------------------------------------------- add new properties
template<class T>
void add_property(JPropHandleT<T>& _ph,
const std::string& _name = "<jprop>") {
_ph = JPropHandleT<T> (jprops_.add(T(), _name));
jprops_.resize(jointCount());
}
template<class T>
void add_property(SPropHandleT<T>& _ph,
const std::string& _name = "<sprop>") {
_ph = SPropHandleT<T> (sprops_.add(T(), _name));
sprops_.resize(1);
}
public:
//--------------------------------------------------- remove properties
template<typename T>
void remove_property(JPropHandleT<T>& _ph) {
if (_ph.is_valid())
jprops_.remove(_ph);
_ph.reset();
}
template<typename T>
void remove_property(SPropHandleT<T>& _ph) {
if (_ph.is_valid())
sprops_.remove(_ph);
_ph.reset();
}
//--------------------------------------------------- remove single elements
void remove_jprop_element(size_t _idx) {
for(prop_iterator p_it = jprops_.begin(); p_it != jprops_.end(); ++p_it) {
(*p_it)->delete_element(_idx);
}
}
public:
//------------------------------------------------ get handle from name
template<class T>
bool get_property_handle(JPropHandleT<T>& _ph, const std::string& _name) const {
return (_ph = JPropHandleT<T> (jprops_.handle(T(), _name))).is_valid();
}
template<class T>
bool get_property_handle(SPropHandleT<T>& _ph, const std::string& _name) const {
return (_ph = SPropHandleT<T> (sprops_.handle(T(), _name))).is_valid();
}
public:
//--------------------------------------------------- access properties
template<class T>
SkeletonPropertyT<T>& property(JPropHandleT<T> _ph) {
return jprops_.property(_ph);
}
template<class T>
const SkeletonPropertyT<T>& property(JPropHandleT<T> _ph) const {
return jprops_.property(_ph);
}
template<class T>
SkeletonPropertyT<T>& property(SPropHandleT<T> _ph) {
return sprops_.property(_ph);
}
template<class T>
const SkeletonPropertyT<T>& property(SPropHandleT<T> _ph) const {
return sprops_.property(_ph);
}
public:
//-------------------------------------------- access property elements
template<class T>
typename JPropHandleT<T>::reference property(JPropHandleT<T> _ph,
unsigned int _jIdx) {
return jprops_.property(_ph)[_jIdx];
}
template<class T>
typename JPropHandleT<T>::const_reference property(JPropHandleT<T> _ph,
unsigned int _jIdx) const {
return jprops_.property(_ph)[_jIdx];
}
template<class T>
typename SPropHandleT<T>::reference property(SPropHandleT<T> _ph) {
return sprops_.property(_ph)[0];
}
template<class T>
typename SPropHandleT<T>::const_reference property(SPropHandleT<T> _ph) const {
return sprops_.property(_ph)[0];
}
//@}
protected:
//------------------------------------------------- low-level access
public:
// used by non-native kernel and MeshIO, should be protected
size_t n_jprops(void) const {
return jprops_.size();
}
size_t n_sprops(void) const {
return sprops_.size();
}
SkeletonBaseProperty* _get_jprop(const std::string& _name) {
return jprops_.property(_name);
}
SkeletonBaseProperty* _get_sprop(const std::string& _name) {
return sprops_.property(_name);
}
SkeletonBaseProperty& _jprop(size_t _idx) {
return jprops_._property(_idx);
}
SkeletonBaseProperty& _sprop(size_t _idx) {
return sprops_._property(_idx);
}
const SkeletonBaseProperty& _jprop(size_t _idx) const {
return jprops_._property(_idx);
}
const SkeletonBaseProperty& _sprop(size_t _idx) const {
return sprops_._property(_idx);
}
size_t _add_jprop(SkeletonBaseProperty* _bp) {
return jprops_._add(_bp);
}
size_t _add_sprop(SkeletonBaseProperty* _bp) {
return sprops_._add(_bp);
}
protected:
// low-level access non-public
SkeletonBaseProperty& _jprop(unsigned int _h) {
return jprops_._property(_h);
}
SkeletonBaseProperty& _sprop(unsigned int _h) {
return sprops_._property(_h);
}
const SkeletonBaseProperty& _jprop(unsigned int _h) const {
return jprops_._property(_h);
}
const SkeletonBaseProperty& _sprop(unsigned int _h) const {
return sprops_._property(_h);
}
public:
//----------------------------------------------------- element numbers
virtual unsigned int jointCount() const {
return 0u;
}
protected:
//------------------------------------------- synchronize properties
void jprops_reserve(unsigned int _n) const {
jprops_.reserve(_n);
}
void jprops_resize(unsigned int _n) const {
jprops_.resize(_n);
}
void jprops_clear() {
jprops_.clear();
}
void jprops_swap(unsigned int _i0, unsigned int _i1) const {
jprops_.swap(_i0, _i1);
}
void jprops_copy(const SkeletonPropertyContainer& _jprops) {
jprops_.clear();
jprops_ = _jprops;
}
void sprops_resize(unsigned int _n) const {
sprops_.resize(_n);
}
void sprops_clear() {
sprops_.clear();
}
void sprops_copy(const SkeletonPropertyContainer& _sprops) {
sprops_.clear();
sprops_ = _sprops;
}
public:
void property_stats(std::ostream& _ostr = std::clog) const;
void jprop_stats(std::string& _string) const;
void sprop_stats(std::string& _string) const;
void jprop_stats(std::ostream& _ostr = std::clog) const;
void sprop_stats(std::ostream& _ostr = std::clog) const;
public:
typedef SkeletonPropertyContainer::iterator prop_iterator;
typedef SkeletonPropertyContainer::const_iterator const_prop_iterator;
prop_iterator jprops_begin() {
return jprops_.begin();
}
prop_iterator jprops_end() {
return jprops_.end();
}
const_prop_iterator jprops_begin() const {
return jprops_.begin();
}
const_prop_iterator jprops_end() const {
return jprops_.end();
}
prop_iterator sprops_begin() {
return sprops_.begin();
}
prop_iterator sprops_end() {
return sprops_.end();
}
const_prop_iterator sprops_begin() const {
return sprops_.begin();
}
const_prop_iterator sprops_end() const {
return sprops_.end();
}
protected:
SkeletonPropertyContainer jprops_;
SkeletonPropertyContainer sprops_;
};
//=============================================================================
#endif // SKELETONMESHBASEKERNEL_HH defined
//=============================================================================
#ifndef SKELETONBASEPROPERTY_HH
#define SKELETONBASEPROPERTY_HH
#include <string>
//== CLASS DEFINITION =========================================================
/** \class SkeletonBaseProperty
Abstract class defining the basic interface of a dynamic property.
**/
class SkeletonBaseProperty {
public:
/// Indicates an error when a size is returned by a member.
static const size_t UnknownSize = size_t(-1);
public:
SkeletonBaseProperty(const std::string& _name = "<unknown>") :
name_(_name), persistent_(false) {
}
SkeletonBaseProperty(const SkeletonBaseProperty& _rhs) :
name_(_rhs.name_), persistent_(_rhs.persistent_) {
}
virtual ~SkeletonBaseProperty() {}
public:
/// Reserve memory for n elements.
virtual void reserve(size_t _n) = 0;
/// Resize storage to hold n elements.
virtual void resize(size_t _n) = 0;
/// Clear all elements and free memory.
virtual void clear() = 0;
/// Extend the number of elements by one.
virtual void push_back() = 0;
/// Let two elements swap their storage place.
virtual void swap(size_t _i0, size_t _i1) = 0;
/// Erase an element of the vector
virtual void delete_element(size_t _idx) = 0;
/// Return a deep copy of self.
virtual SkeletonBaseProperty* clone() const = 0;
public:
/// Return the name of the property
const std::string& name() const {
return name_;
}
virtual void stats(std::ostream& _ostr) const {
_ostr << name() << (persistent() ? ", persistent " : "") << "\n";
}
public:
// I/O support
/// Returns true if the persistent flag is enabled else false.
bool persistent() const {
return persistent_;
}
/// Enable or disable persistency. Self must be a named property to enable
/// persistency.
void set_persistent(bool _yn) {
persistent_ = _yn;
}
/// Number of elements in property
virtual size_t n_elements() const = 0;
/// Size of one element in bytes or UnknownSize if not known.
virtual size_t element_size() const = 0;
/// Return size of property in bytes
virtual size_t size_of() const {
return size_of(n_elements());
}
/// Estimated size of property if it has _n_elem elements.
/// The member returns UnknownSize if the size cannot be estimated.
virtual size_t size_of(size_t _n_elem) const {
return (element_size() != UnknownSize) ? (_n_elem * element_size())
: UnknownSize;
}
private:
std::string name_;
bool persistent_;
};
#endif //SKELETONBASEPROPERTY_HH
#ifndef SKELETONPROPERTY_HH
#define SKELETONPROPERTY_HH
//== INCLUDES =================================================================
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cassert>
#include "SkeletonBaseProperty.hh"
//== CLASS DEFINITION =========================================================
/** \class SkeletonPropertyT
*
* \brief Default property class for any type T.
*
* The default property class for any type T.
*
* The property supports persistence if T is a "fundamental" type:
* - integer fundamental types except bool:
* char, short, int, long, long long (__int64 for MS VC++) and
* their unsigned companions.
* - float fundamentals except <tt>long double</tt>:
* float, double
*/
template<class T>
class SkeletonPropertyT: public SkeletonBaseProperty {
public:
typedef T Value;
typedef std::vector<T> vector_type;
typedef T value_type;
typedef typename vector_type::reference reference;
typedef typename vector_type::const_reference const_reference;
public:
/// Default constructor
SkeletonPropertyT(const std::string& _name = "<unknown>") :
SkeletonBaseProperty(_name) {
}
/// Copy constructor
SkeletonPropertyT(const SkeletonPropertyT& _rhs) :
SkeletonBaseProperty(_rhs), data_(_rhs.data_) {
}
public:
// inherited from SkeletonBaseProperty
virtual void reserve(size_t _n) {
data_.reserve(_n);
}
virtual void resize(size_t _n) {
data_.resize(_n, Value());
}
virtual void clear() {
data_.clear();
vector_type().swap(data_);
}
virtual void push_back() {
data_.push_back(T());
}
virtual void swap(size_t _i0, size_t _i1) {
std::swap(data_[_i0], data_[_i1]);
}
void delete_element(size_t _idx) {
data_.erase(data_.begin() + _idx);
}
virtual void stats(std::ostream& _ostr) const {
/// \TODO: Implement streaming operator
// for(typename vector_type::const_iterator it = data_.begin();
// it != data_.end(); ++it) {
// _ostr << *it << " ";
// }
}
public:
virtual size_t n_elements() const {
return data_.size();
}
virtual size_t element_size() const {
return sizeof(T);
}
#ifndef DOXY_IGNORE_THIS
struct plus {
size_t operator ()(size_t _b, const T& _v) {
return _b + sizeof(T);
}
};
#endif
virtual size_t size_of() const {
if (element_size() != SkeletonBaseProperty::UnknownSize)
return this->SkeletonBaseProperty::size_of(n_elements());
return std::accumulate(data_.begin(), data_.end(), 0, plus());
}
virtual size_t size_of(size_t _n_elem) const {
return this->SkeletonBaseProperty::size_of(_n_elem);
}
public:
// data access interface
/// Get pointer to array (does not work for T==bool)
const T* data() const {
if (data_.empty())
return 0;
return &data_[0];
}
/// Get reference to property vector (be careful, improper usage, e.g. resizing, may crash)
vector_type& data_vector() {
return data_;
}
/// Access the i'th element. No range check is performed!
reference operator[](int _idx) {
assert(size_t(_idx) < data_.size());
return data_[_idx];
}
/// Const access to the i'th element. No range check is performed!
const_reference operator[](int _idx) const {
assert(size_t(_idx) < data_.size());
return data_[_idx];
}