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

Compare commits

...

3 Commits

Author SHA1 Message Date
emv
5defca41ff Improve the algorithm of computation of the exposed area.
The algorithm OCCTools_ComputeExposedArea has been improved by switching to working with compounds of Faces instead of Solids in the Gluing mode.
In the Gluing mode there is no need to work with solids, as the arguments are expected to be touching only and should not have any common volume. Working with faces helps to avoid errors while constructing the solids.
In this mode the result of the operation will be just the compound of faces.
2017-10-02 14:42:30 +03:00
emv
db9ffba268 0027878: Development of the Gluing operations based on the new Boolean component
The Gluing operation is an additional option for the algorithms in the Boolean Component
such as General Fuse, Boolean operations, Section operation, Maker Volume and Cells Builder algorithms.

The Gluing options have been designed to speed up the computation of the interference among arguments of the operations on special cases,
in which the arguments may be overlapping but do not have real intersections between their sub-shapes.

This option cannot be used on the shapes having real intersections, like intersection vertex between edges,
or intersection vertex between edge and a face or intersection line between faces.

The Gluing option is an enumeration implemented in BOPAlgo_GlueEnum.hxx. There are following items in the enum:
* BOPAlgo_GlueOff - default value for the algorithms, Gluing is switched off;
* BOPAlgo_GlueShift - Glue option for shapes with partial coincidence;
* BOPAlgo_GlueFull - Glue option for shapes with full coincidence.

For setting the Gluing options for the algorithm it is just necessary to call the SetGlue(BOPAlgo_GlueEnum) method with appropriate Glue value.

For using this option in DRAW the command bglue has been implemented:
* 0 - default value, Gluing is off;
* 1 - for partial coincidence;
* 2 - for full coincidence

Elimination of the warnings.
2017-05-15 12:46:57 +03:00
bugmaster
f2fcedf674 Creation MOTORS_7.1.0 branch 2017-05-15 10:51:03 +03:00
117 changed files with 8884 additions and 115 deletions

View File

@@ -5,3 +5,6 @@ Visualization TKService TKV3d TKOpenGl TKMeshVS TKIVtk TKD3DHost
ApplicationFramework TKCDF TKLCAF TKCAF TKBinL TKXmlL TKBin TKXml TKStdL TKStd TKTObj TKBinTObj TKXmlTObj TKVCAF
DataExchange TKXSBase TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP TKIGES TKXCAF TKXDEIGES TKXDESTEP TKSTL TKVRML TKXmlXCAF TKBinXCAF
Draw TKDraw TKTopTest TKViewerTest TKXSDRAW TKDCAF TKXDEDRAW TKTObjDRAW TKQADraw TKIVtkDraw DRAWEXE
Helix TKHelix
Unfolding TKUnfolding TKUnfoldingTest
OCCTools TKOCCTools TKOCCToolsTest

View File

@@ -2100,10 +2100,10 @@ With the Fuzzy option it is possible to get the expected result -- it is just ne
Fuzzy option is included in interface of Intersection Part (class *BOPAlgo_PaveFiller*) and application programming interface (class *BRepAlgoAPI_BooleanOperation*)
@subsection occt_algorithms_11a_2 Examples
@subsubsection occt_algorithms_11a_1_1 Examples
The following examples demonstrate the advantages of usage Fuzzy option operations over the Basic Operations in typical situations.
@subsubsection occt_algorithms_11a_1_1 Case 1
#### Case 1
In this example the cylinder (shown in yellow and transparent) is subtracted from the box (shown in red). The cylinder is shifted by 5e<sup>-5</sup> relatively to the box along its axis (the distance between rear faces of the box and cylinder is 5e<sup>-5</sup>).
@@ -2117,7 +2117,7 @@ The following results are obtained using Basic Operations and the Fuzzy ones wit
In this example Fuzzy option allows eliminating a very thin part of the result shape produced by Basic algorithm due to misalignment of rear faces of the box and the cylinder.
@subsubsection occt_algorithms_11a_1_2 Case 2
#### Case 2
In this example two boxes are fused. One of them has dimensions 10*10*10, and the other is 10*10.000001*10.000001 and adjacent to the first one. There is no gap in this case as the surfaces of the neighboring faces coincide, but one box is slightly greater than the other.
@@ -2131,7 +2131,7 @@ The following results are obtained using Basic Operations and the Fuzzy ones wit
In this example Fuzzy option allows eliminating an extremely narrow face in the result produced by Basic operation.
@subsubsection occt_algorithms_11a_1_3 Case 3
#### Case 3
In this example the small planar face (shown in orange) is subtracted from the big one (shown in yellow). There is a gap 1e<sup>-5</sup> between the edges of these faces.
@@ -2145,7 +2145,7 @@ The following results are obtained using Basic Operations and the Fuzzy ones wit
In this example Fuzzy options eliminated a pin-like protrusion resulting from the gap between edges of the argument faces.
@subsubsection occt_algorithms_11a_1_4 Case 4
#### Case 4
In this example the small edge is subtracted from the big one. The edges are overlapping not precisely, with max deviation between them equal to 5.28004e<sup>-5</sup>. We will use 6e<sup>-5</sup> value for Fuzzy option.
@@ -2159,6 +2159,71 @@ The following results are obtained using Basic Operations and the Fuzzy ones wit
This example stresses not only the validity, but also the performance issue. The usage of Fuzzy option with the appropriate value allows processing the case much faster than with the pure Basic operation. The performance gain for the case is 45 (Processor: Intel(R) Core(TM) i5-3450 CPU @ 3.10 GHz).
@subsection occt_algorithms_11a_2 Gluing Operation
The Gluing operation is the option of the Basic Operations, such as General Fuse, Boolean and Section operations.
It has been designed to speed up the computation of the interferences among arguments of the operations on special cases, in which the arguments may be overlapping but do not have real intersections between their sub-shapes.
This option cannot be used on the shapes having real intersections, like intersection vertex between edges, or intersection vertex between edge and a face or intersection line between faces:
@figure{/user_guides/boolean_operations/images/glue_options_image002.png, "Intersecting faces"}
There are two possibilities of overlapping shapes:
* The shapes can be partially coinciding - the faces do not have intersection curves, but overlapping. The faces of such arguments will be split during the operation. The following picture illustrates such shapes:
@figure{/user_guides/boolean_operations/images/glue_options_image001.png, "Partially coinciding faces"}
* The shapes can be fully coinciding - there should be no partial overlapping of the faces, thus no intersection of type EDGE/FACE at all. In such cases the faces will not be split during the operation
@figure{/user_guides/boolean_operations/images/glue_options_image003.png, "Full coinciding faces of the boxes"}
Thus, there are two possible options - for full and partial coincidence of the shapes.
Even though there are no real intersections on such cases without Gluing options the algorithm will still intersect the sub-shapes of the arguments with interfering bounding boxes.
The performance improvement in gluing mode is achieved by excluding the most time consuming computations and in some case can go up to 90%:
* Exclude computation of FACE/FACE intersections for partial coincidence;
* Exclude computation of VERTEX/FACE, EDGE/FACE and FACE/FACE intersections for full coincidence.
By setting the Gluing option for the operation user should guarantee that the arguments are really coinciding. The algorithm does not check this itself. Setting inappropriate option for the operation is likely to lead to incorrect result.
@subsubsection occt_algorithms_11a_2_1 Usage
The Gluing option is an enumeration implemented in BOPAlgo_GlueEnum.hxx:
* BOPAlgo_GlueOff - default value for the algorithms, Gluing is switched off;
* BOPAlgo_GlueShift - Glue option for shapes with partial coincidence;
* BOPAlgo_GlueFull - Glue option for shapes with full coincidence.
#### API level
For setting the Gluing options for the algorithm it is just necessary to call the SetGlue(const BOPAlgo_Glue) method with appropriate value:
~~~~
BOPAlgo_Builder aGF;
//
....
// setting the gluing option to speed up intersection of the arguments
aGF.SetGlue(BOPAlgo_GlueShift)
//
....
~~~~
#### TCL level
For setting the Gluing options in DRAW it is necessary to call the <i>bglue</i> command with appropriate value:
* 0 - default value, Gluing is off;
* 1 - for partial coincidence;
* 2 - for full coincidence
~~~~
bglue 1
~~~~
@subsubsection occt_algorithms_11a_2_2 Examples
#### Case1 - Fusing the 64 bspline boxes into one solid
@figure{/user_guides/boolean_operations/images/glue_options_image004.png, "BSpline Boxes with partial coincidence"}
Performance improvement from using the GlueShift option in this case is about 70 percent.
#### Case2 - Sewing faces of the shape after reading from IGES
@figure{/user_guides/boolean_operations/images/glue_options_image005.png, "Faces with coinciding but not shared edges"}
Performance improvement in this case is also about 70 percent.
@section occt_algorithms_11b Usage
The chapter contains some examples of the OCCT Boolean Component usage. The usage is possible on two levels: C++ and Tcl.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -376,6 +376,7 @@ void BOPAlgo_BOP::Perform()
pPF->SetProgressIndicator(myProgressIndicator);
pPF->SetFuzzyValue(myFuzzyValue);
pPF->SetNonDestructive(myNonDestructive);
pPF->SetGlue(myGlue);
//
pPF->Perform();
//

View File

@@ -51,7 +51,8 @@ BOPAlgo_Builder::BOPAlgo_Builder()
myShapesSD(100, myAllocator),
mySplits(100, myAllocator),
myOrigins(100, myAllocator),
myNonDestructive(Standard_False)
myNonDestructive(Standard_False),
myGlue(BOPAlgo_GlueOff)
{
}
//=======================================================================
@@ -71,7 +72,8 @@ BOPAlgo_Builder::BOPAlgo_Builder
myShapesSD(100, myAllocator),
mySplits(100, myAllocator),
myOrigins(100, myAllocator),
myNonDestructive(Standard_False)
myNonDestructive(Standard_False),
myGlue(BOPAlgo_GlueOff)
{
}
//=======================================================================
@@ -200,6 +202,22 @@ Standard_Boolean BOPAlgo_Builder::NonDestructive() const
return myNonDestructive;
}
//=======================================================================
//function : SetGlue
//purpose :
//=======================================================================
void BOPAlgo_Builder::SetGlue(const BOPAlgo_GlueEnum theGlue)
{
myGlue=theGlue;
}
//=======================================================================
//function : Glue
//purpose :
//=======================================================================
BOPAlgo_GlueEnum BOPAlgo_Builder::Glue() const
{
return myGlue;
}
//=======================================================================
// function: CheckData
// purpose:
//=======================================================================
@@ -268,6 +286,7 @@ void BOPAlgo_Builder::Perform()
pPF->SetProgressIndicator(myProgressIndicator);
pPF->SetFuzzyValue(myFuzzyValue);
pPF->SetNonDestructive(myNonDestructive);
pPF->SetGlue(myGlue);
//
pPF->Perform();
//
@@ -283,6 +302,7 @@ void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller)
myEntryPoint=0;
myNonDestructive = theFiller.NonDestructive();
myFuzzyValue = theFiller.FuzzyValue();
myGlue = theFiller.Glue();
PerformInternal(theFiller);
}
//=======================================================================

View File

@@ -25,6 +25,7 @@
#include <BOPCol_ListOfShape.hxx>
#include <BOPCol_MapOfShape.hxx>
#include <BOPAlgo_PPaveFiller.hxx>
#include <BOPAlgo_GlueEnum.hxx>
#include <BOPDS_PDS.hxx>
#include <Standard_Integer.hxx>
#include <BOPCol_DataMapOfShapeListOfShape.hxx>
@@ -107,6 +108,11 @@ Standard_EXPORT virtual ~BOPAlgo_Builder();
//! a copy of a sub-shape is created in the result if it is needed to be updated.
Standard_EXPORT Standard_Boolean NonDestructive() const;
//! Sets the glue option for the algorithm
Standard_EXPORT void SetGlue(const BOPAlgo_GlueEnum theGlue);
//! Returns the glue option of the algorithm
Standard_EXPORT BOPAlgo_GlueEnum Glue() const;
protected:
@@ -167,6 +173,7 @@ protected:
BOPCol_DataMapOfShapeListOfShape mySplits;
BOPCol_DataMapOfShapeShape myOrigins;
Standard_Boolean myNonDestructive;
BOPAlgo_GlueEnum myGlue;
private:

View File

@@ -0,0 +1,64 @@
// Created by: Eugeny MALTCHIKOV
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _BOPAlgo_GlueEnum_HeaderFile
#define _BOPAlgo_GlueEnum_HeaderFile
//! The Enumeration describes an additional option for the algorithms
//! in the Boolean Component such as General Fuse, Boolean operations,
//! Section operation, Maker Volume and Cells Builder algorithms.
//!
//! The Gluing options have been designed to speed up the computation
//! of the interference among arguments of the operations on special cases,
//! in which the arguments may be overlapping but do not have real intersections
//! between their sub-shapes.
//!
//! This option cannot be used on the shapes having real intersections,
//! like intersection vertex between edges, or intersection vertex between
//! edge and a face or intersection line between faces.
//!
//! There are two possibilities of overlapping shapes:
//! 1. The shapes can be partially coinciding - the faces do not have
//! intersection curves, but overlapping. The faces of such arguments will
//! be split during the operation;
//! 2. The shapes can be fully coinciding - there should be no partial
//! overlapping of the faces, thus no intersection of type EDGE/FACE at all.
//! In such cases the faces will not be split during the operation.
//!
//! Even though there are no real intersections on such cases without Gluing options the algorithm
//! will still intersect the sub-shapes of the arguments with interfering bounding boxes.
//!
//! The performance improvement in gluing mode is achieved by excluding
//! the most time consuming computations according to the given Gluing parameter:
//! 1. Computation of FACE/FACE intersections for partial coincidence;
//! 2. And computation of VERTEX/FACE, EDGE/FACE and FACE/FACE intersections for full coincidence.
//!
//! By setting the Gluing option for the operation user should guarantee
//! that the arguments are really coinciding. The algorithms do not check this itself.
//! Setting inappropriate option for the operation is likely to lead to incorrect result.
//!
//! There are following items in the enumeration:
//! BOPAlgo_GlueOff - default value for the algorithms, Gluing is switched off;
//! BOPAlgo_GlueShift - Glue option for shapes with partial coincidence;
//! BOPAlgo_GlueFull - Glue option for shapes with full coincidence.
//!
enum BOPAlgo_GlueEnum
{
BOPAlgo_GlueOff,
BOPAlgo_GlueShift,
BOPAlgo_GlueFull
};
#endif // _BOPAlgo_GlueEnum_HeaderFile

View File

@@ -101,6 +101,7 @@ void BOPAlgo_MakerVolume::Perform()
pPF->SetProgressIndicator(myProgressIndicator);
pPF->SetFuzzyValue(myFuzzyValue);
pPF->SetNonDestructive(myNonDestructive);
pPF->SetGlue(myGlue);
pPF->Perform();
//
myEntryPoint = 1;

View File

@@ -43,6 +43,7 @@ BOPAlgo_PaveFiller::BOPAlgo_PaveFiller()
myIterator=NULL;
myNonDestructive=Standard_False;
myIsPrimary=Standard_True;
myGlue=BOPAlgo_GlueOff;
}
//=======================================================================
//function :
@@ -57,6 +58,7 @@ BOPAlgo_PaveFiller::BOPAlgo_PaveFiller
myIterator=NULL;
myNonDestructive=Standard_False;
myIsPrimary=Standard_True;
myGlue=BOPAlgo_GlueOff;
}
//=======================================================================
//function : ~
@@ -83,6 +85,22 @@ Standard_Boolean BOPAlgo_PaveFiller::NonDestructive()const
return myNonDestructive;
}
//=======================================================================
//function : SetGlue
//purpose :
//=======================================================================
void BOPAlgo_PaveFiller::SetGlue(const BOPAlgo_GlueEnum theGlue)
{
myGlue=theGlue;
}
//=======================================================================
//function : Glue
//purpose :
//=======================================================================
BOPAlgo_GlueEnum BOPAlgo_PaveFiller::Glue() const
{
return myGlue;
}
//=======================================================================
//function : SetIsPrimary
//purpose :
//=======================================================================
@@ -294,6 +312,10 @@ void BOPAlgo_PaveFiller::PerformInternal()
if (myErrorStatus) {
return;
}
//
if (myGlue != BOPAlgo_GlueOff) {
return;
}
// 03
PerformVZ();
if (myErrorStatus) {

View File

@@ -48,6 +48,7 @@
#include <BOPDS_VectorOfCurve.hxx>
#include <BOPCol_IndexedDataMapOfShapeInteger.hxx>
#include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
#include <BOPAlgo_GlueEnum.hxx>
class IntTools_Context;
class BOPDS_DS;
class BOPAlgo_SectionAttribute;
@@ -101,6 +102,14 @@ public:
//! Sets the glue option for the algorithm
Standard_EXPORT void SetGlue(const BOPAlgo_GlueEnum theGlue);
//! Returns the glue option of the algorithm
Standard_EXPORT BOPAlgo_GlueEnum Glue() const;
protected:
typedef NCollection_DataMap
@@ -395,6 +404,7 @@ protected:
BOPAlgo_SectionAttribute mySectionAttribute;
Standard_Boolean myNonDestructive;
Standard_Boolean myIsPrimary;
BOPAlgo_GlueEnum myGlue;
private:

View File

@@ -142,96 +142,109 @@ typedef BOPCol_ContextCnt
//=======================================================================
void BOPAlgo_PaveFiller::PerformVF()
{
Standard_Boolean bJustAdd;
Standard_Integer iSize, nV, nF, nVSD, iFlag, nVx, aNbVF, k;
Standard_Real aT1, aT2;
BOPAlgo_VectorOfVertexFace aVVF;
//
myErrorStatus=0;
//
myIterator->Initialize(TopAbs_VERTEX, TopAbs_FACE);
iSize=myIterator->ExpectedLength();
if (iSize) {
//
BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
aVFs.SetIncrement(iSize);
//
Standard_Integer iSize = myIterator->ExpectedLength();
//
Standard_Boolean bJustAdd;
Standard_Integer nV, nF;
//
if (myGlue == BOPAlgo_GlueFull) {
// there is no need to intersect vertices with faces in this mode
// just initialize FaceInfo for all faces
for (; myIterator->More(); myIterator->Next()) {
myIterator->Value(nV, nF, bJustAdd);
if(bJustAdd) {
continue;
}
//
if (myDS->IsSubShape(nV, nF)) {
continue;
}
//
if (myDS->HasInterfShapeSubShapes(nV, nF)) {
if (!bJustAdd && !myDS->IsSubShape(nV, nF)) {
myDS->ChangeFaceInfo(nF);
continue;
}
//
nVx=nV;
if (myDS->HasShapeSD(nV, nVSD)) {
nVx=nVSD;
}
//
myDS->ChangeFaceInfo(nF);// !
//
const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
//
BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
//
aVertexFace.SetIndices(nV, nF);
aVertexFace.SetVertex(aV);
aVertexFace.SetFace(aF);
aVertexFace.SetFuzzyValue(myFuzzyValue);
aVertexFace.SetProgressIndicator(myProgressIndicator);
}//for (; myIterator->More(); myIterator->Next()) {
//
aNbVF=aVVF.Extent();
//================================================================
BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
//================================================================
//
for (k=0; k < aNbVF; ++k) {
const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
//
iFlag=aVertexFace.Flag();
if (iFlag) {
continue;
}
//
aVertexFace.Indices(nV, nF);
aVertexFace.Parameters(aT1, aT2);
// 1
BOPDS_InterfVF& aVF=aVFs.Append1();
aVF.SetIndices(nV, nF);
aVF.SetUV(aT1, aT2);
// 2
myDS->AddInterf(nV, nF);
//
// 3 update vertex V/F if necessary
Standard_Real aTolVNew = aVertexFace.VertexNewTolerance();
nVx=UpdateVertex(nV, aTolVNew);
//
// 4
if (myDS->IsNewShape(nVx)) {
aVF.SetIndexNew(nVx);
}
// 5 update FaceInfo
BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
aMVIn.Add(nVx);
}//for (k=0; k < aNbVF; ++k) {
}// if (iSize) {
else {
iSize=10;
BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
aVFs.SetIncrement(iSize);
}
return;
}
//
BOPDS_VectorOfInterfVF& aVFs = myDS->InterfVF();
if (!iSize) {
iSize = 10;
aVFs.SetIncrement(iSize);
//
TreatVerticesEE();
return;
}
//
Standard_Integer nVSD, iFlag, nVx, aNbVF, k;
Standard_Real aT1, aT2;
BOPAlgo_VectorOfVertexFace aVVF;
//
aVFs.SetIncrement(iSize);
//
for (; myIterator->More(); myIterator->Next()) {
myIterator->Value(nV, nF, bJustAdd);
if(bJustAdd) {
continue;
}
//
if (myDS->IsSubShape(nV, nF)) {
continue;
}
//
myDS->ChangeFaceInfo(nF);
if (myDS->HasInterfShapeSubShapes(nV, nF)) {
continue;
}
//
nVx=nV;
if (myDS->HasShapeSD(nV, nVSD)) {
nVx=nVSD;
}
//
const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
//
BOPAlgo_VertexFace& aVertexFace=aVVF.Append1();
//
aVertexFace.SetIndices(nV, nF);
aVertexFace.SetVertex(aV);
aVertexFace.SetFace(aF);
aVertexFace.SetFuzzyValue(myFuzzyValue);
aVertexFace.SetProgressIndicator(myProgressIndicator);
}//for (; myIterator->More(); myIterator->Next()) {
//
aNbVF=aVVF.Extent();
//================================================================
BOPAlgo_VertexFaceCnt::Perform(myRunParallel, aVVF, myContext);
//================================================================
//
for (k=0; k < aNbVF; ++k) {
const BOPAlgo_VertexFace& aVertexFace=aVVF(k);
//
iFlag=aVertexFace.Flag();
if (iFlag) {
continue;
}
//
aVertexFace.Indices(nV, nF);
aVertexFace.Parameters(aT1, aT2);
// 1
BOPDS_InterfVF& aVF=aVFs.Append1();
aVF.SetIndices(nV, nF);
aVF.SetUV(aT1, aT2);
// 2
myDS->AddInterf(nV, nF);
//
// 3 update vertex V/F if necessary
Standard_Real aTolVNew = aVertexFace.VertexNewTolerance();
nVx=UpdateVertex(nV, aTolVNew);
//
// 4
if (myDS->IsNewShape(nVx)) {
aVF.SetIndexNew(nVx);
}
// 5 update FaceInfo
BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
aMVIn.Add(nVx);
}//for (k=0; k < aNbVF; ++k) {
//
TreatVerticesEE();
}
//=======================================================================

View File

@@ -139,22 +139,35 @@ typedef BOPCol_ContextCnt
//=======================================================================
void BOPAlgo_PaveFiller::PerformEF()
{
Standard_Integer iSize;
//
myErrorStatus=0;
//
FillShrunkData(TopAbs_EDGE, TopAbs_FACE);
//
myIterator->Initialize(TopAbs_EDGE, TopAbs_FACE);
iSize=myIterator->ExpectedLength();
Standard_Integer iSize = myIterator->ExpectedLength();
if (!iSize) {
return;
}
//
Standard_Boolean bJustAdd, bV[2], bIsPBSplittable;
Standard_Boolean bJustAdd;
Standard_Integer nE, nF;
//
if (myGlue == BOPAlgo_GlueFull) {
// there is no need to intersect edges with faces in this mode
// just initialize FaceInfo for faces
for (; myIterator->More(); myIterator->Next()) {
myIterator->Value(nE, nF, bJustAdd);
if (!bJustAdd && !myDS->ShapeInfo(nE).HasFlag()) {
myDS->ChangeFaceInfo(nF);
}
}
return;
}
//
Standard_Boolean bV[2], bIsPBSplittable;
Standard_Boolean bV1, bV2, bExpressCompute;
Standard_Integer nV1, nV2;
Standard_Integer nE, nF, aDiscretize, i, aNbCPrts, iX, nV[2];
Standard_Integer aDiscretize, i, aNbCPrts, iX, nV[2];
Standard_Integer aNbEdgeFace, k;
Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2, aDeflection;
Handle(NCollection_BaseAllocator) aAllocator;

View File

@@ -237,22 +237,34 @@ void BOPAlgo_PaveFiller::PerformFF()
//
ToleranceFF(aBAS1, aBAS2, aTolFF);
//
BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1();
//
aFaceFace.SetIndices(nF1, nF2);
aFaceFace.SetFaces(aF1, aF2);
aFaceFace.SetTolFF(aTolFF);
//
IntSurf_ListOfPntOn2S aListOfPnts;
GetEFPnts(nF1, nF2, aListOfPnts);
aNbLP = aListOfPnts.Extent();
if (aNbLP) {
aFaceFace.SetList(aListOfPnts);
if (myGlue == BOPAlgo_GlueOff) {
BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1();
//
aFaceFace.SetIndices(nF1, nF2);
aFaceFace.SetFaces(aF1, aF2);
aFaceFace.SetTolFF(aTolFF);
//
IntSurf_ListOfPntOn2S aListOfPnts;
GetEFPnts(nF1, nF2, aListOfPnts);
aNbLP = aListOfPnts.Extent();
if (aNbLP) {
aFaceFace.SetList(aListOfPnts);
}
//
aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol);
aFaceFace.SetFuzzyValue(myFuzzyValue);
aFaceFace.SetProgressIndicator(myProgressIndicator);
}
else {
// for the Glue mode just add all interferences of that type
BOPDS_InterfFF& aFF = aFFs.Append1();
aFF.SetIndices(nF1, nF2);
aFF.SetTolR3D(Precision::Confusion());
aFF.SetTolR2D(Precision::PConfusion());
aFF.SetTolReal(Precision::Confusion());
aFF.SetTangentFaces(Standard_False);
aFF.Init(0, 0);
}
//
aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol);
aFaceFace.SetFuzzyValue(myFuzzyValue);
aFaceFace.SetProgressIndicator(myProgressIndicator);
}//for (; myIterator->More(); myIterator->Next()) {
//
aNbFaceFace=aVFaceFace.Extent();
@@ -359,6 +371,10 @@ void BOPAlgo_PaveFiller::PerformFF()
//=======================================================================
void BOPAlgo_PaveFiller::MakeBlocks()
{
if (myGlue != BOPAlgo_GlueOff) {
return;
}
//
Standard_Integer aNbFF;
//
myErrorStatus=0;

View File

@@ -65,3 +65,4 @@ BOPAlgo_WireSplitter.lxx
BOPAlgo_WireSplitter_1.cxx
BOPAlgo_CellsBuilder.cxx
BOPAlgo_CellsBuilder.hxx
BOPAlgo_GlueEnum.hxx

View File

@@ -116,6 +116,7 @@ Standard_Integer bapibop(Draw_Interpretor& di,
bRunParallel=BOPTest_Objects::RunParallel();
aFuzzyValue=BOPTest_Objects::FuzzyValue();
bNonDestructive = BOPTest_Objects::NonDestructive();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
if (aOp!=BOPAlgo_CUT21) {
pBuilder->SetArguments(aLS);
@@ -129,6 +130,7 @@ Standard_Integer bapibop(Draw_Interpretor& di,
pBuilder->SetRunParallel(bRunParallel);
pBuilder->SetFuzzyValue(aFuzzyValue);
pBuilder->SetNonDestructive(bNonDestructive);
pBuilder->SetGlue(aGlue);
//
pBuilder->Build();
iErr=pBuilder->ErrorStatus();
@@ -176,11 +178,13 @@ Standard_Integer bapibuild(Draw_Interpretor& di,
bRunParallel=BOPTest_Objects::RunParallel();
aFuzzyValue=BOPTest_Objects::FuzzyValue();
bNonDestructive = BOPTest_Objects::NonDestructive();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
aBuilder.SetArguments(aLS);
aBuilder.SetRunParallel(bRunParallel);
aBuilder.SetFuzzyValue(aFuzzyValue);
aBuilder.SetNonDestructive(bNonDestructive);
aBuilder.SetGlue(aGlue);
//
aBuilder.Build();
iErr=aBuilder.ErrorStatus();

View File

@@ -141,6 +141,7 @@ Standard_Integer bop(Draw_Interpretor& di,
aTol=BOPTest_Objects::FuzzyValue();
bRunParallel=BOPTest_Objects::RunParallel();
bNonDestructive = BOPTest_Objects::NonDestructive();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
aLC.Append(aS1);
aLC.Append(aS2);
@@ -157,6 +158,7 @@ Standard_Integer bop(Draw_Interpretor& di,
pPF->SetFuzzyValue(aTol);
pPF->SetRunParallel(bRunParallel);
pPF->SetNonDestructive(bNonDestructive);
pPF->SetGlue(aGlue);
//
pPF->Perform();
iErr=pPF->ErrorStatus();
@@ -407,6 +409,7 @@ Standard_Integer bsection(Draw_Interpretor& di,
aTol = BOPTest_Objects::FuzzyValue();
bRunParallel = BOPTest_Objects::RunParallel();
bNonDestructive = BOPTest_Objects::NonDestructive();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
for (i = 4; i < n; ++i) {
if (!strcmp(a[i], "-n2d")) {
@@ -433,6 +436,7 @@ Standard_Integer bsection(Draw_Interpretor& di,
aSec.SetFuzzyValue(aTol);
aSec.SetRunParallel(bRunParallel);
aSec.SetNonDestructive(bNonDestructive);
aSec.SetGlue(aGlue);
//
aSec.Build();
iErr=aSec.ErrorStatus();
@@ -484,6 +488,7 @@ Standard_Integer bsmt (Draw_Interpretor& di,
aTol=BOPTest_Objects::FuzzyValue();
bRunParallel = BOPTest_Objects::RunParallel();
bNonDestructive = BOPTest_Objects::NonDestructive();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
Handle(NCollection_BaseAllocator)aAL=
NCollection_BaseAllocator::CommonBaseAllocator();
@@ -495,6 +500,7 @@ Standard_Integer bsmt (Draw_Interpretor& di,
aPF.SetFuzzyValue(aTol);
aPF.SetRunParallel(bRunParallel);
aPF.SetNonDestructive(bNonDestructive);
aPF.SetGlue(aGlue);
//
aPF.Perform();
iErr=aPF.ErrorStatus();
@@ -739,6 +745,7 @@ Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char**
aTol = BOPTest_Objects::FuzzyValue();
bRunParallel = BOPTest_Objects::RunParallel();
bNonDestructive = BOPTest_Objects::NonDestructive();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
bToIntersect = Standard_True;
bCompounds = Standard_False;
@@ -789,6 +796,7 @@ Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char**
aMV.SetRunParallel(bRunParallel);
aMV.SetFuzzyValue(aTol);
aMV.SetNonDestructive(bNonDestructive);
aMV.SetGlue(aGlue);
//
aMV.Perform();
if (aMV.ErrorStatus()) {

View File

@@ -80,7 +80,6 @@ Standard_Integer bcbuild(Draw_Interpretor& di,
return 1;
}
//
Standard_Boolean bRunParallel;
Standard_Integer iErr;
BOPCol_ListIteratorOfListOfShape aIt;
//
@@ -103,8 +102,16 @@ Standard_Integer bcbuild(Draw_Interpretor& di,
aCBuilder.AddArgument(aS);
}
//
bRunParallel = BOPTest_Objects::RunParallel();
// set the options to the algorithm
Standard_Boolean bRunParallel = BOPTest_Objects::RunParallel();
Standard_Real aTol = BOPTest_Objects::FuzzyValue();
Standard_Boolean bNonDestructive = BOPTest_Objects::NonDestructive();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
aCBuilder.SetRunParallel(bRunParallel);
aCBuilder.SetFuzzyValue(aTol);
aCBuilder.SetNonDestructive(bNonDestructive);
aCBuilder.SetGlue(aGlue);
//
aCBuilder.PerformWithFiller(aPF);
iErr = aCBuilder.ErrorStatus();

View File

@@ -52,6 +52,7 @@ class BOPTest_Session {
myRunParallel=Standard_False;
myNonDestructive = Standard_False;
myFuzzyValue = 0.;
myGlue = BOPAlgo_GlueOff;
};
//
// Clear
@@ -123,6 +124,14 @@ class BOPTest_Session {
return myNonDestructive;
};
//
void SetGlue(const BOPAlgo_GlueEnum theGlue) {
myGlue = theGlue;
};
//
BOPAlgo_GlueEnum Glue() const {
return myGlue;
};
//
protected:
//
BOPTest_Session(const BOPTest_Session&);
@@ -139,6 +148,7 @@ protected:
Standard_Boolean myRunParallel;
Standard_Boolean myNonDestructive;
Standard_Real myFuzzyValue;
BOPAlgo_GlueEnum myGlue;
};
//
//=======================================================================
@@ -308,6 +318,22 @@ Standard_Boolean BOPTest_Objects::NonDestructive()
return GetSession().NonDestructive();
}
//=======================================================================
//function : SetGlue
//purpose :
//=======================================================================
void BOPTest_Objects::SetGlue(const BOPAlgo_GlueEnum theGlue)
{
GetSession().SetGlue(theGlue);
}
//=======================================================================
//function : Glue
//purpose :
//=======================================================================
BOPAlgo_GlueEnum BOPTest_Objects::Glue()
{
return GetSession().Glue();
}
//=======================================================================
//function : Allocator1
//purpose :
//=======================================================================

View File

@@ -25,6 +25,8 @@
#include <Standard_Boolean.hxx>
#include <Standard_Real.hxx>
#include <BOPAlgo_CellsBuilder.hxx>
#include <BOPAlgo_GlueEnum.hxx>
//
class BOPAlgo_PaveFiller;
class BOPAlgo_Builder;
class BOPAlgo_BOP;
@@ -75,7 +77,9 @@ public:
Standard_EXPORT static Standard_Boolean NonDestructive();
Standard_EXPORT static void SetGlue(const BOPAlgo_GlueEnum aGlue);
Standard_EXPORT static BOPAlgo_GlueEnum Glue();
protected:

View File

@@ -17,6 +17,7 @@
#include <BOPTest_Objects.hxx>
#include <DBRep.hxx>
#include <Draw.hxx>
#include <BOPAlgo_GlueEnum.hxx>
#include <stdio.h>
#include <string.h>
@@ -24,6 +25,7 @@ static Standard_Integer boptions (Draw_Interpretor&, Standard_Integer, const cha
static Standard_Integer brunparallel (Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bnondestructive(Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bfuzzyvalue(Draw_Interpretor&, Standard_Integer, const char**);
static Standard_Integer bGlue(Draw_Interpretor&, Standard_Integer, const char**);
//=======================================================================
//function : OptionCommands
@@ -41,6 +43,7 @@ void BOPTest::OptionCommands(Draw_Interpretor& theCommands)
theCommands.Add("brunparallel", "use brunparallel [0/1]" , __FILE__, brunparallel, g);
theCommands.Add("bnondestructive", "use bnondestructive [0/1]", __FILE__, bnondestructive, g);
theCommands.Add("bfuzzyvalue", "use bfuzzyvalue value", __FILE__, bfuzzyvalue, g);
theCommands.Add("bglue", "use bglue [0 (off) / 1 (shift) / 2 (full)]", __FILE__, bGlue, g);
}
//=======================================================================
//function : boptions
@@ -58,16 +61,21 @@ Standard_Integer boptions(Draw_Interpretor& di,
char buf[128];
Standard_Boolean bRunParallel, bNonDestructive;
Standard_Real aFuzzyValue;
BOPAlgo_GlueEnum aGlue;
//
bRunParallel=BOPTest_Objects::RunParallel();
bNonDestructive = BOPTest_Objects::NonDestructive();
aFuzzyValue = BOPTest_Objects::FuzzyValue();
aGlue = BOPTest_Objects::Glue();
//
Sprintf(buf, " RunParallel: %d\n", bRunParallel);
di << buf;
Sprintf(buf, " NonDestructive: %d\n", bNonDestructive);
di << buf;
Sprintf(buf, " FuzzyValue : %lf\n", aFuzzyValue);
Sprintf(buf, " FuzzyValue: %lf\n", aFuzzyValue);
di << buf;
Sprintf(buf, " GlueOption: %s\n", ((aGlue == BOPAlgo_GlueOff) ? "Off" :
((aGlue == BOPAlgo_GlueFull) ? "Full" : "Shift")));
di << buf;
//
return 0;
@@ -151,3 +159,28 @@ Standard_Integer bnondestructive(Draw_Interpretor& di,
//
return 0;
}
//=======================================================================
//function : bglue
//purpose :
//=======================================================================
Standard_Integer bGlue(Draw_Interpretor& di,
Standard_Integer n,
const char** a)
{
if (n != 2) {
di << " use bglue [0 (off) / 1 (shift) / 2 (full)]\n";
return 1;
}
//
Standard_Integer iGlue = Draw::Atoi(a[1]);
if (iGlue < 0 || iGlue > 2) {
di << " Wrong value. Use bglue [0 (off) / 1 (shift) / 2 (full)]\n";
return 1;
}
//
BOPAlgo_GlueEnum aGlue = BOPAlgo_GlueEnum(iGlue);
BOPTest_Objects::SetGlue(aGlue);
//
return 0;
}

View File

@@ -83,12 +83,13 @@ Standard_Integer bfillds(Draw_Interpretor& di,
bRunParallel=BOPTest_Objects::RunParallel();
bNonDestructive = BOPTest_Objects::NonDestructive();
aTol = BOPTest_Objects::FuzzyValue();
BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
//
for (i=1; i<n; ++i) {
if (!strcmp(a[i], "-t")) {
bShowTime=Standard_True;
}
}
}
//
BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
//
@@ -110,6 +111,7 @@ Standard_Integer bfillds(Draw_Interpretor& di,
aPF.SetRunParallel(bRunParallel);
aPF.SetNonDestructive(bNonDestructive);
aPF.SetFuzzyValue(aTol);
aPF.SetGlue(aGlue);
//
OSD_Timer aTimer;
aTimer.Start();

View File

@@ -308,6 +308,7 @@ void BRepAlgoAPI_BooleanOperation::Build()
myDSFiller->SetProgressIndicator(myProgressIndicator);
myDSFiller->SetFuzzyValue(myFuzzyValue);
myDSFiller->SetNonDestructive(myNonDestructive);
myDSFiller->SetGlue(myGlue);
//
SetAttributes();
//

View File

@@ -29,7 +29,8 @@ BRepAlgoAPI_BuilderAlgo::BRepAlgoAPI_BuilderAlgo()
myDSFiller(NULL),
myBuilder(NULL),
myFuzzyValue(0.),
myNonDestructive(Standard_False)
myNonDestructive(Standard_False),
myGlue(BOPAlgo_GlueOff)
{}
//=======================================================================
// function:
@@ -42,7 +43,8 @@ BRepAlgoAPI_BuilderAlgo::BRepAlgoAPI_BuilderAlgo
myEntryType(0),
myBuilder(NULL),
myFuzzyValue(0.),
myNonDestructive(Standard_False)
myNonDestructive(Standard_False),
myGlue(BOPAlgo_GlueOff)
{
BOPAlgo_PaveFiller* pPF=(BOPAlgo_PaveFiller*)&aPF;
myDSFiller=pPF;
@@ -88,6 +90,22 @@ Standard_Boolean BRepAlgoAPI_BuilderAlgo::NonDestructive() const
return myNonDestructive;
}
//=======================================================================
//function : SetGlue
//purpose :
//=======================================================================
void BRepAlgoAPI_BuilderAlgo::SetGlue(const BOPAlgo_GlueEnum theGlue)
{
myGlue=theGlue;
}
//=======================================================================
//function : Glue
//purpose :
//=======================================================================
BOPAlgo_GlueEnum BRepAlgoAPI_BuilderAlgo::Glue() const
{
return myGlue;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
@@ -144,6 +162,7 @@ void BRepAlgoAPI_BuilderAlgo::Build()
myDSFiller->SetProgressIndicator(myProgressIndicator);
myDSFiller->SetFuzzyValue(myFuzzyValue);
myDSFiller->SetNonDestructive(myNonDestructive);
myDSFiller->SetGlue(myGlue);
//
myDSFiller->Perform();
iErr=myDSFiller->ErrorStatus();

View File

@@ -22,6 +22,7 @@
#include <Standard_Integer.hxx>
#include <BOPAlgo_PPaveFiller.hxx>
#include <BOPAlgo_PBuilder.hxx>
#include <BOPAlgo_GlueEnum.hxx>
#include <Standard_Real.hxx>
#include <TopTools_ListOfShape.hxx>
#include <BRepAlgoAPI_Algo.hxx>
@@ -62,6 +63,12 @@ Standard_EXPORT virtual ~BRepAlgoAPI_BuilderAlgo();
//! a copy of a sub-shape is created in the result if it is needed to be updated.
Standard_EXPORT Standard_Boolean NonDestructive() const;
//! Sets the glue option for the algorithm
Standard_EXPORT void SetGlue(const BOPAlgo_GlueEnum theGlue);
//! Returns the glue option of the algorithm
Standard_EXPORT BOPAlgo_GlueEnum Glue() const;
//! Sets the arguments
Standard_EXPORT void SetArguments (const TopTools_ListOfShape& theLS);
@@ -113,6 +120,7 @@ protected:
Standard_Real myFuzzyValue;
Standard_Boolean myNonDestructive;
TopTools_ListOfShape myArguments;
BOPAlgo_GlueEnum myGlue;
private:

2
src/HelixBRep/FILES Normal file
View File

@@ -0,0 +1,2 @@
HelixBRep_BuilderHelix.cxx
HelixBRep_BuilderHelix.hxx

View File

@@ -0,0 +1,637 @@
// File: HelixBRep_BuilderHelix.cxx
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <gp.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
#include <gp_Lin.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <HelixBRep_BuilderHelix.hxx>
#include <HelixGeom_BuilderHelix.hxx>
#include <Precision.hxx>
#include <Standard_ConstructionError.hxx>
#include <TColGeom_SequenceOfCurve.hxx>
#include <TColStd_Array1OfBoolean.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HArray1OfBoolean.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
//=======================================================================
//function :
//purpose :
//=======================================================================
HelixBRep_BuilderHelix::HelixBRep_BuilderHelix()
{
gp_Pnt aP0(0.,0.,0);
//
myAxis3.SetDirection(gp::DZ());
myAxis3.SetLocation(aP0);
myDiams = NULL;
myHeights = NULL;
myPitches = NULL;
myIsPitches = NULL;
myNParts = 1;
myShape.Nullify();
//
myTolerance=0.0001;
myContinuity=GeomAbs_C1;
myMaxDegree=8;
myMaxSegments=1000;
//
myTolReached=99.;
//
myErrorStatus = 1;
myWarningStatus = 1;
}
//=======================================================================
//function : ~
//purpose :
//=======================================================================
HelixBRep_BuilderHelix::~HelixBRep_BuilderHelix()
{
}
//=======================================================================
//function : SetParameters
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SetParameters(const gp_Ax3& theAxis,
const TColStd_Array1OfReal& theDiams,
const TColStd_Array1OfReal& theHeights,
const TColStd_Array1OfReal& thePitches,
const TColStd_Array1OfBoolean& bIsPitches)
{
myNParts = theDiams.Length() - 1;
myAxis3 = theAxis;
myDiams = NULL;
myHeights = NULL;
myPitches = NULL;
myShape.Nullify();
myErrorStatus = 1;
myWarningStatus = 1;
if(myNParts != theHeights.Length() || myNParts != thePitches.Length() || myNParts != bIsPitches.Length()) {
Standard_ConstructionError::
Raise("HelixBRep_BuilderHelix::SetParameters: wrong array dimension");
}
myDiams = new TColStd_HArray1OfReal(1, myNParts+1);
myHeights = new TColStd_HArray1OfReal(1, myNParts);
myPitches = new TColStd_HArray1OfReal(1, myNParts);
myIsPitches = new TColStd_HArray1OfBoolean(1, myNParts);
myDiams->ChangeArray1() = theDiams;
myHeights->ChangeArray1() = theHeights;
myPitches->ChangeArray1() = thePitches;
myIsPitches->ChangeArray1() = bIsPitches;
myErrorStatus = 0;
myWarningStatus = 0;
}
//=======================================================================
//function : SetParameters
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SetParameters(const gp_Ax3& theAxis,
const Standard_Real theDiam,
const TColStd_Array1OfReal& theHeights,
const TColStd_Array1OfReal& thePitches,
const TColStd_Array1OfBoolean& bIsPitches)
{
Standard_Integer aNbParts = theHeights.Length();
TColStd_Array1OfReal aDiams(1, aNbParts+1);
aDiams.Init(theDiam);
SetParameters(theAxis, aDiams, theHeights, thePitches, bIsPitches);
}
//=======================================================================
//function : SetParameters
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SetParameters(const gp_Ax3& theAxis,
const Standard_Real theDiam1,
const Standard_Real theDiam2,
const TColStd_Array1OfReal& theHeights,
const TColStd_Array1OfReal& thePitches,
const TColStd_Array1OfBoolean& bIsPitches)
{
Standard_Integer aNbParts = theHeights.Length();
TColStd_Array1OfReal aDiams(1, aNbParts+1);
Standard_Integer i, j;
Standard_Real anH = 0.;
for(i = theHeights.Lower(); i <= theHeights.Upper(); ++i) {
anH += theHeights(i);
}
Standard_Real K = (theDiam2 - theDiam1)/anH;
aDiams(1) = theDiam1;
aDiams(aNbParts+1) = theDiam2;
anH = theHeights(1);
for(i = theHeights.Lower()+1, j = 2; i <= theHeights.Upper(); ++i, ++j) {
aDiams(j) = theDiam1 + K * anH;
anH += theHeights(i);
}
SetParameters(theAxis, aDiams, theHeights, thePitches, bIsPitches);
}
//=======================================================================
//function : SetApproxParameters
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SetApproxParameters(const Standard_Real aTolerance,
const Standard_Integer aMaxDegree,
const GeomAbs_Shape aCont)
{
myTolerance=aTolerance;
myMaxDegree=aMaxDegree;
myContinuity=aCont;
}
//=======================================================================
//function : ToleranceReached
//purpose :
//=======================================================================
Standard_Real HelixBRep_BuilderHelix::ToleranceReached()const
{
return myTolReached;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::Perform()
{
if(myErrorStatus != 0) return;
Standard_Integer i;
myTolReached = 0.;
myShape.Nullify();
BRep_Builder aBB;
//aBB.MakeCompound(TopoDS::Compound(myShape));
TopTools_ListOfShape anLst;
gp_Ax1 anAxis(myAxis3.Axis());
gp_Pnt aPStart = myAxis3.Location();
aPStart.Translate(.5*myDiams->Value(1)*myAxis3.XDirection());
Standard_Boolean bIsClockwise = myAxis3.Direct();
Standard_Real aHeight;
Standard_Real aPitch;
Standard_Real aTaperAngle;
for(i = 1; i <= myNParts; ++i) {
aHeight = myHeights->Value(i);
if(myIsPitches->Value(i)) {
aPitch = myPitches->Value(i);
}
else {
aPitch = aHeight/myPitches->Value(i);
}
aTaperAngle = ATan(.5*(myDiams->Value(i+1) - myDiams->Value(i))/aHeight);
TopoDS_Wire aPart;
aBB.MakeWire(aPart);
BuildPart(anAxis, aPStart, aHeight, aPitch, aTaperAngle, bIsClockwise, aPart);
if(myErrorStatus != 0) return;
TopoDS_Vertex V1, V2;
TopExp::Vertices(aPart, V1, V2);
aPStart = BRep_Tool::Pnt(V2);
anAxis.SetLocation(anAxis.Location().Translated(aHeight*anAxis.Direction()));
anLst.Append(aPart);
//aBB.Add(myShape, aPart);
}
Smoothing(anLst);
TopTools_ListIteratorOfListOfShape anIt(anLst);
BRepBuilderAPI_MakeWire aMkWire(TopoDS::Wire(anLst.First()));
anIt.Next();
for(; anIt.More(); anIt.Next()) {
aMkWire.Add(TopoDS::Wire(anIt.Value()));
}
myShape = aMkWire.Shape();
}
//=======================================================================
//function : BuildPart
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::BuildPart(const gp_Ax1& theAxis,
const gp_Pnt& thePStart,
const Standard_Real theHeight,
const Standard_Real thePitch,
const Standard_Real theTaperAngle,
const Standard_Boolean bIsClockwise,
TopoDS_Wire& thePart)
{
if(myErrorStatus != 0) return;
myErrorStatus=0;
myWarningStatus=0;
//
// 1. check & prepare data
Standard_Real aTolPrec, aDist, aDM, aTwoPI, aC1, aT2, aT1, aT0;
//
aTolPrec=myTolerance;
Standard_Real aTolAng = 1.e-7;
//
if (theTaperAngle > M_PI/2. - aTolAng) {
myErrorStatus=13; // invalid TaperAngle value
return;
}
if (theHeight<aTolPrec) {
myErrorStatus=12; // invalid Height value
return;
}
if (thePitch<aTolPrec) {
myErrorStatus=11; // invalid Pitch value
return;
}
//
gp_Lin aLin(theAxis);
aDist=aLin.Distance(thePStart);
if (aDist<aTolPrec) {
myErrorStatus=10; // myPStart belongs to the myAxis
return;
}
aTolAng = aTolPrec/aDist;
Standard_Real aAngleStart = 0.;
Standard_Boolean bIsOutWard = Standard_False;
if(theTaperAngle > 0.) bIsOutWard = Standard_True;
//
const gp_Dir& aDir=theAxis.Direction();
gp_Vec aVec1 = gp_Vec(aDir);
gp_Pnt aM0 = theAxis.Location();
gp_Vec aVec(aM0, thePStart);
aDM=aVec1.Dot(aVec);
gp_Pnt aM1= aM0.Translated(aDM*aVec1);
gp_Vec aVecX(aM1, thePStart);
gp_Dir aDirX(aVecX);
gp_Ax2 aAx2(aM1, aDir, aDirX);
//
aTwoPI=2.*M_PI;
aC1=thePitch/aTwoPI;
aT0 = 0.;
aT1=aAngleStart;
aT2=theHeight/aC1;
//
// 2. compute
Standard_Boolean bIsDone;
Standard_Integer iErr, aNbC, i;
HelixGeom_BuilderHelix aBH;
gp_Pnt aP1, aP2;
BRep_Builder aBB;
BRepBuilderAPI_MakeEdge aBME;
TopoDS_Vertex aV1, aV2;
//TopoDS_Wire aW;
TopoDS_Edge aE;
//
aBH.SetPosition(aAx2);
aBH.SetCurveParameters(aT0, aT2, thePitch, aDist, theTaperAngle, bIsClockwise);
aBH.SetTolerance(myTolerance);
aBH.SetApproxParameters(myContinuity, myMaxDegree, myMaxSegments);
//
aBH.Perform();
iErr=aBH.ErrorStatus();
if (iErr) {
myErrorStatus=2;
return;
}
//
aBB.MakeWire(thePart);
//
myTolReached=Max(myTolReached, aBH.ToleranceReached());
TColGeom_SequenceOfCurve aSC;
aSC.Assign(aBH.Curves());
if(aT1 < 0.) {
HelixGeom_BuilderHelix aBH1;
aBH1.SetPosition(aAx2);
aBH1.SetCurveParameters(aT1, aT0, thePitch, aDist, theTaperAngle, bIsClockwise);
aBH1.SetTolerance(myTolerance);
aBH1.SetApproxParameters(myContinuity, myMaxDegree, myMaxSegments);
//
aBH1.Perform();
iErr=aBH1.ErrorStatus();
if (iErr) {
myErrorStatus=2;
return;
}
myTolReached = Max(myTolReached, aBH1.ToleranceReached());
const TColGeom_SequenceOfCurve& aSC1=aBH1.Curves();
Standard_Integer nbc = aSC1.Length();
for(i = nbc; i >= 1; i--) {
aSC.Prepend(aSC1.Value(i));
}
}
aNbC=aSC.Length();
for (i=1; i<=aNbC; ++i) {
Handle(Geom_Curve) aC=aSC(i);
//
if (i==1) {
if(aT1 > 0.) {
aT2=aC->LastParameter();
Handle(Geom_TrimmedCurve) aCT = new Geom_TrimmedCurve(aC, aT1, aT2);
aC = aCT;
}
aT1=aC->FirstParameter();
aC->D0(aT1, aP1);
aBB.MakeVertex(aV1, aP1, myTolReached);
aV1.Orientation(TopAbs_FORWARD);
}
//
aT2=aC->LastParameter();
aC->D0(aT2, aP2);
aBB.MakeVertex(aV2, aP2, myTolReached);
aV2.Orientation(TopAbs_REVERSED);
//
aBME.Init(aC, aV1, aV2);
bIsDone=aBME.IsDone();
if (!bIsDone) {
myErrorStatus=3;
return;
}
aE=aBME.Edge();
aBB.UpdateEdge(aE, myTolReached);
aBB.Add(thePart, aE);
//
aV1=aV2;
aV1.Orientation(TopAbs_FORWARD);
}
//
if(myTolReached > myTolerance) myWarningStatus = 1;
}
//=======================================================================
//function : Smoothing
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::Smoothing(TopTools_ListOfShape& theParts)
{
if(theParts.Extent() == 1) return;
BRepTools_WireExplorer anExpl;
TopoDS_Wire aPrevWire = TopoDS::Wire(theParts.First());
anExpl.Init(aPrevWire);
TopoDS_Edge aPrevEdge;
for(; anExpl.More(); anExpl.Next()) {
aPrevEdge = anExpl.Current();
}
TopTools_ListIteratorOfListOfShape anIter(theParts);
anIter.Next();
for(; anIter.More(); anIter.Next()) {
TopoDS_Wire aNextWire = TopoDS::Wire(anIter.Value());
anExpl.Clear();
anExpl.Init(aNextWire);
TopoDS_Edge aNextEdge = anExpl.Current();
//Smoothing curves
SmoothingEdges(aPrevEdge, aNextEdge);
for(; anExpl.More(); anExpl.Next()) {
aPrevEdge = anExpl.Current();
}
}
}
//=======================================================================
//function : Smoothing
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SmoothingEdges(TopoDS_Edge& thePrev,
TopoDS_Edge& theNext)
{
static const Standard_Real EpsAng = 1.e-7;
BRep_Builder aBB;
Standard_Real f1, l1, f2, l2;
Handle(Geom_BSplineCurve) aCPrev =
Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(thePrev, f1, l1));
Handle(Geom_BSplineCurve) aCNext =
Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(theNext, f2, l2));
gp_Pnt P1, P2;
gp_Vec V1, V2;
aCPrev->D1(l1, P1, V1);
aCNext->D1(f2, P2, V2);
if(V1.Angle(V2) < EpsAng) return;
V1 = 0.5*(V1 + V2);
V2 = V1;
Standard_Integer anErrorStatus = 1;
Standard_Integer aDegMax = Geom_BSplineCurve::MaxDegree();
Standard_Integer aDeg = aCPrev->Degree();
Standard_Integer i;
Standard_Boolean bPrevOK = Standard_False;
Standard_Boolean bNextOK = Standard_False;
aCPrev->MovePointAndTangent(l1, P1, V1, myTolerance, 1, -1, anErrorStatus);
if(anErrorStatus != 0) {
for(i = aDeg + 1; i <= aDegMax; ++i) {
aCPrev->IncreaseDegree(i);
aCPrev->MovePointAndTangent(l1, P1, V1, myTolerance, 1, -1, anErrorStatus);
if(anErrorStatus == 0) {
bPrevOK = Standard_True;
break;
}
}
}
else {
bPrevOK = Standard_True;
}
if(bPrevOK) {
aBB.UpdateEdge(thePrev, aCPrev, BRep_Tool::Tolerance(thePrev));
}
aDeg = aCNext->Degree();
aCNext->MovePointAndTangent(f2, P2, V2, myTolerance, -1, 1, anErrorStatus);
if(anErrorStatus != 0) {
for(i = aDeg + 1; i <= aDegMax; ++i) {
aCNext->IncreaseDegree(i);
aCNext->MovePointAndTangent(f2, P2, V2, myTolerance, -1, 1, anErrorStatus);
if(anErrorStatus == 0) {
bNextOK = Standard_True;
break;
}
}
}
else {
bNextOK = Standard_True;
}
if(bNextOK) {
aBB.UpdateEdge(theNext, aCNext, BRep_Tool::Tolerance(theNext));
}
}
//=======================================================================
//function : ErrorStatus
//purpose :
//=======================================================================
Standard_Integer HelixBRep_BuilderHelix::ErrorStatus()const
{
return myErrorStatus;
}
//=======================================================================
//function : WarningStatus
//purpose :
//=======================================================================
Standard_Integer HelixBRep_BuilderHelix::WarningStatus()const
{
return myWarningStatus;
}
//=======================================================================
//function : Shape
//purpose :
//=======================================================================
const TopoDS_Shape& HelixBRep_BuilderHelix::Shape() const
{
return myShape;
}
//=======================================================================
//function : SetParameters
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SetParameters(const gp_Ax3& theAxis,
const TColStd_Array1OfReal& theDiams,
const TColStd_Array1OfReal& thePitches,
const TColStd_Array1OfReal& theNbTurns)
{
Standard_Integer aNbParts = theDiams.Length() - 1;
if(aNbParts != thePitches.Length() || aNbParts != theNbTurns.Length()) {
Standard_ConstructionError::
Raise("HelixBRep_BuilderHelix::SetParameters: wrong array dimension");
}
TColStd_Array1OfReal aHeights(1, aNbParts);
TColStd_Array1OfBoolean bIsPitches(1, aNbParts);
bIsPitches.Init(Standard_True);
Standard_Integer i, ip, in;
for(i = 1, ip = thePitches.Lower(), in = theNbTurns.Lower(); i <= thePitches.Length(); ++i, ip++, in++) {
aHeights(i) = thePitches(ip)*theNbTurns(in);
}
SetParameters(theAxis, theDiams, aHeights, thePitches, bIsPitches);
}
//=======================================================================
//function : SetParameters
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SetParameters(const gp_Ax3& theAxis,
const Standard_Real theDiam,
const TColStd_Array1OfReal& thePitches,
const TColStd_Array1OfReal& theNbTurns)
{
Standard_Integer aNbParts = thePitches.Length();
if(aNbParts != theNbTurns.Length()) {
Standard_ConstructionError::
Raise("HelixBRep_BuilderHelix::SetParameters: wrong array dimension");
}
TColStd_Array1OfReal aHeights(1, aNbParts);
TColStd_Array1OfBoolean bIsPitches(1, aNbParts);
bIsPitches.Init(Standard_True);
Standard_Integer i, ip, in;
for(i = 1, ip = thePitches.Lower(), in = theNbTurns.Lower(); i <= thePitches.Length(); ++i, ip++, in++) {
aHeights(i) = thePitches(ip)*theNbTurns(in);
}
SetParameters(theAxis, theDiam, aHeights, thePitches, bIsPitches);
}
//=======================================================================
//function : SetParameters
//purpose :
//=======================================================================
void HelixBRep_BuilderHelix::SetParameters(const gp_Ax3& theAxis,
const Standard_Real theDiam1,
const Standard_Real theDiam2,
const TColStd_Array1OfReal& thePitches,
const TColStd_Array1OfReal& theNbTurns)
{
Standard_Integer aNbParts = thePitches.Length();
if(aNbParts != theNbTurns.Length()) {
Standard_ConstructionError::
Raise("HelixBRep_BuilderHelix::SetParameters: wrong array dimension");
}
TColStd_Array1OfReal aHeights(1, aNbParts);
TColStd_Array1OfBoolean bIsPitches(1, aNbParts);
bIsPitches.Init(Standard_True);
Standard_Integer i, ip, in;
for(i = 1, ip = thePitches.Lower(), in = theNbTurns.Lower(); i <= thePitches.Length(); ++i, ip++, in++) {
aHeights(i) = thePitches(ip)*theNbTurns(in);
}
SetParameters(theAxis, theDiam1, theDiam2, aHeights, thePitches, bIsPitches);
}

View File

@@ -0,0 +1,133 @@
// File: HelixBRep_BuilderHelix.cdl
#ifndef _HelixBRep_BuilderHelix_HeaderFile
#define _HelixBRep_BuilderHelix_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <gp_Ax3.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Real.hxx>
#include <GeomAbs_Shape.hxx>
#include <TopoDS_Shape.hxx>
#include <Standard_Boolean.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_Array1OfBoolean.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_HArray1OfBoolean.hxx>
class gp_Ax3;
class TopoDS_Shape;
class gp_Ax1;
class gp_Pnt;
class TopoDS_Wire;
class TopoDS_Edge;
//! Implementation of building helix wire
//! Values of Error Status returned by algo:
//! 0 - OK
//! 1 - object is just initialized, it means that no input parameters were set
//! 2 - approximation fails
//!
//! 10 - R < tolerance - starting point is too close to axis
//! 11 - step (Pitch) < tolerancee
//! 12 - Height < tolerance
//! 13 - TaperAngle < 0 or TaperAngle > Pi/2 - TolAng
//! Warning Status:
//! 0 - OK
//! 1 - tolerance reached by approximation > requested tolerance.
class HelixBRep_BuilderHelix
{
public:
DEFINE_STANDARD_ALLOC
//! Empty constructor
Standard_EXPORT HelixBRep_BuilderHelix();
Standard_EXPORT virtual ~HelixBRep_BuilderHelix();
//! Sets parameters of general composite helix
Standard_EXPORT void SetParameters (const gp_Ax3& theAxis, const TColStd_Array1OfReal& theDiams, const TColStd_Array1OfReal& theHeights, const TColStd_Array1OfReal& thePitches, const TColStd_Array1OfBoolean& theIsPitches);
//! Sets parameters of pure helix
Standard_EXPORT void SetParameters (const gp_Ax3& theAxis, const Standard_Real theDiam, const TColStd_Array1OfReal& theHeights, const TColStd_Array1OfReal& thePitches, const TColStd_Array1OfBoolean& theIsPitches);
//! Sets parameters of pure spiral
Standard_EXPORT void SetParameters (const gp_Ax3& theAxis, const Standard_Real theDiam1, const Standard_Real theDiam2, const TColStd_Array1OfReal& theHeights, const TColStd_Array1OfReal& thePitches, const TColStd_Array1OfBoolean& theIsPitches);
//! Sets parameters of general composite helix
Standard_EXPORT void SetParameters (const gp_Ax3& theAxis, const TColStd_Array1OfReal& theDiams, const TColStd_Array1OfReal& thePitches, const TColStd_Array1OfReal& theNbTurns);
//! Sets parameters of pure helix
Standard_EXPORT void SetParameters (const gp_Ax3& theAxis, const Standard_Real theDiam, const TColStd_Array1OfReal& thePitches, const TColStd_Array1OfReal& theNbTurns);
//! Sets parameters of pure spiral
Standard_EXPORT void SetParameters (const gp_Ax3& theAxis, const Standard_Real theDiam1, const Standard_Real theDiam2, const TColStd_Array1OfReal& thePitches, const TColStd_Array1OfReal& theNbTurns);
//! Sets parameters for approximation
Standard_EXPORT void SetApproxParameters (const Standard_Real theTolerance, const Standard_Integer theMaxDegree, const GeomAbs_Shape theContinuity);
//! Performs calculations
Standard_EXPORT void Perform();
//! Gets tolerance reached by approximation
Standard_EXPORT Standard_Real ToleranceReached() const;
//! Returns error status of algorithm
Standard_EXPORT Standard_Integer ErrorStatus() const;
//! Returns warning status of algorithm
Standard_EXPORT Standard_Integer WarningStatus() const;
//! Gets result of algorithm
Standard_EXPORT const TopoDS_Shape& Shape() const;
protected:
gp_Ax3 myAxis3;
Handle(TColStd_HArray1OfReal) myDiams;
Handle(TColStd_HArray1OfReal) myHeights;
Handle(TColStd_HArray1OfReal) myPitches;
Handle(TColStd_HArray1OfBoolean) myIsPitches;
Standard_Real myTolerance;
Standard_Real myTolReached;
GeomAbs_Shape myContinuity;
Standard_Integer myMaxDegree;
Standard_Integer myMaxSegments;
Standard_Integer myErrorStatus;
Standard_Integer myWarningStatus;
TopoDS_Shape myShape;
private:
Standard_EXPORT void BuildPart (const gp_Ax1& theAxis, const gp_Pnt& thePStart, const Standard_Real theHeight, const Standard_Real thePitch, const Standard_Real theTaperAngle, const Standard_Boolean theIsClockwise, TopoDS_Wire& thePart);
Standard_EXPORT void Smoothing (TopTools_ListOfShape& theParts);
Standard_EXPORT void SmoothingEdges (TopoDS_Edge& thePrev, TopoDS_Edge& theNext);
Standard_Integer myNParts;
};
#endif // _HelixBRep_BuilderHelix_HeaderFile

16
src/HelixGeom/FILES Normal file
View File

@@ -0,0 +1,16 @@
HelixGeom_BuilderApproxCurve.cxx
HelixGeom_BuilderApproxCurve.hxx
HelixGeom_BuilderHelix.cxx
HelixGeom_BuilderHelix.hxx
HelixGeom_BuilderHelixCoil.cxx
HelixGeom_BuilderHelixCoil.hxx
HelixGeom_BuilderHelixGen.cxx
HelixGeom_BuilderHelixGen.hxx
HelixGeom_GHHelixCurve.hxx
HelixGeom_GHHelixCurve_0.cxx
HelixGeom_HelixCurve.cxx
HelixGeom_HelixCurve.hxx
HelixGeom_HHelixCurve.cxx
HelixGeom_HHelixCurve.hxx
HelixGeom_Tools.cxx
HelixGeom_Tools.hxx

View File

@@ -0,0 +1,102 @@
// File: HelixGeom_BuilderApproxCurve.cxx
#include <HelixGeom_BuilderApproxCurve.hxx>
#include <TColGeom_SequenceOfCurve.hxx>
//=======================================================================
//function :
//purpose :
//=======================================================================
HelixGeom_BuilderApproxCurve::HelixGeom_BuilderApproxCurve()
{
myTolerance=0.0001;
myCont=GeomAbs_C2;
myMaxDegree=8;
myMaxSeg=150;
//
myTolReached=99.;
}
//=======================================================================
//function : ~
//purpose :
//=======================================================================
HelixGeom_BuilderApproxCurve::~HelixGeom_BuilderApproxCurve()
{
}
//=======================================================================
//function : SetApproxParameters
//purpose :
//=======================================================================
void HelixGeom_BuilderApproxCurve::SetApproxParameters(const GeomAbs_Shape aCont,
const Standard_Integer aMaxDegree,
const Standard_Integer aMaxSeg)
{
myCont=aCont;
myMaxDegree=aMaxDegree;
myMaxSeg=aMaxSeg;
}
//=======================================================================
//function : ApproxParameters
//purpose :
//=======================================================================
void HelixGeom_BuilderApproxCurve::ApproxParameters(GeomAbs_Shape& aCont,
Standard_Integer& aMaxDegree,
Standard_Integer& aMaxSeg)const
{
aCont=myCont;
aMaxDegree=myMaxDegree;
aMaxSeg=myMaxSeg;
}
//=======================================================================
//function : SetTolerance
//purpose :
//=======================================================================
void HelixGeom_BuilderApproxCurve::SetTolerance(const Standard_Real aTolerance)
{
myTolerance=aTolerance;
}
//=======================================================================
//function : Tolerance
//purpose :
//=======================================================================
Standard_Real HelixGeom_BuilderApproxCurve::Tolerance()const
{
return myTolerance;
}
//=======================================================================
//function : ToleranceReached
//purpose :
//=======================================================================
Standard_Real HelixGeom_BuilderApproxCurve::ToleranceReached()const
{
return myTolReached;
}
//=======================================================================
//function : Curves
//purpose :
//=======================================================================
const TColGeom_SequenceOfCurve& HelixGeom_BuilderApproxCurve::Curves()const
{
return myCurves;
}
//=======================================================================
//function : ErrorStatus
//purpose :
//=======================================================================
Standard_Integer HelixGeom_BuilderApproxCurve::ErrorStatus()const
{
return myErrorStatus;
}
//=======================================================================
//function : WarningStatus
//purpose :
//=======================================================================
Standard_Integer HelixGeom_BuilderApproxCurve::WarningStatus()const
{
return myWarningStatus;
}

View File

@@ -0,0 +1,86 @@
// File: HelixGeom_BuilderApproxCurve.cdl
#ifndef _HelixGeom_BuilderApproxCurve_HeaderFile
#define _HelixGeom_BuilderApproxCurve_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Real.hxx>
#include <GeomAbs_Shape.hxx>
#include <TColGeom_SequenceOfCurve.hxx>
//! Root class for algorithm of building helix curves
class HelixGeom_BuilderApproxCurve
{
public:
DEFINE_STANDARD_ALLOC
//! Sets aprroximation parameters
Standard_EXPORT void SetApproxParameters (const GeomAbs_Shape aCont, const Standard_Integer aMaxDegree, const Standard_Integer aMaxSeg);
//! Gets aprroximation parameters
Standard_EXPORT void ApproxParameters (GeomAbs_Shape& aCont, Standard_Integer& aMaxDegree, Standard_Integer& aMaxSeg) const;
//! Sets aprroximation tolerance
Standard_EXPORT void SetTolerance (const Standard_Real aTolerance);
//! Gets aprroximation tolerance
Standard_EXPORT Standard_Real Tolerance() const;
//! Gets actual tolerance reached by approximation algorithm
Standard_EXPORT Standard_Real ToleranceReached() const;
//! Gets sequence of Bspline curves representing helix coins.
Standard_EXPORT const TColGeom_SequenceOfCurve& Curves() const;
//! Returns error status of algorithm
Standard_EXPORT Standard_Integer ErrorStatus() const;
//! Returns warning status of algorithm
Standard_EXPORT Standard_Integer WarningStatus() const;
//! Performs calculations.
//! Must be redefined.
Standard_EXPORT virtual void Perform() = 0;
protected:
//! Sets default values of aprroximation parameters
Standard_EXPORT HelixGeom_BuilderApproxCurve();
Standard_EXPORT virtual ~HelixGeom_BuilderApproxCurve();
Standard_Integer myErrorStatus;
Standard_Integer myWarningStatus;
Standard_Real myTolerance;
GeomAbs_Shape myCont;
Standard_Integer myMaxDegree;
Standard_Integer myMaxSeg;
Standard_Real myTolReached;
TColGeom_SequenceOfCurve myCurves;
private:
};
#endif // _HelixGeom_BuilderApproxCurve_HeaderFile

View File

@@ -0,0 +1,165 @@
// File: HelixGeom_BuilderHelix.cxx
#include <Geom_Curve.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
#include <gp_Trsf.hxx>
#include <HelixGeom_BuilderHelix.hxx>
#include <HelixGeom_BuilderHelixCoil.hxx>
#include <TColGeom_SequenceOfCurve.hxx>
//=======================================================================
//function :
//purpose :
//=======================================================================
HelixGeom_BuilderHelix::HelixGeom_BuilderHelix()
:
HelixGeom_BuilderHelixGen()
{
}
//=======================================================================
//function : ~
//purpose :
//=======================================================================
HelixGeom_BuilderHelix::~HelixGeom_BuilderHelix()
{
}
//=======================================================================
//function : SetPosition
//purpose :
//=======================================================================
void HelixGeom_BuilderHelix::SetPosition(const gp_Ax2& aAx2)
{
myPosition=aAx2;
}
//=======================================================================
//function : Position
//purpose :
//=======================================================================
const gp_Ax2& HelixGeom_BuilderHelix::Position()const
{
return myPosition;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void HelixGeom_BuilderHelix::Perform()
{
myErrorStatus=0;
myWarningStatus=0;
//
Standard_Integer iErr, aN, i, aNbC;
Standard_Real aTwoPI, dT, aT1x, aT2x, aTR;
//HelixGeom_HelixCurve aHC;
HelixGeom_BuilderHelixCoil aBHC;
//
myCurves.Clear();
myTolReached=-1.;
aTwoPI=2.*M_PI;
//
aBHC.SetTolerance(myTolerance);
aBHC.SetApproxParameters(myCont, myMaxDegree, myMaxSeg);
//
dT=myT2-myT1;
aN=(Standard_Integer)(dT/aTwoPI);
//
if (!aN) {
aBHC.SetCurveParameters(myT1, myT2, myPitch, myRStart, myTaperAngle, myIsClockWise);
aBHC.Perform();
iErr=aBHC.ErrorStatus();
if (iErr) {
myErrorStatus=2;
return;
}
const TColGeom_SequenceOfCurve& aSC=aBHC.Curves();
const Handle(Geom_Curve)& aC=aSC(1);
myCurves.Append(aC);
myTolReached=aBHC.ToleranceReached();
}
//
else {
Standard_Boolean bIsCylindrical;
Standard_Real aTolAngle;
//
aTolAngle=1.e-4;
bIsCylindrical=fabs(myTaperAngle)<aTolAngle;
//
aT1x=myT1;
aT2x=myT1+aTwoPI;
for (i=1; i<=aN; ++i) {
//
if (i>1 && bIsCylindrical) {
Handle(Geom_Curve) aCi;
gp_Pnt aP1, aPi;
//
const Handle(Geom_Curve)& aC1=myCurves(1);
aC1->D0(aC1->FirstParameter(), aP1);
aPi.SetCoord(aP1.X(), aP1.Y(), aP1.Z()+(i-1)*myPitch);
aCi=Handle(Geom_Curve)::DownCast(aC1->Translated(aP1, aPi));
//
myCurves.Append(aCi);
//
aT1x=aT2x;
aT2x=aT1x+aTwoPI;
//
continue;
}
aBHC.SetCurveParameters(aT1x, aT2x, myPitch, myRStart, myTaperAngle, myIsClockWise);
//
aBHC.Perform();
iErr=aBHC.ErrorStatus();
if (iErr) {
myErrorStatus=2;
return;
}
//
const TColGeom_SequenceOfCurve& aSC=aBHC.Curves();
const Handle(Geom_Curve)& aC=aSC(1);
myCurves.Append(aC);
aTR=aBHC.ToleranceReached();
if(aTR>myTolReached) {
myTolReached=aTR;
}
//
aT1x=aT2x;
aT2x=aT1x+aTwoPI;
} // for (i=1; i<=aN; ++i) {
//
aT2x=myT2;
Standard_Real eps = 1.e-7*aTwoPI;
if (fabs (aT2x-aT1x)>eps) {
aBHC.SetCurveParameters(aT1x, aT2x, myPitch, myRStart, myTaperAngle, myIsClockWise);
aBHC.Perform();
iErr=aBHC.ErrorStatus();
if (iErr) {
myErrorStatus=2;
return;
}
//
const TColGeom_SequenceOfCurve& aSC=aBHC.Curves();
const Handle(Geom_Curve)& aC=aSC(1);
myCurves.Append(aC);
aTR=aBHC.ToleranceReached();
if(aTR>myTolReached) {
myTolReached=aTR;
}
}
}
//
// Transformation
gp_Trsf aTrsf;
gp_Ax3 aAx3, aAx3x(myPosition);
//
aTrsf.SetDisplacement(aAx3, aAx3x);
//
aNbC=myCurves.Length();
for (i=1; i<=aNbC; ++i) {
Handle(Geom_Curve)& aC=myCurves(i);
aC->Transform(aTrsf);
}
//
}

View File

@@ -0,0 +1,61 @@
// File: HelixGeom_BuilderHelix.cdl
#ifndef _HelixGeom_BuilderHelix_HeaderFile
#define _HelixGeom_BuilderHelix_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <gp_Ax2.hxx>
#include <HelixGeom_BuilderHelixGen.hxx>
class gp_Ax2;
//! Upper level class for geometrical algorithm of building
//! helix curves using arbitrary axis
class HelixGeom_BuilderHelix : public HelixGeom_BuilderHelixGen
{
public:
DEFINE_STANDARD_ALLOC
//! Empty constructor
Standard_EXPORT HelixGeom_BuilderHelix();
Standard_EXPORT virtual ~HelixGeom_BuilderHelix();
//! Sets coordinate axes for helix
Standard_EXPORT void SetPosition (const gp_Ax2& aAx2);
//! Gets coordinate axes for helix
Standard_EXPORT const gp_Ax2& Position() const;
//! Performs calculations
Standard_EXPORT virtual void Perform() Standard_OVERRIDE;
protected:
gp_Ax2 myPosition;
private:
};
#endif // _HelixGeom_BuilderHelix_HeaderFile

View File

@@ -0,0 +1,63 @@
// File: HelixGeom_BuilderHelixCoil.cxx
#include <Geom_BSplineCurve.hxx>
#include <HelixGeom_BuilderHelixCoil.hxx>
#include <HelixGeom_HelixCurve.hxx>
#include <HelixGeom_HHelixCurve.hxx>
#include <HelixGeom_Tools.hxx>
//=======================================================================
//function : HelixGeom_BuilderHelixCoil
//purpose :
//=======================================================================
HelixGeom_BuilderHelixCoil::HelixGeom_BuilderHelixCoil()
:
HelixGeom_BuilderHelixGen()
{
myT1=0.;
myT2=2.*M_PI;
myPitch=1.;
myRStart=1.;
myTaperAngle=0.;
myIsClockWise=Standard_True;
}
//=======================================================================
//function : ~
//purpose :
//=======================================================================
HelixGeom_BuilderHelixCoil::~HelixGeom_BuilderHelixCoil()
{
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void HelixGeom_BuilderHelixCoil::Perform()
{
myErrorStatus=0;
myWarningStatus=0;
//
Standard_Integer iErr;
HelixGeom_HelixCurve aAdaptor;
Handle(HelixGeom_HHelixCurve) aHAdaptor;
Handle(Geom_BSplineCurve)aBC;
//
myCurves.Clear();
//
aAdaptor.Load(myT1, myT2, myPitch, myRStart, myTaperAngle, myIsClockWise);
aHAdaptor=new HelixGeom_HHelixCurve(aAdaptor);
//
iErr=HelixGeom_Tools::ApprCurve3D(aHAdaptor,
myTolerance, myCont, myMaxSeg, myMaxDegree,
aBC, myTolReached);
if(iErr) {
myErrorStatus=2;
}
else {
myCurves.Append(aBC);
}
}

View File

@@ -0,0 +1,52 @@
// File: HelixGeom_BuilderHelixCoil.cdl
#ifndef _HelixGeom_BuilderHelixCoil_HeaderFile
#define _HelixGeom_BuilderHelixCoil_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <HelixGeom_BuilderHelixGen.hxx>
//! Implementation of algorithm for building helix coil with
//! axis OZ
class HelixGeom_BuilderHelixCoil : public HelixGeom_BuilderHelixGen
{
public:
DEFINE_STANDARD_ALLOC
//! Empty constructor
Standard_EXPORT HelixGeom_BuilderHelixCoil();
Standard_EXPORT virtual ~HelixGeom_BuilderHelixCoil();
//! Performs calculations
Standard_EXPORT virtual void Perform() Standard_OVERRIDE;
protected:
private:
};
#endif // _HelixGeom_BuilderHelixCoil_HeaderFile

View File

@@ -0,0 +1,59 @@
// File: HelixGeom_BuilderHelixGen.cxx
#include <HelixGeom_BuilderHelixGen.hxx>
//=======================================================================
//function :
//purpose :
//=======================================================================
HelixGeom_BuilderHelixGen::HelixGeom_BuilderHelixGen()
:
HelixGeom_BuilderApproxCurve()
{
}
//=======================================================================
//function : ~
//purpose :
//=======================================================================
HelixGeom_BuilderHelixGen::~HelixGeom_BuilderHelixGen()
{
}
//=======================================================================
//function : SetCurveParameters
//purpose :
//=======================================================================
void HelixGeom_BuilderHelixGen::SetCurveParameters(const Standard_Real aT1,
const Standard_Real aT2,
const Standard_Real aPitch,
const Standard_Real aRStart,
const Standard_Real aTaperAngle,
const Standard_Boolean aIsCW)
{
myT1=aT1;
myT2=aT2;
myPitch=aPitch;
myRStart=aRStart;
myTaperAngle=aTaperAngle;
myIsClockWise=aIsCW;
}
//=======================================================================
//function : CurveParameters
//purpose :
//=======================================================================
void HelixGeom_BuilderHelixGen::CurveParameters(Standard_Real& aT1,
Standard_Real& aT2,
Standard_Real& aPitch,
Standard_Real& aRStart,
Standard_Real& aTaperAngle,
Standard_Boolean& aIsClockWise)const
{
aT1=myT1;
aT2=myT2;
aPitch=myPitch;
aRStart=myRStart;
aTaperAngle=myTaperAngle;
aIsClockWise=myIsClockWise;
}

View File

@@ -0,0 +1,62 @@
// File: HelixGeom_BuilderHelixGen.cdl
#ifndef _HelixGeom_BuilderHelixGen_HeaderFile
#define _HelixGeom_BuilderHelixGen_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
#include <HelixGeom_BuilderApproxCurve.hxx>
//! Root class for algorithms of building helix curves
class HelixGeom_BuilderHelixGen : public HelixGeom_BuilderApproxCurve
{
public:
DEFINE_STANDARD_ALLOC
//! Sets parameters for building helix curves
Standard_EXPORT void SetCurveParameters (const Standard_Real aT1, const Standard_Real aT2, const Standard_Real aPitch, const Standard_Real aRStart, const Standard_Real aTaperAngle, const Standard_Boolean bIsClockwise);
//! Gets parameters for building helix curves
Standard_EXPORT void CurveParameters (Standard_Real& aT1, Standard_Real& aT2, Standard_Real& aPitch, Standard_Real& aRStart, Standard_Real& aTaperAngle, Standard_Boolean& bIsClockwise) const;
protected:
//! Sets default parameters
Standard_EXPORT HelixGeom_BuilderHelixGen();
Standard_EXPORT virtual ~HelixGeom_BuilderHelixGen();
Standard_Real myT1;
Standard_Real myT2;
Standard_Real myPitch;
Standard_Real myRStart;
Standard_Real myTaperAngle;
Standard_Boolean myIsClockWise;
private:
};
#endif // _HelixGeom_BuilderHelixGen_HeaderFile

View File

@@ -0,0 +1,75 @@
// File: HelixGeom.cdl
#ifndef _HelixGeom_GHHelixCurve_HeaderFile
#define _HelixGeom_GHHelixCurve_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <HelixGeom_HelixCurve.hxx>
#include <Adaptor3d_HCurve.hxx>
class Standard_OutOfRange;
class Standard_NoSuchObject;
class Standard_DomainError;
class HelixGeom_HelixCurve;
class Adaptor3d_Curve;
class HelixGeom_GHHelixCurve;
DEFINE_STANDARD_HANDLE(HelixGeom_GHHelixCurve, Adaptor3d_HCurve)
class HelixGeom_GHHelixCurve : public Adaptor3d_HCurve
{
public:
Standard_EXPORT HelixGeom_GHHelixCurve();
Standard_EXPORT HelixGeom_GHHelixCurve(const HelixGeom_HelixCurve& C);
Standard_EXPORT void Set (const HelixGeom_HelixCurve& C);
Standard_EXPORT const Adaptor3d_Curve& Curve() const;
Standard_EXPORT Adaptor3d_Curve& GetCurve();
HelixGeom_HelixCurve& ChangeCurve();
DEFINE_STANDARD_RTTI_INLINE(HelixGeom_GHHelixCurve,Adaptor3d_HCurve)
protected:
HelixGeom_HelixCurve myCurve;
private:
};
#define TheCurve HelixGeom_HelixCurve
#define TheCurve_hxx <HelixGeom_HelixCurve.hxx>
#define Adaptor3d_GenHCurve HelixGeom_GHHelixCurve
#define Adaptor3d_GenHCurve_hxx <HelixGeom_GHHelixCurve.hxx>
#define Handle_Adaptor3d_GenHCurve Handle(HelixGeom_GHHelixCurve)
#include <Adaptor3d_GenHCurve.lxx>
#undef TheCurve
#undef TheCurve_hxx
#undef Adaptor3d_GenHCurve
#undef Adaptor3d_GenHCurve_hxx
#undef Handle_Adaptor3d_GenHCurve
#endif // _HelixGeom_GHHelixCurve_HeaderFile

View File

@@ -0,0 +1,28 @@
// File: HelixGeom.cdl
#include <HelixGeom_GHHelixCurve.hxx>
#include <Standard_Type.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_DomainError.hxx>
#include <HelixGeom_HelixCurve.hxx>
#include <Adaptor3d_Curve.hxx>
#define TheCurve HelixGeom_HelixCurve
#define TheCurve_hxx <HelixGeom_HelixCurve.hxx>
#define Adaptor3d_GenHCurve HelixGeom_GHHelixCurve
#define Adaptor3d_GenHCurve_hxx <HelixGeom_GHHelixCurve.hxx>
#define Handle_Adaptor3d_GenHCurve Handle(HelixGeom_GHHelixCurve)
#include <Adaptor3d_GenHCurve.gxx>

View File

@@ -0,0 +1,44 @@
// File: HelixGeom_HHelixCurve.cxx
#include <HelixGeom_HelixCurve.hxx>
#include <HelixGeom_HHelixCurve.hxx>
#include <Standard_Type.hxx>
IMPLEMENT_STANDARD_RTTIEXT(HelixGeom_HHelixCurve,HelixGeom_GHHelixCurve)
//=======================================================================
//function : HelixGeom_HHelixCurve
//purpose :
//=======================================================================
HelixGeom_HHelixCurve::HelixGeom_HHelixCurve()
{
}
//=======================================================================
//function : HelixGeom_HHelixCurve// Lastly modified by :
// +---------------------------------------------------------------------------+
// ! ifv ! Creation !$Date: 2007-10-19 18:21:42 $! %V%-%L%!
// +---------------------------------------------------------------------------+
//purpose :
//=======================================================================
HelixGeom_HHelixCurve::HelixGeom_HHelixCurve(const HelixGeom_HelixCurve& aC)
: HelixGeom_GHHelixCurve(aC)
{
}
//=======================================================================
//function : HelixGeom_HHelixCurve
//purpose :
//=======================================================================
HelixGeom_HHelixCurve::HelixGeom_HHelixCurve(const Standard_Real aT1,
const Standard_Real aT2,
const Standard_Real aPitch,
const Standard_Real aRStart,
const Standard_Real aTaperAngle,
const Standard_Boolean aIsCW)
{
ChangeCurve().Load(aT1, aT2, aPitch, aRStart, aTaperAngle, aIsCW);
}

View File

@@ -0,0 +1,57 @@
// File: HelixGeom_HHelixCurve.cdl
#ifndef _HelixGeom_HHelixCurve_HeaderFile
#define _HelixGeom_HHelixCurve_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <HelixGeom_GHHelixCurve.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
class HelixGeom_HelixCurve;
class HelixGeom_HHelixCurve;
DEFINE_STANDARD_HANDLE(HelixGeom_HHelixCurve, HelixGeom_GHHelixCurve)
//! HAdaptor class for helix curve
class HelixGeom_HHelixCurve : public HelixGeom_GHHelixCurve
{
public:
//! Empty constructor
Standard_EXPORT HelixGeom_HHelixCurve();
//! Constructor by corresponding adaptor curve
Standard_EXPORT HelixGeom_HHelixCurve(const HelixGeom_HelixCurve& aC);
//! Constructor by parameters
Standard_EXPORT HelixGeom_HHelixCurve(const Standard_Real aT1, const Standard_Real aT2, const Standard_Real aPitch, const Standard_Real aRStart, const Standard_Real aTaperAngle, const Standard_Boolean aIsCW);
DEFINE_STANDARD_RTTIEXT(HelixGeom_HHelixCurve,HelixGeom_GHHelixCurve)
protected:
private:
};
#endif // _HelixGeom_HHelixCurve_HeaderFile

View File

@@ -0,0 +1,292 @@
// File: HelixGeom_HelixCurve.cxx
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <HelixGeom_HelixCurve.hxx>
#include <Standard_ConstructionError.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_OutOfRange.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <math.h>
//=======================================================================
//function : HelixGeom_HelixCurve
//purpose :
//=======================================================================
HelixGeom_HelixCurve::HelixGeom_HelixCurve()
{
myFirst=0.;
myLast=2.*M_PI;
myPitch=1.;
myRStart=1.;
myTaperAngle=0.;
myIsClockWise=Standard_True;
//
myC1=myPitch/myLast;
myTgBeta=0.;
myTolAngle=1.e-4;
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void HelixGeom_HelixCurve::Load()
{
Load(myFirst, myLast, myPitch, myRStart, myTaperAngle, myIsClockWise);
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void HelixGeom_HelixCurve::Load(const Standard_Real aT1,
const Standard_Real aT2,
const Standard_Real aPitch,
const Standard_Real aRStart,
const Standard_Real aTaperAngle,
const Standard_Boolean aIsCW)
{
char buf[]={"HelixGeom_HelixCurve::Load"};
Standard_Real aTwoPI, aHalfPI;
//
aTwoPI=2.*M_PI;
aHalfPI=0.5*M_PI;
//
myFirst=aT1;
myLast=aT2;
myPitch=aPitch;
myRStart=aRStart;
myTaperAngle=aTaperAngle;
myIsClockWise=aIsCW;
//
if (aT1>=aT2) {
Standard_ConstructionError::Raise(buf);
}
if (myPitch<0.) {
Standard_ConstructionError::Raise(buf);
}
if (myRStart<0.) {
Standard_ConstructionError::Raise(buf);
}
if (myTaperAngle<=-aHalfPI ||
myTaperAngle>=aHalfPI) {
Standard_ConstructionError::Raise(buf);
}
//
myC1=myPitch/aTwoPI;
if (fabs(myTaperAngle)>myTolAngle) {
myTgBeta=tan(myTaperAngle);
}
}
//=======================================================================
//function : FirstParameter
//purpose :
//=======================================================================
Standard_Real HelixGeom_HelixCurve::FirstParameter() const
{
return myFirst;
}
//=======================================================================
//function : LastParameter
//purpose :
//=======================================================================
Standard_Real HelixGeom_HelixCurve::LastParameter() const
{
return myLast;
}
//=======================================================================
//function : Continuity
//purpose :
//=======================================================================
GeomAbs_Shape HelixGeom_HelixCurve::Continuity() const
{
return GeomAbs_CN;
}
//=======================================================================
//function : NbIntervals
//purpose :
//=======================================================================
Standard_Integer HelixGeom_HelixCurve::NbIntervals(const GeomAbs_Shape ) const
{
return 1;
}
//=======================================================================
//function : Intervals
//purpose :
//=======================================================================
void HelixGeom_HelixCurve::Intervals(TColStd_Array1OfReal& T,
const GeomAbs_Shape) const
{
T(1)=myFirst;
T(2)=myLast;
}
//=======================================================================
//function : Resolution
//purpose :
//=======================================================================
Standard_Real HelixGeom_HelixCurve::Resolution(const Standard_Real) const
{
Standard_NotImplemented::Raise("HelixGeom_HelixCurve::Resolution");
return 0.;
}
//=======================================================================
//function : IsClosed
//purpose :
//=======================================================================
Standard_Boolean HelixGeom_HelixCurve::IsClosed() const
{
Standard_NotImplemented::Raise("HelixGeom_HelixCurve::IsClosed");
return Standard_False;
}
//=======================================================================
//function : IsPeriodic
//purpose :
//=======================================================================
Standard_Boolean HelixGeom_HelixCurve::IsPeriodic() const
{
Standard_NotImplemented::Raise("HelixGeom_HelixCurve::IsPeriodic");
return Standard_False;
}
//=======================================================================
//function : Period
//purpose :
//=======================================================================
Standard_Real HelixGeom_HelixCurve::Period()const
{
Standard_DomainError::Raise("HelixGeom_HelixCurve::Periodic");
return 0.;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
gp_Pnt HelixGeom_HelixCurve::Value(const Standard_Real aT) const
{
Standard_Real aST, aCT, aX, aY, aZ, a1;
//
aCT=cos(aT);
aST=sin(aT);
a1=myRStart+myC1*myTgBeta*aT;
//
aX=a1*aCT;
aY=a1*aST;
if (!myIsClockWise) {
aY=-aY;
}
aZ=myC1*aT;
return gp_Pnt(aX, aY, aZ);
}
//=======================================================================
//function : D0
//purpose :
//=======================================================================
void HelixGeom_HelixCurve::D0(const Standard_Real aT,
gp_Pnt& aP) const
{
aP=Value(aT);
}
//=======================================================================
//function : D1
//purpose :
//=======================================================================
void HelixGeom_HelixCurve::D1(const Standard_Real aT,
gp_Pnt& aP,
gp_Vec& aV1) const
{
Standard_Real aST, aCT, aX, aY, aZ, a1, a2;
//
aCT=cos(aT);
aST=sin(aT);
//
a1=myRStart+myC1*myTgBeta*aT;
//
aX=a1*aCT;
aY=a1*aST;
if (!myIsClockWise) {
aY=-aY;
}
aZ=myC1*aT;
aP.SetCoord(aX, aY, aZ);
//
a1=myC1*myTgBeta;
a2=myRStart+a1*aT;
//
aX=a1*aCT-a2*aST;
aY=a1*aST+a2*aCT;
if (!myIsClockWise) {
aY=-aY;
}
aZ=myC1;
aV1.SetCoord(aX, aY, aZ);
}
//=======================================================================
//function : D2
//purpose :
//=======================================================================
void HelixGeom_HelixCurve::D2(const Standard_Real aT,
gp_Pnt& aP,
gp_Vec& aV1,
gp_Vec& aV2) const
{
Standard_Real aST, aCT, aX, aY, aZ, a1, a2;
//
aCT=cos(aT);
aST=sin(aT);
//
a1=myRStart+myC1*myTgBeta*aT;
//
aX=a1*aCT;
aY=a1*aST;
if (!myIsClockWise) {
aY=-aY;
}
aZ=myC1*aT;
aP.SetCoord(aX, aY, aZ);
//
a1=myC1*myTgBeta;
a2=myRStart+a1*aT;
//
aX=a1*aCT-a2*aST;
aY=a1*aST+a2*aCT;
if (!myIsClockWise) {
aY=-aY;
}
aZ=myC1;
aV1.SetCoord(aX, aY, aZ);
//
a1=2.*a1;
aX=-a2*aCT-a1*aST;
aY=-a2*aST-a1*aCT;
if (!myIsClockWise) {
aY=-aY;
}
aZ=0.;
aV2.SetCoord(aX, aY, aZ);
}
//=======================================================================
//function : DN
//purpose :
//=======================================================================
gp_Vec HelixGeom_HelixCurve::DN(const Standard_Real aT,
const Standard_Integer aN) const
{
gp_Pnt aP;
gp_Vec aV1, aV2;
//
switch (aN) {
case 1:
D1(aT, aP, aV1);
break;
case 2:
D2(aT, aP, aV1, aV2);
break;
default:
Standard_NotImplemented::Raise("HelixGeom_HelixCurve::DN");
break;
}
return gp_Vec(aV1);
}

View File

@@ -0,0 +1,117 @@
// File: HelixGeom_HelixCurve.cdl
#ifndef _HelixGeom_HelixCurve_HeaderFile
#define _HelixGeom_HelixCurve_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
#include <Adaptor3d_Curve.hxx>
#include <GeomAbs_Shape.hxx>
#include <Standard_Integer.hxx>
class Standard_ConstructionError;
class Standard_OutOfRange;
class Standard_DomainError;
class gp_Pnt;
class gp_Vec;
//! Adaptor class for calculation helix curve
class HelixGeom_HelixCurve : public Adaptor3d_Curve
{
public:
DEFINE_STANDARD_ALLOC
//! Adaptor class for calculation helix curve
//! implementation of analytical expressions
Standard_EXPORT HelixGeom_HelixCurve();
//! Sets default values for parameters
Standard_EXPORT void Load();
//! Sets helix parameters
Standard_EXPORT void Load (const Standard_Real aT1, const Standard_Real aT2, const Standard_Real aPitch, const Standard_Real aRStart, const Standard_Real aTaperAngle, const Standard_Boolean aIsCW);
//! Gets first parameter
Standard_EXPORT virtual Standard_Real FirstParameter() const Standard_OVERRIDE;
//! Gets last parameter
Standard_EXPORT virtual Standard_Real LastParameter() const Standard_OVERRIDE;
//! Gets continuity
Standard_EXPORT virtual GeomAbs_Shape Continuity() const Standard_OVERRIDE;
//! Gets number of intervals
Standard_EXPORT virtual Standard_Integer NbIntervals (const GeomAbs_Shape S) const Standard_OVERRIDE;
//! Gets parametric intervals
Standard_EXPORT virtual void Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const Standard_OVERRIDE;
//! Gets parametric resolution
Standard_EXPORT virtual Standard_Real Resolution (const Standard_Real R3d) const Standard_OVERRIDE;
//! Returns False
Standard_EXPORT virtual Standard_Boolean IsClosed() const Standard_OVERRIDE;
//! Returns False
Standard_EXPORT virtual Standard_Boolean IsPeriodic() const Standard_OVERRIDE;
//! Returns 2*PI
Standard_EXPORT virtual Standard_Real Period() const Standard_OVERRIDE;
//! Gets curve point for parameter U
Standard_EXPORT virtual gp_Pnt Value (const Standard_Real U) const Standard_OVERRIDE;
//! Gets curve point for parameter U
Standard_EXPORT virtual void D0 (const Standard_Real U, gp_Pnt& P) const Standard_OVERRIDE;
//! Gets curve point and first derivatives
//! for parameter U
Standard_EXPORT virtual void D1 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1) const Standard_OVERRIDE;
//! Gets curve point, first and second derivatives
//! for parameter U
Standard_EXPORT virtual void D2 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const Standard_OVERRIDE;
//! Gets curve derivative of demanded order
//! for parameter U
Standard_EXPORT virtual gp_Vec DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE;
protected:
Standard_Real myFirst;
Standard_Real myLast;
Standard_Real myPitch;
Standard_Real myRStart;
Standard_Real myTaperAngle;
Standard_Boolean myIsClockWise;
Standard_Real myC1;
Standard_Real myTgBeta;
Standard_Real myTolAngle;
private:
};
#endif // _HelixGeom_HelixCurve_HeaderFile

View File

@@ -0,0 +1,166 @@
// File: HelixGeom_Tools.cxx
#include <Adaptor3d_HCurve.hxx>
#include <AdvApprox_ApproxAFunction.hxx>
#include <AdvApprox_DichoCutting.hxx>
#include <AdvApprox_EvaluatorFunction.hxx>
#include <Geom_BSplineCurve.hxx>
#include <HelixGeom_HelixCurve.hxx>
#include <HelixGeom_HHelixCurve.hxx>
#include <HelixGeom_Tools.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_HArray1OfReal.hxx>
//=======================================================================
//class : HelixGeom_Tools_Eval
//purpose: evaluator class for approximation
//=======================================================================
class HelixGeom_Tools_Eval : public AdvApprox_EvaluatorFunction
{
public:
HelixGeom_Tools_Eval (const Handle(Adaptor3d_HCurve)& theFunc)
: fonct(theFunc) {}
virtual void Evaluate (Standard_Integer *Dimension,
Standard_Real StartEnd[2],
Standard_Real *Parameter,
Standard_Integer *DerivativeRequest,
Standard_Real *Result, // [Dimension]
Standard_Integer *ErrorCode);
private:
Handle(Adaptor3d_HCurve) fonct;
};
void HelixGeom_Tools_Eval::Evaluate (Standard_Integer *Dimension,
Standard_Real /*StartEnd*/[2],
Standard_Real *Param, // Parameter at which evaluation
Standard_Integer *Order, // Derivative Request
Standard_Real *Result,// [Dimension]
Standard_Integer *ErrorCode)
{
*ErrorCode = 0;
Standard_Real par = *Param;
// Dimension is incorrect
if (*Dimension!=3) {
*ErrorCode = 1;
}
gp_Pnt pnt;
gp_Vec v1, v2;
switch (*Order) {
case 0:
pnt = fonct->Value(par);
Result[0] = pnt.X();
Result[1] = pnt.Y();
Result[2] = pnt.Z();
break;
case 1:
fonct->D1(par, pnt, v1);
Result[0] = v1.X();
Result[1] = v1.Y();
Result[2] = v1.Z();
break;
case 2:
fonct->D2(par, pnt, v1, v2);
Result[0] = v2.X();
Result[1] = v2.Y();
Result[2] = v2.Z();
break;
default:
Result[0] = Result[1] = Result[2] = 0.;
*ErrorCode = 3;
break;
}
}
//=======================================================================
//function : ApprCurve3D
//purpose :
//=======================================================================
Standard_Integer HelixGeom_Tools::ApprCurve3D(Handle(Adaptor3d_HCurve)& theHC,
const Standard_Real theTol,
const GeomAbs_Shape theCont,
const Standard_Integer theMaxSeg,
const Standard_Integer theMaxDeg,
Handle(Geom_BSplineCurve)& theBSpl,
Standard_Real& theMaxError)
{
Standard_Boolean anIsDone, aHasResult;
Standard_Integer Num1DSS, Num2DSS, Num3DSS;
Standard_Real First, Last;
Handle(TColStd_HArray1OfReal) OneDTolNul, TwoDTolNul, ThreeDTol;
AdvApprox_DichoCutting aCutTool;
//
Num1DSS=0;
Num2DSS=0;
Num3DSS=1;
ThreeDTol = new TColStd_HArray1OfReal(1,Num3DSS);
ThreeDTol->Init(theTol);
//
First = theHC->FirstParameter();
Last = theHC->LastParameter();
//
HelixGeom_Tools_Eval ev (theHC);
AdvApprox_ApproxAFunction aApprox (Num1DSS, Num2DSS, Num3DSS,
OneDTolNul, TwoDTolNul, ThreeDTol,
First, Last, theCont,
theMaxDeg, theMaxSeg,
ev, aCutTool);
//
anIsDone = aApprox.IsDone();
if(!anIsDone) {
return 1;
}
//
theMaxError = 0.;
//
aHasResult = aApprox.HasResult();
if (!aHasResult) {
return 2;
}
//
TColgp_Array1OfPnt Poles(1,aApprox.NbPoles());
aApprox.Poles(1,Poles);
Handle(TColStd_HArray1OfReal) Knots = aApprox.Knots();
Handle(TColStd_HArray1OfInteger) Mults = aApprox.Multiplicities();
Standard_Integer Degree = aApprox.Degree();
theBSpl = new Geom_BSplineCurve(Poles, Knots->Array1(), Mults->Array1(), Degree);
theMaxError = aApprox.MaxError(3, 1);
//
return 0;
}
//=======================================================================
//function : ApprHelix
//purpose :
//=======================================================================
Standard_Integer HelixGeom_Tools::ApprHelix(const Standard_Real aT1,
const Standard_Real aT2,
const Standard_Real aPitch,
const Standard_Real aRStart,
const Standard_Real aTaperAngle,
const Standard_Boolean aIsCW,
const Standard_Real theTol,
Handle(Geom_BSplineCurve)& theBSpl,
Standard_Real& theMaxError)
{
Standard_Integer iErr, aMaxDegree, aMaxSeg;
GeomAbs_Shape aCont;
HelixGeom_HelixCurve aAdaptor;
Handle(HelixGeom_HHelixCurve) aHAdaptor;
//
aAdaptor.Load(aT1, aT2, aPitch, aRStart, aTaperAngle, aIsCW);
aHAdaptor=new HelixGeom_HHelixCurve(aAdaptor);
//
aCont=GeomAbs_C2;
aMaxDegree = 8;
aMaxSeg=150;
//
iErr=HelixGeom_Tools::ApprCurve3D(aHAdaptor,
theTol, aCont, aMaxSeg, aMaxDegree,
theBSpl, theMaxError);
return iErr;
}

View File

@@ -0,0 +1,55 @@
// File: HelixGeom_Tools.cdl
#ifndef _HelixGeom_Tools_HeaderFile
#define _HelixGeom_Tools_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
#include <GeomAbs_Shape.hxx>
class Geom_BSplineCurve;
class Adaptor3d_HCurve;
//! Approximation algorithms for bulding helix curves
class HelixGeom_Tools
{
public:
DEFINE_STANDARD_ALLOC
//! Bulding helix curves
Standard_EXPORT static Standard_Integer ApprHelix (const Standard_Real aT1, const Standard_Real aT2, const Standard_Real aPitch, const Standard_Real aRStart, const Standard_Real aTaperAngle, const Standard_Boolean aIsCW, const Standard_Real aTol, Handle(Geom_BSplineCurve)& theBSpl, Standard_Real& theMaxError);
//! Reaprroximation of adaptor curve
Standard_EXPORT static Standard_Integer ApprCurve3D (Handle(Adaptor3d_HCurve)& theHC, const Standard_Real theTol, const GeomAbs_Shape theCont, const Standard_Integer theMaxSeg, const Standard_Integer theMaxDeg, Handle(Geom_BSplineCurve)& theBSpl, Standard_Real& theMaxError);
protected:
private:
};
#endif // _HelixGeom_Tools_HeaderFile

3
src/HelixTest/FILES Normal file
View File

@@ -0,0 +1,3 @@
HelixTest.cxx
HelixTest.hxx
HelixTest_HelixCommands.cxx

View File

@@ -0,0 +1,36 @@
// File: HelixTest.cxx
#include <HelixTest.hxx>
#include <stdio.h>
//=======================================================================
//function : AllCommands
//purpose :
//=======================================================================
void HelixTest::AllCommands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
done = Standard_True;
//
HelixTest::HelixCommands (theCommands);
}
//=======================================================================
//function : Factory
//purpose :
//=======================================================================
void HelixTest::Factory(Draw_Interpretor& theCommands)
{
static Standard_Boolean FactoryDone = Standard_False;
if (FactoryDone) return;
FactoryDone = Standard_True;
HelixTest::AllCommands(theCommands);
Printf(" Helix Plugin is loaded\n");
}
#include <Draw_PluginMacro.hxx>
DPLUGIN(HelixTest)

View File

@@ -0,0 +1,50 @@
// File: HelixTest.cdl
#ifndef _HelixTest_HeaderFile
#define _HelixTest_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Draw_Interpretor.hxx>
class HelixTest
{
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT static void AllCommands (Draw_Interpretor& aDI);
Standard_EXPORT static void HelixCommands (Draw_Interpretor& aDI);
Standard_EXPORT static void Factory (Draw_Interpretor& aDI);
protected:
private:
};
#endif // _HelixTest_HeaderFile

View File

@@ -0,0 +1,555 @@
// File: HelixTest_HelixCommands.cxx
#include <DBRep.hxx>
#include <Draw.hxx>
#include <Draw_Color.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_Marker3D.hxx>
#include <Draw_Segment3D.hxx>
#include <Draw_Viewer.hxx>
#include <DrawTrSurf.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Line.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAdaptor_HCurve.hxx>
#include <gp.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <HelixBRep_BuilderHelix.hxx>
#include <HelixGeom_BuilderHelix.hxx>
#include <HelixGeom_BuilderHelixCoil.hxx>
#include <HelixGeom_HelixCurve.hxx>
#include <HelixGeom_Tools.hxx>
#include <HelixTest.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <TColGeom_SequenceOfCurve.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_Array1OfBoolean.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TopoDS_Shape.hxx>
//
Standard_IMPORT Draw_Viewer dout;
//
static gp_Ax3 theHelixAxis(gp_Pnt(0., 0., 0), gp_Dir(0., 0., 1.), gp_Dir(1., 0., 0.));
static Standard_Integer comphelix (Draw_Interpretor& , Standard_Integer , const char ** );
static Standard_Integer helix (Draw_Interpretor& , Standard_Integer , const char ** );
static Standard_Integer spiral (Draw_Interpretor& , Standard_Integer , const char ** );
static Standard_Integer setaxis (Draw_Interpretor& , Standard_Integer , const char ** );
static Standard_Integer comphelix2 (Draw_Interpretor& , Standard_Integer , const char ** );
static Standard_Integer helix2 (Draw_Interpretor& , Standard_Integer , const char ** );
static Standard_Integer spiral2 (Draw_Interpretor& , Standard_Integer , const char ** );
//=======================================================================
//function : HelixTest::HelixCommands
//purpose :
//=======================================================================
void HelixTest::HelixCommands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
done = Standard_True;
// Chapters name
const char* g = "Helix commands";
// Commands
theCommands.Add("setaxis", "setaxis x y z Nx Ny Nz Xx Xy Xz",
__FILE__, setaxis, g);
theCommands.Add("comphelix", "comphelix name np D1 [Di...] H1 [Hi...] P1 [Pi...] PF1 [PFi...]",
__FILE__, comphelix, g);
theCommands.Add("helix", "helix name np D1 H1 [Hi...] P1 [Pi...] PF1 [PFi...]",
__FILE__, helix, g);
theCommands.Add("spiral", "spiral name np D1 D2 H1 [Hi...] P1 [Pi...] PF1 [PFi...]",
__FILE__, spiral, g);
theCommands.Add("comphelix2", "comphelix2 name np D1 [Di...] P1 [Pi...] N1 [Ni...]",
__FILE__, comphelix2, g);
theCommands.Add("helix2", "helix2 name np D1 P1 [Pi...] N1 [Ni...]",
__FILE__, helix2, g);
theCommands.Add("spiral2", "spiral2 name np D1 D2 P1 [Pi...] N1 [Ni...]",
__FILE__, spiral2, g);
}
//=======================================================================
//function : setaxis
//purpose :
//=======================================================================
Standard_Integer setaxis(Draw_Interpretor& di, Standard_Integer n, const char ** a)
{
if (n < 10) {
di << "Usage : " << a[0] << " x y z Nx Ny Nz Xx Xy Xz" <<"\n";
di << " " << "x y z - location" <<"\n";
di << " " << "Nx Ny Nz - direction" <<"\n";
di << " " << "Xx Xy Xz - X direction" <<"\n";
return 1;
}
Standard_Real xx[9];
Standard_Integer i;
for(i = 0; i < 9; ++i) {
xx[i] = Draw::Atof(a[i+1]);
}
theHelixAxis.SetLocation(gp_Pnt(xx[0], xx[1], xx[2]));
theHelixAxis.SetDirection(gp_Dir(xx[3], xx[4], xx[5]));
theHelixAxis.SetXDirection(gp_Dir(xx[6], xx[7], xx[8]));
return 0;
}
//
//=======================================================================
//function : comphelix
//purpose :
//=======================================================================
Standard_Integer comphelix(Draw_Interpretor& di, Standard_Integer n, const char ** a)
{
if (n < 8) {
di << "Usage : " << a[0] << " name np D1 D2 [Di...] H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2 ... (must be np+1 values) - diameters" <<"\n";
di << " " << "H1, H2 ... (must be np values) - heights" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches or numbers of turns" <<"\n";
di << " " << "PF1, PF2 ... (must be np values) - 0 or 1, if PFi = 1, Pi is pitch, otherwise Pi is number of turns" <<"\n";
return 1;
}
//
Standard_Integer i, aNb, ic;
HelixBRep_BuilderHelix aBH;
//
aNb = Draw::Atoi(a[2]);
if (n != 3 + (aNb+1) + aNb*3) {
di << "Usage : " << a[0] << " name np D1 D2 [Di...] H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2 ... (must be np+1 values) - diameters" <<"\n";
di << " " << "H1, H2 ... (must be np values) - heights" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches or numbers of turns" <<"\n";
di << " " << "PF1, PF2 ... (must be np values) - 0 or 1, if PFi = 1, Pi is pitch, otherwise Pi is number of turns" <<"\n";
return 1;
}
//
TColStd_Array1OfReal aDiams(1, aNb + 1);
TColStd_Array1OfReal aHeights(1, aNb);
TColStd_Array1OfReal aPitches(1, aNb);
TColStd_Array1OfBoolean bIsPitches(1, aNb);
ic = 3;
for(i = 1; i <= aNb+1; ++i) {
aDiams(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aHeights(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aPitches(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
bIsPitches(i) = Draw::Atoi(a[ic]) != 0;
++ic;
}
//
aBH.SetParameters(theHelixAxis, aDiams, aHeights, aPitches, bIsPitches);
aBH.Perform();
if(aBH.ErrorStatus() == 0) {
Standard_Real aMaxError=aBH.ToleranceReached();
di << "WarningStatus = " << aBH.WarningStatus() <<"\n";
di << "ToleranceReached = " << aMaxError <<"\n";
//
const TopoDS_Shape& aW=aBH.Shape();
DBRep::Set(a[1], aW);
}
else {
di << "ErrorStatus = " << aBH.ErrorStatus() << "\n";
}
return 0;
}
//=======================================================================
//function : helix
//purpose :
//=======================================================================
Standard_Integer helix(Draw_Interpretor& di, Standard_Integer n, const char ** a)
{
if (n < 7) {
di << "Usage : " << a[0] << " name np D1 H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 - diameter" <<"\n";
di << " " << "H1, H2 ... (must be np values) - heights" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches or numbers of turns" <<"\n";
di << " " << "PF1, PF2 ... (must be np values) - 0 or 1, if PFi = 1, Pi is pitch, otherwise Pi is number of turns" <<"\n";
return 1;
}
//
Standard_Integer i, aNb, ic;
HelixBRep_BuilderHelix aBH;
//
aNb = Draw::Atoi(a[2]);
if (n != 3 + 1 + aNb*3) {
di << "Usage : " << a[0] << " name np D1 H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 - diameter" <<"\n";
di << " " << "H1, H2 ... (must be np values) - heights" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches or numbers of turns" <<"\n";
di << " " << "PF1, PF2 ... (must be np values) - 0 or 1, if PFi = 1, Pi is pitch, otherwise Pi is number of turns" <<"\n";
return 1;
}
//
TColStd_Array1OfReal aDiams(1, 1);
TColStd_Array1OfReal aHeights(1, aNb);
TColStd_Array1OfReal aPitches(1, aNb);
TColStd_Array1OfBoolean bIsPitches(1, aNb);
ic = 3;
for(i = 1; i <= 1; ++i) {
aDiams(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aHeights(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aPitches(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
bIsPitches(i) = Draw::Atoi(a[ic]) != 0;
++ic;
}
//
aBH.SetParameters(theHelixAxis, aDiams(1), aHeights, aPitches, bIsPitches);
aBH.Perform();
if(aBH.ErrorStatus() == 0) {
Standard_Real aMaxError=aBH.ToleranceReached();
di << "WarningStatus = " << aBH.WarningStatus() <<"\n";
di << "ToleranceReached = " << aMaxError <<"\n";
//
const TopoDS_Shape& aW=aBH.Shape();
DBRep::Set(a[1], aW);
}
else {
di << "ErrorStatus = " << aBH.ErrorStatus() << "\n";
}
return 0;
}
//=======================================================================
//function : spiral
//purpose :
//=======================================================================
Standard_Integer spiral(Draw_Interpretor& di, Standard_Integer n, const char ** a)
{
if (n < 8) {
di << "Usage : " << a[0] << " name np D1 D2 H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2 - first and last diameters" <<"\n";
di << " " << "H1, H2 ... (must be np values) - heights" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches or numbers of turns" <<"\n";
di << " " << "PF1, PF2 ... (must be np values) - 0 or 1, if PFi = 1, Pi is pitch, otherwise Pi is number of turns" <<"\n";
return 1;
}
//
Standard_Integer i, aNb, ic;
HelixBRep_BuilderHelix aBH;
//
aNb = Draw::Atoi(a[2]);
if (n != 3 + 2 + aNb*3) {
di << "Usage : " << a[0] << " name np D1 D2 H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2 - first and last diameters" <<"\n";
di << " " << "H1, H2 ... (must be np values) - heights" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches or numbers of turns" <<"\n";
di << " " << "PF1, PF2 ... (must be np values) - 0 or 1, if PFi = 1, Pi is pitch, otherwise Pi is number of turns" <<"\n";
return 1;
}
//
TColStd_Array1OfReal aDiams(1, 2);
TColStd_Array1OfReal aHeights(1, aNb);
TColStd_Array1OfReal aPitches(1, aNb);
TColStd_Array1OfBoolean bIsPitches(1, aNb);
ic = 3;
for(i = 1; i <= 2; ++i) {
aDiams(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aHeights(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aPitches(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
bIsPitches(i) = Draw::Atoi(a[ic]) != 0;
++ic;
}
//
aBH.SetParameters(theHelixAxis, aDiams(1), aDiams(2), aHeights, aPitches, bIsPitches);
aBH.Perform();
if(aBH.ErrorStatus() == 0) {
Standard_Real aMaxError=aBH.ToleranceReached();
di << "WarningStatus = " << aBH.WarningStatus() <<"\n";
di << "ToleranceReached = " << aMaxError <<"\n";
//
const TopoDS_Shape& aW=aBH.Shape();
DBRep::Set(a[1], aW);
}
else {
di << "ErrorStatus = " << aBH.ErrorStatus() << "\n";
}
return 0;
}
//=======================================================================
//function : comphelix2
//purpose :
//=======================================================================
Standard_Integer comphelix2(Draw_Interpretor& di, Standard_Integer n, const char ** a)
{
if (n < 7) {
di << "Usage : " << a[0] << " name np D1 D2 [Di...] P1 [Pi...] N1 [Ni...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2, ... (must be np+1 values) - diameters" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches" <<"\n";
di << " " << "N1, N2, ... (must be np values) - numbers of turns" <<"\n";
return 1;
}
//
Standard_Integer i, aNb, ic;
HelixBRep_BuilderHelix aBH;
//
aNb = Draw::Atoi(a[2]);
if (n != 3 + (aNb+1) + aNb*2) {
di << "Usage : " << a[0] << " name np D1 D2 [Di...] P1 [Pi...] N1 [Ni...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2, ... (must be np+1 values) - diameters" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches" <<"\n";
di << " " << "N1, N2, ... (must be np values) - numbers of turns" <<"\n";
return 1;
}
//
TColStd_Array1OfReal aDiams(1, aNb + 1);
TColStd_Array1OfReal aPitches(1, aNb);
TColStd_Array1OfReal aNbTurns(1, aNb);
ic = 3;
for(i = 1; i <= aNb+1; ++i) {
aDiams(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aPitches(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aNbTurns(i) = Draw::Atof(a[ic]);
++ic;
}
//
aBH.SetParameters(theHelixAxis, aDiams, aPitches, aNbTurns);
aBH.Perform();
if(aBH.ErrorStatus() == 0) {
Standard_Real aMaxError=aBH.ToleranceReached();
di << "WarningStatus = " << aBH.WarningStatus() <<"\n";
di << "ToleranceReached = " << aMaxError <<"\n";
//
const TopoDS_Shape& aW=aBH.Shape();
DBRep::Set(a[1], aW);
}
else {
di << "ErrorStatus = " << aBH.ErrorStatus() << "\n";
}
return 0;
}
//=======================================================================
//function : helix2
//purpose :
//=======================================================================
Standard_Integer helix2(Draw_Interpretor& di, Standard_Integer n, const char ** a)
{
if (n < 6) {
di << "Usage : " << a[0] << " name np D1 P1 [Pi...] N1 [Ni...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 - diameter" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches" <<"\n";
di << " " << "N1, N2, ... (must be np values) - numbers of turns" <<"\n";
return 1;
}
//
Standard_Integer i, aNb, ic;
HelixBRep_BuilderHelix aBH;
//
aNb = Draw::Atoi(a[2]);
if (n != 3 + 1 + aNb*2) {
di << "Usage : " << a[0] << " name np D1 H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 - diameter" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches" <<"\n";
di << " " << "N1, N2, ... (must be np values) - numbers of turns" <<"\n";
return 1;
}
//
TColStd_Array1OfReal aDiams(1, 1);
TColStd_Array1OfReal aPitches(1, aNb);
TColStd_Array1OfReal aNbTurns(1, aNb);
ic = 3;
for(i = 1; i <= 1; ++i) {
aDiams(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aPitches(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aNbTurns(i) = Draw::Atof(a[ic]);
++ic;
}
//
aBH.SetParameters(theHelixAxis, aDiams(1), aPitches, aNbTurns);
aBH.Perform();
if(aBH.ErrorStatus() == 0) {
Standard_Real aMaxError=aBH.ToleranceReached();
di << "WarningStatus = " << aBH.WarningStatus() <<"\n";
di << "ToleranceReached = " << aMaxError <<"\n";
//
const TopoDS_Shape& aW=aBH.Shape();
DBRep::Set(a[1], aW);
}
else {
di << "ErrorStatus = " << aBH.ErrorStatus() << "\n";
}
return 0;
}
//=======================================================================
//function : spiral2
//purpose :
//=======================================================================
Standard_Integer spiral2(Draw_Interpretor& di, Standard_Integer n, const char ** a)
{
if (n < 7) {
di << "Usage : " << a[0] << " name np D1 D2 P1 [Pi...] N1 [Ni...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2 - first and last diameters" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches" <<"\n";
di << " " << "N1, N2, ... (must be np values) - numbers of turns" <<"\n";
return 1;
}
//
Standard_Integer i, aNb, ic;
HelixBRep_BuilderHelix aBH;
//
aNb = Draw::Atoi(a[2]);
if (n != 3 + 2 + aNb*2) {
di << "Usage : " << a[0] << " name np D1 D2 H1 [Hi...] P1 [Pi...] PF1 [PFi...]" <<"\n";
di << " " << "name - name of result" <<"\n";
di << " " << "np - number of helix parts" <<"\n";
di << " " << "D1 D2 - first and last diameters" <<"\n";
di << " " << "P1, P2, ... (must be np values) - pitches" <<"\n";
di << " " << "N1, N2, ... (must be np values) - numbers of turns" <<"\n";
return 1;
}
//
TColStd_Array1OfReal aDiams(1, 2);
TColStd_Array1OfReal aPitches(1, aNb);
TColStd_Array1OfReal aNbTurns(1, aNb);
ic = 3;
for(i = 1; i <= 2; ++i) {
aDiams(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aPitches(i) = Draw::Atof(a[ic]);
++ic;
}
for(i = 1; i <= aNb; ++i) {
aNbTurns(i) = Draw::Atof(a[ic]);
++ic;
}
//
aBH.SetParameters(theHelixAxis, aDiams(1), aDiams(2), aPitches, aNbTurns);
aBH.Perform();
if(aBH.ErrorStatus() == 0) {
Standard_Real aMaxError=aBH.ToleranceReached();
di << "WarningStatus = " << aBH.WarningStatus() <<"\n";
di << "ToleranceReached = " << aMaxError <<"\n";
//
const TopoDS_Shape& aW=aBH.Shape();
DBRep::Set(a[1], aW);
}
else {
di << "ErrorStatus = " << aBH.ErrorStatus() << "\n";
}
return 0;
}

5
src/OCCTools/FILES Normal file
View File

@@ -0,0 +1,5 @@
FILES
OCCTools.cxx
OCCTools.hxx
OCCTools_ComputeExposedArea.cxx
OCCTools_ComputeExposedArea.hxx

57
src/OCCTools/OCCTools.cxx Normal file
View File

@@ -0,0 +1,57 @@
// File: OCCTools.cxx
// Created: 21.02.2017
// Author: Mikhail Sazonov
#include "OCCTools.hxx"
#include <TopoDS_Shape.hxx>
#include <StlAPI.hxx>
#include <STEPControl_Reader.hxx>
#include <Standard_ErrorHandler.hxx>
#pragma comment(lib,"TKSTL")
#pragma comment(lib,"TKXSBase")
#pragma comment(lib,"TKSTEP")
//=======================================================================
//function : ReadStl
//purpose :
//=======================================================================
TopoDS_Shape OCCTools::ReadStl(const char* theFName)
{
TopoDS_Shape aShape;
try
{
OCC_CATCH_SIGNALS
StlAPI::Read(aShape, theFName);
}
catch (Standard_Failure)
{
aShape.Nullify();
}
return aShape;
}
//=======================================================================
//function : ReadStep
//purpose :
//=======================================================================
TopoDS_Shape OCCTools::ReadStep(const char* theFName)
{
TopoDS_Shape aShape;
try
{
OCC_CATCH_SIGNALS
STEPControl_Reader aReader;
IFSelect_ReturnStatus aStatus = aReader.ReadFile(theFName);
if (aStatus == IFSelect_RetDone)
{
aReader.TransferRoots();
aShape = aReader.OneShape();
}
}
catch (Standard_Failure)
{
aShape.Nullify();
}
return aShape;
}

27
src/OCCTools/OCCTools.hxx Normal file
View File

@@ -0,0 +1,27 @@
// File: OCCTools.hxx
// Created: 21.02.2017
// Author: Mikhail Sazonov
#ifndef OCCTools_hxx
#define OCCTools_hxx
#include <Standard_TypeDef.hxx>
class TopoDS_Shape;
//! This class provides some useful static methods
class OCCTools
{
public:
//! Reads STL file and creates a shape, in which each triangle from STL is
//! represented by a single TopoDS_Face.
//! Returns null shape in the case of failure.
Standard_EXPORT static TopoDS_Shape ReadStl(const char* theFName);
//! Reads STEP file and creates a shape from its contents.
//! Returns null shape in the case of failure.
Standard_EXPORT static TopoDS_Shape ReadStep(const char* theFName);
};
#endif

View File

@@ -0,0 +1,231 @@
// File: OCCTools_ComputeExposedArea.cxx
// Created: 20.02.2017
// Author: Mikhail Sazonov
#include "OCCTools_ComputeExposedArea.hxx"
#include <BRep_Builder.hxx>
#include <BRepAlgoAPI_BuilderAlgo.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepGProp.hxx>
#include <BOPAlgo_MakerVolume.hxx>
#include <GProp_GProps.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Compound.hxx>
#include <TopTools_MapOfShape.hxx>
#pragma comment(lib,"TKernel")
#pragma comment(lib,"TKMath")
#pragma comment(lib,"TKG2d")
#pragma comment(lib,"TKBRep")
#pragma comment(lib,"TKTopAlgo")
#pragma comment(lib,"TKBO")
static
void MakeCompound(const TopoDS_Shape& theShape,
TopoDS_Shape& theComp,
const TopAbs_ShapeEnum theType = TopAbs_FACE);
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
OCCTools_ComputeExposedArea::OCCTools_ComputeExposedArea()
: myFuzzyValue(0.),
mySumArea(0.),
myArea(0.),
myIsGluing(Standard_False)
{
}
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
OCCTools_ComputeExposedArea::OCCTools_ComputeExposedArea(const TopTools_ListOfShape& theShapes)
: myFuzzyValue(0.),
mySumArea(0.),
myArea(0.),
myIsGluing(Standard_False)
{
TopTools_ListOfShape::Iterator anIt(theShapes);
for (; anIt.More(); anIt.Next())
{
AddShape(anIt.Value());
}
}
//=======================================================================
//function : AddShape
//purpose :
//=======================================================================
Standard_Boolean OCCTools_ComputeExposedArea::AddShape(const TopoDS_Shape& theShape)
{
TopExp_Explorer anExp(theShape, TopAbs_SOLID);
if (anExp.More())
{
// Shape has solids
for (; anExp.More(); anExp.Next())
{
const TopoDS_Shape& aShape = anExp.Current();
myShapes.Append(aShape);
GProp_GProps aProps;
BRepGProp::SurfaceProperties(aShape, aProps);
mySumArea += aProps.Mass();
}
}
else
{
// No solids, so try to make them from faces
BOPAlgo_MakerVolume aMkVol;
aMkVol.SetRunParallel(Standard_True);
anExp.Init(theShape, TopAbs_FACE);
for (; anExp.More(); anExp.Next())
{
aMkVol.AddArgument(anExp.Current());
}
aMkVol.Perform();
if (aMkVol.ErrorStatus() != 0)
return Standard_False;
const TopoDS_Shape& aShape = aMkVol.Shape();
return AddShape(aShape);
}
return Standard_True;
}
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
Standard_Integer OCCTools_ComputeExposedArea::Perform(const Handle(Message_ProgressIndicator)& theProgress)
{
if (myShapes.Extent() == 0)
{
// no solid shapes
return Status_BadInput;
}
else if (myShapes.Extent() == 1)
{
// one solid - nothing to fuse
myFusedShape = myShapes.First();
}
else
{
// For the case of gluing there is no need to perform operation on
// the solids, it is enough to fuse only the faces, and remove all
// coinciding splits from the result.
// Without gluing we need to perform real Boolean Fuse operation
// to avoid common part in the result
BRepAlgoAPI_BuilderAlgo *pBuilder = myIsGluing ?
new BRepAlgoAPI_BuilderAlgo() : new BRepAlgoAPI_Fuse();
pBuilder->SetProgressIndicator(theProgress);
pBuilder->SetRunParallel(Standard_True);
pBuilder->SetFuzzyValue(myFuzzyValue);
if (myIsGluing)
{
pBuilder->SetGlue(BOPAlgo_GlueShift);
// prepare arguments - remove solids and make compound of faces
TopTools_ListOfShape aLFaces;
TopTools_ListIteratorOfListOfShape aItLS(myShapes);
for (; aItLS.More(); aItLS.Next())
{
TopoDS_Shape aFaces;
MakeCompound(aItLS.Value(), aFaces);
aLFaces.Append(aFaces);
}
pBuilder->SetArguments(aLFaces);
}
else
{
// For the fuse one of the shapes should be an object
// and other the tools
TopTools_ListOfShape anObjects, aTools;
anObjects = myShapes;
anObjects.RemoveFirst();
aTools.Append(myShapes.First());
pBuilder->SetArguments(anObjects);
((BRepAlgoAPI_Fuse*)pBuilder)->SetTools(aTools);
}
// perform fusion
pBuilder->Build();
if (!pBuilder->IsDone())
{
return Status_FuseError;
}
myFusedShape = pBuilder->Shape();
if (myIsGluing)
{
// Analyze the result of fuse - the fused result should contain only unique faces
// Result compound
TopoDS_Compound aResult;
BRep_Builder().MakeCompound(aResult);
// Make a map from the result faces to original ones
BOPCol_IndexedDataMapOfShapeListOfShape aFaceLOrigins;
TopTools_ListIteratorOfListOfShape aItLS(myShapes);
for (; aItLS.More(); aItLS.Next())
{
const TopoDS_Shape& aS = aItLS.Value();
TopExp_Explorer anExp(aS, TopAbs_FACE);
for (; anExp.More(); anExp.Next())
{
const TopoDS_Shape& aF = anExp.Current();
const TopTools_ListOfShape& aLFIm = pBuilder->Modified(aF);
if (aLFIm.IsEmpty())
{
// the face has not been even touched
BRep_Builder().Add(aResult, aF);
continue;
}
TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm);
for (; aItLFIm.More(); aItLFIm.Next())
{
const TopoDS_Shape& aFIm = aItLFIm.Value();
TopTools_ListOfShape *pLOrigins = aFaceLOrigins.ChangeSeek(aFIm);
if (!pLOrigins)
pLOrigins = &aFaceLOrigins(aFaceLOrigins.Add(aFIm, TopTools_ListOfShape()));
pLOrigins->Append(aF);
}
}
}
Standard_Integer i, aNb = aFaceLOrigins.Extent();
for (i = 1; i <= aNb; ++i)
{
if (aFaceLOrigins(i).Extent() == 1)
BRep_Builder().Add(aResult, aFaceLOrigins.FindKey(i));
}
myFusedShape = aResult;
}
}
// compute area of fused shape
GProp_GProps aProps;
BRepGProp::SurfaceProperties(myFusedShape, aProps);
myArea = aProps.Mass();
return Status_OK;
}
//=======================================================================
//function : MakeCompound
//purpose :
//=======================================================================
void MakeCompound(const TopoDS_Shape& theShape,
TopoDS_Shape& theComp,
const TopAbs_ShapeEnum theType)
{
TopoDS_Compound aComp;
BRep_Builder().MakeCompound(aComp);
TopExp_Explorer anExp(theShape, theType);
for (; anExp.More(); anExp.Next())
BRep_Builder().Add(aComp, anExp.Current());
theComp = aComp;
}

View File

@@ -0,0 +1,106 @@
// File: OCCTools_ComputeExposedArea.hxx
// Created: 20.02.2017
// Author: Mikhail Sazonov
#ifndef OCCTools_ComputeExposedArea_hxx
#define OCCTools_ComputeExposedArea_hxx
#include <Standard_TypeDef.hxx>
#include <TopTools_ListOfShape.hxx>
class Message_ProgressIndicator;
//! This class computes fusion of inputs shapes
//! and calculates the area of the result (exposed area).
//! It looks only for solid shapes in input arguments. If there are no solids
//! it looks for faces and tries to create closed shells and then solids of them.
//! The class has the following options:
//! - *Gluing mode* - allows speeding up the calculation on the touching arguments;
//! In this mode the area computation will be performed on the faces,
//! forming the closed shells, not on the solids. It will help to avoid
//! extra computations and, most importantly, possible errors while
//! constructing the solids;
//! - *Fuzzy mode* - additional tolerance for the operation to make the arguments
//! interfere when its appropriate.
//!
class OCCTools_ComputeExposedArea
{
public:
//! Enumerates error statuses
enum ErrorStatus
{
Status_OK = 0, //!< No error
Status_BadInput = 0x01, //!< Bad input, no solids are found
Status_FuseError = 0x02 //!< Failure of computation of fused shape
};
//! Empty constructor
Standard_EXPORT OCCTools_ComputeExposedArea();
//! Constructor with input shapes
Standard_EXPORT OCCTools_ComputeExposedArea(const TopTools_ListOfShape& theShapes);
//! Adds an input shape. If there are no solids it tries to make solids from faces.
//! Returns false if the input does not contain solids or faces constituting closed shells.
Standard_EXPORT Standard_Boolean AddShape(const TopoDS_Shape& theShape);
//! Returns the number of recognized input solids
Standard_Integer GetNbOfSolids() const
{
return myShapes.Extent();
}
//! Returns the list of input solid shapes.
const TopTools_ListOfShape& GetShapes() const
{
return myShapes;
}
//! Sets the mode of gluing, which tells that no face-face intersection
//! needs to be performed
void SetIsGluing(const Standard_Boolean theVal)
{
myIsGluing = theVal;
}
//! Sets fuzzy value. It allows ignoring gaps of the given size between shapes.
void SetFuzzyValue(const Standard_Real theVal)
{
myFuzzyValue = theVal;
}
//! Performs the computations.
//! Returns the combination of error statuses (see ErrorStatus)
Standard_EXPORT Standard_Integer Perform(const Handle(Message_ProgressIndicator)& theProgress =
Handle(Message_ProgressIndicator)());
//! Returns the fused shape
const TopoDS_Shape& GetFusedShape() const
{
return myFusedShape;
}
//! Returns the sum of areas of inputs shapes
Standard_Real GetSumArea() const
{
return mySumArea;
}
//! Returns the exposed area
Standard_Real GetArea() const
{
return myArea;
}
private:
TopTools_ListOfShape myShapes;
TopoDS_Shape myFusedShape;
Standard_Real myFuzzyValue;
Standard_Real mySumArea;
Standard_Real myArea;
Standard_Boolean myIsGluing;
};
#endif

3
src/OCCToolsTest/FILES Normal file
View File

@@ -0,0 +1,3 @@
FILES
OCCToolsTest.cpp
OCCToolsTest.hxx

View File

@@ -0,0 +1,160 @@
// File: OCCToolsTest.cpp
#include "OCCToolsTest.hxx"
#include <Draw_PluginMacro.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw.hxx>
#include <DBRep.hxx>
#include <BRepGProp.hxx>
#include <GProp_GProps.hxx>
#include <OCCTools_ComputeExposedArea.hxx>
#include <OCCTools.hxx>
#pragma comment(lib,"TKernel")
#pragma comment(lib,"TKMath")
#pragma comment(lib,"TKDraw")
#pragma comment(lib,"TKG2d")
#pragma comment(lib,"TKTopAlgo")
//=======================================================================
// taExposedArea
//=======================================================================
Standard_Integer taExposedArea(Draw_Interpretor& di,
Standard_Integer n, const char** a)
{
if (n < 3)
{
di << "Invalid usage, use help";
return 1;
}
// algorithm instance
OCCTools_ComputeExposedArea aCompEA;
// read options
Standard_Integer anInd = 2;
while (a[anInd][0] == '-')
{
if (strcmp(a[anInd], "-fuz") == 0)
{
anInd++;
Standard_Real aValue = Draw::Atof(a[anInd++]);
aCompEA.SetFuzzyValue(aValue);
}
else if (strcmp(a[anInd], "-glue") == 0)
{
anInd++;
aCompEA.SetIsGluing(Standard_True);
}
else
{
di << "Invalid option " << a[anInd];
return 1;
}
}
// get shapes
for (; anInd < n; anInd++)
{
TopoDS_Shape aShape = DBRep::Get(a[anInd]);
if (aShape.IsNull())
{
di << "No such shape " << a[anInd];
return 1;
}
aCompEA.AddShape(aShape);
}
di << "Nb solids is " << aCompEA.GetNbOfSolids() << "\n";
di << "Sum area is " << aCompEA.GetSumArea() << "\n";
// perform algo
Standard_Integer anError = aCompEA.Perform();
if (anError != OCCTools_ComputeExposedArea::Status_OK)
{
// process error statuses
if (anError & OCCTools_ComputeExposedArea::Status_BadInput)
{
di << "Bad input, no solids are found\n";
}
if (anError & OCCTools_ComputeExposedArea::Status_FuseError)
{
di << "Failure of computation of fused shape\n";
}
}
else
{
// show result
const TopoDS_Shape& aFusedShape = aCompEA.GetFusedShape();
Standard_Real anArea = aCompEA.GetArea();
DBRep::Set(a[1], aFusedShape);
di << "Area is " << anArea;
}
return 0;
}
//=======================================================================
// taReadStep
//=======================================================================
Standard_Integer taReadFile(Draw_Interpretor& di,
Standard_Integer n, const char** a)
{
if (n < 3)
{
di << "Invalid usage, use help";
return 1;
}
const char* aFName = a[2];
TopoDS_Shape aShape;
if (strcmp(a[0], "taReadStep") == 0)
aShape = OCCTools::ReadStep(aFName);
else //if (strcmp(a[0], "taReadStl") == 0)
aShape = OCCTools::ReadStl(aFName);
if (aShape.IsNull())
{
di << "Read error";
}
else
{
DBRep::Set(a[1], aShape);
}
return 0;
}
//=======================================================================
// Commands
//=======================================================================
void OCCToolsTest::Commands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
done = Standard_True;
char* g = "OCCToolsTest commands";
theCommands.Add("taExposedArea",
"taExposedArea res_name [-fuz <val>] [-glue] shape [shape ...]",
__FILE__, taExposedArea, g);
theCommands.Add("taReadStep",
"taReadStep res_name file_name",
__FILE__, taReadFile, g);
theCommands.Add("taReadStl",
"taReadStl res_name file_name",
__FILE__, taReadFile, g);
}
//=======================================================================
// Factory
//=======================================================================
void OCCToolsTest::Factory(Draw_Interpretor& theDI)
{
static Standard_Boolean FactoryDone = Standard_False;
if (FactoryDone) return;
FactoryDone = Standard_True;
OCCToolsTest::Commands(theDI);
}
// Declare entry point PLUGINFACTORY
DPLUGIN(OCCToolsTest)

View File

@@ -0,0 +1,19 @@
#ifndef _PFC_HeaderFile
#define _PFC_HeaderFile
class Draw_Interpretor;
#include <Standard_TypeDef.hxx>
//! The OCCToolsTest package provides the plug-in for DRAW Test Harness,
//! which contains a set of DRAW commands wrapping OCCTools functions.
class OCCToolsTest {
public:
//! Defines all OCCToolsTest commands.
Standard_EXPORT static void Commands(Draw_Interpretor& DI);
//! Defines the weld-bead plugin. <br>
Standard_EXPORT static void Factory(Draw_Interpretor& DI);
};
#endif

View File

@@ -6,3 +6,6 @@ srcinc:::ModelingAlgorithms.tcl
srcinc:::ModelingData.tcl
srcinc:::Modules.tcl
srcinc:::Visualization.tcl
srcinc:::Helix.tcl
srcinc:::Unfolding.tcl
srcinc:::OCCTools.tcl

36
src/OS/Helix.tcl Normal file
View File

@@ -0,0 +1,36 @@
# Definitions for a product: Helix
# List of toolkits
proc Helix:toolkits { } {
return [list TKHelix]
}
# List of non-toolkits (resource units, executables etc., with associated info)
proc Helix:ressources { } {
return {}
}
# Product name
proc Helix:name { } {
return Helix
}
# And short alias
proc Helix:alias { } {
return Helix
}
# Dependency on other products
proc Helix:depends { } {
return {}
}
proc Helix:CompileWith { } {
}
proc Helix:LinksoWith { } {
}
proc Helix:Export { } {
return [list source runtime wokadm api]
}

View File

@@ -22,6 +22,9 @@ proc OS:Modules { {plat ""} } {
ApplicationFramework \
DataExchange \
Draw \
OCCTools \
Helix \
Unfolding
]
return $ret
}

36
src/OS/OCCTools.tcl Normal file
View File

@@ -0,0 +1,36 @@
# Definitions for a product: Unfolding
# List of toolkits
proc Unfolding:toolkits { } {
return [list TKOCCTools TKOCCToolsTest]
}
# List of non-toolkits (resource units, executables etc., with associated info)
proc Unfolding:ressources { } {
return {}
}
# Product name
proc Unfolding:name { } {
return Unfolding
}
# And short alias
proc Unfolding:alias { } {
return Unfolding
}
# Dependency on other products
proc Unfolding:depends { } {
return {}
}
proc Unfolding:CompileWith { } {
}
proc Unfolding:LinksoWith { } {
}
proc Unfolding:Export { } {
return [list source runtime wokadm api]
}

36
src/OS/Unfolding.tcl Normal file
View File

@@ -0,0 +1,36 @@
# Definitions for a product: Unfolding
# List of toolkits
proc Unfolding:toolkits { } {
return [list TKUnfolding TKUnfoldingTest]
}
# List of non-toolkits (resource units, executables etc., with associated info)
proc Unfolding:ressources { } {
return {}
}
# Product name
proc Unfolding:name { } {
return Unfolding
}
# And short alias
proc Unfolding:alias { } {
return Unfolding
}
# Dependency on other products
proc Unfolding:depends { } {
return {}
}
proc Unfolding:CompileWith { } {
}
proc Unfolding:LinksoWith { } {
}
proc Unfolding:Export { } {
return [list source runtime wokadm api]
}

View File

@@ -0,0 +1,3 @@
project(TKHelix)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

7
src/TKHelix/EXTERNLIB Normal file
View File

@@ -0,0 +1,7 @@
TKBRep
TKMath
TKernel
TKG2d
TKG3d
TKDraw
TKTopAlgo

1
src/TKHelix/FILES Normal file
View File

@@ -0,0 +1 @@
EXTERNLIB

3
src/TKHelix/PACKAGES Normal file
View File

@@ -0,0 +1,3 @@
HelixGeom
HelixBRep
HelixTest

View File

@@ -0,0 +1,3 @@
project(TKOCCTools)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

23
src/TKOCCTools/EXTERNLIB Normal file
View File

@@ -0,0 +1,23 @@
TKBRep
TKGeomAlgo
TKTopAlgo
TKernel
TKMath
TKBO
TKG2d
TKG3d
TKDraw
TKHLR
TKGeomBase
TKMesh
TKService
TKV3d
TKFillet
TKPrim
TKBool
TKOffset
TKFeat
TKShHealing
TKSTL
TKXSBase
TKSTEP

2
src/TKOCCTools/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

2
src/TKOCCTools/PACKAGES Normal file
View File

@@ -0,0 +1,2 @@
OCCTools

View File

@@ -0,0 +1,3 @@
project(TKOCCToolsTest)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,22 @@
TKBRep
TKGeomAlgo
TKTopAlgo
TKernel
TKMath
TKBO
TKG2d
TKG3d
TKDraw
TKHLR
TKGeomBase
TKMesh
TKService
TKV3d
TKFillet
TKPrim
TKBool
TKOffset
TKFeat
TKShHealing
TKSTL
TKOCCTools

2
src/TKOCCToolsTest/FILES Normal file
View File

@@ -0,0 +1,2 @@
EXTERNLIB
PACKAGES

View File

@@ -0,0 +1,2 @@
OCCToolsTest

View File

@@ -0,0 +1,3 @@
project(TKUnfolding)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

10
src/TKUnfolding/EXTERNLIB Normal file
View File

@@ -0,0 +1,10 @@
TKBRep
TKMath
TKernel
TKG2d
TKG3d
TKDraw
TKTopAlgo
TKGeomAlgo
TKShHealing
TKGeomBase

1
src/TKUnfolding/FILES Normal file
View File

@@ -0,0 +1 @@
EXTERNLIB

1
src/TKUnfolding/PACKAGES Normal file
View File

@@ -0,0 +1 @@
Unfolding

View File

@@ -0,0 +1,3 @@
project(TKUnfoldingTest)
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)

View File

@@ -0,0 +1,6 @@
TKBRep
TKMath
TKernel
TKG3d
TKDraw
TKUnfolding

View File

@@ -0,0 +1 @@
EXTERNLIB

View File

@@ -0,0 +1 @@
UnfoldingTest

22
src/Unfolding/FILES Normal file
View File

@@ -0,0 +1,22 @@
Unfolding.cxx
Unfolding.hxx
Unfolding.lxx
Unfolding_Array2OfPoint.hxx
Unfolding_ErrorStatus.hxx
Unfolding_FaceDataContainer.cxx
Unfolding_FaceDataContainer.hxx
Unfolding_FaceDataContainer.lxx
Unfolding_FaceDataMapHasher.hxx
Unfolding_FaceDataMapHasher.lxx
Unfolding_FunctionWithDerivative.cxx
Unfolding_FunctionWithDerivative.hxx
Unfolding_HArray2OfPoint.hxx
Unfolding_IndexedMapOfFaceDataContainer.hxx
Unfolding_Point.hxx
Unfolding_Point.lxx
Unfolding_Shell.cxx
Unfolding_Shell.hxx
Unfolding_Shell.lxx
Unfolding_Surface.cxx
Unfolding_Surface.hxx
Unfolding_Surface.lxx

162
src/Unfolding/Unfolding.cxx Normal file
View File

@@ -0,0 +1,162 @@
// File: Unfolding.cxx
// Created: Wed Sep 17 09:16:05 2008
// Author: Sergey KHROMOV
// <skv@kurox>
#include <Unfolding.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRep_Tool.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
//=======================================================================
//function : ToShell
//purpose :
//=======================================================================
TopoDS_Shell Unfolding::ToShell(const TopoDS_Shape &theShape,
const Standard_Real theTolerance,
Unfolding_ErrorStatus &theStatus)
{
TopoDS_Shell aShell;
TopAbs_ShapeEnum aType = theShape.ShapeType();
if (aType != TopAbs_COMPOUND && aType != TopAbs_COMPSOLID &&
aType != TopAbs_SOLID && aType != TopAbs_SHELL) {
theStatus = Unfolding_InvalidInput;
return aShell;
}
if (aType == TopAbs_SHELL) {
// theShape is a shell. Nothing to be done.
theStatus = Unfolding_Done;
aShell = TopoDS::Shell(theShape);
return aShell;
}
BRepBuilderAPI_Sewing aSewing(theTolerance);
aSewing.Add(theShape);
aSewing.Perform();
const TopoDS_Shape &aShape = aSewing.SewedShape();
if (aShape.IsNull()) {
theStatus = Unfolding_Failure;
return aShell;
}
// Explore shape to extract a shell.
TopExp_Explorer anExp(aShape, TopAbs_SHELL);
if (!anExp.More()) {
theStatus = Unfolding_InvalidShape;
return aShell;
}
TopoDS_Shape aSingleShell = anExp.Current();
anExp.Next();
if (anExp.More()) {
theStatus = Unfolding_ComplexShape;
return aShell;
}
// Check if there is no other redundant shapes that are not in the shell.
anExp.Init(aShape, TopAbs_VERTEX, TopAbs_SHELL);
if (anExp.More()) {
theStatus = Unfolding_ComplexShape;
return aShell;
}
// Get the single shell.
theStatus = Unfolding_Done;
aShell = TopoDS::Shell(aSingleShell);
return aShell;
}
//=======================================================================
//function : ToShell
//purpose :
//=======================================================================
Standard_Integer Unfolding::NbSamples(const TopoDS_Edge &theEdge,
const TopTools_ListOfShape &theFaces,
const Standard_Real theTolerance)
{
Standard_Integer aNbPointsLimit = Unfolding::GetMaxNbSamples() / 2;
Standard_Integer aMaxNbPoints = 11;
Standard_Integer aNbPoints;
TopTools_ListIteratorOfListOfShape anIt( theFaces );
for ( ; anIt.More(); anIt.Next() ) {
TopoDS_Shape aCurShape = anIt.Value();
TopoDS_Face aFace = TopoDS::Face( aCurShape );
aFace.Orientation(TopAbs_FORWARD);
Standard_Integer aNbPnt = 2;
Standard_Real aParam[2];
Handle(Geom2d_Curve) aCurve =
BRep_Tool::CurveOnSurface(theEdge, aFace, aParam[0], aParam[1]);
Handle(Standard_Type) aType = aCurve->DynamicType();
while (aType == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
Handle(Geom2d_TrimmedCurve) aTrCurve =
Handle(Geom2d_TrimmedCurve)::DownCast(aCurve);
aCurve = aTrCurve->BasisCurve();
aType = aCurve->DynamicType();
}
if (aType == STANDARD_TYPE(Geom2d_BezierCurve)) {
Handle(Geom2d_BezierCurve) aBezier =
Handle(Geom2d_BezierCurve)::DownCast(aCurve);
aNbPnt = 3 + aBezier->NbPoles();
if (aNbPnt < 11)
aNbPnt = 11;
} else if (aType == STANDARD_TYPE(Geom2d_BSplineCurve)) {
Handle(Geom2d_BSplineCurve) aBSpline =
Handle(Geom2d_BSplineCurve)::DownCast(aCurve);
aNbPnt = aBSpline->NbKnots()*aBSpline->Degree();
if (aNbPnt < 11)
aNbPnt = 11;
} else {
aNbPnt = 11;
}
aMaxNbPoints = ( aMaxNbPoints < aNbPnt ) ? aNbPnt : aMaxNbPoints;
Geom2dAdaptor_Curve aCurve1(aCurve);
Standard_Real L = GCPnts_AbscissaPoint::Length(aCurve1, aParam[0], aParam[1]) ;
// estimate number of points taking into account the curvature of radius myTolContour * 2.
Standard_Real sizeR = 0.125 * L / theTolerance + 2;
if ( aNbPointsLimit > sizeR )
aNbPointsLimit = (Standard_Integer) sizeR;
}
// Check if the number of points exceeds the maximum number of points.
if(aMaxNbPoints > aNbPointsLimit)
aMaxNbPoints = aNbPointsLimit;
aNbPoints = aMaxNbPoints;
return aNbPoints;
}

View File

@@ -0,0 +1,92 @@
// File: Unfolding.cdl
// Created: Tue Jul 22 12:48:05 2008
// Author: Sergey KHROMOV
// <skv@dimox>
//-Copyright: Open CASCADE 2008
#ifndef _Unfolding_HeaderFile
#define _Unfolding_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Real.hxx>
#include <Unfolding_ErrorStatus.hxx>
#include <Standard_Integer.hxx>
#include <TopTools_ListOfShape.hxx>
class TopoDS_Shell;
class TopoDS_Shape;
class TopoDS_Edge;
class Unfolding_Surface;
class Unfolding_Point;
class Unfolding_FunctionWithDerivative;
class Unfolding_Shell;
class Unfolding_FaceDataContainer;
class Unfolding_FaceDataMapHasher;
//! This package contains a tool for unfolding a surface on a plane.
class Unfolding
{
public:
DEFINE_STANDARD_ALLOC
//! This method converts theShape to a shell. It sewes faces of the
//! shell if it is necessary and possible with the given tolerance.
//! If it is not possible to construct a single shell from theShape,
//! this method returns null shell and the corresponding error
//! status. The status can have the following values:
//! - Unfolding_Done: the operation succeeded
//! - Unfolding_InvalidInput: input shape type is less then
//! TopAbs_SHELL.
//! - Unfolding_Failure: sewing failure.
//! - Unfolding_InvalidShape: the shape after sewing does not
//! contain shells.
//! - Unfolding_ComplexShape: the shape after sewing contains
//! either more then one shell or one shell and other not
//! connected shapes.
Standard_EXPORT static TopoDS_Shell ToShell (const TopoDS_Shape& theShape, const Standard_Real theTolerance, Unfolding_ErrorStatus& theStatus);
//! This method returns the number of sample points for theEdge.
//! theFaces is a list of faces that contain theEdge.
//! This method returns the maximal number of points for sampling of
//! edges and/or faces.
static Standard_Integer NbSamples (const TopoDS_Edge& theEdge, const TopTools_ListOfShape& theFaces, const Standard_Real theTolerance);
Standard_EXPORT static Standard_Integer GetMaxNbSamples();
protected:
private:
friend class Unfolding_Surface;
friend class Unfolding_Point;
friend class Unfolding_FunctionWithDerivative;
friend class Unfolding_Shell;
friend class Unfolding_FaceDataContainer;
friend class Unfolding_FaceDataMapHasher;
};
#include <Unfolding.lxx>
#endif // _Unfolding_HeaderFile

View File

@@ -0,0 +1,12 @@
// File: Unfolding.lxx
// Created: Tue Jul 22 13:12:24 2008
// Author: Sergey KHROMOV
// <skv@dimox>
inline Standard_Integer Unfolding::GetMaxNbSamples()
{
static Standard_Integer aMaxNbSamples = 1000;
return aMaxNbSamples;
}

View File

@@ -0,0 +1,16 @@
// File: Unfolding.cdl
// Created: Tue Jul 22 12:48:05 2008
// Author: Sergey KHROMOV
// <skv@dimox>
//-Copyright: Open CASCADE 2008
#ifndef Unfolding_Array2OfPoint_HeaderFile
#define Unfolding_Array2OfPoint_HeaderFile
#include <Unfolding_Point.hxx>
#include <NCollection_Array2.hxx>
typedef NCollection_Array2<Unfolding_Point> Unfolding_Array2OfPoint;
#endif

View File

@@ -0,0 +1,22 @@
// File: Unfolding.cdl
// Created: Tue Jul 22 12:48:05 2008
// Author: Sergey KHROMOV
// <skv@dimox>
//-Copyright: Open CASCADE 2008
#ifndef _Unfolding_ErrorStatus_HeaderFile
#define _Unfolding_ErrorStatus_HeaderFile
enum Unfolding_ErrorStatus
{
Unfolding_Done,
Unfolding_NotDone,
Unfolding_Failure,
Unfolding_InvalidSurface,
Unfolding_InvalidInput,
Unfolding_InvalidShape,
Unfolding_ComplexShape
};
#endif // _Unfolding_ErrorStatus_HeaderFile

View File

@@ -0,0 +1,116 @@
// File: Unfolding_FaceDataContainer.cxx
// Created: Tue Jul 22 13:12:24 2008
// Author: Sergey KHROMOV
// <skv@dimox>
#include <BRepBuilderAPI_Transform.hxx>
#include <gp_Trsf.hxx>
#include <Standard_Type.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <Unfolding_FaceDataContainer.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Unfolding_FaceDataContainer,MMgt_TShared)
//=======================================================================
//function : SetFace
//purpose :
//=======================================================================
void Unfolding_FaceDataContainer::SetFace(const TopoDS_Face &theFace)
{
Standard_Boolean isSame = theFace.IsSame(myFace);
myFace = theFace;
if (!isSame) {
// Update the map myEdgeMap
myEdgeMap.Clear();
TopExp_Explorer anExp(myFace, TopAbs_EDGE);
TopTools_ListOfShape anEmptyList;
for (; anExp.More(); anExp.Next()) {
const TopoDS_Shape &anEdge = anExp.Current();
myEdgeMap.Bind(anEdge, anEmptyList);
}
}
}
//=======================================================================
//function : ApplyTrsf
//purpose :
//=======================================================================
void Unfolding_FaceDataContainer::ApplyTrsf(const gp_Trsf &theTrsf)
{
BRepBuilderAPI_Transform aTrsf(theTrsf);
if (!myUnfoldedFace.IsNull()) {
aTrsf.Perform(myUnfoldedFace);
if (aTrsf.IsDone())
myUnfoldedFace = TopoDS::Face(aTrsf.Shape());
}
TopTools_DataMapIteratorOfDataMapOfShapeListOfShape anEdgeIter(myEdgeMap);
TopTools_ListIteratorOfListOfShape aUEIter;
for (; anEdgeIter.More(); anEdgeIter.Next()) {
const TopoDS_Shape &anEdge = anEdgeIter.Key();
TopTools_ListOfShape &anEdges = myEdgeMap.ChangeFind(anEdge);
TopTools_ListOfShape aTrsfEdges;
for (aUEIter.Initialize(anEdges); aUEIter.More(); aUEIter.Next()) {
const TopoDS_Shape &aUEdge = aUEIter.Value();
aTrsf.Perform(aUEdge);
if (aTrsf.IsDone())
aTrsfEdges.Append(aTrsf.Shape());
}
anEdges.Clear();
anEdges.Append(aTrsfEdges);
}
}
//=======================================================================
//function : SetEdgesForEdge
//purpose :
//=======================================================================
void Unfolding_FaceDataContainer::SetEdgesForEdge
(const TopoDS_Edge &theEdge,
const TopTools_ListOfShape &theUnfoldedEdges)
{
if (myEdgeMap.IsBound(theEdge)) {
TopTools_ListOfShape &anEdges = myEdgeMap.ChangeFind(theEdge);
anEdges = theUnfoldedEdges;
}
}
//=======================================================================
//function : GetEdgesForEdge
//purpose :
//=======================================================================
const TopTools_ListOfShape &Unfolding_FaceDataContainer::GetEdgesForEdge
(const TopoDS_Edge &theEdge) const
{
if (myEdgeMap.IsBound(theEdge)) {
const TopTools_ListOfShape &anEdges = myEdgeMap.Find(theEdge);
return anEdges;
}
static TopTools_ListOfShape anEmptyList;
return anEmptyList;
}

View File

@@ -0,0 +1,101 @@
// File: Unfolding_FaceDataContainer.cdl
// Created: Fri Sep 19 16:52:05 2008
// Author: Sergey KHROMOV
// <skv@kurox>
//-Copyright: Matra Datavision 2008
#ifndef _Unfolding_FaceDataContainer_HeaderFile
#define _Unfolding_FaceDataContainer_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <TopoDS_Face.hxx>
#include <TopTools_DataMapOfShapeListOfShape.hxx>
#include <Standard_Real.hxx>
#include <MMgt_TShared.hxx>
class TopoDS_Face;
class gp_Trsf;
class TopoDS_Edge;
class Unfolding_FaceDataContainer;
DEFINE_STANDARD_HANDLE(Unfolding_FaceDataContainer, MMgt_TShared)
//! This class represents a data container for data constructed
//! during unfolding operation.
class Unfolding_FaceDataContainer : public MMgt_TShared
{
public:
//! Empty constructor
Standard_EXPORT Unfolding_FaceDataContainer();
//! Sets the original face.
Standard_EXPORT void SetFace (const TopoDS_Face& theFace);
//! Returns the original face.
const TopoDS_Face& GetFace() const;
//! Sets the unfolded face for the original one.
void SetUnfoldedFace (const TopoDS_Face& theUnfoldedFace);
//! Returns the unfolded face for the original one.
const TopoDS_Face& GetUnfoldedFace() const;
//! Sets the distortion area.
void SetDistortionArea (const Standard_Real theDistortionArea);
//! Returns the distortion area.
Standard_Real GetDistortionArea() const;
//! Sets the maximal Gauss curvature.
void SetMaxGaussCurvature (const Standard_Real theCurvature);
//! Returns the maximal Gauss curvature.
Standard_Real GetMaxGaussCurvature() const;
//! Resets the data container.
void Reset();
//! Applies the transformation to all unfolded shapes.
Standard_EXPORT void ApplyTrsf (const gp_Trsf& theTrsf);
//! Associates unfolded edges with the source edge.
Standard_EXPORT void SetEdgesForEdge (const TopoDS_Edge& theEdge, const TopTools_ListOfShape& theUnfoldedEdges);
//! Returns unfolded edges associated to the source edge.
Standard_EXPORT const TopTools_ListOfShape& GetEdgesForEdge (const TopoDS_Edge& theEdge) const;
DEFINE_STANDARD_RTTIEXT(Unfolding_FaceDataContainer,MMgt_TShared)
protected:
private:
TopoDS_Face myFace;
TopoDS_Face myUnfoldedFace;
TopTools_DataMapOfShapeListOfShape myEdgeMap;
Standard_Real myDistortionArea;
Standard_Real myCurvature;
};
#include <Unfolding_FaceDataContainer.lxx>
#endif // _Unfolding_FaceDataContainer_HeaderFile

View File

@@ -0,0 +1,101 @@
// File: Unfolding_FaceDataContainer.lxx
// Created: Tue Jul 22 13:12:24 2008
// Author: Sergey KHROMOV
// <skv@dimox>
//=======================================================================
//function : Empty constructor
//purpose :
//=======================================================================
inline Unfolding_FaceDataContainer::Unfolding_FaceDataContainer()
: myDistortionArea(0.),
myCurvature(0.)
{
}
//=======================================================================
//function : GetFace
//purpose :
//=======================================================================
inline const TopoDS_Face &Unfolding_FaceDataContainer::GetFace() const
{
return myFace;
}
//=======================================================================
//function : SetUnfoldedFace
//purpose :
//=======================================================================
inline void Unfolding_FaceDataContainer::SetUnfoldedFace
(const TopoDS_Face &theUnfoldedFace)
{
myUnfoldedFace = theUnfoldedFace;
}
//=======================================================================
//function : GetUnfoldedFace
//purpose :
//=======================================================================
inline const TopoDS_Face &Unfolding_FaceDataContainer::GetUnfoldedFace() const
{
return myUnfoldedFace;
}
//=======================================================================
//function : SetDistortionArea
//purpose :
//=======================================================================
inline void Unfolding_FaceDataContainer::SetDistortionArea
(const Standard_Real theDistortionArea)
{
myDistortionArea = theDistortionArea;
}
//=======================================================================
//function : GetDistortionArea
//purpose :
//=======================================================================
inline Standard_Real Unfolding_FaceDataContainer::GetDistortionArea() const
{
return myDistortionArea;
}
//=======================================================================
//function : SetMaxGaussCurvature
//purpose :
//=======================================================================
inline void Unfolding_FaceDataContainer::SetMaxGaussCurvature
(const Standard_Real theCurvature)
{
myCurvature = theCurvature;
}
//=======================================================================
//function : GetMaxGaussCurvature
//purpose :
//=======================================================================
inline Standard_Real Unfolding_FaceDataContainer::GetMaxGaussCurvature() const
{
return myCurvature;
}
//=======================================================================
//function : Reset
//purpose :
//=======================================================================
inline void Unfolding_FaceDataContainer::Reset()
{
myUnfoldedFace.Nullify();
myDistortionArea = 0.;
myCurvature = 0.;
}

View File

@@ -0,0 +1,60 @@
// File: Unfolding_FaceDataMapHasher.cdl
// Created: Fri Sep 19 16:52:05 2008
// Author: Sergey KHROMOV
// <skv@kurox>
//-Copyright: Matra Datavision 2008
#ifndef _Unfolding_FaceDataMapHasher_HeaderFile
#define _Unfolding_FaceDataMapHasher_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Boolean.hxx>
class Unfolding_FaceDataContainer;
//! Hash tool, used for generating maps of face data containers.
class Unfolding_FaceDataMapHasher
{
public:
DEFINE_STANDARD_ALLOC
//! Returns a HasCode value for the Key <K> in the
//! range 0..theUpper.
static Standard_Integer HashCode (const Handle(Unfolding_FaceDataContainer)& theKey, const Standard_Integer theUpper);
//! Returns True when the two keys are the same. Two
//! same keys must have the same hashcode, the
//! contrary is not necessary.
static Standard_Boolean IsEqual (const Handle(Unfolding_FaceDataContainer)& theKey1, const Handle(Unfolding_FaceDataContainer)& theKey2);
protected:
private:
};
#include <Unfolding_FaceDataMapHasher.lxx>
#endif // _Unfolding_FaceDataMapHasher_HeaderFile

View File

@@ -0,0 +1,30 @@
// File: Unfolding_FaceDataMapHasher.lxx
// Created: Mon Sep 22 08:54:51 2008
// Author: Sergey KHROMOV
// <skv@kurox>
//=======================================================================
//function : HashCode
//purpose :
//=======================================================================
inline Standard_Integer Unfolding_FaceDataMapHasher::HashCode
(const Handle(Unfolding_FaceDataContainer) &theKey,
const Standard_Integer theUpper)
{
return (theKey.IsNull()) ? 0 : theKey->GetFace().HashCode(theUpper);
}
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
inline Standard_Boolean Unfolding_FaceDataMapHasher::IsEqual
(const Handle(Unfolding_FaceDataContainer) &theKey1,
const Handle(Unfolding_FaceDataContainer) &theKey2)
{
return !theKey1.IsNull() && !theKey2.IsNull() &&
theKey1->GetFace().IsSame(theKey2->GetFace());
}

View File

@@ -0,0 +1,249 @@
// File: Unfolding_FunctionWithDerivative.cxx
// Created: Fri Sep 5 17:51:58 2008
// Author: Mikhail KLOKOV
// <mkk@kurox>
#include <gp_Dir2d.hxx>
#include <gp_Trsf2d.hxx>
#include <TColgp_Array1OfXY.hxx>
#include <Unfolding_FunctionWithDerivative.hxx>
static Standard_Boolean ComputeArea(const TColgp_Array1OfXY& theMasterPolyLine,
const TColgp_Array1OfXY& theSlavePolyLine,
const gp_Dir2d& theShiftDir,
const Standard_Real& theShift,
const gp_Trsf2d theTrsf,
Standard_Real& theArea);
static Standard_Boolean ComputeAreaDeriv(const TColgp_Array1OfXY& theMasterPolyLine,
const TColgp_Array1OfXY& theSlavePolyLine,
const gp_Dir2d& theShiftDir,
const Standard_Real& theShift,
const gp_Trsf2d theTrsf,
Standard_Real& theArea,
Standard_Real& theDeriv);
//=============================================================================
// function: Constructor
//=============================================================================
Unfolding_FunctionWithDerivative::Unfolding_FunctionWithDerivative(const TColgp_Array1OfXY& theMaster,
const TColgp_Array1OfXY& theSlave,
const gp_Dir2d& theDir,
const gp_Trsf2d& theTrsf):
myMasterPolyLine(theMaster.Lower(), theMaster.Upper()),
mySlavePolyLine(theSlave.Lower(), theSlave.Upper())
{
myMasterPolyLine.Assign(theMaster);
mySlavePolyLine.Assign(theSlave);
myTrsf = theTrsf;
myShiftDir = theDir;
myShift = 0.;
myArea = 0.;
}
//=============================================================================
// function: Value
//=============================================================================
Standard_Boolean Unfolding_FunctionWithDerivative::Value(const Standard_Real X,Standard_Real& F)
{
myShift = X;
F = 0.;
Standard_Real A = 0.;
Standard_Real D = 0.;
if ( !ComputeAreaDeriv(myMasterPolyLine, mySlavePolyLine, myShiftDir, myShift, myTrsf, A, D) )
return Standard_False;
myArea = A;
gp_XY aP1P2(0, A);
gp_XY vecD(1,D);
Standard_Real modD = vecD.Modulus();
if ( modD < gp::Resolution() ) {
Standard_Real delta = 1.e-7;
if ( !ComputeArea(myMasterPolyLine, mySlavePolyLine, myShiftDir, myShift - delta, myTrsf, A) )
return Standard_False;
gp_XY P1(0,A);
if ( !ComputeArea(myMasterPolyLine, mySlavePolyLine, myShiftDir, myShift + delta, myTrsf, A) )
return Standard_False;
gp_XY P2(0,A);
gp_XY V = P2-P1;
modD = V.Modulus();
if ( modD < gp::Resolution() )
return Standard_False;
}
F = aP1P2 * vecD;
F /= modD;
return Standard_True;
}
//=============================================================================
// function: Derivative
//=============================================================================
Standard_Boolean Unfolding_FunctionWithDerivative::Derivative(const Standard_Real X,Standard_Real& D)
{
Standard_Real F = 0.;
return Values(X,F,D);
}
//=============================================================================
// function: Values
//=============================================================================
Standard_Boolean Unfolding_FunctionWithDerivative::Values(const Standard_Real X,Standard_Real& F,Standard_Real& D)
{
Standard_Real F1 = 0., F2 = 0.;
Standard_Real aDelta = 1.e-05;
if ( fabs(X) > aDelta )
aDelta = fabs(X) * aDelta;
if ( !Value(X + aDelta, F2) )
return Standard_False;
if ( !Value(X, F1) )
return Standard_False;
myShift = X;
F = F1;
D = F2 - F1;
D /= aDelta;
return Standard_True;
}
//=============================================================================
// function: GetStateNumber
//=============================================================================
Standard_Integer Unfolding_FunctionWithDerivative::GetStateNumber()
{
ComputeArea(myMasterPolyLine, mySlavePolyLine, myShiftDir, myShift, myTrsf, myArea);
return 0;
}
//=============================================================================
// function: Area
//=============================================================================
Standard_Real Unfolding_FunctionWithDerivative::Area() const
{
return myArea;
}
//-----------------------------------------------------------------------------
// function: ComputeAreaDeriv
//-----------------------------------------------------------------------------
static Standard_Boolean ComputeAreaDeriv(const TColgp_Array1OfXY& theMasterPolyLine,
const TColgp_Array1OfXY& theSlavePolyLine,
const gp_Dir2d& theShiftDir,
const Standard_Real& theShift,
const gp_Trsf2d theTrsf,
Standard_Real& theArea,
Standard_Real& theDeriv)
{
theArea = 0.;
theDeriv = 0.;
Standard_Real X = theShift;
Standard_Real F1 = 0., F2 = 0.;
if ( !ComputeArea(theMasterPolyLine, theSlavePolyLine, theShiftDir, X, theTrsf, F1) )
return Standard_False;
theArea = F1;
Standard_Real aDelta = 1.e-05;
if ( fabs(X) > aDelta )
aDelta = fabs(X) * aDelta;
if ( !ComputeArea(theMasterPolyLine, theSlavePolyLine, theShiftDir, X + aDelta, theTrsf, F2) )
return Standard_False;
theDeriv = F2 - F1;
theDeriv /= aDelta;
return Standard_True;
}
//-----------------------------------------------------------------------------
// function: ComputeArea
//-----------------------------------------------------------------------------
static Standard_Boolean ComputeArea(const TColgp_Array1OfXY& theMasterPolyLine,
const TColgp_Array1OfXY& theSlavePolyLine,
const gp_Dir2d& theShiftDir,
const Standard_Real& theShift,
const gp_Trsf2d theTrsf,
Standard_Real& theArea)
{
if ( ( theMasterPolyLine.Length() < 2 ) || ( theSlavePolyLine.Length() < 2 ) ||
( theSlavePolyLine.Length() != theMasterPolyLine.Length() ) )
return Standard_False;
theArea = 0.;
gp_Vec2d aTranslation( theShiftDir.XY() * theShift );
gp_Trsf2d aTransTrsf;
aTransTrsf.SetTranslation( aTranslation );
gp_Trsf2d aTrans;
aTrans = aTransTrsf * theTrsf;
//
TColgp_Array1OfXY aTransformedSlave(theSlavePolyLine.Lower(), theSlavePolyLine.Upper());
Standard_Integer i = 0;
for ( i = aTransformedSlave.Lower(); i <= aTransformedSlave.Upper(); i++ ) {
gp_Pnt2d aP( theSlavePolyLine.Value( i ) );
aP.Transform( aTrans );
aTransformedSlave.SetValue( i, aP.XY() );
}
//
// compute area
// This method assumes that the polylines shape is similar
// if the shape is completely different, the compute area will be wrong.
// But it will grow, that can be considered as a condition of distortion.
// So, the method can be acceptable.
gp_XY aFirstPoint = aTransformedSlave( aTransformedSlave.Lower() );
aFirstPoint += theMasterPolyLine( theMasterPolyLine.Lower() );
aFirstPoint *= 0.5;
gp_XY aLastPoint = aTransformedSlave( aTransformedSlave.Upper() );
aLastPoint += theMasterPolyLine( theMasterPolyLine.Upper() );
aLastPoint *= 0.5;
Standard_Integer nIndexDif = theMasterPolyLine.Lower() - aTransformedSlave.Lower();
gp_XY aP1 = aFirstPoint;
gp_XY aP3 = aFirstPoint;
for ( i = theMasterPolyLine.Lower() + 1; i <= theMasterPolyLine.Upper(); i++ ) {
gp_XY aP2 = theMasterPolyLine(i);
gp_XY aP4 = aTransformedSlave(i-nIndexDif);
if ( i == theMasterPolyLine.Upper() ) {
aP2 = aLastPoint;
aP4 = aLastPoint;
}
gp_XY aP1P4 = aP4 - aP1;
gp_XY aP1P2 = aP2 - aP1;
gp_XY aP1P3 = aP3 - aP1;
Standard_Real aprod1 = aP1P4 ^ aP1P3;
Standard_Real aprod2 = aP1P4 ^ aP1P2;
if ( aprod1 * aprod2 <= 0. ) {
theArea += 0.5 * ( fabs( aprod1 ) + fabs( aprod2 ) );
}
else {
gp_XY aP3P2 = aP2 - aP3;
gp_XY aP3P4 = aP4 - aP3;
gp_XY aP3P1 = -aP1P3;
Standard_Real asum = 0.5 * ( fabs( aprod1 ) + fabs( aprod2 ) );
aprod1 = aP3P2 ^ aP3P4;
aprod2 = aP3P2 ^ aP3P1;
if ( aprod1 * aprod2 <= 0. ) {
theArea += 0.5 * ( fabs( aprod1 ) + fabs( aprod2 ) );
}
else {
asum += 0.5 * ( fabs( aprod1 ) + fabs( aprod2 ) );
asum *= 0.5;
theArea += asum;
}
}
aP1 = aP2;
aP3 = aP4;
}
return Standard_True;
}

View File

@@ -0,0 +1,87 @@
// File: Unfolding_FunctionWithDerivative.cdl
// Created: Fri Sep 5 17:44:29 2008
// Author: Mikhail KLOKOV
// <mkk@kurox>
//-Copyright: Open CASCADE 2008
#ifndef _Unfolding_FunctionWithDerivative_HeaderFile
#define _Unfolding_FunctionWithDerivative_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <TColgp_Array1OfXY.hxx>
#include <gp_Trsf2d.hxx>
#include <gp_Dir2d.hxx>
#include <Standard_Real.hxx>
#include <math_FunctionWithDerivative.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Integer.hxx>
#include <TColgp_Array1OfXY.hxx>
class gp_Dir2d;
class gp_Trsf2d;
class Unfolding_FunctionWithDerivative : public math_FunctionWithDerivative
{
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT Unfolding_FunctionWithDerivative(const TColgp_Array1OfXY& theMaster, const TColgp_Array1OfXY& theSlave, const gp_Dir2d& theDir, const gp_Trsf2d& theTrsf);
//! Computes the value <F>of the function for the variable <X>.
//! Returns True if the calculation were successfully done,
//! False otherwise.
Standard_EXPORT virtual Standard_Boolean Value (const Standard_Real X, Standard_Real& F) Standard_OVERRIDE;
//! Computes the derivative <D> of the function
//! for the variable <X>.
//! Returns True if the calculation were successfully done,
//! False otherwise.
Standard_EXPORT virtual Standard_Boolean Derivative (const Standard_Real X, Standard_Real& D) Standard_OVERRIDE;
//! Computes the value <F> and the derivative <D> of the
//! function for the variable <X>.
//! Returns True if the calculation were successfully done,
//! False otherwise.
Standard_EXPORT virtual Standard_Boolean Values (const Standard_Real X, Standard_Real& F, Standard_Real& D) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Integer GetStateNumber() Standard_OVERRIDE;
Standard_EXPORT Standard_Real Area() const;
protected:
private:
TColgp_Array1OfXY myMasterPolyLine;
TColgp_Array1OfXY mySlavePolyLine;
gp_Trsf2d myTrsf;
gp_Dir2d myShiftDir;
Standard_Real myShift;
Standard_Real myArea;
};
#endif // _Unfolding_FunctionWithDerivative_HeaderFile

View File

@@ -0,0 +1,17 @@
// File: Unfolding.cdl
// Created: Tue Jul 22 12:48:05 2008
// Author: Sergey KHROMOV
// <skv@dimox>
//-Copyright: Open CASCADE 2008
#ifndef Unfolding_HArray2OfPoint_HeaderFile
#define Unfolding_HArray2OfPoint_HeaderFile
#include <Unfolding_Point.hxx>
#include <Unfolding_Array2OfPoint.hxx>
#include <NCollection_DefineHArray2.hxx>
DEFINE_HARRAY2(Unfolding_HArray2OfPoint, Unfolding_Array2OfPoint)
#endif

View File

@@ -0,0 +1,17 @@
// File: Unfolding.cdl
// Created: Tue Jul 22 12:48:05 2008
// Author: Sergey KHROMOV
// <skv@dimox>
//-Copyright: Open CASCADE 2008
#ifndef Unfolding_IndexedMapOfFaceDataContainer_HeaderFile
#define Unfolding_IndexedMapOfFaceDataContainer_HeaderFile
#include <Unfolding_FaceDataContainer.hxx>
#include <Unfolding_FaceDataMapHasher.hxx>
#include <NCollection_IndexedMap.hxx>
typedef NCollection_IndexedMap<Handle(Unfolding_FaceDataContainer),Unfolding_FaceDataMapHasher> Unfolding_IndexedMapOfFaceDataContainer;
#endif

Some files were not shown because too many files have changed in this diff Show More