Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 {
42 namespace NekMeshUtils
43 {
44 
45 CADCurve::CADCurve(int i, TopoDS_Shape in)
46 {
47  gp_Trsf transform;
48  gp_Pnt ori(0.0, 0.0, 0.0);
49  transform.SetScale(ori, 1.0 / 1000.0);
50  TopLoc_Location mv(transform);
51  in.Move(mv);
52 
53  m_occEdge = TopoDS::Edge(in);
54  m_occCurve = BRepAdaptor_Curve(m_occEdge);
55 
56  GProp_GProps System;
57  BRepGProp::LinearProperties(m_occEdge, System);
58  m_length = System.Mass();
59 
60  m_id = i;
61  m_type = curve;
62 }
63 
64 NekDouble CADCurve::tAtArcLength(NekDouble s)
65 {
66  NekDouble dt =
67  (m_occCurve.LastParameter() - m_occCurve.FirstParameter()) / (5000);
68  NekDouble t = m_occCurve.FirstParameter();
69 
70  NekDouble len = 0.0;
71 
72  while (len <= s)
73  {
74  gp_Pnt P1, P2;
75  gp_Vec drdt1, drdt2;
76 
77  m_occCurve.D1(t, P1, drdt1);
78  t += dt;
79  m_occCurve.D1(t, P2, drdt2);
80 
81  len += (drdt1.Magnitude() + drdt2.Magnitude()) / 2.0 * dt;
82  }
83 
84  return t - dt;
85 }
86 
87 NekDouble CADCurve::Length(NekDouble ti, NekDouble tf)
88 {
89  Array<OneD, NekDouble> b = Bounds();
90  Handle(Geom_Curve) m_c = BRep_Tool::Curve(m_occEdge, b[0], b[1]);
91  Handle(Geom_Curve) NewCurve = new Geom_TrimmedCurve(m_c, ti, tf);
92  TopoDS_Edge NewEdge = BRepBuilderAPI_MakeEdge(NewCurve);
93  GProp_GProps System;
94  BRepGProp::LinearProperties(NewEdge, System);
95  return System.Mass() / 1000.0;
96 }
97 
99 {
100  Array<OneD, NekDouble> location(3);
101  gp_Pnt loc = m_occCurve.Value(t);
102 
103  location[0] = loc.X();
104  location[1] = loc.Y();
105  location[2] = loc.Z();
106 
107  return location;
108 }
109 
111 {
112  Array<OneD, NekDouble> out(9);
113  gp_Pnt loc;
114  gp_Vec d1, d2;
115  m_occCurve.D2(t, loc, d1, d2);
116 
117  out[0] = loc.X();
118  out[1] = loc.Y();
119  out[2] = loc.Z();
120  out[3] = d1.X();
121  out[4] = d1.Y();
122  out[5] = d1.Z();
123  out[6] = d2.X();
124  out[7] = d2.Y();
125  out[8] = d2.Z();
126 
127  return out;
128 }
129 
130 Array<OneD, NekDouble> CADCurve::Bounds()
131 {
133  t[0] = m_occCurve.FirstParameter();
134  t[1] = m_occCurve.LastParameter();
135 
136  return t;
137 }
138 
139 Array<OneD, NekDouble> CADCurve::GetMinMax()
140 {
141  Array<OneD, NekDouble> locs(6);
142 
143  gp_Pnt start =
144  BRep_Tool::Pnt(TopExp::FirstVertex(m_occEdge, Standard_True));
145  gp_Pnt end = BRep_Tool::Pnt(TopExp::LastVertex(m_occEdge, Standard_True));
146 
147  locs[0] = start.X();
148  locs[1] = start.Y();
149  locs[2] = start.Z();
150  locs[3] = end.X();
151  locs[4] = end.Y();
152  locs[5] = end.Z();
153 
154  return locs;
155 }
156 }
157 }
STL namespace.
double NekDouble