Skip to content
Snippets Groups Projects
Commit 910d13f2 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

resurect Plugin(ExtractEdges) (just for meshes at the moment)

parent 17451aa2
No related branches found
No related tags found
No related merge requests found
...@@ -16,49 +16,10 @@ ...@@ -16,49 +16,10 @@
#include "GmshMessage.h" #include "GmshMessage.h"
#include "MLine.h" #include "MLine.h"
#include "meshGFaceDelaunayInsertion.h" #include "meshGFaceDelaunayInsertion.h"
#include "meshGFaceOptimize.h"
#include "discreteEdge.h" #include "discreteEdge.h"
#include "discreteFace.h" #include "discreteFace.h"
edge_angle::edge_angle(MVertex *_v1, MVertex *_v2, MElement *t1, MElement *t2) struct compareMLinePtr {
: v1(_v1), v2(_v2)
{
if(!t2) angle = 0;
else{
double c1[3];
double c2[3];
double c3[3];
{
MVertex *p1 = t1->getVertex(0);
MVertex *p2 = t1->getVertex(1);
MVertex *p3 = t1->getVertex(2);
double a[3] = {p1->x() - p2->x(), p1->y() - p2->y(), p1->z() - p2->z()};
double b[3] = {p1->x() - p3->x(), p1->y() - p3->y(), p1->z() - p3->z()};
c1[2] = a[0] * b[1] - a[1] * b[0];
c1[1] = -a[0] * b[2] + a[2] * b[0];
c1[0] = a[1] * b[2] - a[2] * b[1];
}
{
MVertex *p1 = t2->getVertex(0);
MVertex *p2 = t2->getVertex(1);
MVertex *p3 = t2->getVertex(2);
double a[3] = {p1->x() - p2->x(), p1->y() - p2->y(), p1->z() - p2->z()};
double b[3] = {p1->x() - p3->x(), p1->y() - p3->y(), p1->z() - p3->z()};
c2[2] = a[0] * b[1] - a[1] * b[0];
c2[1] = -a[0] * b[2] + a[2] * b[0];
c2[0] = a[1] * b[2] - a[2] * b[1];
}
norme(c1);
norme(c2);
prodve(c1, c2, c3);
double cosa; prosca(c1, c2, &cosa);
double sina = norme(c3);
angle = atan2(sina, cosa);
}
}
struct compareMLinePtr
{
bool operator () (MLine *l1, MLine *l2) const bool operator () (MLine *l1, MLine *l2) const
{ {
static Less_Edge le; static Less_Edge le;
...@@ -66,23 +27,6 @@ struct compareMLinePtr ...@@ -66,23 +27,6 @@ struct compareMLinePtr
} }
}; };
static void buildListOfEdgeAngle(e2t_cont adj, std::vector<edge_angle> &edges_detected,
std::vector<edge_angle> &edges_lonly)
{
e2t_cont::iterator it = adj.begin();
for(; it != adj.end(); ++it){
if(it->second.second)
edges_detected.push_back(edge_angle(it->first.getVertex(0),
it->first.getVertex(1),
it->second.first, it->second.second));
else
edges_lonly.push_back(edge_angle(it->first.getVertex(0),
it->first.getVertex(1),
it->second.first, it->second.second));
}
std::sort(edges_detected.begin(), edges_detected.end());
}
static void recurClassify(MTri3 *t, GFace *gf, static void recurClassify(MTri3 *t, GFace *gf,
std::map<MLine*, GEdge*, compareMLinePtr> &lines, std::map<MLine*, GEdge*, compareMLinePtr> &lines,
std::map<MTriangle*, GFace*> &reverse) std::map<MTriangle*, GFace*> &reverse)
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <FL/Fl_Value_Input.H> #include <FL/Fl_Value_Input.H>
#include "GModel.h" #include "GModel.h"
#include "MElement.h" #include "MElement.h"
#include "meshGFaceOptimize.h"
#define CLASS_BUTTON_SELECT_ELEMENTS 0 #define CLASS_BUTTON_SELECT_ELEMENTS 0
#define CLASS_BUTTON_SELECT_ALL_ELEMENTS 1 #define CLASS_BUTTON_SELECT_ALL_ELEMENTS 1
...@@ -28,17 +29,6 @@ ...@@ -28,17 +29,6 @@
#define CLASS_VALUE_ANGLE 0 #define CLASS_VALUE_ANGLE 0
class edge_angle {
public :
MVertex *v1, *v2;
double angle;
edge_angle(MVertex *_v1, MVertex *_v2, MElement *t1, MElement *t2);
bool operator < (const edge_angle &other) const
{
return other.angle < angle;
}
};
class classificationEditor { class classificationEditor {
public: public:
std::vector<MTriangle*> elements; std::vector<MTriangle*> elements;
......
...@@ -16,6 +16,43 @@ ...@@ -16,6 +16,43 @@
#include "GmshMessage.h" #include "GmshMessage.h"
#include "Generator.h" #include "Generator.h"
edge_angle::edge_angle(MVertex *_v1, MVertex *_v2, MElement *t1, MElement *t2)
: v1(_v1), v2(_v2)
{
if(!t2) angle = 0;
else{
double c1[3];
double c2[3];
double c3[3];
{
MVertex *p1 = t1->getVertex(0);
MVertex *p2 = t1->getVertex(1);
MVertex *p3 = t1->getVertex(2);
double a[3] = {p1->x() - p2->x(), p1->y() - p2->y(), p1->z() - p2->z()};
double b[3] = {p1->x() - p3->x(), p1->y() - p3->y(), p1->z() - p3->z()};
c1[2] = a[0] * b[1] - a[1] * b[0];
c1[1] = -a[0] * b[2] + a[2] * b[0];
c1[0] = a[1] * b[2] - a[2] * b[1];
}
{
MVertex *p1 = t2->getVertex(0);
MVertex *p2 = t2->getVertex(1);
MVertex *p3 = t2->getVertex(2);
double a[3] = {p1->x() - p2->x(), p1->y() - p2->y(), p1->z() - p2->z()};
double b[3] = {p1->x() - p3->x(), p1->y() - p3->y(), p1->z() - p3->z()};
c2[2] = a[0] * b[1] - a[1] * b[0];
c2[1] = -a[0] * b[2] + a[2] * b[0];
c2[0] = a[1] * b[2] - a[2] * b[1];
}
norme(c1);
norme(c2);
prodve(c1, c2, c3);
double cosa; prosca(c1, c2, &cosa);
double sina = norme(c3);
angle = atan2(sina, cosa);
}
}
static void setLcsInit(MTriangle *t, std::map<MVertex*, double> &vSizes) static void setLcsInit(MTriangle *t, std::map<MVertex*, double> &vSizes)
{ {
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
...@@ -194,6 +231,23 @@ void buildEdgeToTriangle(std::vector<MTriangle*> &tris, e2t_cont &adj) ...@@ -194,6 +231,23 @@ void buildEdgeToTriangle(std::vector<MTriangle*> &tris, e2t_cont &adj)
buildEdgeToElement(tris, adj); buildEdgeToElement(tris, adj);
} }
void buildListOfEdgeAngle(e2t_cont adj, std::vector<edge_angle> &edges_detected,
std::vector<edge_angle> &edges_lonly)
{
e2t_cont::iterator it = adj.begin();
for(; it != adj.end(); ++it){
if(it->second.second)
edges_detected.push_back(edge_angle(it->first.getVertex(0),
it->first.getVertex(1),
it->second.first, it->second.second));
else
edges_lonly.push_back(edge_angle(it->first.getVertex(0),
it->first.getVertex(1),
it->second.first, it->second.second));
}
std::sort(edges_detected.begin(), edges_detected.end());
}
void parametricCoordinates(MElement *t, GFace *gf, double u[4], double v[4]) void parametricCoordinates(MElement *t, GFace *gf, double u[4], double v[4])
{ {
for(int j = 0; j < t->getNumVertices(); j++){ for(int j = 0; j < t->getNumVertices(); j++){
......
...@@ -16,11 +16,24 @@ ...@@ -16,11 +16,24 @@
class GFace; class GFace;
class MVertex; class MVertex;
class edge_angle {
public :
MVertex *v1, *v2;
double angle;
edge_angle(MVertex *_v1, MVertex *_v2, MElement *t1, MElement *t2);
bool operator < (const edge_angle &other) const
{
return other.angle < angle;
}
};
typedef std::map<MVertex*, std::vector<MElement*> > v2t_cont; typedef std::map<MVertex*, std::vector<MElement*> > v2t_cont;
typedef std::map<MEdge, std::pair<MElement*, MElement*>, Less_Edge> e2t_cont; typedef std::map<MEdge, std::pair<MElement*, MElement*>, Less_Edge> e2t_cont;
void buildVertexToTriangle(std::vector<MTriangle*> &, v2t_cont &adj); void buildVertexToTriangle(std::vector<MTriangle*> &, v2t_cont &adj);
void buildEdgeToTriangle(std::vector<MTriangle*> &, e2t_cont &adj); void buildEdgeToTriangle(std::vector<MTriangle*> &, e2t_cont &adj);
void buildListOfEdgeAngle(e2t_cont adj, std::vector<edge_angle> &edges_detected,
std::vector<edge_angle> &edges_lonly);
void laplaceSmoothing(GFace *gf); void laplaceSmoothing(GFace *gf);
void edgeSwappingLawson(GFace *gf); void edgeSwappingLawson(GFace *gf);
......
...@@ -23,7 +23,7 @@ set(SRC ...@@ -23,7 +23,7 @@ set(SRC
Probe.cpp Probe.cpp
HarmonicToTime.cpp ModulusPhase.cpp HarmonicToTime.cpp ModulusPhase.cpp
HomologyComputation.cpp HomologyComputation.cpp
Distance.cpp Distance.cpp ExtractEdges.cpp
) )
file(GLOB HDR RELATIVE ${CMAKE_SOURCE_DIR}/Plugin *.h) file(GLOB HDR RELATIVE ${CMAKE_SOURCE_DIR}/Plugin *.h)
......
// Gmsh - Copyright (C) 1997-2010 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>.
#include "GModel.h"
#include "meshGFaceOptimize.h"
#include "ExtractEdges.h"
StringXNumber ExtractEdgesOptions_Number[] = {
{GMSH_FULLRC, "Angle", NULL, 40.},
{GMSH_FULLRC, "IncludeBoundary", NULL, 1.},
};
extern "C"
{
GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin()
{
return new GMSH_ExtractEdgesPlugin();
}
}
std::string GMSH_ExtractEdgesPlugin::getHelp() const
{
return "Plugin(ExtractEdges) extracts sharp edges "
"from a triangular mesh.\n\n"
"Plugin(ExtractEdges) creates one new view.";
}
int GMSH_ExtractEdgesPlugin::getNbOptions() const
{
return sizeof(ExtractEdgesOptions_Number) / sizeof(StringXNumber);
}
StringXNumber *GMSH_ExtractEdgesPlugin::getOption(int iopt)
{
return &ExtractEdgesOptions_Number[iopt];
}
static void add_edge(edge_angle &ea, PViewDataList *data)
{
data->SL.push_back(ea.v1->x());
data->SL.push_back(ea.v2->x());
data->SL.push_back(ea.v1->y());
data->SL.push_back(ea.v2->y());
data->SL.push_back(ea.v1->z());
data->SL.push_back(ea.v2->z());
data->SL.push_back(1.);
data->SL.push_back(1.);
data->NbSL++;
}
PView *GMSH_ExtractEdgesPlugin::execute(PView *v)
{
std::vector<MTriangle*> elements;
for(GModel::fiter it = GModel::current()->firstFace();
it != GModel::current()->lastFace(); ++it)
elements.insert(elements.end(), (*it)->triangles.begin(),
(*it)->triangles.end());
if(elements.empty()){
Msg::Error("No triangles in mesh to extract edges from");
return 0;
}
PView *v2 = new PView();
PViewDataList *data2 = getDataList(v2);
e2t_cont adj;
buildEdgeToTriangle(elements, adj);
std::vector<edge_angle> edges_detected, edges_lonly;
buildListOfEdgeAngle(adj, edges_detected, edges_lonly);
double threshold = ExtractEdgesOptions_Number[0].def / 180. * M_PI;
for(unsigned int i = 0; i < edges_detected.size(); i++){
if(edges_detected[i].angle <= threshold) break;
add_edge(edges_detected[i], data2);
}
if(ExtractEdgesOptions_Number[1].def){
for(unsigned int i = 0; i < edges_lonly.size(); i++){
add_edge(edges_lonly[i], data2);
}
}
data2->setName("ExtractEdges");
data2->setFileName("ExtractEdges.pos");
data2->finalize();
return v2;
}
// Gmsh - Copyright (C) 1997-2010 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>.
#ifndef _EXTRACT_EDGES_H_
#define _EXTRACT_EDGES_H_
#include "Plugin.h"
extern "C"
{
GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin();
}
class GMSH_ExtractEdgesPlugin : public GMSH_PostPlugin
{
public:
GMSH_ExtractEdgesPlugin(){}
std::string getName() const { return "ExtractEdges"; }
std::string getShortHelp() const
{
return "Extract sharp edges from triangular mesh";
}
std::string getHelp() const;
int getNbOptions() const;
StringXNumber* getOption(int iopt);
PView *execute(PView *);
};
#endif
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "GSHHS.h" #include "GSHHS.h"
#include "HomologyComputation.h" #include "HomologyComputation.h"
#include "Distance.h" #include "Distance.h"
#include "ExtractEdges.h"
// for testing purposes only :-) // for testing purposes only :-)
#undef HAVE_DLOPEN #undef HAVE_DLOPEN
...@@ -217,6 +218,8 @@ void PluginManager::registerDefaultPlugins() ...@@ -217,6 +218,8 @@ void PluginManager::registerDefaultPlugins()
#endif #endif
allPlugins.insert(std::pair<std::string, GMSH_Plugin*> allPlugins.insert(std::pair<std::string, GMSH_Plugin*>
("Distance", GMSH_RegisterDistancePlugin())); ("Distance", GMSH_RegisterDistancePlugin()));
allPlugins.insert(std::pair<std::string, GMSH_Plugin*>
("ExtractEdges", GMSH_RegisterExtractEdgesPlugin()));
} }
#if defined(HAVE_FLTK) #if defined(HAVE_FLTK)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment