Graphic3d_ListOfShortReal.hxx
Graphic3d_LOD.hxx
Graphic3d_LOD.cxx
+Graphic3d_LODSelector.hxx
+Graphic3d_LODDistanceSelector.hxx
+Graphic3d_LODDistanceSelector.cxx
+Graphic3d_LODManager.hxx
+Graphic3d_LODManager.cxx
Graphic3d_MapIteratorOfMapOfStructure.hxx
Graphic3d_MapOfObject.hxx
Graphic3d_MapOfStructure.hxx
class Graphic3d_GraphicDriver;
class Graphic3d_StructureManager;
class Graphic3d_LOD;
+class Graphic3d_LODManager;
//! Low-level graphic structure interface
class Graphic3d_CStructure : public Standard_Transient
virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) = 0;
//! Create new LOD within this structure
- virtual Handle(Graphic3d_LOD) NewLOD() = 0;
+ virtual Handle(Graphic3d_LOD) NewLOD (const Handle(Graphic3d_Structure)& theStruct) = 0;
//! Remove group from this structure
virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) = 0;
Graphic3d_SequenceOfGroup myGroups;
Graphic3d_BndBox4f myBndBox;
Graphic3d_SequenceOfHClipPlane myClipPlanes;
+ Handle(Graphic3d_LODManager) myLODManager;
public:
// function : SetRange
// purpose :
//=======================================================================
-void Graphic3d_LOD::SetRange (const Standard_Real /*theFrom*/, const Standard_Real /*theTo*/)
+void Graphic3d_LOD::SetRange (const Standard_Real theFrom, const Standard_Real theTo)
{
- return;
-}
-
-//=======================================================================
-// function : NewGroup
-// purpose :
-//=======================================================================
-Handle(Graphic3d_Group) Graphic3d_LOD::NewGroup (const Handle(Graphic3d_Structure)& /*theParentStruct*/)
-{
- return NULL;
-}
-
-//=======================================================================
-// function : ComputeMetrics
-// purpose :
-//=======================================================================
-Standard_Real Graphic3d_LOD::ComputeMetrics (const Handle(Graphic3d_Camera)& theCamera,
- const Handle(Graphic3d_CStructure)& theParentStruct) const
-{
- if (theParentStruct.IsNull())
- return std::numeric_limits<Standard_Real>::max();
+ Standard_ASSERT_RAISE (theFrom < theTo,
+ "The upper boundary of the interval must be greater than lower one!");
- Graphic3d_BndBox4f aBndBox = theParentStruct->BoundingBox();
- const Graphic3d_Vec4 aCenter = aBndBox.Center();
- const gp_Pnt aGpCenter = gp_Pnt (aCenter.x(), aCenter.y(), aCenter.z());
- return (theCamera->Eye().Distance (aGpCenter)) / theCamera->Scale();
+ myRange = Graphic3d_RangeOfLOD (theFrom, theTo);
}
#include <Standard_Macro.hxx>
#include <Standard_Transient.hxx>
+struct Graphic3d_RangeOfLOD
+{
+public:
+ Graphic3d_RangeOfLOD (const Standard_Real theFrom, const Standard_Real theTo)
+ : myTo (theTo),
+ myFrom (theFrom)
+ {
+ Standard_ASSERT_RAISE (theFrom < theTo,
+ "The upper boundary of the interval must be greater than lower one!");
+ }
+
+ Standard_Boolean IsIn (const Standard_Real theVal) const
+ {
+ return (myFrom < theVal) && (theVal < myTo);
+ }
+
+ Standard_Boolean IsLess (const Standard_Real theVal) const
+ {
+ return myFrom < theVal;
+ }
+
+ Standard_Boolean IsGreater (const Standard_Real theVal) const
+ {
+ return myTo < theVal;
+ }
+
+ bool operator < (const Graphic3d_RangeOfLOD& theOther) const
+ {
+ return myFrom < theOther.myFrom;
+ }
+
+private:
+ Standard_Real myFrom;
+ Standard_Real myTo;
+};
+
class Graphic3d_LOD : public Standard_Transient
{
public:
- Standard_EXPORT Graphic3d_LOD() {};
Standard_EXPORT virtual ~Graphic3d_LOD();
- Standard_EXPORT virtual void SetRange (const Standard_Real theFrom, const Standard_Real theTo);
- Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theParentStruct);
+ Standard_EXPORT void SetRange (const Standard_Real theFrom, const Standard_Real theTo);
+
+ Standard_EXPORT const Graphic3d_RangeOfLOD& GetRange() const
+ {
+ return myRange;
+ }
- Standard_EXPORT Standard_Real ComputeMetrics (const Handle(Graphic3d_Camera)& theCamera,
- const Handle(Graphic3d_CStructure)& theParentStruct) const;
+ Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& /*theParentStruct*/)
+ {
+ return NULL;
+ };
+
+ const Graphic3d_SequenceOfGroup& GetDrawGroups() const
+ {
+ return myGroups;
+ }
DEFINE_STANDARD_RTTI (Graphic3d_LOD, Standard_Transient)
+protected:
+ Standard_EXPORT Graphic3d_LOD() : myRange (-DBL_MAX, DBL_MAX) {};
+
protected:
Graphic3d_SequenceOfGroup myGroups;
+ Graphic3d_RangeOfLOD myRange;
};
DEFINE_STANDARD_HANDLE (Graphic3d_LOD, Standard_Transient)
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Graphic3d_BndBox4f.hxx>
+#include <Graphic3d_Camera.hxx>
+#include <Graphic3d_CStructure.hxx>
+#include <Graphic3d_LODDistanceSelector.hxx>
+
+//=======================================================================
+// function : ComputeMetric
+// purpose :
+//=======================================================================
+Standard_Real Graphic3d_LODDistanceSelector::ComputeMetric (const Handle(Graphic3d_CStructure)& theParentStructure,
+ const Handle(Graphic3d_Camera)& theCamera)
+{
+ const Graphic3d_BndBox4f& aBndBox = theParentStructure->BoundingBox();
+ const Graphic3d_Vec4 aCenter = aBndBox.Center();
+ const gp_Pnt aGpCenter = gp_Pnt (aCenter.x(), aCenter.y(), aCenter.z());
+ return (theCamera->Eye().Distance (aGpCenter)) / theCamera->Scale();
+}
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Graphic3d_LODDistanceSelector_Header
+#define _Graphic3d_LODDistanceSelector_Header
+
+#include <Graphic3d_LODSelector.hxx>
+
+class Graphic3d_CStructure;
+class Graphic3d_Camera;
+
+class Graphic3d_LODDistanceSelector : public Graphic3d_LODSelector
+{
+public:
+ Standard_EXPORT Graphic3d_LODDistanceSelector() {};
+ Standard_EXPORT virtual ~Graphic3d_LODDistanceSelector() {};
+
+ Standard_EXPORT virtual Standard_Real ComputeMetric (const Handle(Graphic3d_CStructure)& theParentStructure,
+ const Handle(Graphic3d_Camera)& theCamera) Standard_OVERRIDE;
+
+ DEFINE_STANDARD_RTTI (Graphic3d_LODDistanceSelector, Graphic3d_LODSelector)
+};
+
+DEFINE_STANDARD_HANDLE (Graphic3d_LODDistanceSelector, Graphic3d_LODSelector)
+
+#endif // _Graphic3d_LODDistanceSelector_Header
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Graphic3d_LOD.hxx>
+#include <Graphic3d_LODManager.hxx>
+
+//=======================================================================
+// function : Creation
+// purpose :
+//=======================================================================
+Graphic3d_LODManager::Graphic3d_LODManager (const Handle(Graphic3d_Structure)& theParentStructure)
+ : myCurrentLODIdx (-1),
+ mySelector (new Graphic3d_LODDistanceSelector())
+{
+ myStructure = theParentStructure.operator->();
+}
+
+//=======================================================================
+// function : GetCurrentLODIdx
+// purpose :
+//=======================================================================
+Standard_Integer Graphic3d_LODManager::GetCurrentLODIdx (const Handle(Graphic3d_Camera)& theCamera)
+{
+ if (theCamera->WorldViewProjState() == myPrevCameraState && myCurrentLODIdx != -1)
+ return myCurrentLODIdx;
+
+ myPrevCameraState = theCamera->WorldViewProjState();
+ const Standard_Real aMetric = mySelector->ComputeMetric (myStructure->CStructure(), theCamera);
+ if (myLODs.Value (0)->GetRange().IsLess (aMetric))
+ return -1;
+
+ for (Standard_Integer aLodIdx = 1; aLodIdx < myLODs.Size(); ++aLodIdx)
+ {
+ if (myLODs.Value (aLodIdx)->GetRange().IsIn (aMetric))
+ {
+ myCurrentLODIdx = aLodIdx;
+ break;
+ }
+ }
+
+ if (myLODs.Value (myLODs.Size() - 1)->GetRange().IsGreater (aMetric))
+ myCurrentLODIdx = myLODs.Size() - 1;
+
+ return myCurrentLODIdx;
+}
+
+//=======================================================================
+// function : SetRange
+// purpose :
+//=======================================================================
+void Graphic3d_LODManager::SetRange (const Standard_Integer theLodIdx,
+ const Standard_Real theFrom,
+ const Standard_Real theTo)
+{
+ myLODs.ChangeValue (theLodIdx)->SetRange (theFrom, theTo);
+}
+
+//=======================================================================
+// function : GetCurrentGroups
+// purpose :
+//=======================================================================
+ const Graphic3d_SequenceOfGroup& Graphic3d_LODManager::GetCurrentGroups() const
+ {
+ return myLODs.Value (myCurrentLODIdx)->GetDrawGroups();
+ }
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Graphic3d_LODManager_Header
+#define _Graphic3d_LODManager_Header
+
+#include <Graphic3d_CStructure.hxx>
+#include <Graphic3d_Camera.hxx>
+#include <Graphic3d_LOD.hxx>
+#include <Graphic3d_LODSelector.hxx>
+#include <Graphic3d_LODDistanceSelector.hxx>
+#include <Graphic3d_SequenceOfGroup.hxx>
+#include <Graphic3d_StructurePtr.hxx>
+#include <NCollection_Vector.hxx>
+#include <Standard.hxx>
+#include <Standard_Handle.hxx>
+
+class Graphic3d_LODManager : public Standard_Transient
+{
+public:
+
+ Standard_EXPORT virtual ~Graphic3d_LODManager() {};
+
+ Standard_EXPORT void SetSelector (const Handle(Graphic3d_LODSelector)& theSelector)
+ {
+ mySelector = theSelector;
+ }
+
+ Standard_EXPORT inline Standard_Integer NbOfDetailLevels() const
+ {
+ return myLODs.Size();
+ }
+
+ Standard_EXPORT void SetRange (const Standard_Integer theLodIdx,
+ const Standard_Real theFrom,
+ const Standard_Real theTo);
+
+ Standard_EXPORT Standard_Integer GetCurrentLODIdx (const Handle(Graphic3d_Camera)& theCamera);
+
+ Standard_EXPORT const Graphic3d_SequenceOfGroup& GetCurrentGroups() const;
+
+ Standard_EXPORT virtual Handle(Graphic3d_LOD)& AddNewLOD() = 0;
+
+ DEFINE_STANDARD_RTTI (Graphic3d_LODManager, Standard_Transient)
+
+protected:
+ Standard_EXPORT Graphic3d_LODManager (const Handle(Graphic3d_Structure)& theParentStructure);
+
+ Standard_EXPORT virtual void sortLODs() {};
+
+protected:
+ NCollection_Vector<Handle(Graphic3d_LOD)> myLODs;
+
+private:
+ Standard_Integer myCurrentLODIdx;
+ Handle(Graphic3d_LODSelector) mySelector;
+ Graphic3d_StructurePtr myStructure;
+ Graphic3d_WorldViewProjState myPrevCameraState;
+};
+
+DEFINE_STANDARD_HANDLE (Graphic3d_LODManager, Standard_Transient)
+
+#endif //_Graphic3d_LODManager_Header
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Graphic3d_LODSelector_Header
+#define _Graphic3d_LODSelector_Header
+
+#include <Standard.hxx>
+#include <Standard_Handle.hxx>
+#include <Standard_Transient.hxx>
+
+class Graphic3d_CStructure;
+class Graphic3d_Camera;
+
+class Graphic3d_LODSelector : public Standard_Transient
+{
+public:
+ virtual Standard_Real ComputeMetric (const Handle(Graphic3d_CStructure)& theParentStructure,
+ const Handle(Graphic3d_Camera)& theCamera) = 0;
+
+ DEFINE_STANDARD_RTTI (Graphic3d_LODSelector, Standard_Transient)
+};
+
+DEFINE_STANDARD_HANDLE (Graphic3d_LODSelector, Standard_Transient)
+
+#endif // _Graphic3d_LODSelector_Header
//=============================================================================
Handle(Graphic3d_LOD) Graphic3d_Structure::NewLOD()
{
- return myCStructure->NewLOD();
+ return myCStructure->NewLOD (this);
}
//=============================================================================
MeshVS_ElementalColorPrsBuilder.hxx
MeshVS_EntityType.hxx
MeshVS_HArray1OfSequenceOfInteger.hxx
+MeshVS_LODBuilder.hxx
+MeshVS_LODBuilder.cxx
MeshVS_LODDataSource.hxx
MeshVS_LODDataSource.cxx
MeshVS_MapIteratorOfMapOfTwoNodes.hxx
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Graphic3d_ArrayOfTriangles.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
+#include <Graphic3d_LOD.hxx>
+#include <MeshVS_Drawer.hxx>
+#include <MeshVS_DrawerAttribute.hxx>
+#include <MeshVS_LODBuilder.hxx>
+#include <MeshVS_MapOfTwoNodes.hxx>
+#include <MeshVS_MeshPrsBuilder.hxx>
+#include <MeshVS_SymmetricPairHasher.hxx>
+#include <MeshVS_Tool.hxx>
+#include <TColStd_HPackedMapOfInteger.hxx>
+#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
+
+//=======================================================================
+// function : Creation
+// purpose :
+//=======================================================================
+MeshVS_LODBuilder::MeshVS_LODBuilder (const Handle(MeshVS_Mesh)& theParentMesh,
+ const MeshVS_DisplayModeFlags& theFlags,
+ const Handle(MeshVS_LODDataSource)& theDataSource,
+ const Standard_Integer theId,
+ const MeshVS_BuilderPriority& thePriority)
+ : MeshVS_PrsBuilder (theParentMesh, theFlags, theDataSource, theId, thePriority)
+{
+ Standard_ASSERT_RAISE (!theDataSource.IsNull(), "LOD data source is null!");
+}
+
+//=======================================================================
+// function : Build
+// purpose :
+//=======================================================================
+void MeshVS_LODBuilder::Build (const Handle(Prs3d_Presentation)& theBasePrs,
+ const TColStd_PackedMapOfInteger& theIDs,
+ TColStd_PackedMapOfInteger& /*theIDsToExclude*/,
+ const Standard_Boolean theIsElement,
+ const Standard_Integer theDisplayMode) const
+{
+ if (myParentMesh == NULL)
+ return;
+
+ //if (!theIsElement)
+ //{
+ // Standard_Boolean hasSelectFlag = ((aDispMode & MeshVS_DMF_SelectionPrs) != 0);
+ // Standard_Boolean hasHilightFlag = ((aDispMode & MeshVS_DMF_HilightPrs) != 0);
+
+ // Standard_Real aCoordsBuf[3];
+ // TColStd_Array1OfReal aCoords (*aCoordsBuf, 1, 3);
+ // Standard_Integer aNodesNb;
+ // MeshVS_EntityType aType;
+
+ // TColStd_PackedMapOfInteger anIDs;
+ // anIDs.Assign (myNodeIdxs);
+ // if (!hasSelectFlag && !hasHilightFlag)
+ // {
+ // // subtract the hidden nodes and ids to exclude (to minimize allocated memory)
+ // Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
+ // if (!aHiddenNodes.IsNull())
+ // anIDs.Subtract (aHiddenNodes->Map());
+ // }
+
+ // Standard_Integer aSize = anIDs.Extent();
+ // if (aSize > 0)
+ // {
+ // Handle(Graphic3d_ArrayOfPoints) aNodePoints = new Graphic3d_ArrayOfPoints (aSize);
+ // Standard_Integer aPntsNb = 0;
+ // for (TColStd_MapIteratorOfPackedMapOfInteger aNodeIdxsIter (myNodeIdxs); aNodeIdxsIter.More(); aNodeIdxsIter.Next())
+ // {
+ // const Standard_Integer aKey = aNodeIdxsIter.Key();
+ // if (GetGeom (aKey, Standard_False, aCoords, aNodesNb, aType))
+ // {
+ // aPntsNb++;
+ // aNodePoints->AddVertex (aCoords(1), aCoords(2), aCoords(3));
+ // }
+ // }
+
+ // if (aPntsNb > 0)
+ // {
+ // Handle(Graphic3d_LOD) aNewLod = Prs3d_Root::NewLOD (aMainPrs);
+ // Handle(Graphic3d_Group) aLODGroup = aNewLod->NewGroup();
+ // aLODGroup->AddPrimitiveArray (aNodePoints);
+ // }
+ // return;
+ // }
+ //}
+ if (theIsElement)
+ {
+ Standard_Integer aMaxNodesNb;
+
+ Handle(MeshVS_MeshPrsBuilder) aBuilder = Handle(MeshVS_MeshPrsBuilder)::DownCast (myParentMesh->GetBuilder (1));
+ if (aBuilder.IsNull())
+ return;
+ Handle(MeshVS_Drawer) aDrawer = aBuilder->GetDrawer();
+ if (aDrawer.IsNull() ||
+ !aDrawer->GetInteger (MeshVS_DA_MaxFaceNodes, aMaxNodesNb) ||
+ aMaxNodesNb <= 0)
+ return;
+
+ //----------- extract useful display mode flags ----------
+ Standard_Integer aDispStatus = (theDisplayMode & aBuilder->GetFlags());
+ if ((aDispStatus & MeshVS_DMF_DeformedMask) != 0)
+ {
+ aDispStatus /= MeshVS_DMF_DeformedPrsWireFrame;
+ // This transformation turns deformed mesh flags to real display modes
+ }
+ aDispStatus &= MeshVS_DMF_OCCMask;
+ //--------------------------------------------------------
+
+ Standard_Real aShrinkCoef;
+ aDrawer->GetDouble (MeshVS_DA_ShrinkCoeff, aShrinkCoef);
+
+ const Standard_Boolean isWireframe = theDisplayMode == MeshVS_DMF_WireFrame;
+ Standard_Boolean isShading = theDisplayMode == MeshVS_DMF_Shading;
+ Standard_Boolean isShrink = theDisplayMode == MeshVS_DMF_Shrink;
+ const Standard_Boolean hasHilightFlag = (aDispStatus & MeshVS_DMF_HilightPrs) != 0;
+ const Standard_Boolean hasSelFlag =(aDispStatus & MeshVS_DMF_SelectionPrs) != 0;
+ Standard_Boolean isMeshSmoothShading = Standard_False;
+ Standard_Boolean isMeshReflect, isMeshAllowOverlap, isReflect;
+
+ aDrawer->GetBoolean (MeshVS_DA_Reflection, isMeshReflect);
+ aDrawer->GetBoolean (MeshVS_DA_IsAllowOverlapped, isMeshAllowOverlap);
+ isReflect = isMeshReflect && !hasHilightFlag;
+ aDrawer->GetBoolean (MeshVS_DA_SmoothShading, isMeshSmoothShading);
+
+ // display mode for highlighted prs of groups
+ isShrink = isShrink && !hasHilightFlag;
+ isShading = isShading || hasHilightFlag;
+
+ Graphic3d_MaterialAspect aMatAspect;
+ aDrawer->GetMaterial (MeshVS_DA_FrontMaterial, aMatAspect);
+ if (!isReflect)
+ {
+ aMatAspect.SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
+ aMatAspect.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
+ aMatAspect.SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
+ aMatAspect.SetReflectionModeOff(Graphic3d_TOR_EMISSION);
+ }
+ Handle(Graphic3d_AspectFillArea3d ) aFill = MeshVS_Tool::CreateAspectFillArea3d (aDrawer, aMatAspect);
+ Handle(Graphic3d_AspectLine3d ) aBeam = MeshVS_Tool::CreateAspectLine3d (aDrawer);
+
+ const Standard_Boolean isOverlapControl =
+ !isMeshAllowOverlap && (isWireframe || isShading) && !hasSelFlag;
+
+ // subtract the hidden elements and ids to exclude (to minimize allocated memory)
+ TColStd_PackedMapOfInteger anIDs;
+ anIDs.Assign (theIDs);
+ Handle(TColStd_HPackedMapOfInteger) aHiddenElems = myParentMesh->GetHiddenElems();
+ if (!aHiddenElems.IsNull())
+ anIDs.Subtract (aHiddenElems->Map());
+
+ Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo;
+
+ Standard_Boolean toShowEdges = Standard_True;
+ aDrawer->GetBoolean (MeshVS_DA_ShowEdges, toShowEdges);
+
+ toShowEdges = isWireframe || toShowEdges;
+
+ Standard_Integer* aNodesBuf = (Standard_Integer*)alloca (aMaxNodesNb * sizeof (Standard_Integer));
+ Standard_Real* aCoordsBuf = (Standard_Real*)alloca (3 * aMaxNodesNb * sizeof (Standard_Real));
+
+ TColStd_Array1OfInteger aNodes (*aNodesBuf, 1, aMaxNodesNb);
+ TColStd_Array1OfReal aCoords (*aCoordsBuf, 1, 3 * aMaxNodesNb);
+
+ Standard_Integer aNbFacePrimitives = 0;
+ Standard_Integer aNbVolmPrimitives = 0;
+ Standard_Integer aNbEdgePrimitives = 0;
+ Standard_Integer aNbLinkPrimitives = 0;
+
+ MeshVS_EntityType aType;
+
+ TColStd_MapIteratorOfPackedMapOfInteger anIdxIter (anIDs);
+ for (anIdxIter.Reset(); anIdxIter.More(); anIdxIter.Next())
+ {
+ Standard_Integer aNbNodes = 0;
+
+ if (!DataSource()->GetGeom (anIdxIter.Key(), Standard_True, aCoords, aNbNodes, aType))
+ continue;
+
+ if (aType == MeshVS_ET_Volume)
+ {
+ if (DataSource()->Get3DGeom (anIdxIter.Key(), aNbNodes, aTopo))
+ {
+ for (Standard_Integer aFaceIdx = aTopo->Lower(); aFaceIdx <= aTopo->Upper(); ++aFaceIdx)
+ {
+ const TColStd_SequenceOfInteger& aFaceNodes = aTopo->Value(aFaceIdx);
+
+ if (toShowEdges) // add edge segments
+ {
+ aNbEdgePrimitives += aFaceNodes.Length();
+ }
+
+ if (isShading || isShrink) // add volumetric cell triangles
+ {
+ if (!hasSelFlag)
+ aNbVolmPrimitives += aFaceNodes.Length() - 2;
+ }
+ }
+ }
+ }
+ else if (aType == MeshVS_ET_Link)
+ {
+ if (toShowEdges)
+ {
+ aNbLinkPrimitives += 1; // add link segment
+ }
+ }
+ else if (aType == MeshVS_ET_Face)
+ {
+ if (toShowEdges)
+ {
+ aNbEdgePrimitives += aNbNodes; // add edge segments
+ }
+
+ if (!isOverlapControl || isShading)
+ {
+ if ((isShading || isShrink) && !hasSelFlag)
+ {
+ aNbFacePrimitives += aNbNodes - 2; // add face triangles
+ }
+ }
+ }
+ }
+
+ // Here we do not use indices arrays because they are not effective for some mesh
+ // drawing modes: shrinking mode (displaces the vertices inside the polygon), 3D
+ // cell rendering (normal interpolation is not always applicable - flat shading),
+ // elemental coloring (color interpolation is impossible)
+ Handle(Graphic3d_ArrayOfTriangles) aVolmTriangles =
+ new Graphic3d_ArrayOfTriangles (aNbVolmPrimitives * 3, 0, isReflect);
+ Handle(Graphic3d_ArrayOfTriangles) aFaceTriangles =
+ new Graphic3d_ArrayOfTriangles (aNbFacePrimitives * 3, 0, isReflect);
+
+ Handle(Graphic3d_ArrayOfSegments) aLinkSegments;
+ Handle(Graphic3d_ArrayOfSegments) aEdgeSegments;
+
+ if (toShowEdges)
+ {
+ aLinkSegments = new Graphic3d_ArrayOfSegments (aNbLinkPrimitives * 2);
+ aEdgeSegments = new Graphic3d_ArrayOfSegments (aNbEdgePrimitives * 2);
+ }
+
+ TColStd_PackedMapOfInteger aCustomElements;
+
+ MeshVS_MapOfTwoNodes aLinkNodes;
+
+ Quantity_Color anOldEdgeColor;
+ Quantity_Color anEdgeColor;
+ Quantity_Color anIntColor;
+ Aspect_InteriorStyle anIntType;
+ Aspect_TypeOfLine aLine;
+ Standard_Real aWidth;
+
+ aFill->Values (anIntType, anIntColor, anEdgeColor, aLine, aWidth);
+
+ // Forbid drawings of edges which overlap with some links
+ if (toShowEdges && isOverlapControl)
+ {
+ for (anIdxIter.Reset(); anIdxIter.More(); anIdxIter.Next())
+ {
+ if (DataSource()->GetGeomType (anIdxIter.Key(), Standard_True, aType) && aType == MeshVS_ET_Link)
+ {
+ Standard_Integer aNbNodes;
+
+ if (DataSource()->GetNodesByElement (anIdxIter.Key(), aNodes, aNbNodes) && aNbNodes == 2)
+ {
+ aLinkNodes.Add (MeshVS_TwoNodes (aNodes(1), aNodes(2)));
+ }
+ }
+ }
+ }
+
+ NCollection_Map<MeshVS_NodePair, MeshVS_SymmetricPairHasher> aSegmentMap;
+
+ for (anIdxIter.Reset(); anIdxIter.More(); anIdxIter.Next())
+ {
+ const Standard_Integer aKey = anIdxIter.Key();
+
+ Standard_Integer NbNodes;
+ if (!DataSource()->GetGeom (aKey, Standard_True, aCoords, NbNodes, aType))
+ continue;
+
+ if (!DataSource()->GetNodesByElement (aKey, aNodes, NbNodes))
+ continue;
+
+ switch (aType)
+ {
+ case MeshVS_ET_Volume:
+ {
+ if (DataSource()->Get3DGeom (aKey, NbNodes, aTopo))
+ {
+ // Add wire-frame presentation (draw edges for shading mode as well)
+ if (toShowEdges)
+ {
+ aBuilder->AddVolumePrs (aTopo, aCoords, NbNodes,
+ aEdgeSegments, isReflect,
+ isShrink, hasSelFlag,
+ aShrinkCoef);
+ }
+
+ // Add shading presentation
+ if ((isShading || isShrink) && !hasSelFlag)
+ {
+ aBuilder->AddVolumePrs (aTopo, aCoords, NbNodes,
+ aVolmTriangles, isReflect,
+ isShrink, hasSelFlag,
+ aShrinkCoef);
+ }
+ }
+ }
+ break;
+
+ case MeshVS_ET_Link:
+ {
+ if (toShowEdges)
+ {
+ aBuilder->AddLinkPrs (aCoords, aLinkSegments, isShrink || hasSelFlag, aShrinkCoef);
+ }
+ }
+ break;
+
+ case MeshVS_ET_Face:
+ {
+ if (toShowEdges && isOverlapControl)
+ {
+ Standard_Integer Last = 0;
+
+ MeshVS_TwoNodes aTwoNodes (aNodes(1));
+
+ for (Standard_Integer i = 1; i <= NbNodes; ++i)
+ {
+ if (i > 1)
+ aTwoNodes.First = aTwoNodes.Second;
+
+ aTwoNodes.Second = (i < NbNodes) ? aNodes (i + 1) : aNodes (1);
+
+ if (aLinkNodes.Contains (aTwoNodes))
+ {
+ for (Standard_Integer aNodeIdx = Last + 1; aNodeIdx < i; ++aNodeIdx)
+ {
+ const Standard_Integer aNextIdx = aNodeIdx + 1;
+
+ aEdgeSegments->AddVertex (
+ aCoords (3 * aNodeIdx - 2), aCoords (3 * aNodeIdx - 1), aCoords (3 * aNodeIdx));
+ aEdgeSegments->AddVertex(
+ aCoords (3 * aNextIdx - 2), aCoords (3 * aNextIdx - 1), aCoords (3 * aNextIdx));
+ }
+
+ Last = i;
+ }
+ }
+
+ if (NbNodes - Last > 0)
+ {
+ for (Standard_Integer aNodeIdx = Last; aNodeIdx < NbNodes; ++aNodeIdx)
+ {
+ const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
+
+ const MeshVS_NodePair aSegment (aNodes (aNodeIdx + 1), aNodes (aNextIdx + 1));
+
+ if (!aSegmentMap.Contains (aSegment))
+ {
+ aEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
+ aCoords (3 * aNodeIdx + 2),
+ aCoords (3 * aNodeIdx + 3));
+
+ aEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
+ aCoords (3 * aNextIdx + 2),
+ aCoords (3 * aNextIdx + 3));
+
+ aSegmentMap.Add (aSegment);
+ }
+ }
+ }
+ }
+
+ if (!isOverlapControl || isShading)
+ {
+ if (!isOverlapControl && toShowEdges)
+ {
+ aBuilder->AddFaceWirePrs (aCoords, NbNodes, aEdgeSegments, isShrink || hasSelFlag, aShrinkCoef);
+ }
+
+ if ((isShading || isShrink) && !hasSelFlag)
+ {
+ aBuilder->AddFaceSolidPrs (DataSource(), aKey, aCoords, NbNodes, aMaxNodesNb, aFaceTriangles, isReflect,
+ isShrink || hasSelFlag, aShrinkCoef, isMeshSmoothShading);
+ }
+ }
+ }
+ break;
+
+ default:
+ aCustomElements.Add (aKey);
+ }
+ }
+
+ if (isShrink)
+ {
+ anOldEdgeColor = anEdgeColor;
+ aFill->SetEdgeColor (Quantity_NOC_BLACK);
+ }
+
+ Standard_Boolean isSupressBackFaces = Standard_False;
+ if (!aDrawer.IsNull())
+ {
+ aDrawer->GetBoolean (MeshVS_DA_SupressBackFaces, isSupressBackFaces);
+ }
+ drawArrays (theBasePrs, aFaceTriangles, aEdgeSegments, aLinkSegments, aVolmTriangles,
+ !toShowEdges, hasSelFlag, isSupressBackFaces, aFill, aBeam);
+ }
+}
+
+//================================================================
+// Function : drawArrays
+// Purpose :
+//================================================================
+void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs,
+ const Handle(Graphic3d_ArrayOfPrimitives)& thePolygons,
+ const Handle(Graphic3d_ArrayOfPrimitives)& theLines,
+ const Handle(Graphic3d_ArrayOfPrimitives)& theLinkLines,
+ const Handle(Graphic3d_ArrayOfPrimitives)& theVolumesInShad,
+ const Standard_Boolean theIsPolygonsEdgesOff,
+ const Standard_Boolean theIsSelected,
+ const Standard_Boolean theIsSupressBackFaces,
+ const Handle(Graphic3d_AspectFillArea3d)& theFillAsp,
+ const Handle(Graphic3d_AspectLine3d)& theLineAsp) const
+{
+ if (theFillAsp.IsNull())
+ return;
+
+ Standard_Boolean isFacePolygons = (!thePolygons.IsNull() && thePolygons->ItemNumber() > 0),
+ isVolumePolygons = (!theVolumesInShad.IsNull() && theVolumesInShad->ItemNumber() > 0),
+ isPolygons = isFacePolygons || isVolumePolygons,
+ isPolylines = (!theLines.IsNull() && theLines->ItemNumber() > 0),
+ isLinkPolylines = (!theLinkLines.IsNull() && theLinkLines->ItemNumber() > 0);
+
+ Aspect_InteriorStyle aStyle;
+ Quantity_Color anIntColor, aBackColor, anEdgeColor;
+ Aspect_TypeOfLine aType;
+ Standard_Real aWidth;
+
+ Handle(Graphic3d_LOD) aNewLod = theBasePrs->NewLOD();
+ theFillAsp->Values (aStyle, anIntColor, aBackColor, anEdgeColor, aType, aWidth);
+
+ if (isPolygons && theFillAsp->FrontMaterial().Transparency() < 0.01)
+ {
+ Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs);
+
+ theFillAsp->SetEdgeOff();
+
+ if (anIntColor != aBackColor)
+ theFillAsp->SetDistinguishOn();
+ else
+ theFillAsp->SetDistinguishOff();
+
+ aGroup->SetClosed (theIsSupressBackFaces);
+ Handle(Graphic3d_AspectFillArea3d) aFillAsp = new Graphic3d_AspectFillArea3d (*(theFillAsp.operator->()));
+ if (theIsSupressBackFaces)
+ {
+ aFillAsp->SuppressBackFace();
+ }
+ aGroup->SetPrimitivesAspect (aFillAsp);
+
+ if (isFacePolygons)
+ {
+ aGroup->AddPrimitiveArray (thePolygons);
+ }
+
+ if (isVolumePolygons)
+ {
+ aGroup->AddPrimitiveArray (theVolumesInShad);
+ }
+ }
+
+ if (isPolylines && !theIsPolygonsEdgesOff)
+ {
+ Handle (Graphic3d_Group) aLGroup = aNewLod->NewGroup (theBasePrs);
+
+ theFillAsp->SetEdgeOff();
+ if (theIsSelected)
+ aLGroup->SetPrimitivesAspect (theLineAsp);
+ else
+ {
+ aLGroup->SetPrimitivesAspect (theFillAsp);
+ aLGroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (anEdgeColor, Aspect_TOL_SOLID, aWidth));
+ }
+ aLGroup->AddPrimitiveArray (theLines);
+ theFillAsp->SetEdgeOn();
+ }
+
+ if (isLinkPolylines)
+ {
+ Handle (Graphic3d_Group) aBeamGroup = aNewLod->NewGroup (theBasePrs);
+
+ theFillAsp->SetEdgeOff();
+ if (!theIsSelected)
+ aBeamGroup->SetPrimitivesAspect (theFillAsp);
+ aBeamGroup->SetPrimitivesAspect (theLineAsp);
+ aBeamGroup->AddPrimitiveArray (theLinkLines);
+ theFillAsp->SetEdgeOn();
+ }
+
+ if (isPolygons && theFillAsp->FrontMaterial().Transparency() >= 0.01)
+ {
+ Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs);
+
+ theFillAsp->SetEdgeOff();
+
+ if (anIntColor != aBackColor)
+ theFillAsp->SetDistinguishOn();
+ else
+ theFillAsp->SetDistinguishOff();
+
+ aGroup->SetClosed (theIsSupressBackFaces);
+ Handle(Graphic3d_AspectFillArea3d) aFillAsp = new Graphic3d_AspectFillArea3d (*(theFillAsp.operator->()));
+ if (theIsSupressBackFaces)
+ {
+ aFillAsp->SuppressBackFace();
+ }
+ aGroup->SetPrimitivesAspect (aFillAsp);
+
+ if (isFacePolygons)
+ {
+ aGroup->AddPrimitiveArray (thePolygons);
+ }
+
+ if (isVolumePolygons)
+ {
+ aGroup->AddPrimitiveArray (theVolumesInShad);
+ }
+ }
+}
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _MeshVS_LODBuilder_Header
+#define _MeshVS_LODBuilder_Header
+
+#include <MeshVS_Mesh.hxx>
+#include <MeshVS_PrsBuilder.hxx>
+#include <MeshVS_LODDataSource.hxx>
+
+class MeshVS_LODBuilder : public MeshVS_PrsBuilder
+{
+public:
+
+ //! Creates builder with certain display mode flags, data source, ID and priority
+ Standard_EXPORT MeshVS_LODBuilder (const Handle(MeshVS_Mesh)& theParentMesh,
+ const MeshVS_DisplayModeFlags& theFlags = MeshVS_DMF_OCCMask,
+ const Handle(MeshVS_LODDataSource)& theDataSource = NULL,
+ const Standard_Integer theId = -1,
+ const MeshVS_BuilderPriority& thePriority = MeshVS_BP_Mesh);
+
+ Standard_EXPORT virtual ~MeshVS_LODBuilder() {};
+
+ //! Builds presentation of certain type of data.
+ //! Prs is presentation object which this method constructs.
+ //! IDs is set of numeric identificators forming object appearance.
+ //! IDsToExclude is set of IDs to exclude from processing. If some entity
+ //! has been excluded, it is not processed by other builders.
+ //! IsElement indicates, IDs is identificators of nodes or elements.
+ //! DisplayMode is numeric constant describing display mode (see MeshVS_DisplayModeFlags.hxx)
+ Standard_EXPORT virtual void Build (const Handle(Prs3d_Presentation)& theBasePrs,
+ const TColStd_PackedMapOfInteger& theIDs,
+ TColStd_PackedMapOfInteger& theIDsToExclude,
+ const Standard_Boolean theIsElement,
+ const Standard_Integer theDisplayMode) const Standard_OVERRIDE;
+
+ DEFINE_STANDARD_RTTI (MeshVS_LODBuilder, MeshVS_PrsBuilder)
+
+protected:
+ void drawArrays (const Handle(Prs3d_Presentation)& theBasePrs,
+ const Handle(Graphic3d_ArrayOfPrimitives)& thePolygons,
+ const Handle(Graphic3d_ArrayOfPrimitives)& theLines,
+ const Handle(Graphic3d_ArrayOfPrimitives)& theLinkLines,
+ const Handle(Graphic3d_ArrayOfPrimitives)& theVolumesInShad,
+ const Standard_Boolean theIsPolygonsEdgesOff,
+ const Standard_Boolean theIsSelected,
+ const Standard_Boolean theIsSupressBackFaces,
+ const Handle(Graphic3d_AspectFillArea3d)& theFillAsp,
+ const Handle(Graphic3d_AspectLine3d)& theLineAsp) const;
+};
+
+DEFINE_STANDARD_HANDLE (MeshVS_LODBuilder, MeshVS_PrsBuilder)
+
+#endif // _MeshVS_LODBuilder_Header
{
return myTriangleIdxs;
}
-
-//=======================================================================
-// function : ComputePrs
-// purpose :
-//=======================================================================
-void MeshVS_LODDataSource::ComputePrs (const Handle(AIS_InteractiveObject) theMesh)
-{
- Handle(MeshVS_Mesh) aMesh = Handle(MeshVS_Mesh)::DownCast (theMesh);
- if (aMesh.IsNull())
- return;
-
- // Standard_Boolean hasNodes = !myNodeIdxs.IsEmpty();
- Standard_Boolean hasTrgs = !myTriangleIdxs.IsEmpty();
- Handle(Prs3d_Presentation) aMainPrs = theMesh->Presentation();
- const Standard_Integer aDispMode = theMesh->DisplayMode();
-
- //if (hasNodes)
- //{
- // Standard_Boolean hasSelectFlag = ((aDispMode & MeshVS_DMF_SelectionPrs) != 0);
- // Standard_Boolean hasHilightFlag = ((aDispMode & MeshVS_DMF_HilightPrs) != 0);
-
- // Standard_Real aCoordsBuf[3];
- // TColStd_Array1OfReal aCoords (*aCoordsBuf, 1, 3);
- // Standard_Integer aNodesNb;
- // MeshVS_EntityType aType;
-
- // TColStd_PackedMapOfInteger anIDs;
- // anIDs.Assign (myNodeIdxs);
- // if (!hasSelectFlag && !hasHilightFlag)
- // {
- // // subtract the hidden nodes and ids to exclude (to minimize allocated memory)
- // Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
- // if (!aHiddenNodes.IsNull())
- // anIDs.Subtract (aHiddenNodes->Map());
- // }
-
- // Standard_Integer aSize = anIDs.Extent();
- // if (aSize > 0)
- // {
- // Handle(Graphic3d_ArrayOfPoints) aNodePoints = new Graphic3d_ArrayOfPoints (aSize);
- // Standard_Integer aPntsNb = 0;
- // for (TColStd_MapIteratorOfPackedMapOfInteger aNodeIdxsIter (myNodeIdxs); aNodeIdxsIter.More(); aNodeIdxsIter.Next())
- // {
- // const Standard_Integer aKey = aNodeIdxsIter.Key();
- // if (GetGeom (aKey, Standard_False, aCoords, aNodesNb, aType))
- // {
- // aPntsNb++;
- // aNodePoints->AddVertex (aCoords(1), aCoords(2), aCoords(3));
- // }
- // }
-
- // if (aPntsNb > 0)
- // {
- // Handle(Graphic3d_LOD) aNewLod = Prs3d_Root::NewLOD (aMainPrs);
- // Handle(Graphic3d_Group) aLODGroup = aNewLod->NewGroup();
- // aLODGroup->AddPrimitiveArray (aNodePoints);
- // }
- // return;
- // }
- //}
- if (hasTrgs)
- {
- Standard_Integer aMaxNodesNb;
-
- Handle(MeshVS_MeshPrsBuilder) aBuilder = Handle(MeshVS_MeshPrsBuilder)::DownCast (aMesh->GetBuilder (1));
- if (aBuilder.IsNull())
- return;
- Handle(MeshVS_Drawer) aDrawer = aBuilder->GetDrawer();
- if (aDrawer.IsNull() ||
- !aDrawer->GetInteger (MeshVS_DA_MaxFaceNodes, aMaxNodesNb) ||
- aMaxNodesNb <= 0)
- return;
-
- //----------- extract useful display mode flags ----------
- Standard_Integer aDispStatus = (aDispMode & aBuilder->GetFlags());
- if ((aDispStatus & MeshVS_DMF_DeformedMask) != 0)
- {
- aDispStatus /= MeshVS_DMF_DeformedPrsWireFrame;
- // This transformation turns deformed mesh flags to real display modes
- }
- aDispStatus &= MeshVS_DMF_OCCMask;
- //--------------------------------------------------------
-
- Standard_Real aShrinkCoef;
- aDrawer->GetDouble (MeshVS_DA_ShrinkCoeff, aShrinkCoef);
-
- const Standard_Boolean isWireframe = aDispMode == MeshVS_DMF_WireFrame;
- Standard_Boolean isShading = aDispMode == MeshVS_DMF_Shading;
- Standard_Boolean isShrink = aDispMode == MeshVS_DMF_Shrink;
- const Standard_Boolean hasHilightFlag = (aDispStatus & MeshVS_DMF_HilightPrs) != 0;
- const Standard_Boolean hasSelFlag =(aDispStatus & MeshVS_DMF_SelectionPrs) != 0;
- Standard_Boolean isMeshSmoothShading = Standard_False;
- Standard_Boolean isMeshReflect, isMeshAllowOverlap, isReflect;
-
- aDrawer->GetBoolean (MeshVS_DA_Reflection, isMeshReflect);
- aDrawer->GetBoolean (MeshVS_DA_IsAllowOverlapped, isMeshAllowOverlap);
- isReflect = isMeshReflect && !hasHilightFlag;
- aDrawer->GetBoolean (MeshVS_DA_SmoothShading, isMeshSmoothShading);
-
- // display mode for highlighted prs of groups
- isShrink = isShrink && !hasHilightFlag;
- isShading = isShading || hasHilightFlag;
-
- Graphic3d_MaterialAspect aMatAspect;
- aDrawer->GetMaterial (MeshVS_DA_FrontMaterial, aMatAspect);
- if (!isReflect)
- {
- aMatAspect.SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
- aMatAspect.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
- aMatAspect.SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
- aMatAspect.SetReflectionModeOff(Graphic3d_TOR_EMISSION);
- }
- Handle(Graphic3d_AspectFillArea3d ) aFill = MeshVS_Tool::CreateAspectFillArea3d (aDrawer, aMatAspect);
- Handle(Graphic3d_AspectLine3d ) aBeam = MeshVS_Tool::CreateAspectLine3d (aDrawer);
-
- const Standard_Boolean isOverlapControl =
- !isMeshAllowOverlap && (isWireframe || isShading) && !hasSelFlag;
-
- // subtract the hidden elements and ids to exclude (to minimize allocated memory)
- TColStd_PackedMapOfInteger anIDs;
- anIDs.Assign (myTriangleIdxs);
- Handle(TColStd_HPackedMapOfInteger) aHiddenElems = aMesh->GetHiddenElems();
- if (!aHiddenElems.IsNull())
- anIDs.Subtract (aHiddenElems->Map());
-
- Handle(MeshVS_HArray1OfSequenceOfInteger) aTopo;
-
- Standard_Boolean toShowEdges = Standard_True;
- aDrawer->GetBoolean (MeshVS_DA_ShowEdges, toShowEdges);
-
- toShowEdges = isWireframe || toShowEdges;
-
- Standard_Integer* aNodesBuf = (Standard_Integer*)alloca (aMaxNodesNb * sizeof (Standard_Integer));
- Standard_Real* aCoordsBuf = (Standard_Real*)alloca (3 * aMaxNodesNb * sizeof (Standard_Real));
-
- TColStd_Array1OfInteger aNodes (*aNodesBuf, 1, aMaxNodesNb);
- TColStd_Array1OfReal aCoords (*aCoordsBuf, 1, 3 * aMaxNodesNb);
-
- Standard_Integer aNbFacePrimitives = 0;
- Standard_Integer aNbVolmPrimitives = 0;
- Standard_Integer aNbEdgePrimitives = 0;
- Standard_Integer aNbLinkPrimitives = 0;
-
- MeshVS_EntityType aType;
-
- TColStd_MapIteratorOfPackedMapOfInteger anIdxIter (anIDs);
- for (anIdxIter.Reset(); anIdxIter.More(); anIdxIter.Next())
- {
- Standard_Integer aNbNodes = 0;
-
- if (!GetGeom (anIdxIter.Key(), Standard_True, aCoords, aNbNodes, aType))
- continue;
-
- if (aType == MeshVS_ET_Volume)
- {
- if (Get3DGeom (anIdxIter.Key(), aNbNodes, aTopo))
- {
- for (Standard_Integer aFaceIdx = aTopo->Lower(); aFaceIdx <= aTopo->Upper(); ++aFaceIdx)
- {
- const TColStd_SequenceOfInteger& aFaceNodes = aTopo->Value(aFaceIdx);
-
- if (toShowEdges) // add edge segments
- {
- aNbEdgePrimitives += aFaceNodes.Length();
- }
-
- if (isShading || isShrink) // add volumetric cell triangles
- {
- if (!hasSelFlag)
- aNbVolmPrimitives += aFaceNodes.Length() - 2;
- }
- }
- }
- }
- else if (aType == MeshVS_ET_Link)
- {
- if (toShowEdges)
- {
- aNbLinkPrimitives += 1; // add link segment
- }
- }
- else if (aType == MeshVS_ET_Face)
- {
- if (toShowEdges)
- {
- aNbEdgePrimitives += aNbNodes; // add edge segments
- }
-
- if (!isOverlapControl || isShading)
- {
- if ((isShading || isShrink) && !hasSelFlag)
- {
- aNbFacePrimitives += aNbNodes - 2; // add face triangles
- }
- }
- }
- }
-
- // Here we do not use indices arrays because they are not effective for some mesh
- // drawing modes: shrinking mode (displaces the vertices inside the polygon), 3D
- // cell rendering (normal interpolation is not always applicable - flat shading),
- // elemental coloring (color interpolation is impossible)
- Handle(Graphic3d_ArrayOfTriangles) aVolmTriangles =
- new Graphic3d_ArrayOfTriangles (aNbVolmPrimitives * 3, 0, isReflect);
- Handle(Graphic3d_ArrayOfTriangles) aFaceTriangles =
- new Graphic3d_ArrayOfTriangles (aNbFacePrimitives * 3, 0, isReflect);
-
- Handle(Graphic3d_ArrayOfSegments) aLinkSegments;
- Handle(Graphic3d_ArrayOfSegments) aEdgeSegments;
-
- if (toShowEdges)
- {
- aLinkSegments = new Graphic3d_ArrayOfSegments (aNbLinkPrimitives * 2);
- aEdgeSegments = new Graphic3d_ArrayOfSegments (aNbEdgePrimitives * 2);
- }
-
- TColStd_PackedMapOfInteger aCustomElements;
-
- MeshVS_MapOfTwoNodes aLinkNodes;
-
- Quantity_Color anOldEdgeColor;
- Quantity_Color anEdgeColor;
- Quantity_Color anIntColor;
- Aspect_InteriorStyle anIntType;
- Aspect_TypeOfLine aLine;
- Standard_Real aWidth;
-
- aFill->Values (anIntType, anIntColor, anEdgeColor, aLine, aWidth);
-
- // Forbid drawings of edges which overlap with some links
- if (toShowEdges && isOverlapControl)
- {
- for (anIdxIter.Reset(); anIdxIter.More(); anIdxIter.Next())
- {
- if (GetGeomType (anIdxIter.Key(), Standard_True, aType) && aType == MeshVS_ET_Link)
- {
- Standard_Integer aNbNodes;
-
- if (GetNodesByElement (anIdxIter.Key(), aNodes, aNbNodes) && aNbNodes == 2)
- {
- aLinkNodes.Add (MeshVS_TwoNodes (aNodes(1), aNodes(2)));
- }
- }
- }
- }
-
- NCollection_Map<MeshVS_NodePair, MeshVS_SymmetricPairHasher> aSegmentMap;
-
- for (anIdxIter.Reset(); anIdxIter.More(); anIdxIter.Next())
- {
- const Standard_Integer aKey = anIdxIter.Key();
-
- Standard_Integer NbNodes;
- if (!GetGeom (aKey, Standard_True, aCoords, NbNodes, aType))
- continue;
-
- if (!GetNodesByElement (aKey, aNodes, NbNodes))
- continue;
-
- switch (aType)
- {
- case MeshVS_ET_Volume:
- {
- if (Get3DGeom (aKey, NbNodes, aTopo))
- {
- // Add wire-frame presentation (draw edges for shading mode as well)
- if (toShowEdges)
- {
- aBuilder->AddVolumePrs (aTopo, aCoords, NbNodes,
- aEdgeSegments, isReflect,
- isShrink, hasSelFlag,
- aShrinkCoef);
- }
-
- // Add shading presentation
- if ((isShading || isShrink) && !hasSelFlag)
- {
- aBuilder->AddVolumePrs (aTopo, aCoords, NbNodes,
- aVolmTriangles, isReflect,
- isShrink, hasSelFlag,
- aShrinkCoef);
- }
- }
- }
- break;
-
- case MeshVS_ET_Link:
- {
- if (toShowEdges)
- {
- aBuilder->AddLinkPrs (aCoords, aLinkSegments, isShrink || hasSelFlag, aShrinkCoef);
- }
- }
- break;
-
- case MeshVS_ET_Face:
- {
- if (toShowEdges && isOverlapControl)
- {
- Standard_Integer Last = 0;
-
- MeshVS_TwoNodes aTwoNodes (aNodes(1));
-
- for (Standard_Integer i = 1; i <= NbNodes; ++i)
- {
- if (i > 1)
- aTwoNodes.First = aTwoNodes.Second;
-
- aTwoNodes.Second = (i < NbNodes) ? aNodes (i + 1) : aNodes (1);
-
- if (aLinkNodes.Contains (aTwoNodes))
- {
- for (Standard_Integer aNodeIdx = Last + 1; aNodeIdx < i; ++aNodeIdx)
- {
- const Standard_Integer aNextIdx = aNodeIdx + 1;
-
- aEdgeSegments->AddVertex (
- aCoords (3 * aNodeIdx - 2), aCoords (3 * aNodeIdx - 1), aCoords (3 * aNodeIdx));
- aEdgeSegments->AddVertex(
- aCoords (3 * aNextIdx - 2), aCoords (3 * aNextIdx - 1), aCoords (3 * aNextIdx));
- }
-
- Last = i;
- }
- }
-
- if (NbNodes - Last > 0)
- {
- for (Standard_Integer aNodeIdx = Last; aNodeIdx < NbNodes; ++aNodeIdx)
- {
- const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
-
- const MeshVS_NodePair aSegment (aNodes (aNodeIdx + 1), aNodes (aNextIdx + 1));
-
- if (!aSegmentMap.Contains (aSegment))
- {
- aEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
- aCoords (3 * aNodeIdx + 2),
- aCoords (3 * aNodeIdx + 3));
-
- aEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
- aCoords (3 * aNextIdx + 2),
- aCoords (3 * aNextIdx + 3));
-
- aSegmentMap.Add (aSegment);
- }
- }
- }
- }
-
- if (!isOverlapControl || isShading)
- {
- if (!isOverlapControl && toShowEdges)
- {
- aBuilder->AddFaceWirePrs (aCoords, NbNodes, aEdgeSegments, isShrink || hasSelFlag, aShrinkCoef);
- }
-
- if ((isShading || isShrink) && !hasSelFlag)
- {
- aBuilder->AddFaceSolidPrs (this, aKey, aCoords, NbNodes, aMaxNodesNb, aFaceTriangles, isReflect,
- isShrink || hasSelFlag, aShrinkCoef, isMeshSmoothShading);
- }
- }
- }
- break;
-
- default:
- aCustomElements.Add (aKey);
- }
- }
-
- if (isShrink)
- {
- anOldEdgeColor = anEdgeColor;
- aFill->SetEdgeColor (Quantity_NOC_BLACK);
- }
-
- Standard_Boolean isSupressBackFaces = Standard_False;
- if (!aDrawer.IsNull())
- {
- aDrawer->GetBoolean (MeshVS_DA_SupressBackFaces, isSupressBackFaces);
- }
- drawArrays (aMainPrs, aFaceTriangles, aEdgeSegments, aLinkSegments, aVolmTriangles,
- !toShowEdges, hasSelFlag, isSupressBackFaces, aFill, aBeam);
- }
-}
-
-//================================================================
-// Function : DrawArrays
-// Purpose :
-//================================================================
-void MeshVS_LODDataSource::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs,
- const Handle(Graphic3d_ArrayOfPrimitives)& thePolygons,
- const Handle(Graphic3d_ArrayOfPrimitives)& theLines,
- const Handle(Graphic3d_ArrayOfPrimitives)& theLinkLines,
- const Handle(Graphic3d_ArrayOfPrimitives)& theVolumesInShad,
- const Standard_Boolean theIsPolygonsEdgesOff,
- const Standard_Boolean theIsSelected,
- const Standard_Boolean theIsSupressBackFaces,
- const Handle(Graphic3d_AspectFillArea3d)& theFillAsp,
- const Handle(Graphic3d_AspectLine3d)& theLineAsp) const
-{
- if (theFillAsp.IsNull())
- return;
-
- Standard_Boolean isFacePolygons = (!thePolygons.IsNull() && thePolygons->ItemNumber() > 0),
- isVolumePolygons = (!theVolumesInShad.IsNull() && theVolumesInShad->ItemNumber() > 0),
- isPolygons = isFacePolygons || isVolumePolygons,
- isPolylines = (!theLines.IsNull() && theLines->ItemNumber() > 0),
- isLinkPolylines = (!theLinkLines.IsNull() && theLinkLines->ItemNumber() > 0);
-
- Aspect_InteriorStyle aStyle;
- Quantity_Color anIntColor, aBackColor, anEdgeColor;
- Aspect_TypeOfLine aType;
- Standard_Real aWidth;
-
- Handle(Graphic3d_LOD) aNewLod = theBasePrs->NewLOD();
- theFillAsp->Values (aStyle, anIntColor, aBackColor, anEdgeColor, aType, aWidth);
-
- if (isPolygons && theFillAsp->FrontMaterial().Transparency() < 0.01)
- {
- Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs);
-
- theFillAsp->SetEdgeOff();
-
- if (anIntColor != aBackColor)
- theFillAsp->SetDistinguishOn();
- else
- theFillAsp->SetDistinguishOff();
-
- aGroup->SetClosed (theIsSupressBackFaces);
- Handle(Graphic3d_AspectFillArea3d) aFillAsp = new Graphic3d_AspectFillArea3d (*(theFillAsp.operator->()));
- if (theIsSupressBackFaces)
- {
- aFillAsp->SuppressBackFace();
- }
- aGroup->SetPrimitivesAspect (aFillAsp);
-
- if (isFacePolygons)
- {
- aGroup->AddPrimitiveArray (thePolygons);
- }
-
- if (isVolumePolygons)
- {
- aGroup->AddPrimitiveArray (theVolumesInShad);
- }
- }
-
- if (isPolylines && !theIsPolygonsEdgesOff)
- {
- Handle (Graphic3d_Group) aLGroup = aNewLod->NewGroup (theBasePrs);
-
- theFillAsp->SetEdgeOff();
- if (theIsSelected)
- aLGroup->SetPrimitivesAspect (theLineAsp);
- else
- {
- aLGroup->SetPrimitivesAspect (theFillAsp);
- aLGroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (anEdgeColor, Aspect_TOL_SOLID, aWidth));
- }
- aLGroup->AddPrimitiveArray (theLines);
- theFillAsp->SetEdgeOn();
- }
-
- if (isLinkPolylines)
- {
- Handle (Graphic3d_Group) aBeamGroup = aNewLod->NewGroup (theBasePrs);
-
- theFillAsp->SetEdgeOff();
- if (!theIsSelected)
- aBeamGroup->SetPrimitivesAspect (theFillAsp);
- aBeamGroup->SetPrimitivesAspect (theLineAsp);
- aBeamGroup->AddPrimitiveArray (theLinkLines);
- theFillAsp->SetEdgeOn();
- }
-
- if (isPolygons && theFillAsp->FrontMaterial().Transparency() >= 0.01)
- {
- Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs);
-
- theFillAsp->SetEdgeOff();
-
- if (anIntColor != aBackColor)
- theFillAsp->SetDistinguishOn();
- else
- theFillAsp->SetDistinguishOff();
-
- aGroup->SetClosed (theIsSupressBackFaces);
- Handle(Graphic3d_AspectFillArea3d) aFillAsp = new Graphic3d_AspectFillArea3d (*(theFillAsp.operator->()));
- if (theIsSupressBackFaces)
- {
- aFillAsp->SuppressBackFace();
- }
- aGroup->SetPrimitivesAspect (aFillAsp);
-
- if (isFacePolygons)
- {
- aGroup->AddPrimitiveArray (thePolygons);
- }
-
- if (isVolumePolygons)
- {
- aGroup->AddPrimitiveArray (theVolumesInShad);
- }
- }
-}
//! This method returns map of all elements the object consist of.
Standard_EXPORT virtual const TColStd_PackedMapOfInteger& GetAllElements() const Standard_OVERRIDE;
- Standard_EXPORT void ComputePrs (const Handle(AIS_InteractiveObject) theMesh);
-
DEFINE_STANDARD_RTTI (MeshVS_LODDataSource, MeshVS_DataSource)
-protected:
- void drawArrays (const Handle(Prs3d_Presentation)& theBasePrs,
- const Handle(Graphic3d_ArrayOfPrimitives)& thePolygons,
- const Handle(Graphic3d_ArrayOfPrimitives)& theLines,
- const Handle(Graphic3d_ArrayOfPrimitives)& theLinkLines,
- const Handle(Graphic3d_ArrayOfPrimitives)& theVolumesInShad,
- const Standard_Boolean theIsPolygonsEdgesOff,
- const Standard_Boolean theIsSelected,
- const Standard_Boolean theIsSupressBackFaces,
- const Handle(Graphic3d_AspectFillArea3d)& theFillAsp,
- const Handle(Graphic3d_AspectLine3d)& theLineAsp) const;
-
private:
TColStd_PackedMapOfInteger myNodeIdxs;
TColStd_PackedMapOfInteger myTriangleIdxs;
#include <MeshVS_Drawer.hxx>
#include <MeshVS_DrawerAttribute.hxx>
#include <MeshVS_DummySensitiveEntity.hxx>
+#include <MeshVS_LODBuilder.hxx>
#include <MeshVS_Mesh.hxx>
#include <MeshVS_MeshEntityOwner.hxx>
#include <MeshVS_MeshOwner.hxx>
thePresentation->Clear();
Standard_Integer len = myBuilders.Length();
+ Handle(MeshVS_LODBuilder) aLODBldr;
if ( theMode > 0 )
for ( Standard_Integer i=1; i<=len; i++ )
{
Handle (MeshVS_PrsBuilder) aCurrent = myBuilders.Value ( i );
+ if (!Handle(MeshVS_LODBuilder)::DownCast (aCurrent))
+ {
+ aLODBldr = Handle(MeshVS_LODBuilder)::DownCast (aCurrent);
+ continue;
+ }
if ( !aCurrent.IsNull() && aCurrent->TestFlags ( theMode ) )
{
aCurrent->SetPresentationManager( thePrsMgr );
}
}
+ if (myLODDataSources.Size() > 0 && !aLODBldr.IsNull() && aLODBldr->TestFlags (theMode))
+ {
+ for (Standard_Integer aLodIdx = 0; aLodIdx < myLODDataSources.Size(); ++aLodIdx)
+ {
+ const TColStd_PackedMapOfInteger aVertIdxs = myLODDataSources.Value (aLodIdx)->GetAllNodes();
+ const TColStd_PackedMapOfInteger aTrgIdxs = myLODDataSources.Value (aLodIdx)->GetAllElements();
+ if (HasNodes)
+ aLODBldr->Build (thePresentation, aVertIdxs, aNodesToExclude, Standard_False, theMode);
+ if (HasElements)
+ aLODBldr->Build (thePresentation, aTrgIdxs, aElemsToExclude, Standard_True, theMode);
+ }
+ }
if ( ShowComputeTime )
{
myDataSource = theDataSource;
}
+//================================================================
+// Function : AddDataSource
+// Purpose :
+//================================================================
+void MeshVS_Mesh::AddDataSource (const Handle(MeshVS_DataSource)& theDataSource)
+{
+ myLODDataSources.Append (theDataSource);
+}
+
//================================================================
// Function : HilightSelected
// Purpose :
//! Sets default builders' data source
Standard_EXPORT void SetDataSource (const Handle(MeshVS_DataSource)& aDataSource);
-
+
+ //! Adds data source to define LOD
+ Standard_EXPORT void AddDataSource (const Handle(MeshVS_DataSource)& theDataSource);
+
//! Returns default builders' drawer
Standard_EXPORT Handle(MeshVS_Drawer) GetDrawer() const;
protected:
-
MeshVS_DataMapOfIntegerOwner myNodeOwners;
MeshVS_DataMapOfIntegerOwner myElementOwners;
MeshVS_DataMapOfIntegerOwner my0DOwners;
Handle(MeshVS_Drawer) myHilightDrawer;
Handle(SelectMgr_EntityOwner) myWholeMeshOwner;
-
private:
-
MeshVS_SequenceOfPrsBuilder myBuilders;
Handle(MeshVS_PrsBuilder) myHilighter;
Handle(TColStd_HPackedMapOfInteger) myHiddenElements;
Handle(TColStd_HPackedMapOfInteger) mySelectableNodes;
Handle(MeshVS_DataSource) myDataSource;
MeshVS_MeshSelectionMethod mySelectionMethod;
-
-
+ NCollection_Vector<Handle(MeshVS_DataSource)> myLODDataSources;
};
-
-
-
-
-
-
#endif // _MeshVS_Mesh_HeaderFile
OpenGl_LayerList.hxx
OpenGl_LayerFilter.hxx
OpenGl_LOD.hxx
-OpenGl_LOD.lxx
OpenGl_LOD.cxx
+OpenGl_LODManager.hxx
+OpenGl_LODManager.cxx
OpenGl_GraphicDriver.cxx
OpenGl_GraphicDriver.hxx
OpenGl_IndexBuffer.cxx
#include <OpenGl_LOD.hxx>
-//=======================================================================
-// function : Construction
-// purpose :
-//=======================================================================
-OpenGl_LOD::OpenGl_LOD()
-: Graphic3d_LOD (),
- myRange (-DBL_MAX, DBL_MAX) {}
-
-//=======================================================================
-// function : SetRange
-// purpose :
-//=======================================================================
-void OpenGl_LOD::SetRange (const Standard_Real theFrom, const Standard_Real theTo)
-{
- Standard_ASSERT_RAISE (theFrom < theTo,
- "The upper boundary of the interval must be greater than lower one!");
-
- myRange = OpenGl_RangeOfLOD (theFrom, theTo);
-}
-
//=======================================================================
// function : NewGroup
// purpose :
#include <OpenGl_AspectLine.hxx>
#include <OpenGl_Structure.hxx>
-struct OpenGl_RangeOfLOD
-{
-public:
- OpenGl_RangeOfLOD (const Standard_Real theFrom, const Standard_Real theTo)
- : myTo (theTo),
- myFrom (theFrom)
- {
- Standard_ASSERT_RAISE (theFrom < theTo,
- "The upper boundary of the interval must be greater than lower one!");
- }
-
- Standard_Boolean IsIn (const Standard_Real theVal) const
- {
- return (myFrom < theVal) && (theVal < myTo);
- }
-
- Standard_Boolean IsLess (const Standard_Real theVal) const
- {
- return myFrom < theVal;
- }
-
- Standard_Boolean IsGreater (const Standard_Real theVal) const
- {
- return myTo < theVal;
- }
-
- bool operator < (const OpenGl_RangeOfLOD& theOther) const
- {
- return myFrom < theOther.myFrom;
- }
-
-private:
- Standard_Real myFrom;
- Standard_Real myTo;
-};
-
class OpenGl_LOD : public Graphic3d_LOD
{
public:
- Standard_EXPORT OpenGl_LOD();
+ Standard_EXPORT OpenGl_LOD() : Graphic3d_LOD () {};
Standard_EXPORT ~OpenGl_LOD() {};
- Standard_EXPORT virtual void SetRange (const Standard_Real theFrom, const Standard_Real theTo) Standard_OVERRIDE;
-
- inline const OpenGl_RangeOfLOD& GetRange() const
- {
- return myRange;
- }
-
Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theParentStruct) Standard_OVERRIDE;
- const Graphic3d_SequenceOfGroup& DrawGroups() const
- {
- return myGroups;
- }
-
DEFINE_STANDARD_RTTI (OpenGl_LOD, Graphic3d_LOD)
-
-private:
- OpenGl_RangeOfLOD myRange;
};
DEFINE_STANDARD_HANDLE (OpenGl_LOD, Graphic3d_LOD)
+++ /dev/null
-// Created on: 2015-10-29
-// Created by: Varvara POSKONINA
-// Copyright (c) 2005-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-struct IsLessLOD
-{
- inline bool operator() (const Handle(OpenGl_LOD)& theLod1, const Handle(OpenGl_LOD)& theLod2) const
- {
- return theLod1->GetRange() < theLod2->GetRange();
- }
-};
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Graphic3d_LOD.hxx>
+#include <OpenGl_LOD.hxx>
+#include <OpenGl_LODManager.hxx>
+
+#include <algorithm>
+
+namespace
+{
+ // Comparison operator for sorting LODs
+ class CompareLODS
+ {
+ public:
+
+ CompareLODS (const NCollection_Vector<Handle(Graphic3d_LOD)>& theLODs)
+ : myLODs (theLODs) {}
+
+ Standard_Boolean operator() (const Handle(Graphic3d_LOD)& theLeft, const Handle(Graphic3d_LOD)& theRight) const
+ {
+ return theLeft->GetRange() < theRight->GetRange();
+ }
+
+ private:
+ void operator = (const CompareLODS&);
+
+ private:
+ const NCollection_Vector<Handle(Graphic3d_LOD)>& myLODs;
+ };
+}
+
+//=======================================================================
+// function : Creation
+// purpose :
+//=======================================================================
+OpenGl_LODManager::OpenGl_LODManager (const Handle(Graphic3d_Structure)& theParentStructure)
+ : Graphic3d_LODManager (theParentStructure)
+{
+ Standard_ASSERT_RAISE (!theParentStructure.IsNull(),
+ "Parent structure of LOD manager is null!");
+}
+
+//=======================================================================
+// function : AddNewLOD
+// purpose :
+//=======================================================================
+Handle(Graphic3d_LOD)& OpenGl_LODManager::AddNewLOD()
+{
+ Handle(Graphic3d_LOD) aNewLOD = new OpenGl_LOD();
+ myLODs.Append (aNewLOD);
+ sortLODs();
+ return aNewLOD;
+}
+
+//=======================================================================
+// function : sortLODs
+// purpose :
+//=======================================================================
+void OpenGl_LODManager::sortLODs()
+{
+ std::sort (myLODs.begin(), myLODs.end(), CompareLODS (myLODs));
+}
--- /dev/null
+// Created on: 2015-11-25
+// Created by: Varvara POSKONINA
+// Copyright (c) 2005-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _OpenGl_LODManager_Header
+#define _OpenGl_LODManager_Header
+
+#include <Graphic3d_LODManager.hxx>
+
+class OpenGl_LODManager : public Graphic3d_LODManager
+{
+public:
+ Standard_EXPORT OpenGl_LODManager (const Handle(Graphic3d_Structure)& theParentStructure);
+
+ Standard_EXPORT virtual ~OpenGl_LODManager() {};
+
+ Standard_EXPORT virtual Handle(Graphic3d_LOD)& AddNewLOD() Standard_OVERRIDE;
+
+ DEFINE_STANDARD_RTTI (OpenGl_LODManager, Graphic3d_LODManager)
+
+protected:
+ Standard_EXPORT virtual void sortLODs() Standard_OVERRIDE;
+};
+
+DEFINE_STANDARD_HANDLE (OpenGl_LODManager, Graphic3d_LODManager)
+
+#endif // _OpenGl_LODManager_Header
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_LOD.hxx>
+#include <OpenGl_LODManager.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_StructureShadow.hxx>
#include <OpenGl_Workspace.hxx>
#include <Graphic3d_SequenceOfHClipPlane.hxx>
+#include <Graphic3d_LODManager.hxx>
//! Auxiliary class for bounding box presentation
myIsRaytracable (Standard_False),
myModificationState (0),
myIsCulled (Standard_True),
- myIsMirrored (Standard_False),
- myCurrentLodId (-1)
+ myIsMirrored (Standard_False)
{
//
}
// function : NewLOD
// purpose :
// =======================================================================
-Handle(Graphic3d_LOD) OpenGl_Structure::NewLOD()
+Handle(Graphic3d_LOD) OpenGl_Structure::NewLOD (const Handle(Graphic3d_Structure)& theStruct)
{
- Handle(OpenGl_LOD) aLOD = new OpenGl_LOD();
- myLODVec.Append (aLOD);
- return aLOD;
+ if (myLODManager.IsNull())
+ {
+ myLODManager = new OpenGl_LODManager (theStruct);
+ }
+ return myLODManager->AddNewLOD();
}
// =======================================================================
return;
}
- Handle(OpenGl_LOD) aLODToRender;
- if (myLODVec.Size() > 0)
- {
- findCurrentLOD (theWorkspace);
- if (myCurrentLodId == -1)
- return;
- aLODToRender = myLODVec.Value (myCurrentLodId);
- }
+ if (!myLODManager.IsNull() && myLODManager->GetCurrentLODIdx (theWorkspace->View()->Camera()) == -1)
+ return;
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
}
// Render groups
- const Graphic3d_SequenceOfGroup& aGroups = !aLODToRender.IsNull() ? aLODToRender->DrawGroups() : DrawGroups();
+ const Graphic3d_SequenceOfGroup& aGroups = DrawGroups();
for (OpenGl_Structure::GroupIterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next())
{
aGroupIter.Value()->Render (theWorkspace);
}
//=======================================================================
-//function : binSearchLOD
+//function : SetDetailLevelRange
//purpose :
//=======================================================================
-Standard_Integer OpenGl_Structure::binSearchLOD (const Standard_Integer theFirst,
- const Standard_Integer theLast,
- const Standard_Real theMetrics) const
+void OpenGl_Structure::SetDetailLevelRange (const Standard_Integer theIdOfLOD,
+ const Standard_Real theFrom,
+ const Standard_Real theTo)
{
- if (theFirst > theLast)
- return -1;
- else
- {
- Standard_Integer aMid = (theFirst + theLast) / 2;
+ Standard_ASSERT_RAISE (theFrom < theTo,
+ "The upper boundary of the interval must be greater than lower one!");
- if (myLODVec.Value (aMid)->GetRange().IsIn (theMetrics))
- return aMid;
- else
- if (myLODVec.Value (aMid)->GetRange().IsLess (theMetrics))
- return binSearchLOD (aMid + 1, theLast, theMetrics);
- else
- return binSearchLOD (theFirst, aMid - 1, theMetrics);
- }
+ if (theIdOfLOD < 0 || theIdOfLOD > myLODManager->NbOfDetailLevels())
+ return;
+
+ myLODManager->SetRange (theIdOfLOD, theFrom, theTo);
}
//=======================================================================
-//function : findCurrentLOD
+//function : DrawGroups
//purpose :
//=======================================================================
-void OpenGl_Structure::findCurrentLOD (const Handle(OpenGl_Workspace)& theWorkspace) const
+const Graphic3d_SequenceOfGroup& OpenGl_Structure::DrawGroups() const
{
- Standard_Real aMetric = myLODVec.Value (0)->ComputeMetrics (theWorkspace->View()->Camera(), this);
- std::cout << aMetric << std::endl;
- if (myCurrentLodId != -1 && myLODVec.Value (myCurrentLodId)->GetRange().IsIn (aMetric))
- return;
-
- if (myLODVec.Last()->GetRange().IsGreater (aMetric))
- {
- myCurrentLodId = myLODVec.Size() - 1;
- return;
- }
-
- myCurrentLodId = binSearchLOD (0, (Standard_Integer)myLODVec.Size() - 1, aMetric);
+ return myLODManager.IsNull() ? myGroups : myLODManager->GetCurrentGroups();
}
//=======================================================================
-//function : SetDetailLevelRange
+//function : NbDetailLevels
//purpose :
//=======================================================================
-void OpenGl_Structure::SetDetailLevelRange (const Standard_Integer theIdOfLOD,
- const Standard_Real theFrom,
- const Standard_Real theTo)
+Standard_Integer OpenGl_Structure::NbDetailLevels() const
{
- Standard_ASSERT_RAISE (theFrom < theTo,
- "The upper boundary of the interval must be greater than lower one!");
-
- if (theIdOfLOD < 0 || theIdOfLOD > myLODVec.Size())
- return;
-
- myLODVec.Value( theIdOfLOD)->SetRange (theFrom, theTo);
- std::sort (myLODVec.begin(), myLODVec.end(), IsLessLOD());
+ return myLODManager->NbOfDetailLevels();
}
Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct);
//! Create new LOD within this structure
- Standard_EXPORT virtual Handle(Graphic3d_LOD) NewLOD() Standard_OVERRIDE;
+ Standard_EXPORT virtual Handle(Graphic3d_LOD) NewLOD (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
//! Remove group from this structure
Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup);
public:
//! @return graphic groups
- virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
- {
- return myGroups;
- }
+ virtual const Graphic3d_SequenceOfGroup& DrawGroups() const;
//! Access graphic driver
OpenGl_GraphicDriver* GlDriver() const
//! Is the structure ray-tracable (contains ray-tracable elements)?
Standard_Boolean IsRaytracable() const;
- Standard_EXPORT virtual Standard_Integer NbDetailLevels() const Standard_OVERRIDE
- {
- return (Standard_Integer)myLODVec.Size();
- }
+ Standard_EXPORT virtual Standard_Integer NbDetailLevels() const Standard_OVERRIDE;
protected:
//! Updates ray-tracable status for structure and its parents.
void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
-private:
- void findCurrentLOD (const Handle(OpenGl_Workspace)& theWorkspace) const;
- Standard_Integer binSearchLOD (const Standard_Integer theFirst, const Standard_Integer theLast, const Standard_Real theMetrics) const;
-
protected:
OpenGl_Matrix* myTransformation;
Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
-private:
- mutable OpenGl_VectorOfLODs myLODVec;
- mutable Standard_Integer myCurrentLodId;
-
public:
DEFINE_STANDARD_RTTI(OpenGl_Structure, Graphic3d_CStructure) // Type definition
}
Handle(MeshVS_LODDataSource) aLod = new MeshVS_LODDataSource (aSTLMesh);
- aLod->ComputePrs (aMesh);
+ aMesh->AddDataSource (aLod);
Standard_Integer aIdOfLod = aMesh->Presentation()->NbDetailLevels();
aMesh->Presentation()->SetDetailLevelRange (aIdOfLod - 1, aFromRange, aToRange);