1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

119
src/ShapeUpgrade/ShapeUpgrade.cdl Executable file
View File

@@ -0,0 +1,119 @@
-- File: ShapeUpgrade.cdl
-- Created: Wed Jun 3 12:34:19 1998
-- Author: data exchange team
-- <det@loufox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1998
package ShapeUpgrade
---Purpose: This package provides tools
-- for splitting and converting shapes by some criteria. It
-- provides modifications of the kind when one topological
-- object can be converted or splitted to several ones. In
-- particular this package contains high level API classes which perform:
-- converting geometry of shapes up to given continuity,
-- splitting revolutions by U to segments less than given value,
-- converting to beziers,
-- splitting closed faces.
uses
gp,
Geom,
Geom2d,
GeomAbs,
Adaptor3d,
GeomAdaptor,
Geom2dAPI,
TopLoc,
TColStd,
TColGeom,
TColGeom2d,
TCollection,
TopoDS,
TopTools,
TopAbs,
ShapeExtend,
ShapeBuild,
ShapeAnalysis,
BRepBuilderAPI
is
--- Instanciation of generic classes (tools)
private class Tool;
class EdgeDivide;
class ClosedEdgeDivide;
class WireDivide;
class FaceDivide;
class ClosedFaceDivide;
class FaceDivideArea;
class ShapeDivide;
class ShapeDivideArea;
class ShapeDivideContinuity;
---Purpose: API Tool for converting shapes with C0 geometry into C1 ones
class ShapeDivideAngle;
---Purpose: API Class for splitting revolutions to segments less than 90
class ShapeConvertToBezier;
---Purpose: API Class for convering curves to beziers.
class ShapeDivideClosed;
---Purpose:
class ShapeDivideClosedEdges;
---Purpose:
class SplitCurve;
class SplitCurve2d;
class SplitCurve2dContinuity;
class ConvertCurve2dToBezier;
class SplitCurve3d;
class SplitCurve3dContinuity;
class ConvertCurve3dToBezier;
class SplitSurface;
class SplitSurfaceContinuity;
class SplitSurfaceAngle;
class ConvertSurfaceToBezierBasis;
class SplitSurfaceArea;
class ShellSewing;
---Purpose: Provides access to a sewing algorithms from BRepOffsetAPI
class FixSmallCurves;
---Purpose:
class FixSmallBezierCurves;
---Purpose:
class RemoveLocations;
---Purpose: Removes all locations sub-shapes of specified shape
class RemoveInternalWires;
---Purpose: Removes all internal wires having area less than specified min area
C0BSplineToSequenceOfC1BSplineCurve (BS : BSplineCurve from Geom;
seqBS: out HSequenceOfBoundedCurve from TColGeom)
returns Boolean;
C0BSplineToSequenceOfC1BSplineCurve (BS : BSplineCurve from Geom2d;
seqBS: out HSequenceOfBoundedCurve from TColGeom2d)
returns Boolean;
--- Purpose: Converts C0 B-Spline curve into sequence of C1 B-Spline curves.
-- This method splits B-Spline at the knots with multiplicities
-- equal to degree, i.e. unlike method
-- GeomConvert::C0BSplineToArrayOfC1BSplineCurve this one does not
-- use any tolerance and therefore does not change the geometry of
-- B-Spline.
-- Returns True if C0 B-Spline was successfully splitted, else
-- returns False (if BS is C1 B-Spline).
end ShapeUpgrade;

188
src/ShapeUpgrade/ShapeUpgrade.cxx Executable file
View File

@@ -0,0 +1,188 @@
// File: ShapeUpgrade.cxx
// Created: Thu Nov 12 11:58:22 1998
// Author: data exchange team
// <det@kinox.nnov.matra-dtv.fr>
// abv 24.05.99 S4174: methods Debug() commented
#include <ShapeUpgrade.ixx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <BSplCLib.hxx>
#include <TColStd_Array1OfInteger.hxx>
/*
// Debug state= True / False.
static Standard_Boolean Dbg=Standard_False;
void ShapeUpgrade::SetDebug(const Standard_Boolean State)
{
Dbg=State;
}
Standard_Boolean ShapeUpgrade::Debug()
{
return Dbg;
}
*/
//=======================================================================
//function : C0BSplineToSequenceOfC1BSplineCurve
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve(const Handle(Geom_BSplineCurve)& BS,
Handle(TColGeom_HSequenceOfBoundedCurve)& seqBS)
{
if (BS.IsNull() || (BS->IsCN (1))) return Standard_False;
seqBS = new TColGeom_HSequenceOfBoundedCurve;
BS->SetNotPeriodic(); //to have equation NbPoles = NbKnots with Multiplicities - degree - 1
Standard_Integer deg = BS->Degree();
Standard_Integer NbKnots = BS->NbKnots();
Standard_Integer NbPoles = BS->NbPoles();
TColgp_Array1OfPnt Poles (1, NbPoles);
TColStd_Array1OfReal Weights (1, NbPoles);
TColStd_Array1OfReal Knots (1, NbKnots);
TColStd_Array1OfInteger Mults (1, NbKnots);
TColStd_Array1OfReal KnotSequence (1, NbPoles + deg + 1);
BS->Poles(Poles);
if (BS->IsRational())
BS->Weights(Weights);
else
Weights.Init(1.);
BS->Knots(Knots);
BS->Multiplicities(Mults);
BS->KnotSequence (KnotSequence);
Standard_Integer StartKnotIndex, EndKnotIndex, j;
StartKnotIndex = BS->FirstUKnotIndex();
for ( EndKnotIndex = StartKnotIndex + 1; EndKnotIndex <= BS->LastUKnotIndex(); EndKnotIndex++ ) {
if ( ( Mults (EndKnotIndex) < deg ) && ( EndKnotIndex < BS->LastUKnotIndex() ) ) continue;
Standard_Integer StartFlatIndex = BSplCLib::FlatIndex (deg, StartKnotIndex, Mults, Standard_False);
// StartFlatIndex += Mults (StartKnotIndex) - 1;
Standard_Integer EndFlatIndex = BSplCLib::FlatIndex (deg, EndKnotIndex, Mults, Standard_False);
EndFlatIndex -= Mults (EndKnotIndex) - 1;
TColStd_Array1OfReal TempKnots (1, NbKnots);
TColStd_Array1OfInteger TempMults (1, NbKnots);
TempMults.Init (1);
Standard_Integer TempKnotIndex = 1;
TempKnots (TempKnotIndex) = KnotSequence (StartFlatIndex - deg);
for ( j = StartFlatIndex - deg + 1; j <= EndFlatIndex + deg; j++ )
if (Abs (KnotSequence (j) - KnotSequence (j - 1)) <= gp::Resolution())
TempMults (TempKnotIndex) ++;
else
TempKnots (++TempKnotIndex) = KnotSequence (j);
Standard_Integer TempStartIndex = 1, TempEndIndex = TempKnotIndex;
if (TempMults (TempStartIndex) == 1)
TempMults (++TempStartIndex) ++;
if (TempMults (TempEndIndex) == 1)
TempMults (--TempEndIndex) ++;
Standard_Integer NewNbKnots = TempEndIndex - TempStartIndex + 1;
TColStd_Array1OfInteger newMults (1, NewNbKnots);
TColStd_Array1OfReal newKnots (1, NewNbKnots);
for ( j = 1; j <= NewNbKnots; j++ ) {
newMults (j) = TempMults (j + TempStartIndex - 1);
newKnots (j) = TempKnots (j + TempStartIndex - 1);
}
Standard_Integer NewNbPoles = BSplCLib::NbPoles(deg, Standard_False, newMults);
TColgp_Array1OfPnt newPoles (1, NewNbPoles);
TColStd_Array1OfReal newWeights (1, NewNbPoles);
Standard_Integer PoleIndex = StartFlatIndex - deg;//Index of starting pole when splitting B-Spline is an index of starting knot
for (j = 1; j <= NewNbPoles; j++) {
newWeights (j) = Weights (j + PoleIndex - 1);
newPoles (j) = Poles (j + PoleIndex - 1);
}
Handle(Geom_BSplineCurve) newC = new Geom_BSplineCurve
(newPoles, newWeights, newKnots, newMults,deg);
seqBS->Append (newC);
StartKnotIndex = EndKnotIndex;
}
return Standard_True;
}
//=======================================================================
//function : C0BSplineToSequenceOfC1BSplineCurve
//purpose :
//=======================================================================
static Handle(Geom_BSplineCurve) BSplineCurve2dTo3d (const Handle(Geom2d_BSplineCurve)& BS)
{
Standard_Integer deg = BS->Degree();
Standard_Integer NbKnots = BS->NbKnots();
Standard_Integer NbPoles = BS->NbPoles();
TColgp_Array1OfPnt2d Poles2d (1,NbPoles);
TColStd_Array1OfReal Weights (1,NbPoles);
TColStd_Array1OfReal Knots (1,NbKnots);
TColStd_Array1OfInteger Mults (1,NbKnots);
BS->Poles(Poles2d);
if (BS->IsRational())
BS->Weights(Weights);
else
Weights.Init (1);
BS->Knots (Knots);
BS->Multiplicities (Mults);
TColgp_Array1OfPnt Poles3d (1,NbPoles);
for (Standard_Integer i = 1; i <= NbPoles; i++)
Poles3d (i) = gp_Pnt (Poles2d (i).X(), Poles2d (i).Y(), 0);
Handle(Geom_BSplineCurve) BS3d = new Geom_BSplineCurve (Poles3d, Weights,
Knots, Mults, deg, BS->IsPeriodic());
return BS3d;
}
static Handle(Geom2d_BSplineCurve) BSplineCurve3dTo2d (const Handle(Geom_BSplineCurve)& BS)
{
Standard_Integer deg = BS->Degree();
Standard_Integer NbKnots = BS->NbKnots();
Standard_Integer NbPoles = BS->NbPoles();
TColgp_Array1OfPnt Poles3d (1, NbPoles);
TColStd_Array1OfReal Weights (1, NbPoles);
TColStd_Array1OfReal Knots (1, NbKnots);
TColStd_Array1OfInteger Mults (1, NbKnots);
BS->Poles(Poles3d);
if (BS->IsRational())
BS->Weights(Weights);
else
Weights.Init (1);
BS->Knots (Knots);
BS->Multiplicities (Mults);
TColgp_Array1OfPnt2d Poles2d (1,NbPoles);
for (Standard_Integer i = 1; i <= NbPoles; i++)
Poles2d (i) = gp_Pnt2d (Poles3d (i).X(), Poles3d (i).Y());
Handle(Geom2d_BSplineCurve) BS2d = new Geom2d_BSplineCurve (Poles2d, Weights,
Knots, Mults, deg, BS->IsPeriodic());
return BS2d;
}
Standard_Boolean ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve(const Handle(Geom2d_BSplineCurve)& BS,
Handle(TColGeom2d_HSequenceOfBoundedCurve)& seqBS)
{
if (BS.IsNull() || (BS->IsCN (1))) return Standard_False;
Handle(Geom_BSplineCurve) BS3d = BSplineCurve2dTo3d (BS);
Handle(TColGeom_HSequenceOfBoundedCurve) seqBS3d;
Standard_Boolean result = C0BSplineToSequenceOfC1BSplineCurve (BS3d, seqBS3d);
if (result) {
seqBS = new TColGeom2d_HSequenceOfBoundedCurve;
for (Standard_Integer i = 1; i <= seqBS3d->Length(); i++)
seqBS->Append (BSplineCurve3dTo2d (Handle(Geom_BSplineCurve)::DownCast (seqBS3d->Value (i))));
}
return result;
}

View File

@@ -0,0 +1,24 @@
-- File: ShapeUpgrade_ClosedEdgeDivide.cdl
-- Created: Thu May 25 10:17:39 2000
-- Author: data exchange team
-- <det@friendox>
---Copyright: Matra Datavision 2000
class ClosedEdgeDivide from ShapeUpgrade inherits EdgeDivide from ShapeUpgrade
---Purpose:
uses
Edge from TopoDS
is
Create returns ClosedEdgeDivide from ShapeUpgrade;
---Purpose: Empty constructor.
Compute(me: mutable; anEdge: Edge from TopoDS)
returns Boolean is redefined;
end ClosedEdgeDivide;

View File

@@ -0,0 +1,122 @@
// File: ShapeUpgrade_ClosedEdgeDivide.cxx
// Created: Thu May 25 10:19:23 2000
// Author: data exchange team
// <det@friendox>
#include <ShapeUpgrade_ClosedEdgeDivide.ixx>
#include <ShapeAnalysis_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <BRep_Tool.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <ShapeUpgrade_SplitCurve3d.hxx>
#include <ShapeUpgrade_SplitCurve2d.hxx>
#include <gp_Pnt.hxx>
#include <Geom_Surface.hxx>
#include <gp_Pnt2d.hxx>
//=======================================================================
//function : ShapeUpgrade_ClosedEdgeDivide
//purpose :
//=======================================================================
ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
ShapeUpgrade_EdgeDivide()
{
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
{
Clear();
ShapeAnalysis_Edge sae;
TopoDS_Vertex V1 = sae.FirstVertex(anEdge);
TopoDS_Vertex V2 = sae.LastVertex(anEdge);
if( V1.IsSame(V2) && !BRep_Tool::Degenerated ( anEdge ) ) {
const Standard_Integer nbPoints = 23;
gp_Pnt pntV = BRep_Tool::Pnt(V1);
Standard_Real TolV1 = LimitTolerance( BRep_Tool::Tolerance(V1) );
TolV1=TolV1*TolV1;
Standard_Real f, l;
Handle(Geom_Curve) curve3d = BRep_Tool::Curve (anEdge, f, l);
myHasCurve3d = !curve3d.IsNull();
Standard_Real f2d, l2d;
Handle(Geom2d_Curve) pcurve1;
if ( ! myFace.IsNull() ) { // process free edges
sae.PCurve (anEdge, myFace, pcurve1, f2d, l2d, Standard_False);
}
myHasCurve2d = !pcurve1.IsNull();
if ( myHasCurve3d ) {
Standard_Real maxPar = f, dMax = 0;
Standard_Real step = (l-f)/(nbPoints-1);
Standard_Real param = f+step;
for (Standard_Integer i = 1; i < 23; i++, param+=step) {
gp_Pnt curPnt = curve3d->Value(param);
Standard_Real dist = pntV.SquareDistance(curPnt);
if(dist > dMax) {
maxPar = param;
dMax = dist;
}
}
if(dMax > TolV1) {
Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
theSplit3dTool->Init(curve3d,f,l);
Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
values->Append(maxPar);
theSplit3dTool->SetSplitValues(values);
myKnots3d = theSplit3dTool->SplitValues();
if(myHasCurve2d) {
Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
theSplit2dTool->Init(pcurve1,f2d,l2d);
myKnots2d = theSplit2dTool->SplitValues();
}
return Standard_True;
}
else
return Standard_False;
}
if ( myHasCurve2d ) {
Handle(Geom_Surface) surf = BRep_Tool::Surface(myFace);
Standard_Real maxPar = f2d, dMax = 0;
Standard_Real step = (l2d-f2d)/(nbPoints-1);
Standard_Real param = f2d+step;
for (Standard_Integer i = 1; i < 23; i++, param+=step) {
gp_Pnt2d p2d = pcurve1->Value(param);
gp_Pnt curPnt = surf->Value(p2d.X(),p2d.Y());
Standard_Real dist = pntV.SquareDistance(curPnt);
if(dist > dMax) {
maxPar = param;
dMax = dist;
}
}
if(dMax > TolV1) {
Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
theSplit2dTool->Init(pcurve1,f2d,l2d);
Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
values->Append(maxPar);
theSplit2dTool->SetSplitValues(values);
myKnots2d = theSplit2dTool->SplitValues();
return Standard_True;
}
else
return Standard_False;
}
return Standard_False;
}
else
return Standard_False;
}

View File

@@ -0,0 +1,43 @@
-- File: ShapeUpgrade_ClosedFaceDivide.cdl
-- Created: Thu Jul 22 16:06:50 1999
-- Author: data exchange team
-- <det@friendox>
---Copyright: Matra Datavision 1999
class ClosedFaceDivide from ShapeUpgrade inherits FaceDivide from ShapeUpgrade
---Purpose: Divides a Face with one or more seam edge to avoid closed faces.
-- Splitting is performed by U and V direction. The number of
-- resulting faces can be defined by user.
uses
Face from TopoDS
is
Create returns ClosedFaceDivide from ShapeUpgrade;
---Purpose: Creates empty constructor.
Create (F : Face from TopoDS)
returns ClosedFaceDivide from ShapeUpgrade;
--- Purpose : Initialize by a Face.
SplitSurface (me: mutable)
returns Boolean is redefined;
---Purpose: Performs splitting of surface and computes the shell
-- from source face.
SetNbSplitPoints(me: mutable; num: Integer);
---Purpose: Sets the number of cutting lines by which closed face
-- will be splitted. The resulting faces will be num+1.
GetNbSplitPoints(me) returns Integer;
---Purpose: Returns the number of splitting points
fields
myNbSplit: Integer;
end ClosedFaceDivide;

View File

@@ -0,0 +1,253 @@
// File: ShapeUpgrade_ClosedFaceDivide.cxx
// Created: Thu Jul 22 16:11:23 1999
// Author: data exchange team
// <det@friendox>
#include <ShapeUpgrade_ClosedFaceDivide.ixx>
#include <Precision.hxx>
#include <ShapeExtend.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Wire.hxx>
#include <ShapeExtend_WireData.hxx>
#include <TopoDS_Edge.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <Geom2d_Curve.hxx>
#include <ShapeAnalysis_Curve.hxx>
#include <Bnd_Box2d.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <BRep_Tool.hxx>
#include <ShapeUpgrade_SplitSurface.hxx>
#include <ShapeExtend_CompositeSurface.hxx>
#include <ShapeFix_ComposeShell.hxx>
#include <TopExp_Explorer.hxx>
#include <ShapeAnalysis_Surface.hxx>
#include <ShapeAnalysis.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <ShapeBuild_ReShape.hxx>
#include <ShapeAnalysis.hxx>
//=======================================================================
//function : ShapeUpgrade_ClosedFaceDivide
//purpose :
//=======================================================================
ShapeUpgrade_ClosedFaceDivide::ShapeUpgrade_ClosedFaceDivide():
ShapeUpgrade_FaceDivide()
{
myNbSplit = 1;
}
//=======================================================================
//function : ShapeUpgrade_ClosedFaceDivide
//purpose :
//=======================================================================
ShapeUpgrade_ClosedFaceDivide::ShapeUpgrade_ClosedFaceDivide(const TopoDS_Face& F):
ShapeUpgrade_FaceDivide(F)
{
myNbSplit = 1;
}
//=======================================================================
//function : SplitSurface
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_ClosedFaceDivide::SplitSurface()
{
Handle(ShapeUpgrade_SplitSurface) SplitSurf = GetSplitSurfaceTool();
if ( SplitSurf.IsNull() ) return Standard_False;
if ( myResult.IsNull() || myResult.ShapeType() != TopAbs_FACE ) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
return Standard_False;
}
TopoDS_Face face = TopoDS::Face ( myResult );
Standard_Real Uf,Ul,Vf,Vl;
ShapeAnalysis::GetFaceUVBounds ( myFace, Uf, Ul, Vf, Vl );
// 01.10.99 pdn Porting on DEC
if( ::Precision::IsInfinite(Uf) || ::Precision::IsInfinite(Ul) ||
::Precision::IsInfinite(Vf) || ::Precision::IsInfinite(Vl) )
return Standard_False;
TopLoc_Location L;
Handle(Geom_Surface) surf;
surf = BRep_Tool::Surface ( face, L );
Standard_Boolean isUSplit = Standard_False;
Standard_Boolean doSplit = Standard_False;
Handle(TColStd_HSequenceOfReal) split = new TColStd_HSequenceOfReal;
for(TopoDS_Iterator iter(face); iter.More()&&!doSplit; iter.Next()) {
if(iter.Value().ShapeType() != TopAbs_WIRE)
continue;
TopoDS_Wire wire = TopoDS::Wire(iter.Value());
Handle(ShapeExtend_WireData) sewd = new ShapeExtend_WireData(wire);
for(Standard_Integer i = 1; i <= sewd->NbEdges()&&!doSplit; i++)
if(sewd->IsSeam(i)) {
doSplit = Standard_True;
TopoDS_Edge edge = sewd->Edge(i);
ShapeAnalysis_Edge sae;
Handle(Geom2d_Curve) c1, c2;
Standard_Real f1,f2,l1,l2;
if(!sae.PCurve(edge,face,c1,f1,l1,Standard_False))
continue;
//smh#8
TopoDS_Shape tmpE = edge.Reversed();
if(!sae.PCurve(TopoDS::Edge(tmpE),face,c2,f2,l2,Standard_False))
continue;
if(c2==c1) continue;
// splitting
ShapeAnalysis_Curve sac;
Bnd_Box2d B1, B2;
sac.FillBndBox ( c1, f1, l1, 20, Standard_True, B1 );
sac.FillBndBox ( c2, f2, l2, 20, Standard_True, B2 );
Standard_Real x1min,y1min,x1max,y1max;
Standard_Real x2min,y2min,x2max,y2max;
B1.Get(x1min,y1min,x1max,y1max);
B2.Get(x2min,y2min,x2max,y2max);
Standard_Real xf,xl,yf,yl;
if(x1min < x2min) {
xf = x1max;
xl = x2min;
} else {
xf = x2max;
xl = x1min;
}
if(y1min < y2min) {
yf = y1max;
yl = y2min;
} else {
yf = y2max;
yl = y1min;
}
Standard_Real dU = xl - xf;
Standard_Real dV = yl - yf;
if(dU > dV) {
Standard_Real step = dU/(myNbSplit+1);
Standard_Real val = xf+step;
for(Standard_Integer j = 1; j <= myNbSplit; j++, val+=step)
split->Append(val);
isUSplit = Standard_True;
}
else {
Standard_Real step = dV/(myNbSplit+1);
Standard_Real val = yf+step;
for(Standard_Integer j = 1; j <= myNbSplit; j++, val+=step)
split->Append(val);
isUSplit = Standard_False;
}
}
}
if(!doSplit) {
//pdn try to define geometric closure.
Handle(ShapeAnalysis_Surface) sas = new ShapeAnalysis_Surface( surf );
Standard_Boolean uclosed = sas->IsUClosed(Precision());
Standard_Boolean vclosed = sas->IsVClosed(Precision());
Standard_Real U1, U2, V1, V2;
if(uclosed) {
surf -> Bounds(U1, U2, V1, V2);
GeomAdaptor_Surface GAS ( surf );
Standard_Real toler = GAS.UResolution ( Precision() );
if((U2-U1) - (Ul-Uf) < toler ) {
Handle(Geom_RectangularTrimmedSurface) rts =
new Geom_RectangularTrimmedSurface(surf,U1,(U2+U1)/2,Standard_True);
Handle(ShapeAnalysis_Surface) sast = new ShapeAnalysis_Surface( rts );
if ( !sast->IsUClosed(Precision())) {
doSplit = Standard_True;
Standard_Real step = (Ul-Uf)/(myNbSplit+1);
Standard_Real val = Uf+step;
for(Standard_Integer i = 1; i <= myNbSplit; i++, val+=step)
split->Append(val);
isUSplit = Standard_True;
}
#ifdef DEB
else cout << "Warning: SU_ClosedFaceDivide: Thin face, not splitted" << endl;
#endif
}
}
if( vclosed && !doSplit ) {
surf -> Bounds(U1, U2, V1, V2);
GeomAdaptor_Surface GAS ( surf );
Standard_Real toler = GAS.VResolution ( Precision() );
if((V2-V1) - (Vl-Vf) < toler) {
Handle(Geom_RectangularTrimmedSurface) rts =
new Geom_RectangularTrimmedSurface(surf,V1,(V2+V1)/2,Standard_False);
Handle(ShapeAnalysis_Surface) sast = new ShapeAnalysis_Surface( rts );
if ( !sast->IsVClosed(Precision())) {
doSplit = Standard_True;
Standard_Real step = (Vl-Vf)/(myNbSplit+1);
Standard_Real val = Vf+step;
for(Standard_Integer i = 1; i <= myNbSplit; i++, val+=step)
split->Append(val);
isUSplit = Standard_False;
}
#ifdef DEB
else cout << "Warning: SU_ClosedFaceDivide: Thin face, not splitted" << endl;
#endif
}
}
}
if(!doSplit)
return Standard_False;
SplitSurf->Init ( surf, Uf, Ul, Vf, Vl );
if(isUSplit)
SplitSurf->SetUSplitValues(split);
else
SplitSurf->SetVSplitValues(split);
SplitSurf->Perform(mySegmentMode);
if ( ! SplitSurf->Status ( ShapeExtend_DONE ) ) return Standard_False;
Handle(ShapeExtend_CompositeSurface) Grid = SplitSurf->ResSurfaces();
ShapeFix_ComposeShell CompShell;
CompShell.Init( Grid, L, face, Precision() );
CompShell.SetMaxTolerance(MaxTolerance());
CompShell.SetContext(Context());
CompShell.Perform();
if ( CompShell.Status ( ShapeExtend_FAIL ) ||
! CompShell.Status ( ShapeExtend_DONE ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
TopoDS_Shape res = CompShell.Result();
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
for(TopExp_Explorer exp(res, TopAbs_FACE); exp.More(); exp.Next()) {
//smh#8
TopoDS_Shape tempf = Context()->Apply(exp.Current());
TopoDS_Face f = TopoDS::Face(tempf);
myResult = f;
if(SplitSurface())
Context()->Replace(f,myResult);
}
myResult = Context()->Apply(res);
return Standard_True;
}
//=======================================================================
//function : SetFaceNumber
//purpose :
//=======================================================================
void ShapeUpgrade_ClosedFaceDivide::SetNbSplitPoints(const Standard_Integer num)
{
if(num > 0)
myNbSplit = num;
}
//=======================================================================
//function : GetNbSplitPoints
//purpose :
//=======================================================================
Standard_Integer ShapeUpgrade_ClosedFaceDivide::GetNbSplitPoints() const
{
return myNbSplit;
}

View File

@@ -0,0 +1,42 @@
-- File: ShapeUpgrade_ConvertCurve2dToBezier.cdl
-- Created: Thu May 13 13:51:24 1999
-- Author: data exchange team
-- <det@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class ConvertCurve2dToBezier from ShapeUpgrade inherits SplitCurve2d from ShapeUpgrade
---Purpose: converts/splits a 2d curve to a list of beziers
uses
HSequenceOfCurve from TColGeom2d,
HSequenceOfReal from TColStd
is
Create returns ConvertCurve2dToBezier from ShapeUpgrade;
---Purpose: Empty constructor.
Compute(me: mutable) is redefined;
---Purpose: Converts curve into a list of beziers, and stores the
-- splitting parameters on original curve.
Build (me: mutable; Segment: Boolean) is redefined;
---Purpose: Splits a list of beziers computed by Compute method according
-- the split values and splitting parameters.
Segments(me) returns HSequenceOfCurve from TColGeom2d is private;
---Purpose: Returns the list of bezier curves correspondent to original
-- curve.
SplitParams(me) returns HSequenceOfReal from TColStd;
---Purpose: Returns the list of splitted parameters in original curve
-- parametrisation.
fields
mySegments : HSequenceOfCurve from TColGeom2d;
mySplitParams: HSequenceOfReal from TColStd;
end ConvertCurve2dToBezier;

View File

@@ -0,0 +1,265 @@
// File: ShapeUpgrade_ConvertCurve2dToBezier.cxx
// Created: Thu May 13 14:06:07 1999
// Author: data exchange team
// <det@friendox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_ConvertCurve2dToBezier.ixx>
#include <Precision.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <ShapeExtend.hxx>
#include <Geom2d_Line.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom2d_Conic.hxx>
#include <Geom_Curve.hxx>
#include <Geom2dConvert_ApproxCurve.hxx>
#include <Geom2dConvert.hxx>
#include <Geom2dConvert_BSplineCurveToBezierCurve.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColGeom2d_HArray1OfCurve.hxx>
#include <GeomTools.hxx>
#include <ShapeCustom_Curve2d.hxx>
ShapeUpgrade_ConvertCurve2dToBezier::ShapeUpgrade_ConvertCurve2dToBezier()
{
mySegments = new TColGeom2d_HSequenceOfCurve;
mySplitParams = new TColStd_HSequenceOfReal;
}
static Handle(Geom2d_BezierCurve) MakeBezier2d(const Handle(Geom2d_Curve)& theCurve2d,
const Standard_Real theFirst,
const Standard_Real theLast)
{
TColgp_Array1OfPnt2d poles(1,2);
poles(1) = theCurve2d->Value(theFirst);
poles(2) = theCurve2d->Value(theLast);
Handle(Geom2d_BezierCurve) bezier = new Geom2d_BezierCurve(poles);
return bezier;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void ShapeUpgrade_ConvertCurve2dToBezier::Compute()
{
mySegments->Clear();
mySplitParams->Clear();
Standard_Real precision = Precision::PConfusion();
Standard_Real First = mySplitValues->Value(1);
Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
// PTV Try to create line2d from myCurve
if ( myCurve->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve)) ||
myCurve->IsKind(STANDARD_TYPE(Geom2d_BezierCurve)) )
{
// static function`s code getted from ShapeConvert
Standard_Real tmpF, tmpL, aDeviation;
Handle(Geom2d_Line) aTmpLine2d =
ShapeCustom_Curve2d::ConvertToLine2d(myCurve, First, Last, Precision::Approximation(),
tmpF, tmpL, aDeviation);
if (!aTmpLine2d.IsNull() && (aDeviation <= Precision::Approximation()) )
{
Handle(Geom2d_BezierCurve) bezier = MakeBezier2d(aTmpLine2d, tmpF, tmpL);
mySegments->Append(bezier);
mySplitParams->Append(First);
mySplitParams->Append(Last);
myNbCurves = mySplitValues->Length()-1;
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
return;
}
}
if(myCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (myCurve);
Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
ShapeUpgrade_ConvertCurve2dToBezier converter;
//converter.Init(BasCurve,Max(First,BasCurve->FirstParameter()),Min(Last,BasCurve->LastParameter())); //???
converter.Init(BasCurve,First,Last);
converter.SetSplitValues(mySplitValues);
converter.Compute();
mySplitValues->Clear();
mySplitValues->ChangeSequence() = converter.SplitValues()->Sequence();
myNbCurves = mySplitValues->Length()-1;
myStatus |= converter.myStatus;
mySegments->ChangeSequence() = converter.Segments()->Sequence();
mySplitParams->ChangeSequence() = converter.SplitParams()->Sequence();
return;
}
else if(myCurve->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
Handle(Geom2d_BezierCurve) bezier = Handle(Geom2d_BezierCurve)::DownCast (myCurve);
myNbCurves = mySplitValues->Length()-1;
mySplitParams->Append(First);
mySplitParams->Append(Last);
if(First < precision && Last > 1 - precision) {
mySegments->Append(bezier);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
} else {
Handle(Geom2d_BezierCurve) besNew = Handle(Geom2d_BezierCurve)::DownCast(bezier->Copy());
besNew->Segment(First,Last);
mySegments->Append(besNew);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
}
return;
}
else if(myCurve->IsKind(STANDARD_TYPE(Geom2d_Line))) {
Handle(Geom2d_Line) aLine2d = Handle(Geom2d_Line)::DownCast(myCurve);
Handle(Geom2d_BezierCurve) bezier = MakeBezier2d(aLine2d, First, Last);
mySegments->Append(bezier);
mySplitParams->Append(First);
mySplitParams->Append(Last);
myNbCurves = mySplitValues->Length()-1;
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
return;
}
else {
Handle(Geom2d_BSplineCurve) aBSpline2d;
Standard_Real Shift = 0.;
if(myCurve->IsKind(STANDARD_TYPE(Geom2d_Conic))) {
Handle(Geom2d_TrimmedCurve) tcurve = new Geom2d_TrimmedCurve(myCurve,First,Last); //protection agains parabols ets
Geom2dConvert_ApproxCurve approx (tcurve, Precision::Approximation(),
GeomAbs_C1, 100, 6 );
if ( approx.HasResult() )
aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(approx.Curve());
else
aBSpline2d = Geom2dConvert::CurveToBSplineCurve(tcurve,Convert_QuasiAngular);
Shift = First - aBSpline2d->FirstParameter();
First = aBSpline2d->FirstParameter();
Last = aBSpline2d->LastParameter();
}
else if(!myCurve->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
aBSpline2d = Geom2dConvert::CurveToBSplineCurve(myCurve,Convert_QuasiAngular);
}
else
aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
Standard_Real bf = aBSpline2d->FirstParameter();
Standard_Real bl = aBSpline2d->LastParameter();
if(Abs(First-bf) < precision)
First = bf;
if(Abs(Last-bl) < precision)
Last = bl;
if(First < bf){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the pcurve domain" <<endl;
#endif
First = bf;
mySplitValues->SetValue(1,First);
}
if(Last > bl){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the pcurve domain" <<endl;
#endif
Last = bl;
mySplitValues->SetValue(mySplitValues->Length(),Last);
}
// PTV 20.12.2001 Try to simpify BSpline Curve
ShapeCustom_Curve2d::SimplifyBSpline2d (aBSpline2d, Precision::Approximation());
Geom2dConvert_BSplineCurveToBezierCurve tool(aBSpline2d,First,Last,precision);
Standard_Integer nbArcs = tool.NbArcs();
TColStd_Array1OfReal knots(1,nbArcs+1);
tool.Knots(knots);
mySplitParams->Append(First+Shift);
Standard_Integer j; // svv Jan 10 2000 : porting on DEC
Standard_Real newFirst = First+Shift;
Standard_Real newLast = First+Shift;
for(j = 1; j <=nbArcs; j++) {
Standard_Real nextKnot = knots(j+1)+Shift;
if(nextKnot - mySplitParams->Value(mySplitParams->Length()) > precision) {
Handle(Geom2d_Curve) aCrv2d = tool.Arc(j);
if ( aCrv2d->IsKind(STANDARD_TYPE(Geom2d_BezierCurve)) )
{
newFirst = newLast;
newLast = nextKnot;
Standard_Real tmpF, tmpL, aDeviation;
Handle(Geom2d_Line) aTmpLine2d =
ShapeCustom_Curve2d::ConvertToLine2d(aCrv2d, newFirst, newLast, Precision::Approximation(),
tmpF, tmpL, aDeviation);
if (!aTmpLine2d.IsNull() && (aDeviation <= Precision::Approximation()) )
{
Handle(Geom2d_BezierCurve) bezier = MakeBezier2d(aBSpline2d, newFirst, newLast);
mySegments->Append(bezier);
mySplitParams->Append(newLast);
continue;
}
}
mySegments->Append(aCrv2d);
mySplitParams->Append(nextKnot);
}
}
First = mySplitValues->Value(1);
for(j = 2; j <= mySplitValues->Length(); j++) {
Last = mySplitValues->Value(j);
for(Standard_Integer i = 2; i <= nbArcs+1; i++) {
Standard_Real valknot = knots(i)+Shift;
if(valknot <= First + precision) continue;
if(valknot >= Last - precision) break;
mySplitValues->InsertBefore(j++,valknot);
}
First = Last;
}
myNbCurves = mySplitValues->Length()-1;
}
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_ConvertCurve2dToBezier::Build(const Standard_Boolean /*Segment*/)
{
Standard_Real prec = Precision::PConfusion();
Standard_Integer nb = mySplitValues->Length();
myResultingCurves = new TColGeom2d_HArray1OfCurve (1,nb-1);
Standard_Real prevPar =0.;
Standard_Integer j=2;
for(Standard_Integer i = 2; i <= nb; i++) {
Standard_Real par = mySplitValues->Value(i);
for(; j<= mySplitParams->Length(); j++)
if(mySplitParams->Value(j)+prec > par)
break;
else
prevPar = 0.;
Handle(Geom2d_BezierCurve) bes = Handle(Geom2d_BezierCurve)
::DownCast(mySegments->Value(j-1)->Copy());
Standard_Real uFact = mySplitParams->Value(j) - mySplitParams->Value(j-1);
Standard_Real pp = mySplitValues->Value(i-1);
Standard_Real length = (par - pp)/uFact;
bes->Segment(prevPar, prevPar+length);
prevPar += length;
myResultingCurves->SetValue(i-1,bes);
}
}
//=======================================================================
//function : Segments
//purpose :
//=======================================================================
Handle(TColGeom2d_HSequenceOfCurve) ShapeUpgrade_ConvertCurve2dToBezier::Segments() const
{
return mySegments;
}
//=======================================================================
//function : SplitParams
//purpose :
//=======================================================================
Handle(TColStd_HSequenceOfReal) ShapeUpgrade_ConvertCurve2dToBezier::SplitParams() const
{
return mySplitParams;
}

View File

@@ -0,0 +1,70 @@
-- File: ShapeUpgrade_ConvertCurve3dToBezier.cdl
-- Created: Thu May 13 14:02:24 1999
-- Author: data exchange team
-- <det@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class ConvertCurve3dToBezier from ShapeUpgrade inherits SplitCurve3d from ShapeUpgrade
---Purpose: converts/splits a 3d curve of any type to a list of beziers
uses
HSequenceOfCurve from TColGeom,
HSequenceOfReal from TColStd
is
Create returns ConvertCurve3dToBezier from ShapeUpgrade;
---Purpose: Empty constructor
SetLineMode(me:mutable; mode: Boolean);
---Purpose: Sets mode for conversion Geom_Line to bezier.
---C++: inline
GetLineMode(me) returns Boolean;
---Purpose: Returns the Geom_Line conversion mode.
---C++: inline
SetCircleMode(me:mutable; mode: Boolean);
---Purpose: Sets mode for conversion Geom_Circle to bezier.
---C++: inline
GetCircleMode(me) returns Boolean;
---Purpose: Returns the Geom_Circle conversion mode.
---C++: inline
SetConicMode(me:mutable; mode: Boolean);
---Purpose: Returns the Geom_Conic conversion mode.
---C++: inline
GetConicMode(me) returns Boolean;
---Purpose: Performs converting and computes the resulting shape.
---C++: inline
Compute(me: mutable) is redefined;
---Purpose: Converts curve into a list of beziers, and stores the
-- splitting parameters on original curve.
Build (me: mutable; Segment: Boolean) is redefined;
---Purpose: Splits a list of beziers computed by Compute method according
-- the split values and splitting parameters.
Segments(me) returns HSequenceOfCurve from TColGeom is private;
---Purpose: Returns the list of bezier curves correspondent to original
-- curve.
SplitParams(me) returns HSequenceOfReal from TColStd;
---Purpose: Returns the list of splitted parameters in original curve
-- parametrisation.
fields
mySegments : HSequenceOfCurve from TColGeom;
mySplitParams: HSequenceOfReal from TColStd;
myLineMode : Boolean;
myCircleMode : Boolean;
myConicMode : Boolean;
end ConvertCurve2dToBezier;

View File

@@ -0,0 +1,228 @@
// File: ShapeUpgrade_ConvertCurve3dToBezier.cxx
// Created: Thu May 13 17:50:43 1999
// Author: data exchange team
// <det@friendox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_ConvertCurve3dToBezier.ixx>
#include <Precision.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_BezierCurve.hxx>
#include <ShapeExtend.hxx>
#include <Geom_Line.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_Conic.hxx>
#include <GeomConvert_ApproxCurve.hxx>
#include <GeomConvert.hxx>
#include <GeomConvert_BSplineCurveToBezierCurve.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <Geom_Circle.hxx>
ShapeUpgrade_ConvertCurve3dToBezier::ShapeUpgrade_ConvertCurve3dToBezier()
{
mySegments = new TColGeom_HSequenceOfCurve;
mySplitParams = new TColStd_HSequenceOfReal;
myLineMode = Standard_True;
myCircleMode = Standard_True;
myConicMode = Standard_True;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void ShapeUpgrade_ConvertCurve3dToBezier::Compute()
{
mySegments->Clear();
mySplitParams->Clear();
Standard_Real precision = Precision::PConfusion();
Standard_Real First = mySplitValues->Value(1);
Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
if(myCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
Handle(Geom_TrimmedCurve) tmp = Handle(Geom_TrimmedCurve)::DownCast (myCurve);
Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
ShapeUpgrade_ConvertCurve3dToBezier converter;
converter.Init(BasCurve,First,Last);
converter.SetSplitValues(mySplitValues);
converter.Compute();
mySplitValues->ChangeSequence() = converter.SplitValues()->Sequence();
myNbCurves = mySplitValues->Length()-1;
myStatus |= converter.myStatus;
mySegments->ChangeSequence() = converter.Segments()->Sequence();
mySplitParams->ChangeSequence() = converter.SplitParams()->Sequence();
return;
}
else if(myCurve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
Handle(Geom_BezierCurve) bezier = Handle(Geom_BezierCurve)::DownCast (myCurve);
myNbCurves = mySplitValues->Length()-1;
mySplitParams->Append(First);
mySplitParams->Append(Last);
if(First < precision && Last > 1 - precision) {
mySegments->Append(bezier);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
} else {
Handle(Geom_BezierCurve) besNew = Handle(Geom_BezierCurve)::DownCast(bezier->Copy());
besNew->Segment(First,Last);
mySegments->Append(besNew);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
}
return;
}
else if(myCurve->IsKind(STANDARD_TYPE(Geom_Line))) {
Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(myCurve);
myNbCurves = mySplitValues->Length()-1;
mySplitParams->Append(First);
mySplitParams->Append(Last);
if(!myLineMode) {
mySegments->Append(aLine);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
return;
}
TColgp_Array1OfPnt poles(1,2);
poles(1) = aLine->Value(First);
poles(2) = aLine->Value(Last);
Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(poles);
mySegments->Append(bezier);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
return;
}
else if((myCurve->IsKind(STANDARD_TYPE(Geom_Conic))&&!myConicMode)||
(myCurve->IsKind(STANDARD_TYPE(Geom_Circle))&&!myCircleMode)) {
myNbCurves = mySplitValues->Length()-1;
mySplitParams->Append(First);
mySplitParams->Append(Last);
mySegments->Append(myCurve);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
return;
}
else {
Handle(Geom_BSplineCurve) aBSpline;
Standard_Real Shift = 0.;
if(myCurve->IsKind(STANDARD_TYPE(Geom_Conic))) {
Handle(Geom_TrimmedCurve) tcurve = new Geom_TrimmedCurve(myCurve,First,Last); //protection agains parabols ets
GeomConvert_ApproxCurve approx (tcurve, Precision::Approximation(),
GeomAbs_C1, 100, 6 );
if ( approx.HasResult() )
aBSpline = Handle(Geom_BSplineCurve)::DownCast(approx.Curve());
else {
Handle(Geom_TrimmedCurve) t3d = new Geom_TrimmedCurve(myCurve,First,Last);
aBSpline = GeomConvert::CurveToBSplineCurve(t3d,Convert_QuasiAngular);
}
Shift = First - aBSpline->FirstParameter();
First = aBSpline->FirstParameter();
Last = aBSpline->LastParameter();
}
else if(!myCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
aBSpline = GeomConvert::CurveToBSplineCurve(myCurve,Convert_QuasiAngular);
}
else
aBSpline = Handle(Geom_BSplineCurve)::DownCast(myCurve);
Standard_Real bf = aBSpline->FirstParameter();
Standard_Real bl = aBSpline->LastParameter();
if(Abs(First-bf) < precision)
First = bf;
if(Abs(Last-bl) < precision)
Last = bl;
if(First < bf){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
First = bf;
mySplitValues->SetValue(1,First);
}
if(Last > bl){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
Last = bl;
mySplitValues->SetValue(mySplitValues->Length(),Last);
}
GeomConvert_BSplineCurveToBezierCurve tool(aBSpline,First,Last,precision);
Standard_Integer nbArcs = tool.NbArcs();
TColStd_Array1OfReal knots(1,nbArcs+1);
tool.Knots(knots);
mySplitParams->Append(First+Shift);
Standard_Integer j; // svv Jan 10 2000 : porting on DEC
for(j = 1; j <=nbArcs; j++) {
Standard_Real nextKnot = knots(j+1)+Shift;
if(nextKnot - mySplitParams->Value(mySplitParams->Length()) > precision) {
mySegments->Append(tool.Arc(j));
mySplitParams->Append(knots(j+1)+Shift);
}
}
First = mySplitValues->Value(1);
for(j = 2; j <= mySplitValues->Length(); j++) {
Last = mySplitValues->Value(j);
for(Standard_Integer i = 2; i <= nbArcs+1; i++) {
Standard_Real valknot = knots(i)+Shift;
if(valknot <= First + precision) continue;
if(valknot >= Last - precision) break;
mySplitValues->InsertBefore(j++,valknot);
}
First = Last;
}
myNbCurves = mySplitValues->Length()-1;
}
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_ConvertCurve3dToBezier::Build(const Standard_Boolean /*Segment*/)
{
Standard_Real prec = Precision::PConfusion();
Standard_Integer nb = mySplitValues->Length();
myResultingCurves = new TColGeom_HArray1OfCurve (1,nb-1);
Standard_Real prevPar = 0.;
Standard_Integer j=2;
for(Standard_Integer i = 2; i <= nb; i++) {
Standard_Real par = mySplitValues->Value(i);
for(; j<= mySplitParams->Length(); j++)
if(mySplitParams->Value(j)+prec > par)
break;
else
prevPar = 0.;
Handle(Geom_Curve) crv = Handle(Geom_Curve)::DownCast(mySegments->Value(j-1)->Copy());
if(crv->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
Handle(Geom_BezierCurve) bes = Handle(Geom_BezierCurve)::DownCast(crv);
Standard_Real uFact = mySplitParams->Value(j) - mySplitParams->Value(j-1);
Standard_Real pp = mySplitValues->Value(i-1);
Standard_Real length = (par - pp)/uFact;
bes->Segment(prevPar, prevPar+length);
prevPar += length;
myResultingCurves->SetValue(i-1,bes);
}
else
myResultingCurves->SetValue(i-1,crv);
}
}
//=======================================================================
//function : Segments
//purpose :
//=======================================================================
Handle(TColGeom_HSequenceOfCurve) ShapeUpgrade_ConvertCurve3dToBezier::Segments() const
{
return mySegments;
}
//=======================================================================
//function : SplitParams
//purpose :
//=======================================================================
Handle(TColStd_HSequenceOfReal) ShapeUpgrade_ConvertCurve3dToBezier::SplitParams() const
{
return mySplitParams;
}

View File

@@ -0,0 +1,64 @@
// File: ShapeUpgrade_ConvertCurve3dToBezier.lxx
// Created: Tue Jun 22 17:02:49 1999
// Author: data exchange team
// <det@friendox>
//=======================================================================
//function : SetLineMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ConvertCurve3dToBezier::SetLineMode(const Standard_Boolean mode)
{
myLineMode = mode;
}
//=======================================================================
//function : GetLineMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ConvertCurve3dToBezier::GetLineMode() const
{
return myLineMode;
}
//=======================================================================
//function : SetCircleMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ConvertCurve3dToBezier::SetCircleMode(const Standard_Boolean mode)
{
myCircleMode = mode;
}
//=======================================================================
//function : GetCircleMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ConvertCurve3dToBezier::GetCircleMode() const
{
return myCircleMode;
}
//=======================================================================
//function : SetConicMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ConvertCurve3dToBezier::SetConicMode(const Standard_Boolean mode)
{
myConicMode = mode;
}
//=======================================================================
//function : GetConicMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ConvertCurve3dToBezier::GetConicMode() const
{
return myConicMode;
}

View File

@@ -0,0 +1,79 @@
-- File: ShapeUpgrade_ConvertSurfaceToE3.cdl
-- Created: Fri May 21 14:20:03 1999
-- Author: Pavel DURANDIN
-- <pdn@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class ConvertSurfaceToBezierBasis from ShapeUpgrade inherits SplitSurface from ShapeUpgrade
---Purpose: Converts a plane, bspline surface, surface of revolution, surface
-- of extrusion, offset surface to grid of bezier basis surface (
-- bezier surface,
-- surface of revolution based on bezier curve,
-- offset surface based on any previous type).
uses
CompositeSurface from ShapeExtend
is
Create returns mutable ConvertSurfaceToBezierBasis from ShapeUpgrade;
---Purpose: Empty constructor.
Build (me: mutable; Segment: Boolean) is redefined;
---Purpose: Splits a list of beziers computed by Compute method according
-- the split values and splitting parameters.
Compute(me: mutable; Segment: Boolean) is redefined;
---Purpose: Converts surface into a grid of bezier based surfaces, and
-- stores this grid.
Segments(me) returns CompositeSurface from ShapeExtend;
---Purpose: Returns the grid of bezier based surfaces correspondent to
-- original surface.
--Methods for handling surface modes
SetPlaneMode(me: mutable; mode: Boolean);
---Purpose: Sets mode for conversion Geom_Plane to Bezier
---C++: inline
GetPlaneMode(me) returns Boolean;
---Purpose: Returns the Geom_Pline conversion mode.
---C++: inline
SetRevolutionMode(me: mutable; mode: Boolean);
---Purpose: Sets mode for conversion Geom_SurfaceOfRevolution to Bezier
---C++: inline
GetRevolutionMode(me) returns Boolean;
---Purpose: Returns the Geom_SurfaceOfRevolution conversion mode.
---C++: inline
SetExtrusionMode(me: mutable; mode: Boolean);
---Purpose: Sets mode for conversion Geom_SurfaceOfLinearExtrusion to Bezier
---C++: inline
GetExtrusionMode(me) returns Boolean;
---Purpose: Returns the Geom_SurfaceOfLinearExtrusion conversion mode.
---C++: inline
SetBSplineMode(me: mutable; mode: Boolean);
---Purpose: Sets mode for conversion Geom_BSplineSurface to Bezier
---C++: inline
GetBSplineMode(me) returns Boolean;
---Purpose: Returns the Geom_BSplineSurface conversion mode.
---C++: inline
fields
mySegments : CompositeSurface from ShapeExtend;
myPlaneMode : Boolean;
myRevolutionMode: Boolean;
myExtrusionMode : Boolean;
myBSplineMode : Boolean;
end ConvertSurfaceToBezierBasis;

View File

@@ -0,0 +1,559 @@
// File: ShapeUpgrade_ConvertSurfaceToE3.cxx
// Created: Fri May 21 15:08:31 1999
// Author: Pavel DURANDIN
// <pdn@friendox.nnov.matra-dtv.fr>
// svv 10.01.00 porting on DEC
#include <ShapeUpgrade_ConvertSurfaceToBezierBasis.ixx>
#include <TColStd_HSequenceOfReal.hxx>
#include <Precision.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <Geom_Plane.hxx>
#include <TColgp_Array2OfPnt.hxx>
#include <Geom_BezierSurface.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColGeom_HArray2OfSurface.hxx>
#include <ShapeExtend.hxx>
#include <Geom_BSplineSurface.hxx>
#include <GeomConvert_BSplineSurfaceToBezierSurface.hxx>
#include <TColGeom_Array2OfBezierSurface.hxx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <Geom_Curve.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <Geom_OffsetCurve.hxx>
#include <ShapeUpgrade_ConvertCurve3dToBezier.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <Geom_BezierCurve.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_Array1OfBoolean.hxx>
ShapeUpgrade_ConvertSurfaceToBezierBasis::ShapeUpgrade_ConvertSurfaceToBezierBasis()
{
myPlaneMode = Standard_True;
myRevolutionMode = Standard_True;
myExtrusionMode = Standard_True;
myBSplineMode = Standard_True;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void ShapeUpgrade_ConvertSurfaceToBezierBasis::Compute(const Standard_Boolean Segment)
{
if(!Segment) {
Standard_Real UF,UL,VF,VL;
mySurface->Bounds(UF,UL,VF,VL);
if(!Precision::IsInfinite(UF)) myUSplitValues->SetValue(1,UF);
if(!Precision::IsInfinite(UL)) myUSplitValues->SetValue(myUSplitValues->Length(),UL);
if(!Precision::IsInfinite(VF)) myVSplitValues->SetValue(1,VF);
if(!Precision::IsInfinite(VL)) myVSplitValues->SetValue(myVSplitValues->Length(),VL);
}
Standard_Real UFirst = myUSplitValues->Value(1);
Standard_Real ULast = myUSplitValues->Value(myUSplitValues->Length());
Standard_Real VFirst = myVSplitValues->Value(1);
Standard_Real VLast = myVSplitValues->Value(myVSplitValues->Length());
Standard_Real precision = Precision::PConfusion();
if (mySurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
Handle(Geom_RectangularTrimmedSurface) Surface = Handle(Geom_RectangularTrimmedSurface)::DownCast(mySurface);
Handle(Geom_Surface) BasSurf = Surface->BasisSurface();
ShapeUpgrade_ConvertSurfaceToBezierBasis converter;
converter.Init(BasSurf,UFirst,ULast,VFirst,VLast);
converter.SetUSplitValues(myUSplitValues);
converter.SetVSplitValues(myVSplitValues);
converter.Compute(Standard_True);
myUSplitValues->ChangeSequence() = converter.USplitValues()->Sequence();
myVSplitValues->ChangeSequence() = converter.VSplitValues()->Sequence();
myStatus |= converter.myStatus;
mySegments = converter.Segments();
return;
} else if(mySurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
Handle(Geom_OffsetSurface) Offset = Handle(Geom_OffsetSurface)::DownCast(mySurface);
Handle(Geom_Surface) BasSurf = Offset->BasisSurface();
ShapeUpgrade_ConvertSurfaceToBezierBasis converter;
converter.Init(BasSurf,UFirst,ULast,VFirst,VLast);
converter.SetUSplitValues(myUSplitValues);
converter.SetVSplitValues(myVSplitValues);
converter.Compute(Standard_True);
myUSplitValues->ChangeSequence() = converter.USplitValues()->Sequence();
myVSplitValues->ChangeSequence() = converter.VSplitValues()->Sequence();
myStatus |= converter.myStatus;
mySegments = converter.Segments();
return;
} else if(mySurface->IsKind(STANDARD_TYPE(Geom_Plane))&&myPlaneMode) {
Handle(Geom_Plane) pln = Handle(Geom_Plane)::DownCast(mySurface);
TColgp_Array2OfPnt poles(1,2,1,2);
gp_Pnt dp;
poles(1,1) = dp = pln->Value(UFirst,VFirst); poles(1,2) = dp = pln->Value(UFirst,VLast);
poles(2,1) = dp = pln->Value(ULast,VFirst); poles(2,2) = dp = pln->Value(ULast,VLast);
Handle(Geom_BezierSurface) bezier = new Geom_BezierSurface(poles);
TColStd_Array1OfReal UJoints(1,2);
UJoints(1) = UFirst; UJoints(2) = ULast;
TColStd_Array1OfReal VJoints(1,2);
VJoints(1) = VFirst; VJoints(2) = VLast;
Handle(TColGeom_HArray2OfSurface) surf = new TColGeom_HArray2OfSurface(1,1,1,1);
surf->SetValue(1,1,bezier);
mySegments = new ShapeExtend_CompositeSurface(surf,UJoints,VJoints);
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
return;
} else if(mySurface->IsKind(STANDARD_TYPE(Geom_BezierSurface))) {
Handle(Geom_BezierSurface) bezier = Handle(Geom_BezierSurface)::DownCast(mySurface);
Handle(TColGeom_HArray2OfSurface) surf = new TColGeom_HArray2OfSurface(1,1,1,1);
TColStd_Array1OfReal UJoints(1,2);
UJoints(1) = UFirst; UJoints(2) = ULast;
TColStd_Array1OfReal VJoints(1,2);
VJoints(1) = VFirst; VJoints(2) = VLast;
if(UFirst < precision && ULast > 1 - precision &&
VFirst < precision && VLast > 1 - precision) {
surf->SetValue(1,1,bezier);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
} else {
Handle(Geom_BezierSurface) besNew = Handle(Geom_BezierSurface)::DownCast(bezier->Copy());
//pdn K4L+ (work around)
// Standard_Real u1 = 2*UFirst - 1;
// Standard_Real u2 = 2*ULast - 1;
// Standard_Real v1 = 2*VFirst - 1;
// Standard_Real v2 = 2*VLast - 1;
//rln C30 (direct use)
Standard_Real u1 = UFirst;
Standard_Real u2 = ULast;
Standard_Real v1 = VFirst;
Standard_Real v2 = VLast;
besNew->Segment(u1,u2,v1,v2);
surf->SetValue(1,1,besNew);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
}
mySegments = new ShapeExtend_CompositeSurface(surf,UJoints,VJoints);
return;
} else if(mySurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface))&&myBSplineMode) {
Handle(Geom_BSplineSurface) bspline = Handle(Geom_BSplineSurface)::DownCast(mySurface);
//pdn
Standard_Real u1,u2,v1,v2;
bspline->Bounds(u1,u2,v1,v2);
GeomConvert_BSplineSurfaceToBezierSurface converter(bspline);//,UFirst,ULast,VFirst,VLast,precision;
Standard_Integer nbUPatches = converter.NbUPatches();
Standard_Integer nbVPatches = converter.NbVPatches();
TColStd_Array1OfReal UJoints(1, nbUPatches+1);
TColStd_Array1OfBoolean UReject(1, nbUPatches+1);
UReject.Init(Standard_False);
TColStd_Array1OfReal VJoints(1, nbVPatches+1);
TColStd_Array1OfBoolean VReject(1, nbVPatches+1);
VReject.Init(Standard_False);
Standard_Integer NbUFiltered = 0;
Standard_Integer NbVFiltered = 0;
converter.UKnots(UJoints);
TColStd_SequenceOfReal UFilteredJoints;
UFilteredJoints.Append(UJoints(1));
Standard_Integer i;
for(i = 2; i <= nbUPatches+1; i++)
if(UJoints(i)-UJoints(i-1) < precision) {
NbUFiltered++;
UReject(i-1) = Standard_True;
}
else
UFilteredJoints.Append(UJoints(i));
converter.VKnots(VJoints);
TColStd_SequenceOfReal VFilteredJoints;
VFilteredJoints.Append(VJoints(1));
for( i = 2; i <= nbVPatches+1; i++)
if(VJoints(i)-VJoints(i-1) < precision) {
NbVFiltered++;
VReject(i-1) = Standard_True;
}
else
VFilteredJoints.Append(VJoints(i));
#ifdef DEB
if(NbVFiltered || NbUFiltered)
cout<<"Warning: ShapeUpgrade_ConvertSurfaceToBezierBasis: thin patches dropped."<<endl;
#endif
TColGeom_Array2OfBezierSurface Surfaces(1, nbUPatches, 1, nbVPatches);
converter.Patches(Surfaces);
Handle(TColGeom_HArray2OfSurface) srf =
new TColGeom_HArray2OfSurface(1,nbUPatches-NbUFiltered,1,nbVPatches-NbVFiltered);
Standard_Integer indApp1 = 0;
for(Standard_Integer ind1 = 1; ind1 <= nbUPatches; ind1++) {
if(UReject(ind1)) continue;
indApp1++;
Standard_Integer indApp2 = 0;
for(Standard_Integer ind2 = 1; ind2 <= nbVPatches; ind2++) {
if(VReject(ind2)) continue;
indApp2++;
srf->SetValue(indApp1,indApp2,Surfaces(ind1,ind2));
}
}
TColStd_Array1OfReal uj (1,UFilteredJoints.Length());
for(i = 1; i <=UFilteredJoints.Length(); i++)
uj(i) = UFilteredJoints.Value(i);
TColStd_Array1OfReal vj (1,VFilteredJoints.Length());
for(i = 1; i <=VFilteredJoints.Length(); i++)
vj(i) = VFilteredJoints.Value(i);
mySegments = new ShapeExtend_CompositeSurface(srf,uj,vj);
Standard_Integer j; // svv #1
for(j = 2; j <= myUSplitValues->Length(); j++) {
ULast = myUSplitValues->Value(j);
for(Standard_Integer ii = 2; ii <= nbUPatches+1; ii++) {
Standard_Real valknot = UJoints(ii);
if(valknot-UFirst <= precision) continue;
if(ULast -valknot <= precision) break;
myUSplitValues->InsertBefore(j++,valknot);
}
UFirst = ULast;
}
for(j = 2; j <= myVSplitValues->Length(); j++) {
VLast = myVSplitValues->Value(j);
for(Standard_Integer ii = 2; ii <= nbVPatches+1; ii++) {
Standard_Real valknot = VJoints(ii);
if(valknot-VFirst <= precision) continue;
if(VLast -valknot <= precision) break;
myVSplitValues->InsertBefore(j++,valknot);
}
VFirst = VLast;
}
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
return;
} else if(mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))&&myRevolutionMode) {
Handle(Geom_SurfaceOfRevolution) revol = Handle(Geom_SurfaceOfRevolution)::DownCast(mySurface);
Handle(Geom_Curve) basis = revol->BasisCurve();
if(basis->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(basis);
basis = tc->BasisCurve();
}
Handle(TColGeom_HArray1OfCurve) curves;
Standard_Integer nbCurves;
Handle(TColStd_HSequenceOfReal) vPar = new TColStd_HSequenceOfReal;
Handle(TColStd_HSequenceOfReal) vSVal= new TColStd_HSequenceOfReal;
if(basis->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
Handle(Geom_OffsetCurve) offset = Handle(Geom_OffsetCurve)::DownCast(basis);
Standard_Real value = offset->Offset();
gp_Dir direction = offset->Direction();
Handle(Geom_Curve) bas = offset->BasisCurve();
ShapeUpgrade_ConvertCurve3dToBezier converter;
converter.Init(bas,VFirst,VLast);
converter.Perform(Standard_True);
if(converter.Status(ShapeExtend_DONE))
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
else
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
vPar->ChangeSequence() = converter.SplitParams()->Sequence();
vSVal->ChangeSequence()= converter.SplitValues()->Sequence();
curves = converter.GetCurves();
nbCurves = curves->Length();
for(Standard_Integer i = 1; i <= nbCurves; i++) {
Handle(Geom_OffsetCurve) offCur = new Geom_OffsetCurve(curves->Value(i),value,direction);
curves->SetValue(i,offCur);
}
} else {
ShapeUpgrade_ConvertCurve3dToBezier converter;
converter.Init(basis,VFirst,VLast);
converter.Perform(Standard_True);
if(converter.Status(ShapeExtend_DONE))
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
else
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
vPar->ChangeSequence() = converter.SplitParams()->Sequence();
vSVal->ChangeSequence()= converter.SplitValues()->Sequence();
curves = converter.GetCurves();
nbCurves = curves->Length();
}
gp_Ax1 axis = revol->Axis();
Handle(TColGeom_HArray2OfSurface) surf = new TColGeom_HArray2OfSurface(1,1,1,nbCurves);
Standard_Real Umin,Umax,Vmin,Vmax;
mySurface->Bounds(Umin,Umax,Vmin,Vmax);
Standard_Integer i; // svv #1
for(i = 1; i <= nbCurves; i++) {
Handle(Geom_SurfaceOfRevolution) rev = new Geom_SurfaceOfRevolution(curves->Value(i),axis);
if( UFirst-Umin < Precision::PConfusion() &&
Umax-ULast < Precision::PConfusion() )
surf->SetValue(1,i,rev);
else {
Handle(Geom_RectangularTrimmedSurface) rect = new Geom_RectangularTrimmedSurface(rev,UFirst,ULast,Standard_True);
surf->SetValue(1,i,rect);
}
}
TColStd_Array1OfReal UJoints(1, 2);
TColStd_Array1OfReal VJoints(1, nbCurves+1);
UJoints(1) = UFirst; UJoints(2) = ULast;
for(i = 1 ; i <= nbCurves+1; i++)
VJoints(i) = vPar->Value(i);
mySegments = new ShapeExtend_CompositeSurface(surf,UJoints,VJoints);
for(Standard_Integer j = 2; j <= myVSplitValues->Length(); j++) {
VLast = myVSplitValues->Value(j);
for(Standard_Integer ii = 2; ii <= nbCurves+1; ii++) {
Standard_Real valknot = vSVal->Value(ii);
if(valknot-VFirst <= precision) continue;
if(VLast -valknot <= precision) break;
myVSplitValues->InsertBefore(j++,valknot);
}
VFirst = VLast;
}
return;
} else if(mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))&&myExtrusionMode) {
Handle(Geom_SurfaceOfLinearExtrusion) extr = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(mySurface);
Handle(Geom_Curve) basis = extr->BasisCurve();
//gp_Dir direction = extr->Direction(); // direction not used (skl)
Handle(TColGeom_HArray1OfCurve) curves;
Standard_Integer nbCurves;
Handle(TColStd_HSequenceOfReal) uPar = new TColStd_HSequenceOfReal;
Handle(TColStd_HSequenceOfReal) uSVal= new TColStd_HSequenceOfReal;
ShapeUpgrade_ConvertCurve3dToBezier converter;
converter.Init(basis,UFirst,ULast);
converter.Perform(Standard_True);
uPar->ChangeSequence() = converter.SplitParams()->Sequence();
uSVal->ChangeSequence()= converter.SplitValues()->Sequence();
curves = converter.GetCurves();
nbCurves = curves->Length();
gp_Trsf shiftF,shiftL;
shiftF.SetTranslation(extr->Value(UFirst,0),extr->Value(UFirst,VFirst));
shiftL.SetTranslation(extr->Value(UFirst,0),extr->Value(UFirst,VLast));
Handle(TColGeom_HArray2OfSurface) surf = new TColGeom_HArray2OfSurface(1,nbCurves,1,1);
Standard_Integer i; // svv #1
for(i = 1; i <= nbCurves; i++) {
Handle(Geom_BezierCurve) bez = Handle(Geom_BezierCurve)::DownCast(curves->Value(i));
Standard_Integer nbPoles = bez->NbPoles();
TColgp_Array1OfPnt poles(1,nbPoles);
bez->Poles(poles);
TColgp_Array2OfPnt resPoles(1,nbPoles,1,2);
for(Standard_Integer j = 1; j <= nbPoles; j++) {
resPoles(j,1) = poles(j).Transformed(shiftF);
resPoles(j,2) = poles(j).Transformed(shiftL);
}
Handle(Geom_BezierSurface) bezier = new Geom_BezierSurface(resPoles);
surf->SetValue(i,1,bezier);
}
TColStd_Array1OfReal UJoints(1, nbCurves+1);
TColStd_Array1OfReal VJoints(1, 2);
VJoints(1) = VFirst; VJoints(2) = VLast;
for(i = 1 ; i <= nbCurves+1; i++)
UJoints(i) = uPar->Value(i);
mySegments = new ShapeExtend_CompositeSurface(surf,UJoints,VJoints);
for(Standard_Integer j = 2; j <= myUSplitValues->Length(); j++) {
ULast = myUSplitValues->Value(j);
for(Standard_Integer ii = 2; ii <= nbCurves+1; ii++) {
Standard_Real valknot = uSVal->Value(ii);
if(valknot+UFirst <= precision) continue;
if(ULast -valknot <= precision) break;
myUSplitValues->InsertBefore(j++,valknot);
}
UFirst = ULast;
}
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
return;
}
else {
TColStd_Array1OfReal UJoints(1,2);
UJoints(1) = UFirst; UJoints(2) = ULast;
TColStd_Array1OfReal VJoints(1,2);
VJoints(1) = VFirst; VJoints(2) = VLast;
Handle(TColGeom_HArray2OfSurface) surf = new TColGeom_HArray2OfSurface(1,1,1,1);
Standard_Real U1,U2,V1,V2;
mySurface->Bounds(U1,U2,V1,V2);
Handle(Geom_Surface) S;
if(U1-UFirst < precision && ULast - U2 < precision &&
V2-VFirst < precision && VLast - V2 < precision)
S = mySurface;
else {
Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(mySurface,UFirst,ULast,VFirst,VLast);
S = rts;
}
surf->SetValue(1,1,S);
mySegments = new ShapeExtend_CompositeSurface(surf,UJoints,VJoints);
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
return;
}
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
static Handle(Geom_Surface) GetSegment(const Handle(Geom_Surface) surf,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real V1,
const Standard_Real V2)
{
if(surf->IsKind(STANDARD_TYPE(Geom_BezierSurface))) {
Handle(Geom_BezierSurface) bezier = Handle(Geom_BezierSurface)::DownCast(surf->Copy());
Standard_Real prec = Precision::PConfusion();
if(U1 < prec && U2 > 1-prec && V1 < prec && V2 > 1-prec)
return bezier;
//pdn K4L+ (work around)
// Standard_Real u1 = 2*U1 - 1;
// Standard_Real u2 = 2*U2 - 1;
// Standard_Real v1 = 2*V1 - 1;
// Standard_Real v2 = 2*V2 - 1;
//rln C30 (direct use)
Standard_Real u1 = U1;
Standard_Real u2 = U2;
Standard_Real v1 = V1;
Standard_Real v2 = V2;
bezier->Segment(u1,u2,v1,v2);
return bezier;
}
Handle(Geom_Surface) S;
if(surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
Handle(Geom_RectangularTrimmedSurface) rect = Handle(Geom_RectangularTrimmedSurface)::DownCast(surf);
S = rect->BasisSurface();
} else
S = surf;
if(S->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
Handle(Geom_SurfaceOfRevolution) revol = Handle(Geom_SurfaceOfRevolution)::DownCast(S->Copy());
Standard_Real Umin,Umax,Vmin,Vmax;
revol->Bounds(Umin,Umax,Vmin,Vmax);
Handle(Geom_Curve) basis = revol->BasisCurve();
if(basis->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
Handle(Geom_OffsetCurve) offset = Handle(Geom_OffsetCurve)::DownCast(basis);
basis = offset->BasisCurve();
}
if(basis->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
Handle(Geom_BezierCurve) bezier = Handle(Geom_BezierCurve)::DownCast(basis);
bezier->Segment(V1,V2);
}
else {
#ifdef DEB
cout <<"Warning: Resulting path is not surface of revolution basis on bezier curve"<<endl;
#endif
}
if(Abs(U1-Umin) < Precision::PConfusion() &&
Abs(U2-Umax) < Precision::PConfusion() )
return revol;
Handle(Geom_RectangularTrimmedSurface) res = new Geom_RectangularTrimmedSurface(revol,U1,U2,Standard_True);
return res;
}
else {
Standard_Real Umin,Umax,Vmin,Vmax;
surf->Bounds(Umin,Umax,Vmin,Vmax);
if( U1-Umin < Precision::PConfusion() &&
Umax-U2 < Precision::PConfusion() &&
V1-Vmin < Precision::PConfusion() &&
Vmax-V2 < Precision::PConfusion() )
return surf;
Handle(Geom_RectangularTrimmedSurface) res = new Geom_RectangularTrimmedSurface(surf,U1,U2,V1,V2);
return res;
}
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_ConvertSurfaceToBezierBasis::Build(const Standard_Boolean /*Segment*/)
{
Standard_Boolean isOffset = Standard_False;
Standard_Real offsetValue=0;
Handle(Geom_Surface) S;
if (mySurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
Handle(Geom_RectangularTrimmedSurface) Surface = Handle(Geom_RectangularTrimmedSurface)::DownCast(mySurface);
S = Surface->BasisSurface();
}
else
S = mySurface;
if(S->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
Handle(Geom_OffsetSurface) offSur = Handle(Geom_OffsetSurface)::DownCast(S);
isOffset = Standard_True;
offsetValue = offSur->Offset();
}
Standard_Real prec = Precision::PConfusion();
Handle(TColStd_HArray1OfReal) myUSplitParams = mySegments->UJointValues();
Handle(TColStd_HArray1OfReal) myVSplitParams = mySegments->VJointValues();
Standard_Integer nbU = myUSplitValues->Length();
Standard_Integer nbV = myVSplitValues->Length();
Handle(TColGeom_HArray2OfSurface) resSurfaces = new TColGeom_HArray2OfSurface(1,nbU-1,1,nbV-1);
Standard_Integer j1 = 2;
for(Standard_Integer i1 = 2; i1 <= nbU; i1++) {
Standard_Real parU = myUSplitValues->Value(i1);
for(; j1<= myUSplitParams->Length(); j1++) {
Standard_Real param = myUSplitParams->Value(j1);
if(parU - param < prec)
break;
}
Standard_Integer j2 = 2;
for(Standard_Integer i2 = 2; i2 <= nbV; i2++) {
Standard_Real parV = myVSplitValues->Value(i2);
for(; j2<= myVSplitParams->Length(); j2++)
if(parV - myVSplitParams->Value(j2) < prec)
break;
Handle(Geom_Surface) patch = mySegments->Patch(j1-1,j2-1);
Standard_Real U1, U2, V1, V2;
patch->Bounds(U1,U2,V1,V2);
//linear recomputation of part:
Standard_Real uFirst = myUSplitParams->Value(j1-1);
Standard_Real uLast = myUSplitParams->Value(j1);
Standard_Real vFirst = myVSplitParams->Value(j2-1);
Standard_Real vLast = myVSplitParams->Value(j2);
Standard_Real uFact = (U2-U1)/(uLast - uFirst);
Standard_Real vFact = (V2-V1)/(vLast - vFirst);
Standard_Real ppU = myUSplitValues->Value(i1-1);
Standard_Real ppV = myVSplitValues->Value(i2-1);
//defining a part
Standard_Real uL1 = U1+(ppU - uFirst)*uFact;
Standard_Real uL2 = U1+(parU- uFirst)*uFact;
Standard_Real vL1 = V1+(ppV - vFirst)*vFact;
Standard_Real vL2 = V1+(parV- vFirst)*vFact;
Handle(Geom_Surface) res = GetSegment(patch,uL1, uL2, vL1, vL2);
if(isOffset) {
Handle(Geom_OffsetSurface) resOff = new Geom_OffsetSurface(res,offsetValue);
res = resOff;
}
resSurfaces->SetValue(i1-1,i2-1,res);
}
}
TColStd_Array1OfReal UJoints(1,nbU);
Standard_Integer i; // svv #1
for(i = 1; i <= nbU; i++)
UJoints(i) = myUSplitValues->Value(i);
TColStd_Array1OfReal VJoints(1,nbV);
for(i = 1; i <= nbV; i++)
VJoints(i) = myVSplitValues->Value(i);
myResSurfaces = new ShapeExtend_CompositeSurface(resSurfaces,UJoints,VJoints);
}
//=======================================================================
//function : Segments
//purpose :
//=======================================================================
Handle(ShapeExtend_CompositeSurface) ShapeUpgrade_ConvertSurfaceToBezierBasis::Segments() const
{
return mySegments;
}

View File

@@ -0,0 +1,84 @@
// File: ShapeUpgrade_ConvertSurfaceToBezierBasis.lxx
// Created: Tue Oct 5 16:44:16 1999
// Author: data exchange team
// <det@hotdox.nnov.matra-dtv.fr>
//=======================================================================
//function : SetPlaneMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ConvertSurfaceToBezierBasis::SetPlaneMode(const Standard_Boolean mode)
{
myPlaneMode = mode;
}
//=======================================================================
//function : GetPlaneMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ConvertSurfaceToBezierBasis::GetPlaneMode() const
{
return myPlaneMode;
}
//=======================================================================
//function : SetRevolutionMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ConvertSurfaceToBezierBasis::SetRevolutionMode(const Standard_Boolean mode)
{
myRevolutionMode = mode;
}
//=======================================================================
//function : GetRevolutionMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ConvertSurfaceToBezierBasis::GetRevolutionMode() const
{
return myRevolutionMode;
}
//=======================================================================
//function : SetExtrusionMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ConvertSurfaceToBezierBasis::SetExtrusionMode(const Standard_Boolean mode)
{
myExtrusionMode = mode;
}
//=======================================================================
//function : GetExtrusionMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ConvertSurfaceToBezierBasis::GetExtrusionMode() const
{
return myExtrusionMode;
}
//=======================================================================
//function : SetBSplineMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ConvertSurfaceToBezierBasis::SetBSplineMode(const Standard_Boolean mode)
{
myBSplineMode = mode;
}
//=======================================================================
//function : GetBSplineMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ConvertSurfaceToBezierBasis::GetBSplineMode() const
{
return myBSplineMode;
}

View File

@@ -0,0 +1,72 @@
-- File: ShapeUpgrade_EdgeDivide.cdl
-- Created: Wed May 24 17:06:59 2000
-- Author: data exchange team
-- <det@friendox>
---Copyright: Matra Datavision 2000
class EdgeDivide from ShapeUpgrade inherits Tool from ShapeUpgrade
---Purpose:
uses
Edge from TopoDS,
Face from TopoDS,
HSequenceOfReal from TColStd,
SplitCurve3d from ShapeUpgrade,
SplitCurve2d from ShapeUpgrade
is
Create returns mutable EdgeDivide from ShapeUpgrade;
---Purpose: Empty constructor
Clear (me: mutable);
SetFace(me: mutable; F: Face from TopoDS);
---C++: inline
---Purpose: Sets supporting surface by face
Compute(me: mutable; E: Edge from TopoDS)
returns Boolean is virtual;
HasCurve2d(me) returns Boolean;
---C++: inline
HasCurve3d(me) returns Boolean;
---C++: inline
Knots2d(me) returns HSequenceOfReal from TColStd;
---C++: inline
Knots3d(me) returns HSequenceOfReal from TColStd;
---C++: inline
SetSplitCurve2dTool(me: mutable; splitCurve2dTool: SplitCurve2d from ShapeUpgrade);
---Purpose: Sets the tool for splitting pcurves.
SetSplitCurve3dTool(me: mutable; splitCurve3dTool: SplitCurve3d from ShapeUpgrade);
---Purpose: Sets the tool for splitting 3D curves.
GetSplitCurve2dTool(me) returns SplitCurve2d from ShapeUpgrade
is virtual;
---Purpose: Returns the tool for splitting pcurves.
GetSplitCurve3dTool(me) returns SplitCurve3d from ShapeUpgrade
is virtual;
---Purpose: Returns the tool for splitting 3D curves.
---Remark: here TopoDS_Edge can be used to transfer some specific information (tolerance, etc)
fields
myFace : Face from TopoDS is protected;
myHasCurve2d: Boolean is protected;
myHasCurve3d: Boolean is protected;
myKnots2d : HSequenceOfReal from TColStd is protected;
myKnots3d : HSequenceOfReal from TColStd is protected;
mySplitCurve3dTool: SplitCurve3d from ShapeUpgrade;
mySplitCurve2dTool: SplitCurve2d from ShapeUpgrade;
end EdgeDivide;

View File

@@ -0,0 +1,114 @@
// File: ShapeUpgrade_EdgeDivide.cxx
// Created: Wed May 24 17:13:15 2000
// Author: data exchange team
// <det@friendox>
#include <ShapeUpgrade_EdgeDivide.ixx>
#include <BRep_Tool.hxx>
#include <ShapeAnalysis_Edge.hxx>
//=======================================================================
//function : ShapeUpgrade_EdgeDivide
//purpose :
//=======================================================================
ShapeUpgrade_EdgeDivide::ShapeUpgrade_EdgeDivide():
ShapeUpgrade_Tool()
{
mySplitCurve3dTool = new ShapeUpgrade_SplitCurve3d;
mySplitCurve2dTool = new ShapeUpgrade_SplitCurve2d;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void ShapeUpgrade_EdgeDivide::Clear()
{
myKnots3d.Nullify();
myKnots2d.Nullify();
myHasCurve3d = Standard_False;
myHasCurve2d = Standard_False;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_EdgeDivide::Compute(const TopoDS_Edge& anEdge)
{
Clear();
Standard_Real f, l;
Handle(Geom_Curve) curve3d = BRep_Tool::Curve (anEdge, f, l);
myHasCurve3d = !curve3d.IsNull();
Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
if ( myHasCurve3d ) {
theSplit3dTool->Init (curve3d, f, l);
theSplit3dTool->Compute();
myKnots3d = theSplit3dTool->SplitValues();
}
// on pcurve(s): all knots
// assume that if seam-edge, its pcurve1 and pcurve2 has the same split knots !!!
Standard_Real f2d, l2d;
Handle(Geom2d_Curve) pcurve1;
if ( ! myFace.IsNull() ) { // process free edges
ShapeAnalysis_Edge sae;
sae.PCurve (anEdge, myFace, pcurve1, f2d, l2d, Standard_False);
}
myHasCurve2d = !pcurve1.IsNull();
Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
if ( myHasCurve2d ) {
theSplit2dTool->Init (pcurve1, f2d, l2d);
theSplit2dTool->Compute();
myKnots2d = theSplit2dTool->SplitValues();
}
if ( theSplit3dTool->Status ( ShapeExtend_DONE ) ||
theSplit2dTool->Status ( ShapeExtend_DONE ) )
return Standard_True;
else
return Standard_False;
}
//=======================================================================
//function : SetSplitCurve2dTool
//purpose :
//=======================================================================
void ShapeUpgrade_EdgeDivide::SetSplitCurve2dTool(const Handle(ShapeUpgrade_SplitCurve2d)& splitCurve2dTool)
{
mySplitCurve2dTool = splitCurve2dTool;
}
//=======================================================================
//function : SetSplitCurve3dTool
//purpose :
//=======================================================================
void ShapeUpgrade_EdgeDivide::SetSplitCurve3dTool(const Handle(ShapeUpgrade_SplitCurve3d)& splitCurve3dTool)
{
mySplitCurve3dTool = splitCurve3dTool;
}
//=======================================================================
//function : GetSplitCurve2dTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_SplitCurve2d) ShapeUpgrade_EdgeDivide::GetSplitCurve2dTool() const
{
return mySplitCurve2dTool;
}
Handle(ShapeUpgrade_SplitCurve3d) ShapeUpgrade_EdgeDivide::GetSplitCurve3dTool() const
{
return mySplitCurve3dTool;
}

View File

@@ -0,0 +1,54 @@
// File: ShapeUpgrade_EdgeDivide.lxx
// Created: Wed May 24 17:35:49 2000
// Author: data exchange team
// <det@friendox>
//=======================================================================
//function : SetFace
//purpose :
//=======================================================================
inline void ShapeUpgrade_EdgeDivide::SetFace(const TopoDS_Face& F)
{
myFace = F;
}
//=======================================================================
//function : HasCurve2d
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_EdgeDivide::HasCurve2d() const
{
return myHasCurve2d;
}
//=======================================================================
//function : HasCurve3d
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_EdgeDivide::HasCurve3d() const
{
return myHasCurve3d;
}
//=======================================================================
//function : Knots2d
//purpose :
//=======================================================================
inline Handle(TColStd_HSequenceOfReal) ShapeUpgrade_EdgeDivide::Knots2d() const
{
return myKnots2d;
}
//=======================================================================
//function : Knots3d
//purpose :
//=======================================================================
inline Handle(TColStd_HSequenceOfReal) ShapeUpgrade_EdgeDivide::Knots3d() const
{
return myKnots3d;
}

View File

@@ -0,0 +1,105 @@
-- File: ShapeUpgrade_FaceDivide.cdl
-- Created: Wed Feb 18 15:43:07 1998
-- Author: Pierre BARRAS
-- <pbs@sgi84>
---Copyright: Matra Datavision 1998
class FaceDivide from ShapeUpgrade
inherits Tool from ShapeUpgrade
---Purpose: Divides a Face (both edges in the wires, by splitting
-- curves and pcurves, and the face itself, by splitting
-- supporting surface) according to splitting criteria.
-- * The domain of the face to divide is defined by the PCurves
-- of the wires on the Face.
--
-- * all the PCurves are supposed to be defined (in the parametric
-- space of the supporting surface).
--
-- The result is available after the call to the Build method.
-- It is a Shell containing all the resulting Faces.
--
-- All the modifications made during splitting are recorded in the
-- external context (ShapeBuild_ReShape).
uses
Face from TopoDS,
Shape from TopoDS,
Status from ShapeExtend,
SplitSurface from ShapeUpgrade,
WireDivide from ShapeUpgrade
is
Create returns FaceDivide from ShapeUpgrade;
---Purpose: Creates empty constructor.
Create (F : Face from TopoDS)
returns FaceDivide from ShapeUpgrade;
--- Purpose : Initialize by a Face.
Init (me: mutable; F : Face from TopoDS);
---Purpose: Initialize by a Face.
SetSurfaceSegmentMode(me: mutable; Segment: Boolean);
---Purpose: Purpose sets mode for trimming (segment) surface by
-- wire UV bounds.
Perform (me: mutable)
returns Boolean is virtual;
---Purpose: Performs splitting and computes the resulting shell
-- The context is used to keep track of former splittings
-- in order to keep sharings. It is updated according to
-- modifications made.
SplitSurface (me: mutable)
returns Boolean is virtual;
---Purpose: Performs splitting of surface and computes the shell
-- from source face.
SplitCurves (me: mutable)
returns Boolean is virtual;
---Purpose: Performs splitting of curves of all the edges in the
-- shape and divides these edges.
Result (me) returns Shape from TopoDS;
---Purpose: Gives the resulting Shell, or Face, or Null shape if not done.
Status (me; status: Status from ShapeExtend) returns Boolean;
---Purpose: Queries the status of last call to Perform
-- OK : no splitting was done (or no call to Perform)
-- DONE1: some edges were splitted
-- DONE2: surface was splitted
-- DONE3: surface was modified without splitting
-- FAIL1: some fails encountered during splitting wires
-- FAIL2: face cannot be splitted
---Level: Internal
SetSplitSurfaceTool (me: mutable; splitSurfaceTool: SplitSurface from ShapeUpgrade);
---Purpose: Sets the tool for splitting surfaces.
SetWireDivideTool (me: mutable; wireDivideTool: WireDivide from ShapeUpgrade);
---Purpose: Sets the tool for dividing edges on Face.
GetSplitSurfaceTool (me) returns SplitSurface from ShapeUpgrade
is virtual protected;
---Purpose: Returns the tool for splitting surfaces.
-- This tool must be already initialized.
GetWireDivideTool (me) returns WireDivide from ShapeUpgrade
is virtual;
---Purpose: Returns the tool for dividing edges on Face.
-- This tool must be already initialized.
fields
mySplitSurfaceTool: SplitSurface from ShapeUpgrade;
myWireDivideTool : WireDivide from ShapeUpgrade;
myFace : Face from TopoDS is protected;
myResult : Shape from TopoDS is protected;
mySegmentMode: Boolean is protected;
myStatus : Integer is protected;
end;

View File

@@ -0,0 +1,256 @@
// File: ShapeUpgrade_FaceDivide.cxx
// Created: Mon Apr 26 17:29:46 1999
// Author: Andrey BETENEV
// <abv@doomox.nnov.matra-dtv.fr>
// gka 01.06.99 S4205: changing order of splitting surface/curves for converting to bezier
#include <ShapeUpgrade_FaceDivide.ixx>
#include <Precision.hxx>
#include <ShapeExtend.hxx>
#include <ShapeBuild_Edge.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Iterator.hxx>
#include <ShapeFix_ComposeShell.hxx>
#include <BRepTools.hxx>
#include <ShapeExtend_CompositeSurface.hxx>
#include <TopExp_Explorer.hxx>
#include <Bnd_Box2d.hxx>
#include <ShapeAnalysis.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <ShapeBuild_ReShape.hxx>
//=======================================================================
//function : ShapeUpgrade_FaceDivide
//purpose :
//=======================================================================
ShapeUpgrade_FaceDivide::ShapeUpgrade_FaceDivide():
ShapeUpgrade_Tool(), myStatus(0)
{
mySegmentMode = Standard_True;
mySplitSurfaceTool = new ShapeUpgrade_SplitSurface;
myWireDivideTool = new ShapeUpgrade_WireDivide;
}
//=======================================================================
//function : ShapeUpgrade_FaceDivide
//purpose :
//=======================================================================
ShapeUpgrade_FaceDivide::ShapeUpgrade_FaceDivide (const TopoDS_Face &F):
ShapeUpgrade_Tool(), myStatus(0)
{
mySegmentMode = Standard_True;
mySplitSurfaceTool = new ShapeUpgrade_SplitSurface;
myWireDivideTool = new ShapeUpgrade_WireDivide;
Init ( F );
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_FaceDivide::Init (const TopoDS_Face &F)
{
myResult = myFace = F;
}
//=======================================================================
//function : SetSurfaceSegmentMode
//purpose :
//=======================================================================
void ShapeUpgrade_FaceDivide::SetSurfaceSegmentMode(const Standard_Boolean Segment)
{
mySegmentMode = Segment;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_FaceDivide::Perform ()
{
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
if ( myFace.IsNull() ) return Standard_False;
myResult = myFace;
SplitSurface();
SplitCurves();
return Status ( ShapeExtend_DONE );
}
//=======================================================================
//function : SplitSurface
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_FaceDivide::SplitSurface ()
{
Handle(ShapeUpgrade_SplitSurface) SplitSurf = GetSplitSurfaceTool();
if ( SplitSurf.IsNull() ) return Standard_False;
// myResult should be face; else return with FAIL
if ( myResult.IsNull() || myResult.ShapeType() != TopAbs_FACE ) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
return Standard_False;
}
TopoDS_Face face = TopoDS::Face ( myResult );
TopLoc_Location L;
Handle(Geom_Surface) surf;
surf = BRep_Tool::Surface ( face, L );
Standard_Real Uf,Ul,Vf,Vl;
// BRepTools::UVBounds(myFace,Uf,Ul,Vf,Vl);
ShapeAnalysis::GetFaceUVBounds ( face, Uf, Ul, Vf, Vl );
if(Precision::IsInfinite(Uf) || Precision::IsInfinite(Ul) ||
Precision::IsInfinite(Vf) || Precision::IsInfinite(Vl))
return Standard_False;
SplitSurf->Init ( surf, Uf, Ul, Vf, Vl );
SplitSurf->Perform(mySegmentMode);
// If surface was neither splitted nor modified, do nothing
if ( ! SplitSurf->Status ( ShapeExtend_DONE ) ) return Standard_False;
// if surface was modified, force copying all vertices (and edges as consequence)
// to protect original shape from increasing tolerance after SameParameter
if ( SplitSurf->Status ( ShapeExtend_DONE3 ) )
for (TopExp_Explorer exp(face,TopAbs_VERTEX); exp.More(); exp.Next() ) {
if ( Context()->IsRecorded ( exp.Current() ) ) continue;
//smh#8
TopoDS_Shape emptyCopied = exp.Current().EmptyCopied();
TopoDS_Vertex V = TopoDS::Vertex ( emptyCopied );
Context()->Replace ( exp.Current(), V );
}
Handle(ShapeExtend_CompositeSurface) Grid = SplitSurf->ResSurfaces();
ShapeFix_ComposeShell CompShell;
CompShell.Init( Grid, L, face, Precision() );
CompShell.SetContext(Context());
CompShell.SetMaxTolerance(MaxTolerance());
Handle(ShapeUpgrade_WireDivide) SplitWire = GetWireDivideTool();
if ( ! SplitWire.IsNull() )
CompShell.SetTransferParamTool(GetWireDivideTool()->GetTransferParamTool());
CompShell.Perform();
if ( CompShell.Status ( ShapeExtend_FAIL ) ||
! CompShell.Status ( ShapeExtend_DONE ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
myResult = CompShell.Result();
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
return Standard_True;
}
//=======================================================================
//function : SplitCurves
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_FaceDivide::SplitCurves ()
{
Handle(ShapeUpgrade_WireDivide) SplitWire = GetWireDivideTool();
if ( SplitWire.IsNull() ) return Standard_False;
SplitWire->SetMaxTolerance(MaxTolerance());
for ( TopExp_Explorer explf(myResult,TopAbs_FACE); explf.More(); explf.Next()) {
TopoDS_Shape S = Context()->Apply ( explf.Current(), TopAbs_SHAPE);
// S should be face; else return with FAIL
if ( S.IsNull() || S.ShapeType() != TopAbs_FACE ) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
return Standard_False;
}
TopoDS_Face F = TopoDS::Face ( S );
SplitWire->SetFace ( F );
for ( TopoDS_Iterator wi(F,Standard_False); wi.More(); wi.Next() ) {
//TopoDS_Wire wire = TopoDS::Wire ( wi.Value() );
// modifications already defined in context are to be applied inside SplitWire
if(wi.Value().ShapeType() !=TopAbs_WIRE)
continue;
TopoDS_Wire wire = TopoDS::Wire(wi.Value());
SplitWire->Load ( wire );
SplitWire->SetContext(Context());
SplitWire->Perform ();
if ( SplitWire->Status ( ShapeExtend_FAIL ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
if ( SplitWire->Status ( ShapeExtend_DONE ) ) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
Context()->Replace ( wire, SplitWire->Wire() );
}
}
}
myResult = Context()->Apply ( myResult );
return Status ( ShapeExtend_DONE );
}
//=======================================================================
//function : Shell
//purpose :
//=======================================================================
TopoDS_Shape ShapeUpgrade_FaceDivide::Result () const
{
return myResult;
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_FaceDivide::Status (const ShapeExtend_Status status) const
{
return ShapeExtend::DecodeStatus ( myStatus, status );
}
//=======================================================================
//function : SetSplitSurfaceTool
//purpose :
//=======================================================================
void ShapeUpgrade_FaceDivide::SetSplitSurfaceTool(const Handle(ShapeUpgrade_SplitSurface)& splitSurfaceTool)
{
mySplitSurfaceTool = splitSurfaceTool;
}
//=======================================================================
//function : SetWireDivideTool
//purpose :
//=======================================================================
void ShapeUpgrade_FaceDivide::SetWireDivideTool(const Handle(ShapeUpgrade_WireDivide)& wireDivideTool)
{
myWireDivideTool = wireDivideTool;
}
//=======================================================================
//function : GetSplitSurfaceTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_SplitSurface) ShapeUpgrade_FaceDivide::GetSplitSurfaceTool () const
{
return mySplitSurfaceTool;
}
//=======================================================================
//function : GetWireDivideTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_WireDivide) ShapeUpgrade_FaceDivide::GetWireDivideTool () const
{
return myWireDivideTool;
}

View File

@@ -0,0 +1,35 @@
-- File: ShapeUpgrade_FaceDivideArea.cdl
-- Created: Mon Aug 7 17:14:06 2006
-- Author: Galina KULIKOVA
-- <gka@zamox.nnov.matra-dtv.fr>
---Copyright: Open CASCADE 2006
class FaceDivideArea from ShapeUpgrade inherits FaceDivide from ShapeUpgrade
---Purpose: Divides face by max area criterium.
uses
Face from TopoDS
is
Create returns FaceDivideArea from ShapeUpgrade;
---Purpose: Creates empty constructor.
Create (F : Face from TopoDS) returns FaceDivideArea from ShapeUpgrade;
Perform (me: mutable) returns Boolean is redefined;
---Purpose: Performs splitting and computes the resulting shell
-- The context is used to keep track of former splittings
MaxArea(me: mutable) returns Real;
---C++: inline
---C++: return &
---Purpose:Set max area allowed for faces
fields
myMaxArea : Real;
end FaceDivideArea;

View File

@@ -0,0 +1,91 @@
#include <ShapeUpgrade_FaceDivideArea.ixx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <Precision.hxx>
#include <ShapeUpgrade_SplitSurfaceArea.hxx>
#include <TopoDS_Shape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <ShapeExtend.hxx>
#include <ShapeBuild_ReShape.hxx>
#include <BRep_Builder.hxx>
//=======================================================================
//function : ShapeUpgrade_FaceDivideArea
//purpose :
//=======================================================================
ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea()
{
myMaxArea = Precision::Infinite();
SetPrecision(1.e-5);
SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
}
//=======================================================================
//function : ShapeUpgrade_FaceDivideArea
//purpose :
//=======================================================================
ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea(const TopoDS_Face& F)
{
myMaxArea = Precision::Infinite();
SetPrecision(1.e-5);
SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
Init(F);
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_FaceDivideArea::Perform()
{
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
GProp_GProps aGprop;
BRepGProp::SurfaceProperties(myFace,aGprop,Precision());
Standard_Real anArea = aGprop.Mass();
if((anArea - myMaxArea) < Precision::Confusion())
return Standard_False;
Standard_Integer anbParts = RealToInt(ceil(anArea/myMaxArea));
Handle(ShapeUpgrade_SplitSurfaceArea) aSurfTool= Handle(ShapeUpgrade_SplitSurfaceArea)::
DownCast(GetSplitSurfaceTool ());
if(aSurfTool.IsNull())
return Standard_False;
aSurfTool->NbParts() = anbParts;
if(!ShapeUpgrade_FaceDivide::Perform())
return Standard_False;
TopoDS_Shape aResult = Result();
if(aResult.ShapeType() == TopAbs_FACE)
return Standard_False;
Standard_Integer aStatus = myStatus;
TopExp_Explorer aExpF(aResult,TopAbs_FACE);
TopoDS_Shape aCopyRes = aResult.EmptyCopied();
Standard_Boolean isModified = Standard_False;
for( ; aExpF.More() ; aExpF.Next()) {
TopoDS_Shape aSh = Context()->Apply(aExpF.Current());
TopoDS_Face aFace = TopoDS::Face(aSh);
Init(aFace);
BRep_Builder aB;
if(Perform()) {
isModified = Standard_True;
TopoDS_Shape aRes = Result();
TopExp_Explorer aExpR(aRes,TopAbs_FACE);
for( ; aExpR.More(); aExpR.Next())
aB.Add(aCopyRes,aExpR.Current());
}
else
aB.Add(aCopyRes,aFace);
}
if(isModified)
Context()->Replace(aResult,aCopyRes);
myStatus |= aStatus;
myResult = Context()->Apply ( aResult );
return Status ( ShapeExtend_DONE );
}

View File

@@ -0,0 +1,6 @@
inline Standard_Real& ShapeUpgrade_FaceDivideArea::MaxArea()
{
return myMaxArea;
}

View File

@@ -0,0 +1,39 @@
-- File: ShapeUpgrade_FixSmallBezierCurves.cdl
-- Created: Wed Jun 7 16:50:55 2000
-- Author: Galina KULIKOVA
-- <gka@zamox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2000
class FixSmallBezierCurves from ShapeUpgrade inherits FixSmallCurves from ShapeUpgrade
---Purpose:
uses
--HArray1OfCurve from TColGeom,
--HArray1OfCurve from TColGeom2d,
--HSequenceOfReal from TColStd,
Edge from TopoDS,
Face from TopoDS,
Curve from Geom,
Curve from Geom2d,
Status from ShapeExtend
is
Create returns FixSmallBezierCurves from ShapeUpgrade;
---Purpose :
Approx(me : mutable; Curve3d : out Curve from Geom;
Curve2d : out Curve from Geom2d;
Curve2dR : out Curve from Geom2d;
First, Last : in out Real) returns Boolean is redefined;
--Perform(me : mutable; theSegments3d :in out HArray1OfCurve from TColGeom;
-- theKnots3d : in out HSequenceOfReal from TColStd;
-- theSegments2d :in out HArray1OfCurve from TColGeom2d;
-- theKnots2d : in out HSequenceOfReal from TColStd) returns Boolean is redefined;
---Purpose :
end FixSmallBezierCurves;

View File

@@ -0,0 +1,154 @@
// File: ShapeUpgrade_FixSmallBezierCurves.cxx
// Created: Wed Jun 7 17:54:42 2000
// Author: Galina KULIKOVA
// <gka@zamox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_FixSmallBezierCurves.ixx>
#include <TopoDS_Edge.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <gp_Pnt.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <TopExp.hxx>
#include <BRep_Tool.hxx>
#include <gp_Pnt2d.hxx>
#include <Geom2dConvert_ApproxCurve.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <ShapeExtend.hxx>
#include <TColGeom2d_HArray1OfCurve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <Geom_Surface.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GeomAbs_Shape.hxx>
#include <TopLoc_Location.hxx>
#include <GeomConvert_ApproxCurve.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <GeomConvert_ApproxCurve.hxx>
#include <ShapeUpgrade_SplitCurve3d.hxx>
#include <ShapeUpgrade_SplitCurve2d.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
ShapeUpgrade_FixSmallBezierCurves::ShapeUpgrade_FixSmallBezierCurves()
{
}
Standard_Boolean ShapeUpgrade_FixSmallBezierCurves::Approx(Handle(Geom_Curve)& Curve3d,Handle(Geom2d_Curve)& Curve2d,Handle(Geom2d_Curve)& Curve2dR,Standard_Real& First,Standard_Real& Last)
{
ShapeAnalysis_Edge sae;
Handle(Geom_Curve) c3d;
Standard_Real f,l;
if(sae.Curve3d(myEdge,c3d,f,l,Standard_False)) {
if(First < f)
First = f;
if(Last > l)
Last =l;
Handle(Geom_TrimmedCurve) trc = new Geom_TrimmedCurve(c3d,First,Last);
GeomAbs_Shape aCont = (GeomAbs_Shape)trc->Continuity();
if(aCont == GeomAbs_C3 || aCont == GeomAbs_CN)
aCont = GeomAbs_C2;
try {
OCC_CATCH_SIGNALS
GeomConvert_ApproxCurve AproxCurve(trc,Precision(),aCont,1,9);
if(AproxCurve.IsDone()) {
Handle(Geom_Curve) newCurve = AproxCurve.Curve();
mySplitCurve3dTool->Init(AproxCurve.Curve(),First,Last);
mySplitCurve3dTool->Perform(Standard_True);
if (!mySplitCurve3dTool->Status ( ShapeExtend_FAIL )) {
Handle(TColGeom_HArray1OfCurve) theSegments3d;
theSegments3d = mySplitCurve3dTool->GetCurves();
if(theSegments3d->Length() >1) return Standard_False;
Curve3d = theSegments3d->Value(1);
}
}
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
return Standard_False;
}
}
if ( myFace.IsNull() ) return Standard_True;
Handle(Geom2d_Curve) c2d;
TopLoc_Location L;
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(myFace,L);
GeomAdaptor_Surface ads(aSurf);// = new GeomAdaptor_Surface(aSurf);
Standard_Real prec = Max(ads.UResolution(Precision()),ads.VResolution(Precision()));
if(sae.PCurve(myEdge,myFace,c2d,f,l,Standard_False)) {
if(First < f)
First = f;
if(Last > l)
Last =l;
Handle(Geom2d_TrimmedCurve) trc2d = new Geom2d_TrimmedCurve(c2d,First,Last);
GeomAbs_Shape aCont = (GeomAbs_Shape)trc2d->Continuity();
try {
OCC_CATCH_SIGNALS
Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9);
if(AproxCurve2d.IsDone()) {
Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve();
mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last);
mySplitCurve2dTool->Perform(Standard_True);
if ( mySplitCurve2dTool->Status ( ShapeExtend_FAIL ))
return Standard_False;
Handle(TColGeom2d_HArray1OfCurve) theSegments2d;
theSegments2d = mySplitCurve2dTool->GetCurves();
if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface
Curve2d = theSegments2d->Value(1);
}
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
return Standard_False;
}
}
Standard_Boolean isSeam = BRep_Tool::IsClosed ( myEdge, myFace );
if ( isSeam ) {
Handle(Geom2d_Curve) c2;
Standard_Real f2, l2;
//smh#8
TopoDS_Shape tmpE = myEdge.Reversed();
TopoDS_Edge erev = TopoDS::Edge (tmpE );
if ( sae.PCurve ( erev, myFace, c2, f2, l2, Standard_False) ) {
if(First > f)
First = f;
if(Last > l)
Last =l;
Handle(Geom2d_TrimmedCurve) trc2d = new Geom2d_TrimmedCurve(c2,First,Last);
GeomAbs_Shape aCont = trc2d->Continuity();
Geom2dConvert_ApproxCurve AproxCurve2d(trc2d,prec,aCont,1,9);
try {
OCC_CATCH_SIGNALS
if(AproxCurve2d.IsDone()) {
Handle(Geom2d_Curve) newCurve = AproxCurve2d.Curve();
mySplitCurve2dTool->Init(AproxCurve2d.Curve(),First,Last);
mySplitCurve2dTool->Perform(Standard_True);
if ( ! mySplitCurve2dTool->Status ( ShapeExtend_DONE ))
return Standard_False;
Handle(TColGeom2d_HArray1OfCurve) theSegments2d;
theSegments2d = mySplitCurve2dTool->GetCurves();
if(theSegments2d->Length() >1) return Standard_False; //ShapeAnalysis_Surface
Curve2dR = theSegments2d->Value(1);
}
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_FixSmallBezierCurve::Approx(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
return Standard_False;
}
}
}
return Standard_True;
}

View File

@@ -0,0 +1,69 @@
-- File: ShapeUpgrade_FixSmallCurves.cdl
-- Created: Wed Jun 7 15:36:50 2000
-- Author: Galina KULIKOVA
-- <gka@zamox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2000
class FixSmallCurves from ShapeUpgrade inherits Tool from ShapeUpgrade
---Purpose:
uses
SplitCurve3d from ShapeUpgrade,
SplitCurve2d from ShapeUpgrade,
--HArray1OfCurve from TColGeom,
--HArray1OfCurve from TColGeom2d,
--HSequenceOfReal from TColStd,
Edge from TopoDS,
Face from TopoDS,
Curve from Geom,
Curve from Geom2d,
Status from ShapeExtend
is
Create returns FixSmallCurves from ShapeUpgrade;
---Purpose :
--Init(me : mutable; theCurve3d : Curve from Geom; theCurve2d : Curve from Geom2d);
Init(me : mutable; theEdge : Edge from TopoDS; theFace : Face from TopoDS);
---Purpose :
Approx(me : mutable; Curve3d : out Curve from Geom;
Curve2d : out Curve from Geom2d;
Curve2dR : out Curve from Geom2d;
First, Last : in out Real) returns Boolean is virtual;
-- theKnots3d : in out HSequenceOfReal from TColStd;
-- theSegments2d :in out HArray1OfCurve from TColGeom2d;
-- theKnots2d : in out HSequenceOfReal from TColStd) returns Boolean is virtual;
---Purpose :
SetSplitCurve3dTool(me: mutable; splitCurve3dTool: SplitCurve3d from ShapeUpgrade);
---Purpose: Sets the tool for splitting 3D curves.
SetSplitCurve2dTool(me: mutable; splitCurve2dTool: SplitCurve2d from ShapeUpgrade);
---Purpose: Sets the tool for splitting pcurves.
GetSplitCurve3dTool(me) returns SplitCurve3d from ShapeUpgrade
is virtual protected;
GetSplitCurve2dTool(me) returns SplitCurve2d from ShapeUpgrade
is virtual protected;
---Purpose: Returns the tool for splitting pcurves.
Status (me; status: Status from ShapeExtend) returns Boolean;
---Purpose: Queries the status of last call to Perform
-- OK :
-- DONE1:
-- DONE2:
-- FAIL1:
fields
myStatus : Integer is protected;
mySplitCurve3dTool: SplitCurve3d from ShapeUpgrade is protected;
mySplitCurve2dTool: SplitCurve2d from ShapeUpgrade is protected;
myEdge : Edge from TopoDS is protected;
myFace : Face from TopoDS is protected;
--myCurve3d : Curve from Geom;
--myCurve2d : Curve from Geom;
end FixSmallCurves;

View File

@@ -0,0 +1,102 @@
// File: ShapeUpgrade_FixSmallCurves.cxx
// Created: Wed Jun 7 17:09:05 2000
// Author: Galina KULIKOVA
// <gka@zamox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_FixSmallCurves.ixx>
//#include <TColGeom_HArray1OfCurve.hxx>
//#include <TColStd_HSequenceOfReal.hxx>
#//include <TColGeom2d_HArray1OfCurve.hxx>
//#include <TColStd_HSequenceOfReal.hxx>
#include <ShapeExtend.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <ShapeUpgrade_SplitCurve3d.hxx>
#include <ShapeUpgrade_SplitCurve2d.hxx>
//=======================================================================
//function : ShapeUpgrade_FixSmallCurves
//purpose :
//=======================================================================
ShapeUpgrade_FixSmallCurves::ShapeUpgrade_FixSmallCurves()
{
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_FixSmallCurves::Init(const TopoDS_Edge& theEdge,const TopoDS_Face& theFace)
{
myEdge = theEdge;
myFace = theFace;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_FixSmallCurves::Approx(Handle(Geom_Curve)& /*Curve3d*/,
Handle(Geom2d_Curve)& /*Curve2d*/,
Handle(Geom2d_Curve)& /*Curve2dR*/,
Standard_Real& /*First*/,
Standard_Real& /*Last*/)
{
return Standard_False;
}
//=======================================================================
//function : SetSplitCurve3dTool
//purpose :
//=======================================================================
void ShapeUpgrade_FixSmallCurves::SetSplitCurve3dTool(const Handle(ShapeUpgrade_SplitCurve3d)& splitCurve3dTool)
{
mySplitCurve3dTool = splitCurve3dTool;
}
//=======================================================================
//function : SetSplitCurve2dTool
//purpose :
//=======================================================================
void ShapeUpgrade_FixSmallCurves::SetSplitCurve2dTool(const Handle(ShapeUpgrade_SplitCurve2d)& splitCurve2dTool)
{
mySplitCurve2dTool = splitCurve2dTool;
}
//=======================================================================
//function : GetSplitCurve3dTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_SplitCurve3d) ShapeUpgrade_FixSmallCurves::GetSplitCurve3dTool() const
{
return mySplitCurve3dTool;
}
//=======================================================================
//function : GetSplitCurve2dTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_SplitCurve2d) ShapeUpgrade_FixSmallCurves::GetSplitCurve2dTool() const
{
return mySplitCurve2dTool;
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_FixSmallCurves::Status(const ShapeExtend_Status status) const
{
return ShapeExtend::DecodeStatus ( myStatus, status );
}

View File

@@ -0,0 +1,93 @@
-- File: ShapeUpgrade_RemoveInternalWires.cdl
-- Created: Thu Aug 10 11:21:43 2006
-- Author: Galina KULIKOVA
-- <gka@zamox.nnov.matra-dtv.fr>
---Copyright: Open CASCADE 2006
class RemoveInternalWires from ShapeUpgrade inherits Tool from ShapeUpgrade
---Purpose: Removes all internal wires having area less than specified min area
uses
Shape from TopoDS,
SequenceOfShape from TopTools,
DataMapOfShapeListOfShape from TopTools,
IndexedDataMapOfShapeListOfShape from TopTools,
Status from ShapeExtend
is
Create returns RemoveInternalWires from ShapeUpgrade;
---Purpose: Creates empty constructor.
Create (theShape : Shape from TopoDS) returns RemoveInternalWires from ShapeUpgrade;
Init (me: mutable; theShape : Shape from TopoDS);
---Purpose: Initialize by a Shape.
Perform (me: mutable) returns Boolean;
---Purpose:Removes all internal wires having area less than area specified as minimal allowed area
Perform (me: mutable; theSeqShapes : SequenceOfShape from TopTools) returns Boolean;
---Purpose:If specified sequence of shape contains -
-- 1.wires then these wires will be removed if they have area less than allowed min area.
-- 2.faces than internal wires from these faces will be removed if they have area less than allowed min area.
GetResult(me) returns Shape from TopoDS;
---C++: inline
---Purpose:Get result shape
MinArea(me: mutable) returns Real;
---C++: inline
---C++: return &
---Purpose:Set min area allowed for holes( all holes having area less than mi area will be removed)
RemoveFaceMode(me: mutable) returns Boolean;
---C++: inline
---C++: return &
---Purpose:Set mode which manage removing faces which have outer wires consisting only from edges
-- belonginig to removed internal wires.
---- By default it is equal to true.
RemovedFaces(me) returns SequenceOfShape from TopTools;
---C++: inline
---C++: return const &
---Purpose:Returns sequence of removed faces.
RemovedWires(me) returns SequenceOfShape from TopTools;
---C++: inline
---C++: return const &
---Purpose:Returns sequence of removed faces.
Status(me; theStatus : Status from ShapeExtend) returns Boolean;
---C++: inline
---Purpose:Queries status of last call to Perform()
-- : OK - nothing was done
-- :DONE1 - internal wires were removed
-- :DONE2 - small faces were removed.
-- :FAIL1 - initial shape is not specified
-- :FAIL2 - specified sub-shape is not belonged to inotial shape.
removeSmallWire (me:mutable;theFace: Shape from TopoDS; theWire : Shape from TopoDS) is private;
---Purpose:Removes internal wires having area of contour less than specified MinArea
removeSmallFaces(me:mutable) is private;
---Purpose:Removes faces having outer wire consisting
-- from removed edges(belonging small internal wires)
Clear(me:mutable)is protected;
---Purpose:Clear all sequences and temporary map;
fields
myShape : Shape from TopoDS;
myResult : Shape from TopoDS;
myMinArea : Real;
myRemoveFacesMode : Boolean;
myEdgeFaces : IndexedDataMapOfShapeListOfShape from TopTools;--map of containing all edges and corresponding them edges
myRemoveEdges : DataMapOfShapeListOfShape from TopTools;
myRemovedFaces : SequenceOfShape from TopTools;
myStatus: Integer is protected;
myRemoveWires : SequenceOfShape from TopTools;
end RemoveInternalWires;

View File

@@ -0,0 +1,267 @@
#include <ShapeUpgrade_RemoveInternalWires.ixx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS.hxx>
#include <ShapeAnalysis.hxx>
#include <ShapeExtend.hxx>
#include <TopTools_SequenceOfShape.hxx>
#include <ShapeExtend_WireData.hxx>
#include <ShapeBuild_ReShape.hxx>
#include <Precision.hxx>
#include <TopoDS_Edge.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
//=======================================================================
//function : ShapeUpgrade_RemoveInternalWires
//purpose :
//=======================================================================
ShapeUpgrade_RemoveInternalWires::ShapeUpgrade_RemoveInternalWires()
{
myMinArea =0.;
myRemoveFacesMode = Standard_True;
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
SetContext(aContext);
}
//=======================================================================
//function : ShapeUpgrade_RemoveInternalWires
//purpose :
//=======================================================================
ShapeUpgrade_RemoveInternalWires::ShapeUpgrade_RemoveInternalWires(const TopoDS_Shape& theShape)
{
Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
SetContext(aContext);
Init(theShape);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_RemoveInternalWires::Init(const TopoDS_Shape& theShape)
{
myShape = theShape;
Context()->Apply(theShape);
TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,myEdgeFaces);
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
myMinArea =0.;
myRemoveFacesMode = Standard_True;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_RemoveInternalWires::Perform()
{
Clear();
if(myShape.IsNull()) {
myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
return Standard_False;
}
TopExp_Explorer aExpF(myShape,TopAbs_FACE);
for( ; aExpF.More(); aExpF.Next()) {
TopoDS_Face aF = TopoDS::Face(aExpF.Current());
removeSmallWire(aF,TopoDS_Wire());
}
if(myRemoveFacesMode)
removeSmallFaces();
myResult = Context()->Apply(myShape);
return Status( ShapeExtend_DONE );
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_RemoveInternalWires::Perform(const TopTools_SequenceOfShape& theSeqShapes)
{
if(myShape.IsNull()) {
myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
return Standard_False;
}
Clear();
TopTools_IndexedDataMapOfShapeListOfShape aWireFaces;
Standard_Integer i =1, nb = theSeqShapes.Length();
for( ; i <= nb; i++) {
TopoDS_Shape aS = theSeqShapes.Value(i);
if(aS.ShapeType() == TopAbs_FACE)
removeSmallWire(aS,TopoDS_Wire());
else if(aS.ShapeType() == TopAbs_WIRE) {
if(!aWireFaces.Extent())
TopExp::MapShapesAndAncestors(myShape,TopAbs_WIRE,TopAbs_FACE,aWireFaces);
if(aWireFaces.Contains(aS)) {
const TopTools_ListOfShape& alfaces = aWireFaces.FindFromKey(aS);
TopTools_ListIteratorOfListOfShape liter(alfaces);
for( ; liter.More(); liter.Next())
removeSmallWire(liter.Value(),aS);
}
}
}
if(myRemoveFacesMode)
removeSmallFaces();
myResult = Context()->Apply(myShape);
return Status( ShapeExtend_DONE );
}
//=======================================================================
//function : removeSmallWire
//purpose :
//=======================================================================
void ShapeUpgrade_RemoveInternalWires::removeSmallWire (const TopoDS_Shape& theFace,
const TopoDS_Shape& theWire)
{
TopoDS_Face aF = TopoDS::Face(theFace);
TopoDS_Wire anOutW = ShapeAnalysis::OuterWire(aF);
TopoDS_Iterator aIt(aF);
for( ; aIt.More(); aIt.Next()) {
if(aIt.Value().ShapeType() != TopAbs_WIRE || aIt.Value().IsSame(anOutW))
continue;
//Handle(ShapeExtend_WireData) asewd = new ShapeExtend_WireData();
TopoDS_Wire aW = TopoDS::Wire(aIt.Value());
if(!theWire.IsNull() && !theWire.IsSame(aW))
continue;
Standard_Real anArea = ShapeAnalysis::ContourArea(aW);
if(anArea < myMinArea -Precision::Confusion()) {
Context()->Remove(aW);
myRemoveWires.Append(aW);
myStatus |= ShapeExtend::EncodeStatus(ShapeExtend_DONE1);
if(!myRemoveFacesMode )
continue;
TopoDS_Iterator aIte(aW,Standard_False);
for( ; aIte.More(); aIte.Next()) {
TopoDS_Shape aE = aIte.Value();
if(myRemoveEdges.IsBound(aE))
myRemoveEdges.ChangeFind(aE).Append(aF);
else {
TopTools_ListOfShape alfaces;
alfaces.Append(aF);
myRemoveEdges.Bind(aE,alfaces);
}
}
}
}
}
//=======================================================================
//function : removeSmallFaces
//purpose :
//=======================================================================
void ShapeUpgrade_RemoveInternalWires::removeSmallFaces ()
{
Standard_Integer i =1;
for( ; i <= myRemoveWires.Length() ; i++) {
TopoDS_Shape aWire = myRemoveWires.Value(i);
TopoDS_Iterator aIte(aWire,Standard_False);
TopTools_IndexedMapOfShape aFaceCandidates;
//collecting all faces containing edges from removed wire
for( ; aIte.More(); aIte.Next()) {
TopoDS_Shape aEdge = aIte.Value();
if(!myEdgeFaces.Contains(aEdge)) {
myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
continue;
}
const TopTools_ListOfShape& aLface1 = myEdgeFaces.FindFromKey(aEdge);
const TopTools_ListOfShape& aLface2 = myRemoveEdges.Find(aEdge);
TopTools_ListIteratorOfListOfShape aliter(aLface1);
TopTools_ListIteratorOfListOfShape aliter2(aLface2);
for( ; aliter.More(); aliter.Next()) {
TopoDS_Shape aF = Context()->Apply(aliter.Value());
if(aF.IsNull())
continue;
Standard_Boolean isFind = Standard_False;
for( ; aliter2.More() && !isFind; aliter2.Next()) {
TopoDS_Shape aF2 = Context()->Apply(aliter2.Value());
isFind = aF.IsSame(aF2);
}
if(!isFind) {
TopoDS_Wire aWout = ShapeAnalysis::OuterWire(TopoDS::Face(aF));
Standard_Boolean isOuter = Standard_False;
TopoDS_Iterator aIter(aWout,Standard_False);
for( ; aIter.More() && !isOuter; aIter.Next())
isOuter = aEdge.IsSame(aIter.Value());
if(isOuter)
aFaceCandidates.Add(aF);
}
}
}
//remove faces which have outer wire consist of only
//edges from removed wires and
//seam edges for faces based on conic surface or
//in the case of a few faces based on the same conic surface
//the edges belogining these faces.
Standard_Integer k =1;
for( ; k <= aFaceCandidates.Extent(); k++) {
TopoDS_Shape aF = aFaceCandidates.FindKey(k);
TopoDS_Wire anOutW = ShapeAnalysis::OuterWire(TopoDS::Face(aF));
Handle(ShapeExtend_WireData) asewd = new ShapeExtend_WireData(anOutW);
Standard_Integer n =1, nbE = asewd->NbEdges();
Standard_Integer nbNotRemoved =0;
for( ; n <= nbE; n++) {
if(asewd->IsSeam(n))
continue;
TopoDS_Edge aE = asewd->Edge(n);
if(!myRemoveEdges.IsBound(aE) ) {
const TopTools_ListOfShape& aLface3 = myEdgeFaces.FindFromKey(aE);
TopTools_ListIteratorOfListOfShape aliter3(aLface3);
Standard_Boolean isRemoved = Standard_True;
for( ; aliter3.More();aliter3.Next()) {
TopoDS_Shape aF2 = Context()->Apply(aliter3.Value());
if(aF2.IsNull())
continue;
if(!aF.IsSame(aF2) && !aFaceCandidates.Contains(aF2))
nbNotRemoved++;
}
}
}
if(!nbNotRemoved) {
Context()->Remove(aF);
myRemovedFaces.Append(aF);
}
}
}
if(myRemovedFaces.Length())
myStatus |= ShapeExtend::EncodeStatus(ShapeExtend_DONE2);
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void ShapeUpgrade_RemoveInternalWires::Clear()
{
myRemoveEdges.Clear();
myRemovedFaces.Clear();
myRemoveWires.Clear();
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
}

View File

@@ -0,0 +1,62 @@
#include <ShapeExtend.hxx>
//=======================================================================
//function : MinArea
//purpose :
//=======================================================================
inline Standard_Real& ShapeUpgrade_RemoveInternalWires::MinArea()
{
return myMinArea;
}
//=======================================================================
//function : RemoveFaceMode
//purpose :
//=======================================================================
inline Standard_Boolean& ShapeUpgrade_RemoveInternalWires::RemoveFaceMode()
{
return myRemoveFacesMode;
}
//=======================================================================
//function : RemovedFaces
//purpose :
//=======================================================================
inline const TopTools_SequenceOfShape& ShapeUpgrade_RemoveInternalWires::RemovedFaces() const
{
return myRemovedFaces;
}
//=======================================================================
//function : RemovedWires
//purpose :
//=======================================================================
inline const TopTools_SequenceOfShape& ShapeUpgrade_RemoveInternalWires::RemovedWires() const
{
return myRemoveWires;
}
//=======================================================================
//function : GetResult
//purpose :
//=======================================================================
inline TopoDS_Shape ShapeUpgrade_RemoveInternalWires::GetResult() const
{
return myResult;
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_RemoveInternalWires::Status(const ShapeExtend_Status theStatus) const
{
return ShapeExtend::DecodeStatus ( myStatus, theStatus );
}

View File

@@ -0,0 +1,54 @@
-- File: ShapeUpgrade_RemoveLocations.cdl
-- Created: Wed Nov 13 11:48:40 2002
-- Author: Galina KULIKOVA
-- <gka@zamox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2002
class RemoveLocations from ShapeUpgrade inherits TShared from MMgt
---Purpose: Removes all locations sub-shapes of specified shape
uses
ShapeEnum from TopAbs,
Shape from TopoDS,
MapOfShape from TopTools,
DataMapOfShapeShape from TopTools
is
Create returns RemoveLocations from ShapeUpgrade;
---Purpose:Empy constructor
Remove(me : mutable;theShape : Shape from TopoDS) returns Boolean;
---Purpose:Removes all location correspodingly to RemoveLevel.
MakeNewShape(me : mutable;theShape , theAncShape: Shape from TopoDS;
theNewShape:in out Shape from TopoDS;theRemoveLoc : Boolean)
returns Boolean is private;
GetResult(me) returns Shape from TopoDS;
---Purpose:Returns shape with removed locatins.
---C++: inline
SetRemoveLevel(me: mutable; theLevel : ShapeEnum from TopAbs);
---Purpose:sets level starting with that location will be removed,
-- by default TopAbs_SHAPE. In this case locations will be kept for specified shape
-- and if specified shape is TopAbs_COMPOUND for sub-shapes of first level.
---C++: inline
RemoveLevel(me) returns ShapeEnum from TopAbs;
---Purpose:sets level starting with that location will be removed.Value of level can be set to
-- TopAbs_SHAPE,TopAbs_COMPOUND,TopAbs_SOLID,TopAbs_SHELL,TopAbs_FACE.By default TopAbs_SHAPE.
-- In this case location will be removed for all shape types for exception of compound.
---C++: inline
ModifiedShape (me; theInitShape : Shape from TopoDS) returns Shape from TopoDS;
---Purpose: Returns modified shape obtained from initial shape.
---C++: inline
fields
myLevelRemoving : ShapeEnum from TopAbs;
myShape : Shape from TopoDS;
myMapNewShapes : DataMapOfShapeShape from TopTools;
end RemoveLocations;

View File

@@ -0,0 +1,271 @@
#include <ShapeUpgrade_RemoveLocations.ixx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <Geom_Surface.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp.hxx>
#include <Geom_Curve.hxx>
#include <BRep_Tool.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom_Geometry.hxx>
#include <gp_Trsf.hxx>
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
#include <BRep_TEdge.hxx>
#include <BRep_GCurve.hxx>
#include <BRep_CurveRepresentation.hxx>
#include <TColStd_ListIteratorOfListOfTransient.hxx>
#include <TopExp_Explorer.hxx>
#include <TColStd_ListOfTransient.hxx>
//#include <ShapeUpgrade_DataMapOfShapeListOfTransient.hxx>
#include <ShapeBuild_Edge.hxx>
#include <Geom_Plane.hxx>
//=======================================================================
//function : ShapeUpgrade_RemoveLocations
//purpose :
//=======================================================================
ShapeUpgrade_RemoveLocations::ShapeUpgrade_RemoveLocations()
{
myLevelRemoving = TopAbs_SHAPE;
}
//=======================================================================
//function : Remove
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_RemoveLocations::Remove(const TopoDS_Shape& theShape)
{
TopoDS_Shape aShape = theShape;
myShape = aShape;
TopAbs_ShapeEnum shtype = theShape.ShapeType();
Standard_Boolean isRemoveLoc = ((shtype != TopAbs_COMPOUND && myLevelRemoving == TopAbs_SHAPE) ||
((Standard_Integer)myLevelRemoving <= ((Standard_Integer)shtype)));
TopoDS_Shape S;
Standard_Boolean isDone = MakeNewShape(theShape,S,myShape,isRemoveLoc);
return isDone;
}
//=======================================================================
//function : RebuildShape
//purpose :
//=======================================================================
static Standard_Boolean RebuildShape(const TopoDS_Face& theFace, TopoDS_Face& theNewFace)
{
BRep_Builder aB;
TopLoc_Location aLoc;
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(theFace,aLoc);
Standard_Boolean isRebuild = Standard_False;
if(!aLoc.IsIdentity()) {
Handle(Geom_Surface) anewSurf =Handle(Geom_Surface)::DownCast( aSurf->Transformed(aLoc.Transformation()));
aB.MakeFace(theNewFace,anewSurf,BRep_Tool::Tolerance(theFace));
isRebuild = Standard_True;
}
return isRebuild;
}
//=======================================================================
//function : RebuildShape
//purpose :
//=======================================================================
static Standard_Boolean RebuildShape(const TopoDS_Edge& theEdge, TopoDS_Edge& theNewEdge,
const TopoDS_Face& theFace, TopoDS_Face& theNewFace,
Standard_Boolean isBound)
{
Standard_Boolean isRebuild = Standard_False;
BRep_Builder aB;
if(!isBound) {
Handle(Geom_Curve) C3d;
TopLoc_Location aLoc;
Standard_Real First3d,Last3d;
C3d = BRep_Tool::Curve( theEdge,aLoc,First3d,Last3d);
aB.MakeEdge(theNewEdge);
if(!C3d.IsNull()) {
if(!aLoc.IsIdentity()) {
Handle(Geom_Curve) anewC3d = Handle(Geom_Curve)::DownCast(C3d->Transformed(aLoc.Transformation()));
C3d = anewC3d;
}
aB.UpdateEdge(theNewEdge,C3d,BRep_Tool::Tolerance(theEdge));
aB.Range(theNewEdge,First3d,Last3d);
}
theNewEdge.Orientation(theEdge.Orientation());
if(BRep_Tool::Degenerated(theEdge))
aB.Degenerated(theNewEdge,Standard_True);
isRebuild = Standard_True;
}
if(!theFace.IsNull()) {
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(theFace);
if(!aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
Handle(Geom2d_Curve) c2d,c2d1;
Standard_Real First2d,Last2d;
c2d= BRep_Tool::CurveOnSurface( theEdge,theFace,First2d,Last2d);
if(BRep_Tool::IsClosed(theEdge,theFace)) {
if(!BRep_Tool::IsClosed(theNewEdge,theNewFace)) {
TopoDS_Edge tmpE = TopoDS::Edge(theEdge.Reversed());
c2d1= BRep_Tool::CurveOnSurface(tmpE,theFace,First2d,Last2d);
TopAbs_Orientation OrEdge = theNewEdge.Orientation();
if(theNewFace.Orientation() == TopAbs_REVERSED)
OrEdge = ( OrEdge == TopAbs_FORWARD ? TopAbs_REVERSED : TopAbs_FORWARD);
if(OrEdge == TopAbs_FORWARD)
aB.UpdateEdge(theNewEdge,c2d, c2d1,theNewFace,0);
else aB.UpdateEdge(theNewEdge,c2d1, c2d,theNewFace,0);
}
}
else
aB.UpdateEdge(theNewEdge,c2d,theNewFace,0);
if(!c2d.IsNull() || !c2d1.IsNull())
aB.Range(theNewEdge,theNewFace,First2d,Last2d);
}
}
return isRebuild;
}
//=======================================================================
//function : RebuildShape
//purpose :
//=======================================================================
static Standard_Boolean RebuildShape(const TopoDS_Vertex& theVertex, TopoDS_Vertex& theNewVertex)
{
BRep_Builder aB;
aB.MakeVertex(theNewVertex);
theNewVertex.Orientation( theVertex.Orientation());
gp_Pnt p1 = BRep_Tool::Pnt( theVertex);
aB.UpdateVertex(theNewVertex,p1,BRep_Tool::Tolerance( theVertex));
return Standard_True;
}
//=======================================================================
//function : MakeNewShape
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_RemoveLocations::MakeNewShape(const TopoDS_Shape& theShape,
const TopoDS_Shape& theAncShape,
TopoDS_Shape& theNewShape,
const Standard_Boolean theRemoveLoc)
{
Standard_Boolean isDone = Standard_False;
TopoDS_Shape aNewShape;
TopAbs_ShapeEnum shtype = theShape.ShapeType();
BRep_Builder aB;
TopoDS_Shape aShape = theShape;
if(!theRemoveLoc && !theShape.Location().IsIdentity()) {
TopLoc_Location nulLoc;
aShape.Location(nulLoc);
}
Standard_Boolean isBound = myMapNewShapes.IsBound(aShape);
if(isBound) {
aNewShape= myMapNewShapes.Find(aShape);
aNewShape.Orientation(theShape.Orientation());
if(!theRemoveLoc && !theShape.Location().IsIdentity()) {
TopLoc_Location aL = theShape.Location();
aNewShape.Location(aL);
}
if(shtype != TopAbs_EDGE) {
theNewShape = aNewShape;
return Standard_True;
}
}
Standard_Boolean isRemoveLoc = theRemoveLoc;
if(!theRemoveLoc) {
isRemoveLoc = ((shtype != TopAbs_COMPOUND && myLevelRemoving == TopAbs_SHAPE) ||
((Standard_Integer)myLevelRemoving <= ((Standard_Integer)shtype)));
}
Standard_Boolean aRebuild = Standard_False;
TopoDS_Shape anAncShape = theAncShape;
if(shtype == TopAbs_FACE)
anAncShape = aShape;
if(isRemoveLoc && (!aShape.Location().IsIdentity() || shtype == TopAbs_EDGE || shtype == TopAbs_FACE )) {
//Rebuild geometry for shape with location.
if(shtype == TopAbs_FACE) {
TopoDS_Face anewFace;
TopoDS_Face oldFace = TopoDS::Face(aShape);
aRebuild = RebuildShape(oldFace,anewFace);
if(aRebuild) {
aNewShape = anewFace;
myMapNewShapes.Bind(oldFace,aNewShape);
}
}
else if(shtype == TopAbs_EDGE) {
TopoDS_Edge oldEdge = TopoDS::Edge(aShape);
TopoDS_Edge anewEdge;
TopoDS_Face F,newFace;
if(!anAncShape.IsNull()) {
F = TopoDS::Face(anAncShape);
newFace = F;
if(myMapNewShapes.IsBound(F))
newFace = TopoDS::Face(myMapNewShapes.Find(F));
}
if(isBound)
anewEdge = TopoDS::Edge(aNewShape);
aRebuild = RebuildShape(oldEdge,anewEdge,F,newFace,isBound);
aNewShape = anewEdge;
}
else if(shtype == TopAbs_VERTEX) {
TopoDS_Vertex aVnew;
TopoDS_Vertex aV = TopoDS::Vertex(aShape);
aRebuild = RebuildShape(aV,aVnew);
if(aRebuild)
aNewShape = aVnew;
}
}
isDone = aRebuild;
//Removing location from sub-shapes in dependance of LevelRemoving and re-building shape.
if(!isBound) {
if(!aRebuild)
aNewShape = theShape.EmptyCopied();
TopLoc_Location oldLoc,nullloc;
oldLoc = theShape.Location();
if(!oldLoc.IsIdentity())
aNewShape.Location(nullloc);
TopAbs_Orientation orient = theShape.Orientation();
aNewShape.Orientation(TopAbs_FORWARD);
TopoDS_Iterator aIt(aShape,Standard_False,isRemoveLoc);
for( ; aIt.More(); aIt.Next()) {
TopoDS_Shape subshape = aIt.Value();
TopoDS_Shape anewsubshape;
Standard_Boolean isDoneSubShape = MakeNewShape(subshape,anAncShape,anewsubshape,isRemoveLoc);
isDone = (isDone || isDoneSubShape);
aB.Add(aNewShape,anewsubshape);
}
if(isDone)
aNewShape.Orientation(orient);
else aNewShape = aShape;
myMapNewShapes.Bind(aShape,aNewShape);
if(!theRemoveLoc && !oldLoc.IsIdentity())
aNewShape.Location(oldLoc);
}
theNewShape = aNewShape;
return (isDone || isBound);
}

View File

@@ -0,0 +1,46 @@
//=======================================================================
//function : GetResult
//purpose :
//=======================================================================
inline TopoDS_Shape ShapeUpgrade_RemoveLocations::GetResult() const
{
return myShape;
}
//=======================================================================
//function : SetRemoveLevel
//purpose :
//=======================================================================
inline void ShapeUpgrade_RemoveLocations::SetRemoveLevel(const TopAbs_ShapeEnum theLevel)
{
if((Standard_Integer)theLevel > TopAbs_FACE)
myLevelRemoving = TopAbs_FACE;
else myLevelRemoving = theLevel;
}
//=======================================================================
//function : RemoveLevel
//purpose :
//=======================================================================
inline TopAbs_ShapeEnum ShapeUpgrade_RemoveLocations::RemoveLevel() const
{
return myLevelRemoving;
}
//=======================================================================
//function : ModifiedShape
//purpose :
//=======================================================================
inline TopoDS_Shape ShapeUpgrade_RemoveLocations::ModifiedShape(const TopoDS_Shape& theInitShape) const
{
TopoDS_Shape aShape = theInitShape;
if( myMapNewShapes.IsBound(theInitShape))
aShape = myMapNewShapes.Find(theInitShape);
return aShape;
}

View File

@@ -0,0 +1,139 @@
-- File: ShapeUpgrade_ShapeConvertToBezier.cdl
-- Created: Fri May 14 09:41:42 1999
-- Author: Pavel DURANDIN
-- <pdn@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class ShapeConvertToBezier from ShapeUpgrade inherits ShapeDivide from ShapeUpgrade
---Purpose: API class for performing conversion of 3D, 2D curves to bezier curves
-- and surfaces to bezier based surfaces (
-- bezier surface,
-- surface of revolution based on bezier curve,
-- offset surface based on any previous type).
uses
Shape from TopoDS,
FaceDivide from ShapeUpgrade
is
Create returns ShapeConvertToBezier from ShapeUpgrade;
---Purpose: Empty constructor.
Create (S: Shape from TopoDS)
returns ShapeConvertToBezier from ShapeUpgrade;
---Purpose: Initialize by a Shape.
Set2dConversion(me:in out; mode: Boolean);
---Purpose: Sets mode for conversion 2D curves to bezier.
---C++:inline
Get2dConversion(me) returns Boolean;
---Purpose: Returns the 2D conversion mode.
---C++:inline
Set3dConversion(me: in out; mode: Boolean);
---Purpose: Sets mode for conversion 3d curves to bezier.
---C++:inline
Get3dConversion(me) returns Boolean;
---Purpose: Returns the 3D conversion mode.
---C++:inline
SetSurfaceConversion(me:in out; mode: Boolean);
---Purpose: Sets mode for conversion surfaces curves to
-- bezier basis.
---C++:inline
GetSurfaceConversion(me) returns Boolean;
---Purpose: Returns the surface conversion mode.
---C++:inline
--Remark: The following "Set.." functions affects only if 3D
-- conversion mode is True.
Set3dLineConversion(me:in out; mode: Boolean);
---Purpose: Sets mode for conversion Geom_Line to bezier.
---C++:inline
Get3dLineConversion(me) returns Boolean;
---Purpose: Returns the Geom_Line conversion mode.
---C++:inline
Set3dCircleConversion(me:in out; mode: Boolean);
---Purpose: Sets mode for conversion Geom_Circle to bezier.
---C++:inline
Get3dCircleConversion(me) returns Boolean;
---Purpose: Returns the Geom_Circle conversion mode.
---C++:inline
Set3dConicConversion(me:in out; mode: Boolean);
---Purpose: Sets mode for conversion Geom_Conic to bezier.
---C++:inline
Get3dConicConversion(me) returns Boolean;
---Purpose: Returns the Geom_Conic conversion mode.
---C++:inline
--Remark: The following "Set.." functions affects only if Surface
-- conversion mode is True.
SetPlaneMode(me: in out; mode: Boolean);
---Purpose: Sets mode for conversion Geom_Plane to Bezier
---C++: inline
GetPlaneMode(me) returns Boolean;
---Purpose: Returns the Geom_Pline conversion mode.
---C++: inline
SetRevolutionMode(me: in out; mode: Boolean);
---Purpose: Sets mode for conversion Geom_SurfaceOfRevolution to Bezier
---C++: inline
GetRevolutionMode(me) returns Boolean;
---Purpose: Returns the Geom_SurfaceOfRevolution conversion mode.
---C++: inline
SetExtrusionMode(me: in out; mode: Boolean);
---Purpose: Sets mode for conversion Geom_SurfaceOfLinearExtrusion to Bezier
---C++: inline
GetExtrusionMode(me) returns Boolean;
---Purpose: Returns the Geom_SurfaceOfLinearExtrusion conversion mode.
---C++: inline
SetBSplineMode(me: in out; mode: Boolean);
---Purpose: Sets mode for conversion Geom_BSplineSurface to Bezier
---C++: inline
GetBSplineMode(me) returns Boolean;
---Purpose: Returns the Geom_BSplineSurface conversion mode.
---C++: inline
Perform(me: in out; newContext: Boolean = Standard_True)
returns Boolean is redefined;
---Purpose: Performs converting and computes the resulting shape
GetSplitFaceTool(me) returns FaceDivide from ShapeUpgrade
is redefined protected;
---Purpose: Returns the tool for dividing faces.
fields
my2dMode : Boolean;
my3dMode : Boolean;
mySurfaceMode : Boolean;
my3dLineMode : Boolean;
my3dCircleMode : Boolean;
my3dConicMode : Boolean;
myPlaneMode : Boolean;
myRevolutionMode: Boolean;
myExtrusionMode : Boolean;
myBSplineMode : Boolean;
myLevel : Integer;
end ShapeConvertToBezier;

View File

@@ -0,0 +1,339 @@
// 15.06 2000 gka fix against small edges ; merging ends pcurves and 3d curves
// File: ShapeUpgrade_ShapeConvertToBezier.cxx
// Created: Fri May 14 10:00:01 1999
// Author: data exchange team
// <det@friendox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_ShapeConvertToBezier.ixx>
#include <ShapeUpgrade_WireDivide.hxx>
#include <ShapeUpgrade_ConvertCurve3dToBezier.hxx>
#include <ShapeUpgrade_ConvertCurve2dToBezier.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <BRep_Builder.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <ShapeBuild_Edge.hxx>
#include <Geom_Curve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Precision.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <BRep_Tool.hxx>
#include <GeomLib.hxx>
#include <TopoDS_Edge.hxx>
#include <ShapeUpgrade_ConvertSurfaceToBezierBasis.hxx>
#include <TopExp.hxx>
#include <TopExp.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <ShapeFix_Wire.hxx>
#include <ShapeExtend_WireData.hxx>
#include <TopoDS_Vertex.hxx>
#include <ShapeUpgrade_FixSmallBezierCurves.hxx>
#include <ShapeUpgrade_FixSmallBezierCurves.hxx>
#include <ShapeUpgrade_FixSmallBezierCurves.hxx>
#include <BRepTools.hxx>
//=======================================================================
//function : ShapeUpgrade_ShapeConvertToBezier
//purpose :
//=======================================================================
ShapeUpgrade_ShapeConvertToBezier::ShapeUpgrade_ShapeConvertToBezier()
{
myLevel = 0;
my2dMode = Standard_False;
my3dMode = Standard_False;
mySurfaceMode = Standard_False;
//set spesial flags to true
my3dLineMode = Standard_True;
my3dCircleMode = Standard_True;
my3dConicMode = Standard_True;
myPlaneMode = Standard_True;
myRevolutionMode = Standard_True;
myExtrusionMode = Standard_True;
myBSplineMode = Standard_True;
}
//=======================================================================
//function : ShapeUpgrade_ShapeConvertToBezier
//purpose :
//=======================================================================
ShapeUpgrade_ShapeConvertToBezier::ShapeUpgrade_ShapeConvertToBezier(const TopoDS_Shape& S):
ShapeUpgrade_ShapeDivide(S)
{
myLevel = 0;
my2dMode = Standard_False;
my3dMode = Standard_False;
mySurfaceMode = Standard_False;
//set spesial flags to true
my3dLineMode = Standard_True;
my3dCircleMode = Standard_True;
my3dConicMode = Standard_True;
myPlaneMode = Standard_True;
myRevolutionMode = Standard_True;
myExtrusionMode = Standard_True;
myBSplineMode = Standard_True;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::Perform (const Standard_Boolean newContext)
{
myLevel++;
Standard_Boolean res = Standard_False;
if ( myLevel ==1 ) {
Standard_Boolean isNewContext = newContext;
if ( mySurfaceMode ) {
Standard_Boolean mode2d = my2dMode, mode3d = my3dMode;
my2dMode = my3dMode = Standard_False;
res = ShapeUpgrade_ShapeDivide::Perform(isNewContext);
isNewContext = Standard_False;
myShape = myResult;
my2dMode = mode2d;
my3dMode = mode3d;
}
if ( my2dMode || my3dMode ) {
Standard_Boolean modeS = mySurfaceMode;
mySurfaceMode = Standard_False;
res = ShapeUpgrade_ShapeDivide::Perform(isNewContext);
mySurfaceMode = modeS;
}
}
else res = ShapeUpgrade_ShapeDivide::Perform(newContext);
//pdn Hereafter the fix on GeomLib:SameParameter.
//In order to fix this bug all edges that are based on
//bezier curves (2d or 3d) and have range not equal to [0,1]
//are performed the following sequence:
// 1. Segment on bezier curve
// 2. Changing rande of edge to [0,1]
if(myLevel == 1) {
BRep_Builder B;
ShapeAnalysis_Edge sae;
ShapeBuild_Edge sbe;
Standard_Real preci = Precision::PConfusion();
for(TopExp_Explorer exp(myResult,TopAbs_FACE); exp.More(); exp.Next()) {
TopoDS_Face face = TopoDS::Face(exp.Current());
face.Orientation(TopAbs_FORWARD);
for(TopExp_Explorer exp1(face, TopAbs_WIRE); exp1.More(); exp1.Next()) {
TopoDS_Wire wire= TopoDS::Wire(exp1.Current());
Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(wire,face,myPrecision);
sfw->FixReorder();
sfw->FixShifted(); // for cylinders.brep
Handle(ShapeExtend_WireData) sewd = sfw->WireData();
for(Standard_Integer i =1; i <= sewd->NbEdges(); i++) {
TopoDS_Edge edge = sewd->Edge(i);
//TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
Handle(Geom_Curve) c3d;
Standard_Real first, last;
TopoDS_Vertex V1,V2;
TopExp::Vertices(edge,V1,V2);
if(sae.Curve3d(edge,c3d,first,last,Standard_False)) {
if(c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
//B.SameRange(edge, Standard_False);
Handle(Geom_BezierCurve) bezier = Handle(Geom_BezierCurve)::DownCast(c3d);
if(first!= 0 || last !=1) {
if(first > preci || last < 1 - preci) {
bezier->Segment(first,last);
B.UpdateEdge(edge,bezier,0.);
}
sbe.SetRange3d(edge,0,1);
}
if(!bezier.IsNull()) { //gka fix against small edges ; merging ends of 3d curves
gp_Pnt p1 = bezier->Value(first);
gp_Pnt p2 = bezier->Value(last);
gp_Pnt p1v = BRep_Tool::Pnt(V1);
gp_Pnt p2v = BRep_Tool::Pnt(V2);
if(p1.Distance(p1v) > Precision::Confusion())
bezier->SetPole(1,p1v);
if(p2.Distance(p2v) > Precision::Confusion())
bezier->SetPole(bezier->NbPoles(),p2v);
B.UpdateEdge(edge,bezier,0.);
}
}
else if(my2dMode)
B.SameRange(edge, Standard_True);
}
Handle(Geom2d_Curve) c2d,c2drev;
Handle(Geom2d_BezierCurve) bezier,bezierR;
Standard_Boolean isSeam = BRep_Tool::IsClosed ( edge, face );
if(!sae.PCurve(edge,face,c2d,first,last,Standard_False)) continue ;
if(!c2d->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) continue;
Handle(Geom2d_Curve) newRevCurve,newCurve;
bezier = Handle(Geom2d_BezierCurve)::DownCast(c2d);
if(isSeam) {
TopoDS_Shape aLocalShape = edge.Reversed();
TopoDS_Edge tmpedge = TopoDS::Edge(aLocalShape);
// TopoDS_Edge tmpedge = TopoDS::Edge(edge.Reversed());
if(sae.PCurve(tmpedge,face,c2drev,first,last,Standard_False)) {
if(c2drev->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
bezierR = Handle(Geom2d_BezierCurve)::DownCast(c2drev);
}
}
}
if(first!= 0 || last !=1) {
if(first > preci || last < 1 - preci) {
if(!bezier.IsNull()) {
bezier->Segment(first,last);
newCurve = bezier;
}
else
GeomLib::SameRange(preci, c2d, first, last, 0, 1, newCurve);
if(isSeam) {
if(!bezierR.IsNull()) {
bezierR->Segment(first, last);
newRevCurve = bezierR;
}
else if(!c2drev.IsNull())
GeomLib::SameRange(preci, c2drev, first, last, 0, 1, newRevCurve);
if(edge.Orientation()==TopAbs_FORWARD)
B.UpdateEdge ( edge, newCurve, newRevCurve, face, 0. );
else
B.UpdateEdge ( edge, newRevCurve, newCurve, face, 0. );
}
}
B.Range(edge,face,0,1);
}
TopoDS_Edge edgenext = sewd->Edge((i == sewd->NbEdges() ? 1 : i+1));
Handle(Geom2d_Curve) c2dnext,c2drevnext,newnextCurve;
Standard_Real first2,last2;
Handle(Geom2d_BezierCurve) beziernext,bezierRnext;
if(!sae.PCurve(edgenext,face,c2dnext,first2,last2,Standard_False)) continue ;
if(!c2dnext->IsKind(STANDARD_TYPE(Geom2d_BezierCurve)) ) continue;
beziernext = Handle(Geom2d_BezierCurve)::DownCast(c2dnext);
//Handle(Geom2d_Curve) newRevCurve;
if(isSeam) {
TopoDS_Shape aLocalShape = edgenext.Reversed();
TopoDS_Edge tmpedge = TopoDS::Edge(aLocalShape);
// TopoDS_Edge tmpedge = TopoDS::Edge(edgenext.Reversed());
if(sae.PCurve(tmpedge,face,c2drevnext,first,last,Standard_False)) {
if(c2drevnext->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
bezierRnext = Handle(Geom2d_BezierCurve)::DownCast(c2drevnext);
}
}
}
if(first2!= 0 || last2 !=1) {
if(first2 > preci || last2 < 1 - preci) {
if(!beziernext.IsNull()) {
beziernext->Segment(first2,last2);
newnextCurve = beziernext;
}
else
GeomLib::SameRange(preci, c2dnext, first2, last2, 0, 1, newnextCurve);
if(isSeam) {
if(!bezierRnext.IsNull()) {
bezierRnext->Segment(first2, last2);
newRevCurve = bezierRnext;
}
else if(!c2drevnext.IsNull())
GeomLib::SameRange(preci, c2drevnext, first2, last2, 0, 1, newRevCurve);
if(edge.Orientation()==TopAbs_FORWARD)
B.UpdateEdge ( edgenext, newnextCurve, newRevCurve, face, 0. );
else
B.UpdateEdge ( edgenext, newRevCurve, newnextCurve, face, 0. );
}
}
B.Range(edgenext,face,0,1);
}
if(bezier.IsNull() || beziernext.IsNull() ) continue; //gka fix against small edges ; merging ends of pcurves
Standard_Real f1,l1,f2,l2;
f1 = bezier->FirstParameter();
l1 = bezier->LastParameter();
f2 = beziernext->FirstParameter();
l2 = beziernext->LastParameter();
gp_Pnt2d p2d1 = bezier->Value(f1);
gp_Pnt2d p2d2 = bezier->Value(l1);
gp_Pnt2d p2d1next = beziernext->Value(f2);
gp_Pnt2d p2d2next = beziernext->Value(l2);
if(edge.Orientation() == TopAbs_FORWARD && edgenext.Orientation() == TopAbs_FORWARD) {
if(p2d2.Distance(p2d1next) > Precision::PConfusion()) {
gp_Pnt2d pmid = 0.5*(p2d2.XY() + p2d1next.XY());
// gp_Pnt2d p1 = bezier->Pole(bezier->NbPoles());
// gp_Pnt2d p2 = beziernext->Pole(1);
bezier->SetPole(bezier->NbPoles(),pmid);
beziernext->SetPole(1,pmid);
}
}
if(edge.Orientation() == TopAbs_FORWARD && edgenext.Orientation() == TopAbs_REVERSED) {
if(p2d2.Distance(p2d2next) > Precision::PConfusion()) {
gp_Pnt2d pmid = 0.5*(p2d2.XY() + p2d2next.XY());
// gp_Pnt2d p1 = bezier->Pole(bezier->NbPoles());
// gp_Pnt2d p2 = beziernext->Pole(beziernext->NbPoles());
bezier->SetPole(bezier->NbPoles(),pmid);
beziernext->SetPole(beziernext->NbPoles(),pmid);
}
}
if(edge.Orientation() == TopAbs_REVERSED && edgenext.Orientation() == TopAbs_FORWARD) {
if(p2d1.Distance(p2d1next) > Precision::PConfusion()) {
gp_Pnt2d pmid = 0.5*(p2d1.XY() + p2d1next.XY());
// gp_Pnt2d p1 = bezier->Pole(1);
// gp_Pnt2d p2 = beziernext->Pole(1);
bezier->SetPole(1,pmid);
beziernext->SetPole(1,pmid);
}
}
if(edge.Orientation() == TopAbs_REVERSED && edgenext.Orientation() == TopAbs_REVERSED) {
if(p2d1.Distance(p2d2next) > Precision::PConfusion()) {
gp_Pnt2d pmid = 0.5*(p2d1.XY() + p2d2next.XY());
// gp_Pnt2d p1 = bezier->Pole(1);
// gp_Pnt2d p2 = beziernext->Pole(beziernext->NbPoles());
bezier->SetPole(1,pmid);
beziernext->SetPole(beziernext->NbPoles(),pmid);
}
}
}
BRepTools::Update(face);
}
}
}
myLevel--;
return res;
}
//=======================================================================
//function : GetSplitFaceTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_FaceDivide) ShapeUpgrade_ShapeConvertToBezier::GetSplitFaceTool() const
{
Handle(ShapeUpgrade_FaceDivide) tool = new ShapeUpgrade_FaceDivide;
Handle(ShapeUpgrade_WireDivide) wtool = new ShapeUpgrade_WireDivide;
if(my3dMode) {
Handle(ShapeUpgrade_ConvertCurve3dToBezier) curve3dConverter = new ShapeUpgrade_ConvertCurve3dToBezier;
curve3dConverter->SetLineMode(my3dLineMode);
curve3dConverter->SetCircleMode(my3dCircleMode);
curve3dConverter->SetConicMode(my3dConicMode);
wtool->SetSplitCurve3dTool(curve3dConverter);
}
if(my2dMode)
wtool->SetSplitCurve2dTool(new ShapeUpgrade_ConvertCurve2dToBezier);
wtool->SetEdgeMode(myEdgeMode);
Handle(ShapeUpgrade_FixSmallBezierCurves) FixSmallBezierCurvesTool = new ShapeUpgrade_FixSmallBezierCurves;
wtool->SetFixSmallCurveTool(FixSmallBezierCurvesTool);
tool->SetWireDivideTool(wtool);
if(mySurfaceMode) {
Handle(ShapeUpgrade_ConvertSurfaceToBezierBasis) stool = new ShapeUpgrade_ConvertSurfaceToBezierBasis;
stool->SetPlaneMode(myPlaneMode);
stool->SetRevolutionMode(myRevolutionMode);
stool->SetExtrusionMode(myExtrusionMode);
stool->SetBSplineMode(myBSplineMode);
tool->SetSplitSurfaceTool(stool);
}
return tool;
}

View File

@@ -0,0 +1,204 @@
// File: ShapeUpgrade_ShapeConvertToBezier.lxx
// Created: Tue Jun 22 16:45:19 1999
// Author: data exchange team
// <det@friendox>
//=======================================================================
//function : Set2dConversion
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::Set2dConversion(const Standard_Boolean mode)
{
my2dMode = mode;
}
//=======================================================================
//function : Get2dConversion
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::Get2dConversion() const
{
return my2dMode;
}
//=======================================================================
//function : Set3dConversion
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::Set3dConversion(const Standard_Boolean mode)
{
my3dMode = mode;
}
//=======================================================================
//function : Get3dConversion
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::Get3dConversion() const
{
return my3dMode;
}
//=======================================================================
//function : SetSurfaceConversion
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::SetSurfaceConversion(const Standard_Boolean mode)
{
mySurfaceMode = mode;
}
//=======================================================================
//function : GetSurfaceConversion
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::GetSurfaceConversion() const
{
return mySurfaceMode;
}
//=======================================================================
//function : Set3dLineConversion
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::Set3dLineConversion(const Standard_Boolean mode)
{
my3dLineMode = mode;
}
//=======================================================================
//function : Get3dLineConversion
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::Get3dLineConversion() const
{
return my3dLineMode;
}
//=======================================================================
//function : Set3dCircleConversion
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::Set3dCircleConversion(const Standard_Boolean mode)
{
my3dCircleMode = mode;
}
//=======================================================================
//function : Get3dCircleConversion
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::Get3dCircleConversion() const
{
return my3dCircleMode;
}
//=======================================================================
//function : Set3dConicConversion
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::Set3dConicConversion(const Standard_Boolean mode)
{
my3dConicMode = mode;
}
//=======================================================================
//function : Get3dConicConversion
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::Get3dConicConversion() const
{
return my3dConicMode;
}
//=======================================================================
//function : SetPlaneMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::SetPlaneMode(const Standard_Boolean mode)
{
myPlaneMode = mode;
}
//=======================================================================
//function : GetPlaneMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::GetPlaneMode() const
{
return myPlaneMode;
}
//=======================================================================
//function : SetRevolutionMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::SetRevolutionMode(const Standard_Boolean mode)
{
myRevolutionMode = mode;
}
//=======================================================================
//function : GetRevolutionMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::GetRevolutionMode() const
{
return myRevolutionMode;
}
//=======================================================================
//function : SetExtrusionMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::SetExtrusionMode(const Standard_Boolean mode)
{
myExtrusionMode = mode;
}
//=======================================================================
//function : GetExtrusionMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::GetExtrusionMode() const
{
return myExtrusionMode;
}
//=======================================================================
//function : SetBSplineMode
//purpose :
//=======================================================================
inline void ShapeUpgrade_ShapeConvertToBezier::SetBSplineMode(const Standard_Boolean mode)
{
myBSplineMode = mode;
}
//=======================================================================
//function : GetBSplineMode
//purpose :
//=======================================================================
inline Standard_Boolean ShapeUpgrade_ShapeConvertToBezier::GetBSplineMode() const
{
return myBSplineMode;
}

View File

@@ -0,0 +1,98 @@
-- File: ShapeUpgrade_ShapeDivide.cdl
-- Created: Mon Apr 26 17:54:01 1999
-- Author: Pavel DURANDIN
-- <pdn@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class ShapeDivide from ShapeUpgrade
---Purpose: Divides a all faces in shell with given criteria Shell.
uses
Shape from TopoDS,
Status from ShapeExtend,
ReShape from ShapeBuild,
FaceDivide from ShapeUpgrade
is
Create returns ShapeDivide from ShapeUpgrade;
---Purpose:
Create (S: Shape from TopoDS)
returns ShapeDivide from ShapeUpgrade;
---Purpose: Initialize by a Shape.
Init (me: in out; S: Shape from TopoDS);
---Purpose: Initialize by a Shape.
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~ShapeUpgrade_ShapeDivide(){Delete();}"
SetPrecision (me: in out; Prec: Real);
---Purpose: Defines the spatial precision used for splitting
SetMaxTolerance(me: in out; maxtol: Real);
---Purpose: Sets maximal allowed tolerance
SetMinTolerance (me: in out; mintol: Real);
---Purpose: Sets minimal allowed tolerance
SetSurfaceSegmentMode(me: in out; Segment: Boolean);
---Purpose: Purpose sets mode for trimming (segment) surface by
-- wire UV bounds.
Perform (me: in out; newContext: Boolean = Standard_True)
returns Boolean is virtual;
---Purpose: Performs splitting and computes the resulting shape
-- If newContext is True (default), the internal context
-- will be cleared at start, else previous substitutions
-- will be acting.
Result (me) returns Shape from TopoDS;
---Purpose: Gives the resulting Shape, or Null shape if not done.
GetContext (me) returns ReShape from ShapeBuild;
---Purpose: Returns context with all the modifications made during
-- last call(s) to Perform() recorded
SetContext (me: in out; context: ReShape from ShapeBuild);
---Purpose: Sets context with recorded modifications to be applied
-- during next call(s) to Perform(shape,Standard_False)
Status (me; status: Status from ShapeExtend) returns Boolean;
---Purpose: Queries the status of last call to Perform
-- OK : no splitting was done (or no call to Perform)
-- DONE1: some edges were splitted
-- DONE2: surface was splitted
-- FAIL1: some errors occured
---Level: Internal
SetSplitFaceTool (me: in out; splitFaceTool: FaceDivide from ShapeUpgrade);
---Purpose: Sets the tool for splitting faces.
GetSplitFaceTool (me) returns FaceDivide from ShapeUpgrade
is virtual protected;
---Purpose: Returns the tool for splitting faces.
SetEdgeMode(me: in out; aEdgeMode : Integer);
---Purpose:Sets mode for splitting 3d curves from edges.
-- 0 - only curve 3d from free edges.
-- 1 - only curve 3d from shared edges.
-- 2 - all curve 3d.
fields
mySplitFaceTool: FaceDivide from ShapeUpgrade;
myContext : ReShape from ShapeBuild is protected;
myShape : Shape from TopoDS is protected;
myResult : Shape from TopoDS is protected;
myPrecision : Real is protected;
myMinTol : Real is protected;
myMaxTol : Real is protected;
mySegmentMode: Boolean is protected;
myStatus : Integer is protected;
myEdgeMode: Integer is protected;
end ShapeDivide;

View File

@@ -0,0 +1,341 @@
// File: ShapeUpgrade_ShapeDivide.cxx
// Created: Tue Apr 27 09:37:14 1999
// Author: Pavel DURANDIN
// <pdn@friendox.nnov.matra-dtv.fr>
// abv 16.06.99 returning ReShape context; processing shared subshapes in compounds
// sln 29.11.01 Bug21: in method Perform(..) nullify location of compound's faces only if mode myConsiderLocation is on
#include <ShapeUpgrade_ShapeDivide.ixx>
#include <Precision.hxx>
#include <ShapeExtend.hxx>
#include <ShapeBuild_ReShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Builder.hxx>
#include <ShapeUpgrade_WireDivide.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
//=======================================================================
//function : ShapeUpgrade_ShapeDivide
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivide::ShapeUpgrade_ShapeDivide() : myStatus(0)
{
myPrecision = myMinTol = Precision::Confusion();
myMaxTol = 1; //Precision::Infinite() ?? pdn
mySplitFaceTool = new ShapeUpgrade_FaceDivide;
myContext = new ShapeBuild_ReShape;
mySegmentMode = Standard_True;
myEdgeMode = 2;
}
//=======================================================================
//function : ShapeUpgrade_ShapeDivide
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivide::ShapeUpgrade_ShapeDivide(const TopoDS_Shape &S) : myStatus(0)
{
myPrecision = myMinTol = Precision::Confusion();
myMaxTol = 1; //Precision::Infinite() ?? pdn
mySplitFaceTool = new ShapeUpgrade_FaceDivide;
myContext = new ShapeBuild_ReShape;
mySegmentMode = Standard_True;
myEdgeMode = 2;
Init(S);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::Init(const TopoDS_Shape &S)
{
myShape = S;
}
//=======================================================================
//function : Delete
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::Delete()
{}
//=======================================================================
//function : SetPrecision
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::SetPrecision (const Standard_Real Prec)
{
myPrecision = Prec;
}
//=======================================================================
//function : SetMaxTolerance
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::SetMaxTolerance (const Standard_Real maxtol)
{
myMaxTol = maxtol;
}
//=======================================================================
//function : SetMinTolerance
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::SetMinTolerance (const Standard_Real mintol)
{
myMinTol = mintol;
}
//=======================================================================
//function : SetSurfaceSegmentMode
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::SetSurfaceSegmentMode(const Standard_Boolean Segment)
{
mySegmentMode = Segment;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_ShapeDivide::Perform(const Standard_Boolean newContext)
{
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
if(myShape.IsNull()) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
return Standard_False;
}
if ( newContext || myContext.IsNull() )
myContext = new ShapeBuild_ReShape;
// Process COMPOUNDs separately in order to handle sharing in assemblies
// NOTE: not optimized: subshape can be processed twice (second time - no modif)
if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
Standard_Integer locStatus = myStatus;
TopoDS_Compound C;
BRep_Builder B;
B.MakeCompound ( C );
TopoDS_Shape savShape = myShape;
for ( TopoDS_Iterator it(savShape,Standard_False); it.More(); it.Next() ) {
TopoDS_Shape shape = it.Value();
TopLoc_Location L = shape.Location();
if(myContext->ModeConsiderLocation()) {
TopLoc_Location nullLoc;
shape.Location ( nullLoc );
}
myShape = myContext->Apply ( shape );
Perform ( Standard_False );
if(myContext->ModeConsiderLocation())
myResult.Location ( L );
myResult.Orientation(TopAbs::Compose(myResult.Orientation(),savShape.Orientation()));
B.Add ( C, myResult );
locStatus |= myStatus;
}
myShape = savShape;
myStatus = locStatus;
if ( Status ( ShapeExtend_DONE ) ) {
myResult = myContext->Apply ( C, TopAbs_SHAPE );
myContext->Replace ( myShape, myResult );
return Standard_True;
}
myResult = myShape;
return Standard_False;
}
// Process FACEs
Handle(ShapeUpgrade_FaceDivide) SplitFace = GetSplitFaceTool();
if ( ! SplitFace.IsNull() ) {
SplitFace->SetPrecision( myPrecision );
SplitFace->SetMaxTolerance(myMaxTol);
SplitFace->SetSurfaceSegmentMode(mySegmentMode);
Handle(ShapeUpgrade_WireDivide) SplitWire = SplitFace->GetWireDivideTool();
if ( ! SplitWire.IsNull() ) {
SplitWire->SetMinTolerance(myMinTol);
SplitWire->SetEdgeMode(myEdgeMode);
}
for(TopExp_Explorer exp(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
//smh#8
TopoDS_Shape tmpF = exp.Current().Oriented ( TopAbs_FORWARD );
TopoDS_Face F = TopoDS::Face (tmpF); // protection against INTERNAL shapes: cts20105a.rle
TopoDS_Shape sh = myContext->Apply ( F, TopAbs_SHAPE );
for (TopExp_Explorer exp2(sh,TopAbs_FACE); exp2.More(); exp2.Next()) {
//szv: try-catch added
try {
OCC_CATCH_SIGNALS
for (; exp2.More(); exp2.Next()) {
TopoDS_Face face = TopoDS::Face ( exp2.Current() );
SplitFace->Init(face);
SplitFace->SetContext(myContext);
SplitFace->Perform();
if(SplitFace->Status(ShapeExtend_FAIL)) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
}
if(SplitFace->Status(ShapeExtend_DONE)) {
myContext->Replace(face,SplitFace->Result());
if(SplitFace->Status(ShapeExtend_DONE1))
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
if(SplitFace->Status(ShapeExtend_DONE2))
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
}
}
}
catch (Standard_Failure) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
#ifdef DEB
cout << "\nError: Exception in ShapeUpgrade_FaceDivide::Perform(): ";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
}
}
}
}
// Process free WIREs
Handle(ShapeUpgrade_WireDivide) SplitWire = SplitFace->GetWireDivideTool();
if ( ! SplitWire.IsNull() ) {
SplitWire->SetFace (TopoDS_Face());
SplitWire->SetPrecision( myPrecision );
SplitWire->SetMaxTolerance(myMaxTol);
SplitWire->SetMinTolerance(myMinTol);
SplitWire->SetEdgeMode(myEdgeMode);
TopExp_Explorer exp;//svv Jan 10 2000 : porting on DEC
for (exp.Init (myShape, TopAbs_WIRE, TopAbs_FACE); exp.More(); exp.Next()) {
//smh#8
TopoDS_Shape tmpW = exp.Current().Oriented ( TopAbs_FORWARD );
TopoDS_Wire W = TopoDS::Wire (tmpW ); // protection against INTERNAL shapes
TopoDS_Shape sh = myContext->Apply ( W, TopAbs_SHAPE );
for (TopExp_Explorer exp2 (sh,TopAbs_WIRE); exp2.More(); exp2.Next()) {
TopoDS_Wire wire = TopoDS::Wire ( exp2.Current() );
SplitWire->Load (wire);
SplitWire->SetContext(myContext);
SplitWire->Perform();
if(SplitWire->Status(ShapeExtend_FAIL)) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
}
if(SplitWire->Status(ShapeExtend_DONE)) {
myContext->Replace(wire,SplitWire->Wire());
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
}
}
}
// Process free EDGEs
for (exp.Init (myShape, TopAbs_EDGE, TopAbs_WIRE); exp.More(); exp.Next()) {
//smh#8
TopoDS_Shape tmpE = exp.Current().Oriented ( TopAbs_FORWARD );
TopoDS_Edge E = TopoDS::Edge (tmpE ); // protection against INTERNAL shapes
TopoDS_Vertex V1,V2;
TopExp::Vertices(E,V2,V1);
if( V1.IsNull() && V2.IsNull() ) continue; // skl 27.10.2004 for OCC5624
TopoDS_Shape sh = myContext->Apply ( E, TopAbs_SHAPE );
for (TopExp_Explorer exp2 (sh,TopAbs_EDGE); exp2.More(); exp2.Next()) {
TopoDS_Edge edge = TopoDS::Edge ( exp2.Current() );
SplitWire->Load (edge);
SplitWire->SetContext(myContext);
SplitWire->Perform();
if(SplitWire->Status(ShapeExtend_FAIL)) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
}
if(SplitWire->Status(ShapeExtend_DONE)) {
myContext->Replace(edge,SplitWire->Wire());
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
}
}
}
}
myResult = myContext->Apply ( myShape, TopAbs_SHAPE );
return ! myResult.IsSame ( myShape );
}
//=======================================================================
//function : Result
//purpose :
//=======================================================================
TopoDS_Shape ShapeUpgrade_ShapeDivide::Result() const
{
return myResult;
}
//=======================================================================
//function : GetContext
//purpose :
//=======================================================================
Handle(ShapeBuild_ReShape) ShapeUpgrade_ShapeDivide::GetContext() const
{
//if ( myContext.IsNull() ) myContext = new ShapeBuild_ReShape;
return myContext;
}
//=======================================================================
//function : SetContext
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::SetContext (const Handle(ShapeBuild_ReShape) &context)
{
myContext = context;
}
//=======================================================================
//function : SetSplitFaceTool
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::SetSplitFaceTool(const Handle(ShapeUpgrade_FaceDivide)& splitFaceTool)
{
mySplitFaceTool = splitFaceTool;
}
//=======================================================================
//function : GetSplitFaceTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_FaceDivide) ShapeUpgrade_ShapeDivide::GetSplitFaceTool () const
{
return mySplitFaceTool;
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_ShapeDivide::Status (const ShapeExtend_Status status) const
{
return ShapeExtend::DecodeStatus ( myStatus, status );
}
//=======================================================================
//function : SetEdgeMode
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivide::SetEdgeMode(const Standard_Integer aEdgeMode)
{
myEdgeMode = aEdgeMode;
}

View File

@@ -0,0 +1,36 @@
-- File: ShapeUpgrade_ShapeDivideAngle.cdl
-- Created: Thu May 6 10:33:49 1999
-- Author: Pavel DURANDIN
-- <pdn@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class ShapeDivideAngle from ShapeUpgrade inherits ShapeDivide from ShapeUpgrade
---Purpose: Splits all surfaces of revolution, cylindrical, toroidal,
-- conical, spherical surfaces in the given shape so that
-- each resulting segment covers not more than defined number
-- of degrees.
uses
Shape from TopoDS
is
Create (MaxAngle: Real) returns ShapeDivideAngle from ShapeUpgrade;
---Purpose: Empty constructor.
Create (MaxAngle: Real; S: Shape from TopoDS)
returns ShapeDivideAngle from ShapeUpgrade;
---Purpose: Initialize by a Shape.
InitTool (me: in out; MaxAngle: Real);
---Purpose: Resets tool for splitting face with given angle
SetMaxAngle (me: in out; MaxAngle: Real);
---Purpose: Set maximal angle (calls InitTool)
MaxAngle (me) returns Real;
---Purpose: Returns maximal angle
end ShapeDivideAngle;

View File

@@ -0,0 +1,69 @@
// File: ShapeUpgrade_ShapeDivideAngle.cxx
// Created: Thu May 6 10:38:17 1999
// Author: Pavel DURANDIN
// <pdn@friendox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_ShapeDivideAngle.ixx>
#include <ShapeUpgrade_SplitSurfaceAngle.hxx>
#include <ShapeUpgrade_FaceDivide.hxx>
//=======================================================================
//function : ShapeUpgrade_ShapeDivideAngle
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideAngle::ShapeUpgrade_ShapeDivideAngle (const Standard_Real MaxAngle)
{
InitTool ( MaxAngle );
}
//=======================================================================
//function : ShapeUpgrade_ShapeDivideAngle
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideAngle::ShapeUpgrade_ShapeDivideAngle(const Standard_Real MaxAngle,
const TopoDS_Shape& S):
ShapeUpgrade_ShapeDivide(S)
{
InitTool ( MaxAngle );
}
//=======================================================================
//function : InitTool
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideAngle::InitTool (const Standard_Real MaxAngle)
{
Handle(ShapeUpgrade_FaceDivide) tool = GetSplitFaceTool();
tool->SetSplitSurfaceTool ( new ShapeUpgrade_SplitSurfaceAngle (MaxAngle) );
tool->SetWireDivideTool ( 0 ); // no splitting of wire
SetSplitFaceTool(tool);
}
//=======================================================================
//function : SetMaxAngle
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideAngle::SetMaxAngle (const Standard_Real MaxAngle)
{
InitTool ( MaxAngle );
}
//=======================================================================
//function : MaxAngle
//purpose :
//=======================================================================
double ShapeUpgrade_ShapeDivideAngle::MaxAngle () const
{
Handle(ShapeUpgrade_FaceDivide) faceTool = GetSplitFaceTool();
if ( faceTool.IsNull() ) return 0.;
Handle(ShapeUpgrade_SplitSurfaceAngle) tool =
Handle(ShapeUpgrade_SplitSurfaceAngle)::DownCast ( faceTool );
return ( tool.IsNull() ? 0. : tool->MaxAngle() );
}

View File

@@ -0,0 +1,40 @@
-- File: ShapeUpgrade_ShapeDivideArea.cdl
-- Created: Tue Aug 8 11:40:33 2006
-- Author: Galina KULIKOVA
-- <gka@zamox.nnov.matra-dtv.fr>
---Copyright: Open CASCADE 2006
class ShapeDivideArea from ShapeUpgrade inherits ShapeDivide from ShapeUpgrade
---Purpose: Divides faces from sprcified shape by max area criterium.
uses
Shape from TopoDS,
FaceDivide from ShapeUpgrade
is
Create returns ShapeDivideArea from ShapeUpgrade;
---Purpose:
Create (S: Shape from TopoDS)
returns ShapeDivideArea from ShapeUpgrade;
---Purpose: Initialize by a Shape.
GetSplitFaceTool (me) returns FaceDivide from ShapeUpgrade
is redefined protected;
---Purpose: Returns the tool for splitting faces.
MaxArea(me: in out) returns Real;
---C++: inline
---C++: return &
---Purpose:Set max area allowed for faces
fields
myMaxArea : Real;
end ShapeDivideArea;

View File

@@ -0,0 +1,39 @@
#include <ShapeUpgrade_ShapeDivideArea.ixx>
#include <ShapeUpgrade_FaceDivideArea.hxx>
#include <Precision.hxx>
//=======================================================================
//function : ShapeUpgrade_ShapeDivideArea
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideArea::ShapeUpgrade_ShapeDivideArea():
ShapeUpgrade_ShapeDivide()
{
myMaxArea = Precision::Infinite();
}
//=======================================================================
//function : ShapeUpgrade_ShapeDivideArea
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideArea::ShapeUpgrade_ShapeDivideArea(const TopoDS_Shape& S):
ShapeUpgrade_ShapeDivide(S)
{
myMaxArea = Precision::Infinite();
}
//=======================================================================
//function : GetSplitFaceTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_FaceDivide) ShapeUpgrade_ShapeDivideArea::GetSplitFaceTool() const
{
Handle(ShapeUpgrade_FaceDivideArea) aFaceTool = new ShapeUpgrade_FaceDivideArea;
aFaceTool->MaxArea() = myMaxArea;
return aFaceTool;
}

View File

@@ -0,0 +1,6 @@
inline Standard_Real& ShapeUpgrade_ShapeDivideArea::MaxArea()
{
return myMaxArea;
}

View File

@@ -0,0 +1,26 @@
-- File: ShapeUpgrade_ShapeDivideClosed.cdl
-- Created: Thu Jul 22 17:58:21 1999
-- Author: data exchange team
-- <det@friendox>
---Copyright: Matra Datavision 1999
class ShapeDivideClosed from ShapeUpgrade inherits ShapeDivide from ShapeUpgrade
---Purpose: Divides all closed faces in the shape. Class
-- ShapeUpgrade_ClosedFaceDivide is used as divide tool.
uses
Shape from TopoDS
is
Create (S: Shape from TopoDS) returns ShapeDivideClosed from ShapeUpgrade;
---Purpose: Initialises tool with shape and default parameter.
SetNbSplitPoints (me: in out; num: Integer);
---Purpose: Sets the number of cuts applied to divide closed faces.
-- The number of resulting faces will be num+1.
end ShapeDivideClosed;

View File

@@ -0,0 +1,32 @@
// File: ShapeUpgrade_ShapeDivideClosed.cxx
// Created: Thu Jul 22 17:59:58 1999
// Author: data exchange team
// <det@friendox>
#include <ShapeUpgrade_ShapeDivideClosed.ixx>
#include <ShapeUpgrade_ClosedFaceDivide.hxx>
//=======================================================================
//function : ShapeUpgrade_ShapeDivideClosed
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideClosed::ShapeUpgrade_ShapeDivideClosed(const TopoDS_Shape& S):
ShapeUpgrade_ShapeDivide(S)
{
SetNbSplitPoints(1);
}
//=======================================================================
//function : SetNbSplitPoints
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideClosed::SetNbSplitPoints(const Standard_Integer num)
{
Handle(ShapeUpgrade_ClosedFaceDivide) tool = new ShapeUpgrade_ClosedFaceDivide;
tool->SetNbSplitPoints(num);
tool->SetWireDivideTool ( 0 ); // no splitting of wire
SetSplitFaceTool(tool);
}

View File

@@ -0,0 +1,25 @@
-- File: ShapeUpgrade_ShapeDivideClosedEdges.cdl
-- Created: Thu May 25 09:59:16 2000
-- Author: data exchange team
-- <det@friendox>
---Copyright: Matra Datavision 2000
class ShapeDivideClosedEdges from ShapeUpgrade inherits ShapeDivide from ShapeUpgrade
---Purpose:
uses
Shape from TopoDS
is
Create (S: Shape from TopoDS) returns ShapeDivideClosedEdges from ShapeUpgrade;
---Purpose: Initialises tool with shape and default parameter.
SetNbSplitPoints (me: in out; num: Integer);
---Purpose: Sets the number of cuts applied to divide closed edges.
-- The number of resulting faces will be num+1.
end ShapeDivideClosedEdges;

View File

@@ -0,0 +1,37 @@
// File: ShapeUpgrade_ShapeDivideClosedEdges.cxx
// Created: Thu May 25 10:01:06 2000
// Author: data exchange team
// <det@friendox>
#include <ShapeUpgrade_ShapeDivideClosedEdges.ixx>
#include <ShapeUpgrade_ClosedEdgeDivide.hxx>
#include <ShapeUpgrade_WireDivide.hxx>
#include <ShapeUpgrade_FaceDivide.hxx>
//=======================================================================
//function : ShapeUpgrade_ShapeDivideClosedEdges
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideClosedEdges::ShapeUpgrade_ShapeDivideClosedEdges(const TopoDS_Shape& S):
ShapeUpgrade_ShapeDivide(S)
{
SetNbSplitPoints(1);
}
//=======================================================================
//function : SetNbSplitPoints
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideClosedEdges::SetNbSplitPoints(const Standard_Integer /*num*/)
{
Handle(ShapeUpgrade_ClosedEdgeDivide) tool = new ShapeUpgrade_ClosedEdgeDivide;
Handle(ShapeUpgrade_WireDivide) wtool = new ShapeUpgrade_WireDivide;
wtool->SetEdgeDivideTool(tool);
Handle(ShapeUpgrade_FaceDivide) ftool = new ShapeUpgrade_FaceDivide;
ftool->SetWireDivideTool(wtool);
ftool->SetSplitSurfaceTool( 0 );
SetSplitFaceTool(ftool);
}

View File

@@ -0,0 +1,72 @@
-- File: ShapeUpgrade_ShapeDivideContinuity.cdl
-- Created: Fri Apr 30 17:01:47 1999
-- Author: data exchange team
-- <det@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class ShapeDivideContinuity from ShapeUpgrade inherits ShapeDivide from ShapeUpgrade
---Purpose:
uses
Shape from TopoDS,
Shape from GeomAbs,
FaceDivide from ShapeUpgrade
is
Create returns ShapeDivideContinuity from ShapeUpgrade;
Create (S: Shape from TopoDS)
returns ShapeDivideContinuity from ShapeUpgrade;
---Purpose: Initialize by a Shape.
SetTolerance(me: in out; Tol: Real);
---Purpose: Sets tolerance.
SetTolerance2d(me: in out; Tol: Real);
---Purpose: Sets tolerance.
SetBoundaryCriterion (me: in out; Criterion: Shape from GeomAbs = GeomAbs_C1);
---Purpose:
-- Defines a criterion of continuity for the boundary (all the
-- Wires)
--
-- The possible values are C0, G1, C1, G2, C2, C3, CN The
-- default is C1 to respect the Cas.Cade Shape Validity. G1
-- and G2 are not authorized.
SetPCurveCriterion (me: in out; Criterion: Shape from GeomAbs = GeomAbs_C1);
---Purpose:
-- Defines a criterion of continuity for the boundary (all the
-- pcurves of Wires)
--
-- The possible values are C0, G1, C1, G2, C2, C3, CN The
-- default is C1 to respect the Cas.Cade Shape Validity. G1
-- and G2 are not authorized.
SetSurfaceCriterion (me: in out; Criterion: Shape from GeomAbs = GeomAbs_C1);
---Purpose:
-- Defines a criterion of continuity for the boundary (all the
-- Wires)
--
-- The possible values are C0, G1, C1, G2, C2, C3, CN The
-- default is C1 to respect the Cas.Cade Shape Validity. G1
-- and G2 are not authorized.
---Level: Internal
GetSplitFaceTool (me) returns FaceDivide from ShapeUpgrade
is redefined protected;
---Purpose: Returns the tool for dividing faces.
fields
myCurve3dCriterion: Shape from GeomAbs;
myCurve2dCriterion: Shape from GeomAbs;
mySurfaceCriterion : Shape from GeomAbs;
myTolerance3d: Real;
myTolerance2d: Real;
end ShapeDivideContinuity;

View File

@@ -0,0 +1,118 @@
// File: ShapeUpgrade_ShapeDivideContinuity.cxx
// Created: Fri Apr 30 17:08:45 1999
// Author: data exchange team
// <det@friendox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_ShapeDivideContinuity.ixx>
#include <Precision.hxx>
#include <ShapeUpgrade_SplitCurve2dContinuity.hxx>
#include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
#include <ShapeUpgrade_SplitSurfaceContinuity.hxx>
#include <ShapeUpgrade_WireDivide.hxx>
#include <ShapeUpgrade_FaceDivide.hxx>
//=======================================================================
//function : ShapeUpgrade_ShapeDivideContinuity
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideContinuity::ShapeUpgrade_ShapeDivideContinuity()
{
myCurve3dCriterion = GeomAbs_C1;
myCurve2dCriterion = GeomAbs_C1;
mySurfaceCriterion = GeomAbs_C1;
myTolerance3d = Precision::Confusion();
myTolerance2d = Precision::PConfusion();
}
//=======================================================================
//function : ShapeUpgrade_ShapeDivideContinuity
//purpose :
//=======================================================================
ShapeUpgrade_ShapeDivideContinuity::ShapeUpgrade_ShapeDivideContinuity(const TopoDS_Shape& S):
ShapeUpgrade_ShapeDivide(S)
{
myCurve3dCriterion = GeomAbs_C1;
myCurve2dCriterion = GeomAbs_C1;
mySurfaceCriterion = GeomAbs_C1;
myTolerance3d = Precision::Confusion();
myTolerance2d = Precision::PConfusion();
}
//=======================================================================
//function : SetTolerance
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideContinuity::SetTolerance(const Standard_Real Tol)
{
myTolerance3d = Tol;
}
//=======================================================================
//function : SetTolerance2d
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideContinuity::SetTolerance2d(const Standard_Real Tol)
{
myTolerance2d = Tol;
}
//=======================================================================
//function : SetBoundaryCriterion
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideContinuity::SetBoundaryCriterion(const GeomAbs_Shape Criterion)
{
myCurve3dCriterion = Criterion;
}
//=======================================================================
//function : SetPCurveCriterion
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideContinuity::SetPCurveCriterion(const GeomAbs_Shape Criterion)
{
myCurve2dCriterion = Criterion;
}
//=======================================================================
//function : SetSurfaceCriterion
//purpose :
//=======================================================================
void ShapeUpgrade_ShapeDivideContinuity::SetSurfaceCriterion(const GeomAbs_Shape Criterion)
{
mySurfaceCriterion = Criterion;
}
//=======================================================================
//function : GetSplitFaceTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_FaceDivide) ShapeUpgrade_ShapeDivideContinuity::GetSplitFaceTool() const
{
Handle(ShapeUpgrade_SplitCurve2dContinuity) theSplitCurve2dTool = new ShapeUpgrade_SplitCurve2dContinuity;
Handle(ShapeUpgrade_SplitCurve3dContinuity) theSplitCurve3dTool = new ShapeUpgrade_SplitCurve3dContinuity;
Handle(ShapeUpgrade_SplitSurfaceContinuity) theSplitSurfaceTool = new ShapeUpgrade_SplitSurfaceContinuity;
theSplitCurve2dTool->SetCriterion (myCurve2dCriterion);
theSplitCurve3dTool->SetCriterion (myCurve3dCriterion);
theSplitSurfaceTool->SetCriterion (mySurfaceCriterion);
theSplitCurve2dTool->SetTolerance (myTolerance2d);
theSplitCurve3dTool->SetTolerance (myTolerance3d);
theSplitSurfaceTool->SetTolerance (myTolerance3d);
Handle(ShapeUpgrade_WireDivide) theSplitWireTool = new ShapeUpgrade_WireDivide;
theSplitWireTool->SetSplitCurve2dTool ( theSplitCurve2dTool );
theSplitWireTool->SetSplitCurve3dTool ( theSplitCurve3dTool );
Handle(ShapeUpgrade_FaceDivide) theSplitFaceTool = new ShapeUpgrade_FaceDivide;
theSplitFaceTool->SetSplitSurfaceTool ( theSplitSurfaceTool );
theSplitFaceTool->SetWireDivideTool ( theSplitWireTool );
return theSplitFaceTool;
}

View File

@@ -0,0 +1,47 @@
-- File: ShapeUpgrade_ShellSewing.cdl
-- Created: Wed Jun 3 12:39:36 1998
-- Author: data exchange team
-- <det@loufox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1998
class ShellSewing from ShapeUpgrade
---Purpose: This class provides a tool for applying sewing algorithm from
-- BRepAlgo: it takes a shape, calls sewing for each shell,
-- and then replaces sewed shells with use of ShapeBuild_ReShape
uses
Shape from TopoDS,
IndexedMapOfShape from TopTools,
ReShape from ShapeBuild
is
Create returns ShellSewing;
---Purpose: Creates a ShellSewing, empty
ApplySewing (me: in out; shape: Shape from TopoDS; tol: Real = 0.0)
returns Shape from TopoDS;
---Purpose: Builds a new shape from a former one, by calling Sewing from
-- BRepOffsetAPI. Rebuilt solids are oriented to be "not infinite"
--
-- If <tol> is not given (i.e. value 0. by default), it is
-- computed as the mean tolerance recorded in <shape>
--
-- If no shell has been sewed, this method returns the input
-- shape
Init (me: in out; shape: Shape from TopoDS) is private;
Prepare (me: in out; tol: Real) returns Integer is private;
Apply (me: in out; shape: Shape from TopoDS; tol: Real)
returns Shape from TopoDS is private;
fields
myShells: IndexedMapOfShape from TopTools;
myReShape: ReShape from ShapeBuild;
end ShellSewing;

View File

@@ -0,0 +1,108 @@
//szv#4 S4163
#include <ShapeUpgrade_ShellSewing.ixx>
#include <TopoDS.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRepClass3d_SolidClassifier.hxx>
#include <ShapeAnalysis_ShapeTolerance.hxx>
//=======================================================================
//function : ShapeUpgrade_ShellSewing
//purpose :
//=======================================================================
ShapeUpgrade_ShellSewing::ShapeUpgrade_ShellSewing()
{
myReShape = new ShapeBuild_ReShape;
}
//=======================================================================
//function : ApplySewing
//purpose :
//=======================================================================
void ShapeUpgrade_ShellSewing::Init (const TopoDS_Shape& shape)
{
if (shape.IsNull()) return;
if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape);
else {
for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) {
myShells.Add (exs.Current());
}
}
}
//=======================================================================
//function : Prepare
//purpose :
//=======================================================================
Standard_Integer ShapeUpgrade_ShellSewing::Prepare (const Standard_Real tol)
{
Standard_Integer nb = myShells.Extent(), ns = 0;
for ( Standard_Integer i = 1; i <= nb; i ++) {
TopoDS_Shell sl = TopoDS::Shell ( myShells.FindKey (i) );
BRepBuilderAPI_Sewing ss ( tol );
TopExp_Explorer exp(sl,TopAbs_FACE);
for (; exp.More(); exp.Next()) ss.Add(exp.Current());
ss.Perform();
TopoDS_Shape newsh = ss.SewedShape();
if (!newsh.IsNull()) { myReShape->Replace (sl,newsh); ns ++; }
}
return ns;
}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
TopoDS_Shape ShapeUpgrade_ShellSewing::Apply (const TopoDS_Shape& shape,
const Standard_Real tol)
{
if ( shape.IsNull() || myShells.Extent() == 0 ) return shape;
TopoDS_Shape res = myReShape->Apply ( shape, TopAbs_FACE, 2 );
// A present orienter les solides correctement
myReShape->Clear();
Standard_Integer ns = 0;
for (TopExp_Explorer exd (shape,TopAbs_SOLID); exd.More(); exd.Next()) {
TopoDS_Solid sd = TopoDS::Solid ( exd.Current() );
BRepClass3d_SolidClassifier bsc3d (sd);
bsc3d.PerformInfinitePoint ( tol );
if (bsc3d.State() == TopAbs_IN) { myReShape->Replace (sd,sd.Reversed()); ns++; }
}
//szv#4:S4163:12Mar99 optimized
if (ns != 0) res = myReShape->Apply( res, TopAbs_SHELL, 2 );
return res;
}
//=======================================================================
//function : ApplySewing
//purpose :
//=======================================================================
TopoDS_Shape ShapeUpgrade_ShellSewing::ApplySewing (const TopoDS_Shape& shape,
const Standard_Real tol)
{
if (shape.IsNull()) return shape;
Standard_Real t = tol;
if (t <= 0.) {
ShapeAnalysis_ShapeTolerance stu;
t = stu.Tolerance (shape,0); // tolerance moyenne
}
Init ( shape );
if ( Prepare ( t ) ) return Apply ( shape, t );
return TopoDS_Shape();
}

View File

@@ -0,0 +1,65 @@
-- File: ShapeUpgrade_SplitCurve.cdl
-- Created: Thu Mar 12 11:14:13 1998
-- Author: Pierre BARRAS
-- <pbs@sgi84>
---Copyright: Matra Datavision 1998
class SplitCurve from ShapeUpgrade inherits TShared from MMgt
---Purpose: Splits a curve with a criterion.
uses
Curve from Geom,
HArray1OfCurve from TColGeom,
HSequenceOfReal from TColStd,
Shape from GeomAbs,
Status from ShapeExtend
is
Create returns mutable SplitCurve from ShapeUpgrade;
---Purpose: Empty constructor.
Init (me: mutable; First, Last: Real);
---Purpose: Initializes with curve first and last parameters.
SetSplitValues (me: mutable; SplitValues: HSequenceOfReal from TColStd);
---Purpose: Sets the parameters where splitting has to be done.
Build (me: mutable; Segment: Boolean) is virtual;
---Purpose: If Segment is True, the result is composed with
-- segments of the curve bounded by the SplitValues. If
-- Segment is False, the result is composed with trimmed
-- Curves all based on the same complete curve.
--
SplitValues(me) returns HSequenceOfReal from TColStd;
---C++: return const &
--- Purpose : returns all the splitting values including the
-- First and Last parameters of the input curve
---Level: Internal
--PrepareKnots (me: mutable) is protected;
---Purpose: Merges input split values and new ones into myGlobalKnots
Compute(me: mutable) is virtual;
---Purpose: Calculates points for correction/splitting of the curve
Perform(me: mutable; Segment: Boolean = Standard_True);
---Purpose: Performs correction/splitting of the curve.
--- First defines splitting values by method Compute(), then calls method Build().
Status (me; status: Status from ShapeExtend) returns Boolean;
---Purpose: Returns the status
-- OK - no splitting is needed
-- DONE1 - splitting required and gives more than one segment
-- DONE2 - splitting is required, but gives only one segment (initial)
-- DONE3 - geometric form of the curve or parametrisation is modified
fields
mySplitValues : HSequenceOfReal from TColStd is protected;
myNbCurves : Integer is protected;
myStatus : Integer is protected;
end;

View File

@@ -0,0 +1,120 @@
// File: ShapeUpgrade_SplitCurve.cxx
// Created: Thu Mar 12 12:26:05 1998
// Author: Pierre BARRAS
// <pbs@sgi84>
// gka 30.04.99 S4137: re-worked
#include <ShapeUpgrade_SplitCurve.ixx>
#include <Geom_BSplineCurve.hxx>
#include <Precision.hxx>
#include <ShapeUpgrade.hxx>
#include <TColStd_ListIteratorOfListOfReal.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <ShapeExtend.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitCurve
//purpose :
//=======================================================================
ShapeUpgrade_SplitCurve::ShapeUpgrade_SplitCurve() : myStatus(0)
{
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve::Init(const Standard_Real First,
const Standard_Real Last)
{
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
// if (ShapeUpgrade::Debug()) cout << "SplitCurve::Init"<<endl;
myNbCurves = 1;
// mySplitValues.Clear();
mySplitValues = new TColStd_HSequenceOfReal;
mySplitValues->Append(First);
mySplitValues->Append(Last);
}
//=======================================================================
//function : SetSplitValues
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve::SetSplitValues (const Handle(TColStd_HSequenceOfReal& SplitValues))
{
Standard_Real precision = Precision::PConfusion();
if(SplitValues.IsNull()) return;
if(SplitValues->Length()==0) return;
Standard_Real First = mySplitValues->Value(1),
Last = mySplitValues->Value(mySplitValues->Length());
Standard_Integer i =1;
Standard_Integer len = SplitValues->Length();
for( Standard_Integer k = 2;k <= mySplitValues->Length();k++) {
Last = mySplitValues->Value(k);
for(; i <= len; i++) {
if( (First + precision) >= SplitValues->Value(i)) continue;
if((Last - precision) <= SplitValues->Value(i)) break;
mySplitValues->InsertBefore(k++,SplitValues->Value(i));
}
First = Last;
}
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve::Build(const Standard_Boolean /*Segment*/)
{
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
}
//=======================================================================
//function : GlobalKnots
//purpose :
//=======================================================================
const Handle(TColStd_HSequenceOfReal)& ShapeUpgrade_SplitCurve::SplitValues() const
{
return mySplitValues;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve::Perform(const Standard_Boolean Segment)
{
Compute();
//if ( ! mySplitValues.IsNull() )
// SetSplitValues(mySplitValues);
Build(Segment);
}
//=======================================================================
//function : Compute
//purpose :
//===================================================================
void ShapeUpgrade_SplitCurve::Compute()
{
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_SplitCurve::Status(const ShapeExtend_Status status) const
{
return ShapeExtend::DecodeStatus (myStatus, status);
}

View File

@@ -0,0 +1,42 @@
-- File: ShapeUpgrade_SplitCurve2d.cdl
-- Created: Thu Mar 12 11:14:13 1998
-- Author: Pierre BARRAS
-- <pbs@sgi84>
---Copyright: Matra Datavision 1998
class SplitCurve2d from ShapeUpgrade inherits SplitCurve from ShapeUpgrade
---Purpose: Splits a 2d curve with a criterion.
uses
Curve from Geom2d,
HArray1OfCurve from TColGeom2d
is
Create returns mutable SplitCurve2d from ShapeUpgrade;
---Purpose: Empty constructor.
Init (me: mutable; C: Curve from Geom2d);
---Purpose: Initializes with pcurve with its first and last parameters.
Init (me: mutable; C : Curve from Geom2d;
First, Last: Real);
---Purpose: Initializes with pcurve with its parameters.
Build (me: mutable; Segment: Boolean) is redefined;
---Purpose: If Segment is True, the result is composed with
-- segments of the curve bounded by the SplitValues. If
-- Segment is False, the result is composed with trimmed
-- Curves all based on the same complete curve.
--
GetCurves(me) returns HArray1OfCurve from TColGeom2d;
---C++: return const &
fields
myCurve : Curve from Geom2d is protected;
myResultingCurves: HArray1OfCurve from TColGeom2d is protected;
end;

View File

@@ -0,0 +1,238 @@
// File: ShapeUpgrade_SplitCurve2d.cxx
// Created: Thu Mar 12 12:26:05 1998
// Author: Pierre BARRAS
// <pbs@sgi84>
#include <ShapeUpgrade_SplitCurve2d.ixx>
#include <ShapeUpgrade.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <TColStd_ListIteratorOfListOfReal.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <TColGeom2d_HArray1OfCurve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_OffsetCurve.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <ShapeExtend.hxx>
#include <Precision.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <ShapeAnalysis_Curve.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitCurve2d
//purpose :
//=======================================================================
ShapeUpgrade_SplitCurve2d::ShapeUpgrade_SplitCurve2d()
{
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve2d::Init(const Handle(Geom2d_Curve)& C)
{
Init (C, C->FirstParameter(), C->LastParameter());
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve2d::Init(const Handle(Geom2d_Curve)& C,
const Standard_Real First,
const Standard_Real Last)
{
// if (ShapeUpgrade::Debug()) cout << "SplitCurve2d::Init"<<endl;
Handle(Geom2d_Curve) CopyOfC = Handle(Geom2d_Curve)::DownCast(C->Copy());
myCurve = CopyOfC;
Standard_Real precision = Precision::PConfusion();
Standard_Real firstPar = First;
Standard_Real lastPar = Last;
Handle (Geom2d_Curve) aCurve = myCurve;
if(aCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
aCurve=Handle(Geom2d_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
// 15.11.2002 PTV OCC966
if(!ShapeAnalysis_Curve::IsPeriodic(C)) {
Standard_Real fP = aCurve->FirstParameter();
Standard_Real lP = aCurve->LastParameter();
if(Abs(firstPar-fP) < precision)
firstPar = fP;
if(Abs(lastPar-lP) < precision)
lastPar = lP;
if(firstPar < fP){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
firstPar = fP;
}
if(lastPar > lP){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
lastPar = lP;
}
if( (lastPar-firstPar) < precision)
lastPar=firstPar+2*precision;
}
ShapeUpgrade_SplitCurve::Init (firstPar, lastPar);
// first, we make a copy of C to prevent modification:
// if (ShapeUpgrade::Debug()) cout << ". copy of the curve"<<endl;
myNbCurves = 1;
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve2d::Build(const Standard_Boolean Segment)
{
// if (ShapeUpgrade::Debug()) cout<<"ShapeUpgrade_SplitCurve2d::Build"<<endl;
Standard_Real First = mySplitValues->Value(1);
Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
//PrepareKnots();
if (mySplitValues->Length() > 2)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
if (myCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (myCurve);
Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
ShapeUpgrade_SplitCurve2d spc;
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.Build(Segment);
myNbCurves = spc.GetCurves()->Length();
myResultingCurves=new TColGeom2d_HArray1OfCurve (1,myNbCurves);
if (myNbCurves == 1) {
Handle(Geom2d_TrimmedCurve) NewTrimCurve =
new Geom2d_TrimmedCurve(spc.GetCurves()->Value(1),First,Last);
myResultingCurves->SetValue(1,NewTrimCurve);
}
else
myResultingCurves = spc.GetCurves();
myStatus |= spc.myStatus;
return;
}
else if (myCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) {
Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (myCurve);
Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
Standard_Real Offset = tmp->Offset();
ShapeUpgrade_SplitCurve2d spc;
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.Build(Segment);
myNbCurves = spc.GetCurves()->Length();
myResultingCurves = new TColGeom2d_HArray1OfCurve (1,myNbCurves);
for(Standard_Integer i = 1; i <= myNbCurves; i++) {
Handle(Geom2d_OffsetCurve) NewOffsetCurve = new Geom2d_OffsetCurve(spc.GetCurves()->Value(i),Offset);
myResultingCurves->SetValue(i,NewOffsetCurve);
}
myStatus |= spc.myStatus;
return;
}
myNbCurves = mySplitValues->Length() -1;
myResultingCurves=new TColGeom2d_HArray1OfCurve (1,myNbCurves);
if(myNbCurves ==1) {
Standard_Boolean filled = Standard_True;
if ( Abs ( myCurve->FirstParameter() - First ) < Precision::PConfusion() &&
Abs ( myCurve->LastParameter() - Last ) < Precision::PConfusion() )
myResultingCurves->SetValue(1,myCurve);
else if ( ! Segment || (!myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)) &&
!myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve))) || ! Status ( ShapeExtend_DONE2 ) ) {
if(myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)) ||
myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve) )) {
Handle(Geom2d_Curve) theNewCurve = Handle(Geom2d_Curve)::DownCast(myCurve->Copy());
try {
OCC_CATCH_SIGNALS
if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)))
Handle(Geom2d_BSplineCurve)::DownCast(theNewCurve)->Segment (First, Last);
else if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve)))
Handle(Geom2d_BezierCurve)::DownCast(theNewCurve)->Segment (First, Last);
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_Split2dCurve::Build(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),First,Last);
}
myResultingCurves->SetValue (1, theNewCurve);
}
else {
Handle(Geom2d_TrimmedCurve) theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),First,Last);
myResultingCurves->SetValue (1, theNewCurve);
}
}
else filled = Standard_False;
if ( filled ) return;
}
if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve))) {
Handle(Geom2d_BSplineCurve) BsCurve = Handle(Geom2d_BSplineCurve)::DownCast(myCurve->Copy());
Standard_Integer FirstInd =BsCurve->FirstUKnotIndex(),
LastInd = BsCurve->LastUKnotIndex();
Standard_Integer j = FirstInd;
for(Standard_Integer ii =1 ; ii <= mySplitValues->Length(); ii++) {
Standard_Real spval = mySplitValues->Value(ii);
for(; j <=LastInd;j++) {
if( spval > BsCurve->Knot(j) + Precision::PConfusion()) continue;
if( spval < BsCurve->Knot(j) - Precision::PConfusion()) break;
mySplitValues->SetValue(ii,BsCurve->Knot(j));
}
if(j == LastInd) break;
}
}
for (Standard_Integer i = 1; i <= myNbCurves; i++) {
// skl : in the next block I change "First","Last" to "Firstt","Lastt"
Standard_Real Firstt = mySplitValues->Value(i), Lastt = mySplitValues->Value(i+1);
Handle(Geom2d_Curve) theNewCurve;
if(Segment) {
// creates a copy of myCurve before to segment:
if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)) ||
myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve))) {
theNewCurve = Handle(Geom2d_Curve)::DownCast(myCurve->Copy());
try {
OCC_CATCH_SIGNALS
if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BSplineCurve)))
Handle(Geom2d_BSplineCurve)::DownCast(theNewCurve)->Segment (Firstt, Lastt);
else if (myCurve->IsKind (STANDARD_TYPE (Geom2d_BezierCurve)))
Handle(Geom2d_BezierCurve)::DownCast(theNewCurve)->Segment (Firstt, Lastt);
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_Split2dCurve::Build(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),Firstt,Lastt);
}
}
else
theNewCurve = new Geom2d_TrimmedCurve(Handle(Geom2d_Curve)::DownCast(myCurve->Copy()),Firstt,Lastt);
}
myResultingCurves->SetValue (i, theNewCurve);
}
}
//=======================================================================
//function : GetCurves
//purpose :
//=======================================================================
const Handle(TColGeom2d_HArray1OfCurve)& ShapeUpgrade_SplitCurve2d::GetCurves() const
{
return myResultingCurves;
}

View File

@@ -0,0 +1,43 @@
-- File: ShapeUpgrade_SplitCurve2dContinuity.cdl
-- Created: Wed Apr 14 18:47:29 1999
-- Author: Roman LYGIN
-- <rln@kinox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class SplitCurve2dContinuity from ShapeUpgrade inherits SplitCurve2d from ShapeUpgrade
---Purpose: Corrects/splits a 2d curve with a continuity criterion.
-- Tolerance is used to correct the curve at a knot that respects
-- geometrically the criterion, in order to reduce the
-- multiplicity of the knot.
uses
Curve from Geom2d,
Shape from GeomAbs
is
Create returns SplitCurve2dContinuity from ShapeUpgrade;
---Purpose: Empty constructor.
SetCriterion (me: mutable; Criterion: Shape from GeomAbs);
---Purpose: Sets criterion for splitting.
SetTolerance (me: mutable; Tol: Real);
---Purpose: Sets tolerance.
Compute(me: mutable) is redefined;
---Purpose: Calculates points for correction/splitting of the curve
fields
myCriterion: Shape from GeomAbs;
myCont : Integer;
myTolerance: Real;
end SplitCurve2dContinuity;

View File

@@ -0,0 +1,182 @@
// File: ShapeUpgrade_SplitCurve2dContinuity.cxx
// Created: Wed Apr 14 19:18:17 1999
// Author: Roman LYGIN
// <rln@kinox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_SplitCurve2dContinuity.ixx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Precision.hxx>
#include <ShapeUpgrade.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_OffsetCurve.hxx>
#include <TColGeom2d_HArray1OfCurve.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <TColGeom2d_HArray1OfCurve.hxx>
#include <ShapeExtend.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitCurve2dContinuity
//purpose :
//=======================================================================
ShapeUpgrade_SplitCurve2dContinuity::ShapeUpgrade_SplitCurve2dContinuity()
{
myCriterion = GeomAbs_C1;
myTolerance = Precision::PConfusion();
myCont =1;
}
//=======================================================================
//function : SetCriterion
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve2dContinuity::SetCriterion(const GeomAbs_Shape Criterion)
{
myCriterion = Criterion;
switch (myCriterion) {
case GeomAbs_C0 : myCont = 0; break;
case GeomAbs_C1 : myCont = 1; break;
case GeomAbs_C2 : myCont = 2; break;
case GeomAbs_C3 : myCont = 3; break;
case GeomAbs_CN : myCont = 4; break;
default : myCont = 1;
}
}
//=======================================================================
//function : SetTolerance
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve2dContinuity::SetTolerance(const Standard_Real Tol)
{
myTolerance = Tol;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve2dContinuity::Compute()
{
if(myCurve->Continuity() < myCriterion)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
if (mySplitValues->Length() > 2)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
Standard_Real precision = Precision::PConfusion();
Standard_Real First = mySplitValues->Value(1);
Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
if (myCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (myCurve);
Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
ShapeUpgrade_SplitCurve2dContinuity spc;
// spc.Init(BasCurve,Max(First,tmp->FirstParameter()),Min(Last,tmp->LastParameter()));
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.SetTolerance(myTolerance);
spc.SetCriterion(myCriterion);
spc.Compute();
mySplitValues->Clear();
mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
//mySplitValues = spc.SplitValues();
myStatus |= spc.myStatus;
return;
}
else if (myCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) {
GeomAbs_Shape BasCriterion;
switch (myCriterion) {
default :
case GeomAbs_C1 : BasCriterion = GeomAbs_C2; break;
case GeomAbs_C2 : BasCriterion = GeomAbs_C3; break;
case GeomAbs_C3 : //if (ShapeUpgrade::Debug()) cout<<". this criterion is not suitable for a Offset curve"<<endl;
#ifdef DEB
cout << "Warning: ShapeUpgrade_SplitCurve2dContinuity: criterion C3 for Offset curve" << endl;
#endif
case GeomAbs_CN : BasCriterion = GeomAbs_CN; break;
}
Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (myCurve);
Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
//Standard_Real Offset = tmp->Offset(); // Offset not used (skl)
ShapeUpgrade_SplitCurve2dContinuity spc;
// spc.Init(BasCurve,Max(tmp->FirstParameter(),First),Min(tmp->LastParameter(),Last));
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.SetTolerance(myTolerance);
spc.SetCriterion(BasCriterion);
spc.Compute();
mySplitValues->Clear();
mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
myStatus |= spc.myStatus;
return;
}
Handle(Geom2d_BSplineCurve) MyBSpline = Handle(Geom2d_BSplineCurve)::DownCast (myCurve);
if (MyBSpline.IsNull()) {
// if (ShapeUpgrade::Debug()) cout<<". curve is not a Bspline"<<endl;
return;
}
myNbCurves=1;
Standard_Integer Deg=MyBSpline->Degree();
Standard_Integer NbKnots= MyBSpline->NbKnots();
// if (ShapeUpgrade::Debug()) cout<<". NbKnots="<<NbKnots<<endl;
if (NbKnots <= 2) {
return;
}
Standard_Integer FirstInd =MyBSpline->FirstUKnotIndex()+1,
LastInd = MyBSpline->LastUKnotIndex()-1;
Standard_Integer iknot = FirstInd;
for(Standard_Integer j =2; j <= mySplitValues->Length(); j++) {
Last = mySplitValues->Value(j);
for (; iknot <= LastInd; iknot++) {
Standard_Real valknot = MyBSpline->Knot(iknot);
if(valknot <= First + precision) continue;
if(valknot >= Last - precision) break;
Standard_Integer Continuity=Deg-MyBSpline->Multiplicity(iknot);
//Standard_Real tt = MyBSpline->Knot(iknot); // tt not used (skl)
if (Continuity < myCont) {
// At this knot, the curve is C0; try to remove Knot.
Standard_Boolean corrected = Standard_False;
Standard_Integer newMultiplicity = Deg - myCont;
if (newMultiplicity < 0) newMultiplicity = 0;
{
try {
OCC_CATCH_SIGNALS
corrected = MyBSpline->RemoveKnot(iknot, newMultiplicity, myTolerance);
}
catch (Standard_Failure) {
corrected = Standard_False;
}
}
if (corrected && newMultiplicity > 0) {
Continuity=Deg-MyBSpline->Multiplicity(iknot);
corrected = (Continuity >= myCont);
}
if (corrected) {
// at this knot, the continuity is now C1. Nothing else to do.
// if (ShapeUpgrade::Debug()) cout<<". Correction at Knot "<<iknot<<endl;
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
else {
// impossible to force C1 within the tolerance:
// this knot will be a splitting value.
mySplitValues->InsertBefore(j++,MyBSpline->Knot(iknot));
myNbCurves++;
// if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl;
}
}
}
First = Last;
}
if (mySplitValues->Length() > 2)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
}

View File

@@ -0,0 +1,43 @@
-- File: ShapeUpgrade_SplitCurve3d.cdl
-- Created: Thu Mar 12 11:14:13 1998
-- Author: Roman LYGIN
-- <rln@kinox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1998
class SplitCurve3d from ShapeUpgrade inherits SplitCurve from ShapeUpgrade
---Purpose: Splits a 3d curve with a criterion.
uses
Curve from Geom,
HArray1OfCurve from TColGeom
is
Create returns mutable SplitCurve3d from ShapeUpgrade;
---Purpose: Empty constructor.
Init (me: mutable; C: Curve from Geom);
---Purpose: Initializes with curve with its first and last parameters.
Init (me: mutable; C : Curve from Geom;
First, Last: Real);
---Purpose: Initializes with curve with its parameters.
Build (me: mutable; Segment: Boolean) is redefined;
---Purpose: If Segment is True, the result is composed with
-- segments of the curve bounded by the SplitValues. If
-- Segment is False, the result is composed with trimmed
-- Curves all based on the same complete curve.
--
GetCurves(me) returns HArray1OfCurve from TColGeom;
---C++: return const &
fields
myCurve : Curve from Geom is protected;
myResultingCurves: HArray1OfCurve from TColGeom is protected;
end;

View File

@@ -0,0 +1,262 @@
// File: ShapeUpgrade_SplitCurve3d.cxx
// Created: Thu Mar 12 12:26:05 1998
// Author: Roman LYGIN
// <rln@kinox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_SplitCurve3d.ixx>
#include <Geom_BSplineCurve.hxx>
#include <Precision.hxx>
#include <ShapeUpgrade.hxx>
#include <TColStd_ListIteratorOfListOfReal.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_OffsetCurve.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <ShapeExtend.hxx>
#include <Precision.hxx>
#include <Geom_BezierCurve.hxx>
#include <ShapeAnalysis_Curve.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitCurve3d
//purpose :
//=======================================================================
ShapeUpgrade_SplitCurve3d::ShapeUpgrade_SplitCurve3d()
{
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve3d::Init(const Handle(Geom_Curve)& C)
{
Init (C, C->FirstParameter(), C->LastParameter());
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve3d::Init(const Handle(Geom_Curve)& C,
const Standard_Real First,
const Standard_Real Last)
{
// if (ShapeUpgrade::Debug()) cout << "SplitCurve3d::Init"<<endl;
Handle(Geom_Curve) CopyOfC = Handle(Geom_Curve)::DownCast(C->Copy());
myCurve = CopyOfC;
Standard_Real precision = Precision::PConfusion();
Standard_Real firstPar = First;
Standard_Real lastPar = Last;
Handle (Geom_Curve) aCurve = myCurve;
if(aCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)))
aCurve=Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
// 15.11.2002 PTV OCC966
if(!ShapeAnalysis_Curve::IsPeriodic(C)) {
Standard_Real fP = aCurve->FirstParameter();
Standard_Real lP = aCurve->LastParameter();
if(Abs(firstPar-fP) < precision)
firstPar = fP;
if(Abs(lastPar-lP) < precision)
lastPar = lP;
if(firstPar < fP){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
firstPar = fP;
}
if(lastPar > lP){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
lastPar = lP;
}
if( (lastPar-firstPar) < precision)
lastPar=firstPar+2*precision;
}
ShapeUpgrade_SplitCurve::Init (firstPar, lastPar);
// first, we make a copy of C to prevent modification:
// if (ShapeUpgrade::Debug()) cout << ". copy of the curve"<<endl;
myNbCurves = 1;
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve3d::Build(const Standard_Boolean Segment)
{
// if (ShapeUpgrade::Debug()) cout<<"ShapeUpgrade_SplitCurve3d::Build"<<endl;
Standard_Real First = mySplitValues->Value(1);
Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
if (mySplitValues->Length() >2)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
if (myCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
Handle(Geom_TrimmedCurve) tmp = Handle(Geom_TrimmedCurve)::DownCast (myCurve);
Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
ShapeUpgrade_SplitCurve3d spc;
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.Build(Segment);
myNbCurves = spc.GetCurves()->Length();
myResultingCurves=new TColGeom_HArray1OfCurve (1,myNbCurves);
if(myNbCurves == 1) {
Handle(Geom_TrimmedCurve) NewTrimCurve =
new Geom_TrimmedCurve(spc.GetCurves()->Value(1),First,Last);
myResultingCurves->SetValue(1,NewTrimCurve);
}
else
myResultingCurves = spc.GetCurves();
myStatus |= spc.myStatus;
return;
}
else if (myCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
Handle(Geom_OffsetCurve) tmp = Handle(Geom_OffsetCurve)::DownCast (myCurve);
Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
Standard_Real Offset = tmp->Offset();
gp_Dir Direct = tmp->Direction();
ShapeUpgrade_SplitCurve3d spc;
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.Build(Segment);
myNbCurves = spc.GetCurves()->Length();
myResultingCurves = new TColGeom_HArray1OfCurve (1,myNbCurves);
for(Standard_Integer i = 1; i <= myNbCurves; i++) {
Handle(Geom_OffsetCurve) NewOffsetCurve =
new Geom_OffsetCurve(spc.GetCurves()->Value(i),Offset,Direct);
myResultingCurves->SetValue(i,NewOffsetCurve);
}
myStatus |= spc.myStatus;
return;
}
//pdn fix on BuildCurve 3d
// 15.11.2002 PTV OCC966
if(!ShapeAnalysis_Curve::IsPeriodic(myCurve)) {
//pdn exceptons only on non periodic curves
Standard_Real precision = Precision::PConfusion();
Standard_Real firstPar = myCurve->FirstParameter();
Standard_Real lastPar = myCurve->LastParameter();
if(Abs(First-firstPar) < precision)
First = firstPar;
if(Abs(Last-lastPar) < precision)
Last = lastPar;
if(First < firstPar){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
First = firstPar;
mySplitValues->SetValue(1,First);
}
if(Last > lastPar){
#ifdef DEB
cout <<"Warning: The range of the edge exceeds the curve domain" <<endl;
#endif
Last = lastPar;
mySplitValues->SetValue(mySplitValues->Length(),Last);
}
}
myNbCurves = mySplitValues->Length() -1;
myResultingCurves = new TColGeom_HArray1OfCurve (1, myNbCurves);
if (myNbCurves == 1) {
Standard_Boolean filled = Standard_True;
if ( Abs ( myCurve->FirstParameter() - First ) < Precision::PConfusion() &&
Abs ( myCurve->LastParameter() - Last ) < Precision::PConfusion() )
myResultingCurves->SetValue(1,myCurve);
else if ( ! Segment || (!myCurve->IsKind (STANDARD_TYPE (Geom_BSplineCurve)) &&
!myCurve->IsKind (STANDARD_TYPE (Geom_BezierCurve))) || ! Status ( ShapeExtend_DONE2 ) ) {
/* if(myCurve->IsKind (STANDARD_TYPE (Geom_BSplineCurve)) ||
myCurve->IsKind (STANDARD_TYPE (Geom_BezierCurve) )) {
Handle(Geom_Curve) theNewCurve = Handle(Geom_Curve)::DownCast(myCurve->Copy());
try {
OCC_CATCH_SIGNALS
if (myCurve->IsKind (STANDARD_TYPE (Geom_BSplineCurve)))
Handle(Geom_BSplineCurve)::DownCast(theNewCurve)->Segment (First, Last);
else if (myCurve->IsKind (STANDARD_TYPE (Geom_BezierCurve)))
Handle(Geom_BezierCurve)::DownCast(theNewCurve)->Segment (First, Last);
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_Split3dCurve::Build(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
theNewCurve = new Geom_TrimmedCurve(Handle(Geom_Curve)::DownCast(myCurve->Copy()),First,Last);
}
myResultingCurves->SetValue (1, theNewCurve);
}
else {*/
Handle(Geom_TrimmedCurve) theNewCurve = new Geom_TrimmedCurve(Handle(Geom_Curve)::DownCast(myCurve->Copy()),First,Last);
myResultingCurves->SetValue (1, theNewCurve);
// }
}
else filled = Standard_False;
if ( filled ) return;
}
if (myCurve->IsKind (STANDARD_TYPE (Geom_BSplineCurve))) {
Handle(Geom_BSplineCurve) BsCurve = Handle(Geom_BSplineCurve)::DownCast(myCurve->Copy());
Standard_Integer FirstInd =BsCurve->FirstUKnotIndex(),
LastInd = BsCurve->LastUKnotIndex();
Standard_Integer j = FirstInd;
for(Standard_Integer ii =1; ii <= mySplitValues->Length(); ii++) {
Standard_Real spval = mySplitValues->Value(ii);
for(; j <=LastInd;j++) {
if( spval > BsCurve->Knot(j) + Precision::PConfusion()) continue;
if( spval < BsCurve->Knot(j) - Precision::PConfusion()) break;
mySplitValues->SetValue(ii,BsCurve->Knot(j));
}
if(j == LastInd) break;
}
}
for (Standard_Integer i = 1; i <= myNbCurves; i++) {
// skl : in the next block I change "First","Last" to "Firstt","Lastt"
Standard_Real Firstt = mySplitValues->Value(i), Lastt = mySplitValues->Value(i+1);
Handle(Geom_Curve) theNewCurve;
if(Segment) {
if (myCurve->IsKind (STANDARD_TYPE (Geom_BSplineCurve)) ||
myCurve->IsKind (STANDARD_TYPE (Geom_BezierCurve))) {
theNewCurve = Handle(Geom_Curve)::DownCast(myCurve->Copy());
try {
OCC_CATCH_SIGNALS
if (myCurve->IsKind (STANDARD_TYPE (Geom_BSplineCurve)))
Handle(Geom_BSplineCurve)::DownCast(theNewCurve)->Segment (Firstt, Lastt);
else if (myCurve->IsKind (STANDARD_TYPE (Geom_BezierCurve)))
Handle(Geom_BezierCurve)::DownCast(theNewCurve)->Segment (Firstt, Lastt);
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_Split3dCurve::Build(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
theNewCurve = new Geom_TrimmedCurve(Handle(Geom_Curve)::DownCast(myCurve->Copy()),Firstt,Lastt);
}
}
else theNewCurve = new Geom_TrimmedCurve(Handle(Geom_Curve)::DownCast(myCurve->Copy()),Firstt,Lastt);
}
myResultingCurves->SetValue (i, theNewCurve);
}
}
//=======================================================================
//function : GetCurves
//purpose :
//=======================================================================
const Handle(TColGeom_HArray1OfCurve)& ShapeUpgrade_SplitCurve3d::GetCurves() const
{
return myResultingCurves;
}

View File

@@ -0,0 +1,45 @@
-- File: ShapeUpgrade_SplitCurve3dContinuity.cdl
-- Created: Thu Apr 15 11:04:56 1999
-- Author: Roman LYGIN
-- <rln@kinox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class SplitCurve3dContinuity from ShapeUpgrade inherits SplitCurve3d from ShapeUpgrade
---Purpose: Corrects/splits a 2d curve with a continuity criterion.
-- Tolerance is used to correct the curve at a knot that respects
-- geometrically the criterion, in order to reduce the
-- multiplicity of the knot.
uses
Curve from Geom,
Shape from GeomAbs
is
Create returns SplitCurve3dContinuity from ShapeUpgrade;
---Purpose: Empty constructor.
SetCriterion (me: mutable; Criterion: Shape from GeomAbs);
---Purpose: Sets criterion for splitting.
SetTolerance (me: mutable; Tol: Real);
---Purpose: Sets tolerance.
Compute(me: mutable) is redefined;
---Purpose: Calculates points for correction/splitting of the curve
GetCurve(me) returns Curve from Geom;
---C++: return const&
fields
myCriterion: Shape from GeomAbs;
myTolerance: Real;
myCont : Integer;
end SplitCurve3dContinuity;

View File

@@ -0,0 +1,198 @@
// File: ShapeUpgrade_SplitCurve3dContinuity.cxx
// Created: Thu Apr 15 11:15:10 1999
// Author: Roman LYGIN
// <rln@kinox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_SplitCurve3dContinuity.ixx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Precision.hxx>
#include <ShapeUpgrade.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_OffsetCurve.hxx>
#include <Geom_Curve.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <ShapeExtend.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitCurve3dContinuity
//purpose :
//=======================================================================
ShapeUpgrade_SplitCurve3dContinuity::ShapeUpgrade_SplitCurve3dContinuity()
{
myCriterion = GeomAbs_C1;
myTolerance = Precision::Confusion();
myCont =1;
}
//=======================================================================
//function : SetCriterion
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve3dContinuity::SetCriterion(const GeomAbs_Shape Criterion)
{
myCriterion = Criterion;
switch (myCriterion) {
case GeomAbs_C0 : myCont = 0; break;
case GeomAbs_C1 : myCont = 1; break;
case GeomAbs_C2 : myCont = 2; break;
case GeomAbs_C3 : myCont = 3; break;
case GeomAbs_CN : myCont = 4; break;
default : myCont = 1;
}
}
//=======================================================================
//function : SetTolerance
//purpose :
//=======================================================================
void ShapeUpgrade_SplitCurve3dContinuity::SetTolerance(const Standard_Real Tol)
{
myTolerance = Tol;
}
//=======================================================================
//function : Compute
//purpose :
//===================================================================
void ShapeUpgrade_SplitCurve3dContinuity::Compute()
{
Standard_Real First = mySplitValues->Value(1);
Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
Standard_Real precision = Precision::PConfusion();
if(myCurve->Continuity() < myCriterion)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
if (mySplitValues->Length() > 2)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
if (myCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
Handle(Geom_TrimmedCurve) tmp = Handle(Geom_TrimmedCurve)::DownCast (myCurve);
Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
ShapeUpgrade_SplitCurve3dContinuity spc;
// spc.Init(BasCurve,Max(tmp->FirstParameter(),First),Min(tmp->LastParameter(),Last));
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.SetTolerance(myTolerance);
spc.SetCriterion(myCriterion);
spc.Compute();
mySplitValues->Clear();
mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
myStatus |= spc.myStatus;
return;
}
else if (myCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
GeomAbs_Shape BasCriterion;
switch (myCriterion) {
default :
case GeomAbs_C1 : BasCriterion = GeomAbs_C2; break;
case GeomAbs_C2 : BasCriterion = GeomAbs_C3; break;
case GeomAbs_C3 : // if (ShapeUpgrade::Debug()) cout<<". this criterion is not suitable for a Offset curve"<<endl;
#ifdef DEB
cout << "Warning: ShapeUpgrade_SplitCurve3dContinuity: criterion C3 for Offset curve" << endl;
#endif
case GeomAbs_CN : BasCriterion = GeomAbs_CN; break;
}
Handle(Geom_OffsetCurve) tmp = Handle(Geom_OffsetCurve)::DownCast (myCurve);
Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
//Standard_Real Offset = tmp->Offset(); // Offset not used (skl)
//gp_Dir Direct = tmp->Direction(); // Direct not used (skl)
ShapeUpgrade_SplitCurve3dContinuity spc;
// spc.Init(BasCurve,Max(tmp->FirstParameter(),First),Min(tmp->LastParameter(),Last));
spc.Init(BasCurve,First,Last);
spc.SetSplitValues(mySplitValues);
spc.SetTolerance(myTolerance);
spc.SetCriterion(BasCriterion);
spc.Compute();
mySplitValues->Clear();
mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
myStatus |= spc.myStatus;
return ;
}
Handle(Geom_BSplineCurve) MyBSpline = Handle(Geom_BSplineCurve)::DownCast (myCurve);
if (MyBSpline.IsNull()) {
// if (ShapeUpgrade::Debug()) cout<<". curve is not a Bspline"<<endl;
return ;
}
// it is a BSplineCurve
// if (ShapeUpgrade::Debug()) cout<<". curve is a Bspline"<<endl;
myNbCurves=1;
Standard_Integer Deg=MyBSpline->Degree();
Standard_Integer NbKnots= MyBSpline->NbKnots();
// if (ShapeUpgrade::Debug()) cout<<". NbKnots="<<NbKnots<<endl;
if (NbKnots <= 2) {
return;
}
// Only the internal knots are checked.
Standard_Integer FirstInd =MyBSpline->FirstUKnotIndex()+1,
LastInd = MyBSpline->LastUKnotIndex()-1;
for(Standard_Integer j =2; j <= mySplitValues->Length(); j++) {
Last = mySplitValues->Value(j);
for (Standard_Integer iknot = FirstInd; iknot <= LastInd; iknot++) {
Standard_Real valknot = MyBSpline->Knot(iknot);
if(valknot <= First + precision) continue;
if(valknot > Last - precision) break;
Standard_Integer Continuity=Deg-MyBSpline->Multiplicity(iknot);
if (Continuity < myCont) {
// At this knot, the curve is C0; try to remove Knot.
Standard_Boolean corrected = Standard_False;
Standard_Integer newMultiplicity = Deg - myCont;
if (newMultiplicity < 0) newMultiplicity = 0;
{
try {
OCC_CATCH_SIGNALS
corrected = MyBSpline->RemoveKnot(iknot, newMultiplicity, myTolerance);
}
catch (Standard_Failure) {
corrected = Standard_False;
}
}
if (corrected && newMultiplicity > 0) {
Continuity=Deg-MyBSpline->Multiplicity(iknot);
corrected = (Continuity >= myCont);
}
if (corrected) {
// at this knot, the continuity is now C1. Nothing else to do.
// if (ShapeUpgrade::Debug()) cout<<". Correction at Knot "<<iknot<<endl;
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
if(newMultiplicity == 0) {
//in case if knot is completelly removed
//it is necessary to modify last idex and decrease current knot index
LastInd = MyBSpline->LastUKnotIndex()-1;
iknot--;
}
}
else {
// impossible to force C1 within the tolerance:
// this knot will be a splitting value.
mySplitValues->InsertBefore(j++,MyBSpline->Knot(iknot));
myNbCurves++;
// if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl;
}
}
}
First = Last;
}
if (mySplitValues->Length() > 2)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
}
//=======================================================================
//function : GetCurve
//purpose :
//=======================================================================
const Handle(Geom_Curve)& ShapeUpgrade_SplitCurve3dContinuity::GetCurve() const
{
return myCurve;
}

View File

@@ -0,0 +1,85 @@
-- File: ShapeUpgrade_SplitSurface.cdl
-- Created: Mon Mar 16 17:28:27 1998
-- Author: Pierre BARRAS
-- <pbs@sgi84>
---Copyright: Matra Datavision 1998
class SplitSurface from ShapeUpgrade inherits TShared from MMgt
---Purpose: Splits a Surface with a criterion.
uses
HArray1OfInteger from TColStd,
HSequenceOfReal from TColStd,
HArray2OfSurface from TColGeom,
Surface from Geom,
Status from ShapeExtend,
CompositeSurface from ShapeExtend
is
Create returns mutable SplitSurface from ShapeUpgrade;
---Purpose: Empty constructor.
Init (me: mutable; S: Surface from Geom);
---Purpose: Initializes with single supporting surface.
Init (me: mutable; S: Surface from Geom; UFirst,ULast,VFirst,VLast : Real);
---Purpose: Initializes with single supporting surface with bounding parameters.
SetUSplitValues(me: mutable; UValues : HSequenceOfReal from TColStd);
---Purpose: Sets U parameters where splitting has to be done
SetVSplitValues(me: mutable; VValues : HSequenceOfReal from TColStd);
---Purpose: Sets V parameters where splitting has to be done
Build (me: mutable; Segment: Boolean) is virtual;
---Purpose: Performs splitting of the supporting surface.
-- If resulting surface is B-Spline and Segment is True,
-- the result is composed with segments of the surface bounded
-- by the U and V SplitValues (method Geom_BSplineSurface::Segment
-- is used).
-- If Segment is False, the result is composed with
-- Geom_RectangularTrimmedSurface all based on the same complete
-- surface.
-- Fields myNbResultingRow and myNbResultingCol must be set to
-- specify the size of resulting grid of surfaces.
Compute(me: mutable; Segment: Boolean = Standard_True) is virtual;
---Purpose: Calculates points for correction/splitting of the surface.
Perform(me: mutable; Segment: Boolean = Standard_True);
---Purpose: Performs correction/splitting of the surface.
--- First defines splitting values by method Compute(), then calls method Build().
USplitValues(me) returns HSequenceOfReal from TColStd;
---C++: return const &
--- Purpose : returns all the U splitting values including the
-- First and Last parameters of the input surface
VSplitValues(me) returns HSequenceOfReal from TColStd;
---C++: return const &
--- Purpose : returns all the splitting V values including the
-- First and Last parameters of the input surface
Status (me; status: Status from ShapeExtend) returns Boolean;
---Purpose: Returns the status
-- OK - no splitting is needed
-- DONE1 - splitting required and gives more than one patch
-- DONE2 - splitting is required, but gives only single patch (initial)
-- DONE3 - geometric form of the surface or parametrisation is modified
ResSurfaces(me) returns CompositeSurface from ShapeExtend;
---C++: return const &
---Purpose: Returns obtained surfaces after splitting as CompositeSurface
fields
myUSplitValues : HSequenceOfReal from TColStd is protected;
myVSplitValues : HSequenceOfReal from TColStd is protected;
myNbResultingRow : Integer is protected;
myNbResultingCol : Integer is protected;
mySurface : Surface from Geom is protected;
myStatus : Integer is protected;
myResSurfaces : CompositeSurface from ShapeExtend is protected;
end;

View File

@@ -0,0 +1,517 @@
// File: ShapeUpgrade_SplitSurface.cxx
// Created: Mon Mar 16 19:18:49 1998
// Author: Pierre BARRAS
// <pbs@sgi84>
// gka 30.04.99 S4137: extended for all types of surfaces
#include <ShapeUpgrade_SplitSurface.ixx>
#include <ShapeUpgrade.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <TColGeom_HArray2OfSurface.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <Precision.hxx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <ShapeUpgrade_SplitCurve3d.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <gp_Ax1.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <ShapeExtend.hxx>
#include <Geom_BezierSurface.hxx>
#include <TColStd_Array1OfReal.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitSurface
//purpose :
//=======================================================================
ShapeUpgrade_SplitSurface::ShapeUpgrade_SplitSurface() : myStatus(0)
{
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurface::Init(const Handle(Geom_Surface)& S)
{
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
myUSplitValues = new TColStd_HSequenceOfReal();
myVSplitValues = new TColStd_HSequenceOfReal();
mySurface = S;
myResSurfaces = new ShapeExtend_CompositeSurface();
myNbResultingRow =1;
myNbResultingCol =1;
Standard_Real U1,U2,V1,V2;
mySurface->Bounds(U1,U2,V1,V2);
myUSplitValues->Append(U1);
myUSplitValues->Append(U2);
myVSplitValues->Append(V1);
myVSplitValues->Append(V2);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurface::Init(const Handle(Geom_Surface)& S, const Standard_Real UFirst,const Standard_Real ULast,
const Standard_Real VFirst, const Standard_Real VLast)
{
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
mySurface = S;
myResSurfaces = new ShapeExtend_CompositeSurface();
myUSplitValues = new TColStd_HSequenceOfReal();
myVSplitValues = new TColStd_HSequenceOfReal();
myNbResultingRow =1;
myNbResultingCol =1;
Standard_Real U1,U2,V1,V2;
mySurface->Bounds(U1,U2,V1,V2);
Standard_Real precision = Precision::PConfusion();
if ( mySurface->IsUPeriodic() &&
ULast - UFirst <= U2 - U1 + precision ) { U1 = UFirst; U2 = U1 + mySurface->UPeriod(); }
if ( mySurface->IsVPeriodic() &&
VLast - VFirst <= V2 - V1 + precision ) { V1 = VFirst; V2 = V1 + mySurface->VPeriod(); }
Standard_Real UF,UL,VF,VL;
if( UFirst > U2-precision ||
ULast < U1-precision ) {
UF =U1; UL = U2;
}
else {
UF = Max(U1,UFirst);
UL = Min(U2,ULast);
}
if( VFirst > V2-precision ||
VLast < V1-precision ) {
VF =V1; VL = V2;
}
else {
VF = Max(V1,VFirst);
VL = Min(V2,VLast);
}
if(UL-UF < precision) {
Standard_Real p2 = precision/2.;
UF-= p2;
UL+= p2;
}
if(VL-VF < precision) {
Standard_Real p2 = precision/2.;
VF-= p2;
VL+= p2;
}
myUSplitValues->Append(UF);
myUSplitValues->Append(UL);
myVSplitValues->Append(VF);
myVSplitValues->Append(VL);
}
//=======================================================================
//function : SetSplitValues
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurface::SetUSplitValues(const Handle(TColStd_HSequenceOfReal)& UValues)
{
if(UValues.IsNull()) return;
Standard_Real precision = Precision::PConfusion();
Standard_Real UFirst = myUSplitValues->Value(1),
ULast = myUSplitValues->Value(myUSplitValues->Length());
Standard_Integer i =1;
Standard_Integer len = UValues->Length();
for(Standard_Integer ku =2; ku <= myUSplitValues->Length();ku++) {
ULast = myUSplitValues->Value(ku);
for(; i <= len; i++) {
if( (UFirst + precision) >= UValues->Value(i)) continue;
if((ULast - precision) <= UValues->Value(i)) break;
myUSplitValues->InsertBefore(ku++,UValues->Value(i));
}
UFirst = ULast;
}
}
//=======================================================================
//function : SetSplitVValues
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurface::SetVSplitValues(const Handle(TColStd_HSequenceOfReal)& VValues)
{
if(VValues.IsNull()) return;
Standard_Real precision = Precision::PConfusion();
Standard_Real VFirst = myVSplitValues->Value(1),
VLast = myVSplitValues->Value(myVSplitValues->Length());
Standard_Integer i =1;
Standard_Integer len = VValues->Length();
for(Standard_Integer kv =2; kv <= myVSplitValues->Length();kv++) {
VLast = myVSplitValues->Value(kv);
for(; i <= len; i++) {
if( (VFirst + precision) >= VValues->Value(i)) continue;
if((VLast - precision) <= VValues->Value(i)) break;
myVSplitValues->InsertBefore(kv++,VValues->Value(i));
}
VFirst = VLast;
}
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurface::Build(const Standard_Boolean Segment)
{
Standard_Real UFirst = myUSplitValues->Value(1);
Standard_Real ULast = myUSplitValues->Value(myUSplitValues->Length());
Standard_Real VFirst = myVSplitValues->Value(1);
Standard_Real VLast = myVSplitValues->Value(myVSplitValues->Length());
if(myUSplitValues->Length() > 2 || myVSplitValues->Length() > 2)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
Standard_Real U1,U2,V1,V2;
mySurface->Bounds(U1, U2, V1, V2);
if (mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
Handle(Geom_SurfaceOfRevolution) Surface = Handle(Geom_SurfaceOfRevolution)::DownCast(mySurface);
Handle(Geom_Curve) BasCurve = Surface->BasisCurve();
ShapeUpgrade_SplitCurve3d spc;
spc.Init(BasCurve,VFirst,VLast);
spc.SetSplitValues(myVSplitValues);
spc.Build(Segment);
Handle(TColGeom_HArray2OfSurface) Surfaces;
myNbResultingCol = spc.GetCurves()->Length();
if(myUSplitValues->Length()> 2) {
myNbResultingRow = myUSplitValues->Length() -1;
Surfaces = new TColGeom_HArray2OfSurface(1, myNbResultingRow,1,myNbResultingCol);
for(Standard_Integer nc =1; nc <= myNbResultingCol; nc++) {
Handle(Geom_SurfaceOfRevolution) NewSurfaceRev =
new Geom_SurfaceOfRevolution(spc.GetCurves()->Value(nc),Surface->Axis());
Standard_Real U1p,U2p,V1p,V2p;
NewSurfaceRev->Bounds(U1p,U2p,V1p,V2p);
for(Standard_Integer nc1 =1; nc1 <= myNbResultingRow; nc1++) {
Handle(Geom_RectangularTrimmedSurface) NewSurf =
new Geom_RectangularTrimmedSurface ( NewSurfaceRev, myUSplitValues->Value(nc1),
myUSplitValues->Value(nc1+1), V1p, V2p );
Surfaces->SetValue(nc1,nc,NewSurf);
}
}
}
else {
Surfaces = new TColGeom_HArray2OfSurface(1,1,1,myNbResultingCol);
for(Standard_Integer nc =1; nc <= spc.GetCurves()->Length(); nc++) {
Handle(Geom_SurfaceOfRevolution) NewSurfaceRev =
new Geom_SurfaceOfRevolution ( spc.GetCurves()->Value(nc), Surface->Axis() );
NewSurfaceRev->Bounds(U1, U2, V1, V2);
if( UFirst == U1 && ULast == U2)
Surfaces ->SetValue(1,nc,NewSurfaceRev);
else {
Handle(Geom_RectangularTrimmedSurface) NewSurf = new Geom_RectangularTrimmedSurface
(NewSurfaceRev,UFirst,ULast,V1,V2); //pdn correction for main seq
Surfaces ->SetValue(1,nc,NewSurf);
}
}
}
myResSurfaces->Init(Surfaces);
myResSurfaces->SetUFirstValue ( myUSplitValues->Sequence().First() );
myResSurfaces->SetVFirstValue ( myVSplitValues->Sequence().First() );
if ( spc.Status ( ShapeExtend_DONE1 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
if ( spc.Status ( ShapeExtend_DONE2 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
if ( spc.Status ( ShapeExtend_DONE3 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
return;
}
if (mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
Handle(Geom_SurfaceOfLinearExtrusion) Surface = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(mySurface);
Handle(Geom_Curve) BasCurve = Surface->BasisCurve();
ShapeUpgrade_SplitCurve3d spc;
spc.Init(BasCurve,UFirst,ULast);
spc.SetSplitValues(myUSplitValues);
spc.Build(Segment);
myNbResultingRow = spc.GetCurves()->Length();
Handle(TColGeom_HArray2OfSurface) Surfaces;
if(myVSplitValues->Length() > 2) {
myNbResultingCol = myVSplitValues->Length() - 1;
Surfaces = new TColGeom_HArray2OfSurface(1,myNbResultingRow,1,myNbResultingCol);
for(Standard_Integer nc1 =1; nc1 <= myNbResultingRow; nc1++) {
Handle(Geom_SurfaceOfLinearExtrusion) NewSurfaceEx = new Geom_SurfaceOfLinearExtrusion(spc.GetCurves()->Value(nc1),
Surface->Direction());
Standard_Real U1p,U2p,V1p,V2p;
NewSurfaceEx->Bounds(U1p,U2p,V1p,V2p);
for(Standard_Integer nc2 =1; nc2 <= myNbResultingCol; nc2++) {
Handle(Geom_RectangularTrimmedSurface) NewSurf = new Geom_RectangularTrimmedSurface
(NewSurfaceEx,U1p,U2p,myVSplitValues->Value(nc2),myVSplitValues->Value(nc2+1));
Surfaces ->SetValue(nc1,nc2,NewSurf);
}
}
}
else {
Surfaces = new TColGeom_HArray2OfSurface(1,myNbResultingRow,1,1);
for(Standard_Integer nc1 =1; nc1 <= myNbResultingRow; nc1++) {
Handle(Geom_SurfaceOfLinearExtrusion) NewSurfaceEx = new Geom_SurfaceOfLinearExtrusion(spc.GetCurves()->Value(nc1),Surface->Direction());
NewSurfaceEx->Bounds(U1,U2,V1,V2);
if(VFirst == V1 && VLast == V2)
Surfaces -> SetValue(nc1,1,NewSurfaceEx);
else {
Handle(Geom_RectangularTrimmedSurface) NewSurf = new Geom_RectangularTrimmedSurface
(NewSurfaceEx,Max(U1,UFirst),Min(ULast,U2),Max(VFirst,V1),Min(VLast,V2));
Surfaces ->SetValue(nc1,1,NewSurf);
}
}
}
myResSurfaces->Init(Surfaces);
myResSurfaces->SetUFirstValue ( myUSplitValues->Sequence().First() );
myResSurfaces->SetVFirstValue ( myVSplitValues->Sequence().First() );
if ( spc.Status ( ShapeExtend_DONE1 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
if ( spc.Status ( ShapeExtend_DONE2 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
if ( spc.Status ( ShapeExtend_DONE3 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
return;
}
if (mySurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
Handle(Geom_RectangularTrimmedSurface) tmp = Handle(Geom_RectangularTrimmedSurface)::DownCast (mySurface);
Handle(Geom_Surface) theSurf = tmp->BasisSurface();
ShapeUpgrade_SplitSurface sps;
sps.Init(theSurf,UFirst,ULast,VFirst,VLast);
sps.SetUSplitValues(myUSplitValues);
sps.SetVSplitValues(myVSplitValues);
sps.myStatus = myStatus;
sps.Build(Segment);
myStatus |= sps.myStatus;
myResSurfaces = sps.myResSurfaces;
return;
}
else if (mySurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
Handle(Geom_OffsetSurface) tmp = Handle(Geom_OffsetSurface)::DownCast (mySurface);
Handle(Geom_Surface) theSurf = tmp->BasisSurface();
ShapeUpgrade_SplitSurface sps;
sps.Init(theSurf,UFirst,ULast,VFirst,VLast);
sps.SetUSplitValues(myUSplitValues);
sps.SetVSplitValues(myVSplitValues);
sps.myStatus = myStatus;
sps.Build(Segment);
Handle(TColGeom_HArray2OfSurface) Patches = new TColGeom_HArray2OfSurface
(1,sps.ResSurfaces()->NbUPatches(),1,sps.ResSurfaces()->NbVPatches());
for(Standard_Integer i1 = 1; i1 <= sps.ResSurfaces()->NbUPatches(); i1++) {
for(Standard_Integer j1 = 1 ; j1 <= sps.ResSurfaces()->NbVPatches(); j1++) {
Handle(Geom_OffsetSurface) NewOffSur = new Geom_OffsetSurface(sps.ResSurfaces()->Patch(i1,j1),tmp->Offset());
Patches->SetValue(i1,j1,NewOffSur);
}
}
myResSurfaces->Init(Patches);
myResSurfaces->SetUFirstValue ( myUSplitValues->Sequence().First() );
myResSurfaces->SetVFirstValue ( myVSplitValues->Sequence().First() );
myStatus |= sps.myStatus;
return;
}
// splitting the surfaces:
myNbResultingRow = myUSplitValues->Length() -1;
myNbResultingCol = myVSplitValues->Length() -1;
Handle(TColGeom_HArray2OfSurface) Surfaces =new TColGeom_HArray2OfSurface(1,myNbResultingRow,1,myNbResultingCol);
Standard_Boolean isBSpline = mySurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface));
Standard_Boolean isBezier = mySurface->IsKind(STANDARD_TYPE(Geom_BezierSurface));
// Standard_Real U1,U2,V1,V2;
// U1=UFirst;
// U2 = ULast;
// V1 = VFirst;
// V2 = VLast;
if(myNbResultingRow == 1 && myNbResultingCol == 1) {
mySurface->Bounds(U1, U2, V1, V2);
Standard_Boolean filled = Standard_True;
if ( Abs ( U1 - UFirst ) < Precision::PConfusion() &&
Abs ( U2 - ULast ) < Precision::PConfusion() &&
Abs ( V1 - VFirst ) < Precision::PConfusion() &&
Abs ( V2 - VLast ) < Precision::PConfusion() )
Surfaces->SetValue(1,1,mySurface);
else if ( ! Segment || ! mySurface->IsKind (STANDARD_TYPE (Geom_BSplineSurface) ) ||
! Status ( ShapeExtend_DONE2 ) ) {
//pdn copying of surface
Handle(Geom_Surface) tmp = Handle(Geom_Surface)::DownCast(mySurface->Copy());
Handle(Geom_RectangularTrimmedSurface) Surf=
new Geom_RectangularTrimmedSurface(tmp,UFirst,ULast,VFirst,VLast);
Surfaces->SetValue(1,1,Surf);
}
else filled = Standard_False;
if ( filled ) {
myResSurfaces->Init(Surfaces);
myResSurfaces->SetUFirstValue ( myUSplitValues->Sequence().First() );
myResSurfaces->SetVFirstValue ( myVSplitValues->Sequence().First() );
return;
}
}
if (mySurface->IsKind (STANDARD_TYPE (Geom_BSplineSurface))) {
Handle(Geom_BSplineSurface) BsSurface = Handle(Geom_BSplineSurface)::DownCast(mySurface->Copy());
Standard_Integer FirstInd =BsSurface->FirstUKnotIndex(),
LastInd = BsSurface->LastUKnotIndex();
Standard_Integer j = FirstInd;
for(Standard_Integer ii =1 ; ii <= myUSplitValues->Length(); ii++) {
Standard_Real spval = myUSplitValues->Value(ii);
for(; j <=LastInd;j++) {
if( spval > BsSurface->UKnot(j) + Precision::PConfusion()) continue;
if( spval < BsSurface->UKnot(j) - Precision::PConfusion()) break;
myUSplitValues->ChangeValue(ii) = BsSurface->UKnot(j);
}
if(j == LastInd) break;
}
FirstInd =BsSurface->FirstVKnotIndex(),
LastInd = BsSurface->LastVKnotIndex();
j = FirstInd;
for(Standard_Integer ii1 =1 ; ii1 <= myVSplitValues->Length(); ii1++) {
Standard_Real spval = myVSplitValues->Value(ii1);
for(; j <=LastInd;j++) {
if( spval > BsSurface->VKnot(j) + Precision::PConfusion()) continue;
if( spval < BsSurface->VKnot(j) - Precision::PConfusion()) break;
myVSplitValues->ChangeValue(ii1) =BsSurface->VKnot(j);
}
if(j == LastInd) break;
}
}
U1 = myUSplitValues->Value(1);
V1 = myVSplitValues->Value(1);
for(Standard_Integer irow = 2; irow <= myUSplitValues->Length(); irow++) {
U2 = myUSplitValues->Value(irow);
for(Standard_Integer icol = 2; icol <= myVSplitValues->Length(); icol++) {
V2 = myVSplitValues->Value(icol);
// if (ShapeUpgrade::Debug()) {
// cout<<".. bounds ="<<U1 <<","<<U2 <<","<<V1 <<","<<V2 <<endl;
// cout<<".. -> pos ="<<irow <<","<<icol<<endl;
// }
// creates a copy of theSurf before to segment:
Handle(Geom_Surface) theNew = Handle(Geom_Surface)::DownCast ( mySurface->Copy() );
if ( isBSpline || isBezier ) {
try {
OCC_CATCH_SIGNALS
if ( isBSpline )
Handle(Geom_BSplineSurface)::DownCast(theNew)->Segment(U1,U2,V1,V2);
else if ( isBezier ) {
//pdn K4L+ (work around)
// Standard_Real u1 = 2*U1 - 1;
// Standard_Real u2 = 2*U2 - 1;
// Standard_Real v1 = 2*V1 - 1;
// Standard_Real v2 = 2*V2 - 1;
//rln C30 (direct use)
Standard_Real u1 = U1;
Standard_Real u2 = U2;
Standard_Real v1 = V1;
Standard_Real v2 = V2;
Handle(Geom_BezierSurface)::DownCast(theNew)->Segment(u1,u2,v1,v2);
}
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
catch (Standard_Failure) {
#ifdef DEB
cout << "Warning: ShapeUpgrade_SplitSurface::Build(): Exception in Segment :";
Standard_Failure::Caught()->Print(cout); cout << endl;
#endif
Handle(Geom_Surface) theNewSurf = theNew;
theNew = new Geom_RectangularTrimmedSurface(theNewSurf,U1,U2,V1,V2);
}
Surfaces->SetValue((irow-1),(icol-1),theNew);
}
else {
// not a BSpline: trimming instead of segmentation
Handle(Geom_Surface)
theNewSurf = Handle(Geom_Surface)::DownCast(theNew);
Handle(Geom_RectangularTrimmedSurface) SplittedSurf=
new Geom_RectangularTrimmedSurface(theNewSurf,U1,U2,V1,V2);
Surfaces->SetValue((irow-1),(icol-1),SplittedSurf);
}
V1=V2;
}
U1=U2;
V1 = myVSplitValues->Value(1);
}
Standard_Integer nbU = myUSplitValues->Length();
TColStd_Array1OfReal UJoints(1,nbU);
Standard_Integer i;//svv Jan 10 2000 : porting on DEC
for(i = 1; i <= nbU; i++)
UJoints(i) = myUSplitValues->Value(i);
Standard_Integer nbV= myVSplitValues->Length();
TColStd_Array1OfReal VJoints(1,nbV);
for(i = 1; i <= nbV; i++)
VJoints(i) = myVSplitValues->Value(i);
myResSurfaces->Init(Surfaces,UJoints,VJoints);
// if (ShapeUpgrade::Debug()) cout<<"SplitSurface::Build - end"<<endl;
}
//=======================================================================
//function : GlobalUKnots
//purpose :
//=======================================================================
const Handle(TColStd_HSequenceOfReal)& ShapeUpgrade_SplitSurface::USplitValues() const
{
return myUSplitValues;
}
//=======================================================================
//function : GlobalVKnots
//purpose :
//=======================================================================
const Handle(TColStd_HSequenceOfReal)& ShapeUpgrade_SplitSurface::VSplitValues() const
{
return myVSplitValues;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurface::Perform(const Standard_Boolean Segment)
{
Compute(Segment);
// SetUSplitValues(myUSplitValues);
// SetVSplitValues(myVSplitValues);
Build (Segment);
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurface::Compute(const Standard_Boolean /*Segment*/)
{
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_SplitSurface::Status(const ShapeExtend_Status status) const
{
return ShapeExtend::DecodeStatus (myStatus, status);
}
const Handle(ShapeExtend_CompositeSurface)& ShapeUpgrade_SplitSurface::ResSurfaces() const
{
return myResSurfaces;
}

View File

@@ -0,0 +1,33 @@
-- File: ShapeUpgrade_SplitSurfaceAngle.cdl
-- Created: Thu May 6 10:45:05 1999
-- Author: data exchange team
-- <det@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class SplitSurfaceAngle from ShapeUpgrade inherits SplitSurface from ShapeUpgrade
---Purpose: Splits a surfaces of revolution, cylindrical, toroidal,
-- conical, spherical so that each resulting segment covers
-- not more than defined number of degrees.
is
Create (MaxAngle: Real) returns mutable SplitSurfaceAngle from ShapeUpgrade;
---Purpose: Empty constructor.
SetMaxAngle (me: mutable; MaxAngle: Real);
---Purpose: Set maximal angle
MaxAngle (me) returns Real;
---Purpose: Returns maximal angle
Compute(me: mutable; Segment: Boolean) is redefined;
---Purpose: Performs splitting of the supporting surface(s).
--- First defines splitting values, then calls inherited method.
fields
myMaxAngle: Real;
end SplitSurfaceAngle;

View File

@@ -0,0 +1,97 @@
// File: ShapeUpgrade_SplitSurfaceAngle.cxx
// Created: Thu May 6 10:51:57 1999
// Author: data exchange team
// <det@friendox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_SplitSurfaceAngle.ixx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_ToroidalSurface.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_SphericalSurface.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <ShapeExtend.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <Precision.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitSurfaceAngle
//purpose :
//=======================================================================
ShapeUpgrade_SplitSurfaceAngle::ShapeUpgrade_SplitSurfaceAngle (const Standard_Real MaxAngle)
{
myMaxAngle = MaxAngle;
}
//=======================================================================
//function : SetMaxAngle
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceAngle::SetMaxAngle (const Standard_Real MaxAngle)
{
myMaxAngle = MaxAngle;
}
//=======================================================================
//function : MaxAngle
//purpose :
//=======================================================================
double ShapeUpgrade_SplitSurfaceAngle::MaxAngle () const
{
return myMaxAngle;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceAngle::Compute(const Standard_Boolean /*Segment*/)
{
Handle(Geom_Surface) S;
Standard_Real U1,U2;
Standard_Boolean isRect = Standard_False;
if(mySurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))){
Handle(Geom_RectangularTrimmedSurface) rts =
Handle(Geom_RectangularTrimmedSurface)::DownCast(mySurface);
isRect = Standard_True;
Standard_Real V1,V2;
rts->Bounds(U1,U2,V1,V2);
S = rts->BasisSurface();
}
else if (mySurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
Handle(Geom_OffsetSurface) ofs =
Handle(Geom_OffsetSurface)::DownCast(mySurface);
S = ofs->BasisSurface();
}
else
S = mySurface;
if(S->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))||
S->IsKind(STANDARD_TYPE(Geom_ConicalSurface))||
S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))||
S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))||
S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
Standard_Real UFirst = myUSplitValues->Sequence().First();
Standard_Real ULast = myUSplitValues->Sequence().Last();
Standard_Real maxAngle = myMaxAngle; //maximal u length of segment
Standard_Real uLength = ULast-UFirst;
Standard_Integer nbSegments = Standard_Integer((uLength-Precision::Angular())/maxAngle)+1;
if(nbSegments==1)
if(!isRect || !(uLength < maxAngle) || !((U2-U1) < maxAngle))
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
Standard_Real segAngle = uLength/nbSegments;
Standard_Real currAngle = segAngle+UFirst;
Handle(TColStd_HSequenceOfReal) splitValues = new TColStd_HSequenceOfReal;
for( Standard_Integer i = 1; i < nbSegments; i++, currAngle+=segAngle)
splitValues->Append(currAngle);
SetUSplitValues ( splitValues );
}
}

View File

@@ -0,0 +1,30 @@
-- File: ShapeUpgrade_SplitSurfaceArea.cdl
-- Created: Mon Aug 7 11:35:17 2006
-- Author: Galina KULIKOVA
-- <gka@zamox.nnov.matra-dtv.fr>
---Copyright: Open CASCADE 2006
class SplitSurfaceArea from ShapeUpgrade inherits SplitSurface from ShapeUpgrade
---Purpose:Split surface in the parametric space
-- in according specified number of splits on the
is
Create returns mutable SplitSurfaceArea from ShapeUpgrade;
---Purpose: Empty constructor.
NbParts(me: mutable) returns Integer;
---C++: inline
---C++: return &
---Purpose:Set number of split for surfaces
Compute(me: mutable; Segment: Boolean = Standard_True) is redefined;
fields
myNbParts : Integer; -- number of splitting
end SplitSurfaceArea;

View File

@@ -0,0 +1,67 @@
#include <ShapeUpgrade_SplitSurfaceArea.ixx>
#include <TColStd_HSequenceOfReal.hxx>
#include <GeomAdaptor_Surface.hxx>
//=======================================================================
//function : ShapeUpgrade_SplitSurfaceArea
//purpose :
//=======================================================================
ShapeUpgrade_SplitSurfaceArea::ShapeUpgrade_SplitSurfaceArea():
ShapeUpgrade_SplitSurface()
{
myNbParts =1;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceArea::Compute(const Standard_Boolean /*Segment*/)
{
if(myNbParts <= 1)
return;
GeomAdaptor_Surface ads(mySurface,myUSplitValues->Value(1),myUSplitValues->Value(2),
myVSplitValues->Value(1),myVSplitValues->Value(2));
Standard_Real aKoefU = ads.UResolution(1.);
Standard_Real aKoefV = ads.VResolution(1.);
if(aKoefU ==0)
aKoefU =1.;
if(aKoefV ==0)
aKoefV =1.;
Standard_Real aUSize = fabs(myUSplitValues->Value(2) - myUSplitValues->Value(1))/aKoefU;
Standard_Real aVSize = fabs(myVSplitValues->Value(2) - myVSplitValues->Value(1))/aKoefV;
Standard_Real aNbUV = aUSize/aVSize;
Handle(TColStd_HSequenceOfReal) aFirstSplit = (aNbUV <1. ? myVSplitValues : myUSplitValues);
Handle(TColStd_HSequenceOfReal) aSecondSplit = (aNbUV <1. ? myUSplitValues : myVSplitValues);
if(aNbUV<1)
aNbUV = 1./aNbUV;
Standard_Integer nbSplitF = (aNbUV >= myNbParts ? myNbParts : RealToInt(ceil(sqrt(myNbParts*ceil(aNbUV)))));
Standard_Integer nbSplitS = (aNbUV >= myNbParts ? 0 : RealToInt(ceil((Standard_Real)myNbParts/(Standard_Real)nbSplitF)));
if(nbSplitS ==1)
nbSplitS++;
if(!nbSplitF)
return;
Standard_Real aStep = (aFirstSplit->Value(2) - aFirstSplit->Value(1))/nbSplitF;
Standard_Real aPrevPar = aFirstSplit->Value(1);
Standard_Integer i =1;
for( ; i < nbSplitF; i++) {
Standard_Real aNextPar = aPrevPar + aStep;
aFirstSplit->InsertBefore(i+1,aNextPar);
aPrevPar = aNextPar;
}
if(nbSplitS) {
aStep = (aSecondSplit->Value(2) - aSecondSplit->Value(1))/nbSplitS;
aPrevPar = aSecondSplit->Value(1);
for(i =1 ; i < nbSplitS; i++) {
Standard_Real aNextPar = aPrevPar + aStep;
aSecondSplit->InsertBefore(i+1,aNextPar);
aPrevPar = aNextPar;
}
}
}

View File

@@ -0,0 +1,6 @@
inline Standard_Integer& ShapeUpgrade_SplitSurfaceArea::NbParts()
{
return myNbParts;
}

View File

@@ -0,0 +1,43 @@
-- File: ShapeUpgrade_SplitSurfaceContinuity.cdl
-- Created: Wed Apr 14 15:00:13 1999
-- Author: Roman LYGIN
-- <rln@kinox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class SplitSurfaceContinuity from ShapeUpgrade inherits SplitSurface from ShapeUpgrade
---Purpose: Splits a Surface with a continuity criterion.
-- At the present moment C1 criterion is used only.
-- This tool works with tolerance. If C0 surface can be corrected
-- at a knot with given tolerance then the surface is corrected,
-- otherwise it is spltted at that knot.
uses
Shape from GeomAbs
is
Create returns mutable SplitSurfaceContinuity from ShapeUpgrade;
---Purpose: Empty constructor.
SetCriterion (me: mutable; Criterion: Shape from GeomAbs);
---Purpose: Sets criterion for splitting.
SetTolerance (me: mutable; Tol: Real);
---Purpose: Sets tolerance.
--Build (me: mutable; Segment: Boolean) is redefined;
--Purpose: Performs correction/splitting of the supporting surface(s).
--- First defines splitting values, then calls inherited method.
Compute(me: mutable; Segment: Boolean) is redefined;
--Perform(me: mutable; Segment: Boolean);
fields
myCriterion: Shape from GeomAbs;
myTolerance: Real;
myCont : Integer;
end SplitSurfaceContinuity;

View File

@@ -0,0 +1,305 @@
// File: ShapeUpgrade_SplitSurfaceContinuity.cxx
// Created: Wed Apr 14 15:19:20 1999
// Author: Roman LYGIN
// <rln@kinox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_SplitSurfaceContinuity.ixx>
#include <Geom_BSplineSurface.hxx>
#include <Precision.hxx>
#include <ShapeUpgrade.hxx>
#include <TColGeom_HArray2OfSurface.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <Geom_SweptSurface.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <gp_Ax1.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <ShapeExtend.hxx>
//======================================================================
//function : ShapeUpgrade_SplitSurface
//purpose :
//=======================================================================
ShapeUpgrade_SplitSurfaceContinuity::ShapeUpgrade_SplitSurfaceContinuity()
{
myCriterion = GeomAbs_C1;
myTolerance = Precision::Confusion();
}
//=======================================================================
//function : SetCrierion
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceContinuity::SetCriterion(const GeomAbs_Shape Criterion)
{
myCriterion = Criterion;
switch (myCriterion) {
default :
case GeomAbs_C1 : myCont = 1; break;
case GeomAbs_C2 : myCont = 2; break;
case GeomAbs_C3 : myCont = 3; break;
case GeomAbs_CN : myCont = 4; break;
}
}
//=======================================================================
//function : SetTolerance
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceContinuity::SetTolerance(const Standard_Real Tol)
{
myTolerance = Tol;
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceContinuity::Compute(const Standard_Boolean Segment)
{
if(!Segment) {
Standard_Real UF,UL,VF,VL;
mySurface->Bounds(UF,UL,VF,VL);
if(!Precision::IsInfinite(UF)) myUSplitValues->SetValue(1,UF);
if(!Precision::IsInfinite(UL)) myUSplitValues->SetValue(myUSplitValues->Length(),UL);
if(!Precision::IsInfinite(VF)) myVSplitValues->SetValue(1,VF);
if(!Precision::IsInfinite(VL)) myVSplitValues->SetValue(myVSplitValues->Length(),VL);
}
Standard_Real UFirst = myUSplitValues->Value(1);
Standard_Real ULast = myUSplitValues->Value(myUSplitValues->Length());
Standard_Real VFirst = myVSplitValues->Value(1);
Standard_Real VLast = myVSplitValues->Value(myVSplitValues->Length());
Standard_Real precision = Precision::Confusion();
// if (ShapeUpgrade::Debug()) cout << "SplitSurfaceContinuity::Build" << endl;
if(mySurface->Continuity() < myCriterion)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
if (myUSplitValues->Length() >2 || myVSplitValues->Length() >2 )
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
if (mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
Handle(Geom_SurfaceOfRevolution) Surface = Handle(Geom_SurfaceOfRevolution)::DownCast(mySurface);
if(Surface->Continuity() >= myCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() ==2 ) {
return;
}
Handle(Geom_Curve) BasCurve = Surface->BasisCurve();
ShapeUpgrade_SplitCurve3dContinuity spc;
spc.Init(BasCurve,VFirst,VLast);
spc.SetCriterion(myCriterion);
spc.SetTolerance(myTolerance);
spc.SetSplitValues(myVSplitValues);
spc.Compute();
myVSplitValues->Clear();
myVSplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
if ( spc.Status ( ShapeExtend_DONE1 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
if ( spc.Status ( ShapeExtend_DONE2 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
if ( spc.Status ( ShapeExtend_DONE3 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
return;
}
if (mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
Handle(Geom_SurfaceOfLinearExtrusion) Surface = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(mySurface);
if(Surface->Continuity() >= myCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() == 2) {
return;
}
Handle(Geom_Curve) BasCurve = Surface->BasisCurve();
ShapeUpgrade_SplitCurve3dContinuity spc;
spc.Init(BasCurve,UFirst,ULast);
spc.SetCriterion(myCriterion);
spc.SetTolerance(myTolerance);
spc.SetSplitValues(myUSplitValues);
spc.Compute();
myUSplitValues->Clear();
myUSplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
if ( spc.Status ( ShapeExtend_DONE1 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
if ( spc.Status ( ShapeExtend_DONE2 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
if ( spc.Status ( ShapeExtend_DONE3 ) ) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
Handle(Geom_Curve) aNewBascurve = spc.GetCurve();
Surface->SetBasisCurve(aNewBascurve);
}
return;
}
if (mySurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
Handle(Geom_RectangularTrimmedSurface) tmp = Handle(Geom_RectangularTrimmedSurface)::DownCast (mySurface);
if(tmp->Continuity() >= myCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() == 2) {
return;
}
Standard_Real U1,U2,V1,V2;
tmp->Bounds(U1,U2,V1,V2);
Handle(Geom_Surface) theSurf = tmp->BasisSurface();
ShapeUpgrade_SplitSurfaceContinuity sps;
sps.Init(theSurf,Max(U1,UFirst),Min(U2,ULast),Max(V1,VFirst),Min(V2,VLast));
sps.SetUSplitValues(myUSplitValues);
sps.SetVSplitValues(myVSplitValues);
sps.SetTolerance(myTolerance);
sps.SetCriterion(myCriterion);
sps.Compute(Standard_True);
myUSplitValues->Clear();
myUSplitValues->ChangeSequence() = sps.USplitValues()->Sequence();
myVSplitValues->Clear();
myVSplitValues->ChangeSequence() = sps.VSplitValues()->Sequence();
myStatus |= sps.myStatus;
return;
}
else if (mySurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
GeomAbs_Shape BasCriterion;
switch (myCriterion) {
default :
case GeomAbs_C1 : BasCriterion = GeomAbs_C2; break;
case GeomAbs_C2 : BasCriterion = GeomAbs_C3; break;
case GeomAbs_C3 : //if (ShapeUpgrade::Debug()) cout<<". this criterion is not suitable for a Offset Surface"<<endl;;
#ifdef DEB
cout << "Warning: ShapeUpgrade_SplitSurfaceContinuity: criterion C3 for Offset surface" << endl;
#endif
case GeomAbs_CN : BasCriterion = GeomAbs_CN; break;
}
Handle(Geom_OffsetSurface) tmp = Handle(Geom_OffsetSurface)::DownCast (mySurface);
Handle(Geom_Surface) theSurf = tmp->BasisSurface();
if(theSurf->Continuity() >= BasCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() == 2) {
return;
}
ShapeUpgrade_SplitSurfaceContinuity sps;
sps.Init(theSurf,UFirst,ULast,VFirst,VLast);
sps.SetUSplitValues(myUSplitValues);
sps.SetVSplitValues(myVSplitValues);
sps.SetTolerance(myTolerance);
sps.SetCriterion(BasCriterion);
sps.Compute(Standard_True);
myUSplitValues->Clear();
myUSplitValues->ChangeSequence() = sps.USplitValues()->Sequence();
myVSplitValues->Clear();
myVSplitValues->ChangeSequence() = sps.VSplitValues()->Sequence();
myStatus |= sps.myStatus;
return;
}
Handle(Geom_BSplineSurface) MyBSpline;
if(mySurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface)))
MyBSpline = Handle(Geom_BSplineSurface)::DownCast(mySurface->Copy());
if (MyBSpline.IsNull()) {
// if (ShapeUpgrade::Debug()) cout<<". "<<" Surface is not a Bspline"<<endl;
return;
}
if(mySurface->Continuity() >= myCriterion) {
return;
}
// it is a BSplineSurface
Standard_Integer UDeg=MyBSpline->UDegree();
Standard_Integer VDeg=MyBSpline->VDegree();
Standard_Integer NbUKnots= MyBSpline->NbUKnots();
Standard_Integer UFirstInd =MyBSpline->FirstUKnotIndex()+1,
ULastInd = MyBSpline->LastUKnotIndex()-1,
VFirstInd =MyBSpline->FirstVKnotIndex()+1,
VLastInd = MyBSpline->LastVKnotIndex()-1;
Standard_Integer NbVKnots= MyBSpline->NbVKnots();
// if (ShapeUpgrade::Debug()) cout<<". NbUKnots="<<NbUKnots<<endl;
if (NbUKnots>2) {
// Only the internal knots are checked.
Standard_Integer iknot= UFirstInd;
for(Standard_Integer j =2; j <= myUSplitValues->Length(); j++) {
ULast = myUSplitValues->Value(j);
for (; iknot <= ULastInd; iknot++) {
Standard_Real valknot = MyBSpline->UKnot(iknot);
if(valknot <= UFirst + precision) continue;
if( valknot >= ULast - precision) break;
Standard_Integer Continuity=UDeg-MyBSpline->UMultiplicity(iknot);
if (Continuity < myCont) {
// At this knot, the Surface is C0; try to remove Knot.
Standard_Integer newMultiplicity=UDeg - myCont;
Standard_Boolean corrected = Standard_False;
if ( newMultiplicity >= 0 )
corrected=MyBSpline->RemoveUKnot(iknot, newMultiplicity, myTolerance);
if (corrected && newMultiplicity > 0) {
Continuity=UDeg-MyBSpline->UMultiplicity(iknot);
corrected = (Continuity >= myCont);
}
if (corrected) {
// at this knot, the continuity is now C1. Nothing else to do.
// if (ShapeUpgrade::Debug()) cout<<". Correction at UKnot "<<iknot<<endl;
// PTV 15.05.2002 decrease iknot and ULastIndex values if knot removed
if (newMultiplicity ==0) { iknot--; ULastInd--; }
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
else {
// impossible to force C1 within the tolerance:
// this knot will be a splitting value.
Standard_Real u=MyBSpline->UKnot(iknot);
myUSplitValues->InsertBefore(j++,u);
myNbResultingRow++;
// if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl;
}
}
}
UFirst = ULast;
}
}
// if (ShapeUpgrade::Debug()) cout<<". NbVKnots="<<NbVKnots<<endl;
if (NbVKnots>2) {
// Only the internal knots are checked.
Standard_Integer iknot=VFirstInd;
for(Standard_Integer j1 =2; j1 <= myVSplitValues->Length(); j1++) {
VLast = myVSplitValues->Value(j1);
for (; iknot <= VLastInd; iknot++) {
Standard_Real valknot = MyBSpline->VKnot(iknot);
if(valknot <= VFirst + precision) continue;
if( valknot >= VLast - precision) break;
Standard_Integer Continuity=VDeg-MyBSpline->VMultiplicity(iknot);
if (Continuity < myCont) {
// At this knot, the Surface is C0; try to remove Knot.
Standard_Integer newMultiplicity=VDeg - myCont;
Standard_Boolean corrected = Standard_False;
if( newMultiplicity >= 0 )
corrected=MyBSpline->RemoveVKnot(iknot, newMultiplicity, myTolerance);
if (corrected && newMultiplicity > 0) {
Continuity=VDeg-MyBSpline->VMultiplicity(iknot);
corrected = (Continuity >= myCont);
}
if (corrected ) {
// at this knot, the continuity is now Criterion. Nothing else to do.
// if (ShapeUpgrade::Debug()) cout<<". Correction at VKnot "<<iknot<<endl;
// PTV 15.05.2002 decrease iknot and ULastIndex values if knot removed
if (newMultiplicity ==0) { iknot--; VLastInd--; }
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
else {
// this knot will be a splitting value.
Standard_Real v=MyBSpline->VKnot(iknot);
myVSplitValues->InsertBefore(j1++,v);
myNbResultingCol++;
// if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl;
}
}
}
VFirst = VLast;
}
}
if ( Status ( ShapeExtend_DONE3 ) ) {
mySurface = MyBSpline;
}
if (myUSplitValues->Length() >2 || myVSplitValues->Length() >2 )
myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
}

View File

@@ -0,0 +1,70 @@
-- File: ShapeUpgrade_Tool.cdl
-- Created: Tue Aug 31 15:08:56 1999
-- Author: Pavel DURANDIN
-- <pdn@friendox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
private class Tool from ShapeUpgrade inherits TShared from MMgt
---Purpose: Tool is a root class for splitting classes
-- Provides context for recording changes, basic
-- precision value and limit (minimal and maximal)
-- values for tolerances
uses
ReShape from ShapeBuild
is
Create returns Tool from ShapeUpgrade;
---Purpose: Empty constructor
Set (me: mutable; tool: Tool from ShapeUpgrade);
---Purpose: Copy all fields from another Root object
SetContext (me: mutable; context : ReShape from ShapeBuild);
---Purpose: Sets context
---C++: inline
Context (me) returns ReShape from ShapeBuild;
---Purpose: Returns context
---C++: inline
SetPrecision (me: mutable; preci: Real);
---Purpose: Sets basic precision value
---C++: inline
Precision (me) returns Real;
---Purpose: Returns basic precision value
---C++: inline
SetMinTolerance (me: mutable; mintol: Real);
---Purpose: Sets minimal allowed tolerance
---C++: inline
MinTolerance (me) returns Real;
---Purpose: Returns minimal allowed tolerance
---C++: inline
SetMaxTolerance (me: mutable; maxtol: Real);
---Purpose: Sets maximal allowed tolerance
---C++: inline
MaxTolerance (me) returns Real;
---Purpose: Returns maximal allowed tolerance
---C++: inline
LimitTolerance (me; toler: Real) returns Real;
---Purpose: Returns tolerance limited by [myMinTol,myMaxTol]
---C++: inline
fields
myContext : ReShape from ShapeBuild;
myPrecision: Real; -- basic precision
myMinTol : Real; -- minimal allowed tolerance
myMaxTol : Real; -- maximal allowed tolerance
end Tool;

View File

@@ -0,0 +1,33 @@
// File: ShapeUpgrade_Tool.cxx
// Created: Tue Aug 31 15:16:08 1999
// Author: Pavel DURANDIN
// <pdn@friendox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_Tool.ixx>
#include <Precision.hxx>
//=======================================================================
//function : ShapeUpgrade_Tool
//purpose :
//=======================================================================
ShapeUpgrade_Tool::ShapeUpgrade_Tool()
{
myPrecision = myMinTol = Precision::Confusion();
myMaxTol = 1; //Precision::Infinite() ?? pdn
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void ShapeUpgrade_Tool::Set(const Handle(ShapeUpgrade_Tool)& tool)
{
myContext = tool->myContext;
myPrecision = tool->myPrecision;
myMinTol = tool->myMinTol;
myMaxTol = tool->myMaxTol;
}

View File

@@ -0,0 +1,105 @@
// File: ShapeUpgrade_Tool.lxx
// Created: Tue Aug 31 15:21:41 1999
// Author: Pavel DURANDIN
// <pdn@friendox.nnov.matra-dtv.fr>
//=======================================================================
//function : SetContext
//purpose :
//=======================================================================
inline void ShapeUpgrade_Tool::SetContext (const Handle(ShapeBuild_ReShape)& context)
{
myContext = context;
}
//=======================================================================
//function : Context
//purpose :
//=======================================================================
inline Handle(ShapeBuild_ReShape) ShapeUpgrade_Tool::Context() const
{
return myContext;
}
//=======================================================================
//function : SetPrecision
//purpose :
//=======================================================================
inline void ShapeUpgrade_Tool::SetPrecision (const Standard_Real preci)
{
myPrecision = preci;
if(myMaxTol < myPrecision) myMaxTol = myPrecision;
if(myMinTol > myPrecision) myMinTol = myPrecision;
}
//=======================================================================
//function : Precision
//purpose :
//=======================================================================
inline Standard_Real ShapeUpgrade_Tool::Precision() const
{
return myPrecision;
}
//=======================================================================
//function : SetMinTolerance
//purpose :
//=======================================================================
inline void ShapeUpgrade_Tool::SetMinTolerance (const Standard_Real mintol)
{
myMinTol = mintol;
}
//=======================================================================
//function : MinTolerance
//purpose :
//=======================================================================
inline Standard_Real ShapeUpgrade_Tool::MinTolerance() const
{
return myMinTol;
}
//=======================================================================
//function : SetMaxTolerance
//purpose :
//=======================================================================
inline void ShapeUpgrade_Tool::SetMaxTolerance (const Standard_Real maxtol)
{
myMaxTol = maxtol;
}
//=======================================================================
//function : MaxTolerance
//purpose :
//=======================================================================
inline Standard_Real ShapeUpgrade_Tool::MaxTolerance() const
{
return myMaxTol;
}
//=======================================================================
//function : LimitTolerance
//purpose :
//=======================================================================
inline Standard_Real ShapeUpgrade_Tool::LimitTolerance(const Standard_Real toler) const
{
//only maximal restriction implemented.
return Min(myMaxTol,toler);
}

View File

@@ -0,0 +1,140 @@
-- File: ShapeUpgrade_WireDivide.cdl
-- Created: Thu Apr 15 13:06:17 1999
-- Author: Roman LYGIN
-- <rln@kinox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class WireDivide from ShapeUpgrade inherits Tool from ShapeUpgrade
---Purpose: Divides edges in the wire lying on the face or free wires or
-- free edges with a criterion.
-- Splits 3D curve and pcurve(s) of the edge on the face.
-- Other pcurves which may be associated with the edge are simply
-- copied.
-- If 3D curve is splitted then pcurve on the face is splitted as
-- well, and wice-versa.
-- Input shape is not modified.
-- The modifications made are recorded in external context
-- (ShapeBuild_ReShape). This tool is applied to all edges
-- before splitting them in order to keep sharing.
uses
Edge from TopoDS,
Wire from TopoDS,
Face from TopoDS,
Surface from Geom,
Location from TopLoc,
SplitCurve3d from ShapeUpgrade,
SplitCurve2d from ShapeUpgrade,
TransferParameters from ShapeAnalysis,
Status from ShapeExtend,
HSequenceOfReal from TColStd,
EdgeDivide from ShapeUpgrade,
FixSmallCurves from ShapeUpgrade
is
Create returns mutable WireDivide from ShapeUpgrade;
---Purpose: Empty constructor
Init (me: mutable; W: Wire from TopoDS; F: Face from TopoDS);
---Purpose: Initializes by wire and face
Init (me: mutable; W: Wire from TopoDS;
S: Surface from Geom);
---Purpose: Initializes by wire and surface
Load (me: mutable; W: Wire from TopoDS);
---Purpose: Loads working wire
Load (me: mutable; E: Edge from TopoDS);
---Purpose: Creates wire of one edge and calls Load for wire
SetFace (me: mutable; F: Face from TopoDS);
---Purpose: Sets supporting surface by face
SetSurface (me: mutable; S: Surface from Geom);
---Purpose: Sets supporting surface
SetSurface (me: mutable; S: Surface from Geom; L: Location from TopLoc);
---Purpose: Sets supporting surface with location
Perform (me: mutable) is virtual;
---Purpose: Computes the resulting wire by splitting all the edges
-- according to splitting criteria.
-- All the modifications made are recorded in context
-- (ShapeBuild_ReShape). This tool is applied to all edges
-- before splitting them in order to keep sharings.
-- If no supporting face or surface is defined, only 3d
-- splitting criteria are used.
Wire (me) returns Wire from TopoDS;
---C++: return const &
---Purpose: Gives the resulting Wire (equal to initial one if not done
-- or Null if not loaded)
Status (me; status: Status from ShapeExtend) returns Boolean;
---Purpose: Queries status of last call to Perform()
-- OK - no edges were splitted, wire left untouched
-- DONE1 - some edges were splitted
-- FAIL1 - some edges have no 3d curve (skipped)
-- FAIL2 - some edges have no pcurve (skipped)
---Level: Internal
SetSplitCurve3dTool(me: mutable; splitCurve3dTool: SplitCurve3d from ShapeUpgrade);
---Purpose: Sets the tool for splitting 3D curves.
SetSplitCurve2dTool(me: mutable; splitCurve2dTool: SplitCurve2d from ShapeUpgrade);
---Purpose: Sets the tool for splitting pcurves.
SetTransferParamTool(me: mutable; TransferParam: TransferParameters from ShapeAnalysis);
---Purpose: Sets the tool for Transfer parameters between curves and pcurves.
GetSplitCurve3dTool(me) returns SplitCurve3d from ShapeUpgrade
is virtual protected;
---Purpose: Returns the tool for splitting 3D curves.
---Remark: here TopoDS_Edge can be used to transfer some specific information (tolerance, etc)
GetSplitCurve2dTool(me) returns SplitCurve2d from ShapeUpgrade
is virtual protected;
---Purpose: Returns the tool for splitting pcurves.
SetEdgeDivideTool (me: mutable; edgeDivideTool: EdgeDivide from ShapeUpgrade);
---Purpose: Sets tool for splitting edge
GetEdgeDivideTool (me) returns EdgeDivide from ShapeUpgrade
is virtual;
---Purpose: returns tool for splitting edges
GetTransferParamTool(me:mutable) returns TransferParameters from ShapeAnalysis
is virtual;
---Purpose: Returns the tool for Transfer of parameters.
SetEdgeMode(me : mutable;EdgeMode : Integer);
---Purpose:Sets mode for splitting 3d curves from edges.
-- 0 - only curve 3d from free edges.
-- 1 - only curve 3d from shared edges.
-- 2 - all curve 3d.
SetFixSmallCurveTool(me : mutable; FixSmallCurvesTool : FixSmallCurves from ShapeUpgrade);
---Purpose:Sets tool for fixing small curves with specified min tolerance;
GetFixSmallCurveTool(me) returns FixSmallCurves from ShapeUpgrade;
---Purpose:Returns tool for fixing small curves
fields
mySplitCurve3dTool: SplitCurve3d from ShapeUpgrade;
mySplitCurve2dTool: SplitCurve2d from ShapeUpgrade;
myEdgeDivide : EdgeDivide from ShapeUpgrade;
myTransferParamTool : TransferParameters from ShapeAnalysis;
myFace : Face from TopoDS is protected; -- supporting face
myWire : Wire from TopoDS is protected; -- wire being splitted
myStatus: Integer is protected;
myEdgeMode : Integer is protected;
myFixSmallCurveTool : FixSmallCurves from ShapeUpgrade;
end WireDivide;

View File

@@ -0,0 +1,847 @@
// File: ShapeUpgrade_FaceDivide.cxx
// Created: Thu Apr 15 13:10:17 1999
// Author: Roman LYGIN
// <rln@kinox.nnov.matra-dtv.fr>
// gka 23.06.99 S4208: using tool SU_TransferParameter
// pdn 13.07.99 synchronizing splitting values on 3d curve and pcurve
// abv 14.07.99 dealing with edges without 3d curve
// svv 10.01.00 porting on DEC
#include <ShapeUpgrade_WireDivide.ixx>
#include <ShapeUpgrade.hxx>
#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <BRepLib_MakeFace.hxx>
#include <BRepLib_MakeWire.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Iterator.hxx>
#include <ShapeBuild_Edge.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <Precision.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <TColGeom2d_HArray1OfCurve.hxx>
#include <gp_Pnt.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <ShapeExtend.hxx>
#include <TColStd_Array1OfBoolean.hxx>
#include <ShapeBuild_ReShape.hxx>
#include <ShapeAnalysis_TransferParametersProj.hxx>
#include <ShapeUpgrade_FixSmallCurves.hxx>
#include <TopTools_SequenceOfShape.hxx>
#include <TColStd_SequenceOfReal.hxx>
#include <GeomAdaptor_HSurface.hxx>
#include <Geom2dAdaptor_HCurve.hxx>
#include <ShapeAnalysis_Curve.hxx>
#include <Adaptor3d_CurveOnSurface.hxx>
//=======================================================================
//function : ShapeUpgrade_WireDivide
//purpose :
//=======================================================================
ShapeUpgrade_WireDivide::ShapeUpgrade_WireDivide():
ShapeUpgrade_Tool(), myStatus(0)
{
// if (ShapeUpgrade::Debug()) cout <<"ShapeUpgrade_WireDivide"<<endl;
mySplitCurve3dTool = new ShapeUpgrade_SplitCurve3d;
mySplitCurve2dTool = new ShapeUpgrade_SplitCurve2d;
myTransferParamTool = new ShapeAnalysis_TransferParametersProj;
myEdgeMode = 2;
myFixSmallCurveTool = new ShapeUpgrade_FixSmallCurves;
myEdgeDivide = new ShapeUpgrade_EdgeDivide;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::Init(const TopoDS_Wire& W,
const TopoDS_Face& F)
{
// if (ShapeUpgrade::Debug()) cout <<"ShapeUpgrade_WireDivide::Init with Wire, Face"<<endl;
myWire = W;
myFace = F;
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::Init(const TopoDS_Wire& W,
const Handle(Geom_Surface)& S)
{
// if (ShapeUpgrade::Debug()) cout <<"ShapeUpgrade_WireDivide::Init with Wire, Surface "<<endl;
myWire = W;
BRepLib_MakeFace mkf(S);
myFace = mkf.Face();
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::Load(const TopoDS_Wire& W)
{
myWire = W;
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::Load(const TopoDS_Edge& E)
{
BRepLib_MakeWire MakeWire (E);
if (MakeWire.IsDone())
Load (MakeWire.Wire());
}
//=======================================================================
//function : SetFace
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetFace(const TopoDS_Face& F)
{
myFace = F;
}
//=======================================================================
//function : SetSurface
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetSurface(const Handle(Geom_Surface)& S)
{
BRepLib_MakeFace mkf(S);
myFace = mkf.Face();
}
//=======================================================================
//function : SetSurface
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetSurface(const Handle(Geom_Surface)& S,
const TopLoc_Location& L)
{
BRep_Builder B;
B.MakeFace(myFace,S,L,Precision::Confusion());
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
static void CorrectSplitValues(const Handle(TColStd_HSequenceOfReal) orig3d,
const Handle(TColStd_HSequenceOfReal) orig2d,
Handle(TColStd_HSequenceOfReal) new2d,
Handle(TColStd_HSequenceOfReal) new3d)
{
Standard_Real preci = Precision::PConfusion();
Standard_Integer len3d = orig3d->Length();
Standard_Integer len2d = orig2d->Length();
TColStd_Array1OfBoolean fixNew2d (1, len3d);
fixNew2d.Init (Standard_False);
TColStd_Array1OfBoolean fixNew3d (1, len2d);
fixNew3d.Init (Standard_False);
Standard_Real Last3d = orig3d->Value(len3d);
Standard_Real Last2d = orig2d->Value(len2d);
Standard_Integer i;// svv #1
for( i = 1; i <= len3d ; i++) {
Standard_Real par = new2d->Value(i);
Standard_Integer index = 0;
for(Standard_Integer j = 1; j <= len2d && !index; j++)
if(Abs(par-orig2d->Value(j)) < preci)
index = j;
if(index&&!fixNew3d(index)) {
Standard_Real newPar = orig2d->Value(index);
new2d->SetValue(i,newPar);
fixNew2d(i) = Standard_True;
Standard_Real newPar3d = orig3d->Value(i);
new3d->SetValue(index,newPar3d);
fixNew3d(index) = Standard_True;
}
}
for(i = 1; i <= len2d ; i++) {
Standard_Real par = new3d->Value(i);
Standard_Integer index = 0;
for(Standard_Integer j = 1; j <= len3d && !index; j++)
if(Abs(par-orig3d->Value(j)) < preci)
index = j;
if(index&&!fixNew2d(index)) {
Standard_Real newPar = orig3d->Value(index);
new3d->SetValue(i,newPar);
fixNew3d(i) = Standard_True;
Standard_Real newPar2d = orig2d->Value(i);
new2d->SetValue(index,newPar2d);
fixNew2d(index) = Standard_True;
}
}
Standard_Real dpreci = 2* preci;
for(i = 1; i < len3d; i++) {
Standard_Real dist = new2d->Value(i+1) - new2d->Value(i);
if(dist < preci) {
if(fixNew2d(i+1)) {
//changing
Standard_Real tmp = new2d->Value(i+1);
new2d->SetValue(i+1,new2d->Value(i)+dpreci);
new2d->SetValue(i,tmp);
fixNew2d(i) = Standard_True;
fixNew2d(i+1) = Standard_False;
}
else
new2d->SetValue(i+1,new2d->Value(i)+dpreci);
}
}
if(new2d->Value(len3d) > Last3d) {
Standard_Integer ind; // svv #1
for( ind = len3d; ind > 1 && !fixNew2d(ind); ind--);
Standard_Real lastFix = new2d->Value(ind);
for(i = len3d; i >= ind; i--) {
new2d->SetValue(i,lastFix);
lastFix-=dpreci;
}
}
for(i = 1; i < len2d; i++) {
Standard_Real dist = new3d->Value(i+1) - new3d->Value(i);
if(dist < preci) {
if(fixNew3d(i+1)) {
//changing
Standard_Real tmp = new3d->Value(i+1);
new3d->SetValue(i+1,new3d->Value(i)+dpreci);
new3d->SetValue(i,tmp);
fixNew3d(i) = Standard_True;
fixNew3d(i+1) = Standard_False;
}
else
new3d->SetValue(i+1,new3d->Value(i)+dpreci);
}
}
if(new3d->Value(len2d) > Last2d) {
Standard_Integer ind; // svv #1
for(ind = len2d; ind > 1 && !fixNew3d(ind); ind--);
Standard_Real lastFix = new3d->Value(ind);
for(i = len2d; i >= ind; i--) {
new3d->SetValue(i,lastFix);
lastFix-=dpreci;
}
}
}
void ShapeUpgrade_WireDivide::Perform ()
{
myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
// if (ShapeUpgrade::Debug()) cout << "ShapeUpgrade_WireDivide::Perform" << endl;
BRep_Builder B;
ShapeAnalysis_Edge sae;
TopoDS_Wire newWire;
B.MakeWire (newWire);
TopLoc_Location Loc;
Handle(Geom_Surface) Surf;
if(!myFace.IsNull())
Surf = BRep_Tool::Surface(myFace, Loc);
Standard_Boolean isSplit3d = Standard_True;
switch(myEdgeMode) {
case 0: if(!myFace.IsNull()) isSplit3d = Standard_False; break;
case 1: if(myFace.IsNull()) isSplit3d = Standard_False; break;
default : break;
}
myEdgeDivide->SetFace(myFace);
if(isSplit3d)
myEdgeDivide->SetSplitCurve3dTool(GetSplitCurve3dTool());
myEdgeDivide->SetSplitCurve2dTool(GetSplitCurve2dTool());
for (TopoDS_Iterator ItW (myWire,Standard_False); ItW.More(); ItW.Next()) {
// for each Edge:
TopoDS_Shape sh = Context()->Apply(ItW.Value(),TopAbs_SHAPE);
for(TopExp_Explorer exp(sh,TopAbs_EDGE); exp.More(); exp.Next()) {
TopoDS_Edge E = TopoDS::Edge(exp.Current());
// if (ShapeUpgrade::Debug()) cout << ".. Edge " << (void*) &(*E.TShape()) << endl;
// skip degenerated edges (and also INTERNAL/EXTERNAL, to avoid failures)
if ( E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL ) {
B.Add ( newWire, E );
continue;
}
if(!myEdgeDivide->Compute(E)) {
B.Add ( newWire, E );
continue;
}
// first iteration: getting split knots
// on 3D curve: preliminary
Handle(ShapeAnalysis_TransferParameters) theTransferParamTool = GetTransferParamTool();
theTransferParamTool->SetMaxTolerance(MaxTolerance());
theTransferParamTool->Init(E,myFace);
Standard_Boolean wasSR = theTransferParamTool->IsSameRange();
// on pcurve(s): all knots
// assume that if seam-edge, its pcurve1 and pcurve2 has the same split knots !!!
Handle(TColStd_HSequenceOfReal) theKnots3d = myEdgeDivide->Knots3d();
Handle(TColStd_HSequenceOfReal) theKnots2d = myEdgeDivide->Knots2d();
// second iteration: transfer parameters and build segments
Handle(TColStd_HSequenceOfReal) SplitValues2d;
Handle(TColStd_HSequenceOfReal) SplitValues3d;
if(myEdgeDivide->HasCurve2d() && myEdgeDivide->HasCurve3d() ) {
SplitValues2d = theTransferParamTool->Perform(theKnots3d,Standard_True);
SplitValues3d = theTransferParamTool->Perform(theKnots2d,Standard_False);
CorrectSplitValues(theKnots3d,theKnots2d,SplitValues2d,SplitValues3d);
}
Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = myEdgeDivide->GetSplitCurve3dTool();
Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = myEdgeDivide->GetSplitCurve2dTool();
if ( myEdgeDivide->HasCurve2d() ) {
if(! theKnots3d.IsNull() ) {
SplitValues2d->Remove(1);
SplitValues2d->Remove(SplitValues2d->Length());
theSplit2dTool->SetSplitValues (SplitValues2d);
}
theSplit2dTool->Build(Standard_True);
}
if ( myEdgeDivide->HasCurve3d() ) {
if( ! theKnots2d.IsNull() ) {
SplitValues3d->Remove(1);
SplitValues3d->Remove(SplitValues3d->Length());
theSplit3dTool->SetSplitValues (SplitValues3d);
}
theSplit3dTool->Build (Standard_True);
}
// get 2d and 3d split values which should be the same
if ( myEdgeDivide->HasCurve2d() ) theKnots2d = theSplit2dTool->SplitValues();
if ( myEdgeDivide->HasCurve3d() ) theKnots3d = theSplit3dTool->SplitValues();
Standard_Boolean isSeam = Standard_False;
if (! myFace.IsNull() )
isSeam = BRep_Tool::IsClosed ( E, myFace );
Handle(TColGeom2d_HArray1OfCurve) theSegments2d;
if(myEdgeDivide->HasCurve2d())
theSegments2d = theSplit2dTool->GetCurves();
Handle(TColGeom2d_HArray1OfCurve) theSegments2dR;
if ( isSeam ) {
Handle(Geom2d_Curve) c2;
Standard_Real f2, l2;
//smh#8
TopoDS_Shape tmpE = E.Reversed();
TopoDS_Edge erev = TopoDS::Edge (tmpE );
if ( sae.PCurve ( erev, myFace, c2, f2, l2, Standard_False) ) {
theSplit2dTool->Init (c2, f2, l2);
if(!theKnots2d.IsNull())
theSplit2dTool->SetSplitValues (theKnots2d);
theSplit2dTool->Perform (Standard_True);
Handle(TColStd_HSequenceOfReal) revKnots2d = theSplit2dTool->SplitValues();
if(revKnots2d->Length()!=revKnots2d->Length()) {
isSeam = Standard_False;
#ifdef DEB
cout << "Error: ShapeUpgrade_WireDivide: seam has different splitting values on pcurvesd" << endl;
#endif
}
else
theSegments2dR = theSplit2dTool->GetCurves();
}
else isSeam = Standard_False;
}
// Exploring theEdge
TopoDS_Vertex V1o = TopExp::FirstVertex (E, Standard_False);
TopoDS_Vertex V2o = TopExp::LastVertex (E, Standard_False);
Standard_Boolean isForward = ( E.Orientation() == TopAbs_FORWARD );
Standard_Real TolEdge = BRep_Tool::Tolerance (E);
Standard_Boolean isDeg = BRep_Tool::Degenerated ( E );
// Copy vertices to protect original shape against SameParamseter
//smh#8
TopoDS_Shape emptyCopiedV1 = V1o.EmptyCopied();
TopoDS_Vertex V1 = TopoDS::Vertex ( emptyCopiedV1 );
Context()->Replace ( V1o, V1 );
TopoDS_Vertex V2;
if ( V1o.IsSame ( V2o ) ) {
//smh#8
TopoDS_Shape tmpV = V1.Oriented(V2o.Orientation() );
V2 = TopoDS::Vertex ( tmpV );
}
else {
//smh#8
TopoDS_Shape emptyCopied = V2o.EmptyCopied();
V2 = TopoDS::Vertex ( emptyCopied );
Context()->Replace ( V2o, V2 );
}
//collect NM vertices
Standard_Real af,al;
Handle(Geom_Curve) c3d;
Adaptor3d_CurveOnSurface AdCS;
if(myEdgeDivide->HasCurve3d())
sae.Curve3d(E,c3d,af,al,Standard_False);
else if(myEdgeDivide->HasCurve2d() && !Surf.IsNull()) {
Handle(Geom2d_Curve) c2d;
sae.PCurve ( E, myFace, c2d, af, al, Standard_False);
Handle(GeomAdaptor_HSurface) AdS = new GeomAdaptor_HSurface(Surf);
Handle(Geom2dAdaptor_HCurve) AC2d = new Geom2dAdaptor_HCurve(c2d,af,al);
AdCS.Load(AC2d);
AdCS.Load(AdS);
}
TopTools_SequenceOfShape aSeqNMVertices;
TColStd_SequenceOfReal aSeqParNM;
TopoDS_Iterator aItv(E,Standard_False);
ShapeAnalysis_Curve sac;
for ( ; aItv.More() ; aItv.Next()) {
if(aItv.Value().Orientation() == TopAbs_INTERNAL ||
aItv.Value().Orientation() == TopAbs_EXTERNAL) {
TopoDS_Vertex aVold = TopoDS::Vertex(aItv.Value());
aSeqNMVertices.Append(aVold);
gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aVold));
Standard_Real ppar;
gp_Pnt pproj;
if(!c3d.IsNull())
sac.Project(c3d,aP,Precision(),pproj,ppar,af,al,Standard_False);
else
sac.Project(AdCS,aP,Precision(),pproj,ppar);
aSeqParNM.Append(ppar);
}
}
// creating new edge(s)
Handle(TColGeom_HArray1OfCurve) theSegments3d;
if(myEdgeDivide->HasCurve3d()) theSegments3d = theSplit3dTool->GetCurves();
Standard_Integer nbc = 0;
if (!theSegments3d.IsNull()) {
nbc = theSegments3d->Length();
if ( !theSegments2d.IsNull() ) {
Standard_Integer nbc2d = theSegments2d->Length();
if (nbc!=nbc2d) {
#ifdef DEB
cout<<"Error: Number of intervals are not equal for 2d 3d. Ignored."<<endl;
#endif
nbc = Min( nbc,nbc2d);
}
}
}
else
if(!theSegments2d.IsNull())// if theSegments have different length ???
nbc = theSegments2d->Length();
if ( nbc <= 1 && ! theSplit3dTool->Status ( ShapeExtend_DONE ) &&
! theSplit2dTool->Status ( ShapeExtend_DONE ) ) {
B.Add ( newWire, E );
continue;
}
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
TopoDS_Wire resWire;
B.MakeWire (resWire);
// TopoDS_Vertex firstVertex, lastVertex;
Standard_Integer numE =0;
gp_Pnt pntV1 = BRep_Tool::Pnt(V1);
//gp_Pnt pntV2 = BRep_Tool::Pnt(V2); // pntV2 not used - see below (skl)
Standard_Real V1Tol = LimitTolerance( BRep_Tool::Tolerance(V1) );
//Standard_Real V2Tol = LimitTolerance( BRep_Tool::Tolerance(V2) ); // V2Tol not used - see below (skl)
Handle(ShapeUpgrade_FixSmallCurves) FixSmallCurveTool = GetFixSmallCurveTool(); //gka Precision
FixSmallCurveTool->SetMinTolerance(MinTolerance());
FixSmallCurveTool->Init(E, myFace);
FixSmallCurveTool->SetSplitCurve3dTool(theSplit3dTool);
FixSmallCurveTool->SetSplitCurve2dTool(theSplit2dTool);
FixSmallCurveTool->SetPrecision(MinTolerance());
Standard_Integer Savnum =0;
Standard_Real SavParf;
Standard_Integer Small = 0;
for ( Standard_Integer icurv = 1; icurv <= nbc; icurv++ ) {
Handle(Geom_Curve) theNewCurve3d;
if(!theSegments3d.IsNull()) theNewCurve3d = theSegments3d->Value(icurv);
Handle(Geom2d_Curve) theNewPCurve1;
if(!theSegments2d.IsNull()) theNewPCurve1 = theSegments2d->Value(icurv);
Handle(Geom2d_Curve) revPCurve;
if(isSeam)
revPCurve = theSegments2dR->Value(icurv);
// construction of the intermediate Vertex
TopoDS_Vertex V;
if ( icurv <= nbc && nbc != 1 && ! isDeg ) {
Standard_Real par,parf /*,SavParl*/;
//Standard_Real SaveParf; // SaveParf not used - see below (skl)
gp_Pnt P,P1,PM;
// if edge has 3d curve, take point from it
if ( ! theNewCurve3d.IsNull() ) {
if(theNewCurve3d->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) {
par = theNewCurve3d->LastParameter();
parf = theNewCurve3d->FirstParameter();
}
else {
par = theKnots3d->Value (icurv + 1);
parf = theKnots3d->Value (icurv);
}
P = theNewCurve3d->Value (par);
P1 = theNewCurve3d->Value (parf);
PM = theNewCurve3d->Value ((parf+par)/2);
}
// else use pcurve and surface (suppose that both exist)
else {
if ( Surf.IsNull() ) Surf = BRep_Tool::Surface ( myFace, Loc );
if ( theNewPCurve1->IsKind(STANDARD_TYPE(Geom2d_BoundedCurve)) ) {
par = theNewPCurve1->LastParameter();
parf = theNewPCurve1->FirstParameter();
}
else {
par = theKnots2d->Value (icurv + 1);
parf = theKnots2d->Value (icurv);
}
gp_Pnt2d p2d = theNewPCurve1->Value (par);
gp_Pnt2d p2df = theNewPCurve1->Value (parf);
gp_Pnt2d p2dM = theNewPCurve1->Value ((parf+par)/2);
P = Surf->Value ( p2d.X(), p2d.Y() );
P1 = Surf->Value ( p2df.X(), p2df.Y() );
PM = Surf->Value ( p2dM.X(), p2dM.Y() );
P.Transform ( Loc.Transformation() );
P1.Transform ( Loc.Transformation() );
PM.Transform ( Loc.Transformation() );
}
if(P.Distance(pntV1) < MinTolerance() && P.Distance(PM) < MinTolerance() && !myFace.IsNull()) {
if(!Small) {
SavParf = parf;
Savnum = icurv;
}
//SavParl = par;
Small++;
if(icurv == nbc) {
TopoDS_Vertex VVV = V1;
VVV.Orientation ( V2.Orientation() );
Context()->Replace(V2,VVV);
}
continue;
}
if(Small) {
if(P.Distance(P1) > MinTolerance() || P.Distance(PM) > MinTolerance()) {
//FixSmallCurveTool->Perform(prevEdge,theNewCurve3d,theNewPCurve1,revPCurve,SavParf,SavParl);
gp_Pnt pmid = 0.5 * ( pntV1.XYZ() + P1.XYZ() );
B.UpdateVertex(V1,pmid,0);
}
else {
Handle(Geom_Curve) atmpCurve;
Handle(Geom2d_Curve) atmpCurve2d1,atmprepcurve;
if(FixSmallCurveTool->Approx( atmpCurve,atmpCurve2d1,atmprepcurve,SavParf,par)) { //BRepTools
theNewCurve3d = atmpCurve;
theNewPCurve1 = atmpCurve2d1;
revPCurve = atmprepcurve;
}
else {
gp_Pnt pmid = 0.5 * ( pntV1.XYZ() + P1.XYZ() );
B.UpdateVertex(V1,pmid,0);
}
}
Small =0;
}
//pdn
/* if(P.Distance (pntV1) < V1Tol)
V = V1;
else if (P.Distance (pntV2) < V2Tol) {
V = V2;
V1Tol = V2Tol;
pntV1 = pntV2;
}
else {*/
if(icurv != nbc) {
B.MakeVertex (V, P, TolEdge); //tolerance of the edge
pntV1 = P;
V1Tol = LimitTolerance( TolEdge );
}
else V = V2;
// else V2;
// }
// if (ShapeUpgrade::Debug()) cout <<"... New intermediate Vertex ("
// <<P.X()<<","<<P.Y()<<","<<P.Z()<<") :"<<(void*) &(*V.TShape())
// <<" with Tolerance "<<TolEdge <<endl;
}
//else V = V2;
TopoDS_Edge newEdge;
ShapeBuild_Edge sbe;
if ( isForward ) {
V1.Orientation ( TopAbs_FORWARD );
V.Orientation ( TopAbs_REVERSED );
newEdge = sbe.CopyReplaceVertices ( E, V1, V );
}
else {
V1.Orientation ( TopAbs_REVERSED );
V.Orientation ( TopAbs_FORWARD );
newEdge = sbe.CopyReplaceVertices ( E, V, V1 );
}
sbe.CopyPCurves ( newEdge, E );
if(!theNewCurve3d.IsNull())
B.UpdateEdge ( newEdge, theNewCurve3d, 0. );
else if ( isDeg )
B.Degenerated( newEdge, Standard_True);
//if(isSeam) {
// Handle(Geom2d_Curve) revPCurve = theSegments2dR->Value(icurv);
//if(newEdge.Orientation()==TopAbs_FORWARD)
//B.UpdateEdge ( newEdge, theNewPCurve1, revPCurve, myFace, 0. );
//else
//B.UpdateEdge ( newEdge, revPCurve, theNewPCurve1, myFace, 0. );
//}
//else if ( ! myFace.IsNull() )
//B.UpdateEdge ( newEdge, theNewPCurve1, myFace, 0. );
Standard_Real f3d = 0., l3d =0.;
if(!Savnum) Savnum = icurv;
Standard_Boolean srNew;
if(!theNewCurve3d.IsNull()) {
if(theNewCurve3d->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) {
f3d = theNewCurve3d->FirstParameter();
l3d = theNewCurve3d->LastParameter();
srNew = ((f3d == theKnots3d->Value (Savnum)) && (l3d == theKnots3d->Value (icurv + 1)));
}
else {
f3d = theKnots3d->Value (Savnum);
l3d = theKnots3d->Value (icurv + 1);
srNew = Standard_True;
}
}
else
srNew = Standard_True;
Standard_Real f2d=0, l2d=0;
if(!theNewPCurve1.IsNull()){
if(theNewPCurve1->IsKind(STANDARD_TYPE(Geom2d_BoundedCurve))) {
f2d = theNewPCurve1->FirstParameter();
l2d = theNewPCurve1->LastParameter();
srNew &= ((f2d == theKnots2d->Value (Savnum)) && (l2d == theKnots2d->Value (icurv + 1)));
}
else {
f2d = theKnots2d->Value (Savnum);
l2d = theKnots2d->Value (icurv + 1);
}
}
//if(!Savnum) Savnum = icurv;
if(!theNewCurve3d.IsNull())
theTransferParamTool->TransferRange(newEdge,theKnots3d->Value (Savnum),theKnots3d->Value (icurv + 1),Standard_False);
else
theTransferParamTool->TransferRange(newEdge,theKnots2d->Value (Savnum),theKnots2d->Value (icurv + 1),Standard_True);
/*
Standard_Real alpha = (theKnots3d->Value (icurv) - f)/(l - f);
Standard_Real beta = (theKnots3d->Value (icurv + 1) - f)/(l - f);
sbe.CopyRanges(newEdge,E, alpha, beta);*/
Savnum =0;
Handle(Geom2d_Curve) c2dTmp;
Standard_Real setF, setL;
if( ! myFace.IsNull() && sae.PCurve (newEdge, myFace, c2dTmp, setF, setL, Standard_False))
srNew &= ( (setF==f2d) && (setL==l2d) );
if(isSeam) {
// Handle(Geom2d_Curve revPCurve = theSegments2dR->Value(icurv);
if(newEdge.Orientation()==TopAbs_FORWARD)
B.UpdateEdge ( newEdge, theNewPCurve1, revPCurve, myFace, 0. );
else
B.UpdateEdge ( newEdge, revPCurve, theNewPCurve1, myFace, 0. );
}
else if ( ! myFace.IsNull() ) {
B.UpdateEdge ( newEdge, theNewPCurve1, myFace, 0. );
}
if(!theNewCurve3d.IsNull())
sbe.SetRange3d(newEdge,f3d,l3d);
if(!theNewPCurve1.IsNull())
B.Range ( newEdge, myFace, f2d, l2d);
if((!wasSR || !srNew)&&!BRep_Tool::Degenerated(newEdge) )
B.SameRange(newEdge, Standard_False);
//addition NM vertices to new edges
Standard_Real afpar = (myEdgeDivide->HasCurve3d() ? f3d : f2d);
Standard_Real alpar = (myEdgeDivide->HasCurve3d() ? l3d: l2d);
Standard_Integer n =1;
for( ; n <= aSeqParNM.Length(); n++) {
Standard_Real apar = aSeqParNM.Value(n);
TopoDS_Vertex aVold = TopoDS::Vertex(aSeqNMVertices.Value(n));
TopoDS_Vertex aNMVer =ShapeAnalysis_TransferParametersProj::CopyNMVertex(aVold,newEdge,E);
Context()->Replace(aVold,aNMVer);
if(fabs(apar - afpar) <= Precision::PConfusion())
Context()->Replace(aNMVer,V1);
else if(fabs(apar - alpar) <= Precision::PConfusion())
Context()->Replace(aNMVer,V);
else if( apar > afpar && apar <alpar)
B.Add (newEdge,aNMVer);
else continue;
aSeqNMVertices.Remove(n);
aSeqParNM.Remove(n);
n--;
}
// if (ShapeUpgrade::Debug()) cout <<"... New Edge "
// <<(void*) &(*newEdge.TShape())<<" on vertices "
// <<(void*) &(*V1.TShape())<<", " <<(void*) &(*V.TShape())
// <<" with Tolerance "<<TolEdge <<endl;
B.Add ( resWire, newEdge );
B.Add ( newWire, newEdge );
numE++;
V1 = V;
}
if(numE)
Context()->Replace(E,resWire);
else
Context()->Remove(E);
}
}
if ( Status ( ShapeExtend_DONE ) ) {
//smh#8
TopoDS_Shape tmpW = Context()->Apply ( newWire ).Oriented(myWire.Orientation());
myWire = TopoDS::Wire (tmpW );
}
}
//=======================================================================
//function : Face
//purpose :
//=======================================================================
const TopoDS_Wire& ShapeUpgrade_WireDivide::Wire() const
{
return myWire;
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_WireDivide::Status (const ShapeExtend_Status status) const
{
return ShapeExtend::DecodeStatus ( myStatus, status );
}
//=======================================================================
//function : SetSplitCurve3dTool
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetSplitCurve3dTool(const Handle(ShapeUpgrade_SplitCurve3d)& splitCurve3dTool)
{
mySplitCurve3dTool = splitCurve3dTool;
}
//=======================================================================
//function : SetSplitCurve2dTool
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetSplitCurve2dTool(const Handle(ShapeUpgrade_SplitCurve2d)& splitCurve2dTool)
{
mySplitCurve2dTool = splitCurve2dTool;
}
//=======================================================================
//function : GetSplitCurve3dTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_SplitCurve3d) ShapeUpgrade_WireDivide::GetSplitCurve3dTool() const
{
return mySplitCurve3dTool;
}
//=======================================================================
//function : GetSplitCurve2dTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_SplitCurve2d) ShapeUpgrade_WireDivide::GetSplitCurve2dTool() const
{
return mySplitCurve2dTool;
}
//=======================================================================
//function : SetEdgeDivideTool
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetEdgeDivideTool(const Handle (ShapeUpgrade_EdgeDivide)& edgeDivideTool)
{
myEdgeDivide = edgeDivideTool;
}
//=======================================================================
//function : GetEdgeDivideTool
//purpose :
//=======================================================================
Handle (ShapeUpgrade_EdgeDivide) ShapeUpgrade_WireDivide::GetEdgeDivideTool() const
{
return myEdgeDivide;
}
//=======================================================================
//function : SetTransferParamTool
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetTransferParamTool(const Handle(ShapeAnalysis_TransferParameters)& TransferParam)
{
myTransferParamTool = TransferParam;
}
//=======================================================================
//function : GetTransferParamTool
//purpose :
//=======================================================================
Handle(ShapeAnalysis_TransferParameters) ShapeUpgrade_WireDivide::GetTransferParamTool()
{
return myTransferParamTool;
}
//=======================================================================
//function : SetEdgeMode
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetEdgeMode(const Standard_Integer EdgeMode)
{
myEdgeMode = EdgeMode;
}
//=======================================================================
//function : SetFixSmallCurveTool
//purpose :
//=======================================================================
void ShapeUpgrade_WireDivide::SetFixSmallCurveTool(const Handle(ShapeUpgrade_FixSmallCurves)& FixSmallCurvesTool)
{
myFixSmallCurveTool = FixSmallCurvesTool;
}
//=======================================================================
//function : GetFixSmallCurveTool
//purpose :
//=======================================================================
Handle(ShapeUpgrade_FixSmallCurves) ShapeUpgrade_WireDivide::GetFixSmallCurveTool() const
{
return myFixSmallCurveTool;
}