Skip to content

Commit

Permalink
OCC: better separation between edges and faces
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Sep 9, 2024
1 parent 33a9f9f commit 5c8b09e
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 67 deletions.
4 changes: 2 additions & 2 deletions Cassiopee/Converter/Converter/Internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ def setName(node, name):
if name.dtype.char == 'S': node[0] = name.tobytes().decode()
elif name.dtype.char == 'c': node[0] = name.tobytes().decode()
else:
raise TypeError("setName: name of node must be a string(%s)"%(name.__repr__()[:min(len(name.__repr__()),60)]))
else: raise TypeError("setName: name of node must be a string(%s)"%(name.__repr__()[:min(len(name.__repr__()),60)]))
raise TypeError("setName: name of node must be a string (%s)."%(name.__repr__()[:min(len(name.__repr__()),60)]))
else: raise TypeError("setName: name of node must be a string (%s)."%(name.__repr__()[:min(len(name.__repr__()),60)]))
return None

def _setName(node, name):
Expand Down
44 changes: 36 additions & 8 deletions Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@

// ultimate (best) functions

// ============================================================================
// Return uniform distribution of NbPoints on edge
// ============================================================================
E_Int __getUniform(const TopoDS_Edge& E, E_Int nbPoints, E_Float*& ue)
{
BRepAdaptor_Curve C0(E);
GeomAdaptor_Curve geomAdap(C0.Curve()); // Geometric Interface <=> access to discretizations tool
Standard_Real u0 = geomAdap.FirstParameter();
Standard_Real u1 = geomAdap.LastParameter();
GCPnts_UniformAbscissa param(geomAdap, int(nbPoints), u0, u1);
ue = new E_Float [nbPoints];
for (E_Int i = 0; i < nbPoints; i++) ue[i] = param.Parameter(i+1);
return 0;
}

// ============================================================================
// Return the nbPoints and ue for meshing E regular with hmax
// ============================================================================
Expand All @@ -49,7 +64,7 @@ E_Int __getParamHmax(const TopoDS_Edge& E, E_Float hmax, E_Int& nbPoints, E_Floa
Standard_Real u1 = geomAdap.LastParameter();
if (BRep_Tool::Degenerated(E))
{
nbPoints=2;
nbPoints = 2;
ue = new E_Float [nbPoints];
for (E_Int i = 0; i < nbPoints; i++) ue[i] = u0;
return 1;
Expand Down Expand Up @@ -487,17 +502,19 @@ E_Int __meshEdgeByFace(const TopoDS_Edge& E, const TopoDS_Face& F,

// ============================================================================
/* Mesh one edge of CAD, return STRUCT
hmax
hausd
hmax + hausd
external param ue
hmax
or hausd
or hmax + hausd
or N
or external param ue
not used if hmax=-1, hausd=-1, N=-1, ue=None
*/
// ============================================================================
PyObject* K_OCC::meshOneEdge(PyObject* self, PyObject* args)
{
PyObject* hook; E_Int i;
E_Float hmax; E_Float hausd; PyObject* externalEdge;
if (!PYPARSETUPLE_(args, O_ I_ RR_ O_, &hook, &i, &hmax, &hausd, &externalEdge)) return NULL;
E_Float hmax; E_Float hausd; E_Int N; PyObject* externalEdge;
if (!PYPARSETUPLE_(args, O_ I_ RR_ I_ O_, &hook, &i, &hmax, &hausd, &N, &externalEdge)) return NULL;

void** packet = NULL;
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
Expand All @@ -513,7 +530,18 @@ PyObject* K_OCC::meshOneEdge(PyObject* self, PyObject* args)
E_Int nbPoints = 0; // nbre of points of discretized edge
E_Float* ue; // edge param

if (hmax > 0 && hausd < 0 && externalEdge == Py_None) // pure hmax
if (N > 0 && externalEdge == Py_None)
{
nbPoints = N;
__getUniform(E, nbPoints, ue);
PyObject* o = K_ARRAY::buildArray2(4, "x,y,z,u", nbPoints, 1, 1, 1);
FldArrayF* f; K_ARRAY::getFromArray2(o, f);
__meshEdge(E, nbPoints, ue, *f, false);
delete [] ue;
RELEASESHAREDS(o, f);
return o;
}
else if (hmax > 0 && hausd < 0 && externalEdge == Py_None) // pure hmax
{
__getParamHmax(E, hmax, nbPoints, ue);
PyObject* o = K_ARRAY::buildArray2(4, "x,y,z,u", nbPoints, 1, 1, 1);
Expand Down
58 changes: 53 additions & 5 deletions Cassiopee/OCC/OCC/OCC.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
__all__ = ['convertCAD2Arrays', 'switch2UV', 'switch2UV2', '_scaleUV', '_unscaleUV',
'allTFI', 'meshSTRUCT', 'meshSTRUCT__', 'meshTRI', 'meshTRI__', 'meshTRIU__',
'meshTRIHO', 'meshQUAD', 'meshQUAD__', 'meshQUADHO', 'meshQUADHO__',
'ultimate', 'meshAllEdges', 'meshAllFaces']
'ultimate', 'meshAllEdges', 'meshAllFacesTri', 'meshAllFacesStruct']

# algo=0: mailleur open cascade (chordal_error)
# algo=1: algorithme T3mesher (h, chordal_error, growth_ratio)
Expand Down Expand Up @@ -602,23 +602,25 @@ def meshFaceInUV(hook, i, edges, grading, mesh, FAILED):
return SUCCESS

# mesh all CAD edges with hmax, hausd
def meshAllEdges(hook, hmax, hausd):
def meshAllEdges(hook, hmax, hausd, N):
nbEdges = occ.getNbEdges(hook)
dedges = []
for i in range(nbEdges):
e = occ.meshOneEdge(hook, i+1, hmax, hausd, None)
e = occ.meshOneEdge(hook, i+1, hmax, hausd, N, None)
dedges.append(e)
return dedges

# mesh some CAD faces from discrete edges + hList
#=================================================================
# mesh TRI given CAD faces from discrete edges U + hList
# IN: hook: hook of cad
# IN: hmax: hmax size
# IN: hausd: hausd size
# IN: dedges: list of all discretized edges (all CAD edges)
# IN: metric: if True use metric else mesh in uv
# IN: faceList: list of faces to mesh (start 1)
# IN: hList: list of (hmin, hmax, hausd) for each face to mesh
def meshAllFaces(hook, dedges, metric=True, faceList=[], hList=[]):
#==================================================================
def meshAllFacesTri(hook, dedges, metric=True, faceList=[], hList=[]):
nbFaces = occ.getNbFaces(hook)
FAILED1 = []; FAILED2 = []; dfaces = []
for c, i in enumerate(faceList):
Expand Down Expand Up @@ -657,3 +659,49 @@ def meshAllFaces(hook, dedges, metric=True, faceList=[], hList=[]):
print("FINAL FAILED on face = %03d_edgeUV.plt"%f)

return dfaces

#==================================================================
# mesh STRUCT given CAD faces from discrete edges U
#==================================================================
def meshAllFacesStruct(hook, dedges, faceList=[]):
nbFaces = occ.getNbFaces(hook)
FAILED1 = []; dfaces = []
nloct = []; nofacet = [] # nbre de grilles pour la face c; no de la face
for c, i in enumerate(faceList):

print("========== face %d / %d ==========="%(i,nbFaces))

wires = occ.meshEdgesOfFace(hook, i, dedges)
edges = wires[0] # only first for now

SUCCESS = False
edges = switch2UV(edges)
# scale uv
T = _scaleUV(edges)
# force la fermeture des boucles
#edges = Generator.close(edges, 1.e-6) # the weakness
# TFI dans espace uv
try:
als = allTFI(edges)
# unscale uv
_unscaleUV(als, T)
for c, a in enumerate(als):
# evaluation sur la CAD
o = occ.evalFace(hook, a, i)
dfaces.append(o)
nofacet.append(i)
nloct.append(c+1)
except Exception as e:
print(str(e))
Converter.convertArrays2File(edges, "edgesOfFace%03d.plt"%i)
FAILED1.append(i)
dfaces.append(None)
nofacet.append(i)
nloct.append(0)

FAIL1 = len(FAILED1)
print("STRUCTFAILURE = %d / %d"%(FAIL1, nbFaces))
for f in FAILED1:
print("STRUCTFAILED on face = %03d_edgeUV.plt"%f)

return dfaces, nloct, nofacet
Loading

0 comments on commit 5c8b09e

Please sign in to comment.