1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 \class GEOM_AISShape GEOM_AISShape.hxx
28 #include "GEOM_AISShape.hxx"
29 #include "GEOM_AISVector.hxx"
31 #include <GEOMUtils.hxx>
33 // Open CASCADE Includes
34 #include <AIS_InteractiveContext.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 #include <BRep_Tool.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
38 #include <GeomAdaptor_Curve.hxx>
39 #include <Graphic3d_ArrayOfPoints.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Graphic3d_AspectMarker3d.hxx>
43 #include <Graphic3d_AspectText3d.hxx>
44 #include <Prs3d_Arrow.hxx>
45 #include <Prs3d_IsoAspect.hxx>
46 #include <Prs3d_ShadingAspect.hxx>
47 #include <SelectBasics_SensitiveEntity.hxx>
48 #include <SelectMgr_EntityOwner.hxx>
49 #include <SelectMgr_IndexedMapOfOwner.hxx>
50 #include <SelectMgr_Selection.hxx>
51 #include <StdPrs_ShadedShape.hxx>
52 #include <StdSelect_BRepOwner.hxx>
53 #include <StdSelect_DisplayMode.hxx>
54 #include <TColStd_IndexedMapOfInteger.hxx>
55 #include <TColStd_ListIteratorOfListOfInteger.hxx>
56 #include <TColStd_ListOfInteger.hxx>
58 #include <TopExp_Explorer.hxx>
59 #include <TopTools_IndexedMapOfShape.hxx>
61 #include <TopoDS_Edge.hxx>
62 #include <TopoDS_Shape.hxx>
63 #include <TopoDS_Vertex.hxx>
64 #include <V3d_View.hxx>
68 #include <Prs3d_VertexDrawMode.hxx>
69 #include <StdPrs_WFShape.hxx>
71 #include <SalomeApp_Tools.h>
72 #include <SUIT_Session.h>
73 #include <SUIT_ResourceMgr.h>
75 IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
77 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
78 Quantity_Color GEOM_AISShape::myTopLevelColor;
81 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
82 const Handle(AIS_InteractiveContext)& theIC,
83 SelectMgr_IndexedMapOfOwner& theMap )
85 if ( theObj.IsNull() || theIC.IsNull() )
88 TColStd_ListOfInteger modes;
89 theIC->ActivatedModes( theObj, modes );
91 TColStd_ListIteratorOfListOfInteger itr( modes );
92 for (; itr.More(); itr.Next() ) {
94 if ( !theObj->HasSelection( m ) )
97 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
99 for ( sel->Init(); sel->More(); sel->Next() ) {
100 const Handle(SelectMgr_SensitiveEntity) aHSenEntity = sel->Sensitive();
101 if( aHSenEntity.IsNull() )
104 Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
105 if ( entity.IsNull() )
107 Handle(SelectMgr_EntityOwner) owner =
108 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
109 if ( !owner.IsNull() )
115 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
116 const TopoDS_Shape& aMainShape,
117 const SelectMgr_IndexedMapOfOwner& anAllMap,
118 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
120 TopTools_IndexedMapOfShape aMapOfShapes;
121 TopExp::MapShapes(aMainShape, aMapOfShapes);
123 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
124 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
125 if ( anOwner.IsNull() || !anOwner->HasShape() )
128 const TopoDS_Shape& aSubShape = anOwner->Shape();
129 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
130 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
133 if ( !aToHiliteMap.Contains( anOwner ) )
134 aToHiliteMap.Add( anOwner );
138 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
139 const Standard_CString aName)
140 : SALOME_AISShape(shape),
142 myDisplayVectors(false),
143 myDisplayVertices(false),
144 myFieldDataType(GEOM::FDT_Double),
146 myFieldStepRangeMin(0),
147 myFieldStepRangeMax(0)
149 //rnv: Commented to avoid bug with local selection
150 //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
152 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
153 myPrevDisplayMode = 0;
155 myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
157 myTopLevel = Standard_False;
158 Graphic3d_MaterialAspect aMatAspect;
159 if ( !HasMaterial() ) {
160 aMatAspect.SetAmbient( 0.5 );
161 aMatAspect.SetDiffuse( 0.5 );
162 aMatAspect.SetEmissive( 0.5 );
163 aMatAspect.SetShininess(0.5 );
164 aMatAspect.SetSpecular( 0.5 );
166 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
167 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
171 GEOM_AISShape::~GEOM_AISShape()
175 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io)
180 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO()
182 Handle(SALOME_InteractiveObject) IO;
183 if ( !GetOwner().IsNull() )
184 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
188 Standard_Boolean GEOM_AISShape::hasIO()
190 return !getIO().IsNull();
193 void GEOM_AISShape::setName(const Standard_CString aName)
197 Handle(SALOME_InteractiveObject) IO = getIO();
202 Standard_CString GEOM_AISShape::getName()
204 return myName.ToCString();
207 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
208 const Handle(Prs3d_Presentation)& aPrs,
209 const Standard_Integer aMode)
211 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
213 Handle(AIS_InteractiveContext) anIC = GetContext();
214 // AKL: use old behavior to avoid keeping object's wireframe
215 // if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos')
216 // calling popup menu over(!) the shape in OCC viewer.
217 anIC->SetToHilightSelected( false );
219 bool anIsField = !myFieldStepData.isEmpty();
220 bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
221 bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
223 if (isShowVertices())
224 myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
226 // StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
227 bool isTopLev = isTopLevel() && switchTopLevel();
230 case CustomHighlight:
233 SetColor(topLevelColor());
234 Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
235 anAspect->SetColor( topLevelColor() );
236 Attributes()->SetWireAspect( anAspect );
238 if( !isTopLev && anIsColorField && myFieldDimension == 1 )
239 drawField( aPrs, false, aMode == CustomHighlight );
241 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
246 shadingMode(aPresentationManager, aPrs, aMode);
249 case ShadingWithEdges:
251 myDrawer->SetFaceBoundaryDraw( Standard_True );
252 shadingMode(aPresentationManager, aPrs, Shading);
253 if( anIsColorField && myFieldDimension == 1 ) {
254 myDrawer->SetFaceBoundaryDraw( Standard_False );
261 shadingMode(aPresentationManager, aPrs, Shading);
267 const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
268 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
269 for ( ; Exp.More(); Exp.Next() ) {
270 TopoDS_Vertex aV1, aV2;
271 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
273 // draw curve direction (issue 0021087)
274 anEdgeE.Orientation( TopAbs_FORWARD );
276 if ( anEdgeE.IsNull() ) continue;
278 TopExp::Vertices(anEdgeE, aV1, aV2);
279 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
280 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
284 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
286 if ( C.IsNull() ) continue;
288 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
289 C->D1(lp, aP2, aDirVec);
291 C->D1(fp, aP1, aDirVec);
295 GeomAdaptor_Curve aAdC;
296 aAdC.Load(C, fp, lp);
297 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
299 if (aDist > gp::Resolution()) {
301 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
306 Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
311 // draw color field on vertices
312 if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
317 drawField( aPrs, true );
322 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
325 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
327 myShadingColor = aCol;
330 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
332 myEdgesInShadingColor = aCol;
335 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
340 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
341 const Standard_Boolean aHighlight )
343 Handle(AIS_InteractiveObject) anObj = this;
344 Handle(AIS_InteractiveContext) anIC = GetContext();
345 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
348 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
349 anIC->SetAutomaticHilight( false );
351 anIC->ClearSelected( false );
354 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
356 // Get entity owners for all activated selection modes
357 getEntityOwners( anObj, anIC, anAllMap );
359 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
360 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
363 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
364 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
367 anIC->SetAutomaticHilight( isAutoHilight );
368 anIC->HilightSelected( false );
371 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
373 myDisplayVectors = isDisplayed;
376 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
378 myDisplayVertices = isDisplayed;
381 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
383 myDisplayName = isDisplayed;
386 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
387 const Handle(Prs3d_Presentation)& aPrs,
388 const Standard_Integer aMode)
390 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
392 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
393 aMatAspect.SetTransparency(Transparency());
394 Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
395 Graphic3d_MaterialAspect currentBackMaterial = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
396 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
397 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial );
399 if( isTopLevel() && switchTopLevel() )
400 myDrawer->ShadingAspect()->SetColor( topLevelColor() );
402 if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
403 myDrawer->ShadingAspect()->SetColor(myShadingColor);
405 myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
408 bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
409 if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
415 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
416 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
417 SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
421 Standard_Boolean GEOM_AISShape::isTopLevel()
426 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
430 myPrevDisplayMode = DisplayMode();
432 switch(topLevelDisplayMode()) {
433 case TopWireFrame : dm = Wireframe; break;
434 case TopShading : dm = Shading; break;
435 case TopShadingWithEdges : dm = ShadingWithEdges; break;
436 default : dm = myPrevDisplayMode; break;
441 SetDisplayMode(myPrevDisplayMode);
446 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
448 myPrevDisplayMode = mode;
451 Quantity_Color GEOM_AISShape::topLevelColor()
453 return myTopLevelColor;
456 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
461 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
466 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
471 Standard_Boolean GEOM_AISShape::switchTopLevel()
473 return myTopLevelDm != TopShowAdditionalWActor;
476 Standard_Boolean GEOM_AISShape::toActivate()
478 return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
481 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
482 const int theFieldDimension,
483 const QList<QVariant>& theFieldStepData,
484 const TCollection_AsciiString& theFieldStepName,
485 const double theFieldStepRangeMin,
486 const double theFieldStepRangeMax )
488 myFieldDataType = theFieldDataType;
489 myFieldDimension = theFieldDimension;
490 myFieldStepData = theFieldStepData;
491 myFieldStepName = theFieldStepName;
492 myFieldStepRangeMin = theFieldStepRangeMin;
493 myFieldStepRangeMax = theFieldStepRangeMax;
496 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
497 int& theFieldDimension,
498 QList<QVariant>& theFieldStepData,
499 TCollection_AsciiString& theFieldStepName,
500 double& theFieldStepRangeMin,
501 double& theFieldStepRangeMax ) const
503 theFieldDataType = myFieldDataType;
504 theFieldDimension = myFieldDimension;
505 theFieldStepData = myFieldStepData;
506 theFieldStepName = myFieldStepName;
507 theFieldStepRangeMin = myFieldStepRangeMin;
508 theFieldStepRangeMax = myFieldStepRangeMax;
511 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
512 const bool theIsString,
513 const bool theIsHighlight )
515 if( myFieldStepData.isEmpty() )
518 QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
520 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
521 switch( myFieldDimension )
523 case 0: aShapeType = TopAbs_VERTEX; break;
524 case 1: aShapeType = TopAbs_EDGE; break;
525 case 2: aShapeType = TopAbs_FACE; break;
526 case 3: aShapeType = TopAbs_SOLID; break;
527 case -1: aShapeType = TopAbs_VERTEX; break;
530 TopTools_IndexedMapOfShape aShapeMap;
531 TopExp::MapShapes( myshape, aShapeMap );
533 TColStd_IndexedMapOfInteger anIndexMap;
535 TopExp_Explorer anExp;
536 for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
538 TopoDS_Shape aSubShape = anExp.Current();
539 if( !aSubShape.IsNull() )
541 Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
542 if( anIndexMap.Contains( aSubShapeIndex ) )
545 anIndexMap.Add( aSubShapeIndex );
547 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
551 if( aFieldStepDataIter.hasNext() )
553 const QVariant& aVariant = aFieldStepDataIter.next();
555 aString = aVariant.toString();
557 aQColor = aVariant.value<QColor>();
565 if( computeMassCenter( aSubShape, aCenter ) )
567 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
569 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
570 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
571 anAspectText3d->SetColor( myLabelColor );
572 aGroup->SetPrimitivesAspect( anAspectText3d );
574 aGroup->Text( aString.toLatin1().constData(), aVertex, 14 );
579 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
580 SetCustomColor( aSubShape, aColor );
581 if( myFieldDimension == 0 )
583 TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
584 if( !aVertexShape.IsNull() )
586 gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
588 Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
589 anAspectMarker3d->SetColor( aColor );
590 anAspectMarker3d->SetType( Aspect_TOM_POINT );
591 anAspectMarker3d->SetScale( 10.0 );
592 aGroup->SetPrimitivesAspect( anAspectMarker3d );
594 Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
595 anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
597 aGroup->AddPrimitiveArray( anArray );
600 else if( myFieldDimension == 1 )
602 myDrawer->WireAspect()->SetColor( aColor );
604 myDrawer->WireAspect()->SetWidth( myOwnWidth );
606 myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
608 StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
611 else if( myFieldDimension == 2 ||
612 myFieldDimension == 3 ||
613 myFieldDimension == -1 )
615 //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
616 //anAspect->SetColor( aColor );
617 //myDrawer->SetShadingAspect( anAspect );
618 //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
624 SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
625 thePrs, AIS_Shaded );
628 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
630 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
632 gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
633 gp_Pnt aCenter = anAx3.Location();
635 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
637 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
638 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
639 anAspectText3d->SetColor( myLabelColor );
640 aGroup->SetPrimitivesAspect( anAspectText3d );
642 const char* aName = getIO()->getName();
643 aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
646 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
649 theCenter.SetCoord( 0,0,0 );
650 Standard_Integer aNbPoints = 0;
652 if ( theShape.ShapeType() == TopAbs_EDGE )
655 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
656 if ( !curve.IsNull() )
658 theCenter = curve->Value( 0.5 * ( f + l ));
662 else if ( theShape.ShapeType() == TopAbs_FACE )
664 const TopoDS_Face& F = TopoDS::Face( theShape );
665 BRepAdaptor_Surface surface( F );
668 Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
669 if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
673 const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
674 const Poly_Array1OfTriangle& trias = triangulation->Triangles();
675 Standard_Integer n1,n2,n3;
676 for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
678 trias( iT ).Get( n1,n2,n3 );
679 const gp_Pnt2d& uv1 = uvArray( n1 );
680 const gp_Pnt2d& uv2 = uvArray( n2 );
681 const gp_Pnt2d& uv3 = uvArray( n3 );
682 double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
683 ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
684 C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
687 if ( A > std::numeric_limits<double>::min() )
690 theCenter = surface.Value( C.X(), C.Y() );
694 if ( aNbPoints == 0 )
696 theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
697 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
702 if ( aNbPoints == 0 )
704 TopExp_Explorer anExp;
705 for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
707 TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
708 if( !aVertex.IsNull() )
710 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
711 theCenter.ChangeCoord() += aPnt.XYZ();
718 theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;