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

Mesh rasterisation #2367

Merged
merged 6 commits into from
Feb 21, 2019
Merged

Mesh rasterisation #2367

merged 6 commits into from
Feb 21, 2019

Conversation

rinkk
Copy link
Member

@rinkk rinkk commented Feb 18, 2019

Takes a 2D mesh and constructs an asc-raster by sampling elevation values at user-specified equidistant intervals.

@@ -0,0 +1,205 @@
/**
* \file moveMeshNodes.cpp
Copy link
Member

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

Copy link
Member Author

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

Choose a reason for hiding this comment

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

2019

Copy link
Member Author

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

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.

Copy link
Member Author

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

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"?

Copy link
Member Author

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

@endJunction endJunction Feb 18, 2019

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.

Copy link
Member Author

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

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.

Copy link
Member Author

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

Choose a reason for hiding this comment

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

unused

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️

* 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.)
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 recommend to prefer the correctness over runtime in such cases.

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 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?

Copy link
Member

Choose a reason for hiding this comment

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

@TomFischer your decision.

Copy link
Member

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

Choose a reason for hiding this comment

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

triangles.

Copy link
Member Author

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

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?

Copy link
Member Author

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

Choose a reason for hiding this comment

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

drop unused code...

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️

@codecov
Copy link

codecov bot commented Feb 18, 2019

Codecov Report

Merging #2367 into master will increase coverage by 0.25%.
The diff coverage is 0%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
MeshLib/MeshSearch/MeshElementGrid.h 0% <0%> (ø) ⬆️
GeoLib/Polyline.cpp 35.86% <0%> (-0.61%) ⬇️
Applications/ApplicationsLib/ProjectData.cpp 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6382411...00ba9c1. Read the comment docs.

@endJunction
Copy link
Member

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

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);

Copy link
Member Author

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

Choose a reason for hiding this comment

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

const

Copy link
Member Author

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

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.

Copy link
Member Author

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

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).

Copy link
Member Author

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.

@TomFischer
Copy link
Member

You could use GeoLib::Raster and Applications/FileIO/AsciiRasterInterface for the implementation to reuse existing code.

@rinkk
Copy link
Member Author

rinkk commented Feb 19, 2019

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.

@rinkk
Copy link
Member Author

rinkk commented Feb 19, 2019

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

@TomFischer
Copy link
Member

I would suggest to put the asc test file to git large filesystem.

@rinkk
Copy link
Member Author

rinkk commented Feb 20, 2019

I did the test precisely as both Dima and Lars said I should do it.

@endJunction
Copy link
Member

@rinkk For discussion an refactored version of the tool https://github.com/endJunction/ogs/tree/master2raster.

@TomFischer
Copy link
Member

I don't insist to move the raster test data to git large file system.

@rinkk
Copy link
Member Author

rinkk commented Feb 20, 2019

👍

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.

👍

@TomFischer TomFischer merged commit 5685fd6 into ufz:master Feb 21, 2019
@rinkk rinkk mentioned this pull request Feb 28, 2019
@rinkk rinkk deleted the master2raster branch April 12, 2019 15:30
@ogsbot
Copy link
Member

ogsbot commented Jun 19, 2020

OpenGeoSys development has been moved to GitLab.

See this pull request on GitLab.

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.

4 participants