p BOPAlgo
p BOPDS
p BOPCol
+p IVtk
+p IVtkOCC
+p IVtkVTK
+p IVtkTools
+t TKIVtk
--- /dev/null
+IVtk_Interface.hxx
+IVtk_Interface.cxx
+IVtk_IShape.hxx
+IVtk_IShape.cxx
+IVtk_IShapeData.hxx
+IVtk_IShapeData.cxx
+IVtk_IShapeMesher.hxx
+IVtk_IShapeMesher.cxx
+IVtk_IShapePickerAlgo.hxx
+IVtk_IShapePickerAlgo.cxx
+IVtk_IView.hxx
+IVtk_IView.cxx
+IVtk_Types.hxx
--- /dev/null
+// Created on: 2011-10-12
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtk_IShape.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtk_IShape, IVtk_Interface)
+IMPLEMENT_STANDARD_RTTIEXT(IVtk_IShape, IVtk_Interface)
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTK_ISHAPE_H__
+#define __IVTK_ISHAPE_H__
+
+#include <IVtk_Interface.hxx>
+#include <IVtk_Types.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtk_IShape, IVtk_Interface )
+
+//! @class IVtk_IShape
+//! @brief Interface for working with a shape and its sub-shapes ids.
+class IVtk_IShape : public IVtk_Interface
+{
+public:
+ typedef Handle(IVtk_IShape) Handle;
+
+ virtual ~IVtk_IShape() { }
+
+ IVtk_IdType GetId() const { return myId; }
+
+ void SetId (const IVtk_IdType theId) { myId = theId; }
+
+ //! Get ids of sub-shapes composing a sub-shape with the given id
+ virtual IVtk_ShapeIdList GetSubIds (const IVtk_IdType theId) const = 0;
+
+ DEFINE_STANDARD_RTTI( IVtk_IShape )
+
+private:
+ IVtk_IdType myId;
+};
+
+typedef NCollection_List< IVtk_IShape::Handle > IVtk_ShapePtrList;
+
+#endif // __IVTK_ISHAPE_H__
--- /dev/null
+// Created on: 2011-10-12
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtk_IShapeData.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtk_IShapeData, IVtk_Interface)
+IMPLEMENT_STANDARD_RTTIEXT(IVtk_IShapeData, IVtk_Interface)
--- /dev/null
+// Created on: 2011-10-12
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTK_ISHAPEDATA_H__
+#define __IVTK_ISHAPEDATA_H__
+
+#include <IVtk_Interface.hxx>
+#include <IVtk_Types.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtk_IShapeData, IVtk_Interface )
+
+//! @class IVtk_IShapeData
+//! @brief Interface for working with triangulated data.
+class IVtk_IShapeData : public IVtk_Interface
+{
+public:
+ typedef Handle(IVtk_IShapeData) Handle;
+
+ virtual ~IVtk_IShapeData() { }
+
+ DEFINE_STANDARD_RTTI( IVtk_IShapeData )
+
+ //! Insert a coordinate
+ //! @param [in] theX X coordinate
+ //! @param [in] theY Y coordinate
+ //! @param [in] theZ Z coordinate
+ //! @return id of added point
+ virtual IVtk_PointId InsertCoordinate (double theX, double theY, double theZ) = 0;
+
+ //! Insert a vertex.
+ //! @param [in] theShapeID id of the sub-shape to which the vertex belongs.
+ //! @param [in] thePointId id of the point that defines the coordinates of the vertex
+ //! @param [in] theMeshType mesh type of the sub-shape (MT_Undefined by default)
+ virtual void InsertVertex (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId,
+ const IVtk_MeshType theMeshType = MT_Undefined) = 0;
+
+ //! Insert a line.
+ //! @param [in] theShapeID id of the subshape to which the line belongs.
+ //! @param [in] thePointId1 id of the first point
+ //! @param [in] thePointId2 id of the second point
+ //! @param [in] theMeshType mesh type of the subshape (MT_Undefined by default)
+ virtual void InsertLine (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId1,
+ const IVtk_PointId thePointId2,
+ const IVtk_MeshType theMeshType = MT_Undefined) = 0;
+
+ //! Insert a poly-line.
+ //! @param [in] shapeID id of the subshape to which the polyline belongs.
+ //! @param [in] pointIds vector of point ids
+ //! @param [in] meshType mesh type of the subshape (MT_Undefined by default)
+ virtual void InsertLine (const IVtk_IdType theShapeID,
+ const IVtk_PointIdList* thePointIds,
+ const IVtk_MeshType theMeshType = MT_Undefined) = 0;
+
+ //! Insert a triangle
+ //! @param [in] theShapeID id of the subshape to which the triangle belongs.
+ //! @param [in] thePointId1 id of the first point
+ //! @param [in] thePointId2 id of the second point
+ //! @param [in] thePointId3 id of the third point
+ //! @param [in] theMeshType mesh type of the subshape (MT_Undefined by default)
+ virtual void InsertTriangle (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId1,
+ const IVtk_PointId thePointId2,
+ const IVtk_PointId thePointId3,
+ const IVtk_MeshType theMeshType = MT_Undefined) = 0;
+};
+
+#endif // __IVTK_ISHAPEDATA_H__
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtk_IShapeMesher.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtk_IShapeMesher, IVtk_Interface)
+IMPLEMENT_STANDARD_RTTIEXT(IVtk_IShapeMesher, IVtk_Interface)
+
+//! Excutes the mesh generation algorithms. To be defined in implementation class.
+void IVtk_IShapeMesher::initialize (const IVtk_IShape::Handle& theShape,
+ const IVtk_IShapeData::Handle& theData)
+{
+ myShapeObj = theShape;
+ myShapeData = theData;
+}
+
+//! Main entry point for building shape representation
+//! @param [in] shape IShape to be meshed
+//! @param [in] data IShapeData interface visualization data is passed to.
+void IVtk_IShapeMesher::Build (const IVtk_IShape::Handle& theShape,
+ const IVtk_IShapeData::Handle& theData)
+{
+ if (!theShape.IsNull())
+ {
+ initialize (theShape, theData);
+ internalBuild();
+ }
+}
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTK_ISHAPEMESHER_H__
+#define __IVTK_ISHAPEMESHER_H__
+
+#include <IVtk_Interface.hxx>
+#include <IVtk_IShape.hxx>
+#include <IVtk_IShapeData.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtk_IShapeMesher, IVtk_Interface )
+
+//! @class IVtk_IShapeMesher
+//! @brief Interface for triangulator of 3D shapes.
+class IVtk_IShapeMesher : public IVtk_Interface
+{
+public:
+ typedef Handle(IVtk_IShapeMesher) Handle;
+ virtual ~IVtk_IShapeMesher() { }
+
+ Standard_EXPORT void Build (const IVtk_IShape::Handle& theShape, const IVtk_IShapeData::Handle& theData);
+
+ DEFINE_STANDARD_RTTI( IVtk_IShapeMesher )
+
+protected:
+ Standard_EXPORT virtual void initialize (const IVtk_IShape::Handle& theShapeObj,
+ const IVtk_IShapeData::Handle& theShapeData);
+ virtual void internalBuild() = 0;
+
+protected:
+ IVtk_IShape::Handle myShapeObj;
+ IVtk_IShapeData::Handle myShapeData;
+};
+
+#endif // __IVTK_ISHAPEMESHER_H__
--- /dev/null
+// Created on: 2011-10-12
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtk_IShapePickerAlgo.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtk_IShapePickerAlgo, IVtk_Interface)
+IMPLEMENT_STANDARD_RTTIEXT(IVtk_IShapePickerAlgo, IVtk_Interface)
--- /dev/null
+// Created on: 2011-10-12
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTK_ISHAPEPICKERALGO_H__
+#define __IVTK_ISHAPEPICKERALGO_H__
+
+#include <IVtk_IView.hxx>
+#include <IVtk_IShape.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtk_IShapePickerAlgo, IVtk_Interface )
+
+//! @class IVtk_IShapePickerAlgo
+//! @brief Interface for 3D shapes picking algorithm.
+class IVtk_IShapePickerAlgo : public IVtk_Interface
+{
+public:
+ typedef Handle(IVtk_IShapePickerAlgo) Handle;
+
+ virtual ~IVtk_IShapePickerAlgo() { }
+
+ DEFINE_STANDARD_RTTI( IVtk_IShapePickerAlgo )
+
+ virtual void SetView (const IVtk_IView::Handle& theView) = 0;
+ virtual void Modified() = 0;
+ virtual int NbPicked() = 0;
+
+ //! Get activated selection modes for a shape.
+ //! @param [in] theShape a shape with activated selection mode(s)
+ //! @return list of active selection modes
+ virtual IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const = 0;
+
+public: // @name Set selectable shapes and selection modes
+
+ //! Activates/deactivates the given selection mode for the shape.
+ //! If mode == SM_None, the shape becomes non-selectable and
+ //! is removed from the internal selection data.
+ //! @param [in] theShape Shape for which the selection mode should be activated
+ //! @param [in] theMode Selection mode to be activated
+ //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
+ virtual void SetSelectionMode (const IVtk_IShape::Handle& theShape,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn = true) = 0;
+
+ //! Activates/deactivates the given selection mode for the shape.
+ //! If mode == SM_None, the shape becomes non-selectable and
+ //! is removed from the internal selection data.
+ //! @param [in] theShapes List of shapes for which the selection mode should be activated
+ //! @param [in] theMode Selection mode to be activated
+ //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
+ virtual void SetSelectionMode (const IVtk_ShapePtrList& theShapes,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn = true) = 0;
+
+public: // @name Picking methods
+
+ virtual bool Pick (const double theX, const double theY) = 0;
+ virtual bool Pick (const double theXMin,
+ const double theYMin,
+ const double theXMax,
+ const double theYMax) = 0;
+
+ virtual bool Pick (double** /* double poly[][3]*/, const int theNbPoints) = 0;
+
+public: // @name Obtain picking results
+
+ //! @return the list of picked top-level shape IDs,
+ //! in the order of increasing depth (the ID of the shape closest to the eye
+ //! is the first in the list)
+ virtual const IVtk_ShapeIdList& ShapesPicked() const = 0;
+
+ //! @param [in] theId Top-level shape ID
+ //! @param [out] theShapeList the list of picked sub-shape IDs for the given top-level shape ID,
+ //! in the order of increasing depth (the ID of the sub-shape closest to the eye
+ //! is the first in the list)
+ virtual void SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const = 0;
+};
+
+#endif // __IVTK_ISHAPEPICKERALGO_H__
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtk_IView.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtk_IView, IVtk_Interface)
+IMPLEMENT_STANDARD_RTTIEXT(IVtk_IView, IVtk_Interface)
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTK_IVIEW_H__
+#define __IVTK_IVIEW_H__
+
+#include <IVtk_Interface.hxx>
+#include <gp_XY.hxx>
+#include <gp_XYZ.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtk_IView, IVtk_Interface )
+
+//! @class IVtk_IView
+//! @brief Interface for obtaining view transformation parameters.
+//!
+//! These parameters are used by selection algorithm to compute
+//! projections of selectable (active) 3D shapes.
+class IVtk_IView : public IVtk_Interface
+{
+
+public:
+ typedef Handle(IVtk_IView) Handle;
+
+ //! Destructor
+ virtual ~IVtk_IView() { }
+
+ //! @return true if this is a perspective view, and false otherwise.
+ virtual bool IsPerspective() const = 0;
+
+ //! @return The focal distance of the view
+ virtual double GetDistance() const = 0;
+
+ //! @return The world coordinates of the view position
+ virtual void GetPosition (double& theX, double& theY, double& theZ) const = 0;
+
+ //! @return The "view up" direction of the view
+ virtual void GetViewUp (double& theDx, double& theDy, double& theDz) const = 0;
+
+ //! @return The projection direction vector of this view
+ virtual void GetDirectionOfProjection (double& theDx,
+ double& theDy,
+ double& theDz) const = 0;
+
+ //! @return Three doubles contaning scale components of the view transformation
+ virtual void GetScale (double& theX, double& theY, double& theZ) const = 0;
+
+ //! @return The current view's zoom factor (for parallel projection)
+ virtual double GetParallelScale() const = 0;
+
+ //! @return The current view angle (for perspective projection)
+ virtual double GetViewAngle() const = 0;
+
+ //! @return Two doubles containing the display coordinates of the view window center
+ virtual void GetViewCenter (double& theX, double& theY) const = 0;
+
+ //! Converts 3D display coordinates into 3D world coordinates.
+ //! @param [in] theDisplayPnt 2d point of display coordinates
+ //! @param [out] theWorldPnt 3d point of world coordinates
+ //! @return true if conversion was successful, false otherwise
+ virtual bool DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldPnt) const = 0;
+
+ DEFINE_STANDARD_RTTI( IVtk_IView )
+};
+
+#endif // __IVTK_IVIEW_H__
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtk_Interface.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtk_Interface, Standard_Transient)
+IMPLEMENT_STANDARD_RTTIEXT(IVtk_Interface, Standard_Transient)
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTK_INTERFACE_H__
+#define __IVTK_INTERFACE_H__
+
+#include <Standard_DefineHandle.hxx>
+#include <Standard_Transient.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtk_Interface, Standard_Transient )
+
+//! @class IVtk_Interface
+//! @brief Base interface for visualisation component.
+//!
+//! It is a handle class ("smart" pointer). IVtk_Interface is a base class for OCC interfaces
+//! for VTK classes, such as interface for shape objects (IVtk_IShape) and view(IVtk_IView),
+//! shape triangulation (IVtk_IShapeData, IVtk_IShapeMesher) and picking (IVtk_IShapePickerAlgo).
+class IVtk_Interface : public Standard_Transient
+{
+
+public:
+ typedef Handle(IVtk_Interface) Handle;
+ DEFINE_STANDARD_RTTI(IVtk_Interface)
+
+ virtual ~IVtk_Interface() { }
+};
+
+#endif // __IVTK_INTERFACE_H__
--- /dev/null
+// Created on: 2011-10-11
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTK_TYPES_H__
+#define __IVTK_TYPES_H__
+
+#include <gp_XY.hxx>
+#include <NCollection_List.hxx>
+#include <NCollection_TListIterator.hxx>
+#include <NCollection_DataMap.hxx>
+#include <NCollection_Map.hxx>
+#include <Standard_Integer.hxx>
+#include <Standard_Boolean.hxx>
+
+typedef Standard_Size IVtk_IdType;
+
+typedef IVtk_IdType IVtk_PointId;
+
+typedef IVtk_IdType IVtk_FaceId;
+typedef IVtk_IdType IVtk_EdgeId;
+
+typedef NCollection_List <IVtk_IdType> IVtk_ShapeIdList;
+typedef NCollection_List <IVtk_PointId> IVtk_PointIdList;
+
+typedef NCollection_DataMap <IVtk_IdType, IVtk_ShapeIdList> IVtk_SubShapeMap;
+typedef NCollection_Map <IVtk_IdType> IVtk_IdTypeMap;
+
+typedef NCollection_List <gp_XY> IVtk_Pnt2dList;
+
+//! @enum IVtk_SelectionMode Selection modes for 3D shapes
+//!
+//! Enumeration that describes all supported selection modes for 3D shapes.
+//! SM_None means that the shape should become non-selectable.
+//! SM_Shape makes the shape selectable as a whole.
+//! Other modes activate selection of sub-shapes of corresponding types.
+typedef enum
+{
+ SM_None = -1, //!< No selection
+ SM_Shape = 0, //!< Shape selection
+ SM_Vertex = 1, //!< Vertex selection
+ SM_Edge = 2, //!< Edge selection
+ SM_Wire = 3, //!< Wire selection
+ SM_Face = 4, //!< Face selection
+ SM_Shell = 5, //!< Shell selection
+ SM_Solid = 6, //!< Solid selection
+ SM_CompSolid = 7, //!< CompSolid selection
+ SM_Compound = 8, //!< Compound selection
+} IVtk_SelectionMode;
+
+typedef NCollection_List< IVtk_SelectionMode > IVtk_SelectionModeList;
+
+//! @enum IVtk_MeshType Types of mesh parts for 3D shapes
+//!
+//! Enumeration that describes all supported types of mesh parts for 3D shapes.
+typedef enum
+{
+ MT_Undefined = -1, //!< Undefined
+ MT_IsoLine = 0, //!< Isoline
+ MT_FreeVertex = 1, //!< Free vertex
+ MT_SharedVertex = 2, //!< Shared vertex
+ MT_FreeEdge = 3, //!< Free edge
+ 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
+} IVtk_MeshType;
+
+//! @enum IVtk_DisplayMode Display modes for 3D shapes
+//!
+//! Enumeration that describes all supported display modes for 3D shapes.
+typedef enum
+{
+ DM_Wireframe = 0, //!< Wireframe display mode
+ DM_Shading = 1 //!< Shaded display mode
+} IVtk_DisplayMode;
+
+#endif // __IVTK_TYPES_H__
+
--- /dev/null
+IVtkOCC_SelectableObject.hxx
+IVtkOCC_SelectableObject.cxx
+IVtkOCC_Shape.hxx
+IVtkOCC_Shape.cxx
+IVtkOCC_ShapeMesher.hxx
+IVtkOCC_ShapeMesher.cxx
+IVtkOCC_ShapePickerAlgo.hxx
+IVtkOCC_ShapePickerAlgo.cxx
+IVtkOCC_ViewerSelector.hxx
+IVtkOCC_ViewerSelector.cxx
--- /dev/null
+// Created on: 2011-10-20
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <AIS_Shape.hxx>
+#include <BRepBndLib.hxx>
+#include <IVtkOCC_SelectableObject.hxx>
+#include <Select3D_SensitiveBox.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <StdSelect_BRepOwner.hxx>
+#include <StdSelect_BRepSelectionTool.hxx>
+#include <TopoDS_Iterator.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE( IVtkOCC_SelectableObject, SelectMgr_SelectableObject )
+IMPLEMENT_STANDARD_RTTIEXT( IVtkOCC_SelectableObject, SelectMgr_SelectableObject )
+
+//============================================================================
+// Method: Constructor
+// Purpose: Constructs a selectable object initalized by the given shape
+//============================================================================
+IVtkOCC_SelectableObject::IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape)
+: SelectMgr_SelectableObject (PrsMgr_TOP_AllView),
+ myShape (theShape)
+{
+ if (!myShape.IsNull())
+ {
+ myShape->SetSelectableObject (this);
+ }
+
+ // Minor stuff - but it facilitates usage of OCCT selection
+ // classes dealing with deflection, see ComputeSelection() below
+ myOCCTDrawer = new Prs3d_Drawer();
+}
+
+//============================================================================
+// Method: Constructor
+// Purpose: Constructs uninitialized selectable object.
+// setShape() should be called later.
+//============================================================================
+IVtkOCC_SelectableObject::IVtkOCC_SelectableObject()
+: SelectMgr_SelectableObject (PrsMgr_TOP_AllView),
+ myShape (0)
+{ }
+
+//============================================================================
+// Method: SetShape
+// Purpose: Sets the selectable shape
+//============================================================================
+void IVtkOCC_SelectableObject::SetShape (const IVtkOCC_Shape::Handle& theShape)
+{
+ myShape = theShape;
+ if (myShape)
+ {
+ myShape->SetSelectableObject (this);
+ }
+
+ // Shape has changed -> Clear all internal data
+ myBndBox.SetVoid();
+ myselections.Clear();
+}
+
+//============================================================================
+// Method: ComputeSelection
+// Purpose: Internal method, computes selection data for viewer selector
+//============================================================================
+void IVtkOCC_SelectableObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer theMode)
+{
+ if (!myShape)
+ {
+ return;
+ }
+
+ TopoDS_Shape anOcctShape = myShape->GetShape();
+
+ if (anOcctShape.ShapeType() == TopAbs_COMPOUND)
+ {
+ TopoDS_Iterator anExplor (anOcctShape);
+ if (!anExplor.More()) // Shape empty -> go away
+ {
+ return;
+ }
+ }
+
+ TopAbs_ShapeEnum aTypeOfSel = AIS_Shape::SelectionType (theMode);
+
+ Standard_Real aDeflection = myOCCTDrawer->MaximalChordialDeviation();
+ if (myOCCTDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
+ {
+ Bnd_Box aBndBox;
+ BRepBndLib::Add (anOcctShape, aBndBox);
+ if (!aBndBox.IsVoid())
+ {
+ Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+ aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+ aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) *
+ myOCCTDrawer->DeviationCoefficient();
+ }
+ }
+
+ // Assume the shape has been displayed already -> triangulation should exist
+ Standard_Boolean isAutoTriangulation = Standard_False;
+
+ try
+ {
+ OCC_CATCH_SIGNALS
+ StdSelect_BRepSelectionTool::Load (theSelection,
+ this,
+ anOcctShape,
+ aTypeOfSel,
+ aDeflection,
+ myOCCTDrawer->DeviationAngle(),
+ isAutoTriangulation);
+ }
+ catch (Standard_Failure)
+ {
+ if (theMode == 0)
+ {
+ Bnd_Box aBndBox = BoundingBox();
+ Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner (anOcctShape, this);
+ Handle(Select3D_SensitiveBox) aSensitiveBox =
+ new Select3D_SensitiveBox (aOwner, aBndBox);
+ theSelection->Add (aSensitiveBox);
+ }
+ }
+}
+
+//============================================================================
+// Method: BoundingBox
+// Purpose:
+//============================================================================
+const Bnd_Box& IVtkOCC_SelectableObject::BoundingBox()
+{
+ if (!myShape)
+ {
+ myBndBox.SetVoid();
+ return myBndBox;
+ }
+
+ TopoDS_Shape anOcctShape = myShape->GetShape();
+
+ if (anOcctShape.ShapeType() == TopAbs_COMPOUND)
+ {
+ TopoDS_Iterator anExplor (anOcctShape);
+ if (!anExplor.More())
+ { // Shape empty -> nothing to do
+ myBndBox.SetVoid();
+ return myBndBox;
+ }
+ }
+
+ if (myBndBox.IsVoid())
+ {
+ // Add only edges and vertices, in case of troubles this should work anyway
+ BRepBndLib::AddClose (anOcctShape, myBndBox);
+ }
+
+ return myBndBox;
+}
--- /dev/null
+// Created on: 2011-10-20
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKOCC_SELECTABLEOBJECT_H__
+#define __IVTKOCC_SELECTABLEOBJECT_H__
+
+#include <Bnd_Box.hxx>
+#include <IVtkOCC_Shape.hxx>
+#include <Prs3d_Drawer.hxx>
+#include <SelectMgr_SelectableObject.hxx>
+#include <SelectMgr_Selection.hxx>
+
+// -----------------------------------------------------------------------------
+//! @class IVtkOCC_SelectableObject
+//! @brief Class with selection primitives used by OCCT selection algorithm.
+class IVtkOCC_SelectableObject : public SelectMgr_SelectableObject
+{
+public:
+
+ //! Constructs a selectable object initialized by the given shape
+ //! @param [in] theShape Selectable shape
+ IVtkOCC_SelectableObject (const IVtkOCC_Shape::Handle& theShape);
+
+ //! Constructs uninitialized selectable object.
+ //! setShape() should be called later.
+ IVtkOCC_SelectableObject();
+
+ //! Sets the selectable shape
+ //! @param [in] theShape Selectable shape
+ void SetShape (const IVtkOCC_Shape::Handle& theShape);
+
+ const IVtkOCC_Shape::Handle& GetShape() const { return myShape; };
+
+ DEFINE_STANDARD_RTTI( IVtkOCC_SelectableObject )
+
+private:
+
+ //! Internal method, computes selection data for viewer selector
+ //! Inspired by AIS_Shape::ComputeSelection() from OCCT 6.5.1
+ //! @param [in] selection container for sensitive primitives
+ //! @param [in] mode Selection mode
+ void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer theMode);
+
+ const Bnd_Box& BoundingBox();
+
+ IVtkOCC_Shape::Handle myShape;
+ Bnd_Box myBndBox;
+ Handle(Prs3d_Drawer) myOCCTDrawer;
+};
+
+DEFINE_STANDARD_HANDLE( IVtkOCC_SelectableObject, SelectMgr_SelectableObject )
+
+#endif // __IVTKOCC_SELECTABLEOBJECT_H__
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkOCC_Shape.hxx>
+#include <TopExp.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtkOCC_Shape, IVtk_IShape)
+IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_Shape, IVtk_IShape)
+
+//============================================================================
+// Method: Constructor
+// Purpose:
+//============================================================================
+IVtkOCC_Shape::IVtkOCC_Shape (const TopoDS_Shape& theShape)
+: myTopoDSShape (theShape)
+{
+ buildSubShapeIdMap();
+}
+
+//============================================================================
+// Method: Destructor
+// Purpose:
+//============================================================================
+IVtkOCC_Shape::~IVtkOCC_Shape() { }
+
+//============================================================================
+// Method: getSubShapeId
+// Purpose: Returns unique ID of the given sub-shape within the top-level shape.
+//============================================================================
+IVtk_IdType IVtkOCC_Shape::GetSubShapeId (const TopoDS_Shape& theSubShape) const
+{
+ Standard_Integer anIndex = theSubShape.IsSame (myTopoDSShape) ?
+ -1 :
+ mySubShapeIds.FindIndex (theSubShape);
+
+ if (!anIndex) // Not found in the map
+ {
+ anIndex = -1;
+ }
+
+ return (IVtk_IdType)anIndex;
+}
+
+//============================================================================
+// Method: getSubIds
+// Purpose: Get ids of sub-shapes composing a sub-shape with the given id.
+//============================================================================
+IVtk_ShapeIdList IVtkOCC_Shape::GetSubIds (const IVtk_IdType theId) const
+{
+ IVtk_ShapeIdList aRes;
+ // Get the sub-shape by the given id.
+ TopoDS_Shape aShape = mySubShapeIds.FindKey (theId);
+ TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+ if (aShapeType == TopAbs_VERTEX || aShapeType == TopAbs_EDGE ||
+ aShapeType == TopAbs_FACE)
+ {
+ // If it is vertex, edge or face return just the input id.
+ aRes.Append (theId);
+ }
+ else
+ {
+ // Find all composing vertices, edges and faces of the the found sub-shape
+ // and append their ids to the result.
+ TopTools_IndexedMapOfShape aSubShapes;
+ if (aShape.IsSame (myTopoDSShape))
+ {
+ aSubShapes = mySubShapeIds;
+ }
+ else
+ {
+ TopExp::MapShapes (aShape, aSubShapes);
+ }
+
+ for (int anIt = 1; anIt <= aSubShapes.Extent(); anIt++)
+ {
+ aShape = aSubShapes.FindKey (anIt);
+ aShapeType = aShape.ShapeType();
+ if (aShapeType == TopAbs_VERTEX || aShapeType == TopAbs_EDGE ||
+ aShapeType == TopAbs_FACE)
+ {
+ // If it is vertex, edge or face add its id to the result.
+ aRes.Append (mySubShapeIds.FindIndex (aShape));
+ }
+ }
+ }
+
+ return aRes;
+}
+
+//============================================================================
+// Method: GetSubShape
+// Purpose:
+//============================================================================
+const TopoDS_Shape& IVtkOCC_Shape::GetSubShape (const IVtk_IdType theId) const
+{
+ return mySubShapeIds.FindKey (theId);
+}
+
+//============================================================================
+// Method: buildShapeIdMap
+// Purpose: Private method, assigns IDs to all sub-shapes of the top-level shape.
+//============================================================================
+void IVtkOCC_Shape::buildSubShapeIdMap()
+{
+ mySubShapeIds.Clear();
+ TopExp::MapShapes (myTopoDSShape, mySubShapeIds);
+}
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKOCC_SHAPE_H__
+#define __IVTKOCC_SHAPE_H__
+
+#include <IVtk_IShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <SelectMgr_SelectableObject.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtkOCC_Shape, IVtk_IShape )
+
+//! @class IVtkOCC_Shape
+//! @brief OCC implementation of IShape interface.
+class IVtkOCC_Shape : public IVtk_IShape
+{
+public:
+
+ typedef Handle(IVtkOCC_Shape) Handle;
+
+ //! Constructor for OCC IShape implementation
+ Standard_EXPORT IVtkOCC_Shape (const TopoDS_Shape& theShape);
+
+ //! Destructor
+ Standard_EXPORT virtual ~IVtkOCC_Shape();
+
+ IVtk_IdType GetSubShapeId (const IVtk_IShape::Handle&) const;
+
+ DEFINE_STANDARD_RTTI( IVtkOCC_Shape )
+
+ //! Get the wrapped original OCCT shape
+ //! @return TopoDS_Shape the wrapped original OCCT shape
+ TopoDS_Shape GetShape() const
+ {
+ return myTopoDSShape;
+ }
+
+ //! @brief Get local ID of a sub-shape.
+ //!
+ //! Returns unique ID of the given sub-shape within the top-level shape.
+ //! Note that the sub-shape ID remains unchanged until the top-level is
+ //! modified by some operation.
+ //! @param [in] subShape sub-shape whose ID is returned
+ //! @return local ID of the sub-shape.
+ IVtk_IdType GetSubShapeId (const TopoDS_Shape& theSubShape) const;
+
+ //! Get ids of sub-shapes composing a sub-shape with the given id
+ Standard_EXPORT IVtk_ShapeIdList GetSubIds (const IVtk_IdType) const;
+
+ //! @brief Get a sub-shape by its local ID.
+ //!
+ //! @param [in] id local ID of a sub-shape
+ //! @return TopoDS_Shape& a sub-shape
+ Standard_EXPORT const TopoDS_Shape& GetSubShape (const IVtk_IdType theId) const;
+
+ //! Stores a handle to selectable object used by OCCT selection algorithm
+ //! in a data field. This object internally caches selection data
+ //! so it should be stored until the shape is no longer selectable.
+ //! Note that the selectable object keeps a pointer to OccShape.
+ //! @param [in] selObj Handle to the selectable object
+ void SetSelectableObject (const Handle(SelectMgr_SelectableObject)& theSelObj)
+ {
+ mySelectable = theSelObj;
+ }
+
+ //! @return Handle to the selectable object for this shape.
+ Handle(SelectMgr_SelectableObject) GetSelectableObject() const
+ {
+ return mySelectable;
+ }
+
+private:
+ //! @brief Build a map of sub-shapes by their IDs
+ //!
+ //! Private method, assigns IDs to all sub-shapes of the
+ //! top-level shape.
+ //! @see IVtkOCC_Shape::GetSubShapeId
+ void buildSubShapeIdMap();
+
+private:
+ TopTools_IndexedMapOfShape mySubShapeIds; //!< Map of sub-shapes by their IDs
+ TopoDS_Shape myTopoDSShape; //!< The wrapped main OCCT shape
+ Handle(SelectMgr_SelectableObject) mySelectable; //!< Link to a holder of selection primitives
+};
+
+#endif // __IVTKOCC_SHAPE_H__
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <Adaptor3d_HCurve.hxx>
+#include <Adaptor3d_IsoCurve.hxx>
+#include <Bnd_Box.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepMesh_DiscretFactory.hxx>
+#include <BRepMesh_DiscretRoot.hxx>
+#include <BRepMesh_PDiscretRoot.hxx>
+#include <BRepTools.hxx>
+#include <Hatch_Hatcher.hxx>
+#include <GCPnts_QuasiUniformDeflection.hxx>
+#include <GCPnts_TangentialDeflection.hxx>
+#include <Geom2dAdaptor_Curve.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <gp_Dir2d.hxx>
+#include <gp_Pnt2d.hxx>
+#include <IVtkOCC_ShapeMesher.hxx>
+#include <NCollection_Array1.hxx>
+#include <Poly_Polygon3D.hxx>
+#include <Poly_PolygonOnTriangulation.hxx>
+#include <Poly_Triangulation.hxx>
+#include <Precision.hxx>
+#include <Prs3d.hxx>
+#include <Prs3d_Drawer.hxx>
+#include <Quantity_Length.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <TColgp_SequenceOfPnt2d.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtkOCC_ShapeMesher, IVtk_IShapeMesher)
+IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher, IVtk_IShapeMesher)
+
+//================================================================
+// Function : internalBuild
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::internalBuild()
+{
+ // TODO: do we need any protection here so as not to triangualte
+ // the shape twice??? This can be done e.g. by checking if
+ // triangulation exists for TopoDS_Shape..
+ meshShape();
+
+ // Free vertices and free edges should always be shown.
+ // Shared edges are needed in WF representation only.
+ // TODO: how to filter free edges at visualization level????
+ addFreeVertices();
+ addEdges();
+
+ // Build wireframe points and cells (lines for isolines)
+ addWireFrameFaces();
+
+ // Build shaded representation (based on Poly_Triangulation)
+ addShadedFaces();
+}
+
+//================================================================
+// Function : GetShapeObj
+// Purpose :
+//================================================================
+const IVtkOCC_Shape::Handle IVtkOCC_ShapeMesher::GetShapeObj() const
+{
+ return (IVtkOCC_Shape::Handle::DownCast(myShapeObj));
+}
+
+//================================================================
+// Function : GetDeflection
+// Purpose : Returns absolute deflection used by this algorithm.
+//================================================================
+Standard_Real IVtkOCC_ShapeMesher::GetDeflection() const
+{
+ if (myDeflection < Precision::Confusion()) // if not yet initialized
+ {
+ Handle(Prs3d_Drawer) aDefDrawer = new Prs3d_Drawer();
+ aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
+ aDefDrawer->SetDeviationCoefficient (GetDeviationCoeff());
+ myDeflection = Prs3d::GetDeflection (GetShapeObj()->GetShape(), aDefDrawer);
+ }
+
+ return myDeflection;
+}
+
+//================================================================
+// Function : meshShape
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::meshShape()
+{
+ TopoDS_Shape anOcctShape = GetShapeObj()->GetShape();
+ if (anOcctShape.IsNull())
+ {
+ return;
+ }
+
+ //Clean triangulation before compute incremental mesh
+ BRepTools::Clean (anOcctShape);
+
+ //Compute triangulation
+ Standard_Real aDeflection = GetDeflection();
+ if (aDeflection < Precision::Confusion())
+ {
+ return;
+ }
+
+ try
+ {
+ OCC_CATCH_SIGNALS
+
+ Handle(BRepMesh_DiscretRoot) anAlgo;
+ anAlgo = BRepMesh_DiscretFactory::Get().Discret (anOcctShape,
+ aDeflection,
+ GetDeviationAngle());
+ if (!anAlgo.IsNull())
+ {
+ anAlgo->Perform();
+ }
+ }
+ catch (Standard_Failure)
+ { }
+}
+
+//================================================================
+// Function : addFreeVertices
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addFreeVertices()
+{
+ TopTools_IndexedDataMapOfShapeListOfShape aVertexMap;
+ TopExp::MapShapesAndAncestors (GetShapeObj()->GetShape(),
+ TopAbs_VERTEX,
+ TopAbs_EDGE,
+ aVertexMap);
+
+ Standard_Integer aVertNum = aVertexMap.Extent();
+ IVtk_MeshType aType;
+ for (Standard_Integer anIt = 1; anIt <= aVertNum; anIt++)
+ {
+ if (aVertexMap.FindFromIndex(anIt).IsEmpty())
+ {
+ aType = MT_FreeVertex;
+ }
+ else
+ {
+ aType = MT_SharedVertex;
+ }
+ TopoDS_Vertex aVertex = TopoDS::Vertex (aVertexMap.FindKey (anIt));
+ addVertex (aVertex, GetShapeObj()->GetSubShapeId (aVertex), aType);
+ }
+}
+
+//================================================================
+// Function : addEdges
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addEdges()
+{
+ TopTools_IndexedDataMapOfShapeListOfShape anEdgesMap;
+ TopExp::MapShapesAndAncestors (GetShapeObj()->GetShape(),
+ TopAbs_EDGE,
+ TopAbs_FACE,
+ anEdgesMap);
+
+ int aNbFaces;
+ IVtk_MeshType aType;
+ myEdgesTypes.Clear();
+
+ TopExp_Explorer anEdgeIter (GetShapeObj()->GetShape(), TopAbs_EDGE);
+ for (; anEdgeIter.More(); anEdgeIter.Next())
+ {
+ TopoDS_Edge anOcctEdge = TopoDS::Edge (anEdgeIter.Current());
+ aNbFaces = anEdgesMap.FindFromKey (anOcctEdge).Extent();
+ if (aNbFaces == 0)
+ {
+ aType = MT_FreeEdge;
+ }
+ else if (aNbFaces == 1)
+ {
+ aType = MT_BoundaryEdge;
+ }
+ else
+ {
+ aType = MT_SharedEdge;
+ }
+ addEdge (anOcctEdge, GetShapeObj()->GetSubShapeId (anOcctEdge), aType);
+ myEdgesTypes.Bind (anOcctEdge, aType);
+ }
+}
+
+//================================================================
+// Function : addWireFrameFaces
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addWireFrameFaces()
+{
+ // Check the deflection value once for all faces
+ if (GetDeflection() < Precision::Confusion())
+ {
+ return;
+ }
+
+ TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
+ for (; aFaceIter.More(); aFaceIter.Next())
+ {
+ TopoDS_Face anOcctFace = TopoDS::Face (aFaceIter.Current());
+ try
+ {
+ OCC_CATCH_SIGNALS
+ addWFFace (anOcctFace,
+ GetShapeObj()->GetSubShapeId (anOcctFace));
+ }
+ catch (Standard_Failure)
+ { }
+ }
+}
+
+//================================================================
+// Function : addShadedFaces
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addShadedFaces()
+{
+ TopExp_Explorer aFaceIter (GetShapeObj()->GetShape(), TopAbs_FACE);
+ for (; aFaceIter.More(); aFaceIter.Next())
+ {
+ TopoDS_Face anOcctFace = TopoDS::Face (aFaceIter.Current());
+ addShadedFace (anOcctFace,
+ GetShapeObj()->GetSubShapeId (anOcctFace));
+ }
+}
+
+//================================================================
+// Function : addVertex
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addVertex (const TopoDS_Vertex& theVertex,
+ const IVtk_IdType theShapeId,
+ const IVtk_MeshType theMeshType)
+{
+ if (theVertex.IsNull())
+ {
+ return;
+ }
+
+ gp_Pnt aPnt3d = BRep_Tool::Pnt (theVertex);
+
+ IVtk_PointId anId =
+ myShapeData->InsertCoordinate (aPnt3d.X(), aPnt3d.Y(), aPnt3d.Z());
+ myShapeData->InsertVertex (theShapeId, anId, theMeshType);
+
+}
+
+//================================================================
+// Function : processPolyline
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::processPolyline (Standard_Integer theNbNodes,
+ const TColgp_Array1OfPnt& thePoints,
+ const TColStd_Array1OfInteger& thePointIds,
+ const IVtk_IdType theOcctId,
+ bool theNoTransform,
+ gp_Trsf theTransformation,
+ const IVtk_MeshType theMeshType)
+{
+ if (theNbNodes < 2)
+ {
+ return;
+ }
+
+ IVtk_PointIdList *aPolyPointIds = new IVtk_PointIdList();
+
+ IVtk_PointId anId;
+ for (Standard_Integer aJ = 0; aJ < theNbNodes; aJ++)
+ {
+ Standard_Integer aPntId = thePointIds (aJ + 1);
+ gp_Pnt point = thePoints (aPntId);
+
+ if (!theNoTransform)
+ {
+ // Apply the transformation to points
+ point.Transform (theTransformation);
+ }
+
+ anId = myShapeData->InsertCoordinate (point.X(), point.Y(), point.Z());
+ aPolyPointIds->Append (anId);
+ }
+
+ myShapeData->InsertLine (theOcctId, aPolyPointIds, theMeshType);
+
+ delete aPolyPointIds;
+}
+
+//================================================================
+// Function : addEdge
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addEdge (const TopoDS_Edge& theEdge,
+ const IVtk_IdType theShapeId,
+ const IVtk_MeshType theMeshType)
+{
+ if (theEdge.IsNull() || BRep_Tool::Degenerated (theEdge))
+ {
+ return;
+ }
+
+ // Two discrete representations of an OCCT edge are possible:
+ // 1. Polygon on trinagulation - holds Ids of points
+ // contained in Poly_Triangulation object
+ Handle(Poly_PolygonOnTriangulation) aPolyOnTriangulation;
+ Handle(Poly_Triangulation) aTriangulation;
+ TopLoc_Location aLocation;
+ BRep_Tool::PolygonOnTriangulation (theEdge,
+ aPolyOnTriangulation,
+ aTriangulation,
+ aLocation,
+ 1);
+
+ // 2. 3D polygon - holds 3D points
+ Handle(Poly_Polygon3D) aPoly3d;
+ if (aPolyOnTriangulation.IsNull())
+ {
+ aPoly3d = BRep_Tool::Polygon3D (theEdge, aLocation);
+ }
+
+ if (aPoly3d.IsNull() && aPolyOnTriangulation.IsNull())
+ {
+ return;
+ }
+
+ // Handle a non-identity transofmation applied to the edge
+ gp_Trsf anEdgeTransf;
+ bool noTransform = true;
+ if (!aLocation.IsIdentity())
+ {
+ noTransform = false;
+ anEdgeTransf = aLocation.Transformation();
+ }
+
+ if (!aPoly3d.IsNull())
+ {
+ Standard_Integer aNbNodes = aPoly3d->NbNodes();
+ const TColgp_Array1OfPnt& aPoints = aPoly3d->Nodes();
+ TColStd_Array1OfInteger aPointIds (1, aNbNodes);
+
+ for (Standard_Integer anI = 1; anI <= aNbNodes; anI++)
+ {
+ aPointIds.SetValue (anI, anI);
+ }
+
+ processPolyline (aNbNodes,
+ aPoints,
+ aPointIds,
+ theShapeId,
+ noTransform,
+ anEdgeTransf,
+ theMeshType);
+ }
+ else
+ {
+ Standard_Integer aNbNodes = aPolyOnTriangulation->NbNodes();
+ const TColStd_Array1OfInteger& aPointIds = aPolyOnTriangulation->Nodes();
+ const TColgp_Array1OfPnt& aPoints = aTriangulation->Nodes();
+
+ processPolyline (aNbNodes,
+ aPoints,
+ aPointIds,
+ theShapeId,
+ noTransform,
+ anEdgeTransf,
+ theMeshType);
+ }
+}
+
+
+//================================================================
+// Function : FindLimits
+// Purpose : Static internal function, finds parametrical limits of the curve.
+//! @param [in] theCurve 3D curve adaptor used to retrieve the curve geometry
+//! @param [in] theLimit maximum allowed absolute parameter value
+//! @param [out] theFirst minimum parameter value for the curve
+//! @param [out] theLast maximum parameter value for the curve
+//================================================================
+static void FindLimits (const Adaptor3d_Curve& theCurve,
+ const Standard_Real& theLimit,
+ Standard_Real& theFirst,
+ Standard_Real& theLast)
+{
+ theFirst = Max(theCurve.FirstParameter(), theFirst);
+ theLast = Min(theCurve.LastParameter(), theLast);
+ Standard_Boolean isFirstInf = Precision::IsNegativeInfinite (theFirst);
+ Standard_Boolean isLastInf = Precision::IsPositiveInfinite (theLast);
+
+ if (isFirstInf || isLastInf)
+ {
+ gp_Pnt aP1, aP2;
+ Standard_Real aDelta = 1;
+ if (isFirstInf && isLastInf)
+ {
+ do
+ {
+ aDelta *= 2;
+ theFirst = - aDelta;
+ theLast = aDelta;
+ theCurve.D0 (theFirst, aP1);
+ theCurve.D0 (theLast, aP2);
+ } while (aP1.Distance (aP2) < theLimit);
+ }
+ else if (isFirstInf)
+ {
+ theCurve.D0 (theLast, aP2);
+ do {
+ aDelta *= 2;
+ theFirst = theLast - aDelta;
+ theCurve.D0 (theFirst, aP1);
+ } while (aP1.Distance(aP2) < theLimit);
+ }
+ else if (isLastInf)
+ {
+ theCurve.D0 (theFirst, aP1);
+ do
+ {
+ aDelta *= 2;
+ theLast = theFirst + aDelta;
+ theCurve.D0 (theLast, aP2);
+ } while (aP1.Distance (aP2) < theLimit);
+ }
+ }
+}
+
+//================================================================
+// Function : FindLimits
+// Purpose :Static helper function, builds a discrete representation
+//! (sequence of points) for the given curve.
+//!
+//! @param [in] theCurve 3D curve adaptor used to retrieve the curve geometry
+//! @param [in] theDeflection absolute deflection value
+//! @param [in] theAngle deviation angle value
+//! @param [in] theU1 minimal curve parameter value
+//! @param [in] theU2 maximal curve parameter value
+//! @param [out] thePoints the container for generated polyline
+//================================================================
+static void DrawCurve (Adaptor3d_Curve& theCurve,
+ const Quantity_Length theDeflection,
+ const Standard_Real theAngle,
+ const Standard_Real theU1,
+ const Standard_Real theU2,
+ IVtk_Polyline& thePoints)
+{
+ switch (theCurve.GetType())
+ {
+ case GeomAbs_Line:
+ {
+ gp_Pnt aPnt = theCurve.Value(theU1);
+ thePoints.Append (aPnt);
+
+ aPnt = theCurve.Value(0.5 * (theU1 + theU2));
+ thePoints.Append (aPnt);
+
+ aPnt = theCurve.Value (theU2);
+ thePoints.Append(aPnt);
+ }
+ break;
+ default:
+ {
+ Standard_Integer aNbInter = theCurve.NbIntervals(GeomAbs_C1);
+ Standard_Integer anI, aJ;
+ TColStd_Array1OfReal aParams(1, aNbInter+1);
+ theCurve.Intervals(aParams, GeomAbs_C1);
+ Standard_Real theU1, theU2;
+ Standard_Integer NumberOfPoints;
+
+ for (aJ = 1; aJ <= aNbInter; aJ++)
+ {
+ theU1 = aParams (aJ); theU2 = aParams (aJ + 1);
+ if (theU2 > theU1 && theU1 < theU2)
+ {
+ theU1 = Max(theU1, theU1);
+ theU2 = Min(theU2, theU2);
+
+ GCPnts_TangentialDeflection anAlgo (theCurve, theU1, theU2, theAngle, theDeflection);
+ NumberOfPoints = anAlgo.NbPoints();
+
+ if (NumberOfPoints > 0)
+ {
+ for (anI = 1; anI < NumberOfPoints; anI++)
+ {
+ thePoints.Append(anAlgo.Value (anI));
+ }
+ if (aJ == aNbInter)
+ {
+ thePoints.Append (anAlgo.Value (NumberOfPoints));
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : buildIsoLines
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::buildIsoLines (const Handle(BRepAdaptor_HSurface)& theFace,
+ const Standard_Boolean theIsDrawUIso,
+ const Standard_Boolean theIsDrawVIso,
+ const Standard_Integer theNBUiso,
+ const Standard_Integer theNBViso,
+ IVtk_PolylineList& thePolylines)
+{
+ Standard_Real anUF, anUL, aVF, aVL;
+ anUF = theFace->FirstUParameter();
+ anUL = theFace->LastUParameter();
+ aVF = theFace->FirstVParameter();
+ aVL = theFace->LastVParameter();
+
+ // Restrict maximal parameter value
+ // in OCCT it's 5e+5 by default
+ const Standard_Real aLimit = 5e+5;
+
+ // compute bounds of the restriction
+ Standard_Real anUMin, anUMax, aVMin, aVMax;
+ Standard_Integer anI;
+
+ anUMin = Max (anUF, -aLimit);
+ anUMax = Min (anUL, aLimit);
+ aVMin = Max (aVF, -aLimit);
+ aVMax = Min (aVL, aLimit);
+
+ // update min max for the hatcher.
+ gp_Pnt2d aP1,aP2;
+ gp_Pnt aDummyPnt;
+
+ Standard_Real aDdefle = Max (anUMax - anUMin, aVMax - aVMin) * GetDeviationCoeff();
+ TColgp_SequenceOfPnt2d aTabPoints;
+
+ anUMin = aVMin = 1.e100;
+ anUMax = aVMax = -1.e100;
+
+ // Process the edges
+ TopExp_Explorer aToolRst;
+ TopoDS_Face aTopoFace (((BRepAdaptor_Surface*)&(theFace->Surface()))->Face());
+ for (aToolRst.Init (aTopoFace, TopAbs_EDGE); aToolRst.More(); aToolRst.Next())
+ {
+ TopAbs_Orientation anOrient = aToolRst.Current().Orientation();
+ // Skip INTERNAL and EXTERNAL edges
+ if (anOrient == TopAbs_FORWARD || anOrient == TopAbs_REVERSED)
+ {
+ Standard_Real anU1, anU2;
+ const Handle(Geom2d_Curve)& aCurve =
+ BRep_Tool::CurveOnSurface (TopoDS::Edge (aToolRst.Current()),
+ aTopoFace,
+ anU1, anU2);
+ if (aCurve.IsNull())
+ {
+ continue;
+ }
+
+ Geom2dAdaptor_Curve aRCurve;
+ aRCurve.Load (aCurve, anU1, anU2);
+ if (aRCurve.GetType() != GeomAbs_Line)
+ {
+ GCPnts_QuasiUniformDeflection aUDP(aRCurve, aDdefle);
+ if (aUDP.IsDone())
+ {
+ Standard_Integer NumberOfPoints = aUDP.NbPoints();
+ if ( NumberOfPoints >= 2 )
+ {
+ aDummyPnt = aUDP.Value (1);
+ aP2.SetCoord (aDummyPnt.X(), aDummyPnt.Y());
+ anUMin = Min (aP2.X(), anUMin);
+ anUMax = Max (aP2.X(), anUMax);
+ aVMin = Min (aP2.Y(), aVMin);
+ aVMax = Max (aP2.Y(), aVMax);
+ for (anI = 2; anI <= NumberOfPoints; anI++)
+ {
+ aP1 = aP2;
+ aDummyPnt = aUDP.Value (anI);
+ aP2.SetCoord (aDummyPnt.X(), aDummyPnt.Y());
+ anUMin = Min(aP2.X(), anUMin);
+ anUMax = Max(aP2.X(), anUMax);
+ aVMin = Min(aP2.Y(), aVMin);
+ aVMax = Max(aP2.Y(), aVMax);
+
+ if(anOrient == TopAbs_FORWARD )
+ {
+ //isobuild.Trim(P1,P2);
+ aTabPoints.Append (aP1);
+ aTabPoints.Append (aP2);
+ }
+ else
+ {
+ //isobuild.Trim(P2,P1);
+ aTabPoints.Append (aP2);
+ aTabPoints.Append (aP1);
+ }
+ }
+ }
+ }
+ else
+ {
+ cout << "Cannot evaluate curve on surface"<<endl;
+ }
+ }
+ else
+ {
+ anU1 = aRCurve.FirstParameter();
+ anU2 = aRCurve.LastParameter();
+ // MSV 17.08.06 OCC13144: U2 occured less than U1, to overcome it
+ // ensure that distance U2-U1 is not greater than aLimit*2,
+ // if greater then choose an origin and use aLimit to define
+ // U1 and U2 anew
+ Standard_Real aOrigin = 0.;
+ if (!Precision::IsNegativeInfinite(anU1) || !Precision::IsPositiveInfinite (anU2))
+ {
+ if (Precision::IsNegativeInfinite (anU1))
+ {
+ aOrigin = anU2 - aLimit;
+ }
+ else if (Precision::IsPositiveInfinite (anU2))
+ {
+ aOrigin = anU1 + aLimit;
+ }
+ else
+ {
+ aOrigin = (anU1 + anU2) * 0.5;
+ }
+ }
+
+ anU1 = Max (aOrigin - aLimit, anU1);
+ anU2 = Min (aOrigin + aLimit, anU2);
+ aP1 = aRCurve.Value (anU1);
+ aP2 = aRCurve.Value (anU2);
+ anUMin = Min(aP1.X(), anUMin);
+ anUMax = Max(aP1.X(), anUMax);
+ aVMin = Min(aP1.Y(), aVMin);
+ aVMax = Max(aP1.Y(), aVMax);
+ anUMin = Min(aP2.X(), anUMin);
+ anUMax = Max(aP2.X(), anUMax);
+ aVMin = Min(aP2.Y(), aVMin);
+ aVMax = Max(aP2.Y(), aVMax);
+ if(anOrient == TopAbs_FORWARD )
+ {
+ // isobuild.Trim(P1,P2);
+ aTabPoints.Append (aP1);
+ aTabPoints.Append (aP2);
+ }
+ else
+ {
+ //isobuild.Trim(P2,P1);
+ aTabPoints.Append (aP2);
+ aTabPoints.Append (aP1);
+ }
+ }
+ }
+ }
+
+ // load the isos
+ const Standard_Real anIntersectionTolerance = 1.e-5;
+ Hatch_Hatcher anIsoBuild (anIntersectionTolerance, Standard_True );
+
+ Standard_Boolean isUClosed = theFace->IsUClosed();
+ Standard_Boolean isVClosed = theFace->IsVClosed();
+
+ if (!isUClosed)
+ {
+ anUMin = anUMin + (anUMax - anUMin) / 1000.0;
+ anUMax = anUMax - (anUMax - anUMin) /1000.0;
+ }
+
+ if (!isVClosed)
+ {
+ aVMin = aVMin + (aVMax - aVMin) /1000.0;
+ aVMax = aVMax - (aVMax - aVMin) /1000.0;
+ }
+
+ if (theIsDrawUIso)
+ {
+ if (theNBUiso > 0)
+ {
+ isUClosed = Standard_False;
+ Standard_Real aDu= isUClosed ? (anUMax - anUMin) / theNBUiso : (anUMax - anUMin) / (1 + theNBUiso);
+ for (anI = 1; anI <= theNBUiso; anI++)
+ {
+ anIsoBuild.AddXLine (anUMin + aDu*anI);
+ }
+ }
+ }
+ if (theIsDrawVIso)
+ {
+ if (theNBViso > 0)
+ {
+ isVClosed = Standard_False;
+ Standard_Real aDv= isVClosed ? (aVMax - aVMin) / theNBViso : (aVMax - aVMin) / (1 + theNBViso);
+ for (anI = 1; anI <= theNBViso; anI++)
+ {
+ anIsoBuild.AddYLine (aVMin + aDv*anI);
+ }
+ }
+ }
+
+ Standard_Integer aLength = aTabPoints.Length();
+ for (anI = 1; anI <= aLength; anI += 2)
+ {
+ anIsoBuild.Trim (aTabPoints (anI),aTabPoints (anI + 1));
+ }
+
+ // Create the polylines for isos
+ Adaptor3d_IsoCurve anIso;
+ anIso.Load(theFace);
+ Handle(Geom_Curve) aBCurve;
+ const BRepAdaptor_Surface& aBSurf = *(BRepAdaptor_Surface*)&(theFace->Surface());
+ GeomAbs_SurfaceType aType = theFace->GetType();
+
+ Standard_Integer aNumberOfLines = anIsoBuild.NbLines();
+ Handle(Geom_Surface) aGeomSurf;
+ if (aType == GeomAbs_BezierSurface)
+ {
+ aGeomSurf = aBSurf.Bezier();
+ }
+ else if (aType == GeomAbs_BSplineSurface)
+ {
+ aGeomSurf = aBSurf.BSpline();
+ }
+
+ Standard_Real aDeflection = GetDeflection();
+ Standard_Real anAngle = GetDeviationAngle();
+ for (anI = 1; anI <= aNumberOfLines; anI++)
+ {
+ Standard_Integer aNumberOfIntervals = anIsoBuild.NbIntervals(anI);
+ Standard_Real aCoord = anIsoBuild.Coordinate(anI);
+ for (Standard_Integer aJ = 1; aJ <= aNumberOfIntervals; aJ++)
+ {
+ Standard_Real aB1 = anIsoBuild.Start (anI, aJ);
+ Standard_Real aB2 = anIsoBuild.End(anI, aJ);
+
+ if (!aGeomSurf.IsNull())
+ {
+ if (anIsoBuild.IsXLine (anI))
+ {
+ aBCurve = aGeomSurf->UIso (aCoord);
+ }
+ else
+ {
+ aBCurve = aGeomSurf->VIso (aCoord);
+ }
+
+ GeomAdaptor_Curve aGeomCurve (aBCurve);
+ FindLimits (aGeomCurve, aLimit, aB1, aB2);
+ if (aB2 - aB1 > Precision::Confusion())
+ {
+ IVtk_Polyline aPoints;
+ DrawCurve (aGeomCurve, aDeflection, anAngle, aB1, aB2, aPoints);
+ thePolylines.Append (aPoints);
+ }
+ }
+ else
+ {
+ if (anIsoBuild.IsXLine (anI))
+ {
+ anIso.Load (GeomAbs_IsoU, aCoord, aB1, aB2);
+ }
+ else
+ {
+ anIso.Load (GeomAbs_IsoV, aCoord, aB1, aB2);
+ }
+ FindLimits (anIso, aLimit, aB1, aB2);
+ if (aB2 - aB1>Precision::Confusion())
+ {
+ IVtk_Polyline aPoints;
+ DrawCurve (anIso, aDeflection, anAngle, aB1, aB2, aPoints);
+ thePolylines.Append (aPoints);
+ }
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : addWFFace
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addWFFace (const TopoDS_Face& theFace,
+ const IVtk_IdType theShapeId)
+{
+ if (theFace.IsNull())
+ {
+ return;
+ }
+
+ TopoDS_Face aFaceToMesh = theFace;
+ aFaceToMesh.Orientation (TopAbs_FORWARD);
+
+ // The code that builds wireframe representation for a TopoDS_Face
+ // has been adapted from some OCCT 6.5.1 methods:
+ // - Prs3d_WFShape::Add()
+ // - StdPrs_WFDeflectionRestrictedFace::Add()
+ // - StdPrs_DeflectionCurve::Add()
+
+ // Add face's edges here but with the face ID
+ TopExp_Explorer anEdgeIter (aFaceToMesh, TopAbs_EDGE );
+ for (; anEdgeIter.More(); anEdgeIter.Next())
+ {
+ TopoDS_Edge anOcctEdge = TopoDS::Edge (anEdgeIter.Current());
+ addEdge (anOcctEdge, theShapeId, myEdgesTypes (anOcctEdge));
+ }
+
+ TopLoc_Location aLoc;
+ const Handle(Geom_Surface)& aGeomSurf = BRep_Tool::Surface (aFaceToMesh, aLoc);
+ if (aGeomSurf.IsNull())
+ {
+ return;
+ }
+
+ BRepAdaptor_Surface aSurf;
+ aSurf.Initialize (aFaceToMesh);
+ Handle(BRepAdaptor_HSurface) aSurfAdaptor = new BRepAdaptor_HSurface (aSurf);
+
+ IVtk_PolylineList aPolylines;
+ gp_Trsf aDummyTrsf;
+
+ // Building U isolines
+ // Introducing a local scope here to simplify variable naming
+ {
+ buildIsoLines (aSurfAdaptor,
+ myNbIsos[0],
+ Standard_False,
+ myNbIsos[0],
+ 0,
+ aPolylines);
+
+ IVtk_PolylineList::Iterator anIt (aPolylines);
+ for (; anIt.More(); anIt.Next())
+ {
+ const IVtk_Polyline& aPntSeq = anIt.Value();
+ Standard_Integer aNbNodes = aPntSeq.Length();
+ TColgp_Array1OfPnt aPoints (1, aNbNodes);
+ for (Standard_Integer aJ = 1; aJ <= aNbNodes; aJ++)
+ {
+ aPoints.SetValue (aJ, aPntSeq.Value(aJ));
+ }
+
+ TColStd_Array1OfInteger aPointIds (1, aNbNodes);
+ for (Standard_Integer anI = 1; anI <= aNbNodes; anI++)
+ {
+ aPointIds.SetValue (anI, anI);
+ }
+
+ processPolyline (aNbNodes,
+ aPoints,
+ aPointIds,
+ theShapeId,
+ true,
+ aDummyTrsf,
+ MT_IsoLine);
+ }
+ }
+
+ // Building V isolines
+ {
+ aPolylines.Clear();
+ buildIsoLines (aSurfAdaptor,
+ Standard_False,
+ myNbIsos[1],
+ 0,
+ myNbIsos[1],
+ aPolylines);
+
+ IVtk_PolylineList::Iterator anIt (aPolylines);
+ for (; anIt.More(); anIt.Next())
+ {
+ const IVtk_Polyline& aPntSeq = anIt.Value();
+ Standard_Integer aNbNodes = aPntSeq.Length();
+ TColgp_Array1OfPnt aPoints (1, aNbNodes);
+ for (int aJ = 1; aJ <= aNbNodes; aJ++)
+ {
+ aPoints.SetValue (aJ, aPntSeq.Value (aJ));
+ }
+
+ TColStd_Array1OfInteger aPointIds (1, aNbNodes);
+ for (Standard_Integer anI = 1; anI <= aNbNodes; anI++)
+ {
+ aPointIds.SetValue (anI, anI);
+ }
+
+ processPolyline (aNbNodes,
+ aPoints,
+ aPointIds,
+ theShapeId,
+ true,
+ aDummyTrsf,
+ MT_IsoLine);
+ }
+ }
+}
+
+//================================================================
+// Function : addShadedFace
+// Purpose :
+//================================================================
+void IVtkOCC_ShapeMesher::addShadedFace (const TopoDS_Face& theFace,
+ const IVtk_IdType theShapeId)
+{
+ if (theFace.IsNull())
+ {
+ return;
+ }
+
+ // Build triangulation of the face.
+ TopLoc_Location aLoc;
+ Handle(Poly_Triangulation) anOcctTriangulation = BRep_Tool::Triangulation (theFace, aLoc);
+ if (anOcctTriangulation.IsNull())
+ {
+ return;
+ }
+
+ gp_Trsf aPntTransform;
+ Standard_Boolean noTransform = Standard_True;
+ if (!aLoc.IsIdentity())
+ {
+ noTransform = Standard_False;
+ aPntTransform = aLoc.Transformation();
+ }
+
+ // Get triangulation points.
+ const TColgp_Array1OfPnt& aPoints = anOcctTriangulation->Nodes();
+ Standard_Integer aNbPoints = anOcctTriangulation->NbNodes();
+
+ // Keep inserted points id's of triangulation in an array.
+ NCollection_Array1<IVtk_PointId> aPointIds (1, aNbPoints);
+ IVtk_PointId anId;
+
+ Standard_Integer anI;
+ for (anI = 1; anI <= aNbPoints; anI++)
+ {
+ gp_Pnt aPoint = aPoints (anI);
+
+ if (!noTransform)
+ {
+ aPoint.Transform (aPntTransform);
+ }
+
+ // Add a point into output shape data and keep its id in the array.
+ anId = myShapeData->InsertCoordinate (aPoint.X(), aPoint.Y(), aPoint.Z());
+ aPointIds.SetValue (anI, anId);
+ }
+
+ // Create triangles on the created triangulation points.
+ const Poly_Array1OfTriangle& aTriangles = anOcctTriangulation->Triangles();
+ Standard_Integer aNbTriangles = anOcctTriangulation->NbTriangles();
+ Standard_Integer aN1, aN2, aN3;
+ for (anI = 1; anI <= aNbTriangles; anI++)
+ {
+ aTriangles(anI).Get (aN1, aN2, aN3); // get indexes of triangle's points
+ // Insert new triangle on these points into output shape data.
+ myShapeData->InsertTriangle (
+ theShapeId, aPointIds(aN1), aPointIds(aN2), aPointIds(aN3), MT_ShadedFace);
+ }
+}
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKOCC_SHAPEMESHER_H__
+#define __IVTKOCC_SHAPEMESHER_H__
+
+#include <BRepAdaptor_HSurface.hxx>
+#include <IVtkOCC_Shape.hxx>
+#include <IVtk_IShapeMesher.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TColgp_SequenceOfPnt.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ShapeMapHasher.hxx>
+
+typedef NCollection_DataMap <TopoDS_Shape, IVtk_MeshType, TopTools_ShapeMapHasher> IVtk_ShapeTypeMap;
+typedef NCollection_Sequence <gp_Pnt> IVtk_Polyline;
+typedef NCollection_List <IVtk_Polyline> IVtk_PolylineList;
+
+DEFINE_STANDARD_HANDLE( IVtkOCC_ShapeMesher, IVtk_IShapeMesher )
+
+//! @class IVtkOCC_ShapeMesher
+//! @brief OCC implementation of IMesher interface.
+//!
+//! Mesher produces shape data using implementation of IShapeData interface for
+//! VTK and then result can be retrieved from this implementation as a vtkPolyData:
+//! @image html doc/img/image002.gif
+//! Then the resulting vtkPolyData can be used for initialization of VTK pipeline.
+class IVtkOCC_ShapeMesher : public IVtk_IShapeMesher
+{
+public:
+ IVtkOCC_ShapeMesher (const Standard_Real& theDevCoeff = 0.0001,
+ const Standard_Real& theDevAngle = 12.0 * M_PI / 180.0,
+ const Standard_Integer theNbUIsos = 1,
+ const Standard_Integer theNbVIsos = 1)
+ : myDevCoeff (theDevCoeff),
+ myDevAngle (theDevAngle),
+ myDeflection (0.0),
+ myPointId (0)
+ {
+ myNbIsos[0] = theNbUIsos;
+ myNbIsos[1] = theNbVIsos;
+ }
+
+ virtual ~IVtkOCC_ShapeMesher() { }
+
+ //! Returns absolute deflection used by this algorithm.
+ //! This value is calculated on the basis of the shape's bounding box.
+ //! Zero might be returned in case if the underlying OCCT shape
+ //! is empty or invalid. Thus check the returned value before
+ //! passing it to OCCT meshing algorithms!
+ //! @return absolute deflection value
+ Standard_EXPORT Standard_Real GetDeflection() const;
+
+ //! Returns relative deviation coefficient used by this algorithm.
+ //! @return relative deviation coefficient
+ Standard_Real GetDeviationCoeff() const
+ {
+ return myDevCoeff;
+ }
+
+ //! Returns deviation angle used by this algorithm.
+ //! This is the maximum allowed angle between the normals to the
+ //! curve/surface and the normals to polyline/faceted representation.
+ //! @return deviation angle (in radians)
+ Standard_Real GetDeviationAngle() const
+ {
+ return myDevAngle;
+ }
+
+protected:
+ //! Executes the mesh generation algorithms. To be defined in implementation class.
+ Standard_EXPORT virtual void internalBuild();
+
+private:
+ //! Internal method, generates OCCT triangulation starting from TopoDS_Shape
+ //! @see IVtkOCC_ShapeMesher::addEdge, IVtkOCC_ShapeMesher::addShadedFace
+ void meshShape();
+
+ //! Extracts free vertices from the shape (i.e. those not belonging to any edge)
+ //! and passes the geometry to IPolyData.
+ //! Each vertex is associated with its sub-shape ID.
+ void addFreeVertices();
+
+ //! Adds all the edges (free and non-free) to IPolyData.
+ void addEdges();
+
+ //! Adds wireframe representations of all faces to IPolyData.
+ void addWireFrameFaces();
+
+ //! Adds shaded representations of all faces to IPolyData.
+ void addShadedFaces();
+
+ //! Adds the point coordinates, connectivity info and
+ //! sub-shape ID for the OCCT vertex.
+ //!
+ //! @param theVertex OCCT vertex to be added to the mesh
+ //! @param theShapeId global point ID needed for connectivity data creation
+ void addVertex (const TopoDS_Vertex& theVertex,
+ const IVtk_IdType theShapeId,
+ const IVtk_MeshType theMeshType);
+
+ //! Adds the point coordinates and a polyline for the OCCT edge.
+ //! Note that the edge should be triangulated in advance.
+ //!
+ //! @param theEdge OCCT edge to be meshed
+ //! @param theShapeId the edge's subshape ID
+ //! @see IVtkOCC_ShapeMesher::meshShape
+ void addEdge (const TopoDS_Edge& theEdge,
+ const IVtk_IdType theShapeId,
+ const IVtk_MeshType theMeshType);
+
+ //! Generates wireframe representation of the given TopoDS_Face object
+ //! with help of OCCT algorithms. The resulting polylines are passed to IPolyData
+ //! interface and associated with the given sub-shape ID.
+ //! @param [in] faceToMesh TopoDS_Face object to build wireframe representation for.
+ //! @param [in] shapeId The face' sub-shape ID
+ void addWFFace (const TopoDS_Face& theFace,
+ const IVtk_IdType theShapeId);
+
+ //! Creates shaded representation of the given TopoDS_Face object
+ //! starting from OCCT triangulation that should be created in advance.
+ //! The resulting triangles are passed to IPolyData
+ //! interface and associated with the given sub-shape ID.
+ //! @param [in] faceToMesh TopoDS_Face object to build shaded representation for.
+ //! @param [in] shapeId The face' sub-shape ID
+ //! @see IVtkOCC_ShapeMesher::meshShape, IVtkOCC_ShapeMesher::addEdge
+ void addShadedFace (const TopoDS_Face& theFace,
+ const IVtk_IdType theShapeId);
+
+ //! Internal function, builds polylines for boundary edges
+ //! and isolines of the face. It has been made a class method in order
+ //! to facilitate passing deflection, etc. here.
+ //!
+ //! @param [in] theFace surface adaptor for the face
+ //! @param [in] theIsDrawUIso if equal to Standard_True, U isolines are built
+ //! @param [in] theIsDrawVIso if equal to Standard_True, V isolines are built
+ //! @param [in] theNBUiso number of U isolines
+ //! @param [in] theNBViso number of V isolines
+ //! @param [out] thePolylines container for the generated polylines
+ void buildIsoLines (const Handle(BRepAdaptor_HSurface)& theFace,
+ const Standard_Boolean theIsDrawUIso,
+ const Standard_Boolean theIsDrawVIso,
+ const Standard_Integer theNBUiso,
+ const Standard_Integer theNBViso,
+ IVtk_PolylineList& thePolylines);
+
+ //! Internal helper method that unpacks the input arrays of points and
+ //! connectivity and creates the polyline using IPolyData interface.
+ //! Optionally, the transformation specified through the last argument
+ //! can be applied to each point's coordinates (noTransform == true).
+ //! The polyline is associated with the given sub-shape ID.
+ void processPolyline (Standard_Integer theNbNodes,
+ const TColgp_Array1OfPnt& thePoints,
+ const TColStd_Array1OfInteger& thePointIds,
+ const IVtk_IdType theOcctId,
+ bool theNoTransform,
+ gp_Trsf theTransformation,
+ const IVtk_MeshType theMeshType);
+
+ //! Get the IShape as OCC implementation
+ const IVtkOCC_Shape::Handle GetShapeObj() const;
+
+ DEFINE_STANDARD_RTTI(IVtkOCC_ShapeMesher)
+
+private:
+ IVtk_ShapeTypeMap myEdgesTypes;
+ Standard_Real myDevCoeff;
+ Standard_Real myDevAngle;
+ mutable Standard_Real myDeflection;
+ IVtk_PointId myPointId;
+ Standard_Integer myNbIsos[2];
+};
+
+#endif // __IVTKOCC_SHAPEMESHER_H__
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtk_Types.hxx>
+#include <IVtkOCC_ShapePickerAlgo.hxx>
+#include <IVtkOCC_Shape.hxx>
+#include <IVtkOCC_SelectableObject.hxx>
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
+#include <StdSelect_BRepOwner.hxx>
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo)
+IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo)
+
+//================================================================
+// Function : Constructor
+// Purpose :
+//================================================================
+IVtkOCC_ShapePickerAlgo::IVtkOCC_ShapePickerAlgo() :
+myViewerSelector (new IVtkOCC_ViewerSelector())
+{ }
+
+//================================================================
+// Function : Destructor
+// Purpose :
+//================================================================
+IVtkOCC_ShapePickerAlgo::~IVtkOCC_ShapePickerAlgo()
+{ }
+
+//================================================================
+// Function : SetView
+// Purpose :
+//================================================================
+void IVtkOCC_ShapePickerAlgo::SetView (const IVtk_IView::Handle& theView)
+{
+ myView = theView;
+ Modified();
+}
+
+//================================================================
+// Function : Modified
+// Purpose :
+//================================================================
+void IVtkOCC_ShapePickerAlgo::Modified()
+{
+ myViewerSelector->Update (myView);
+}
+
+//================================================================
+// Function : GetSelectionModes
+// Purpose :
+//================================================================
+IVtk_SelectionModeList IVtkOCC_ShapePickerAlgo::GetSelectionModes (
+ const IVtk_IShape::Handle& theShape) const
+{
+ IVtk_SelectionModeList aRes;
+
+ if (theShape)
+ {
+ // Get shape implementation from shape interface.
+ Handle(IVtkOCC_Shape) aShapeImpl = Handle(IVtkOCC_Shape)::DownCast(theShape);
+
+ // Get selectable object from the shape implementation.
+ Handle(IVtkOCC_SelectableObject) aSelObj =
+ Handle(IVtkOCC_SelectableObject)::DownCast(aShapeImpl->GetSelectableObject());
+
+ if (!aSelObj.IsNull())
+ {
+ IVtk_SelectionMode aSelMode;
+ for (aSelMode = SM_Shape; aSelMode <= SM_Compound; aSelMode = (IVtk_SelectionMode)(aSelMode + 1))
+ {
+ if (myViewerSelector->IsActive (aSelObj, aSelMode))
+ {
+ aRes.Append (aSelMode);
+ }
+ }
+ }
+ }
+
+ return aRes;
+}
+
+//================================================================
+// Function : SetSelectionMode
+// Purpose :
+//================================================================
+void IVtkOCC_ShapePickerAlgo::SetSelectionMode (const IVtk_IShape::Handle& theShape,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn)
+{
+ if (!theShape)
+ {
+ return;
+ }
+
+ // TODO: treatment for mode == -1 - deactivate the shape...
+ // Is this really needed? The picker and all selection classes
+ // are destroyed when shapes are deactivated...
+
+ // Get shape implementation from shape interface.
+ Handle(IVtkOCC_Shape) aShapeImpl =
+ Handle(IVtkOCC_Shape)::DownCast(theShape);
+
+ // Get selectable object from the shape implementation.
+ Handle(IVtkOCC_SelectableObject) aSelObj =
+ Handle(IVtkOCC_SelectableObject)::DownCast(aShapeImpl->GetSelectableObject());
+
+ if (theIsTurnOn)
+ {
+ // If there is no selectable object then create a new one for this shape.
+ if (aSelObj.IsNull())
+ {
+ aSelObj = new IVtkOCC_SelectableObject (aShapeImpl);
+ }
+
+ // If the selectable object has no selection in the given mode
+ if (!aSelObj->HasSelection (theMode))
+ {
+ // then create a new selection in the given mode for this object (shape).
+ Handle(SelectMgr_Selection) aNewSelection = new SelectMgr_Selection (theMode);
+ aSelObj->AddSelection (aNewSelection, theMode);
+ }
+
+ // Update the selection for the given mode according to its status.
+ const Handle(SelectMgr_Selection)& aSel = aSelObj->Selection (theMode);
+
+ switch (aSel->UpdateStatus())
+ {
+ case SelectMgr_TOU_Full:
+ // Recompute the sensitive primitives which correspond to the mode.
+ aSelObj->UpdateSelection (theMode);
+ case SelectMgr_TOU_Partial:
+ {
+ if (aSelObj->HasTransformation())
+ {
+ // Updates locations in all sensitive entities from the Selection and
+ // corresponding entity owners (shapes).
+ aSelObj->UpdateTransformations (aSel);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ // Set status of the selection to "nothing to update".
+ aSel->UpdateStatus (SelectMgr_TOU_None);
+
+ // Activate the selection in the viewer selector.
+ myViewerSelector->Activate (aSelObj->Selection (theMode));
+
+ }
+ else
+ { // turn off the selection mode
+
+ if (!aSelObj.IsNull())
+ {
+ if (aSelObj->HasSelection (theMode))
+ {
+ const Handle(SelectMgr_Selection)& aSel = aSelObj->Selection (theMode);
+ myViewerSelector->Deactivate (aSel);
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : SetSelectionMode
+// Purpose :
+//================================================================
+void IVtkOCC_ShapePickerAlgo::SetSelectionMode (const IVtk_ShapePtrList& theShapes,
+ const IVtk_SelectionMode theMode,
+ const bool /*theIsTurnOn*/)
+{
+ IVtk_IShape::Handle aShape;
+ IVtk_ShapePtrList::Iterator anIt (theShapes);
+ for (; anIt.More(); anIt.Next())
+ {
+ aShape = anIt.Value();
+ SetSelectionMode (aShape, theMode);
+ }
+}
+
+//================================================================
+// Function : Pick
+// Purpose :
+//================================================================
+bool IVtkOCC_ShapePickerAlgo::Pick (const double theX, const double theY)
+{
+ clearPicked();
+
+ // Calling OCCT algortihm
+ myViewerSelector->Pick ((Standard_Integer)theX,
+ (Standard_Integer)theY,
+ myView);
+
+ // Fill the results
+ return processPicked();
+}
+
+//================================================================
+// Function : Pick
+// Purpose :
+//================================================================
+bool IVtkOCC_ShapePickerAlgo::Pick (const double theXMin,
+ const double theYMin,
+ const double theXMax,
+ const double theYMax)
+{
+ clearPicked();
+
+ // Calling OCCT algortihm
+ myViewerSelector->Pick ((Standard_Integer)theXMin,
+ (Standard_Integer)theYMin,
+ (Standard_Integer)theXMax,
+ (Standard_Integer)theYMax,
+ myView);
+
+ // Fill the results
+ return processPicked();
+}
+
+//================================================================
+// Function : Pick
+// Purpose :
+//================================================================
+bool IVtkOCC_ShapePickerAlgo::Pick (double** thePoly,
+ const int theNbPoints)
+{
+ clearPicked();
+
+ // Calling OCCT algortihm
+ myViewerSelector->Pick (thePoly, theNbPoints, myView);
+
+ // Fill the results
+ return processPicked();
+}
+
+//================================================================
+// Function : ShapesPicked
+// Purpose :
+//================================================================
+const IVtk_ShapeIdList& IVtkOCC_ShapePickerAlgo::ShapesPicked() const
+{
+ return myShapesPicked;
+}
+
+//================================================================
+// Function : SubShapesPicked
+// Purpose :
+//================================================================
+void IVtkOCC_ShapePickerAlgo::SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const
+{
+ if (mySubShapesPicked.IsBound (theId))
+ {
+ // Need non-const this to call the map's operator[]
+ IVtkOCC_ShapePickerAlgo* that = const_cast< IVtkOCC_ShapePickerAlgo* >(this);
+ theShapeList = that->mySubShapesPicked (theId);
+ }
+}
+
+//================================================================
+// Function : clearPicked
+// Purpose : Internal method, resets picked data
+//================================================================
+void IVtkOCC_ShapePickerAlgo::clearPicked()
+{
+ myShapesPicked.Clear();
+ mySubShapesPicked.Clear();
+}
+
+//================================================================
+// Function : NbPicked
+// Purpose : Get number of picked entities.
+//================================================================
+int IVtkOCC_ShapePickerAlgo::NbPicked()
+{
+ return myShapesPicked.Extent();
+}
+
+//================================================================
+// Function : processPicked
+// Purpose :
+//================================================================
+bool IVtkOCC_ShapePickerAlgo::processPicked()
+{
+ Standard_Integer aNbPicked = myViewerSelector->NbPicked();
+ Handle(StdSelect_BRepOwner) anEntityOwner;
+ Handle(Message_Messenger) anOutput = Message::DefaultMessenger();
+
+ for (Standard_Integer aDetectIt = 1; aDetectIt <= aNbPicked; aDetectIt++)
+ {
+ // ViewerSelector detects sensitive entities under the mouse
+ // and for each entity returns its entity owner.
+ // StdSelect_BRepOwner instance holds corresponding sub-shape (TopoDS_Shape)
+ // and in general entity owners have a pointer to SelectableObject that can tell us
+ // what is the top-level TopoDS_Shape.
+ anEntityOwner = Handle(StdSelect_BRepOwner)::DownCast (myViewerSelector->Picked (aDetectIt));
+ if (!anEntityOwner.IsNull())
+ {
+ Handle(IVtkOCC_SelectableObject) aSelectable =
+ Handle(IVtkOCC_SelectableObject)::DownCast (anEntityOwner->Selectable());
+
+ if (!aSelectable)
+ {
+ anOutput << "Error: EntityOwner having null SelectableObject picked!";
+ continue;
+ }
+
+ Handle(IVtkOCC_Shape) aSelShape = aSelectable->GetShape();
+ if (!aSelShape)
+ {
+ anOutput << "Error: SelectableObject with null OccShape pointer picked!";
+ continue;
+ }
+
+ IVtk_IdType aTopLevelId = aSelShape->GetId();
+ myShapesPicked.Append (aTopLevelId);
+
+ // Now try to guess if it's the top-level shape itself or just a sub-shape picked
+ TopoDS_Shape aTopLevelShape = aSelShape->GetShape();
+ TopoDS_Shape aSubShape = anEntityOwner->Shape();
+ if (aTopLevelShape.IsNull())
+ {
+ anOutput << "Error: OccShape with null top-level TopoDS_Shape picked!";
+ continue;
+ }
+ if (aSubShape.IsNull())
+ {
+ anOutput << "Error: EntityOwner with null TopoDS_Shape picked!";
+ continue;
+ }
+
+ if (!aSubShape.IsSame (aTopLevelShape))
+ {
+ IVtk_IdType aSubId = aSelShape->GetSubShapeId (aSubShape);
+
+ if (!mySubShapesPicked.IsBound (aTopLevelId))
+ {
+ const IVtk_ShapeIdList aList;
+ mySubShapesPicked.Bind (aTopLevelId, aList);
+ }
+ // Order of selected sub-shapes
+ mySubShapesPicked (aTopLevelId).Append (aSubId);
+ }
+ }
+ }
+
+ return !myShapesPicked.IsEmpty();
+}
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKOCC_SHAPEPICKERALGO_H__
+#define __IVTKOCC_SHAPEPICKERALGO_H__
+
+#include <IVtk_IShapePickerAlgo.hxx>
+#include <IVtkOCC_ViewerSelector.hxx>
+
+DEFINE_STANDARD_HANDLE( IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo )
+
+//! @class IVtkOCC_ShapePickerAlgo
+//! @brief OCC implementation of 3D shapes picking algorithm.
+class IVtkOCC_ShapePickerAlgo : public IVtk_IShapePickerAlgo
+{
+public:
+ typedef Handle(IVtkOCC_ShapePickerAlgo) Handle;
+
+ //! Constructor
+ Standard_EXPORT IVtkOCC_ShapePickerAlgo();
+
+ //! Destructor
+ Standard_EXPORT virtual ~IVtkOCC_ShapePickerAlgo();
+
+ //! Sets the picker's view interface.
+ //! The picker uses the view to obtain parameters of
+ //! the 3D view projection.
+ Standard_EXPORT virtual void SetView (const IVtk_IView::Handle& theView);
+
+ //! Informs the picker that some parameters of the view
+ //! has been modified so it is necessary to recompute internal selection data.
+ //! It makes sense to call this method automatically as soon as
+ //! the underlying VTK object emits its ModifiedEvent.
+ Standard_EXPORT virtual void Modified();
+
+ //! Get number of picked entities.
+ Standard_EXPORT virtual int NbPicked();
+
+ //! Get activated selection modes for a shape.
+ //! @param [in] theShape a shape with activated selection mode(s)
+ //! @return list of active selection modes
+ Standard_EXPORT virtual IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const;
+
+public: //! @name Set selectable shapes and selection modes
+
+ //! Activates/deactivates the given selection mode for the shape.
+ //! If mode == SM_None, the shape becomes non-selectable and
+ //! is removed from the internal selection data.
+ //! @param [in] theShape Shape for which the selection mode should be activated
+ //! @param [in] theMode Selection mode to be activated
+ //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
+ Standard_EXPORT virtual void SetSelectionMode (const IVtk_IShape::Handle& theShape,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn = true);
+
+ //! Activates/deactivates the given selection mode for the shape.
+ //! If mode == SM_None, the shape becomes non-selectable and
+ //! is removed from the internal selection data.
+ //! @param [in] theShapes List of shapes for which the selection mode should be activated
+ //! @param [in] theMode Selection mode to be activated
+ //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
+ Standard_EXPORT virtual void SetSelectionMode (const IVtk_ShapePtrList& theShapes,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn = true);
+
+public: //! @name Picking methods
+
+ Standard_EXPORT virtual bool Pick (const double theX, const double theY);
+
+ Standard_EXPORT virtual bool Pick (const double theXMin,
+ const double theYMin,
+ const double theXMax,
+ const double theYMax);
+
+ Standard_EXPORT virtual bool Pick (double** thePolyLine, const int theNbPoints);
+
+public: //! @name Obtain picking results
+
+ //! @return the list of picked top-level shape IDs,
+ //! in the order of increasing depth (the ID of the shape closest to the eye
+ //! is the first in the list)
+ Standard_EXPORT virtual const IVtk_ShapeIdList& ShapesPicked() const;
+
+ //! @param [in] theId Top-level shape ID
+ //! @param [out] theShapeList the list of picked sub-shape IDs for the given top-level shape ID,
+ //! in the order of increasing depth (the ID of the sub-shape closest to the eye
+ //! is the first in the list)
+ Standard_EXPORT virtual void SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const;
+
+public:
+
+ DEFINE_STANDARD_RTTI(IVtkOCC_ShapePickerAlgo)
+
+private:
+
+ //! Internal method, resets picked data
+ void clearPicked();
+
+ //! Internal method, extracts picked shapes from ViewerSelector
+ //! and prepares the results in the form of IDs:
+ //! In case of top-level shape(s) selected, only myShapesPicked list is filled.
+ //! Otherwise, mySubShapesPicked map is filled in addition, to provide the information
+ //! about selected sub-shapes grouped by their top-level shapes.
+ //! @return true if some shapes has been picked, and false otherwise
+ //! @see IVtkOCC_ShapePickerAlgo::pick
+ bool processPicked();
+
+ IVtk_IView::Handle myView;
+ IVtk_ShapeIdList myShapesPicked;
+ IVtk_SubShapeMap mySubShapesPicked;
+ Handle(IVtkOCC_ViewerSelector) myViewerSelector;
+};
+
+#endif // __IVTKOCC_SHAPEPICKERALGO_H__
--- /dev/null
+// Created on: 2011-10-20
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkOCC_ViewerSelector.hxx>
+#include <Select3D_SensitiveBox.hxx>
+#include <TColgp_Array1OfPnt2d.hxx>
+#include <gp_Quaternion.hxx>
+#include <Graphic3d_Camera.hxx>
+
+IMPLEMENT_STANDARD_HANDLE( IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector )
+IMPLEMENT_STANDARD_RTTIEXT( IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector )
+
+//============================================================================
+// Method: Constructor
+// Purpose:
+//============================================================================
+IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector()
+: SelectMgr_ViewerSelector(),
+myPixTol(2),
+myToUpdateTol(Standard_True)
+{
+ for (Standard_Integer i=0;i<=13;i++) {myCoeff [i] = 0.;myPrevCoeff[i]=0.0;}
+ for (Standard_Integer j=0;j<2;j++) {myCenter [j] = 0.;myPrevCenter[j]=0.0;}
+}
+
+//============================================================================
+// Method: Convert
+// Purpose: Projects all sensitive entities from the given selection container
+// to 2D space
+//============================================================================
+void IVtkOCC_ViewerSelector::Convert (const Handle(SelectMgr_Selection)& theSelection)
+{
+ for (theSelection->Init(); theSelection->More(); theSelection->Next())
+ {
+ if(theSelection->Sensitive()->NeedsConversion())
+ {
+ Handle(Select3D_SensitiveEntity) aSensEntity =
+ *((Handle(Select3D_SensitiveEntity)*) &(theSelection->Sensitive()));
+ aSensEntity->Project (myPrj);
+ if (!tosort)
+ {
+ tosort = Standard_True;
+ }
+ }
+ }
+}
+
+//============================================================================
+// Method: Pick
+// Purpose: Implements point picking
+//============================================================================
+void IVtkOCC_ViewerSelector::Pick (const Standard_Integer theXPix,
+ const Standard_Integer theYPix,
+ const IVtk_IView::Handle& theView)
+{
+ myclip.SetVoid();
+ Update (theView);
+ gp_XY aDispPnt (theXPix, theYPix);
+ gp_XYZ aWorldPnt;
+ gp_Pnt2d aP2d;
+ theView->DisplayToWorld (aDispPnt, aWorldPnt);
+ myPrj->Project (gp_Pnt (aWorldPnt), aP2d);
+ InitSelect (aP2d.X(), aP2d.Y());
+}
+
+//============================================================================
+// Method: Pick
+// Purpose: Picking by rectangle
+//============================================================================
+void IVtkOCC_ViewerSelector::Pick (const Standard_Integer theXMin,
+ const Standard_Integer theYMin,
+ const Standard_Integer theXMax,
+ const Standard_Integer theYMax,
+ const IVtk_IView::Handle& theView)
+{
+ if (myToUpdateTol)
+ {
+ // Compute and set a sensitivity tolerance according to the renderer (viewport).
+ // TODO: Think if this works well in perspective view...'cause result depends
+ // on position on the screen, but we always use the point close to the
+ // screen's origin...
+ gp_XYZ aWorldPnt1, aWorldPnt2;
+ gp_XY aDispPnt1 (0.0, 0.0);
+ gp_XY aDispPnt2 (myPixTol, 0.0);
+ theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
+ theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
+ gp_Pnt aPnt1 (aWorldPnt1);
+ gp_Pnt aPnt2 (aWorldPnt2);
+ SetSensitivity (aPnt2.Distance (aPnt1));
+ myToUpdateTol = Standard_False;
+ }
+ Update (theView);
+
+ gp_XY aDispPnt1 (theXMin, theYMin);
+ gp_XY aDispPnt2 (theXMax, theYMax);
+ gp_XYZ aWorldPnt1, aWorldPnt2;
+
+ gp_Pnt2d aP2d_1, aP2d_2;
+ theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
+ theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
+
+ myPrj->Project (gp_Pnt (aWorldPnt1), aP2d_1);
+ myPrj->Project (gp_Pnt (aWorldPnt2), aP2d_2);
+
+ InitSelect (Min (aP2d_1.X(), aP2d_2.X()),
+ Min (aP2d_1.Y(), aP2d_2.Y()),
+ Max (aP2d_1.X(), aP2d_2.X()),
+ Max (aP2d_1.Y(), aP2d_2.Y()));
+}
+
+//============================================================================
+// Method: Pick
+// Purpose:
+//============================================================================
+void IVtkOCC_ViewerSelector::Pick (double** thePoly,
+ const int theNbPoints,
+ const IVtk_IView::Handle& theView)
+{
+ TColgp_Array1OfPnt2d aPolyline (1, theNbPoints);
+
+ if (myToUpdateTol)
+ {
+ // Compute and set a sensitivity tolerance according to the renderer (viewport).
+ // TODO: Think if this works well in perspective view...'cause result depends
+ // on position on the screen, but we always use the point close to the
+ // screen's origin...
+ gp_XYZ aWorldPnt1, aWorldPnt2;
+ gp_XY aDispPnt1 (0.0, 0.0);
+ gp_XY aDispPnt2 (myPixTol, 0.0);
+ theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
+ theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
+ gp_Pnt aPnt1 (aWorldPnt1);
+ gp_Pnt aPnt2 (aWorldPnt2);
+ SetSensitivity (aPnt2.Distance (aPnt1));
+ myToUpdateTol = Standard_False;
+ }
+
+ Update (theView);
+
+ // Build TColgp_Array1OfPnt2d from input array of doubles
+ gp_XYZ aWorldPnt;
+
+ for (Standard_Integer anIt = 0; anIt < theNbPoints; anIt++)
+ {
+ gp_XY aDispPnt = thePoly[anIt][2] != 0 ? gp_XY (thePoly[anIt][0] / thePoly[anIt][2], thePoly[anIt][1] / thePoly[anIt][2])
+ : gp_XY (thePoly[anIt][0], thePoly[anIt][1]);
+ gp_Pnt2d aP2d;
+ theView->DisplayToWorld (aDispPnt, aWorldPnt);
+ myPrj->Project (gp_Pnt (aWorldPnt), aP2d);
+ aPolyline.SetValue (anIt + 1, aP2d);
+ }
+
+ InitSelect (aPolyline);
+}
+
+//============================================================================
+// Method: Update
+// Purpose: Checks if some projection parameters have changed,
+// and updates the 2D projections of all sensitive entities if necessary.
+//============================================================================
+Standard_Boolean IVtkOCC_ViewerSelector::Update (const IVtk_IView::Handle& theView)
+{
+ static Standard_Real aZoom (0.0);
+
+ // No focal distance by default
+ myPrevCoeff[9] = 0.0;
+ // Parallel projection by default
+ myPrevCoeff[10] = 0.0;
+
+ // Flag related to perspective or parallel projection
+ Standard_Boolean isPerspective = theView->IsPerspective();
+
+ // For perspective projections only
+ if (isPerspective)
+ {
+ // Flag = 1 if perspective projection
+ myPrevCoeff[10] = 1.0;
+ // Focal distance
+ myPrevCoeff[9] = theView->GetDistance();
+ }
+ // View point
+ // Use (0,0,0) as a view reference point:
+
+ theView->GetPosition (myPrevCoeff[0], myPrevCoeff[1], myPrevCoeff[2]);
+
+ // Orientation
+ theView->GetViewUp (myPrevCoeff[3], myPrevCoeff[4], myPrevCoeff[5]);
+ // Projection direction vector
+ theView->GetDirectionOfProjection (myPrevCoeff[6], myPrevCoeff[7], myPrevCoeff[8]);
+
+ // 3D Scale
+ theView->GetScale (myPrevCoeff[11], myPrevCoeff[12], myPrevCoeff[13]);
+
+ // Return the center of this viewport in display coordinates.
+ theView->GetViewCenter (myPrevCenter[0], myPrevCenter[1]);
+
+ Standard_Integer anIt;
+
+ for (anIt=0; anIt <= 13 && (myPrevCoeff[anIt] == myCoeff[anIt]); anIt++) { }
+
+ if (anIt <= 13 || (myPrevCenter[0] != myCenter[0]) || (myPrevCenter[1] != myCenter[1]))
+ {
+ toupdate = Standard_True;
+ myToUpdateTol = Standard_True;
+
+ for (Standard_Integer anI = anIt; anI <= 13; anI++)
+ {
+ myCoeff[anI] = myPrevCoeff[anI];
+ }
+
+ for (Standard_Integer aJ = 0; aJ < 2; aJ++)
+ {
+ myCenter[aJ] = myPrevCenter[aJ];
+ }
+
+ // For orthographic view use only direction of projection and up vector
+ // Panning, and zooming has no effect on 2D selection sensitives.
+ Handle (Graphic3d_Camera) aCamera = new Graphic3d_Camera();
+
+ aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
+ aCamera->SetCenter (gp::Origin());
+ aCamera->SetDirection (gp_Dir (-myCoeff[6], -myCoeff[7], -myCoeff[8]));
+ aCamera->SetUp (gp_Dir (myCoeff[3], myCoeff[4], myCoeff[5]));
+ aCamera->SetDistance (1.0);
+ aCamera->SetAxialScale (gp_XYZ (myCoeff[11], myCoeff[12], myCoeff[13]));
+
+ myPrj = new Select3D_Projector (aCamera->OrientationMatrix(), Graphic3d_Mat4d());
+ }
+
+ if (isPerspective)
+ {
+ if (Abs(theView->GetViewAngle() - aZoom) > 1.e-3)
+ {
+ myToUpdateTol = Standard_True;
+ aZoom = theView->GetViewAngle();
+ }
+ }
+ else
+ {
+ if (Abs (theView->GetParallelScale() - aZoom) > 1.e-3)
+ {
+ myToUpdateTol = Standard_True;
+ aZoom = theView->GetParallelScale();
+ }
+ }
+
+ if(myToUpdateTol)
+ {
+ // Compute and set a sensitivity tolerance according to the view
+ gp_XYZ aWorldPnt1, aWorldPnt2;
+ gp_XY aDispPnt1 (0.0, 0.0);
+ gp_XY aDispPnt2 (myPixTol, 0.0);
+
+ theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
+ theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
+ gp_Pnt aPnt1 (aWorldPnt1);
+ gp_Pnt aPnt2 (aWorldPnt2);
+ SetSensitivity (aPnt2.Distance (aPnt1));
+
+ myToUpdateTol = Standard_False;
+ }
+
+ if(toupdate) UpdateConversion();
+ if(tosort) UpdateSort();
+
+ return Standard_True;
+}
+
+//============================================================================
+// Method: Activate
+// Purpose: Activates the given selection
+//============================================================================
+void IVtkOCC_ViewerSelector::Activate (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Boolean theIsAutomaticProj)
+{
+ tosort = Standard_True;
+
+ if (!myselections.IsBound (theSelection))
+ {
+ myselections.Bind (theSelection, 0);
+ }
+ else if (myselections (theSelection) != 0)
+ {
+ myselections (theSelection) = 0;
+ }
+ if (theIsAutomaticProj)
+ {
+ Convert (theSelection);
+ }
+}
+
+//============================================================================
+// Method: Deactivate
+// Purpose: Deactivate the given selection
+//============================================================================
+void IVtkOCC_ViewerSelector::Deactivate (const Handle(SelectMgr_Selection)& theSelection)
+{
+ if (myselections.IsBound (theSelection))
+ {
+ myselections (theSelection) = 1;
+ tosort = Standard_True;
+ }
+}
+
+//============================================================================
+// Method: PickingLine
+// Purpose: Deactivate the given selection
+//============================================================================
+gp_Lin IVtkOCC_ViewerSelector::PickingLine (const Standard_Real theX,const Standard_Real theY) const
+{
+ return myPrj->Shoot (theX, theY);
+}
--- /dev/null
+// Created on: 2011-10-20
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKOCC_VIEWERSELECTOR_H__
+#define __IVTKOCC_VIEWERSELECTOR_H__
+
+#include <IVtk_IView.hxx>
+#include <Select3D_Projector.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <SelectMgr_ViewerSelector.hxx>
+
+// -----------------------------------------------------------------------------
+//! @class IVtkOCC_ViewerSelector
+//! @brief Class that implements OCCT selection algorithm.
+//!
+//! Inspired by StdSelect_ViewerSelector3d class from OCCT 6.5.1
+
+class IVtkOCC_ViewerSelector : public SelectMgr_ViewerSelector
+{
+public:
+ IVtkOCC_ViewerSelector();
+
+ //! Projects all sensitive entities from the given selection container to 2D space
+ //! param [in] theSelection Container with sensitive entities to project
+ void Convert (const Handle(SelectMgr_Selection)& theSelection);
+
+ //! Implements point picking
+ //! @param [in] theXPix, theYPix Display coordinates of the point
+ //! @param [in] theView ICamera interface to update the projection parameters.
+ void Pick (const Standard_Integer theXPix,
+ const Standard_Integer theYPix,
+ const IVtk_IView::Handle& theView);
+
+ //! Picking by rectangle
+ //! @param [in] theXMin, theYMin, theXMax, theYMax Rectangle coords
+ //! @param [in] theView ICamera interface to calculate projections
+ void Pick (const Standard_Integer theXMin,
+ const Standard_Integer theYMin,
+ const Standard_Integer theXMax,
+ const Standard_Integer theYMax,
+ const IVtk_IView::Handle& theView);
+
+ //! Implements point picking
+ void Pick (double** thePoly, const int theNbPoints, const IVtk_IView::Handle& theView);
+
+ //! Activates the given selection
+ void Activate (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Boolean isAutomaticProj = Standard_True);
+
+ //! Deactivate the given selection
+ void Deactivate (const Handle(SelectMgr_Selection)& theSelection);
+
+ //! Checks if some projection parameters have changed,
+ //! and updates the 2D projections of all sensitive entities if necessary.
+ //! @param [in] theView Interface to VTK renderer to access projection parameters
+ Standard_Boolean Update (const IVtk_IView::Handle& theView);
+
+ //! Returns picking line.
+ //! @param theX direction X.
+ //! @param theX direction Y.
+ //! @return picking direction.
+ virtual gp_Lin PickingLine (const Standard_Real theX, const Standard_Real theY) const;
+
+ DEFINE_STANDARD_RTTI( IVtkOCC_ViewerSelector )
+
+private:
+ Standard_Real myCoeff[14];
+ Standard_Real myPrevCoeff[14];
+ Standard_Real myCenter[2];
+ Standard_Real myPrevCenter[2];
+ Standard_Integer myPixTol;
+ Handle(Select3D_Projector) myPrj;
+ Standard_Boolean myToUpdateTol;
+};
+
+DEFINE_STANDARD_HANDLE( IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector )
+#endif // __IVTKOCC_VIEWERSELECTOR_H__
--- /dev/null
+CSF_VTK
\ No newline at end of file
--- /dev/null
+EXTERNLIB
+IVtkTools.hxx
+IVtkTools.cxx
+IVtkTools_DisplayModeFilter.hxx
+IVtkTools_DisplayModeFilter.cxx
+IVtkTools_ShapeDataSource.hxx
+IVtkTools_ShapeDataSource.cxx
+IVtkTools_ShapeObject.hxx
+IVtkTools_ShapeObject.cxx
+IVtkTools_ShapePicker.hxx
+IVtkTools_ShapePicker.cxx
+IVtkTools_SubPolyDataFilter.hxx
+IVtkTools_SubPolyDataFilter.cxx
\ No newline at end of file
--- /dev/null
+// Created on: 2011-12-20
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkTools.hxx>
+#include <IVtkVTK_ShapeData.hxx>
+#include <vtkLookupTable.h>
+#include <vtkMapper.h>
+
+namespace IVtkTools
+{
+//============================================================================
+// Method: InitLookupTable
+// Purpose: Returns vtkLookupTable instance initialized by standrad OCCT colors.
+//============================================================================
+vtkLookupTable* InitLookupTable()
+{
+ vtkLookupTable* aColorTable = vtkLookupTable::New();
+ // Set colors table for 3D shapes
+ double aRange[2];
+ aRange[0] = MT_Undefined;
+ aRange[1] = MT_ShadedFace;
+ aColorTable->Allocate (9);
+ aColorTable->SetNumberOfTableValues (9);
+ aColorTable->SetTableRange (aRange);
+ aColorTable->SetValueRange (0, 1);
+/*
+ MT_Undefined = -1 Undefined
+ MT_IsoLine = 0 IsoLine
+ MT_FreeVertex = 1 Free vertex
+ MT_SharedVertex = 2 Shared vertex
+ MT_FreeEdge = 3 Free edge
+ 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
+*/
+ aColorTable->SetTableValue (0, 0, 0, 0); // Undefined
+ aColorTable->SetTableValue (1, 0.5, 0.5, 0.5); // gray for IsoLine
+ aColorTable->SetTableValue (2, 1, 0, 0); // red for Free vertex
+ aColorTable->SetTableValue (3, 1, 1, 0); // yellow for Shared vertex
+ aColorTable->SetTableValue (4, 1, 0, 0); // red for Free edge
+ aColorTable->SetTableValue (5, 0, 1, 0); // green for Boundary edge (related to a single face)
+ aColorTable->SetTableValue (6, 1, 1, 0); // yellow for Shared edge (related to several faces)
+ aColorTable->SetTableValue (7, 1, 1, 0); // yellow for Wireframe face
+ aColorTable->SetTableValue (8, 1, 1, 0); // yellow for Shaded face
+ return aColorTable;
+}
+
+//============================================================================
+// Method: SetLookupTableColor
+// Purpose: Set a color for given type of sub-shapes.
+//============================================================================
+void SetLookupTableColor (vtkLookupTable* theColorTable,
+ const IVtk_MeshType theColorRole,
+ const double theR, const double theG, const double theB,
+ const double /*theA*/)
+{
+ theColorTable->SetTableValue (theColorRole + 1, theR, theG, theB);
+}
+
+//============================================================================
+// Method: GetLookupTableColor
+// Purpose: Get a color for given type of sub-shapes.
+//============================================================================
+void GetLookupTableColor (vtkLookupTable* theColorTable,
+ const IVtk_MeshType theColorRole,
+ double &theR, double &theG, double &theB)
+{
+ double aRgb[3];
+ theColorTable->GetColor (theColorRole + 1, aRgb);
+ theR = aRgb[0];
+ theG = aRgb[1];
+ theB = aRgb[2];
+}
+
+//============================================================================
+// Method: GetLookupTableColor
+// Purpose: Get a color for given type of sub-shapes.
+//============================================================================
+void GetLookupTableColor (vtkLookupTable* theColorTable,
+ const IVtk_MeshType theColorRole,
+ double &theR, double &theG, double &theB,
+ double &theA)
+{
+ theA = theColorTable->GetOpacity (theColorRole + 1);
+ GetLookupTableColor (theColorTable, theColorRole, theR, theG, theB);
+}
+
+//============================================================================
+// Method: InitShapeMapper
+// Purpose: Set up the initial shape mapper parameters with default OCC colors.
+//============================================================================
+void InitShapeMapper (vtkMapper* theMapper)
+{
+ InitShapeMapper (theMapper, InitLookupTable());
+}
+
+//============================================================================
+// Method: InitShapeMapper
+// Purpose: Set up the initial shape mapper parameters with user colors.
+//============================================================================
+void InitShapeMapper (vtkMapper* theMapper, vtkLookupTable* theColorTable)
+{
+ theMapper->ScalarVisibilityOn();
+ theMapper->SetScalarModeToUseCellFieldData();
+ theMapper->SelectColorArray (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES);
+ theMapper->SetColorModeToMapScalars();
+ theMapper->SetScalarRange (theColorTable->GetRange());
+ theMapper->SetLookupTable (theColorTable);
+ theMapper->Update();
+}
+};
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 IVtkTOOLS_H
+#define IVtkTOOLS_H
+
+#include <IVtk_Types.hxx>
+
+#if defined(_WIN32) && !defined(HAVE_NO_DLL)
+ #ifdef __IVtkTools_DLL
+ #define IVtkTools_EXPORT __declspec( dllexport )
+ #else
+ #define IVtkTools_EXPORT __declspec( dllimport )
+ #endif
+#else
+ #define IVtkTools_EXPORT
+#endif
+
+class vtkLookupTable;
+class vtkMapper;
+
+//! Helper methods to facilitate usage of VIS classes in an application.
+namespace IVtkTools
+{
+
+ //! Returns vtkLookupTable instance initialized by standrad OCCT colors used
+ //! in wireframe mode for different kinds of sub-shapes (free/boundary/shared
+ //! edges, isolines,...)
+ Standard_EXPORT vtkLookupTable* InitLookupTable();
+
+ //! Set a color for given type of sub-shapes.
+ //! @param [in,out] theColorTable vtkLookupTable to set the color.
+ //! @param [in] theColorRole type of sub-shapes to set the color.
+ //! @param [in] theR red color component. Use [0,1] double values.
+ //! @param [in] theG green color component. Use [0,1] double values.
+ //! @param [in] theB blue color component. Use [0,1] double values.
+ //! @param [in] theA the alpha value (the opacity) as a double between 0 and 1.
+ Standard_EXPORT void SetLookupTableColor (vtkLookupTable* theColorTable,
+ const IVtk_MeshType theColorRole,
+ const double theR, const double theG, const double theB,
+ const double theA = 1);
+
+ //! Get a color for given type of sub-shapes.
+ //! @param [in] theColorTable vtkLookupTable to set the color.
+ //! @param [in] theColorRole type of sub-shapes to set the color.
+ //! @param [out] theR red color component as a double between 0 and 1.
+ //! @param [out] theG green color component as a double between 0 and 1.
+ //! @param [out] theB blue color component as a double between 0 and 1.
+ Standard_EXPORT void GetLookupTableColor (vtkLookupTable* theColorTable,
+ const IVtk_MeshType theColorRole,
+ double &theR, double &theG, double &theB);
+
+ //! Get a color for given type of sub-shapes.
+ //! @param [in] theColorTable vtkLookupTable to set the color.
+ //! @param [in] theColorRole type of sub-shapes to set the color.
+ //! @param [out] theR red color component as a double between 0 and 1.
+ //! @param [out] theG green color component as a double between 0 and 1.
+ //! @param [out] theB blue color component as a double between 0 and 1.
+ //! @param [out] theA the alpha value (the opacity) as a double between 0 and 1.
+ Standard_EXPORT void GetLookupTableColor (vtkLookupTable* theColorTable,
+ const IVtk_MeshType theColorRole,
+ double &theR, double &theG, double &theB,
+ double &theA);
+
+ //! Set up the initial shape mapper parameters with default OCC colors.
+ Standard_EXPORT void InitShapeMapper (vtkMapper* theMapper);
+
+ //! Set up the initial shape mapper parameters with user colors.
+ //! @param [in,out] theMapper mapper to initialize
+ //! @param [in] theColorTable a table with user's colors definition
+ Standard_EXPORT void InitShapeMapper (vtkMapper* theMapper,
+ vtkLookupTable* theColorTable);
+
+};
+
+#endif // IVtkTOOLS_H
--- /dev/null
+// Created on: 2011-11-15
+// Created by: Roman KOZLOV
+// Copyright (c) 2001-2012 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 <IVtkTools_DisplayModeFilter.hxx>
+#include <IVtkVTK_ShapeData.hxx>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkObjectFactory.h>
+
+vtkStandardNewMacro(IVtkTools_DisplayModeFilter);
+
+//============================================================================
+// Method: Constructor
+// Purpose:
+//============================================================================
+IVtkTools_DisplayModeFilter::IVtkTools_DisplayModeFilter()
+ : myDisplayMode (DM_Wireframe),
+ myDoDisplaySharedVertices (false)
+{
+ // Filter according to values in subshapes types array.
+ myIdsArrayName = IVtkVTK_ShapeData::ARRNAME_MESH_TYPES;
+
+ IVtk_IdTypeMap aTypes;
+
+ aTypes.Add (MT_IsoLine);
+ aTypes.Add (MT_FreeVertex);
+ aTypes.Add (MT_FreeEdge);
+ aTypes.Add (MT_BoundaryEdge);
+ aTypes.Add (MT_SharedEdge);
+ aTypes.Add (MT_WireFrameFace);
+
+ myModesDefinition.Bind (DM_Wireframe, aTypes);
+
+ aTypes.Clear();
+ aTypes.Add (MT_FreeVertex);
+ aTypes.Add (MT_ShadedFace);
+
+ myModesDefinition.Bind (DM_Shading, aTypes);
+}
+
+//============================================================================
+// Method: Destructor
+// Purpose:
+//============================================================================
+IVtkTools_DisplayModeFilter::~IVtkTools_DisplayModeFilter() { }
+
+//============================================================================
+// Method: RequestData
+// Purpose: Filters cells according to the selected display mode by mesh
+// parts types.
+//============================================================================
+int IVtkTools_DisplayModeFilter::RequestData (vtkInformation *theRequest,
+ vtkInformationVector **theInputVector,
+ vtkInformationVector *theOutputVector)
+{
+ SetData (myModesDefinition.Find (myDisplayMode));
+ return Superclass::RequestData (theRequest, theInputVector, theOutputVector);
+}
+
+//============================================================================
+// Method: PrintSelf
+// Purpose:
+//============================================================================
+void IVtkTools_DisplayModeFilter::PrintSelf (std::ostream& theOs, vtkIndent theIndent)
+{
+ this->Superclass::PrintSelf (theOs, theIndent);
+ theOs << theIndent << "IVtkTools_DisplayModeFilter: display mode = ";
+ if (myDisplayMode == DM_Wireframe)
+ {
+ theOs << "Wireframe\n";
+ }
+ else
+ {
+ theOs << "Shading\n";
+ }
+}
+
+//============================================================================
+// Method: SetDisplaySharedVertices
+// Purpose:
+//============================================================================
+void IVtkTools_DisplayModeFilter::SetDisplaySharedVertices (const bool theDoDisplay)
+{
+ 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())
+ {
+ aModeTypes = aModes.Value();
+ if (theDoDisplay && !aModeTypes.Contains(aVertexType))
+ {
+ aModeTypes.Add (aVertexType);
+ }
+ else if (!theDoDisplay && aModeTypes.Contains (aVertexType))
+ {
+ aModeTypes.Remove (aVertexType);
+ }
+ aNewModes.Bind (aModes.Key(), aModeTypes);
+ }
+ myModesDefinition = aNewModes;
+ Modified();
+ }
+}
+
+//============================================================================
+// Method: SetDisplayMode
+// Purpose:
+//============================================================================
+void IVtkTools_DisplayModeFilter::SetDisplayMode(const IVtk_DisplayMode theMode)
+{
+ if (myDisplayMode != theMode)
+ {
+ myDisplayMode = theMode;
+ Modified();
+ }
+}
+
+//============================================================================
+// Method: GetDisplayMode
+// Purpose:
+//============================================================================
+const IVtk_DisplayMode IVtkTools_DisplayModeFilter::GetDisplayMode () const
+{
+ return myDisplayMode;
+}
+
--- /dev/null
+// Created on: 2011-11-15
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 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 IVtkTOOLS_DISPLAYMODEFILTER_H
+#define IVtkTOOLS_DISPLAYMODEFILTER_H
+
+#include <IVtkTools.hxx>
+#include <IVtkTools_SubPolyDataFilter.hxx>
+#include <IVtk_Types.hxx>
+#include <NCollection_DataMap.hxx>
+
+//! @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
+//! display modes.
+class Standard_EXPORT IVtkTools_DisplayModeFilter : public IVtkTools_SubPolyDataFilter
+{
+public:
+ vtkTypeMacro(IVtkTools_DisplayModeFilter,IVtkTools_SubPolyDataFilter);
+ static IVtkTools_DisplayModeFilter *New();
+ void PrintSelf (std::ostream& os, vtkIndent indent);
+
+ //! Set display mode to define cells types to be passed through this filter.
+ void SetDisplayMode (const IVtk_DisplayMode aMode);
+
+ //! Display or not shared vertices.
+ void SetDisplaySharedVertices (const bool doDisplay);
+
+ //! Get current display mode.
+ const IVtk_DisplayMode GetDisplayMode() const;
+
+protected:
+ //! Filter cells according to the given set of ids.
+ virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *);
+
+ IVtkTools_DisplayModeFilter();
+ ~IVtkTools_DisplayModeFilter();
+
+protected:
+ //! Display mode defining mesh types to pass through this filter.
+ IVtk_DisplayMode myDisplayMode;
+ NCollection_DataMap<IVtk_DisplayMode, IVtk_IdTypeMap> myModesDefinition;
+ bool myDoDisplaySharedVertices;
+};
+
+#endif // IVtkTOOLS_DISPLAYMODEFILTER_H
+
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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.
+
+// VIS includes
+#include <IVtkOCC_ShapeMesher.hxx>
+#include <IVtkTools_ShapeDataSource.hxx>
+#include <IVtkTools_ShapeObject.hxx>
+
+// VTK includes
+#include <vtkCellArray.h>
+#include <vtkCellData.h>
+#include <vtkDoubleArray.h>
+#include <vtkIdTypeArray.h>
+#include <vtkInformation.h>
+#include <vtkObjectFactory.h>
+#include <vtkPoints.h>
+#include <vtkPolyData.h>
+#include <vtkStreamingDemandDrivenPipeline.h>
+#include <vtkTransform.h>
+#include <vtkTransformPolyDataFilter.h>
+
+vtkStandardNewMacro(IVtkTools_ShapeDataSource);
+
+//================================================================
+// Function : Constructor
+// Purpose :
+//================================================================
+IVtkTools_ShapeDataSource::IVtkTools_ShapeDataSource()
+: myPolyData (new IVtkVTK_ShapeData),
+ myIsFastTransformMode (Standard_False),
+ myIsTransformOnly (Standard_False)
+{
+ this->SetNumberOfInputPorts (0);
+}
+
+//================================================================
+// Function : Destructor
+// Purpose :
+//================================================================
+IVtkTools_ShapeDataSource::~IVtkTools_ShapeDataSource()
+{ }
+
+//================================================================
+// Function : SetShape
+// Purpose :
+//================================================================
+void IVtkTools_ShapeDataSource::SetShape (const IVtkOCC_Shape::Handle& theOccShape)
+{
+ if (myIsFastTransformMode && !myOccShape.IsNull() &&
+ theOccShape->GetShape().IsPartner (myOccShape->GetShape() ) )
+ {
+ myIsTransformOnly = Standard_True;
+ }
+ else
+ {
+ myIsTransformOnly = Standard_False;
+ }
+
+ myOccShape = theOccShape;
+ this->Modified();
+}
+
+//================================================================
+// Function : GetShape
+// Purpose :
+//================================================================
+IVtkOCC_Shape::Handle IVtkTools_ShapeDataSource::GetShape()
+{
+ return myOccShape;
+}
+
+//================================================================
+// Function : RequestData
+// Purpose :
+//================================================================
+int IVtkTools_ShapeDataSource::RequestData (vtkInformation* theRequest,
+ vtkInformationVector** theInputVector,
+ vtkInformationVector* theOutputVector)
+{
+ vtkPolyData* aPolyData = vtkPolyData::GetData (theOutputVector);
+ aPolyData->Allocate();
+ vtkPoints* aPts = vtkPoints::New();
+ aPolyData->SetPoints (aPts);
+ aPts->Delete();
+
+ vtkSmartPointer<vtkPolyData> aTransformedData;
+ TopoDS_Shape aShape = myOccShape->GetShape();
+ TopLoc_Location aShapeLoc = aShape.Location();
+
+ if (myIsTransformOnly)
+ {
+ vtkPolyData* aPrevData = myPolyData->getVtkPolyData();
+ if (!aShapeLoc.IsIdentity() )
+ {
+ aTransformedData = this->transform (aPrevData, aShapeLoc);
+ }
+ else
+ {
+ aTransformedData = aPrevData;
+ }
+ }
+ else
+ {
+ IVtkOCC_Shape::Handle aShapeWrapperCopy;
+ if (myIsFastTransformMode && !aShapeLoc.IsIdentity() )
+ {
+ // Reset location before meshing
+ aShape.Location (TopLoc_Location() );
+ aShapeWrapperCopy = new IVtkOCC_Shape (aShape);
+ aShapeWrapperCopy->SetId (myOccShape->GetId() );
+ }
+ else
+ {
+ aShapeWrapperCopy = myOccShape;
+ }
+
+ myPolyData = new IVtkVTK_ShapeData;
+ IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher;
+ aMesher->Build (aShapeWrapperCopy, myPolyData);
+ vtkPolyData* aMeshData = myPolyData->getVtkPolyData();
+
+ if (myIsFastTransformMode && !aShapeLoc.IsIdentity() )
+ {
+ aTransformedData = this->transform (aMeshData, aShapeLoc);
+ }
+ else
+ {
+ aTransformedData = aMeshData;
+ }
+ }
+
+ aPolyData->CopyStructure (aTransformedData); // Copy points and cells
+ aPolyData->CopyAttributes (aTransformedData); // Copy data arrays (sub-shapes IDs)
+
+ // We store the OccShape instance in a IVtkTools_ShapeObject
+ // wrapper in vtkInformation object of vtkDataObject, then pass it
+ // to the actors through pipelines, so selection logic can access
+ // OccShape easily given the actor instance.
+ IVtkTools_ShapeObject::SetShapeSource (this, aPolyData);
+ aPolyData->GetAttributes (vtkDataObject::CELL)->SetPedigreeIds (SubShapeIDs() );
+
+ return Superclass::RequestData (theRequest, theInputVector, theOutputVector);
+}
+
+//================================================================
+// Function : SubShapeIDs
+// Purpose :
+//================================================================
+vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs()
+{
+ vtkDataArray* arr = GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
+ return vtkSmartPointer<vtkIdTypeArray>( vtkIdTypeArray::SafeDownCast(arr) );
+}
+
+//================================================================
+// Function : GetId
+// Purpose :
+//================================================================
+IVtk_IdType IVtkTools_ShapeDataSource::GetId() const
+{
+ return myOccShape ? myOccShape->GetId() : -1;
+}
+
+//================================================================
+// Function : Contains
+// Purpose :
+//================================================================
+Standard_Boolean IVtkTools_ShapeDataSource::Contains (const IVtkOCC_Shape::Handle& shape) const
+{
+ return ((myOccShape == shape) ? Standard_True : Standard_False);
+}
+
+//================================================================
+// Function : transform
+// Purpose :
+//================================================================
+vtkSmartPointer<vtkPolyData> IVtkTools_ShapeDataSource::transform (vtkPolyData* theSource,
+ const gp_Trsf& theTrsf) const
+{
+ vtkSmartPointer<vtkPolyData> aResult = vtkSmartPointer<vtkPolyData>::New();
+ aResult->Allocate();
+ vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New();
+ aResult->SetPoints (aPts);
+
+ vtkSmartPointer<vtkTransform> aTransform = vtkSmartPointer<vtkTransform>::New();
+ vtkSmartPointer<vtkMatrix4x4> aMx = vtkSmartPointer<vtkMatrix4x4>::New();
+ for (Standard_Integer aRow = 0; aRow < 3; ++aRow)
+ for (Standard_Integer aCol = 0; aCol < 4; ++aCol)
+ {
+ aMx->SetElement (aRow, aCol, theTrsf.Value (aRow + 1, aCol + 1) );
+ }
+
+ aTransform->SetMatrix (aMx);
+ vtkSmartPointer<vtkTransformPolyDataFilter> aTrsfFilter
+ = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
+
+ aTrsfFilter->SetTransform (aTransform);
+ aTrsfFilter->SetInputData (theSource);
+ aTrsfFilter->Update();
+
+ vtkPolyData* aTransformed = aTrsfFilter->GetOutput();
+ aResult->CopyStructure (aTransformed); // Copy points and cells
+ aResult->CopyAttributes (aTransformed); // Copy data arrays (sub-shapes ids)
+
+ return aResult;
+}
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKTOOLS_SHAPEDATASOURCE_H__
+#define __IVTKTOOLS_SHAPEDATASOURCE_H__
+
+#include <IVtkTools.hxx>
+#include <IVtkOCC_Shape.hxx>
+#include <IVtkVTK_ShapeData.hxx>
+#include <vtkInformationIdTypeKey.h>
+#include <vtkPolyDataAlgorithm.h>
+#include <vtkType.h>
+#include <vtkSmartPointer.h>
+
+class vtkIdTypeArray;
+class vtkPolyData;
+
+//! @class IVtkTools_ShapeDataSource.
+//! @brief VTK data source for OCC shapes polygonal data.
+class IVtkTools_EXPORT IVtkTools_ShapeDataSource : public vtkPolyDataAlgorithm
+{
+public:
+
+ vtkTypeMacro(IVtkTools_ShapeDataSource, vtkPolyDataAlgorithm);
+ static IVtkTools_ShapeDataSource* New();
+
+
+public: //! @name Initialization
+
+ //! Set the source OCCT shape.
+ //! @param theOccShape [in] OCCT shape wrapper.
+ void SetShape(const IVtkOCC_Shape::Handle& theOccShape);
+
+ //! Get the source OCCT shape.
+ //! @return occShape OCCT shape wrapper.
+ IVtkOCC_Shape::Handle GetShape();
+ inline void FastTransformModeOn() { myIsFastTransformMode = true; }
+ inline void FastTransformModeOff() { myIsFastTransformMode = false; }
+
+public: //! @name Data accessors
+
+ //! Returns ID of the shape used as a topological input for this data source.
+ //! @return requested ID.
+ IVtk_IdType GetId() const;
+
+ //! Checks if the internal OccShape pointer is the same the argument.
+ //! @param [in] shape OccShape pointer to be checked.
+ //! @return true if the two OccShape instances are the same, and false otherwise.
+ Standard_Boolean Contains (const IVtkOCC_Shape::Handle& theOccShape) const;
+
+ //! Access to the shape's sub-shape ids array
+ //! @returns the array cast to vtkIdTypeArray
+ vtkSmartPointer<vtkIdTypeArray> SubShapeIDs();
+
+protected: //! @name Interface to override
+
+ //! This is called by the superclass.
+ //! This is the method you should override if you use this class as ancestor.
+ //! Build output polygonal data set from the shape wrapper.
+ //! @param theRequest [in] information about data object.
+ //! In current implementation it is ignored.
+ //! @param theInputVector [in] the input data. As adata source is the start
+ //! stage of the VTK pipeline, theInputVector is empty and not used (no input port).
+ //! @param theOutputVector [in] the pointer to output data, that is filled in this method.
+ virtual int RequestData(vtkInformation* theRequest,
+ vtkInformationVector** theInputVector,
+ vtkInformationVector* theOutputVector);
+
+protected: //! @name Internals
+
+ //! Transforms the passed polygonal data by the given OCCT transformation
+ //! matrix.
+ //! @param theSource [in] source polygonal data to transform.
+ //! @param theTrsf [in] transformation to apply.
+ //! @return resulting polygonal data (transformed copy of source).
+ vtkSmartPointer<vtkPolyData> transform (vtkPolyData* theSource, const gp_Trsf& theTrsf) const;
+
+protected:
+
+ IVtkTools_ShapeDataSource();
+ ~IVtkTools_ShapeDataSource();
+
+private:
+
+ IVtkTools_ShapeDataSource (const IVtkTools_ShapeDataSource&);
+ IVtkTools_ShapeDataSource& operator= (const IVtkTools_ShapeDataSource&);
+
+private:
+
+ IVtkOCC_Shape::Handle myOccShape; //!< Shape wrapper used as an input.
+ IVtkVTK_ShapeData::Handle myPolyData; //!< Polygonal representation of shape.
+
+ //! Indicates whether light-weighted processing for transformed shapes is
+ //! enabled. If so, data source does not re-compute the discrete model for
+ //! the input topological shape. It rather uses the already existing one
+ //! and applies the necessary transformation to it.
+ Standard_Boolean myIsFastTransformMode;
+
+ //! Internal flag indicating that the current working shape is just a
+ //! transformed copy of the previously processed one. This flag is used in
+ //! a couple with "fast transformation" mode flag.
+ Standard_Boolean myIsTransformOnly;
+
+};
+
+#endif // __IVTKTOOLS_SHAPEDATA_H__
--- /dev/null
+// Created on: 2011-10-27
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkTools_ShapeObject.hxx>
+#include <IVtkTools_ShapeDataSource.hxx>
+#include <vtkActor.h>
+#include <vtkObjectBase.h>
+#include <vtkObjectFactory.h>
+#include <vtkDataSet.h>
+#include <vtkInformation.h>
+#include <vtkInformationObjectBaseKey.h>
+#include <vtkDebugLeaks.h>
+#include <vtkPolyData.h>
+
+IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::myKey = 0;
+
+//============================================================================
+// Method: getKey
+// Purpose: Static method to get vtkInformationKey for retrieving OccShape
+// instance from the actor.
+//============================================================================
+IVtkTools_ShapeObject::KeyPtr IVtkTools_ShapeObject::getKey()
+{
+ if (!myKey)
+ {
+ myKey = new vtkInformationObjectBaseKey( "OccShapePtr", "IVtkTools_ShapeObject::Key" );
+ }
+
+ return myKey;
+}
+
+//============================================================================
+// Method: GetOccShape
+// Purpose: Static method to get OCC shape from VTK actor's data from
+// information object by key.
+//============================================================================
+IVtkOCC_Shape::Handle IVtkTools_ShapeObject::GetOccShape (vtkActor* theActor)
+{
+ IVtkOCC_Shape::Handle anOccShape;
+ IVtkTools_ShapeDataSource* aSrc = IVtkTools_ShapeObject::GetShapeSource (theActor);
+ if (aSrc)
+ {
+ anOccShape = aSrc->GetShape();
+ }
+ return anOccShape;
+}
+
+//============================================================================
+// Method: GetShapeSource
+// Purpose: Static method to get OCC shape source from VTK actor's data from
+// information object by key.
+//============================================================================
+IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource (vtkActor* theActor)
+{
+ IVtkTools_ShapeDataSource* anOccShapeSource = 0;
+ vtkInformation* anInfo = theActor->GetPropertyKeys();
+ if (anInfo)
+ {
+ KeyPtr aKey = getKey();
+ if (aKey->Has(anInfo))
+ {
+ IVtkTools_ShapeObject* aShapeObj = (IVtkTools_ShapeObject*)(aKey->Get (anInfo));
+ anOccShapeSource = aShapeObj->GetShapeSource();
+ }
+ }
+ return anOccShapeSource;
+}
+
+//============================================================================
+// Method: SetShapeSource
+// Purpose: Static method to set OCC shape source to VTK dataset in information
+// object with key.
+//============================================================================
+void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
+ vtkDataSet* theDataSet)
+{
+ if (!theDataSet->GetInformation() )
+ {
+ theDataSet->SetInformation (vtkInformation::New());
+ }
+ vtkInformation* aDatasetInfo = theDataSet->GetInformation();
+ KeyPtr aKey = getKey();
+ IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New();
+ aShapeObj->SetShapeSource (theDataSource);
+ aKey->Set(aDatasetInfo, aShapeObj);
+ aShapeObj->Delete();
+}
+
+//============================================================================
+// Method: SetShapeSource
+// Purpose: Static method to set OCC shape source to VTK actor in information
+// object with key.
+//============================================================================
+void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource,
+ vtkActor* theActor)
+{
+ if ( !theActor->GetPropertyKeys() )
+ {
+ theActor->SetPropertyKeys (vtkInformation::New());
+ }
+
+ vtkInformation* anInfo = theActor->GetPropertyKeys();
+ KeyPtr aKey = getKey();
+ IVtkTools_ShapeObject* aShapeObj = IVtkTools_ShapeObject::New();
+ aShapeObj->SetShapeSource (theDataSource);
+ aKey->Set (anInfo, aShapeObj);
+ aShapeObj->Delete();
+}
+
+//! @class IVtkTools_ShapeObject
+//! @brief VTK holder class for OCC shapes to pass them through pipelines.
+vtkStandardNewMacro(IVtkTools_ShapeObject);
+
+//============================================================================
+// Method: Constructor
+// Purpose: Protected constructor.
+//============================================================================
+IVtkTools_ShapeObject::IVtkTools_ShapeObject()
+{ }
+
+//============================================================================
+// Method: Destructor
+// Purpose: Protected destructor.
+//============================================================================
+IVtkTools_ShapeObject::~IVtkTools_ShapeObject()
+{ }
+
+//============================================================================
+// Method: SetShapeSource
+// Purpose:
+//============================================================================
+void IVtkTools_ShapeObject::SetShapeSource (IVtkTools_ShapeDataSource* theDataSource)
+{
+ myShapeSource = theDataSource;
+}
+
+//============================================================================
+// Method: GetShapeSource
+// Purpose:
+//============================================================================
+IVtkTools_ShapeDataSource* IVtkTools_ShapeObject::GetShapeSource () const
+{
+ return myShapeSource;
+}
+
--- /dev/null
+// Created on: 2011-10-27
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKTOOLS_SHAPEOBJECT_H__
+#define __IVTKTOOLS_SHAPEOBJECT_H__
+
+#include <IVtkTools.hxx>
+#include <IVtkOCC_Shape.hxx>
+#include <vtkDataObject.h>
+#include <vtkSetGet.h>
+#include <vtkSmartPointer.h>
+
+class vtkActor;
+class vtkDataSet;
+class vtkInformationObjectBaseKey;
+class IVtkTools_ShapeDataSource;
+
+//! @class IVtkTools_ShapeObject
+//! @brief VTK holder class for OCC shapes to pass them through pipelines.
+//!
+//! It is descendent of vtkObject (data). Logically it is a one of milestones of VTK pipeline.
+//! It stores data of OCC shape (the OccShape instance) in vtkInformation object of vtkDataObject.
+//! Then pass it to the actors through pipelines,
+//! so selection logic can access OccShape easily given the actor instance.
+class IVtkTools_EXPORT IVtkTools_ShapeObject : public vtkDataObject
+{
+public:
+ vtkTypeMacro (IVtkTools_ShapeObject, vtkObject);
+
+ static IVtkTools_ShapeObject* New();
+
+ //! Get OCC shape source from VTK data from actor's information object by key.
+ static IVtkTools_ShapeDataSource* GetShapeSource (vtkActor* theActor);
+
+ //! Get OCC shape from VTK data from actor's information object by key.
+ static IVtkOCC_Shape::Handle GetOccShape (vtkActor* theActor);
+
+ //! Static method to set OCC shape source to VTK dataset in information object
+ //! with key.
+ static void SetShapeSource (IVtkTools_ShapeDataSource* theDataSource, vtkDataSet* theData);
+
+ //! Static method to set OCC shape source to VTK actor in information object
+ //! with key.
+ static void SetShapeSource (IVtkTools_ShapeDataSource* theDataSource, vtkActor* theActor);
+
+ typedef vtkInformationObjectBaseKey* KeyPtr;
+
+ //! Static method used by shape selection logic in order to establish
+ //! a connection from vtkActor to OccShape instance.
+ //! @return vtkInformationKey for retrieving OccShape instance from the actor
+ static KeyPtr getKey();
+
+ //! OCC shape source setter.
+ void SetShapeSource (IVtkTools_ShapeDataSource* theDataSource);
+
+ //! OCC shape source getter.
+ IVtkTools_ShapeDataSource* GetShapeSource () const;
+
+protected:
+ IVtkTools_ShapeObject();
+ ~IVtkTools_ShapeObject();
+
+private: // not copyable
+ IVtkTools_ShapeObject (const IVtkTools_ShapeObject&);
+ IVtkTools_ShapeObject& operator= (const IVtkTools_ShapeObject&);
+
+private: // OCC
+ vtkSmartPointer<IVtkTools_ShapeDataSource> myShapeSource;
+
+ static KeyPtr myKey;
+};
+
+#endif // __IVTKTOOLS_SHAPEOBJECT_H__
--- /dev/null
+// Created on: 2011-10-27
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkTools_ShapePicker.hxx>
+#include <IVtkTools_ShapeObject.hxx>
+#include <IVtkVTK_View.hxx>
+#include <IVtkOCC_Shape.hxx>
+#include <vtkCommand.h>
+#include <vtkObjectFactory.h>
+#include <vtkRenderer.h>
+#include <vtkActorCollection.h>
+
+//! @class IVtkTools_ShapePicker
+//! VTK picker implementation for OCCT shapes.
+//! Can pick either whole shapes or sub-shapes.
+//! The kind of selectable entities is defined by the current selection mode.
+//! NOTE: For performance reasons, setRenderer() method should be called in advance,
+//! before the user starts to select interactively, in order for the OCCT selection
+//! algorithm to prepare its internal selection data.
+
+vtkStandardNewMacro(IVtkTools_ShapePicker);
+
+//============================================================================
+// Method: IVtkTools_ShapePicker
+// Purpose: Constructs the picker with empty renderer and ready for point selection.
+//============================================================================
+IVtkTools_ShapePicker::IVtkTools_ShapePicker()
+: myRenderer (0),
+ myIsRectSelection (false)
+{
+ myOccPickerAlgo = new IVtkOCC_ShapePickerAlgo();
+}
+
+//============================================================================
+// Method: ~IVtkTools_ShapePicker
+// Purpose: Destructor
+//============================================================================
+IVtkTools_ShapePicker::~IVtkTools_ShapePicker()
+{
+}
+
+//============================================================================
+// Method: SetTolerance
+// Purpose: Setter for tolerance of picking.
+//============================================================================
+void IVtkTools_ShapePicker::SetTolerance (float theTolerance )
+{
+ myTolerance = theTolerance;
+}
+
+//============================================================================
+// Method: GetTolerance
+// Purpose: Getter for tolerance of picking.
+//============================================================================
+float IVtkTools_ShapePicker::GetTolerance( ) const
+{
+ return myTolerance;
+}
+
+//============================================================================
+// Method: convertDisplayToWorld
+// Purpose: Convert display coordinates to world coordinates
+//============================================================================
+bool IVtkTools_ShapePicker::convertDisplayToWorld (vtkRenderer *theRenderer,
+ vtkFloatingPointType theDisplayCoord[3],
+ vtkFloatingPointType theWorldCoord[3])
+{
+ // Convert the selection point into world coordinates.
+ theRenderer->SetDisplayPoint (theDisplayCoord[0], theDisplayCoord[1], theDisplayCoord[2]);
+ theRenderer->DisplayToWorld();
+
+ vtkFloatingPointType* const aCoords = theRenderer->GetWorldPoint();
+ if (aCoords[3] == 0.0)
+ {
+ return false;
+ }
+
+ for (Standard_Integer anI = 0; anI < 3; anI++)
+ {
+ theWorldCoord[anI] = aCoords[anI] / aCoords[3];
+ }
+ return true;
+}
+
+//============================================================================
+// Method: Pick
+// Purpose: Pick entities in the given point.
+//============================================================================
+int IVtkTools_ShapePicker::Pick (double theX, double theY, double /*theZ*/, vtkRenderer *theRenderer)
+{
+ double aPos[2] = {theX, theY};
+ myIsRectSelection = false;
+ myIsPolySelection = false;
+ return pick (aPos, theRenderer);
+}
+
+//============================================================================
+// Method: pick
+// Purpose: Pick entities in the given rectangle area.
+//============================================================================
+int IVtkTools_ShapePicker::Pick (double theXPMin, double theYPMin, double theXPMax, double theYPMax,
+ vtkRenderer *theRenderer)
+{
+ double aPos[4] = {theXPMin, theYPMin, theXPMax, theYPMax};
+ myIsRectSelection = true;
+ myIsPolySelection = false;
+ return pick (aPos, theRenderer);
+}
+//============================================================================
+// Method: pick
+// Purpose: Pick entities in the given polygonal area.
+//============================================================================
+int IVtkTools_ShapePicker::Pick (double thePoly[][3], const int theNbPoints,
+ vtkRenderer *theRenderer)
+{
+ myIsRectSelection = false;
+ myIsPolySelection = true;
+ return pick ((double*)thePoly, theRenderer, theNbPoints);
+}
+
+//============================================================================
+// Method: pick
+// Purpose: Pick entities in the given point or area.
+//============================================================================
+int IVtkTools_ShapePicker::pick (double* thePos,
+ vtkRenderer *theRenderer,
+ const int theNbPoints)
+{
+ // Initialize picking process
+ Initialize();
+
+ // Emit StartPickEvent for observer callbacks (if any)
+ InvokeEvent(vtkCommand::StartPickEvent, NULL);
+
+ vtkRenderer* aRenderer;
+ if (theRenderer == NULL)
+ {
+ aRenderer = myRenderer; // by default use own renderer
+ }
+ else
+ {
+ aRenderer = theRenderer;
+ }
+ doPickImpl (thePos, aRenderer, theNbPoints);
+
+ // Emit EndPickEvent for observer callbacks (if any)
+ InvokeEvent(vtkCommand::EndPickEvent, NULL);
+
+ return myOccPickerAlgo->NbPicked();
+}
+
+//============================================================================
+// Method: doPickImpl
+// Purpose: Implementation of picking algorithm.
+//============================================================================
+void IVtkTools_ShapePicker::doPickImpl (double* thePos,
+ vtkRenderer* theRenderer,
+ const int theNbPoints)
+{
+ // Make sure the correct renderer is used
+ SetRenderer (theRenderer);
+
+ if (myIsPolySelection)
+ {
+ myOccPickerAlgo->Pick ((double**)thePos, theNbPoints);
+ }
+ else if (myIsRectSelection)
+ {
+ myOccPickerAlgo->Pick (thePos[0], thePos[1], thePos[2], thePos[3]);
+ }
+ else
+ {
+ myOccPickerAlgo->Pick (thePos[0], thePos[1]);
+ }
+}
+
+//============================================================================
+// Method: SetRenderer
+// Purpose: Sets the renderer to be used by OCCT selection algorithm
+//============================================================================
+void IVtkTools_ShapePicker::SetRenderer (vtkRenderer* theRenderer)
+{
+ if (theRenderer == myRenderer)
+ {
+ return;
+ // In this case we should not do anything.
+ // In the worth case we need to update picker algorithm (view er selector and projection options)
+ // If any needs this , call myOccPickerAlgo->Modified();
+ }
+
+ myRenderer = theRenderer;
+ IVtkVTK_View::Handle aView = new IVtkVTK_View (myRenderer);
+ myOccPickerAlgo->SetView (aView);
+}
+
+//============================================================================
+// Method: SetAreaSelection
+// Purpose: Sets area selection on/off
+//============================================================================
+void IVtkTools_ShapePicker::SetAreaSelection (bool theIsOn)
+{
+ myIsRectSelection = theIsOn;
+}
+
+//============================================================================
+// Method: GetSelectionModes
+// Purpose: Get activated selection modes for a shape.
+//============================================================================
+IVtk_SelectionModeList IVtkTools_ShapePicker::GetSelectionModes (
+ const IVtk_IShape::Handle& theShape) const
+{
+ return myOccPickerAlgo->GetSelectionModes (theShape);
+}
+
+//============================================================================
+// Method: GetSelectionModes
+// Purpose: Get activated selection modes for a shape actor.
+//============================================================================
+IVtk_SelectionModeList IVtkTools_ShapePicker::GetSelectionModes (
+ vtkActor* theShapeActor) const
+{
+ IVtk_SelectionModeList aRes;
+ IVtk_IShape::Handle aShape = IVtkTools_ShapeObject::GetOccShape (theShapeActor);
+ if (!aShape.IsNull())
+ {
+ aRes = myOccPickerAlgo->GetSelectionModes (aShape);
+ }
+ return aRes;
+}
+
+//============================================================================
+// Method: SetSelectionMode
+// Purpose: Turn on/off a selection mode for a shape.
+//============================================================================
+void IVtkTools_ShapePicker::SetSelectionMode (const IVtk_IShape::Handle& theShape,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn) const
+{
+ myOccPickerAlgo->SetSelectionMode (theShape, theMode, theIsTurnOn);
+}
+
+//============================================================================
+// Method: SetSelectionMode
+// Purpose: Turn on/off a selection mode for a shape actor.
+//============================================================================
+void IVtkTools_ShapePicker::SetSelectionMode (vtkActor* theShapeActor,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn) const
+{
+ IVtk_IShape::Handle aShape = IVtkTools_ShapeObject::GetOccShape (theShapeActor);
+ if (!aShape.IsNull())
+ {
+ myOccPickerAlgo->SetSelectionMode (aShape, theMode, theIsTurnOn);
+ }
+}
+
+//============================================================================
+// Method: SetSelectionMode
+// Purpose: Sets the current selection mode for all visible shape objects.
+//============================================================================
+void IVtkTools_ShapePicker::SetSelectionMode (const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn) const
+{
+ if (myRenderer)
+ {
+ // Obtain all OccShapes displayed and activate the specified selection mode
+ vtkActorCollection *anActors = myRenderer->GetActors();
+ anActors->InitTraversal();
+ while ( vtkActor* anActor = anActors->GetNextActor() )
+ {
+ if (anActor->GetPickable() && anActor->GetVisibility())
+ {
+ if (anActor->GetMapper())
+ {
+ IVtk_IShape::Handle aShape = IVtkTools_ShapeObject::GetOccShape (anActor);
+ if (!aShape.IsNull())
+ {
+ myOccPickerAlgo->SetSelectionMode (aShape, theMode, theIsTurnOn);
+ }
+ }
+ }
+ }
+ }
+}
+
+//============================================================================
+// Method: GetPickedShapesIds
+// Purpose: Access to the list of top-level shapes picked.
+//============================================================================
+IVtk_ShapeIdList IVtkTools_ShapePicker::GetPickedShapesIds (bool theIsAll) const
+{
+ if (theIsAll || myIsRectSelection )
+ {
+ return myOccPickerAlgo->ShapesPicked();
+ }
+
+ IVtk_ShapeIdList aRes;
+ IVtk_ShapeIdList aPicked = myOccPickerAlgo->ShapesPicked();
+ if (!aPicked.IsEmpty())
+ {
+ aRes.Append (aPicked.First());
+ }
+ return aRes;
+}
+
+//============================================================================
+// Method: GetPickedSubShapesIds
+// Purpose: Access to the list of sub-shapes ids picked.
+//============================================================================
+IVtk_ShapeIdList IVtkTools_ShapePicker::GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll) const
+{
+ IVtk_ShapeIdList aRes;
+ if (theIsAll)
+ {
+ myOccPickerAlgo->SubShapesPicked (theId,aRes);
+ }
+ else
+ {
+ IVtk_ShapeIdList aList;
+ myOccPickerAlgo->SubShapesPicked (theId, aList);
+ if (!aList.IsEmpty())
+ {
+ aRes.Append (aList.First());
+ }
+ }
+ return aRes;
+}
+
+//============================================================================
+// Method: GetPickedActors
+// Purpose: Access to the list of actors picked.
+//============================================================================
+vtkActorCollection* IVtkTools_ShapePicker::GetPickedActors (bool theIsAll) const
+{
+ vtkActorCollection* aRes = vtkActorCollection::New();
+ IVtk_ShapeIdList anIds = GetPickedShapesIds (theIsAll);
+ if (myRenderer)
+ {
+ // Obtain all actors whose source shape ids are within selected ids.
+ vtkActorCollection *anActors = myRenderer->GetActors();
+ anActors->InitTraversal();
+ while ( vtkActor* anActor = anActors->GetNextActor() )
+ {
+ if (anActor->GetPickable() && anActor->GetVisibility())
+ {
+ if (anActor->GetMapper())
+ {
+ IVtk_IShape::Handle aShape = IVtkTools_ShapeObject::GetOccShape (anActor);
+ if (!aShape.IsNull())
+ {
+ for (IVtk_ShapeIdList::Iterator anIt (anIds); anIt.More(); anIt.Next())
+ {
+ if (aShape->GetId() == anIt.Value())
+ {
+ aRes->AddItem (anActor);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return aRes;
+}
--- /dev/null
+// Created: 2011-10-27
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKTOOLS_SHAPEPICKER_H__
+#define __IVTKTOOLS_SHAPEPICKER_H__
+
+#include <IVtkTools.hxx>
+#include <IVtk_Types.hxx>
+#include <IVtkOCC_ShapePickerAlgo.hxx>
+#include <vtkAbstractPropPicker.h>
+
+class vtkRenderer;
+class vtkActorCollection;
+
+//! @class IVtkTools_ShapePicker
+//! @brief VTK picker for OCC shapes with OCC selection algorithm.
+class IVtkTools_EXPORT IVtkTools_ShapePicker : public vtkAbstractPropPicker
+{
+public:
+ vtkTypeMacro(IVtkTools_ShapePicker, vtkAbstractPropPicker);
+ static IVtkTools_ShapePicker* New();
+
+ //! Pick entities in the given point or area.
+ //! @return Number of detected entities.
+ int pick (double* thePos, vtkRenderer *theRenderer, const int theNbPoints = -1);
+
+ //! Pick entities in the given point.
+ //! @return Number of detected entities.
+ int Pick (double theX, double theY, double theZ, vtkRenderer *theRenderer = NULL);
+
+ //! Pick entities in the given rectangle area.
+ //! @return Number of detected entities.
+ int Pick(double theX0, double theY0, double theX1, double theY1, vtkRenderer *theRenderer = NULL);
+
+ //! Pick entities in the given polygonal area.
+ //! @return Number of detected entities.
+ int Pick(double poly[][3], const int theNbPoints, vtkRenderer *theRenderer = NULL);
+
+ //! Setter for tolerance of picking.
+ void SetTolerance (float theTolerance);
+ //! Getter for tolerance of picking.
+ float GetTolerance () const;
+
+ //! Sets the renderer to be used by OCCT selection algorithm
+ void SetRenderer (vtkRenderer* theRenderer);
+ //! Sets area selection on/off
+ //! @param [in] theIsOn true if area selection is turned on, false otherwise.
+ void SetAreaSelection (bool theIsOn);
+
+ //! Get activated selection modes for a shape.
+ //! @param [in] theShape a shape with activated selection mode(s)
+ //! @return list of active selection modes
+ IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const;
+
+ //! Get activated selection modes for a shape actor.
+ //! @param [in] theShapeActor an actor with activated selection mode(s)
+ //! @return list of active selection modes
+ IVtk_SelectionModeList GetSelectionModes (vtkActor* theShapeActor) const;
+
+ //! Turn on/off a selection mode for a shape actor.
+ //! @param [in] theShape a shape to set a selection mode for
+ //! @param [in] theMode selection mode to be activated
+ //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
+ void SetSelectionMode (const IVtk_IShape::Handle& theShape,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn = true) const;
+
+ //! Turn on/off a selection mode for a shape actor.
+ //! @param [in] shapeActor shape presentation actor to set a selection mode for
+ //! @param [in] mode selection mode to be activated
+ //! @param [in] turnOn Flag to turn on/off the selection mode
+ void SetSelectionMode (vtkActor* theShapeActor,
+ const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn = true) const;
+
+ //! Sets the current selection mode for all visible shape objects.
+ //! @param [in] theMode selection mode to be activated
+ //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
+ void SetSelectionMode (const IVtk_SelectionMode theMode,
+ const bool theIsTurnOn = true) const;
+
+ // Picking results
+
+ //! Access to the list of top-level shapes picked.
+ //! If all argument is true, the picker returns the list of
+ //! all OccShape objects found by the picking algorithm. e.g. all
+ //! shapes under the mouse cursor. Otherwise, ID of the shape closest to the eye
+ //! is returned.
+ //! @param [in] all Controls if all selected shapes or just the only
+ //! top one is returned, has no effect during area selection.
+ //! @return List of top-level shape IDs
+ IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const;
+
+ //! Access to the list of sub-shapes ids picked.
+ //! @param [in] id top-level shape ID
+ //! @param [in] all Controls if all selected sub-shapes or just the
+ //! only top one is returned, has no effect during area selection.
+ //! @return List of sub-shapes IDs
+ IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const;
+
+ //! Access to the list of actors picked.
+ //! @param [in] all Controls if all selected actors or just the only
+ //! top one is returned, has no effect during area selection.
+ //! @return List of actors IDs
+ vtkActorCollection* GetPickedActors (bool theIsAll = false) const;
+
+protected:
+ //! Constructs the picker with empty renderer and ready for point selection.
+ IVtkTools_ShapePicker();
+ //! Destructor
+ ~IVtkTools_ShapePicker();
+
+ //! Convert display coordinates to world coordinates
+ static bool convertDisplayToWorld (vtkRenderer *theRenderer,
+ vtkFloatingPointType theDisplayCoord[3],
+ vtkFloatingPointType theWorldCoord[3] );
+
+private: // not copyable
+ IVtkTools_ShapePicker (const IVtkTools_ShapePicker&);
+ IVtkTools_ShapePicker& operator= (const IVtkTools_ShapePicker&);
+
+ //! Implementation of picking algorithm.
+ //! The coordinates accepted by this method are display (pixel) coordinates.
+ //! @param [in] pos contains the pick point (3 coordinates) or pick rectangle (6 coordinates)
+ //! or polyline (array of 2d coordinates)
+ //! @param [in] renderer vtkRenderer object to be used (normally set in advance with setRenderer())
+ //! @param [in] nbPoints number of points for polyline case
+ //! @see IVtkTools_ShapePicker::setRenderer
+ virtual void doPickImpl (double*, vtkRenderer* theRenderer, const int theNbPoints = -1);
+
+private:
+ IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation
+ vtkRenderer* myRenderer; //!< VTK renderer
+ bool myIsRectSelection;//!< Rectangle selection mode flag
+ bool myIsPolySelection;//!< Polyline selection mode flag
+ float myTolerance; //!< Selectoin tolerance
+};
+
+#endif // __IVTKTOOLS_SHAPEPICKER_H__
--- /dev/null
+// Created on: 2011-10-27
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkTools_SubPolyDataFilter.hxx>
+#include <IVtkVTK_ShapeData.hxx>
+#include <vtkCellArray.h>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkObjectFactory.h>
+#include <vtkCellData.h>
+#include <vtkIdTypeArray.h>
+
+
+vtkStandardNewMacro(IVtkTools_SubPolyDataFilter);
+
+//================================================================
+// Function : Constructor
+// Purpose :
+//================================================================
+IVtkTools_SubPolyDataFilter::IVtkTools_SubPolyDataFilter()
+{
+ myIdsArrayName = IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS;
+ myDoFiltering = true;
+}
+
+//================================================================
+// Function : Destructor
+// Purpose :
+//================================================================
+IVtkTools_SubPolyDataFilter::~IVtkTools_SubPolyDataFilter() { }
+
+//================================================================
+// Function : RequestData
+// Purpose : Filter cells according to the given set of ids.
+//================================================================
+int IVtkTools_SubPolyDataFilter::RequestData (vtkInformation *vtkNotUsed(theRequest),
+ vtkInformationVector **theInputVector,
+ vtkInformationVector *theOutputVector)
+{
+ // get the input and output
+ vtkInformation *anInInfo = theInputVector[0]->GetInformationObject(0);
+ vtkInformation *anOutInfo = theOutputVector->GetInformationObject(0);
+
+ vtkPolyData *anInput = vtkPolyData::SafeDownCast(
+ anInInfo->Get (vtkDataObject::DATA_OBJECT()));
+
+ vtkPolyData *anOutput = vtkPolyData::SafeDownCast(
+ anOutInfo->Get (vtkDataObject::DATA_OBJECT()));
+
+ vtkIdList *anIdList = vtkIdList::New(); // List of cell ids to be passed
+ anIdList->Allocate(myIdsSet.Extent()); // Allocate the list of ids
+
+ anInput->Modified();
+
+ if (myDoFiltering)
+ {
+ vtkCellData* aCellData = anInput->GetCellData();
+ int aSize = 0;
+ vtkIdTypeArray* aDataArray = vtkIdTypeArray::SafeDownCast (aCellData->GetArray (myIdsArrayName));
+
+ if(aDataArray != NULL)
+ {
+ aSize = aDataArray->GetNumberOfTuples();
+ anIdList->Allocate (aSize); // Allocate the list of ids
+ }
+
+ // Prepare the list of ids from the set of ids.
+ // Iterate on input cells.
+ if (!myIdsSet.IsEmpty())
+ {
+ for (vtkIdType anI = 0; anI < aSize; anI++)
+ {
+ if (myIdsSet.Contains (aDataArray->GetValue (anI)))
+ {
+ // Add a cell id to output if it's value is in the set.
+ anIdList->InsertNextId (anI);
+ }
+ }
+ }
+
+ // Copy cells with their points according to the prepared list of cell ids.
+ anOutput->GetCellData()->AllocateArrays(anInput->GetCellData()->GetNumberOfArrays());
+ anOutput->Allocate(anInput, anIdList->GetNumberOfIds()); // Allocate output cells
+ // Pass data arrays.
+ // Create new arrays for output data
+ vtkCellData *const anInData = anInput->GetCellData();
+ vtkCellData *const anOutData = anOutput->GetCellData();
+ vtkDataArray *anOutArr, *anInArr;
+
+ for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++)
+ {
+ anInArr = anInData->GetArray (anI);
+ anOutArr = vtkDataArray::CreateDataArray(anInArr->GetDataType());
+ anOutArr->SetName(anInArr->GetName());
+ anOutArr->Allocate(anIdList->GetNumberOfIds() * anInArr->GetNumberOfComponents());
+ anOutArr->SetNumberOfTuples (anIdList->GetNumberOfIds());
+ anOutArr->SetNumberOfComponents (anInArr->GetNumberOfComponents());
+ anOutData->AddArray(anOutArr);
+ }
+
+ // Copy cells with ids from our list.
+ anOutput->CopyCells (anInput, anIdList);
+
+ // Copy filtered arrays data
+ vtkIdType anOutId, anInId;
+
+ for (Standard_Integer anI = 0; anI < anInData->GetNumberOfArrays(); anI++)
+ {
+ anInArr = anInData->GetArray (anI);
+ anOutArr = anOutData->GetArray (anI);
+ for (anOutId = 0; anOutId < anIdList->GetNumberOfIds(); anOutId++)
+ {
+ anInId = anIdList->GetId (anOutId);
+ anOutArr->SetTuple (anOutId, anInId, anInArr);
+ }
+ }
+
+ anIdList->Delete();
+
+ }
+ else
+ {
+ anOutput->CopyStructure (anInput); // Copy points and cells
+ anOutput->CopyAttributes (anInput); // Copy data arrays (sub-shapes ids)
+ }
+
+ return 1; // Return non-zero value if success and pipeline is not failed.
+}
+
+//================================================================
+// Function : SetDoFiltering
+// Purpose :
+//================================================================
+void IVtkTools_SubPolyDataFilter::SetDoFiltering (const bool theDoFiltering)
+{
+ myDoFiltering = theDoFiltering;
+}
+
+//================================================================
+// Function : PrintSelf
+// Purpose :
+//================================================================
+void IVtkTools_SubPolyDataFilter::PrintSelf (std::ostream& theOs, vtkIndent theIndent)
+{
+ this->Superclass::PrintSelf (theOs,theIndent);
+ theOs << theIndent << "SubPolyData: " << "\n";
+ theOs << theIndent << " Number of cells to pass: " << myIdsSet.Extent() << "\n";
+ theOs << theIndent << " Cells ids to pass: {" ;
+ // Print the content of the set of ids.
+ IVtk_IdTypeMap::Iterator anIter(myIdsSet);
+ while (anIter.More())
+ {
+ theOs << " " << anIter.Value();
+ anIter.Next();
+ if (anIter.More())
+ {
+ theOs << "; ";
+ }
+ }
+ theOs << "}" << "\n";
+}
+
+//================================================================
+// Function : Clear
+// Purpose : Clear ids set to be passed through this filter.
+//================================================================
+void IVtkTools_SubPolyDataFilter::Clear()
+{
+ myIdsSet.Clear();
+}
+
+//================================================================
+// Function : SetData
+// Purpose : Set ids to be passed through this filter.
+//================================================================
+void IVtkTools_SubPolyDataFilter::SetData (const IVtk_IdTypeMap theSet)
+{
+ myIdsSet = theSet;
+}
+
+//================================================================
+// Function : AddData
+// Purpose : Add ids to be passed through this filter.
+//================================================================
+void IVtkTools_SubPolyDataFilter::AddData (const IVtk_IdTypeMap theSet)
+{
+ IVtk_IdTypeMap::Iterator anIt (theSet);
+ for (; anIt.More(); anIt.Next())
+ {
+ if (!myIdsSet.Contains (anIt.Value()))
+ {
+ myIdsSet.Add (anIt.Value());
+ }
+ }
+}
+
+//================================================================
+// Function : SetData
+// Purpose : Set ids to be passed through this filter.
+//================================================================
+void IVtkTools_SubPolyDataFilter::SetData (const IVtk_ShapeIdList theIdList)
+{
+ myIdsSet.Clear();
+ AddData (theIdList);
+}
+
+//================================================================
+// Function : AddData
+// Purpose : Add ids to be passed through this filter.
+//================================================================
+void IVtkTools_SubPolyDataFilter::AddData (const IVtk_ShapeIdList theIdList)
+{
+ IVtk_ShapeIdList::Iterator anIt (theIdList);
+ for (; anIt.More(); anIt.Next())
+ {
+ if (!myIdsSet.Contains (anIt.Value()))
+ {
+ myIdsSet.Add (anIt.Value());
+ }
+ }
+}
+
+//! Set ids to be passed through this filter.
+//================================================================
+// Function : SetIdsArrayName
+// Purpose :
+//================================================================
+void IVtkTools_SubPolyDataFilter::SetIdsArrayName (const char* theArrayName)
+{
+ myIdsArrayName = theArrayName;
+}
--- /dev/null
+// Created on: 2011-10-27
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 IVtkTOOLS_SUBPOLYDATAFILTER_H
+#define IVtkTOOLS_SUBPOLYDATAFILTER_H
+
+#include <IVtkTools.hxx>
+
+#include "vtkPolyDataAlgorithm.h"
+#include <IVtk_Types.hxx>
+
+//! @class IVtkTools_SubPolyDataFilter
+//! @brief Cells filter according to the given set of cells ids.
+class IVtkTools_EXPORT IVtkTools_SubPolyDataFilter : public vtkPolyDataAlgorithm
+{
+public:
+ vtkTypeMacro(IVtkTools_SubPolyDataFilter,vtkPolyDataAlgorithm);
+ static IVtkTools_SubPolyDataFilter *New();
+ void PrintSelf (std::ostream& theOs, vtkIndent theIndent);
+
+ //! Set ids to be passed through this filter.
+ void SetData(const IVtk_IdTypeMap theSet);
+
+ //! Add ids to be passed through this filter.
+ void AddData(const IVtk_IdTypeMap theSet);
+
+ //! Set ids to be passed through this filter.
+ void SetData(const IVtk_ShapeIdList theIds);
+
+ //! Add ids to be passed through this filter.
+ void AddData(const IVtk_ShapeIdList theIds);
+
+ //! Clear ids set to be passed through this filter.
+ void Clear();
+
+ //! Set ids array name.
+ void SetIdsArrayName(const char* theArrayName);
+
+ void SetDoFiltering (const bool theDoFiltering);
+
+protected:
+ //! @brief Filter cells according to the given set of ids.
+ //! Note: Data arrays are not passed through if filtering is turned on.
+ virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
+
+ IVtkTools_SubPolyDataFilter();
+ ~IVtkTools_SubPolyDataFilter();
+
+protected:
+ //! Set of ids to be passed through this filter.
+ IVtk_IdTypeMap myIdsSet;
+ const char* myIdsArrayName;
+ bool myDoFiltering;
+};
+
+#endif // IVtkTOOLS_SUBPOLYDATAFILTER_H
--- /dev/null
+CSF_VTK
\ No newline at end of file
--- /dev/null
+EXTERNLIB
+IVtkVTK_ShapeData.hxx
+IVtkVTK_ShapeData.cxx
+IVtkVTK_View.hxx
+IVtkVTK_View.cxx
--- /dev/null
+-- File: IVtkVTK_CMPLRS.edl
+-- Created by: Anastasia Arzhadeyeva
+
+@ifnotdefined ( %IVtkVTK_CMPLRS_EDL) then
+ @set %IVtkVTK_CMPLRS_EDL = "";
+
+ @if (%Station == "wnt") then
+ @string %CMPLRS_CXX_INCLUDE = %CMPLRS_CXX_INCLUDE " " %CSF_VTK_INCLUDES;
+ @endif;
+
+@endif;
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkVTK_ShapeData.hxx>
+#include <vtkCellArray.h>
+#include <vtkCellData.h>
+#include <vtkDoubleArray.h>
+#include <vtkIdTypeArray.h>
+#include <vtkPoints.h>
+#include <vtkPolyData.h>
+
+const char* const IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS = "SUBSHAPE_IDS";
+
+const char* const IVtkVTK_ShapeData::ARRNAME_MESH_TYPES = "MESH_TYPES";
+
+//! Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtkVTK_ShapeData, IVtk_IShapeData)
+IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_ShapeData, IVtk_IShapeData)
+
+
+//================================================================
+// Function : Constructor
+// Purpose :
+//================================================================
+IVtkVTK_ShapeData::IVtkVTK_ShapeData()
+ : myPolyData( vtkPolyData::New() )
+{
+ myPolyData->Allocate();
+ myPolyData->SetPoints (vtkPoints::New());
+
+ mySubShapeIDs = vtkIdTypeArray::New();
+ mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
+ mySubShapeIDs->SetNumberOfComponents (1);
+ myPolyData->GetCellData()->AddArray (mySubShapeIDs);
+
+ myMeshTypes = vtkIdTypeArray::New();
+ myMeshTypes->SetName (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES);
+ myMeshTypes->SetNumberOfComponents (1);
+ myPolyData->GetCellData()->AddArray (myMeshTypes);
+}
+
+//================================================================
+// Function : Destructor
+// Purpose :
+//================================================================
+IVtkVTK_ShapeData::~IVtkVTK_ShapeData()
+{ }
+
+//================================================================
+// Function : InsertCoordinate
+// Purpose :
+//================================================================
+IVtk_PointId IVtkVTK_ShapeData::InsertCoordinate (double theX,
+ double theY,
+ double theZ)
+{
+ return myPolyData->GetPoints()->InsertNextPoint (theX, theY, theZ);
+}
+
+//================================================================
+// Function : InsertVertex
+// Purpose :
+//================================================================
+void IVtkVTK_ShapeData::InsertVertex (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId,
+ const IVtk_MeshType theMeshType)
+{
+ vtkIdType aPointIdVTK = thePointId;
+ myPolyData->InsertNextCell (VTK_VERTEX, 1, &aPointIdVTK);
+ const vtkIdType aShapeIDVTK = theShapeID;
+ mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
+ const vtkIdType aType = theMeshType;
+ myMeshTypes->InsertNextTupleValue (&aType);
+}
+
+//================================================================
+// Function : InsertLine
+// Purpose :
+//================================================================
+void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId1,
+ const IVtk_PointId thePointId2,
+ const IVtk_MeshType theMeshType)
+{
+ vtkIdType aPoints[2] = { thePointId1, thePointId2 };
+ myPolyData->InsertNextCell (VTK_LINE, 2, aPoints);
+ const vtkIdType aShapeIDVTK = theShapeID;
+ mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
+ const vtkIdType aType = theMeshType;
+ myMeshTypes->InsertNextTupleValue (&aType);
+}
+
+//================================================================
+// Function : InsertLine
+// Purpose :
+//================================================================
+void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
+ const IVtk_PointIdList* thePointIds,
+ const IVtk_MeshType theMeshType)
+{
+ if (!thePointIds->IsEmpty())
+ {
+ vtkIdList* anIdList = vtkIdList::New();
+ // Fill the vtk id list by ids from IVtk_PointIdList.
+ IVtk_PointIdList::Iterator anIterOfIds =
+ IVtk_PointIdList::Iterator(*thePointIds);
+ anIdList->Allocate(thePointIds->Extent());
+ for(; anIterOfIds.More(); anIterOfIds.Next())
+ {
+ anIdList->InsertNextId (anIterOfIds.Value());
+ }
+
+ myPolyData->InsertNextCell (VTK_POLY_LINE, anIdList);
+ const vtkIdType aShapeIDVTK = theShapeID;
+ mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
+ const vtkIdType aType = theMeshType;
+ myMeshTypes->InsertNextTupleValue (&aType);
+ anIdList->Delete();
+ }
+}
+
+//================================================================
+// Function : InsertTriangle
+// Purpose :
+//================================================================
+void IVtkVTK_ShapeData::InsertTriangle (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId1,
+ const IVtk_PointId thePointId2,
+ const IVtk_PointId thePointId3,
+ const IVtk_MeshType theMeshType)
+{
+ vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
+ myPolyData->InsertNextCell (VTK_TRIANGLE, 3, aPoints);
+ const vtkIdType aShapeIDVTK = theShapeID;
+ mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
+ const vtkIdType aType = theMeshType;
+ myMeshTypes->InsertNextTupleValue (&aType);
+}
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKVTK_SHAPEDATA_H__
+#define __IVTKVTK_SHAPEDATA_H__
+
+#include <IVtk_IShapeData.hxx>
+#include <vtkType.h>
+#include <vtkSmartPointer.h>
+
+class vtkIdTypeArray;
+class vtkPolyData;
+
+DEFINE_STANDARD_HANDLE( IVtkVTK_ShapeData, IVtk_IShapeData )
+
+// macros to export static field in class
+#if (defined(_WIN32) || defined(__WIN32__))
+ #ifdef __IVtkVTK_DLL
+ #define IVtkVTK_EXPORT __declspec(dllexport)
+ #else
+ #define IVtkVTK_EXPORT __declspec(dllimport)
+ #endif
+#else
+ #define IVtkVTK_EXPORT
+#endif
+
+//! @class IVtkVTK_ShapeData
+//! @brief IShapeData implementation for VTK.
+//!
+//! Contains the shape geometry information as vtkPolyData.
+class IVtkVTK_ShapeData : public IVtk_IShapeData
+{
+public:
+
+ IVtkVTK_EXPORT static const char* const ARRNAME_SUBSHAPE_IDS;
+ IVtkVTK_EXPORT static const char* const ARRNAME_MESH_TYPES;
+
+ typedef Handle(IVtkVTK_ShapeData) Handle;
+
+ //! Constructor
+ Standard_EXPORT IVtkVTK_ShapeData();
+ //! Destructor
+ Standard_EXPORT ~IVtkVTK_ShapeData();
+
+ DEFINE_STANDARD_RTTI( IVtkVTK_ShapeData )
+
+ //! Insert a coordinate
+ //! @param [in] theX X coordinate
+ //! @param [in] theY Y coordinate
+ //! @param [in] theZ Z coordinate
+ //! @return id of added point
+ Standard_EXPORT virtual IVtk_PointId InsertCoordinate (double theX, double theY, double theZ);
+
+ //! Insert a vertex.
+ //! @param [in] theShapeID id of the subshape to which the vertex belongs.
+ //! @param [in] thePointId id of the point that defines the coordinates of the vertex
+ //! @param [in] theMeshType mesh type of the subshape (MT_Undefined by default)
+ Standard_EXPORT virtual void InsertVertex (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId,
+ const IVtk_MeshType theMeshType);
+
+ //! Insert a line.
+ //! @param [in] theShapeID id of the subshape to which the line belongs.
+ //! @param [in] thePointId1 id of the first point
+ //! @param [in] thePointId2 id of the second point
+ //! @param [in] theMeshType mesh type of the subshape (MT_Undefined by default)
+ Standard_EXPORT virtual void InsertLine (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId1,
+ const IVtk_PointId thePointId2,
+ const IVtk_MeshType theMeshType);
+
+ //! Insert a poly-line.
+ //! @param [in] theShapeID id of the subshape to which the polyline belongs.
+ //! @param [in] thePointIds vector of point ids
+ //! @param [in] theMeshType mesh type of the subshape (MT_Undefined by default)
+ Standard_EXPORT virtual void InsertLine (const IVtk_IdType theShapeID,
+ const IVtk_PointIdList* thePointIds,
+ const IVtk_MeshType theMeshType);
+ //! Insert a triangle
+ //! @param [in] theShapeID id of the subshape to which the triangle belongs.
+ //! @param [in] thePointId1 id of the first point
+ //! @param [in] thePointId2 id of the second point
+ //! @param [in] thePointId3 id of the third point
+ //! @param [in] theMeshType mesh type of the subshape (MT_Undefined by default)
+ Standard_EXPORT virtual void InsertTriangle (const IVtk_IdType theShapeID,
+ const IVtk_PointId thePointId1,
+ const IVtk_PointId thePointId2,
+ const IVtk_PointId thePointId3,
+ const IVtk_MeshType theMeshType);
+
+
+public: //! @name Specific methods
+
+ //! Get VTK PolyData.
+ //! @return VTK PolyData
+ vtkSmartPointer< vtkPolyData > getVtkPolyData() const
+ { return myPolyData; }
+
+private:
+ vtkSmartPointer< vtkPolyData > myPolyData; //!< Shape geometry as vtkPolyData
+ vtkSmartPointer< vtkIdTypeArray > mySubShapeIDs; //!< Array of sub-shapes ids
+ vtkSmartPointer< vtkIdTypeArray > myMeshTypes; //!< Array of type codes of mesh parts
+};
+
+#endif // __IVTKVTK_SHAPEDATA_H__
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 <IVtkVTK_View.hxx>
+#include <vtkAutoInit.h>
+#include <vtkCamera.h>
+#include <vtkRenderer.h>
+#include <vtkTransform.h>
+
+// Initialization of VTK object factories.
+// Since VTK 6 the factory methods require "auto-initialization" depending on
+// what modules are enabled at VTK configure time.
+// Some defines are needed in order to make the factories work properly.
+VTK_MODULE_INIT(vtkRenderingOpenGL);
+VTK_MODULE_INIT(vtkInteractionStyle);
+
+// Handle implementation
+IMPLEMENT_STANDARD_HANDLE(IVtkVTK_View, IVtk_IView)
+IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_View, IVtk_IView)
+
+//================================================================
+// Function : Constructor
+// Purpose :
+//================================================================
+IVtkVTK_View::IVtkVTK_View (vtkRenderer* theRenderer)
+: myRenderer (theRenderer)
+{ }
+
+//================================================================
+// Function : Destructor
+// Purpose :
+//================================================================
+IVtkVTK_View::~IVtkVTK_View()
+{ }
+
+//================================================================
+// Function : IsPerspective
+// Purpose :
+//================================================================
+bool IVtkVTK_View::IsPerspective() const
+{
+ return !myRenderer->GetActiveCamera()->GetParallelProjection();
+}
+
+//================================================================
+// Function : GetDistance
+// Purpose :
+//================================================================
+double IVtkVTK_View::GetDistance() const
+{
+ return myRenderer->GetActiveCamera()->GetDistance();
+}
+
+//================================================================
+// Function : GetPosition
+// Purpose :
+//================================================================
+void IVtkVTK_View::GetPosition (double& theX, double& theY, double& theZ) const
+{
+ myRenderer->GetActiveCamera()->GetFocalPoint (theX, theY, theZ);
+}
+
+//================================================================
+// Function : GetViewUp
+// Purpose :
+//================================================================
+void IVtkVTK_View::GetViewUp (double& theDx, double& theDy, double& theDz) const
+{
+ myRenderer->GetActiveCamera()->OrthogonalizeViewUp();
+ myRenderer->GetActiveCamera()->GetViewUp (theDx, theDy, theDz);
+}
+
+//================================================================
+// Function : GetDirectionOfProjection
+// Purpose :
+//================================================================
+void IVtkVTK_View::GetDirectionOfProjection (double& theDx,
+ double& theDy,
+ double& theDz) const
+{
+ myRenderer->GetActiveCamera()->GetDirectionOfProjection (theDx, theDy, theDz);
+ theDx = -theDx;
+ theDy = -theDy;
+ theDz = -theDz;
+}
+
+//================================================================
+// Function : GetScale
+// Purpose :
+//================================================================
+void IVtkVTK_View::GetScale (double& theX, double& theY, double& theZ) const
+{
+ double aScale[3];
+ myRenderer->GetActiveCamera()->GetViewTransformObject()->GetScale (aScale);
+ theX = aScale[0];
+ theY = aScale[1];
+ theZ = aScale[2];
+}
+
+//================================================================
+// Function : GetParallelScale
+// Purpose :
+//================================================================
+double IVtkVTK_View::GetParallelScale() const
+{
+ return myRenderer->GetActiveCamera()->GetParallelScale();
+}
+
+//================================================================
+// Function : GetViewAngle
+// Purpose :
+//================================================================
+double IVtkVTK_View::GetViewAngle() const
+{
+ return myRenderer->GetActiveCamera()->GetViewAngle();
+}
+
+//================================================================
+// Function : GetViewCenter
+// Purpose :
+//================================================================
+void IVtkVTK_View::GetViewCenter (double& theX, double& theY) const
+{
+ double* aCenter = myRenderer->GetCenter();
+ theX = aCenter[0];
+ theY = aCenter[1];
+}
+
+//================================================================
+// Function : DisplayToWorld
+// Purpose :
+//================================================================
+bool IVtkVTK_View::DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldPnt) const
+{
+ // Convert the selection point into world coordinates.
+ myRenderer->SetDisplayPoint (theDisplayPnt.X(), theDisplayPnt.Y(), 0.0);
+ myRenderer->DisplayToWorld();
+
+ vtkFloatingPointType* const aCoords = myRenderer->GetWorldPoint();
+ if (aCoords[3] == 0.0) // Point at infinity in homogeneous coordinates
+ {
+ return false;
+ }
+
+ theWorldPnt = gp_XYZ (aCoords[0] / aCoords[3], aCoords[1] / aCoords[3], aCoords[2] / aCoords[3]);
+
+ return true;
+}
--- /dev/null
+// Created on: 2011-10-14
+// Created by: Roman KOZLOV
+// Copyright (c) 2011-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 __IVTKVTK_VIEW_H__
+#define __IVTKVTK_VIEW_H__
+
+#include <IVtk_IView.hxx>
+
+class vtkRenderer;
+
+DEFINE_STANDARD_HANDLE( IVtkVTK_View, IVtk_IView )
+
+//! @class IVtkVTK_View
+//! @brief ICamera implementation for VTK.
+//!
+//! This class is used for obtaining view transformation parameters.
+//! These parameters are used by selection algorithm to compute
+//! projections of selectable (active) 3D shapes.
+class IVtkVTK_View : public IVtk_IView
+{
+
+public:
+ typedef Handle(IVtkVTK_View) Handle;
+
+ Standard_EXPORT IVtkVTK_View (vtkRenderer* theRenderer);
+
+ //! Destructor
+ Standard_EXPORT virtual ~IVtkVTK_View();
+
+ //! @return true if this is a perspective view, and false otherwise.
+ Standard_EXPORT virtual bool IsPerspective() const;
+
+ //! @return The focal distance of the view
+ Standard_EXPORT virtual double GetDistance() const;
+
+ //! @return The world coordinates of the view position
+ Standard_EXPORT virtual void GetPosition (double& theX, double& theY, double& theZ) const;
+
+ //! @return The "view up" direction of the view
+ Standard_EXPORT virtual void GetViewUp (double& theDx, double& theDy, double& theDz) const;
+
+ //! @return The projection direction vector of this view
+ Standard_EXPORT virtual void GetDirectionOfProjection (double& theDx,
+ double& theDy,
+ double& theDz) const;
+
+ //! @return Three doubles containing scale components of the view transformation
+ Standard_EXPORT virtual void GetScale (double& theX, double& theY, double& theZ) const;
+
+ //! @return The current view's zoom factor (for parallel projection)
+ Standard_EXPORT virtual double GetParallelScale() const;
+
+ //! @return The current view angle (for perspective projection)
+ Standard_EXPORT virtual double GetViewAngle() const;
+
+ //! @return Two doubles containing the display coordinates of the view window center
+ Standard_EXPORT virtual void GetViewCenter (double& theX, double& theY) const;
+
+ //! Converts 3D display coordinates into 3D world coordinates.
+ //! @param [in] theDisplayPnt 2d point of display coordinates
+ //! @param [out] theWorldPnt 3d point of world coordinates
+ //! @return true if conversion was successful, false otherwise
+ Standard_EXPORT virtual bool DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldPnt) const;
+
+ DEFINE_STANDARD_RTTI( IVtkVTK_View )
+
+private:
+ vtkRenderer* myRenderer;
+};
+
+#endif // __IVTKVTK_VIEW_H__
;# Liste des toolkits WOK sous forme de full path
;#
proc Visualization:toolkits { } {
- return [list TKService \
- TKV3d \
- TKOpenGl \
- TKMeshVS \
- TKNIS \
- TKVoxel \
- ]
+ set aResult [list TKService \
+ TKV3d \
+ TKOpenGl \
+ TKMeshVS \
+ TKNIS \
+ TKVoxel]
+
+ if { "$::env(HAVE_VTK)" == "true" } {
+ lappend aResult "TKIVtk"
+ }
+
+ return $aResult
}
;#
;# Autres UDs a prendre.
}
proc Visualization:acdepends { } {
- return [list X11 GL FREETYPE]
+ return [list X11 GL FREETYPE VTK]
}
;#
UpdateTransformation(me:mutable) is redefined virtual;
---Purpose: Recomputes the location of the selection aSelection.
- UpdateTransformation(me:mutable;aSelection: Selection from SelectMgr) is virtual protected;
- ---Level: Internal
+ UpdateTransformations(me:mutable;aSelection: Selection from SelectMgr) is virtual;
+ ---Level: Public
---Purpose: Updates locations in all sensitive entities from <aSelection>
-- and in corresponding entity owners.
mySelectionPrs : Presentation from Prs3d;
myHilightPrs : Presentation from Prs3d;
-
-friends
- class SelectionManager from SelectMgr
end SelectableObject;
//function : UpdateTransformation
//purpose :
//=======================================================================
-void SelectMgr_SelectableObject::UpdateTransformation(const Handle(SelectMgr_Selection)& Sel)
+void SelectMgr_SelectableObject::UpdateTransformations(const Handle(SelectMgr_Selection)& Sel)
{
TopLoc_Location aSelfLocation (Transformation());
Handle(Select3D_SensitiveEntity) SE;
case SelectMgr_TOU_Partial:
{
if(anObject->HasTransformation())
- anObject->UpdateTransformation(Sel);
+ anObject->UpdateTransformations(Sel);
Sel->UpdateStatus(SelectMgr_TOU_None);
break;
}
case SelectMgr_TOU_Partial:
{
if(anObject->HasTransformation())
- anObject->UpdateTransformation(Sel);
+ anObject->UpdateTransformations(Sel);
break;
}
default:
case SelectMgr_TOU_Full:
anObject->UpdateSelection(curmode); // no break on purpose...
case SelectMgr_TOU_Partial:
- anObject->UpdateTransformation(Sel);
+ anObject->UpdateTransformations(Sel);
break;
default:
break;
case SelectMgr_TOU_Full:
anObject->UpdateSelection(Sel->Mode()); // no break on purpose...
case SelectMgr_TOU_Partial:
- anObject->UpdateTransformation(Sel);
+ anObject->UpdateTransformations(Sel);
wasrecomputed = Standard_True;
break;
default:
case SelectMgr_TOU_Full:
anObject->UpdateSelection(Sel->Mode()); // no break on purpose...
case SelectMgr_TOU_Partial:
- anObject->UpdateTransformation(Sel);
+ anObject->UpdateTransformations(Sel);
wasrecomputed = Standard_True;
break;
default:
case SelectMgr_TOU_Full:
anObject->UpdateSelection(Sel->Mode()); // no break on purpose...
case SelectMgr_TOU_Partial:
- anObject->UpdateTransformation(Sel);
+ anObject->UpdateTransformations(Sel);
wasrecomputed = Standard_True;
break;
default:
anObject->UpdateSelection(Sel->Mode());
case SelectMgr_TOU_Partial:
if(anObject->HasTransformation())
- anObject->UpdateTransformation(Sel);
+ anObject->UpdateTransformations(Sel);
wasrecomputed = Standard_True;
break;
default:
--- /dev/null
+CSF_VTK
+TKernel
+TKBRep
+TKG2d
+TKG3d
+TKGeomAlgo
+TKGeomBase
+TKMath
+TKMesh
+TKService
+TKTopAlgo
+TKV3d
--- /dev/null
+PACKAGES
+EXTERNLIB
\ No newline at end of file
--- /dev/null
+IVtk
+IVtkOCC
+IVtkVTK
+IVtkTools
\ No newline at end of file