-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raster data to mesh #2984
Raster data to mesh #2984
Conversation
|
||
bool projectToElements(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, | ||
double const default, std::string const& array_name); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}; | |
} // end namespace RasterDataToMesh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
OGSError::box("Please specify path to raster file."); | ||
return; | ||
} | ||
else if (this->arrayNameEdit->text().isEmpty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No else after a return needed. Will be a warning in clang-tidy.
else if (this->arrayNameEdit->text().isEmpty()) | |
if (this->arrayNameEdit->text().isEmpty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct the way it is. Otherwise the user drowns in error pop-ups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After OGSError::box is displayed, there is a return. Therefor the other if-conditions will not be checked and the user is presented with single error box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. This is the way it is supposed to work.
namespace RasterDataToMesh | ||
{ | ||
|
||
bool checkMesh2D(MeshLib::Mesh const& mesh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer all functions not exposed in the interface to have internal linkage. Either static
or anonymous namespace.
Makes life of a linker easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
return true; | ||
} | ||
std::string getValidName(std::vector<std::string> const& vec_names, | ||
std::string const& array_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format. Also few other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
bool name_exists = std::find(vec_names.cbegin(), vec_names.cend(), | ||
array_name) != vec_names.end(); | ||
while (name_exists) | ||
{ | ||
count++; | ||
new_name = array_name + std::to_string(count); | ||
name_exists = std::find(vec_names.cbegin(), vec_names.cend(), | ||
array_name) != vec_names.end(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be equivalent:
bool name_exists = std::find(vec_names.cbegin(), vec_names.cend(), | |
array_name) != vec_names.end(); | |
while (name_exists) | |
{ | |
count++; | |
new_name = array_name + std::to_string(count); | |
name_exists = std::find(vec_names.cbegin(), vec_names.cend(), | |
array_name) != vec_names.end(); | |
} | |
while (std::find(vec_names.cbegin(), vec_names.cend(), array_name) | |
!= vec_names.end()) | |
{ | |
count++; | |
new_name = array_name + std::to_string(count); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
return new_name; | ||
} | ||
|
||
double evaluatePixel(double value, double no_data, double replacement) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double evaluatePixel(double value, double no_data, double replacement) | |
double evaluatePixel(double const value, double const no_data, double const replacement) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
for (auto node : nodes) | ||
{ | ||
vec->push_back( | ||
evaluatePixel(raster.getValueAtPoint(*node), no_data, default)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (auto node : nodes) | |
{ | |
vec->push_back( | |
evaluatePixel(raster.getValueAtPoint(*node), no_data, default)); | |
} | |
transform(cbegin(nodes), cend(nodes), back_inserter(*vec), [&](auto const node) | |
{ | |
return evaluatePixel(raster.getValueAtPoint(*node), no_data, default)); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
std::transform(nodes.cbegin(), nodes.cend(), std::back_inserter(vec), [&](auto const node){
evaluatePixel(raster.getValueAtPoint(*node), no_data, default);
});
results in
\MSVC\14.25.28610\include\xutility(5302,1): error C2825: "_Container": Muss eine Klasse oder ein Namespace sein, wenn gefolgt von "::".
/ogs/MeshLib/MeshEditing/RasterDataToMesh.cpp(67): message : Siehe Verweis auf die gerade kompilierte Klasse Vorlage-Instanziierung "std::back_insert_iterator<MeshLib::PropertyVector<double> *>".
\MSVC\14.25.28610\include\xutility(5302,64): error C2510: "_Container": Der linke Teil von "::" muss eine Klasse/Struktur/Union sein
\MSVC\14.25.28610\include\xutility(5302,1): error C2182: "_Val": Unzulässige Verwendung des Typs "void"
\MSVC\14.25.28610\include\xutility(5307,1): error C2825: "_Container": Muss eine Klasse oder ein Namespace sein, wenn gefolgt von "::".
\MSVC\14.25.28610\include\xutility(5307,58): error C2510: "_Container": Der linke Teil von "::" muss eine Klasse/Struktur/Union sein
\MSVC\14.25.28610\include\xutility(5307,1): error C2182: "_Val": Unzulässige Verwendung des Typs "void"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since vec
is a pointer to a PropertyVector, std::back_inserter(*vec)
should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Tom, I fixed above in the suggestion too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Tom!
✔️
auto vec = props.createNewPropertyVector<double>( | ||
name, MeshLib::MeshItemType::Cell, 1); | ||
double const no_data = raster.getHeader().no_data; | ||
for (auto elem : elems) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transform here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor corrections. ⏩
For namespace error in vtk take Wenqing's commit: 'git cherry-pick c596c46' |
ERR("This functionality is currently only available for 2D meshes."); | ||
return false; | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not testing mesh.getDimension() == 2
? The function name lets one expect that only with 2d grids true is returned. At the moment for 1d meshes the function returns also true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this works for 1D meshes, too. So >=2
is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the check returns true for 1d and 2d meshes the name of the function should be changed.
} | ||
|
||
bool projectToNodes(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, | ||
double const default, std::string const& array_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since default
is a keyword it should not be used as a variable name. At least renaming default -> def fixed compile errors for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't cause any issues with MSVC. Anyway, I've changed the name. ✔️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... though default_value
or whatever default there is default_status
default_future_multiplier
would be better and would save explanation of the function arguments in doxygen comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump.
Rename or documentation would improve the code.
From the function signature it is not clear, what that def
thingy is.
} | ||
|
||
bool projectToElements(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, | ||
double const default, std::string const& array_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: default
doesn't seem to be a good variable name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
double const default, std::string const& array_name) | ||
{ | ||
if (!checkMesh2D(mesh)) | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives a new warning: statement should be inside braces [google-readability-braces-around-statements]
return false; | |
{ | |
return false; | |
} |
static double evaluatePixel(double value, double no_data, double replacement) | ||
{ | ||
if (std::abs(value - no_data) < std::numeric_limits<double>::epsilon()) | ||
return replacement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives a new warning: statement should be inside braces [google-readability-braces-around-statements]
return replacement; | |
{ | |
return replacement; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When tests are green: ⏩
OpenGeoSys development has been moved to GitLab. |
Adds a new node or cell array to a mesh based on specified raster.