From 7a7ec18c13a7e733ffb0bee1722f48f4245ea51a Mon Sep 17 00:00:00 2001 From: Oliver Gloth Date: Tue, 7 May 2013 11:08:45 +0200 Subject: [PATCH] not required anymore --- src/libengrid/orthogonalityoptimiser.cpp | 281 ------------------------------- src/libengrid/orthogonalityoptimiser.h | 47 ------ src/libengrid/sharpenedges.cpp | 238 -------------------------- src/libengrid/sharpenedges.h | 48 ------ 4 files changed, 614 deletions(-) delete mode 100644 src/libengrid/orthogonalityoptimiser.cpp delete mode 100644 src/libengrid/orthogonalityoptimiser.h delete mode 100644 src/libengrid/sharpenedges.cpp delete mode 100644 src/libengrid/sharpenedges.h diff --git a/src/libengrid/orthogonalityoptimiser.cpp b/src/libengrid/orthogonalityoptimiser.cpp deleted file mode 100644 index bd29782d..00000000 --- a/src/libengrid/orthogonalityoptimiser.cpp +++ /dev/null @@ -1,281 +0,0 @@ -#include "orthogonalityoptimiser.h" -#include "surfaceprojection.h" -#include "guimainwindow.h" - -OrthogonalityOptimiser::OrthogonalityOptimiser() -{ - m_StrictPrismChecking = true; -} - -double OrthogonalityOptimiser::faceError(const face_t &face, vec3_t x) -{ - vec3_t n = face.c1 - face.c2; - n.normalise(); - vec3_t xm = x; - foreach (vtkIdType id_node, face.nodes) { - if (id_node != m_IdNode) { - vec3_t xn; - m_Grid->GetPoint(id_node, xn.data()); - xm += xn; - } - } - xm *= 1.0/face.nodes.size(); - vec3_t v = x - xm; - if (!checkVector(v)) { - EG_BUG; - } - return sqr(v*n); -} - -double OrthogonalityOptimiser::func(vec3_t x) -{ - if (m_IdNode == 427) { - //cout << "stop" << endl; - } - double err = 0; - foreach (int i_face, m_Node2Face[m_IdNode]) { - double e = faceError(m_Faces[i_face], x); - if (isnan(e)) { - EG_BUG; - } - if (isinf(e)) { - EG_BUG; - } - err += e; - } - return err; -} - -void OrthogonalityOptimiser::getFace(vtkIdType id_cell, int subidx, QSet &nodes) -{ - nodes.clear(); - vtkIdType N_pts, *pts; - m_Grid->GetCellPoints(id_cell, N_pts, pts); - vtkIdType type_cell = m_Grid->GetCellType(id_cell); - if (type_cell == VTK_TETRA) { - if (subidx == 0) { - nodes.insert(pts[2]); - nodes.insert(pts[1]); - nodes.insert(pts[0]); - } - if (subidx == 1) { - nodes.insert(pts[1]); - nodes.insert(pts[3]); - nodes.insert(pts[0]); - } - if (subidx == 2) { - nodes.insert(pts[3]); - nodes.insert(pts[2]); - nodes.insert(pts[0]); - } - if (subidx == 3) { - nodes.insert(pts[2]); - nodes.insert(pts[3]); - nodes.insert(pts[1]); - } - } - if (type_cell == VTK_WEDGE) { - if (subidx == 0) { - nodes.insert(pts[0]); - nodes.insert(pts[1]); - nodes.insert(pts[2]); - } - if (subidx == 1) { - nodes.insert(pts[3]); - nodes.insert(pts[5]); - nodes.insert(pts[4]); - } - if (subidx == 2) { - nodes.insert(pts[3]); - nodes.insert(pts[4]); - nodes.insert(pts[1]); - nodes.insert(pts[0]); - } - if (subidx == 3) { - nodes.insert(pts[1]); - nodes.insert(pts[4]); - nodes.insert(pts[2]); - nodes.insert(pts[5]); - } - if (subidx == 4) { - nodes.insert(pts[0]); - nodes.insert(pts[2]); - nodes.insert(pts[5]); - nodes.insert(pts[3]); - } - } - if (type_cell == VTK_HEXAHEDRON) { - if (subidx == 0) { - nodes.insert(pts[0]); - nodes.insert(pts[3]); - nodes.insert(pts[2]); - nodes.insert(pts[1]); - } - if (subidx == 1) { - nodes.insert(pts[4]); - nodes.insert(pts[5]); - nodes.insert(pts[6]); - nodes.insert(pts[7]); - } - if (subidx == 2) { - nodes.insert(pts[0]); - nodes.insert(pts[1]); - nodes.insert(pts[5]); - nodes.insert(pts[4]); - } - if (subidx == 3) { - nodes.insert(pts[3]); - nodes.insert(pts[7]); - nodes.insert(pts[6]); - nodes.insert(pts[2]); - } - if (subidx == 4) { - nodes.insert(pts[0]); - nodes.insert(pts[4]); - nodes.insert(pts[7]); - nodes.insert(pts[3]); - } - if (subidx == 5) { - nodes.insert(pts[1]); - nodes.insert(pts[2]); - nodes.insert(pts[6]); - nodes.insert(pts[5]); - } - } -} - -int OrthogonalityOptimiser::getNumberOfFaces(vtkIdType id_cell) -{ - vtkIdType cell_type = m_Grid->GetCellType(id_cell); - int N = 0; - if (cell_type == VTK_TETRA) N = 4; - else if (cell_type == VTK_PYRAMID) N = 5; - else if (cell_type == VTK_WEDGE) N = 5; - else if (cell_type == VTK_HEXAHEDRON) N = 6; - return N; -} - -void OrthogonalityOptimiser::buildNode2Face() -{ - l2g_t cells = m_Part.getCells(); - m_Node2Face.resize(m_Grid->GetNumberOfPoints()); - QList faces; - foreach (vtkIdType id_cell1, cells) { - if (!isSurface(id_cell1, m_Grid)) { - for (int i = 0; i < m_Part.c2cGSize(id_cell1); ++i) { - vtkIdType id_cell2 = m_Part.c2cGG(id_cell1, i); - if (id_cell1 < id_cell2 && !isSurface(id_cell2, m_Grid)) { - for (int j = 0; j < getNumberOfFaces(id_cell1); ++j) { - QSet nodes1; - getFace(id_cell1, j, nodes1); - for (int k = 0; k < getNumberOfFaces(id_cell2); ++k) { - QSet nodes2; - getFace(id_cell2, j, nodes2); - if (nodes1 == nodes2) { - face_t F; - F.c1 = cellCentre(m_Grid, id_cell1); - F.c2 = cellCentre(m_Grid, id_cell2); - F.nodes.resize(nodes1.size()); - qCopy(nodes1.begin(), nodes1.end(), F.nodes.begin()); - faces.append(F); - } - } - } - } - } - } - } - m_Faces.resize(faces.size()); - qCopy(faces.begin(), faces.end(), m_Faces.begin()); - for (int i = 0; i < m_Faces.size(); ++i) { - foreach (vtkIdType id_node, m_Faces[i].nodes) { - m_Node2Face[id_node].append(i); - } - } -} - -void OrthogonalityOptimiser::fixBoundaryNodes() -{ - l2g_t cells = m_Part.getCells(); - m_Fixed.fill(false, m_Grid->GetNumberOfPoints()); - EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); - QVector > n2bc(m_Grid->GetNumberOfPoints()); - foreach (vtkIdType id_cell, cells) { - if (isSurface(id_cell, m_Grid)) { - vtkIdType N_pts, *pts; - m_Grid->GetCellPoints(id_cell, N_pts, pts); - for (int i = 0; i < N_pts; ++i) { - n2bc[pts[i]].insert(cell_code->GetValue(id_cell)); - } - } - } - m_Projection.fill(NULL, m_Grid->GetNumberOfPoints()); - for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { - if (n2bc[id_node].size() > 1) { - m_Fixed[id_node] = true; - } else if (n2bc[id_node].size() == 1) { - GuiMainWindow::pointer()->getSurfProj(n2bc[id_node].toList().first()); - } - if (m_Node2Face[id_node].size() == 0) { - m_Fixed[id_node] = true; - } - } -} - -vec3_t OrthogonalityOptimiser::newPosition(vtkIdType id_node) -{ - vec3_t x_old; - m_Grid->GetPoint(id_node, x_old.data()); - if (m_Node2Face[id_node].size() == 0) { - return x_old; - } - vec3_t x_new(0,0,0); - foreach (int i_face, m_Node2Face[id_node]) { - const face_t &face = m_Faces[i_face]; - vec3_t n = face.c1 - face.c2; - n.normalise(); - vec3_t xm(0,0,0); - foreach (vtkIdType id_node, face.nodes) { - vec3_t xn; - m_Grid->GetPoint(id_node, xn.data()); - xm += xn; - } - xm *= 1.0/face.nodes.size(); - vec3_t v = x_old - xm; - if (!checkVector(v)) { - EG_BUG; - } - vec3_t Dx = (v*n)*n; - x_new += x_old - Dx; - } - x_new *= (1.0/m_Node2Face[id_node].size()); - return x_new; -} - -void OrthogonalityOptimiser::operate() -{ - computeNormals(); - buildNode2Face(); - fixBoundaryNodes(); - l2g_t nodes = m_Part.getNodes(); - int N = 0; - foreach (vtkIdType id_node, nodes) { - if (!m_Fixed[id_node]) { - m_IdNode = id_node; - vec3_t x_old; - m_Grid->GetPoint(id_node, x_old.data()); - //vec3_t x_new = optimise(x_old); - vec3_t x_new = newPosition(id_node); - if (checkVector(x_new)) { - if (m_Projection[id_node]) { - x_new = m_Projection[id_node]->project(x_new, id_node); - } - if (checkVector(x_new)) { - vec3_t Dx = x_new - x_old; - if (moveNode(id_node, Dx)) ++N; - } - } - } - } - cout << N << " nodes optimised" << endl; -} diff --git a/src/libengrid/orthogonalityoptimiser.h b/src/libengrid/orthogonalityoptimiser.h deleted file mode 100644 index f1b13248..00000000 --- a/src/libengrid/orthogonalityoptimiser.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef ORTHOGONALITYOPTIMISER_H -#define ORTHOGONALITYOPTIMISER_H - -class OrthogonalityOptimiser; -class SurfaceProjection; - -#include "optimisation.h" -#include "gridsmoother.h" - -class OrthogonalityOptimiser : public GridSmoother, public Optimisation -{ - -protected: // types - - struct face_t { - vec3_t c1, c2; - QVector nodes; - }; - -protected: // attributes - - QVector m_Faces; - QVector > m_Node2Face; - QVector m_Fixed; - QVector m_Projection; - - vtkIdType m_IdNode; - -protected: // methods - - void getFace(vtkIdType id_cell, int subidx, QSet &nodes); - int getNumberOfFaces(vtkIdType id_cell); - void buildNode2Face(); - void fixBoundaryNodes(); - double faceError(const face_t& face, vec3_t x); - vec3_t newPosition(vtkIdType id_node); - - virtual double func(vec3_t x); - virtual void operate(); - -public: // methods - - OrthogonalityOptimiser(); - -}; - -#endif // ORTHOGONALITYOPTIMISER_H diff --git a/src/libengrid/sharpenedges.cpp b/src/libengrid/sharpenedges.cpp deleted file mode 100644 index 0af3efee..00000000 --- a/src/libengrid/sharpenedges.cpp +++ /dev/null @@ -1,238 +0,0 @@ -// -// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// + + -// + This file is part of enGrid. + -// + + -// + Copyright 2008-2012 enGits GmbH + -// + + -// + enGrid is free software: you can redistribute it and/or modify + -// + it under the terms of the GNU General Public License as published by + -// + the Free Software Foundation, either version 3 of the License, or + -// + (at your option) any later version. + -// + + -// + enGrid is distributed in the hope that it will be useful, + -// + but WITHOUT ANY WARRANTY; without even the implied warranty of + -// + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + -// + GNU General Public License for more details. + -// + + -// + You should have received a copy of the GNU General Public License + -// + along with enGrid. If not, see . + -// + + -// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// - -#include "sharpenedges.h" -#include "guimainwindow.h" -#include "laplacesmoother.h" - -SharpenEdges::SharpenEdges() -{ - EG_TYPENAME; - m_PerformGeometricTests = true; - m_UseProjectionForSmoothing = true; - m_UseNormalCorrectionForSmoothing = false; - m_AllowFeatureEdgeSwapping = false; - m_RespectFeatureEdgesForDeleteNodes = false; - m_FeatureAngle = deg2rad(180); - m_EdgeAngle = deg2rad(180); - m_FeatureAngleForDeleteNodes = deg2rad(20); - m_NumDelaunaySweeps = 5; - m_NumSmoothSteps = 5; -} - - -void SharpenEdges::assignBCs() -{ - QVector bc_set(m_Grid->GetNumberOfCells(),0); - EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - bool certain_bc = true; - vtkIdType N_pts, *pts; - m_Grid->GetCellPoints(id_cell, N_pts, pts); - for (int i = 0; i < N_pts; ++i) { - vtkIdType id_node = pts[i]; - for (int j = 0; j < m_Part.n2cGSize(pts[i]); ++j) { - if (cell_code->GetValue(id_cell) != cell_code->GetValue(m_Part.n2cGG(pts[i], j))) { - certain_bc = false; - break; - } - } - } - if (certain_bc) { - bc_set[id_cell] = cell_code->GetValue(id_cell); - } - } - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - if (bc_set[id_cell] == 0) { - cell_code->SetValue(id_cell, 9999); - } - } - GuiMainWindow::pointer()->storeSurfaceProjection(); - int N; - int count = 0; - double scal_par = 1.0; - do { - N = 0; - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - if (bc_set[id_cell] == 0) { - ++N; - vec3_t n1 = cellNormal(m_Grid, id_cell); - int bc = 9999; - double scal_max = -3; - vtkIdType id_copy = -1; - for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) { - vtkIdType id_neigh = m_Part.c2cGG(id_cell, i); - vec3_t n2 = cellNormal(m_Grid, id_neigh); - n1.normalise(); - n2.normalise(); - double scal = n1*n2; - bool parallel = false; - if (scal >= scal_par && cell_code->GetValue(id_neigh) < 9999) { - scal = 1.0; - parallel = true; - } - if (scal > scal_max || parallel) { - bc = cell_code->GetValue(id_neigh); - scal_max = scal; - } - } - if (bc < 9999) { - bc_set[id_cell] = bc; - cell_code->SetValue(id_cell, bc); - } - } - } - scal_par *= 0.99; - cout << scal_par << ',' << N << endl; - ++count; - } while (N > 0 && count < 1000); -} - - -/* -void SharpenEdges::assignBCs() -{ - QVector bc_set(m_Grid->GetNumberOfCells(),0); - QVector bc_old(m_Grid->GetNumberOfCells(),0); - EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - bool certain_bc = true; - vtkIdType N_pts, *pts; - m_Grid->GetCellPoints(id_cell, N_pts, pts); - bc_old[id_cell] = cell_code->GetValue(id_cell); - for (int i = 0; i < N_pts; ++i) { - for (int j = 0; j < m_Part.n2cGSize(pts[i]); ++j) { - if (cell_code->GetValue(id_cell) != cell_code->GetValue(m_Part.n2cGG(pts[i], j))) { - certain_bc = false; - break; - } - } - } - if (certain_bc) { - bc_set[id_cell] = cell_code->GetValue(id_cell); - } - } - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - if (bc_set[id_cell] == 0) { - cell_code->SetValue(id_cell, 9999); - } - } - GuiMainWindow::pointer()->storeSurfaceProjection(); - - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - if (cell_code->GetValue(id_cell) == 9999) { - cell_code->SetValue(id_cell, bc_old[id_cell]); - } - } - - int N; - int count = 0; - do { - N = 0; - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - bool ok = false; - int bc; - for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) { - bc = cell_code->GetValue(m_Part.c2cGG(id_cell, i)); - if (bc == cell_code->GetValue(id_cell)) { - ok = true; - break; - } - } - if (!ok) { - cell_code->SetValue(id_cell, bc); - ++N; - } - } - ++count; - } while (N > 0 && count < 1000); -} -*/ - -void SharpenEdges::operate() -{ - cout << "sharpening edges" << endl; - assignBCs(); - return; - - - EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code"); - QVector > n2bc(m_Grid->GetNumberOfPoints()); - for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { - vtkIdType N_pts, *pts; - m_Grid->GetCellPoints(id_cell, N_pts, pts); - int bc = cell_code->GetValue(id_cell); - for (int i = 0; i < N_pts; ++i) { - n2bc[pts[i]].insert(bc); - } - } - int N = 0; - for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { - if (n2bc[id_node].size() > 1) { - ++N; - } - } - int total_count = 0; - int count = 0; - for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { - if (n2bc[id_node].size() > 1) { - ++count; - ++total_count; - vec3_t x; - m_Grid->GetPoint(id_node, x.data()); - for (int i_proj_iter = 0; i_proj_iter < 20; ++i_proj_iter) { - foreach (int bc, n2bc[id_node]) { - x = GuiMainWindow::pointer()->getSurfProj(bc)->project(x, id_node); - } - } - m_Grid->GetPoints()->SetPoint(id_node, x.data()); - if (count >= 100) { - cout << total_count << " of " << N << " nodes corrected" << endl; - count = 0; - } - } - } - GuiMainWindow::pointer()->storeSurfaceProjection(); - - -/* - { - LaplaceSmoother lap; - lap.setGrid(m_Grid); - QVector cls; - m_BoundaryCodes = GuiMainWindow::pointer()->getAllBoundaryCodes(); - getSurfaceCells(m_BoundaryCodes, cls, m_Grid); - lap.setCells(cls); - lap.setNumberOfIterations(5); - lap.setBoundaryCodes(m_BoundaryCodes);//IMPORTANT: so that unselected nodes become fixed when node types are updated! - lap.setProjectionOn(); - lap.setNormalCorrectionOff(); - lap.setFreeProjectionForEdgesOn(); - lap(); - } -*/ - - UpdateCellIndex(m_Grid); - GuiMainWindow::pointer()->updateBoundaryCodes(true); - GuiMainWindow::pointer()->updateActors(); -} diff --git a/src/libengrid/sharpenedges.h b/src/libengrid/sharpenedges.h deleted file mode 100644 index 004bb49b..00000000 --- a/src/libengrid/sharpenedges.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// + + -// + This file is part of enGrid. + -// + + -// + Copyright 2008-2012 enGits GmbH + -// + + -// + enGrid is free software: you can redistribute it and/or modify + -// + it under the terms of the GNU General Public License as published by + -// + the Free Software Foundation, either version 3 of the License, or + -// + (at your option) any later version. + -// + + -// + enGrid is distributed in the hope that it will be useful, + -// + but WITHOUT ANY WARRANTY; without even the implied warranty of + -// + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + -// + GNU General Public License for more details. + -// + + -// + You should have received a copy of the GNU General Public License + -// + along with enGrid. If not, see . + -// + + -// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// - -#ifndef SHARPENEDGES_H -#define SHARPENEDGES_H - -#include "surfacealgorithm.h" - -class SharpenEdges : public SurfaceAlgorithm -{ - -private: // methods - - void assignBCs(); - - -protected: // methods - - virtual void operate(); - - -public: // methods - - SharpenEdges(); - -}; - -#endif // SHARPENEDGES_H -- 2.11.4.GIT