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();
155 for (
unsigned i = 0; i < AData.getScalarDataSize(); ++i) {
156 auto scalarDataLabel = AData.getScalarDataLabel(i);
157 auto BPointer = BData.getScalarData(scalarDataLabel,
true);
158 if (BPointer !=
nullptr) {
159 auto APointer = AData.getScalarData(i);
162 scalars.resize(newlsDomain->getNumberOfPoints());
163 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
164 scalars[j] = (newDataLS[0][j])
165 ? APointer->at(newDataSourceIds[0][j])
166 : BPointer->at(newDataSourceIds[0][j]);
168 newData.insertNextScalarData(scalars, scalarDataLabel);
173 for (
unsigned i = 0; i < AData.getVectorDataSize(); ++i) {
174 auto vectorDataLabel = AData.getVectorDataLabel(i);
175 auto BPointer = BData.getVectorData(vectorDataLabel,
true);
176 if (BPointer !=
nullptr) {
177 auto APointer = AData.getVectorData(i);
180 vectors.resize(newlsDomain->getNumberOfPoints());
181 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
182 vectors[j] = (newDataLS[0][j])
183 ? APointer->at(newDataSourceIds[0][j])
184 : BPointer->at(newDataSourceIds[0][j]);
186 newData.insertNextVectorData(vectors, vectorDataLabel);
197 pruner.setRemoveStrayZeros(
true);
204 levelSetA->deepCopy(newlsDomain);
208 auto &hrleDomain = levelSetA->getDomain();
209#pragma omp parallel num_threads(hrleDomain.getNumberOfSegments())
213 p = omp_get_thread_num();
215 auto &domainSegment = hrleDomain.getDomainSegment(p);
218 for (
unsigned i = 0; i < domainSegment.definedValues.size(); ++i) {
219 domainSegment.definedValues[i] = -domainSegment.definedValues[i];
223 if (domainSegment.undefinedValues.size() < 1) {
226 if (domainSegment.undefinedValues.size() < 2) {
237 for (
unsigned dim = 0; dim <
D; ++dim) {
238 for (
unsigned c = 0; c < domainSegment.runTypes[dim].size(); ++c) {
239 if (domainSegment.runTypes[dim][c] ==
240 viennahrle::RunTypeValues::UNDEF_PT) {
241 domainSegment.runTypes[dim][c] =
242 viennahrle::RunTypeValues::UNDEF_PT + 1;
243 }
else if (domainSegment.runTypes[dim][c] ==
244 viennahrle::RunTypeValues::UNDEF_PT + 1) {
245 domainSegment.runTypes[dim][c] =
246 viennahrle::RunTypeValues::UNDEF_PT;
251 levelSetA->finalize();
254 static std::pair<T, bool> minComp(
const T &a,
const T &b) {
255 bool AIsSmaller = a < b;
257 return std::make_pair(a,
true);
259 return std::make_pair(b,
false);
262 static std::pair<T, bool> maxComp(
const T &a,
const T &b) {
263 bool AIsLarger = a > b;
265 return std::make_pair(a,
true);
267 return std::make_pair(b,
false);
270 static std::pair<T, bool> relativeComplementComp(
const T &a,
const T &b) {
271 return maxComp(a, -b);
280 : levelSetA(passedlsDomain), operation(passedOperation) {}
286 : levelSetA(passedlsDomainA), levelSetB(passedlsDomainB),
287 operation(passedOperation){};
291 levelSetA = passedlsDomain;
297 levelSetB = passedlsDomain;
302 operation = passedOperation;
308 operationComp = passedOperationComp;
320 if (levelSetA ==
nullptr) {
321 VIENNACORE_LOG_ERROR(
"No level set was passed to BooleanOperation.");
325 if (
static_cast<unsigned>(operation) < 3) {
326 if (levelSetB ==
nullptr) {
327 VIENNACORE_LOG_ERROR(
328 "Only one level set was passed to BooleanOperation, "
329 "although two were required.");
336 booleanOpInternal(&BooleanOperation::maxComp);
339 booleanOpInternal(&BooleanOperation::minComp);
342 booleanOpInternal(&BooleanOperation::relativeComplementComp);
348 if (operationComp ==
nullptr) {
349 VIENNACORE_LOG_ERROR(
350 "No comparator supplied to custom BooleanOperation.");
353 booleanOpInternal(operationComp);
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:28
viennahrle::Domain< T, D > DomainType
Definition lsDomain.hpp:33
static constexpr T NEG_VALUE
Definition lsDomain.hpp:53
unsigned getNumberOfSegments() const
returns the number of segments, the levelset is split into. This is useful for algorithm parallelisat...
Definition lsDomain.hpp:154
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:118
static constexpr T POS_VALUE
Definition lsDomain.hpp:52