#include <Graphic3d_AspectMarker3d.hxx>
#include <Graphic3d_GraphicDriver.hxx>
-// S3603
-#include <Aspect_GenericColorMap.hxx>
-#include <Aspect_TypeMap.hxx>
-#include <Aspect_WidthMap.hxx>
-#include <Aspect_MarkMap.hxx>
-#include <Aspect_FontMap.hxx>
-#include <Aspect.hxx>
-
#define V3d_FLAG_COMPUTATION 0x00000004
// Perspective
//purpose :
//=============================================================================
V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
- MyProjModel(V3d_TPM_SCREEN),
MyViewer(VM.operator->()),
MyActiveLights(),
MyViewContext (),
myActiveLightsIterator(),
SwitchSetFront(Standard_False),
- MyTrsf (1, 4, 1, 4),
- myAutoZFitIsOn (Standard_True),
- myAutoZFitScaleFactor (1.0)
+ MyTrsf (1, 4, 1, 4)
{
myImmediateUpdate = Standard_False;
MyView = new Visual3d_View(MyViewer->Viewer());
//purpose :
//=============================================================================
V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theView) :
- MyProjModel(V3d_TPM_SCREEN),
MyViewer(theVM.operator->()),
MyActiveLights(),
MyViewContext (),
MyViewContext = aFromView->Context() ;
SetCamera (new Graphic3d_Camera (theView->Camera()));
- myAutoZFitIsOn = theView->AutoZFitMode();
- myAutoZFitScaleFactor = theView->AutoZFitScaleFactor();
+ View()->SetAutoZFitMode (theView->View()->AutoZFitMode(), theView->View()->AutoZFitScaleFactor());
MyBackground = aFromView->Background() ;
MyGradientBackground = aFromView->GradientBackground();
//=============================================================================
void V3d_View::Update() const
{
- if( MyView->IsDefined() ) MyView->Update() ;
+ if( MyView->IsDefined() ) MyView->Update (Aspect_TOU_ASAP) ;
}
//=============================================================================
}
}
+//=============================================================================
+//function : AutoZFit
+//purpose :
+//=============================================================================
+void V3d_View::AutoZFit()
+{
+ View()->AutoZFit();
+}
+
+//=============================================================================
+//function : ZFitAll
+//purpose :
+//=============================================================================
+void V3d_View::ZFitAll (const Standard_Real theScaleFactor)
+{
+ View()->ZFitAll (theScaleFactor);
+}
+
//=============================================================================
//function : Redraw
//purpose :
myCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
myCamera->SetUp (gp_Dir (xu, yu, zu));
- AutoZFit();
+ View()->AutoZFit();
SwitchSetFront = !SwitchSetFront;
myCamera->Transform (aTrsf);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->Transform (aTrsf);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
myCamera->Transform (aRotation);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
myCamera->Transform (aRotation);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->Transform (aTrsf);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
myCamera->Transform (aRotation);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
myCamera->Transform (aTrsf);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
-//=============================================================================
-//function : SetAutoZFitMode
-//purpose :
-//=============================================================================
-void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn, const Standard_Real theScaleFactor)
-{
- Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
- myAutoZFitScaleFactor = theScaleFactor;
- myAutoZFitIsOn = theIsOn;
-}
-
-//=============================================================================
-//function : AutoZFitMode
-//purpose :
-//=============================================================================
-Standard_Boolean V3d_View::AutoZFitMode() const
-{
- return myAutoZFitIsOn;
-}
-
-//=============================================================================
-//function : AutoZFitScaleFactor
-//purpose :
-//=============================================================================
-Standard_Real V3d_View::AutoZFitScaleFactor () const
-{
- return myAutoZFitScaleFactor;
-}
-
//=============================================================================
//function : SetEye
//purpose :
myCamera->SetEye (gp_Pnt (X, Y, Z));
SetTwist (aTwistBefore);
- AutoZFit();
+ View()->AutoZFit();
SetImmediateUpdate (wasUpdateEnabled);
myCamera->SetCenter (aCameraCenter);
}
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
- if (MyProjModel == V3d_TPM_SCREEN)
- {
- SetTwist(aTwistBefore);
- }
+ SetTwist(aTwistBefore);
- AutoZFit();
+ View()->AutoZFit();
SetImmediateUpdate (wasUpdateEnabled);
Panning (aPanX, aPanY);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
SetTwist (aTwistBefore);
- AutoZFit();
+ View()->AutoZFit();
SetImmediateUpdate (wasUpdateEnabled);
myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->CopyMappingData (aDefaultCamera);
myCamera->CopyOrientationData (aDefaultCamera);
- AutoZFit();
+ View()->AutoZFit();
}
SwitchSetFront = Standard_False;
myCamera->SetScale (myCamera->Aspect() >= 1.0 ? theSize / myCamera->Aspect() : theSize);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->SetEye (myCamStartOpEye);
myCamera->SetCenter (myCamStartOpCenter);
myCamera->SetScale (myCamera->Scale() / Coef);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
myCamera->SetScale (myCamera->Scale() / Coef);
}
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
myCamera->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
- AutoZFit();
+ View()->AutoZFit();
}
//=============================================================================
return;
}
- AutoZFit();
+ View()->AutoZFit();
if (myImmediateUpdate || theToUpdate)
{
}
}
-//=============================================================================
-//function : AutoZFit
-//purpose :
-//=============================================================================
-void V3d_View::AutoZFit()
-{
- if (!AutoZFitMode())
- {
- return;
- }
-
- ZFitAll (myAutoZFitScaleFactor);
-}
-
-//=============================================================================
-//function : ZFitAll
-//purpose :
-//=============================================================================
-void V3d_View::ZFitAll (const Standard_Real theScaleFactor)
-{
- Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
-
- // Method changes ZNear and ZFar planes of camera so as to fit the graphical structures
- // by their real boundaries (computed ignoring infinite flag) into the viewing volume.
- // In addition to the graphical boundaries, the usual min max used for fitting perspective
- // camera. To avoid numeric errors for perspective camera the negative ZNear values are
- // fixed using tolerance distance, relative to boundaries size. The tolerance distance
- // should be computed using information on boundaries of primary application actors,
- // (e.g. representing the displayed model) - to ensure that they are not unreasonably clipped.
-
- Standard_Real aMinMax[6]; // applicative min max boundaries
- View()->MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2],
- aMinMax[3], aMinMax[4], aMinMax[5],
- Standard_False);
-
- Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag).
- View()->MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
- aGraphicBB[3], aGraphicBB[4], aGraphicBB[5],
- Standard_True);
-
- // Check if anything can be adjusted
- Standard_Real aLim = (ShortRealLast() - 1.0);
- if (Abs (aGraphicBB[0]) > aLim || Abs (aGraphicBB[1]) > aLim || Abs (aGraphicBB[2]) > aLim ||
- Abs (aGraphicBB[3]) > aLim || Abs (aGraphicBB[4]) > aLim || Abs (aGraphicBB[5]) > aLim)
- {
- SetZSize (0.0);
- ImmediateUpdate();
- return;
- }
-
- // Measure depth of boundary points from camera eye
- gp_Pnt aPntsToMeasure[16] =
- {
- gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[2]),
- gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[5]),
- gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[2]),
- gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[5]),
- gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[2]),
- gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[5]),
- gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[2]),
- gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[5]),
-
- gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2]),
- gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[5]),
- gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[2]),
- gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[5]),
- gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[2]),
- gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[5]),
- gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[2]),
- gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[5])
- };
-
- // Camera eye plane
- gp_Dir aCamDir = myCamera->Direction();
- gp_Pnt aCamEye = myCamera->Eye();
- gp_Pln aCamPln (aCamEye, aCamDir);
-
- Standard_Real aModelMinDist = RealLast();
- Standard_Real aModelMaxDist = RealFirst();
- Standard_Real aGraphicMinDist = RealLast();
- Standard_Real aGraphicMaxDist = RealFirst();
-
- const gp_XYZ& anAxialScale = myCamera->AxialScale();
-
- // Get minimum and maximum distances to the eye plane
- for (Standard_Integer aPntIt = 0; aPntIt < 16; ++aPntIt)
- {
- gp_Pnt aMeasurePnt = aPntsToMeasure[aPntIt];
-
- if (Abs (aMeasurePnt.X()) > aLim || Abs (aMeasurePnt.Y()) > aLim || Abs (aMeasurePnt.Z()) > aLim)
- {
- continue;
- }
-
- aMeasurePnt = gp_Pnt (aMeasurePnt.X() * anAxialScale.X(),
- aMeasurePnt.Y() * anAxialScale.Y(),
- aMeasurePnt.Z() * anAxialScale.Z());
-
- Standard_Real aDistance = aCamPln.Distance (aMeasurePnt);
-
- // Check if the camera is intruded into the scene
- if (aCamDir.IsOpposite (gp_Vec (aCamEye, aMeasurePnt), M_PI * 0.5))
- {
- aDistance *= -1;
- }
-
- Standard_Real& aChangeMinDist = aPntIt >= 8 ? aGraphicMinDist : aModelMinDist;
- Standard_Real& aChangeMaxDist = aPntIt >= 8 ? aGraphicMaxDist : aModelMaxDist;
- aChangeMinDist = Min (aDistance, aChangeMinDist);
- aChangeMaxDist = Max (aDistance, aChangeMaxDist);
- }
-
- // Compute depth of bounding box center
- Standard_Real aMidDepth = (aGraphicMinDist + aGraphicMaxDist) * 0.5;
- Standard_Real aHalfDepth = (aGraphicMaxDist - aGraphicMinDist) * 0.5;
-
- // ShortReal precision factor used to add meaningful tolerance to
- // ZNear, ZFar values in order to avoid equality after type conversion
- // to ShortReal matrices type.
- const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1);
-
- // Compute enlarged or shrank near and far z ranges
- Standard_Real aZNear = aMidDepth - aHalfDepth * theScaleFactor;
- Standard_Real aZFar = aMidDepth + aHalfDepth * theScaleFactor;
- aZNear -= Abs (aZNear) * aPrecision;
- aZFar += Abs (aZFar) * aPrecision;
-
- if (!myCamera->IsOrthographic())
- {
- if (aZFar >= aPrecision)
- {
- // To avoid numeric errors... (See comments in the beginning of the method).
- // Choose between model distance and graphical distance, as the model boundaries
- // might be infinite if all structures have infinite flag.
- const Standard_Real aGraphicDepth = aGraphicMaxDist >= aGraphicMinDist
- ? aGraphicMaxDist - aGraphicMinDist : RealLast();
-
- const Standard_Real aModelDepth = aModelMaxDist >= aModelMinDist
- ? aModelMaxDist - aModelMinDist : RealLast();
-
- const Standard_Real aMinDepth = Min (aModelDepth, aGraphicDepth);
- const Standard_Real aZTolerance =
- Max (Abs (aMinDepth) * aPrecision, aPrecision);
-
- if (aZNear < aZTolerance)
- {
- aZNear = aZTolerance;
- }
- }
- else // aZFar < aPrecision - Invalid case when both ZNear and ZFar are negative
- {
- aZNear = aPrecision;
- aZFar = aPrecision * 2.0;
- }
- }
-
- // If range is too small
- if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
- {
- aZFar = aZNear + Abs (aZFar) * aPrecision;
- }
-
- myCamera->SetZRange (aZNear, aZFar);
-
- ImmediateUpdate();
-}
-
//=============================================================================
//function : DepthFitAll
//purpose :
Translate (myCamera, aPanVec.X(), -aPanVec.Y());
Scale (myCamera, aUSize, aVSize);
- AutoZFit();
+ View()->AutoZFit();
}
else
{
gp_Pnt aPoint = myCamera->Project (gp_Pnt (X, Y, Z));
Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
- Yp = RealToInt ((aPoint.Y() + 1) * 0.5 * aHeight);
+ Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
}
//=======================================================================
myCamera->SetScale (myCamera->Scale() / aCoef);
Translate (myCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
- AutoZFit();
+ View()->AutoZFit();
SetImmediateUpdate (wasUpdateEnabled);
myCamera->SetAspect (aWinAspect);
Translate (myCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5);
Scale (myCamera, aFitSizeU, aFitSizeV);
- AutoZFit();
+ View()->AutoZFit();
ImmediateUpdate();
}
const Standard_Boolean toAutoUpdate = myImmediateUpdate;
myImmediateUpdate = Standard_False;
- AutoZFit();
+ View()->AutoZFit();
myImmediateUpdate = toAutoUpdate;
if (theToKeepAspect)
gp_Trsf aCenterTrsf;
aCenterTrsf.SetTranslation (theCamera->Center(), aNewCenter);
theCamera->Transform (aCenterTrsf);
- theCamera->SetDistance (Max (aMatchDistance[5] + aMatchDistance[4], Precision::Confusion()));
+ theCamera->SetDistance (aMatchDistance[5] + aMatchDistance[4]);
// Bounding box collapses to a point or thin line going in depth of the screen
if (aViewSizeXv < theResolution && aViewSizeYv < theResolution)
theCamera->Transform (aPanTrsf);
}
+
+// =======================================================================
+// function : IsCullingEnabled
+// purpose :
+// =======================================================================
+Standard_Boolean V3d_View::IsCullingEnabled() const
+{
+ Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView();
+ return aView->IsCullingEnabled;
+}
+
+// =======================================================================
+// function : SetFrustumCulling
+// purpose :
+// =======================================================================
+void V3d_View::SetFrustumCulling (const Standard_Boolean theToClip)
+{
+ Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView();
+ aView->IsCullingEnabled = theToClip;
+}