Skip to content

Commit

Permalink
Added assign subsets from raster.
Browse files Browse the repository at this point in the history
  • Loading branch information
sreiter committed Jan 24, 2018
1 parent abacf17 commit 640fd38
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 8 deletions.
11 changes: 10 additions & 1 deletion register_subset_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ void RegisterSubsetTools(ProMeshRegistry& reg, std::string baseGrp)
"mesh", TOOLTIP_ASSIGN_SUBSETS_BY_ELEMENT_TYPE)
.add_function("AssignSubsetsByAspectRatio", &AssignSubsetsByAspectRatio, grp, "",
"mesh # histogram sections || min=1; value=10 # erase old subsets || value=true",
TOOLTIP_ASSIGN_SUBSETS_BY_ASPECT_RATIO);
TOOLTIP_ASSIGN_SUBSETS_BY_ASPECT_RATIO)
.add_function("AssignSubsetsFromRaster", &AssignSubsetsFromRaster, grp, "",
"mesh #"
"raster filename #"
"raster dimension || min=1;value=3;max=3 #"
"vertices || value=true #"
"edges || value=true #"
"faces || value=true #"
"volumes || value=true",
TOOLTIP_ASSIGN_SUBSETS_FROM_RASTER);
}

}}// end of namespace
82 changes: 75 additions & 7 deletions tools/subset_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include "common/util/table.h"
#include "common/util/raster.h"
#include "subset_tools.h"
#include "lib_grid/algorithms/quality_util.h"
#include "lib_grid/algorithms/subset_color_util.h"
Expand Down Expand Up @@ -432,11 +433,15 @@ void CopySubsetIndicesToSides(
}
}


// NEW GROUP: Quality Util
void AssignSubsetsByAspectRatio (
Mesh* msh,
int numHistoSecs,
bool eraseOldSubsets)
// Parameters:
// + Assign Subset (bool)
// + Face / Volume (enum)
// + Quality Measure (enum)
{
if(numHistoSecs < 1){
UG_LOG("Can't create histogram with " << numHistoSecs << " sections.\n");
Expand Down Expand Up @@ -493,11 +498,74 @@ void AssignSubsetsByAspectRatio (
UG_LOG(t.to_string() << std::endl);
}

// void AssignSubsetFromRaster(
// Mesh* obj,
// const char* rasterFileName)
// {

// }

template <int dim, class elem_t>
void AssignSubsetsFromRaster_IMPL (Mesh* obj, const char* rasterFileName)
{
typedef Raster<number, dim> raster_t;
typedef typename Grid::traits<elem_t>::iterator iter_t;

Mesh::position_accessor_t& aaPos = obj->position_accessor();
Grid& g = obj->grid();
SubsetHandler& sh = obj->subset_handler();

raster_t raster;
raster.load_from_asc(rasterFileName);

typename raster_t::Coordinate coord(0);


for(iter_t ielem = g.begin<elem_t>(); ielem != g.end<elem_t>(); ++ielem)
{
vector3 c = CalculateCenter(*ielem, aaPos);
for(int i = 0; i < dim; ++i)
coord[i] = c[i];
int si = (int)raster.interpolate(coord, 0);
sh.assign_subset(*ielem, si);
}
}

template <int dim>
void AssignSubsetsFromRaster_IMPL(
Mesh* obj,
const char* rasterFileName,
bool vertices,
bool edges,
bool faces,
bool volumes)
{
if(vertices)
AssignSubsetsFromRaster_IMPL<dim, Vertex> (obj, rasterFileName);
if(edges)
AssignSubsetsFromRaster_IMPL<dim, Edge> (obj, rasterFileName);
if(faces)
AssignSubsetsFromRaster_IMPL<dim, Face> (obj, rasterFileName);
if(volumes)
AssignSubsetsFromRaster_IMPL<dim, Volume> (obj, rasterFileName);
}

void AssignSubsetsFromRaster(
Mesh* obj,
const char* rasterFileName,
int rasterDimension,
bool vertices,
bool edges,
bool faces,
bool volumes)
{
switch(rasterDimension){
case 1: AssignSubsetsFromRaster_IMPL<1> (obj, rasterFileName, vertices,
edges, faces, volumes);
break;
case 2: AssignSubsetsFromRaster_IMPL<2> (obj, rasterFileName, vertices,
edges, faces, volumes);
break;
case 3: AssignSubsetsFromRaster_IMPL<3> (obj, rasterFileName, vertices,
edges, faces, volumes);
break;
default: UG_THROW("Unsupported dimension '" << rasterDimension << "'"
<< "in AssignSubsetFromRaster."); break;
}
}

}}// end of namespace
10 changes: 10 additions & 0 deletions tools/subset_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#define TOOLTIP_COPY_SUBSET_INDICES_TO_SIDES "Copies subset indices of selected elements to sides of those elements."
#define TOOLTIP_ASSIGN_SUBSETS_BY_ELEMENT_TYPE "Assigns elemets to subsets based on their concrete type."
#define TOOLTIP_ASSIGN_SUBSETS_BY_ASPECT_RATIO "Assigns subsets according to a aspect ratio histogram"
#define TOOLTIP_ASSIGN_SUBSETS_FROM_RASTER "Assigns the subset index for each element from the raster-cell in which the center of the element lies."

namespace ug{
namespace promesh{
Expand Down Expand Up @@ -142,6 +143,15 @@ void AssignSubsetsByAspectRatio (
Mesh* msh,
int numHistoSecs,
bool eraseOldSubsets);

void AssignSubsetsFromRaster(
Mesh* obj,
const char* rasterFileName,
int rasterDimension,
bool vertices,
bool edges,
bool faces,
bool volumes);
/// \}

}}// end of namespace
Expand Down

0 comments on commit 640fd38

Please sign in to comment.