Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
rinkk committed Feb 19, 2019
1 parent d590208 commit bf76f36
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Applications/Utils/FileConverter/MeshToRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#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,
std::size_t getProjectedElementIndex(std::vector<const MeshLib::Element*> const& elems,
MeshLib::Node const& node)
{
std::size_t const n_elems = elems.size();
Expand Down Expand Up @@ -64,7 +64,7 @@ std::size_t getProjectedElement(std::vector<const MeshLib::Element*> const& elem
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);
MeshLib::Node const& orig = *elem.getNode(0);
MathLib::Point3d const v{{node[0] - orig[0], node[1] - orig[1], node[2] - orig[2]}};
double const dist = n[0] * v[0] + n[1] * v[1] + n[2] * v[2];
return node[2] - dist * n[2];
Expand Down Expand Up @@ -117,7 +117,7 @@ int main(int argc, char* argv[])
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());
GeoLib::AABB const bounding_box(nodes_vec.begin(), nodes_vec.end());
MathLib::Point3d const& min(bounding_box.getMinPoint());
MathLib::Point3d const& max(bounding_box.getMaxPoint());
std::size_t const n_cols = static_cast<std::size_t>(std::ceil((max[0] - min[0]) / cellsize));
Expand Down Expand Up @@ -148,7 +148,7 @@ int main(int argc, char* argv[])
MathLib::Point3d min_vol{{x - max_edge, y - max_edge, -std::numeric_limits<double>::max()}};
MathLib::Point3d max_vol{{x + max_edge, y + max_edge, std::numeric_limits<double>::max()}};
std::vector<const MeshLib::Element*> const elems = grid.getElementsInVolume(min_vol, max_vol);
std::size_t const elem_idx = getProjectedElement(elems, node);
std::size_t const elem_idx = getProjectedElementIndex(elems, node);
// 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) << " ";
Expand All @@ -163,7 +163,7 @@ int main(int argc, char* argv[])
for (std::size_t i=0; i<4; ++i)
{
MeshLib::Node const node(x+x_off[i], y+y_off[i], 0);
std::size_t const corner_idx = getProjectedElement(elems, node);
std::size_t const corner_idx = getProjectedElementIndex(elems, node);
if (corner_idx != std::numeric_limits<std::size_t>::max())
{
sum += getElevation(*(mesh->getElement(corner_idx)), node);
Expand All @@ -184,6 +184,6 @@ int main(int argc, char* argv[])
out << "\n";
}
out.close();
INFO("Result written to %s", output_arg.getValue());
INFO("Result written to %s", output_arg.getValue().c_str());
return 0;
}
9 changes: 9 additions & 0 deletions Applications/Utils/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,12 @@ AddTest(
EXECUTABLE_ARGS -p -v TaskB_mesh.vtu
REQUIREMENTS NOT OGS_USE_MPI
)

AddTest(
NAME mesh2raster_test
PATH MeshGeoToolsLib/Hamburg
EXECUTABLE mesh2raster
EXECUTABLE_ARGS -i 00-surface.vtu -o ${Data_BINARY_DIR}/MeshGeoToolsLib/Hamburg/00-raster.asc -c 25
TESTER diff
DIFF_DATA 00-raster.asc
)
Loading

0 comments on commit bf76f36

Please sign in to comment.