Skip to content
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

Merged
merged 8 commits into from
Jun 10, 2020
Merged

Raster data to mesh #2984

merged 8 commits into from
Jun 10, 2020

Conversation

rinkk
Copy link
Member

@rinkk rinkk commented Jun 5, 2020

Adds a new node or cell array to a mesh based on specified raster.

  1. Feature description was added to the changelog
  2. Tests covering your feature were added?


bool projectToElements(MeshLib::Mesh& mesh, GeoLib::Raster const& raster,
double const default, std::string const& array_name);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};
} // end namespace RasterDataToMesh

Copy link
Member Author

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())
Copy link
Member

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.

Suggested change
else if (this->arrayNameEdit->text().isEmpty())
if (this->arrayNameEdit->text().isEmpty())

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Comment on lines 35 to 42
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();
}
Copy link
Member

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:

Suggested change
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);
}

Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double evaluatePixel(double value, double no_data, double replacement)
double evaluatePixel(double const value, double const no_data, double const replacement)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Comment on lines 67 to 71
for (auto node : nodes)
{
vec->push_back(
evaluatePixel(raster.getValueAtPoint(*node), no_data, default));
}
Copy link
Member

@endJunction endJunction Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));
}

Copy link
Member Author

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"

Copy link
Member

@TomFischer TomFischer Jun 9, 2020

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.

Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform here too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Copy link
Member

@endJunction endJunction left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor corrections. ⏩

@endJunction
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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. ✔️

Copy link
Member

@endJunction endJunction Jun 9, 2020

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.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

@TomFischer TomFischer Jun 9, 2020

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]

Suggested change
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;
Copy link
Member

@TomFischer TomFischer Jun 9, 2020

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]

Suggested change
return replacement;
{
return replacement;
}

Copy link
Member

@TomFischer TomFischer left a 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: ⏩

@TomFischer TomFischer merged commit 75e89e9 into ufz:master Jun 10, 2020
@ogsbot
Copy link
Member

ogsbot commented Jun 19, 2020

OpenGeoSys development has been moved to GitLab.

See this pull request on GitLab.

@rinkk rinkk deleted the RasterDataToMesh branch July 1, 2020 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants