-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// 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.
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// SMESH SMESH : implementaion of SMESH idl descriptions
+// SMESH SMESH : implementation of SMESH idl descriptions
// File : StdMeshers_Import_1D.cxx
// Module : SMESH
//
#include "SMESH_Group.hxx"
#include "SMESH_HypoFilter.hxx"
#include "SMESH_Mesh.hxx"
+#include "SMESH_MeshEditor.hxx"
#include "SMESH_MesherHelper.hxx"
+#include "SMESH_Octree.hxx"
#include "SMESH_subMesh.hxx"
#include "SMESH_subMeshEventListener.hxx"
#include "Utils_SALOME_Exception.hxx"
#include "utilities.h"
+#include <BRepAdaptor_Curve.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
+#include <BndLib_Add3dCurve.hxx>
+#include <GCPnts_TangentialDeflection.hxx>
+#include <ShapeAnalysis_Curve.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
using namespace std;
-//=============================================================================
-/*!
- * Creates StdMeshers_Import_1D
- */
-//=============================================================================
-
-StdMeshers_Import_1D::StdMeshers_Import_1D(int hypId, int studyId, SMESH_Gen * gen)
- :SMESH_1D_Algo(hypId, studyId, gen), _sourceHyp(0)
+//================================================================================
+namespace // INTERNAL STUFF
+//================================================================================
{
- MESSAGE("StdMeshers_Import_1D::StdMeshers_Import_1D");
- _name = "Import_1D";
- _shapeType = (1 << TopAbs_EDGE);
+ /*!
+ * \brief Compute point position on a curve. Use octree to fast reject far points
+ */
+ class CurveProjector : public SMESH_Octree
+ {
+ public:
+ CurveProjector( const TopoDS_Edge& edge, double enlarge );
- _compatibleHypothesis.push_back("ImportSource1D");
-}
+ bool IsOnCurve( const gp_XYZ& point, double & distance2, double & u );
-//=============================================================================
-/*!
- * Check presence of a hypothesis
- */
-//=============================================================================
+ bool IsOut( const gp_XYZ& point ) const { return getBox()->IsOut( point ); }
-bool StdMeshers_Import_1D::CheckHypothesis
- (SMESH_Mesh& aMesh,
- const TopoDS_Shape& aShape,
- SMESH_Hypothesis::Hypothesis_Status& aStatus)
-{
- _sourceHyp = 0;
+ protected:
+ CurveProjector() {}
+ SMESH_Octree* newChild() const { return new CurveProjector; }
+ void buildChildrenData();
+ Bnd_B3d* buildRootBox();
- const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
- if ( hyps.size() == 0 )
+ private:
+ struct CurveSegment : public Bnd_B3d
+ {
+ double _chord, _chord2, _length2;
+ gp_Pnt _pFirst, _pLast;
+ gp_Lin _line;
+ Handle(Geom_Curve) _curve;
+
+ CurveSegment() {}
+ void Init( const gp_Pnt& pf, const gp_Pnt& pl,
+ double uf, double ul, double tol, Handle(Geom_Curve)& curve );
+ bool IsOn( const gp_XYZ& point, double & distance2, double & u );
+ bool IsInContact( const Bnd_B3d& bb );
+ };
+ std::vector< CurveSegment > _segments;
+ };
+
+ //===============================================================================
+ /*!
+ * \brief Create an octree of curve segments
+ */
+ //================================================================================
+
+ CurveProjector::CurveProjector( const TopoDS_Edge& edge, double enlarge )
+ :SMESH_Octree( 0 )
{
- aStatus = SMESH_Hypothesis::HYP_MISSING;
- return false; // can't work with no hypothesis
+ double f,l;
+ Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f, l );
+ double curDeflect = 0.3; // Curvature deflection
+ double angDeflect = 1e+100; // Angular deflection - don't control chordal error
+ GCPnts_TangentialDeflection div( BRepAdaptor_Curve( edge ), angDeflect, curDeflect );
+ _segments.resize( div.NbPoints() - 1 );
+ for ( int i = 1; i < div.NbPoints(); ++i )
+ try {
+ _segments[ i - 1 ].Init( div.Value( i ), div.Value( i+1 ),
+ div.Parameter( i ), div.Parameter( i+1 ),
+ enlarge, curve );
+ }
+ catch ( Standard_Failure ) {
+ _segments.resize( _segments.size() - 1 );
+ --i;
+ }
+ if ( _segments.size() < 3 )
+ myIsLeaf = true;
+
+ compute();
+
+ if ( _segments.size() == 1 )
+ myBox->Enlarge( enlarge );
}
- if ( hyps.size() > 1 )
+ //================================================================================
+ /*!
+ * \brief Return the maximal box
+ */
+ //================================================================================
+
+ Bnd_B3d* CurveProjector::buildRootBox()
{
- aStatus = SMESH_Hypothesis::HYP_ALREADY_EXIST;
- return false;
+ Bnd_B3d* box = new Bnd_B3d;
+ for ( size_t i = 0; i < _segments.size(); ++i )
+ box->Add( _segments[i] );
+ return box;
}
- const SMESHDS_Hypothesis *theHyp = hyps.front();
+ //================================================================================
+ /*!
+ * \brief Redistribute segments among children
+ */
+ //================================================================================
- string hypName = theHyp->GetName();
+ void CurveProjector::buildChildrenData()
+ {
+ bool allIn = true;
+ for ( size_t i = 0; i < _segments.size(); ++i )
+ {
+ for (int j = 0; j < 8; j++)
+ {
+ if ( _segments[i].IsInContact( *myChildren[j]->getBox() ))
+ ((CurveProjector*)myChildren[j])->_segments.push_back( _segments[i]);
+ else
+ allIn = false;
+ }
+ }
+ if ( allIn && _segments.size() < 3 )
+ {
+ myIsLeaf = true;
+ for (int j = 0; j < 8; j++)
+ static_cast<CurveProjector*>( myChildren[j])->myIsLeaf = true;
+ }
+ else
+ {
+ SMESHUtils::FreeVector( _segments ); // = _segments.clear() + free memory
- if (hypName == _compatibleHypothesis.front())
+ for (int j = 0; j < 8; j++)
+ {
+ CurveProjector* child = static_cast<CurveProjector*>( myChildren[j]);
+ if ( child->_segments.size() < 3 )
+ child->myIsLeaf = true;
+ }
+ }
+ }
+
+ //================================================================================
+ /*!
+ * \brief Return true if a point is close to the curve
+ * \param [in] point - the point
+ * \param [out] distance2 - distance to the curve
+ * \param [out] u - parameter on the curve
+ * \return bool - is the point is close to the curve
+ */
+ //================================================================================
+
+ bool CurveProjector::IsOnCurve( const gp_XYZ& point, double & distance2, double & u )
{
- _sourceHyp = (StdMeshers_ImportSource1D *)theHyp;
- aStatus = SMESH_Hypothesis::HYP_OK;
+ if ( getBox()->IsOut( point ))
+ return false;
+
+ bool ok = false;
+ double dist2, param;
+ distance2 = Precision::Infinite();
+
+ if ( isLeaf() )
+ {
+ for ( size_t i = 0; i < _segments.size(); ++i )
+ if ( !_segments[i].IsOut( point ) &&
+ _segments[i].IsOn( point, dist2, param ) &&
+ dist2 < distance2 )
+ {
+ distance2 = dist2;
+ u = param;
+ ok = true;
+ }
+ return ok;
+ }
+ else
+ {
+ for (int i = 0; i < 8; i++)
+ if (((CurveProjector*) myChildren[i])->IsOnCurve( point, dist2, param ) &&
+ dist2 < distance2 )
+ {
+ distance2 = dist2;
+ u = param;
+ ok = true;
+ }
+ }
+ return ok;
+ }
+
+ //================================================================================
+ /*!
+ * \brief Initialize
+ */
+ //================================================================================
+
+ void CurveProjector::CurveSegment::Init(const gp_Pnt& pf,
+ const gp_Pnt& pl,
+ const double uf,
+ const double ul,
+ const double tol,
+ Handle(Geom_Curve)& curve )
+ {
+ _pFirst = pf;
+ _pLast = pl;
+ _curve = curve;
+ _length2 = pf.SquareDistance( pl );
+ _line.SetLocation( pf );
+ _line.SetDirection( gp_Vec( pf, pl ));
+ _chord2 = Max( _line. SquareDistance( curve->Value( uf + 0.25 * ( ul - uf ))),
+ Max( _line.SquareDistance( curve->Value( uf + 0.5 * ( ul - uf ))),
+ _line.SquareDistance( curve->Value( uf + 0.75 * ( ul - uf )))));
+ _chord2 = Max( tol, _chord2 );
+ _chord = Sqrt( _chord2 );
+
+ Bnd_Box bb;
+ BndLib_Add3dCurve::Add( GeomAdaptor_Curve( curve, uf, ul ), tol, bb );
+ Add( bb.CornerMin() );
+ Add( bb.CornerMax() );
+ }
+
+ //================================================================================
+ /*!
+ * \brief Return true if a point is close to the curve segment
+ * \param [in] point - the point
+ * \param [out] distance2 - distance to the curve
+ * \param [out] u - parameter on the curve
+ * \return bool - is the point is close to the curve segment
+ */
+ //================================================================================
+
+ bool CurveProjector::CurveSegment::IsOn( const gp_XYZ& point, double & distance2, double & u )
+ {
+ distance2 = _line.SquareDistance( point );
+ if ( distance2 > _chord2 )
+ return false;
+
+ // check if the point projection falls into the segment range
+ {
+ gp_Vec edge( _pFirst, _pLast );
+ gp_Vec n1p ( _pFirst, point );
+ u = ( edge * n1p ) / _length2; // param [0,1] on the edge
+ if ( u < 0. )
+ {
+ if ( _pFirst.SquareDistance( point ) > _chord2 )
+ return false;
+ }
+ else if ( u > 1. )
+ {
+ if ( _pLast.SquareDistance( point ) > _chord2 )
+ return false;
+ }
+ }
+ gp_Pnt proj;
+ distance2 = ShapeAnalysis_Curve().Project( _curve, point, Precision::Confusion(),
+ proj, u, false );
+ distance2 *= distance2;
return true;
}
- aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
- return true;
-}
+ //================================================================================
+ /*!
+ * \brief Check if the segment is in contact with a box
+ */
+ //================================================================================
+
+ bool CurveProjector::CurveSegment::IsInContact( const Bnd_B3d& bb )
+ {
+ if ( bb.IsOut( _line.Position(), /*isRay=*/true, _chord ))
+ return false;
+
+ gp_Ax1 axRev = _line.Position().Reversed();
+ axRev.SetLocation( _pLast );
+ return !bb.IsOut( axRev, /*isRay=*/true, _chord );
+ }
+
+ //================================================================================
+ //================================================================================
-//================================================================================
-namespace // INTERNAL STUFF
-//================================================================================
-{
int getSubmeshIDForCopiedMesh(const SMESHDS_Mesh* srcMeshDS, SMESH_Mesh* tgtMesh);
enum _ListenerDataType
_ListenerData(const StdMeshers_ImportSource1D* h, _ListenerDataType type=SRC_HYP):
SMESH_subMeshEventListenerData(/*isDeletable=*/true), _srcHyp(h)
{
- myType = type;
+ myType = type;
}
};
//================================================================================
if ( !_importMeshSubDS ) return;
SMDS_ElemIteratorPtr eIt = _importMeshSubDS->GetElements();
while ( eIt->more() )
- meshDS->RemoveFreeElement( eIt->next(), _importMeshSubDS, /*fromGroups=*/false );
+ meshDS->RemoveFreeElement( eIt->next(), 0, /*fromGroups=*/false );
SMDS_NodeIteratorPtr nIt = _importMeshSubDS->GetNodes();
while ( nIt->more() )
- meshDS->RemoveFreeNode( nIt->next(), _importMeshSubDS, /*fromGroups=*/false );
+ meshDS->RemoveFreeNode( nIt->next(), 0, /*fromGroups=*/false );
+ _importMeshSubDS->Clear();
_n2n.clear();
_e2e.clear();
}
switch ( sm->GetSubShape().ShapeType() )
{
case TopAbs_EDGE:
+ if ( SMESH_Algo::isDegenerated( TopoDS::Edge( sm->GetSubShape() )))
+ continue;
case TopAbs_FACE:
_subM.insert( sm );
if ( !sm->IsEmpty() )
"StdMeshers_Import_1D::_Listener") {}
public:
- // return poiter to a static listener
+ // return pointer to a static listener
static _Listener* get() { static _Listener theListener; return &theListener; }
static _ImportData* getImportData(const SMESH_Mesh* srcMesh, SMESH_Mesh* tgtMesh);
const SMESH_Hypothesis* hyp);
void removeSubmesh( SMESH_subMesh* sm, _ListenerData* data );
void clearSubmesh ( SMESH_subMesh* sm, _ListenerData* data, bool clearAllSub );
+ void clearN2N ( SMESH_Mesh* tgtMesh );
// mark sm as missing src hyp with valid groups
static void waitHypModification(SMESH_subMesh* sm)
//--------------------------------------------------------------------------------
/*!
* \brief Remove imported mesh and/or groups if needed
- * \param sm - submesh loosing Import algo
+ * \param sm - submesh losing Import algo
* \param data - data holding imported groups
*/
void _Listener::removeSubmesh( SMESH_subMesh* sm, _ListenerData* data )
bool rmGroups = (d->_copyGroupSubM.erase( sm ) && d->_copyGroupSubM.empty()) || rmMesh;
if ( rmMesh )
d->removeImportedMesh( sm->GetFather()->GetMeshDS() );
- if ( rmGroups && data )
+ if ( rmGroups && data && data->myType == SRC_HYP )
d->removeGroups( sm, data->_srcHyp );
}
}
//--------------------------------------------------------------------------------
+ /*!
+ * \brief Clear _ImportData::_n2n.
+ * _n2n is useful within one mesh.Compute() only
+ */
+ void _Listener::clearN2N( SMESH_Mesh* tgtMesh )
+ {
+ list< _ImportData >& dList = get()->_tgtMesh2ImportData[tgtMesh];
+ list< _ImportData >::iterator d = dList.begin();
+ for ( ; d != dList.end(); ++d )
+ d->_n2n.clear();
+ }
+ //--------------------------------------------------------------------------------
/*!
* \brief Clear submeshes and remove imported mesh and/or groups if necessary
* \param sm - cleared submesh
// remove imported mesh and groups
d->removeImportedMesh( sm->GetFather()->GetMeshDS() );
- if ( data )
+ if ( data && data->myType == SRC_HYP )
d->removeGroups( sm, data->_srcHyp );
// clear the rest submeshes
{
SMESH_subMesh* subM = *sub;
_ListenerData* hypData = (_ListenerData*) subM->GetEventListenerData( get() );
- if ( hypData )
+ if ( hypData && hypData->myType == SRC_HYP )
d->removeGroups( sm, hypData->_srcHyp );
subM->ComputeStateEngine( SMESH_subMesh::CLEAN );
if ( sm->GetSubShape().ShapeType() == TopAbs_FACE )
sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
}
- if ( data )
+ if ( data && data->myType == SRC_HYP )
d->trackHypParams( sm, data->_srcHyp );
d->_n2n.clear();
d->_e2e.clear();
default:;
}
}
+ if ( !data->mySubMeshes.empty() )
+ clearN2N( data->mySubMeshes.front()->GetFather() );
}
else // event of Import submesh
{
d->_computedSubM.insert( *smIt);
}
}
+ // Clear _ImportData::_n2n if it's no more useful, i.e. when
+ // the event is not within mesh.Compute()
+ if ( SMESH_subMesh::ALGO_EVENT == eventType )
+ clearN2N( subMesh->GetFather() );
}
}
TopExp::MapShapes( SMESH_Mesh::PseudoShape(), pseudoSubShapes );
// index of pseudoSubShapes corresponding to srcMeshDS
- int subIndex = srcMeshDS->GetPersistentId() % pseudoSubShapes.Extent();
+ int subIndex = 1 + srcMeshDS->GetPersistentId() % pseudoSubShapes.Extent();
int nbSubShapes = 1 + srcMeshDS->GetPersistentId() / pseudoSubShapes.Extent();
// try to find already present shapeForSrcMesh
aBuilder.MakeCompound( comp );
shapeForSrcMesh = comp;
for ( int iSub = 0; iSub < nbSubShapes; ++iSub )
- aBuilder.Add( comp, pseudoSubShapes( subIndex+iSub ));
+ if ( subIndex+iSub <= pseudoSubShapes.Extent() )
+ aBuilder.Add( comp, pseudoSubShapes( subIndex+iSub ));
TopExp_Explorer vExp( tgtMeshDS->ShapeToMesh(), TopAbs_VERTEX );
aBuilder.Add( comp, vExp.Current() );
}
return 0;
}
+ //================================================================================
+ /*!
+ * \brief Return minimal square length of edges of 1D and 2D elements sharing the node
+ */
+ //================================================================================
+
+ double getMinEdgeLength2( const SMDS_MeshNode* n )
+ {
+ SMESH_NodeXYZ p = n;
+ double minLen2 = Precision::Infinite();
+ for ( SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator(); eIt->more(); )
+ {
+ const SMDS_MeshElement* e = eIt->next();
+ const SMDSAbs_ElementType type = e->GetType();
+ if ( type != SMDSAbs_Edge && type != SMDSAbs_Face )
+ continue;
+ int i = e->GetNodeIndex( n );
+ int iNext = SMESH_MesherHelper::WrapIndex( i + 1, e->NbCornerNodes() );
+ minLen2 = Min( minLen2, p.SquareDistance( e->GetNode( iNext )));
+ if ( type != SMDSAbs_Face )
+ continue;
+ int iPrev = SMESH_MesherHelper::WrapIndex( i - 1, e->NbCornerNodes() );
+ minLen2 = Min( minLen2, p.SquareDistance( e->GetNode( iPrev )));
+ }
+ return minLen2;
+ }
+
} // namespace
+//=============================================================================
+/*!
+ * Creates StdMeshers_Import_1D
+ */
+//=============================================================================
+
+StdMeshers_Import_1D::StdMeshers_Import_1D(int hypId, SMESH_Gen * gen)
+ :SMESH_1D_Algo(hypId, gen), _sourceHyp(0)
+{
+ _name = "Import_1D";
+ _shapeType = (1 << TopAbs_EDGE);
+
+ _compatibleHypothesis.push_back("ImportSource1D");
+}
+
+//=============================================================================
+/*!
+ * Check presence of a hypothesis
+ */
+//=============================================================================
+
+bool StdMeshers_Import_1D::CheckHypothesis
+ (SMESH_Mesh& aMesh,
+ const TopoDS_Shape& aShape,
+ SMESH_Hypothesis::Hypothesis_Status& aStatus)
+{
+ _sourceHyp = 0;
+
+ const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
+ if ( hyps.size() == 0 )
+ {
+ aStatus = SMESH_Hypothesis::HYP_MISSING;
+ return false; // can't work with no hypothesis
+ }
+
+ if ( hyps.size() > 1 )
+ {
+ aStatus = SMESH_Hypothesis::HYP_ALREADY_EXIST;
+ return false;
+ }
+
+ const SMESHDS_Hypothesis *theHyp = hyps.front();
+
+ string hypName = theHyp->GetName();
+
+ if (hypName == _compatibleHypothesis.front())
+ {
+ _sourceHyp = (StdMeshers_ImportSource1D *)theHyp;
+ aStatus = _sourceHyp->GetGroups().empty() ? HYP_BAD_PARAMETER : HYP_OK;
+ if ( aStatus == HYP_BAD_PARAMETER )
+ _Listener::waitHypModification( aMesh.GetSubMesh( aShape ));
+ return aStatus == HYP_OK;
+ }
+
+ aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
+ return false;
+}
//=============================================================================
/*!
- * Import elements from the other mesh
+ * Import elements from the other mesh
*/
//=============================================================================
{
if ( !_sourceHyp ) return false;
- const vector<SMESH_Group*>& srcGroups = _sourceHyp->GetGroups();
+ //MESSAGE("---------> StdMeshers_Import_1D::Compute");
+ const vector<SMESH_Group*>& srcGroups = _sourceHyp->GetGroups(/*loaded=*/true);
if ( srcGroups.empty() )
return error("Invalid source groups");
const double edgeTol = BRep_Tool::Tolerance( geomEdge );
const int shapeID = tgtMesh->ShapeToIndex( geomEdge );
- set<int> subShapeIDs;
- subShapeIDs.insert( shapeID );
+
+ double geomTol = Precision::Confusion();
+ for ( size_t iG = 0; iG < srcGroups.size(); ++iG )
+ {
+ const SMESHDS_GroupBase* srcGroup = srcGroups[iG]->GetGroupDS();
+ for ( SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements(); srcElems->more(); )
+ {
+ const SMDS_MeshElement* edge = srcElems->next();
+ geomTol = Sqrt( 0.5 * ( getMinEdgeLength2( edge->GetNode(0) ) +
+ getMinEdgeLength2( edge->GetNode(1) ))) / 25;
+ iG = srcGroups.size();
+ break;
+ }
+ }
+ CurveProjector curveProjector( geomEdge, geomTol );
// get nodes on vertices
- list < SMESH_TNodeXYZ > vertexNodes;
- list < SMESH_TNodeXYZ >::iterator vNIt;
+ set<int> vertexIDs;
+ list < SMESH_TNodeXYZ > vertexNodes;
+ list < SMESH_TNodeXYZ >::iterator vNIt;
TopExp_Explorer vExp( theShape, TopAbs_VERTEX );
for ( ; vExp.More(); vExp.Next() )
{
const TopoDS_Vertex& v = TopoDS::Vertex( vExp.Current() );
- if ( !subShapeIDs.insert( tgtMesh->ShapeToIndex( v )).second )
+ if ( !vertexIDs.insert( tgtMesh->ShapeToIndex( v )).second )
continue; // closed edge
const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, tgtMesh );
if ( !n )
{
_gen->Compute(theMesh,v,/*anUpward=*/true);
n = SMESH_Algo::VertexNode( v, tgtMesh );
+ //MESSAGE("_gen->Compute " << n);
if ( !n ) return false; // very strange
}
vertexNodes.push_back( SMESH_TNodeXYZ( n ));
+ //MESSAGE("SMESH_Algo::VertexNode " << n->GetID() << " " << n->X() << " " << n->Y() << " " << n->Z() );
}
// import edges from groups
TNodeNodeMap* n2n;
TElemElemMap* e2e;
- for ( int iG = 0; iG < srcGroups.size(); ++iG )
+ for ( size_t iG = 0; iG < srcGroups.size(); ++iG )
{
const SMESHDS_GroupBase* srcGroup = srcGroups[iG]->GetGroupDS();
SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements();
vector<const SMDS_MeshNode*> newNodes;
- SMDS_MeshNode *tmpNode = helper.AddNode(0,0,0);
- double u;
while ( srcElems->more() ) // loop on group contents
{
const SMDS_MeshElement* edge = srcElems->next();
+ gp_XYZ middle = 0.5 * ( SMESH_NodeXYZ( edge->GetNode(0)) +
+ SMESH_NodeXYZ( edge->GetNode(1)));
+ if ( curveProjector.IsOut( middle ))
+ continue;
+
// find or create nodes of a new edge
newNodes.resize( edge->NbNodes() );
newNodes.back() = 0;
+ int nbNodesOnVertex = 0;
SMDS_MeshElement::iterator node = edge->begin_nodes();
- for ( unsigned i = 0; i < newNodes.size(); ++i, ++node )
+ for ( size_t i = 0; i < newNodes.size(); ++i, ++node )
{
- TNodeNodeMap::iterator n2nIt = n2n->insert( make_pair( *node, (SMDS_MeshNode*)0 )).first;
+ TNodeNodeMap::iterator n2nIt = n2n->insert( make_pair( *node, nullptr )).first;
if ( n2nIt->second )
{
- if ( !subShapeIDs.count( n2nIt->second->getshapeId() ))
- break;
+ int sId = n2nIt->second->getshapeId();
+ if ( sId != shapeID )
+ {
+ if ( vertexIDs.count( sId ))
+ ++nbNodesOnVertex;
+ else
+ break;
+ }
}
- else
+ else if ( !vertexNodes.empty() )
{
// find an existing vertex node
+ double checktol = max(1.E-10, 10*edgeTol*edgeTol);
for ( vNIt = vertexNodes.begin(); vNIt != vertexNodes.end(); ++vNIt)
- if ( vNIt->SquareDistance( *node ) < 10 * edgeTol * edgeTol)
+ if ( vNIt->SquareDistance( *node ) < checktol)
{
(*n2nIt).second = vNIt->_node;
vertexNodes.erase( vNIt );
+ ++nbNodesOnVertex;
break;
}
}
if ( !n2nIt->second )
{
- // find out if node lies on theShape
- tmpNode->setXYZ( (*node)->X(), (*node)->Y(), (*node)->Z());
- if ( helper.CheckNodeU( geomEdge, tmpNode, u, 10 * edgeTol, /*force=*/true ))
+ // find out if the node lies on theShape
+ SMESH_NodeXYZ xyz = *node;
+ double dist2, u;
+ if ( curveProjector.IsOnCurve( xyz, dist2, u ))
{
- SMDS_MeshNode* newNode = tgtMesh->AddNode( (*node)->X(), (*node)->Y(), (*node)->Z());
- n2nIt->second = newNode;
- tgtMesh->SetNodeOnEdge( newNode, shapeID, u );
+ // tolerance relative to the length of surrounding edges
+ double mytol2 = getMinEdgeLength2( *node ) / 25 / 25;
+ if ( dist2 < mytol2 )
+ {
+ SMDS_MeshNode* newNode = tgtMesh->AddNode( xyz.X(), xyz.Y(), xyz.Z() );
+ n2nIt->second = newNode;
+ tgtMesh->SetNodeOnEdge( newNode, shapeID, u );
+ }
}
}
if ( !(newNodes[i] = n2nIt->second ))
break;
}
if ( !newNodes.back() )
+ {
+ //MESSAGE("not all nodes of edge lie on theShape");
continue; // not all nodes of edge lie on theShape
+ }
// make a new edge
SMDS_MeshElement * newEdge;
newEdge = tgtMesh->AddEdge( newNodes[0], newNodes[1]);
tgtMesh->SetMeshElementOnShape( newEdge, shapeID );
e2e->insert( make_pair( edge, newEdge ));
- }
- helper.GetMeshDS()->RemoveNode(tmpNode);
- }
+
+ if ( nbNodesOnVertex >= 2 ) // EDGE is meshed by a sole segment
+ {
+ iG = srcGroups.size(); // stop looingp on groups
+ break;
+ }
+ } // loop on group contents
+ } // loop on groups
+
if ( n2n->empty())
return error("Empty source groups");
// copy meshes
vector<SMESH_Mesh*> srcMeshes = _sourceHyp->GetSourceMeshes();
- for ( unsigned i = 0; i < srcMeshes.size(); ++i )
+ for ( size_t i = 0; i < srcMeshes.size(); ++i )
importMesh( srcMeshes[i], theMesh, _sourceHyp, theShape );
return true;
// 1. Copy mesh
+ SMESH_MeshEditor::ElemFeatures elemType;
vector<const SMDS_MeshNode*> newNodes;
const SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
SMDS_ElemIteratorPtr eIt = srcMeshDS->elementsIterator();
tgtMeshDS->FindElement( newNodes, elem->GetType(), /*noMedium=*/false );
if ( !newElem )
{
- newElem = additor.AddElement( newNodes, elem->GetType(), elem->IsPoly());
+ newElem = additor.AddElement( newNodes, elemType.Init( elem, /*basicOnly=*/false ));
tgtSubMesh->AddElement( newElem );
}
if ( toCopyGroups )
(*e2eIt).second = newElem;
}
// copy free nodes
- if ( srcMeshDS->NbNodes() > n2n->size() )
+ if ( srcMeshDS->NbNodes() > (int) n2n->size() )
{
SMDS_NodeIteratorPtr nIt = srcMeshDS->nodesIterator();
while( nIt->more() )
int nb = 1;
while ( !namesByType[ srcGroupDS->GetType() ].insert( name ).second )
name = SMESH_Comment(srcGroup->GetName()) << "_imported_" << nb++;
- SMESH_Group* newGroup = tgtMesh.AddGroup( srcGroupDS->GetType(), name.c_str(), nb );
+ SMESH_Group* newGroup = tgtMesh.AddGroup( srcGroupDS->GetType(), name.c_str() );
SMESHDS_Group* newGroupDS = (SMESHDS_Group*)newGroup->GetGroupDS();
resultGroups.push_back( newGroup );
*/
//=============================================================================
-void StdMeshers_Import_1D::setEventListener(SMESH_subMesh* subMesh,
+void StdMeshers_Import_1D::setEventListener(SMESH_subMesh* subMesh,
StdMeshers_ImportSource1D* sourceHyp)
{
if ( sourceHyp )
// count edges imported from groups
int nbEdges = 0, nbQuadEdges = 0;
- for ( int iG = 0; iG < srcGroups.size(); ++iG )
+ for ( size_t iG = 0; iG < srcGroups.size(); ++iG )
{
const SMESHDS_GroupBase* srcGroup = srcGroups[iG]->GetGroupDS();
SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements();
}
SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
- aResMap.insert(make_pair(sm,aVec));
+ aResMap.insert( make_pair( sm, aVec ));
return true;
}
e2e = &iData->_e2e;
if ( iData->_copyMeshSubM.empty() )
{
- n2n->clear();
+ // n2n->clear(); -- for sharing nodes on EDGEs
e2e->clear();
}
}