-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 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
SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen)
: SMESH_Hypothesis(hypId, studyId, gen)
{
- //gen->_mapAlgo[hypId] = this;
-
+ _compatibleAllHypFilter = _compatibleNoAuxHypFilter = NULL;
_onlyUnaryInput = _requireDiscreteBoundary = _requireShape = true;
_quadraticMesh = _supportSubmeshes = false;
_error = COMPERR_OK;
SMESH_Algo::~SMESH_Algo()
{
+ delete _compatibleNoAuxHypFilter;
+ // delete _compatibleAllHypFilter; -- _compatibleNoAuxHypFilter does it!!!
}
//=============================================================================
{
_shapeType = (1 << TopAbs_VERTEX);
_type = ALGO_0D;
- //gen->_map0D_Algo[hypId] = this;
}
SMESH_1D_Algo::SMESH_1D_Algo(int hypId, int studyId, SMESH_Gen* gen)
: SMESH_Algo(hypId, studyId, gen)
{
_shapeType = (1 << TopAbs_EDGE);
_type = ALGO_1D;
- //gen->_map1D_Algo[hypId] = this;
}
SMESH_2D_Algo::SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen)
: SMESH_Algo(hypId, studyId, gen)
{
_shapeType = (1 << TopAbs_FACE);
_type = ALGO_2D;
- //gen->_map2D_Algo[hypId] = this;
}
SMESH_3D_Algo::SMESH_3D_Algo(int hypId, int studyId, SMESH_Gen* gen)
: SMESH_Algo(hypId, studyId, gen)
{
_shapeType = (1 << TopAbs_SOLID);
_type = ALGO_3D;
- //gen->_map3D_Algo[hypId] = this;
}
//=============================================================================
{
SMESH_Algo* me = const_cast< SMESH_Algo* >( this );
me->_usedHypList.clear();
- SMESH_HypoFilter filter;
- if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
+ if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary ))
{
- aMesh.GetHypotheses( aShape, filter, me->_usedHypList, true );
+ aMesh.GetHypotheses( aShape, *filter, me->_usedHypList, true );
if ( ignoreAuxiliary && _usedHypList.size() > 1 )
me->_usedHypList.clear(); //only one compatible hypothesis allowed
}
{
SMESH_Algo* me = const_cast< SMESH_Algo* >( this );
me->_appliedHypList.clear();
- SMESH_HypoFilter filter;
- if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
- aMesh.GetHypotheses( aShape, filter, me->_appliedHypList, false );
+ if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary ))
+ aMesh.GetHypotheses( aShape, *filter, me->_appliedHypList, false );
return _appliedHypList;
}
double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
{
double UMin = 0, UMax = 0;
- if (BRep_Tool::Degenerated(E))
- return 0;
TopLoc_Location L;
Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
+ if ( C.IsNull() )
+ return 0.;
GeomAdaptor_Curve AdaptCurve(C, UMin, UMax); //range is important for periodic curves
double length = GCPnts_AbscissaPoint::Length(AdaptCurve, UMin, UMax);
return length;
bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
const TopoDS_Edge& theEdge,
const bool ignoreMediumNodes,
- map< double, const SMDS_MeshNode* > & theNodes)
+ map< double, const SMDS_MeshNode* > & theNodes,
+ const SMDSAbs_ElementType typeToCheck)
{
theNodes.clear();
return false;
SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
- if ( !eSubMesh || !eSubMesh->GetElements()->more() )
+ if ( !eSubMesh || ( eSubMesh->NbElements()==0 && eSubMesh->NbNodes() == 0))
return false; // edge is not meshed
int nbNodes = 0;
while ( nIt->more() )
{
const SMDS_MeshNode* node = nIt->next();
- if ( ignoreMediumNodes ) {
- SMDS_ElemIteratorPtr elemIt = node->GetInverseElementIterator();
- if ( elemIt->more() && elemIt->next()->IsMediumNode( node ))
- continue;
- }
+ if ( ignoreMediumNodes && SMESH_MesherHelper::IsMedium( node, typeToCheck ))
+ continue;
const SMDS_PositionPtr& pos = node->GetPosition();
if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
return false;
//================================================================================
/*!
- * \brief Make filter recognize only compatible hypotheses
- * \param theFilter - the filter to initialize
- * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
+ * \brief Returns the filter recognizing only compatible hypotheses
+ * \param ignoreAuxiliary - make filter ignore auxiliary hypotheses
+ * \retval SMESH_HypoFilter* - the filter that can be NULL
*/
//================================================================================
-bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
- const bool ignoreAuxiliary) const
+const SMESH_HypoFilter*
+SMESH_Algo::GetCompatibleHypoFilter(const bool ignoreAuxiliary) const
{
if ( !_compatibleHypothesis.empty() )
{
- theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] ));
- for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
- theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] ));
-
- if ( ignoreAuxiliary )
- theFilter.AndNot( theFilter.IsAuxiliary() );
-
- return true;
+ if ( !_compatibleAllHypFilter )
+ {
+ SMESH_HypoFilter* filter = new SMESH_HypoFilter();
+ filter->Init( filter->HasName( _compatibleHypothesis[0] ));
+ for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
+ filter->Or( filter->HasName( _compatibleHypothesis[ i ] ));
+
+ SMESH_HypoFilter* filterNoAux = new SMESH_HypoFilter( filter );
+ filterNoAux->AndNot( filterNoAux->IsAuxiliary() );
+
+ // _compatibleNoAuxHypFilter will detele _compatibleAllHypFilter!!!
+ SMESH_Algo* me = const_cast< SMESH_Algo* >( this );
+ me->_compatibleAllHypFilter = filter;
+ me->_compatibleNoAuxHypFilter = filterNoAux;
+ }
+ return ignoreAuxiliary ? _compatibleNoAuxHypFilter : _compatibleAllHypFilter;
}
- return false;
+ return 0;
}
//================================================================================
Standard_Real tol = BRep_Tool::Tolerance( V );
Standard_Real angTol = 2e-3;
try {
-#if OCC_VERSION_LARGE > 0x06010000
OCC_CATCH_SIGNALS;
-#endif
return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol);
}
catch (Standard_Failure) {
return GeomAbs_C0;
}
+//================================================================================
+/*!
+ * \brief Return true if an edge can be considered straight
+ */
+//================================================================================
+
+bool SMESH_Algo::IsStraight( const TopoDS_Edge & E,
+ const bool degenResult)
+{
+ {
+ double f,l;
+ if ( BRep_Tool::Curve( E, f, l ).IsNull())
+ return degenResult;
+ }
+ BRepAdaptor_Curve curve( E );
+ switch( curve.GetType() )
+ {
+ case GeomAbs_Line:
+ return true;
+ case GeomAbs_Circle:
+ case GeomAbs_Ellipse:
+ case GeomAbs_Hyperbola:
+ case GeomAbs_Parabola:
+ return false;
+ // case GeomAbs_BezierCurve:
+ // case GeomAbs_BSplineCurve:
+ // case GeomAbs_OtherCurve:
+ default:;
+ }
+ const double f = curve.FirstParameter();
+ const double l = curve.LastParameter();
+ const gp_Pnt pf = curve.Value( f );
+ const gp_Pnt pl = curve.Value( l );
+ const gp_Vec v1( pf, pl );
+ const double v1Len = v1.Magnitude();
+ if ( v1Len < std::numeric_limits< double >::min() )
+ return false; // E seems closed
+ const double tol = Min( 10 * curve.Tolerance(), v1Len * 1e-2 );
+ const int nbSamples = 7;
+ for ( int i = 0; i < nbSamples; ++i )
+ {
+ const double r = ( i + 1 ) / nbSamples;
+ const gp_Pnt pi = curve.Value( f * r + l * ( 1 - r ));
+ const gp_Vec vi( pf, pi );
+ const double h = 0.5 * v1.Crossed( vi ).Magnitude() / v1Len;
+ if ( h > tol )
+ return false;
+ }
+ return true;
+}
+
+//================================================================================
+/*!
+ * \brief Return true if an edge has no 3D curve
+ */
+//================================================================================
+
+bool SMESH_Algo::isDegenerated( const TopoDS_Edge & E )
+{
+ double f,l;
+ TopLoc_Location loc;
+ Handle(Geom_Curve) C = BRep_Tool::Curve( E, loc, f,l );
+ return C.IsNull();
+}
+
//================================================================================
/*!
* \brief Return the node built on a vertex
* \param V - the vertex
* \param meshDS - mesh
* \retval const SMDS_MeshNode* - found node or NULL
+ * \sa SMESH_MesherHelper::GetSubShapeByNode( const SMDS_MeshNode*, SMESHDS_Mesh* )
*/
//================================================================================