Bezier and B spline cleanup, fixed B spline error

I have made further cleanup in Bezier and B spline surface code, and
corrected the bug in face creation for B splines (Nate has also written
that that was incomplete).
This commit is contained in:
balazs-bamer
2015-01-06 20:06:05 +01:00
committed by wmayer
parent 1037cce62f
commit 7b090bcc5e
4 changed files with 42 additions and 310 deletions

View File

@@ -23,7 +23,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
@@ -31,14 +30,13 @@
#include <Geom_BSplineCurve.hxx>
#include <Precision.hxx>
#include <gp_Trsf.hxx>
#include <GeomFill.hxx>
#include <GeomFill_BSplineCurves.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRep_Tool.hxx>
#include <TopExp_Explorer.hxx>
#include <Standard_ConstructionError.hxx>
#include <Base/Tools.h>
#include <Base/Exception.h>
#include <GeomFill_BSplineCurves.hxx>
#include <GeomFill.hxx>
#endif
#include "FeatureBSplineSurf.h"
@@ -56,50 +54,32 @@ BSplineSurf::BSplineSurf()
ADD_PROPERTY(filltype,(1));
}
//Structures
struct crvs{
Handle_Geom_BSplineCurve C1;
Handle_Geom_BSplineCurve C2;
Handle_Geom_BSplineCurve C3;
Handle_Geom_BSplineCurve C4;
};
//Functions
App::DocumentObjectExecReturn *BSplineSurf::execute(void)
{
//Begin Construction
try{
GeomFill_FillingStyle fstyle = getFillingStyle();
GeomFill_BSplineCurves aSurfBuilder; //Create Surface Builder
Handle_Geom_BSplineCurve crvs[4];
TopoDS_Wire aWire; //Create empty wire
//Gets the healed wire
getWire(aWire);
//Create BSpline Surface builder
crvs bcrv;
Standard_Real u0;// contains output
Standard_Real u1;// contains output
Standard_Real u1, u2; // contains output
TopExp_Explorer anExp (aWire, TopAbs_EDGE);
int it = 0;
for (; anExp.More(); anExp.Next()) {
const TopoDS_Edge hedge = TopoDS::Edge (anExp.Current());
TopLoc_Location heloc; // this will be output
Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge,heloc,u0,u1); //The geometric curve
Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge, heloc, u1, u2); //The geometric curve
Handle_Geom_BSplineCurve b_geom = Handle_Geom_BSplineCurve::DownCast(c_geom); //Try to get BSpline curve
if (!b_geom.IsNull()) {
gp_Trsf transf = heloc.Transformation();
b_geom->Transform(transf); // apply original transformation to control points
//Store Underlying Geometry
if(it==0){bcrv.C1 = b_geom;}
else if(it==1){bcrv.C2 = b_geom;}
else if(it==2){bcrv.C3 = b_geom;}
else if(it==3){bcrv.C4 = b_geom;}
crvs[it] = b_geom;
}
else {
Standard_Failure::Raise("Curve not a BSpline Curve");
@@ -107,28 +87,14 @@ App::DocumentObjectExecReturn *BSplineSurf::execute(void)
it++;
}
GeomFill_FillingStyle fstyle = getFillingStyle();
GeomFill_BSplineCurves aSurfBuilder; //Create Surface Builder
int ncrv = aBList.getSize();
if(ncrv==2){aSurfBuilder.Init(bcrv.C1,bcrv.C2,fstyle);}
else if(ncrv==3){aSurfBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,fstyle);}
else if(ncrv==4){aSurfBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,bcrv.C4,fstyle);}
if(ncrv==2) {aSurfBuilder.Init(crvs[0], crvs[1], fstyle);}
else if(ncrv==3) {aSurfBuilder.Init(crvs[0], crvs[1], crvs[2], fstyle);}
else if(ncrv==4) {aSurfBuilder.Init(crvs[0], crvs[1], crvs[2], crvs[3], fstyle);}
//Create the surface
const Handle_Geom_BSplineSurface aSurface = aSurfBuilder.Surface();
BRepBuilderAPI_MakeFace aFaceBuilder;//(aSurface,aWire,Standard_True); //Create Face Builder
u0 = 0.;
u1 = 1.;
Standard_Real v0 = 0.;
Standard_Real v1 = 1.;
aFaceBuilder.Init(aSurface,u0,u1,v0,v1,Precision::Confusion());
TopoDS_Face aFace = aFaceBuilder.Face(); //Returned Face
if(!aFaceBuilder.IsDone()){return new App::DocumentObjectExecReturn("Face unable to be constructed");}
if (aFace.IsNull()){
return new App::DocumentObjectExecReturn("Resulting Face is null");
}
this->Shape.setValue(aFace);
createFace(aSurfBuilder.Surface());
return App::DocumentObject::StdReturn;
@@ -143,221 +109,3 @@ App::DocumentObjectExecReturn *BSplineSurf::execute(void)
} //End Catch
} //End execute
/*
#include "PreCompiled.h"
#ifndef _PreComp_
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Precision.hxx>
#include <GeomFill.hxx>
#include <GeomFill_BSplineCurves.hxx>
#include <ShapeFix_Wire.hxx>
#include <ShapeExtend_WireData.hxx>
#include <BRep_Tool.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <Base/Tools.h>
#include <Base/Exception.h>
#include <TopExp_Explorer.hxx>
#endif
#include "FeatureBSplineSurf.h"
#include "FillType.h"
using namespace Surface;
PROPERTY_SOURCE(Surface::BSplineSurf, Part::Feature)
//Initial values
BSplineSurf::BSplineSurf()
{
ADD_PROPERTY(aBSplineList,(0,"Geom_BSplineCurve"));
ADD_PROPERTY(filltype,(1));
}
//Structures
struct crvs{
Handle_Geom_BSplineCurve C1;
Handle_Geom_BSplineCurve C2;
Handle_Geom_BSplineCurve C3;
Handle_Geom_BSplineCurve C4;
};
//Functions
void getCurves(GeomFill_BSplineCurves& aBuilder,TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge, GeomFill_FillingStyle fstyle);
//bool orderCurves(crvs& Cs, int size);
//Check if any components of the surface have been modified
short BSplineSurf::mustExecute() const
{
if (aBSplineList.isTouched() ||
filltype.isTouched())
return 1;
return 0;
}
App::DocumentObjectExecReturn *BSplineSurf::execute(void)
{
//Set Variables
int ftype = filltype.getValue();
//Begin Construction
try{
//Identify filling style
GeomFill_FillingStyle fstyle;
if(ftype==StretchStyle) {fstyle = GeomFill_StretchStyle;}
else if(ftype==CoonsStyle) {fstyle = GeomFill_CoonsStyle;}
else if(ftype==CurvedStyle) {fstyle = GeomFill_CurvedStyle;}
else {return new App::DocumentObjectExecReturn("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");}
//Create BSpline Surface
GeomFill_BSplineCurves aSurfBuilder; //Create Surface Builder
// BRepBuilderAPI_MakeWire aWireBuilder; //Create Wire Builder
TopoDS_Wire aWire; //Create empty wire
//Get BSpline Curves from edges and initialize the builder
printf("Entering getCurves\n");
getCurves(aSurfBuilder,aWire,aBSplineList,fstyle);
//Create the surface
printf("Creating the Surface\n");
const Handle_Geom_BSplineSurface aSurface = aSurfBuilder.Surface();
printf("Creating the Face\n");
BRepBuilderAPI_MakeFace aFaceBuilder(aSurface,aWire,Standard_True); //Create Face Builder
// Standard_Real u0 = 0.;
// Standard_Real u1 = 2.;
// Standard_Real v0 = 0.;
// Standard_Real v1 = 2.;
// aFaceBuilder.Init(aSurface,u0,u1,v0,v1,Precision::Confusion());
printf("Returning the Face\n");
TopoDS_Face aFace = aFaceBuilder.Face(); //Returned Face
if(!aFaceBuilder.IsDone()){return new App::DocumentObjectExecReturn("Face unable to be constructed");}
if (aFace.IsNull()){
return new App::DocumentObjectExecReturn("Resulting Face is null");
}
this->Shape.setValue(aFace);
return App::DocumentObject::StdReturn;
} //End Try
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
} //End Catch
} //End execute
void getCurves(GeomFill_BSplineCurves& aBuilder,TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge, GeomFill_FillingStyle fstyle){
//void getCurves(TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge){
crvs bcrv;
Standard_Real u0 = 0.;
Standard_Real u1 = 1.;
Handle(ShapeFix_Wire) aShFW = new ShapeFix_Wire;
Handle(ShapeExtend_WireData) aWD = new ShapeExtend_WireData;
if(anEdge.getSize()>4){Standard_Failure::Raise("Only 2-4 continuous BSpline Curves are allowed");return;}
if(anEdge.getSize()<2){Standard_Failure::Raise("Only 2-4 continuous BSpline Curves are allowed");return;}
for(int i=0; i<anEdge.getSize(); i++){
Part::TopoShape ts; //Curve TopoShape
TopoDS_Shape sub; //Curve TopoDS_Shape
TopoDS_Edge etmp; //Curve TopoDS_Edge
//Get Edge
App::PropertyLinkSubList::SubSet set = anEdge[i];
if(set.obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
ts = static_cast<Part::Feature*>(set.obj)->Shape.getShape();
//we want only the subshape which is linked
sub = ts.getSubShape(set.sub);
if(sub.ShapeType() == TopAbs_EDGE) {etmp = TopoDS::Edge(sub);} //Check Shape type and assign edge
else{Standard_Failure::Raise("Curves must be type TopoDS_Edge");return;} //Raise exception
aWD->Add(etmp);
}
else{Standard_Failure::Raise("Curve not from Part::Feature");return;}
}
//Reorder the curves and fix the wire if required
aShFW->Load(aWD); //Load in the wire
aShFW->FixReorder(); //Fix the order of the edges if required
aShFW->ClosedWireMode() = Standard_True; //Enables closed wire mode
aShFW->FixConnected(); //Fix connection between wires
aShFW->FixSelfIntersection(); //Fix Self Intersection
aShFW->Perform(); //Perform the fixes
aWire = aShFW->Wire(); //Healed Wire
if(aWire.IsNull()){Standard_Failure::Raise("Wire unable to be constructed");return;}
//Create BSpline Surface
TopExp_Explorer anExp (aWire, TopAbs_EDGE);
int it = 0;
for (; anExp.More(); anExp.Next()) {
const TopoDS_Edge hedge = TopoDS::Edge (anExp.Current());
TopLoc_Location heloc = hedge.Location();
Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge,heloc,u0,u1); //The geometric curve
Handle_Geom_BSplineCurve b_geom = Handle_Geom_BSplineCurve::DownCast(c_geom); //Try to get BSpline curve
if (!b_geom.IsNull()) {
//Store Underlying Geometry
if(it==0){bcrv.C1 = b_geom;}
else if(it==1){bcrv.C2 = b_geom;}
else if(it==2){bcrv.C3 = b_geom;}
else if(it==3){bcrv.C4 = b_geom;}
}
else {
Standard_Failure::Raise("Curve not a BSpline Curve");
return;
}
it++;
}
int ncrv = anEdge.getSize();
if(ncrv==2){aBuilder.Init(bcrv.C1,bcrv.C2,fstyle);}
else if(ncrv==3){aBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,fstyle);}
else if(ncrv==4){aBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,bcrv.C4,fstyle);}
return;
}
*/

View File

@@ -32,6 +32,7 @@
#include <BRepBuilderAPI_Copy.hxx>
#include <Base/Tools.h>
#include <Base/Exception.h>
#include <BRepBuilderAPI_MakeFace.hxx>
#endif
#include "FeatureBSurf.h"
@@ -113,3 +114,18 @@ void BSurf::getWire(TopoDS_Wire& aWire)
if(aWire.IsNull()){Standard_Failure::Raise("Wire unable to be constructed");return;}
}
void BSurf::createFace(Handle_Geom_BoundedSurface aSurface)
{
BRepBuilderAPI_MakeFace aFaceBuilder;
Standard_Real u1, u2, v1, v2;
// transfer surface bounds to face
aSurface->Bounds(u1, u2, v1, v2);
aFaceBuilder.Init(aSurface, u1, u2, v1, v2, Precision::Confusion());
TopoDS_Face aFace = aFaceBuilder.Face();
if(!aFaceBuilder.IsDone()) { Standard_Failure::Raise("Face unable to be constructed");}
if (aFace.IsNull()) { Standard_Failure::Raise("Resulting Face is null"); }
this->Shape.setValue(aFace);
}

View File

@@ -28,6 +28,7 @@
#include <App/PropertyUnits.h>
#include <App/PropertyLinks.h>
#include <GeomFill_BezierCurves.hxx>
#include <Geom_BoundedSurface.hxx>
#include "Mod/Part/App/PartFeature.h"
namespace Surface
@@ -49,6 +50,7 @@ public:
protected:
GeomFill_FillingStyle getFillingStyle();
void getWire(TopoDS_Wire& aWire);
void createFace(const Handle_Geom_BoundedSurface aSurface);
};
}

View File

@@ -23,7 +23,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
@@ -31,14 +30,13 @@
#include <Geom_BezierCurve.hxx>
#include <Precision.hxx>
#include <gp_Trsf.hxx>
#include <GeomFill.hxx>
#include <GeomFill_BezierCurves.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRep_Tool.hxx>
#include <TopExp_Explorer.hxx>
#include <Standard_ConstructionError.hxx>
#include <Base/Tools.h>
#include <Base/Exception.h>
#include <GeomFill_BezierCurves.hxx>
#include <GeomFill.hxx>
#endif
#include "FeatureBezSurf.h"
@@ -56,50 +54,32 @@ BezSurf::BezSurf()
ADD_PROPERTY(filltype,(1));
}
//Structures
struct crvs{
Handle_Geom_BezierCurve C1;
Handle_Geom_BezierCurve C2;
Handle_Geom_BezierCurve C3;
Handle_Geom_BezierCurve C4;
};
//Functions
App::DocumentObjectExecReturn *BezSurf::execute(void)
{
//Begin Construction
try{
GeomFill_FillingStyle fstyle = getFillingStyle();
GeomFill_BezierCurves aSurfBuilder; //Create Surface Builder
Handle_Geom_BezierCurve crvs[4];
TopoDS_Wire aWire; //Create empty wire
//Gets the healed wire
getWire(aWire);
//Create Bezier Surface builder
crvs bcrv;
Standard_Real u0;// contains output
Standard_Real u1;// contains output
Standard_Real u1, u2; // contains output
TopExp_Explorer anExp (aWire, TopAbs_EDGE);
int it = 0;
for (; anExp.More(); anExp.Next()) {
const TopoDS_Edge hedge = TopoDS::Edge (anExp.Current());
TopLoc_Location heloc; // this will be output
Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge,heloc,u0,u1); //The geometric curve
Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge, heloc, u1, u2); //The geometric curve
Handle_Geom_BezierCurve b_geom = Handle_Geom_BezierCurve::DownCast(c_geom); //Try to get Bezier curve
if (!b_geom.IsNull()) {
gp_Trsf transf = heloc.Transformation();
b_geom->Transform(transf); // apply original transformation to control points
//Store Underlying Geometry
if(it==0){bcrv.C1 = b_geom;}
else if(it==1){bcrv.C2 = b_geom;}
else if(it==2){bcrv.C3 = b_geom;}
else if(it==3){bcrv.C4 = b_geom;}
crvs[it] = b_geom;
}
else {
Standard_Failure::Raise("Curve not a Bezier Curve");
@@ -107,28 +87,14 @@ App::DocumentObjectExecReturn *BezSurf::execute(void)
it++;
}
GeomFill_FillingStyle fstyle = getFillingStyle();
GeomFill_BezierCurves aSurfBuilder; //Create Surface Builder
int ncrv = aBList.getSize();
if(ncrv==2){aSurfBuilder.Init(bcrv.C1,bcrv.C2,fstyle);}
else if(ncrv==3){aSurfBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,fstyle);}
else if(ncrv==4){aSurfBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,bcrv.C4,fstyle);}
if(ncrv==2) {aSurfBuilder.Init(crvs[0], crvs[1], fstyle);}
else if(ncrv==3) {aSurfBuilder.Init(crvs[0], crvs[1], crvs[2], fstyle);}
else if(ncrv==4) {aSurfBuilder.Init(crvs[0], crvs[1], crvs[2], crvs[3], fstyle);}
//Create the surface
const Handle_Geom_BezierSurface aSurface = aSurfBuilder.Surface();
BRepBuilderAPI_MakeFace aFaceBuilder;//(aSurface,aWire,Standard_True); //Create Face Builder
u0 = 0.;
u1 = 1.;
Standard_Real v0 = 0.;
Standard_Real v1 = 1.;
aFaceBuilder.Init(aSurface,u0,u1,v0,v1,Precision::Confusion());
TopoDS_Face aFace = aFaceBuilder.Face(); //Returned Face
if(!aFaceBuilder.IsDone()){return new App::DocumentObjectExecReturn("Face unable to be constructed");}
if (aFace.IsNull()){
return new App::DocumentObjectExecReturn("Resulting Face is null");
}
this->Shape.setValue(aFace);
createFace(aSurfBuilder.Surface());
return App::DocumentObject::StdReturn;