// commercial license or contractual agreement.
// VIS includes
-#include <IVtkOCC_ShapeMesher.hxx>
#include <IVtkTools_ShapeDataSource.hxx>
+#include <IVtkOCC_ShapeMesher.hxx>
#include <IVtkTools_ShapeObject.hxx>
-// VTK includes
-#include <vtkCellArray.h>
+// prevent disabling some MSVC warning messages by VTK headers
+#ifdef _MSC_VER
+#pragma warning(push)
+#endif
+#include <vtkObjectFactory.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>
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
-vtkStandardNewMacro(IVtkTools_ShapeDataSource);
+vtkStandardNewMacro(IVtkTools_ShapeDataSource)
//================================================================
// Function : Constructor
myIsFastTransformMode (Standard_False),
myIsTransformOnly (Standard_False)
{
- this->SetNumberOfInputPorts (0);
+ this->SetNumberOfInputPorts(0);
+ this->SetNumberOfOutputPorts(1);
}
//================================================================
// Function : RequestData
// Purpose :
//================================================================
-int IVtkTools_ShapeDataSource::RequestData (vtkInformation* theRequest,
- vtkInformationVector** theInputVector,
- vtkInformationVector* theOutputVector)
+int IVtkTools_ShapeDataSource::RequestData(vtkInformation *vtkNotUsed(theRequest),
+ vtkInformationVector **vtkNotUsed(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)
+ vtkSmartPointer<vtkPolyData> aPolyData = vtkPolyData::GetData (theOutputVector);
+ if (aPolyData.GetPointer() != NULL)
{
- 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;
- }
+ aPolyData->Allocate();
+ vtkSmartPointer<vtkPoints> aPts = vtkSmartPointer<vtkPoints>::New();
+ aPolyData->SetPoints (aPts);
- myPolyData = new IVtkVTK_ShapeData;
- IVtkOCC_ShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher;
- aMesher->Build (aShapeWrapperCopy, myPolyData);
- vtkPolyData* aMeshData = myPolyData->getVtkPolyData();
+ vtkSmartPointer<vtkPolyData> aTransformedData;
+ TopoDS_Shape aShape = myOccShape->GetShape();
+ TopLoc_Location aShapeLoc = aShape.Location();
- if (myIsFastTransformMode && !aShapeLoc.IsIdentity() )
+ if (myIsTransformOnly)
{
- aTransformedData = this->transform (aMeshData, aShapeLoc);
+ vtkSmartPointer<vtkPolyData> aPrevData = myPolyData->getVtkPolyData();
+ if ( !aShapeLoc.IsIdentity() )
+ {
+ aTransformedData = this->transform (aPrevData, aShapeLoc);
+ }
+ else
+ {
+ aTransformedData = aPrevData;
+ }
}
else
{
- aTransformedData = aMeshData;
+ 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);
+ vtkSmartPointer<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)
+ 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() );
+ // 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);
+ return 1;
}
//================================================================
//================================================================
vtkSmartPointer<vtkIdTypeArray> IVtkTools_ShapeDataSource::SubShapeIDs()
{
- vtkDataArray* arr = GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
- return vtkSmartPointer<vtkIdTypeArray>( vtkIdTypeArray::SafeDownCast(arr) );
+ vtkSmartPointer<vtkDataArray> arr =
+ GetOutput()->GetCellData()->GetArray(IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS());
+ return vtkSmartPointer<vtkIdTypeArray>(
+ vtkIdTypeArray::SafeDownCast(arr.GetPointer()) );
}
//================================================================
//================================================================
IVtk_IdType IVtkTools_ShapeDataSource::GetId() const
{
- return myOccShape ? myOccShape->GetId() : -1;
+ return myOccShape.IsNull() ? -1 : myOccShape->GetId();
}
//================================================================
aTrsfFilter->SetInputData (theSource);
aTrsfFilter->Update();
- vtkPolyData* aTransformed = aTrsfFilter->GetOutput();
+ vtkSmartPointer<vtkPolyData> aTransformed = aTrsfFilter->GetOutput();
aResult->CopyStructure (aTransformed); // Copy points and cells
aResult->CopyAttributes (aTransformed); // Copy data arrays (sub-shapes ids)