+ theCenter = curve->Value( 0.5 * ( f + l ));
+ aNbPoints = 1;
+ }
+ }
+ else if ( theShape.ShapeType() == TopAbs_FACE )
+ {
+ const TopoDS_Face& F = TopoDS::Face( theShape );
+ BRepAdaptor_Surface surface( F );
+
+ TopLoc_Location L;
+ Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
+ if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
+ {
+ gp_XY C( 0, 0 );
+ double A = 0;
+ const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
+ const Poly_Array1OfTriangle& trias = triangulation->Triangles();
+ Standard_Integer n1,n2,n3;
+ for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
+ {
+ trias( iT ).Get( n1,n2,n3 );
+ const gp_Pnt2d& uv1 = uvArray( n1 );
+ const gp_Pnt2d& uv2 = uvArray( n2 );
+ const gp_Pnt2d& uv3 = uvArray( n3 );
+ double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
+ ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
+ C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
+ A += a;
+ }
+ if ( A > std::numeric_limits<double>::min() )
+ {
+ C /= A;
+ theCenter = surface.Value( C.X(), C.Y() );
+ aNbPoints = 1;
+ }
+ }
+ if ( aNbPoints == 0 )
+ {
+ theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
+ 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
+ }
+ aNbPoints = 1;
+ }
+
+ if ( aNbPoints == 0 )
+ {
+ TopExp_Explorer anExp;
+ for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
+ {
+ TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
+ if( !aVertex.IsNull() )
+ {
+ gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
+ theCenter.ChangeCoord() += aPnt.XYZ();
+ aNbPoints++;
+ }