void ColorSorter::sortNearestTo( int center, const ColorSample* clusters, int* idxMap, int* mask, int& sidx, int& start, int& span, float threshold, int clusterNum) { assert(center < clusterNum); int* sorted = new int[clusterNum]; float dist_tmp; float* dist = new float[clusterNum]; threshold = 25.5; /////// 测试用 lab //threshold = 0.1; /////// 测试用 hue for (int i = 0; i < clusterNum; ++i) { sorted[i] = idxMap[i]; dist[sorted[i]] = distance_lab(clusters[idxMap[center]], clusters[idxMap[i]]); } for (int i = 0; i < clusterNum; ++i) { for (int j = i + 1; j < clusterNum; ++j) { if(dist[sorted[i]] > dist[sorted[j]]) std::swap(sorted[i], sorted[j]); } } for(int i = 0; i < clusterNum; ++i) { printf("%f ", dist[sorted[i]]); if (dist[sorted[i]] > threshold) { span = i; break; } } printf(" -> %d\n", span); ////////////////////////////////////////////////////////////////////////// // 更新mask和idxMap // memcpy(idxMap, sorted,clusterNum * sizeof(int)); bool flag; int idx = 0; for(int i = 0; i < center; ++i) { flag = findIn(&sorted[0], &sorted[0] + span, idxMap[i]); if (!flag) { if(idx < i) //不在span区间内且需要交换 idxMap[idx] = idxMap[i]; ++idx; } } start = idx; idx = clusterNum - 1; for(int i = clusterNum - 1; i > center; --i) { flag = findIn(&sorted[0], &sorted[0] + span, idxMap[i]); if (!flag) { if (idx > i) //不在span区间内且需要交换 idxMap[idx] = idxMap[i]; --idx; } } //printf("[%d,%d]_%d\n", start, idx, span); sidx = start; idx = start; for (int i = 0; i < span; ++i) { idxMap[idx] = sorted[i]; //mask[idx] = sidx; ++idx; } delete[] sorted; delete[] dist; }
bool ItemSet<T>::contained(const std::list<ItemSet<T>* >& collection) const { return (findIn(collection) != collection.end()); }