81 if (levelSets.size() < 1) {
83 .addWarning(
"No Level Sets supplied to ToVoxelMesh! Not converting.")
86 if (mesh ==
nullptr) {
88 .addWarning(
"No mesh was passed to ToVoxelMesh.")
94 auto &levelSet = *(levelSets.back());
95 auto &grid = levelSet.getGrid();
100 for (
unsigned i = 0; i <
D; ++i) {
101 mesh->minimumExtent[i] = std::numeric_limits<T>::max();
102 mesh->maximumExtent[i] = std::numeric_limits<T>::lowest();
105 std::unordered_map<hrleVectorType<hrleIndexType, D>, size_t,
106 typename hrleVectorType<hrleIndexType, D>::hash>
108 size_t currentPointId = 0;
113 auto &materialIds = *(mesh->cellData.getScalarData(0));
114 const bool useMaterialMap = materialMap !=
nullptr;
117 std::vector<hrleConstDenseCellIterator<typename Domain<T, D>::DomainType>>
119 for (
auto it = levelSets.begin(); it != levelSets.end(); ++it) {
122 (*it)->getDomain(), minIndex));
127 unsigned counter = 0;
128 for (; iterators.front().getIndices() < maxIndex;
129 iterators.front().next()) {
131 for (
unsigned materialId = 0; materialId < levelSets.size();
134 auto &cellIt = iterators[materialId];
136 cellIt.goToIndicesSequential(iterators.front().getIndices());
140 for (
int i = 0; i < (1 <<
D); ++i) {
141 centerValue += cellIt.getCorner(i).getValue();
144 if (centerValue <= 0.) {
145 std::array<unsigned, 1 << D> voxel;
148 for (
unsigned i = 0; i < (1 <<
D); ++i) {
149 hrleVectorType<hrleIndexType, D> index;
151 for (
unsigned j = 0; j <
D; ++j) {
153 cellIt.getIndices(j) + cellIt.getCorner(i).getOffset()[j];
154 if (index[j] > maxIndex[j]) {
160 auto pointIdValue = std::make_pair(index, currentPointId);
161 auto pointIdPair = pointIdMapping.insert(pointIdValue);
162 voxel[i] = pointIdPair.first->second;
163 if (pointIdPair.second) {
173 int material = materialId;
175 material = materialMap->getMaterialId(materialId);
177 if constexpr (
D == 3) {
179 std::array<unsigned, 8> hexa{voxel[0], voxel[1], voxel[3],
180 voxel[2], voxel[4], voxel[5],
182 mesh->hexas.push_back(hexa);
183 materialIds.push_back(material);
185 std::array<unsigned, 4> tetra{voxel[0], voxel[2], voxel[3],
187 mesh->tetras.push_back(tetra);
188 materialIds.push_back(material);
198 double gridDelta = grid.getGridDelta();
199 mesh->nodes.resize(pointIdMapping.size());
200 for (
auto it = pointIdMapping.begin(); it != pointIdMapping.end(); ++it) {
201 std::array<T, 3> coords{};
202 for (
unsigned i = 0; i <
D; ++i) {
203 coords[i] = gridDelta * it->first[i];
206 if (coords[i] < mesh->minimumExtent[i]) {
207 mesh->minimumExtent[i] = coords[i];
208 }
else if (coords[i] > mesh->maximumExtent[i]) {
209 mesh->maximumExtent[i] = coords[i];
212 mesh->nodes[it->second] = coords;