Skip to content

Commit

Permalink
OCC: try compounds on addSphere
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Sep 8, 2024
1 parent 843979d commit bd8d15a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cassiopee/CPlot/apps/validCassiopee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<Return>', setThreads)
TextThreads.bind('<KP_Enter>', setThreads)
getThreads()
Expand Down
12 changes: 7 additions & 5 deletions Cassiopee/KCore/KCore/Nuga/include/BbTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
}
Expand Down Expand Up @@ -271,8 +272,9 @@ class BoundingBox{
(const K_FLD::ArrayAccessor<CoordinateArray_t>& pos, const Vector<E_Int> & 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)
{
Expand Down
32 changes: 17 additions & 15 deletions Cassiopee/KCore/KCore/Nuga/include/geom_sensor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool geom_sensor<mesh_t, sensor_input_t>::fill_adap_incr(output_t& adap_incr, bo
//points_to_cell gives the number of points per cell
Vector_t<E_Int> 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)
Expand All @@ -152,7 +152,7 @@ bool geom_sensor<mesh_t, sensor_input_t>::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);
Expand All @@ -166,7 +166,7 @@ bool geom_sensor<mesh_t, sensor_input_t>::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

Expand All @@ -177,15 +177,15 @@ bool geom_sensor<mesh_t, sensor_input_t>::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;
if (sum > _max_pts_per_cell) break; // number of source points in the father > criteria chosen : cannot agglomerate
}
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;
}
Expand Down Expand Up @@ -215,11 +215,11 @@ void geom_sensor<mesh_t, sensor_input_t>::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;
Expand Down Expand Up @@ -255,7 +255,7 @@ E_Int geom_sensor<mesh_t, sensor_input_t>::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<UNKNOWN>::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
{
Expand Down Expand Up @@ -284,7 +284,7 @@ E_Int geom_sensor<mesh_t, sensor_input_t>::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<UNKNOWN>::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
{
Expand Down Expand Up @@ -313,18 +313,20 @@ E_Int geom_sensor<mesh_t, sensor_input_t>::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];
}
}

Expand All @@ -342,7 +344,7 @@ bool geom_sensor<mesh_t, sensor_input_t>::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];

Expand Down
49 changes: 33 additions & 16 deletions Cassiopee/OCC/OCC/Atomic/addSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "TopExp.hxx"
#include "TopExp_Explorer.hxx"
#include "BRepPrimAPI_MakeSphere.hxx"
#include "BRep_Builder.hxx"

//=====================================================================
// Add a sphere to hook
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Cassiopee/OCC/OCC/Atomic/createEmptyCAD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
// ============================================================================
Expand All @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit bd8d15a

Please sign in to comment.