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>
45 #include <Prs3d_Arrow.hxx>
46 #include <Prs3d_IsoAspect.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <SelectBasics_SensitiveEntity.hxx>
49 #include <SelectMgr_EntityOwner.hxx>
50 #include <SelectMgr_IndexedMapOfOwner.hxx>
51 #include <SelectMgr_Selection.hxx>
52 #include <StdPrs_ShadedShape.hxx>
53 #include <StdPrs_ToolTriangulatedShape.hxx>
54 #include <StdSelect_BRepOwner.hxx>
55 #include <StdSelect_DisplayMode.hxx>
56 #include <TColStd_IndexedMapOfInteger.hxx>
57 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <TColStd_ListOfInteger.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopoDS_Vertex.hxx>
66 #include <V3d_View.hxx>
70 #include <Prs3d_VertexDrawMode.hxx>
71 #include <StdPrs_WFShape.hxx>
73 #include <SalomeApp_Tools.h>
74 #include <SUIT_Session.h>
75 #include <SUIT_ResourceMgr.h>
77 IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
79 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
80 Quantity_Color GEOM_AISShape::myTopLevelColor;
83 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
84 const Handle(AIS_InteractiveContext)& theIC,
85 SelectMgr_IndexedMapOfOwner& theMap )
87 if ( theObj.IsNull() || theIC.IsNull() )
90 TColStd_ListOfInteger modes;
91 theIC->ActivatedModes( theObj, modes );
93 TColStd_ListIteratorOfListOfInteger itr( modes );
94 for (; itr.More(); itr.Next() ) {
96 if ( !theObj->HasSelection( m ) )
99 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
101 for ( sel->Init(); sel->More(); sel->Next() ) {
102 const Handle(SelectMgr_SensitiveEntity) aHSenEntity = sel->Sensitive();
103 if( aHSenEntity.IsNull() )
106 Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
107 if ( entity.IsNull() )
109 Handle(SelectMgr_EntityOwner) owner =
110 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
111 if ( !owner.IsNull() )
117 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
118 const TopoDS_Shape& aMainShape,
119 const SelectMgr_IndexedMapOfOwner& anAllMap,
120 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
122 TopTools_IndexedMapOfShape aMapOfShapes;
123 TopExp::MapShapes(aMainShape, aMapOfShapes);
125 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
126 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
127 if ( anOwner.IsNull() || !anOwner->HasShape() )
130 const TopoDS_Shape& aSubShape = anOwner->Shape();
131 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
132 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
135 if ( !aToHiliteMap.Contains( anOwner ) )
136 aToHiliteMap.Add( anOwner );
140 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
141 const Standard_CString aName)
142 : SALOME_AISShape(shape),
144 myDisplayVectors(false),
145 myDisplayVertices(false),
146 myFieldDataType(GEOM::FDT_Double),
148 myFieldStepRangeMin(0),
149 myFieldStepRangeMax(0)
151 //rnv: Commented to avoid bug with local selection
152 //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
154 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
155 myPrevDisplayMode = 0;
157 myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
159 myTopLevel = Standard_False;
160 Graphic3d_MaterialAspect aMatAspect;
161 if ( !HasMaterial() ) {
162 aMatAspect.SetAmbient( 0.5 );
163 aMatAspect.SetDiffuse( 0.5 );
164 aMatAspect.SetEmissive( 0.5 );
165 aMatAspect.SetShininess(0.5 );
166 aMatAspect.SetSpecular( 0.5 );
168 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
169 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
173 GEOM_AISShape::~GEOM_AISShape()
177 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io)
182 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO()
184 Handle(SALOME_InteractiveObject) IO;
185 if ( !GetOwner().IsNull() )
186 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
190 Standard_Boolean GEOM_AISShape::hasIO()
192 return !getIO().IsNull();
195 void GEOM_AISShape::setName(const Standard_CString aName)
199 Handle(SALOME_InteractiveObject) IO = getIO();
204 Standard_CString GEOM_AISShape::getName()
206 return myName.ToCString();
209 Standard_Boolean GEOM_AISShape::AcceptDisplayMode(const Standard_Integer theMode) const
211 return theMode >= Wireframe && theMode <= CustomHighlight;
214 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
215 const Handle(Prs3d_Presentation)& aPrs,
216 const Standard_Integer aMode)
218 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
220 Handle(AIS_InteractiveContext) anIC = GetContext();
221 // AKL: use old behavior to avoid keeping object's wireframe
222 // if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos')
223 // calling popup menu over(!) the shape in OCC viewer.
224 anIC->SetToHilightSelected( false );
226 bool anIsField = !myFieldStepData.isEmpty();
227 bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
228 bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
230 if (isShowVertices())
231 myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
233 // StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
234 bool isTopLev = isTopLevel() && switchTopLevel();
237 // Begin 0023271: [CEA 1823] Deflection Coefficient not taken into account in wireframe
239 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
241 // After this call if type of deflection is relative
242 // computed deflection coefficient is stored as absolute.
243 Prs3d::GetDeflection (myshape, myDrawer);
246 case CustomHighlight:
249 SetColor(topLevelColor());
250 Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
251 anAspect->SetColor( topLevelColor() );
252 Attributes()->SetWireAspect( anAspect );
254 if( !isTopLev && anIsColorField && myFieldDimension == 1 )
255 drawField( aPrs, false, aMode == CustomHighlight );
257 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
262 shadingMode(aPresentationManager, aPrs, aMode);
265 case ShadingWithEdges:
267 myDrawer->SetFaceBoundaryDraw( Standard_True );
268 shadingMode(aPresentationManager, aPrs, Shading);
269 if( anIsColorField && myFieldDimension == 1 ) {
270 myDrawer->SetFaceBoundaryDraw( Standard_False );
277 shadingMode(aPresentationManager, aPrs, Shading);
283 const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
284 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
285 for ( ; Exp.More(); Exp.Next() ) {
286 TopoDS_Vertex aV1, aV2;
287 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
289 // draw curve direction (issue 0021087)
290 anEdgeE.Orientation( TopAbs_FORWARD );
292 if ( anEdgeE.IsNull() ) continue;
294 TopExp::Vertices(anEdgeE, aV1, aV2);
295 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
296 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
300 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
302 if ( C.IsNull() ) continue;
304 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
305 C->D1(lp, aP2, aDirVec);
307 C->D1(fp, aP1, aDirVec);
311 GeomAdaptor_Curve aAdC;
312 aAdC.Load(C, fp, lp);
313 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
315 if (aDist > gp::Resolution()) {
317 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
322 Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
327 // draw color field on vertices
328 if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
333 drawField( aPrs, true );
338 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
341 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
343 myShadingColor = aCol;
346 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
348 myEdgesInShadingColor = aCol;
351 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
356 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
357 const Standard_Boolean aHighlight )
359 Handle(AIS_InteractiveObject) anObj = this;
360 Handle(AIS_InteractiveContext) anIC = GetContext();
361 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
364 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
365 anIC->SetAutomaticHilight( false );
367 anIC->ClearSelected( false );
370 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
372 // Get entity owners for all activated selection modes
373 getEntityOwners( anObj, anIC, anAllMap );
375 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
376 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
379 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
380 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
383 anIC->SetAutomaticHilight( isAutoHilight );
384 anIC->HilightSelected( false );
387 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
389 myDisplayVectors = isDisplayed;
392 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
394 myDisplayVertices = isDisplayed;
397 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
399 myDisplayName = isDisplayed;
402 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
403 const Handle(Prs3d_Presentation)& aPrs,
404 const Standard_Integer aMode)
406 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
408 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
409 aMatAspect.SetTransparency(Transparency());
410 Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
411 Graphic3d_MaterialAspect currentBackMaterial = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
412 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
413 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial );
415 if( isTopLevel() && switchTopLevel() )
416 myDrawer->ShadingAspect()->SetColor( topLevelColor() );
418 if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
419 myDrawer->ShadingAspect()->SetColor(myShadingColor);
421 myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
424 bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
425 if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
431 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
432 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
433 SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
437 Standard_Boolean GEOM_AISShape::isTopLevel()
442 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
446 myPrevDisplayMode = DisplayMode();
448 switch(topLevelDisplayMode()) {
449 case TopWireFrame : dm = Wireframe; break;
450 case TopShading : dm = Shading; break;
451 case TopShadingWithEdges : dm = ShadingWithEdges; break;
452 default : dm = myPrevDisplayMode; break;
457 SetDisplayMode(myPrevDisplayMode);
462 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
464 myPrevDisplayMode = mode;
467 Quantity_Color GEOM_AISShape::topLevelColor()
469 return myTopLevelColor;
472 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
477 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
482 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
487 Standard_Boolean GEOM_AISShape::switchTopLevel()
489 return myTopLevelDm != TopShowAdditionalWActor;
492 Standard_Boolean GEOM_AISShape::toActivate()
494 return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
497 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
498 const int theFieldDimension,
499 const QList<QVariant>& theFieldStepData,
500 const TCollection_AsciiString& theFieldStepName,
501 const double theFieldStepRangeMin,
502 const double theFieldStepRangeMax )
504 myFieldDataType = theFieldDataType;
505 myFieldDimension = theFieldDimension;
506 myFieldStepData = theFieldStepData;
507 myFieldStepName = theFieldStepName;
508 myFieldStepRangeMin = theFieldStepRangeMin;
509 myFieldStepRangeMax = theFieldStepRangeMax;
512 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
513 int& theFieldDimension,
514 QList<QVariant>& theFieldStepData,
515 TCollection_AsciiString& theFieldStepName,
516 double& theFieldStepRangeMin,
517 double& theFieldStepRangeMax ) const
519 theFieldDataType = myFieldDataType;
520 theFieldDimension = myFieldDimension;
521 theFieldStepData = myFieldStepData;
522 theFieldStepName = myFieldStepName;
523 theFieldStepRangeMin = myFieldStepRangeMin;
524 theFieldStepRangeMax = myFieldStepRangeMax;
527 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
528 const bool theIsString,
529 const bool theIsHighlight )
531 if( myFieldStepData.isEmpty() )
534 QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
536 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
537 switch( myFieldDimension )
539 case 0: aShapeType = TopAbs_VERTEX; break;
540 case 1: aShapeType = TopAbs_EDGE; break;
541 case 2: aShapeType = TopAbs_FACE; break;
542 case 3: aShapeType = TopAbs_SOLID; break;
543 case -1: aShapeType = TopAbs_VERTEX; break;
546 TopTools_IndexedMapOfShape aShapeMap;
547 TopExp::MapShapes( myshape, aShapeMap );
549 TColStd_IndexedMapOfInteger anIndexMap;
551 TopExp_Explorer anExp;
552 for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
554 TopoDS_Shape aSubShape = anExp.Current();
555 if( !aSubShape.IsNull() )
557 Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
558 if( anIndexMap.Contains( aSubShapeIndex ) )
561 anIndexMap.Add( aSubShapeIndex );
563 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
567 if( aFieldStepDataIter.hasNext() )
569 const QVariant& aVariant = aFieldStepDataIter.next();
571 aString = aVariant.toString();
573 aQColor = aVariant.value<QColor>();
581 if( computeMassCenter( aSubShape, aCenter ) )
583 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
585 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
586 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
587 anAspectText3d->SetColor( myLabelColor );
588 aGroup->SetPrimitivesAspect( anAspectText3d );
590 aGroup->Text( aString.toUtf8().constData(), aVertex, 14 );
595 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
596 SetCustomColor( aSubShape, aColor );
597 if( myFieldDimension == 0 )
599 TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
600 if( !aVertexShape.IsNull() )
602 gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
604 Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
605 anAspectMarker3d->SetColor( aColor );
606 anAspectMarker3d->SetType( Aspect_TOM_POINT );
607 anAspectMarker3d->SetScale( 10.0 );
608 aGroup->SetPrimitivesAspect( anAspectMarker3d );
610 Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
611 anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
613 aGroup->AddPrimitiveArray( anArray );
616 else if( myFieldDimension == 1 )
618 myDrawer->WireAspect()->SetColor( aColor );
620 myDrawer->WireAspect()->SetWidth( myOwnWidth );
622 myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
624 StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
627 else if( myFieldDimension == 2 ||
628 myFieldDimension == 3 ||
629 myFieldDimension == -1 )
631 //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
632 //anAspect->SetColor( aColor );
633 //myDrawer->SetShadingAspect( anAspect );
634 //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
640 SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
641 thePrs, AIS_Shaded );
644 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
646 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
648 gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
649 gp_Pnt aCenter = anAx3.Location();
651 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
653 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
654 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
655 anAspectText3d->SetColor( myLabelColor );
656 aGroup->SetPrimitivesAspect( anAspectText3d );
658 const char* aName = getIO()->getName();
659 aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
662 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
665 theCenter.SetCoord( 0,0,0 );
666 Standard_Integer aNbPoints = 0;
668 if ( theShape.ShapeType() == TopAbs_EDGE )
671 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
672 if ( !curve.IsNull() )
674 theCenter = curve->Value( 0.5 * ( f + l ));
678 else if ( theShape.ShapeType() == TopAbs_FACE )
680 const TopoDS_Face& F = TopoDS::Face( theShape );
681 BRepAdaptor_Surface surface( F );
684 Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
685 if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
689 const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
690 const Poly_Array1OfTriangle& trias = triangulation->Triangles();
691 Standard_Integer n1,n2,n3;
692 for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
694 trias( iT ).Get( n1,n2,n3 );
695 const gp_Pnt2d& uv1 = uvArray( n1 );
696 const gp_Pnt2d& uv2 = uvArray( n2 );
697 const gp_Pnt2d& uv3 = uvArray( n3 );
698 double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
699 ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
700 C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
703 if ( A > std::numeric_limits<double>::min() )
706 theCenter = surface.Value( C.X(), C.Y() );
710 if ( aNbPoints == 0 )
712 theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
713 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
718 if ( aNbPoints == 0 )
720 TopExp_Explorer anExp;
721 for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
723 TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
724 if( !aVertex.IsNull() )
726 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
727 theCenter.ChangeCoord() += aPnt.XYZ();
734 theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;