From bd8d15acf32ba9dc43fc415b828aba74d699fd09 Mon Sep 17 00:00:00 2001 From: benoit128 Date: Sun, 8 Sep 2024 09:14:32 +0200 Subject: [PATCH] OCC: try compounds on addSphere --- Cassiopee/CPlot/apps/validCassiopee.py | 2 +- Cassiopee/KCore/KCore/Nuga/include/BbTree.h | 12 +++-- .../KCore/KCore/Nuga/include/geom_sensor.hxx | 32 ++++++------ Cassiopee/OCC/OCC/Atomic/addSphere.cpp | 49 +++++++++++++------ Cassiopee/OCC/OCC/Atomic/createEmptyCAD.cpp | 4 +- Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp | 5 +- 6 files changed, 63 insertions(+), 41 deletions(-) diff --git a/Cassiopee/CPlot/apps/validCassiopee.py b/Cassiopee/CPlot/apps/validCassiopee.py index 8a58d5235..bbcbbe99d 100644 --- a/Cassiopee/CPlot/apps/validCassiopee.py +++ b/Cassiopee/CPlot/apps/validCassiopee.py @@ -1822,7 +1822,7 @@ def updateASANLabel(entry_index): Threads = TK.StringVar(Master) TextThreads = TK.Entry(Frame, textvariable=Threads, background='White', width=3) - TextThreads.grid(row=1, column=9, sticky=TK.EW) + TextThreads.grid(row=1, column=9, columnspan=2, sticky=TK.EW) TextThreads.bind('', setThreads) TextThreads.bind('', setThreads) getThreads() diff --git a/Cassiopee/KCore/KCore/Nuga/include/BbTree.h b/Cassiopee/KCore/KCore/Nuga/include/BbTree.h index 7f1751522..ef7b11729 100755 --- a/Cassiopee/KCore/KCore/Nuga/include/BbTree.h +++ b/Cassiopee/KCore/KCore/Nuga/include/BbTree.h @@ -63,7 +63,7 @@ class BoundingBox{ { const E_Float* Pi; for (E_Int i = 0; i < DIM; ++i) - {minB[i] = NUGA::FLOAT_MAX; maxB[i] = -NUGA::FLOAT_MAX;} + { minB[i] = NUGA::FLOAT_MAX; maxB[i] = -NUGA::FLOAT_MAX; } if (N0 < 0 || N0 >= pos.cols()) N0 = pos.cols(); //if max id is not (or badly) specified @@ -89,9 +89,10 @@ class BoundingBox{ inline const E_Float& getMaxB(E_Int axis) const {return maxB[axis];} // Warning : strict comparison - bool operator==(const BoundingBox& rhs){ - - for (E_Int i = 0; i < DIM; ++i){ + bool operator==(const BoundingBox& rhs) + { + for (E_Int i = 0; i < DIM; ++i) + { if (minB[i] != rhs.minB[i]) return false; if (maxB[i] != rhs.maxB[i]) return false; } @@ -271,8 +272,9 @@ class BoundingBox{ (const K_FLD::ArrayAccessor& pos, const Vector & indices, E_Int idx_start=0) { E_Float Pi[DIM]; + for (E_Int i = 0; i < DIM; ++i) Pi[i] = -1.; for (E_Int i = 0; i < DIM; ++i) - {minB[i] = NUGA::FLOAT_MAX; maxB[i] = -NUGA::FLOAT_MAX;} + { minB[i] = NUGA::FLOAT_MAX; maxB[i] = -NUGA::FLOAT_MAX; } for (size_t i = 0; i < indices.size(); ++i) { diff --git a/Cassiopee/KCore/KCore/Nuga/include/geom_sensor.hxx b/Cassiopee/KCore/KCore/Nuga/include/geom_sensor.hxx index 701abeeb9..253989584 100644 --- a/Cassiopee/KCore/KCore/Nuga/include/geom_sensor.hxx +++ b/Cassiopee/KCore/KCore/Nuga/include/geom_sensor.hxx @@ -141,7 +141,7 @@ bool geom_sensor::fill_adap_incr(output_t& adap_incr, bo //points_to_cell gives the number of points per cell Vector_t nb_pts_per_cell(_cur_nphs,0); - for (int i = 0; i < nb_pts; ++i) + for (E_Int i = 0; i < nb_pts; ++i) { E_Int PHi = _points_to_cell[i]; if (PHi != IDX_NONE) @@ -152,7 +152,7 @@ bool geom_sensor::fill_adap_incr(output_t& adap_incr, bo if (maxnbpercell > _max_pts_per_cell) { - for (int i = 0; i < _cur_nphs; ++i) + for (E_Int i = 0; i < _cur_nphs; ++i) { const E_Int* faces = parent_t::_hmesh._ng.PHs.get_facets_ptr(i); E_Int nb_faces = parent_t::_hmesh._ng.PHs.stride(i); @@ -166,7 +166,7 @@ bool geom_sensor::fill_adap_incr(output_t& adap_incr, bo if (do_agglo) { - for (int i = 0; i < _cur_nphs; ++i) + for (E_Int i = 0; i < _cur_nphs; ++i) { if (adap_incr.cell_adap_incr[i] == -1) continue; //already processed by brothorhood @@ -177,7 +177,7 @@ bool geom_sensor::fill_adap_incr(output_t& adap_incr, bo E_Int nb_children = parent_t::_hmesh._PHtree.nb_children(father); E_Int sum = 0; - for (int k = 0; k < nb_children; ++k) + for (E_Int k = 0; k < nb_children; ++k) { sum += nb_pts_per_cell[p[k]]; if (!parent_t::_hmesh._PHtree.is_enabled(p[k])) sum = _max_pts_per_cell + 1; @@ -185,7 +185,7 @@ bool geom_sensor::fill_adap_incr(output_t& adap_incr, bo } if (sum <= _max_pts_per_cell) // number of source points in the father <= criteria chosen : might be agglomerated : -1 for every child { - for (int k = 0; k < nb_children; ++k) { + for (E_Int k = 0; k < nb_children; ++k) { adap_incr.cell_adap_incr[p[k]] = -1; filled = true; } @@ -215,11 +215,11 @@ void geom_sensor::locate_points() E_Float minB[3]; E_Float maxB[3]; // - for (int i = 0; i < nb_src_pts; i++) + for (E_Int i = 0; i < nb_src_pts; i++) { const E_Float* p =parent_t::_data.get(i); - for (int j = 0; j < 3;j++) + for (E_Int j = 0; j < 3;j++) { minB[j] = p[j]-EPSILON; // small box over the source point maxB[j] = p[j]+EPSILON; @@ -255,7 +255,7 @@ E_Int geom_sensor::get_higher_lvl_cell(const E_Float* p, E_Int nb_children = parent_t::_hmesh._PHtree.nb_children(PHi); bool found = false; - for (int j = 0; j < nb_children; ++j) + for (E_Int j = 0; j < nb_children; ++j) { if (K_MESH::Polyhedron::pt_is_inside(q[j], parent_t::_hmesh._ng.PGs, parent_t::_hmesh._ng.PHs.get_facets_ptr(q[j]), parent_t::_hmesh._ng.PHs.stride(q[j]), parent_t::_hmesh._crd, parent_t::_hmesh._F2E, p, 1.e-14)) // true when the point is located in a child { @@ -284,7 +284,7 @@ E_Int geom_sensor::get_highest_lvl_cell(const E_Float* p const E_Int* q = parent_t::_hmesh._PHtree.children(PHi); // the children of PHi bool found = false; - for (int j = 0; j < nb_children; ++j) + for (E_Int j = 0; j < nb_children; ++j) { if (K_MESH::Polyhedron::pt_is_inside(q[j], parent_t::_hmesh._ng.PGs, parent_t::_hmesh._ng.PHs.get_facets_ptr(q[j]), parent_t::_hmesh._ng.PHs.stride(q[j]), parent_t::_hmesh._crd, parent_t::_hmesh._F2E, p, 1.e-14)) // true when the point is located in a child { @@ -313,18 +313,20 @@ E_Int geom_sensor::detect_child(const E_Float* p, E_Int parent_t::_hmesh.get_cell_center(children[0], center); E_Float min = NUGA::sqrDistance(p, center,3); - for (int i = 1; i < nb_children; ++i) + E_Float tmp[3]; + tmp[0] = K_CONST::E_MAX_FLOAT; + tmp[1] = K_CONST::E_MAX_FLOAT; + tmp[2] = K_CONST::E_MAX_FLOAT; + for (E_Int i = 1; i < nb_children; ++i) { - E_Float tmp[3]; parent_t::_hmesh.get_cell_center(children[i], tmp); - E_Float d = NUGA::sqrDistance(p,tmp,3); + E_Float d = NUGA::sqrDistance(p, tmp, 3); if (d < min) { min = d; closest_child = i; - for (int i = 0; i < 3; ++i) - center[i] = tmp[i]; + for (E_Int i = 0; i < 3; ++i) center[i] = tmp[i]; } } @@ -342,7 +344,7 @@ bool geom_sensor::update() E_Int nb_pts = _points_to_cell.size(); - for (int i = 0; i < nb_pts; ++i) + for (E_Int i = 0; i < nb_pts; ++i) { E_Int PHi = _points_to_cell[i]; diff --git a/Cassiopee/OCC/OCC/Atomic/addSphere.cpp b/Cassiopee/OCC/OCC/Atomic/addSphere.cpp index 13e73ea5f..a7526ffd1 100644 --- a/Cassiopee/OCC/OCC/Atomic/addSphere.cpp +++ b/Cassiopee/OCC/OCC/Atomic/addSphere.cpp @@ -23,6 +23,7 @@ #include "TopExp.hxx" #include "TopExp_Explorer.hxx" #include "BRepPrimAPI_MakeSphere.hxx" +#include "BRep_Builder.hxx" //===================================================================== // Add a sphere to hook @@ -39,29 +40,45 @@ PyObject* K_OCC::addSphere(PyObject* self, PyObject* args) packet = (void**) PyCapsule_GetPointer(hook, NULL); #endif - /* previous shape */ - //TopoDS_Shape* psh = (TopoDS_Shape*)packet[0]; - //TopAbs_ShapeEnum ptype = curShape.ShapeType(); - // == TopAbs_COMPOUND - //for(TopoDS_Iterator anExp(curShape); anExp.More(); anExp.Next()){ - //const TopoDS_Shape &curShape1 = anExp.Value(); + /* previous shape or compound */ + /* + TopoDS_Shape* psh = (TopoDS_Shape*)packet[0]; + + if (psh != NULL) + { + TopAbs_ShapeEnum ptype = psh->ShapeType(); + if (ptype == TopAbs_COMPOUND) + { + printf("previous is a compoud\n"); + // == TopAbs_COMPOUND + //for(TopoDS_Iterator anExp(psh); anExp.More(); anExp.Next()){ + //const TopoDS_Shape &curShape1 = anExp.Value();} + } + else + { printf("previous is a shape\n"); } + }*/ /* new sphere */ gp_Pnt center(xc, yc, zc); BRepPrimAPI_MakeSphere makerSphere(center, R); - TopoDS_Shape sh = makerSphere.Shape(); + TopoDS_Shape sphere = makerSphere.Shape(); - // Building the Resulting Compound - /* - TopoDS_Compound aRes; - BRep_Builder aBuilder; - aBuilder.MakeCompound(aRes); - aBuilder.Add(aRes, myBody); - aBuilder.Add(aRes, myThreading); - */ + /* another sphere */ + //gp_Pnt center2(xc+2, yc, zc); + //BRepPrimAPI_MakeSphere makerSphere2(center2, R); + //TopoDS_Shape sphere2 = makerSphere2.Shape(); + // Building a Compound + //TopoDS_Compound sh; + //BRep_Builder aBuilder; + //aBuilder.MakeCompound(sh); + //aBuilder.Add(sh, sphere); + //aBuilder.Add(sh, sphere2); + /* export */ - TopoDS_Shape* newshp = new TopoDS_Shape(sh); + TopoDS_Shape* newshp = new TopoDS_Shape(sphere); + //TopoDS_Shape* newshp = new TopoDS_Compound(sh); + packet[0] = newshp; // Extract surfaces diff --git a/Cassiopee/OCC/OCC/Atomic/createEmptyCAD.cpp b/Cassiopee/OCC/OCC/Atomic/createEmptyCAD.cpp index 6d7d89b23..b6e3bd897 100644 --- a/Cassiopee/OCC/OCC/Atomic/createEmptyCAD.cpp +++ b/Cassiopee/OCC/OCC/Atomic/createEmptyCAD.cpp @@ -19,11 +19,11 @@ #include "occ.h" #include "TopoDS_Shape.hxx" +#include "TopoDS_Compound.hxx" #include "TopTools_IndexedMapOfShape.hxx" #include "TopExp.hxx" #include "TopExp_Explorer.hxx" - // ============================================================================ /* Convert CAD to OpenCascade hook */ // ============================================================================ @@ -33,6 +33,8 @@ PyObject* K_OCC::createEmptyCAD(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "ss", &fileName, &fileFmt)) return NULL; TopoDS_Shape* shp = new TopoDS_Shape(); // empty shape + //TopoDS_Shape* shp = new TopoDS_Compound(); // empty shape + //TopoDS_Shape* shp = NULL; // Extract surfaces TopTools_IndexedMapOfShape* surfs = new TopTools_IndexedMapOfShape(); diff --git a/Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp b/Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp index b16ed8e84..8b60812a2 100644 --- a/Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp +++ b/Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp @@ -155,9 +155,8 @@ void geom3(E_Float u0, E_Float u1, E_Float h0, E_Float h1, E_Int& N, E_Float*& u if (delta >= 0) delta = sqrt(delta); E_Float r = ((u1-u0-h0)+delta)/(2*(u1-u0)); - E_Float r1 = ((u1-u0-h0)-delta)/(2*(u1-u0)); - - printf("r=%f\n", r); + //E_Float r1 = ((u1-u0-h0)-delta)/(2*(u1-u0)); + //printf("r=%f\n", r); E_Float a = log(r); if (a > 1.e-12) // r!=1 {