diff --git a/register_subset_tools.cpp b/register_subset_tools.cpp index 5417526..276008e 100644 --- a/register_subset_tools.cpp +++ b/register_subset_tools.cpp @@ -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 diff --git a/tools/subset_tools.cpp b/tools/subset_tools.cpp index 83bcfaf..e30071d 100644 --- a/tools/subset_tools.cpp +++ b/tools/subset_tools.cpp @@ -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" @@ -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"); @@ -493,11 +498,74 @@ void AssignSubsetsByAspectRatio ( UG_LOG(t.to_string() << std::endl); } -// void AssignSubsetFromRaster( -// Mesh* obj, -// const char* rasterFileName) -// { - -// } + +template +void AssignSubsetsFromRaster_IMPL (Mesh* obj, const char* rasterFileName) +{ + typedef Raster raster_t; + typedef typename Grid::traits::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(); ielem != g.end(); ++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 +void AssignSubsetsFromRaster_IMPL( + Mesh* obj, + const char* rasterFileName, + bool vertices, + bool edges, + bool faces, + bool volumes) +{ + if(vertices) + AssignSubsetsFromRaster_IMPL (obj, rasterFileName); + if(edges) + AssignSubsetsFromRaster_IMPL (obj, rasterFileName); + if(faces) + AssignSubsetsFromRaster_IMPL (obj, rasterFileName); + if(volumes) + AssignSubsetsFromRaster_IMPL (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 diff --git a/tools/subset_tools.h b/tools/subset_tools.h index 24d9840..d14adba 100644 --- a/tools/subset_tools.h +++ b/tools/subset_tools.h @@ -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{ @@ -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