#define NOMINMAX #include // VA #include // Utils #include "VABinauralClusteringState.h" #include "./VABinauralClusterPoolFactory.h" VABinauralClusteringState::VABinauralClusteringState(int numClusters) { for (int i = numClusters - 1; i >= 0; --i) { freeClusterIDs.push(i); } } VABinauralClusteringState::~VABinauralClusteringState() { } VABinauralClusteringState::VABinauralClusteringState(const VABinauralClusteringState& state) : numClusters(state.numClusters), sourceClusterReference(state.sourceClusterReference) { std::map< int, VABinauralCluster* >::const_iterator it; for (it = state.clusters.begin(); it != state.clusters.end(); ++it) { int clusterID = it->first; VABinauralCluster* cluster = new VABinauralCluster(*(it->second)); clusters.insert(std::pair< int, VABinauralCluster* >(clusterID, cluster)); } } void VABinauralClusteringState::addSource(int sourceID, VABinauralSoundSource* source, double threshold, int numBlockedClusters) { int numFreeClusters = numClusters - numBlockedClusters - clusters.size(); double err = 0, minerr = std::numeric_limits::infinity(); int nearestClusterID = -1; VABinauralCluster* nearestCluster = nullptr; std::map< int, VABinauralCluster* >::iterator it; for (it = clusters.begin(); it != clusters.end(); ++it) { err = it->second->getDistError(source); if (err < minerr) { minerr = err; nearestClusterID = it->first; nearestCluster = it->second; } } if ((minerr > threshold) && (numFreeClusters > 0)) { std::pair< int, VABinauralCluster*> p; p = createCluster(source); nearestClusterID = p.first; nearestCluster = p.second; } nearestCluster->addSource(source, minerr); sourceClusterReference.insert(std::pair< int, int >(sourceID, nearestClusterID)); } std::pair< int, VABinauralCluster*> VABinauralClusteringState::createCluster(VABinauralSoundSource* source) { int clusterID = freeClusterIDs.back(); VABinauralCluster* cluster = dynamic_cast< VABinauralCluster* >(_clusterPool->RequestObject()); // Reference = 1 cluster->init(source); clusters.insert(std::pair< int, VABinauralCluster* >(clusterID, cluster)); freeClusterIDs.pop(); return std::pair< int, VABinauralCluster* >(clusterID, cluster); } double VABinauralClusteringState::getMaxError() { double max = 0; std::map< int, VABinauralCluster* >::iterator it; for (it = clusters.begin(); it != clusters.end(); ++it) { max = std::max(max, it->second->maxError); } return max; }