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

Conversation

Projects
None yet
3 participants
@rinkk
Copy link
Member

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

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

Wrong file name. Just use \file

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

* 2012/03/07 KR Initial implementation
*
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)

This comment has been minimized.

@endJunction

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️


#include <memory>
#include <string>
#include <iostream>

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

Don't include iostream, use logog.

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

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

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

Probably just me, but what is the "element p"?

This comment has been minimized.

@rinkk

rinkk Feb 19, 2019

Author Member

✔️

{
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())

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

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.

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

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

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

ofstream is already having the default argument for the open mode set to std::ios::out, no need to mention it here.

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

: mesh->getMinEdgeLength();
INFO ("Cellsize set to %f", cellsize);

std::size_t const nNodes (mesh->getNumberOfNodes());

This comment has been minimized.

@endJunction

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

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

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

I'd recommend to prefer the correctness over runtime in such cases.

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

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?

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

@TomFischer your decision.

This comment has been minimized.

@TomFischer

TomFischer Feb 19, 2019

Member

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

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

triangles.

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

cmd.parse(argc, argv);

INFO("Rasterising mesh...");
if (!input_arg.isSet())

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

Isn't tclap already testing this? The third last argument to the constructor of the argument is the requirement, isn't it?

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

std::size_t getProjectedElement(std::vector<const MeshLib::Element*> const& elems,
MeshLib::Node const& node)
{
// std::vector<MeshLib::Element*> const& elems = mesh.getElements();

This comment has been minimized.

@endJunction

endJunction Feb 18, 2019

Member

drop unused code...

This comment has been minimized.

@rinkk

rinkk Feb 18, 2019

Author Member

✔️

@codecov

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

endJunction commented Feb 18, 2019

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

This comment has been minimized.

@TomFischer

TomFischer Feb 19, 2019

Member

Why making a copy here?
MeshLib::Node const& orig = *elem.getNode(0);

This comment has been minimized.

@rinkk

rinkk Feb 19, 2019

Author Member

✔️

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

This comment has been minimized.

@TomFischer

This comment has been minimized.

@rinkk

rinkk Feb 19, 2019

Author Member

✔️

#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,

This comment has been minimized.

@TomFischer

TomFischer Feb 19, 2019

Member

The function name doesn't express exactly what the comment says and what is returned.

This comment has been minimized.

@rinkk

rinkk Feb 19, 2019

Author Member

✔️

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

This comment has been minimized.

@TomFischer

TomFischer Feb 19, 2019

Member

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

This comment has been minimized.

@rinkk

rinkk Feb 19, 2019

Author Member

There are multiple comments below this line, including one that mentions the corner points.

@TomFischer

This comment has been minimized.

Copy link
Member

TomFischer commented Feb 19, 2019

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

@rinkk

This comment has been minimized.

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 rinkk force-pushed the rinkk:master2raster branch from b5b707e to 9213277 Feb 19, 2019

@rinkk

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

TomFischer commented Feb 20, 2019

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

@rinkk

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

endJunction commented Feb 20, 2019

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

@TomFischer

This comment has been minimized.

Copy link
Member

TomFischer commented Feb 20, 2019

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

@endJunction endJunction force-pushed the rinkk:master2raster branch from 69c89a5 to 4acd353 Feb 20, 2019

@endJunction endJunction force-pushed the rinkk:master2raster branch from 4acd353 to 5863429 Feb 20, 2019

@rinkk

This comment has been minimized.

Copy link
Member Author

rinkk commented Feb 20, 2019

👍

@endJunction endJunction force-pushed the rinkk:master2raster branch from 5863429 to 00ba9c1 Feb 20, 2019

@TomFischer
Copy link
Member

TomFischer left a comment

👍

@TomFischer TomFischer merged commit 5685fd6 into ufz:master Feb 21, 2019

4 of 5 checks passed

codecov/patch 0% of diff hit (target 32.37%)
Details
codecov/project 32.63% (+0.25%) compared to 6382411
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
deploy/netlify Deploy preview ready!
Details
ufz.ogs #20190220.11 succeeded
Details

@rinkk rinkk referenced this pull request Feb 28, 2019

Merged

Mesh on mesh mapping fix #2390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.