Skip to content

Commit

Permalink
OCC: update tree from CAD
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Sep 30, 2024
1 parent 7625ccd commit da6b4c8
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 44 deletions.
5 changes: 3 additions & 2 deletions Cassiopee/CPlot/apps/tkCADFix.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,15 @@ def removeFaces(event=None):
CTK.setCursor(2, WIDGETS['frame'])
CTK.setCursor(2, WIDGETS['removeFacesButton'])

OCC._removeFaces(hook, faces)
edgeMap = []; faceMap = []
OCC._removeFaces(hook, faces, edgeMap, faceMap)

# remesh CAD and redisplay
edges = Internal.getNodeFromName1(CTK.t, 'EDGES')
edges[2] = []
faces = Internal.getNodeFromName1(CTK.t, 'FACES')
faces[2] = []
OCC._meshAllEdges(hook, CTK.t, hmax=hmax, hausd=hausd) # loose manual remeshing...
OCC._meshAllEdges(hook, CTK.t, hmax=hmax, hausd=hausd)
OCC._meshAllFacesTri(hook, CTK.t, hmax=hmax, hausd=hausd)
CTK.setCursor(0, WIDGETS['frame'])
CTK.setCursor(0, WIDGETS['removeFacesButton'])
Expand Down
4 changes: 2 additions & 2 deletions Cassiopee/CPlot/apps/tkCADMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def meshCADEdges(event=None):
import OCC.PyTree as OCC
hmax = CTK.varsFromWidget(VARS[0].get(), 1)[0]
hausd = CTK.varsFromWidget(VARS[1].get(), 1)[0]
CTK.saveTree()
CTK.setCursor(2, WIDGETS['frame'])
# remesh CAD and redisplay
edges = Internal.getNodeFromName1(CTK.t, 'EDGES')
Expand All @@ -38,10 +39,9 @@ def meshCADFaces(event=None):
import OCC.PyTree as OCC
hmax = CTK.varsFromWidget(VARS[0].get(), 1)[0]
hausd = CTK.varsFromWidget(VARS[1].get(), 1)[0]

CTK.saveTree()
CTK.setCursor(2, WIDGETS['frame'])
CTK.setCursor(2, WIDGETS['meshFaceButton'])

faces = Internal.getNodeFromName1(CTK.t, 'FACES')
if faces is not None: faces[2] = []
if mtype == 'TRI':
Expand Down
2 changes: 2 additions & 0 deletions Cassiopee/CPlot/apps/tkMapEdge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ def enforceLocal(event=None):
imax = ind+1+delta

CAD = Internal.getNodeFromName1(z, 'CAD')
render = Internal.getNodeFromName1(z, '.RenderInfo')

#print("imin=",imin,"imax",imax,"ind",ind,"npts",npts)
if imin > 1: z0 = T.subzone(z, (1,1,1), (imin,-1,-1))
Expand Down Expand Up @@ -1220,6 +1221,7 @@ def enforceLocal(event=None):
if z1 is not None: zo = T.join(zo, z1)
zo[0] = z[0] # keep orig name and CAD
zo[2].append(CAD)
if render: zo[2].append(render)

CTK.replace(CTK.t, nob, noz, zo)
(CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
Expand Down
16 changes: 8 additions & 8 deletions Cassiopee/CPlot/apps/tkView.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ def loadSlot():
pos = Internal.getNodesFromName(slot, 'isoScales*')
if pos != []:
updateIsoWidgets(); updateIsoPyTree()
scales = []
for p in pos:
name = p[0]
name = name.replace('isoScales[', '')
name = name[0:-2]
out = [name]+p[1].tolist()
scales.append(out)
if scales != []: CPlot.setState(isoScales=scales)
scales = []
for p in pos:
name = p[0]
name = name.replace('isoScales[', '')
name = name[0:-2]
out = [name]+p[1].tolist()
scales.append(out)
if scales != []: CPlot.setState(isoScales=scales)

pos = Internal.getNodeFromName1(slot, 'mode')
if pos is not None:
Expand Down
13 changes: 7 additions & 6 deletions Cassiopee/Converter/Converter/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,13 +1017,14 @@ def convertFile2PyTree(fileName, format=None, nptsCurve=20, nptsLine=2,
CAD = Internal.getNodeFromName1(t, 'CAD')
if CAD is not None: # reload CAD
file = Internal.getNodeFromName1(CAD, 'file')
file = Internal.getValue(file)
if file is not None: file = Internal.getValue(file)
fmt = Internal.getNodeFromName1(CAD, 'format')
fmt = Internal.getValue(fmt)
import OCC.PyTree as OCC
import CPlot.Tk as CTK
hook = OCC.readCAD(file, fmt)
CTK.CADHOOK = hook
if fmt is not None: fmt = Internal.getValue(fmt)
if file is not None and fmt is not None:
import OCC.PyTree as OCC
import CPlot.Tk as CTK
hook = OCC.readCAD(file, fmt)
CTK.CADHOOK = hook
return t
except:
if format == 'bin_cgns' or format == 'bin_adf':
Expand Down
5 changes: 5 additions & 0 deletions Cassiopee/Envs/env_Cassiopee_local
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ else if ($MAC == "ld") then
@ ncpu++
setenv OMP_NUM_THREADS $ncpu
setenv ASAN_OPTIONS verify_asan_link_order=false
setenv LSAN_OPTIONS suppressions="$CASSIOPEE"/Dist/bin/"$ELSAPROD"/asan.supp:print_suppressions=0
setenv ASAN_LIB /opt/tools/gcc/10.2.0-gnu831/lib64/libasan.so

else if ($MAC == "eos814") then
Expand Down Expand Up @@ -228,6 +229,9 @@ else if ($MAC == "ubuntu") then
setenv PYTHONEXE=python3
setenv PRODMODE=1
setenv PIP_DISABLE_PIP_VERSION_CHECK=1
setenv ASAN_OPTIONS verify_asan_link_order=false
setenv LSAN_OPTIONS suppressions="$CASSIOPEE"/Dist/bin/"$ELSAPROD"/asan.supp:print_suppressions=0
setenv ASAN_LIB /usr/lib/gcc/x86_64-linux-gnu/13/libasan.so

else if ($MAC == "fulvio") then
#------------------------------- fulvio ---------------------------------------
Expand Down Expand Up @@ -700,6 +704,7 @@ else if ($MAC == "juno_gcc") then
unsetenv SLURM*
unsetenv OMP_PLACES
setenv ASAN_OPTIONS verify_asan_link_order=false
setenv LSAN_OPTIONS suppressions="$CASSIOPEE"/Dist/bin/"$ELSAPROD"/asan.supp:print_suppressions=0
setenv ASAN_LIB /opt/tools/gcc/12.1.0-gnu831/lib64/libasan.so

else if ($MAC == "juno_gpu") then
Expand Down
3 changes: 3 additions & 0 deletions Cassiopee/Envs/sh_Cassiopee_local
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ elif [ "$MAC" = "ubuntu" ]; then
export PYTHONEXE=python3
export PRODMODE=1
export PIP_DISABLE_PIP_VERSION_CHECK=1
export ASAN_OPTIONS=verify_asan_link_order=false
export LSAN_OPTIONS=suppressions=$CASSIOPEE/Dist/bin/"$ELSAPROD"/asan.supp:print_suppressions=0
export ASAN_LIB=/usr/lib/gcc/x86_64-linux-gnu/13/libasan.so

elif [ "$MAC" = "azure" ]; then
#------------------------ azure: ubuntu - github actions ----------------------
Expand Down
3 changes: 0 additions & 3 deletions Cassiopee/KCore/KCore/Nuga/include/metric.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
#ifndef NUGA_METRIC_HXX
#define NUGA_METRIC_HXX


namespace NUGA
{

enum eMetricType { ISO_MIN=0, ISO_MEAN=1, ISO_MAX=2,/*, ANISO*/ };

}

#endif
Expand Down
1 change: 1 addition & 0 deletions Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ E_Int __getParamHausd(const TopoDS_Edge& E, E_Float hausd, E_Int& nbPoints, E_Fl
return 0;
}

// ============================================================================
// Geom distrib entre u0 et u1, h0 et h1 (interieurs)
void geom1(E_Float u0, E_Float u1, E_Float h0, E_Float h1, E_Int& N, E_Float*& ue)
{
Expand Down
87 changes: 75 additions & 12 deletions Cassiopee/OCC/OCC/Atomic/removeFaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,77 @@
#include "occ.h"

#include "TopoDS.hxx"
#include "TopoDS_Edge.hxx"
#include "BRep_Tool.hxx"
#include "TopExp.hxx"
#include "TopExp_Explorer.hxx"
#include "TopTools_IndexedMapOfShape.hxx"
#include "ShapeBuild_ReShape.hxx"
#include "BRep_Builder.hxx"

//=============================================================
void getEdgeMap(TopTools_IndexedMapOfShape& oldEdges, TopTools_IndexedMapOfShape& newEdges, PyObject*& edgeMap)
{
bool found;
E_Int neold = oldEdges.Extent();
E_Int nenew = newEdges.Extent();
PyList_SetSlice(edgeMap, 0, PyList_Size(edgeMap), NULL);
for (E_Int i = 1; i <= nenew; i++)
{
const TopoDS_Edge& E = TopoDS::Edge(newEdges(i));

found = false;
for (E_Int j = 1; j <= neold; j++)
{
const TopoDS_Edge& EO = TopoDS::Edge(oldEdges(j));
if (E.IsSame(EO))
{
//printf("edge identified %d %d\n", i, j);
PyList_Append(edgeMap, PyLong_FromLong(j));
found = true;
break;
}
}
if (not found) PyList_Append(edgeMap, PyLong_FromLong(-1));
//printf("%d -> %p\n", i, (void*)&E);
}
}

//=============================================================
// Get new->old for faces
void getFaceMap(TopTools_IndexedMapOfShape& oldFaces, TopTools_IndexedMapOfShape& newFaces, PyObject*& faceMap)
{
bool found;
E_Int neold = oldFaces.Extent();
E_Int nenew = newFaces.Extent();
PyList_SetSlice(faceMap, 0, PyList_Size(faceMap), NULL);
for (E_Int i = 1; i <= nenew; i++)
{
const TopoDS_Face& F = TopoDS::Face(newFaces(i));
found = false;
for (E_Int j = 1; j <= neold; j++)
{
const TopoDS_Face& FO = TopoDS::Face(oldFaces(j));
if (F.IsSame(FO))
{
//printf("face identified %d %d\n", i, j);
PyList_Append(faceMap, PyLong_FromLong(j));
found = true;
break;
}
}
if (not found) PyList_Append(faceMap, PyLong_FromLong(-1));
}
}

//=====================================================================
// Remove some faces and rebuild compound
// output edgeMap et faceMap
//=====================================================================
PyObject* K_OCC::removeFaces(PyObject* self, PyObject* args)
{
PyObject* hook; PyObject* listFaces;
if (!PYPARSETUPLE_(args, OO_, &hook, &listFaces)) return NULL;
PyObject* hook; PyObject* listFaces; PyObject* edgeMap; PyObject* faceMap;
if (!PYPARSETUPLE_(args, OO_ OO_, &hook, &listFaces, &edgeMap, &faceMap)) return NULL;

void** packet = NULL;
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
Expand All @@ -44,10 +101,15 @@ PyObject* K_OCC::removeFaces(PyObject* self, PyObject* args)

// get top shape
TopoDS_Shape* shp = (TopoDS_Shape*)packet[0];
//TopTools_IndexedMapOfShape& edges = *(TopTools_IndexedMapOfShape*)packet[2];
TopTools_IndexedMapOfShape& edges = *(TopTools_IndexedMapOfShape*)packet[2];
TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1];
E_Int nbFaces = surfaces.Extent();

//Handle(TDF_Data) data = new TDF_Data();
//TDF_Label label = data->Root();
//TDataStd_Name::Set(label, "MyFaceTag");
//TDF_Tool::AddShape(label, F);

ShapeBuild_ReShape reshaper;
for (E_Int no = 0; no < PyList_Size(listFaces); no++)
{
Expand All @@ -64,21 +126,22 @@ PyObject* K_OCC::removeFaces(PyObject* self, PyObject* args)
TopoDS_Shape shc = reshaper.Apply(*shp);

// export
delete shp;
TopoDS_Shape* newshp = new TopoDS_Shape(shc);

// Export
packet[0] = newshp;
TopTools_IndexedMapOfShape* ptr = (TopTools_IndexedMapOfShape*)packet[1];
delete ptr;
TopTools_IndexedMapOfShape* sf = new TopTools_IndexedMapOfShape();
TopExp::MapShapes(*newshp, TopAbs_FACE, *sf);
packet[1] = sf;
TopTools_IndexedMapOfShape* ptr2 = (TopTools_IndexedMapOfShape*)packet[2];
delete ptr2;
TopTools_IndexedMapOfShape* se = new TopTools_IndexedMapOfShape();
TopExp::MapShapes(*newshp, TopAbs_EDGE, *se);
getFaceMap(surfaces, *sf, faceMap);
getEdgeMap(edges, *se, edgeMap);
delete shp;
TopTools_IndexedMapOfShape* ptr = (TopTools_IndexedMapOfShape*)packet[1];
delete ptr;
TopTools_IndexedMapOfShape* ptr2 = (TopTools_IndexedMapOfShape*)packet[2];
delete ptr2;
packet[0] = newshp;
packet[1] = sf;
packet[2] = se;

printf("INFO: after removeFaces: Nb edges=%d\n", se->Extent());
printf("INFO: after removeFaces: Nb faces=%d\n", sf->Extent());

Expand Down
4 changes: 1 addition & 3 deletions Cassiopee/OCC/OCC/OCCSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ void K_OCC::OCCSurface::__normalize(E_Float& u, E_Float& v) const
v = (v - _V0) / (_V1 - _V0);
}


void K_OCC::OCCSurface::__denormalize(E_Float& u, E_Float& v) const
{
if (!_normalize_domain) return;
Expand Down Expand Up @@ -510,7 +509,6 @@ void K_OCC::OCCSurface::__traverse_face_edges(const TopoDS_Face& F, TopExp_Explo
void K_OCC::OCCSurface::__get_params_and_type
(const TopoDS_Face& F, E_Float& U0, E_Float& U1, E_Float& V0, E_Float& V1, bool& isUClosed, bool& isVClosed)
{

E_Float paramtol = 1.e-6;

ShapeAnalysis::GetFaceUVBounds(F, U0, U1, V0, V1);
Expand All @@ -530,4 +528,4 @@ void K_OCC::OCCSurface::__get_params_and_type
isUClosed = (U0 == paramtol) & (U1 == (twoPI - paramtol));
isVClosed = (V0 == paramtol) & (V1 == (twoPI - paramtol));

}
}
Loading

0 comments on commit da6b4c8

Please sign in to comment.