From ef1260aa2447137725fc2a47f7b1ee65e383ed41 Mon Sep 17 00:00:00 2001 From: Oliver Gloth Date: Tue, 10 Feb 2015 16:56:48 +0100 Subject: [PATCH] quick and dirty feature edge solution for dual grids --- src/libengrid/guiconverttopolymesh.cpp | 2 ++ src/libengrid/guiconverttopolymesh.ui | 27 ++++++++++++-- src/libengrid/operation.cpp | 65 ++++++++++++++++++++++++++++++++++ src/libengrid/operation.h | 6 +++- src/libengrid/polymesh.cpp | 6 ++-- 5 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/libengrid/guiconverttopolymesh.cpp b/src/libengrid/guiconverttopolymesh.cpp index 8ce798e5..a3b5dd45 100644 --- a/src/libengrid/guiconverttopolymesh.cpp +++ b/src/libengrid/guiconverttopolymesh.cpp @@ -34,5 +34,7 @@ void GuiConvertToPolyMesh::operate() convert.setSplitCellsOn(); } convert.setPullInFactor(m_Ui.horizontalSliderPullIn->value()*0.01); + createFeatureBcs(m_Ui.m_DoubleSpinBoxFeatureAngle->value()); convert(); + restoreNormalBcs(); } diff --git a/src/libengrid/guiconverttopolymesh.ui b/src/libengrid/guiconverttopolymesh.ui index c4f431da..1b1d6e67 100644 --- a/src/libengrid/guiconverttopolymesh.ui +++ b/src/libengrid/guiconverttopolymesh.ui @@ -6,8 +6,8 @@ 0 0 - 241 - 135 + 240 + 208 @@ -32,7 +32,7 @@ 100 - 50 + 0 Qt::Horizontal @@ -81,6 +81,26 @@ + + + + feature angle + + + + + + + 180.000000000000000 + + + 2.500000000000000 + + + 20.000000000000000 + + + @@ -113,6 +133,7 @@ checkBoxOptimise checkBoxSplitConcaveFaces checkBoxSplitConcaveCells + m_DoubleSpinBoxFeatureAngle buttonBox diff --git a/src/libengrid/operation.cpp b/src/libengrid/operation.cpp index f9d2ce20..08c2cf6c 100644 --- a/src/libengrid/operation.cpp +++ b/src/libengrid/operation.cpp @@ -22,6 +22,7 @@ #include "guimainwindow.h" #include "egvtkobject.h" +#include "setboundarycode.h" #include #include @@ -42,6 +43,7 @@ #include #include "geometrytools.h" + using namespace GeometryTools; QSet Operation::garbage_operations; @@ -278,3 +280,66 @@ void Operation::eliminateDuplicateCells(bool surf_only) makeCopy(m_Grid, new_grid, new_cells); makeCopy(new_grid, m_Grid); } + +void Operation::createFeatureBcs(double feature_angle) +{ + m_New2OldBc.clear(); + SetBoundaryCode set_bc; + set_bc.setGrid(m_Grid); + set_bc.setAllSurfaceCells(); + QSet all_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes(); + foreach (int bc, all_bcs) { + m_New2OldBc[bc] = bc; + } + + QMap > oldbc2cells; + int max_bc = 1; + EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); + for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { + int bc = cell_code->GetValue(id_cell); + max_bc = max(max_bc, bc + 1); + if (all_bcs.contains(bc)) { + oldbc2cells[bc] << id_cell; + } + } + bool done = false; + int old_max_bc = max_bc; + do { + vtkIdType id_start = -1; + for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { + if (cell_code->GetValue(id_cell) < old_max_bc && isSurface(id_cell, m_Grid)) { + id_start = id_cell; + break; + } + } + if (id_start == -1) { + done = true; + } else { + set_bc.setFeatureAngle(feature_angle); + set_bc.setBC(max_bc); + set_bc.setProcessAll(true); + set_bc.setSelectAllVisible(false); + set_bc.setOnlyPickedCell(false); + set_bc.setOnlyPickedCellAndNeighbours(false); + set_bc.setStart(id_start); + set_bc(); + ++max_bc; + } + } while (!done); + m_New2OldBc.clear(); + foreach (int bc, oldbc2cells.keys()) { + foreach (vtkIdType id_cell, oldbc2cells[bc]) { + m_New2OldBc[cell_code->GetValue(id_cell)] = bc; + } + } +} + +void Operation::restoreNormalBcs() +{ + EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); + for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { + int bc = cell_code->GetValue(id_cell); + cell_code->SetValue(id_cell, m_New2OldBc[bc]); + } +} + diff --git a/src/libengrid/operation.h b/src/libengrid/operation.h index ff6a527f..7646b592 100644 --- a/src/libengrid/operation.h +++ b/src/libengrid/operation.h @@ -86,7 +86,8 @@ private: // attributes Error *err; QString volume_name; QString m_TypeName; ///< typename retrieved from typeid(this).name() - QTime m_StartTime; ///< start time for run-time information + QTime m_StartTime; ///< start time for run-time information + QMap m_New2OldBc; private: // methods @@ -125,6 +126,9 @@ protected: // methods l2l_t getPartN2C() { return m_Part.getN2C(); } l2l_t getPartC2C() { return m_Part.getC2C(); } + void createFeatureBcs(double feature_angle); + void restoreNormalBcs(); + public: // methods Operation(); diff --git a/src/libengrid/polymesh.cpp b/src/libengrid/polymesh.cpp index 61c64a2c..828118d3 100644 --- a/src/libengrid/polymesh.cpp +++ b/src/libengrid/polymesh.cpp @@ -144,7 +144,7 @@ PolyMesh::PolyMesh(vtkUnstructuredGrid *grid, bool dualise, double pull_in, bool m_CreateDualMesh = false; m_OptimiseConvexity = false; m_SplitCells = false; - m_SplitFaces = false; + m_SplitFaces = split_faces; if (dualise) { for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (isVolume(id_cell, grid) && grid->GetCellType(id_cell) != VTK_POLYHEDRON) { @@ -1137,7 +1137,7 @@ void PolyMesh::splitConcaveFaces() } x.first() = x_face.last(); x.last() = x_face.first(); - double L_max = 1e99;//0.1; + double L_max = 0.1; int i1 = -1; vec3_t v; for (int i = 1; i <= num_nodes; ++i) { @@ -1397,7 +1397,7 @@ void PolyMesh::sortFaces() foreach (face_t face, m_Faces) { max_bc = max(max_bc, face.bc); } - int hash_stride = -1; + int hash_stride = 1; foreach (face_t face, m_Faces) { hash_stride = max(hash_stride, face.owner); } -- 2.11.4.GIT