From: vpa Date: Thu, 26 Nov 2015 17:20:27 +0000 (+0300) Subject: Bugs of the redesigned version were fixed X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=b720f78482709595dff78e7c762949274f0b863b;p=occt-copy.git Bugs of the redesigned version were fixed --- diff --git a/src/Graphic3d/Graphic3d_LOD.hxx b/src/Graphic3d/Graphic3d_LOD.hxx index 04d0eb5079..affb449a77 100644 --- a/src/Graphic3d/Graphic3d_LOD.hxx +++ b/src/Graphic3d/Graphic3d_LOD.hxx @@ -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 diff --git a/src/Graphic3d/Graphic3d_LODManager.cxx b/src/Graphic3d/Graphic3d_LODManager.cxx index dcbaa2938f..7f2a3ed05b 100644 --- a/src/Graphic3d/Graphic3d_LODManager.cxx +++ b/src/Graphic3d/Graphic3d_LODManager.cxx @@ -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(); } //======================================================================= diff --git a/src/Graphic3d/Graphic3d_LODManager.hxx b/src/Graphic3d/Graphic3d_LODManager.hxx index 570f089e41..61c3e09ede 100644 --- a/src/Graphic3d/Graphic3d_LODManager.hxx +++ b/src/Graphic3d/Graphic3d_LODManager.hxx @@ -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) diff --git a/src/MeshVS/MeshVS_LODBuilder.cxx b/src/MeshVS/MeshVS_LODBuilder.cxx index ba7cb27009..eaed5f24e8 100644 --- a/src/MeshVS/MeshVS_LODBuilder.cxx +++ b/src/MeshVS/MeshVS_LODBuilder.cxx @@ -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 diff --git a/src/MeshVS/MeshVS_Mesh.cxx b/src/MeshVS/MeshVS_Mesh.cxx index fdcb32b7bb..39a173304f 100644 --- a/src/MeshVS/MeshVS_Mesh.cxx +++ b/src/MeshVS/MeshVS_Mesh.cxx @@ -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); } } diff --git a/src/OpenGl/OpenGl_LOD.hxx b/src/OpenGl/OpenGl_LOD.hxx index b6b4a59990..e90a1ddf20 100644 --- a/src/OpenGl/OpenGl_LOD.hxx +++ b/src/OpenGl/OpenGl_LOD.hxx @@ -35,6 +35,4 @@ public: DEFINE_STANDARD_HANDLE (OpenGl_LOD, Graphic3d_LOD) -#include - #endif // _OpenGl_LOD_Header diff --git a/src/OpenGl/OpenGl_LODManager.cxx b/src/OpenGl/OpenGl_LODManager.cxx index 2fa7c202df..cbc19d762c 100644 --- a/src/OpenGl/OpenGl_LODManager.cxx +++ b/src/OpenGl/OpenGl_LODManager.cxx @@ -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); diff --git a/src/OpenGl/OpenGl_LODManager.hxx b/src/OpenGl/OpenGl_LODManager.hxx index 914525a14f..1d43b1ccfc 100644 --- a/src/OpenGl/OpenGl_LODManager.hxx +++ b/src/OpenGl/OpenGl_LODManager.hxx @@ -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) diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx index 3fcaf9f9a2..957323cc0f 100644 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx @@ -1419,11 +1419,26 @@ static int MeshGenLods (Draw_Interpretor& theDI, return 0; } +#include 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 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 aTokens; + std::copy (std::istream_iterator (aStream), + std::istream_iterator(), + 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::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::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); } diff --git a/tests/bugs/vis/bug26812 b/tests/bugs/vis/bug26812 index d9ba0e5469..cb93e21b9d 100644 --- a/tests/bugs/vis/bug26812 +++ b/tests/bugs/vis/bug26812 @@ -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