CADCurveOCE.cpp 4.75 KB
Newer Older
1 2
////////////////////////////////////////////////////////////////////////////////
//
Michael Turner's avatar
Michael Turner committed
3
//  File: CADCurve.cpp
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
//
//  For more information, please see: http://www.nektar.info/
//
//  The MIT License
//
//  Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
//  Department of Aeronautics, Imperial College London (UK), and Scientific
//  Computing and Imaging Institute, University of Utah (USA).
//
//  License for the specific language governing rights and limitations under
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included
//  in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
//  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//
Michael Turner's avatar
Michael Turner committed
32
//  Description: CAD object curve methods.
33 34 35
//
////////////////////////////////////////////////////////////////////////////////

36
#include <NekMeshUtils/CADSystem/OCE/CADCurveOCE.h>
37 38

using namespace std;
39

40 41
namespace Nektar
{
42
namespace NekMeshUtils
43
{
44

45 46
std::string CADCurveOCE::key = GetCADCurveFactory().RegisterCreatorFunction(
    "oce", CADCurveOCE::create, "CADCurveOCE");
Michael Turner's avatar
Michael Turner committed
47

48 49 50 51 52 53
void CADCurveOCE::Initialise(int i, TopoDS_Shape in)
{
    m_occEdge = TopoDS::Edge(in);

    GProp_GProps System;
    BRepGProp::LinearProperties(m_occEdge, System);
mt4313's avatar
mt4313 committed
54
    m_length = System.Mass() / 1000.0;
55 56 57 58 59 60 61

    m_b = Array<OneD, NekDouble>(2);
    m_c = BRep_Tool::Curve(TopoDS::Edge(in), m_b[0], m_b[1]);

    m_id = i;
}

mike's avatar
mike committed
62
NekDouble CADCurveOCE::tAtArcLength(NekDouble s)
Michael Turner's avatar
Michael Turner committed
63
{
Michael Turner's avatar
Michael Turner committed
64 65 66
    GeomAdaptor_Curve c(m_c);
    GCPnts_AbscissaPoint ap(c, s*1000.0, m_b[0]);
    return ap.Parameter();
Michael Turner's avatar
Michael Turner committed
67
}
68

mike's avatar
mike committed
69
NekDouble CADCurveOCE::Length(NekDouble ti, NekDouble tf)
Michael Turner's avatar
Michael Turner committed
70
{
71
    Handle(Geom_Curve) NewCurve = new Geom_TrimmedCurve(m_c, ti, tf);
72
    TopoDS_Edge NewEdge         = BRepBuilderAPI_MakeEdge(NewCurve);
73
    GProp_GProps System;
74
    BRepGProp::LinearProperties(NewEdge, System);
mt4313's avatar
mt4313 committed
75
    return System.Mass() / 1000.0;
Michael Turner's avatar
Michael Turner committed
76
}
77

cadfix's avatar
cadfix committed
78
NekDouble CADCurveOCE::loct(Array<OneD, NekDouble> xyz, NekDouble &t)
Michael Turner's avatar
Michael Turner committed
79
{
cadfix's avatar
cadfix committed
80
    t = 0.0;
Michael Turner's avatar
Michael Turner committed
81

mt4313's avatar
mt4313 committed
82
    gp_Pnt loc(xyz[0] * 1000.0, xyz[1] * 1000.0, xyz[2] * 1000.0);
Michael Turner's avatar
Michael Turner committed
83 84 85

    ShapeAnalysis_Curve sac;
    gp_Pnt p;
mt4313's avatar
mt4313 committed
86
    sac.Project(m_c, loc, Precision::Confusion(), p, t);
Michael Turner's avatar
Michael Turner committed
87

mt4313's avatar
mt4313 committed
88
    return p.Distance(loc) / 1000.0;
's avatar
committed
89 90
}

mike's avatar
mike committed
91
Array<OneD, NekDouble> CADCurveOCE::P(NekDouble t)
Michael Turner's avatar
Michael Turner committed
92 93
{
    Array<OneD, NekDouble> location(3);
94
    gp_Pnt loc = m_c->Value(t);
95

mt4313's avatar
mt4313 committed
96 97 98
    location[0] = loc.X()/1000.0;
    location[1] = loc.Y()/1000.0;
    location[2] = loc.Z()/1000.0;
99

Michael Turner's avatar
Michael Turner committed
100 101
    return location;
}
102

mike's avatar
mike committed
103
Array<OneD, NekDouble> CADCurveOCE::D2(NekDouble t)
104 105 106 107
{
    Array<OneD, NekDouble> out(9);
    gp_Pnt loc;
    gp_Vec d1, d2;
108 109
    m_c->D2(t, loc, d1, d2);

mt4313's avatar
mt4313 committed
110 111 112 113 114 115 116 117 118
    out[0] = loc.X()/1000.0;
    out[1] = loc.Y()/1000.0;
    out[2] = loc.Z()/1000.0;
    out[3] = d1.X()/1000.0;
    out[4] = d1.Y()/1000.0;
    out[5] = d1.Z()/1000.0;
    out[6] = d2.X()/1000.0;
    out[7] = d2.Y()/1000.0;
    out[8] = d2.Z()/1000.0;
119 120 121 122

    return out;
}

Michael Turner's avatar
Michael Turner committed
123 124
Array<OneD, NekDouble> CADCurveOCE::N(NekDouble t)
{
mt4313's avatar
mt4313 committed
125
    GeomLProp_CLProps d(m_c, 2, Precision::Confusion());
126
    d.SetParameter(t + 1e-8);
Michael Turner's avatar
Michael Turner committed
127 128

    gp_Vec d2 = d.D2();
129
    if (d2.Magnitude() < 1e-8)
Michael Turner's avatar
Michael Turner committed
130
    {
131 132
        // no normal, stright line
        return Array<OneD, NekDouble>(3, 0.0);
Michael Turner's avatar
Michael Turner committed
133 134 135 136 137 138 139 140 141 142 143 144 145
    }

    gp_Dir n;
    d.Normal(n);

    Array<OneD, NekDouble> N(3);
    N[0] = n.X();
    N[1] = n.Y();
    N[2] = n.Z();

    return N;
}

146 147
NekDouble CADCurveOCE::Curvature(NekDouble t)
{
mt4313's avatar
mt4313 committed
148
    GeomLProp_CLProps d(m_c, 2, Precision::Confusion());
Michael Turner's avatar
working  
Michael Turner committed
149
    d.SetParameter(t);
150

mt4313's avatar
mt4313 committed
151
    return d.Curvature() * 1000.0;
152 153
}

mike turner's avatar
mike turner committed
154
Array<OneD, NekDouble> CADCurveOCE::GetBounds()
Michael Turner's avatar
Michael Turner committed
155
{
156
    return m_b;
Michael Turner's avatar
Michael Turner committed
157
}
158

mike's avatar
mike committed
159
Array<OneD, NekDouble> CADCurveOCE::GetMinMax()
Michael Turner's avatar
Michael Turner committed
160 161 162
{
    Array<OneD, NekDouble> locs(6);

163 164 165
    gp_Pnt start =
        BRep_Tool::Pnt(TopExp::FirstVertex(m_occEdge, Standard_True));
    gp_Pnt end = BRep_Tool::Pnt(TopExp::LastVertex(m_occEdge, Standard_True));
166

mt4313's avatar
mt4313 committed
167 168 169 170 171 172
    locs[0] = start.X()/1000.0;
    locs[1] = start.Y()/1000.0;
    locs[2] = start.Z()/1000.0;
    locs[3] = end.X()/1000.0;
    locs[4] = end.Y()/1000.0;
    locs[5] = end.Z()/1000.0;
Michael Turner's avatar
Michael Turner committed
173

174
    return locs;
Michael Turner's avatar
Michael Turner committed
175
}
176
}
Michael Turner's avatar
Michael Turner committed
177
}