]> OCCT Git - occt-copy.git/commitdiff
Bugs of the redesigned version were fixed CR26812
authorvpa <vpa@opencascade.com>
Thu, 26 Nov 2015 17:20:27 +0000 (20:20 +0300)
committervpa <vpa@opencascade.com>
Thu, 26 Nov 2015 17:20:27 +0000 (20:20 +0300)
src/Graphic3d/Graphic3d_LOD.hxx
src/Graphic3d/Graphic3d_LODManager.cxx
src/Graphic3d/Graphic3d_LODManager.hxx
src/MeshVS/MeshVS_LODBuilder.cxx
src/MeshVS/MeshVS_Mesh.cxx
src/OpenGl/OpenGl_LOD.hxx
src/OpenGl/OpenGl_LODManager.cxx
src/OpenGl/OpenGl_LODManager.hxx
src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx
tests/bugs/vis/bug26812

index 04d0eb50796224c002087b33ce57fcfc7bba11fe..affb449a777a521a7a0c297a3819ccc360a2cc7f 100644 (file)
@@ -41,7 +41,7 @@ public:
 
   Standard_Boolean IsLess (const Standard_Real theVal) const
   {
-    return myFrom < theVal;
+    return theVal < myFrom;
   }
 
   Standard_Boolean IsGreater (const Standard_Real theVal) const
index dcbaa2938fc6a4f3232b3b374166073b95722b90..7f2a3ed05bcec540e2f704e5414538f896fd8ba1 100644 (file)
@@ -39,20 +39,25 @@ Standard_Integer Graphic3d_LODManager::GetCurrentLODIdx (const Handle(Graphic3d_
   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 = -1;
+  }
+  else if (myLODs.Value (myLODs.Size() - 1)->GetRange().IsGreater (aMetric))
+  {
+    myCurrentLODIdx = myLODs.Size() - 1;
+  }
+  else
+  {
+    for (Standard_Integer aLodIdx = 0; aLodIdx < myLODs.Size(); ++aLodIdx)
     {
-      myCurrentLODIdx = aLodIdx;
-      break;
+      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;
 }
 
@@ -65,6 +70,7 @@ void Graphic3d_LODManager::SetRange (const Standard_Integer theLodIdx,
                                      const Standard_Real theTo)
 {
   myLODs.ChangeValue (theLodIdx)->SetRange (theFrom, theTo);
+  sortLODs();
 }
 
 //=======================================================================
index 570f089e4189649b93044794d8161c72a1aaaf4f..61c3e09ede240c288ad4a3a8aaa11f135eed74b1 100644 (file)
@@ -51,7 +51,7 @@ public:
 
   Standard_EXPORT const Graphic3d_SequenceOfGroup& GetCurrentGroups() const;
 
-  Standard_EXPORT virtual Handle(Graphic3d_LOD)& AddNewLOD() = 0;
+  Standard_EXPORT virtual Handle(Graphic3d_LOD) AddNewLOD() = 0;
 
   DEFINE_STANDARD_RTTI (Graphic3d_LODManager, Standard_Transient)
 
index ba7cb27009490c6033aba2809292e601af9e09e6..eaed5f24e8af1ab536b73919427973426e4e4470 100644 (file)
@@ -36,9 +36,7 @@ MeshVS_LODBuilder::MeshVS_LODBuilder (const Handle(MeshVS_Mesh)& theParentMesh,
                                       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
index fdcb32b7bb9acb687dc675bb56ff35de3436f015..39a173304f42b4e622997afa1ee7e44b4eca87bb 100644 (file)
@@ -169,14 +169,12 @@ void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMg
 
   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))
+      if (!Handle(MeshVS_LODBuilder)::DownCast (aCurrent).IsNull())
       {
-        aLODBldr = Handle(MeshVS_LODBuilder)::DownCast (aCurrent);
         continue;
       }
       if ( !aCurrent.IsNull() && aCurrent->TestFlags ( theMode ) )
@@ -189,16 +187,20 @@ void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMg
       }
     }
 
-  if (myLODDataSources.Size() > 0 && !aLODBldr.IsNull() && aLODBldr->TestFlags (theMode))
+  if (myLODDataSources.Size() > 0)
   {
-    for (Standard_Integer aLodIdx = 0; aLodIdx < myLODDataSources.Size(); ++aLodIdx)
+    for (Standard_Integer aLodBldrIdx = 1; aLodBldrIdx <= myBuilders.Length(); ++aLodBldrIdx)
     {
-      const TColStd_PackedMapOfInteger aVertIdxs = myLODDataSources.Value (aLodIdx)->GetAllNodes();
-      const TColStd_PackedMapOfInteger aTrgIdxs = myLODDataSources.Value (aLodIdx)->GetAllElements();
+      const Handle(MeshVS_LODBuilder) aLodBldr = Handle(MeshVS_LODBuilder)::DownCast (myBuilders.Value (aLodBldrIdx));
+      if (aLodBldr.IsNull() || !aLodBldr->TestFlags (theMode))
+        continue;
+
+      const TColStd_PackedMapOfInteger aVertIdxs = aLodBldr->GetDataSource()->GetAllNodes();
+      const TColStd_PackedMapOfInteger aTrgIdxs = aLodBldr->GetDataSource()->GetAllElements();
       if (HasNodes)
-        aLODBldr->Build (thePresentation, aVertIdxs, aNodesToExclude, Standard_False, theMode);
+        aLodBldr->Build (thePresentation, aVertIdxs, aNodesToExclude, Standard_False, theMode);
       if (HasElements)
-        aLODBldr->Build (thePresentation, aTrgIdxs, aElemsToExclude, Standard_True,  theMode);
+        aLodBldr->Build (thePresentation, aTrgIdxs, aElemsToExclude, Standard_True,  theMode);
     }
   }
 
index b6b4a5999048c6f0a6459a20e5277be9db9fdd7f..e90a1ddf200cc4206b2d1fe000ad4887a94dbf53 100644 (file)
@@ -35,6 +35,4 @@ public:
 
 DEFINE_STANDARD_HANDLE (OpenGl_LOD, Graphic3d_LOD)
 
-#include <OpenGl_LOD.lxx>
-
 #endif // _OpenGl_LOD_Header
index 2fa7c202df17e0446e45d659dbca7e8c300369a5..cbc19d762c594ff0e93d4457766150fc8055089c 100644 (file)
@@ -57,7 +57,7 @@ OpenGl_LODManager::OpenGl_LODManager (const Handle(Graphic3d_Structure)& thePare
 // function : AddNewLOD
 // purpose  :
 //=======================================================================
-Handle(Graphic3d_LOD)& OpenGl_LODManager::AddNewLOD()
+Handle(Graphic3d_LOD) OpenGl_LODManager::AddNewLOD()
 {
   Handle(Graphic3d_LOD) aNewLOD = new OpenGl_LOD();
   myLODs.Append (aNewLOD);
index 914525a14f1b05901c590d279e7f75af2e3d66fb..1d43b1ccfcba3c4718a4fe5376bf5d26a9c1e2d4 100644 (file)
@@ -25,7 +25,7 @@ public:
 
   Standard_EXPORT virtual ~OpenGl_LODManager() {};
 
-  Standard_EXPORT virtual Handle(Graphic3d_LOD)& AddNewLOD() Standard_OVERRIDE;
+  Standard_EXPORT virtual Handle(Graphic3d_LOD) AddNewLOD() Standard_OVERRIDE;
 
   DEFINE_STANDARD_RTTI (OpenGl_LODManager, Graphic3d_LODManager)
 
index 3fcaf9f9a20ed2fc2668f3833aa8e63916bbab89..957323cc0ffd080d3c0f6e959451cee09d35950a 100644 (file)
@@ -1419,11 +1419,26 @@ static int MeshGenLods (Draw_Interpretor& theDI,
   return 0;
 }
 
+#include <MeshVS_LODBuilder.hxx>
 static int MeshLod (Draw_Interpretor& theDI,
                     Standard_Integer  theArgNum,
                     const char**      theArgs)
 {
-  if (theArgNum < 6)
+  struct DetailLevelData
+  {
+  public:
+    DetailLevelData()
+      : myMesh (NULL),
+        myFrom (-DBL_MAX),
+        myTo (DBL_MAX) {}
+
+  public:
+    Handle(StlMesh_Mesh) myMesh;
+    Standard_Real        myFrom;
+    Standard_Real        myTo;
+  };
+
+  if (theArgNum < 3)
   {
     std::cout << "Error! Wrong number of arguments. See usage:\n";
     theDI.PrintHelp (theArgs[0]);
@@ -1438,58 +1453,103 @@ static int MeshLod (Draw_Interpretor& theDI,
   }
 
   Standard_CString aShapeName = theArgs[1];
-  if (!GetMapOfAIS().IsBound2 (aShapeName))
+  if (GetMapOfAIS().IsBound2 (aShapeName))
   {
-    std::cout << "Error! No interactive object with the name " << aShapeName << "." << std::endl;
+    std::cout << "Error! The context already has an interactive object with the name " << aShapeName << "." << std::endl;
     return 1;
   }
-  Handle(MeshVS_Mesh) aMesh = Handle(MeshVS_Mesh)::DownCast (GetMapOfAIS().Find2 (aShapeName));
-  if (aMesh.IsNull())
+  const TCollection_AsciiString aPathToLODInfo = Draw::Atoi (theArgs[2]);
+  if (aPathToLODInfo == "")
   {
-    std::cout << "Error! No mesh with the name " << aShapeName << "." << std::endl;
+    std::cout << "Error! Path to LOD info must not be empty!" << std::endl;
     return 1;
   }
-  const TCollection_AsciiString aPathToLOD = Draw::Atoi (theArgs[3]);
-  if (aPathToLOD == "")
-  {
-    std::cout << "Error! Path to LOD must not be empty!" << std::endl;
-    return 1;
-  }
-  Standard_Real aFromRange = -DBL_MAX;
-  Standard_Real aToRange = DBL_MAX;
-  for (Standard_Integer anArgIdx = 4; anArgIdx < theArgNum; ++anArgIdx)
+
+  std::ifstream aLODInfoFile (theArgs[2]);
+  NCollection_List<DetailLevelData> myLODDataList;
+  Handle(StlMesh_Mesh) aLargestMesh;
+  for (std::string aLODInfoStr; getline (aLODInfoFile, aLODInfoStr);)
   {
-    TCollection_AsciiString anArg (theArgs[anArgIdx]);
-    anArg.LowerCase();
-    if (anArg == "-from")
+    DetailLevelData aData;
+    std::istringstream aStream (aLODInfoStr);
+    std::vector<std::string> aTokens;
+    std::copy (std::istream_iterator<std::string> (aStream),
+               std::istream_iterator<std::string>(),
+               std::back_inserter (aTokens));
+    for (Standard_Integer aTokenIdx = 0; aTokenIdx < aTokens.size(); ++aTokenIdx)
     {
-      aFromRange = Draw::Atof (theArgs[++anArgIdx]);
-    }
-    else if (anArg == "-to")
-    {
-      aToRange = Draw::Atof (theArgs[++anArgIdx]);
+      if (aTokens[aTokenIdx] == "-path")
+      {
+        OSD_Path aFile (aTokens[++aTokenIdx].c_str());
+        Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
+        Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
+        if (aSTLMesh.IsNull())
+        {
+          std::cout << "Error! Can not read LOD located at the path: " << aTokens[aTokenIdx] << std::endl;
+          return 1;
+        }
+        aData.myMesh = aSTLMesh;
+        if (aLargestMesh.IsNull() || aSTLMesh->Triangles().Length() > aLargestMesh->Triangles().Length())
+        {
+          aLargestMesh = aSTLMesh;
+        }
+      }
+      else if (aTokens[aTokenIdx] == "-from")
+      {
+        aData.myFrom = Draw::Atof (aTokens[++aTokenIdx].c_str());
+      }
+      else if (aTokens[aTokenIdx] == "-to")
+      {
+        aData.myTo = Draw::Atof (aTokens[++aTokenIdx].c_str());
+      }
     }
+    myLODDataList.Append (aData);
   }
-  if (aFromRange > aToRange)
+
+  if (aLargestMesh.IsNull())
   {
-    std::cout << "Error! From range must be less than to! Current values are:" << std::endl;
-    std::cout << "from: " << aFromRange << "; to: " << aToRange << std::endl;
+    std::cout << "Error! No meshes found in lod info file!" << std::endl;
     return 1;
   }
 
-  OSD_Path aFile (theArgs[3]);
-  Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
-  Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
-  if (aSTLMesh.IsNull())
+  Handle(MeshVS_Mesh) anOriginMesh = new MeshVS_Mesh();
+  Handle(XSDRAWSTLVRML_DataSource) anOriginDataSource = new XSDRAWSTLVRML_DataSource (aLargestMesh);
+  anOriginMesh->SetDataSource (anOriginDataSource);
+  Handle(MeshVS_MeshPrsBuilder) anOriginBuilder = new MeshVS_MeshPrsBuilder (anOriginMesh.operator->());
+  anOriginMesh->AddBuilder (anOriginBuilder, Standard_True);
+  anOriginMesh->GetDrawer()->SetColor (MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW);
+
+  for (NCollection_List<DetailLevelData>::Iterator aLodDataIter (myLODDataList); aLodDataIter.More(); aLodDataIter.Next())
   {
-    std::cout << "Error! Can not read LOD located at the path: " << aPathToLOD << std::endl;
-    return 1;
+    Handle(MeshVS_LODDataSource) aLod = new MeshVS_LODDataSource (aLodDataIter.Value().myMesh);
+    anOriginMesh->AddDataSource (aLod);
+    Handle(MeshVS_LODBuilder) aLODBuilder = new MeshVS_LODBuilder (anOriginMesh.operator->());
+    aLODBuilder->SetDataSource (aLod);
+    aLODBuilder->SetDrawer (anOriginBuilder->GetDrawer());
+    anOriginMesh->AddBuilder (aLODBuilder);
   }
 
-  Handle(MeshVS_LODDataSource) aLod = new MeshVS_LODDataSource (aSTLMesh);
-  aMesh->AddDataSource (aLod);
-  Standard_Integer aIdOfLod = aMesh->Presentation()->NbDetailLevels();
-  aMesh->Presentation()->SetDetailLevelRange (aIdOfLod - 1, aFromRange, aToRange);
+  // Hide all nodes by default
+  Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
+  Standard_Integer aLen = aLargestMesh->Vertices().Length();
+  for (Standard_Integer anIndex = 1; anIndex <= aLen; ++anIndex)
+    aNodes->ChangeMap().Add (anIndex);
+  anOriginMesh->SetHiddenNodes (aNodes);
+  anOriginMesh->SetSelectableNodes (aNodes);
+
+  VDisplayAISObject (aShapeName, anOriginMesh);
+  aCtx->Deactivate (anOriginMesh);
+
+  Standard_Integer aLodIdx = 0;
+  for (NCollection_List<DetailLevelData>::Iterator aLodDataIter (myLODDataList); aLodDataIter.More(); aLodDataIter.Next())
+  {
+    anOriginMesh->Presentation()->SetDetailLevelRange (aLodIdx, aLodDataIter.Value().myFrom, aLodDataIter.Value().myTo);
+  }
+
+  Draw::Set (aShapeName, new XSDRAWSTLVRML_DrawableMesh (anOriginMesh));
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  if (!aView.IsNull())
+    aView->FitAll();
 
   return 0;
 }
@@ -1532,8 +1592,15 @@ void  XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
                    "\n\t\t: [-debug] enables printing of meshing status and each LOD's info.",
                    __FILE__, MeshGenLods, g);
   theCommands.Add ("meshlod",
-                   "meshlod shapeName [-path pathToLOD] [-from rangeFrom] [-to rangeTo]"
-                   "\n\t\t: Adds LOD to the shape with shapeName. It will be visible in range [rangeFrom; rangeTo]."
+                   "meshlod shapeName pathToFileWithLodInfo"
+                   "\n\t\t: Creates an object with the name shapeName that has LODs described in file stored at"
+                   "\n\t\t: pathToFileWithLodInfo. Each string in the file is a full description of LOD. It must"
+                   "\n\t\t: be filled using the following form:"
+                   "\n\t\t: -path pathToLOD [-from fromRange] [-to toRange], where"
+                   "\n\t\t: pathToLOD is a path to STL file with LOD mesh, fromRange and toRange define a depth"
+                   "\n\t\t: range where the LOD will be visible. Each of range parameters is optional, but in this"
+                   "\n\t\t: case, it will be equal to positive and negative max double correspondingly."
+                   "\n\t\t: It is assumed that ranges are non-overlapping segments of the real axis."
                    __FILE__, MeshLod, g);
 }
 
index d9ba0e54693b4d434110a2cee0be969e77ce8689..cb93e21b9d65510a0c990790bad0e1e6fc12b27b 100644 (file)
@@ -3,18 +3,7 @@ set aTmpFolder ""
 
 pload ALL
 vinit
-# restore $aPathToData/occ/fuse.brep f
-# vdisplay f
-# restore $aTmpFolder/bearing.brep f
-meshfromstl m $aTmpFolder/bearing.stl
-# restore $aTmpFolder/bearing.brep f
-# vdisplay f
-# meshfromstl f $aPathToData/stl/bearing.stl
-vfit
-# meshgenlods f 2 -debug -mesh m -save D:/OCCT-tests/LOD
-meshlod m -path $aTmpFolder/f_LOD0.stl -from 0.5 -to 1
-meshlod m -path $aTmpFolder/f_LOD1.stl -from 1 -to 3
-
+meshlod m $aTmpFolder/lod_data.txt
 
 ##########################################################################
 # to generate brep file for LODs generaion, it is requred to use