45 if (levelSet ==
nullptr) {
47 .addWarning(
"No level set passed to Expand. Not expanding.")
52 if (width <= levelSet->getLevelSetWidth())
55 if (levelSet->getNumberOfPoints() == 0)
58 const T totalLimit = width * 0.5;
59 const int startWidth = levelSet->getLevelSetWidth();
60 const int numberOfRequiredCycles = width - startWidth;
62 for (
int currentCycle = 0; currentCycle < numberOfRequiredCycles;
65 const int allocationFactor =
66 1 + 1.0 /
static_cast<double>(startWidth + currentCycle);
67 const T limit = (startWidth + currentCycle + 1) *
T(0.5);
69 auto &grid = levelSet->getGrid();
70 auto newlsDomain = SmartPointer<Domain<T, D>>::New(grid);
74 newDomain.initialize(domain.getNewSegmentation(),
75 domain.getAllocation() * allocationFactor);
77 const bool updateData = updatePointData;
80 std::vector<std::vector<unsigned>> newDataSourceIds;
84#pragma omp parallel num_threads(newDomain.getNumberOfSegments())
88 p = omp_get_thread_num();
91 auto &domainSegment = newDomain.getDomainSegment(p);
93 hrleVectorType<hrleIndexType, D> startVector =
94 (p == 0) ? grid.getMinGridPoint()
95 : newDomain.getSegmentation()[p - 1];
97 hrleVectorType<hrleIndexType, D> endVector =
99 ? newDomain.getSegmentation()[p]
100 : grid.incrementIndices(grid.getMaxGridPoint());
103 neighborIt(domain, startVector);
104 neighborIt.getIndices() < endVector; neighborIt.next()) {
106 auto ¢erIt = neighborIt.getCenter();
107 if (std::abs(centerIt.getValue()) <= totalLimit) {
108 domainSegment.insertNextDefinedPoint(neighborIt.getIndices(),
109 centerIt.getValue());
111 newDataSourceIds[p].push_back(centerIt.getPointId());
113 if (centerIt.getValue() > -std::numeric_limits<T>::epsilon()) {
116 for (
int i = 0; i < 2 *
D; i++) {
117 T newValue = neighborIt.getNeighbor(i).getValue() +
T(1);
118 if (distance > newValue) {
123 if (distance <= limit) {
124 domainSegment.insertNextDefinedPoint(neighborIt.getIndices(),
127 newDataSourceIds[p].push_back(
128 neighborIt.getNeighbor(neighbor).getPointId());
131 domainSegment.insertNextUndefinedPoint(neighborIt.getIndices(),
137 for (
int i = 0; i < 2 *
D; i++) {
138 T newValue = neighborIt.getNeighbor(i).getValue() -
T(1);
139 if (distance < newValue) {
144 if (distance >= -limit) {
145 domainSegment.insertNextDefinedPoint(neighborIt.getIndices(),
148 newDataSourceIds[p].push_back(
149 neighborIt.getNeighbor(neighbor).getPointId());
152 domainSegment.insertNextUndefinedPoint(neighborIt.getIndices(),
162 newlsDomain->getPointData().translateFromMultiData(
163 levelSet->getPointData(), newDataSourceIds);
167 levelSet->deepCopy(newlsDomain);
169 levelSet->getDomain().segment();
170 levelSet->finalize(width);