| 83 | } |
| 84 | |
| 85 | Expected<std::vector<VertBitSet>> getLargeComponents( const PointCloud& pointCloud, float maxDist, int minSize, ProgressCallback pc /*= {} */ ) |
| 86 | { |
| 87 | MR_TIMER; |
| 88 | |
| 89 | assert( maxDist > 0.f ); |
| 90 | assert( minSize > 1 ); |
| 91 | const auto& validPoints = pointCloud.validPoints; |
| 92 | ProgressCallback subPc = subprogress( pc, 0.f, 0.9f ); |
| 93 | auto unionStructsRes = getUnionFindStructureVerts( pointCloud, maxDist, nullptr, subPc ); |
| 94 | if ( !unionStructsRes.has_value() ) |
| 95 | return unexpectedOperationCanceled(); |
| 96 | auto& unionStructs = *unionStructsRes; |
| 97 | const auto& allRoots = unionStructs.roots(); |
| 98 | |
| 99 | subPc = subprogress( pc, 0.9f, 0.95f ); |
| 100 | int counter = 0; |
| 101 | const float counterMax = float( validPoints.count() ); |
| 102 | const int counterDivider = std::max( 1, int( validPoints.count() ) / 100 ); |
| 103 | HashMap<VertId, int> root2size; |
| 104 | for ( auto v : validPoints ) |
| 105 | { |
| 106 | ++root2size[allRoots[v]]; |
| 107 | if ( !reportProgress( subPc, counter / counterMax, counter, counterDivider ) ) |
| 108 | return unexpectedOperationCanceled(); |
| 109 | } |
| 110 | |
| 111 | subPc = subprogress( pc, 0.95f, 1.f ); |
| 112 | counter = 0; |
| 113 | std::vector<VertBitSet> result; |
| 114 | HashMap<VertId, size_t> root2index; |
| 115 | const size_t validPointsSize = validPoints.find_last() + 1; |
| 116 | for ( auto v : validPoints ) |
| 117 | { |
| 118 | const VertId root = allRoots[v]; |
| 119 | if ( root2size[root] >= minSize ) |
| 120 | { |
| 121 | auto [it, inserted] = root2index.insert( { root, result.size() } ); |
| 122 | if ( inserted ) |
| 123 | { |
| 124 | result.push_back( VertBitSet( validPointsSize ) ); |
| 125 | } |
| 126 | result[it->second].set( v ); |
| 127 | } |
| 128 | if ( !reportProgress( subPc, counter / counterMax, counter, counterDivider ) ) |
| 129 | return unexpectedOperationCanceled(); |
| 130 | } |
| 131 | |
| 132 | return result; |
| 133 | } |
| 134 | |
| 135 | Expected<std::pair<std::vector<VertBitSet>, int>> getAllComponents( const PointCloud& pointCloud, float maxDist, |
| 136 | int maxComponentCount /*= INT_MAX*/, ProgressCallback pc /*= {} */ ) |
nothing calls this directly
no test coverage detected