]> OCCT Git - occt-copy.git/commitdiff
0002618: Visualization - choose better center of gravity for camera rotation operations
authorduv <duv@opencascade.com>
Tue, 10 Mar 2015 12:15:07 +0000 (15:15 +0300)
committerduv <duv@opencascade.com>
Fri, 25 Mar 2016 09:44:57 +0000 (12:44 +0300)
Gravity point set to camera center.

src/V3d/V3d_View.cxx

index f2c04933fa70d4519021d934e486e6967c20a99d..151d4d8f79e3e2fc9452f0b0eeffc42de6ea7185 100644 (file)
@@ -2167,107 +2167,9 @@ void V3d_View::Gravity (Standard_Real& theX,
                         Standard_Real& theY,
                         Standard_Real& theZ) const
 {
-  Graphic3d_MapOfStructure aSetOfStructures;
-  myView->DisplayedStructures (aSetOfStructures);
-
-  Standard_Boolean hasSelection = Standard_False;
-  for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
-       aStructIter.More(); aStructIter.Next())
-  {
-    if (aStructIter.Key()->IsHighlighted()
-     && aStructIter.Key()->IsVisible())
-    {
-      hasSelection = Standard_True;
-      break;
-    }
-  }
-
-  Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
-  Standard_Integer aNbPoints = 0;
-  gp_XYZ aResult (0.0, 0.0, 0.0);
-  for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
-       aStructIter.More(); aStructIter.Next())
-  {
-    const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
-    if (!aStruct->IsVisible()
-      || aStruct->IsInfinite()
-      || (hasSelection && !aStruct->IsHighlighted()))
-    {
-      continue;
-    }
-
-    const Graphic3d_BndBox4f& aBox = aStruct->CStructure()->BoundingBox();
-    if (!aBox.IsValid())
-    {
-      continue;
-    }
-
-    // skip transformation-persistent objects
-    if (aStruct->TransformPersistence().Flags != Graphic3d_TMF_None)
-    {
-      continue;
-    }
-
-    // use camera projection to find gravity point
-    Xmin = (Standard_Real )aBox.CornerMin().x();
-    Ymin = (Standard_Real )aBox.CornerMin().y();
-    Zmin = (Standard_Real )aBox.CornerMin().z();
-    Xmax = (Standard_Real )aBox.CornerMax().x();
-    Ymax = (Standard_Real )aBox.CornerMax().y();
-    Zmax = (Standard_Real )aBox.CornerMax().z();
-    gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
-    {
-      gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
-      gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
-      gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
-      gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
-    };
-
-    for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
-    {
-      const gp_Pnt& aBndPnt    = aPnts[aPntIt];
-      const gp_Pnt  aProjected = Camera()->Project (aBndPnt);
-      if (Abs (aProjected.X()) <= 1.0
-       && Abs (aProjected.Y()) <= 1.0)
-      {
-        aResult += aBndPnt.XYZ();
-        ++aNbPoints;
-      }
-    }
-  }
-
-  if (aNbPoints == 0)
-  {
-    // fallback - just use bounding box of entire scene
-    Bnd_Box aBox = myView->MinMaxValues (Standard_True);
-    if (!aBox.IsVoid())
-    {
-      aBox.Get (Xmin, Ymin, Zmin,
-                Xmax, Ymax, Zmax);
-      gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
-      {
-        gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
-        gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
-        gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
-        gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
-      };
-
-      for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
-      {
-        const gp_Pnt& aBndPnt = aPnts[aPntIt];
-        aResult += aBndPnt.XYZ();
-        ++aNbPoints;
-      }
-    }
-  }
-
-  if (aNbPoints > 0)
-  {
-    aResult /= aNbPoints;
-  }
-  theX = aResult.X();
-  theY = aResult.Y();
-  theZ = aResult.Z();
+  theX = myCamera->Center().X();
+  theY = myCamera->Center().Y();
+  theZ = myCamera->Center().Z();
 }
 
 //=======================================================================