Hi ,
I need to receate the surface using the boundary curve and inner points by GeomPlate_BuildPlateSurface.For reference, here is some code which may demonstrate what I'm doing ( I took inspiration mostly from http://opencascade.blogspot.co.uk/2010/03/surface-modeling-part6.html):
However ,when input the constraint points and constraint curve, the BPSurf.Perform() doesn't work.
I would really appreciate any info on this.
Thanks,
Commenter-2.
Standard_Real aDeflection = 0.1;
Standard_Integer i;
Standard_Integer aIndex = 1, nbNodes = 0;
//// define two sequence of points
TColgp_SequenceOfPnt aPoints, aPoints1;
aPoints.Clear();
vector<D_3DOT> idots;
LoadData("C:\\Users\\zuo\\Desktop\\3.xyz",idots);
for(i=0;i<idots.size();i++)
{
aPoints.Append(gp_Pnt(idots[i].x,idots[i].y,idots[i].z));
}
// remove double points
nbNodes = aPoints.Length();
for( i = 1; i <= nbNodes; i++)
{
gp_Pnt aPi = aPoints(i);
Standard_Integer j;
for( j = i + 1; j < nbNodes; j++)
{
gp_Pnt aPj = aPoints(j);
if(!aPi.IsEqual(aPj,0.9))
aIndex++;
}
if(aIndex == j - 1)
aPoints1.Append(aPi);
aIndex = i + 1;
}
// find max point
aIndex = 0;
gp_Pnt aPntMax = aPoints1(1);
nbNodes = aPoints1.Length();
for(i = 2; i <= nbNodes; i++)
{
if(aPoints1(i).X() > aPntMax.X())
{
aIndex = i;
aPntMax = aPoints1(aIndex);
}
}
// clear seguence
aPoints.Clear();
Standard_Integer nbLeftNodes = nbNodes;
// ascending sort - fill aPoints with ascending
// by X coordinate points from aPoints1
for(i = 1; i < nbNodes; i++)
{
Standard_Real aMin = aPntMax.X();
aIndex = 1;
for( Standard_Integer j = 1; j <= nbLeftNodes; j++)
{
if(aPoints1(j).X() < aMin)
{
aMin = aPoints1(j).X();
aIndex = j;
}
}
aPoints.Append(aPoints1(aIndex));
aPoints1.Remove(aIndex);
nbLeftNodes = aPoints1.Length();
}
vector<D_3DOT> dots;
D_3DOT dot;
for( i = 1; i <= aPoints.Length(); i++)
{
gp_Pnt aPi = aPoints(i);
dot.x=aPi.X();
dot.y=aPi.Y();
dot.z=aPi.Z();
dots.push_back(dot);
}
SaveData("C:\\Users\\zuo\\Desktop\\bi.xyz",dots);
//void Add (const Handle(GeomPlate_CurveConstraint)& Cont);
TColStd_ListOfTransient theBoundaries;
LoadData("C:\\Users\\zuo\\Desktop\\bian1.xyz",dots);
RemoveSame(dots);
gp_Pnt p1,p2;
for(i=0;i<dots.size()-1;i++)
{
p1.SetX(dots[i].x);
p1.SetY(dots[i].y);
p1.SetZ(dots[i].z);
p2.SetX(dots[i+1].x);
p2.SetY(dots[i+1].y);
p2.SetZ(dots[i+1].z);
Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(p1,p2);
Handle(GeomAdaptor_HCurve) aCurve1 = new GeomAdaptor_HCurve(GeomAdaptor_HCurve(aSegment1));
theBoundaries.Append(aCurve1);
}
LoadData("C:\\Users\\zuo\\Desktop\\bian2.xyz",dots);
RemoveSame(dots);
for(i=0;i<dots.size()-1;i++)
{
Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(gp_Pnt(dots[i].x,dots[i].y,dots[i].z),gp_Pnt(dots[i+1].x,dots[i+1].y,dots[i+1].z));
Handle(GeomAdaptor_HCurve) aCurve1 = new GeomAdaptor_HCurve(GeomAdaptor_HCurve(aSegment1));
theBoundaries.Append(aCurve1);
}
LoadData("C:\\Users\\zuo\\Desktop\\bian3.xyz",dots);
RemoveSame(dots);
for(i=0;i<dots.size()-1;i++)
{
Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(gp_Pnt(dots[i].x,dots[i].y,dots[i].z),gp_Pnt(dots[i+1].x,dots[i+1].y,dots[i+1].z));
Handle(GeomAdaptor_HCurve) aCurve1 = new GeomAdaptor_HCurve(GeomAdaptor_HCurve(aSegment1));
theBoundaries.Append(aCurve1);
}
LoadData("C:\\Users\\zuo\\Desktop\\bian4.xyz",dots);
RemoveSame(dots);
for(i=0;i<dots.size()-1;i++)
{
Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(gp_Pnt(dots[i].x,dots[i].y,dots[i].z),gp_Pnt(dots[i+1].x,dots[i+1].y,dots[i+1].z));
Handle(GeomAdaptor_HCurve) aCurve1 = new GeomAdaptor_HCurve(GeomAdaptor_HCurve(aSegment1));
theBoundaries.Append(aCurve1);
}
// define parameters GeomPlate_BuildPlateSurface
Standard_Integer Degree = 3;
Standard_Integer NbPtsOnCur = 10;
Standard_Integer NbIter = 3;
Standard_Integer Order = 0;
Standard_Integer MaxSeg = 9;
Standard_Integer MaxDegree = 5;
Standard_Real dmax, anApproxTol = 0.001;
Standard_Real aConstrTol = Precision::Confusion();
// define object BuildPlateSurface
GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);
// add point constraints to GeomPlate_BuildPlateSurface object
nbNodes = aPoints.Length();
// for (i = 1; i <= nbNodes; i++)
// BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));
const Standard_Real aTol3d = 1.e-04;
const Standard_Real aTol2d = 1.e-05;
const Standard_Real anAngTol = 1.e-02; //angular
const Standard_Real aCurvTol = 1.e-01; //curvature
TColStd_ListIteratorOfListOfTransient anIt (theBoundaries);
if (anIt.More())
{
int i = 1;
for (; anIt.More(); anIt.Next(), i++)
{
const Handle(Standard_Transient)& aCur = anIt.Value();
if (aCur.IsNull())
{
}
else if (aCur->IsKind (STANDARD_TYPE (Adaptor3d_HCurveOnSurface)))
{
//G1 constraint
const Handle(Adaptor3d_HCurveOnSurface)& aHCOS = Handle(Adaptor3d_HCurveOnSurface)::DownCast (aCur);
Handle (GeomPlate_CurveConstraint) aConst = new GeomPlate_CurveConstraint (aHCOS, 1 /*GeomAbs_G1*/, NbPtsOnCur, aTol3d, anAngTol, aCurvTol);
BPSurf.Add (aConst);
}
else if (aCur->IsKind (STANDARD_TYPE (GeomAdaptor_HCurve)))
{
//G0 constraint
const Handle(GeomAdaptor_HCurve)& aHC = Handle(GeomAdaptor_HCurve)::DownCast (aCur);
Handle (GeomPlate_CurveConstraint) aConst = new GeomPlate_CurveConstraint (aHC, 0 /*GeomAbs_G0*/, NbPtsOnCur, aTol3d);
BPSurf.Add (aConst);
}
else
{
}
}
}
BPSurf.Perform();
// make PlateSurface
Handle(GeomPlate_Surface) PSurf;
Handle(Geom_Surface) aSurf;
if (BPSurf.IsDone())
{
PSurf = BPSurf.Surface();
// define parameter approximation
dmax = Max(0.01,10*BPSurf.G0Error());
// make approximation
GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);
aSurf = Mapp.Surface();
}