From 32e56a241f21859130edcfcc7a9d9c452c8d00d4 Mon Sep 17 00:00:00 2001 From: ouv Date: Tue, 15 Jun 2010 09:41:18 +0000 Subject: [PATCH] Issue 0020904: [CEA 411] export VTK in GEOM --- configure.ac | 2 + src/Makefile.am | 19 +- src/OBJECT/GEOM_Actor.cxx | 105 +---------- src/OBJECT/GEOM_Actor.h | 5 - src/OBJECT/GEOM_AssemblyBuilder.cxx | 49 +----- src/OBJECT/GEOM_AssemblyBuilder.h | 5 - src/OBJECT/Makefile.am | 20 +-- src/{OBJECT => OCC2VTK}/GEOM_EdgeSource.cxx | 0 src/{OBJECT => OCC2VTK}/GEOM_EdgeSource.h | 8 +- src/{OBJECT => OCC2VTK}/GEOM_FaceSource.cxx | 0 src/{OBJECT => OCC2VTK}/GEOM_FaceSource.h | 13 +- src/{OBJECT => OCC2VTK}/GEOM_ShadingFace.cxx | 0 src/{OBJECT => OCC2VTK}/GEOM_ShadingFace.h | 6 +- src/{OBJECT => OCC2VTK}/GEOM_VertexSource.cxx | 0 src/{OBJECT => OCC2VTK}/GEOM_VertexSource.h | 8 +- .../GEOM_WireframeFace.cxx | 0 src/{OBJECT => OCC2VTK}/GEOM_WireframeFace.h | 6 +- src/OCC2VTK/Makefile.am | 53 ++++++ src/OCC2VTK/OCC2VTK.h | 36 ++++ src/OCC2VTK/OCC2VTK_Tools.cxx | 165 ++++++++++++++++++ src/OCC2VTK/OCC2VTK_Tools.h | 55 ++++++ src/VTKExport/Makefile.am | 45 +++++ src/VTKExport/VTKExport.cxx | 144 +++++++++++++++ src/VTKExport/VTKExport.pro | 47 +++++ 24 files changed, 594 insertions(+), 197 deletions(-) rename src/{OBJECT => OCC2VTK}/GEOM_EdgeSource.cxx (100%) rename src/{OBJECT => OCC2VTK}/GEOM_EdgeSource.h (94%) rename src/{OBJECT => OCC2VTK}/GEOM_FaceSource.cxx (100%) rename src/{OBJECT => OCC2VTK}/GEOM_FaceSource.h (90%) rename src/{OBJECT => OCC2VTK}/GEOM_ShadingFace.cxx (100%) rename src/{OBJECT => OCC2VTK}/GEOM_ShadingFace.h (94%) rename src/{OBJECT => OCC2VTK}/GEOM_VertexSource.cxx (100%) rename src/{OBJECT => OCC2VTK}/GEOM_VertexSource.h (93%) rename src/{OBJECT => OCC2VTK}/GEOM_WireframeFace.cxx (100%) rename src/{OBJECT => OCC2VTK}/GEOM_WireframeFace.h (97%) create mode 100644 src/OCC2VTK/Makefile.am create mode 100755 src/OCC2VTK/OCC2VTK.h create mode 100755 src/OCC2VTK/OCC2VTK_Tools.cxx create mode 100755 src/OCC2VTK/OCC2VTK_Tools.h create mode 100644 src/VTKExport/Makefile.am create mode 100644 src/VTKExport/VTKExport.cxx create mode 100644 src/VTKExport/VTKExport.pro diff --git a/configure.ac b/configure.ac index 207f596b8..78894f478 100644 --- a/configure.ac +++ b/configure.ac @@ -423,6 +423,7 @@ AC_OUTPUT([ \ src/NMTDS/Makefile \ src/NMTTools/Makefile \ src/OBJECT/Makefile \ + src/OCC2VTK/Makefile \ src/OperationGUI/Makefile \ src/PrimitiveGUI/Makefile \ src/RepairGUI/Makefile \ @@ -432,6 +433,7 @@ AC_OUTPUT([ \ src/STLExport/Makefile \ src/ShHealOper/Makefile \ src/TransformationGUI/Makefile \ + src/VTKExport/Makefile \ resources/Makefile \ resources/GEOMCatalog.xml \ idl/Makefile \ diff --git a/src/Makefile.am b/src/Makefile.am index 761e3d6a9..3742902eb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,10 +21,10 @@ # Author : Alexander BORODIN, Open CASCADE S.A.S. (alexander.borodin@opencascade.com) # Package : src (source files directory) # -SUBDIRS = ARCHIMEDE NMTDS NMTTools GEOMAlgo SKETCHER GEOM BREPExport \ - BREPImport IGESExport IGESImport STEPExport STEPImport \ - STLExport ShHealOper GEOMImpl GEOM_I GEOMClient GEOM_I_Superv \ - GEOM_SWIG +SUBDIRS = ARCHIMEDE NMTDS NMTTools GEOMAlgo SKETCHER OCC2VTK GEOM \ + BREPExport BREPImport IGESExport IGESImport STEPExport \ + STEPImport STLExport VTKExport ShHealOper GEOMImpl GEOM_I \ + GEOMClient GEOM_I_Superv GEOM_SWIG if GEOM_ENABLE_GUI SUBDIRS += OBJECT DlgRef GEOMFiltersSelection GEOMGUI GEOMBase GEOMToolsGUI \ @@ -35,8 +35,9 @@ endif DIST_SUBDIRS = ARCHIMEDE NMTDS NMTTools GEOMAlgo SKETCHER GEOM BREPExport \ BREPImport IGESExport IGESImport STEPExport STEPImport STLExport \ - ShHealOper GEOMImpl GEOM_I GEOMClient GEOM_I_Superv GEOM_SWIG \ - OBJECT DlgRef GEOMFiltersSelection GEOMGUI GEOMBase GEOMToolsGUI \ - DisplayGUI BasicGUI PrimitiveGUI GenerationGUI EntityGUI \ - BuildGUI BooleanGUI TransformationGUI OperationGUI RepairGUI \ - MeasureGUI GroupGUI BlocksGUI AdvancedGUI GEOM_SWIG_WITHIHM + VTKExport ShHealOper GEOMImpl GEOM_I GEOMClient GEOM_I_Superv \ + GEOM_SWIG OBJECT DlgRef GEOMFiltersSelection GEOMGUI GEOMBase \ + GEOMToolsGUI DisplayGUI BasicGUI PrimitiveGUI GenerationGUI \ + EntityGUI BuildGUI BooleanGUI TransformationGUI OperationGUI \ + RepairGUI MeasureGUI GroupGUI BlocksGUI AdvancedGUI \ + GEOM_SWIG_WITHIHM diff --git a/src/OBJECT/GEOM_Actor.cxx b/src/OBJECT/GEOM_Actor.cxx index b152bafd2..c80f2d121 100644 --- a/src/OBJECT/GEOM_Actor.cxx +++ b/src/OBJECT/GEOM_Actor.cxx @@ -39,6 +39,8 @@ #include "GEOM_ShadingFace.h" #include "SVTK_Actor.h" +#include + #include #include #include @@ -47,14 +49,8 @@ #include #include -#include -#include -#include #include #include -#include -#include -#include #include #include @@ -354,35 +350,6 @@ GEOM_Actor return myVectorMode; } -static -void -MeshShape(const TopoDS_Shape& theShape, - float& theDeflection, - bool theIsRelative) -{ - static Standard_Real RELATIVE_DEFLECTION = 0.0001; - Standard_Real aDeflection = theDeflection; - - if(theDeflection <= 0) { // Compute default theDeflection - Bnd_Box B; - BRepBndLib::Add(theShape, B); - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) + - (aYmax-aYmin)*(aYmax-aYmin) + - (aZmax-aZmin)*(aZmax-aZmin); - aDiagonal = sqrt(aDiagonal); - aDeflection = aDiagonal*RELATIVE_DEFLECTION; - - if(theIsRelative) - theDeflection = RELATIVE_DEFLECTION; - else - theDeflection = aDeflection; - } - - BRepMesh_IncrementalMesh aMesh(theShape,aDeflection); -} - void GEOM_Actor:: SetDeflection(float theDeflection, bool theIsRelative) @@ -390,7 +357,7 @@ SetDeflection(float theDeflection, bool theIsRelative) myDeflection = theDeflection; myIsRelative = theIsRelative; - MeshShape(myShape,myDeflection,myIsRelative); + GEOM::MeshShape2(myShape,myDeflection,myIsRelative); SetModified(); } @@ -421,7 +388,12 @@ void GEOM_Actor::SetShape (const TopoDS_Shape& theShape, TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap; TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap); - SetShape(theShape,anEdgeMap,theIsVector); + GEOM::SetShape(theShape,anEdgeMap,theIsVector, + myIsolatedEdgeSource.Get(), + myOneFaceEdgeSource.Get(), + mySharedEdgeSource.Get(), + myWireframeFaceSource.Get(), + myShadingFaceSource.Get()); isOnlyVertex = myIsolatedEdgeSource->IsEmpty() && myOneFaceEdgeSource->IsEmpty() && @@ -436,65 +408,6 @@ void GEOM_Actor::SetShape (const TopoDS_Shape& theShape, } } -void GEOM_Actor::SetShape (const TopoDS_Shape& theShape, - const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap, - bool theIsVector) -{ - if (theShape.ShapeType() == TopAbs_COMPOUND) { - TopoDS_Iterator anItr(theShape); - for (; anItr.More(); anItr.Next()) { - SetShape(anItr.Value(),theEdgeMap,theIsVector); - } - } - - switch (theShape.ShapeType()) { - case TopAbs_WIRE: { - TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE); - for (; anEdgeExp.More(); anEdgeExp.Next()){ - const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current()); - if (!BRep_Tool::Degenerated(anEdge)) - myIsolatedEdgeSource->AddEdge(anEdge,theIsVector); - } - break; - } - case TopAbs_EDGE: { - const TopoDS_Edge& anEdge = TopoDS::Edge(theShape); - if (!BRep_Tool::Degenerated(anEdge)) - myIsolatedEdgeSource->AddEdge(anEdge,theIsVector); - break; - } - case TopAbs_VERTEX: { - break; - } - default: { - TopExp_Explorer aFaceExp (theShape,TopAbs_FACE); - for(; aFaceExp.More(); aFaceExp.Next()) { - const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current()); - myWireframeFaceSource->AddFace(aFace); - myShadingFaceSource->AddFace(aFace); - TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE); - for(; anEdgeExp.More(); anEdgeExp.Next()) { - const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current()); - if(!BRep_Tool::Degenerated(anEdge)){ - // compute the number of faces - int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent(); - switch(aNbOfFaces){ - case 0: // isolated edge - myIsolatedEdgeSource->AddEdge(anEdge,theIsVector); - break; - case 1: // edge in only one face - myOneFaceEdgeSource->AddEdge(anEdge,theIsVector); - break; - default: // edge shared by at least two faces - mySharedEdgeSource->AddEdge(anEdge,theIsVector); - } - } - } - } - } - } -} - // OLD METHODS void GEOM_Actor::setDeflection(double adef) { #ifdef MYDEBUG diff --git a/src/OBJECT/GEOM_Actor.h b/src/OBJECT/GEOM_Actor.h index e8e086464..e31ea1990 100644 --- a/src/OBJECT/GEOM_Actor.h +++ b/src/OBJECT/GEOM_Actor.h @@ -51,7 +51,6 @@ typedef GEOM_SmartPtr PWFaceSource; class GEOM_ShadingFace; typedef GEOM_SmartPtr PSFaceSource; -#include class vtkRenderer; class vtkAppendPolyData; @@ -174,10 +173,6 @@ public: GetVectorMode(); protected: - void SetShape(const TopoDS_Shape& theShape, - const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap, - bool theIsVector = false); - void SetModified(); void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result); diff --git a/src/OBJECT/GEOM_AssemblyBuilder.cxx b/src/OBJECT/GEOM_AssemblyBuilder.cxx index 6c0f52833..ebad1a415 100644 --- a/src/OBJECT/GEOM_AssemblyBuilder.cxx +++ b/src/OBJECT/GEOM_AssemblyBuilder.cxx @@ -34,6 +34,8 @@ #include "GEOM_AssemblyBuilder.h" #include "GEOM_Actor.h" +#include + #include #include @@ -43,14 +45,9 @@ // Open CASCADE Includes #include -#include -#include -#include -#include #include #include #include -#include #include // Qt includes @@ -58,15 +55,6 @@ #include "utilities.h" -// SALOME - -#define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) ) -#define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) ) - - - - - void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp, vtkProperty* FaceProp, vtkProperty* EdgeFProp, @@ -159,37 +147,6 @@ void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp, } -void GEOM_AssemblyBuilder::MeshShape(const TopoDS_Shape myShape, - Standard_Real deflection, - Standard_Boolean forced) -{ - // Mesh the shape if necessary - Standard_Boolean alreadymesh = Standard_True; - TopExp_Explorer ex; - TopLoc_Location aLoc; - - for (ex.Init(myShape, 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()) { alreadymesh = Standard_False; break; } - } - - if(!alreadymesh || forced) { - if(deflection<=0) { - // Compute default deflection - Bnd_Box B; - BRepBndLib::Add(myShape, B); - if ( B.IsVoid() ) return; // NPAL15983 (Bug when displaying empty groups) - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - deflection = MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) * 0.001 *4; - } - BRepMesh_IncrementalMesh MESH(myShape,deflection); - } -} - - - vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShape, Standard_Real deflection, Standard_Integer mode, @@ -210,7 +167,7 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap */ vtkActorCollection* AISActors = vtkActorCollection::New(); - MeshShape(myShape,deflection,forced); + GEOM::MeshShape(myShape,deflection,forced); GEOM_Actor* aGeomActor = GEOM_Actor::New(); aGeomActor->SetShape(myShape,(float)deflection,false,isVector); AISActors->AddItem(aGeomActor); diff --git a/src/OBJECT/GEOM_AssemblyBuilder.h b/src/OBJECT/GEOM_AssemblyBuilder.h index 73fadc31d..1f8bd88fb 100644 --- a/src/OBJECT/GEOM_AssemblyBuilder.h +++ b/src/OBJECT/GEOM_AssemblyBuilder.h @@ -50,11 +50,6 @@ class GEOM_OBJECT_EXPORT GEOM_AssemblyBuilder { vtkProperty* EdgePVProp, vtkProperty* VertePVProp); - static void MeshShape(const TopoDS_Shape myShape, - Standard_Real deflection, - Standard_Boolean forced); - - public: diff --git a/src/OBJECT/Makefile.am b/src/OBJECT/Makefile.am index 52fbad34b..454f6c0f8 100644 --- a/src/OBJECT/Makefile.am +++ b/src/OBJECT/Makefile.am @@ -43,12 +43,7 @@ salomeinclude_HEADERS = \ GEOM_OBJECT_defs.hxx \ GEOM_OCCReader.h \ GEOM_SmartPtr.h \ - GEOM_DeviceActor.h \ - GEOM_EdgeSource.h \ - GEOM_FaceSource.h \ - GEOM_ShadingFace.h \ - GEOM_VertexSource.h \ - GEOM_WireframeFace.h + GEOM_DeviceActor.h # Libraries targets lib_LTLIBRARIES = libGEOMObject.la @@ -62,12 +57,7 @@ dist_libGEOMObject_la_SOURCES = \ GEOM_AISTrihedron.cxx \ GEOM_VTKTrihedron.cxx \ GEOM_AISVector.cxx \ - GEOM_DeviceActor.cxx \ - GEOM_EdgeSource.cxx \ - GEOM_FaceSource.cxx \ - GEOM_ShadingFace.cxx \ - GEOM_VertexSource.cxx \ - GEOM_WireframeFace.cxx + GEOM_DeviceActor.cxx libGEOMObject_la_CPPFLAGS = \ @@ -78,9 +68,11 @@ libGEOMObject_la_CPPFLAGS = \ $(CAS_CPPFLAGS) \ $(VTK_INCLUDES) \ $(KERNEL_CXXFLAGS) \ - $(GUI_CXXFLAGS) - + $(GUI_CXXFLAGS) \ + -I$(srcdir)/../OCC2VTK + libGEOMObject_la_LDFLAGS = \ + ../OCC2VTK/libOCC2VTK.la \ $(QT_MT_LIBS) \ $(CAS_KERNEL) -lTKBRep -lTKG2d -lTKG3d -lTKV3d -lTKMesh -lTKGeomBase -lTKGeomAlgo -lTKTopAlgo -lTKService \ $(VTK_LIBS) \ diff --git a/src/OBJECT/GEOM_EdgeSource.cxx b/src/OCC2VTK/GEOM_EdgeSource.cxx similarity index 100% rename from src/OBJECT/GEOM_EdgeSource.cxx rename to src/OCC2VTK/GEOM_EdgeSource.cxx diff --git a/src/OBJECT/GEOM_EdgeSource.h b/src/OCC2VTK/GEOM_EdgeSource.h similarity index 94% rename from src/OBJECT/GEOM_EdgeSource.h rename to src/OCC2VTK/GEOM_EdgeSource.h index 82383a663..9ef08683f 100755 --- a/src/OBJECT/GEOM_EdgeSource.h +++ b/src/OCC2VTK/GEOM_EdgeSource.h @@ -20,17 +20,17 @@ #ifndef GEOM_EDGESOURCE_H #define GEOM_EDGESOURCE_H -#include "GEOM_DeviceActor.h" +#include "OCC2VTK.h" #include #include typedef NCollection_Set TEdgeSet; +#include #include - - -class VTK_EXPORT GEOM_EdgeSource: public vtkPolyDataSource + +class OCC2VTK_EXPORT GEOM_EdgeSource: public vtkPolyDataSource { public: vtkTypeMacro(GEOM_EdgeSource,vtkPolyDataSource); diff --git a/src/OBJECT/GEOM_FaceSource.cxx b/src/OCC2VTK/GEOM_FaceSource.cxx similarity index 100% rename from src/OBJECT/GEOM_FaceSource.cxx rename to src/OCC2VTK/GEOM_FaceSource.cxx diff --git a/src/OBJECT/GEOM_FaceSource.h b/src/OCC2VTK/GEOM_FaceSource.h similarity index 90% rename from src/OBJECT/GEOM_FaceSource.h rename to src/OCC2VTK/GEOM_FaceSource.h index 2fed7cb40..555dcdeb1 100755 --- a/src/OBJECT/GEOM_FaceSource.h +++ b/src/OCC2VTK/GEOM_FaceSource.h @@ -20,21 +20,18 @@ #ifndef GEOM_FACESOURCE_H #define GEOM_FACESOURCE_H -#include "GEOM_DeviceActor.h" - +#include "OCC2VTK.h" + #include #include #include typedef NCollection_Set TFaceSet; +#include #include - -class GEOM_FaceSource; -typedef GEOM_SmartPtr PFaceSource; - - -class VTK_EXPORT GEOM_FaceSource: public vtkPolyDataSource + +class OCC2VTK_EXPORT GEOM_FaceSource: public vtkPolyDataSource { public: vtkTypeMacro(GEOM_FaceSource,vtkPolyDataSource); diff --git a/src/OBJECT/GEOM_ShadingFace.cxx b/src/OCC2VTK/GEOM_ShadingFace.cxx similarity index 100% rename from src/OBJECT/GEOM_ShadingFace.cxx rename to src/OCC2VTK/GEOM_ShadingFace.cxx diff --git a/src/OBJECT/GEOM_ShadingFace.h b/src/OCC2VTK/GEOM_ShadingFace.h similarity index 94% rename from src/OBJECT/GEOM_ShadingFace.h rename to src/OCC2VTK/GEOM_ShadingFace.h index ee1f7a924..2af0254ae 100755 --- a/src/OBJECT/GEOM_ShadingFace.h +++ b/src/OCC2VTK/GEOM_ShadingFace.h @@ -20,10 +20,10 @@ #ifndef GEOM_SHADINGFACE_H #define GEOM_SHADINGFACE_H +#include "OCC2VTK.h" #include "GEOM_FaceSource.h" - - -class VTK_EXPORT GEOM_ShadingFace: public GEOM_FaceSource + +class OCC2VTK_EXPORT GEOM_ShadingFace: public GEOM_FaceSource { public: vtkTypeMacro(GEOM_ShadingFace,GEOM_FaceSource); diff --git a/src/OBJECT/GEOM_VertexSource.cxx b/src/OCC2VTK/GEOM_VertexSource.cxx similarity index 100% rename from src/OBJECT/GEOM_VertexSource.cxx rename to src/OCC2VTK/GEOM_VertexSource.cxx diff --git a/src/OBJECT/GEOM_VertexSource.h b/src/OCC2VTK/GEOM_VertexSource.h similarity index 93% rename from src/OBJECT/GEOM_VertexSource.h rename to src/OCC2VTK/GEOM_VertexSource.h index 782c528a8..612e11237 100755 --- a/src/OBJECT/GEOM_VertexSource.h +++ b/src/OCC2VTK/GEOM_VertexSource.h @@ -20,17 +20,17 @@ #ifndef GEOM_VERTEXSOURCE_H #define GEOM_VERTEXSOURCE_H -#include "GEOM_DeviceActor.h" +#include "OCC2VTK.h" #include #include typedef NCollection_Set TVertexSet; +#include #include - - -class VTK_EXPORT GEOM_VertexSource: public vtkPolyDataSource + +class OCC2VTK_EXPORT GEOM_VertexSource: public vtkPolyDataSource { public: vtkTypeMacro(GEOM_VertexSource,vtkPolyDataSource); diff --git a/src/OBJECT/GEOM_WireframeFace.cxx b/src/OCC2VTK/GEOM_WireframeFace.cxx similarity index 100% rename from src/OBJECT/GEOM_WireframeFace.cxx rename to src/OCC2VTK/GEOM_WireframeFace.cxx diff --git a/src/OBJECT/GEOM_WireframeFace.h b/src/OCC2VTK/GEOM_WireframeFace.h similarity index 97% rename from src/OBJECT/GEOM_WireframeFace.h rename to src/OCC2VTK/GEOM_WireframeFace.h index d34bf9652..1b506f95d 100755 --- a/src/OBJECT/GEOM_WireframeFace.h +++ b/src/OCC2VTK/GEOM_WireframeFace.h @@ -20,15 +20,15 @@ #ifndef GEOM_WIREFRAME_FACE_H #define GEOM_WIREFRAME_FACE_H +#include "OCC2VTK.h" #include "GEOM_FaceSource.h" #include #include #include - - -class VTK_EXPORT GEOM_WireframeFace: public GEOM_FaceSource + +class OCC2VTK_EXPORT GEOM_WireframeFace: public GEOM_FaceSource { public: vtkTypeMacro(GEOM_WireframeFace,GEOM_FaceSource); diff --git a/src/OCC2VTK/Makefile.am b/src/OCC2VTK/Makefile.am new file mode 100644 index 000000000..0ad1ea823 --- /dev/null +++ b/src/OCC2VTK/Makefile.am @@ -0,0 +1,53 @@ +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# header files +salomeinclude_HEADERS = \ + OCC2VTK.h \ + OCC2VTK_Tools.h \ + GEOM_EdgeSource.h \ + GEOM_FaceSource.h \ + GEOM_ShadingFace.h \ + GEOM_VertexSource.h \ + GEOM_WireframeFace.h + +# Libraries targets +lib_LTLIBRARIES = libOCC2VTK.la + +dist_libOCC2VTK_la_SOURCES = \ + OCC2VTK_Tools.cxx \ + GEOM_EdgeSource.cxx \ + GEOM_FaceSource.cxx \ + GEOM_ShadingFace.cxx \ + GEOM_VertexSource.cxx \ + GEOM_WireframeFace.cxx + +libOCC2VTK_la_CPPFLAGS = \ + $(QT_INCLUDES) \ + $(CAS_CPPFLAGS) \ + $(VTK_INCLUDES) \ + $(KERNEL_CXXFLAGS) + +libOCC2VTK_la_LDFLAGS = \ + $(QT_MT_LIBS) \ + $(CAS_KERNEL) -lTKBRep -lTKG2d -lTKG3d -lTKV3d -lTKMesh -lTKGeomBase -lTKGeomAlgo -lTKTopAlgo -lTKService \ + $(VTK_LIBS) \ + $(KERNEL_LDFLAGS) -lSALOMELocalTrace diff --git a/src/OCC2VTK/OCC2VTK.h b/src/OCC2VTK/OCC2VTK.h new file mode 100755 index 000000000..603942ac1 --- /dev/null +++ b/src/OCC2VTK/OCC2VTK.h @@ -0,0 +1,36 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef OCC2VTK_H +#define OCC2VTK_H + +#if defined WIN32 +# if defined OCC2VTK_EXPORTS +# define OCC2VTK_EXPORT __declspec( dllexport ) +# else +# define OCC2VTK_EXPORT __declspec( dllimport ) +# endif +#else +# define OCC2VTK_EXPORT +#endif + +#endif // OCC2VTK_H diff --git a/src/OCC2VTK/OCC2VTK_Tools.cxx b/src/OCC2VTK/OCC2VTK_Tools.cxx new file mode 100755 index 000000000..ef0e4ce35 --- /dev/null +++ b/src/OCC2VTK/OCC2VTK_Tools.cxx @@ -0,0 +1,165 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "OCC2VTK_Tools.h" + +#include "GEOM_VertexSource.h" +#include "GEOM_EdgeSource.h" +#include "GEOM_WireframeFace.h" +#include "GEOM_ShadingFace.h" + +#include +#include +#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)) + +namespace GEOM +{ + void MeshShape(const TopoDS_Shape theShape, + Standard_Real theDeflection, + Standard_Boolean theForced) + { + // Mesh the shape if necessary + Standard_Boolean alreadymesh = Standard_True; + TopExp_Explorer ex; + TopLoc_Location aLoc; + + for (ex.Init(theShape, 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()) { alreadymesh = Standard_False; break; } + } + + if(!alreadymesh || theForced) { + if(theDeflection<=0) { + // Compute default deflection + Bnd_Box B; + BRepBndLib::Add(theShape, B); + if ( B.IsVoid() ) return; // NPAL15983 (Bug when displaying empty groups) + Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + theDeflection = MAX3(aXmax-aXmin, aYmax-aYmin, aZmax-aZmin) * 0.001 * 4; + } + BRepMesh_IncrementalMesh MESH(theShape,theDeflection); + } + } + + void MeshShape2(const TopoDS_Shape& theShape, + float& theDeflection, + bool theIsRelative) + { + static Standard_Real RELATIVE_DEFLECTION = 0.0001; + Standard_Real aDeflection = theDeflection; + + if(theDeflection <= 0) { // Compute default theDeflection + Bnd_Box B; + BRepBndLib::Add(theShape, B); + Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) + + (aYmax-aYmin)*(aYmax-aYmin) + + (aZmax-aZmin)*(aZmax-aZmin); + aDiagonal = sqrt(aDiagonal); + aDeflection = aDiagonal*RELATIVE_DEFLECTION; + + if(theIsRelative) + theDeflection = RELATIVE_DEFLECTION; + else + theDeflection = aDeflection; + } + + BRepMesh_IncrementalMesh aMesh(theShape,aDeflection); + } + + void SetShape(const TopoDS_Shape& theShape, + const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap, + bool theIsVector, + GEOM_EdgeSource* theIsolatedEdgeSource, + GEOM_EdgeSource* theOneFaceEdgeSource, + GEOM_EdgeSource* theSharedEdgeSource, + GEOM_WireframeFace* theWireframeFaceSource, + GEOM_ShadingFace* theShadingFaceSource) + { + if (theShape.ShapeType() == TopAbs_COMPOUND) { + TopoDS_Iterator anItr(theShape); + for (; anItr.More(); anItr.Next()) { + SetShape(anItr.Value(),theEdgeMap,theIsVector, + theIsolatedEdgeSource, + theOneFaceEdgeSource, + theSharedEdgeSource, + theWireframeFaceSource, + theShadingFaceSource); + } + } + + switch (theShape.ShapeType()) { + case TopAbs_WIRE: { + TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE); + for (; anEdgeExp.More(); anEdgeExp.Next()){ + const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current()); + if (!BRep_Tool::Degenerated(anEdge)) + theIsolatedEdgeSource->AddEdge(anEdge,theIsVector); + } + break; + } + case TopAbs_EDGE: { + const TopoDS_Edge& anEdge = TopoDS::Edge(theShape); + if (!BRep_Tool::Degenerated(anEdge)) + theIsolatedEdgeSource->AddEdge(anEdge,theIsVector); + break; + } + case TopAbs_VERTEX: { + break; + } + default: { + TopExp_Explorer aFaceExp (theShape,TopAbs_FACE); + for(; aFaceExp.More(); aFaceExp.Next()) { + const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current()); + theWireframeFaceSource->AddFace(aFace); + theShadingFaceSource->AddFace(aFace); + TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE); + for(; anEdgeExp.More(); anEdgeExp.Next()) { + const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current()); + if(!BRep_Tool::Degenerated(anEdge)){ + // compute the number of faces + int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent(); + switch(aNbOfFaces){ + case 0: // isolated edge + theIsolatedEdgeSource->AddEdge(anEdge,theIsVector); + break; + case 1: // edge in only one face + theOneFaceEdgeSource->AddEdge(anEdge,theIsVector); + break; + default: // edge shared by at least two faces + theSharedEdgeSource->AddEdge(anEdge,theIsVector); + } + } + } + } + } + } + } +} diff --git a/src/OCC2VTK/OCC2VTK_Tools.h b/src/OCC2VTK/OCC2VTK_Tools.h new file mode 100755 index 000000000..c019154cb --- /dev/null +++ b/src/OCC2VTK/OCC2VTK_Tools.h @@ -0,0 +1,55 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef OCC2VTK_TOOLS_H +#define OCC2VTK_TOOLS_H + +#include "OCC2VTK.h" + +#include +#include + +class GEOM_EdgeSource; +class GEOM_WireframeFace; +class GEOM_ShadingFace; + +namespace GEOM +{ + // moved from GEOM_AssemblyBuilder + OCC2VTK_EXPORT void MeshShape(const TopoDS_Shape theShape, + Standard_Real theDeflection, + Standard_Boolean theForced); + + // moved from GEOM_Actor + OCC2VTK_EXPORT void MeshShape2(const TopoDS_Shape& theShape, + float& theDeflection, + bool theIsRelative); + + // moved from GEOM_Actor + OCC2VTK_EXPORT void SetShape(const TopoDS_Shape& theShape, + const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap, + bool theIsVector, + GEOM_EdgeSource* theIsolatedEdgeSource, + GEOM_EdgeSource* theOneFaceEdgeSource, + GEOM_EdgeSource* theSharedEdgeSource, + GEOM_WireframeFace* theWireframeFaceSource, + GEOM_ShadingFace* theShadingFaceSource); +} + +#endif // OCC2VTK_TOOLS_H diff --git a/src/VTKExport/Makefile.am b/src/VTKExport/Makefile.am new file mode 100644 index 000000000..109e78b63 --- /dev/null +++ b/src/VTKExport/Makefile.am @@ -0,0 +1,45 @@ +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# $Header$ +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# header files +salomeinclude_HEADERS = + +# Libraries targets +lib_LTLIBRARIES = libVTKExport.la + +dist_libVTKExport_la_SOURCES = \ + VTKExport.cxx + +# additional information to compile and link file + +libVTKExport_la_CPPFLAGS = \ + $(CAS_CPPFLAGS) \ + $(VTK_INCLUDES) \ + $(KERNEL_CXXFLAGS) \ + -I$(srcdir)/../OCC2VTK + +libVTKExport_la_LDFLAGS = \ + ../OCC2VTK/libOCC2VTK.la \ + $(KERNEL_LDFLAGS) -lSALOMELocalTrace \ + $(STDLIB) \ + $(CAS_LDPATH) diff --git a/src/VTKExport/VTKExport.cxx b/src/VTKExport/VTKExport.cxx new file mode 100644 index 000000000..4d0f3ac7a --- /dev/null +++ b/src/VTKExport/VTKExport.cxx @@ -0,0 +1,144 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: VTKExport.cxx +// Author: Oleg UVAROV +// +#include "utilities.h" + +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#ifdef WIN32 +# if defined VTKEXPORT_EXPORTS || defined VTKExport_EXPORTS +# define VTKEXPORT_EXPORT __declspec( dllexport ) +# else +# define VTKEXPORT_EXPORT __declspec( dllimport ) +# endif +#else +# define VTKEXPORT_EXPORT +#endif + +//============================================================================= +/*! + * + */ +//============================================================================= + +extern "C" +{ + VTKEXPORT_EXPORT + int Export(const TopoDS_Shape& theShape, + const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& theFormatName) + { + MESSAGE("Export VTK into file " << theFileName.ToCString()); + + 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->AddInput( myVertexSource->GetOutput() ); + myAppendFilter->AddInput( myIsolatedEdgeSource->GetOutput() ); + myAppendFilter->AddInput( myOneFaceEdgeSource->GetOutput() ); + myAppendFilter->AddInput( mySharedEdgeSource->GetOutput() ); + //myAppendFilter->AddInput( myWireframeFaceSource->GetOutput() ); // iso-lines are unnecessary + myAppendFilter->AddInput( myShadingFaceSource->GetOutput() ); + + float aDeflection = 1.0; + bool anIsForced = true; + bool anIsRelative = false; + bool anIsVector = false; + + GEOM::MeshShape( theShape, aDeflection, anIsForced ); + + TopExp_Explorer aVertexExp( theShape, TopAbs_VERTEX ); + for( ; aVertexExp.More(); aVertexExp.Next() ) + { + const TopoDS_Vertex& aVertex = TopoDS::Vertex( aVertexExp.Current() ); + myVertexSource->AddVertex( aVertex ); + } + + GEOM::MeshShape2( theShape, aDeflection, anIsRelative ); + + TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap; + TopExp::MapShapesAndAncestors( theShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap ); + + GEOM::SetShape( theShape, + anEdgeMap, + anIsVector, + myIsolatedEdgeSource, + myOneFaceEdgeSource, + mySharedEdgeSource, + myWireframeFaceSource, + myShadingFaceSource ); + + myAppendFilter->Update(); + + // Set "C" numeric locale to save numbers correctly + Kernel_Utils::Localizer loc; + + vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); + aWriter->SetInput( myAppendFilter->GetOutput() ); + aWriter->SetFileName( theFileName.ToCString() ); + aWriter->Write(); + aWriter->Delete(); + + myVertexSource->Delete(); + myIsolatedEdgeSource->Delete(); + myOneFaceEdgeSource->Delete(); + mySharedEdgeSource->Delete(); + myWireframeFaceSource->Delete(); + myShadingFaceSource->Delete(); + + myAppendFilter->Delete(); + + return 1; + } + catch(Standard_Failure) + { + //THROW_SALOME_CORBA_EXCEPTION("Exception catched in VTKExport", SALOME::BAD_PARAM); + } + return 0; + } +} diff --git a/src/VTKExport/VTKExport.pro b/src/VTKExport/VTKExport.pro new file mode 100644 index 000000000..ddc34fe23 --- /dev/null +++ b/src/VTKExport/VTKExport.pro @@ -0,0 +1,47 @@ +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +TEMPLATE = lib +TARGET = VTKExport +DESTDIR = ../../lib +MOC_DIR = ../../moc +OBJECTS_DIR = ../../obj/$$TARGET + +CASROOT = $$(CASROOT) +CAS_CPPFLAGS = $${CASROOT}/inc + +KERNEL_CXXFLAGS = $$(KERNEL_ROOT_DIR)/include/salome + +KERNEL_LDFLAGS = -L$$(KERNEL_ROOT_DIR)/lib/salome + +STDLIB = -lstdc++ + +CAS_LDPATH = -L$$(CASROOT)/Linux/lib + +INCLUDEPATH += $${CAS_CPPFLAGS} $${KERNEL_CXXFLAGS} + +LIBS += $${STDLIB} $${CAS_LDPATH} $${KERNEL_LDFLAGS} -lSALOMELocalTrace + +CONFIG -= debug release debug_and_release +CONFIG += qt thread debug dll shared + +win32:DEFINES += WIN32 +DEFINES += OCC_VERSION_MAJOR=6 OCC_VERSION_MINOR=1 OCC_VERSION_MAINTENANCE=1 LIN LINTEL CSFDB No_exception HAVE_CONFIG_H HAVE_LIMITS_H HAVE_WOK_CONFIG_H OCC_CONVERT_SIGNALS + +SOURCES = VTKExport.cxx -- 2.39.2