7fd59977 |
1 | // File: GeoAlgo_Sol.cxx |
2 | // Created: Mon Dec 15 16:32:27 1997 |
3 | // Author: Cascade_Manager |
4 | // <cascade@savv04> |
5 | |
6 | #include "stdafx.h" |
7 | |
8 | #include "GeoAlgo_Sol.hxx" |
9 | |
10 | #include <Geom_BSplineSurface.hxx> |
11 | #include <Geom_Plane.hxx> |
12 | |
13 | #include <GeomPlate_Surface.hxx> |
14 | #include <GeomPlate_MakeApprox.hxx> |
15 | |
16 | #include <Plate_Plate.hxx> |
17 | #include <Plate_PinpointConstraint.hxx> |
18 | |
19 | #include <TColgp_SequenceOfXYZ.hxx> |
20 | #include <TColgp_Array1OfXYZ.hxx> |
21 | #include <TColgp_Array1OfXY.hxx> |
22 | #include <TColgp_Array2OfPnt.hxx> |
23 | |
24 | #include <TCollection_AsciiString.hxx> |
25 | |
26 | #include <gp_Vec.hxx> |
27 | |
28 | #include <Standard_Stream.hxx> |
29 | |
30 | |
31 | |
32 | //============================================================================= |
33 | // Empty constructor |
34 | //============================================================================= |
35 | GeoAlgo_Sol::GeoAlgo_Sol():myIsDone(Standard_False) |
36 | { |
5c1f974e |
37 | |
7fd59977 |
38 | } |
39 | |
40 | |
41 | |
42 | //============================================================================= |
43 | // Constructor with a file name |
44 | //============================================================================= |
45 | GeoAlgo_Sol::GeoAlgo_Sol(const Standard_CString aGroundName) |
46 | { |
47 | myGround = Read(aGroundName); |
48 | // if an error occurs in the construction the method IsDone |
49 | // returns False. |
50 | } |
51 | |
52 | |
53 | |
54 | //============================================================================= |
55 | // Build(File) |
56 | // Build method from an empty object |
57 | //============================================================================= |
58 | void GeoAlgo_Sol::Build(const Standard_CString aGroundName) |
59 | { |
60 | myGround = Read(aGroundName); |
61 | // if an error occurs in the construction the method IsDone |
62 | // returns False. |
63 | } |
64 | |
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) |
71 | { |
72 | // Build the surface: |
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 |
76 | |
77 | myIsDone = Standard_True; |
78 | Standard_Integer nbPnt = seqOfXYZ.Length(); |
79 | Standard_Integer i; |
80 | |
81 | //Filling plate |
82 | Plate_Plate myPlate; |
83 | cout<<" * Nunber of points = "<< nbPnt << 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 |
90 | } |
91 | myPlate.SolveTI(2, 1.);// resolution |
92 | if (!myPlate.IsDone()) { |
93 | cout<<" plate computation has failed"<< endl; |
94 | myIsDone=Standard_False; |
95 | } |
96 | |
97 | // Computation of plate surface |
98 | gp_Pnt Or(0,0,0.); |
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 |
104 | |
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 |
108 | // returns False. |
109 | } |
110 | |
111 | |
112 | //============================================================================= |
113 | // Surface() |
114 | // Returns the resulting surface as a bspline surface |
115 | //============================================================================= |
116 | Handle(Geom_BSplineSurface) GeoAlgo_Sol::Surface() const |
117 | { |
7fd59977 |
118 | return myGround; |
119 | } |
120 | |
121 | |
122 | |
123 | //============================================================================ |
124 | // IsDone() |
125 | // Checks the construction of the surface |
126 | //============================================================================ |
127 | Standard_Boolean GeoAlgo_Sol::IsDone() const |
128 | { |
129 | // Returns True if the construction successes, False otherwise |
130 | return myIsDone; |
131 | } |
132 | |
133 | |
134 | |
135 | //============================================================================= |
136 | // Read(File) |
137 | // Private method called from constructor |
138 | //============================================================================= |
139 | Handle(Geom_BSplineSurface) GeoAlgo_Sol::Read(const Standard_CString aGroundName) |
140 | { |
5c1f974e |
141 | // This methods read a file of points ans build a surface using plate algorithm |
7fd59977 |
142 | |
143 | myIsDone = Standard_True; |
144 | Standard_Integer nbPnt=0; |
145 | |
5c1f974e |
146 | // Read points from the file |
7fd59977 |
147 | filebuf fic; |
148 | istream in(&fic); |
5c1f974e |
149 | |
7fd59977 |
150 | if (!fic.open(aGroundName,ios::in)){ |
151 | cout << " impossible to open a file : "<<aGroundName<<endl; |
152 | myIsDone = Standard_False; |
153 | return 0; |
154 | } |
155 | // Store the points into a sequence |
156 | TColgp_SequenceOfXYZ seqOfXYZ; |
157 | gp_XYZ pntXYZ; |
158 | Standard_Real x,y,z; |
159 | while (!in.fail()|| !in.eof()){ |
160 | if (in >> x && in >> y && in >> z){ |
5c1f974e |
161 | pntXYZ.SetX(x); |
162 | pntXYZ.SetY(y); |
163 | pntXYZ.SetZ(z); |
7fd59977 |
164 | nbPnt++; |
165 | seqOfXYZ.Append(pntXYZ); |
166 | } |
167 | } |
168 | fic.close(); |
169 | Build(seqOfXYZ); |
170 | return myGround; |
7fd59977 |
171 | } |