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 for
80 auto &domainSegment = newDomain.getDomainSegment(p);
82 viennahrle::Index<D> currentVector =
83 (p == 0) ? grid.getMinGridPoint()
84 : newDomain.getSegmentation()[p - 1];
86 viennahrle::Index<D>
const endVector =
88 ? newDomain.getSegmentation()[p]
89 : grid.incrementIndices(grid.getMaxGridPoint());
91 viennahrle::ConstSparseIterator<hrleDomainType> itA(
92 levelSetA->getDomain(), currentVector);
93 viennahrle::ConstSparseIterator<hrleDomainType> itB(
94 levelSetB->getDomain(), currentVector);
96 while (currentVector < endVector) {
97 const auto &comparison = comp(itA.getValue(), itB.getValue());
98 const auto ¤tValue = comparison.first;
102 domainSegment.insertNextDefinedPoint(currentVector, currentValue);
105 const bool originLS = comparison.second;
106 newDataLS[p].push_back(originLS);
107 const auto originPointId =
108 (originLS) ? itA.getPointId() : itB.getPointId();
109 newDataSourceIds[p].push_back(originPointId);
112 domainSegment.insertNextUndefinedPoint(
117 switch (Compare(itA.getEndIndices(), itB.getEndIndices())) {
127 Max(itA.getStartIndices().get(), itB.getStartIndices().get());
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();
156 for (
unsigned i = 0; i < AData.getScalarDataSize(); ++i) {
157 auto scalarDataLabel = AData.getScalarDataLabel(i);
158 auto APointer = AData.getScalarData(i);
160 BData.getScalarData(scalarDataLabel,
true);
162 scalars.resize(newlsDomain->getNumberOfPoints(),
T(0));
163 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
165 scalars[j] = APointer->at(newDataSourceIds[0][j]);
166 else if (BPointer !=
nullptr)
167 scalars[j] = BPointer->at(newDataSourceIds[0][j]);
170 newData.insertNextScalarData(scalars, scalarDataLabel);
174 for (
unsigned i = 0; i < AData.getVectorDataSize(); ++i) {
175 auto vectorDataLabel = AData.getVectorDataLabel(i);
176 auto APointer = AData.getVectorData(i);
178 BData.getVectorData(vectorDataLabel,
true);
182 vectors.resize(newlsDomain->getNumberOfPoints(), Vec{});
183 for (
unsigned j = 0; j < newlsDomain->getNumberOfPoints(); ++j) {
185 vectors[j] = APointer->at(newDataSourceIds[0][j]);
186 else if (BPointer !=
nullptr)
187 vectors[j] = BPointer->at(newDataSourceIds[0][j]);
191 newData.insertNextVectorData(vectors, vectorDataLabel);
201 pruner.setRemoveStrayZeros(
true);
208 levelSetA->deepCopy(newlsDomain);
212 auto &hrleDomain = levelSetA->getDomain();
213#pragma omp parallel for
214 for (
unsigned p = 0; p < hrleDomain.getNumberOfSegments(); ++p) {
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: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
void setLevelSetWidth(int width)
Definition lsDomain.hpp:160