0025540: Visualization - discretization of the circle differs in shaded and wireframe...
authorosa <osa@opencascade.com>
Thu, 5 Mar 2015 11:05:11 +0000 (14:05 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 5 Mar 2015 12:58:26 +0000 (15:58 +0300)
1. "HilightDrawer" were added to SelectMgr_SelectableObject.
2. Static drawer in StdSelect_Shape was replaced by class member. It's value is taken from special HilightDrawer of Selectable() object.
3. Computed relative deflection is stored as absolute deflection to be used for sub-shapes.
4. The ColoredShape object was updated to use for sub-shapes relative deflection computed for main shape.
5. Test case was added.

Tuning of test-case bug25532

13 files changed:
src/AIS/AIS_ColoredShape.cxx
src/AIS/AIS_LocalContext_1.cxx
src/Prs3d/Prs3d.cdl
src/Prs3d/Prs3d.cxx
src/SelectMgr/SelectMgr_SelectableObject.cdl
src/SelectMgr/SelectMgr_SelectableObject.cxx
src/SelectMgr/SelectMgr_SelectableObject.lxx
src/StdPrs/StdPrs_ShadedShape.cxx
src/StdSelect/StdSelect_BRepOwner.cxx
src/StdSelect/StdSelect_Shape.cdl
src/StdSelect/StdSelect_Shape.cxx
tests/bugs/vis/bug25532
tests/bugs/vis/bug25540 [new file with mode: 0644]

index 5d0f8d9..46a2880 100644 (file)
@@ -36,7 +36,6 @@
 #include <StdPrs_ShadedShape.hxx>
 #include <StdPrs_ToolShadedShape.hxx>
 #include <StdPrs_WFDeflectionShape.hxx>
-#include <StdPrs_WFShape.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Compound.hxx>
@@ -321,6 +320,15 @@ void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
       }
       StdPrs_ShadedShape::Tessellate (myshape, myDrawer);
     }
+    // After this call if type of deflection is relative
+    // computed deflection coefficient is stored as absolute.
+    StdPrs_ShadedShape::Tessellate (myshape, myDrawer);
+  }
+  else // WireFrame mode
+  {
+    // After this call if type of deflection is relative
+    // computed deflection coefficient is stored as absolute.
+    Prs3d::GetDeflection (myshape, myDrawer);
   }
 
   TopoDS_Compound anOpened, aClosed;
@@ -395,6 +403,12 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation
         aDrawer = myDrawer;
       }
 
+      // It is supposed that absolute deflection contains previously computed relative deflection
+      // (if deflection type is relative).
+      // In case of CustomDrawer it is taken from Link().
+      Aspect_TypeOfDeflection aPrevType = aDrawer->TypeOfDeflection();
+      aDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
+
       // Draw each kind of subshapes and personal-colored shapes in a separate group
       // since it's necessary to set transparency/material for all subshapes
       // without affecting their unique colors
@@ -408,6 +422,7 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation
       {
         StdPrs_WFDeflectionShape::Add (thePrs, aShapeDraw, aDrawer);
       }
+      aDrawer->SetTypeOfDeflection (aPrevType);
     }
   }
 }
index 13042c5..cbf86d8 100644 (file)
@@ -28,7 +28,6 @@
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_ShadingAspect.hxx>
 #include <AIS_LocalStatus.hxx>
-#include <StdPrs_WFShape.hxx>
 #include <Graphic3d_ArrayOfTriangles.hxx>
 #include <Graphic3d_Group.hxx>
 #include <Select3D_SensitiveTriangulation.hxx>
index 1563502..da879ef 100644 (file)
@@ -155,6 +155,8 @@ is
   --   deviation coefficient from theDrawer and the shape's bounding box;</li>
   -- <li><b>Aspect_TOD_ABSOLUTE</b>: the maximal chordial deviation from theDrawer is returned.</li>
   -- </ul>
+  -- In case of the type of deflection in theDrawer computed relative deflection for shape
+  -- is stored as absolute deflection. It is necessary to use it later on for sub-shapes.
   -- This function should always be used to compute the deflection value for building
   -- discrete representations of the shape (triangualtion, wireframe) to avoid incosistencies
   -- between different representations of the shape and undesirable visual artifacts.
index db6b09d..c1f22c4 100644 (file)
@@ -69,6 +69,9 @@ Standard_Real Prs3d::GetDeflection (const TopoDS_Shape&         theShape,
       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
       aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
       aDeflection = MAX3 (aXmax-aXmin, aYmax-aYmin, aZmax-aZmin) * theDrawer->DeviationCoefficient() * 4.0;
+      // we store computed relative deflection of shape as absolute deviation coefficient
+      // in case relative type to use it later on for sub-shapes.
+      theDrawer->SetMaximalChordialDeviation (aDeflection);
     }
   }
   return aDeflection;
index e011f98..1c889c0 100644 (file)
@@ -198,10 +198,25 @@ is
     UnsetAttributes(me:mutable) is virtual;
        ---Purpose: Clears settings provided by the drawing tool theDrawer.
 
+    SetHilightAttributes(me:mutable; theDrawer: Drawer from Prs3d) is virtual;
+       ---Purpose: Initializes the hilight drawing tool theDrawer.
+
+    HilightAttributes(me) returns any Drawer from Prs3d;
+       ---C++: return const&
+       ---C++:  inline
+       ---Purpose: Returns the hilight attributes settings.
+
+    UnsetHilightAttributes(me:mutable) is virtual;
+       ---Purpose: Clears settings provided by the hilight drawing tool theDrawer.
+
+    InitDefaultHilightAttributes(myclass; theDrawer : Drawer from Prs3d);
+       ---Purpose: Initializes theDrawer by default hilight settings.
+
 fields
 
     myselections        : SequenceOfSelection is protected;
     myDrawer            : Drawer from Prs3d is protected;
+    myHilightDrawer     : Drawer from Prs3d is protected;
     mycurrent           : Integer;
     myAutoHilight       : Boolean from Standard;
 
index c65ba20..4a0d3a7 100644 (file)
 #include <SelectMgr_EntityOwner.hxx>
 #include <PrsMgr_PresentationManager3d.hxx>
 #include <Prs3d_Drawer.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Aspect_TypeOfMarker.hxx>
+#include <Prs3d_PlaneAspect.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
 
 #include <TopLoc_Location.hxx>
 #include <gp_Pnt.hxx>
@@ -47,8 +53,12 @@ static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
 SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
   PrsMgr_PresentableObject (aTypeOfPresentation3d),
   myDrawer                 (new Prs3d_Drawer()),
+  myHilightDrawer          (new Prs3d_Drawer()),
   myAutoHilight            (Standard_True)
-{}
+{
+  InitDefaultHilightAttributes (myHilightDrawer);
+  myHilightDrawer->Link (myDrawer);
+}
 
 
 //==================================================
@@ -378,3 +388,93 @@ void SelectMgr_SelectableObject::UnsetAttributes()
   myDrawer = aDrawer;
 }
 
+//=======================================================================
+//function : SetHilightAttributes
+//purpose  :
+//=======================================================================
+void SelectMgr_SelectableObject::SetHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer)
+{
+  myHilightDrawer = theDrawer;
+}
+
+//=======================================================================
+//function : UnsetAttributes
+//purpose  :
+//=======================================================================
+void SelectMgr_SelectableObject::UnsetHilightAttributes()
+{
+  Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer();
+  InitDefaultHilightAttributes (aDrawer);
+  aDrawer->Link (myDrawer);
+  myHilightDrawer = aDrawer;
+}
+
+//=======================================================================
+//function : InitDefaultHilightAttributes
+//purpose  :
+//=======================================================================
+void SelectMgr_SelectableObject::InitDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer)
+{
+  if (!theDrawer->HasOwnPointAspect())
+  {
+    theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
+    if (theDrawer->HasLink())
+    {
+      *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
+    }
+  }
+  if (!theDrawer->HasOwnLineAspect())
+  {
+    theDrawer->SetLineAspect  (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
+    if (theDrawer->HasLink())
+    {
+      *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
+    }
+  }
+  if (!theDrawer->HasOwnWireAspect())
+  {
+    theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
+    if (theDrawer->HasLink())
+    {
+      *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
+    }
+  }
+  if (!theDrawer->HasOwnPlaneAspect())
+  {
+    theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
+    if (theDrawer->HasLink())
+    {
+      *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
+    }
+  }
+  if (!theDrawer->HasOwnFreeBoundaryAspect())
+  {
+    theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
+    if (theDrawer->HasLink())
+    {
+      *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
+    }
+  }
+  if (!theDrawer->HasOwnUnFreeBoundaryAspect())
+  {
+    theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
+    if (theDrawer->HasLink())
+    {
+      *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
+    }
+  }
+
+  theDrawer->WireAspect()->SetWidth(2.);
+  theDrawer->LineAspect()->SetWidth(2.);
+  theDrawer->PlaneAspect()->EdgesAspect()->SetWidth(2.);
+  theDrawer->FreeBoundaryAspect()->SetWidth(2.);
+  theDrawer->UnFreeBoundaryAspect()->SetWidth(2.);
+  theDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_POINT);
+  theDrawer->PointAspect()->SetScale(2.);
+
+  // By default the hilight drawer has absolute type of deflection.
+  // It is supposed that absolute deflection is taken from Link().
+  // It is necessary to use for all sub-shapes identical coefficient
+  // computed in ::Compute() call for whole shape and stored in base drawer.
+  theDrawer->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
+}
index f140d68..31ddd4a 100644 (file)
@@ -29,3 +29,6 @@ inline const Handle(Prs3d_Drawer)& SelectMgr_SelectableObject::
 Attributes() const
 {return myDrawer;}
 
+inline const Handle(Prs3d_Drawer)& SelectMgr_SelectableObject::
+HilightAttributes() const
+{return myHilightDrawer;}
index 3ddef99..3a9ac5e 100644 (file)
@@ -74,7 +74,7 @@ namespace
     if (!aShapeIter.More())
     {
       // compound contains no shaded elements at all
-      StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
+      StdPrs_WFDeflectionShape::Add (thePrs, theShape, theDrawer);
       return;
     }
 
@@ -103,7 +103,7 @@ namespace
     }
     if (hasElement)
     {
-      StdPrs_WFShape::Add (thePrs, aCompoundWF, theDrawer);
+      StdPrs_WFDeflectionShape::Add (thePrs, aCompoundWF, theDrawer);
     }
   }
 
index fb3feff..41af9cd 100644 (file)
 // commercial license or contractual agreement.
 
 #include <StdSelect_BRepOwner.ixx>
-#include <SelectBasics_EntityOwner.hxx>
-
-#include <StdPrs_WFShape.hxx>
 
 #include <Graphic3d_StructureManager.hxx>
+#include <Prs3d_Drawer.hxx>
+#include <SelectBasics_EntityOwner.hxx>
 
 //==================================================
 // Function: 
@@ -88,10 +87,21 @@ void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM,
         myPrsSh.Nullify();
     }
 
+    Handle(Prs3d_Drawer) aDrawer;
+    if (!aSel.IsNull())
+    {
+      aDrawer = aSel->HilightAttributes();
+    }
+    else
+    {
+      aDrawer = new Prs3d_Drawer();
+      SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer);
+    }
+
     // generate new presentable shape
     if (myPrsSh.IsNull())
     {
-      myPrsSh = new StdSelect_Shape (myShape);
+      myPrsSh = new StdSelect_Shape (myShape, aDrawer);
     }
     if (!aSel.IsNull())
     {
@@ -100,7 +110,6 @@ void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM,
 
     // highlight and set layer
     PM->Highlight (myPrsSh, M);
-
   }  
   else
   {
@@ -131,6 +140,17 @@ void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManag
         myPrsSh.Nullify();
     }
 
+    Handle(Prs3d_Drawer) aDrawer;
+    if (!aSel.IsNull())
+    {
+      aDrawer = aSel->HilightAttributes();
+    }
+    else
+    {
+      aDrawer = new Prs3d_Drawer();
+      SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer);
+    }
+
     // generate new presentable shape
     if(myPrsSh.IsNull())
     {
@@ -138,10 +158,10 @@ void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManag
       {
         TopLoc_Location lbid = Location() * myShape.Location();
         TopoDS_Shape ShBis = myShape.Located(lbid);
-        myPrsSh = new StdSelect_Shape(ShBis);
+        myPrsSh = new StdSelect_Shape(ShBis, aDrawer);
       }
       else
-        myPrsSh = new StdSelect_Shape(myShape);
+        myPrsSh = new StdSelect_Shape(myShape, aDrawer);
     }
     if (!aSel.IsNull())
     {
index fc3d7ff..372b6ea 100644 (file)
@@ -23,10 +23,12 @@ uses
     Transformation        from Geom,
     Shape                 from TopoDS,
     PresentationManager3d from PrsMgr,
+    Drawer                from Prs3d,
     Presentation          from Prs3d
 
 is
-    Create(Sh:Shape from TopoDS) returns Shape from StdSelect;
+    Create(theShape  : Shape from TopoDS;
+           theDrawer : Drawer from Prs3d) returns Shape from StdSelect;
     
     Compute(me:mutable;
                aPresentationManager: PresentationManager3d from PrsMgr;
@@ -61,5 +63,6 @@ is
        ---C++: inline
 
 fields
-    mysh : Shape  from TopoDS;
+    mysh     : Shape  from TopoDS;
+    myDrawer : Drawer from Prs3d;
 end Shape;
index 90e8ea2..b81a292 100644 (file)
 // commercial license or contractual agreement.
 
 #include <StdSelect_Shape.ixx>
-#include <StdPrs_WFShape.hxx>
-#include <Prs3d_LineAspect.hxx>
-#include <Prs3d_PointAspect.hxx>
-#include <Aspect_TypeOfMarker.hxx>
-#include <Prs3d_PlaneAspect.hxx>
+
 #include <Prs3d_Drawer.hxx>
 #include <StdPrs_ShadedShape.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 
-StdSelect_Shape::StdSelect_Shape(const TopoDS_Shape& sh):
-       mysh(sh)
+StdSelect_Shape::StdSelect_Shape (const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer):
+  mysh     (theShape),
+  myDrawer (theDrawer)
 {}
-     
+
 void StdSelect_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*PM*/,
                              const Handle(Prs3d_Presentation)& P,
                              const Standard_Integer aMode)
 {
-  if(mysh.IsNull()) return;
-  
-  static Handle(Prs3d_Drawer) DRWR;
-  if(DRWR.IsNull()){
-    DRWR = new Prs3d_Drawer();
-    DRWR->WireAspect()->SetWidth(2);
-    DRWR->LineAspect()->SetWidth(2.);
-    DRWR->PlaneAspect()->EdgesAspect()->SetWidth(2.);
-    DRWR->FreeBoundaryAspect()->SetWidth(2.);
-    DRWR->UnFreeBoundaryAspect()->SetWidth(2.);
-    Standard_Integer I = 5;//pour tests...
-    DRWR->PointAspect()->SetTypeOfMarker((Aspect_TypeOfMarker)I);
-    DRWR->PointAspect()->SetScale(2.);
+  if(mysh.IsNull())
+  {
+    return;
   }
-  
+
   Standard_Boolean CanShade = (mysh.ShapeType()<5 || mysh.ShapeType()==8);
   if(aMode==1){
     if(CanShade)
-      StdPrs_ShadedShape::Add(P,mysh,DRWR);
+      StdPrs_ShadedShape::Add (P, mysh, myDrawer);
     else
-      StdPrs_WFShape::Add(P,mysh,DRWR);
+      StdPrs_WFDeflectionShape::Add (P, mysh, myDrawer);
   }
   else if (aMode==0)
-    StdPrs_WFShape::Add(P,mysh,DRWR);
+    StdPrs_WFDeflectionShape::Add (P, mysh, myDrawer);
 }
 
 void StdSelect_Shape::Compute(const Handle(Prs3d_Projector)& aProjector ,
index 3b39479..fbcf94a 100644 (file)
@@ -47,8 +47,8 @@ puts "Clearing   (connected): [expr $aMemClear2 / (1024 * 1024)] MiB"
 
 set aRatio [expr $aMemClear2 / double($aMemClear1)]
 
-# check if the memory difference is greater than 10%
-if [expr $aRatio > 1.1] {
+# check if the memory difference is greater than 20%
+if [expr $aRatio > 1.2] {
     puts "Error : TEST FAILED"
 }
 
diff --git a/tests/bugs/vis/bug25540 b/tests/bugs/vis/bug25540
new file mode 100644 (file)
index 0000000..d5dac3a
--- /dev/null
@@ -0,0 +1,49 @@
+puts "============"
+puts "CR25540"
+puts "Check that the discretization of local selection,"
+puts "wireframe and shaded presentation of shape is identical."
+puts "============"
+puts ""
+
+vinit View1 w=912 h=912
+vclear
+
+# Create object in shaded mode
+vsetdispmode 1
+pcylinder p 1 100
+vdisplay p
+vfit
+
+# Setup field of view
+vrotate 1 1.5 0
+vfit
+vtranslateview 24 18.5 0
+vzoom 32
+vtranslateview -0.1 -0.6 0
+vzoom 2
+
+vdump $imagedir/${casename}_shaded_pres.png
+
+vmoveto 100 100
+vdump $imagedir/${casename}_h_pres.png
+
+# Activate the local selection by edges and hilight small circle edge.
+# It's discretization should coincide with discretization of whole shape hiligting.
+vsetam 2
+vmoveto 130 80
+vdump $imagedir/${casename}_local_h_pres.png
+
+vunsetam
+
+# Explode object on faces
+explode p F
+# Create colored shape: set another color to one face
+vaspects p -subshapes p_3 -setcolor RED
+
+vsetam 0
+vmoveto 100 100
+vdump $imagedir/${casename}_h_sub_pres.png
+
+vsetam 2
+vmoveto 130 80
+vdump $imagedir/${casename}_local_h_sub_pres.png