From 7a6de7b1dcc294af707256783dfbb661dbd6c62d Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 27 Oct 2016 15:41:08 +0200 Subject: [PATCH] further fixes --- libsrc/csg/edgeflw.cpp | 14 +++- libsrc/csg/python_csg.cpp | 37 ++++++++-- libsrc/csg/splinesurface.cpp | 136 +++++++++-------------------------- libsrc/csg/splinesurface.hpp | 41 +++++++++-- 4 files changed, 109 insertions(+), 119 deletions(-) diff --git a/libsrc/csg/edgeflw.cpp b/libsrc/csg/edgeflw.cpp index 4541567c..9ba3af9f 100644 --- a/libsrc/csg/edgeflw.cpp +++ b/libsrc/csg/edgeflw.cpp @@ -44,6 +44,7 @@ namespace netgen for (PointIndex pi : mesh.Points().Range()) meshpoint_tree->Insert (mesh[pi], pi); + // add all special points before edge points (important for periodic identification) // JS, Jan 2007 const double di=1e-7*geometry.MaxSize(); @@ -454,7 +455,6 @@ namespace netgen refedges[i].surfnr2 = geometry.GetSurfaceClassRepresentant(refedges[i].surfnr2); } - /* for (int i = oldnseg+1; i <= mesh.GetNSeg(); i++) for (int j = 1; j <= oldnseg; j++) @@ -485,7 +485,6 @@ namespace netgen layer, mesh); } - for(int i=0; i(geometry.GetSurface(refedges[i].surfnr1)); @@ -494,6 +493,17 @@ namespace netgen auto name = splinesurface->GetBCNameOf(specpoints[startpoints.Get(refedges[i].edgenr)].p,specpoints[endpoints.Get(refedges[i].edgenr)].p); mesh.SetCD2Name(refedges[i].edgenr,*name); } + else + { + auto splinesurface2 = dynamic_cast(geometry.GetSurface(refedges[i].surfnr2)); + if(splinesurface2) + { + auto name = splinesurface2->GetBCNameOf(specpoints[startpoints.Get(refedges[i].edgenr)].p,specpoints[endpoints.Get(refedges[i].edgenr)].p); + mesh.SetCD2Name(refedges[i].edgenr,*name); + } + + } + } /* diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index dec21fb7..4ef7cd26 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -252,7 +252,28 @@ DLL_HEADER void ExportCSG() })) ; - bp::class_,boost::noncopyable> ("SplineSurface") + bp::class_,boost::noncopyable> ("SplineSurface", + "A surface for co dim 2 integrals on the splines", bp::no_init) + .def("__init__", bp::make_constructor (FunctionPointer + ([](const shared_ptr base, bp::list cuts) + { + auto primitive = dynamic_cast (base->GetSolid()->GetPrimitive()); + auto acuts = new Array(); + for(int i = 0; i> sps(cuts[i]); + if(!sps.check()) + throw NgException("Cut must be SurfacePrimitive in constructor of SplineSurface!"); + auto sp = dynamic_cast(sps()->GetSolid()->GetPrimitive()); + if(sp) + acuts->Append(sp); + else + throw NgException("Cut must be SurfacePrimitive in constructor of SplineSurface!"); + } + if(!primitive) + throw NgException("Base is not a SurfacePrimitive in constructor of SplineSurface!"); + return make_shared(primitive,acuts); + }),bp::default_call_policies(),(bp::arg("base"), bp::arg("cuts")=bp::list()))) .def("AddPoint", FunctionPointer ([] (SplineSurface & self, double x, double y, double z, bool hpref) { @@ -261,12 +282,12 @@ DLL_HEADER void ExportCSG() }), (bp::arg("self"),bp::arg("x"),bp::arg("y"),bp::arg("z"),bp::arg("hpref")=false)) .def("AddSegment", FunctionPointer - ([] (SplineSurface & self, int i1, int i2, string bcname) + ([] (SplineSurface & self, int i1, int i2, string bcname, double maxh) { auto str = new string(bcname); - self.AppendSegment(new LineSeg<3>(self.GetPoint(i1),self.GetPoint(i2)),str); + self.AppendSegment(new LineSeg<3>(self.GetPoint(i1),self.GetPoint(i2)),str,maxh); }), - (bp::arg("self"),bp::arg("pnt1"),bp::arg("pnt2"),bp::arg("bcname")="default")) + (bp::arg("self"),bp::arg("pnt1"),bp::arg("pnt2"),bp::arg("bcname")="default", bp::arg("maxh")=-1.)) ; #if (BOOST_VERSION >= 106000) && (BOOST_VERSION < 106100) @@ -450,13 +471,15 @@ DLL_HEADER void ExportCSG() .def("AddSplineSurface", FunctionPointer ([] (CSGeometry & self, shared_ptr surf) { - auto planes = surf->CreatePlanes(); + auto cuttings = surf->CreateCuttingSurfaces(); auto spsol = make_shared(new Solid(&*surf)); - for(auto plane : (*planes)){ - spsol = make_shared(SPSolid::SECTION,spsol,make_shared(new Solid(plane))); + for(auto cut : (*cuttings)){ + spsol = make_shared(SPSolid::SECTION,spsol,make_shared(new Solid(cut))); } spsol->AddSurfaces(self); int tlonr = self.SetTopLevelObject(spsol->GetSolid(), &*surf); + for(auto p : surf->GetPoints()) + self.AddUserPoint(p); }), (bp::arg("self"), bp::arg("SplineSurface"))) diff --git a/libsrc/csg/splinesurface.cpp b/libsrc/csg/splinesurface.cpp index 1009f41f..d66c8bff 100644 --- a/libsrc/csg/splinesurface.cpp +++ b/libsrc/csg/splinesurface.cpp @@ -3,47 +3,60 @@ namespace netgen { - SplineSurface :: SplineSurface() : OneSurfacePrimitive() -{ ; } - -SplineSurface :: ~SplineSurface() { ; } - void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const bool hpref) { - geompoints.Append(GeomPoint<3>(p,reffac)); + auto pp = Point<3>(p); + geompoints.Append(GeomPoint<3>(pp,reffac)); geompoints.Last().hpref = hpref; } - void SplineSurface :: AppendSegment(SplineSeg<3>* spline, string* bcname) + void SplineSurface :: AppendSegment(SplineSeg<3>* spline, string* bcname, double amaxh) { - splines.Append(spline); - bcnames.Append(bcname); + splines.Append(spline); + bcnames.Append(bcname); + maxh.Append(amaxh); } string* SplineSurface :: GetBCNameOf (Point<3> p1, Point<3> p2) const { - (*testout) << "segment: " << p1 << ", " << p2 << endl; + + double eps = 1e-5; for(int i=0; iGetPoint(0) << ", " << splines[i]->GetPoint(1) << endl; - if (((splines[i]->GetPoint(0)-p1).Length()<1e-12 && (splines[i]->GetPoint(1)-p2).Length() < 1e-12) || ((splines[i]->GetPoint(0)-p2).Length() < 1e-12 && (splines[i]->GetPoint(1)-p1).Length() < 1e-12)) + auto pp1 = Point<3>(splines[i]->GetPoint(0)); + Project(pp1); + auto pp2 = Point<3>(splines[i]->GetPoint(1)); + Project(pp2); + if (((pp1-p1).Length()* SplineSurface :: CreatePlanes() const + Array* SplineSurface :: CreateCuttingSurfaces() const { - auto planes = new Array(); - auto sol = new Solid(new Plane(splines[0]->GetPoint(0),Cross(splines[0]->GetTangent(0),GetNormalVector(splines[0]->GetPoint(0))))); - for(auto spline : splines) + auto cuttings = new Array(); + for (auto cut : *cuts) + cuttings->Append(cut); + for(int i = 0; iAppend(new Plane(spline->GetPoint(0),-spline->GetTangent(0))); + auto spline = splines[i]; + auto lineseg = dynamic_cast*>(spline); + auto p1 = Point<3>(spline->GetPoint(0)); + Project(p1); + auto p2 = Point<3>(spline->GetPoint(1)); + Project(p2); + auto vec = Vec<3>(p2)-Vec<3>(p1); + auto plane = new Plane(p1,-Cross(vec,baseprimitive->GetNormalVector(p1))); + if(maxh[i]>0) + { + plane->SetMaxH(maxh[i]); + } + cuttings->Append(plane); } - return planes; + return cuttings; } void SplineSurface :: Print(ostream & str) const @@ -51,89 +64,4 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const str << "SplineSurface " << endl; } - void SplineSurface :: Project(Point<3> & p3d) const - { - double val = CalcFunctionValue(p3d); - p3d -= val * GetNormalVector(p3d); - } - - -double SplineSurface :: CalcFunctionValue (const Point<3> & point) const -{ - auto v1 = splines[0]->GetTangent(0); - auto v2 = splines.Last()->GetTangent(1); - auto p1 = splines[0]->GetPoint(0); - auto n = Cross(v1,v2); - n.Normalize(); - return n * (point-p1); -} - -void SplineSurface :: CalcGradient (const Point<3> & point, Vec<3> & grad) const -{ - auto v1 = splines[0]->GetTangent(0); - auto v2 = splines.Last()->GetTangent(1); - auto p1 = splines[0]->GetPoint(0); - grad = Cross(v1,v2); - grad.Normalize(); -} - - double SplineSurface :: HesseNorm() const -{ - return 0; -} - - Point<3> SplineSurface :: GetSurfacePoint() const -{ - return splines[0]->GetPoint(0); -} - - - void SplineSurface :: CalcSpecialPoints(Array> & pts) const - { - for(auto pt : geompoints) - { - pts.Append(Point<3>(pt)); - } - } - - - -INSOLID_TYPE SplineSurface :: BoxInSolid(const BoxSphere<3> & box) const -{ - - int i; - double val; - - val = CalcFunctionValue (box.Center()); - if (val > box.Diam() / 2) return IS_OUTSIDE; - if (val < -box.Diam() / 2) return IS_INSIDE; - - Vec<3> n = GetNormalVector(box.Center()); - double cx = n[0]; - double cy = n[1]; - double cz = n[2]; - - if (val > 0) - { - Vec<3> vdiag = box.PMax() - box.PMin(); - double modify = (vdiag(0) * fabs (cx) + - vdiag(1) * fabs (cy) + - vdiag(2) * fabs (cz) ) / 2; - - if (val - modify < 0) - return DOES_INTERSECT; - return IS_OUTSIDE; - } - else - { - Vec<3> vdiag = box.PMax() - box.PMin(); - double modify = (vdiag(0) * fabs (cx) + - vdiag(1) * fabs (cy) + - vdiag(2) * fabs (cz) ) / 2; - if (val + modify > 0) - return DOES_INTERSECT; - return IS_INSIDE; - } -} - } diff --git a/libsrc/csg/splinesurface.hpp b/libsrc/csg/splinesurface.hpp index 9211049f..1f68ae73 100644 --- a/libsrc/csg/splinesurface.hpp +++ b/libsrc/csg/splinesurface.hpp @@ -4,19 +4,25 @@ namespace netgen { - class SplineSurface : public OneSurfacePrimitive + class SplineSurface : public OneSurfacePrimitive { protected: Array> geompoints; Array*> splines; Array bcnames; + Array maxh; + OneSurfacePrimitive* baseprimitive; + Array* cuts; public: - SplineSurface(); - virtual ~SplineSurface(); + SplineSurface(OneSurfacePrimitive* abaseprimitive, Array* acuts) : + OneSurfacePrimitive(), baseprimitive(abaseprimitive), cuts(acuts) + { ; } + virtual ~SplineSurface() { ; } const Array*> & GetSplines() const { return splines; } int GetNSplines() const { return splines.Size(); } + const Array>& GetPoints() const { return geompoints; } string GetSplineType(const int i) const { return splines[i]->GetType(); } SplineSeg<3> & GetSpline(const int i) { return *splines[i]; } const SplineSeg<3> & GetSpline(const int i) const { return *splines[i]; } @@ -26,9 +32,30 @@ namespace netgen string* GetBCNameOf(Point<3> p1, Point<3> p2) const; DLL_HEADER void AppendPoint(const Point<3> & p, const double reffac = 1., const bool hpref=false); - void AppendSegment(SplineSeg<3>* spline, string* bcname); - Array* CreatePlanes() const; + void AppendSegment(SplineSeg<3>* spline, string* bcname, double amaxh = -1); + OneSurfacePrimitive* GetBase() const { return baseprimitive; } + + Array* CreateCuttingSurfaces() const; + + + virtual void Project (Point<3> & p3d) const { baseprimitive->Project(p3d); } + virtual double CalcFunctionValue (const Point<3> & point) const + { return baseprimitive->CalcFunctionValue (point); } + virtual void CalcGradient (const Point<3> & point, Vec<3> & grad) const + { baseprimitive->CalcGradient (point,grad); } + virtual double HesseNorm () const + { return baseprimitive->HesseNorm(); } + virtual Point<3> GetSurfacePoint () const + { return baseprimitive->GetSurfacePoint(); } + virtual void CalcSpecialPoints(Array> & pts) const + { baseprimitive->CalcSpecialPoints(pts); } + + virtual INSOLID_TYPE BoxInSolid(const BoxSphere<3> & box) const + { return baseprimitive->BoxInSolid(box); } + + + /* virtual void Project (Point<3> & p3d) const; virtual double CalcFunctionValue (const Point<3> & point) const; virtual void CalcGradient (const Point<3> & point, Vec<3> & grad) const; @@ -38,13 +65,15 @@ namespace netgen virtual INSOLID_TYPE BoxInSolid(const BoxSphere<3> & box) const; - + */ virtual void Print (ostream & str) const; }; + + } #endif