Nektar++
CADCurveOCE.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: CADCurve.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: CAD object curve methods.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
36 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 namespace NekMeshUtils
42 {
43 
44 std::string CADCurveOCE::key = GetCADCurveFactory().RegisterCreatorFunction(
45  "oce", CADCurveOCE::create, "CADCurveOCE");
46 
47 void CADCurveOCE::Initialise(int i, TopoDS_Shape in)
48 {
49  m_occEdge = TopoDS::Edge(in);
50 
51  GProp_GProps System;
52  BRepGProp::LinearProperties(m_occEdge, System);
53  m_length = System.Mass() / 1000.0;
54 
55  m_b = Array<OneD, NekDouble>(2);
56  m_c = BRep_Tool::Curve(TopoDS::Edge(in), m_b[0], m_b[1]);
57 
58  m_id = i;
59 }
60 
61 NekDouble CADCurveOCE::tAtArcLength(NekDouble s)
62 {
63  GeomAdaptor_Curve c(m_c);
64  GCPnts_AbscissaPoint ap(c, s * 1000.0, m_b[0]);
65  return ap.Parameter();
66 }
67 
68 NekDouble CADCurveOCE::Length(NekDouble ti, NekDouble tf)
69 {
70  Handle(Geom_Curve) NewCurve = new Geom_TrimmedCurve(m_c, ti, tf);
71  TopoDS_Edge NewEdge = BRepBuilderAPI_MakeEdge(NewCurve);
72  GProp_GProps System;
73  BRepGProp::LinearProperties(NewEdge, System);
74  return System.Mass() / 1000.0;
75 }
76 
77 NekDouble CADCurveOCE::loct(Array<OneD, NekDouble> xyz, NekDouble &t)
78 {
79  t = 0.0;
80 
81  gp_Pnt loc(xyz[0] * 1000.0, xyz[1] * 1000.0, xyz[2] * 1000.0);
82 
83  ShapeAnalysis_Curve sac;
84  gp_Pnt p;
85  sac.Project(m_c, loc, Precision::Confusion(), p, t);
86 
87  return p.Distance(loc) / 1000.0;
88 }
89 
91 {
92  Array<OneD, NekDouble> location(3);
93  gp_Pnt loc = m_c->Value(t);
94 
95  location[0] = loc.X() / 1000.0;
96  location[1] = loc.Y() / 1000.0;
97  location[2] = loc.Z() / 1000.0;
98 
99  return location;
100 }
101 
103 {
104  gp_Pnt loc = m_c->Value(t);
105 
106  x = loc.X() / 1000.0;
107  y = loc.Y() / 1000.0;
108  z = loc.Z() / 1000.0;
109 }
110 
112 {
113  Array<OneD, NekDouble> out(9);
114  gp_Pnt loc;
115  gp_Vec d1, d2;
116  m_c->D2(t, loc, d1, d2);
117 
118  out[0] = loc.X() / 1000.0;
119  out[1] = loc.Y() / 1000.0;
120  out[2] = loc.Z() / 1000.0;
121  out[3] = d1.X() / 1000.0;
122  out[4] = d1.Y() / 1000.0;
123  out[5] = d1.Z() / 1000.0;
124  out[6] = d2.X() / 1000.0;
125  out[7] = d2.Y() / 1000.0;
126  out[8] = d2.Z() / 1000.0;
127 
128  return out;
129 }
130 
132 {
133  GeomLProp_CLProps d(m_c, 2, Precision::Confusion());
134  d.SetParameter(t + 1e-8);
135 
136  gp_Vec d2 = d.D2();
137  if (d2.Magnitude() < 1e-8)
138  {
139  // no normal, stright line
140  return Array<OneD, NekDouble>(3, 0.0);
141  }
142 
143  gp_Dir n;
144  d.Normal(n);
145 
147  N[0] = n.X();
148  N[1] = n.Y();
149  N[2] = n.Z();
150 
151  return N;
152 }
153 
154 NekDouble CADCurveOCE::Curvature(NekDouble t)
155 {
156  GeomLProp_CLProps d(m_c, 2, Precision::Confusion());
157  d.SetParameter(t);
158 
159  return d.Curvature() * 1000.0;
160 }
161 
162 Array<OneD, NekDouble> CADCurveOCE::GetBounds()
163 {
164  return m_b;
165 }
166 
167 void CADCurveOCE::GetBounds(NekDouble &tmin, NekDouble &tmax)
168 {
169  tmin = m_b[0];
170  tmax = m_b[1];
171 }
172 
173 Array<OneD, NekDouble> CADCurveOCE::GetMinMax()
174 {
175  Array<OneD, NekDouble> locs(6);
176 
177  gp_Pnt start =
178  BRep_Tool::Pnt(TopExp::FirstVertex(m_occEdge, Standard_True));
179  gp_Pnt end = BRep_Tool::Pnt(TopExp::LastVertex(m_occEdge, Standard_True));
180 
181  locs[0] = start.X() / 1000.0;
182  locs[1] = start.Y() / 1000.0;
183  locs[2] = start.Z() / 1000.0;
184  locs[3] = end.X() / 1000.0;
185  locs[4] = end.Y() / 1000.0;
186  locs[5] = end.Z() / 1000.0;
187 
188  return locs;
189 }
190 }
191 }
CADCurveFactory & GetCADCurveFactory()
Definition: CADSystem.cpp:59
STL namespace.
double NekDouble
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199