49 SmartPointer<Domain<T, D>> levelSetA =
nullptr;
50 SmartPointer<Domain<T, D>> levelSetB =
nullptr;
53 bool updatePointData =
true;
54 bool pruneResult =
true;
57 auto &grid = levelSetA->getGrid();
58 auto newlsDomain = SmartPointer<Domain<T, D>>::New(grid);
62 newDomain.initialize(domain.getNewSegmentation(), domain.getAllocation());
64 const bool updateData = updatePointData;
67 std::vector<std::vector<unsigned>> newDataSourceIds;
68 std::vector<std::vector<bool>> newDataLS;
71 newDataLS.resize(newDataSourceIds.size());
74#pragma omp parallel num_threads(newDomain.getNumberOfSegments())
78 p = omp_get_thread_num();
81 auto &domainSegment = newDomain.getDomainSegment(p);
83 hrleVectorType<hrleIndexType, D> currentVector =
84 (p == 0) ? grid.getMinGridPoint()
85 : newDomain.getSegmentation()[p - 1];
87 hrleVectorType<hrleIndexType, D> endVector =
89 ? newDomain.getSegmentation()[p]
90 : grid.incrementIndices(grid.getMaxGridPoint());
92 hrleConstSparseIterator<hrleDomainType> itA(levelSetA->getDomain(),
94 hrleConstSparseIterator<hrleDomainType> itB(levelSetB->getDomain(),
97 while (currentVector < endVector) {
98 const auto &comparison = comp(itA.getValue(), itB.getValue());
99 const auto ¤tValue = comparison.first;
103 domainSegment.insertNextDefinedPoint(currentVector, currentValue);
106 const bool originLS = comparison.second;
107 newDataLS[p].push_back(originLS);
108 const auto originPointId =
109 (originLS) ? itA.getPointId() : itB.getPointId();
110 newDataSourceIds[p].push_back(originPointId);
113 domainSegment.insertNextUndefinedPoint(
118 switch (compare(itA.getEndIndices(), itB.getEndIndices())) {
127 currentVector = std::max(itA.getStartIndices(), itB.getStartIndices());
132 for (
unsigned i = 1; i < newDataLS.size(); ++i) {
133 newDataLS[0].insert(newDataLS[0].end(), newDataLS[i].begin(),
136 newDataSourceIds[0].insert(newDataSourceIds[0].end(),
137 newDataSourceIds[i].begin(),
138 newDataSourceIds[i].end());
146 const auto &AData = levelSetA->getPointData();
147 const auto &BData = levelSetB->getPointData();
148 auto &newData = newlsDomain->getPointData();
151 for (
unsigned i = 0; i < AData.getScalarDataSize(); ++i) {
152 auto scalarDataLabel = AData.getScalarDataLabel(i);
153 auto BPointer = BData.getScalarData(scalarDataLabel,
true);
154 if (BPointer !=
nullptr) {
155 auto APointer = AData.getScalarData(i);
158 scalars.resize(newlsDomain->getNumberOfPoints());
159 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
160 scalars[j] = (newDataLS[0][j])
161 ? APointer->at(newDataSourceIds[0][j])
162 : BPointer->at(newDataSourceIds[0][j]);
164 newData.insertNextScalarData(scalars, scalarDataLabel);
169 for (
unsigned i = 0; i < AData.getVectorDataSize(); ++i) {
170 auto vectorDataLabel = AData.getVectorDataLabel(i);
171 auto BPointer = BData.getVectorData(vectorDataLabel,
true);
172 if (BPointer !=
nullptr) {
173 auto APointer = AData.getVectorData(i);
176 vectors.resize(newlsDomain->getNumberOfPoints());
177 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
178 vectors[j] = (newDataLS[0][j])
179 ? APointer->at(newDataSourceIds[0][j])
180 : BPointer->at(newDataSourceIds[0][j]);
182 newData.insertNextVectorData(vectors, vectorDataLabel);
193 pruner.setRemoveStrayZeros(
true);
200 levelSetA->deepCopy(newlsDomain);
204 auto &hrleDomain = levelSetA->getDomain();
205#pragma omp parallel num_threads(hrleDomain.getNumberOfSegments())
209 p = omp_get_thread_num();
211 auto &domainSegment = hrleDomain.getDomainSegment(p);
214 for (
unsigned i = 0; i < domainSegment.definedValues.size(); ++i) {
215 domainSegment.definedValues[i] = -domainSegment.definedValues[i];
219 if (domainSegment.undefinedValues.size() < 1) {
222 if (domainSegment.undefinedValues.size() < 2) {
233 for (
unsigned dim = 0; dim <
D; ++dim) {
234 for (
unsigned c = 0; c < domainSegment.runTypes[dim].size(); ++c) {
235 if (domainSegment.runTypes[dim][c] == hrleRunTypeValues::UNDEF_PT) {
236 domainSegment.runTypes[dim][c] = hrleRunTypeValues::UNDEF_PT + 1;
237 }
else if (domainSegment.runTypes[dim][c] ==
238 hrleRunTypeValues::UNDEF_PT + 1) {
239 domainSegment.runTypes[dim][c] = hrleRunTypeValues::UNDEF_PT;
244 levelSetA->finalize();
247 static std::pair<T, bool> minComp(
const T &a,
const T &b) {
248 bool AIsSmaller = a < b;
250 return std::make_pair(a,
true);
252 return std::make_pair(b,
false);
255 static std::pair<T, bool> maxComp(
const T &a,
const T &b) {
256 bool AIsLarger = a > b;
258 return std::make_pair(a,
true);
260 return std::make_pair(b,
false);
263 static std::pair<T, bool> relativeComplementComp(
const T &a,
const T &b) {
264 return maxComp(a, -b);
273 : levelSetA(passedlsDomain), operation(passedOperation) {}
279 : levelSetA(passedlsDomainA), levelSetB(passedlsDomainB),
280 operation(passedOperation){};
284 levelSetA = passedlsDomain;
290 levelSetB = passedlsDomain;
295 operation = passedOperation;
301 operationComp = passedOperationComp;
313 if (levelSetA ==
nullptr) {
314 Logger::getInstance()
315 .addWarning(
"No level set was passed to BooleanOperation. Not "
316 "performing operation.")
321 if (
static_cast<unsigned>(operation) < 3) {
322 if (levelSetB ==
nullptr) {
323 Logger::getInstance()
324 .addWarning(
"Only one level set was passed to BooleanOperation, "
325 "although two were required. Not performing operation.")
333 booleanOpInternal(&BooleanOperation::maxComp);
336 booleanOpInternal(&BooleanOperation::minComp);
339 booleanOpInternal(&BooleanOperation::relativeComplementComp);
345 if (operationComp ==
nullptr) {
346 Logger::getInstance()
347 .addWarning(
"No comparator supplied to custom BooleanOperation. "
348 "Not performing operation.")
352 booleanOpInternal(operationComp);
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:28
static constexpr T NEG_VALUE
Definition lsDomain.hpp:55
unsigned getNumberOfSegments() const
returns the number of segments, the levelset is split into. This is useful for algorithm parallelisat...
Definition lsDomain.hpp:150
hrleDomain< T, D > DomainType
Definition lsDomain.hpp:33
void finalize(int newWidth)
this function sets a new levelset width and finalizes the levelset, so it is ready for use by other a...
Definition lsDomain.hpp:114
static constexpr T POS_VALUE
Definition lsDomain.hpp:54
void setLevelSetWidth(int width)
Definition lsDomain.hpp:157