262 const labelType *pointLabels,
263 const size_t nPoints,
264 Nodes &nodes)
const {
269 std::map<labelType, size_t> labelIndexMap;
270 this->computeLabelIndexMap(pointLabels, nPoints, labelIndexMap);
272 size_t const nNodes = labelIndexMap.size();
274 nodes.resize(nNodes);
275 for(
size_t i = 0, q = 0; i < nPoints; i++) {
276 labelType label = pointLabels[i];
277 Node &n = nodes[labelIndexMap[label]];
280 n.
x += pointCoordinates[q++];
281 n.
y += pointCoordinates[q++];
282 n.
z += pointCoordinates[q++];
285 for(
size_t i = 0; i < nNodes; i++) {
287 float const size = (float)n.
size;
295 std::stringstream msg;
296 msg <<
"done (#" << nNodes <<
" in " << t.
getElapsedTime() <<
" s).";
308 const float *pointCoordinates1,
309 const labelType *pointLabels0,
310 const labelType *pointLabels1,
311 const size_t nPoints0,
312 const size_t nPoints1,
314 Edges &edges)
const {
318 std::map<labelType, size_t> labelIndexMap0;
319 std::map<labelType, size_t> labelIndexMap1;
320 this->computeLabelIndexMap<labelType>(pointLabels0, nPoints0, labelIndexMap0);
321 this->computeLabelIndexMap<labelType>(pointLabels1, nPoints1, labelIndexMap1);
326 std::vector<size_t> sortedIndices0;
327 std::vector<size_t> sortedIndices1;
328 this->sortCoordinates(pointCoordinates0, nPoints0, sortedIndices0);
329 this->sortCoordinates(pointCoordinates1, nPoints1, sortedIndices1);
342 auto compare = [&](
size_t p0,
size_t p1) {
343 size_t p0CoordIndex = p0 * 3;
344 size_t p1CoordIndex = p1 * 3;
346 float const p0_X = pointCoordinates0[p0CoordIndex++];
347 float const p0_Y = pointCoordinates0[p0CoordIndex++];
348 float const p0_Z = pointCoordinates0[p0CoordIndex];
350 float const p1_X = pointCoordinates1[p1CoordIndex++];
351 float const p1_Y = pointCoordinates1[p1CoordIndex++];
352 float const p1_Z = pointCoordinates1[p1CoordIndex];
354 return p0_X == p1_X ? p0_Y == p1_Y ? p0_Z == p1_Z ? 0
367 std::unordered_map<size_t, std::unordered_map<size_t, size_t>> edgesMap;
369 while(i < nPoints0 && j < nPoints1) {
370 size_t const pointIndex0 = sortedIndices0[i];
371 size_t const pointIndex1 = sortedIndices1[j];
374 int const c = compare(pointIndex0, pointIndex1);
377 labelType label0 = pointLabels0[pointIndex0];
378 labelType label1 = pointLabels1[pointIndex1];
380 size_t const &nodeIndex0 = labelIndexMap0[label0];
381 size_t const &nodeIndex1 = labelIndexMap1[label1];
384 auto edges0 = edgesMap.find(nodeIndex0);
387 if(edges0 == edgesMap.end()) {
388 edgesMap[nodeIndex0] = std::unordered_map<size_t, size_t>();
389 edges0 = edgesMap.find(nodeIndex0);
393 auto edge = edges0->second.find(nodeIndex1);
396 if(edge == edges0->second.end()) {
397 edges0->second[nodeIndex1] = 0;
398 edge = edges0->second.find(nodeIndex1);
418 edges.resize(nEdges * 4);
420 for(
auto &it0 : edgesMap) {
421 for(
auto &it1 : it0.second) {
422 edges[q++] = it0.first;
423 edges[q++] = it1.first;
424 edges[q++] = it1.second;
432 std::stringstream msg;
433 msg <<
"done (#" << nEdges <<
" in " << t.
getElapsedTime() <<
" s).";
boost::variant< double, float, long long, unsigned long long, long, unsigned long, int, unsigned int, short, unsigned short, char, signed char, unsigned char > labelTypeVariant
int computeOverlap(const float *pointCoordinates0, const float *pointCoordinates1, const labelType *pointLabels0, const labelType *pointLabels1, const size_t nPoints0, const size_t nPoints1, Edges &edges) const
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)