WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
occ_axis_projection.cc
Go to the documentation of this file.
1 #include "occ_axis_projection.h"
2 #include "occ_utilities.h"
3 
4 #include <iostream>
5 
6 #include <TopoDS_Shape.hxx>
7 #include <TopoDS_Face.hxx>
8 #include <gp_Pnt.hxx>
9 #include <gp_Vec.hxx>
10 #include <Standard_Real.hxx>
11 #include <Standard_Integer.hxx>
12 #include <BRep_Tool.hxx>
13 #include <Geom_Surface.hxx>
14 #include <Prs3d_ShapeTool.hxx>
15 #include <gp_Ax3.hxx>
16 #include <gp_Lin.hxx>
17 #include <GeomLProp_SLProps.hxx>
18 #include <IntCurvesFace_ShapeIntersector.hxx>
19 #include <vector>
20 #define FALSE 0
21 #define TRUE 1
22 
23 
26 
27 
28 namespace OpenCascade
29 {
30 
31 
32  AxisProjection::AxisProjection(const TopoDS_Shape &sh,
33  Point<3> direction,
34  double tolerance,
35  double recovery_tolerance) :
36  sh(sh),
37  direction(direction(0),
38  direction(1),
39  direction(2)),
40  Direction(direction),
41  tolerance(tolerance),
42  recovery_tolerance(recovery_tolerance)
43  {
44  // Check that we have at least
45  // one face.
46  TopExp_Explorer faceExplorer(sh , TopAbs_FACE);
47  unsigned int n_faces = 0;
48  while (faceExplorer.More())
49  {
50  n_faces++;
51  faceExplorer.Next();
52  }
53  AssertThrow(n_faces > 0, ExcMessage("We have no faces to process"));
54 
55 
56  }
57 
58 
60  Point<3> &normal,
61  double &mean_curvature,
62  const Point<3> &origin) const
63  {
64  // translating original
65  // Point<dim> to gp point
66  gp_Pnt P0 = Pnt(origin);
67  gp_Ax1 gpaxis(P0, direction);
68  gp_Lin line(gpaxis);
69 
70  // destination point, normal
71  // and mean curvature
72  gp_Pnt Pproj(0.0,0.0,0.0);
73  gp_Dir Normal;
74  Standard_Real Mean_Curvature;
75 
76  // we prepare now the surface
77  // for the projection we get
78  // the whole shape from the
79  // iges model
80  IntCurvesFace_ShapeIntersector Inters;
81  Inters.Load(sh,tolerance);
82  Inters.Perform(line,-RealLast(),+RealLast());
83 
84  Point<3> average(0.0,0.0,0.0);
85  Point<3> av_normal(0.0,0.0,0.0);
86  double av_curvature = 0.0;
87  if (Inters.NbPnt() == 0)
88  {
89  unsigned int succeeded = 0;
90  cout<<"Axis A("<<Direction<<") direction projection of point P("<<origin<<") on shape FAILED!"<<endl;
91  cout<<"Trying to fix this"<<endl;
92 
93  gp_Pnt P1 = Pnt(origin+recovery_tolerance*Point<3>(1.0,0.0,0.0));
94  gp_Ax1 gpaxis1(P1, direction);
95  gp_Lin line1(gpaxis1);
96  IntCurvesFace_ShapeIntersector Inters1;
97  Inters1.Load(sh,tolerance);
98  Inters1.Perform(line1,-RealLast(),+RealLast());
99  //AssertThrow(Inters1.NbPnt() > 0,
100  // ExcMessage("Recovery point 1 projection on surface in given direction does not exist"));
101  if (Inters1.NbPnt() > 0)
102  {
103  succeeded++;
104  Standard_Real min_distance = 1e15;
105  Standard_Real distance;
106  int lowest_dist_int=0;
107  for (int i=0; i<Inters1.NbPnt(); ++i)
108  {
109  distance = Pnt(origin).Distance(Inters1.Pnt(i+1));
110  //cout<<"Point "<<i<<": "<<Pnt(Inters1.Pnt(i+1))<<" distance: "<<distance<<endl;
111  if (distance < min_distance)
112  {
113  min_distance = distance;
114  Pproj = Inters1.Pnt(i+1);
115  lowest_dist_int = i+1;
116  }
117  }
118  average += Pnt(Inters1.Pnt(lowest_dist_int));
119  TopoDS_Face face1 = Inters1.Face(lowest_dist_int);
120  Handle(Geom_Surface) SurfToProj1 = BRep_Tool::Surface(face1);
121  GeomLProp_SLProps props1(SurfToProj1, Inters1.UParameter(lowest_dist_int), Inters1.VParameter(lowest_dist_int), 1, tolerance);
122  gp_Dir Normal1 = props1.Normal();
123  Standard_Real Mean_Curvature1 = props1.MeanCurvature();
124  // adjusting normal orientation
125  if (face1.Orientation()==TopAbs_REVERSED)
126  {
127  Normal1.SetCoord(-1.0*Normal1.X(),-1.0*Normal1.Y(),-1.0*Normal1.Z());
128  Mean_Curvature1*=-1.0;
129  }
130  av_normal += Point<3>(Normal1.X(),Normal1.Y(),Normal1.Z());
131  av_curvature += Mean_Curvature1;
132  }
133 
134  gp_Pnt P2 = Pnt(origin+recovery_tolerance*Point<3>(-1.0,0.0,0.0));
135  gp_Ax1 gpaxis2(P2, direction);
136  gp_Lin line2(gpaxis2);
137  IntCurvesFace_ShapeIntersector Inters2;
138  Inters2.Load(sh,tolerance);
139  Inters2.Perform(line2,-RealLast(),+RealLast());
140  //AssertThrow(Inters2.NbPnt() > 0,
141  // ExcMessage("Recovery point 2 projection on surface in given direction does not exist"));
142  if (Inters2.NbPnt() > 0)
143  {
144  succeeded++;
145  Standard_Real min_distance = 1e15;
146  Standard_Real distance;
147  int lowest_dist_int=0;
148  for (int i=0; i<Inters2.NbPnt(); ++i)
149  {
150  distance = Pnt(origin).Distance(Inters2.Pnt(i+1));
151  //cout<<"Point "<<i<<": "<<Pnt(Inters2.Pnt(i+1))<<" distance: "<<distance<<endl;
152  if (distance < min_distance)
153  {
154  min_distance = distance;
155  Pproj = Inters2.Pnt(i+1);
156  lowest_dist_int = i+1;
157  }
158  }
159  average += Pnt(Inters2.Pnt(lowest_dist_int));
160  TopoDS_Face face2 = Inters2.Face(lowest_dist_int);
161  Handle(Geom_Surface) SurfToProj2 = BRep_Tool::Surface(face2);
162  GeomLProp_SLProps props2(SurfToProj2, Inters2.UParameter(lowest_dist_int), Inters2.VParameter(lowest_dist_int), 1, tolerance);
163  gp_Dir Normal2 = props2.Normal();
164  Standard_Real Mean_Curvature2 = props2.MeanCurvature();
165  // adjusting normal orientation
166  if (face2.Orientation()==TopAbs_REVERSED)
167  {
168  Normal2.SetCoord(-1.0*Normal2.X(),-1.0*Normal2.Y(),-1.0*Normal2.Z());
169  Mean_Curvature2*=-1.0;
170  }
171  av_normal += Point<3>(Normal2.X(),Normal2.Y(),Normal2.Z());
172  av_curvature += Mean_Curvature2;
173  }
174 
175  gp_Pnt P3 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,1.0));
176  gp_Ax1 gpaxis3(P3, direction);
177  gp_Lin line3(gpaxis3);
178  IntCurvesFace_ShapeIntersector Inters3;
179  Inters3.Load(sh,tolerance);
180  Inters3.Perform(line3,-RealLast(),+RealLast());
181  //AssertThrow(Inters3.NbPnt() > 0,
182  // ExcMessage("Recovery point 3 projection on surface in given direction does not exist"));
183  if (Inters3.NbPnt() > 0)
184  {
185  succeeded++;
186  Standard_Real min_distance = 1e15;
187  Standard_Real distance;
188  int lowest_dist_int=0;
189  for (int i=0; i<Inters3.NbPnt(); ++i)
190  {
191  distance = Pnt(origin).Distance(Inters3.Pnt(i+1));
192  //cout<<"Point "<<i<<": "<<Pnt(Inters3.Pnt(i+1))<<" distance: "<<distance<<endl;
193  if (distance < min_distance)
194  {
195  min_distance = distance;
196  Pproj = Inters3.Pnt(i+1);
197  lowest_dist_int = i+1;
198  }
199  }
200  average += Pnt(Inters3.Pnt(lowest_dist_int));
201  TopoDS_Face face3 = Inters3.Face(lowest_dist_int);
202  Handle(Geom_Surface) SurfToProj3 = BRep_Tool::Surface(face3);
203  GeomLProp_SLProps props3(SurfToProj3, Inters3.UParameter(lowest_dist_int), Inters3.VParameter(lowest_dist_int), 1, tolerance);
204  gp_Dir Normal3 = props3.Normal();
205  Standard_Real Mean_Curvature3 = props3.MeanCurvature();
206  // adjusting normal orientation
207  if (face3.Orientation()==TopAbs_REVERSED)
208  {
209  Normal3.SetCoord(-1.0*Normal3.X(),-1.0*Normal3.Y(),-1.0*Normal3.Z());
210  Mean_Curvature3*=-1.0;
211  }
212  av_normal += Point<3>(Normal3.X(),Normal3.Y(),Normal3.Z());
213  av_curvature += Mean_Curvature3;
214  }
215 
216  gp_Pnt P4 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,-1.0));
217  gp_Ax1 gpaxis4(P4, direction);
218  gp_Lin line4(gpaxis4);
219  IntCurvesFace_ShapeIntersector Inters4;
220  Inters4.Load(sh,tolerance);
221  Inters4.Perform(line4,-RealLast(),+RealLast());
222  //AssertThrow(Inters4.NbPnt() > 0,
223  // ExcMessage("Recovery point 4 projection on surface in given direction does not exist"));
224  if (Inters4.NbPnt() > 0)
225  {
226  succeeded++;
227  Standard_Real min_distance = 1e15;
228  Standard_Real distance;
229  int lowest_dist_int=0;
230  for (int i=0; i<Inters4.NbPnt(); ++i)
231  {
232  distance = Pnt(origin).Distance(Inters4.Pnt(i+1));
233  //cout<<"Point "<<i<<": "<<Pnt(Inters4.Pnt(i+1))<<" distance: "<<distance<<endl;
234  if (distance < min_distance)
235  {
236  min_distance = distance;
237  Pproj = Inters4.Pnt(i+1);
238  lowest_dist_int = i+1;
239  }
240  }
241  average += Pnt(Inters4.Pnt(lowest_dist_int));
242  TopoDS_Face face4 = Inters4.Face(lowest_dist_int);
243  Handle(Geom_Surface) SurfToProj4 = BRep_Tool::Surface(face4);
244  GeomLProp_SLProps props4(SurfToProj4, Inters4.UParameter(lowest_dist_int), Inters4.VParameter(lowest_dist_int), 1, tolerance);
245  gp_Dir Normal4 = props4.Normal();
246  Standard_Real Mean_Curvature4 = props4.MeanCurvature();
247  // adjusting normal orientation
248  if (face4.Orientation()==TopAbs_REVERSED)
249  {
250  Normal4.SetCoord(-1.0*Normal4.X(),-1.0*Normal4.Y(),-1.0*Normal4.Z());
251  Mean_Curvature4*=-1.0;
252  }
253  av_normal += Point<3>(Normal4.X(),Normal4.Y(),Normal4.Z());
254  av_curvature += Mean_Curvature4;
255  }
256  if (succeeded > 0)
257  {
258  cout<<"Recovery attempt of point projection on surface in given direction FAILED"<<endl;
259  return false;
260  }
261  //AssertThrow(succeeded > 0,
262  // ExcMessage("Recovery attempt of point projection on surface in given direction FAILED"));
263 
264  Pproj = Pnt(average/succeeded);
265  av_normal/=succeeded;
266  Normal.SetCoord(av_normal(0),av_normal(1),av_normal(2));
267  Mean_Curvature = av_curvature/succeeded;
268  }
269  else
270  {
271  //cout<<"Intersections found: "<<Inters.NbPnt()<<endl;
272  Standard_Real min_distance = 1e15;
273  Standard_Real distance;
274  int lowest_dist_int=0;
275  for (int i=0; i<Inters.NbPnt(); ++i)
276  {
277  distance = Pnt(origin).Distance(Inters.Pnt(i+1));
278  //cout<<"Point "<<i<<": "<<Pnt(Inters.Pnt(i+1))<<" distance: "<<distance<<endl;
279  if (distance < min_distance)
280  {
281  min_distance = distance;
282  Pproj = Inters.Pnt(i+1);
283  lowest_dist_int = i+1;
284  }
285  }
286  TopoDS_Face face = Inters.Face(lowest_dist_int);
287  Handle(Geom_Surface) SurfToProj = BRep_Tool::Surface(face);
288  GeomLProp_SLProps props(SurfToProj, Inters.UParameter(lowest_dist_int), Inters.VParameter(lowest_dist_int), 1, tolerance);
289  Normal = props.Normal();
290  Mean_Curvature = props.MeanCurvature();
291  // adjusting normal orientation
292  if (face.Orientation()==TopAbs_REVERSED)
293  {
294  Normal.SetCoord(-1.0*Normal.X(),-1.0*Normal.Y(),-1.0*Normal.Z());
295  Mean_Curvature*=-1.0;
296  }
297  }
298 
299 
300 // translating destination point
301  projection = Pnt(Pproj);
302 
303 // translating normal vector
304  normal(0) = Normal.X();
305  normal(1) = Normal.Y();
306  normal(2) = Normal.Z();
307 
308 
309 // translating mean curvature
310  mean_curvature = double(Mean_Curvature);
311 
312  return true;
313  }
314 
316  const Point<3> &origin) const
317  {
318  // translating original
319  // Point<dim> to gp point
320 
321 
322  gp_Pnt P0 = Pnt(origin);
323  gp_Ax1 gpaxis(P0, direction);
324  gp_Lin line(gpaxis);
325 
326  // destination point
327  gp_Pnt Pproj(0.0,0.0,0.0);
328 
329  // we prepare now the surface
330  // for the projection we get
331  // the whole shape from the
332  // iges model
333  IntCurvesFace_ShapeIntersector Inters;
334  Inters.Load(sh,tolerance);
335 
336  Inters.Perform(line,-RealLast(),+RealLast());
337 
338  Point<3> average(0.0,0.0,0.0);
339  if (Inters.NbPnt() == 0)
340  {
341  unsigned int succeeded = 0;
342  cout<<"Axis A("<<Direction<<") direction projection of point P("<<origin<<") on shape FAILED!"<<endl;
343  cout<<"Trying to fix this"<<endl;
344 
345  gp_Pnt P1 = Pnt(origin+recovery_tolerance*Point<3>(1.0,0.0,0.0));
346  gp_Ax1 gpaxis1(P1, direction);
347  gp_Lin line1(gpaxis1);
348  IntCurvesFace_ShapeIntersector Inters1;
349  Inters1.Load(sh,tolerance);
350  Inters1.Perform(line1,-RealLast(),+RealLast());
351  //AssertThrow(Inters1.NbPnt() > 0,
352  // ExcMessage("Recovery point 1 projection on surface in given direction does not exist"));
353  if (Inters1.NbPnt() > 0)
354  {
355  Standard_Real min_distance = 1e15;
356  Standard_Real distance;
357  int lowest_dist_int=0;
358  for (int i=0; i<Inters1.NbPnt(); ++i)
359  {
360  distance = Pnt(origin).Distance(Inters1.Pnt(i+1));
361  //cout<<"Point "<<i<<": "<<Pnt(Inters1.Pnt(i+1))<<" distance: "<<distance<<endl;
362  if (distance < min_distance)
363  {
364  min_distance = distance;
365  Pproj = Inters1.Pnt(i+1);
366  lowest_dist_int = i+1;
367  }
368  }
369  average += Pnt(Inters1.Pnt(lowest_dist_int));
370  succeeded++;
371  }
372 
373  gp_Pnt P2 = Pnt(origin+recovery_tolerance*Point<3>(-1.0,0.0,0.0));
374  gp_Ax1 gpaxis2(P2, direction);
375  gp_Lin line2(gpaxis2);
376  IntCurvesFace_ShapeIntersector Inters2;
377  Inters2.Load(sh,tolerance);
378  Inters2.Perform(line2,-RealLast(),+RealLast());
379  //AssertThrow(Inters2.NbPnt() > 0,
380  // ExcMessage("Recovery point 2 projection on surface in given direction does not exist"));
381  if (Inters2.NbPnt() > 0)
382  {
383  Standard_Real min_distance = 1e15;
384  Standard_Real distance;
385  int lowest_dist_int=0;
386  for (int i=0; i<Inters2.NbPnt(); ++i)
387  {
388  distance = Pnt(origin).Distance(Inters2.Pnt(i+1));
389  //cout<<"Point "<<i<<": "<<Pnt(Inters2.Pnt(i+1))<<" distance: "<<distance<<endl;
390  if (distance < min_distance)
391  {
392  min_distance = distance;
393  Pproj = Inters2.Pnt(i+1);
394  lowest_dist_int = i+1;
395  }
396  }
397  average += Pnt(Inters2.Pnt(lowest_dist_int));
398  succeeded++;
399  }
400 
401  gp_Pnt P3 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,1.0));
402  gp_Ax1 gpaxis3(P3, direction);
403  gp_Lin line3(gpaxis3);
404  IntCurvesFace_ShapeIntersector Inters3;
405  Inters3.Load(sh,tolerance);
406  Inters3.Perform(line3,-RealLast(),+RealLast());
407  //AssertThrow(Inters3.NbPnt() > 0,
408  // ExcMessage("Recovery point 3 projection on surface in given direction does not exist"));
409  if (Inters3.NbPnt() > 0)
410  {
411  Standard_Real min_distance = 1e15;
412  Standard_Real distance;
413  int lowest_dist_int=0;
414  for (int i=0; i<Inters3.NbPnt(); ++i)
415  {
416  distance = Pnt(origin).Distance(Inters3.Pnt(i+1));
417  //cout<<"Point "<<i<<": "<<Pnt(Inters3.Pnt(i+1))<<" distance: "<<distance<<endl;
418  if (distance < min_distance)
419  {
420  min_distance = distance;
421  Pproj = Inters3.Pnt(i+1);
422  lowest_dist_int = i+1;
423  }
424  }
425  average += Pnt(Inters3.Pnt(lowest_dist_int));
426  succeeded++;
427  }
428 
429  gp_Pnt P4 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,-1.0));
430  gp_Ax1 gpaxis4(P4, direction);
431  gp_Lin line4(gpaxis4);
432  IntCurvesFace_ShapeIntersector Inters4;
433  Inters4.Load(sh,tolerance);
434  Inters4.Perform(line4,-RealLast(),+RealLast());
435  //AssertThrow(Inters4.NbPnt() > 0,
436  // ExcMessage("Recovery point 4 projection on surface in given direction does not exist"));
437  if (Inters4.NbPnt() > 0)
438  {
439  Standard_Real min_distance = 1e15;
440  Standard_Real distance;
441  int lowest_dist_int=0;
442  for (int i=0; i<Inters4.NbPnt(); ++i)
443  {
444  distance = Pnt(origin).Distance(Inters4.Pnt(i+1));
445  //cout<<"Point "<<i<<": "<<Pnt(Inters4.Pnt(i+1))<<" distance: "<<distance<<endl;
446  if (distance < min_distance)
447  {
448  min_distance = distance;
449  Pproj = Inters4.Pnt(i+1);
450  lowest_dist_int = i+1;
451  }
452  }
453  average += Pnt(Inters4.Pnt(lowest_dist_int));
454  succeeded++;
455  }
456  if (succeeded > 0)
457  {
458  cout<<"Recovery attempt of point projection on surface in given direction FAILED"<<endl;
459  return false;
460  }
461  //AssertThrow(succeeded > 0,
462  // ExcMessage("Recovery attempt of point projection on surface in given direction FAILED"));
463 
464  Pproj = Pnt(average/succeeded);
465  }
466  else
467  {
468  //cout<<"Intersections found: "<<Inters.NbPnt()<<endl;
469  Standard_Real min_distance = 1e15;
470  Standard_Real distance;
471  for (int i=0; i<Inters.NbPnt(); ++i)
472  {
473  distance = Pnt(origin).Distance(Inters.Pnt(i+1));
474  //cout<<"Point "<<i<<": "<<Pnt(Inters.Pnt(i+1))<<" distance: "<<distance<<endl;
475  if (distance < min_distance)
476  {
477  min_distance = distance;
478  Pproj = Inters.Pnt(i+1);
479  }
480  }
481  }
482 
483 // translating destination point
484  projection = Pnt(Pproj);
485 
486  return true;
487  }
488 
489 
491  const Point<3> &origin,
492  const Point<3> &assigned_axis) const
493  {
494  // translating original
495  // Point<dim> to gp point
496  gp_Pnt P0 = Pnt(origin);
497  gp_Dir axis(assigned_axis(0),assigned_axis(1),assigned_axis(2));
498  gp_Ax1 gpaxis(P0, axis);
499  gp_Lin line(gpaxis);
500 
501  // destination point
502  gp_Pnt Pproj(0.0,0.0,0.0);
503  // we prepare now the surface
504  // for the projection we get
505  // the whole shape from the
506  // iges model
507  IntCurvesFace_ShapeIntersector Inters;
508  Inters.Load(sh,tolerance);
509  Inters.Perform(line,-RealLast(),+RealLast());
510 
511  Point<3> average(0.0,0.0,0.0);
512  if (Inters.NbPnt() == 0)
513  {
514  unsigned int succeeded = 0;
515  cout<<"Axis A("<<assigned_axis <<") direction projection of point P("<<origin<<") on shape FAILED!"<<endl;
516  cout<<"Trying to fix this"<<endl;
517 
518  gp_Pnt P1 = Pnt(origin+recovery_tolerance*Point<3>(1.0,0.0,0.0));
519  gp_Ax1 gpaxis1(P1, direction);
520  gp_Lin line1(gpaxis1);
521  IntCurvesFace_ShapeIntersector Inters1;
522  Inters1.Load(sh,tolerance);
523  Inters1.Perform(line1,-RealLast(),+RealLast());
524  //AssertThrow(Inters1.NbPnt() > 0,
525  // ExcMessage("Recovery point 1 projection on surface in given direction does not exist"));
526  if (Inters1.NbPnt() > 0)
527  {
528  Standard_Real min_distance = 1e15;
529  Standard_Real distance;
530  int lowest_dist_int=0;
531  for (int i=0; i<Inters1.NbPnt(); ++i)
532  {
533  distance = Pnt(origin).Distance(Inters1.Pnt(i+1));
534  //cout<<"Point "<<i<<": "<<Pnt(Inters1.Pnt(i+1))<<" distance: "<<distance<<endl;
535  if (distance < min_distance)
536  {
537  min_distance = distance;
538  Pproj = Inters1.Pnt(i+1);
539  lowest_dist_int = i+1;
540  }
541  }
542  succeeded++;
543  average += Pnt(Inters1.Pnt(lowest_dist_int));
544  }
545 
546  gp_Pnt P2 = Pnt(origin+recovery_tolerance*Point<3>(-1.0,0.0,0.0));
547  gp_Ax1 gpaxis2(P2, direction);
548  gp_Lin line2(gpaxis2);
549  IntCurvesFace_ShapeIntersector Inters2;
550  Inters2.Load(sh,tolerance);
551  Inters2.Perform(line2,-RealLast(),+RealLast());
552  //AssertThrow(Inters2.NbPnt() > 0,
553  // ExcMessage("Recovery point 2 projection on surface in given direction does not exist"));
554  if (Inters2.NbPnt() > 0)
555  {
556  Standard_Real min_distance = 1e15;
557  Standard_Real distance;
558  int lowest_dist_int=0;
559  for (int i=0; i<Inters2.NbPnt(); ++i)
560  {
561  distance = Pnt(origin).Distance(Inters2.Pnt(i+1));
562  //cout<<"Point "<<i<<": "<<Pnt(Inters2.Pnt(i+1))<<" distance: "<<distance<<endl;
563  if (distance < min_distance)
564  {
565  min_distance = distance;
566  Pproj = Inters2.Pnt(i+1);
567  lowest_dist_int = i+1;
568  }
569  }
570  succeeded++;
571  average += Pnt(Inters2.Pnt(lowest_dist_int));
572  }
573  gp_Pnt P3 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,1.0));
574  gp_Ax1 gpaxis3(P3, direction);
575  gp_Lin line3(gpaxis3);
576  IntCurvesFace_ShapeIntersector Inters3;
577  Inters3.Load(sh,tolerance);
578  Inters3.Perform(line3,-RealLast(),+RealLast());
579  //AssertThrow(Inters3.NbPnt() > 0,
580  // ExcMessage("Recovery point 3 projection on surface in given direction does not exist"));
581  if (Inters3.NbPnt() > 0)
582  {
583  succeeded++;
584  Standard_Real min_distance = 1e15;
585  Standard_Real distance;
586  int lowest_dist_int=0;
587  for (int i=0; i<Inters3.NbPnt(); ++i)
588  {
589  distance = Pnt(origin).Distance(Inters3.Pnt(i+1));
590  //cout<<"Point "<<i<<": "<<Pnt(Inters3.Pnt(i+1))<<" distance: "<<distance<<endl;
591  if (distance < min_distance)
592  {
593  min_distance = distance;
594  Pproj = Inters3.Pnt(i+1);
595  lowest_dist_int = i+1;
596  }
597  }
598  average += Pnt(Inters3.Pnt(lowest_dist_int));
599  }
600  gp_Pnt P4 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,-1.0));
601  gp_Ax1 gpaxis4(P4, direction);
602  gp_Lin line4(gpaxis4);
603  IntCurvesFace_ShapeIntersector Inters4;
604  Inters4.Load(sh,tolerance);
605  Inters4.Perform(line4,-RealLast(),+RealLast());
606  //AssertThrow(Inters4.NbPnt() > 0,
607  // ExcMessage("Recovery point 4 projection on surface in given direction does not exist"));
608  if (Inters4.NbPnt() > 0)
609  {
610  succeeded++;
611  Standard_Real min_distance = 1e15;
612  Standard_Real distance;
613  int lowest_dist_int=0;
614  for (int i=0; i<Inters4.NbPnt(); ++i)
615  {
616  distance = Pnt(origin).Distance(Inters4.Pnt(i+1));
617  //cout<<"Point "<<i<<": "<<Pnt(Inters4.Pnt(i+1))<<" distance: "<<distance<<endl;
618  if (distance < min_distance)
619  {
620  min_distance = distance;
621  Pproj = Inters4.Pnt(i+1);
622  lowest_dist_int = i+1;
623  }
624  }
625  average += Pnt(Inters4.Pnt(lowest_dist_int));
626  }
627  if (succeeded > 0)
628  {
629  cout<<"Recovery attempt of point projection on surface in given direction FAILED"<<endl;
630  return false;
631  }
632  //AssertThrow(succeeded > 0,
633  // ExcMessage("Recovery attempt of point projection on surface in given direction FAILED"));
634 
635  Pproj = Pnt(average/succeeded);
636  }
637  else
638  {
639  //cout<<"Intersections found: "<<Inters.NbPnt()<<endl;
640  Standard_Real min_distance = 1e15;
641  Standard_Real distance;
642  for (int i=0; i<Inters.NbPnt(); ++i)
643  {
644  distance = Pnt(origin).Distance(Inters.Pnt(i+1));
645  //cout<<"Point "<<i<<": "<<Pnt(Inters.Pnt(i+1))<<" distance: "<<distance<<endl;
646  if (distance < min_distance)
647  {
648  min_distance = distance;
649  Pproj = Inters.Pnt(i+1);
650  }
651  }
652  }
653 
654 
655  //Pproj = Inters.Pnt(1);
656 // translating destination point
657  projection = Pnt(Pproj);
658  return true;
659  }
660 
661 
662 
664  Point<3> &normal,
665  double &mean_curvature,
666  const Point<3> &origin,
667  const Point<3> &assigned_axis) const
668  {
669  // translating original
670  // Point<dim> to gp point
671  gp_Pnt P0 = Pnt(origin);
672  gp_Dir axis(assigned_axis(0),assigned_axis(1),assigned_axis(2));
673  gp_Ax1 gpaxis(P0, axis);
674  gp_Lin line(gpaxis);
675 
676  // destination point, normal
677  // and mean curvature
678  gp_Pnt Pproj(0.0,0.0,0.0);
679  gp_Dir Normal;
680  Standard_Real Mean_Curvature;
681 
682  // we prepare now the surface
683  // for the projection we get
684  // the whole shape from the
685  // iges model
686  IntCurvesFace_ShapeIntersector Inters;
687  Inters.Load(sh,tolerance);
688  //Inters.Load(sh,Precision::Confusion());
689  Inters.Perform(line,-RealLast(),+RealLast());
690 
691  Point<3> average(0.0,0.0,0.0);
692  Point<3> av_normal(0.0,0.0,0.0);
693  double av_curvature = 0.0;
694  if (Inters.NbPnt() == 0)
695  {
696  unsigned int succeeded = 0;
697  cout<<"Axis A("<<assigned_axis <<") direction projection of point P("<<origin<<") on shape FAILED!"<<endl;
698  cout<<"Trying to fix this"<<endl;
699 
700 
701  gp_Pnt P1 = Pnt(origin+recovery_tolerance*Point<3>(1.0,0.0,0.0));
702  gp_Ax1 gpaxis1(P1, direction);
703  gp_Lin line1(gpaxis1);
704  IntCurvesFace_ShapeIntersector Inters1;
705  Inters1.Load(sh,tolerance);
706  Inters1.Perform(line1,-RealLast(),+RealLast());
707  //AssertThrow(Inters1.NbPnt() > 0,
708  // ExcMessage("Recovery point 1 projection on surface in given direction does not exist"));
709  if (Inters1.NbPnt() > 0)
710  {
711  succeeded++;
712  Standard_Real min_distance = 1e15;
713  Standard_Real distance;
714  int lowest_dist_int=0;
715  for (int i=0; i<Inters1.NbPnt(); ++i)
716  {
717  distance = Pnt(origin).Distance(Inters1.Pnt(i+1));
718  //cout<<"Point "<<i<<": "<<Pnt(Inters1.Pnt(i+1))<<" distance: "<<distance<<endl;
719  if (distance < min_distance)
720  {
721  min_distance = distance;
722  Pproj = Inters1.Pnt(i+1);
723  lowest_dist_int = i+1;
724  }
725  }
726  average += Pnt(Inters1.Pnt(lowest_dist_int));
727  TopoDS_Face face1 = Inters1.Face(lowest_dist_int);
728  Handle(Geom_Surface) SurfToProj1 = BRep_Tool::Surface(face1);
729  GeomLProp_SLProps props1(SurfToProj1, Inters1.UParameter(lowest_dist_int), Inters1.VParameter(lowest_dist_int), 1, tolerance);
730  gp_Dir Normal1 = props1.Normal();
731  Standard_Real Mean_Curvature1 = props1.MeanCurvature();
732  // adjusting normal orientation
733  if (face1.Orientation()==TopAbs_REVERSED)
734  {
735  Normal1.SetCoord(-1.0*Normal1.X(),-1.0*Normal1.Y(),-1.0*Normal1.Z());
736  Mean_Curvature1*=-1.0;
737  }
738  av_normal += Point<3>(Normal1.X(),Normal1.Y(),Normal1.Z());
739  av_curvature += Mean_Curvature1;
740  }
741 
742  gp_Pnt P2 = Pnt(origin+recovery_tolerance*Point<3>(-1.0,0.0,0.0));
743  gp_Ax1 gpaxis2(P2, direction);
744  gp_Lin line2(gpaxis2);
745  IntCurvesFace_ShapeIntersector Inters2;
746  Inters2.Load(sh,tolerance);
747  Inters2.Perform(line2,-RealLast(),+RealLast());
748  //AssertThrow(Inters2.NbPnt() > 0,
749  // ExcMessage("Recovery point 2 projection on surface in given direction does not exist"));
750  if (Inters2.NbPnt() > 0)
751  {
752  succeeded++;
753  Standard_Real min_distance = 1e15;
754  Standard_Real distance;
755  int lowest_dist_int=0;
756  for (int i=0; i<Inters2.NbPnt(); ++i)
757  {
758  distance = Pnt(origin).Distance(Inters2.Pnt(i+1));
759  //cout<<"Point "<<i<<": "<<Pnt(Inters2.Pnt(i+1))<<" distance: "<<distance<<endl;
760  if (distance < min_distance)
761  {
762  min_distance = distance;
763  Pproj = Inters2.Pnt(i+1);
764  lowest_dist_int = i+1;
765  }
766  }
767  average += Pnt(Inters2.Pnt(lowest_dist_int));
768  TopoDS_Face face2 = Inters2.Face(lowest_dist_int);
769  Handle(Geom_Surface) SurfToProj2 = BRep_Tool::Surface(face2);
770  GeomLProp_SLProps props2(SurfToProj2, Inters2.UParameter(lowest_dist_int), Inters2.VParameter(lowest_dist_int), 1, tolerance);
771  gp_Dir Normal2 = props2.Normal();
772  Standard_Real Mean_Curvature2 = props2.MeanCurvature();
773  // adjusting normal orientation
774  if (face2.Orientation()==TopAbs_REVERSED)
775  {
776  Normal2.SetCoord(-1.0*Normal2.X(),-1.0*Normal2.Y(),-1.0*Normal2.Z());
777  Mean_Curvature2*=-1.0;
778  }
779  av_normal += Point<3>(Normal2.X(),Normal2.Y(),Normal2.Z());
780  av_curvature += Mean_Curvature2;
781  }
782 
783  gp_Pnt P3 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,1.0));
784  gp_Ax1 gpaxis3(P3, direction);
785  gp_Lin line3(gpaxis3);
786  IntCurvesFace_ShapeIntersector Inters3;
787  Inters3.Load(sh,tolerance);
788  Inters3.Perform(line3,-RealLast(),+RealLast());
789  //AssertThrow(Inters3.NbPnt() > 0,
790  // ExcMessage("Recovery point 3 projection on surface in given direction does not exist"));
791  if (Inters3.NbPnt() > 0)
792  {
793  succeeded++;
794  Standard_Real min_distance = 1e15;
795  Standard_Real distance;
796  int lowest_dist_int=0;
797  for (int i=0; i<Inters3.NbPnt(); ++i)
798  {
799  distance = Pnt(origin).Distance(Inters3.Pnt(i+1));
800  //cout<<"Point "<<i<<": "<<Pnt(Inters3.Pnt(i+1))<<" distance: "<<distance<<endl;
801  if (distance < min_distance)
802  {
803  min_distance = distance;
804  Pproj = Inters3.Pnt(i+1);
805  lowest_dist_int = i+1;
806  }
807  }
808  average += Pnt(Inters3.Pnt(lowest_dist_int));
809  TopoDS_Face face3 = Inters3.Face(lowest_dist_int);
810  Handle(Geom_Surface) SurfToProj3 = BRep_Tool::Surface(face3);
811  GeomLProp_SLProps props3(SurfToProj3, Inters3.UParameter(lowest_dist_int), Inters3.VParameter(lowest_dist_int), 1, tolerance);
812  gp_Dir Normal3 = props3.Normal();
813  Standard_Real Mean_Curvature3 = props3.MeanCurvature();
814  // adjusting normal orientation
815  if (face3.Orientation()==TopAbs_REVERSED)
816  {
817  Normal3.SetCoord(-1.0*Normal3.X(),-1.0*Normal3.Y(),-1.0*Normal3.Z());
818  Mean_Curvature3*=-1.0;
819  }
820  av_normal += Point<3>(Normal3.X(),Normal3.Y(),Normal3.Z());
821  av_curvature += Mean_Curvature3;
822  }
823 
824  gp_Pnt P4 = Pnt(origin+recovery_tolerance*Point<3>(0.0,0.0,-1.0));
825  gp_Ax1 gpaxis4(P4, direction);
826  gp_Lin line4(gpaxis4);
827  IntCurvesFace_ShapeIntersector Inters4;
828  Inters4.Load(sh,tolerance);
829  Inters4.Perform(line4,-RealLast(),+RealLast());
830  //AssertThrow(Inters4.NbPnt() > 0,
831  // ExcMessage("Recovery point 4 projection on surface in given direction does not exist"));
832  if (Inters4.NbPnt() > 0)
833  {
834  succeeded++;
835  Standard_Real min_distance = 1e15;
836  Standard_Real distance;
837  int lowest_dist_int=0;
838  for (int i=0; i<Inters4.NbPnt(); ++i)
839  {
840  distance = Pnt(origin).Distance(Inters4.Pnt(i+1));
841  //cout<<"Point "<<i<<": "<<Pnt(Inters4.Pnt(i+1))<<" distance: "<<distance<<endl;
842  if (distance < min_distance)
843  {
844  min_distance = distance;
845  Pproj = Inters4.Pnt(i+1);
846  lowest_dist_int = i+1;
847  }
848  }
849  average += Pnt(Inters4.Pnt(lowest_dist_int));
850  TopoDS_Face face4 = Inters4.Face(lowest_dist_int);
851  Handle(Geom_Surface) SurfToProj4 = BRep_Tool::Surface(face4);
852  GeomLProp_SLProps props4(SurfToProj4, Inters4.UParameter(lowest_dist_int), Inters4.VParameter(lowest_dist_int), 1, tolerance);
853  gp_Dir Normal4 = props4.Normal();
854  Standard_Real Mean_Curvature4 = props4.MeanCurvature();
855  // adjusting normal orientation
856  if (face4.Orientation()==TopAbs_REVERSED)
857  {
858  Normal4.SetCoord(-1.0*Normal4.X(),-1.0*Normal4.Y(),-1.0*Normal4.Z());
859  Mean_Curvature4*=-1.0;
860  }
861  av_normal += Point<3>(Normal4.X(),Normal4.Y(),Normal4.Z());
862  av_curvature += Mean_Curvature4;
863  }
864  if (succeeded > 0)
865  {
866  cout<<"Recovery attempt of point projection on surface in given direction FAILED"<<endl;
867  return false;
868  }
869  //AssertThrow(succeeded > 0,
870  // ExcMessage("Recovery attempt of point projection on surface in given direction FAILED"));
871 
872  Pproj = Pnt(average/succeeded);
873  av_normal/=succeeded;
874  Normal.SetCoord(av_normal(0),av_normal(1),av_normal(2));
875  Mean_Curvature = av_curvature/succeeded;
876  }
877  else
878  {
879  //cout<<"Intersections found: "<<Inters.NbPnt()<<endl;
880  Standard_Real min_distance = 1e15;
881  Standard_Real distance;
882  int lowest_dist_int=0;
883  for (int i=0; i<Inters.NbPnt(); ++i)
884  {
885  distance = Pnt(origin).Distance(Inters.Pnt(i+1));
886  //cout<<"Point "<<i<<": "<<Pnt(Inters.Pnt(i+1))<<" distance: "<<distance<<endl;
887  if (distance < min_distance)
888  {
889  min_distance = distance;
890  Pproj = Inters.Pnt(i+1);
891  lowest_dist_int = i+1;
892  }
893  }
894  TopoDS_Face face = Inters.Face(lowest_dist_int);
895  Handle(Geom_Surface) SurfToProj = BRep_Tool::Surface(face);
896  GeomLProp_SLProps props(SurfToProj, Inters.UParameter(lowest_dist_int), Inters.VParameter(lowest_dist_int), 1, tolerance);
897  Normal = props.Normal();
898  Mean_Curvature = props.MeanCurvature();
899  // adjusting normal orientation
900  if (face.Orientation()==TopAbs_REVERSED)
901  {
902  Normal.SetCoord(-1.0*Normal.X(),-1.0*Normal.Y(),-1.0*Normal.Z());
903  Mean_Curvature*=-1.0;
904  }
905  }
906 
907 
908 // translating destination point
909  projection = Pnt(Pproj);
910 
911 // translating normal vector
912  normal(0) = Normal.X();
913  normal(1) = Normal.Y();
914  normal(2) = Normal.Z();
915 
916 // translating mean curvature
917  mean_curvature = double(Mean_Curvature);
918  return true;
919  }
920 
921 
924  {
925  Point<3> projected_point;
927  axis_projection(projected_point, source_point);
928  return projected_point;
929  }
930 
931 
934  {
935  Point<3> projected_point;
937 
938  axis_projection(projected_point, source_point);
939 
940 
941  return projected_point;
942  }
943 
945  (const Triangulation< 2,3 >::quad_iterator &quad, const Point<3> &y) const
946  {
947  Point<3> projected_point;
948  axis_projection(projected_point, y);
949 
950  return projected_point;
951  }
952 
953 
954 
955 
956 }
#define AssertThrow(cond, exc)
bool assigned_axis_projection_and_diff_forms(Point< 3 > &projection, Point< 3 > &normal, double &mean_curvature, const Point< 3 > &origin, const Point< 3 > &assigned_axis) const
bool axis_projection(Point< 3 > &projection, const Point< 3 > &origin) const
static::ExceptionBase & ExcMessage(std::string arg1)
virtual Point< 3 > get_new_point_on_quad(const Triangulation< 2, 3 >::quad_iterator &quad) const
virtual Point< spacedim > get_new_point_on_line(const typename Triangulation< dim, spacedim >::line_iterator &line) const
AxisProjection(const TopoDS_Shape &sh, Point< 3 > direction, double tolerance=1e-7, double recovery_tolerance=1e-7)
dealii::Point< 3 > Pnt(const gp_Pnt &p)
Convert OpenCascade point into.
Definition: occ_utilities.h:76
bool axis_projection_and_diff_forms(Point< 3 > &projection, Point< 3 > &normal, double &mean_curvature, const Point< 3 > &origin) const
We collect in this namespace all utilities which operate on OpenCascade entities which don't need cla...
bool assigned_axis_projection(Point< 3 > &projection, const Point< 3 > &origin, const Point< 3 > &assigned_axis) const
Handle(Geom_Curve) NumericalTowingTank
virtual Point< spacedim > get_new_point_on_quad(const typename Triangulation< dim, spacedim >::quad_iterator &quad) const
virtual Point< 3 > project_to_surface(const Triangulation< 2, 3 >::quad_iterator &quad, const Point< 3 > &y) const
virtual Point< 3 > get_new_point_on_line(const Triangulation< 2, 3 >::line_iterator &line) const