50 if (levelSet ==
nullptr) {
52 .addWarning(
"No level set was passed to ToMesh.")
56 if (mesh ==
nullptr) {
57 Logger::getInstance().addWarning(
"No mesh was passed to ToMesh.").print();
64 if (levelSet->getNumberOfPoints() == 0) {
69 std::vector<T> LSValues;
72 const auto &pointData = levelSet->getPointData();
74 using ScalarDataType =
typename DomainType::PointDataType::ScalarDataType;
75 using VectorDataType =
typename DomainType::PointDataType::VectorDataType;
78 std::vector<ScalarDataType> scalarData;
79 std::vector<VectorDataType> vectorData;
80 scalarData.resize(pointData.getScalarDataSize());
81 vectorData.resize(pointData.getVectorDataSize());
83 const T gridDelta = levelSet->getGrid().getGridDelta();
85 for (hrleConstSparseIterator<hrleDomainType> it(levelSet->getDomain());
86 !it.isFinished(); ++it) {
87 if ((onlyDefined && !it.isDefined()) ||
88 (onlyActive && std::abs(it.getValue()) > 0.5))
91 if (!onlyDefined && !it.isDefined()) {
92 bool skipPoint =
false;
93 for (
unsigned i = 0; i <
D; ++i) {
94 if (std::abs(it.getStartIndices(i)) > maxDomainExtent) {
104 std::array<unsigned, 1> vertex;
105 vertex[0] = mesh->nodes.size();
106 mesh->insertNextVertex(vertex);
109 std::array<T, 3> node;
112 for (
unsigned i = 0; i <
D; ++i) {
113 node[i] =
T(it.getStartIndices(i)) * gridDelta;
115 mesh->insertNextNode(node);
118 if (it.isDefined()) {
119 LSValues.push_back(it.getDefinedValue());
121 LSValues.push_back((it.getValue() < 0) ? -1000 : 1000);
123 subLS.push_back(it.getSegmentId());
126 for (
unsigned i = 0; i < pointData.getScalarDataSize(); ++i) {
127 if (
const auto dataPointer = pointData.getScalarData(i);
128 dataPointer !=
nullptr) {
129 const auto ¤tData = *dataPointer;
130 scalarData[i].push_back(currentData[it.getPointId()]);
132 Logger::getInstance()
133 .addWarning(
"ToMesh: Tried to access out of bounds scalarData! "
140 for (
unsigned i = 0; i < pointData.getVectorDataSize(); ++i) {
141 if (
const auto dataPointer = pointData.getVectorData(i);
142 dataPointer !=
nullptr) {
143 const auto ¤tData = *dataPointer;
144 vectorData[i].push_back(currentData[it.getPointId()]);
146 Logger::getInstance()
147 .addWarning(
"ToMesh: Tried to access out of bounds vectorData! "
155 mesh->cellData.insertNextScalarData(LSValues,
"LSValues");
156 mesh->cellData.insertNextScalarData(subLS,
"SegmentID");
160 for (
unsigned i = 0; i < scalarData.size(); ++i) {
161 mesh->cellData.insertNextScalarData(std::move(scalarData[i]),
162 pointData.getScalarDataLabel(i));
165 for (
unsigned i = 0; i < vectorData.size(); ++i) {
166 mesh->cellData.insertNextVectorData(std::move(vectorData[i]),
167 pointData.getVectorDataLabel(i));