From: eap Date: Mon, 3 Oct 2016 17:30:07 +0000 (+0300) Subject: Improve GEOM_AISShape::computeMassCenter() on edges and faces X-Git-Tag: V8_2_0a1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=accebb2c2b022dec5352b916aa9cb4573c9e90b6;p=modules%2Fgeom.git Improve GEOM_AISShape::computeMassCenter() on edges and faces which is used to show field values --- diff --git a/src/OBJECT/GEOM_AISShape.cxx b/src/OBJECT/GEOM_AISShape.cxx index 7d4842187..4734bf77e 100644 --- a/src/OBJECT/GEOM_AISShape.cxx +++ b/src/OBJECT/GEOM_AISShape.cxx @@ -34,54 +34,49 @@ // Open CASCADE Includes #include +#include #include #include #include -#include -#include -#include +#include #include #include #include #include -#include - -#include #include #include -#if OCC_VERSION_LARGE > 0x06070200 -#include -#endif - +#include #include #include -#include #include #include -#include #include -#if OCC_VERSION_MAJOR < 7 - #include -#else - #include -#endif - +#include +#include #include #include #include #include -#include -#include -#include #include +#include #include #include #include #include +#include +#include +#include +#include -#include +#if OCC_VERSION_LARGE > 0x06070200 +#include +#endif -#include +#if OCC_VERSION_MAJOR < 7 + #include +#else + #include +#endif #include #include @@ -280,9 +275,9 @@ void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresent case TexturedShape: { #ifdef USE_TEXTURED_SHAPE - AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode); + AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode); #else - AIS_Shape::Compute(aPresentationManager, aPrs, aMode); + AIS_Shape::Compute(aPresentationManager, aPrs, aMode); #endif } } @@ -657,30 +652,46 @@ void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs ) } Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape, - gp_Pnt& theCenter ) + gp_Pnt& theCenter ) { - Standard_Real aX = 0, aY = 0, aZ = 0; + theCenter.SetCoord( 0,0,0 ); Standard_Integer aNbPoints = 0; - TopExp_Explorer anExp; - for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) + if ( theShape.ShapeType() == TopAbs_EDGE ) + { + double f,l; + Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l ); + if ( !curve.IsNull() ) + { + theCenter = curve->Value( 0.5 * ( f + l )); + aNbPoints = 1; + } + } + else if ( theShape.ShapeType() == TopAbs_FACE ) + { + BRepAdaptor_Surface surface( TopoDS::Face( theShape )); + theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ), + 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() )); + aNbPoints = 1; + } + + if ( aNbPoints == 0 ) { - TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() ); - if( !aVertex.IsNull() ) + TopExp_Explorer anExp; + for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) { - gp_Pnt aPnt = BRep_Tool::Pnt( aVertex ); - aX += aPnt.X(); - aY += aPnt.Y(); - aZ += aPnt.Z(); - aNbPoints++; + TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() ); + if( !aVertex.IsNull() ) + { + gp_Pnt aPnt = BRep_Tool::Pnt( aVertex ); + theCenter.ChangeCoord() += aPnt.XYZ(); + aNbPoints++; + } } } - if( aNbPoints == 0 ) - return Standard_False; + if ( aNbPoints > 0 ) + theCenter.ChangeCoord() /= (Standard_Real) aNbPoints; - theCenter.SetCoord( aX / (Standard_Real)aNbPoints, - aY / (Standard_Real)aNbPoints, - aZ / (Standard_Real)aNbPoints ); - return Standard_True; + return aNbPoints; }