42 namespace NekMeshUtils
46 "oce", CADSurfOCE::create,
"CADSurfOCE");
48 void CADSurfOCE::Initialise(
int i, TopoDS_Shape in)
53 m_s = BRep_Tool::Surface(TopoDS::Face(in));
55 if (in.Orientation() == 1)
61 gp_Pnt ori(0.0, 0.0, 0.0);
62 transform.SetScale(ori, 1.0 / 1000.0);
63 TopLoc_Location mv(transform);
66 m_occSurface = BRepAdaptor_Surface(TopoDS::Face(in));
70 BRepTools::UVBounds(TopoDS::Face(in), m_bounds[0], m_bounds[1], m_bounds[2],
72 m_sas =
new ShapeAnalysis_Surface(m_s);
73 m_sas->SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
84 gp_Pnt loc(p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0);
88 gp_Pnt2d p2 = m_sas->ValueOfUV(loc, 1e-3);
92 gp_Pnt p3 = m_sas->Value(p2);
93 WARNINGL2(p3.Distance(loc) < 1e-3,
"large locuv distance " +
94 boost::lexical_cast<
string>(p3.Distance(loc)/1000.0) +
" " +
95 boost::lexical_cast<
string>(m_id));
99 if (uvr[0] < m_bounds[0] || uvr[0] > m_bounds[1] || uvr[1] < m_bounds[2] ||
100 uvr[1] > m_bounds[3])
102 if (uvr[0] < m_bounds[0])
104 uvr[0] = m_bounds[0];
106 else if (uvr[0] > m_bounds[1])
108 uvr[0] = m_bounds[1];
110 else if (uvr[1] < m_bounds[2])
112 uvr[1] = m_bounds[2];
114 else if (uvr[1] > m_bounds[3])
116 uvr[1] = m_bounds[3];
120 ASSERTL0(
false,
"Cannot correct locuv");
129 #if defined(NEKTAR_DEBUG)
137 if (n[0] == 0 && n[1] == 0 && n[2] == 0)
145 NekDouble E = r[3] * r[3] + r[4] * r[4] + r[5] * r[5];
146 NekDouble F = r[3] * r[6] + r[4] * r[7] + r[5] * r[8];
147 NekDouble G = r[6] * r[6] + r[7] * r[7] + r[8] * r[8];
148 NekDouble e = n[0] * r[9] + n[1] * r[10] + n[2] * r[11];
149 NekDouble f = n[0] * r[15] + n[1] * r[16] + n[2] * r[17];
150 NekDouble g = n[0] * r[12] + n[1] * r[13] + n[2] * r[14];
153 if (E * G - F * F < 1E-30)
160 K = (e * g - f * f) / (E * G - F * F);
161 H = 0.5 * (e * G - 2 * f * F + g * E) / (E * G - F * F);
164 kv[0] = abs(H + sqrt(H * H - K));
165 kv[1] = abs(H - sqrt(H * H - K));
167 return kv[0] > kv[1] ? kv[0] : kv[1];
172 gp_Pnt loc(p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0);
175 ShapeAnalysis_Surface sas(m_s);
176 sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
178 gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
180 gp_Pnt p3 = sas.Value(p2);
182 return p3.Distance(loc);
188 gp_Pnt loc(tp[0] * 1000.0, tp[1] * 1000.0, tp[2] * 1000.0);
191 ShapeAnalysis_Surface sas(m_s);
192 sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
194 gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
196 gp_Pnt p3 = sas.Value(p2);
198 tp[0] = p3.X() / 1000.0;
199 tp[1] = p3.Y() / 1000.0;
200 tp[2] = p3.Z() / 1000.0;
208 #if defined(NEKTAR_DEBUG)
214 loc = m_occSurface.Value(uv[0], uv[1]);
215 location[0] = loc.X();
216 location[1] = loc.Y();
217 location[2] = loc.Z();
223 #if defined(NEKTAR_DEBUG)
227 BRepLProp_SLProps slp(m_occSurface, 2, 1e-6);
228 slp.SetParameters(uv[0], uv[1]);
230 if (!slp.IsNormalDefined())
235 gp_Dir d = slp.Normal();
253 #if defined(NEKTAR_DEBUG)
260 m_occSurface.D1(uv[0], uv[1], Loc, D1U, D1V);
277 #if defined(NEKTAR_DEBUG)
283 gp_Vec D1U, D1V, D2U, D2V, D2UV;
284 m_occSurface.D2(uv[0], uv[1], Loc, D1U, D1V, D2U, D2V, D2UV);
312 error <<
"Point not within parameter plane: ";
316 if (uv[0] < m_bounds[0])
318 if (fabs(uv[0] - m_bounds[0]) > 1E-6)
320 error <<
"U(" << uv[0] <<
") is less than Umin(" << m_bounds[0]
325 else if (uv[0] > m_bounds[1])
327 if (fabs(uv[0] - m_bounds[1]) > 1E-6)
329 error <<
"U(" << uv[0] <<
") is greater than Umax(" << m_bounds[1]
334 else if (uv[1] < m_bounds[2])
336 if (fabs(uv[1] - m_bounds[2]) > 1E-6)
338 error <<
"V(" << uv[1] <<
") is less than Vmin(" << m_bounds[2]
343 else if (uv[1] > m_bounds[3])
345 if (fabs(uv[1] - m_bounds[3]) > 1E-6)
347 error <<
"V(" << uv[1] <<
") is greater than Vmax(" << m_bounds[3]
353 error <<
" On Surface: " << GetId();
354 ASSERTL1(passed,
"Warning: " + error.str());
#define ASSERTL0(condition, msg)
CADSurfFactory & GetCADSurfFactory()
#define WARNINGL2(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.