2016-10-04 22:30:57 +05:00
|
|
|
|
|
|
|
#include <csg.hpp>
|
|
|
|
|
|
|
|
namespace netgen
|
|
|
|
{
|
|
|
|
void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const bool hpref)
|
|
|
|
{
|
2017-08-02 17:45:03 +05:00
|
|
|
auto pp = p;
|
|
|
|
Project(pp);
|
2017-02-27 15:32:42 +05:00
|
|
|
geompoints.Append(GeomPoint<3>(pp,reffac));
|
|
|
|
geompoints.Last().hpref = hpref;
|
2016-10-04 22:30:57 +05:00
|
|
|
}
|
|
|
|
|
2017-02-23 20:41:27 +05:00
|
|
|
void SplineSurface :: AppendSegment(shared_ptr<SplineSeg<3>> sp, string & bcname, double amaxh)
|
2016-10-04 22:30:57 +05:00
|
|
|
{
|
2017-02-27 15:32:42 +05:00
|
|
|
splines.Append(sp);
|
|
|
|
bcnames.Append(bcname);
|
2016-10-27 18:41:08 +05:00
|
|
|
maxh.Append(amaxh);
|
2016-10-04 22:30:57 +05:00
|
|
|
}
|
2016-10-05 22:48:18 +05:00
|
|
|
|
2017-02-23 20:41:27 +05:00
|
|
|
string SplineSurface :: GetBCNameOf (Point<3> p1, Point<3> p2) const
|
2016-10-05 22:48:18 +05:00
|
|
|
{
|
2016-10-27 18:41:08 +05:00
|
|
|
|
2017-02-27 15:32:42 +05:00
|
|
|
for(int i=0; i<splines.Size(); i++)
|
2016-10-05 22:48:18 +05:00
|
|
|
{
|
2016-10-27 18:41:08 +05:00
|
|
|
auto pp1 = Point<3>(splines[i]->GetPoint(0));
|
|
|
|
Project(pp1);
|
|
|
|
auto pp2 = Point<3>(splines[i]->GetPoint(1));
|
|
|
|
Project(pp2);
|
2017-08-02 17:45:03 +05:00
|
|
|
double eps = (p1-p2).Length() * 1e-4;
|
2016-10-27 18:41:08 +05:00
|
|
|
if (((pp1-p1).Length()<eps && (pp2-p2).Length() < eps) || ((pp1-p2).Length() < eps && (pp2-p1).Length() < eps))
|
2016-10-05 22:48:18 +05:00
|
|
|
{
|
|
|
|
return bcnames[i];
|
|
|
|
}
|
|
|
|
}
|
2017-02-23 20:41:27 +05:00
|
|
|
return "default";
|
2016-10-05 22:48:18 +05:00
|
|
|
}
|
2016-10-11 17:10:36 +05:00
|
|
|
|
2017-02-27 15:32:42 +05:00
|
|
|
const shared_ptr<Array<shared_ptr<OneSurfacePrimitive>>> SplineSurface :: CreateCuttingSurfaces()
|
2016-10-11 17:10:36 +05:00
|
|
|
{
|
2017-02-23 20:41:27 +05:00
|
|
|
if(all_cuts)
|
|
|
|
return all_cuts;
|
2017-02-27 15:32:42 +05:00
|
|
|
auto cuttings = make_shared<Array<shared_ptr<OneSurfacePrimitive>>>();
|
2016-10-27 18:41:08 +05:00
|
|
|
for (auto cut : *cuts)
|
2017-02-27 15:32:42 +05:00
|
|
|
cuttings->Append(cut);
|
|
|
|
for(int i = 0; i<splines.Size(); i++)
|
2016-10-11 17:10:36 +05:00
|
|
|
{
|
2016-10-27 18:41:08 +05:00
|
|
|
auto spline = splines[i];
|
2017-02-23 20:41:27 +05:00
|
|
|
auto lineseg = dynamic_cast<LineSeg<3>*>(spline.get());
|
|
|
|
if(lineseg)
|
|
|
|
{
|
|
|
|
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 = make_shared<Plane>(p1,-Cross(vec,baseprimitive->GetNormalVector(p1)));
|
|
|
|
if(maxh[i]>0)
|
|
|
|
{
|
|
|
|
plane->SetMaxH(maxh[i]);
|
|
|
|
}
|
2017-02-27 15:32:42 +05:00
|
|
|
cuttings->Append(plane);
|
2017-02-23 20:41:27 +05:00
|
|
|
}
|
|
|
|
else
|
2018-11-26 15:41:25 +05:00
|
|
|
{
|
|
|
|
auto spline3 = dynamic_cast<SplineSeg3<3>*>(spline.get());
|
|
|
|
if(spline3)
|
|
|
|
{
|
|
|
|
auto p1 = Point<3>(spline3->StartPI());
|
|
|
|
Project(p1);
|
|
|
|
auto p2 = Point<3>(spline3->TangentPoint());
|
|
|
|
Project(p2);
|
|
|
|
auto p3 = Point<3>(spline3->EndPI());
|
|
|
|
Project(p3);
|
|
|
|
Vec<3> v1 = p2-p1;
|
|
|
|
Vec<3> v2 = p2-p3;
|
|
|
|
Point<3> mid = p1 - v2;
|
|
|
|
cout << "mid point = " << mid << endl;
|
|
|
|
cout << "v1 = " << v1 << endl;
|
|
|
|
cout << "v2 = " << v2 << endl;
|
|
|
|
auto cyl = make_shared<EllipticCylinder>(mid, v1, v2);
|
|
|
|
if(maxh[i] > 0)
|
|
|
|
cyl->SetMaxH(maxh[i]);
|
|
|
|
cuttings->Append(cyl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw NgException("Spline type not implemented for SplineSurface!");
|
|
|
|
}
|
2016-10-11 17:10:36 +05:00
|
|
|
}
|
2017-02-23 20:41:27 +05:00
|
|
|
all_cuts = cuttings;
|
2016-10-27 18:41:08 +05:00
|
|
|
return cuttings;
|
2016-10-11 17:10:36 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SplineSurface :: Print(ostream & str) const
|
|
|
|
{
|
2017-02-23 20:41:27 +05:00
|
|
|
str << "SplineSurface with base " << *baseprimitive << endl;
|
2016-10-11 17:10:36 +05:00
|
|
|
}
|
|
|
|
|
2018-12-13 18:33:21 +05:00
|
|
|
static RegisterClassForArchive<SplineSurface, OneSurfacePrimitive> regss;
|
2016-10-04 22:30:57 +05:00
|
|
|
}
|