From 4b8228f9aba2459bc67fcfd1aaa7c95284d8803d Mon Sep 17 00:00:00 2001 From: ema Date: Tue, 25 Nov 2014 15:50:47 +0300 Subject: [PATCH] ParaView / PARAVIS improvements 2014: 2.6.3/2.6.4: Geometry & Mesh plug-ins in the ParaVis module --- src/OCC2VTK/OCC2VTK_Tools.cxx | 70 +++++++++++++++++++++++ src/OCC2VTK/OCC2VTK_Tools.h | 4 +- src/VTKPlugin/VTKPlugin_ExportDriver.cxx | 72 ++---------------------- 3 files changed, 77 insertions(+), 69 deletions(-) diff --git a/src/OCC2VTK/OCC2VTK_Tools.cxx b/src/OCC2VTK/OCC2VTK_Tools.cxx index e9b592035..6326c2904 100755 --- a/src/OCC2VTK/OCC2VTK_Tools.cxx +++ b/src/OCC2VTK/OCC2VTK_Tools.cxx @@ -35,6 +35,12 @@ #include #include + +#include +#include +#include +#include + #define MAX2(X, Y) (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y)) #define MAX3(X, Y, Z) (MAX2(MAX2(X,Y), Z)) @@ -159,4 +165,68 @@ namespace GEOM } } } + + vtkPolyData* GetData(const TopoDS_Shape& theShape, float theDeflection) { + BRepBuilderAPI_Copy aCopy(theShape); + if(!aCopy.IsDone()) { + return 0; + } + + TopoDS_Shape aShape = aCopy.Shape(); + + try { + GEOM_VertexSource* myVertexSource = GEOM_VertexSource::New(); + GEOM_EdgeSource* myIsolatedEdgeSource = GEOM_EdgeSource::New(); + GEOM_EdgeSource* myOneFaceEdgeSource = GEOM_EdgeSource::New(); + GEOM_EdgeSource* mySharedEdgeSource = GEOM_EdgeSource::New(); + GEOM_WireframeFace* myWireframeFaceSource = GEOM_WireframeFace::New(); + GEOM_ShadingFace* myShadingFaceSource = GEOM_ShadingFace::New(); + + vtkAppendPolyData* myAppendFilter = vtkAppendPolyData::New(); + myAppendFilter->AddInputConnection( myVertexSource->GetOutputPort() ); + myAppendFilter->AddInputConnection( myIsolatedEdgeSource->GetOutputPort() ); + myAppendFilter->AddInputConnection( myOneFaceEdgeSource->GetOutputPort() ); + myAppendFilter->AddInputConnection( mySharedEdgeSource->GetOutputPort() ); + myAppendFilter->AddInputConnection( myShadingFaceSource->GetOutputPort() ); + + bool anIsVector = false; + + GEOM::MeshShape( aShape, theDeflection ); + TopExp_Explorer aVertexExp( aShape, TopAbs_VERTEX ); + for( ; aVertexExp.More(); aVertexExp.Next() ) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex( aVertexExp.Current() ); + myVertexSource->AddVertex( aVertex ); + } + + TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap; + TopExp::MapShapesAndAncestors( aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap ); + + GEOM::SetShape( aShape, + anEdgeMap, + anIsVector, + 0, + myIsolatedEdgeSource, + myOneFaceEdgeSource, + mySharedEdgeSource, + myWireframeFaceSource, + myShadingFaceSource ); + + myAppendFilter->Update(); + + myVertexSource->Delete(); + myIsolatedEdgeSource->Delete(); + myOneFaceEdgeSource->Delete(); + mySharedEdgeSource->Delete(); + myWireframeFaceSource->Delete(); + myShadingFaceSource->Delete(); + + vtkPolyData* ret = vtkPolyData::New(); + ret->ShallowCopy(myAppendFilter->GetOutput()); + myAppendFilter->Delete(); + return ret; + } + catch(Standard_Failure) { + return 0; + } + } } diff --git a/src/OCC2VTK/OCC2VTK_Tools.h b/src/OCC2VTK/OCC2VTK_Tools.h index 523ca14b9..9ca546550 100755 --- a/src/OCC2VTK/OCC2VTK_Tools.h +++ b/src/OCC2VTK/OCC2VTK_Tools.h @@ -29,7 +29,7 @@ class GEOM_VertexSource; class GEOM_EdgeSource; class GEOM_WireframeFace; class GEOM_ShadingFace; - +class vtkPolyData; namespace GEOM { // moved from GEOM_AssemblyBuilder @@ -47,6 +47,8 @@ namespace GEOM GEOM_EdgeSource* theSharedEdgeSource, GEOM_WireframeFace* theWireframeFaceSource, GEOM_ShadingFace* theShadingFaceSource); + + OCC2VTK_EXPORT vtkPolyData* GetData(const TopoDS_Shape& theShape, float theDeflection); } #endif // OCC2VTK_TOOLS_H diff --git a/src/VTKPlugin/VTKPlugin_ExportDriver.cxx b/src/VTKPlugin/VTKPlugin_ExportDriver.cxx index a77897278..1242f4468 100644 --- a/src/VTKPlugin/VTKPlugin_ExportDriver.cxx +++ b/src/VTKPlugin/VTKPlugin_ExportDriver.cxx @@ -91,80 +91,16 @@ Standard_Integer VTKPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const MESSAGE( "Export VTK into file " << aFileName ); try { - GEOM_VertexSource* myVertexSource = GEOM_VertexSource::New(); - GEOM_EdgeSource* myIsolatedEdgeSource = GEOM_EdgeSource::New(); - GEOM_EdgeSource* myOneFaceEdgeSource = GEOM_EdgeSource::New(); - GEOM_EdgeSource* mySharedEdgeSource = GEOM_EdgeSource::New(); - GEOM_WireframeFace* myWireframeFaceSource = GEOM_WireframeFace::New(); - GEOM_ShadingFace* myShadingFaceSource = GEOM_ShadingFace::New(); - - vtkAppendPolyData* myAppendFilter = vtkAppendPolyData::New(); - myAppendFilter->AddInputConnection( myVertexSource->GetOutputPort() ); - myAppendFilter->AddInputConnection( myIsolatedEdgeSource->GetOutputPort() ); - myAppendFilter->AddInputConnection( myOneFaceEdgeSource->GetOutputPort() ); - myAppendFilter->AddInputConnection( mySharedEdgeSource->GetOutputPort() ); - //myAppendFilter->AddInputConnection( myWireframeFaceSource->GetOutputPort() ); // iso-lines are unnecessary - myAppendFilter->AddInputConnection( myShadingFaceSource->GetOutputPort() ); - - bool anIsVector = false; - - // Is shape triangulated? - bool wasMeshed = true; - TopExp_Explorer ex; - TopLoc_Location aLoc; - for (ex.Init(aShape, TopAbs_FACE); ex.More(); ex.Next()) { - const TopoDS_Face& aFace = TopoDS::Face(ex.Current()); - Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc); - if(aPoly.IsNull()) { - wasMeshed = false; - break; - } - } - - GEOM::MeshShape( aShape, aDeflection ); - - TopExp_Explorer aVertexExp( aShape, TopAbs_VERTEX ); - for( ; aVertexExp.More(); aVertexExp.Next() ) - { - const TopoDS_Vertex& aVertex = TopoDS::Vertex( aVertexExp.Current() ); - myVertexSource->AddVertex( aVertex ); - } - - TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap; - TopExp::MapShapesAndAncestors( aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap ); - - GEOM::SetShape( aShape, - anEdgeMap, - anIsVector, - 0, - myIsolatedEdgeSource, - myOneFaceEdgeSource, - mySharedEdgeSource, - myWireframeFaceSource, - myShadingFaceSource ); - - myAppendFilter->Update(); - // Set "C" numeric locale to save numbers correctly Kernel_Utils::Localizer loc; - vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); - aWriter->SetInputConnection( myAppendFilter->GetOutputPort() ); + vtkPolyData* pd = GEOM::GetData( aShape, aDeflection ); + vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); + aWriter->SetInputData( pd ); aWriter->SetFileName( aFileName.ToCString() ); aWriter->Write(); aWriter->Delete(); - - myVertexSource->Delete(); - myIsolatedEdgeSource->Delete(); - myOneFaceEdgeSource->Delete(); - mySharedEdgeSource->Delete(); - myWireframeFaceSource->Delete(); - myShadingFaceSource->Delete(); - - myAppendFilter->Delete(); - - if(!wasMeshed) - BRepTools::Clean(aShape); + pd->Delete(); //instanciated by the GEOM::GetData(...) method return 1; } -- 2.39.2