From: Anthony Geay Date: Thu, 29 Aug 2024 16:10:09 +0000 (+0200) Subject: [EDF30834] : WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bd8171f43be538b749c3fbf7e76a2c841d3c4db5;p=tools%2Fmedcoupling.git [EDF30834] : WIP --- diff --git a/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx b/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx index 4f1895c55..fe0e7b2b0 100644 --- a/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx +++ b/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx @@ -27,6 +27,17 @@ using namespace MEDCoupling; ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh) +{ + assign( mesh ); +} + +ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh) +{ + MCAuto< MEDCouplingUMesh > meshIn = MCAuto< MEDCouplingUMesh >::TakeRef( mesh ); + assign( meshIn ); +} + +void ShapeRecognMeshBuilder::assign(MCAuto< MEDCouplingUMesh > mesh) { this->mesh = mesh; if (mesh->getMeshDimension() != 2) @@ -35,6 +46,7 @@ ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh) throw INTERP_KERNEL::Exception("Expect a mesh containing exclusively triangular cells"); } + MCAuto ShapeRecognMeshBuilder::recognize() { mesh->incrRef(); diff --git a/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx b/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx index 6bd1853c8..af7b53476 100644 --- a/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx +++ b/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx @@ -37,6 +37,7 @@ namespace MEDCoupling { public: ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh); + ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh); ~ShapeRecognMeshBuilder() = default; const Nodes *getNodes() const; @@ -77,6 +78,7 @@ namespace MEDCoupling MCAuto values) const; double *buildArea3DArray(const std::array &(*areaFunc)(Areas *, mcIdType)) const; double *buildAreaArray(double (*areaFunc)(Areas *, mcIdType)) const; + void assign(MCAuto< MEDCouplingUMesh > mesh); private: MCConstAuto< MEDCouplingUMesh > mesh; std::unique_ptr nodes; diff --git a/src/ShapeRecogn/Swig/CMakeLists.txt b/src/ShapeRecogn/Swig/CMakeLists.txt index c738e10f5..1a73c982c 100644 --- a/src/ShapeRecogn/Swig/CMakeLists.txt +++ b/src/ShapeRecogn/Swig/CMakeLists.txt @@ -75,7 +75,6 @@ IF(WIN32) ENDIF(WIN32) INSTALL(TARGETS _ShapeRecogn DESTINATION ${MEDCOUPLING_INSTALL_PYTHON}) -INSTALL(FILES ShapeRecogn.i DESTINATION ${MEDCOUPLING_INSTALL_HEADERS}) SALOME_INSTALL_SCRIPTS( ${CMAKE_CURRENT_BINARY_DIR}/ShapeRecogn.py diff --git a/src/ShapeRecogn/Swig/ShapeRecogn.i b/src/ShapeRecogn/Swig/ShapeRecogn.i index 3e0313357..0b129593b 100644 --- a/src/ShapeRecogn/Swig/ShapeRecogn.i +++ b/src/ShapeRecogn/Swig/ShapeRecogn.i @@ -19,16 +19,199 @@ %module ShapeRecogn -%include "std_string.i" -%include "MEDCouplingCommon.i" +%include "ShapeRecognCommon.i" -%{ -#include "ShapeRecognMesh.hxx" -#include "ShapeRecognMeshBuilder.hxx" -using namespace MEDCoupling; +%pythoncode %{ +def MEDCouplingDataArrayDoubleIadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDouble____iadd___(self, self, *args) +def MEDCouplingDataArrayDoubleIsub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDouble____isub___(self, self, *args) +def MEDCouplingDataArrayDoubleImul(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDouble____imul___(self, self, *args) +def MEDCouplingDataArrayDoubleIdiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDouble____idiv___(self, self, *args) +def MEDCouplingDataArrayDoubleIpow(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDouble____ipow___(self, self, *args) +def MEDCouplingDataArrayInt32Iadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32____iadd___(self, self, *args) +def MEDCouplingDataArrayInt32Isub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32____isub___(self, self, *args) +def MEDCouplingDataArrayInt32Imul(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32____imul___(self, self, *args) +def MEDCouplingDataArrayInt32Idiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32____idiv___(self, self, *args) +def MEDCouplingDataArrayInt32Imod(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32____imod___(self, self, *args) +def MEDCouplingDataArrayInt32Ipow(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32____ipow___(self, self, *args) +def MEDCouplingDataArrayInt64Iadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64____iadd___(self, self, *args) +def MEDCouplingDataArrayInt64Isub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64____isub___(self, self, *args) +def MEDCouplingDataArrayInt64Imul(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64____imul___(self, self, *args) +def MEDCouplingDataArrayInt64Idiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64____idiv___(self, self, *args) +def MEDCouplingDataArrayInt64Imod(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64____imod___(self, self, *args) +def MEDCouplingDataArrayInt64Ipow(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64____ipow___(self, self, *args) +def MEDCouplingDataArrayFloatIadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayFloat____iadd___(self, self, *args) +def MEDCouplingDataArrayFloatIsub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayFloat____isub___(self, self, *args) +def MEDCouplingDataArrayFloatImul(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayFloat____imul___(self, self, *args) +def MEDCouplingDataArrayFloatIdiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayFloat____idiv___(self, self, *args) +def MEDCouplingDataArrayDoubleTupleIadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDoubleTuple____iadd___(self, self, *args) +def MEDCouplingDataArrayDoubleTupleIsub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDoubleTuple____isub___(self, self, *args) +def MEDCouplingDataArrayDoubleTupleImul(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDoubleTuple____imul___(self, self, *args) +def MEDCouplingDataArrayDoubleTupleIdiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayDoubleTuple____idiv___(self, self, *args) +def MEDCouplingDataArrayInt32TupleIadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32Tuple____iadd___(self, self, *args) +def MEDCouplingDataArrayInt32TupleIsub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32Tuple____isub___(self, self, *args) +def MEDCouplingDataArrayInt32TupleImul(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32Tuple____imul___(self, self, *args) +def MEDCouplingDataArrayInt32TupleIdiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32Tuple____idiv___(self, self, *args) +def MEDCouplingDataArrayInt32TupleImod(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt32Tuple____imod___(self, self, *args) +def MEDCouplingDataArrayInt64TupleIadd(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64Tuple____iadd___(self, self, *args) +def MEDCouplingDataArrayInt64TupleIsub(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64Tuple____isub___(self, self, *args) +def MEDCouplingDataArrayInt64TupleImul(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64Tuple____imul___(self, self, *args) +def MEDCouplingDataArrayInt64TupleIdiv(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64Tuple____idiv___(self, self, *args) +def MEDCouplingDataArrayInt64TupleImod(self,*args): + import _MEDRenumber + return _MEDRenumber.DataArrayInt64Tuple____imod___(self, self, *args) %} -%ignore getAreas() const; -%ignore getNodes() const; -%include "ShapeRecognMesh.hxx" -%include "ShapeRecognMeshBuilder.hxx" + +%pythoncode %{ +InterpKernelException.__reduce__=INTERPKERNELExceptionReduce +DataArrayDouble.__reduce__=MEDCouplingDataArrayDoubleReduce +DataArrayDouble.__iadd__=MEDCouplingDataArrayDoubleIadd +DataArrayDouble.__isub__=MEDCouplingDataArrayDoubleIsub +DataArrayDouble.__imul__=MEDCouplingDataArrayDoubleImul +DataArrayDouble.__idiv__=MEDCouplingDataArrayDoubleIdiv +DataArrayDouble.__ipow__=MEDCouplingDataArrayDoubleIpow + +DataArrayInt32.__reduce__=MEDCouplingDataArrayInt32Reduce +DataArrayInt32.__iadd__=MEDCouplingDataArrayInt32Iadd +DataArrayInt32.__isub__=MEDCouplingDataArrayInt32Isub +DataArrayInt32.__imul__=MEDCouplingDataArrayInt32Imul +DataArrayInt32.__idiv__=MEDCouplingDataArrayInt32Idiv +DataArrayInt32.__imod__=MEDCouplingDataArrayInt32Imod +DataArrayInt32.__ipow__=MEDCouplingDataArrayInt32Ipow +DataArrayInt64.__reduce__=MEDCouplingDataArrayInt64Reduce +DataArrayInt64.__iadd__=MEDCouplingDataArrayInt64Iadd +DataArrayInt64.__isub__=MEDCouplingDataArrayInt64Isub +DataArrayInt64.__imul__=MEDCouplingDataArrayInt64Imul +DataArrayInt64.__idiv__=MEDCouplingDataArrayInt64Idiv +DataArrayInt64.__imod__=MEDCouplingDataArrayInt64Imod +DataArrayInt64.__ipow__=MEDCouplingDataArrayInt64Ipow + +DataArrayDoubleTuple.__iadd__=MEDCouplingDataArrayDoubleTupleIadd +DataArrayDoubleTuple.__isub__=MEDCouplingDataArrayDoubleTupleIsub +DataArrayDoubleTuple.__imul__=MEDCouplingDataArrayDoubleTupleImul +DataArrayDoubleTuple.__idiv__=MEDCouplingDataArrayDoubleTupleIdiv + +DataArrayInt32Tuple.__iadd__=MEDCouplingDataArrayInt32TupleIadd +DataArrayInt32Tuple.__isub__=MEDCouplingDataArrayInt32TupleIsub +DataArrayInt32Tuple.__imul__=MEDCouplingDataArrayInt32TupleImul +DataArrayInt32Tuple.__idiv__=MEDCouplingDataArrayInt32TupleIdiv +DataArrayInt32Tuple.__itruediv__=MEDCouplingDataArrayInt32TupleIdiv +DataArrayInt32Tuple.__ifloordiv__=MEDCouplingDataArrayInt32TupleIdiv +DataArrayInt32Tuple.__imod__=MEDCouplingDataArrayInt32TupleImod + +DataArrayInt64Tuple.__iadd__=MEDCouplingDataArrayInt64TupleIadd +DataArrayInt64Tuple.__isub__=MEDCouplingDataArrayInt64TupleIsub +DataArrayInt64Tuple.__imul__=MEDCouplingDataArrayInt64TupleImul +DataArrayInt64Tuple.__idiv__=MEDCouplingDataArrayInt64TupleIdiv +DataArrayInt64Tuple.__itruediv__=MEDCouplingDataArrayInt64TupleIdiv +DataArrayInt64Tuple.__ifloordiv__=MEDCouplingDataArrayInt64TupleIdiv +DataArrayInt64Tuple.__imod__=MEDCouplingDataArrayInt64TupleImod + + + + +del INTERPKERNELExceptionReduce +del MEDCouplingDataArrayDoubleIadd +del MEDCouplingDataArrayDoubleIdiv +del MEDCouplingDataArrayDoubleImul +del MEDCouplingDataArrayDoubleIpow +del MEDCouplingDataArrayDoubleIsub +del MEDCouplingDataArrayDoubleReduce +del MEDCouplingDataArrayDoubleTupleIadd +del MEDCouplingDataArrayDoubleTupleIdiv +del MEDCouplingDataArrayDoubleTupleImul +del MEDCouplingDataArrayDoubleTupleIsub +del MEDCouplingDataArrayInt32Iadd +del MEDCouplingDataArrayInt32Idiv +del MEDCouplingDataArrayInt32Imod +del MEDCouplingDataArrayInt32Imul +del MEDCouplingDataArrayInt32Ipow +del MEDCouplingDataArrayInt32Isub +del MEDCouplingDataArrayInt32Reduce +del MEDCouplingDataArrayInt32TupleIadd +del MEDCouplingDataArrayInt32TupleIdiv +del MEDCouplingDataArrayInt32TupleImod +del MEDCouplingDataArrayInt32TupleImul +del MEDCouplingDataArrayInt32TupleIsub +del MEDCouplingDataArrayInt64Iadd +del MEDCouplingDataArrayInt64Idiv +del MEDCouplingDataArrayInt64Imod +del MEDCouplingDataArrayInt64Imul +del MEDCouplingDataArrayInt64Ipow +del MEDCouplingDataArrayInt64Isub +del MEDCouplingDataArrayInt64Reduce +del MEDCouplingDataArrayInt64TupleIadd +del MEDCouplingDataArrayInt64TupleIdiv +del MEDCouplingDataArrayInt64TupleImod +del MEDCouplingDataArrayInt64TupleImul +del MEDCouplingDataArrayInt64TupleIsub + +%} diff --git a/src/ShapeRecogn/Swig/ShapeRecognCommon.i b/src/ShapeRecogn/Swig/ShapeRecognCommon.i new file mode 100644 index 000000000..5362e77bd --- /dev/null +++ b/src/ShapeRecogn/Swig/ShapeRecognCommon.i @@ -0,0 +1,65 @@ +// Copyright (C) 2024 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%include "std_string.i" +%include "MEDCouplingCommon.i" + +%{ +#include "MEDCouplingMemArray.txx" +#include "MCAuto.hxx" +#include "MEDCouplingDataArrayTypemaps.i" + +using namespace MEDCoupling; +using namespace INTERP_KERNEL; +%} + +%template(ivec) std::vector; +%template(dvec) std::vector; +%template(svec) std::vector; + +#ifdef WITH_NUMPY +%init %{ import_array(); %} +#endif + +%init %{ initializeMe_shape_recogn(); %} + +%feature("autodoc", "1"); +%feature("docstring"); + +%nodefaultctor; + +%rename (InterpKernelException) INTERP_KERNEL::Exception; + +%{ + void initializeMe_shape_recogn() + {// AGY : here initialization of C++ traits in MEDCouplingDataArrayTypemaps.i for code factorization. Awful, I know, but no other solutions. + SWIGTITraits::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble; + SWIGTITraits::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat; + } +%} + +%include "ShapeRecognImpl.i" + +%pythoncode %{ +import os +__filename=os.environ.get('PYTHONSTARTUP') +if __filename and os.path.isfile(__filename): + with open(__filename) as __fp: + exec(__fp.read()) +%} diff --git a/src/ShapeRecogn/Swig/ShapeRecognImpl.i b/src/ShapeRecogn/Swig/ShapeRecognImpl.i new file mode 100644 index 000000000..c09a23315 --- /dev/null +++ b/src/ShapeRecogn/Swig/ShapeRecognImpl.i @@ -0,0 +1,185 @@ +// Copyright (C) 2024 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%{ +#include "ShapeRecognMesh.hxx" +#include "ShapeRecognMeshBuilder.hxx" +#include "Areas.hxx" +%} + +%feature("unref") ShapeRecognMesh "$this->decrRef();" + +%newobject ShapeRecognMeshBuilder::recognize; + +%newobject ShapeRecognMesh::getNodeK1; +%newobject ShapeRecognMesh::getNodeK2; +%newobject ShapeRecognMesh::getNodePrimitiveType; +%newobject ShapeRecognMesh::getNodeNormal; +%newobject ShapeRecognMesh::getAreaId; +%newobject ShapeRecognMesh::getAreaPrimitiveType; +%newobject ShapeRecognMesh::getAreaNormal; +%newobject ShapeRecognMesh::getMinorRadius; +%newobject ShapeRecognMesh::getRadius; +%newobject ShapeRecognMesh::getAngle; +%newobject ShapeRecognMesh::getCenter; +%newobject ShapeRecognMesh::getAxis; +%newobject ShapeRecognMesh::getApex; + +class Areas +{ +public: + double getMinorRadius(mcIdType areaId) const; + double getRadius(mcIdType areaId) const; + double getAngle(mcIdType areaId) const; + /*const std::array &getNormal(mcIdType areaId) const; + const std::array &getCenter(mcIdType areaId) const; + const std::array &getAxis(mcIdType areaId) const; + const std::array &getAxisPoint(mcIdType areaId) const; + const std::array &getApex(mcIdType areaId) const; + std::array getAffinePoint(mcIdType areaId) const;*/ +private: + Areas(); + ~Areas(); +}; + +class ShapeRecognMesh : public RefCountObject +{ +public: + ~ShapeRecognMesh(); + + // Node properties + MEDCouplingFieldDouble *getNodeK1() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getNodeK1() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getNodeK2() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getNodeK2() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getNodePrimitiveType() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getNodePrimitiveType() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getNodeNormal() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getNodeNormal() ); + ret->incrRef(); + return ret; + } + + // Area properties + + MEDCouplingFieldDouble *getAreaId() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getAreaId() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getAreaPrimitiveType() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getAreaPrimitiveType() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getAreaNormal() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getAreaNormal() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getMinorRadius() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getMinorRadius() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getRadius() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getRadius() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getAngle() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getAngle() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getCenter() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getCenter() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getAxis() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getAxis() ); + ret->incrRef(); + return ret; + } + + MEDCouplingFieldDouble *getApex() const + { + MEDCouplingFieldDouble *ret = const_cast( self->getApex() ); + ret->incrRef(); + return ret; + } +private: + ShapeRecognMesh(); +}; + +class ShapeRecognMeshBuilder +{ +public: + ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh); + ~ShapeRecognMeshBuilder(); + + //const Nodes *getNodes() const; + const Areas *getAreas() const; + %extend + { + ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh) + { + + + } + + ShapeRecognMesh *recognize() + { + MCAuto ret = self->recognize(); + return ret.retn(); + } + } +};