STRING(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS")
ENDIF(MEDCOUPLING_USE_64BIT_IDS)
-IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
- LIST(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS -DWITH_SHAPE_RECOGN)
-ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
-
SET(medcoupling_SWIG_DPYS_FILES medcoupling.i)
INCLUDE_DIRECTORIES(
${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 OR CYGWIN)
+ 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;
return false;
#endif
}
+
+ bool HasShapeRecognitionExt()
+ {
+#ifdef WITH_SHAPE_RECOGN
+ return true;
+#else
+ return false;
+#endif
+ }
std::vector<std::string> ActiveExtensions()
{
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
#include <iterator>
#include <algorithm>
-std::vector<std::string> MEDCoupling::allManagedPrimitivesStr()
+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::copy();
+ 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;
+}
#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::vector<PrimitiveType> allManagedPrimitives()
- {
- return {Plane,Sphere,Cylinder,Cone,Torus,Unknown};
- }
+ std::vector<PrimitiveType> AllManagedPrimitives();
- std::vector<std::string> allManagedPrimitivesStr();
+ std::vector<std::string> AllManagedPrimitivesStr();
- 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::string ConvertPrimitiveToString(PrimitiveType type);
+
+ PrimitiveType ConvertStringToPrimitive(const std::string& type);
- 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;
- };
+ int ConvertPrimitiveToInt(PrimitiveType type);
};
#include "MEDCouplingFieldInt32.hxx"
#include <algorithm>
+#include <iterator>
#include <limits>
using namespace MEDCoupling;
MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildNodePrimitiveType() const
{
checkNodesBeforeBuildingField();
- const std::vector<PrimitiveType> tmp( nodes->getPrimitiveType() );
- return buildField<Int32>("Primitive Type (Node)", 1, {tmp.begin(),tmp.end()}, mesh);
+ 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
#include "ShapeRecognMesh.hxx"
#include "ShapeRecognMeshBuilder.hxx"
#include "Areas.hxx"
+
+ #include <type_traits>
%}
%feature("unref") ShapeRecognMesh "$this->decrRef();"
%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
{
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
{
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:
TARGET_LINK_LIBRARIES(${TESTSHAPE_RECOGN0} shaperecogn InterpKernelTestUtils medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${MEDCOUPLING_INSTALL_BINS})
+
+ #### Test section
+ SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
SET(BASE_TESTS ${TESTSHAPE_RECOGN0})
FOREACH(test ${BASE_TESTS})
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test})
SET_TESTS_PROPERTIES(${test} PROPERTIES ENVIRONMENT "${tests_env}")
ENDFOREACH()
+ INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${TEST_INSTALL_DIRECTORY})
- # Application tests
- SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
- INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${TEST_INSTALL_DIRECTORY})
+ 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)
# 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} ${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} )
"""
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()
- assert( areas.getNumberOfAreas() == 1 )
- assert( areas.getNumberOfNodes(0) == 36 )
+ self.assertEqual( areas.getNumberOfAreas(), 1 )
+ self.assertEqual( areas.getNumberOfNodes(0), 36 )
nodeIds = areas.getNodeIds(0)
f = rem.getAreaPrimitiveType()
- assert( areas.getPrimitiveTypeName(0) == "Plane")
+ 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] ]