1 // Copyright (C) 2007-2019 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 <Basics_OCCTVersion.hxx>
75 #include <SalomeApp_Tools.h>
76 #include <SUIT_Session.h>
77 #include <SUIT_ResourceMgr.h>
79 IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
81 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
82 Quantity_Color GEOM_AISShape::myTopLevelColor;
85 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
86 const Handle(AIS_InteractiveContext)& theIC,
87 SelectMgr_IndexedMapOfOwner& theMap )
89 if ( theObj.IsNull() || theIC.IsNull() )
92 TColStd_ListOfInteger modes;
93 theIC->ActivatedModes( theObj, modes );
95 TColStd_ListIteratorOfListOfInteger itr( modes );
96 for (; itr.More(); itr.Next() ) {
98 if ( !theObj->HasSelection( m ) )
101 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
103 for ( sel->Init(); sel->More(); sel->Next() ) {
104 const Handle(SelectMgr_SensitiveEntity) aHSenEntity = sel->Sensitive();
105 if( aHSenEntity.IsNull() )
108 Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
109 if ( entity.IsNull() )
111 Handle(SelectMgr_EntityOwner) owner =
112 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
113 if ( !owner.IsNull() )
119 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
120 const TopoDS_Shape& aMainShape,
121 const SelectMgr_IndexedMapOfOwner& anAllMap,
122 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
124 TopTools_IndexedMapOfShape aMapOfShapes;
125 TopExp::MapShapes(aMainShape, aMapOfShapes);
127 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
128 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
129 if ( anOwner.IsNull() || !anOwner->HasShape() )
132 const TopoDS_Shape& aSubShape = anOwner->Shape();
133 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
134 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
137 if ( !aToHiliteMap.Contains( anOwner ) )
138 aToHiliteMap.Add( anOwner );
142 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
143 const Standard_CString aName)
144 : SALOME_AISShape(shape),
146 myDisplayVectors(false),
147 myDisplayVertices(false),
148 myFieldDataType(GEOM::FDT_Double),
150 myFieldStepRangeMin(0),
151 myFieldStepRangeMax(0)
153 //rnv: Commented to avoid bug with local selection
154 //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
156 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
157 myPrevDisplayMode = 0;
159 myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
161 myTopLevel = Standard_False;
162 Graphic3d_MaterialAspect aMatAspect;
163 if ( !HasMaterial() ) {
164 aMatAspect.SetAmbient( 0.5 );
165 aMatAspect.SetDiffuse( 0.5 );
166 aMatAspect.SetEmissive( 0.5 );
167 aMatAspect.SetShininess(0.5 );
168 aMatAspect.SetSpecular( 0.5 );
170 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
171 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
175 GEOM_AISShape::~GEOM_AISShape()
179 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io)
184 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO()
186 Handle(SALOME_InteractiveObject) IO;
187 if ( !GetOwner().IsNull() )
188 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
192 Standard_Boolean GEOM_AISShape::hasIO()
194 return !getIO().IsNull();
197 void GEOM_AISShape::setName(const Standard_CString aName)
201 Handle(SALOME_InteractiveObject) IO = getIO();
206 Standard_CString GEOM_AISShape::getName()
208 return myName.ToCString();
211 Standard_Boolean GEOM_AISShape::AcceptDisplayMode(const Standard_Integer theMode) const
213 return theMode >= Wireframe && theMode <= CustomHighlight;
216 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
217 const Handle(Prs3d_Presentation)& aPrs,
218 const Standard_Integer aMode)
220 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
222 Handle(AIS_InteractiveContext) anIC = GetContext();
223 // AKL: use old behavior to avoid keeping object's wireframe
224 // if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos')
225 // calling popup menu over(!) the shape in OCC viewer.
226 anIC->SetToHilightSelected( false );
228 bool anIsField = !myFieldStepData.isEmpty();
229 bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
230 bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
232 if (isShowVertices())
233 myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
235 // StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
236 bool isTopLev = isTopLevel() && switchTopLevel();
239 // Begin 0023271: [CEA 1823] Deflection Coefficient not taken into account in wireframe
241 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
243 // After this call if type of deflection is relative
244 // computed deflection coefficient is stored as absolute.
245 Prs3d::GetDeflection (myshape, myDrawer);
248 case CustomHighlight:
251 SetColor(topLevelColor());
252 Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
253 anAspect->SetColor( topLevelColor() );
254 Attributes()->SetWireAspect( anAspect );
256 if( !isTopLev && anIsColorField && myFieldDimension == 1 )
257 drawField( aPrs, false, aMode == CustomHighlight );
259 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
264 shadingMode(aPresentationManager, aPrs, aMode);
267 case ShadingWithEdges:
269 myDrawer->SetFaceBoundaryDraw( Standard_True );
270 shadingMode(aPresentationManager, aPrs, Shading);
271 if( anIsColorField && myFieldDimension == 1 ) {
272 myDrawer->SetFaceBoundaryDraw( Standard_False );
279 shadingMode(aPresentationManager, aPrs, Shading);
285 const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
286 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
287 for ( ; Exp.More(); Exp.Next() ) {
288 TopoDS_Vertex aV1, aV2;
289 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
291 // draw curve direction (issue 0021087)
292 anEdgeE.Orientation( TopAbs_FORWARD );
294 if ( anEdgeE.IsNull() ) continue;
296 TopExp::Vertices(anEdgeE, aV1, aV2);
297 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
298 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
302 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
304 if ( C.IsNull() ) continue;
306 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
307 C->D1(lp, aP2, aDirVec);
309 C->D1(fp, aP1, aDirVec);
313 GeomAdaptor_Curve aAdC;
314 aAdC.Load(C, fp, lp);
315 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
317 if (aDist > gp::Resolution()) {
319 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
324 Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
329 // draw color field on vertices
330 if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
335 drawField( aPrs, true );
340 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
343 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
345 myShadingColor = aCol;
348 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
350 myEdgesInShadingColor = aCol;
353 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
358 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
359 const Standard_Boolean aHighlight )
361 Handle(AIS_InteractiveObject) anObj = this;
362 Handle(AIS_InteractiveContext) anIC = GetContext();
364 #if OCC_VERSION_LARGE <= 0x07030000
365 || !anIC->HasOpenedContext()
370 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
371 anIC->SetAutomaticHilight( false );
373 anIC->ClearSelected( false );
376 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
378 // Get entity owners for all activated selection modes
379 getEntityOwners( anObj, anIC, anAllMap );
381 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
382 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
385 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
386 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
389 anIC->SetAutomaticHilight( isAutoHilight );
390 anIC->HilightSelected( false );
393 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
395 myDisplayVectors = isDisplayed;
398 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
400 myDisplayVertices = isDisplayed;
403 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
405 myDisplayName = isDisplayed;
408 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
409 const Handle(Prs3d_Presentation)& aPrs,
410 const Standard_Integer aMode)
412 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
414 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
415 aMatAspect.SetTransparency(Transparency());
416 Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
417 Graphic3d_MaterialAspect currentBackMaterial = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
418 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
419 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial );
421 if( isTopLevel() && switchTopLevel() )
422 myDrawer->ShadingAspect()->SetColor( topLevelColor() );
424 if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
425 myDrawer->ShadingAspect()->SetColor(myShadingColor);
427 myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
430 bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
431 if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
437 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
438 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
439 SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
443 Standard_Boolean GEOM_AISShape::isTopLevel()
448 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
452 myPrevDisplayMode = DisplayMode();
454 switch(topLevelDisplayMode()) {
455 case TopWireFrame : dm = Wireframe; break;
456 case TopShading : dm = Shading; break;
457 case TopShadingWithEdges : dm = ShadingWithEdges; break;
458 default : dm = myPrevDisplayMode; break;
463 SetDisplayMode(myPrevDisplayMode);
468 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
470 myPrevDisplayMode = mode;
473 Quantity_Color GEOM_AISShape::topLevelColor()
475 return myTopLevelColor;
478 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
483 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
488 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
493 Standard_Boolean GEOM_AISShape::switchTopLevel()
495 return myTopLevelDm != TopShowAdditionalWActor;
498 Standard_Boolean GEOM_AISShape::toActivate()
500 return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
503 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
504 const int theFieldDimension,
505 const QList<QVariant>& theFieldStepData,
506 const TCollection_AsciiString& theFieldStepName,
507 const double theFieldStepRangeMin,
508 const double theFieldStepRangeMax )
510 myFieldDataType = theFieldDataType;
511 myFieldDimension = theFieldDimension;
512 myFieldStepData = theFieldStepData;
513 myFieldStepName = theFieldStepName;
514 myFieldStepRangeMin = theFieldStepRangeMin;
515 myFieldStepRangeMax = theFieldStepRangeMax;
518 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
519 int& theFieldDimension,
520 QList<QVariant>& theFieldStepData,
521 TCollection_AsciiString& theFieldStepName,
522 double& theFieldStepRangeMin,
523 double& theFieldStepRangeMax ) const
525 theFieldDataType = myFieldDataType;
526 theFieldDimension = myFieldDimension;
527 theFieldStepData = myFieldStepData;
528 theFieldStepName = myFieldStepName;
529 theFieldStepRangeMin = myFieldStepRangeMin;
530 theFieldStepRangeMax = myFieldStepRangeMax;
533 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
534 const bool theIsString,
535 const bool theIsHighlight )
537 if( myFieldStepData.isEmpty() )
540 QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
542 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
543 switch( myFieldDimension )
545 case 0: aShapeType = TopAbs_VERTEX; break;
546 case 1: aShapeType = TopAbs_EDGE; break;
547 case 2: aShapeType = TopAbs_FACE; break;
548 case 3: aShapeType = TopAbs_SOLID; break;
549 case -1: aShapeType = TopAbs_VERTEX; break;
552 TopTools_IndexedMapOfShape aShapeMap;
553 TopExp::MapShapes( myshape, aShapeMap );
555 TColStd_IndexedMapOfInteger anIndexMap;
557 TopExp_Explorer anExp;
558 for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
560 TopoDS_Shape aSubShape = anExp.Current();
561 if( !aSubShape.IsNull() )
563 Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
564 if( anIndexMap.Contains( aSubShapeIndex ) )
567 anIndexMap.Add( aSubShapeIndex );
569 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
573 if( aFieldStepDataIter.hasNext() )
575 const QVariant& aVariant = aFieldStepDataIter.next();
577 aString = aVariant.toString();
579 aQColor = aVariant.value<QColor>();
587 if( computeMassCenter( aSubShape, aCenter ) )
589 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
591 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
592 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
593 anAspectText3d->SetColor( myLabelColor );
594 aGroup->SetPrimitivesAspect( anAspectText3d );
596 aGroup->Text( aString.toUtf8().constData(), aVertex, 14 );
601 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
602 SetCustomColor( aSubShape, aColor );
603 if( myFieldDimension == 0 )
605 TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
606 if( !aVertexShape.IsNull() )
608 gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
610 Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
611 anAspectMarker3d->SetColor( aColor );
612 anAspectMarker3d->SetType( Aspect_TOM_POINT );
613 anAspectMarker3d->SetScale( 10.0 );
614 aGroup->SetPrimitivesAspect( anAspectMarker3d );
616 Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
617 anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
619 aGroup->AddPrimitiveArray( anArray );
622 else if( myFieldDimension == 1 )
624 myDrawer->WireAspect()->SetColor( aColor );
626 myDrawer->WireAspect()->SetWidth( myOwnWidth );
628 myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
630 StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
633 else if( myFieldDimension == 2 ||
634 myFieldDimension == 3 ||
635 myFieldDimension == -1 )
637 //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
638 //anAspect->SetColor( aColor );
639 //myDrawer->SetShadingAspect( anAspect );
640 //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
646 SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
647 thePrs, AIS_Shaded );
650 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
652 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
654 gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
655 gp_Pnt aCenter = anAx3.Location();
657 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
659 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
660 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
661 anAspectText3d->SetColor( myLabelColor );
662 aGroup->SetPrimitivesAspect( anAspectText3d );
664 const char* aName = getIO()->getName();
665 aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
668 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
671 theCenter.SetCoord( 0,0,0 );
672 Standard_Integer aNbPoints = 0;
674 if ( theShape.ShapeType() == TopAbs_EDGE )
677 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
678 if ( !curve.IsNull() )
680 theCenter = curve->Value( 0.5 * ( f + l ));
684 else if ( theShape.ShapeType() == TopAbs_FACE )
686 const TopoDS_Face& F = TopoDS::Face( theShape );
687 BRepAdaptor_Surface surface( F );
690 Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
691 if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
695 const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
696 const Poly_Array1OfTriangle& trias = triangulation->Triangles();
697 Standard_Integer n1,n2,n3;
698 for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
700 trias( iT ).Get( n1,n2,n3 );
701 const gp_Pnt2d& uv1 = uvArray( n1 );
702 const gp_Pnt2d& uv2 = uvArray( n2 );
703 const gp_Pnt2d& uv3 = uvArray( n3 );
704 double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
705 ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
706 C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
709 if ( A > std::numeric_limits<double>::min() )
712 theCenter = surface.Value( C.X(), C.Y() );
716 if ( aNbPoints == 0 )
718 theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
719 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
724 if ( aNbPoints == 0 )
726 TopExp_Explorer anExp;
727 for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
729 TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
730 if( !aVertex.IsNull() )
732 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
733 theCenter.ChangeCoord() += aPnt.XYZ();
740 theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;