-
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
Mesh rasterisation #2367
Mesh rasterisation #2367
Conversation
@@ -0,0 +1,205 @@ | |||
/** | |||
* \file moveMeshNodes.cpp |
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.
Wrong file name. Just use \file
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.
✔️
* 2012/03/07 KR Initial implementation | ||
* | ||
* \copyright | ||
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org) |
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.
2019
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.
✔️
|
||
#include <memory> | ||
#include <string> | ||
#include <iostream> |
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.
Don't include iostream, use logog.
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.
✔️
#include "MeshLib/Elements/Quad.h" | ||
#include "MeshLib/MeshSearch/MeshElementGrid.h" | ||
|
||
/// Returns the index of the element p is located in when projected onto a 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.
Probably just me, but what is the "element p"?
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.
✔️
{ | ||
MeshLib::Node const node(x+x_off[i], y+y_off[i], 0); | ||
std::size_t const elem_idx = getProjectedElement(elems, node); | ||
if (elem_idx != std::numeric_limits<std::size_t>::max()) |
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 if condition seems to be always false, because it is in the else branch of the same test in line 169
Sorry, I'm wrong here. You tricked me by using the same variable name. Choose a different name, please.
Or, if you extract the "test for all of the pixels' corners" in own function, you can keep it as is; this would also be more readable.
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.
✔️
std::size_t const n_rows = static_cast<std::size_t>(std::ceil((max[1] - min[1]) / cellsize)); | ||
|
||
// raster header | ||
std::ofstream out(output_arg.getValue(), std::ios::out); |
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.
ofstream is already having the default argument for the open mode set to std::ios::out
, no need to mention it here.
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.
✔️
: mesh->getMinEdgeLength(); | ||
INFO ("Cellsize set to %f", cellsize); | ||
|
||
std::size_t const nNodes (mesh->getNumberOfNodes()); |
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.
unused
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.
✔️
GeoLib/AnalyticalGeometry.h
Outdated
* Tests if p is right of the line defined by a and b in 2D. | ||
* (Note: This functionality is similar to getOrientation(). It is probably | ||
* not quite as exact in numerically challenging situations but requires only | ||
* about half the runtime.) |
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 recommend to prefer the correctness over runtime in such cases.
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 probably my computer graphics POV but nothing bad happens if this gives a result that is wrong by a measure of epsilon outside of the elevation also being wrong by an epsilon (which is most likely less of an error than any rounding artifacts, measurement errors, etc that happened before already). Should I still remove it and use the slower method?
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.
@TomFischer your decision.
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 would take the safe implementation.
if (mesh->getDimension() != 2) | ||
{ | ||
ERR("The programme requires a mesh containing two-dimensional elements " | ||
"(i.e. triangals or quadrilaterals."); |
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.
triangles.
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.
✔️
cmd.parse(argc, argv); | ||
|
||
INFO("Rasterising mesh..."); | ||
if (!input_arg.isSet()) |
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.
Isn't tclap already testing this? The third last argument to the constructor of the argument is the requirement, isn't it?
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.
✔️
std::size_t getProjectedElement(std::vector<const MeshLib::Element*> const& elems, | ||
MeshLib::Node const& node) | ||
{ | ||
// std::vector<MeshLib::Element*> const& elems = mesh.getElements(); |
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.
drop unused code...
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.
✔️
Codecov Report
@@ Coverage Diff @@
## master #2367 +/- ##
==========================================
+ Coverage 32.37% 32.63% +0.25%
==========================================
Files 527 527
Lines 19935 19771 -164
Branches 9413 9260 -153
==========================================
- Hits 6454 6452 -2
+ Misses 10179 10032 -147
+ Partials 3302 3287 -15
Continue to review full report at Codecov.
|
Is it possible to have a small example to be included in the ctests? |
double getElevation(MeshLib::Element const& elem, MeshLib::Node const& node) | ||
{ | ||
MathLib::Vector3 const n = MeshLib::FaceRule::getSurfaceNormal(&elem).getNormalizedVector(); | ||
MeshLib::Node const orig = *elem.getNode(0); |
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 making a copy here?
MeshLib::Node const& orig = *elem.getNode(0);
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.
✔️
INFO ("Cellsize set to %f", cellsize); | ||
|
||
std::vector<MeshLib::Node*> const& nodes_vec(mesh->getNodes()); | ||
GeoLib::AABB bounding_box(nodes_vec.begin(), nodes_vec.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.
const
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.
✔️
#include "MeshLib/MeshSearch/MeshElementGrid.h" | ||
|
||
/// Returns the index of the element the given node is located in when projected onto a mesh. | ||
std::size_t getProjectedElement(std::vector<const MeshLib::Element*> const& 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.
The function name doesn't express exactly what the comment says and what is returned.
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.
✔️
// centre of the pixel is located within a mesh element | ||
if (elem_idx != std::numeric_limits<std::size_t>::max()) | ||
out << getElevation(*(mesh->getElement(elem_idx)), node) << " "; | ||
// centre of the pixel isn't located within a mesh element |
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.
From the above comment it is already clear that the centre of the pixel isn't located within a mesh element. Maybe, it is better to write what you'll do in the following (checking the corner points of the element).
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 are multiple comments below this line, including one that mentions the corner points.
You could use |
The raster interface is hard to use in this case. For one thing, it'd require writing more code than I did. Most annoyingly, it'd require storing all the data first before I can start creating a raster object (currently I'm not storing anything!), then creating a header object and then writing all of it to a file. |
I'm using the slower (but presumably more correct) method now for determining if a point is in a triangle. For the record: I think it's extremely annoying to do this. The runtime is noticably longer now but the result for the test data is exactly the same. Not a single byte was changed. We're basically hobbling our legs here, nobody was ever going to notice a difference in the results... |
I would suggest to put the asc test file to git large filesystem. |
I did the test precisely as both Dima and Lars said I should do it. |
@rinkk For discussion an refactored version of the tool https://github.com/endJunction/ogs/tree/master2raster. |
I don't insist to move the raster test data to git large file system. |
69c89a5
to
4acd353
Compare
copy happens element-wise, insert can do insertions in batches.
4acd353
to
5863429
Compare
👍 |
5863429
to
00ba9c1
Compare
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.
👍
OpenGeoSys development has been moved to GitLab. |
Takes a 2D mesh and constructs an asc-raster by sampling elevation values at user-specified equidistant intervals.