]> OCCT Git - occt-copy.git/commitdiff
Implementation of additional Display Mode from IILS contract
authorvsv <vsv@opencascade.com>
Thu, 30 Apr 2020 09:53:42 +0000 (12:53 +0300)
committervsv <vsv@opencascade.com>
Thu, 30 Apr 2020 09:53:42 +0000 (12:53 +0300)
src/IVtk/IVtk_Types.hxx
src/IVtkDraw/IVtkDraw.cxx
src/IVtkOCC/IVtkOCC_ShapeMesher.cxx
src/IVtkTools/IVtkTools_DisplayModeFilter.cxx
src/IVtkTools/IVtkTools_DisplayModeFilter.hxx
tests/v3d/ivtk/boundary_draw [new file with mode: 0644]

index 862222b0cb007059d3036e51c3f27d3b6cb2c8c6..5ae46834d9dbec4f7ece05db4f988ee91224641e 100644 (file)
@@ -86,7 +86,8 @@ typedef enum
   MT_BoundaryEdge  =  4, //!< Boundary edge (related to a single face)
   MT_SharedEdge    =  5, //!< Shared edge (related to several faces)
   MT_WireFrameFace =  6, //!< Wireframe face
-  MT_ShadedFace    =  7  //!< Shaded face
+  MT_ShadedFace    =  7, //!< Shaded face
+  MT_SeamEdge      =  8  //!< Seam edge between faces
 } IVtk_MeshType;
 
 //! @enum IVtk_DisplayMode Display modes for 3D shapes
index 9c517db488fa7c4cf2e0c614afb00920cd16ebdf..b6dabd638e2c8a0dcf07f1cbd2ba45c38b0bb43d 100644 (file)
@@ -719,6 +719,85 @@ static Standard_Integer VtkSetDisplayMode (Draw_Interpretor& theDI,
   return 0;
 }
 
+//================================================================
+// Function  : VtkSetBoundaryDraw
+// Purpose   : 
+// Draw args : ivtksetboundingdraw [name] draw on/off(0,1)
+//================================================================
+static Standard_Integer VtkSetBoundaryDraw(Draw_Interpretor& theDI,
+  Standard_Integer theArgNum,
+  const char** theArgs)
+{
+  // Check viewer
+  if (!GetInteractor()->IsEnabled())
+  {
+    theDI << theArgs[0] << " error: call ivtkinit before\n";
+    return 1; // TCL_ERROR
+  }
+
+  // Check arguments
+  if (theArgNum != 2 && theArgNum != 3)
+  {
+    theDI << theArgs[0] << " error: expects 1 or 2 arguments\n";
+    return 1; // TCL_ERROR
+  }
+
+  vtkSmartPointer<vtkActor> anActor;
+  // Set disp mode for all objects
+  if (theArgNum == 2)
+  {
+    // Get mode
+    Standard_Integer toDraw = Draw::Atoi(theArgs[1]);
+    DoubleMapOfActorsAndNames::Iterator anIter(GetMapOfActors());
+    while (anIter.More())
+    {
+      anActor = anIter.Key1();
+      IVtkTools_ShapeDataSource* aSrc = IVtkTools_ShapeObject::GetShapeSource(anActor);
+      if (aSrc)
+      {
+        IVtkOCC_Shape::Handle anOccShape = aSrc->GetShape();
+        if (!anOccShape.IsNull())
+        {
+          IVtkTools_DisplayModeFilter* aFilter = GetPipeline(anOccShape->GetId())->GetDisplayModeFilter();
+          aFilter->SetDisplayMode(DM_Shading);
+          aFilter->SetFaceBoundaryDraw((toDraw == 0)? false : true);
+          aFilter->Modified();
+          aFilter->Update();
+        }
+      }
+      anIter.Next();
+    }
+  }
+  // Set disp mode for named object
+  else
+  {
+    Standard_Integer toDraw = atoi(theArgs[2]);
+    TCollection_AsciiString aName = theArgs[1];
+    if (GetMapOfActors().IsBound2(aName))
+    {
+      anActor = GetMapOfActors().Find2(aName);
+      vtkSmartPointer<IVtkTools_ShapeDataSource> aSrc = IVtkTools_ShapeObject::GetShapeSource(anActor);
+      if (aSrc)
+      {
+        IVtkOCC_Shape::Handle anOccShape = aSrc->GetShape();
+        if (!anOccShape.IsNull())
+        {
+          IVtkTools_DisplayModeFilter* aFilter = GetPipeline(anOccShape->GetId())->GetDisplayModeFilter();
+          aFilter->SetDisplayMode(DM_Shading);
+          aFilter->SetFaceBoundaryDraw((toDraw == 0) ? false : true);
+          aFilter->Modified();
+          aFilter->Update();
+        }
+      }
+    }
+  }
+
+  // Redraw window
+  GetInteractor()->Render();
+  return 0;
+}
+
+
 //================================================================
 // Function  : VtkSetSelectionMode
 // Purpose   : 
@@ -1198,6 +1277,13 @@ void IVtkDraw::Commands (Draw_Interpretor& theCommands)
     "if name is not defined.",
     __FILE__, VtkSetDisplayMode, group);
 
+  theCommands.Add("ivtksetboundingdraw",
+    "ivtksetboundingdraw usage:\n"
+    "ivtksetboundingdraw [name] draw on/off (0,1)"
+    "\n\t\t: Sets or unsets boundaries drawing for shading display mode to the object with name 'name' or to all objects"
+    "if name is not defined.",
+    __FILE__, VtkSetBoundaryDraw, group);
+
   theCommands.Add("ivtksetselmode",
     "ivtksetselmode usage:\n"
     " ivtksetselmode [name] mode on/off(0,1)"
index 643f427ec9967326e547d7cf634625e6931c4516..70a89d6edf842eaa7150294f8631846357a625f2 100644 (file)
@@ -180,15 +180,19 @@ void IVtkOCC_ShapeMesher::addEdges()
                                  TopAbs_FACE,
                                  anEdgesMap);
 
+  TopTools_IndexedMapOfShape anEdgesList;
+  TopExp::MapShapes(GetShapeObj()->GetShape(), TopAbs_EDGE, anEdgesList);
+
   int aNbFaces;
   IVtk_MeshType aType;
   myEdgesTypes.Clear();
 
-  TopExp_Explorer anEdgeIter (GetShapeObj()->GetShape(), TopAbs_EDGE);
-  for (; anEdgeIter.More(); anEdgeIter.Next())
+  TopTools_IndexedMapOfShape::const_iterator aEdgeIt;
+  for (aEdgeIt = anEdgesList.cbegin(); aEdgeIt != anEdgesList.cend(); aEdgeIt++)
   {
-    const TopoDS_Edge& anOcctEdge = TopoDS::Edge (anEdgeIter.Current());
-    aNbFaces = anEdgesMap.FindFromKey (anOcctEdge).Extent();
+    const TopoDS_Edge& anOcctEdge = TopoDS::Edge (*aEdgeIt);
+    const TopTools_ListOfShape& aFaceList = anEdgesMap.FindFromKey(anOcctEdge);
+    aNbFaces = aFaceList.Extent();
     if (aNbFaces == 0)
     {
       aType = MT_FreeEdge;
@@ -199,7 +203,21 @@ void IVtkOCC_ShapeMesher::addEdges()
     }
     else
     {
-      aType = MT_SharedEdge;
+      bool isSame = false;
+      TopTools_ListOfShape::const_iterator aFaceIt;
+      for (aFaceIt = aFaceList.cbegin(); aFaceIt != aFaceList.cend(); aFaceIt++) {
+        TopExp_Explorer aIt((*aFaceIt), TopAbs_EDGE);
+        int aCount = 0;
+        for (; aIt.More(); aIt.Next()) {
+          if (aIt.Current().IsSame(anOcctEdge))
+            aCount++;
+        }
+        if (aCount == 2) {
+          isSame = true;
+          break;
+        }
+      }
+      aType = isSame? MT_SeamEdge : MT_SharedEdge;
     }
     addEdge (anOcctEdge, GetShapeObj()->GetSubShapeId (anOcctEdge), aType);
     myEdgesTypes.Bind (anOcctEdge, aType);
index 2889fd4c68b40e89508f47879718f0eab06a33c8..c6976cf9ee29a4db4983d82b0f9de7a167f75a67 100644 (file)
@@ -35,7 +35,8 @@ vtkStandardNewMacro(IVtkTools_DisplayModeFilter)
 //============================================================================
 IVtkTools_DisplayModeFilter::IVtkTools_DisplayModeFilter()
   : myDisplayMode (DM_Wireframe),
-    myDoDisplaySharedVertices (false)
+    myDoDisplaySharedVertices (false),
+  myDrawFaceBoundaries( false )
 {
   // Filter according to values in subshapes types array.
   myIdsArrayName = IVtkVTK_ShapeData::ARRNAME_MESH_TYPES();
@@ -47,15 +48,16 @@ IVtkTools_DisplayModeFilter::IVtkTools_DisplayModeFilter()
   aTypes.Add (MT_FreeEdge);
   aTypes.Add (MT_BoundaryEdge);
   aTypes.Add (MT_SharedEdge);
+  aTypes.Add (MT_SeamEdge);
   aTypes.Add (MT_WireFrameFace);
 
-  myModesDefinition.Bind (DM_Wireframe, aTypes);
+  myModesDefinition[DM_Wireframe] = aTypes;
 
   aTypes.Clear();
   aTypes.Add (MT_FreeVertex);
   aTypes.Add (MT_ShadedFace);
 
-  myModesDefinition.Bind (DM_Shading, aTypes);
+  myModesDefinition[DM_Shading] = aTypes;
 }
 
 //============================================================================
@@ -73,7 +75,7 @@ int IVtkTools_DisplayModeFilter::RequestData (vtkInformation        *theRequest,
                                               vtkInformationVector **theInputVector,
                                               vtkInformationVector  *theOutputVector)
 {
-  SetData (myModesDefinition.Find (myDisplayMode));
+  SetData (myModesDefinition[myDisplayMode]);
   return Superclass::RequestData (theRequest, theInputVector, theOutputVector);
 }
 
@@ -104,24 +106,20 @@ void IVtkTools_DisplayModeFilter::SetDisplaySharedVertices (const bool theDoDisp
   if (myDoDisplaySharedVertices != theDoDisplay)
   {
     myDoDisplaySharedVertices = theDoDisplay;
-    vtkIdType aVertexType = MT_SharedVertex;
-    NCollection_DataMap<IVtk_DisplayMode, IVtk_IdTypeMap>::Iterator aModes (myModesDefinition);
-    NCollection_DataMap<IVtk_DisplayMode, IVtk_IdTypeMap> aNewModes;
     IVtk_IdTypeMap aModeTypes;
-    for (; aModes.More(); aModes.Next())
+    for (int i = 0; i < 2; i++)
     {
-      aModeTypes = aModes.Value();
-      if (theDoDisplay && !aModeTypes.Contains(aVertexType))
+      aModeTypes = myModesDefinition[i];
+      if (theDoDisplay && !aModeTypes.Contains(MT_SharedVertex))
       {
-        aModeTypes.Add (aVertexType);
+        aModeTypes.Add (MT_SharedVertex);
       }
-      else if (!theDoDisplay && aModeTypes.Contains (aVertexType))
+      else if (!theDoDisplay && aModeTypes.Contains (MT_SharedVertex))
       {
-        aModeTypes.Remove (aVertexType);
+        aModeTypes.Remove (MT_SharedVertex);
       }
-      aNewModes.Bind (aModes.Key(), aModeTypes);
+      myModesDefinition[i] = aModeTypes;
     }
-    myModesDefinition = aNewModes;
     Modified();
   }
 }
@@ -148,3 +146,42 @@ IVtk_DisplayMode IVtkTools_DisplayModeFilter::GetDisplayMode () const
   return myDisplayMode;
 }
 
+//============================================================================
+// Method: meshTypesForMode
+// Purpose:
+//============================================================================
+const IVtk_IdTypeMap& IVtkTools_DisplayModeFilter::MeshTypesForMode(IVtk_DisplayMode theMode) const
+{
+  return myModesDefinition[theMode];
+}
+
+//============================================================================
+// Method: setMeshTypesForMode
+// Purpose:
+//============================================================================
+void IVtkTools_DisplayModeFilter::SetMeshTypesForMode(IVtk_DisplayMode theMode, const IVtk_IdTypeMap& theMeshTypes)
+{
+  myModesDefinition[theMode] = theMeshTypes;
+  Modified();
+}
+
+//============================================================================
+// Method: SetFaceBoundaryDraw
+// Purpose:
+//============================================================================
+void IVtkTools_DisplayModeFilter::SetFaceBoundaryDraw(bool theToDraw)
+{
+  myDrawFaceBoundaries = theToDraw;
+  if (theToDraw) {
+    myModesDefinition[DM_Shading].Add(MT_BoundaryEdge);
+    myModesDefinition[DM_Shading].Add(MT_SharedEdge);
+  }
+  else {
+    if (myModesDefinition[DM_Shading].Contains(MT_BoundaryEdge))
+      myModesDefinition[DM_Shading].Remove(MT_BoundaryEdge);
+
+    if (myModesDefinition[DM_Shading].Contains(MT_SharedEdge))
+      myModesDefinition[DM_Shading].Remove(MT_SharedEdge);
+  }
+  Modified();
+}
index 5f2301b174c73f93e6c8f52f80f5e674137d15da..0d177cb366da62171ef51ecfa6eae6aad9aec0b8 100644 (file)
 #include <IVtkTools_SubPolyDataFilter.hxx>
 #include <NCollection_DataMap.hxx>
 
+#include <array>
+
 #ifdef _MSC_VER
 #pragma warning(push)
 #pragma warning(disable: 4251) // avoid warning C4251: "class needs to have dll-interface..."
 #endif
 
+typedef std::array<IVtk_IdTypeMap, 2> IVtk_DisplayModeArray;
+
 //! @class IVtkTools_DisplayModeFilter 
 //! @brief Cells filter according to the selected display mode by mesh parts types.
 //! This filter is used to get parts of a shape according to different 
@@ -46,6 +50,18 @@ public:
   //! Get current display mode.
   IVtk_DisplayMode GetDisplayMode() const;
 
+  //! Returns list of displaying mesh element types for the given display mode
+  const IVtk_IdTypeMap& MeshTypesForMode(IVtk_DisplayMode theMode) const;
+
+  //! Set a list of displaying mesh element types for the given display mode
+  void SetMeshTypesForMode(IVtk_DisplayMode theMode, const IVtk_IdTypeMap& theMeshTypes);
+
+  //! Draw Boundary of faces for shading mode
+  void SetFaceBoundaryDraw(bool theToDraw);
+
+  //! Returns True if drawing Boundary of faces for shading mode is defined.
+  bool FaceBoundaryDraw() const { return myDrawFaceBoundaries; }
+
 protected:
   //! Filter cells according to the given set of ids.
   virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *);
@@ -55,9 +71,10 @@ protected:
 
 protected:
   //! Display mode defining mesh types to pass through this filter.
-  IVtk_DisplayMode                                      myDisplayMode;
-  NCollection_DataMap<IVtk_DisplayMode, IVtk_IdTypeMap> myModesDefinition;
-  bool                                                  myDoDisplaySharedVertices;
+  IVtk_DisplayMode      myDisplayMode;
+  IVtk_DisplayModeArray myModesDefinition;
+  bool                  myDoDisplaySharedVertices;
+  bool                  myDrawFaceBoundaries;
 };
 
 #ifdef _MSC_VER
diff --git a/tests/v3d/ivtk/boundary_draw b/tests/v3d/ivtk/boundary_draw
new file mode 100644 (file)
index 0000000..e4aa640
--- /dev/null
@@ -0,0 +1,19 @@
+puts "============="
+puts "boundary_draw"
+puts "============="
+puts ""
+#######################################################
+#  Tests boundary draw flag changing in the IVtk view
+#######################################################
+
+set anImage1 $imagedir/${casename}_1.png
+set anImage2 $imagedir/${casename}_2.png
+
+ivtkinit
+box b 1 1 1
+ivtkdisplay b
+ivtksetboundingdraw 1
+ivtkdump $anImage1
+
+ivtksetboundingdraw 0
+ivtkdump $anImage2