41 if (levelSet ==
nullptr) {
43 .addWarning(
"No level set was passed to FromMesh.")
47 if (mesh ==
nullptr) {
49 .addWarning(
"No Mesh<> was supplied to FromMesh.")
54 auto &domain = levelSet->getDomain();
55 auto &nodes = mesh->getNodes();
56 auto values = mesh->cellData.getScalarData(
"LSValues",
true);
58 if (values ==
nullptr) {
60 .addWarning(
"Mesh does not contain level set values (\"LSValues\").")
72 const hrleGrid<D> &grid = domain.getGrid();
73 const T gridDelta = grid.getGridDelta();
75 if (hrleVectorType<T, D>(nodes.front()) != grid.getMinGridPoint()) {
76 domain.insertNextUndefinedPoint(0, grid.getMinGridPoint(),
82 hrleVectorType<hrleIndexType, D> lastIndex(nodes.front());
83 for (
unsigned i = 0; i <
D; ++i) {
84 lastIndex[i] = nodes.front()[i] / gridDelta;
87 auto pointDataIt = nodes.begin();
88 auto pointDataEnd = nodes.end();
90 auto valueIt = values->begin();
91 auto valueEnd = values->end();
93 hrleVectorType<bool, D> signs(values->front() <=
94 -std::numeric_limits<T>::epsilon());
96 while (pointDataIt != pointDataEnd && valueIt != valueEnd) {
99 if (std::abs(*valueIt) > 2.5) {
105 bool setPoint =
true;
107 hrleVectorType<hrleIndexType, D> currentIndex;
108 for (
unsigned i = 0; i <
D; ++i) {
109 currentIndex[i] = std::round(pointDataIt->at(i) / gridDelta);
114 for (
unsigned i = 0; i <
D; ++i) {
115 if (grid.getBoundaryConditions(i) != hrleGrid<D>::INFINITE_BOUNDARY) {
116 if (currentIndex[i] > grid.getMaxBounds(i) ||
117 currentIndex[i] < grid.getMinBounds(i)) {
125 domain.insertNextDefinedPoint(0, currentIndex, *valueIt);
129 bool changeSign =
false;
130 for (
int i =
D - 1; i >= 0; --i) {
131 changeSign = changeSign || (currentIndex[i] > lastIndex[i]);
133 signs[i] = *valueIt <= -std::numeric_limits<T>::epsilon();
134 lastIndex[i] = currentIndex[i];
140 hrleVectorType<hrleIndexType, D> nextIndex;
146 if (pointDataIt == pointDataEnd) {
147 nextIndex = grid.getMaxGridPoint();
150 for (
unsigned i = 0; i <
D; ++i) {
151 nextIndex[i] = std::round(pointDataIt->at(i) / gridDelta);
158 for (
int q = 0; q <
D; q++) {
159 hrleVectorType<hrleIndexType, D> tmp = currentIndex;
161 if (tmp[q] > grid.getMaxGridPoint(q))
163 for (
int r = 0; r < q; ++r)
164 tmp[r] = grid.getMinGridPoint(r);
166 if (tmp >= nextIndex)
169 domain.insertNextUndefinedPoint(0, tmp,