157 std::vector<std::vector<std::vector<IndexType>>> componentList(
158 domain->getNumberOfSegments());
159 for (
unsigned segmentId = 0; segmentId < domain->getNumberOfSegments();
161 componentList[segmentId].resize(
D + 1);
162 for (
int dim = -1; dim <
D; ++dim) {
163 componentList[segmentId][dim + 1].resize(
164 domain->getDomain().getNumberOfRuns(segmentId, dim), -1);
168 std::size_t numberOfComponents = 0;
169 std::vector<IndexType> pointsPerComponent;
173 neighborIt(domain->getDomain());
174 !neighborIt.isFinished(); neighborIt.next()) {
175 auto ¢er = neighborIt.getCenter();
178 auto ¤tComponentId =
179 componentList[center.getSegmentId()][center.getLevel()]
180 [center.getRunTypePosition()];
183 if (currentComponentId == -1) {
184 for (
int k = 0; k < 2 *
D; ++k) {
185 auto &neighbor = neighborIt.getNeighbor(k);
186 const auto neighborComponentId =
187 componentList[neighbor.getSegmentId()][neighbor.getLevel()]
188 [neighbor.getRunTypePosition()];
192 if (neighborComponentId != -1) {
193 if (areConnected(center.getValue(), neighbor.getValue())) {
194 currentComponentId = neighborComponentId;
195 if (center.getValue() >= 0.)
196 ++pointsPerComponent[currentComponentId];
204 if (currentComponentId == -1) {
205 currentComponentId = numberOfComponents;
206 pointsPerComponent.push_back((center.getValue() > 0.) ? 1 : 0);
208 ++numberOfComponents;
212 for (
int k = 0; k < 2 *
D; ++k) {
213 auto &neighbor = neighborIt.getNeighbor(k);
214 auto &neighborComponentId =
215 componentList[neighbor.getSegmentId()][neighbor.getLevel()]
216 [neighbor.getRunTypePosition()];
217 if (areConnected(center.getValue(), neighbor.getValue())) {
219 if (neighborComponentId != -1) {
221 if (currentComponentId != neighborComponentId) {
225 neighborComponentId = currentComponentId;
226 if (neighbor.getValue() >= 0.)
227 ++pointsPerComponent[neighborComponentId];
236 (reverseVoidDetection) ? components[0] : components.back();
240 auto pointsPerConnected =
241 mergeComponentCounts(components, pointsPerComponent);
244 if (detectLargestSurface) {
245 topComponent = calculateTopID(components, pointsPerConnected);
247 while (pointsPerConnected[topComponent] == 0) {
248 if (reverseVoidDetection)
256 std::vector<T> voidPointMarkers;
257 voidPointMarkers.resize(domain->getNumberOfPoints());
259 std::vector<T> componentMarkers;
261 componentMarkers.resize(domain->getNumberOfPoints());
265 neighborIt(domain->getDomain());
266 !neighborIt.isFinished(); neighborIt.next()) {
267 auto center = neighborIt.getCenter();
269 if (!center.isDefined())
273 if (center.getValue() >= 0) {
274 const int &oldComponentId = componentList[center.getSegmentId()][0]
275 [center.getRunTypePosition()];
276 voidPointMarkers[center.getPointId()] =
277 (components[oldComponentId] != topComponent);
283 for (k = 0; k < 2 *
D; ++k) {
284 auto &neighbor = neighborIt.getNeighbor(k);
285 if (std::signbit(neighbor.getValue()) ==
286 std::signbit(center.getValue()))
288 const int &oldneighborComponentId =
289 componentList[neighbor.getSegmentId()][neighbor.getLevel()]
290 [neighbor.getRunTypePosition()];
291 if (components[oldneighborComponentId] == topComponent) {
295 voidPointMarkers[center.getPointId()] = (k == 2 *
D);
298 if (saveComponents) {
299 const int &oldComponentId = componentList[center.getSegmentId()][0]
300 [center.getRunTypePosition()];
301 componentMarkers[center.getPointId()] = components[oldComponentId];
305 auto &pointData = domain->getPointData();
306 auto voidMarkersPointer = pointData.getScalarData(
voidPointLabel,
true);
308 if (voidMarkersPointer ==
nullptr) {
311 *voidMarkersPointer = std::move(voidPointMarkers);
314 if (saveComponents) {
315 auto componentMarkersPointer =
316 pointData.getScalarData(
"ConnectedComponentId",
true);
318 if (componentMarkersPointer ==
nullptr) {
319 pointData.insertNextScalarData(componentMarkers,
320 "ConnectedComponentId");
322 *componentMarkersPointer = std::move(componentMarkers);