6#include <TopoDS_Wire.hxx>
7#include <TopTools_HSequenceOfShape.hxx>
8#include <TColgp_HArray1OfPnt.hxx>
10#include <BRepBuilderAPI_MakeEdge.hxx>
11#include <BRepBuilderAPI_MakeWire.hxx>
12#include <BRepBuilderAPI_MakePolygon.hxx>
13#include <BRepOffsetAPI_ThruSections.hxx>
14#include <BRepBuilderAPI_MakeFace.hxx>
15#include <BRepPrimAPI_MakeHalfSpace.hxx>
16#include <BRepPrimAPI_MakeBox.hxx>
17#include <GeomAPI_Interpolate.hxx>
19#include <BRepAlgoAPI_Common.hxx>
20#include <BRepAlgoAPI_Fuse.hxx>
21#include <BRepAlgoAPI_Cut.hxx>
23#include <BRepBuilderAPI_Transform.hxx>
24#include <BRepBuilderAPI_Copy.hxx>
26#include <IGESControl_Controller.hxx>
27#include <IGESControl_Writer.hxx>
28#include <Interface_Static.hxx>
29#include <STEPControl_Writer.hxx>
30#include <STEPControl_StepModelType.hxx>
36, m_bSubtractYarns(false)
37, m_bExportDomain(true)
48 TGLOGINDENT(
"Saving Domain to IGES file: " << szFileName);
49 TopTools_HSequenceOfShape Shapes;
56 TGLOGINDENT(
"Saving Domain to STEP file: " << szFileName);
57 TopTools_HSequenceOfShape Shapes;
64 TGLOGINDENT(
"Saving Textile to IGES file: " << szFileName);
65 TopTools_HSequenceOfShape Shapes;
72 TGLOGINDENT(
"Saving Textile to STEP file: " << szFileName);
73 TopTools_HSequenceOfShape Shapes;
98 STEPControl_Writer aWriter;
100 IFSelect_ReturnStatus status;
101 for (Standard_Integer i=1; i<=Shapes.Length(); i++)
103 status = aWriter.Transfer(Shapes.Value(i), STEPControl_AsIs);
104 if (status != IFSelect_RetDone)
109 status = aWriter.Write(szFileName);
110 return (status == IFSelect_RetDone);
115 IGESControl_Controller::Init();
117 IGESControl_Writer ICW(Interface_Static::CVal(
"XSTEP.iges.unit"),
118 Interface_Static::IVal(
"XSTEP.iges.writebrep.mode"));
120 for (Standard_Integer i=1;i<=Shapes.Length();i++)
122 ICW.AddShape(Shapes.Value(i));
126 Standard_Boolean result = ICW.Write(szFileName);
127 return result?
true:
false;
134 TGLOGINDENT(
"Converting Textile to Open CASCADE format");
136 for (i=0; i<(int)Textile.
GetYarns().size(); ++i)
138 TopTools_HSequenceOfShape Yarns;
141 for (j=1; j<=Yarns.Length(); ++j)
143 Shapes.Append(Yarns.Value(j));
148 bool bConfineSuccess;
155 if ( bConfineSuccess )
158 TGERROR(
"Cannot subtract yarn from domain: errors confining yarns");
160 Shapes.Append(Domain);
169 bool bSuccess =
true;
171 for (i=1; i<=Yarns.Length(); ++i)
173 TGLOG(
"Confining yarn: " << i <<
"/" << Yarns.Length());
176 Yarns.SetValue(i, BRepAlgoAPI_Common(Yarns.Value(i), Domain));
180 TGERROR(
"Failed to confine yarn " << i <<
" to domain" );
191 for (i=1; i<=Yarns.Length(); ++i)
193 TGLOG(
"Cutting domain with yarn: " << i <<
"/" << Yarns.Length());
194 Domain = BRepAlgoAPI_Cut(Domain, Yarns.Value(i));
201 TopTools_HSequenceOfShape YarnShapes;
203 TGLOG(
"Converting Yarn to Open CASCADE format");
205 vector<CSlaveNode>::const_iterator itSlaveNode;
208 BRepOffsetAPI_ThruSections SectionsSolid(
true,
m_bFaceted);
209 for (itSlaveNode = SlaveNodes.begin(); itSlaveNode != SlaveNodes.end(); ++itSlaveNode)
211 SectionsSolid.AddWire(
ConvertSection(itSlaveNode->GetSectionPoints()));
213 TopoDS_Shape Shape = SectionsSolid.Shape();
215 YarnShapes.Append(Shape);
219 TGLOGINDENT(
"Repeating Yarn to fully encompass domain");
222 for (i = 0; i < (int)RepeatLimits.size(); ++i)
230 TGLOG(
"Fusing yarn sections");
231 Shapes.Append( YarnShapes.Value(1) );
233 for (
int i = 2; i <= YarnShapes.Length(); )
235 BRepAlgoAPI_Fuse Fused( Shapes.Value(1), YarnShapes.Value(i) );
236 if ( !Fused.ErrorStatus() )
238 Shapes.SetValue( 1, Fused.Shape() );
239 YarnShapes.Remove(i);
255 BRepBuilderAPI_MakePolygon PolygonalWire;
256 vector<XYZ>::const_iterator itSectionPoint;
257 for (itSectionPoint = SectionPoints.begin(); itSectionPoint != SectionPoints.end(); ++itSectionPoint)
259 gp_Pnt Point(itSectionPoint->x, itSectionPoint->y, itSectionPoint->z);
260 PolygonalWire.Add(Point);
262 PolygonalWire.Close();
263 return PolygonalWire.Wire();
267 vector<int> Discontinuities;
268 const double dMaxAngle = 90*(
PI/180.0);
270 int i, j, iPrev, iNext;
275 for (i=0; i<(int)SectionPoints.size(); ++i)
277 iNext = (i+1)%SectionPoints.size();
279 iPrev = SectionPoints.size()-1;
281 iPrev = (i-1)%SectionPoints.size();
282 V1 = SectionPoints[iNext] - SectionPoints[i];
283 V2 = SectionPoints[i] - SectionPoints[iPrev];
290 if (dAngle > dMaxAngle)
292 Discontinuities.push_back(i);
296 if (Discontinuities.empty())
298 Handle(TColgp_HArray1OfPnt) pPoints =
new TColgp_HArray1OfPnt(1, SectionPoints.size()+1);
299 for (i=0; i<(int)SectionPoints.size(); ++i)
301 pPoints->SetValue(i+1, gp_Pnt(SectionPoints[i].x, SectionPoints[i].y, SectionPoints[i].z));
303 pPoints->SetValue(i+1, gp_Pnt(SectionPoints[0].x, SectionPoints[0].y, SectionPoints[0].z));
304 GeomAPI_Interpolate Interpolation(pPoints, Standard_False, 0.001);
307 gp_Vec Tangent = gp_Vec(TanV.
x, TanV.
y, TanV.
z);
308 Interpolation.Load(Tangent,Tangent, Standard_False);
310 Interpolation.Perform();
311 BRepBuilderAPI_MakeEdge Edge(Interpolation.Curve());
312 BRepBuilderAPI_MakeWire Wire(Edge.Edge());
318 int iStart, iEnd, iRange;
319 TopoDS_Wire CrossSectionWire;
320 for (j=0; j<(int)Discontinuities.size(); ++j)
323 iStart = Discontinuities[j];
324 iEnd = Discontinuities[(j+1)%Discontinuities.size()];
326 iEnd += SectionPoints.size();
327 iRange = iEnd - iStart + 1;
329 Handle(TColgp_HArray1OfPnt) pPoints =
new TColgp_HArray1OfPnt(1, iRange);
330 for (i=iStart; i<=iEnd; ++i)
332 XYZ Pt = SectionPoints[i%SectionPoints.size()];
333 pPoints->SetValue(i-iStart+1, gp_Pnt(Pt.
x, Pt.
y, Pt.
z));
335 GeomAPI_Interpolate Interpolation(pPoints, Standard_False, 0.001);
336 Interpolation.Perform();
337 BRepBuilderAPI_MakeEdge Edge(Interpolation.Curve());
341 BRepBuilderAPI_MakeWire Wire(Edge.Edge());
342 CrossSectionWire = Wire.Wire();
346 BRepBuilderAPI_MakeWire Wire(CrossSectionWire, Edge.Edge());
347 CrossSectionWire = Wire.Wire();
350 return CrossSectionWire;
360 TopTools_HSequenceOfShape NewShapes;
361 for (i=iLowerLimit; i<=iUpperLimit; ++i)
363 Translation = i*Vector;
364 Transform.SetTranslation(gp_Vec(Translation.
x, Translation.
y, Translation.
z));
365 for (j=1; j<=Shapes.Length(); ++j)
367 BRepBuilderAPI_Transform Translated(Shapes.Value(j), Transform, Standard_True);
368 NewShapes.Append(Translated.Shape());
376 TGLOGINDENT(
"Converting Domain to Open CASCADE format");
377 if (Domain.
GetType() ==
"CDomainPlanes")
392 TopoDS_Shape DomainShape = BRepPrimAPI_MakeBox(gp_Pnt(
Min.
x,
Min.
y,
Min.
z), gp_Pnt(
Max.x,
Max.y,
Max.z));
393 vector<PLANE>::const_iterator itPlane;
394 for (itPlane = DomainPlanes.
GetPlanes().begin(); itPlane != DomainPlanes.
GetPlanes().end(); ++itPlane)
396 gp_Pln Plane(itPlane->Normal.x, itPlane->Normal.y, itPlane->Normal.z, -itPlane->d);
397 BRepBuilderAPI_MakeFace Face(Plane);
398 XYZ RefPoint = (itPlane->d+1)*itPlane->Normal;
399 BRepPrimAPI_MakeHalfSpace HalfSpace(Face.Face(), gp_Pnt(RefPoint.
x, RefPoint.
y, RefPoint.
z));
400 DomainShape = BRepAlgoAPI_Common(HalfSpace.Solid(), DomainShape);
404 return TopoDS_Shape();
#define TGLOGINDENT(MESSAGE)
Combines the TGLOG macro and TGLOGAUTOINDENT macro in one.
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Abstract base class representing the domain in which a textile cell may lie.
virtual string GetType() const =0
Derived class should return the class name.
const CMesh & GetMesh() const
Get the mesh representing the domain as a surface mesh.
vector< pair< int, int > > GetRepeatLimits(const CYarn &Yarn) const
Domain implementation described using planes, the simplest of which would be a box.
const vector< PLANE > & GetPlanes() const
Accessor method to get the planes making up this domain.
bool GetBoxLimits(XYZ &Min, XYZ &Max)
If the limits describe a box return the minimum and maximum otherwise return false.
bool OutputTextileToIGES(char szFileName[], CTextile &Textile)
Output the textile to IGES file format.
bool SaveToIGES(char szFileName[], TopTools_HSequenceOfShape &Shapes)
Save sequence of shapes to IGES file.
void ConvertYarn(TopTools_HSequenceOfShape &Shapes, CYarn &Yarn, const CDomain *pDomain=NULL)
Convert yarn to a sequence of OpenCascade TopoDS_Shape.
void ConvertTextile(TopTools_HSequenceOfShape &Shapes, CTextile &Textile)
Convert textile to a sequence of OpenCascade TopoDS_Shape.
static void CopyShapesToRange(TopTools_HSequenceOfShape &Shapes, XYZ Vector, int iLowerLimit, int iUpperLimit)
Copy the shapes to given range with given repeat vector.
bool OutputDomainToIGES(char szFileName[], CDomain &Domain)
Output the domain to IGES file format.
TopoDS_Shape ConvertDomain(const CDomain &Domain)
Convert domain to a OpenCascade TopoDS_Shape.
bool OutputDomainToSTEP(char szFileName[], CDomain &Domain)
Output the domain to STEP file format.
TopoDS_Wire ConvertSection(const vector< XYZ > &SectionPoints)
Convert a yarn section to a OpenCascade wire.
bool ConfineYarnsToDomain(TopTools_HSequenceOfShape &Yarns, const TopoDS_Shape &Domain)
Trim the yarns such they fit within the domain.
bool SaveToSTEP(char szFileName[], TopTools_HSequenceOfShape &Shapes)
Save sequence of shapes to STEP file.
void SubtractYarnsFromDomain(TopoDS_Shape &Domain, const TopTools_HSequenceOfShape &Yarns)
Subtract yarns from the domain (NOTE: THIS IS UNSTABLE AND VERY SLOW)
bool OutputTextileToSTEP(char szFileName[], CTextile &Textile)
Output the textile to STEP file format.
pair< XYZ, XYZ > GetAABB(double dGrowDistance=0) const
Get an axis aligned bounding box for the mesh.
static CTexGen & GetInstance()
CTextile * GetTextile(string TextileName="")
Get a textile with given name.
Represents a textile cell containing yarns.
const CDomain * GetDomain() const
const vector< CYarn > & GetYarns() const
Represents a yarn consisting of master nodes, section and interpolation function.
const vector< CSlaveNode > & GetSlaveNodes(BUILD_TYPE Usage) const
Get the slave nodes and build them if necessary.
const vector< XYZ > & GetRepeats() const
Namespace containing a series of customised math operations not found in the standard c++ library.
double Max(XYZ &Vector)
Get maximum element of vector and return it.
XYZ Min(const XYZ &P1, const XYZ &P2)
Given two points, return a new point who's coordinates are the smaller of the two.
WXYZ & Normalise(WXYZ &Quaternion)
Normalise the quaternion and return it.
double DotProduct(const XYZ &left, const XYZ &right)
Get the dot product of two vectors.
Struct for representing points in 3D space.