5#include <vcVectorType.hpp>
9using namespace viennacore;
14template <
class T,
int D>
class Reduce {
16 SmartPointer<Domain<T, D>> levelSet =
nullptr;
18 bool noNewSegment =
false;
19 bool updatePointData =
true;
25 : levelSet(passedlsDomain){};
28 bool passedNoNewSegment =
false)
29 : levelSet(passedlsDomain), width(passedWidth),
30 noNewSegment(passedNoNewSegment){};
33 levelSet = passedlsDomain;
39 void setWidth(
int passedWidth) { width = passedWidth; }
45 noNewSegment = passedNoNewSegment;
56 if (levelSet ==
nullptr) {
58 .addWarning(
"No level set was passed to Reduce.")
63 if (width >= levelSet->getLevelSetWidth())
66 const T valueLimit = width * 0.5;
68 auto &grid = levelSet->getGrid();
69 auto newlsDomain = SmartPointer<Domain<T, D>>::New(levelSet->getGrid());
74 newDomain.initialize(domain.getSegmentation(), domain.getAllocation());
76 newDomain.initialize(domain.getNewSegmentation(), domain.getAllocation());
78 const bool updateData = updatePointData;
81 std::vector<std::vector<unsigned>> newDataSourceIds;
85#pragma omp parallel num_threads(newDomain.getNumberOfSegments())
89 p = omp_get_thread_num();
92 auto &domainSegment = newDomain.getDomainSegment(p);
94 viennahrle::Index<D>
const startVector =
95 (p == 0) ? grid.getMinGridPoint()
96 : newDomain.getSegmentation()[p - 1];
98 viennahrle::Index<D>
const endVector =
100 ? newDomain.getSegmentation()[p]
101 : grid.incrementIndices(grid.getMaxGridPoint());
104 domain, startVector);
105 it.getStartIndices() < endVector; ++it) {
106 T currentValue = it.getValue();
107 if (it.isDefined() && std::abs(currentValue) <= valueLimit) {
108 domainSegment.insertNextDefinedPoint(it.getStartIndices(),
111 newDataSourceIds[p].push_back(it.getPointId());
114 domainSegment.insertNextUndefinedPoint(it.getStartIndices(),
124 newlsDomain->getPointData().translateFromMultiData(
125 levelSet->getPointData(), newDataSourceIds);
133 levelSet->finalize(width);
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
viennahrle::Grid< D > GridType
Definition lsDomain.hpp:31
static constexpr T NEG_VALUE
Definition lsDomain.hpp:52
void deepCopy(const SmartPointer< Domain< T, D > > passedDomain)
copy all values of "passedDomain" to this Domain
Definition lsDomain.hpp:119
unsigned getNumberOfSegments() const
returns the number of segments, the levelset is split into. This is useful for algorithm parallelisat...
Definition lsDomain.hpp:148
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:112
static constexpr T POS_VALUE
Definition lsDomain.hpp:51
Reduce(SmartPointer< Domain< T, D > > passedlsDomain, int passedWidth, bool passedNoNewSegment=false)
Definition lsReduce.hpp:27
void apply()
Reduces the leveleSet to the specified number of layers. The largest value in the levelset is thus wi...
Definition lsReduce.hpp:55
void setUpdatePointData(bool update)
Set whether to update the point data stored in the LS during this algorithm. Defaults to true.
Definition lsReduce.hpp:50
void setLevelSet(SmartPointer< Domain< T, D > > passedlsDomain)
Definition lsReduce.hpp:32
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:39
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:44
Reduce(SmartPointer< Domain< T, D > > passedlsDomain)
Definition lsReduce.hpp:24
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:36
double T
Definition pyWrap.cpp:68