Nektar++
CADSurf.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: CADSurf.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 surface methods.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
37 
38 using namespace std;
39 
40 namespace Nektar {
41 namespace LibUtilities {
42 
43 CADSurf::CADSurf(int i, TopoDS_Shape in,
44  vector<vector<pair<int,int> > > ein) : m_ID(i), m_edges(ein)
45 {
46  // this bit of code changes the units of the cad from mm opencascade
47  // defualt to m
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  m_s = BRep_Tool::Surface(TopoDS::Face(in));
53  in.Move(mv);
54  m_occSurface = BRepAdaptor_Surface(TopoDS::Face(in));
55 }
56 
57 /**
58  * @brief Performs a reverse look up to find u,v and x,y,z.
59  *
60  * @param p Array of xyz location
61  * @return The parametric location of xyz on this surface
62  */
64 {
65  //has to transfer back to mm
66  gp_Pnt loc(p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0);
67 
68  GeomAPI_ProjectPointOnSurf projection(loc, m_s,
69  m_occSurface.FirstUParameter(),
70  m_occSurface.LastUParameter(),
71  m_occSurface.FirstVParameter(),
72  m_occSurface.LastVParameter(),
73  Extrema_ExtAlgo_Tree);
74 
75  ASSERTL0(projection.NbPoints() > 0, "locuv failed");
76 
77  Quantity_Parameter ui;
78  Quantity_Parameter vi;
79 
80  projection.Parameters(1,ui,vi);
81 
82  /// @todo create a check so that if the calculated uv is out of bounds
83 
85  uvr[0] = ui;
86  uvr[1] = vi;
87 
88  ASSERTL1(projection.Distance(1) < NekConstants::GeomTol,
89  "large locuv distance");
90 
91  return uvr;
92 }
93 
94 /**
95  * @brief Get the x,y,z at parametric point u,v.
96  *
97  * @param uv Array of u and v parametric coords.
98  * @return Array of xyz location.
99  */
101 {
102  /// @todo create bound checking
103  Array<OneD, NekDouble> location(3);
104  gp_Pnt loc;
105  loc = m_occSurface.Value(uv[0], uv[1]);
106  location[0] = loc.X();
107  location[1] = loc.Y();
108  location[2] = loc.Z();
109  return location;
110 }
111 
112 /**
113  * @brief Get the normal vector at parametric point u,v.
114  *
115  * @param uv Array of u and v parametric coords.
116  * @return Array of xyz components of normal vector.
117  */
119 {
120  Array<OneD, NekDouble> normal(3);
121  gp_Pnt Loc;
122  gp_Vec D1U, D1V;
123  m_occSurface.D1(uv[0], uv[1], Loc, D1U, D1V);
124  gp_Vec n = D1U.Crossed(D1V);
125 
126  if (n.X() == 0 && n.Y() == 0 && n.Z() == 0)
127  {
128  // Return bad normal
129  normal[0] = 0.0;
130  normal[1] = 0.0;
131  normal[2] = 0.0;
132  }
133  else
134  {
135  n.Normalize();
136  normal[0] = n.X();
137  normal[1] = n.Y();
138  normal[2] = n.Z();
139  }
140 
141  return normal;
142 }
143 
144 /**
145  * @brief Get the set of first derivatives at parametric point u,v
146  *
147  * @param uv Array of u and v parametric coords.
148  * @return Array of xyz copmonents of first derivatives.
149  */
150 
152 {
154  gp_Pnt Loc;
155  gp_Vec D1U, D1V;
156  m_occSurface.D1(uv[0], uv[1], Loc, D1U, D1V);
157 
158  r[0] = Loc.X(); //x
159  r[1] = Loc.Y(); //y
160  r[2] = Loc.Z(); //z
161  r[3] = D1U.X(); //dx/du
162  r[4] = D1U.Y(); //dy/du
163  r[5] = D1U.Z(); //dz/du
164  r[6] = D1V.X(); //dx/dv
165  r[7] = D1V.Y(); //dy/dv
166  r[8] = D1V.Z(); //dz/dv
167 
168  return r;
169 }
170 
171 /**
172  * @brief Get the set of second derivatives at parametric point u,v
173  *
174  * @param uv array of u and v parametric coords
175  * @return array of xyz copmonents of second derivatives
176  */
177 
179 {
181  gp_Pnt Loc;
182  gp_Vec D1U, D1V, D2U, D2V, D2UV;
183  m_occSurface.D2(uv[0], uv[1], Loc, D1U, D1V, D2U, D2V, D2UV);
184 
185  r[0] = Loc.X(); //x
186  r[1] = Loc.Y(); //y
187  r[2] = Loc.Z(); //z
188  r[3] = D1U.X(); //dx/dx
189  r[4] = D1U.Y(); //dy/dy
190  r[5] = D1U.Z(); //dz/dz
191  r[6] = D1V.X(); //dx/dx
192  r[7] = D1V.Y(); //dy/dy
193  r[8] = D1V.Z(); //dz/dz
194  r[9] = D2U.X(); //d2x/du2
195  r[10] = D2U.Y(); //d2y/du2
196  r[11] = D2U.Z(); //d2z/du2
197  r[12] = D2V.X(); //d2x/dv2
198  r[13] = D2V.Y(); //d2y/dv2
199  r[14] = D2V.Z(); //d2z/dv2
200  r[15] = D2UV.X(); //d2x/dudv
201  r[16] = D2UV.Y(); //d2y/dudv
202  r[17] = D2UV.Z(); //d2z/dudv
203 
204  return r;
205 }
206 
207 }
208 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
Array< OneD, NekDouble > D1(Array< OneD, NekDouble > uv)
Get the set of first derivatives at parametric point u,v.
Definition: CADSurf.cpp:151
STL namespace.
Array< OneD, NekDouble > locuv(Array< OneD, NekDouble > p)
Performs a reverse look up to find u,v and x,y,z.
Definition: CADSurf.cpp:63
Array< OneD, NekDouble > P(Array< OneD, NekDouble > uv)
Get the x,y,z at parametric point u,v.
Definition: CADSurf.cpp:100
Array< OneD, NekDouble > N(Array< OneD, NekDouble > uv)
Get the normal vector at parametric point u,v.
Definition: CADSurf.cpp:118
BRepAdaptor_Surface m_occSurface
OpenCascade object for surface.
Definition: CADSurf.h:102
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191
Array< OneD, NekDouble > D2(Array< OneD, NekDouble > uv)
Get the set of second derivatives at parametric point u,v.
Definition: CADSurf.cpp:178
static const NekDouble GeomTol