X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Filter_i.cxx;h=e52d29b558c5259311793762df8a11de1961aa31;hb=3c2705b25c2e026bd033aa2c2843eecfc36ceb80;hp=6ab4d0850818ffdd8f84b63bad8f237c458b2ba6;hpb=b47c58114142779e28b8071a0332619cd2a71a3b;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index 6ab4d0850..e52d29b55 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -33,6 +33,7 @@ #include "SMDS_MeshNode.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESH_Gen_i.hxx" +#include "SMESH_Group_i.hxx" #include "SMESH_PythonDump.hxx" #include @@ -588,12 +589,63 @@ SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, COR std::vector elements; myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic); -#ifdef WIN32 - nbIntervals = CORBA::Short( min( nbEvents.size(), funValues.size() - 1)); -#else - nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1)); -#endif SMESH::Histogram_var histogram = new SMESH::Histogram; + + nbIntervals = CORBA::Short( Min( int( nbEvents.size()), + int( funValues.size() - 1 ))); + if ( nbIntervals > 0 ) + { + histogram->length( nbIntervals ); + for ( int i = 0; i < nbIntervals; ++i ) + { + HistogramRectangle& rect = histogram[i]; + rect.nbEvents = nbEvents[i]; + rect.min = funValues[i]; + rect.max = funValues[i+1]; + } + } + return histogram._retn(); +} + +SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short nbIntervals, + CORBA::Boolean isLogarithmic, + SMESH::SMESH_IDSource_ptr object) +{ + SMESH::Histogram_var histogram = new SMESH::Histogram; + + std::vector nbEvents; + std::vector funValues; + std::vector elements; + + SMDS_ElemIteratorPtr elemIt; + if ( SMESH::DownCast< SMESH_GroupOnFilter_i* >( object ) || + SMESH::DownCast< SMESH::Filter_i* >( object )) + { + elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() ); + } + else + { + SMESH::SMESH_Mesh_var mesh = object->GetMesh(); + SMESH::long_array_var objNbElems = object->GetNbElementsByType(); + SMESH::long_array_var meshNbElems = mesh-> GetNbElementsByType(); + if ( meshNbElems[ GetElementType() ] != + objNbElems [ GetElementType() ] ) + { + elements.reserve( objNbElems[ GetElementType() ]); + elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() ); + } + } + if ( elemIt ) + { + while ( elemIt->more() ) + elements.push_back( elemIt->next()->GetID() ); + if ( elements.empty() ) return histogram._retn(); + } + + myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic); + + nbIntervals = CORBA::Short( Min( int( nbEvents.size()), + int( funValues.size() - 1 ))); if ( nbIntervals > 0 ) { histogram->length( nbIntervals ); @@ -920,6 +972,29 @@ CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId ) return myPredicatePtr->IsSatisfy( theId ); } +CORBA::Long Predicate_i::NbSatisfying( SMESH::SMESH_IDSource_ptr obj ) +{ + SMESH::SMESH_Mesh_var meshVar = obj->GetMesh(); + const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( meshVar ); + if ( !meshDS ) + return 0; + myPredicatePtr->SetMesh( meshDS ); + + SMDSAbs_ElementType elemType = SMDSAbs_ElementType( GetElementType() ); + + int nb = 0; + SMDS_ElemIteratorPtr elemIt = + SMESH::DownCast( meshVar )->GetElements( obj, GetElementType() ); + if ( elemIt ) + while ( elemIt->more() ) + { + const SMDS_MeshElement* e = elemIt->next(); + if ( e && e->GetType() == elemType ) + nb += myPredicatePtr->IsSatisfy( e->GetID() ); + } + return nb; +} + Controls::PredicatePtr Predicate_i::GetPredicate() { return myPredicatePtr; @@ -2702,59 +2777,63 @@ GetElementsId( SMESH_Mesh_ptr theMesh ) return anArray._retn(); } -template -static void collectMeshInfo(const TIterator& theItr, - TPredicate& thePred, - SMESH::long_array& theRes) -{ - if (!theItr) - return; - while (theItr->more()) { - const SMDS_MeshElement* anElem = theItr->next(); - if ( thePred->IsSatisfy( anElem->GetID() ) ) - theRes[ anElem->GetEntityType() ]++; +//============================================================================= +/*! + * \brief Returns number of mesh elements per each \a EntityType + */ +//============================================================================= + +SMESH::long_array* ::Filter_i::GetMeshInfo() +{ + SMESH::long_array_var aRes = new SMESH::long_array(); + aRes->length(SMESH::Entity_Last); + for (int i = 0; i < SMESH::Entity_Last; i++) + aRes[i] = 0; + + if ( !CORBA::is_nil(myMesh) && myPredicate ) + { + const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh); + SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() )); + while ( it->more() ) + { + const SMDS_MeshElement* anElem = it->next(); + if ( myPredicate->IsSatisfy( anElem->GetID() ) ) + aRes[ anElem->GetEntityType() ]++; + } } + + return aRes._retn(); } //============================================================================= /*! - * \brief Returns statistic of mesh elements + * \brief Returns number of mesh elements of each \a ElementType */ //============================================================================= -SMESH::long_array* ::Filter_i::GetMeshInfo() + +SMESH::long_array* ::Filter_i::GetNbElementsByType() { SMESH::long_array_var aRes = new SMESH::long_array(); - aRes->length(SMESH::Entity_Last); - for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++) + aRes->length(SMESH::NB_ELEMENT_TYPES); + for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++) aRes[i] = 0; - if(!CORBA::is_nil(myMesh) && myPredicate) { - const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh); - SMDS_ElemIteratorPtr it; - switch( GetElementType() ) + if ( !CORBA::is_nil(myMesh) && myPredicate ) { + const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh); + SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() )); + CORBA::Long& nbElems = aRes[ GetElementType() ]; + while ( it->more() ) { - case SMDSAbs_Node: - collectMeshInfo(aMesh->nodesIterator(),myPredicate,aRes); - break; - case SMDSAbs_Edge: - collectMeshInfo(aMesh->edgesIterator(),myPredicate,aRes); - break; - case SMDSAbs_Face: - collectMeshInfo(aMesh->facesIterator(),myPredicate,aRes); - break; - case SMDSAbs_Volume: - collectMeshInfo(aMesh->volumesIterator(),myPredicate,aRes); - break; - case SMDSAbs_All: - default: - collectMeshInfo(aMesh->elementsIterator(),myPredicate,aRes); - break; + const SMDS_MeshElement* anElem = it->next(); + if ( myPredicate->IsSatisfy( anElem->GetID() ) ) + nbElems++; } } return aRes._retn(); } + //================================================================================ /*! * \brief Return GetElementType() within an array @@ -2991,8 +3070,7 @@ CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria ) //======================================================================= CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria ) { - if ( myPredicate != 0 ) - myPredicate->UnRegister(); + SetPredicate( SMESH::Predicate::_nil() ); SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i(); FilterManager_ptr aFilterMgr = aFilter->_this(); @@ -3345,6 +3423,8 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria SetPredicate( aResPredicate ); + aResPredicate->UnRegister(); + return !aResPredicate->_is_nil(); }