48 std::function<std::pair<T, bool>(
const T &,
const T &)>;
52 SmartPointer<Domain<T, D>> levelSetA =
nullptr;
53 SmartPointer<Domain<T, D>> levelSetB =
nullptr;
56 bool updatePointData =
true;
57 bool pruneResult =
true;
60 auto &grid = levelSetA->getGrid();
61 auto newlsDomain = SmartPointer<Domain<T, D>>::New(grid);
65 newDomain.initialize(domain.getNewSegmentation(), domain.getAllocation());
67 const bool updateData = updatePointData;
70 std::vector<std::vector<unsigned>> newDataSourceIds;
71 std::vector<std::vector<bool>> newDataLS;
74 newDataLS.resize(newDataSourceIds.size());
77#pragma omp parallel num_threads(newDomain.getNumberOfSegments())
81 p = omp_get_thread_num();
84 auto &domainSegment = newDomain.getDomainSegment(p);
86 viennahrle::Index<D> currentVector =
87 (p == 0) ? grid.getMinGridPoint()
88 : newDomain.getSegmentation()[p - 1];
90 viennahrle::Index<D>
const endVector =
92 ? newDomain.getSegmentation()[p]
93 : grid.incrementIndices(grid.getMaxGridPoint());
95 viennahrle::ConstSparseIterator<hrleDomainType> itA(
96 levelSetA->getDomain(), currentVector);
97 viennahrle::ConstSparseIterator<hrleDomainType> itB(
98 levelSetB->getDomain(), currentVector);
100 while (currentVector < endVector) {
101 const auto &comparison = comp(itA.getValue(), itB.getValue());
102 const auto ¤tValue = comparison.first;
106 domainSegment.insertNextDefinedPoint(currentVector, currentValue);
109 const bool originLS = comparison.second;
110 newDataLS[p].push_back(originLS);
111 const auto originPointId =
112 (originLS) ? itA.getPointId() : itB.getPointId();
113 newDataSourceIds[p].push_back(originPointId);
116 domainSegment.insertNextUndefinedPoint(
121 switch (Compare(itA.getEndIndices(), itB.getEndIndices())) {
131 Max(itA.getStartIndices().get(), itB.getStartIndices().get());
136 for (
unsigned i = 1; i < newDataLS.size(); ++i) {
137 newDataLS[0].insert(newDataLS[0].end(), newDataLS[i].begin(),
140 newDataSourceIds[0].insert(newDataSourceIds[0].end(),
141 newDataSourceIds[i].begin(),
142 newDataSourceIds[i].end());
150 const auto &AData = levelSetA->getPointData();
151 const auto &BData = levelSetB->getPointData();
152 auto &newData = newlsDomain->getPointData();
160 for (
unsigned i = 0; i < AData.getScalarDataSize(); ++i) {
161 auto scalarDataLabel = AData.getScalarDataLabel(i);
162 auto APointer = AData.getScalarData(i);
164 BData.getScalarData(scalarDataLabel,
true);
166 scalars.resize(newlsDomain->getNumberOfPoints(),
T(0));
167 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
169 scalars[j] = APointer->at(newDataSourceIds[0][j]);
170 else if (BPointer !=
nullptr)
171 scalars[j] = BPointer->at(newDataSourceIds[0][j]);
174 newData.insertNextScalarData(scalars, scalarDataLabel);
178 for (
unsigned i = 0; i < AData.getVectorDataSize(); ++i) {
179 auto vectorDataLabel = AData.getVectorDataLabel(i);
180 auto APointer = AData.getVectorData(i);
182 BData.getVectorData(vectorDataLabel,
true);
186 vectors.resize(newlsDomain->getNumberOfPoints(), Vec{});
187 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
189 vectors[j] = APointer->at(newDataSourceIds[0][j]);
190 else if (BPointer !=
nullptr)
191 vectors[j] = BPointer->at(newDataSourceIds[0][j]);
195 newData.insertNextVectorData(vectors, vectorDataLabel);
205 pruner.setRemoveStrayZeros(
true);
212 levelSetA->deepCopy(newlsDomain);
216 auto &hrleDomain = levelSetA->getDomain();
217#pragma omp parallel num_threads(hrleDomain.getNumberOfSegments())
221 p = omp_get_thread_num();
223 auto &domainSegment = hrleDomain.getDomainSegment(p);
226 for (
unsigned i = 0; i < domainSegment.definedValues.size(); ++i) {
227 domainSegment.definedValues[i] = -domainSegment.definedValues[i];
231 if (domainSegment.undefinedValues.size() < 1) {
234 if (domainSegment.undefinedValues.size() < 2) {
245 for (
unsigned dim = 0; dim <
D; ++dim) {
246 for (
unsigned c = 0; c < domainSegment.runTypes[dim].size(); ++c) {
247 if (domainSegment.runTypes[dim][c] ==
248 viennahrle::RunTypeValues::UNDEF_PT) {
249 domainSegment.runTypes[dim][c] =
250 viennahrle::RunTypeValues::UNDEF_PT + 1;
251 }
else if (domainSegment.runTypes[dim][c] ==
252 viennahrle::RunTypeValues::UNDEF_PT + 1) {
253 domainSegment.runTypes[dim][c] =
254 viennahrle::RunTypeValues::UNDEF_PT;
259 levelSetA->finalize();
262 static std::pair<T, bool> minComp(
const T &a,
const T &b) {
263 bool AIsSmaller = a < b;
265 return std::make_pair(a,
true);
267 return std::make_pair(b,
false);
270 static std::pair<T, bool> maxComp(
const T &a,
const T &b) {
271 bool AIsLarger = a > b;
273 return std::make_pair(a,
true);
275 return std::make_pair(b,
false);
278 static std::pair<T, bool> relativeComplementComp(
const T &a,
const T &b) {
279 return maxComp(a, -b);
288 : levelSetA(passedlsDomain), operation(passedOperation) {}
294 : levelSetA(passedlsDomainA), levelSetB(passedlsDomainB),
295 operation(passedOperation){};
299 levelSetA = passedlsDomain;
305 levelSetB = passedlsDomain;
310 operation = passedOperation;
316 operationComp = passedOperationComp;
328 if (levelSetA ==
nullptr) {
329 VIENNACORE_LOG_ERROR(
"No level set was passed to BooleanOperation.");
333 if (
static_cast<unsigned>(operation) < 3) {
334 if (levelSetB ==
nullptr) {
335 VIENNACORE_LOG_ERROR(
336 "Only one level set was passed to BooleanOperation, "
337 "although two were required.");
344 booleanOpInternal(&BooleanOperation::maxComp);
347 booleanOpInternal(&BooleanOperation::minComp);
350 booleanOpInternal(&BooleanOperation::relativeComplementComp);
356 if (operationComp ==
nullptr) {
357 VIENNACORE_LOG_ERROR(
358 "No comparator supplied to custom BooleanOperation.");
361 booleanOpInternal(operationComp);
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:27
viennahrle::Domain< T, D > DomainType
Definition lsDomain.hpp:32
static constexpr T NEG_VALUE
Definition lsDomain.hpp:52
unsigned getNumberOfSegments() const
returns the number of segments, the levelset is split into. This is useful for algorithm parallelisat...
Definition lsDomain.hpp:153
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:117
static constexpr T POS_VALUE
Definition lsDomain.hpp:51