Skip to content

Commit

Permalink
Merge pull request #402 from LIHPC-Computational-Geometry/LaplacianSm…
Browse files Browse the repository at this point in the history
…oother_3_UC

- Added 3D UnClassified LaplacianSmoother
  • Loading branch information
SimonCald authored Aug 2, 2024
2 parents 641acff + 67a2467 commit aee8f98
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 1 deletion.
2 changes: 2 additions & 0 deletions smoothy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(GMDS_INC
inc/gmds/smoothy/AbstractSmoother.h
inc/gmds/smoothy/AngleBasedQuadSmoother.h
inc/gmds/smoothy/LaplacianSmoother3C.h
inc/gmds/smoothy/LaplacianSmoother3UC.h
inc/gmds/smoothy/LaplacianSmoother2UC.h
inc/gmds/smoothy/HLBFGSWrapper.h
inc/gmds/smoothy/EllipticSmoothing.h
Expand All @@ -20,6 +21,7 @@ set(GMDS_SRC
src/AbstractSmoother.cpp
src/AngleBasedQuadSmoother.cpp
src/LaplacianSmoother3C.cpp
src/LaplacianSmoother3UC.cpp
src/LaplacianSmoother2UC.cpp
src/HLBFGSWrapper.cpp
src/EllipticSmoothing.cpp
Expand Down
1 change: 0 additions & 1 deletion smoothy/inc/gmds/smoothy/AbstractSmoother.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class GMDSSmoothy_API AbstractSmoother
* @param ANbIterations the expected number of iterations
*/
void setNbIterations(const int ANbIterations);
;

protected:
/** the mesh we work on*/
Expand Down
49 changes: 49 additions & 0 deletions smoothy/inc/gmds/smoothy/LaplacianSmoother3UC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*----------------------------------------------------------------------------*/
// GMDS File Headers
/*----------------------------------------------------------------------------*/
#include "AbstractSmoother.h"
#include "GMDSSmoothy_export.h"
#include <gmds/utils/CommonTypes.h>
#include <gmds/utils/Exception.h>
/*----------------------------------------------------------------------------*/
#ifndef GMDS_LAPLACIANSMOOTHER_3UC_H
# define GMDS_LAPLACIANSMOOTHER_3UC_H
/*----------------------------------------------------------------------------*/
namespace gmds {
/*----------------------------------------------------------------------------*/
namespace smoothy {
/*----------------------------------------------------------------------------*/
/** \class LaplacianSmoother
* \brief This class provides a straightforward implementation of a Laplacian
* smoother for unclassified 2D meshes.
*/
/*----------------------------------------------------------------------------*/
class GMDSSmoothy_API LaplacianSmoother3UC : public AbstractSmoother
{
public:
/**@brief constructor
* @param AMesh the mesh we work on
*/
LaplacianSmoother3UC(Mesh *AMesh);
/** @brief check if the mesh is valid for performing the algorithm.
* More specifically the mesh must not have regions and the relation N2F
* must be available.
*
* @return true if the mesh is valid, false otherwise.
*/
bool isValid() const override;
/** @brief perform the smoothing algorithm
* @return 1 if the mesh is smoothed
*/
int smooth() override;

private:
void getAdjacentNodes(const Region& ARegion, const TCellID &ANode1, TCellID &ANode2, TCellID &ANode3, TCellID &ANode4);
};
/*----------------------------------------------------------------------------*/
} // namespace smoothy
/*----------------------------------------------------------------------------*/
} // end namespace gmds
/*----------------------------------------------------------------------------*/
#endif // GMDS_LAPLACIANSMOOTHER_3UC_H
/*----------------------------------------------------------------------------*/
113 changes: 113 additions & 0 deletions smoothy/src/LaplacianSmoother3UC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*----------------------------------------------------------------------------*/
#include <gmds/smoothy/LaplacianSmoother3UC.h>
/*----------------------------------------------------------------------------*/
using namespace gmds;
using namespace gmds::smoothy;
/*----------------------------------------------------------------------------*/
LaplacianSmoother3UC::LaplacianSmoother3UC(gmds::Mesh *AMesh) : AbstractSmoother(AMesh) {}
/*----------------------------------------------------------------------------*/
bool LaplacianSmoother3UC::isValid() const
{
MeshModel model = m_mesh->getModel();

if (!model.has(N2R) && !model.has(R2N)) return false;

return true;
}
/*----------------------------------------------------------------------------*/
int LaplacianSmoother3UC::smooth()
{
// First we build the N2N connectivity for the nodes to be smoothed
std::map<TCellID, std::set<TCellID>> n2n;
for (auto nid : m_nodes) {
Node ni = m_mesh->get<Node>(nid);
std::vector<Region> ni_regions = ni.get<Region>();
for (const auto& r : ni_regions) {
TCellID id1, id2, id3;
getAdjacentNodes(r, nid, id1, id2, id3);
n2n[nid].insert(id1);
n2n[nid].insert(id2);
n2n[nid].insert(id3);
}
}

for (auto i = 0; i < m_nb_iterations; i++) {

// We smooth each node in a naive way
for (auto nid : m_nodes) {
Node ni = m_mesh->get<Node>(nid);
std::set<TCellID> adj_n = n2n[nid];
math::Point pi(0, 0, 0);
for (auto adj_id : adj_n) {
math::Point pj = m_mesh->get<Node>(adj_id).point();
pi = pi + pj;
}
pi = pi * (1.0 / adj_n.size());
ni.setPoint(pi);
}
}

return 1;
}

/*----------------------------------------------------------------------------*/
void LaplacianSmoother3UC::getAdjacentNodes(const Region& ARegion, const TCellID & ANode1, TCellID& ANode2, TCellID& ANode3, TCellID& ANode4){
std::vector<TCellID> nodes = ARegion.getIDs<Node>();
int index1 = -1, index2, index3, index4;
for (int i = 0; i < 8; i++) {
if (nodes[i] == ANode1)
index1 = i;
}
switch (index1) {
case -1:
#ifdef _DEBUG
std::cout << "Index error" << std::endl;
#endif //_DEBUG
throw GMDSException("getAdjacentNodes: node 1 is not adjacent to the face");
break;
case 0:
index2 = 3;
index3 = 1;
index4 = 4;
break;
case 1:
index2 = 0;
index3 = 2;
index4 = 5;
break;
case 2:
index2 = 1;
index3 = 3;
index4 = 6;
break;
case 3:
index2 = 2;
index3 = 0;
index4 = 7;
break;
case 4:
index2 = 7;
index3 = 5;
index4 = 0;
break;
case 5:
index2 = 4;
index3 = 6;
index4 = 1;
break;
case 6:
index2 = 5;
index3 = 7;
index4 = 2;
break;
case 7:
index2 = 6;
index3 = 4;
index4 = 3;
break;
}

ANode2 = nodes[index2];
ANode3 = nodes[index3];
ANode4 = nodes[index4];
}

0 comments on commit aee8f98

Please sign in to comment.