Skip to content

Commit

Permalink
Add noWarning option is lsPointData
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed Jun 14, 2024
1 parent 1b5c161 commit 116770d
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 37 deletions.
4 changes: 1 addition & 3 deletions examples/VolumeToLevelSets/VolumeToLevelSets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ int main(int argc, char *argv[]) {
mesh->getCellData().getScalarData("Material");

std::vector<int> translator = {3, 2, 4, 7, 7, 6, 5, 7, 1, 0};
if (materialData == nullptr) {
std::cout << "Could not get material data" << std::endl;
} else {
if (materialData != nullptr) {
for (auto &cell : *materialData) {
cell = translator[std::round(cell)];
}
Expand Down
2 changes: 1 addition & 1 deletion include/viennals/lsAdvect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ template <class T, int D> class Advect {
MarkVoidPoints<T, D>(levelSets.back()).apply();
auto &pointData = levelSets.back()->getPointData();
voidMarkerPointer =
pointData.getScalarData(MarkVoidPoints<T, D>::voidPointLabel);
pointData.getScalarData(MarkVoidPoints<T, D>::voidPointLabel, true);
if (voidMarkerPointer == nullptr) {
Logger::getInstance()
.addWarning("Advect: Cannot find void point markers. Not "
Expand Down
2 changes: 1 addition & 1 deletion include/viennals/lsBooleanOperation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template <class T, int D> class BooleanOperation {
// scalars
for (unsigned i = 0; i < AData.getScalarDataSize(); ++i) {
auto scalarDataLabel = AData.getScalarDataLabel(i);
auto BPointer = BData.getScalarData(scalarDataLabel);
auto BPointer = BData.getScalarData(scalarDataLabel, true);
if (BPointer != nullptr) {
auto APointer = AData.getScalarData(i);
// copy all data into the new scalarData
Expand Down
6 changes: 4 additions & 2 deletions include/viennals/lsCalculateCurvatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ template <class T, int D> class CalculateCurvatures {
// insert into pointData of levelSet
if (calculateMean) {
auto &pointData = levelSet->getPointData();
auto scalarDataPointer = pointData.getScalarData(meanCurvatureLabel);
auto scalarDataPointer =
pointData.getScalarData(meanCurvatureLabel, true);
// if it does not exist, insert new normals vector
if (scalarDataPointer == nullptr) {
pointData.insertNextScalarData(meanCurvaturesVector[0],
Expand All @@ -186,7 +187,8 @@ template <class T, int D> class CalculateCurvatures {

if (calculateGauss) {
auto &pointData = levelSet->getPointData();
auto scalarDataPointer = pointData.getScalarData(gaussianCurvatureLabel);
auto scalarDataPointer =
pointData.getScalarData(gaussianCurvatureLabel, true);
// if it does not exist, insert new normals vector
if (scalarDataPointer == nullptr) {
pointData.insertNextScalarData(gaussCurvaturesVector[0],
Expand Down
2 changes: 1 addition & 1 deletion include/viennals/lsDetectFeatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ template <class T, int D> class DetectFeatures {

// insert into pointData of levelSet
auto &pointData = levelSet->getPointData();
auto vectorDataPointer = pointData.getScalarData(featureMarkersLabel);
auto vectorDataPointer = pointData.getScalarData(featureMarkersLabel, true);
// if it does not exist, insert new feature vector
if (vectorDataPointer == nullptr) {
pointData.insertNextScalarData(flaggedCells, featureMarkersLabel);
Expand Down
2 changes: 1 addition & 1 deletion include/viennals/lsFromMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ template <class T, int D> class FromMesh {

auto &domain = levelSet->getDomain();
auto &nodes = mesh->getNodes();
auto values = mesh->cellData.getScalarData("LSValues");
auto values = mesh->cellData.getScalarData("LSValues", true);

if (values == nullptr) {
Logger::getInstance()
Expand Down
2 changes: 1 addition & 1 deletion include/viennals/lsFromVolumeMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ template <class T, int D> class FromVolumeMesh {
// get the unique material numbers for explicit booling
std::vector<int> materialInts;
typename PointData<T>::ScalarDataType *materialData =
mesh->cellData.getScalarData("Material");
mesh->cellData.getScalarData("Material", true);
if (materialData != nullptr) {
// make unique list of materialIds
materialInts =
Expand Down
4 changes: 2 additions & 2 deletions include/viennals/lsMarkVoidPoints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ template <class T, int D> class MarkVoidPoints {
}

auto &pointData = domain->getPointData();
auto voidMarkersPointer = pointData.getScalarData(voidPointLabel);
auto voidMarkersPointer = pointData.getScalarData(voidPointLabel, true);
// if vector data does not exist
if (voidMarkersPointer == nullptr) {
pointData.insertNextScalarData(voidPointMarkers, voidPointLabel);
Expand All @@ -313,7 +313,7 @@ template <class T, int D> class MarkVoidPoints {

if (saveComponents) {
auto componentMarkersPointer =
pointData.getScalarData("ConnectedComponentId");
pointData.getScalarData("ConnectedComponentId", true);
// if vector data does not exist
if (componentMarkersPointer == nullptr) {
pointData.insertNextScalarData(componentMarkers,
Expand Down
56 changes: 32 additions & 24 deletions include/viennals/lsPointData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,31 @@ class PointData {
return indexPointerOrNull(scalarData, index);
}

ScalarDataType *getScalarData(std::string searchLabel) {
ScalarDataType *getScalarData(std::string searchLabel,
bool noWarning = false) {
if (int i = getScalarDataIndex(searchLabel); i != -1) {
return &(scalarData[i]);
}
Logger::getInstance()
.addWarning("PointData attempted to access scalar data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
if (!noWarning)
Logger::getInstance()
.addWarning("PointData attempted to access scalar data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
return nullptr;
}

const ScalarDataType *getScalarData(std::string searchLabel) const {
const ScalarDataType *getScalarData(std::string searchLabel,
bool noWarning = false) const {
if (int i = getScalarDataIndex(searchLabel); i != -1) {
return &(scalarData[i]);
}
Logger::getInstance()
.addWarning("PointData attempted to access scalar data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
if (!noWarning)
Logger::getInstance()
.addWarning("PointData attempted to access scalar data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
return nullptr;
}

Expand Down Expand Up @@ -152,27 +156,31 @@ class PointData {
return indexPointerOrNull(vectorData, index);
}

VectorDataType *getVectorData(std::string searchLabel) {
VectorDataType *getVectorData(std::string searchLabel,
bool noWarning = false) {
if (int i = getVectorDataIndex(searchLabel); i != -1) {
return &(vectorData[i]);
}
Logger::getInstance()
.addWarning("PointData attempted to access scalar data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
if (!noWarning)
Logger::getInstance()
.addWarning("PointData attempted to access vector data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
return nullptr;
}

const VectorDataType *getVectorData(std::string searchLabel) const {
const VectorDataType *getVectorData(std::string searchLabel,
bool noWarning = false) const {
if (int i = getVectorDataIndex(searchLabel); i != -1) {
return &(vectorData[i]);
}
Logger::getInstance()
.addWarning("PointData attempted to access scalar data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
if (!noWarning)
Logger::getInstance()
.addWarning("PointData attempted to access vector data labeled '" +
searchLabel +
"', which does not exist. Returning nullptr instead.")
.print();
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion include/viennals/lsRemoveStrayPoints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ template <class T, int D> class RemoveStrayPoints {
}

auto voidMarkers =
levelSet->getPointData().getScalarData("VoidPointMarkers");
levelSet->getPointData().getScalarData("VoidPointMarkers", true);
if (voidMarkers == nullptr) {
Logger::getInstance()
.addWarning("RemoveStrayPoints: No scalar data for void point "
Expand Down

0 comments on commit 116770d

Please sign in to comment.