Nektar++
CADCurve.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: CAD object curve methods.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
37 
38 using namespace std;
39 
40 namespace Nektar {
41 namespace LibUtilities {
42 
43 /**
44  * @brief Default constructor.
45  */
46 CADCurve::CADCurve(int i, TopoDS_Shape in) : m_ID(i)
47 {
48  gp_Trsf transform;
49  gp_Pnt ori(0.0, 0.0, 0.0);
50  transform.SetScale(ori, 1.0 / 1000.0);
51  TopLoc_Location mv(transform);
52  in.Move(mv);
53  m_occCurve = BRepAdaptor_Curve(TopoDS::Edge(in));
54 }
55 
56 /**
57  * @brief Calculates the parametric coordinate and arclength location
58  * defined by \p s.
59  *
60  * @param s Arclength location.
61  * @return Calculated parametric coordinate.
62  *
63  * @todo This really needs improving for accuracy.
64  */
66 {
67  NekDouble dt = (m_occCurve.LastParameter() -
68  m_occCurve.FirstParameter()) / (5000);
69  NekDouble t = m_occCurve.FirstParameter();
70 
71  NekDouble len = 0.0;
72 
73  while(len <= s)
74  {
75  gp_Pnt P1,P2;
76  gp_Vec drdt1,drdt2;
77 
78  m_occCurve.D1(t,P1,drdt1);
79  t += dt;
80  m_occCurve.D1(t,P2,drdt2);
81 
82  len += (drdt1.Magnitude() + drdt2.Magnitude()) / 2.0 * dt;
83  }
84 
85  return t - dt;
86 }
87 
88 /**
89  * @brief Calculates the arclength between the two paremetric points \p ti
90  * and \p tf. \p ti must be less than \p tf.
91  *
92  * @param ti First parametric coordinate.
93  * @param tf Second parametric coordinate.
94  * @return Arc length between \p ti and \p tf.
95  */
97 {
98  NekDouble len = 0;
99  NekDouble dt = (m_occCurve.LastParameter() -
100  m_occCurve.FirstParameter()) / (1000 - 1);
101  NekDouble t = ti;
102 
103  while(t + dt <= tf)
104  {
105  gp_Pnt P1,P2;
106  gp_Vec drdt1,drdt2;
107 
108  m_occCurve.D1(t,P1,drdt1);
109  t += dt;
110  m_occCurve.D1(t,P2,drdt2);
111 
112  len += (drdt1.Magnitude() + drdt2.Magnitude()) / 2.0 * dt;
113  }
114 
115  return len;
116 }
117 
118 /**
119  * @brief Gets the location (x,y,z) in an array out of the curve at point \p t.
120  *
121  * @param t Parametric coordinate
122  * @return Array of x,y,z
123  */
125 {
126  Array<OneD, NekDouble> location(3);
127  gp_Pnt loc = m_occCurve.Value(t);
128 
129  location[0] = loc.X();
130  location[1] = loc.Y();
131  location[2] = loc.Z();
132 
133  return location;
134 }
135 
136 /**
137  * @brief Returns the minimum and maximum parametric coords t of the curve.
138  *
139  * @return Array of two entries, min and max parametric coordinate.
140  */
141 
143 {
145  t[0] = m_occCurve.FirstParameter();
146  t[1] = m_occCurve.LastParameter();
147 
148  return t;
149 }
150 
151 /**
152  * @brief Gets OpenCascade point objects for the start and end of the curve.
153  *
154  * @return Array with 6 entries of endpoints x1,y1,z1,x2,y2,z2.
155  */
156 
158 {
159  Array<OneD, NekDouble> locs(6);
160 
161  gp_Pnt start = m_occCurve.Value(m_occCurve.FirstParameter());
162  gp_Pnt end = m_occCurve.Value(m_occCurve.LastParameter());
163 
164  locs[0] = start.X();
165  locs[1] = start.Y();
166  locs[2] = start.Z();
167  locs[3] = end.X();
168  locs[4] = end.Y();
169  locs[5] = end.Z();
170 
171  return locs;
172 }
173 
174 }
175 }
Array< OneD, NekDouble > P(NekDouble t)
Gets the location (x,y,z) in an array out of the curve at point t.
Definition: CADCurve.cpp:124
Array< OneD, NekDouble > Bounds()
Returns the minimum and maximum parametric coords t of the curve.
Definition: CADCurve.cpp:142
NekDouble Length(NekDouble ti, NekDouble tf)
Calculates the arclength between the two paremetric points ti and tf. ti must be less than tf...
Definition: CADCurve.cpp:96
STL namespace.
Array< OneD, NekDouble > GetMinMax()
Gets OpenCascade point objects for the start and end of the curve.
Definition: CADCurve.cpp:157
double NekDouble
BRepAdaptor_Curve m_occCurve
OpenCascade object of the curve.
Definition: CADCurve.h:87
NekDouble tAtArcLength(NekDouble s)
Calculates the parametric coordinate and arclength location defined by s.
Definition: CADCurve.cpp:65