WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
occ_arclength_projection.cc
Go to the documentation of this file.
2 
3 
4 #include <iostream>
5 #include <TopoDS.hxx>
6 #include <TopoDS_Shape.hxx>
7 #include <TopoDS_Shell.hxx>
8 #include <TopoDS_Face.hxx>
9 #include <BRepTools.hxx>
10 #include <TopTools_SequenceOfShape.hxx>
11 #include <Handle_Standard_Transient.hxx>
12 #include <TColStd_SequenceOfTransient.hxx>
13 #include <TColStd_HSequenceOfTransient.hxx>
14 #include <TopExp_Explorer.hxx>
15 #include <gp_Pnt.hxx>
16 #include <gp_Vec.hxx>
17 #include <GeomAPI_ProjectPointOnSurf.hxx>
18 #include <GeomAPI_ProjectPointOnCurve.hxx>
19 #include <Standard_Real.hxx>
20 #include <Standard_Integer.hxx>
21 #include <BRep_Tool.hxx>
22 #include <Geom_Surface.hxx>
23 #include <Geom_Plane.hxx>
24 #include <Prs3d_ShapeTool.hxx>
25 #include <Bnd_Box.hxx>
26 #include <gp_Ax3.hxx>
27 #include <gp_Pln.hxx>
28 #include <BRepBuilderAPI_MakeFace.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <GeomAPI_IntSS.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <BRepBuilderAPI_MakePolygon.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_BoundedCurve.hxx>
35 #include <Geom_TrimmedCurve.hxx>
36 #include <TColGeom_Array1OfCurve.hxx>
37 #include <GeomAPI_IntCS.hxx>
38 #include <BRepBuilderAPI_MakeEdge.hxx>
39 #include <GeomLib_Tool.hxx>
40 #include <GCPnts_AbscissaPoint.hxx>
41 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
42 #include <ShapeAnalysis_Curve.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <vector>
45 #define FALSE 0
46 #define TRUE 1
47 
48 
51 
52 
53 namespace OpenCascade
54 {
55 
57  double tolerance) :
58  sh(sh),
59  tolerance(tolerance)
60  {
61  // Check that we have at most
62  // one edge.
63  TopExp_Explorer edgeExplorer(sh , TopAbs_EDGE);
64  unsigned int n_edges = 0;
65  while (edgeExplorer.More())
66  {
67  n_edges++;
68  edgeExplorer.Next();
69  }
70  AssertThrow(n_edges == 1, ExcMessage("We can do this only "
71  "on a single edge: "
72  "split your geometry."));
73 
74  }
75 
77  (const Point<3> &p0, const Point<3> &p1, const double distance) const
78  {
79 
80  //cout<<p0<<" --"<<distance<<"-- "<<p1<<endl;
81  Point<3> projected_point;
82 
83  Assert((0. <= distance) &&
84  (distance <= 1.),
85  ExcMessage("Distance should be between 0. and 1."));
86 
87  gp_Pnt P0(p0(0),p0(1),p0(2));
88  gp_Pnt P1(p1(0),p1(1),p1(2));
89 
90  TopExp_Explorer edgeExplorer(sh , TopAbs_EDGE);
91  TopoDS_Edge edge;
92  edgeExplorer.More();
93  edge = TopoDS::Edge(edgeExplorer.Current());
94  TopLoc_Location L = sh.Location();
95  edge.Location(L);
96  Standard_Real First;
97  Standard_Real Last;
98 
99 
100  // the projection function
101  // needs a curve, so we
102  // obtain the curve upon
103  // which the edge is defined
104  BRepAdaptor_Curve gg_curve(edge);
105  First = gg_curve.FirstParameter();
106  Last = gg_curve.LastParameter();
107  //Handle(Geom_Curve) g_curve = BRep_Tool::Curve(edge,L,First,Last);
108 
109 
110  //gp_Trsf L_transformation = this->sh.Location().Transformation();
111  //TopLoc_Location L_inv = L.Inverted();
112  //gp_Trsf L_inv_transformation = L_inv.Transformation();
113  //P0.Transform(L_inv_transformation);
114  //P1.Transform(L_inv_transformation);
115  //cout<<P0.X()<<" "<<P0.Y()<<" "<<P0.Z()<<" --"<<distance<<"-- "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z()<<endl;
116  Standard_Real t0;
117  Standard_Real t1;
118  Standard_Real t2;
119 
120 
121  gp_Pnt proj;
122  ShapeAnalysis_Curve curve_analysis;
123 
124  double off = curve_analysis.Project(gg_curve, P0, tolerance, proj, t0, Standard_True);
125  AssertThrow( (off < 1000*tolerance), ExcMessage("Point of the edge to be refined is not on curve."));
126  off = curve_analysis.Project(gg_curve, P1, tolerance, proj, t1, Standard_True);
127  AssertThrow( (off < 1000*tolerance), ExcMessage("Point of the edge to be refined is not on curve."));
128 
129  //cout<<"First: "<<First<<" Last: "<<Last<<endl;
130  //cout<<"P0: "<<p0<<" ("<<t0<<") vs P1: "<<p1<<" ("<<t1<<")"<<endl;
131 
132  //GeomLib_Tool tool;
133  //tool.Parameter(gg_curve, P0, tolerance, t0);
134  //tool.Parameter(gg_curve, P1, tolerance, t1);
135 
136  //Check that we are in the right
137  //range.
138  AssertThrow((First-1000*tolerance <= t0) &&
139  (t0 <= Last+1000*tolerance),
140  ExcMessage("Parameter 1 is out of range!"));
141  AssertThrow((First-1000*tolerance <= t1) &&
142  (t1 <= Last+1000*tolerance),
143  ExcMessage("Parameter 2 is out of range!"));
144 
145 
146  // we now get the mean
147  // curvilinear distance point
148  //cout<<endl;
149  //cout<<"Points "<<p0<<" vs "<<p1<<endl;
150  //cout<<"Params "<<t0<<" vs "<<t1<<endl;
151  double direction = t1 > t0 ? 1.0 : -1.0;
152  //cout<<"Direction "<<direction<<endl;
153  //GeomAdaptor_Curve AC(g_curve);
154  Standard_Real arcLength = GCPnts_AbscissaPoint::Length(gg_curve,t0,t1);
155  //cout<<"arcLength "<<arcLength<<endl;
156  GCPnts_AbscissaPoint AP(gg_curve, direction*arcLength*distance, t0);
157  //cout<<"direction*arcLength*distance "<<direction*arcLength*distance<<endl;
158  t2 = AP.Parameter();
159 
160  AssertThrow((First <= t2) &&
161  (t2 <= Last),
162  ExcMessage("Parameter 3 is out of range!"));
163 
164 
165  gp_Pnt P2 = gg_curve.Value(t2);
166  //cout<<"new_point "<<P2.X()<<" "<<P2.Y()<<" "<<P2.Z()<<endl;
167  //P2.Transform(L_transformation);
168  //cout<<"new_point re-located "<<P2.X()<<" "<<P2.Y()<<" "<<P2.Z()<<endl;
169 
170  projected_point(0) = P2.X();
171  projected_point(1) = P2.Y();
172  projected_point(2) = P2.Z();
173 
174  return projected_point;
175  }
176 
179  {
180  //cout<<"V1: "<<line->vertex(0)<<" V2: "<<line->vertex(1)<<" NP: "<<arclength_projection(line->vertex(0), line->vertex(1))<<endl;
181  return arclength_projection(line->vertex(0), line->vertex(1));
182  }
183 
184 }
virtual Point< 3 > get_new_point_on_line(const Triangulation< 2, 3 >::line_iterator &line) const
Point< 3 > arclength_projection(const Point< 3 > &p0, const Point< 3 > &p1, const double distance=.5) const
#define AssertThrow(cond, exc)
static::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
ArclengthProjection(const TopoDS_Shape &sh, double tolerance=1e-7)
We collect in this namespace all utilities which operate on OpenCascade entities which don't need cla...