diff --git a/Applications/Utils/MeshEdit/Vtu2Grid.cpp b/Applications/Utils/MeshEdit/Vtu2Grid.cpp index 65b310c997bc86de8b8ca11724288b6beb34a2b2..bf9c58c2f12a84e415bed80602a112db85ca591b 100644 --- a/Applications/Utils/MeshEdit/Vtu2Grid.cpp +++ b/Applications/Utils/MeshEdit/Vtu2Grid.cpp @@ -1,4 +1,5 @@ /** + * \file * * @copyright * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) @@ -28,7 +29,7 @@ #include <vtkUnstructuredGrid.h> #include <vtkXMLUnstructuredGridReader.h> -static std::string cell_id_name = "CellIds"; +std::string const cell_id_name = "CellIds"; std::array<std::size_t, 3> getDimensions(MathLib::Point3d const& min, MathLib::Point3d const& max, @@ -42,18 +43,17 @@ std::array<std::size_t, 3> getDimensions(MathLib::Point3d const& min, }; } -void assignCellIds(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, - MathLib::Point3d const& min, - std::array<std::size_t, 3> const& dims, - std::array<double, 3> const& cellsize, - std::vector<int>& cell_ids) +std::vector<int> assignCellIds(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, + MathLib::Point3d const& min, + std::array<std::size_t, 3> const& dims, + std::array<double, 3> const& cellsize) { vtkSmartPointer<vtkCellLocator> locator = vtkSmartPointer<vtkCellLocator>::New(); locator->SetDataSet(mesh); locator->Update(); - cell_ids.clear(); + std::vector<int> cell_ids; cell_ids.reserve(dims[0] * dims[1] * dims[2]); std::array<double, 3> const grid_max = {min[0] + dims[0] * cellsize[0], min[1] + dims[1] * cellsize[1], @@ -72,6 +72,7 @@ void assignCellIds(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, } } } + return cell_ids; } bool removeUnusedGridCells(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, @@ -130,7 +131,7 @@ void mapMeshArraysOntoGrid(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, mapArray<int, vtkSmartPointer<vtkIntArray>>(*grid, int_arr, name); continue; } - WARN("Ignoring array \"%s\"...", name.c_str()); + WARN("Ignoring array '%s'...", name.c_str()); } } @@ -198,8 +199,7 @@ int main (int argc, char* argv[]) reader->Update(); vtkSmartPointer<vtkUnstructuredGrid> mesh = reader->GetOutput(); - double bounds[6]; - mesh->GetBounds(bounds); + double* bounds = mesh->GetBounds(); MathLib::Point3d const min(std::array<double, 3>{bounds[0], bounds[2], bounds[4]}); MathLib::Point3d const max(std::array<double, 3>{bounds[1], bounds[3], bounds[5]}); std::array<std::size_t, 3> const dims = getDimensions(min, max, cellsize); @@ -208,10 +208,12 @@ int main (int argc, char* argv[]) dims[0], dims[1], dims[2], cellsize[0], cellsize[1], cellsize[2], min, "grid")); + + std::vector<int> const tmp_ids = assignCellIds(mesh, min, dims, cellsize); std::vector<int>& cell_ids = *grid->getProperties().createNewPropertyVector<int>( cell_id_name, MeshLib::MeshItemType::Cell, 1); - assignCellIds(mesh, min, dims, cellsize, cell_ids); + std::copy(tmp_ids.cbegin(), tmp_ids.cend(), std::back_inserter(cell_ids)); if (!removeUnusedGridCells(mesh, grid)) return EXIT_FAILURE; diff --git a/Applications/Utils/Tests.cmake b/Applications/Utils/Tests.cmake index e1783d50572d818013390d1b892402139e191f35..6fffe0a5ed3f1d529abea405ff4131b99f866778 100644 --- a/Applications/Utils/Tests.cmake +++ b/Applications/Utils/Tests.cmake @@ -283,5 +283,5 @@ AddTest( REQUIREMENTS NOT OGS_USE_MPI TESTER vtkdiff DIFF_DATA - AmmerSubsurfaceCoarse.vtu AmmerGridOutput.vtu MaterialIDs MaterialIDs 0 0 + AmmerSubsurfaceGrid.vtu AmmerGridOutput.vtu MaterialIDs MaterialIDs 0 0 )