Skip to content

Commit

Permalink
OCC: solve corner points
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Dec 16, 2024
1 parent bb87424 commit 2c268be
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 28 deletions.
9 changes: 3 additions & 6 deletions Cassiopee/CPlot/CPlot/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,7 @@ PyObject* K_CPLOT::setSelectedZones(PyObject* self, PyObject* args)

if (PyList_Check(o) == 0)
{
PyErr_SetString(
PyExc_TypeError,
PyErr_SetString(PyExc_TypeError,
"setSelectedZones: arg must be a list.");
return NULL;
}
Expand All @@ -645,15 +644,13 @@ PyObject* K_CPLOT::setSelectedZones(PyObject* self, PyObject* args)
// tpl must be a tuple of two ints (no, 1)
if (PyTuple_Check(tpl) == 0)
{
PyErr_SetString(
PyExc_TypeError,
PyErr_SetString(PyExc_TypeError,
"setSelectedZones: arg must be a list of tuples (noz, 1).");
return NULL;
}
if (PyTuple_Size(tpl) != 2)
{
PyErr_SetString(
PyExc_TypeError,
PyErr_SetString(PyExc_TypeError,
"setSelectedZones: arg must be a list of tuples (noz, 1).");
return NULL;
}
Expand Down
21 changes: 12 additions & 9 deletions Cassiopee/CPlot/apps/tkCADFix.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,25 +411,28 @@ def checkWatertight(event=None):
if CAD is not None:
hmax = Internal.getNodeFromName1(CAD, 'hmax')
hmax = Internal.getValue(hmax)
tol = hmax/100.
hmin = Internal.getNodeFromName1(CAD, 'hmin')
hmin = Internal.getValue(hmin)
tol = (hmin+hmax)*0.2

CTK.t = C.addBase2PyTree(CTK.t, 'LEAKS', 1)
p = Internal.getNodeFromName1(CTK.t, 'LEAKS')
gnob = C.getNobOfBase(p, CTK.t)

ef = OCC.getComponents(CTK.t, tol)
ef = OCC.getComponents(CTK.t)

VARS[6].set('Components: %d'%(len(ef)))

isWatertight = False
try:
isWatertight = True
for f in ef:
#try:
isWatertight = True
for f in ef:
try:
ext = P.exteriorFaces(f)
ext = T.splitConnexity(ext)
for i in ext: CTK.add(CTK.t, gnob, -1, i)
if len(ext) != 0: isWatertight = False
except: isWatertight = True
if len(ext) != 0: isWatertight = False; break
except: isWatertight = True

(CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
CTK.TKTREE.updateApp()
Expand Down Expand Up @@ -468,7 +471,8 @@ def createApp(win):
WIDGETS['frameMenu'] = FrameMenu

#- VARS -
tol = 1.e-6
tol = 1.e-6; NL = 0
fileName = ''; fileFmt = 'fmt_step'
if CTK.CADHOOK is not None:
import OCC.PyTree as OCC
fileName, fileFmt = OCC.getFileAndFormat(CTK.CADHOOK)
Expand All @@ -479,7 +483,6 @@ def createApp(win):
tol = Internal.getValue(tol)
power = math.floor(math.log10(abs(tol)))
tol = round(tol, -power)
else: fileName = ''; fileFmt = 'fmt_step'; NL = 0

# -0- CAD file name -
V = TK.StringVar(win); V.set(fileName); VARS.append(V)
Expand Down
1 change: 0 additions & 1 deletion Cassiopee/Generator/Generator/closeBorders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,5 @@ void K_GENERATOR::closeAllStructuredMeshes(
}
}
}

} // tous les pts
}
21 changes: 15 additions & 6 deletions Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,11 @@ E_Int __meshEdgeByFace(const TopoDS_Edge& E, const TopoDS_Face& F,
E_Float* pu = coords.begin(4);
E_Float* pv = coords.begin(5);

E_Float* pex = fe.begin(1);
E_Float* pey = fe.begin(2);
E_Float* pez = fe.begin(3);
E_Float* peu = fe.begin(4);

// degenerated
if (BRep_Tool::Degenerated(E))
{
Expand All @@ -1084,12 +1089,14 @@ E_Int __meshEdgeByFace(const TopoDS_Edge& E, const TopoDS_Face& F,
pCurve->D0(u, Puv);
if (reverse)
{
px[nbPoints-i-1] = Pt.X(); py[nbPoints-i-1] = Pt.Y(); pz[nbPoints-i-1] = Pt.Z();
//px[nbPoints-i-1] = Pt.X(); py[nbPoints-i-1] = Pt.Y(); pz[nbPoints-i-1] = Pt.Z();
px[nbPoints-i-1] = pex[i]; py[nbPoints-i-1] = pey[i]; pz[nbPoints-i-1] = pez[i];
pu[nbPoints-i-1] = Puv.X(); pv[nbPoints-i-1] = Puv.Y();
}
else
{
px[i] = Pt.X(); py[i] = Pt.Y(); pz[i] = Pt.Z();
//px[i] = Pt.X(); py[i] = Pt.Y(); pz[i] = Pt.Z();
px[i] = pex[i]; py[i] = pey[i]; pz[i] = pez[i];
pu[i] = Puv.X(); pv[i] = Puv.Y();
}
}
Expand All @@ -1098,20 +1105,22 @@ E_Int __meshEdgeByFace(const TopoDS_Edge& E, const TopoDS_Face& F,

// non degenerated
{
gp_Pnt Pt; gp_Pnt2d Puv;
gp_Pnt Pt; gp_Pnt2d Puv; E_Float u;
for (E_Int i = 1; i <= nbPoints; i++)
{
E_Float u = fe(i-1,4);
u = peu[i-1];
C0.D0(u, Pt);
pCurve->D0(u, Puv);
if (reverse)
{
px[nbPoints-i] = Pt.X(); py[nbPoints-i] = Pt.Y(); pz[nbPoints-i] = Pt.Z();
//px[nbPoints-i] = Pt.X(); py[nbPoints-i] = Pt.Y(); pz[nbPoints-i] = Pt.Z();
px[nbPoints-i] = pex[i-1]; py[nbPoints-i] = pey[i-1]; pz[nbPoints-i] = pez[i-1];
pu[nbPoints-i] = Puv.X(); pv[nbPoints-i] = Puv.Y();
}
else
{
px[i-1] = Pt.X(); py[i-1] = Pt.Y(); pz[i-1] = Pt.Z();
//px[i-1] = Pt.X(); py[i-1] = Pt.Y(); pz[i-1] = Pt.Z();
px[i-1] = pex[i-1]; py[i-1] = pey[i-1]; pz[i-1] = pez[i-1];
pu[i-1] = Puv.X(); pv[i-1] = Puv.Y();
}
}
Expand Down
8 changes: 8 additions & 0 deletions Cassiopee/OCC/OCC/Atomic/readCAD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ PyObject* K_OCC::readCAD(PyObject* self, PyObject* args)
char* fileName; char* fileFmt;
if (!PyArg_ParseTuple(args, "ss", &fileName, &fileFmt)) return NULL;

FILE* ptrFile = fopen(fileName, "r");
if (ptrFile == NULL)
{
PyErr_SetString(PyExc_TypeError, "readCAD: file not found.");
return NULL;
}
fclose(ptrFile);

TopoDS_Shape* shp = new TopoDS_Shape();

TDocStd_Document* doc = NULL;
Expand Down
5 changes: 4 additions & 1 deletion Cassiopee/OCC/OCC/OCC.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ def meshFaceWithMetric(hook, i, edges, hmin, hmax, hausd, mesh, FAILED):
try:
a = occ.trimesh(hook, edges, i, hmin, hmax, hausd, 1.1)
_enforceEdgesInFace(a, edgesSav)
a = Generator.close(a, 1.e-10) # needed for periodic faces
if occ.getFaceOrientation(hook, i) == 0:
a = Transform.reorder(a, (-1,))
mesh.append(a)
Expand Down Expand Up @@ -572,6 +573,7 @@ def meshFaceInUV(hook, i, edges, grading, mesh, FAILED):
_unscaleUV([a], T)
o = occ.evalFace(hook, a, i)
_enforceEdgesInFace(o, edgesSav)
a = Generator.close(a, 1.e-10) # needed for periodic faces
if occ.getFaceOrientation(hook, i) == 0:
o = Transform.reorder(o, (-1,))
mesh.append(o)
Expand All @@ -584,7 +586,7 @@ def meshFaceInUV(hook, i, edges, grading, mesh, FAILED):

return SUCCESS

# mesh all CAD edges with hmax, hausd
# mesh all CAD edges with hmin, hmax, hausd
def meshAllEdges(hook, hmin, hmax, hausd, N, edgeList=None):
if edgeList is None:
nbEdges = occ.getNbEdges(hook)
Expand All @@ -593,6 +595,7 @@ def meshAllEdges(hook, hmin, hmax, hausd, N, edgeList=None):
for i in edgeList:
e = occ.meshOneEdge(hook, i, hmin, hmax, hausd, N, None)
dedges.append(e)
dedges = Generator.zip(dedges, tol=hmax/100.) # safe and necessary for corner/seam points
return dedges

#=================================================================
Expand Down
7 changes: 4 additions & 3 deletions Cassiopee/OCC/OCC/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ def identifyTags__(a):
array = C.getFields(Internal.__FlowSolutionNodes__, a, "__tag__", api=3)[0]
return OCC.identifyTags__(array)

def getComponents(t, tol=1.e-10):
def getComponents(t):
"""Return the number of components in t, taggings faces with component number."""
import Transform.PyTree as T
# init FACES with a tag
Expand All @@ -1397,9 +1397,10 @@ def getComponents(t, tol=1.e-10):
C._initVars(z, '__tag__ = %d'%no)

# join all zones
a = G.zip(zones, tol)
G._zip(zones, 1.e-10) # volontairement in place, maybe useless
a = T.join(zones)
a = T.splitConnexity(a)
#a = T.splitConnexity(a)
a = T.splitManifold(a)

# Identify faces in component
tags = {}
Expand Down
4 changes: 2 additions & 2 deletions Cassiopee/Post/Post/zipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ PyObject* K_POST::zipperF(PyObject* self, PyObject* args)
}

//=============================================================================
// Lecture des options et retourne les valeurs associées:
// Lecture des options et retourne les valeurs associ�es:
// geomTol: tolerance geometrique
//=============================================================================
void K_POST::readZipperOptions(PyObject* optionList, E_Float& overlapTol,
Expand Down Expand Up @@ -287,7 +287,7 @@ void K_POST::readZipperOptions(PyObject* optionList, E_Float& overlapTol,
{
printf("Warning: zipper: matchTol must be a float. Set to default value: 1.e-6.\n");
}
else matchTol = PyFloat_AsDouble(tpl2);
else matchTol = PyFloat_AsDouble(tpl2);
}
else //autres
{
Expand Down

0 comments on commit 2c268be

Please sign in to comment.