Nektar++
Loading...
Searching...
No Matches
CADCurveOCE.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: CADCurveOCE.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
37#include <array>
38
39using namespace std;
40
42{
43
45 "oce", CADCurveOCE::create, "CADCurveOCE");
46
47void 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 = CADUnits::FromCAD(System.Mass());
54
55 m_c = BRep_Tool::Curve(TopoDS::Edge(in), m_b[0], m_b[1]);
56 m_id = i;
57}
58
60{
61 GeomAdaptor_Curve c(m_c);
62 GCPnts_AbscissaPoint ap(c, CADUnits::ToCAD(s), m_b[0]);
63 return ap.Parameter();
64}
65
67{
68 Handle(Geom_Curve) NewCurve = new Geom_TrimmedCurve(m_c, ti, tf);
69 TopoDS_Edge NewEdge = BRepBuilderAPI_MakeEdge(NewCurve);
70 GProp_GProps System;
71 BRepGProp::LinearProperties(NewEdge, System);
72 return CADUnits::FromCAD(System.Mass());
73}
74
75NekDouble CADCurveOCE::GetMinDistance(std::array<NekDouble, 3> &xyz)
76{
77 gp_Pnt loc = CADUnits::PntToCAD(xyz);
78 GeomAPI_ProjectPointOnCurve proj(loc, m_c, m_b[0], m_b[1]);
79 if (proj.NbPoints())
80 {
81 return CADUnits::FromCAD(proj.LowerDistance());
82 }
83 else
84 {
85 return CADUnits::FromCAD(std::min(loc.Distance(m_c->Value(m_b[0])),
86 loc.Distance(m_c->Value(m_b[1]))));
87 }
88}
89
90NekDouble CADCurveOCE::loct(std::array<NekDouble, 3> xyz, NekDouble &t)
91{
92 t = 0.0;
93 gp_Pnt loc = CADUnits::PntToCAD(xyz);
94 ShapeAnalysis_Curve sac;
95 gp_Pnt p;
96 sac.Project(m_c, loc, Precision::Confusion(), p, t);
97 return CADUnits::FromCAD(p.Distance(loc));
98}
99
100// This function updates the parametric coordinate t of a cartesian point xyz
101// within the bounds of the CADCurve cf and cl ; Fixes the bug with respect to
102// Periodic CADCurves like Circles
103NekDouble CADCurveOCE::loct(std::array<NekDouble, 3> xyz, NekDouble &t,
104 NekDouble cf, NekDouble cl)
105{
106 t = 0.0;
107
108 gp_Pnt loc = CADUnits::PntToCAD(xyz);
109
110 ShapeAnalysis_Curve sac;
111 gp_Pnt p;
112 sac.Project(m_c, loc, Precision::Confusion(), p, t, cf, cl);
113
114 return CADUnits::FromCAD(p.Distance(loc));
115}
116
117std::array<NekDouble, 3> CADCurveOCE::P(NekDouble t)
118{
119 return CADUnits::PntFromCAD(m_c->Value(t));
120}
121
123{
124 auto loc = CADUnits::PntFromCAD(m_c->Value(t));
125 x = loc[0];
126 y = loc[1];
127 z = loc[2];
128}
129
130std::array<NekDouble, 9> CADCurveOCE::D2(NekDouble t)
131{
132 gp_Pnt loc;
133 gp_Vec d1, d2;
134 m_c->D2(t, loc, d1, d2);
135
136 auto l = CADUnits::PntFromCAD(loc);
137 auto a = CADUnits::VecFromCAD(d1);
138 auto b = CADUnits::VecFromCAD(d2);
139
140 return {l[0], l[1], l[2], a[0], a[1], a[2], b[0], b[1], b[2]};
141}
142
143std::array<NekDouble, 3> CADCurveOCE::N(NekDouble t)
144{
145 GeomLProp_CLProps d(m_c, 2, Precision::Confusion());
146 d.SetParameter(t + 1e-8);
147
148 gp_Vec d2 = d.D2();
149 if (d2.Magnitude() < 1e-8)
150 {
151 // no normal, stright line
152 return {0.0, 0.0, 0.0};
153 }
154
155 gp_Dir n;
156 d.Normal(n);
157
158 return {n.X(), n.Y(), n.Z()};
159}
160
162{
163 GeomLProp_CLProps d(m_c, 2, Precision::Confusion());
164 d.SetParameter(t);
165
166 return CADUnits::CurvatureFromCAD(d.Curvature());
167}
168
169std::array<NekDouble, 2> CADCurveOCE::GetBounds()
170{
171 return m_b;
172}
173
175{
176 tmin = m_b[0];
177 tmax = m_b[1];
178}
179
180std::array<NekDouble, 6> CADCurveOCE::GetMinMax()
181{
182 gp_Pnt start =
183 BRep_Tool::Pnt(TopExp::FirstVertex(m_occEdge, Standard_True));
184 gp_Pnt end = BRep_Tool::Pnt(TopExp::LastVertex(m_occEdge, Standard_True));
185
186 auto s0 = CADUnits::PntFromCAD(start);
187 auto s1 = CADUnits::PntFromCAD(end);
188
189 return {s0[0], s0[1], s0[2], s1[0], s1[1], s1[2]};
190}
191
192std::array<NekDouble, 6> CADCurveOCE::BoundingBox(NekDouble scale)
193{
194 BRepMesh_IncrementalMesh brmsh(m_occEdge, 0.005 * scale);
195
196 Bnd_Box B;
197 BRepBndLib::Add(m_occEdge, B);
198 NekDouble e = sqrt(B.SquareExtent()) * 0.01 * scale;
199 e = min(e, 5e-3 * scale);
200 B.Enlarge(e);
201
202 std::array<NekDouble, 6> ret;
203 B.Get(ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]);
204 for (auto &r : ret)
205 {
206 r = CADUnits::FromCAD(r);
207 }
208
209 return ret;
210}
211
212} // namespace Nektar::SpatialDomains
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
NekDouble m_length
Length of edge.
Definition CADCurve.h:239
std::array< NekDouble, 2 > GetBounds() override
Returns the minimum and maximum parametric coords t of the curve.
std::array< NekDouble, 3 > P(NekDouble t) override
Gets the location (x,y,z) in an array out of the curve at point t.
NekDouble GetMinDistance(std::array< NekDouble, 3 > &xyz) override
Locates a point xyz in the parametric space. returns the distance to the point.
static CADCurveSharedPtr create()
Definition CADCurveOCE.h:47
std::array< NekDouble, 6 > BoundingBox(NekDouble scale) override
Returns the bounding box of a curve enlarged by 5e-3mm * scale.
std::array< NekDouble, 6 > GetMinMax() override
Gets the start and end of the curve.
void Initialise(int i, TopoDS_Shape in)
NekDouble loct(std::array< NekDouble, 3 > xyz, NekDouble &t) override
locates a point in the parametric space. returns the distance to the point and passes t by reference ...
std::array< NekDouble, 2 > m_b
store the parametric bounds of the curve
Definition CADCurveOCE.h:93
TopoDS_Edge m_occEdge
OpenCascade edge.
Definition CADCurveOCE.h:89
NekDouble Curvature(NekDouble t) override
Calculates the radius of curvature of the curve at point t.
std::array< NekDouble, 3 > N(NekDouble t) override
Returns the normal to a curve, it will always point in the concave direction.
std::array< NekDouble, 9 > D2(NekDouble t) override
Gets the second derivatives at t.
NekDouble tAtArcLength(NekDouble s) override
Calculates the parametric coordinate and arclength location defined by s.
Handle(Geom_Curve) m_c
object used for reverse lookups
NekDouble Length(NekDouble ti, NekDouble tf) override
Calculates the arclength between the two paremetric points ti and tf. ti must be less than tf.
gp_Pnt PntToCAD(const std::array< NekDouble, 3 > &p)
A point on its way into OpenCASCADE.
Definition CADUnits.hpp:95
std::array< NekDouble, 3 > PntFromCAD(const gp_Pnt &p)
A point on its way out of OpenCASCADE.
Definition CADUnits.hpp:101
std::array< NekDouble, 3 > VecFromCAD(const gp_Vec &v)
A vector on its way out of OpenCASCADE.
Definition CADUnits.hpp:107
NekDouble CurvatureFromCAD(NekDouble curvature)
A curvature, one over a length, on its way out of OpenCASCADE.
Definition CADUnits.hpp:89
NekDouble FromCAD(NekDouble length)
A length on its way out of OpenCASCADE.
Definition CADUnits.hpp:83
NekDouble ToCAD(NekDouble length)
A length on its way into OpenCASCADE.
Definition CADUnits.hpp:77
CADCurveFactory & GetCADCurveFactory()
Definition CADSystem.cpp:54
STL namespace.
scalarT< T > min(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:299
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:289