1 // Created on: 2004-05-11
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BinTools.hxx>
18 #include <BinTools_Curve2dSet.hxx>
19 #include <BinTools_CurveSet.hxx>
20 #include <BinTools_LocationSet.hxx>
21 #include <BinTools_ShapeSet.hxx>
22 #include <BinTools_SurfaceSet.hxx>
23 #include <BRep_CurveOnClosedSurface.hxx>
24 #include <BRep_CurveOnSurface.hxx>
25 #include <BRep_CurveRepresentation.hxx>
26 #include <BRep_GCurve.hxx>
27 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
28 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
29 #include <BRep_PointOnCurve.hxx>
30 #include <BRep_PointOnCurveOnSurface.hxx>
31 #include <BRep_PointOnSurface.hxx>
32 #include <BRep_PointRepresentation.hxx>
33 #include <BRep_Polygon3D.hxx>
34 #include <BRep_PolygonOnTriangulation.hxx>
35 #include <BRep_TEdge.hxx>
36 #include <BRep_TFace.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRep_TVertex.hxx>
39 #include <BRepTools.hxx>
40 #include <gp_Trsf.hxx>
41 #include <Poly_Polygon2D.hxx>
42 #include <Poly_Polygon3D.hxx>
43 #include <Poly_PolygonOnTriangulation.hxx>
44 #include <Poly_Triangulation.hxx>
45 #include <Precision.hxx>
46 #include <Standard_ErrorHandler.hxx>
47 #include <TColgp_Array1OfPnt2d.hxx>
48 #include <TColStd_HArray1OfInteger.hxx>
49 #include <TColStd_HArray1OfReal.hxx>
51 #include <TopoDS_Iterator.hxx>
52 #include <TopoDS_Shape.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <Message_ProgressRange.hxx>
58 Standard_CString BinTools_ShapeSet::Version_1 = "Open CASCADE Topology V1 (c)";
59 Standard_CString BinTools_ShapeSet::Version_2 = "Open CASCADE Topology V2 (c)";
60 Standard_CString BinTools_ShapeSet::Version_3 = "Open CASCADE Topology V3 (c)";
62 //=======================================================================
63 //function : operator << (gp_Pnt)
65 //=======================================================================
67 static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Pnt P)
69 BinTools::PutReal(OS, P.X());
70 BinTools::PutReal(OS, P.Y());
71 BinTools::PutReal(OS, P.Z());
74 //=======================================================================
75 //function : BinTools_ShapeSet
77 //=======================================================================
78 BinTools_ShapeSet::BinTools_ShapeSet (const Standard_Boolean theWithTriangles)
79 : myFormatNb (BinTools_FormatVersion_CURRENT),
80 myWithTriangles (theWithTriangles)
83 //=======================================================================
84 //function : ~BinTools_ShapeSet
86 //=======================================================================
88 BinTools_ShapeSet::~BinTools_ShapeSet()
91 //=======================================================================
92 //function : SetFormatNb
94 //=======================================================================
95 void BinTools_ShapeSet::SetFormatNb(const Standard_Integer theFormatNb)
97 Standard_ASSERT_RETURN(theFormatNb == BinTools_FormatVersion_VERSION_1 ||
98 theFormatNb == BinTools_FormatVersion_VERSION_2 ||
99 theFormatNb == BinTools_FormatVersion_VERSION_3,
100 "Error: unsupported BinTools version.", );
102 myFormatNb = theFormatNb;
105 //=======================================================================
106 //function : FormatNb
108 //=======================================================================
109 Standard_Integer BinTools_ShapeSet::FormatNb() const
114 //=======================================================================
117 //=======================================================================
119 void BinTools_ShapeSet::Clear()
124 myPolygons3D.Clear();
125 myPolygons2D.Clear();
127 myTriangulations.Clear();
131 //=======================================================================
134 //=======================================================================
136 Standard_Integer BinTools_ShapeSet::Add(const TopoDS_Shape& theShape)
138 if (theShape.IsNull()) return 0;
139 myLocations.Add(theShape.Location());
140 TopoDS_Shape aS2 = theShape;
141 aS2.Location(TopLoc_Location());
142 Standard_Integer anIndex = myShapes.FindIndex(aS2);
145 for (TopoDS_Iterator its(aS2,Standard_False,Standard_False);its.More(); its.Next())
147 anIndex = myShapes.Add(aS2);
153 //=======================================================================
156 //=======================================================================
158 const TopoDS_Shape& BinTools_ShapeSet::Shape(const Standard_Integer theIndx)const
160 return myShapes(theIndx);
163 //=======================================================================
166 //=======================================================================
168 Standard_Integer BinTools_ShapeSet::Index(const TopoDS_Shape& theShape) const
170 return myShapes.FindIndex(theShape);
173 //=======================================================================
174 //function : Locations
176 //=======================================================================
178 const BinTools_LocationSet& BinTools_ShapeSet::Locations()const
184 //=======================================================================
185 //function : ChangeLocations
187 //=======================================================================
189 BinTools_LocationSet& BinTools_ShapeSet::ChangeLocations()
194 //=======================================================================
195 //function : AddGeometry
197 //=======================================================================
199 void BinTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
203 if (S.ShapeType() == TopAbs_VERTEX) {
205 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
206 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
208 while (itrp.More()) {
209 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
211 if (PR->IsPointOnCurve()) {
212 myCurves.Add(PR->Curve());
215 else if (PR->IsPointOnCurveOnSurface()) {
216 myCurves2d.Add(PR->PCurve());
217 mySurfaces.Add(PR->Surface());
220 else if (PR->IsPointOnSurface()) {
221 mySurfaces.Add(PR->Surface());
224 ChangeLocations().Add(PR->Location());
229 else if (S.ShapeType() == TopAbs_EDGE) {
231 // Add the curve geometry
232 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
233 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
235 while (itrc.More()) {
236 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
237 if (CR->IsCurve3D()) {
238 if (!CR->Curve3D().IsNull()) {
239 myCurves.Add(CR->Curve3D());
240 ChangeLocations().Add(CR->Location());
243 else if (CR->IsCurveOnSurface()) {
244 mySurfaces.Add(CR->Surface());
245 myCurves2d.Add(CR->PCurve());
246 ChangeLocations().Add(CR->Location());
247 if (CR->IsCurveOnClosedSurface())
248 myCurves2d.Add(CR->PCurve2());
250 else if (CR->IsRegularity()) {
251 mySurfaces.Add(CR->Surface());
252 ChangeLocations().Add(CR->Location());
253 mySurfaces.Add(CR->Surface2());
254 ChangeLocations().Add(CR->Location2());
256 else if (myWithTriangles) {
257 if (CR->IsPolygon3D()) {
258 if (!CR->Polygon3D().IsNull()) {
259 myPolygons3D.Add(CR->Polygon3D());
260 ChangeLocations().Add(CR->Location());
263 else if (CR->IsPolygonOnTriangulation()) {
264 myTriangulations.Add(CR->Triangulation());
265 myNodes.Add(CR->PolygonOnTriangulation());
266 ChangeLocations().Add(CR->Location());
267 if (CR->IsPolygonOnClosedTriangulation())
268 myNodes.Add(CR->PolygonOnTriangulation2());
270 else if (CR->IsPolygonOnSurface()) {
271 mySurfaces.Add(CR->Surface());
272 myPolygons2D.Add(CR->Polygon());
273 ChangeLocations().Add(CR->Location());
274 if (CR->IsPolygonOnClosedSurface())
275 myPolygons2D.Add(CR->Polygon2());
282 else if (S.ShapeType() == TopAbs_FACE) {
284 // Add the surface geometry
285 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
286 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
289 || TF->Surface().IsNull())
291 Handle(Poly_Triangulation) Tr = TF->Triangulation();
292 if (!Tr.IsNull()) myTriangulations.Add(Tr);
295 ChangeLocations().Add(TF->Location());
299 //=======================================================================
300 //function : WriteGeometry
302 //=======================================================================
304 void BinTools_ShapeSet::WriteGeometry (Standard_OStream& OS,
305 const Message_ProgressRange& theRange)const
307 Message_ProgressScope aPS(theRange, "Writing geometry", 6);
308 myCurves2d.Write(OS, aPS.Next());
311 myCurves.Write(OS, aPS.Next());
314 WritePolygon3D(OS, aPS.Next());
317 WritePolygonOnTriangulation(OS, aPS.Next());
320 mySurfaces.Write(OS, aPS.Next());
323 WriteTriangulation(OS, aPS.Next());
326 //=======================================================================
329 //=======================================================================
331 void BinTools_ShapeSet::Write (Standard_OStream& OS,
332 const Message_ProgressRange& theRange)const
334 // write the copyright
335 if (myFormatNb == BinTools_FormatVersion_VERSION_3)
337 OS << "\n" << Version_3 << "\n";
339 else if (myFormatNb == BinTools_FormatVersion_VERSION_2)
341 OS << "\n" << Version_2 << "\n";
345 OS << "\n" << Version_1 << "\n";
348 //-----------------------------------------
349 // write the locations
350 //-----------------------------------------
352 myLocations.Write(OS);
354 //-----------------------------------------
355 // write the geometry
356 //-----------------------------------------
358 Message_ProgressScope aPS(theRange, "Writing geometry", 2);
360 WriteGeometry(OS, aPS.Next());
364 //-----------------------------------------
366 //-----------------------------------------
368 Standard_Integer i, nbShapes = myShapes.Extent();
369 Message_ProgressScope aPSinner(aPS.Next(), "Writing shapes", nbShapes);
370 OS << "\nTShapes " << nbShapes << "\n";
372 // subshapes are written first
373 for (i = 1; i <= nbShapes && aPSinner.More(); i++, aPSinner.Next()) {
375 const TopoDS_Shape& S = myShapes(i);
378 OS << (Standard_Byte)S.ShapeType();
384 BinTools::PutBool(OS, S.Free()? 1:0);
385 BinTools::PutBool(OS, S.Modified()? 1:0);
386 BinTools::PutBool(OS, S.Checked()? 1:0);
387 BinTools::PutBool(OS, S.Orientable()? 1:0);
388 BinTools::PutBool(OS, S.Closed()? 1:0);
389 BinTools::PutBool(OS, S.Infinite()? 1:0);
390 BinTools::PutBool(OS, S.Convex()? 1:0);
394 TopoDS_Iterator its(S,Standard_False,Standard_False);
396 Write(its.Value(),OS);
399 Write(TopoDS_Shape(),OS); // Null shape to end the list
403 //=======================================================================
406 //=======================================================================
408 void BinTools_ShapeSet::Read (Standard_IStream& IS,
409 const Message_ProgressRange& theRange)
417 IS.getline(vers,100,'\n');
418 // BUC60769 PTV 18.10.2000: remove possible '\r' at the end of the line
420 Standard_Size lv = strlen(vers);
422 for (lv--; lv > 0 && (vers[lv] == '\r' || vers[lv] == '\n'); lv--)
426 } while ( ! IS.fail() && strcmp(vers,Version_1) && strcmp(vers,Version_2) &&
427 strcmp(vers,Version_3));
429 std::cout << "BinTools_ShapeSet::Read: File was not written with this version of the topology" << std::endl;
433 if (strcmp (vers, Version_3) == 0)
435 SetFormatNb (BinTools_FormatVersion_VERSION_3);
437 else if (strcmp (vers, Version_2) == 0)
439 SetFormatNb (BinTools_FormatVersion_VERSION_2);
443 SetFormatNb (BinTools_FormatVersion_VERSION_1);
446 //-----------------------------------------
447 // read the locations
448 //-----------------------------------------
450 myLocations.Read(IS);
451 //-----------------------------------------
453 //-----------------------------------------
454 Message_ProgressScope aPSouter(theRange, "Reading", 2);
455 ReadGeometry(IS, aPSouter.Next());
456 if (!aPSouter.More())
458 //-----------------------------------------
460 //-----------------------------------------
464 if (IS.fail() || strcmp(buffer,"TShapes")) {
465 Standard_SStream aMsg;
466 aMsg << "BinTools_ShapeSet::Read: Not a TShape table"<<std::endl;
467 throw Standard_Failure(aMsg.str().c_str());
470 Standard_Integer nbShapes = 0;
473 Message_ProgressScope aPSinner(aPSouter.Next(), "Reading Shapes", nbShapes);
474 for (int i = 1; i <= nbShapes && aPSinner.More(); i++, aPSinner.Next()) {
478 //Read type and create empty shape.
480 TopAbs_ShapeEnum T = (TopAbs_ShapeEnum) IS.get();
482 ReadGeometry(T,IS,S);
485 Standard_Boolean aFree, aMod, aChecked, anOrient, aClosed, anInf, aConv;
486 BinTools::GetBool(IS, aFree);
487 BinTools::GetBool(IS, aMod);
488 BinTools::GetBool(IS, aChecked);
489 BinTools::GetBool(IS, anOrient);
490 BinTools::GetBool(IS, aClosed);
491 BinTools::GetBool(IS, anInf);
492 BinTools::GetBool(IS, aConv);
497 Read(SS,IS,nbShapes);
500 } while(!SS.IsNull());
504 if (myFormatNb != BinTools_FormatVersion_VERSION_2
505 && myFormatNb != BinTools_FormatVersion_VERSION_3)
507 aChecked = false; // force check at reading
509 S.Checked (aChecked);
510 S.Orientable(anOrient);
516 if (myFormatNb == BinTools_FormatVersion_VERSION_1)
517 if(T == TopAbs_FACE) {
518 const TopoDS_Face& F = TopoDS::Face(S);
519 BRepTools::Update(F);
525 //=======================================================================
528 //=======================================================================
530 void BinTools_ShapeSet::Write (const TopoDS_Shape& S,
531 Standard_OStream& OS)const
537 // {TopAbs_FORWARD, TopAbs_REVERSED, TopAbs_INTERNAL, TopAbs_EXTERNAL}
538 OS << (Standard_Byte) S.Orientation();
539 BinTools::PutInteger(OS, myShapes.Extent() - myShapes.FindIndex(S.Located(TopLoc_Location())) + 1);
540 BinTools::PutInteger(OS, Locations().Index(S.Location()));
544 //=======================================================================
547 //=======================================================================
549 void BinTools_ShapeSet::Read (TopoDS_Shape& S, Standard_IStream& IS,
550 const Standard_Integer nbshapes)const
552 Standard_Character aChar = '\0';
557 TopAbs_Orientation anOrient;
558 anOrient = (TopAbs_Orientation)aChar;
559 Standard_Integer anIndx;
560 BinTools::GetInteger(IS, anIndx);
561 S = myShapes(nbshapes - anIndx + 1);
562 S.Orientation(anOrient);
565 BinTools::GetInteger(IS, l);
566 S.Location(myLocations.Location(l));
570 //=======================================================================
571 //function : ReadGeometry
573 //=======================================================================
575 void BinTools_ShapeSet::ReadGeometry (Standard_IStream& IS,
576 const Message_ProgressRange& theRange)
578 Message_ProgressScope aPS(theRange, "Reading geomentry", 6);
579 myCurves2d.Read(IS, aPS.Next());
582 myCurves.Read(IS, aPS.Next());
585 ReadPolygon3D(IS, aPS.Next());
588 ReadPolygonOnTriangulation(IS, aPS.Next());
591 mySurfaces.Read(IS, aPS.Next());
594 ReadTriangulation(IS, aPS.Next());
597 //=======================================================================
598 //function : WriteGeometry
600 //=======================================================================
602 void BinTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S,
603 Standard_OStream& OS)const
605 // Write the geometry
608 if (S.ShapeType() == TopAbs_VERTEX) {
610 // Write the point geometry
611 TopoDS_Vertex V = TopoDS::Vertex(S);
612 BinTools::PutReal(OS, BRep_Tool::Tolerance(V));
613 gp_Pnt p = BRep_Tool::Pnt(V);
615 #ifdef OCCT_DEBUG_POS
618 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
619 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
620 while (itrp.More()) {
621 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
622 // BinTools::PutReal(OS, PR->Parameter());
623 if (PR->IsPointOnCurve()) {
624 #ifdef OCCT_DEBUG_POS
627 OS << (Standard_Byte)1; // 1
628 BinTools::PutReal(OS, PR->Parameter());
629 BinTools::PutInteger(OS, myCurves.Index(PR->Curve()));
632 else if (PR->IsPointOnCurveOnSurface()) {
633 #ifdef OCCT_DEBUG_POS
636 OS << (Standard_Byte)2;// 2
637 BinTools::PutReal(OS, PR->Parameter());
638 BinTools::PutInteger(OS, myCurves2d.Index(PR->PCurve()));
639 BinTools::PutInteger(OS, mySurfaces.Index(PR->Surface()));
642 else if (PR->IsPointOnSurface()) {
643 #ifdef OCCT_DEBUG_POS
646 OS << (Standard_Byte)3;// 3
647 BinTools::PutReal(OS, PR->Parameter2());
648 BinTools::PutReal(OS, PR->Parameter());
649 BinTools::PutInteger(OS, mySurfaces.Index(PR->Surface()));
651 BinTools::PutInteger(OS, Locations().Index(PR->Location()));
655 // OS << "0 0\n"; // end representations
656 OS.put((Standard_Byte)0);
659 else if (S.ShapeType() == TopAbs_EDGE) {
661 // Write the curve geometry
663 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
665 BinTools::PutReal(OS, TE->Tolerance());
667 Standard_Boolean aVal = (TE->SameParameter()) ? Standard_True : Standard_False;
668 BinTools::PutBool(OS, aVal);
669 aVal = (TE->SameRange()) ? Standard_True : Standard_False;
670 BinTools::PutBool(OS, aVal);
671 aVal = (TE->Degenerated()) ? Standard_True : Standard_False;
672 BinTools::PutBool(OS, aVal);
674 Standard_Real first, last;
675 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
676 while (itrc.More()) {
677 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
678 if (CR->IsCurve3D()) {
679 if (!CR->Curve3D().IsNull()) {
680 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
681 GC->Range(first, last);
682 OS << (Standard_Byte)1;//CURVE_3D;
683 BinTools::PutInteger(OS, myCurves.Index(CR->Curve3D()));
684 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
685 BinTools::PutReal(OS, first);
686 BinTools::PutReal(OS, last);
689 else if (CR->IsCurveOnSurface()) {
690 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
691 GC->Range(first, last);
692 if (!CR->IsCurveOnClosedSurface())
694 OS << (Standard_Byte)2;
696 // -3- Curve on closed surf
697 OS << (Standard_Byte)3;
698 BinTools::PutInteger(OS, myCurves2d.Index(CR->PCurve()));
699 if (CR->IsCurveOnClosedSurface()) {//+ int|char
700 BinTools::PutInteger(OS, myCurves2d.Index(CR->PCurve2()));
701 OS << (Standard_Byte)CR->Continuity();
703 BinTools::PutInteger(OS, mySurfaces.Index(CR->Surface()));
704 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
705 BinTools::PutReal(OS, first);
706 BinTools::PutReal(OS, last);
708 // Write UV Points for higher performance
709 if (myFormatNb == BinTools_FormatVersion_VERSION_2
710 || myFormatNb == BinTools_FormatVersion_VERSION_3)
713 if (CR->IsCurveOnClosedSurface()) {
714 Handle(BRep_CurveOnClosedSurface) COCS = Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
715 COCS->UVPoints2(Pf,Pl);
718 Handle(BRep_CurveOnSurface) COS = Handle(BRep_CurveOnSurface)::DownCast(CR);
719 COS->UVPoints(Pf,Pl);
721 BinTools::PutReal(OS, Pf.X());
722 BinTools::PutReal(OS, Pf.Y());
723 BinTools::PutReal(OS, Pl.X());
724 BinTools::PutReal(OS, Pl.Y());
727 else if (CR->IsRegularity()) {
729 OS << (Standard_Byte)4;
730 OS << (Standard_Byte)CR->Continuity();
731 BinTools::PutInteger(OS, mySurfaces.Index(CR->Surface()));
732 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
733 BinTools::PutInteger(OS, mySurfaces.Index(CR->Surface2()));
734 BinTools::PutInteger(OS, Locations().Index(CR->Location2()));
738 else if (myWithTriangles) {
739 if (CR->IsPolygon3D()) {
740 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
741 if (!GC->Polygon3D().IsNull()) {
743 OS << (Standard_Byte)5;
744 BinTools::PutInteger(OS, myPolygons3D.FindIndex(CR->Polygon3D()));
745 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
748 else if (CR->IsPolygonOnTriangulation()) {
749 Handle(BRep_PolygonOnTriangulation) PT =
750 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
751 if (!CR->IsPolygonOnClosedTriangulation())
752 // -6- Polygon on triangulation
753 OS << (Standard_Byte)6;
755 // -7- Polygon on closed triangulation
756 OS << (Standard_Byte)7;
757 BinTools::PutInteger(OS, myNodes.FindIndex(PT->PolygonOnTriangulation()));
759 if (CR->IsPolygonOnClosedTriangulation()) {
760 BinTools::PutInteger(OS, myNodes.FindIndex(PT->PolygonOnTriangulation2()));
762 BinTools::PutInteger(OS, myTriangulations.FindIndex(PT->Triangulation()));
763 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
769 // OS << "0\n"; // end of the list of representations
771 OS << (Standard_Byte)0;
774 else if (S.ShapeType() == TopAbs_FACE) {
776 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
777 const TopoDS_Face& F = TopoDS::Face(S);
779 // Write the surface geometry
780 Standard_Boolean aNatRes = BRep_Tool::NaturalRestriction(F);
781 BinTools::PutBool (OS, aNatRes);
782 BinTools::PutReal (OS, TF->Tolerance());
783 BinTools::PutInteger (OS, !TF->Surface().IsNull()
784 ? mySurfaces.Index (TF->Surface())
786 BinTools::PutInteger (OS, Locations().Index (TF->Location()));
789 || TF->Surface().IsNull())
791 if (!(TF->Triangulation()).IsNull()) {
792 OS << (Standard_Byte) 2;
793 // Write the triangulation
794 BinTools::PutInteger(OS, myTriangulations.FindIndex(TF->Triangulation()));
796 OS << (Standard_Byte) 1;
798 OS << (Standard_Byte) 0;//without triangulation
801 catch(Standard_Failure const& anException) {
802 Standard_SStream aMsg;
803 aMsg << "EXCEPTION in BinTools_ShapeSet::WriteGeometry(S,OS)" << std::endl;
804 aMsg << anException << std::endl;
805 throw Standard_Failure(aMsg.str().c_str());
809 //=======================================================================
810 //function : ReadGeometry
812 //=======================================================================
814 void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
815 Standard_IStream& IS,
820 Standard_Integer val, c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
821 Standard_Real tol,X,Y,Z,first,last,p1 = 0.,p2;
822 Standard_Real PfX,PfY,PlX,PlY;
824 Standard_Boolean closed, bval;
825 GeomAbs_Shape reg = GeomAbs_C0;
837 // Standard_Integer aPos = IS.tellg();
838 // std::cout << "\nPOS = " << aPos << std::endl;
839 TopoDS_Vertex& V = TopoDS::Vertex(S);
841 // Read the point geometry
842 BinTools::GetReal(IS, tol);
843 BinTools::GetReal(IS, X);
844 BinTools::GetReal(IS, Y);
845 BinTools::GetReal(IS, Z);
846 gp_Pnt aPnt (X, Y, Z);
847 myBuilder.MakeVertex (V, aPnt, tol);
848 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
850 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
853 if(myFormatNb == BinTools_FormatVersion_VERSION_3) {
854 val = (Standard_Integer)IS.get();//case {0|1|2|3}
855 if (val > 0 && val <= 3)
856 BinTools::GetReal(IS, p1);
858 std::streampos aPos = IS.tellg();
859 BinTools::GetReal(IS, p1);
860 val = (Standard_Integer)IS.get();//case {0|1|2|3}
862 std::cout << "\nVal = " << val <<std::endl;
864 if(val != 1 && val !=2 && val !=3){
866 val = (Standard_Integer)IS.get();
867 if (val > 0 && val <= 3)
868 BinTools::GetReal(IS, p1);
871 Handle(BRep_PointRepresentation) PR;
878 BinTools::GetInteger(IS, c);
879 if (myCurves.Curve(c).IsNull())
881 Handle(BRep_PointOnCurve) POC =
882 new BRep_PointOnCurve(p1,
891 BinTools::GetInteger(IS, pc);
892 BinTools::GetInteger(IS, s);
893 if (myCurves2d.Curve2d(pc).IsNull() ||
894 mySurfaces.Surface(s).IsNull())
897 Handle(BRep_PointOnCurveOnSurface) POC =
898 new BRep_PointOnCurveOnSurface(p1,
899 myCurves2d.Curve2d(pc),
900 mySurfaces.Surface(s),
908 BinTools::GetReal(IS, p2);
909 BinTools::GetInteger(IS, s);
910 if (mySurfaces.Surface(s).IsNull())
913 Handle(BRep_PointOnSurface) POC =
914 new BRep_PointOnSurface(p1,p2,
915 mySurfaces.Surface(s),
923 Standard_SStream aMsg;
924 aMsg << "BinTools_SurfaceSet::ReadGeometry: UnExpected BRep_PointRepresentation = "<< val <<std::endl;
925 throw Standard_Failure(aMsg.str().c_str());
930 BinTools::GetInteger(IS, l);//Locations index
933 PR->Location(Locations().Location(l));
951 TopoDS_Edge& E = TopoDS::Edge(S);
953 myBuilder.MakeEdge(E);
955 // Read the curve geometry
956 BinTools::GetReal(IS, tol);
957 BinTools::GetBool(IS, bval);
958 myBuilder.SameParameter(E, bval);
960 BinTools::GetBool(IS, bval);
961 myBuilder.SameRange(E,bval);
963 BinTools::GetBool(IS, bval);
964 myBuilder.Degenerated(E,bval);
967 val = (Standard_Integer)IS.get();//{0|1|2|3|4|5|6|7}
968 // -0- no representation
971 // -3- Curve on closed surf
974 // -6- Polygon on triangulation
975 // -7- Polygon on closed triangulation
981 case 1 : // -1- Curve 3D
982 BinTools::GetInteger(IS, c);
983 BinTools::GetInteger(IS, l);
984 if (!myCurves.Curve(c).IsNull()) {
985 myBuilder.UpdateEdge(E,myCurves.Curve(c),
986 Locations().Location(l),tol);
988 BinTools::GetReal(IS, first);
989 BinTools::GetReal(IS, last);
990 if (!myCurves.Curve(c).IsNull()) {
991 Standard_Boolean Only3d = Standard_True;
992 myBuilder.Range(E,first,last,Only3d);
997 case 2 : // -2- Curve on surf
998 case 3 : // -3- Curve on closed surf
1000 BinTools::GetInteger(IS, pc);
1002 BinTools::GetInteger(IS, pc2);
1003 reg = (GeomAbs_Shape)IS.get();
1006 // surface, location
1007 BinTools::GetInteger(IS, s);
1008 BinTools::GetInteger(IS, l);
1011 BinTools::GetReal(IS, first);
1012 BinTools::GetReal(IS, last);
1014 // read UV Points // for XML Persistence higher performance
1015 if (myFormatNb == BinTools_FormatVersion_VERSION_2
1016 || myFormatNb == BinTools_FormatVersion_VERSION_3)
1018 BinTools::GetReal(IS, PfX);
1019 BinTools::GetReal(IS, PfY);
1020 BinTools::GetReal(IS, PlX);
1021 BinTools::GetReal(IS, PlY);
1022 aPf = gp_Pnt2d(PfX,PfY);
1023 aPl = gp_Pnt2d(PlX,PlY);
1026 if (myCurves2d.Curve2d(pc).IsNull() ||
1027 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
1028 mySurfaces.Surface(s).IsNull())
1032 if (myFormatNb == BinTools_FormatVersion_VERSION_2
1033 || myFormatNb == BinTools_FormatVersion_VERSION_3)
1035 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1036 myCurves2d.Curve2d(pc2),
1037 mySurfaces.Surface(s),
1038 Locations().Location(l),tol,
1043 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1044 myCurves2d.Curve2d(pc2),
1045 mySurfaces.Surface(s),
1046 Locations().Location(l),tol);
1049 myBuilder.Continuity(E,
1050 mySurfaces.Surface(s),
1051 mySurfaces.Surface(s),
1052 Locations().Location(l),
1053 Locations().Location(l),
1058 if (myFormatNb == BinTools_FormatVersion_VERSION_2
1059 || myFormatNb == BinTools_FormatVersion_VERSION_3)
1061 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1062 mySurfaces.Surface(s),
1063 Locations().Location(l),tol,
1068 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1069 mySurfaces.Surface(s),
1070 Locations().Location(l),tol);
1074 mySurfaces.Surface(s),
1075 Locations().Location(l),
1079 case 4 : // -4- Regularity
1080 reg = (GeomAbs_Shape)IS.get();
1081 BinTools::GetInteger(IS, s);
1082 BinTools::GetInteger(IS, l);
1083 BinTools::GetInteger(IS, s2);
1084 BinTools::GetInteger(IS, l2);
1085 if (mySurfaces.Surface(s).IsNull() ||
1086 mySurfaces.Surface(s2).IsNull())
1088 myBuilder.Continuity(E,
1089 mySurfaces.Surface(s),
1090 mySurfaces.Surface(s2),
1091 Locations().Location(l),
1092 Locations().Location(l2),
1096 case 5 : // -5- Polygon3D
1097 BinTools::GetInteger(IS, c);
1098 BinTools::GetInteger(IS, l);
1099 //??? Bug? myBuilder.UpdateEdge(E,myPolygons3D(c));
1100 myBuilder.UpdateEdge(E, myPolygons3D(c), Locations().Location(l));
1103 case 6 : // -6- Polygon on triangulation
1104 case 7 : // -7- Polygon on closed triangulation
1105 closed = (val == 7);
1106 BinTools::GetInteger(IS, pt);
1108 BinTools::GetInteger(IS, pt2);
1110 BinTools::GetInteger(IS, t);
1111 BinTools::GetInteger(IS, l);
1114 myBuilder.UpdateEdge (E, myNodes(pt), myNodes(pt2), myTriangulations(t), Locations().Location(l));
1118 myBuilder.UpdateEdge (E, myNodes(pt), myTriangulations(t), Locations().Location(l));
1124 Standard_SStream aMsg;
1125 aMsg <<"Unexpected Curve Representation ="<< val << std::endl;
1126 throw Standard_Failure(aMsg.str().c_str());
1140 myBuilder.MakeWire(TopoDS::Wire(S));
1151 TopoDS_Face& F = TopoDS::Face(S);
1152 myBuilder.MakeFace(F);
1153 BinTools::GetBool(IS, bval); //NaturalRestriction flag
1154 BinTools::GetReal(IS, tol);
1155 BinTools::GetInteger(IS, s); //surface indx
1156 BinTools::GetInteger(IS, l); //location indx
1157 myBuilder.UpdateFace (F,
1158 s > 0 ? mySurfaces.Surface(s) : Handle(Geom_Surface)(),
1159 Locations().Location(l),
1161 myBuilder.NaturalRestriction (F, bval);
1163 Standard_Byte aByte = (Standard_Byte)IS.get();
1164 // cas triangulation
1166 BinTools::GetInteger(IS, s);
1167 myBuilder.UpdateFace(TopoDS::Face(S), myTriangulations(s));
1178 myBuilder.MakeShell(TopoDS::Shell(S));
1187 myBuilder.MakeSolid(TopoDS::Solid(S));
1195 case TopAbs_COMPSOLID :
1196 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1204 case TopAbs_COMPOUND :
1205 myBuilder.MakeCompound(TopoDS::Compound(S));
1210 Standard_SStream aMsg;
1211 aMsg << "Unexpected topology type = "<< T <<std::endl;
1212 throw Standard_Failure(aMsg.str().c_str());
1217 catch(Standard_Failure const& anException) {
1218 Standard_SStream aMsg;
1219 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadGeometry(S,OS)" << std::endl;
1220 aMsg << anException << std::endl;
1221 throw Standard_Failure(aMsg.str().c_str());
1227 //=======================================================================
1228 //function : AddShapes
1230 //=======================================================================
1232 void BinTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1233 const TopoDS_Shape& S2)
1235 myBuilder.Add(S1,S2);
1239 //=======================================================================
1240 //function : WritePolygonOnTriangulation
1242 //=======================================================================
1243 void BinTools_ShapeSet::WritePolygonOnTriangulation
1244 (Standard_OStream& OS,
1245 const Message_ProgressRange& theRange) const
1247 const Standard_Integer aNbPol = myNodes.Extent();
1248 OS << "PolygonOnTriangulations " << aNbPol << "\n";
1252 Message_ProgressScope aPS(theRange, "Writing polygons on triangulation", aNbPol);
1253 for (Standard_Integer aPolIter = 1; aPolIter <= aNbPol && aPS.More(); ++aPolIter, aPS.Next())
1255 const Handle(Poly_PolygonOnTriangulation)& aPoly = myNodes.FindKey (aPolIter);
1256 const TColStd_Array1OfInteger& aNodes = aPoly->Nodes();
1257 BinTools::PutInteger(OS, aNodes.Length());
1258 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNodes.Length(); ++aNodeIter)
1260 BinTools::PutInteger(OS, aNodes.Value (aNodeIter));
1263 // write the deflection
1264 BinTools::PutReal(OS, aPoly->Deflection());
1266 // writing parameters
1267 if (const Handle(TColStd_HArray1OfReal)& aParam = aPoly->Parameters())
1269 BinTools::PutBool(OS, Standard_True);
1270 for (Standard_Integer aNodeIter = 1; aNodeIter <= aParam->Length(); ++aNodeIter)
1272 BinTools::PutReal(OS, aParam->Value (aNodeIter));
1277 BinTools::PutBool(OS, Standard_False);
1281 catch (Standard_Failure const& anException)
1283 Standard_SStream aMsg;
1284 aMsg << "EXCEPTION in BinTools_ShapeSet::WritePolygonOnTriangulation(..)\n" << anException << "\n";
1285 throw Standard_Failure(aMsg.str().c_str());
1289 //=======================================================================
1290 //function : ReadPolygonOnTriangulation
1292 //=======================================================================
1293 void BinTools_ShapeSet::ReadPolygonOnTriangulation
1294 (Standard_IStream& IS,
1295 const Message_ProgressRange& theRange)
1299 if (IS.fail() || (strstr(aHeader,"PolygonOnTriangulations") == NULL))
1301 throw Standard_Failure("BinTools_ShapeSet::ReadPolygonOnTriangulation: Not a PolygonOnTriangulation section");
1304 Standard_Integer aNbPol = 0;
1306 IS.get();//remove LF
1310 Message_ProgressScope aPS(theRange, "Reading Polygones on triangulation", aNbPol);
1311 for (Standard_Integer aPolIter = 1; aPolIter <= aNbPol && aPS.More(); ++aPolIter, aPS.Next())
1313 Standard_Integer aNbNodes = 0;
1314 BinTools::GetInteger(IS, aNbNodes);
1315 Handle(Poly_PolygonOnTriangulation) aPoly = new Poly_PolygonOnTriangulation (aNbNodes, Standard_False);
1316 TColStd_Array1OfInteger& aNodes = aPoly->ChangeNodes();
1317 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1319 BinTools::GetInteger(IS, aNodes.ChangeValue (aNodeIter));
1322 Standard_Real aDefl = 0.0;
1323 BinTools::GetReal(IS, aDefl);
1324 aPoly->Deflection (aDefl);
1326 Standard_Boolean hasParameters = Standard_False;
1327 BinTools::GetBool(IS, hasParameters);
1330 Handle(TColStd_HArray1OfReal) aParams = new TColStd_HArray1OfReal (1, aNbNodes);
1331 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1333 BinTools::GetReal(IS, aParams->ChangeValue (aNodeIter));
1335 aPoly->SetParameters (aParams);
1337 myNodes.Add (aPoly);
1340 catch (Standard_Failure const& anException)
1342 Standard_SStream aMsg;
1343 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadPolygonOnTriangulation(..)\n" << anException << "\n";
1344 throw Standard_Failure(aMsg.str().c_str());
1348 //=======================================================================
1349 //function : WritePolygon3D
1351 //=======================================================================
1352 void BinTools_ShapeSet::WritePolygon3D (Standard_OStream& OS,
1353 const Message_ProgressRange& theRange)const
1355 const Standard_Integer aNbPol = myPolygons3D.Extent();
1356 OS << "Polygon3D " << aNbPol << "\n";
1360 Message_ProgressScope aPS(theRange, "Writing polygons 3D", aNbPol);
1361 for (Standard_Integer aPolIter = 1; aPolIter <= aNbPol && aPS.More(); ++aPolIter, aPS.Next())
1363 const Handle(Poly_Polygon3D)& aPoly = myPolygons3D.FindKey (aPolIter);
1364 BinTools::PutInteger(OS, aPoly->NbNodes());
1365 BinTools::PutBool(OS, aPoly->HasParameters());
1367 // write the deflection
1368 BinTools::PutReal(OS, aPoly->Deflection());
1371 const Standard_Integer aNbNodes = aPoly->NbNodes();
1372 const TColgp_Array1OfPnt& aNodes = aPoly->Nodes();
1373 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1375 const gp_Pnt& aPnt = aNodes.Value (aNodeIter);
1376 BinTools::PutReal(OS, aPnt.X());
1377 BinTools::PutReal(OS, aPnt.Y());
1378 BinTools::PutReal(OS, aPnt.Z());
1380 if (aPoly->HasParameters())
1382 const TColStd_Array1OfReal& aParam = aPoly->Parameters();
1383 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1385 BinTools::PutReal(OS, aParam.Value (aNodeIter));
1390 catch (Standard_Failure const& anException)
1392 Standard_SStream aMsg;
1393 aMsg << "EXCEPTION in BinTools_ShapeSet::WritePolygon3D(..)\n" << anException << "\n";
1394 throw Standard_Failure(aMsg.str().c_str());
1397 //=======================================================================
1398 //function : ReadPolygon3D
1400 //=======================================================================
1401 void BinTools_ShapeSet::ReadPolygon3D (Standard_IStream& IS,
1402 const Message_ProgressRange& theRange)
1407 if (IS.fail() || strstr(aHeader,"Polygon3D") == NULL)
1410 std::cout <<"Buffer: " << aHeader << std::endl;
1412 throw Standard_Failure("BinTools_ShapeSet::ReadPolygon3D: Not a Polygon3D section");
1415 Standard_Integer aNbPol = 0;
1417 IS.get();//remove LF
1421 Message_ProgressScope aPS(theRange, "Reading polygones 3D", aNbPol);
1422 for (Standard_Integer aPolIter = 1; aPolIter <= aNbPol && aPS.More(); ++aPolIter, aPS.Next())
1424 Standard_Integer aNbNodes = 0;
1425 Standard_Boolean hasParameters = Standard_False;
1426 Standard_Real aDefl = 0.0;
1427 BinTools::GetInteger(IS, aNbNodes);
1428 BinTools::GetBool(IS, hasParameters);
1429 BinTools::GetReal(IS, aDefl);
1431 Handle(Poly_Polygon3D) aPoly = new Poly_Polygon3D (aNbNodes, hasParameters);
1432 aPoly->Deflection (aDefl);
1434 TColgp_Array1OfPnt& aNodes = aPoly->ChangeNodes();
1435 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1437 gp_XYZ& aPnt = aNodes.ChangeValue (aNodeIter).ChangeCoord();
1438 BinTools::GetReal(IS, aPnt.ChangeCoord (1));
1439 BinTools::GetReal(IS, aPnt.ChangeCoord (2));
1440 BinTools::GetReal(IS, aPnt.ChangeCoord (3));
1444 TColStd_Array1OfReal& aParam = aPoly->ChangeParameters();
1445 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1447 BinTools::GetReal(IS, aParam.ChangeValue (aNodeIter));
1451 myPolygons3D.Add (aPoly);
1454 catch (Standard_Failure const& anException)
1456 Standard_SStream aMsg;
1457 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadPolygon3D(..)\n" << anException << "\n";
1458 throw Standard_Failure(aMsg.str().c_str());
1463 //=======================================================================
1464 //function : WriteTriangulation
1466 //=======================================================================
1467 void BinTools_ShapeSet::WriteTriangulation (Standard_OStream& OS,
1468 const Message_ProgressRange& theRange) const
1470 const Standard_Integer aNbTriangulations = myTriangulations.Extent();
1471 OS << "Triangulations " << aNbTriangulations << "\n";
1476 Message_ProgressScope aPS(theRange, "Writing triangulation", aNbTriangulations);
1477 for (Standard_Integer aTriangulationIter = 1; aTriangulationIter <= aNbTriangulations && aPS.More(); ++aTriangulationIter, aPS.Next())
1479 const Handle(Poly_Triangulation)& aTriangulation = myTriangulations.FindKey (aTriangulationIter);
1480 const Standard_Integer aNbNodes = aTriangulation->NbNodes();
1481 const Standard_Integer aNbTriangles = aTriangulation->NbTriangles();
1482 BinTools::PutInteger(OS, aNbNodes);
1483 BinTools::PutInteger(OS, aNbTriangles);
1484 BinTools::PutBool(OS, aTriangulation->HasUVNodes() ? 1 : 0);
1485 BinTools::PutReal(OS, aTriangulation->Deflection());
1487 // write the 3d nodes
1488 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
1489 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1491 const gp_Pnt& aPnt = aNodes.Value (aNodeIter);
1492 BinTools::PutReal(OS, aPnt.X());
1493 BinTools::PutReal(OS, aPnt.Y());
1494 BinTools::PutReal(OS, aPnt.Z());
1497 if (aTriangulation->HasUVNodes())
1499 const TColgp_Array1OfPnt2d& aUVNodes = aTriangulation->UVNodes();
1500 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1502 const gp_Pnt2d aUV = aUVNodes.Value (aNodeIter);
1503 BinTools::PutReal(OS, aUV.X());
1504 BinTools::PutReal(OS, aUV.Y());
1508 const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
1509 for (Standard_Integer aTriIter = 1; aTriIter <= aNbTriangles; ++aTriIter)
1511 const Poly_Triangle& aTri = aTriangles.Value (aTriIter);
1512 BinTools::PutInteger(OS, aTri.Value (1));
1513 BinTools::PutInteger(OS, aTri.Value (2));
1514 BinTools::PutInteger(OS, aTri.Value (3));
1518 catch (Standard_Failure const& anException)
1520 Standard_SStream aMsg;
1521 aMsg << "EXCEPTION in BinTools_ShapeSet::WriteTriangulation(..)\n" << anException << "\n";
1522 throw Standard_Failure(aMsg.str().c_str());
1526 //=======================================================================
1527 //function : ReadTriangulation
1529 //=======================================================================
1530 void BinTools_ShapeSet::ReadTriangulation (Standard_IStream& IS,
1531 const Message_ProgressRange& theRange)
1535 if (IS.fail() || (strstr(aHeader, "Triangulations") == NULL))
1537 throw Standard_Failure("BinTools_ShapeSet::Triangulation: Not a Triangulation section");
1540 Standard_Integer aNbTriangulations = 0;
1541 IS >> aNbTriangulations;
1542 IS.get();// remove LF
1547 Message_ProgressScope aPS(theRange, "Reading triangulation", aNbTriangulations);
1548 for (Standard_Integer aTriangulationIter = 1; aTriangulationIter <= aNbTriangulations && aPS.More(); ++aTriangulationIter, aPS.Next())
1550 Standard_Integer aNbNodes = 0, aNbTriangles = 0;
1551 Standard_Boolean hasUV = Standard_False;
1552 Standard_Real aDefl = 0.0;
1553 BinTools::GetInteger(IS, aNbNodes);
1554 BinTools::GetInteger(IS, aNbTriangles);
1555 BinTools::GetBool(IS, hasUV);
1556 BinTools::GetReal(IS, aDefl); //deflection
1557 Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (aNbNodes, aNbTriangles, hasUV);
1558 aTriangulation->Deflection (aDefl);
1560 TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes();
1561 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1563 Standard_Real* anXYZ = aNodes.ChangeValue (aNodeIter).ChangeCoord().ChangeData();
1564 BinTools::GetReal(IS, anXYZ[0]);
1565 BinTools::GetReal(IS, anXYZ[1]);
1566 BinTools::GetReal(IS, anXYZ[2]);
1571 TColgp_Array1OfPnt2d& aUVNodes = aTriangulation->ChangeUVNodes();
1572 for (Standard_Integer aNodeIter = 1; aNodeIter <= aNbNodes; ++aNodeIter)
1574 gp_XY& anUV = aUVNodes.ChangeValue (aNodeIter).ChangeCoord();
1575 BinTools::GetReal(IS, anUV.ChangeCoord (1));
1576 BinTools::GetReal(IS, anUV.ChangeCoord (2));
1580 // read the triangles
1581 Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles();
1582 for (Standard_Integer aTriIter = 1; aTriIter <= aNbTriangles; ++aTriIter)
1584 Poly_Triangle& aTri = aTriangles.ChangeValue (aTriIter);
1585 BinTools::GetInteger(IS, aTri.ChangeValue (1));
1586 BinTools::GetInteger(IS, aTri.ChangeValue (2));
1587 BinTools::GetInteger(IS, aTri.ChangeValue (3));
1590 myTriangulations.Add (aTriangulation);
1593 catch (Standard_Failure const& anException)
1595 Standard_SStream aMsg;
1596 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadTriangulation(..)\n" << anException << "\n";
1597 throw Standard_Failure(aMsg.str().c_str());
1601 //=======================================================================
1602 //function : NbShapes
1604 //=======================================================================
1606 Standard_Integer BinTools_ShapeSet::NbShapes() const
1608 return myShapes.Extent();