From: ageay Date: Wed, 14 Apr 2010 07:29:24 +0000 (+0000) Subject: Some usefull algos for 2DExtruded meshes. X-Git-Tag: V5_1_main_FINAL~132 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d748c8392b8c47564bf209dda4379996c078d3c3;p=tools%2Fmedcoupling.git Some usefull algos for 2DExtruded meshes. --- diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index aa3be9b9e..89d009306 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -346,6 +346,31 @@ void MEDCouplingPointSet::tryToShareSameCoords(const MEDCouplingPointSet& other, setCoords(other._coords); } +/*! + * This method is expecting to be called for meshes so that getSpaceDimension() returns 3. + * This method returns in 'nodes' output all the nodes that are at a distance lower than epsilon from plane + * defined by the point 'pt' and the vector 'vec'. + * @param pt points to an array of size 3 and represents a point that owns to plane. + * @param vec points to an array of size 3 and represents the normal vector of the plane. The norm of the vector is not compulsory equal to 1. But norm must be greater than 10*abs(eps) + * @param eps is the maximal distance around the plane where node in this->_coords will be picked. + * @param nodes is the output of the method. The vector is not compulsory empty before call. The nodes that fulfills the condition will be added at the end of the nodes. + */ +void MEDCouplingPointSet::findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector& nodes) const throw(INTERP_KERNEL::Exception) +{ + if(getSpaceDimension()!=3) + throw INTERP_KERNEL::Exception("Invalid spacedim to be applied on this ! Must be equal to 3 !"); + int nbOfNodes=getNumberOfNodes(); + double a=vec[0],b=vec[1],c=vec[2],d=-pt[0]*vec[0]-pt[1]*vec[1]-pt[2]*vec[2]; + double deno=sqrt(a*a+b*b+c*c); + const double *work=_coords->getConstPointer(); + for(int i=0;i& nodes) const throw(INTERP_KERNEL::Exception); static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2); static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type); static void rotate2DAlg(const double *center, double angle, int nbNodes, double *coords); static void rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, double *coords); virtual MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const = 0; virtual MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; + virtual MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; virtual void findBoundaryNodes(std::vector& nodes) const = 0; virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0; virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 8a776468f..360da8429 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -499,6 +499,23 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelfNode(const int *start, c return buildPartOfMySelf(&cellIdsKept[0],&cellIdsKept[0]+cellIdsKept.size(),true); } +/*! + * Contrary to MEDCouplingUMesh::buildPartOfMySelfNode method this method a mesh with a meshDimension equal to + * this->getMeshDimension()-1. The return newly allocated mesh will share the same coordinates as 'this'. + * Parameter 'fullyIn' specifies if a face that has part of its nodes in ids array is kept or not. + * If 'fullyIn' is true only faces whose ids are \b fully contained in ['start','end') tab will be kept. + */ +MEDCouplingPointSet *MEDCouplingUMesh::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const +{ + DataArrayInt *desc,*descIndx,*revDesc,*revDescIndx; + desc=DataArrayInt::New(); descIndx=DataArrayInt::New(); revDesc=DataArrayInt::New(); revDescIndx=DataArrayInt::New(); + MEDCouplingUMesh *subMesh=buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + desc->decrRef(); descIndx->decrRef(); revDesc->decrRef(); revDescIndx->decrRef(); + MEDCouplingUMesh *ret=(MEDCouplingUMesh *)subMesh->buildPartOfMySelfNode(start,end,fullyIn); + subMesh->decrRef(); + return ret; +} + /*! * This method returns a mesh with meshDim=this->getMeshDimension()-1. * This returned mesh contains cells that are linked with one and only one cell of this. diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 189400f06..8e71a19f9 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -66,6 +66,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *mergeNodes(double precision, bool& areNodesMerged); MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const; + MEDCOUPLING_EXPORT MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const; MEDCOUPLING_EXPORT void findBoundaryNodes(std::vector& nodes) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const; MEDCOUPLING_EXPORT void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 1c353687e..efa7607d8 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -256,6 +256,12 @@ MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelfNode(const int *star return 0; } +MEDCouplingPointSet *MEDCouplingUMeshDesc::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const +{ + //not implemented yet + return 0; +} + void MEDCouplingUMeshDesc::findBoundaryNodes(std::vector& nodes) const { //not implemented yet diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index 0cf2537f7..fa7eeb987 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -54,6 +54,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *mergeNodes(double precision, bool& areNodesMerged); MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const; + MEDCOUPLING_EXPORT MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const; MEDCOUPLING_EXPORT void findBoundaryNodes(std::vector& nodes) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const; MEDCOUPLING_EXPORT void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index b38b4222b..19bff00cd 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -68,6 +68,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testCMesh0 ); CPPUNIT_TEST( testScale ); CPPUNIT_TEST( testTryToShareSameCoords ); + CPPUNIT_TEST( testFindNodeOnPlane ); CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_2 ); @@ -165,6 +166,7 @@ namespace ParaMEDMEM void testCMesh0(); void testScale(); void testTryToShareSameCoords(); + void testFindNodeOnPlane(); void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); void test2DInterpP0P0PL_2(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx index 99e28e8d9..7fc964ded 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx @@ -1691,4 +1691,39 @@ void MEDCouplingBasicsTest::testScale() void MEDCouplingBasicsTest::testTryToShareSameCoords() { + MEDCouplingUMesh *m1=build2DTargetMesh_1(); + MEDCouplingUMesh *m2=build2DTargetMesh_1(); + CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords()); + m1->tryToShareSameCoords(*m2,1e-12); + CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords()); + m1->tryToShareSameCoords(*m2,1e-12); + CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords()); + m2->tryToShareSameCoords(*m1,1e-12); + CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords()); + m1->decrRef(); + m2->decrRef(); + // + m1=build2DTargetMesh_1(); + m2=build2DTargetMesh_2(); + CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords()); + m1->tryToShareSameCoords(*m2,1e-12); + CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords()); + m1->tryToShareSameCoords(*m2,1e-12); + CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords()); + m2->tryToShareSameCoords(*m1,1e-12); + CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords()); + m1->decrRef(); + m2->decrRef(); + // + m1=build2DTargetMesh_1(); + m2=build2DSourceMesh_1(); + CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords()); + CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception); + m1->decrRef(); + m2->decrRef(); +} + +void MEDCouplingBasicsTest::testFindNodeOnPlane() +{ + }