Hi all, 

It looks to me like there's no easy way to generate a BSPline from the
API (i.e. using GModel), so I modified GModel.* and GModelFactory.* to
allow this. Attached is what I came up with, and although it's not very
complicated and cursory inspection suggests it may work, I don't really
know what I'm doing. In particular, I'm not sure what the third argument
to Create_Curve does (I just set it to 2 since that's what other calls
using MSH_SEGM_BSPLN seem to do).  

Note that it is a patch against svn from a few days ago (although I can
update and rediff if necessary). 

Hope this is helpful... 


-Cosmin




-- 
PhD Candidate in Experimental Particle Physics
Massachusetts Institute of Technology / Laboratory for Nuclear Science
77 Massachusetts Ave #26-456, Cambridge, MA 02139
(617) 253-1593 (office)   /   (775) 846-9105 (mobile)
[email protected] 
Index: GModel.cpp
===================================================================
--- GModel.cpp	(revision 17251)
+++ GModel.cpp	(working copy)
@@ -2612,6 +2612,13 @@
   return 0;
 }
 
+GEdge *GModel::addBSpline(std::vector<GVertex*> pts)
+{
+  if(_factory) return _factory->addBSpline(this, pts);
+  return 0;
+}
+
+
 GEdge *GModel::addLine(GVertex *v1, GVertex *v2)
 {
   if(_factory) return _factory->addLine(this, v1, v2);
Index: GModel.h
===================================================================
--- GModel.h	(revision 17251)
+++ GModel.h	(working copy)
@@ -485,6 +485,7 @@
   // create brep geometry entities using the factory
   GVertex *addVertex(double x, double y, double z, double lc);
   GEdge *addLine(GVertex *v1, GVertex *v2);
+  GEdge *addBSpline(std::vector<GVertex*> control_points);
   GEdge *addCircleArcCenter(double x, double y, double z, GVertex *start, GVertex *end);
   GEdge *addCircleArcCenter(GVertex *start, GVertex *center, GVertex *end);
   GEdge *addCircleArc3Points(double x, double y, double z, GVertex *start, GVertex *end);
Index: GModelFactory.cpp
===================================================================
--- GModelFactory.cpp	(revision 17251)
+++ GModelFactory.cpp	(working copy)
@@ -41,6 +41,31 @@
   return v;
 }
 
+GEdge *GeoFactory::addBSpline(GModel *gm, std::vector<GVertex *> control_points)
+{
+  int num =  gm->getMaxElementaryNumber(1) + 1;
+  List_T *iList = List_Create(control_points.size(), control_points.size(), sizeof(int));
+  for (unsigned i = 0; i < control_points.size(); i++)
+  {
+    int tag = control_points[i]->tag(); 
+    List_Add(iList, &tag);
+  }
+
+  Curve *c = Create_Curve(num, MSH_SEGM_BSPLN, 2, iList, NULL,
+			  -1,-1,  0., 1.);
+  
+  Tree_Add(gm->getGEOInternals()->Curves, &c);
+  CreateReversedCurve(c);
+  List_Delete(iList);
+  c->Typ = MSH_SEGM_BSPLN;
+  c->Num = num;
+
+  GEdge *e = new gmshEdge(gm, c, control_points[0], control_points[control_points.size()-1]);
+  gm->add(e);
+
+  return e;
+}
+
 GEdge *GeoFactory::addLine(GModel *gm, GVertex *start, GVertex *end)
 {
   int num =  gm->getMaxElementaryNumber(1) + 1;
Index: GModelFactory.h
===================================================================
--- GModelFactory.h	(revision 17251)
+++ GModelFactory.h	(working copy)
@@ -30,6 +30,11 @@
   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 *addBSpline(GModel *, std::vector<GVertex*>)
+  {
+    Msg::Error("addBSpline not implemented yet");
+    return 0;
+  }
   virtual GFace *addPlanarFace(GModel *gm, std::vector<std::vector<GEdge *> > edges) = 0;
   virtual GRegion*addVolume(GModel *gm, std::vector<std::vector<GFace *> > faces) = 0;
   virtual GEdge *addCircleArc(GModel *gm, GVertex *start, GVertex *center, GVertex *end)
@@ -224,6 +229,7 @@
   GeoFactory(){}
   GVertex *addVertex(GModel *gm,double x, double y, double z, double lc);
   GEdge *addLine(GModel *gm,GVertex *v1, GVertex *v2);
+  GEdge *addBSpline(GModel *, std::vector<GVertex*>);
   GFace *addPlanarFace(GModel *gm, std::vector<std::vector<GEdge *> > edges);
   GRegion *addVolume(GModel *gm, std::vector<std::vector<GFace *> > faces);
   GEdge *addCircleArc(GModel *gm,GVertex *begin, GVertex *center, GVertex *end);
_______________________________________________
gmsh mailing list
[email protected]
http://www.geuz.org/mailman/listinfo/gmsh

Reply via email to