#ifndef CT_CLOUDINDEXSTDMAPT_HPP #define CT_CLOUDINDEXSTDMAPT_HPP #include "ct_cloudindex/ct_cloudindexstdmapt.h" #include template CT_CloudIndexStdMapT::CT_CloudIndexStdMapT() : CT_AbstractModifiableCloudIndexT() { this->internalSetSortType(CT_AbstractCloudIndex::SortedInAscendingOrder); this->internalSetUnregisteredWhenIsEmpty(false); m_collection = QSharedPointer< std::map >(new std::map()); } template size_t CT_CloudIndexStdMapT::size() const { return m_collection->size(); } template size_t CT_CloudIndexStdMapT::memoryUsed() const { return size() * (sizeof(T) + sizeof(ValueT)); } template size_t CT_CloudIndexStdMapT::indexAt(const size_t &i) const { typename std::map::const_iterator it = m_collection->begin(); std::advance(it, i); return it->first; } template const ct_index_type& CT_CloudIndexStdMapT::constIndexAt(const size_t &i) const { typename std::map::const_iterator it = m_collection->begin(); std::advance(it, i); return it->first; } template size_t CT_CloudIndexStdMapT::operator[](const size_t &i) const { typename std::map::const_iterator it = m_collection->begin(); std::advance(it, i); return it->first; } template void CT_CloudIndexStdMapT::indexAt(const size_t &i, size_t &index) const { typename std::map::const_iterator it = m_collection->begin(); std::advance(it, i); index = it->first; } template size_t CT_CloudIndexStdMapT::first() const { return m_collection->begin()->first; } template size_t CT_CloudIndexStdMapT::last() const { return m_collection->rbegin()->first; } template bool CT_CloudIndexStdMapT::contains(const size_t &index) const { return (m_collection->find(index) != m_collection->end()); } template size_t CT_CloudIndexStdMapT::indexOf(const size_t &index) const { typename std::map::iterator f = m_collection->begin(); typename std::map::iterator l = m_collection->end(); f = m_collection->lower_bound(index); if(f!=l && !(index < f->first)) return f->first; return size(); } template size_t CT_CloudIndexStdMapT::lowerBound(const size_t &value) const { typename std::map::iterator it; typename std::map::iterator itEnd = m_collection->end(); it = m_collection->lower_bound(value); return size() - std::distance(it, itEnd); } template size_t CT_CloudIndexStdMapT::upperBound(const size_t &value) const { typename std::map::iterator it; typename std::map::iterator itEnd = m_collection->end(); it = m_collection->upper_bound(value); return size() - std::distance(it, itEnd); } template void CT_CloudIndexStdMapT::addIndex(const size_t &newIndex) { ValueT val = ValueT(); insertIndexAndValue(newIndex, val); } template void CT_CloudIndexStdMapT::removeIndex(const size_t &index) { typename std::map::iterator f = m_collection->begin(); typename std::map::iterator l = m_collection->end(); f = m_collection->lower_bound(index); if(f!=l && !(index < f->first)) m_collection->erase(f); } template void CT_CloudIndexStdMapT::replaceIndex(const size_t &i, const ct_index_type &newIndex, const bool &verifyRespectSort) { Q_UNUSED(verifyRespectSort) typename std::map::iterator f = m_collection->begin(); std::advance(f, i); ValueT val = f->second; m_collection->erase(f); insertIndexAndValue(newIndex, val); } template void CT_CloudIndexStdMapT::insertIndexAndValue(const size_t &index, const ValueT & value) { std::pair< typename std::map::iterator, bool > ret; ret = m_collection->insert( std::pair(index,value) ); if (ret.second == false) ret.first->second = value; } template const ValueT CT_CloudIndexStdMapT::valueAtGlobalIndex(const size_t &index, const ValueT & defaultValue) const { typename std::map::const_iterator it = m_collection->find(index); if(it != m_collection->end()) return it->second; return defaultValue; } template const ValueT CT_CloudIndexStdMapT::valueAt(const size_t &index, const ValueT & defaultValue) const { typename std::map::const_iterator it = m_collection->begin(); std::advance(it, index); if(it != m_collection->end()) return it->second; return defaultValue; } template void CT_CloudIndexStdMapT::push_front(const size_t &newIndex) { m_collection->insert( std::pair(newIndex, ValueT()) ); } template void CT_CloudIndexStdMapT::fill() { qFatal("CT_CloudIndexStdMapT::fill can not be used"); } template void CT_CloudIndexStdMapT::clear() { internalClear(); } template void CT_CloudIndexStdMapT::erase(const size_t &beginIndex, const size_t &sizes) { typename std::map::iterator b = m_collection->begin(); std::advance(b, beginIndex); typename std::map::iterator e = m_collection->begin(); std::advance(e, beginIndex+sizes); m_collection->erase(b, e); } template void CT_CloudIndexStdMapT::resize(const size_t &newSize) { Q_UNUSED(newSize) qFatal("CT_CloudIndexStdMapT::resize can not be used"); } template void CT_CloudIndexStdMapT::removeIfOrShiftIf(typename CT_CloudIndexStdMapT::FindIfFunction findIf, typename CT_CloudIndexStdMapT::RemoveIfFunction removeIf, typename CT_CloudIndexStdMapT::ShiftIfFunction shiftIf, const size_t &shiftValue, const bool &negativeShift, void *context) { Q_UNUSED(findIf) Q_UNUSED(removeIf) Q_UNUSED(shiftIf) Q_UNUSED(shiftValue) Q_UNUSED(negativeShift) Q_UNUSED(context) // used only for not sorted cloud index qFatal("CT_CloudIndexStdMapT::removeIfOrShiftIf can not be used"); } template void CT_CloudIndexStdMapT::shiftAll(const size_t &offset, const bool &negativeOffset) { this->internalShiftAll(offset, negativeOffset); } template void CT_CloudIndexStdMapT::eraseBetweenAndShiftRest(const size_t &eraseBeginPos, const size_t &eraseSize, const size_t &offset, const bool &negativeOffset) { typename std::map::iterator f = m_collection->begin(); typename std::map::iterator l = m_collection->end(); std::advance(f, eraseBeginPos+eraseSize); std::map tmp; if(negativeOffset) { while(f != l) { tmp[f->first - offset] = f->second; ++f; } } else { while(f != l) { tmp[f->first + offset] = f->second; ++f; } } erase(eraseBeginPos, size()-eraseBeginPos); m_collection->insert(tmp.begin(), tmp.end()); } template CT_SharedPointer< std::vector > CT_CloudIndexStdMapT::toStdVectorInt() const { CT_SharedPointer< std::vector > indices(new std::vector(size())); typename std::map::iterator f = m_collection->begin(); typename std::map::iterator l = m_collection->end(); size_t i = 0; while(f != l) { (*indices.get())[i] = f->first; ++f; ++i; } return indices; } template CT_AbstractCloud* CT_CloudIndexStdMapT::copy() const { CT_CloudIndexStdMapT *index = new CT_CloudIndexStdMapT(); index->m_collection->insert(m_collection->begin(), m_collection->end()); return index; } template template typename std::map::iterator CT_CloudIndexStdMapT::mapFindIf(typename CT_CloudIndexStdMapT::FindIfFunction findIf, void *context) const { typename std::map::iterator f = m_collection->begin(); typename std::map::iterator l = m_collection->end(); size_t tmp; while (f!=l) { tmp = f->first; if ((*findIf)(context, tmp)) return f; ++f; } return l; } template std::map< ct_index_type, ValueT >* CT_CloudIndexStdMapT::internalData() const { return m_collection.data(); } template void CT_CloudIndexStdMapT::internalShiftAll(const size_t &offset, const bool &negativeOffset) { typename std::map::iterator f = m_collection->begin(); typename std::map::iterator l = m_collection->end(); std::map tmp; if(negativeOffset) { while(f != l) { tmp[f->first - offset] = f->second; ++f; } } else { while(f != l) { tmp[f->first + offset] = f->second; ++f; } } internalClear(); m_collection->insert(tmp.begin(), tmp.end()); } template void CT_CloudIndexStdMapT::internalClear() { m_collection->clear(); } #endif // CT_CLOUDINDEXSTDMAPT_HPP