ViennaLS
Loading...
Searching...
No Matches
lsRemoveStrayPoints.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <lsDomain.hpp>
5
6namespace viennals {
7
8using namespace viennacore;
9
17template <class T, int D> class RemoveStrayPoints {
18 SmartPointer<Domain<T, D>> levelSet = nullptr;
20
21public:
23
24 RemoveStrayPoints(SmartPointer<Domain<T, D>> passedLevelSet)
25 : levelSet(passedLevelSet) {}
26
27 void setLevelSet(SmartPointer<Domain<T, D>> passedLevelSet) {
28 levelSet = passedLevelSet;
29 }
30
34 voidTopSurface = topSurface;
35 }
36
37 void apply() {
38 if (levelSet == nullptr) {
39 Logger::getInstance()
40 .addWarning("No level set was passed to lsPrune.")
41 .print();
42 return;
43 }
44 if (levelSet->getNumberOfPoints() == 0) {
45 return;
46 }
47
48 // Mark which points are voids
49 {
51 marker.setLevelSet(levelSet);
52 marker.setVoidTopSurface(voidTopSurface);
53 marker.apply();
54 }
55
56 auto voidMarkers =
57 levelSet->getPointData().getScalarData("VoidPointMarkers", true);
58 if (voidMarkers == nullptr) {
59 Logger::getInstance()
60 .addWarning("RemoveStrayPoints: No scalar data for void point "
61 "markers found. Cannot remove stray points.")
62 .print();
63 }
64
65 // now iterate through the domain and remove points which are void points
66 auto &grid = levelSet->getGrid();
67 auto newlsDomain = SmartPointer<Domain<T, D>>::New(grid);
68 typename Domain<T, D>::DomainType &newDomain = newlsDomain->getDomain();
69 typename Domain<T, D>::DomainType &domain = levelSet->getDomain();
70
71 newDomain.initialize(domain.getNewSegmentation(), domain.getAllocation());
72
73 std::vector<typename Domain<T, D>::PointValueVectorType> newPoints;
74 newPoints.resize(newDomain.getNumberOfSegments());
75
76#pragma omp parallel num_threads(newDomain.getNumberOfSegments())
77 {
78 int p = 0;
79#ifdef _OPENMP
80 p = omp_get_thread_num();
81#endif
82
83 auto &domainSegment = newDomain.getDomainSegment(p);
84
85 hrleVectorType<hrleIndexType, D> startVector =
86 (p == 0) ? grid.getMinGridPoint()
87 : newDomain.getSegmentation()[p - 1];
88
89 hrleVectorType<hrleIndexType, D> endVector =
90 (p != static_cast<int>(newDomain.getNumberOfSegments() - 1))
91 ? newDomain.getSegmentation()[p]
92 : grid.incrementIndices(grid.getMaxGridPoint());
93
94 for (hrleConstSparseIterator<typename Domain<T, D>::DomainType> it(
95 domain, startVector);
96 it.getStartIndices() < endVector; it.next()) {
97 if (it.isDefined() && !voidMarkers->at(it.getPointId())) {
98 newPoints[p].push_back(
99 std::make_pair(it.getStartIndices(), it.getValue()));
100 }
101 }
102 }
103
104 // merge points
105 for (unsigned i = 1; i < newDomain.getNumberOfSegments(); ++i) {
106 newPoints[0].insert(newPoints[0].end(), newPoints[i].begin(),
107 newPoints[i].end());
108 }
109
110 newlsDomain->insertPoints(newPoints[0]);
111
112 // distribute evenly across segments and copy
113 newDomain.finalize();
114 newDomain.segment();
115 levelSet->deepCopy(newlsDomain);
116 levelSet->finalize(2);
117 }
118};
119
120} // namespace viennals
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:28
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
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
hrleDomain< T, D > DomainType
Definition lsDomain.hpp:33
void insertPoints(PointValueVectorType pointData, bool sort=true)
re-initalise Domain with the point/value pairs in pointData This is similar to lsFromMesh with the di...
Definition lsDomain.hpp:132
This class is used to mark points of the level set which are enclosed in a void.
Definition lsMarkVoidPoints.hpp:30
void setLevelSet(SmartPointer< Domain< T, D > > passedlsDomain)
Definition lsMarkVoidPoints.hpp:95
void apply()
Definition lsMarkVoidPoints.hpp:154
void setVoidTopSurface(VoidTopSurfaceEnum topSurface)
Set which connected component to use as the top surface and mark all other components as void points.
Definition lsMarkVoidPoints.hpp:119
This algorithm can be used to remove all LS values which are not part of a so-called top surface....
Definition lsRemoveStrayPoints.hpp:17
void setVoidTopSurface(VoidTopSurfaceEnum topSurface)
Set how the algorithm should pick the surface which will not be removed. Defaults to the surface with...
Definition lsRemoveStrayPoints.hpp:33
RemoveStrayPoints()
Definition lsRemoveStrayPoints.hpp:22
RemoveStrayPoints(SmartPointer< Domain< T, D > > passedLevelSet)
Definition lsRemoveStrayPoints.hpp:24
void apply()
Definition lsRemoveStrayPoints.hpp:37
void setLevelSet(SmartPointer< Domain< T, D > > passedLevelSet)
Definition lsRemoveStrayPoints.hpp:27
Definition lsAdvect.hpp:46
VoidTopSurfaceEnum
Enumeration describing which connected component to use as top surface during void point detection....
Definition lsMarkVoidPoints.hpp:21