mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-03 14:10:33 +03:00
0024904: Visualization - Integration of VIS component:
Added new toolkit TKIVtk: - TKIVtk toolkit includes IVtkVTK, IVtkTools, IVtkOCC, IVtk packages. - TKIVtk provides OCC interface for VTK library functionality: it allows to use VTK window and event managment for OCC objects (shapes) Porting on VTK 6: - shape source inherits vtkPolyDataAlgorithm now (vtkPolyDataSource was removed form VTK as deprecated functionality). - added factory auto-initialization in IVtkVTK_View - remove using of deprecated methods of pipeline mechanism. Get rid from warning in SelectMgr_SelectableObject. Removed firendship from SelectMgr_SelectableObject. Corrected projector parameters for selection algorithm. Removed unneeded picking algorithm modification.
This commit is contained in:
1
src/IVtkTools/EXTERNLIB
Normal file
1
src/IVtkTools/EXTERNLIB
Normal file
@@ -0,0 +1 @@
|
||||
CSF_VTK
|
13
src/IVtkTools/FILES
Normal file
13
src/IVtkTools/FILES
Normal file
@@ -0,0 +1,13 @@
|
||||
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
|
124
src/IVtkTools/IVtkTools.cxx
Normal file
124
src/IVtkTools/IVtkTools.cxx
Normal file
@@ -0,0 +1,124 @@
|
||||
// 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();
|
||||
}
|
||||
};
|
88
src/IVtkTools/IVtkTools.hxx
Normal file
88
src/IVtkTools/IVtkTools.hxx
Normal file
@@ -0,0 +1,88 @@
|
||||
// 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
|
142
src/IVtkTools/IVtkTools_DisplayModeFilter.cxx
Normal file
142
src/IVtkTools/IVtkTools_DisplayModeFilter.cxx
Normal file
@@ -0,0 +1,142 @@
|
||||
// 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;
|
||||
}
|
||||
|
59
src/IVtkTools/IVtkTools_DisplayModeFilter.hxx
Normal file
59
src/IVtkTools/IVtkTools_DisplayModeFilter.hxx
Normal file
@@ -0,0 +1,59 @@
|
||||
// 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
|
||||
|
218
src/IVtkTools/IVtkTools_ShapeDataSource.cxx
Normal file
218
src/IVtkTools/IVtkTools_ShapeDataSource.cxx
Normal file
@@ -0,0 +1,218 @@
|
||||
// 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;
|
||||
}
|
118
src/IVtkTools/IVtkTools_ShapeDataSource.hxx
Normal file
118
src/IVtkTools/IVtkTools_ShapeDataSource.hxx
Normal file
@@ -0,0 +1,118 @@
|
||||
// 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__
|
157
src/IVtkTools/IVtkTools_ShapeObject.cxx
Normal file
157
src/IVtkTools/IVtkTools_ShapeObject.cxx
Normal file
@@ -0,0 +1,157 @@
|
||||
// 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;
|
||||
}
|
||||
|
85
src/IVtkTools/IVtkTools_ShapeObject.hxx
Normal file
85
src/IVtkTools/IVtkTools_ShapeObject.hxx
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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__
|
376
src/IVtkTools/IVtkTools_ShapePicker.cxx
Normal file
376
src/IVtkTools/IVtkTools_ShapePicker.cxx
Normal file
@@ -0,0 +1,376 @@
|
||||
// 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;
|
||||
}
|
151
src/IVtkTools/IVtkTools_ShapePicker.hxx
Normal file
151
src/IVtkTools/IVtkTools_ShapePicker.hxx
Normal file
@@ -0,0 +1,151 @@
|
||||
// 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__
|
243
src/IVtkTools/IVtkTools_SubPolyDataFilter.cxx
Normal file
243
src/IVtkTools/IVtkTools_SubPolyDataFilter.cxx
Normal file
@@ -0,0 +1,243 @@
|
||||
// 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;
|
||||
}
|
68
src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx
Normal file
68
src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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
|
Reference in New Issue
Block a user