5#include <hrleSparseStarIterator.hpp>
6#include <hrleVectorType.hpp>
11using namespace viennacore;
16template <
class T,
int D>
class Reduce {
18 SmartPointer<Domain<T, D>> levelSet =
nullptr;
20 bool noNewSegment =
false;
21 bool updatePointData =
true;
27 : levelSet(passedlsDomain){};
30 bool passedNoNewSegment =
false)
31 : levelSet(passedlsDomain), width(passedWidth),
32 noNewSegment(passedNoNewSegment){};
35 levelSet = passedlsDomain;
41 void setWidth(
int passedWidth) { width = passedWidth; }
47 noNewSegment = passedNoNewSegment;
58 if (levelSet ==
nullptr) {
60 .addWarning(
"No level set was passed to Reduce.")
65 if (width >= levelSet->getLevelSetWidth())
68 const T valueLimit = width * 0.5;
70 auto &grid = levelSet->getGrid();
71 auto newlsDomain = SmartPointer<Domain<T, D>>::New(levelSet->getGrid());
76 newDomain.initialize(domain.getSegmentation(), domain.getAllocation());
78 newDomain.initialize(domain.getNewSegmentation(), domain.getAllocation());
80 const bool updateData = updatePointData;
83 std::vector<std::vector<unsigned>> newDataSourceIds;
87#pragma omp parallel num_threads(newDomain.getNumberOfSegments())
91 p = omp_get_thread_num();
94 auto &domainSegment = newDomain.getDomainSegment(p);
96 hrleVectorType<hrleIndexType, D> startVector =
97 (p == 0) ? grid.getMinGridPoint()
98 : newDomain.getSegmentation()[p - 1];
100 hrleVectorType<hrleIndexType, D> endVector =
102 ? newDomain.getSegmentation()[p]
103 : grid.incrementIndices(grid.getMaxGridPoint());
106 domain, startVector);
107 it.getStartIndices() < endVector; ++it) {
108 T currentValue = it.getValue();
109 if (it.isDefined() && std::abs(currentValue) <= valueLimit) {
110 domainSegment.insertNextDefinedPoint(it.getStartIndices(),
113 newDataSourceIds[p].push_back(it.getPointId());
116 domainSegment.insertNextUndefinedPoint(it.getStartIndices(),
126 newlsDomain->getPointData().translateFromMultiData(
127 levelSet->getPointData(), newDataSourceIds);
135 levelSet->finalize(width);
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:28
hrleGrid< D > GridType
Definition lsDomain.hpp:32
void deepCopy(const SmartPointer< Domain< T, D > > passedDomain)
copy all values of "passedDomain" to this Domain
Definition lsDomain.hpp:121
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
Reduce the level set size to the specified width. This means all level set points with value <= 0....
Definition lsReduce.hpp:16
Reduce(SmartPointer< Domain< T, D > > passedlsDomain, int passedWidth, bool passedNoNewSegment=false)
Definition lsReduce.hpp:29
void apply()
Reduces the leveleSet to the specified number of layers. The largest value in the levelset is thus wi...
Definition lsReduce.hpp:57
void setUpdatePointData(bool update)
Set whether to update the point data stored in the LS during this algorithm. Defaults to true.
Definition lsReduce.hpp:52
void setLevelSet(SmartPointer< Domain< T, D > > passedlsDomain)
Definition lsReduce.hpp:34
Reduce()
Definition lsReduce.hpp:24
void setWidth(int passedWidth)
Set which level set points should be kept. All points with a level set value >0.5*width will be remov...
Definition lsReduce.hpp:41
void setNoNewSegment(bool passedNoNewSegment)
Set whether to segment the level set after algorithm is finished. This means points will be evenly di...
Definition lsReduce.hpp:46
Reduce(SmartPointer< Domain< T, D > > passedlsDomain)
Definition lsReduce.hpp:26
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:46
double T
Definition pyWrap.cpp:63