OPTION(MEDCOUPLING_ENABLE_PYTHON "Build PYTHON bindings." ON)
OPTION(MEDCOUPLING_ENABLE_PARTITIONER "Build MEDPartitioner." ON)
OPTION(MEDCOUPLING_ENABLE_RENUMBER "Build Renumber." ON)
-OPTION(MEDCOUPLING_ENABLE_SHAPERECOGN "Build ShapeRecogn" OFF)
+OPTION(MEDCOUPLING_ENABLE_SHAPERECOGN "Build Shape Recognition module." OFF)
OPTION(MEDCOUPLING_WITH_FILE_EXAMPLES "Install examples of files containing meshes and fields of different formats." ON)
OPTION(MEDCOUPLING_USE_MPI "(Use MPI containers) - For MED this triggers the build of ParaMEDMEM." OFF)
OPTION(MEDCOUPLING_BUILD_TESTS "Build MEDCoupling C++ tests." ON)
IF(MEDCOUPLING_BUILD_STATIC)
SET(BUILD_SHARED_LIBS 0)
SET(CMAKE_POSITION_INDEPENDENT_CODE 1) # -fPIC option
-ELSE()
+ELSE(MEDCOUPLING_BUILD_STATIC)
SET(BUILD_SHARED_LIBS 1)
-ENDIF()
+ENDIF(MEDCOUPLING_BUILD_STATIC)
IF(${MEDCOUPLING_PARTITIONER_PARMETIS} AND ${MEDCOUPLING_PARTITIONER_METIS})
MESSAGE(FATAL_ERROR "ParMetis and Metis are mutually exclusive! Make a choice (options MEDCOUPLING_PARTITIONER_METIS and MEDCOUPLING_PARTITIONER_PARMETIS).")
-ENDIF()
+ENDIF(${MEDCOUPLING_PARTITIONER_PARMETIS} AND ${MEDCOUPLING_PARTITIONER_METIS})
IF(${MEDCOUPLING_PARTITIONER_PTSCOTCH} AND ${MEDCOUPLING_PARTITIONER_SCOTCH})
MESSAGE(FATAL_ERROR "PTScotch and Scotch are mutually exclusive! Make a choice (options MEDCOUPLING_PARTITIONER_SCOTCH and MEDCOUPLING_PARTITIONER_PTSCOTCH).")
-ENDIF()
+ENDIF(${MEDCOUPLING_PARTITIONER_PTSCOTCH} AND ${MEDCOUPLING_PARTITIONER_SCOTCH})
#
# Set list of prerequisites
ADD_SUBDIRECTORY(MEDCoupling)
ADD_SUBDIRECTORY(ICoCo)
+# Shape recognition
+IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+ ADD_SUBDIRECTORY(ShapeRecogn)
+ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+
IF(MEDCOUPLING_ENABLE_PYTHON)
ADD_SUBDIRECTORY(MEDCoupling_Swig)
ENDIF(MEDCOUPLING_BUILD_TESTS)
ENDIF(MEDCOUPLING_USE_MPI)
-IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
- ADD_SUBDIRECTORY(ShapeRecogn)
-ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
# Application tests
configure_file(CTestTestfileInstall.cmake.in "CTestTestfileST.cmake" @ONLY)
SET(TIMEOUT 120)
SET(MEDCOUPLING_BUILD_PY_TESTS $<BOOL:@MEDCOUPLING_BUILD_PY_TESTS@>)
SET(MEDCOUPLING_USE_MPI_BOOL $<BOOL:@MEDCOUPLING_USE_MPI@>)
+SET(MEDCOUPLING_ENABLE_SHAPERECOGN $<BOOL:@MEDCOUPLING_ENABLE_SHAPERECOGN@>)
SUBDIRS(INTERP_KERNELTest)
SUBDIRS(MEDCoupling)
SUBDIRS(ParaMEDMEM_Swig)
endif()
+if(MEDCOUPLING_ENABLE_SHAPERECOGN)
+ SUBDIRS(ShapeRecogn)
+endif()
+
SUBDIRS(MEDPartitioner_Swig)
SUBDIRS(RENUMBER_Swig)
SUBDIRS(PyWrapping)
bool operator==(const MCConstAuto& other) const { return _ptr==other._ptr; }
bool operator==(const T *other) const { return _ptr==other; }
MCConstAuto &operator=(const MCConstAuto& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; }
+ MCConstAuto &operator=(const typename MEDCoupling::MCAuto<T>& other) { if(_ptr!=(const T*)other) { destroyPtr(); referPtr((const T*)other); } return *this; }
MCConstAuto &operator=(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
void takeRef(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; if(_ptr) _ptr->incrRef(); } }
const T *operator->() { return _ptr ; }
${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM
${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM/MPIAccess
${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM_Swig
+ ${CMAKE_CURRENT_SOURCE_DIR}/../ShapeRecogn
+ ${CMAKE_CURRENT_SOURCE_DIR}/../ShapeRecogn/Swig
${PROJECT_BINARY_DIR}/doc
)
-
-IF(WIN32 OR CYGWIN)
+
+ IF(WIN32 OR CYGWIN)
SET(medcoupling_LIB_dependancies ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medcouplingremapper medicoco)
-ELSE(WIN32)
+ ELSE(WIN32 OR CYGWIN)
# ${PYTHON_LIBRARIES} not needed see https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
SET(medcoupling_LIB_dependancies ${PLATFORM_LIBS} medcouplingremapper medicoco)
-ENDIF(WIN32 OR CYGWIN)
+ ENDIF(WIN32 OR CYGWIN)
+ IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+ LIST(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS -DWITH_SHAPE_RECOGN)
+ LIST(APPEND medcoupling_LIB_dependancies shaperecogn)
+ ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+
IF(NOT MEDCOUPLING_MICROMED)
LIST(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS -DWITH_MED_FILE)
LIST(APPEND medcoupling_LIB_dependancies medloader)
a,b,c=f3.getTime()
self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14);
pass
-
+
+ @unittest.skipUnless(HasShapeRecognitionExt(),"Requires Shape recognition extension activated")
+ def test6(self):
+ m = MEDCouplingCMesh()
+ arr = DataArrayDouble(5) ; arr.iota()
+ m.setCoords(arr,arr)
+ m = m.buildUnstructured()
+ m.simplexize(0)
+ m.changeSpaceDimension(3,0.)
+ srMesh = ShapeRecognMeshBuilder( m )
+ rem = srMesh.recognize()
def partitionerTesterHelper(self,algoSelected):
arr=DataArrayDouble(10) ; arr.iota()
%include "ParaMEDMEMCommon.i"
#endif
+#ifdef WITH_SHAPE_RECOGN
+%include "ShapeRecognCommon.i"
+#endif
+
%constant const char __version__[]=MEDCOUPLING_GIT_SHA1;
%constant const char __config_datetime__[]=MEDCOUPLING_CONFIG_DT;
static const char RENUM_EXT[]="Renumberer";
static const char PART_EXT[]="Partitioner";
static const char PAR_INTERPOL_EXT[]="Parallel interpolator (SPMD paradigm)";
- static const char IT_STATS_EXT[] = "Iterative statistics";
-
- static const char *EXTENSIONS[]={SEQ_INTERPOL_EXT,MEDFILEIO_EXT,RENUM_EXT,PART_EXT,PAR_INTERPOL_EXT,IT_STATS_EXT};
+ static const char IT_STATS_EXT[]="Iterative statistics";
+ static const char SHAPE_RECOGNITION_EXT[]="Shape Recognition";
+
+ static const char *EXTENSIONS[]={SEQ_INTERPOL_EXT,MEDFILEIO_EXT,RENUM_EXT,PART_EXT,PAR_INTERPOL_EXT,IT_STATS_EXT,SHAPE_RECOGNITION_EXT};
static const int NB_OF_EXTENSIONS=sizeof(EXTENSIONS)/sizeof(const char *);
%}
return false;
#endif
}
+
+ bool HasShapeRecognitionExt()
+ {
+#ifdef WITH_SHAPE_RECOGN
+ return true;
+#else
+ return false;
+#endif
+ }
std::vector<std::string> ActiveExtensions()
{
#endif
#ifdef WITH_ITERATIVE_STATISTICS
ret.push_back(std::string(IT_STATS_EXT));
+#endif
+#ifdef WITH_SHAPE_RECOGN
+ ret.push_back(std::string(SHAPE_RECOGNITION_EXT));
#endif
return ret;
}
+// 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 "Areas.hxx"
#include "MathOps.hxx"
void Areas::addNode(mcIdType areaId, mcIdType nodeId)
{
removeNode(nodeId);
- areaIdByNodes[nodeId] = areaId;
+ areaIdByNodes[nodeId] = FromIdType<Int32>(areaId);
Area &area = areas[areaId];
area.nodeIds.push_back(nodeId);
size_t nbNodes = area.nodeIds.size();
std::string Areas::getPrimitiveTypeName(mcIdType areaId) const
{
- return convertPrimitiveToString(getPrimitiveType(areaId));
+ return ConvertPrimitiveToString(getPrimitiveType(areaId));
}
int Areas::getPrimitiveTypeInt(mcIdType areaId) const
{
- return convertPrimitiveToInt(getPrimitiveType(areaId));
+ return ConvertPrimitiveToInt(getPrimitiveType(areaId));
}
const std::vector<mcIdType> &Areas::getNodeIds(mcIdType areaId) const
{
Area &area = areas[areaId];
for (mcIdType nodeId : area.nodeIds)
- areaIdByNodes[nodeId] = newAreaId;
+ areaIdByNodes[nodeId] = FromIdType<Int32>( newAreaId );
area.primitive = PrimitiveType::Unknown;
area.k1 = 0.0;
area.k2 = 0.0;
area.center[i] = xc * base2d[i] + yc * base2d[3 + i] + meanMajorRadiusNodes[i];
}
-const std::vector<mcIdType> &Areas::getAreaIdByNodes() const
+const std::vector<Int32> &Areas::getAreaIdByNodes() const
{
return areaIdByNodes;
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __AREAS_HXX__
-#define __AREAS_HXX__
+#pragma once
#include "PrimitiveType.hxx"
#include "Nodes.hxx"
void cleanInvalidNodeAreas();
mcIdType getAreaId(mcIdType nodeId) const;
- const std::vector<mcIdType> &getAreaIdByNodes() const;
+ const std::vector<Int32> &getAreaIdByNodes() const;
bool isEmpty(mcIdType areaId) const;
size_t getNumberOfAreas() const;
std::vector<Area> areas;
const Nodes *nodes;
- std::vector<mcIdType> areaIdByNodes;
+ std::vector<Int32> areaIdByNodes;
};
-};
-
-#endif // __AREAS_HXX__
+}
+// 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 "AreasBuilder.hxx"
#include "MathOps.hxx"
#include "ShapeRecongConstants.hxx"
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __AREASBUILDER_HXX__
-#define __AREASBUILDER_HXX__
+#pragma once
#include "Nodes.hxx"
#include "Areas.hxx"
size_t threshold = 5;
};
-};
-
-#endif // __AREASBUILDER_HXX__
\ No newline at end of file
+}
-# Copyright (C) 2012-2024 CEA, EDF
+# 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
${MEDFILE_INCLUDE_DIRS}
${HDF5_INCLUDE_DIRS}
${LAPACKE_INCLUDE_DIRS}
- ${CMAKE_CURRENT_SOURCE_DIR}/../MEDLoader
${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling
${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL
${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases
AreasBuilder.cxx
ShapeRecognMeshBuilder.cxx
ShapeRecognMesh.cxx
+ PrimitiveType.cxx
)
ADD_LIBRARY(shaperecogn ${shaperecogn_SOURCES})
SET_TARGET_PROPERTIES(shaperecogn PROPERTIES COMPILE_FLAGS "")
-TARGET_LINK_LIBRARIES(shaperecogn medcouplingcpp medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${LAPACK_LIBRARIES})
+TARGET_LINK_LIBRARIES(shaperecogn medcouplingcpp ${LAPACK_LIBRARIES})
INSTALL(TARGETS shaperecogn EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${MEDCOUPLING_INSTALL_LIBS})
FILE(GLOB shaperecogn_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
-INSTALL(FILES ${shaperecogn_HEADERS_HXX} DESTINATION ${MEDCOUPLING_INSTALL_HEADERS})
# To allow usage as SWIG dependencies:
SET(shaperecogn_HEADERS_HXX PARENT_SCOPE)
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
//
#include "MathOps.hxx"
+#include "MCIdType.hxx"
#include <algorithm>
#include <lapacke.h>
#include <cblas.h>
#include <iostream>
#include <cfloat>
+#include <cmath>
+#include <cstdlib>
using namespace MEDCoupling;
std::vector<double> &a,
const std::vector<double> &b)
{
- int m = b.size();
- int n = 3;
- int nrhs = 1;
- int ldb = std::max<int>(m, n);
- int lds = std::min<int>(m, n);
+ auto m = b.size();
+ std::size_t n = 3;
+ std::size_t nrhs = 1;
+ std::size_t ldb = std::max<std::size_t>(m, n);
+ std::size_t lds = std::min<std::size_t>(m, n);
std::vector<double> x(ldb, 0.0);
for (size_t i = 0; i < b.size(); ++i)
x[i] = b[i];
int rank = 0;
int info = LAPACKE_dgelsd(
LAPACK_ROW_MAJOR,
- m, n, nrhs,
- a.data(), n,
- x.data(), nrhs,
+ FromIdType<int>(m), FromIdType<int>(n), FromIdType<int>(nrhs),
+ a.data(), FromIdType<int>(n),
+ x.data(), FromIdType<int>(nrhs),
s.data(),
rcond,
&rank);
double mean = 0.0;
for (double value : values)
mean += value;
- return mean / values.size();
+ return mean / double( values.size() );
}
std::array<double, 3> MathOps::meanCoordinates(const std::vector<double> &coordinates)
coordsMean[1] += coordinates[3 * nodeId + 1];
coordsMean[2] += coordinates[3 * nodeId + 2];
}
- coordsMean[0] /= nbNodes;
- coordsMean[1] /= nbNodes;
- coordsMean[2] /= nbNodes;
+ coordsMean[0] /= double( nbNodes );
+ coordsMean[1] /= double( nbNodes );
+ coordsMean[2] /= double( nbNodes );
return coordsMean;
}
{
std::vector<double> sortedValues(values);
std::sort(sortedValues.begin(), sortedValues.end());
- double pos = q * (sortedValues.size() - 1);
+ double pos = q * double(sortedValues.size() - 1);
size_t index = static_cast<size_t>(pos);
- if (pos == index)
+ if ( std::abs( pos - double(index) ) < 1e-12 )
return sortedValues[index];
else
{
- double frac = pos - index;
+ double frac = pos - double(index);
return sortedValues[index] * (1 - frac) + sortedValues[index + 1] * frac;
}
}
cblas_dgemv(
CBLAS_LAYOUT::CblasRowMajor,
CBLAS_TRANSPOSE::CblasNoTrans,
- nbDirections, 3, 1.0,
+ int(nbDirections), 3, 1.0,
directions.data(), 3,
axis.data(), 1,
0.0, angles.data(), 1);
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __MATHOPS_HXX__
-#define __MATHOPS_HXX__
+#pragma once
#include <vector>
#include <array>
static double computeVariance(std::vector<double> values);
static std::array<double, 6> computeBaseFromNormal(std::array<double, 3> normal);
};
-};
-
-#endif //__MATHOPS_HXX__
+}
+// 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 "Nodes.hxx"
using namespace MEDCoupling;
{
}
-Nodes::~Nodes()
-{
- mesh->decrRef();
- neighbors->decrRef();
- neighborsIdx->decrRef();
-}
-
mcIdType Nodes::getNbNodes() const
{
return coords->getNumberOfTuples();
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __NODES_HXX__
-#define __NODES_HXX__
+#pragma once
#include <vector>
#include "MEDCouplingUMesh.hxx"
Nodes(const MEDCouplingUMesh *mesh,
const DataArrayInt64 *neighbors,
const DataArrayInt64 *neighborsIdx);
- ~Nodes();
+ ~Nodes() = default;
mcIdType getNbNodes() const;
const std::vector<double> &getK1() const;
std::array<double, 3> getCoordinates(mcIdType nodeId) const;
private:
- const MEDCouplingUMesh *mesh;
+ MCConstAuto<MEDCouplingUMesh> mesh;
const DataArrayDouble *coords;
// normals 3 * nbNodes
std::vector<double> normals;
// neighbors
- const DataArrayInt64 *neighbors;
- const DataArrayInt64 *neighborsIdx;
+ MCConstAuto<DataArrayInt64> neighbors;
+ MCConstAuto<DataArrayInt64> neighborsIdx;
// curvature
std::vector<double> k1;
std::vector<double> k2;
std::vector<double> mainDirections;
std::vector<PrimitiveType> primitives;
};
-};
-
-#endif //__NODES_HXX__
+}
+// 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 "NodesBuilder.hxx"
#include "Nodes.hxx"
}
//
nodes->normals.resize(3 * nbNodes, 1.0);
- DataArrayInt64 *revNodal = DataArrayInt64::New();
- DataArrayInt64 *revNodalIdx = DataArrayInt64::New();
+ MCAuto<DataArrayInt64> revNodal = DataArrayInt64::New();
+ MCAuto<DataArrayInt64> revNodalIdx = DataArrayInt64::New();
mesh->getReverseNodalConnectivity(revNodal, revNodalIdx);
for (size_t nodeId = 0; nodeId < (size_t)nbNodes; nodeId++)
{
- int nbCells = revNodalIdx->getIJ(nodeId + 1, 0) -
- revNodalIdx->getIJ(nodeId, 0);
+ mcIdType nbCells = revNodalIdx->getIJ(nodeId + 1, 0) -
+ revNodalIdx->getIJ(nodeId, 0);
std::vector<mcIdType> cellIds(nbCells, 0);
- int start = revNodalIdx->getIJ(nodeId, 0);
+ mcIdType start = revNodalIdx->getIJ(nodeId, 0);
for (size_t i = 0; i < cellIds.size(); ++i)
cellIds[i] = revNodal->getIJ(start + i, 0);
double normal = 0.0;
for (size_t i = 0; i < 3; i++)
nodes->normals[3 * nodeId + i] /= sqrt(normal);
}
- revNodal->decrRef();
- revNodalIdx->decrRef();
}
void NodesBuilder::computeCurvatures(double tol)
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __NODECURVATURECALCULATOR_HXX__
-#define __NODECURVATURECALCULATOR_HXX__
+#pragma once
#include <string>
#include <vector>
const MEDCouplingUMesh *mesh;
Nodes *nodes;
};
-};
-
-#endif //__NODECURVATURECALCULATOR_HXX__
\ No newline at end of file
+}
--- /dev/null
+// 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 "PrimitiveType.hxx"
+
+#include <iterator>
+#include <algorithm>
+
+constexpr char PLANE_STR[] = "Plane";
+constexpr char SPHERE_STR[] = "Sphere";
+constexpr char CYLINDER_STR[] = "Cylinder";
+constexpr char CONE_STR[] = "Cone";
+constexpr char TORUS_STR[] = "Torus";
+constexpr char UNKNOWN_STR[] = "Unknown";
+
+std::vector<MEDCoupling::PrimitiveType> MEDCoupling::AllManagedPrimitives()
+{
+ return {PrimitiveType::Plane,PrimitiveType::Sphere,PrimitiveType::Cylinder,PrimitiveType::Cone,PrimitiveType::Torus,PrimitiveType::Unknown};
+}
+
+std::vector<std::string> MEDCoupling::AllManagedPrimitivesStr()
+{
+ std::vector<PrimitiveType> apt( AllManagedPrimitives() );
+ std::vector<std::string> ret;
+ std::transform(apt.begin(),apt.end(),std::back_inserter(ret),[](PrimitiveType type) { return MEDCoupling::ConvertPrimitiveToString(type); } );
+ return ret;
+}
+
+std::string MEDCoupling::ConvertPrimitiveToString(MEDCoupling::PrimitiveType type)
+{
+ std::string typeName;
+ switch (type)
+ {
+ case PrimitiveType::Plane:
+ typeName = PLANE_STR;
+ break;
+ case PrimitiveType::Sphere:
+ typeName = SPHERE_STR;
+ break;
+ case PrimitiveType::Cylinder:
+ typeName = CYLINDER_STR;
+ break;
+ case PrimitiveType::Cone:
+ typeName = CONE_STR;
+ break;
+ case PrimitiveType::Torus:
+ typeName = TORUS_STR;
+ break;
+ case PrimitiveType::Unknown:
+ typeName = UNKNOWN_STR;
+ break;
+ default:
+ break;
+ }
+ return typeName;
+};
+
+MEDCoupling::PrimitiveType MEDCoupling::ConvertStringToPrimitive(const std::string& type)
+{
+ if( type == PLANE_STR )
+ return PrimitiveType::Plane;
+ if( type == SPHERE_STR )
+ return PrimitiveType::Sphere;
+ if( type == CYLINDER_STR )
+ return PrimitiveType::Cylinder;
+ if( type == CONE_STR )
+ return PrimitiveType::Cone;
+ if( type == TORUS_STR )
+ return PrimitiveType::Torus;
+ if( type == UNKNOWN_STR )
+ return PrimitiveType::Unknown;
+ return PrimitiveType::Unknown;
+}
+
+int MEDCoupling::ConvertPrimitiveToInt(MEDCoupling::PrimitiveType type)
+{
+ int typeInt = 5;
+ switch (type)
+ {
+ case PrimitiveType::Plane:
+ typeInt = 0;
+ break;
+ case PrimitiveType::Sphere:
+ typeInt = 1;
+ break;
+ case PrimitiveType::Cylinder:
+ typeInt = 2;
+ break;
+ case PrimitiveType::Cone:
+ typeInt = 3;
+ break;
+ case PrimitiveType::Torus:
+ typeInt = 4;
+ break;
+ case PrimitiveType::Unknown:
+ default:
+ break;
+ }
+ return typeInt;
+}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __PRIMITIVETYPE_HXX__
-#define __PRIMITIVETYPE_HXX__
+#pragma once
+#include <vector>
#include <string>
+#include <cstdint>
+
namespace MEDCoupling
{
- enum PrimitiveType
- {
- Plane = 0,
- Sphere = 1,
- Cylinder = 2,
- Cone = 3,
- Torus = 4,
- Unknown = 5
- };
+ enum class PrimitiveType : std::uint8_t
+ {
+ Plane = 0,
+ Sphere = 1,
+ Cylinder = 2,
+ Cone = 3,
+ Torus = 4,
+ Unknown = 5
+ };
- inline std::string convertPrimitiveToString(PrimitiveType type)
- {
- std::string typeName = "";
- switch (type)
- {
- case PrimitiveType::Plane:
- typeName = "Plane";
- break;
- case PrimitiveType::Sphere:
- typeName = "Sphere";
- break;
- case PrimitiveType::Cylinder:
- typeName = "Cylinder";
- break;
- case PrimitiveType::Cone:
- typeName = "Cone";
- break;
- case PrimitiveType::Torus:
- typeName = "Torus";
- break;
- case PrimitiveType::Unknown:
- typeName = "Unknown";
- break;
- default:
- break;
- }
- return typeName;
- };
+ std::vector<PrimitiveType> AllManagedPrimitives();
- inline int convertPrimitiveToInt(PrimitiveType type)
- {
- int typeInt = 5;
- switch (type)
- {
- case PrimitiveType::Plane:
- typeInt = 0;
- break;
- case PrimitiveType::Sphere:
- typeInt = 1;
- break;
- case PrimitiveType::Cylinder:
- typeInt = 2;
- break;
- case PrimitiveType::Cone:
- typeInt = 3;
- break;
- case PrimitiveType::Torus:
- typeInt = 4;
- break;
- case PrimitiveType::Unknown:
- default:
- break;
- }
- return typeInt;
- };
-};
+ std::vector<std::string> AllManagedPrimitivesStr();
-#endif // __PRIMITIVETYPE_HXX__
\ No newline at end of file
+ std::string ConvertPrimitiveToString(PrimitiveType type);
+
+ PrimitiveType ConvertStringToPrimitive(const std::string& type);
+
+ int ConvertPrimitiveToInt(PrimitiveType type);
+};
>>
>> shape_recogn_builder = sr.ShapeRecognMeshBuilder("resources/ShapeRecognCone.med")
>> shape_recogn = shape_recogn_builder.recognize()
->> shape_recogn.save("ShapeRecognCone_areas.med")
+>> #shape_recogn.save("ShapeRecognCone_areas.med")
```
### Without output file
-#include "ShapeRecognMesh.hxx"
+// 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 "MEDLoader.hxx"
+#include "ShapeRecognMesh.hxx"
using namespace MEDCoupling;
ShapeRecognMesh::ShapeRecognMesh()
- : nodeK1(0), nodeK2(0), nodePrimitiveType(0),
- nodeNormal(0), areaId(0), areaPrimitiveType(0),
- areaNormal(0), minorRadius(0), radius(0),
- angle(0), center(0), axis(0), apex(0)
-{
-}
-ShapeRecognMesh::~ShapeRecognMesh()
+ : nodeK1(nullptr), nodeK2(nullptr), nodePrimitiveType(nullptr),
+ nodeNormal(nullptr), areaId(nullptr), areaPrimitiveType(nullptr),
+ areaNormal(nullptr), minorRadius(nullptr), radius(nullptr),
+ angle(nullptr), center(nullptr), axis(nullptr), apex(nullptr)
{
- nodeK1->decrRef();
- nodeK2->decrRef();
- nodePrimitiveType->decrRef();
- nodeNormal->decrRef();
- areaId->decrRef();
- areaPrimitiveType->decrRef();
- areaNormal->decrRef();
- minorRadius->decrRef();
- radius->decrRef();
- angle->decrRef();
- center->decrRef();
- axis->decrRef();
- apex->decrRef();
}
std::size_t ShapeRecognMesh::getHeapMemorySizeWithoutChildren() const
return new ShapeRecognMesh;
}
-void ShapeRecognMesh::save(const std::string &outputFile, bool writeFromScratch) const
-{
- // Nodes
- // - k1
- WriteField(outputFile, nodeK1, writeFromScratch);
- // - k2
- WriteField(outputFile, nodeK2, false);
- // - primitive types
- WriteField(outputFile, nodePrimitiveType, false);
- // - Normal
- WriteField(outputFile, nodeNormal, false);
- // Areas
- // - Area Id
- WriteField(outputFile, areaId, false);
- // - Primitive Types
- WriteField(outputFile, areaPrimitiveType, false);
- // - Normal
- WriteField(outputFile, areaNormal, false);
- // - Minor Radius
- WriteField(outputFile, minorRadius, false);
- // - Radius
- WriteField(outputFile, radius, false);
- // - Angle
- WriteField(outputFile, angle, false);
- // - Center
- WriteField(outputFile, center, false);
- // - Axis
- WriteField(outputFile, axis, false);
- // - Apex
- WriteField(outputFile, apex, false);
-}
-
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK1() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK1() const
{
return nodeK1;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK2() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK2() const
{
return nodeK2;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodePrimitiveType() const
+const MEDCouplingFieldInt32 *ShapeRecognMesh::getNodePrimitiveType() const
{
return nodePrimitiveType;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodeNormal() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeNormal() const
{
return nodeNormal;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getAreaId() const
+const MEDCouplingFieldInt32 *ShapeRecognMesh::getAreaId() const
{
return areaId;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getAreaPrimitiveType() const
+const MEDCouplingFieldInt32 *ShapeRecognMesh::getAreaPrimitiveType() const
{
return areaPrimitiveType;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getAreaNormal() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getAreaNormal() const
{
return areaNormal;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getMinorRadius() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getMinorRadius() const
{
return minorRadius;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getRadius() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getRadius() const
{
return radius;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getAngle() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getAngle() const
{
return angle;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getCenter() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getCenter() const
{
return center;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getAxis() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getAxis() const
{
return axis;
}
-MEDCouplingFieldDouble *ShapeRecognMesh::getApex() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getApex() const
{
return apex;
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __SHAPERECOGNMESH_HXX__
-#define __SHAPERECOGNMESH_HXX__
+#pragma once
#include <string>
#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingFieldInt32.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingRefCountObject.hxx"
std::size_t getHeapMemorySizeWithoutChildren() const;
std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
- void save(const std::string &outputFile, bool writeFromScratch = true) const;
-
// Node properties
- MEDCoupling::MEDCouplingFieldDouble *getNodeK1() const;
- MEDCoupling::MEDCouplingFieldDouble *getNodeK2() const;
- MEDCoupling::MEDCouplingFieldDouble *getNodePrimitiveType() const;
- MEDCoupling::MEDCouplingFieldDouble *getNodeNormal() const;
+ const MEDCouplingFieldDouble *getNodeK1() const;
+ const MEDCouplingFieldDouble *getNodeK2() const;
+ const MEDCouplingFieldInt32 *getNodePrimitiveType() const;
+ const MEDCouplingFieldDouble *getNodeNormal() const;
+ // see ShapeRecognMeshBuilder::buildNodeWeakDirections
+ // see ShapeRecognMeshBuilder::buildNodeMainDirections
// Area properties
- MEDCoupling::MEDCouplingFieldDouble *getAreaId() const;
- MEDCoupling::MEDCouplingFieldDouble *getAreaPrimitiveType() const;
- MEDCoupling::MEDCouplingFieldDouble *getAreaNormal() const;
- MEDCoupling::MEDCouplingFieldDouble *getMinorRadius() const;
- MEDCoupling::MEDCouplingFieldDouble *getRadius() const;
- MEDCoupling::MEDCouplingFieldDouble *getAngle() const;
- MEDCoupling::MEDCouplingFieldDouble *getCenter() const;
- MEDCoupling::MEDCouplingFieldDouble *getAxis() const;
- MEDCoupling::MEDCouplingFieldDouble *getApex() const;
+ const MEDCouplingFieldInt32 *getAreaId() const;
+ const MEDCouplingFieldInt32 *getAreaPrimitiveType() const;
+ const MEDCouplingFieldDouble *getAreaNormal() const;
+ const MEDCouplingFieldDouble *getMinorRadius() const;
+ const MEDCouplingFieldDouble *getRadius() const;
+ const MEDCouplingFieldDouble *getAngle() const;
+ const MEDCouplingFieldDouble *getCenter() const;
+ const MEDCouplingFieldDouble *getAxis() const;
+ const MEDCouplingFieldDouble *getApex() const;
+
+ // see ShapeRecognMeshBuilder::buildAreaAxisPoint
+ // see ShapeRecognMeshBuilder::buildAreaAffinePoint
protected:
ShapeRecognMesh();
- ~ShapeRecognMesh();
+ ~ShapeRecognMesh() = default;
private:
- MEDCoupling::MEDCouplingFieldDouble *nodeK1;
- MEDCoupling::MEDCouplingFieldDouble *nodeK2;
- MEDCoupling::MEDCouplingFieldDouble *nodePrimitiveType;
- MEDCoupling::MEDCouplingFieldDouble *nodeNormal;
- MEDCoupling::MEDCouplingFieldDouble *areaId;
- MEDCoupling::MEDCouplingFieldDouble *areaPrimitiveType;
- MEDCoupling::MEDCouplingFieldDouble *areaNormal;
- MEDCoupling::MEDCouplingFieldDouble *minorRadius;
- MEDCoupling::MEDCouplingFieldDouble *radius;
- MEDCoupling::MEDCouplingFieldDouble *angle;
- MEDCoupling::MEDCouplingFieldDouble *center;
- MEDCoupling::MEDCouplingFieldDouble *axis;
- MEDCoupling::MEDCouplingFieldDouble *apex;
+ MCAuto<MEDCouplingFieldDouble> nodeK1;
+ MCAuto<MEDCouplingFieldDouble> nodeK2;
+ MCAuto<MEDCouplingFieldInt32> nodePrimitiveType;
+ MCAuto<MEDCouplingFieldDouble> nodeNormal;
+ MCAuto<MEDCouplingFieldInt32> areaId;
+ MCAuto<MEDCouplingFieldInt32> areaPrimitiveType;
+ MCAuto<MEDCouplingFieldDouble> areaNormal;
+ MCAuto<MEDCouplingFieldDouble> minorRadius;
+ MCAuto<MEDCouplingFieldDouble> radius;
+ MCAuto<MEDCouplingFieldDouble> angle;
+ MCAuto<MEDCouplingFieldDouble> center;
+ MCAuto<MEDCouplingFieldDouble> axis;
+ MCAuto<MEDCouplingFieldDouble> apex;
};
-};
-
-#endif // __SHAPERECOGNMESH_HXX__
+}
+// 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 "ShapeRecognMeshBuilder.hxx"
#include "NodesBuilder.hxx"
#include "AreasBuilder.hxx"
-#include "MEDLoader.hxx"
#include "ShapeRecognMesh.hxx"
+
#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldInt64.hxx"
+#include "MEDCouplingFieldInt32.hxx"
+
+#include <algorithm>
+#include <iterator>
+#include <limits>
using namespace MEDCoupling;
-ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(const std::string &fileName, int meshDimRelToMax)
+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)
{
- mesh = ReadUMeshFromFile(fileName, meshDimRelToMax);
+ this->mesh = mesh;
if (mesh->getMeshDimension() != 2)
throw INTERP_KERNEL::Exception("Expect a mesh with a dimension equal to 2");
if (mesh->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3) != mesh->getNumberOfCells())
throw INTERP_KERNEL::Exception("Expect a mesh containing exclusively triangular cells");
}
-ShapeRecognMeshBuilder::~ShapeRecognMeshBuilder()
-{
- if (areas != nullptr)
- delete areas;
- if (nodes != nullptr)
- delete nodes;
- mesh->decrRef();
-}
-ShapeRecognMesh *ShapeRecognMeshBuilder::recognize()
+MCAuto<ShapeRecognMesh> ShapeRecognMeshBuilder::recognize()
{
mesh->incrRef();
NodesBuilder nodesBuilder(mesh);
- nodes = nodesBuilder.build();
- AreasBuilder areasBuilder(nodes);
+ nodes.reset( nodesBuilder.build() );
+ AreasBuilder areasBuilder(nodes.get());
areasBuilder.build();
- areas = areasBuilder.getAreas();
+ areas.reset( areasBuilder.getAreas() );
MCAuto<ShapeRecognMesh> recognMesh = ShapeRecognMesh::New();
recognMesh->nodeK1 = buildNodeK1();
recognMesh->nodeK2 = buildNodeK2();
recognMesh->center = buildCenter();
recognMesh->axis = buildAxis();
recognMesh->apex = buildApex();
- return recognMesh.retn();
+ return recognMesh;
}
const Nodes *ShapeRecognMeshBuilder::getNodes() const
{
- return nodes;
+ return nodes.get();
}
const Areas *ShapeRecognMeshBuilder::getAreas() const
{
- return areas;
+ return areas.get();
}
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK1() const
+void ShapeRecognMeshBuilder::checkNodesBeforeBuildingField() const
{
- if (nodes == nullptr)
+ if ( ! nodes.get() )
throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- return buildField("K1 (Node)", 1, nodes->getK1());
}
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK2() const
+void ShapeRecognMeshBuilder::checkAreasBeforeBuildingField() const
{
- if (nodes == nullptr)
+ if ( ! areas.get() )
throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- return buildField("K2 (Node)", 1, nodes->getK2());
}
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodePrimitiveType() const
+template <typename T>
+typename Traits<T>::FieldType *buildField(
+ const std::string &name,
+ MCAuto<typename Traits<T>::ArrayType> data,
+ const MEDCouplingUMesh *mesh)
{
- if (nodes == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- return buildField("Primitive Type (Node)", 1, nodes->getPrimitiveType());
+ using ZeField = typename Traits<T>::FieldType;
+ ZeField *field = ZeField::New(ON_NODES);
+ mcIdType nbNodes = data->getNumberOfTuples();
+ size_t nbOfCompo = data->getNumberOfComponents();
+ field->setName(name);
+ field->setMesh(mesh);
+ if (nbOfCompo == 3)
+ {
+ data->setInfoOnComponent(0, "X");
+ data->setInfoOnComponent(1, "Y");
+ data->setInfoOnComponent(2, "Z");
+ }
+ field->setArray(data);
+ return field;
+}
+
+template <typename T>
+typename Traits<T>::FieldType *buildField(
+ const std::string &name,
+ size_t nbOfCompo,
+ const std::vector<T> &values,
+ const MEDCouplingUMesh *mesh)
+{
+ using ZeArray = typename Traits<T>::ArrayType;
+ mcIdType nbNodes = mesh->getNumberOfNodes();
+ MCAuto<ZeArray> data( ZeArray::New() );
+ data->setName(name);
+ data->alloc(nbNodes, nbOfCompo);
+ std::copy(values.begin(), values.end(), data->getPointer());
+ data->declareAsNew();
+ return buildField<T>(name, data, mesh);
+}
+
+template <typename T>
+typename Traits<T>::FieldType *buildField(
+ const std::string &name,
+ size_t nbOfCompo,
+ T *values,
+ const MEDCouplingUMesh *mesh)
+{
+ using ZeArray = typename Traits<T>::ArrayType;
+ mcIdType nbNodes = mesh->getNumberOfNodes();
+ ZeArray *data = ZeArray::New();
+ data->setName(name);
+ data->useArray(
+ values,
+ true,
+ MEDCoupling::DeallocType::CPP_DEALLOC,
+ nbNodes,
+ nbOfCompo);
+ return buildField<T>(name, data, mesh);
+}
+
+template<class T>
+T *buildAreaArrayT(Areas *areas, Nodes *nodes, std::function<T(Areas *, mcIdType)> areaFunc)
+{
+ const std::vector<Int32> &areaIdByNodes = areas->getAreaIdByNodes();
+ T *values = new T[nodes->getNbNodes()];
+ for (size_t nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
+ {
+ Int32 areaId = areaIdByNodes[nodeId];
+ if (areaId != -1)
+ values[nodeId] = areaFunc(areas, areaId);
+ else
+ values[nodeId] = std::numeric_limits<T>::max();
+ }
+ return values;
+}
+
+MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK1() const
+{
+ checkNodesBeforeBuildingField();
+ return buildField<double>("K1 (Node)", 1, nodes->getK1(), mesh);
+}
+
+MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK2() const
+{
+ checkNodesBeforeBuildingField();
+ return buildField<double>("K2 (Node)", 1, nodes->getK2(), mesh);
+}
+
+MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildNodePrimitiveType() const
+{
+ checkNodesBeforeBuildingField();
+ std::vector<Int32> tmp;
+ std::transform(nodes->getPrimitiveType().begin(),nodes->getPrimitiveType().end(),std::back_inserter(tmp),[](const PrimitiveType& elt){ return Int32(elt); });
+ return buildField<Int32>("Primitive Type (Node)", 1, tmp, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeNormal() const
{
- if (nodes == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- return buildField("Normal (Node)", 3, nodes->getNormals());
+ checkNodesBeforeBuildingField();
+ return buildField<double>("Normal (Node)", 3, nodes->getNormals(), mesh);
}
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaId() const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildNodeWeakDirections() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- return buildField("Area Id", 1, areas->getAreaIdByNodes());
+ checkNodesBeforeBuildingField();
+ return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>(buildField<double>("WeakDirection (Node)", 3, nodes->getWeakDirections(), mesh));
}
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaPrimitiveType() const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildNodeMainDirections() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
- { return (double)areas->getPrimitiveType(areaId); });
- return buildField("Primitive Type (Area)", 1, values);
+ checkNodesBeforeBuildingField();
+ return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>(buildField<double>("MainDirection (Node)", 3, nodes->getMainDirections(), mesh));
+}
+
+MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildAreaId() const
+{
+ checkAreasBeforeBuildingField();
+ return buildField<Int32>("Area Id", 1, areas->getAreaIdByNodes(), mesh);
+}
+
+MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildAreaPrimitiveType() const
+{
+ checkAreasBeforeBuildingField();
+ Int32 *values = buildAreaArrayT<Int32>(areas.get(),nodes.get(),[](Areas *areas, mcIdType areaId) -> Int32
+ { return (Int32)areas->getPrimitiveType(areaId); });
+ return buildField<Int32>("Primitive Type (Area)", 1, values, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaNormal() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+ checkAreasBeforeBuildingField();
double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
{ return areas->getNormal(areaId); });
- return buildField("Normal (Area)", 3, values);
+ return buildField<double>("Normal (Area)", 3, values, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildMinorRadius() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+ checkAreasBeforeBuildingField();
double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
{ return areas->getMinorRadius(areaId); });
- return buildField("Minor Radius (Area)", 1, values);
+ return buildField<double>("Minor Radius (Area)", 1, values, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildRadius() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+ checkAreasBeforeBuildingField();
double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
{ return areas->getRadius(areaId); });
- return buildField("Radius (Area)", 1, values);
+ return buildField<double>("Radius (Area)", 1, values, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAngle() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+ checkAreasBeforeBuildingField();
double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
{ return areas->getAngle(areaId); });
- return buildField("Angle (Area)", 1, values);
+ return buildField<double>("Angle (Area)", 1, values, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildCenter() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
+ checkAreasBeforeBuildingField();
+ double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
{ return areas->getCenter(areaId); });
- return buildField("Center (Area)", 3, values);
+ return buildField<double>("Center (Area)", 3, values, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAxis() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
+ checkAreasBeforeBuildingField();
+ double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
{ return areas->getAxis(areaId); });
- return buildField("Axis (Area)", 3, values);
+ return buildField<double>("Axis (Area)", 3, values, mesh);
}
MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildApex() const
{
- if (areas == nullptr)
- throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
- double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
+ checkAreasBeforeBuildingField();
+ double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
{ return areas->getApex(areaId); });
- return buildField("Apex (Area)", 3, values);
-}
-
-template <typename T>
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField(
- const std::string &name,
- size_t nbOfCompo,
- const std::vector<T> &values) const
-{
- DataArrayDouble *data = DataArrayDouble::New();
- data->setName(name);
- data->alloc(nodes->getNbNodes(), nbOfCompo);
- std::copy(values.begin(), values.end(), data->getPointer());
- data->declareAsNew();
- return buildField(name, nbOfCompo, data);
+ return buildField<double>("Apex (Area)", 3, values, mesh);
}
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField(
- const std::string &name,
- size_t nbOfCompo,
- double *values) const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildAreaAxisPoint() const
{
- DataArrayDouble *data = DataArrayDouble::New();
- data->setName(name);
- data->useArray(
- values,
- true,
- MEDCoupling::DeallocType::CPP_DEALLOC,
- nodes->getNbNodes(),
- nbOfCompo);
- return buildField(name, nbOfCompo, data);
+ checkAreasBeforeBuildingField();
+ double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
+ { return areas->getAxisPoint(areaId); });
+ return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>( buildField<double>("AxisPoint (Area)", 3, values, mesh) );
}
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField(
- const std::string &name,
- size_t nbOfCompo,
- DataArrayDouble *data) const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildAreaAffinePoint() const
{
- MEDCouplingFieldDouble *field = MEDCouplingFieldDouble::New(ON_NODES);
- field->setName(name);
- field->setMesh(mesh);
- if (nbOfCompo == 3)
- {
- data->setInfoOnComponent(0, "X");
- data->setInfoOnComponent(1, "Y");
- data->setInfoOnComponent(2, "Z");
- }
- field->setArray(data);
- data->decrRef();
- return field;
+ checkAreasBeforeBuildingField();
+ double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
+ { return areas->getAffinePoint(areaId); });
+ return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>( buildField<double>("AffinePoint (Area)", 3, values, mesh) );
}
-double *ShapeRecognMeshBuilder::buildArea3DArray(
- const std::array<double, 3> &(*areaFunc)(Areas *, mcIdType)) const
+double *ShapeRecognMeshBuilder::buildArea3DArray(std::function<std::array<double, 3>(Areas *, Int32)> areaFunc) const
{
double *values = new double[3 * nodes->getNbNodes()];
- const std::vector<mcIdType> &areaIdByNodes = areas->getAreaIdByNodes();
+ const std::vector<Int32> &areaIdByNodes = areas->getAreaIdByNodes();
for (size_t nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
{
- mcIdType areaId = areaIdByNodes[nodeId];
+ Int32 areaId = areaIdByNodes[nodeId];
if (areaId != -1)
{
- const std::array<double, 3> &areaValues = areaFunc(areas, areaId);
+ const std::array<double, 3> areaValues( areaFunc(areas.get(), areaId) );
values[3 * nodeId] = areaValues[0];
values[3 * nodeId + 1] = areaValues[1];
values[3 * nodeId + 2] = areaValues[2];
}
+ else
+ {
+ std::for_each(values + 3 * nodeId, values + 3 * (nodeId + 1), [](double& val) { val = std::numeric_limits<double>::max(); });
+ }
}
return values;
}
-double *ShapeRecognMeshBuilder::buildAreaArray(double (*areaFunc)(Areas *, mcIdType)) const
+double *ShapeRecognMeshBuilder::buildAreaArray(std::function<double(Areas *, Int32)> areaFunc) const
{
- const std::vector<mcIdType> &areaIdByNodes = areas->getAreaIdByNodes();
- double *values = new double[nodes->getNbNodes()];
- for (size_t nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
- {
- mcIdType areaId = areaIdByNodes[nodeId];
- if (areaId != -1)
- values[nodeId] = areaFunc(areas, areaId);
- }
- return values;
+ return buildAreaArrayT<double>(areas.get(), nodes.get(), areaFunc );
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __SHAPERECOGNMESHBUILDER_HXX__
-#define __SHAPERECOGNMESHBUILDER_HXX__
+#pragma once
#include <string>
#include "MEDCouplingUMesh.hxx"
-#include "MEDCouplingFieldDouble.hxx"
+
+#include "Nodes.hxx"
+#include "Areas.hxx"
+
+#include <memory>
+#include <functional>
namespace MEDCoupling
{
- class Nodes;
- class Areas;
+ class MEDCouplingFieldInt32;
+ class MEDCouplingFieldInt64;
+ class MEDCouplingFieldDouble;
+
class ShapeRecognMesh;
class ShapeRecognMeshBuilder
{
public:
- ShapeRecognMeshBuilder(const std::string &fileName, int meshDimRelToMax = 0);
- ~ShapeRecognMeshBuilder();
+ ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh);
+ ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh);
+ ~ShapeRecognMeshBuilder() = default;
const Nodes *getNodes() const;
const Areas *getAreas() const;
- ShapeRecognMesh *recognize();
+ MCAuto<ShapeRecognMesh> recognize();
+
+ // Node properties
+ MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildNodeWeakDirections() const;
+ MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildNodeMainDirections() const;
+ //Area properties
+ MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildAreaAxisPoint() const;
+ MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildAreaAffinePoint() const;
private:
// Node properties
MEDCoupling::MEDCouplingFieldDouble *buildNodeK1() const;
MEDCoupling::MEDCouplingFieldDouble *buildNodeK2() const;
- MEDCoupling::MEDCouplingFieldDouble *buildNodePrimitiveType() const;
+ MEDCoupling::MEDCouplingFieldInt32 *buildNodePrimitiveType() const;
MEDCoupling::MEDCouplingFieldDouble *buildNodeNormal() const;
-
+
// Area properties
- MEDCoupling::MEDCouplingFieldDouble *buildAreaId() const;
- MEDCoupling::MEDCouplingFieldDouble *buildAreaPrimitiveType() const;
+ MEDCoupling::MEDCouplingFieldInt32 *buildAreaId() const;
+ MEDCoupling::MEDCouplingFieldInt32 *buildAreaPrimitiveType() const;
MEDCoupling::MEDCouplingFieldDouble *buildAreaNormal() const;
MEDCoupling::MEDCouplingFieldDouble *buildMinorRadius() const;
MEDCoupling::MEDCouplingFieldDouble *buildRadius() const;
MEDCoupling::MEDCouplingFieldDouble *buildAxis() const;
MEDCoupling::MEDCouplingFieldDouble *buildApex() const;
- template <typename T>
- MEDCouplingFieldDouble *buildField(
- const std::string &name,
- size_t nbOfCompo,
- const std::vector<T> &values) const;
- MEDCouplingFieldDouble *buildField(
- const std::string &name,
- size_t nbOfCompo,
- double *values) const;
- MEDCouplingFieldDouble *buildField(
- const std::string &name,
- size_t nbOfCompo,
- DataArrayDouble *values) const;
- double *buildArea3DArray(const std::array<double, 3> &(*areaFunc)(Areas *, mcIdType)) const;
- double *buildAreaArray(double (*areaFunc)(Areas *, mcIdType)) const;
-
- const MEDCouplingUMesh *mesh;
- Nodes *nodes = nullptr;
- Areas *areas = nullptr;
+ double *buildArea3DArray(std::function<std::array<double, 3>(Areas *, Int32)> areaFunc) const;
+ double *buildAreaArray(std::function<double(Areas *, Int32)> areaFunc) const;
+ void assign(MCAuto< MEDCouplingUMesh > mesh);
+ void checkNodesBeforeBuildingField() const;
+ void checkAreasBeforeBuildingField() const;
+ private:
+ MCConstAuto< MEDCouplingUMesh > mesh;
+ std::unique_ptr<Nodes> nodes;
+ std::unique_ptr<Areas> areas;
};
-};
-
-#endif // __SHAPERECOGNMESHBUILDER_HXX__
+}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __SHAPERECOGNCONSTANTS_HXX__
-#define __SHAPERECOGNCONSTANTS_HXX__
+#pragma once
namespace MEDCoupling
{
// - Thresholds
constexpr int THRESHOLD_MIN_NB_NODES = 5;
constexpr int THRESHOLD_MAX_NB_AREAS = 500;
-};
-
-#endif //__SHAPERECOGNCONSTANTS_HXX__
\ No newline at end of file
+}
-# Copyright (C) 2012-2024 CEA, EDF
+# 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
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
+// 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
+//
+
%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
+
+%}
--- /dev/null
+// 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;
+%}
+
+#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<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
+ SWIGTITraits<float>::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())
+%}
--- /dev/null
+// 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"
+
+ #include <type_traits>
+%}
+
+%feature("unref") ShapeRecognMesh "$this->decrRef();"
+
+%newobject Areas::getNodeIds;
+
+%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;
+%newobject ShapeRecognMeshBuilder::buildNodeWeakDirections;
+%newobject ShapeRecognMeshBuilder::buildNodeMainDirections;
+%newobject ShapeRecognMeshBuilder::buildAreaAxisPoint;
+%newobject ShapeRecognMeshBuilder::buildAreaAffinePoint;
+
+%rename (ConvertStringToPrimitive) ConvertStringToPrimitiveSwig;
+%rename (ConvertPrimitiveToString) ConvertPrimitiveToStringSwig;
+
+class Areas
+{
+public:
+ double getMinorRadius(mcIdType areaId) const;
+ double getRadius(mcIdType areaId) const;
+ double getAngle(mcIdType areaId) const;
+ //
+ bool isEmpty(mcIdType areaId) const;
+ size_t getNumberOfAreas() const;
+ size_t getNumberOfNodes(mcIdType areaId) const;
+ int getPrimitiveType(mcIdType areaId) const;
+ std::string getPrimitiveTypeName(mcIdType areaId) const;
+ %extend
+ {
+ DataArrayIdType *getNodeIds(mcIdType areaId) const
+ {
+ const std::vector<mcIdType> &res = self->getNodeIds(areaId);
+ MCAuto< DataArrayIdType > ret( DataArrayIdType::New() );
+ ret->alloc(res.size(),1);
+ std::copy(res.begin(),res.end(),ret->getPointer());
+ return ret.retn();
+ }
+ }
+private:
+ Areas();
+ ~Areas();
+};
+
+using namespace MEDCoupling;
+
+std::vector<std::string> AllManagedPrimitivesStr();
+
+%inline
+{
+ std::string ConvertPrimitiveToStringSwig(int type)
+ {
+ return ConvertPrimitiveToString(static_cast<PrimitiveType>(type));
+ }
+
+ int ConvertStringToPrimitiveSwig(const std::string& type)
+ {
+ return static_cast<std::underlying_type_t<PrimitiveType>>( ConvertStringToPrimitive(type) );
+ }
+}
+
+class ShapeRecognMesh : public RefCountObject
+{
+public:
+ ~ShapeRecognMesh();
+ %extend
+ {
+ // Node properties
+ MEDCouplingFieldDouble *getNodeK1() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getNodeK1() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getNodeK2() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getNodeK2() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldInt32 *getNodePrimitiveType() const
+ {
+ MEDCouplingFieldInt32 *ret = const_cast<MEDCouplingFieldInt32 *>( self->getNodePrimitiveType() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getNodeNormal() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getNodeNormal() );
+ ret->incrRef();
+ return ret;
+ }
+
+ // Area properties
+
+ MEDCouplingFieldInt32 *getAreaId() const
+ {
+ MEDCouplingFieldInt32 *ret = const_cast<MEDCouplingFieldInt32 *>( self->getAreaId() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldInt32 *getAreaPrimitiveType() const
+ {
+ MEDCouplingFieldInt32 *ret = const_cast<MEDCouplingFieldInt32 *>( self->getAreaPrimitiveType() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getAreaNormal() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getAreaNormal() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getMinorRadius() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getMinorRadius() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getRadius() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getRadius() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getAngle() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getAngle() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getCenter() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getCenter() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getAxis() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getAxis() );
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *getApex() const
+ {
+ MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getApex() );
+ ret->incrRef();
+ return ret;
+ }
+ }
+private:
+ ShapeRecognMesh();
+};
+
+class ShapeRecognMeshBuilder
+{
+public:
+ ShapeRecognMeshBuilder(MEDCoupling::MEDCouplingUMesh *mesh);
+ ~ShapeRecognMeshBuilder();
+ const Areas *getAreas() const;
+ %extend
+ {
+ MEDCouplingFieldDouble *buildNodeWeakDirections() const
+ {
+ MCAuto<MEDCouplingFieldDouble> ret = self->buildNodeWeakDirections();
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *buildNodeMainDirections() const
+ {
+ MCAuto<MEDCouplingFieldDouble> ret = self->buildNodeMainDirections();
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *buildAreaAxisPoint() const
+ {
+ MCAuto<MEDCouplingFieldDouble> ret = self->buildAreaAxisPoint();
+ ret->incrRef();
+ return ret;
+ }
+
+ MEDCouplingFieldDouble *buildAreaAffinePoint() const
+ {
+ MCAuto<MEDCouplingFieldDouble> ret = self->buildAreaAffinePoint();
+ ret->incrRef();
+ return ret;
+ }
+
+ ShapeRecognMesh *recognize()
+ {
+ MCAuto<ShapeRecognMesh> ret = self->recognize();
+ return ret.retn();
+ }
+ }
+};
-# Copyright (C) 2012-2024 CEA, EDF
+# 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
SET(TestShapeRecogn_SOURCES
TestShapeRecogn.cxx
MathOpsTest.cxx
+ ShapeRecognTest.cxx
PlaneTest.cxx
CylinderTest.cxx
ConeTest.cxx
SALOME_ACCUMULATE_ENVIRONMENT(MEDCOUPLING_RESOURCE_DIR "${CMAKE_BINARY_DIR}/resources")
SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
-ADD_EXECUTABLE(TestShapeRecogn ${TestShapeRecogn_SOURCES})
-TARGET_LINK_LIBRARIES(TestShapeRecogn shaperecogn InterpKernelTestUtils ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
-INSTALL(TARGETS TestShapeRecogn DESTINATION ${MEDCOUPLING_INSTALL_BINS})
+IF(NOT MEDCOUPLING_MICROMED)
+ SET(TESTSHAPE_RECOGN0 TestShapeRecogn)
+ ADD_EXECUTABLE(${TESTSHAPE_RECOGN0} ${TestShapeRecogn_SOURCES})
+ TARGET_LINK_LIBRARIES(${TESTSHAPE_RECOGN0} shaperecogn InterpKernelTestUtils medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
-SET(BASE_TESTS TestShapeRecogn)
+ INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${MEDCOUPLING_INSTALL_BINS})
+
+ #### Test section
-FOREACH(test ${BASE_TESTS})
- ADD_TEST(NAME ${test}
- COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MCTestLauncher.py ${CMAKE_CURRENT_BINARY_DIR}/${test})
- SET_TESTS_PROPERTIES(${test} PROPERTIES ENVIRONMENT "${tests_env}")
-ENDFOREACH()
+ SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
+ SET(BASE_TESTS ${TESTSHAPE_RECOGN0})
-# Application tests
+ FOREACH(test ${BASE_TESTS})
+ ADD_TEST(NAME ${test}
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test})
+ SET_TESTS_PROPERTIES(${test} PROPERTIES ENVIRONMENT "${tests_env}")
+ ENDFOREACH()
+ INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${TEST_INSTALL_DIRECTORY})
-SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
-INSTALL(TARGETS TestShapeRecogn DESTINATION ${TEST_INSTALL_DIRECTORY})
-INSTALL(FILES CTestTestfileInstall.cmake
- DESTINATION ${TEST_INSTALL_DIRECTORY}
- RENAME CTestTestfile.cmake)
+ SET(TESTSHAPE_RECOGN1 "TestShapeRecogn.py")
+ SET(test ${TESTSHAPE_RECOGN1})
+ SET(testname "TestShapeRecognPy")
+ ADD_TEST(NAME ${testname} COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test})
+ SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TESTSHAPE_RECOGN1} DESTINATION ${TEST_INSTALL_DIRECTORY})
+
+ INSTALL(FILES CTestTestfileInstall.cmake
+ DESTINATION ${TEST_INSTALL_DIRECTORY}
+ RENAME CTestTestfile.cmake)
+
+ #### End Test section
+ENDIF(NOT MEDCOUPLING_MICROMED)
-# Copyright (C) 2015-2024 CEA, EDF
+# 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
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-SET(TEST_NAMES
- TestShapeRecogn
-)
+SET(TEST_NAME "${COMPONENT_NAME}_ShapeRecogn")
+ADD_TEST(${TEST_NAME} TestShapeRecogn)
+SET_TESTS_PROPERTIES( ${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} )
-FOREACH(tfile ${TEST_NAMES})
- SET(TEST_NAME ${COMPONENT_NAME}_${tfile})
- ADD_TEST(${TEST_NAME} python3 MCTestLauncher.py ${tfile})
- SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES
- LABELS "${COMPONENT_NAME}"
- TIMEOUT ${TIMEOUT}
- )
-ENDFOREACH()
+SET(tfile "TestShapeRecogn.py")
+set(BASE_NAME "ShapeRecognPy")
+SET(TEST_NAME ${COMPONENT_NAME}_${BASE_NAME})
+ADD_TEST(${TEST_NAME} python3 ${tfile})
+SET_TESTS_PROPERTIES( ${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} )
+// 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 "ConeTest.hxx"
#include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
#include "Areas.hxx"
#include "MathOps.hxx"
#include "TestInterpKernelUtils.hxx" // getResourceFile()
+#include "ShapeRecognTest.hxx"
+
using namespace MEDCoupling;
void ConeTest::setUp()
{
std::string file = INTERP_TEST::getResourceFile("ShapeRecognCone.med", 3);
- srMesh = new ShapeRecognMeshBuilder(file);
+ srMesh = BuildShapeRecognMeshBuilderFromFile(file);
srMesh->recognize();
areas = srMesh->getAreas();
}
void ConeTest::tearDown()
{
- if (srMesh != 0)
- delete srMesh;
areas = 0;
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __CONETEST_HXX__
-#define __CONETEST_HXX__
+#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
namespace MEDCoupling
{
class ShapeRecognMeshBuilder;
void testThirdArea();
private:
- ShapeRecognMeshBuilder *srMesh = 0;
+ std::unique_ptr<ShapeRecognMeshBuilder> srMesh;
const Areas *areas;
};
-};
-
-#endif // __CONETEST_HXX__
+}
+// 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 "CylinderTest.hxx"
#include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
#include "Areas.hxx"
#include "MathOps.hxx"
#include "TestInterpKernelUtils.hxx" // getResourceFile()
+#include "ShapeRecognTest.hxx"
+
using namespace MEDCoupling;
void CylinderTest::setUp()
{
std::string file = INTERP_TEST::getResourceFile("ShapeRecognCylinder.med", 3);
- srMesh = new ShapeRecognMeshBuilder(file);
+ srMesh = BuildShapeRecognMeshBuilderFromFile(file);
srMesh->recognize();
areas = srMesh->getAreas();
}
void CylinderTest::tearDown()
{
- if (srMesh != 0)
- delete srMesh;
areas = 0;
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __CYLINDERTEST_HXX__
-#define __CYLINDERTEST_HXX__
-
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
namespace MEDCoupling
{
class ShapeRecognMeshBuilder;
void testThirdArea();
private:
- ShapeRecognMeshBuilder *srMesh = 0;
+ std::unique_ptr< ShapeRecognMeshBuilder > srMesh;
const Areas *areas;
};
-};
-
-#endif // __CYLINDERTEST_HXX__
+}
+// 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 "MathOpsTest.hxx"
#include "MathOps.hxx"
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __MATHOPSTEST_HXX__
-#define __MATHOPSTEST_HXX__
+#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
static void testComputeAngles();
static void testComputeBaseFromNormal();
};
-};
-
-#endif // __MATHOPSTEST_HXX__
+}
+// 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 "PlaneTest.hxx"
#include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
#include "Areas.hxx"
#include "MathOps.hxx"
#include "TestInterpKernelUtils.hxx" // getResourceFile()
+#include "ShapeRecognTest.hxx"
+
using namespace MEDCoupling;
void PlaneTest::setUp()
{
std::string file = INTERP_TEST::getResourceFile("ShapeRecognPlane.med", 3);
- srMesh = new ShapeRecognMeshBuilder(file);
+ srMesh = BuildShapeRecognMeshBuilderFromFile(file);
srMesh->recognize();
areas = srMesh->getAreas();
}
void PlaneTest::tearDown()
{
- if (srMesh != 0)
- delete srMesh;
areas = 0;
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __PLANETEST_HXX__
-#define __PLANETEST_HXX__
+#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognTest.hxx"
+
+#include <memory>
+
namespace MEDCoupling
{
class ShapeRecognMeshBuilder;
void testArea();
private:
- ShapeRecognMeshBuilder *srMesh = 0;
+ std::unique_ptr<ShapeRecognMeshBuilder> srMesh;
const Areas *areas;
};
-};
-
-#endif // __PLANETEST_HXX__
+}
--- /dev/null
+// 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 "ShapeRecognTest.hxx"
+
+#include "MEDLoader.hxx"
+
+std::unique_ptr<MEDCoupling::ShapeRecognMeshBuilder> BuildShapeRecognMeshBuilderFromFile(const std::string& fileName, int meshDimRelToMax)
+{
+ MEDCoupling::MCAuto<MEDCoupling::MEDCouplingUMesh> mesh = MEDCoupling::ReadUMeshFromFile(fileName, 0);
+ return std::make_unique<MEDCoupling::ShapeRecognMeshBuilder>(mesh);
+}
\ No newline at end of file
--- /dev/null
+// 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
+//
+
+#pragma once
+
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <string>
+#include <memory>
+
+std::unique_ptr<MEDCoupling::ShapeRecognMeshBuilder> BuildShapeRecognMeshBuilderFromFile(const std::string& fileName, int meshDimRelToMax = 0);
+// 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 "SphereTest.hxx"
#include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
#include "Areas.hxx"
#include "MathOps.hxx"
#include "TestInterpKernelUtils.hxx" // getResourceFile()
+#include "ShapeRecognTest.hxx"
+
using namespace MEDCoupling;
void SphereTest::setUp()
{
std::string file = INTERP_TEST::getResourceFile("ShapeRecognSphere.med", 3);
- srMesh = new ShapeRecognMeshBuilder(file);
+ srMesh = BuildShapeRecognMeshBuilderFromFile(file);
srMesh->recognize();
areas = srMesh->getAreas();
}
void SphereTest::tearDown()
{
- if (srMesh != 0)
- delete srMesh;
areas = 0;
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __SPHERETEST_HXX__
-#define __SPHERETEST_HXX__
+#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
namespace MEDCoupling
{
class ShapeRecognMeshBuilder;
void testArea();
private:
- ShapeRecognMeshBuilder *srMesh = 0;
+ std::unique_ptr<ShapeRecognMeshBuilder> srMesh;
const Areas *areas;
};
-};
-
-#endif // __SPHERETEST_HXX__
+}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
--- /dev/null
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# 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
+#
+
+import ShapeRecogn as sr
+import MEDLoader as ml
+from numpy.testing import assert_allclose
+import unittest
+
+def getResourceFile(filename, levelUp = 2):
+ ROOT_DIR_0 = "MEDCOUPLING_ROOT_DIR"
+ ROOT_DIR_1 = "MEDCOUPLING_RESOURCE_DIR"
+ import os
+ from pathlib import Path
+ if ROOT_DIR_0 in os.environ:
+ resourceFile = Path( os.environ[ROOT_DIR_0] ).absolute() / "share" / "resources" / "med" / filename
+ if resourceFile.exists():
+ return f"{resourceFile}"
+ if ROOT_DIR_1 in os.environ:
+ resourceFile = Path( os.environ[ROOT_DIR_1].split(":")[-1] ).absolute() / filename
+ if resourceFile.exists():
+ return f"{resourceFile}"
+ p = Path.cwd()
+ for i in range(levelUp):
+ p = p.parent
+ resourceFile = p / "resources" / filename
+ if not resourceFile.exists():
+ raise RuntimeError( f"getResourceFile: could not open resource test file {filename}" )
+ return f"{resourceFile}"
+
+class MEDCouplingIterativeStatisticsTest(unittest.TestCase):
+ def testPlane(self):
+ """
+ Direct translation of PlaneTest::testArea
+ """
+ self.assertEqual( sr.AllManagedPrimitivesStr() , ('Plane', 'Sphere', 'Cylinder', 'Cone', 'Torus', 'Unknown') )
+ fname = "ShapeRecognPlane.med"
+ mesh = ml.ReadUMeshFromFile( getResourceFile( fname, 3 ),0)
+ srMesh = sr.ShapeRecognMeshBuilder( mesh )
+ rem = srMesh.recognize()
+ areas = srMesh.getAreas()
+ self.assertEqual( areas.getNumberOfAreas(), 1 )
+ self.assertEqual( areas.getNumberOfNodes(0), 36 )
+ nodeIds = areas.getNodeIds(0)
+ f = rem.getAreaPrimitiveType()
+ self.assertEqual( areas.getPrimitiveType(0), 0)
+ self.assertEqual( areas.getPrimitiveTypeName(0), "Plane")
+ self.assertEqual( sr.ConvertStringToPrimitive("Plane"),0)
+ self.assertEqual( sr.ConvertPrimitiveToString(0),"Plane")
+ f_normal = rem.getNodeNormal()
+ affinePoint = srMesh.buildAreaAffinePoint().getArray()[ nodeIds[0] ]
+ normal = f_normal.getArray()[ nodeIds[0] ]
+ normalRef = sr.DataArrayDouble([0.781525, 0.310606, -0.541056],1,3)
+ proportion0 = normal[0,0] / normalRef[0,0]
+ proportion1 = normal[0,1] / normalRef[0,1]
+ proportion2 = normal[0,2] / normalRef[0,2]
+ proportion3 = sr.DataArrayDouble.Dot(normal,affinePoint)[0] / sr.DataArrayDouble.Dot(normalRef,affinePoint)[0]
+ assert_allclose([proportion0,proportion1,proportion2,proportion3],[1.0,1.0,1.0,1.0] , rtol = 1e-5)
+ angle = sr.DataArrayDouble.CrossProduct(normal,normalRef).magnitude()[0]
+ assert_allclose( [angle], [0.0], atol = 1e-6 )
+
+if __name__ == "__main__":
+ unittest.main()
+// 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 "TorusTest.hxx"
#include "ShapeRecognMeshBuilder.hxx"
#include "Areas.hxx"
#include "MathOps.hxx"
#include "TestInterpKernelUtils.hxx" // getResourceFile()
+#include "ShapeRecognMesh.hxx"
+
+#include "ShapeRecognTest.hxx"
using namespace MEDCoupling;
void TorusTest::setUp()
{
std::string file = INTERP_TEST::getResourceFile("ShapeRecognTorus.med", 3);
- srMesh = new ShapeRecognMeshBuilder(file);
+ srMesh = BuildShapeRecognMeshBuilderFromFile(file);
srMesh->recognize();
areas = srMesh->getAreas();
}
void TorusTest::tearDown()
{
- if (srMesh != 0)
- delete srMesh;
areas = 0;
}
-// Copyright (C) 2007-2024 CEA, EDF
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __TORUSTEST_HXX__
-#define __TORUSTEST_HXX__
+#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
namespace MEDCoupling
{
class ShapeRecognMeshBuilder;
void testArea();
private:
- ShapeRecognMeshBuilder *srMesh = 0;
+ std::unique_ptr< ShapeRecognMeshBuilder > srMesh;
const Areas *areas;
};
-};
-
-#endif // __TORUSTEST_HXX__
+}