#ifndef CT_INDEXCLOUDCOLORSTDMAPT_HPP #define CT_INDEXCLOUDCOLORSTDMAPT_HPP #include "ct_colorcloud/ct_indexcloudcolorstdmapt.h" template CT_IndexCloudColorStdMapT::CT_IndexCloudColorStdMapT() : CT_CloudIndexStdMapT(), CT_AbstractModifiableIndexCloudColorMap() { } template void CT_IndexCloudColorStdMapT::insertIndexAndColor(const size_t &newIndex, const CT_Color &color) { // insert a new element, if the element already exist it will be ignored this->internalData()->insert( std::pair(newIndex, color) ); } template CT_Color* CT_IndexCloudColorStdMapT::colorAtGlobalIndex(const size_t &index, const CT_Color *defaultValue) const { std::map< ct_index_type, CT_Color > *collect = this->internalData(); typename std::map< ct_index_type,CT_Color >::const_iterator it = collect->find(index); if(it != collect->end()) return (CT_Color*)&(it->second); return (CT_Color*)defaultValue; } template CT_Color* CT_IndexCloudColorStdMapT::colorAt(const size_t &index, const CT_Color *defaultValue) const { std::map< ct_index_type, CT_Color > *collect = this->internalData(); typename std::map< ct_index_type,CT_Color >::const_iterator it = collect->begin(); std::advance(it, index); if(it != collect->end()) return (CT_Color*)&(it->second); return (CT_Color*)defaultValue; } template void CT_IndexCloudColorStdMapT::copyColors(CT_AbstractColorCloud *cc) const { std::map< ct_index_type, CT_Color > *collect = this->internalData(); typename std::map< ct_index_type,CT_Color >::const_iterator it = collect->begin(); typename std::map< ct_index_type,CT_Color >::const_iterator end = collect->end(); while(it != end) { const CT_Color &colBackup = it->second; CT_Color &col = cc->colorAt(it->first); colBackup.copy(col); ++it; } } template void CT_IndexCloudColorStdMapT::copyColorsOfKeys(CT_AbstractColorCloud *cc, const std::vector &indexes, bool eraseKeys) { std::vector::const_iterator itV = indexes.begin(); std::vector::const_iterator endV = indexes.end(); std::map< ct_index_type, CT_Color > *collect = this->internalData(); while(itV != endV) { typename std::map< ct_index_type,CT_Color >::iterator it = collect->find(*itV); if(it != collect->end()) { const CT_Color &colBackup = it->second; CT_Color &col = cc->colorAt(it->first); colBackup.copy(col); if(eraseKeys) collect->erase(it); } ++itV; } } template void CT_IndexCloudColorStdMapT::copyColorsOfCloudIndex(CT_AbstractColorCloud *cc, const QList &lci, bool eraseKeys) { std::map *collect = this->internalData(); QListIterator itC(lci); while(itC.hasNext()) { CT_AbstractCloudIndexT *ci = dynamic_cast*>(itC.next()); if(ci != NULL) { CT_CloudIndexIteratorT itK(ci); while(itK.hasNext()) { typename std::map< ct_index_type,CT_Color >::iterator it = collect->find(itK.next().cIndex()); if(it != collect->end()) { const CT_Color &colBackup = it->second; CT_Color &col = cc->colorAt(it->first); colBackup.copy(col); if(eraseKeys) collect->erase(it); } } } } } template void CT_IndexCloudColorStdMapT::removeIndex(const size_t &index) { CT_CloudIndexStdMapT::removeIndex(index); } template void CT_IndexCloudColorStdMapT::clear() { CT_CloudIndexStdMapT::clear(); } template CT_AbstractCloud* CT_IndexCloudColorStdMapT::copy() const { CT_IndexCloudColorStdMapT *index = new CT_IndexCloudColorStdMapT(); std::map< ct_index_type, CT_Color > *myCollect = this->internalData(); std::map< ct_index_type, CT_Color > *collect = index->internalData(); collect->insert(myCollect->begin(), myCollect->end()); return index; } #endif // CT_INDEXCLOUDCOLORSTDMAPT_HPP