Program Listing for File ClusterBiMap.hpp

Return to documentation for file (include/lvr2/util/ClusterBiMap.hpp)

/*
 * ClusterBiMap.hpp
 *
 *  @date 17.06.2017
 *  @author Johan M. von Behren <johan@vonbehren.eu>
 */

#ifndef LVR2_UTIL_CLUSTERBIMAP_H_
#define LVR2_UTIL_CLUSTERBIMAP_H_

#include "lvr2/geometry/Handles.hpp"
#include "lvr2/util/Cluster.hpp"

#include "lvr2/attrmaps/AttrMaps.hpp"
#include "lvr2/attrmaps/StableVector.hpp"

namespace lvr2
{

 template<typename HandleT>
class ClusterBiMapIterator
{
public:
    ClusterBiMapIterator(StableVectorIterator<ClusterHandle, Cluster<HandleT>> iterator) : m_iterator(iterator) {};
    ClusterBiMapIterator& operator++();
    bool operator==(const ClusterBiMapIterator& other) const;
    bool operator!=(const ClusterBiMapIterator& other) const;
    ClusterHandle operator*() const;

private:
    StableVectorIterator<ClusterHandle, Cluster<HandleT>> m_iterator;
};

template<typename HandleT>
class ClusterBiMap
{
public:
    ClusterBiMap() : m_numHandles(0) {};

    ClusterHandle createCluster();

    void removeCluster(ClusterHandle clusterHandle);

    ClusterHandle addToCluster(ClusterHandle clusterHandle, HandleT handle);

    ClusterHandle removeFromCluster(ClusterHandle clusterHandle, HandleT handle);

    ClusterHandle getClusterH(HandleT handle) const;

    OptionalClusterHandle getClusterOf(HandleT handle) const;

    size_t numCluster() const;

    ClusterBiMapIterator<HandleT> begin() const;
    ClusterBiMapIterator<HandleT> end() const;

    const Cluster<HandleT>& getCluster(ClusterHandle clusterHandle) const;

    const Cluster<HandleT>& operator[](ClusterHandle clusterHandle) const;

    void reserve(size_t newCap);

    size_t numHandles() const;

private:
    size_t m_numHandles;

    StableVector<ClusterHandle, Cluster<HandleT>> m_cluster;

    DenseAttrMap<HandleT, ClusterHandle> m_clusterMap;

    Cluster<HandleT>& getC(ClusterHandle clusterHandle);
};

} // namespace lvr2

#include "lvr2/util/ClusterBiMap.tcc"

#endif /* LVR2_UTIL_CLUSTERBIMAP_H_ */