1 // File: GeoAlgo_Sol.cxx
2 // Created: Mon Dec 15 16:32:27 1997
3 // Author: Cascade_Manager
8 #include "GeoAlgo_Sol.hxx"
10 #include <Geom_BSplineSurface.hxx>
11 #include <Geom_Plane.hxx>
13 #include <GeomPlate_Surface.hxx>
14 #include <GeomPlate_MakeApprox.hxx>
16 #include <Plate_Plate.hxx>
17 #include <Plate_PinpointConstraint.hxx>
19 #include <TColgp_SequenceOfXYZ.hxx>
20 #include <TColgp_Array1OfXYZ.hxx>
21 #include <TColgp_Array1OfXY.hxx>
22 #include <TColgp_Array2OfPnt.hxx>
24 #include <TCollection_AsciiString.hxx>
28 #include <Standard_Stream.hxx>
32 //=============================================================================
34 //=============================================================================
35 GeoAlgo_Sol::GeoAlgo_Sol():myIsDone(Standard_False)
42 //=============================================================================
43 // Constructor with a file name
44 //=============================================================================
45 GeoAlgo_Sol::GeoAlgo_Sol(const Standard_CString aGroundName)
47 myGround = Read(aGroundName);
48 // if an error occurs in the construction the method IsDone
54 //=============================================================================
56 // Build method from an empty object
57 //=============================================================================
58 void GeoAlgo_Sol::Build(const Standard_CString aGroundName)
60 myGround = Read(aGroundName);
61 // if an error occurs in the construction the method IsDone
65 //=============================================================================
66 // Build(Sequence of Points)
67 // Build method from an empty object
68 // Called also from the Builde method from a file
69 //=============================================================================
70 void GeoAlgo_Sol::Build(const TColgp_SequenceOfXYZ& seqOfXYZ)
73 // points are projected on plane z = 0
74 // the projection vector for each point is computed
75 // These data give the input constraints loaded into plate algorithm
77 myIsDone = Standard_True;
78 Standard_Integer nbPnt = seqOfXYZ.Length();
83 std::cout<<" * Nunber of points = "<< nbPnt << std::endl;
84 for (i=1; i<= nbPnt; i++) {
85 gp_Pnt ptProj(seqOfXYZ.Value(i).X(), seqOfXYZ.Value(i).Y(), 0. );
86 gp_Vec aVec( ptProj, seqOfXYZ.Value(i));
87 gp_XY pntXY(seqOfXYZ.Value(i).X(),seqOfXYZ.Value(i).Y());
88 Plate_PinpointConstraint PCst( pntXY,aVec.XYZ() );
89 myPlate.Load(PCst);// Load plate
91 myPlate.SolveTI(2, 1.);// resolution
92 if (!myPlate.IsDone()) {
93 std::cout<<" plate computation has failed"<< std::endl;
94 myIsDone=Standard_False;
97 // Computation of plate surface
99 gp_Dir Norm(0., 0., 1.);
100 Handle(Geom_Plane) myPlane =
101 new Geom_Plane(Or, Norm);// Plane of normal Oz
102 Handle(GeomPlate_Surface) myPlateSurf =
103 new GeomPlate_Surface( myPlane, myPlate);//plate surface
105 GeomPlate_MakeApprox aMKS(myPlateSurf, Precision::Approximation(), 4, 7, 0.001, 0);//bspline surface
106 myGround = aMKS.Surface();
107 // if an error occurs in the construction the method IsDone
112 //=============================================================================
114 // Returns the resulting surface as a bspline surface
115 //=============================================================================
116 Handle(Geom_BSplineSurface) GeoAlgo_Sol::Surface() const
123 //============================================================================
125 // Checks the construction of the surface
126 //============================================================================
127 Standard_Boolean GeoAlgo_Sol::IsDone() const
129 // Returns True if the construction successes, False otherwise
135 //=============================================================================
137 // Private method called from constructor
138 //=============================================================================
139 Handle(Geom_BSplineSurface) GeoAlgo_Sol::Read(const Standard_CString aGroundName)
141 // This methods read a file of points ans build a surface using plate algorithm
143 myIsDone = Standard_True;
144 Standard_Integer nbPnt=0;
146 // Read points from the file
148 std::istream in(&fic);
150 if (!fic.open(aGroundName,std::ios::in)){
151 std::cout << " impossible to open a file : "<<aGroundName<<std::endl;
152 myIsDone = Standard_False;
155 // Store the points into a sequence
156 TColgp_SequenceOfXYZ seqOfXYZ;
159 while (!in.fail()|| !in.eof()){
160 if (in >> x && in >> y && in >> z){
165 seqOfXYZ.Append(pntXYZ);