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 if (p3.Distance(loc) > 1.0)
95 cout <<
"large locuv distance " << p3.Distance(loc) <<
" " << m_id
101 if (uvr[0] < m_bounds[0] || uvr[0] > m_bounds[1] || uvr[1] < m_bounds[2] ||
102 uvr[1] > m_bounds[3])
104 if (uvr[0] < m_bounds[0])
106 uvr[0] = m_bounds[0];
108 else if (uvr[0] > m_bounds[1])
110 uvr[0] = m_bounds[1];
112 else if (uvr[1] < m_bounds[2])
114 uvr[1] = m_bounds[2];
116 else if (uvr[1] > m_bounds[3])
118 uvr[1] = m_bounds[3];
122 ASSERTL0(
false,
"Cannot correct locuv");
131 #if defined(NEKTAR_DEBUG)
139 if (n[0] == 0 && n[1] == 0 && n[2] == 0)
147 NekDouble E = r[3] * r[3] + r[4] * r[4] + r[5] * r[5];
148 NekDouble F = r[3] * r[6] + r[4] * r[7] + r[5] * r[8];
149 NekDouble G = r[6] * r[6] + r[7] * r[7] + r[8] * r[8];
150 NekDouble e = n[0] * r[9] + n[1] * r[10] + n[2] * r[11];
151 NekDouble f = n[0] * r[15] + n[1] * r[16] + n[2] * r[17];
152 NekDouble g = n[0] * r[12] + n[1] * r[13] + n[2] * r[14];
155 if (E * G - F * F < 1E-30)
162 K = (e * g - f * f) / (E * G - F * F);
163 H = 0.5 * (e * G - 2 * f * F + g * E) / (E * G - F * F);
166 kv[0] = abs(H + sqrt(H * H - K));
167 kv[1] = abs(H - sqrt(H * H - K));
169 return kv[0] > kv[1] ? kv[0] : kv[1];
174 gp_Pnt loc(p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0);
177 ShapeAnalysis_Surface sas(m_s);
178 sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
180 gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
182 gp_Pnt p3 = sas.Value(p2);
184 return p3.Distance(loc);
190 gp_Pnt loc(tp[0] * 1000.0, tp[1] * 1000.0, tp[2] * 1000.0);
193 ShapeAnalysis_Surface sas(m_s);
194 sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
196 gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
198 gp_Pnt p3 = sas.Value(p2);
200 tp[0] = p3.X() / 1000.0;
201 tp[1] = p3.Y() / 1000.0;
202 tp[2] = p3.Z() / 1000.0;
210 #if defined(NEKTAR_DEBUG)
216 loc = m_occSurface.Value(uv[0], uv[1]);
217 location[0] = loc.X();
218 location[1] = loc.Y();
219 location[2] = loc.Z();
225 #if defined(NEKTAR_DEBUG)
229 BRepLProp_SLProps slp(m_occSurface, 2, 1e-6);
230 slp.SetParameters(uv[0], uv[1]);
232 if (!slp.IsNormalDefined())
237 gp_Dir d = slp.Normal();
255 #if defined(NEKTAR_DEBUG)
262 m_occSurface.D1(uv[0], uv[1], Loc, D1U, D1V);
279 #if defined(NEKTAR_DEBUG)
285 gp_Vec D1U, D1V, D2U, D2V, D2UV;
286 m_occSurface.D2(uv[0], uv[1], Loc, D1U, D1V, D2U, D2V, D2UV);
314 error <<
"Point not within parameter plane: ";
318 if (uv[0] < m_bounds[0])
320 if (fabs(uv[0] - m_bounds[0]) > 1E-6)
322 error <<
"U(" << uv[0] <<
") is less than Umin(" << m_bounds[0]
327 else if (uv[0] > m_bounds[1])
329 if (fabs(uv[0] - m_bounds[1]) > 1E-6)
331 error <<
"U(" << uv[0] <<
") is greater than Umax(" << m_bounds[1]
336 else if (uv[1] < m_bounds[2])
338 if (fabs(uv[1] - m_bounds[2]) > 1E-6)
340 error <<
"V(" << uv[1] <<
") is less than Vmin(" << m_bounds[2]
345 else if (uv[1] > m_bounds[3])
347 if (fabs(uv[1] - m_bounds[3]) > 1E-6)
349 error <<
"V(" << uv[1] <<
") is greater than Vmax(" << m_bounds[3]
355 error <<
" On Surface: " << GetId();
356 ASSERTL1(passed,
"Warning: " + error.str());
#define ASSERTL0(condition, msg)
CADSurfFactory & GetCADSurfFactory()
#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.