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<viennahrle::Index<D>, size_t,
106 typename viennahrle::Index<D>::hash>
108 size_t currentPointId = 0;
113 auto &materialIds = *(mesh->cellData.getScalarData(0));
114 const bool useMaterialMap = materialMap !=
nullptr;
118 viennahrle::ConstDenseCellIterator<typename Domain<T, D>::DomainType>>
120 for (
auto it = levelSets.begin(); it != levelSets.end(); ++it) {
121 iterators.emplace_back((*it)->getDomain(), minIndex);
126 for (; iterators.front().getIndices() < maxIndex;
127 iterators.front().next()) {
129 for (
unsigned materialId = 0; materialId < levelSets.size();
132 auto &cellIt = iterators[materialId];
134 cellIt.goToIndicesSequential(iterators.front().getIndices());
138 for (
int i = 0; i < (1 <<
D); ++i) {
139 centerValue += cellIt.getCorner(i).getValue();
142 if (centerValue <= 0.) {
143 std::array<unsigned, 1 << D> voxel;
144 bool addVoxel =
false;
146 for (
unsigned i = 0; i < (1 <<
D); ++i) {
147 viennahrle::Index<D> index;
149 for (
unsigned j = 0; j <
D; ++j) {
151 cellIt.getIndices(j) + cellIt.getCorner(i).getOffset()[j];
152 if (index[j] > maxIndex[j]) {
158 auto pointIdValue = std::make_pair(index, currentPointId);
159 auto pointIdPair = pointIdMapping.insert(pointIdValue);
160 voxel[i] = pointIdPair.first->second;
161 if (pointIdPair.second) {
171 int material = materialId;
173 material = materialMap->getMaterialId(materialId);
175 if constexpr (
D == 3) {
177 std::array<unsigned, 8> hexa{voxel[0], voxel[1], voxel[3],
178 voxel[2], voxel[4], voxel[5],
180 mesh->hexas.push_back(hexa);
181 materialIds.push_back(material);
183 std::array<unsigned, 4> tetra{voxel[0], voxel[2], voxel[3],
185 mesh->tetras.push_back(tetra);
186 materialIds.push_back(material);
196 double gridDelta = grid.getGridDelta();
197 mesh->nodes.resize(pointIdMapping.size());
198 for (
auto it = pointIdMapping.begin(); it != pointIdMapping.end(); ++it) {
200 for (
unsigned i = 0; i <
D; ++i) {
201 coords[i] = gridDelta * it->first[i];
204 if (coords[i] < mesh->minimumExtent[i]) {
205 mesh->minimumExtent[i] = coords[i];
206 }
else if (coords[i] > mesh->maximumExtent[i]) {
207 mesh->maximumExtent[i] = coords[i];
210 mesh->nodes[it->second] = coords;