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

merged JF and my new solid modeler code

parent 14925158
No related branches found
No related tags found
No related merge requests found
......@@ -26,16 +26,15 @@
#include "drawContext.h"
#include "GmshMessage.h"
#include "linearSystem.h"
#include "GModelFactory.h"
#if defined(HAVE_SOLVER)
#include "linearSystemCSR.h"
#endif
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#if defined(HAVE_READLINE)
......@@ -49,7 +48,7 @@ class gmshOptions {
gmshOptions(){}
void colorSet(std::string category, int index, std::string name, int value)
{
GmshSetOption(category,name,(unsigned int)(value), index);
GmshSetOption(category, name, (unsigned int)(value), index);
}
int colorGet(std::string category, int index, std::string name)
{
......@@ -77,7 +76,8 @@ class gmshOptions {
{
GmshSetOption(category, name, value, index);
}
static void registerBindings(binding *b) {
static void registerBindings(binding *b)
{
classBinding *cb = b->addClass<gmshOptions>("gmshOptions");
cb->setDescription("access the gmsh option database");
methodBinding *mb;
......@@ -227,7 +227,7 @@ static int luaClear(lua_State *L)
}
#endif
static int luaRefresh (lua_State *L)
static int luaRefresh(lua_State *L)
{
drawContext::global()->draw();
return 0;
......@@ -371,11 +371,11 @@ binding::binding()
// Register Lua bindings
DocRecord::registerBindings(this);
GEntity::registerBindings(this);
GVertex::registerBindings(this);
GEdge::registerBindings(this);
GFace::registerBindings(this);
GModel::registerBindings(this);
GRegion::registerBindings(this);
GVertex::registerBindings(this);
GModel::registerBindings(this);
MElement::registerBindings(this);
MVertex::registerBindings(this);
fullMatrix<double>::registerBindings(this);
......@@ -386,12 +386,14 @@ binding::binding()
function::registerBindings(this);
linearSystemCSRGmm<double>::registerBindings(this);
#endif
GModelFactory::registerBindings(this);
}
binding *binding::_instance=NULL;
binding::~binding() {
for (std::map<std::string,classBinding *>::iterator it = classes.begin(); it != classes.end(); it++) {
binding::~binding()
{
for (std::map<std::string,classBinding *>::iterator it = classes.begin();
it != classes.end(); it++) {
delete it->second;
}
}
......
This diff is collapsed.
......@@ -17,7 +17,7 @@
#include "GRegion.h"
#include "SPoint3.h"
#include "SBoundingBox3d.h"
#include "discreteFace.h"
#include "fullMatrix.h"
class Octree;
class FM_Internals;
......@@ -29,7 +29,7 @@ class CGNSOptions;
class gLevelset;
class discreteFace;
class binding;
class OCCFactory;
class GModelFactory;
// A geometric model. The model is a "not yet" non-manifold B-Rep.
class GModel
......@@ -73,6 +73,9 @@ class GModel
void _createFMInternals();
void _deleteFMInternals();
// CAD creation factory
GModelFactory *_factory;
// characteristic length (mesh size) fields
FieldManager *_fields;
......@@ -342,13 +345,38 @@ class GModel
// mesh the model
int mesh(int dimension);
// glue entities in the model
// assume a tolerance eps and merge vertices that are too close,
// then merge edges, faces and regions.
// the gluer changes the geometric model, so that some pointers
// could become invalid !! I think that using references to some
// tables of pointers for bindings e.g. could be better. FIXME !!
void glue (const double &eps);
// change the entity creation factory
void setFactory(std::string name);
// create brep geometry entities using the factory
GVertex *addVertex(double x, double y, double z, double lc);
GEdge *addLine(GVertex *v1, GVertex *v2);
GEdge *addCircleArcCenter(double x, double y, double z, GVertex *start, GVertex *end);
GEdge *addCircleArc3Points(double x, double y, double z, GVertex *start, GVertex *end);
GEdge *addBezier(GVertex *start, GVertex *end, fullMatrix<double> *controlPoints);
GEntity *revolve(GEntity *e, double angle, fullMatrix<double> *axis);
GEntity *extrude(GEntity *e, fullMatrix<double> *axis);
// create solid geometry primitives using the factory
GEntity *addSphere(double cx, double cy, double cz, double radius);
GEntity *addCylinder(std::vector<double> p1, std::vector<double> p2, double radius);
GEntity *addTorus(std::vector<double> p1, std::vector<double> p2, double radius1,
double radius2);
GEntity *addBlock(std::vector<double> p1, std::vector<double> p2);
GEntity *addCone(std::vector<double> p1, std::vector<double> p2, double radius1,
double radius2);
// boolean operators acting on 2 models
GModel *computeBooleanUnion(GModel *tool, int createNewModel);
GModel *computeBooleanIntersection(GModel *tool, int createNewModel);
GModel *computeBooleanDifference(GModel *tool, int createNewModel);
// glue entities in the model (i.e., assume a tolerance eps and
// merge vertices that are too close, then merge edges, faces and
// regions). Warning: the gluer changes the geometric model, so that
// some pointers could become invalid! I think that using references
// to some tables of pointers for bindings e.g. could be better
void glue(const double &eps);
// build a new GModel by cutting the elements crossed by the levelset ls
// if cutElem is set to false, split the model without cutting the elements
......@@ -365,6 +393,15 @@ class GModel
std::vector<int> &elementary,
std::vector<int> &partition);
// Store mesh elements of a chain in a new elementary and physical entity
void storeChain(int dim, std::map<int, std::vector<MElement*> > &entityMap,
std::map<int, std::map<int, std::string> > &physicalMap)
{
_storeElementsInEntities(entityMap);
_storePhysicalTagsInEntities(dim, physicalMap);
_associateEntityWithMeshVertices();
}
// Gmsh native CAD format (readGEO is static, since it can create
// multiple models)
static int readGEO(const std::string &name);
......@@ -460,20 +497,10 @@ class GModel
int writeDIFF(const std::string &name, bool binary=false,
bool saveAll=false, double scalingFactor=1.0);
void save(std::string fileName);
void load(std::string fileName);
static void registerBindings(binding *b);
// Store mesh elements of a chain in a new elementary and physical entity
void storeChain(int dim, std::map<int, std::vector<MElement*> > &entityMap,
std::map<int, std::map<int, std::string> > &physicalMap)
{
_storeElementsInEntities(entityMap);
_storePhysicalTagsInEntities(dim, physicalMap);
_associateEntityWithMeshVertices();
}
};
#endif
This diff is collapsed.
// 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 _GMODEL_FACTORY_H_
#define _GMODEL_FACTORY_H_
#include <vector>
#include <vector>
#include "GmshConfig.h"
#include "fullMatrix.h"
#include "SPoint3.h"
......@@ -12,120 +17,90 @@ class GEdge;
class GModel;
class binding;
// Abstract CAD creation factory.
class GModelFactory {
protected :
public:
// constructor takes the GModel as input
GModelFactory (){}
// creation methods
virtual ~GModelFactory(){}
// brep primitives
enum arcCreationMethod {THREE_POINTS=1, CENTER_START_END=2};
enum splineType {BEZIER=1, CATMULL_ROM=2};
virtual GVertex* createVertex (GModel *gm, double x, double y, double z, double lc) = 0;
virtual GEdge *createLine (GModel *, GVertex *v1, GVertex *v2) = 0;
virtual GEdge *createCircleArc (GModel *gm, const arcCreationMethod &method,
GVertex *start,
GVertex *end,
const SPoint3 &aPoint)= 0;
inline GEdge *createCircleArcCenter (GModel *gm, double x, double y, double z,
GVertex *start,
GVertex *end){
return createCircleArc (gm, CENTER_START_END,start,end,SPoint3(x,y,z));
}
inline GEdge *createCircleArc3Points (GModel *gm, double x, double y, double z,
GVertex *start,
GVertex *end){
return createCircleArc (gm, THREE_POINTS,start,end,SPoint3(x,y,z));
}
virtual GEdge *createSpline (GModel *gm,const splineType &type,
GVertex *start,
GVertex *end,
fullMatrix<double> *controlPoints)= 0;
inline GEdge *createBezier ( GModel *gm, GVertex *start,
GVertex *end,
fullMatrix<double> *controlPoints){
return createSpline(gm, BEZIER,start, end, controlPoints);
}
virtual GEntity* revolve (GModel *gm, GEntity*,
double x1, double y1, double z1,
double x2, double y2, double z2,
double angle ) = 0;
virtual GEntity* extrude (GModel *gm, GEntity*,
double x1, double y1, double z1,
double x2, double y2, double z2) = 0;
inline GEntity* revolve_ (GModel *gm, GEntity* e,
double angle,
fullMatrix<double> *axis){
revolve (gm, e, (*axis)(0,0),(*axis)(0,1),(*axis)(0,2),
(*axis)(1,0),(*axis)(1,1),(*axis)(1,2),angle);
}
inline GEntity* extrude_ (GModel *gm, GEntity* e,
fullMatrix<double> *axis){
extrude (gm, e, (*axis)(0,0),(*axis)(0,1),(*axis)(0,2),
(*axis)(1,0),(*axis)(1,1),(*axis)(1,2));
}
// primitives
virtual GEntity * sphere (GModel *gm, double cx, double cy, double cz, double radius) = 0;
virtual GEntity * cylinder (GModel *gm, std::vector<double> p1, std::vector<double> p2,
double radius) = 0;
virtual GEntity * torus (GModel *gm, std::vector<double> p1, std::vector<double> p2,
double radius1, double radius2) = 0;
virtual GEntity * block (GModel *gm, std::vector<double> p1, std::vector<double> p2) = 0;
virtual GEntity * cone (GModel *gm, std::vector<double> p1, std::vector<double> p2,
double radius1, double radius2) = 0;
// boolean operators acting on 2 GEntities
virtual GModel * booleanUnion (GModel *obj, GModel*tool, int createNewModel) = 0;
virtual GModel * booleanIntersection (GModel *obj, GModel*tool, int createNewModel) = 0;
virtual GModel * booleanDifference (GModel *obj, GModel*tool, int createNewModel) = 0;
// bindings
static void registerBindings(binding *b);
virtual GVertex *addVertex(GModel *gm, double x, double y, double z,
double lc) = 0;
virtual GEdge *addLine(GModel *, GVertex *v1, GVertex *v2) = 0;
virtual GEdge *addCircleArc(GModel *gm, const arcCreationMethod &method,
GVertex *start, GVertex *end,
const SPoint3 &aPoint) = 0;
virtual GEdge *addSpline(GModel *gm, const splineType &type,
GVertex *start, GVertex *end,
fullMatrix<double> *controlPoints) = 0;
virtual GEntity *revolve(GModel *gm, GEntity*, double x1, double y1, double z1,
double x2, double y2, double z2, double angle) = 0;
virtual GEntity *extrude(GModel *gm, GEntity*, double x1, double y1, double z1,
double x2, double y2, double z2) = 0;
// solid primitives
virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz,
double radius) = 0;
virtual GEntity *addCylinder(GModel *gm, std::vector<double> p1,
std::vector<double> p2, double radius) = 0;
virtual GEntity *addTorus(GModel *gm, std::vector<double> p1,
std::vector<double> p2, double radius1,
double radius2) = 0;
virtual GEntity *addBlock(GModel *gm, std::vector<double> p1,
std::vector<double> p2) = 0;
virtual GEntity *addCone(GModel *gm, std::vector<double> p1,
std::vector<double> p2, double radius1,
double radius2) = 0;
// boolean operators acting on two GModels
virtual GModel *computeBooleanUnion(GModel *obj, GModel *tool,
int createNewModel) = 0;
virtual GModel *computeBooleanIntersection(GModel *obj, GModel *tool,
int createNewModel) = 0;
virtual GModel *computeBooleanDifference(GModel *obj, GModel *tool,
int createNewModel) = 0;
};
#if defined(HAVE_OCC)
class OCCFactory : public GModelFactory {
public:
OCCFactory ();
GVertex *createVertex (GModel *gm,double x, double y, double z, double lc);
virtual GEdge *createLine (GModel *gm,GVertex *v1, GVertex *v2);
GEdge *createCircleArc (GModel *gm,const arcCreationMethod &method,
GVertex *start,
GVertex *end,
const SPoint3 &aPoint);
GEdge *createSpline (GModel *gm,const splineType &type,
GVertex *start,
GVertex *end,
fullMatrix<double> *controlPoints);
GEntity* revolve (GModel *gm,GEntity*,
double x1, double y1, double z1,
double x2, double y2, double z2,
double angle );
GEntity* extrude (GModel *gm,GEntity*,
double x1, double y1, double z1,
double x2, double y2, double z2);
GEntity * sphere (GModel *gm,double cx, double cy, double cz, double radius);
GEntity * cylinder (GModel *gm,std::vector<double> p1, std::vector<double> p2,
double radius);
GEntity * torus (GModel *gm,std::vector<double> p1, std::vector<double> p2,
double radius1, double radius2);
GEntity * block (GModel *gm,std::vector<double> p1, std::vector<double> p2);
GEntity * cone (GModel *gm,std::vector<double> p1, std::vector<double> p2, double radius1, double radius2);
// booleans
GModel * booleanUnion (GModel *obj, GModel*tool, int createNewModel);
GModel * booleanIntersection (GModel *obj, GModel*tool, int createNewModel);
GModel * booleanDifference (GModel *obj, GModel*tool, int createNewModel);
OCCFactory(){}
virtual ~OCCFactory(){}
virtual GVertex *addVertex(GModel *gm, double x, double y, double z,
double lc);
virtual GEdge *addLine(GModel *, GVertex *v1, GVertex *v2);
virtual GEdge *addCircleArc(GModel *gm, const arcCreationMethod &method,
GVertex *start, GVertex *end,
const SPoint3 &aPoint);
virtual GEdge *addSpline(GModel *gm, const splineType &type,
GVertex *start, GVertex *end,
fullMatrix<double> *controlPoints);
virtual GEntity *revolve(GModel *gm, GEntity*, double x1, double y1, double z1,
double x2, double y2, double z2, double angle);
virtual GEntity *extrude(GModel *gm, GEntity*, double x1, double y1, double z1,
double x2, double y2, double z2);
virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz,
double radius) ;
virtual GEntity *addCylinder(GModel *gm, std::vector<double> p1,
std::vector<double> p2, double radius);
virtual GEntity *addTorus(GModel *gm, std::vector<double> p1,
std::vector<double> p2, double radius1,
double radius2);
virtual GEntity *addBlock(GModel *gm, std::vector<double> p1,
std::vector<double> p2);
virtual GEntity *addCone(GModel *gm, std::vector<double> p1,
std::vector<double> p2, double radius1,
double radius2);
virtual GModel *computeBooleanUnion(GModel *obj, GModel *tool,
int createNewModel);
virtual GModel *computeBooleanIntersection(GModel *obj, GModel *tool,
int createNewModel);
virtual GModel *computeBooleanDifference(GModel *obj, GModel *tool,
int createNewModel);
};
#endif
#endif
......@@ -282,18 +282,26 @@ void OCC_Internals::healGeometry(double tolerance, bool fixsmalledges,
if(sfwf->FixSmallEdges()){
Msg::Info("- fixing wire frames");
if(sfwf->StatusSmallEdges(ShapeExtend_OK)) Msg::Info("no small edges found");
if(sfwf->StatusSmallEdges(ShapeExtend_DONE1)) Msg::Info("some small edges fixed");
if(sfwf->StatusSmallEdges(ShapeExtend_FAIL1)) Msg::Info("failed to fix some small edges");
if(sfwf->StatusSmallEdges(ShapeExtend_OK))
Msg::Info("no small edges found");
if(sfwf->StatusSmallEdges(ShapeExtend_DONE1))
Msg::Info("some small edges fixed");
if(sfwf->StatusSmallEdges(ShapeExtend_FAIL1))
Msg::Info("failed to fix some small edges");
}
if(sfwf->FixWireGaps()){
Msg::Info("- fixing wire gaps");
if(sfwf->StatusWireGaps(ShapeExtend_OK)) Msg::Info("no gaps found");
if(sfwf->StatusWireGaps(ShapeExtend_DONE1)) Msg::Info("some 2D gaps fixed");
if(sfwf->StatusWireGaps(ShapeExtend_DONE2)) Msg::Info("some 3D gaps fixed");
if(sfwf->StatusWireGaps(ShapeExtend_FAIL1)) Msg::Info("failed to fix some 2D gaps");
if(sfwf->StatusWireGaps(ShapeExtend_FAIL2)) Msg::Info("failed to fix some 3D gaps");
if(sfwf->StatusWireGaps(ShapeExtend_OK))
Msg::Info("no gaps found");
if(sfwf->StatusWireGaps(ShapeExtend_DONE1))
Msg::Info("some 2D gaps fixed");
if(sfwf->StatusWireGaps(ShapeExtend_DONE2))
Msg::Info("some 3D gaps fixed");
if(sfwf->StatusWireGaps(ShapeExtend_FAIL1))
Msg::Info("failed to fix some 2D gaps");
if(sfwf->StatusWireGaps(ShapeExtend_FAIL2))
Msg::Info("failed to fix some 3D gaps");
}
shape = sfwf->Shape();
......@@ -421,9 +429,9 @@ void OCC_Internals::loadSTEP(const char *fn)
void OCC_Internals::writeSTEP(const char *fn)
{
STEPControl_Writer writer;
IFSelect_ReturnStatus status = writer.Transfer( shape, STEPControl_ManifoldSolidBrep ) ;
if ( status == IFSelect_RetDone )
status = writer.Write( (char*) fn) ;
IFSelect_ReturnStatus status = writer.Transfer(shape, STEPControl_ManifoldSolidBrep);
if (status == IFSelect_RetDone)
status = writer.Write((char*)fn);
}
void OCC_Internals::loadIGES(const char *fn)
......@@ -476,7 +484,7 @@ GEdge *OCC_Internals::addEdgeToModel(GModel *model, TopoDS_Edge edge)
}
GEdge *OCC_Internals::addEdgeToModel(GModel *model, TopoDS_Edge edge, GVertex *g1,
GVertex *g2)
GVertex *g2)
{
OCCEdge *e = new OCCEdge(model, edge, model->maxEdgeNum() + 1, g1, g2);
e->replaceEndingPoints (g1,g2);
......@@ -815,7 +823,7 @@ void OCC_Internals::applyBooleanOperator(TopoDS_Shape tool, const BooleanOperato
}
}
void OCC_Internals::Fillet(std::vector<TopoDS_Edge> &edgesToFillet,
void OCC_Internals::fillet(std::vector<TopoDS_Edge> &edgesToFillet,
double Radius)
{
// create a tool for fillet
......
......@@ -48,7 +48,7 @@ class OCC_Internals {
GFace *addFaceToModel(GModel *model, TopoDS_Face f, int i=-1);
GRegion *addRegionToModel(GModel *model, TopoDS_Solid r, int i=-1);
void buildGModel(GModel *gm);
void Fillet(std::vector<TopoDS_Edge> &shapes, double radius);
void fillet(std::vector<TopoDS_Edge> &shapes, double radius);
void applyBooleanOperator(TopoDS_Shape tool, const BooleanOperator &op);
};
......
......@@ -97,6 +97,8 @@ void linearSystemPETSc<fullMatrix<PetscScalar> >::allocate(int nbRows)
#include "Bindings.h"
void linearSystemPETScRegisterBindings(binding *b)
{
// FIXME on complex arithmetic this crashes
#if !defined(PETSC_USE_COMPLEX)
classBinding *cb;
methodBinding *cm;
cb = b->addClass<linearSystemPETSc<PetscScalar> >("linearSystemPETSc");
......@@ -107,7 +109,6 @@ void linearSystemPETScRegisterBindings(binding *b)
cm->setArgNames(NULL);
cm = cb->addMethod("systemSolve", &linearSystem<fullMatrix<PetscScalar> >::systemSolve);
cm->setDescription("compute x = A^{-1}b");
cb = b->addClass<linearSystemPETSc<fullMatrix<PetscScalar> > >("linearSystemPETScBlock");
cb->setDescription("A linear system solver, based on PETSc");
cm = cb->setConstructor<linearSystemPETSc<fullMatrix<PetscScalar> >, int>();
......@@ -115,6 +116,8 @@ void linearSystemPETScRegisterBindings(binding *b)
cm->setArgNames("blockSize", NULL);
cm = cb->addMethod("systemSolve", &linearSystem<fullMatrix<PetscScalar> >::systemSolve);
cm->setDescription("compute x = A^{-1}b");
#endif // FIXME
}
#endif // HAVE_PETSC
g = GModel()
v1 = g:addVertex(0, 0, 0, 1)
v2 = g:addVertex(1, 0, 0, 1)
v3 = g:addVertex(1, 1, 0, 1)
v4 = g:addVertex(0, 1, 0, 1)
e1 = g:addLine(v1, v2)
e2 = g:addLine(v2, v3)
e3 = g:addLine(v3, v4)
e4 = g:addLine(v4, v1)
g = GModel()
v1 = g:addVertex(0, 0, 0, 1)
v2 = g:addVertex(1, 0, 0, 1)
e1 = g:addLine(v1, v2)
dir = fullMatrix(2,3)
dir:set(0,0, 0);
dir:set(0,1, 0);
dir:set(0,2, 0);
dir:set(1,0, 0);
dir:set(1,1, 1);
dir:set(1,2, 0);
f1 = g:extrude(e1, dir)
-- from http://en.wikipedia.org/wiki/Constructive_solid_geometry
R = 1.0;
s = .8;
t = 1.35;
myModel = GModel();
myModel:addBlock({-R,-R,-R},{R,R,R});
myTool = GModel();
myTool:addSphere(0,0,0,R*t);
myModel:computeIntersection(myTool,0);
myTool2 = GModel();
myTool2:addCylinder({-2*R,0,0},{2*R,0,0},R*s);
myTool3 = GModel();
myTool3:addCylinder({0,-2*R,0},{0,2*R,0},R*s);
myModel2 = GModel();
myModel2:addCylinder({0,0,-2*R},{0,0,2*R},R*s);
myModel2:computeUnion(myTool2,0);
myModel2:computeUnion(myTool3,0);
myModel:computeDifference(myModel2,0);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment