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

pp+MVertexOctree

parent ab975561
No related branches found
No related tags found
No related merge requests found
...@@ -30,10 +30,9 @@ set(SRC ...@@ -30,10 +30,9 @@ set(SRC
findLinks.cpp findLinks.cpp
SOrientedBoundingBox.cpp SOrientedBoundingBox.cpp
GeomMeshMatcher.cpp GeomMeshMatcher.cpp
MVertex.cpp MVertex.cpp MVertexOctree.cpp
MFace.cpp MFace.cpp
MElement.cpp MElement.cpp MElementOctree.cpp
MElementOctree.cpp
MLine.cpp MTriangle.cpp MQuadrangle.cpp MTetrahedron.cpp MLine.cpp MTriangle.cpp MQuadrangle.cpp MTetrahedron.cpp
MHexahedron.cpp MPrism.cpp MPyramid.cpp MElementCut.cpp MHexahedron.cpp MPrism.cpp MPyramid.cpp MElementCut.cpp
MZone.cpp MZoneBoundary.cpp MZone.cpp MZoneBoundary.cpp
......
// 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 _MELEMENT_OCTREE_ #ifndef _MELEMENT_OCTREE_
#define _MELEMENT_OCTREE_ #define _MELEMENT_OCTREE_
......
...@@ -222,11 +222,20 @@ std::set<MVertex*, MVertexLessThanLexicographic>::iterator ...@@ -222,11 +222,20 @@ std::set<MVertex*, MVertexLessThanLexicographic>::iterator
MVertex::linearSearch(std::set<MVertex*, MVertexLessThanLexicographic> &pos) MVertex::linearSearch(std::set<MVertex*, MVertexLessThanLexicographic> &pos)
{ {
double tol = MVertexLessThanLexicographic::tolerance; double tol = MVertexLessThanLexicographic::tolerance;
double dmin = 1e22;
std::set<MVertex*, MVertexLessThanLexicographic>::iterator itmin = pos.end();
for(std::set<MVertex*, MVertexLessThanLexicographic>::iterator it = pos.begin(); for(std::set<MVertex*, MVertexLessThanLexicographic>::iterator it = pos.begin();
it != pos.end(); ++it){ it != pos.end(); ++it){
double d = distance(*it);
if(d < dmin){
dmin = d;
itmin = it;
}
if(distance(*it) < tol) return it; if(distance(*it) < tol) return it;
} }
return pos.end(); Msg::Warning("Could not find point: returning closest (dist = %g)", dmin);
//return pos.end();
return itmin;
} }
static void getAllParameters(MVertex *v, GFace *gf, std::vector<SPoint2> &params) static void getAllParameters(MVertex *v, GFace *gf, std::vector<SPoint2> &params)
......
// 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 "Octree.h"
#include "GModel.h"
#include "MVertex.h"
#include "MVertexOctree.h"
#include "SBoundingBox3d.h"
static void MVertexBB(void *a, double *min, double *max)
{
MVertex *v = (MVertex*)a;
double tol = MVertexLessThanLexicographic::tolerance;
min[0] = v->x() - tol;
max[0] = v->x() + tol;
min[1] = v->y() - tol;
max[1] = v->y() + tol;
min[2] = v->z() - tol;
max[2] = v->z() + tol;
}
static void MVertexCentroid(void *a, double *x)
{
MVertex *v = (MVertex*)a;
x[0] = v->x();
x[1] = v->y();
x[2] = v->z();
}
static int MVertexInEle(void *a, double *x)
{
MVertex *v = (MVertex*)a;
double d = sqrt((x[0] - v->x()) * (x[0] - v->x()) +
(x[1] - v->y()) * (x[1] - v->y()) +
(x[2] - v->z()) * (x[2] - v->z()));
return (d < MVertexLessThanLexicographic::tolerance);
}
MVertexOctree::MVertexOctree(GModel *m)
{
SBoundingBox3d bb = m->bounds();
double min[3] = {bb.min().x(), bb.min().y(), bb.min().z()};
double size[3] = {bb.max().x() - bb.min().x(),
bb.max().y() - bb.min().y(),
bb.max().z() - bb.min().z()};
const int maxElePerBucket = 100; // memory vs. speed trade-off
_octree = Octree_Create(maxElePerBucket, min, size,
MVertexBB, MVertexCentroid, MVertexInEle);
}
MVertexOctree::~MVertexOctree()
{
Octree_Delete(_octree);
}
void MVertexOctree::insert(MVertex *v)
{
Octree_Insert(v, _octree);
}
void MVertexOctree::finalize()
{
Octree_Arrange(_octree);
}
MVertex *MVertexOctree::find(double x, double y, double z)
{
double P[3] = {x, y, z};
return (MVertex*)Octree_Search(P, _octree);
}
#ifndef _MVERTEX_OCTREE_
#define _MVERTEX_OCTREE_
class Octree;
class GModel;
class MVertex;
class MVertexOctree{
private:
Octree *_octree;
public:
MVertexOctree(GModel *);
~MVertexOctree();
void insert(MVertex *);
void finalize();
MVertex *find(double x, double y, double z);
};
#endif
...@@ -12,20 +12,25 @@ ...@@ -12,20 +12,25 @@
#include "Context.h" #include "Context.h"
#include "GmshMessage.h" #include "GmshMessage.h"
static void addTriangle(MVertex* v1, MVertex* v2, MVertex* v3, GFace *to, MElement* source) { static void addTriangle(MVertex* v1, MVertex* v2, MVertex* v3,
GFace *to, MElement* source)
{
MTriangle* newTri = new MTriangle(v1, v2, v3); MTriangle* newTri = new MTriangle(v1, v2, v3);
to->triangles.push_back(newTri); to->triangles.push_back(newTri);
to->meshAttributes.extrude->elementMap.addExtrudedElem((MElement*)source,(MElement*)newTri); to->meshAttributes.extrude->elementMap.addExtrudedElem(source, (MElement*)newTri);
} }
static void addQuadrangle(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4, GFace *to, MElement* source) { static void addQuadrangle(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4,
GFace *to, MElement* source)
{
MQuadrangle* newQuad = new MQuadrangle(v1, v2, v3, v4); MQuadrangle* newQuad = new MQuadrangle(v1, v2, v3, v4);
to->quadrangles.push_back(newQuad); to->quadrangles.push_back(newQuad);
to->meshAttributes.extrude->elementMap.addExtrudedElem((MElement*)source,(MElement*)newQuad); to->meshAttributes.extrude->elementMap.addExtrudedElem(source, (MElement*)newQuad);
} }
static void createQuaTri(std::vector<MVertex*> &v, GFace *to, static void createQuaTri(std::vector<MVertex*> &v, GFace *to,
std::set<std::pair<MVertex*, MVertex*> > *constrainedEdges,MLine* source) std::set<std::pair<MVertex*, MVertex*> > *constrainedEdges,
MLine* source)
{ {
ExtrudeParams *ep = to->meshAttributes.extrude; ExtrudeParams *ep = to->meshAttributes.extrude;
if(v[0] == v[1] || v[1] == v[3]) if(v[0] == v[1] || v[1] == v[3])
......
...@@ -17,27 +17,37 @@ ...@@ -17,27 +17,37 @@
#include "Context.h" #include "Context.h"
#include "GmshMessage.h" #include "GmshMessage.h"
static void addTetrahedron(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4, GRegion *to, MElement* source) { static void addTetrahedron(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4,
GRegion *to, MElement* source)
{
MTetrahedron* newElem = new MTetrahedron(v1, v2, v3, v4); MTetrahedron* newElem = new MTetrahedron(v1, v2, v3, v4);
to->tetrahedra.push_back(newElem); to->tetrahedra.push_back(newElem);
to->meshAttributes.extrude->elementMap.addExtrudedElem((MElement*)source,(MElement*)newElem); to->meshAttributes.extrude->elementMap.addExtrudedElem(source, (MElement*)newElem);
} }
static void addPyramid(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4, MVertex* v5, GRegion *to, MElement* source) { static void addPyramid(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4,
MVertex* v5, GRegion *to, MElement* source)
{
MPyramid* newElem = new MPyramid(v1, v2, v3, v4, v5); MPyramid* newElem = new MPyramid(v1, v2, v3, v4, v5);
to->pyramids.push_back(newElem); to->pyramids.push_back(newElem);
to->meshAttributes.extrude->elementMap.addExtrudedElem((MElement*)source,(MElement*)newElem); to->meshAttributes.extrude->elementMap.addExtrudedElem(source, (MElement*)newElem);
} }
static void addPrism(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4, MVertex* v5, MVertex* v6, GRegion *to, MElement* source) { static void addPrism(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4,
MVertex* v5, MVertex* v6, GRegion *to, MElement* source)
{
MPrism* newElem = new MPrism(v1, v2, v3, v4, v5, v6); MPrism* newElem = new MPrism(v1, v2, v3, v4, v5, v6);
to->prisms.push_back(newElem); to->prisms.push_back(newElem);
to->meshAttributes.extrude->elementMap.addExtrudedElem((MElement*)source,(MElement*)newElem); to->meshAttributes.extrude->elementMap.addExtrudedElem(source, (MElement*)newElem);
} }
static void addHexahedron(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4, MVertex* v5, MVertex* v6, MVertex* v7, MVertex* v8, GRegion *to, MElement* source) {
static void addHexahedron(MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4,
MVertex* v5, MVertex* v6, MVertex* v7, MVertex* v8,
GRegion *to, MElement* source)
{
MHexahedron* newElem = new MHexahedron(v1, v2, v3, v4, v5, v6, v7, v8); MHexahedron* newElem = new MHexahedron(v1, v2, v3, v4, v5, v6, v7, v8);
to->hexahedra.push_back(newElem); to->hexahedra.push_back(newElem);
to->meshAttributes.extrude->elementMap.addExtrudedElem((MElement*)source,(MElement*)newElem); to->meshAttributes.extrude->elementMap.addExtrudedElem(source, (MElement*)newElem);
} }
static void createPriPyrTet(std::vector<MVertex*> &v, GRegion *to, MElement* source) static void createPriPyrTet(std::vector<MVertex*> &v, GRegion *to, MElement* source)
...@@ -96,7 +106,8 @@ static void createHexPri(std::vector<MVertex*> &v, GRegion *to, MElement* source ...@@ -96,7 +106,8 @@ static void createHexPri(std::vector<MVertex*> &v, GRegion *to, MElement* source
} }
} }
static void createTet(MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, GRegion *to, MElement* source) static void createTet(MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, GRegion *to,
MElement* source)
{ {
if(v1 != v2 && v1 != v3 && v1 != v4 && v2 != v3 && v2 != v4 && v3 != v4) if(v1 != v2 && v1 != v3 && v1 != v4 && v2 != v3 && v2 != v4 && v3 != v4)
addTetrahedron(v1, v2, v3, v4, to, source); addTetrahedron(v1, v2, v3, v4, to, source);
......
...@@ -63,4 +63,4 @@ Extrude Surface { 21, {0,1,0} , {0,0,0} , Pi/2 } { ...@@ -63,4 +63,4 @@ Extrude Surface { 21, {0,1,0} , {0,0,0} , Pi/2 } {
}; };
Symmetry { 0,1,0,0 } { Duplicata{ Surface{158}; } } //Symmetry { 0,1,0,0 } { Duplicata{ Surface{158}; } }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment