From: ouv Date: Tue, 15 Jun 2010 09:41:18 +0000 (+0000) Subject: Issue 0020904: [CEA 411] export VTK in GEOM X-Git-Tag: translate_resources_09Jul10~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=32e56a241f21859130edcfcc7a9d9c452c8d00d4;p=modules%2Fgeom.git Issue 0020904: [CEA 411] export VTK in GEOM --- 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/GEOM_EdgeSource.cxx b/src/OBJECT/GEOM_EdgeSource.cxx deleted file mode 100755 index e44cc81e0..000000000 --- a/src/OBJECT/GEOM_EdgeSource.cxx +++ /dev/null @@ -1,272 +0,0 @@ -// 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 "GEOM_EdgeSource.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -vtkStandardNewMacro(GEOM_EdgeSource); - -GEOM_EdgeSource::GEOM_EdgeSource() : - myIsVector(false) -{ -} - -GEOM_EdgeSource::~GEOM_EdgeSource() -{ -} - -void GEOM_EdgeSource::AddEdge (const TopoDS_Edge& theEdge, - bool theIsVector) -{ - myEdgeSet.Add(theEdge); - myIsVector = theIsVector; -} - -void -GEOM_EdgeSource:: -Execute() -{ - vtkPolyData* aPolyData = GetOutput(); - aPolyData->Allocate(); - vtkPoints* aPts = vtkPoints::New(); - aPolyData->SetPoints(aPts); - aPts->Delete(); - - TEdgeSet::Iterator anIter (myEdgeSet); - for (; anIter.More(); anIter.Next()) { - const TopoDS_Edge& anEdge = anIter.Value(); - OCC2VTK(anEdge,aPolyData,aPts,myIsVector); - } -} - -void GEOM_EdgeSource::OCC2VTK (const TopoDS_Edge& theEdge, - vtkPolyData* thePolyData, - vtkPoints* thePts, - bool theIsVector) -{ - Handle(Poly_PolygonOnTriangulation) aEdgePoly; - Standard_Integer i = 1; - Handle(Poly_Triangulation) T; - TopLoc_Location aEdgeLoc; - BRep_Tool::PolygonOnTriangulation(theEdge, aEdgePoly, T, aEdgeLoc, i); - - Handle(Poly_Polygon3D) P; - if(aEdgePoly.IsNull()) - P = BRep_Tool::Polygon3D(theEdge, aEdgeLoc); - - if(P.IsNull() && aEdgePoly.IsNull()) - return; - - // Location edges - //--------------- - gp_Trsf edgeTransf; - Standard_Boolean isidtrsf = true; - if(!aEdgeLoc.IsIdentity()) { - isidtrsf = false; - edgeTransf = aEdgeLoc.Transformation(); - } - - gp_Pnt aP1, aP2; - - if (aEdgePoly.IsNull()) { - Standard_Integer aNbNodes = P->NbNodes(); - const TColgp_Array1OfPnt& aNodesP = P->Nodes(); - - aP1 = aNodesP(1); - aP2 = aNodesP(aNbNodes); - - for (int j = 1; j < aNbNodes; j++) { - gp_Pnt pt1 = aNodesP(j); - gp_Pnt pt2 = aNodesP(j+1); - - if (!isidtrsf) { - // apply edge transformation - pt1.Transform(edgeTransf); - pt2.Transform(edgeTransf); - } - - float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()}; - vtkIdType anIds[2]; - anIds[0] = thePts->InsertNextPoint(aCoord1); - - float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()}; - anIds[1] = thePts->InsertNextPoint(aCoord2); - - thePolyData->InsertNextCell(VTK_LINE,2,anIds); - } - } else { - Standard_Integer aNbNodes = aEdgePoly->NbNodes(); - const TColStd_Array1OfInteger& aNodeIds = aEdgePoly->Nodes(); - const TColgp_Array1OfPnt& anId2Pnts = T->Nodes(); - - aP1 = anId2Pnts(aNodeIds(1)); - aP2 = anId2Pnts(aNodeIds(aNbNodes)); - - for(int j = 1; j < aNbNodes; j++) { - Standard_Integer id1 = aNodeIds(j); - Standard_Integer id2 = aNodeIds(j+1); - - gp_Pnt pt1 = anId2Pnts(id1); - gp_Pnt pt2 = anId2Pnts(id2); - - if(!isidtrsf) { - // apply edge transformation - pt1.Transform(edgeTransf); - pt2.Transform(edgeTransf); - } - - float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()}; - vtkIdType anIds[2]; - anIds[0] = thePts->InsertNextPoint(aCoord1); - - float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()}; - anIds[1] = thePts->InsertNextPoint(aCoord2); - - thePolyData->InsertNextCell(VTK_LINE,2,anIds); - } - } - - - // vector representation has an arrow on its end - if (theIsVector) - { - if (!isidtrsf) { - // apply edge transformation - aP1.Transform(edgeTransf); - aP2.Transform(edgeTransf); - } - - // draw an arrow - - double fp,lp; - gp_Vec aDirVec; - Handle(Geom_Curve) C = BRep_Tool::Curve(theEdge,fp,lp); - if ( theEdge.Orientation() == TopAbs_FORWARD ) { - C->D1(lp, aP2, aDirVec); - } else { - C->D1(fp, aP1, aDirVec); - aP2 = aP1; - } - - GeomAdaptor_Curve aAdC; - aAdC.Load(C, fp, lp); - Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp); - if (aDist < gp::Resolution()) return; - - gp_Dir aDirection; - - if ( theEdge.Orientation() == TopAbs_FORWARD ) - aDirection = aDirVec; - else - aDirection = -aDirVec; - - Standard_Real anAngle = PI/180.*5.; - Standard_Real aLength = aDist/10.; - - Standard_Real dx,dy,dz; - aDirection.Coord(dx,dy,dz); - - // Arrow Point - Standard_Real xo,yo,zo; - aP2.Coord(xo,yo,zo); - - // Center of circle that arrow based - gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength; - - // Construction of the base vectors for the arrow circle - gp_Dir aDirN; - if (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX(); - else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY(); - else aDirN = gp::DZ(); - - gp_Dir aDirI = aDirection ^ aDirN; - gp_Dir aDirJ = aDirection ^ aDirI; - - // Add points and segments, composing the arrow - Standard_Real cosinus, sinus, Tg = tan(anAngle); - - float coord[3] = {xo, yo, zo}; - - vtkIdType ptLoc = thePts->InsertNextPoint(coord); - vtkIdType ptFirst = 0; - vtkIdType ptPrev = 0; - vtkIdType ptCur = 0; - - vtkIdType pts[2]; - - int NbPoints = 15; - for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur) - { - cosinus = cos(2. * PI / NbPoints * (i-1)); - sinus = sin(2. * PI / NbPoints * (i-1)); - - gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg; - coord[0] = aP.X(); - coord[1] = aP.Y(); - coord[2] = aP.Z(); - - // insert pts - ptCur = thePts->InsertNextPoint(coord); - pts[0] = ptCur; - - if (i == 1) { - ptFirst = ptCur; - } - else { - // insert line (ptCur,ptPrev) - pts[1] = ptPrev; - thePolyData->InsertNextCell(VTK_LINE,2,pts); - } - - // insert line (ptCur,ptLoc) - pts[1] = ptLoc; - thePolyData->InsertNextCell(VTK_LINE,2,pts); - } - - // insert line (ptCur,ptFirst) - pts[0] = ptCur; - pts[1] = ptFirst; - thePolyData->InsertNextCell(VTK_LINE,2,pts); - } -} - -void GEOM_EdgeSource::SetVectorMode (bool theMode) -{ - myIsVector = theMode; -} - -bool GEOM_EdgeSource::GetVectorMode () -{ - return myIsVector; -} diff --git a/src/OBJECT/GEOM_EdgeSource.h b/src/OBJECT/GEOM_EdgeSource.h deleted file mode 100755 index 82383a663..000000000 --- a/src/OBJECT/GEOM_EdgeSource.h +++ /dev/null @@ -1,74 +0,0 @@ -// 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 GEOM_EDGESOURCE_H -#define GEOM_EDGESOURCE_H - -#include "GEOM_DeviceActor.h" - -#include -#include - -typedef NCollection_Set TEdgeSet; - -#include - - -class VTK_EXPORT GEOM_EdgeSource: public vtkPolyDataSource -{ -public: - vtkTypeMacro(GEOM_EdgeSource,vtkPolyDataSource); - static GEOM_EdgeSource* New(); - - void AddEdge (const TopoDS_Edge& theEdge, - bool theIsVector = false); - void Clear(){ myEdgeSet.Clear();} - - void SetVectorMode(bool); - - bool GetVectorMode(); - - static - void OCC2VTK(const TopoDS_Edge& theEdge, - vtkPolyData* thePolyData, - vtkPoints* thePts, - bool theIsVector = false); - - bool IsEmpty(){return myEdgeSet.IsEmpty();} - - -protected: - TEdgeSet myEdgeSet; - // The flag is common for all edges, because the shape, - // representing a vector, can have only one edge. - bool myIsVector; - - void Execute(); - - GEOM_EdgeSource(); - ~GEOM_EdgeSource(); - -private: - // Not implememnted - GEOM_EdgeSource(const GEOM_EdgeSource&); - void operator=(const GEOM_EdgeSource&); -}; - - -#endif //GEOM_EDGESOURCE_H diff --git a/src/OBJECT/GEOM_FaceSource.cxx b/src/OBJECT/GEOM_FaceSource.cxx deleted file mode 100755 index 7035ef85e..000000000 --- a/src/OBJECT/GEOM_FaceSource.cxx +++ /dev/null @@ -1,63 +0,0 @@ -// 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 "GEOM_FaceSource.h" - -#include - -#include -#include - -#include -#include - -GEOM_FaceSource::GEOM_FaceSource() -{ -} - -GEOM_FaceSource::~GEOM_FaceSource() -{ -} - -void -GEOM_FaceSource:: -AddFace(const TopoDS_Face& theFace) -{ - myFaceSet.Add(theFace); -} - -void -GEOM_FaceSource:: -MoveTo(gp_Pnt thePnt, - vtkPoints* thePts) -{ - thePts->InsertNextPoint(thePnt.X(), thePnt.Y(), thePnt.Z()); -} - -void -GEOM_FaceSource:: -DrawTo(gp_Pnt thePnt, - vtkPolyData* thePolyData, - vtkPoints* thePts) -{ - vtkIdType anId = - thePts->InsertNextPoint(thePnt.X(), thePnt.Y(), thePnt.Z()); - vtkIdType anIds[2] = {anId-1, anId}; - thePolyData->InsertNextCell(VTK_LINE,2,anIds); -} diff --git a/src/OBJECT/GEOM_FaceSource.h b/src/OBJECT/GEOM_FaceSource.h deleted file mode 100755 index 2fed7cb40..000000000 --- a/src/OBJECT/GEOM_FaceSource.h +++ /dev/null @@ -1,67 +0,0 @@ -// 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 GEOM_FACESOURCE_H -#define GEOM_FACESOURCE_H - -#include "GEOM_DeviceActor.h" - -#include -#include -#include - -typedef NCollection_Set TFaceSet; - -#include - -class GEOM_FaceSource; -typedef GEOM_SmartPtr PFaceSource; - - -class VTK_EXPORT GEOM_FaceSource: public vtkPolyDataSource -{ -public: - vtkTypeMacro(GEOM_FaceSource,vtkPolyDataSource); - - void AddFace(const TopoDS_Face& theFace); - void Clear(){ myFaceSet.Clear();} - bool IsEmpty(){return myFaceSet.IsEmpty();} - -protected: - TFaceSet myFaceSet; - - static - void MoveTo(gp_Pnt thePnt, - vtkPoints* thePts); - static - void DrawTo(gp_Pnt thePnt, - vtkPolyData* thePolyData, - vtkPoints* thePts); - - GEOM_FaceSource(); - ~GEOM_FaceSource(); - -private: - // Not implememnted - GEOM_FaceSource(const GEOM_FaceSource&); - void operator=(const GEOM_FaceSource&); -}; - - -#endif //GEOM_FACESOURCE_H diff --git a/src/OBJECT/GEOM_ShadingFace.cxx b/src/OBJECT/GEOM_ShadingFace.cxx deleted file mode 100755 index 704db5bdc..000000000 --- a/src/OBJECT/GEOM_ShadingFace.cxx +++ /dev/null @@ -1,103 +0,0 @@ -// 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 "GEOM_ShadingFace.h" - -#include - -#include -#include - -#include -#include - -#include -#include - - -vtkStandardNewMacro(GEOM_ShadingFace); - -GEOM_ShadingFace::GEOM_ShadingFace() -{ -} - -GEOM_ShadingFace::~GEOM_ShadingFace() -{ -} - -void -GEOM_ShadingFace:: -Execute() -{ - vtkPolyData* aPolyData = GetOutput(); - aPolyData->Allocate(); - vtkPoints* aPts = vtkPoints::New(); - aPolyData->SetPoints(aPts); - aPts->Delete(); - - TFaceSet::Iterator anIter(myFaceSet); - for(; anIter.More(); anIter.Next()){ - const TopoDS_Face& aFace = anIter.Value(); - OCC2VTK(aFace,aPolyData,aPts); - } -} - -void -GEOM_ShadingFace:: -OCC2VTK(const TopoDS_Face& theFace, - vtkPolyData* thePolyData, - vtkPoints* thePts) -{ - TopLoc_Location aLoc; - Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc); - if(aPoly.IsNull()) - return; - else{ - gp_Trsf myTransf; - Standard_Boolean identity = true; - if(!aLoc.IsIdentity()){ - identity = false; - myTransf = aLoc.Transformation(); - } - - Standard_Integer i; - int aNbOfNodes = thePts->GetNumberOfPoints(); - const TColgp_Array1OfPnt& Nodes = aPoly->Nodes(); - Standard_Integer nbNodesInFace = aPoly->NbNodes(); - for(i = 1; i <= nbNodesInFace; i++) { - gp_Pnt P = Nodes(i); - if(!identity) - P.Transform(myTransf); - thePts->InsertNextPoint(P.X(),P.Y(),P.Z()); - } - - const Poly_Array1OfTriangle& Triangles = aPoly->Triangles(); - Standard_Integer nbTriInFace = aPoly->NbTriangles(); - for(i = 1; i <= nbTriInFace; i++){ - // Get the triangle - Standard_Integer N1,N2,N3; - Triangles(i).Get(N1,N2,N3); - N1 += aNbOfNodes - 1; - N2 += aNbOfNodes - 1; - N3 += aNbOfNodes - 1; - vtkIdType anIds[3] = {N1, N2, N3}; - thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds); - } - } -} diff --git a/src/OBJECT/GEOM_ShadingFace.h b/src/OBJECT/GEOM_ShadingFace.h deleted file mode 100755 index ee1f7a924..000000000 --- a/src/OBJECT/GEOM_ShadingFace.h +++ /dev/null @@ -1,50 +0,0 @@ -// 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 GEOM_SHADINGFACE_H -#define GEOM_SHADINGFACE_H - -#include "GEOM_FaceSource.h" - - -class VTK_EXPORT GEOM_ShadingFace: public GEOM_FaceSource -{ -public: - vtkTypeMacro(GEOM_ShadingFace,GEOM_FaceSource); - static GEOM_ShadingFace* New(); - - static - void OCC2VTK(const TopoDS_Face& theFace, - vtkPolyData* theCells, - vtkPoints* thePts); - -protected: - void Execute(); - - GEOM_ShadingFace(); - ~GEOM_ShadingFace(); - -private: - // Not implememnted - GEOM_ShadingFace(const GEOM_ShadingFace&); - void operator=(const GEOM_ShadingFace&); -}; - - -#endif //GEOM_SHADINGFACE_H diff --git a/src/OBJECT/GEOM_VertexSource.cxx b/src/OBJECT/GEOM_VertexSource.cxx deleted file mode 100755 index c565896e6..000000000 --- a/src/OBJECT/GEOM_VertexSource.cxx +++ /dev/null @@ -1,75 +0,0 @@ -// 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 "GEOM_VertexSource.h" - -#include - -#include -#include -#include -#include - -#include -#include - -vtkStandardNewMacro(GEOM_VertexSource); - -GEOM_VertexSource::GEOM_VertexSource() -{ -} - -GEOM_VertexSource::~GEOM_VertexSource() -{ -} - -void -GEOM_VertexSource:: -AddVertex(const TopoDS_Vertex& theVertex) -{ - myVertexSet.Add(theVertex); -} - -void -GEOM_VertexSource:: -Execute() -{ - vtkPolyData* aPolyData = GetOutput(); - aPolyData->Allocate(); - vtkPoints* aPts = vtkPoints::New(); - aPolyData->SetPoints(aPts); - aPts->Delete(); - - TVertexSet::Iterator anIter(myVertexSet); - for(; anIter.More(); anIter.Next()){ - const TopoDS_Vertex& aVertex = anIter.Value(); - OCC2VTK(aVertex,aPolyData,aPts); - } -} - -void -GEOM_VertexSource:: -OCC2VTK(const TopoDS_Vertex& theVertex, - vtkPolyData* thePolyData, - vtkPoints* thePts) -{ - gp_Pnt aPnt = BRep_Tool::Pnt(theVertex); - vtkIdType anId = thePts->InsertNextPoint(aPnt.X(),aPnt.Y(),aPnt.Z()); - thePolyData->InsertNextCell(VTK_VERTEX,1,&anId); -} diff --git a/src/OBJECT/GEOM_VertexSource.h b/src/OBJECT/GEOM_VertexSource.h deleted file mode 100755 index 782c528a8..000000000 --- a/src/OBJECT/GEOM_VertexSource.h +++ /dev/null @@ -1,62 +0,0 @@ -// 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 GEOM_VERTEXSOURCE_H -#define GEOM_VERTEXSOURCE_H - -#include "GEOM_DeviceActor.h" - -#include -#include - -typedef NCollection_Set TVertexSet; - -#include - - -class VTK_EXPORT GEOM_VertexSource: public vtkPolyDataSource -{ -public: - vtkTypeMacro(GEOM_VertexSource,vtkPolyDataSource); - static GEOM_VertexSource* New(); - - void AddVertex(const TopoDS_Vertex& theVertex); - void Clear(){ myVertexSet.Clear();} - - static - void OCC2VTK(const TopoDS_Vertex& theVertex, - vtkPolyData* thePolyData, - vtkPoints* thePts); - -protected: - TVertexSet myVertexSet; - - void Execute(); - - GEOM_VertexSource(); - ~GEOM_VertexSource(); - -private: - // Not implememnted - GEOM_VertexSource(const GEOM_VertexSource&); - void operator=(const GEOM_VertexSource&); -}; - - -#endif //GEOM_VERTEXSOURCE_H diff --git a/src/OBJECT/GEOM_WireframeFace.cxx b/src/OBJECT/GEOM_WireframeFace.cxx deleted file mode 100755 index c3d3b4b59..000000000 --- a/src/OBJECT/GEOM_WireframeFace.cxx +++ /dev/null @@ -1,509 +0,0 @@ -// 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 "GEOM_WireframeFace.h" - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -vtkStandardNewMacro(GEOM_WireframeFace); - -GEOM_WireframeFace::GEOM_WireframeFace(): - Discret(15) -{ - NbIso[0] = 1; - NbIso[1] = 1; -} - -GEOM_WireframeFace::~GEOM_WireframeFace() -{ -} - -void -GEOM_WireframeFace:: -Execute() -{ - vtkPolyData* aPolyData = GetOutput(); - aPolyData->Allocate(); - vtkPoints* aPts = vtkPoints::New(); - aPolyData->SetPoints(aPts); - aPts->Delete(); - - TFaceSet::Iterator anIter(myFaceSet); - for(; anIter.More(); anIter.Next()){ - const TopoDS_Face& aFace = anIter.Value(); - OCC2VTK(aFace,aPolyData,aPts,NbIso,Discret); - } -} - -void GEOM_WireframeFace::SetNbIso(const int theNb[2]) -{ - if ( theNb[0] == NbIso[0] && theNb[1] == NbIso[1]) - return; - - NbIso[0] = theNb[0]; - NbIso[1] = theNb[1]; - - Modified(); -} - -void GEOM_WireframeFace::GetNbIso(int &theNbU,int &theNbV) -{ - theNbU = NbIso[0]; - theNbV = NbIso[1]; -} - -void -GEOM_WireframeFace:: -OCC2VTK(const TopoDS_Face& theFace, - vtkPolyData* thePolyData, - vtkPoints* thePts, - const int theNbIso[2], - const int theDiscret) -{ - TopoDS_Face aFace = theFace; - aFace.Orientation(TopAbs_FORWARD); - CreateIso(aFace,theNbIso,theDiscret,thePolyData,thePts); -} - -void -GEOM_WireframeFace:: -CreateIso(const TopoDS_Face& theFace, - const int theNbIso[2], - const int theDiscret, - vtkPolyData* thePolyData, - vtkPoints* thePts) -{ - // Constants for iso building - static Standard_Real INTERSECTOR_CONFUSION = 1.e-10 ; // -8 ; - static Standard_Real INTERSECTOR_TANGENCY = 1.e-10 ; // -8 ; - - static Standard_Real HATHCER_CONFUSION_2D = 1.e-8 ; - static Standard_Real HATHCER_CONFUSION_3D = 1.e-8 ; - - Geom2dHatch_Hatcher - aHatcher(Geom2dHatch_Intersector(INTERSECTOR_CONFUSION, - INTERSECTOR_TANGENCY), - HATHCER_CONFUSION_2D, - HATHCER_CONFUSION_3D, - Standard_True, - Standard_False); - - Standard_Real anUMin, anUMax, aVMin, aVMax; - TColStd_Array1OfReal anUPrm(1, theNbIso[0]), aVPrm(1, theNbIso[1]); - TColStd_Array1OfInteger anUInd(1, theNbIso[0]), aVInd(1, theNbIso[1]); - - anUInd.Init(0); - aVInd.Init(0); - - //----------------------------------------------------------------------- - // If the Min Max bounds are infinite, there are bounded to Infinite - // value. - //----------------------------------------------------------------------- - BRepTools::UVBounds(theFace, anUMin, anUMax, aVMin, aVMax) ; - Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (anUMin) ; - Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (anUMax) ; - Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (aVMin) ; - Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (aVMax) ; - - static float VTKINFINITE = 1.0E38; - if(InfiniteUMin && InfiniteUMax){ - anUMin = - VTKINFINITE ; - anUMax = VTKINFINITE ; - }else if(InfiniteUMin){ - anUMin = anUMax - VTKINFINITE ; - }else if(InfiniteUMax){ - anUMax = anUMin + VTKINFINITE ; - } - - if(InfiniteVMin && InfiniteVMax){ - aVMin = - VTKINFINITE ; - aVMax = VTKINFINITE ; - }else if(InfiniteVMin){ - aVMin = aVMax - VTKINFINITE ; - }else if(InfiniteVMax){ - aVMax = aVMin + VTKINFINITE ; - } - - //----------------------------------------------------------------------- - // Retreiving the edges and loading them into the hatcher. - //----------------------------------------------------------------------- - TopExp_Explorer ExpEdges(theFace, TopAbs_EDGE); - for(; ExpEdges.More(); ExpEdges.Next()){ - const TopoDS_Edge& anEdge = TopoDS::Edge(ExpEdges.Current()); - Standard_Real U1, U2 ; - const Handle(Geom2d_Curve) PCurve = - BRep_Tool::CurveOnSurface(anEdge, theFace, U1, U2) ; - - if(PCurve.IsNull() || U1 == U2) - return; - - //-- Test if a TrimmedCurve is necessary - if(Abs(PCurve->FirstParameter()-U1) <= Precision::PConfusion() && - Abs(PCurve->LastParameter()-U2) <= Precision::PConfusion()) - { - aHatcher.AddElement(PCurve, anEdge.Orientation()) ; - }else{ - if(!PCurve->IsPeriodic()){ - Handle(Geom2d_TrimmedCurve) TrimPCurve = - Handle(Geom2d_TrimmedCurve)::DownCast(PCurve); - if(!TrimPCurve.IsNull()){ - Handle_Geom2d_Curve aBasisCurve = TrimPCurve->BasisCurve(); - if(aBasisCurve->FirstParameter()-U1 > Precision::PConfusion() || - U2-aBasisCurve->LastParameter() > Precision::PConfusion()) - { - aHatcher.AddElement(PCurve, anEdge.Orientation()) ; - return; - } - }else{ - if(PCurve->FirstParameter()-U1 > Precision::PConfusion()){ - U1=PCurve->FirstParameter(); - } - if(U2-PCurve->LastParameter() > Precision::PConfusion()){ - U2=PCurve->LastParameter(); - } - } - } - Handle(Geom2d_TrimmedCurve) TrimPCurve = - new Geom2d_TrimmedCurve(PCurve, U1, U2); - aHatcher.AddElement(TrimPCurve, anEdge.Orientation()); - } - } - - - //----------------------------------------------------------------------- - // Loading and trimming the hatchings. - //----------------------------------------------------------------------- - Standard_Integer IIso; - Standard_Real DeltaU = Abs(anUMax - anUMin) ; - Standard_Real DeltaV = Abs(aVMax - aVMin) ; - Standard_Real confusion = Min(DeltaU, DeltaV) * HATHCER_CONFUSION_3D ; - aHatcher.Confusion3d (confusion) ; - - if ( theNbIso[0] ) { - Standard_Real StepU = DeltaU / (Standard_Real)theNbIso[0]; - if(StepU > confusion){ - Standard_Real UPrm = anUMin + StepU / 2.; - gp_Dir2d Dir(0., 1.) ; - for(IIso = 1 ; IIso <= theNbIso[0] ; IIso++) { - anUPrm(IIso) = UPrm ; - gp_Pnt2d Ori (UPrm, 0.) ; - Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ; - anUInd(IIso) = aHatcher.AddHatching (HCur) ; - UPrm += StepU ; - } - } - } - - if ( theNbIso[1] ) { - Standard_Real StepV = DeltaV / (Standard_Real) theNbIso[1] ; - if(StepV > confusion){ - Standard_Real VPrm = aVMin + StepV / 2.; - gp_Dir2d Dir(1., 0.); - for(IIso = 1 ; IIso <= theNbIso[1] ; IIso++){ - aVPrm(IIso) = VPrm; - gp_Pnt2d Ori (0., VPrm); - Geom2dAdaptor_Curve HCur(new Geom2d_Line (Ori, Dir)); - aVInd(IIso) = aHatcher.AddHatching (HCur) ; - VPrm += StepV ; - } - } - } - - //----------------------------------------------------------------------- - // Computation. - //----------------------------------------------------------------------- - aHatcher.Trim() ; - - Standard_Integer aNbDom = 0 ; // for debug purpose - Standard_Integer Index ; - - for(IIso = 1 ; IIso <= theNbIso[0] ; IIso++){ - Index = anUInd(IIso) ; - if(Index != 0){ - if(aHatcher.TrimDone(Index) && !aHatcher.TrimFailed(Index)){ - aHatcher.ComputeDomains(Index); - if(aHatcher.IsDone (Index)) - aNbDom = aHatcher.NbDomains (Index); - } - } - } - - for(IIso = 1 ; IIso <= theNbIso[1] ; IIso++){ - Index = aVInd(IIso); - if(Index != 0){ - if(aHatcher.TrimDone (Index) && !aHatcher.TrimFailed(Index)){ - aHatcher.ComputeDomains (Index); - if(aHatcher.IsDone (Index)) - aNbDom = aHatcher.NbDomains (Index); - } - } - } - - //----------------------------------------------------------------------- - // Push iso lines in vtk kernel - //----------------------------------------------------------------------- - for(Standard_Integer UIso = anUPrm.Lower() ; UIso <= anUPrm.Upper(); UIso++){ - Standard_Integer UInd = anUInd.Value(UIso); - if(UInd != 0){ - Standard_Real UPrm = anUPrm.Value(UIso); - if(aHatcher.IsDone(UInd)){ - Standard_Integer NbDom = aHatcher.NbDomains(UInd); - for(Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++){ - const HatchGen_Domain& Dom = aHatcher.Domain(UInd, IDom) ; - Standard_Real V1 = Dom.HasFirstPoint()? Dom.FirstPoint().Parameter(): aVMin - VTKINFINITE; - Standard_Real V2 = Dom.HasSecondPoint()? Dom.SecondPoint().Parameter(): aVMax + VTKINFINITE; - CreateIso_(theFace, GeomAbs_IsoU, UPrm, V1, V2, theDiscret, thePolyData, thePts); - } - } - } - } - - for(Standard_Integer VIso = aVPrm.Lower() ; VIso <= aVPrm.Upper(); VIso++){ - Standard_Integer VInd = aVInd.Value(VIso); - if(VInd != 0){ - Standard_Real VPrm = aVPrm.Value(VIso); - if(aHatcher.IsDone (VInd)){ - Standard_Integer NbDom = aHatcher.NbDomains(VInd); - for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++){ - const HatchGen_Domain& Dom = aHatcher.Domain(VInd, IDom); - Standard_Real U1 = Dom.HasFirstPoint()? Dom.FirstPoint().Parameter(): aVMin - VTKINFINITE; - Standard_Real U2 = Dom.HasSecondPoint()? Dom.SecondPoint().Parameter(): aVMax + VTKINFINITE; - CreateIso_(theFace, GeomAbs_IsoV, VPrm, U1, U2, theDiscret, thePolyData, thePts); - } - } - } - } -} - - - -void -GEOM_WireframeFace:: -CreateIso_(const TopoDS_Face& theFace, - GeomAbs_IsoType theIsoType, - Standard_Real Par, - Standard_Real T1, - Standard_Real T2, - const int theDiscret, - vtkPolyData* thePolyData, - vtkPoints* thePts) -{ - Standard_Real U1, U2, V1, V2, stepU=0., stepV=0.; - Standard_Integer j; - gp_Pnt P; - - TopLoc_Location aLoc; - const Handle(Geom_Surface)& S = BRep_Tool::Surface(theFace,aLoc); - - if(!S.IsNull()){ - BRepAdaptor_Surface S(theFace,Standard_False); - - GeomAbs_SurfaceType SurfType = S.GetType(); - - GeomAbs_CurveType CurvType = GeomAbs_OtherCurve; - - Standard_Integer Intrv, nbIntv; - Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN); - Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN); - TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1); - - if(theIsoType == GeomAbs_IsoU){ - S.VIntervals(TI, GeomAbs_CN); - V1 = Max(T1, TI(1)); - V2 = Min(T2, TI(2)); - U1 = Par; - U2 = Par; - stepU = 0; - nbIntv = nbVIntv; - }else{ - S.UIntervals(TI, GeomAbs_CN); - U1 = Max(T1, TI(1)); - U2 = Min(T2, TI(2)); - V1 = Par; - V2 = Par; - stepV = 0; - nbIntv = nbUIntv; - } - - S.D0(U1,V1,P); - MoveTo(P,thePts); - - for(Intrv = 1; Intrv <= nbIntv; Intrv++){ - if(TI(Intrv) <= T1 && TI(Intrv + 1) <= T1) - continue; - if(TI(Intrv) >= T2 && TI(Intrv + 1) >= T2) - continue; - if(theIsoType == GeomAbs_IsoU){ - V1 = Max(T1, TI(Intrv)); - V2 = Min(T2, TI(Intrv + 1)); - stepV = (V2 - V1) / theDiscret; - }else{ - U1 = Max(T1, TI(Intrv)); - U2 = Min(T2, TI(Intrv + 1)); - stepU = (U2 - U1) / theDiscret; - } - - switch (SurfType) { - case GeomAbs_Plane : - break; - case GeomAbs_Cylinder : - case GeomAbs_Cone : - if(theIsoType == GeomAbs_IsoV){ - for(j = 1; j < theDiscret; j++){ - U1 += stepU; - V1 += stepV; - S.D0(U1,V1,P); - DrawTo(P,thePolyData,thePts); - } - } - break; - case GeomAbs_Sphere : - case GeomAbs_Torus : - case GeomAbs_OffsetSurface : - case GeomAbs_OtherSurface : - for(j = 1; j < theDiscret; j++){ - U1 += stepU; - V1 += stepV; - S.D0(U1,V1,P); - DrawTo(P,thePolyData,thePts); - } - break; - case GeomAbs_BezierSurface : - case GeomAbs_BSplineSurface : - for(j = 1; j <= theDiscret/2; j++){ - Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.; - CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts); - U1 += stepU*2.; - V1 += stepV*2.; - } - break; - case GeomAbs_SurfaceOfExtrusion : - case GeomAbs_SurfaceOfRevolution : - if((theIsoType == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) || - (theIsoType == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) - { - if(SurfType == GeomAbs_SurfaceOfExtrusion) - break; - for(j = 1; j < theDiscret; j++){ - U1 += stepU; - V1 += stepV; - S.D0(U1,V1,P); - DrawTo(P,thePolyData,thePts); - } - }else{ - CurvType = (S.BasisCurve())->GetType(); - switch(CurvType){ - case GeomAbs_Line : - break; - case GeomAbs_Circle : - case GeomAbs_Ellipse : - for (j = 1; j < theDiscret; j++) { - U1 += stepU; - V1 += stepV; - S.D0(U1,V1,P); - DrawTo(P,thePolyData,thePts); - } - break; - case GeomAbs_Parabola : - case GeomAbs_Hyperbola : - case GeomAbs_BezierCurve : - case GeomAbs_BSplineCurve : - case GeomAbs_OtherCurve : - for(j = 1; j <= theDiscret/2; j++){ - Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.; - CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts); - U1 += stepU*2.; - V1 += stepV*2.; - } - break; - } - } - } - } - S.D0(U2,V2,P); - DrawTo(P,thePolyData,thePts); - } -} - - - - -void -GEOM_WireframeFace:: -CreateIso__(const BRepAdaptor_Surface& theSurface, - GeomAbs_IsoType theIsoType, - Standard_Real& theU, - Standard_Real& theV, - Standard_Real theStep, - vtkPolyData* thePolyData, - vtkPoints* thePts) -{ - gp_Pnt Pl, Pr, Pm; - if (theIsoType == GeomAbs_IsoU) { - theSurface.D0(theU, theV, Pl); - theSurface.D0(theU, theV + theStep/2., Pm); - theSurface.D0(theU, theV + theStep, Pr); - } else { - theSurface.D0(theU, theV, Pl); - theSurface.D0(theU + theStep/2., theV, Pm); - theSurface.D0(theU + theStep, theV, Pr); - } - - static Standard_Real ISO_RATIO = 1.001; - if (Pm.Distance(Pl) + Pm.Distance(Pr) <= ISO_RATIO*Pl.Distance(Pr)) { - DrawTo(Pr,thePolyData,thePts); - } else { - if (theIsoType == GeomAbs_IsoU) { - CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts); - Standard_Real aLocalV = theV + theStep/2 ; - CreateIso__(theSurface, theIsoType, theU, aLocalV , theStep/2, thePolyData, thePts); - } else { - CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts); - Standard_Real aLocalU = theU + theStep/2 ; - CreateIso__(theSurface, theIsoType, aLocalU , theV, theStep/2, thePolyData, thePts); - } - } -} diff --git a/src/OBJECT/GEOM_WireframeFace.h b/src/OBJECT/GEOM_WireframeFace.h deleted file mode 100755 index d34bf9652..000000000 --- a/src/OBJECT/GEOM_WireframeFace.h +++ /dev/null @@ -1,100 +0,0 @@ -// 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 GEOM_WIREFRAME_FACE_H -#define GEOM_WIREFRAME_FACE_H - -#include "GEOM_FaceSource.h" - -#include -#include - -#include - - -class VTK_EXPORT GEOM_WireframeFace: public GEOM_FaceSource -{ -public: - vtkTypeMacro(GEOM_WireframeFace,GEOM_FaceSource); - static GEOM_WireframeFace* New(); - - /* vtkSetMacro(NbIso,int); - vtkGetMacro(NbIso,int);*/ - - vtkSetMacro(Discret,int); - vtkGetMacro(Discret,int); - - static - void OCC2VTK(const TopoDS_Face& theFace, - vtkPolyData* thePolyData, - vtkPoints* thePts, - const int theNbIso[2], - const int theDiscret = 15); - - //! IsoLines management - // theNb[0] - number of U lines - // theNb[1] - number of V lines - virtual void SetNbIso(const int theNb[2]); - virtual void GetNbIso(int &theNbU,int &theNbV); - -protected: - int NbIso[2], Discret; - - static - void - CreateIso(const TopoDS_Face& theFace, - const int theNbIso[2], - const int theDiscret, - vtkPolyData* thePolyData, - vtkPoints* thePts); - - static - void - CreateIso_(const TopoDS_Face& theFace, - GeomAbs_IsoType theIsoType, - Standard_Real Par, - Standard_Real T1, - Standard_Real T2, - const int theDiscret, - vtkPolyData* thePolyData, - vtkPoints* thePts); - - static - void - CreateIso__(const BRepAdaptor_Surface& theSurface, - GeomAbs_IsoType theIsoType, - Standard_Real& theU, - Standard_Real& theV, - Standard_Real theStep, - vtkPolyData* thePolyData, - vtkPoints* thePts); - - void Execute(); - - GEOM_WireframeFace(); - ~GEOM_WireframeFace(); - -private: - // Not implememnted - GEOM_WireframeFace(const GEOM_WireframeFace&); - void operator=(const GEOM_WireframeFace&); -}; - - -#endif //GEOM_WFACEACTOR_H 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/OCC2VTK/GEOM_EdgeSource.cxx b/src/OCC2VTK/GEOM_EdgeSource.cxx new file mode 100755 index 000000000..e44cc81e0 --- /dev/null +++ b/src/OCC2VTK/GEOM_EdgeSource.cxx @@ -0,0 +1,272 @@ +// 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 "GEOM_EdgeSource.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +vtkStandardNewMacro(GEOM_EdgeSource); + +GEOM_EdgeSource::GEOM_EdgeSource() : + myIsVector(false) +{ +} + +GEOM_EdgeSource::~GEOM_EdgeSource() +{ +} + +void GEOM_EdgeSource::AddEdge (const TopoDS_Edge& theEdge, + bool theIsVector) +{ + myEdgeSet.Add(theEdge); + myIsVector = theIsVector; +} + +void +GEOM_EdgeSource:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TEdgeSet::Iterator anIter (myEdgeSet); + for (; anIter.More(); anIter.Next()) { + const TopoDS_Edge& anEdge = anIter.Value(); + OCC2VTK(anEdge,aPolyData,aPts,myIsVector); + } +} + +void GEOM_EdgeSource::OCC2VTK (const TopoDS_Edge& theEdge, + vtkPolyData* thePolyData, + vtkPoints* thePts, + bool theIsVector) +{ + Handle(Poly_PolygonOnTriangulation) aEdgePoly; + Standard_Integer i = 1; + Handle(Poly_Triangulation) T; + TopLoc_Location aEdgeLoc; + BRep_Tool::PolygonOnTriangulation(theEdge, aEdgePoly, T, aEdgeLoc, i); + + Handle(Poly_Polygon3D) P; + if(aEdgePoly.IsNull()) + P = BRep_Tool::Polygon3D(theEdge, aEdgeLoc); + + if(P.IsNull() && aEdgePoly.IsNull()) + return; + + // Location edges + //--------------- + gp_Trsf edgeTransf; + Standard_Boolean isidtrsf = true; + if(!aEdgeLoc.IsIdentity()) { + isidtrsf = false; + edgeTransf = aEdgeLoc.Transformation(); + } + + gp_Pnt aP1, aP2; + + if (aEdgePoly.IsNull()) { + Standard_Integer aNbNodes = P->NbNodes(); + const TColgp_Array1OfPnt& aNodesP = P->Nodes(); + + aP1 = aNodesP(1); + aP2 = aNodesP(aNbNodes); + + for (int j = 1; j < aNbNodes; j++) { + gp_Pnt pt1 = aNodesP(j); + gp_Pnt pt2 = aNodesP(j+1); + + if (!isidtrsf) { + // apply edge transformation + pt1.Transform(edgeTransf); + pt2.Transform(edgeTransf); + } + + float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()}; + vtkIdType anIds[2]; + anIds[0] = thePts->InsertNextPoint(aCoord1); + + float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()}; + anIds[1] = thePts->InsertNextPoint(aCoord2); + + thePolyData->InsertNextCell(VTK_LINE,2,anIds); + } + } else { + Standard_Integer aNbNodes = aEdgePoly->NbNodes(); + const TColStd_Array1OfInteger& aNodeIds = aEdgePoly->Nodes(); + const TColgp_Array1OfPnt& anId2Pnts = T->Nodes(); + + aP1 = anId2Pnts(aNodeIds(1)); + aP2 = anId2Pnts(aNodeIds(aNbNodes)); + + for(int j = 1; j < aNbNodes; j++) { + Standard_Integer id1 = aNodeIds(j); + Standard_Integer id2 = aNodeIds(j+1); + + gp_Pnt pt1 = anId2Pnts(id1); + gp_Pnt pt2 = anId2Pnts(id2); + + if(!isidtrsf) { + // apply edge transformation + pt1.Transform(edgeTransf); + pt2.Transform(edgeTransf); + } + + float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()}; + vtkIdType anIds[2]; + anIds[0] = thePts->InsertNextPoint(aCoord1); + + float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()}; + anIds[1] = thePts->InsertNextPoint(aCoord2); + + thePolyData->InsertNextCell(VTK_LINE,2,anIds); + } + } + + + // vector representation has an arrow on its end + if (theIsVector) + { + if (!isidtrsf) { + // apply edge transformation + aP1.Transform(edgeTransf); + aP2.Transform(edgeTransf); + } + + // draw an arrow + + double fp,lp; + gp_Vec aDirVec; + Handle(Geom_Curve) C = BRep_Tool::Curve(theEdge,fp,lp); + if ( theEdge.Orientation() == TopAbs_FORWARD ) { + C->D1(lp, aP2, aDirVec); + } else { + C->D1(fp, aP1, aDirVec); + aP2 = aP1; + } + + GeomAdaptor_Curve aAdC; + aAdC.Load(C, fp, lp); + Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp); + if (aDist < gp::Resolution()) return; + + gp_Dir aDirection; + + if ( theEdge.Orientation() == TopAbs_FORWARD ) + aDirection = aDirVec; + else + aDirection = -aDirVec; + + Standard_Real anAngle = PI/180.*5.; + Standard_Real aLength = aDist/10.; + + Standard_Real dx,dy,dz; + aDirection.Coord(dx,dy,dz); + + // Arrow Point + Standard_Real xo,yo,zo; + aP2.Coord(xo,yo,zo); + + // Center of circle that arrow based + gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength; + + // Construction of the base vectors for the arrow circle + gp_Dir aDirN; + if (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX(); + else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY(); + else aDirN = gp::DZ(); + + gp_Dir aDirI = aDirection ^ aDirN; + gp_Dir aDirJ = aDirection ^ aDirI; + + // Add points and segments, composing the arrow + Standard_Real cosinus, sinus, Tg = tan(anAngle); + + float coord[3] = {xo, yo, zo}; + + vtkIdType ptLoc = thePts->InsertNextPoint(coord); + vtkIdType ptFirst = 0; + vtkIdType ptPrev = 0; + vtkIdType ptCur = 0; + + vtkIdType pts[2]; + + int NbPoints = 15; + for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur) + { + cosinus = cos(2. * PI / NbPoints * (i-1)); + sinus = sin(2. * PI / NbPoints * (i-1)); + + gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg; + coord[0] = aP.X(); + coord[1] = aP.Y(); + coord[2] = aP.Z(); + + // insert pts + ptCur = thePts->InsertNextPoint(coord); + pts[0] = ptCur; + + if (i == 1) { + ptFirst = ptCur; + } + else { + // insert line (ptCur,ptPrev) + pts[1] = ptPrev; + thePolyData->InsertNextCell(VTK_LINE,2,pts); + } + + // insert line (ptCur,ptLoc) + pts[1] = ptLoc; + thePolyData->InsertNextCell(VTK_LINE,2,pts); + } + + // insert line (ptCur,ptFirst) + pts[0] = ptCur; + pts[1] = ptFirst; + thePolyData->InsertNextCell(VTK_LINE,2,pts); + } +} + +void GEOM_EdgeSource::SetVectorMode (bool theMode) +{ + myIsVector = theMode; +} + +bool GEOM_EdgeSource::GetVectorMode () +{ + return myIsVector; +} diff --git a/src/OCC2VTK/GEOM_EdgeSource.h b/src/OCC2VTK/GEOM_EdgeSource.h new file mode 100755 index 000000000..9ef08683f --- /dev/null +++ b/src/OCC2VTK/GEOM_EdgeSource.h @@ -0,0 +1,74 @@ +// 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 GEOM_EDGESOURCE_H +#define GEOM_EDGESOURCE_H + +#include "OCC2VTK.h" + +#include +#include + +typedef NCollection_Set TEdgeSet; + +#include +#include + +class OCC2VTK_EXPORT GEOM_EdgeSource: public vtkPolyDataSource +{ +public: + vtkTypeMacro(GEOM_EdgeSource,vtkPolyDataSource); + static GEOM_EdgeSource* New(); + + void AddEdge (const TopoDS_Edge& theEdge, + bool theIsVector = false); + void Clear(){ myEdgeSet.Clear();} + + void SetVectorMode(bool); + + bool GetVectorMode(); + + static + void OCC2VTK(const TopoDS_Edge& theEdge, + vtkPolyData* thePolyData, + vtkPoints* thePts, + bool theIsVector = false); + + bool IsEmpty(){return myEdgeSet.IsEmpty();} + + +protected: + TEdgeSet myEdgeSet; + // The flag is common for all edges, because the shape, + // representing a vector, can have only one edge. + bool myIsVector; + + void Execute(); + + GEOM_EdgeSource(); + ~GEOM_EdgeSource(); + +private: + // Not implememnted + GEOM_EdgeSource(const GEOM_EdgeSource&); + void operator=(const GEOM_EdgeSource&); +}; + + +#endif //GEOM_EDGESOURCE_H diff --git a/src/OCC2VTK/GEOM_FaceSource.cxx b/src/OCC2VTK/GEOM_FaceSource.cxx new file mode 100755 index 000000000..7035ef85e --- /dev/null +++ b/src/OCC2VTK/GEOM_FaceSource.cxx @@ -0,0 +1,63 @@ +// 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 "GEOM_FaceSource.h" + +#include + +#include +#include + +#include +#include + +GEOM_FaceSource::GEOM_FaceSource() +{ +} + +GEOM_FaceSource::~GEOM_FaceSource() +{ +} + +void +GEOM_FaceSource:: +AddFace(const TopoDS_Face& theFace) +{ + myFaceSet.Add(theFace); +} + +void +GEOM_FaceSource:: +MoveTo(gp_Pnt thePnt, + vtkPoints* thePts) +{ + thePts->InsertNextPoint(thePnt.X(), thePnt.Y(), thePnt.Z()); +} + +void +GEOM_FaceSource:: +DrawTo(gp_Pnt thePnt, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + vtkIdType anId = + thePts->InsertNextPoint(thePnt.X(), thePnt.Y(), thePnt.Z()); + vtkIdType anIds[2] = {anId-1, anId}; + thePolyData->InsertNextCell(VTK_LINE,2,anIds); +} diff --git a/src/OCC2VTK/GEOM_FaceSource.h b/src/OCC2VTK/GEOM_FaceSource.h new file mode 100755 index 000000000..555dcdeb1 --- /dev/null +++ b/src/OCC2VTK/GEOM_FaceSource.h @@ -0,0 +1,64 @@ +// 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 GEOM_FACESOURCE_H +#define GEOM_FACESOURCE_H + +#include "OCC2VTK.h" + +#include +#include +#include + +typedef NCollection_Set TFaceSet; + +#include +#include + +class OCC2VTK_EXPORT GEOM_FaceSource: public vtkPolyDataSource +{ +public: + vtkTypeMacro(GEOM_FaceSource,vtkPolyDataSource); + + void AddFace(const TopoDS_Face& theFace); + void Clear(){ myFaceSet.Clear();} + bool IsEmpty(){return myFaceSet.IsEmpty();} + +protected: + TFaceSet myFaceSet; + + static + void MoveTo(gp_Pnt thePnt, + vtkPoints* thePts); + static + void DrawTo(gp_Pnt thePnt, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + GEOM_FaceSource(); + ~GEOM_FaceSource(); + +private: + // Not implememnted + GEOM_FaceSource(const GEOM_FaceSource&); + void operator=(const GEOM_FaceSource&); +}; + + +#endif //GEOM_FACESOURCE_H diff --git a/src/OCC2VTK/GEOM_ShadingFace.cxx b/src/OCC2VTK/GEOM_ShadingFace.cxx new file mode 100755 index 000000000..704db5bdc --- /dev/null +++ b/src/OCC2VTK/GEOM_ShadingFace.cxx @@ -0,0 +1,103 @@ +// 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 "GEOM_ShadingFace.h" + +#include + +#include +#include + +#include +#include + +#include +#include + + +vtkStandardNewMacro(GEOM_ShadingFace); + +GEOM_ShadingFace::GEOM_ShadingFace() +{ +} + +GEOM_ShadingFace::~GEOM_ShadingFace() +{ +} + +void +GEOM_ShadingFace:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TFaceSet::Iterator anIter(myFaceSet); + for(; anIter.More(); anIter.Next()){ + const TopoDS_Face& aFace = anIter.Value(); + OCC2VTK(aFace,aPolyData,aPts); + } +} + +void +GEOM_ShadingFace:: +OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + TopLoc_Location aLoc; + Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc); + if(aPoly.IsNull()) + return; + else{ + gp_Trsf myTransf; + Standard_Boolean identity = true; + if(!aLoc.IsIdentity()){ + identity = false; + myTransf = aLoc.Transformation(); + } + + Standard_Integer i; + int aNbOfNodes = thePts->GetNumberOfPoints(); + const TColgp_Array1OfPnt& Nodes = aPoly->Nodes(); + Standard_Integer nbNodesInFace = aPoly->NbNodes(); + for(i = 1; i <= nbNodesInFace; i++) { + gp_Pnt P = Nodes(i); + if(!identity) + P.Transform(myTransf); + thePts->InsertNextPoint(P.X(),P.Y(),P.Z()); + } + + const Poly_Array1OfTriangle& Triangles = aPoly->Triangles(); + Standard_Integer nbTriInFace = aPoly->NbTriangles(); + for(i = 1; i <= nbTriInFace; i++){ + // Get the triangle + Standard_Integer N1,N2,N3; + Triangles(i).Get(N1,N2,N3); + N1 += aNbOfNodes - 1; + N2 += aNbOfNodes - 1; + N3 += aNbOfNodes - 1; + vtkIdType anIds[3] = {N1, N2, N3}; + thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds); + } + } +} diff --git a/src/OCC2VTK/GEOM_ShadingFace.h b/src/OCC2VTK/GEOM_ShadingFace.h new file mode 100755 index 000000000..2af0254ae --- /dev/null +++ b/src/OCC2VTK/GEOM_ShadingFace.h @@ -0,0 +1,50 @@ +// 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 GEOM_SHADINGFACE_H +#define GEOM_SHADINGFACE_H + +#include "OCC2VTK.h" +#include "GEOM_FaceSource.h" + +class OCC2VTK_EXPORT GEOM_ShadingFace: public GEOM_FaceSource +{ +public: + vtkTypeMacro(GEOM_ShadingFace,GEOM_FaceSource); + static GEOM_ShadingFace* New(); + + static + void OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* theCells, + vtkPoints* thePts); + +protected: + void Execute(); + + GEOM_ShadingFace(); + ~GEOM_ShadingFace(); + +private: + // Not implememnted + GEOM_ShadingFace(const GEOM_ShadingFace&); + void operator=(const GEOM_ShadingFace&); +}; + + +#endif //GEOM_SHADINGFACE_H diff --git a/src/OCC2VTK/GEOM_VertexSource.cxx b/src/OCC2VTK/GEOM_VertexSource.cxx new file mode 100755 index 000000000..c565896e6 --- /dev/null +++ b/src/OCC2VTK/GEOM_VertexSource.cxx @@ -0,0 +1,75 @@ +// 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 "GEOM_VertexSource.h" + +#include + +#include +#include +#include +#include + +#include +#include + +vtkStandardNewMacro(GEOM_VertexSource); + +GEOM_VertexSource::GEOM_VertexSource() +{ +} + +GEOM_VertexSource::~GEOM_VertexSource() +{ +} + +void +GEOM_VertexSource:: +AddVertex(const TopoDS_Vertex& theVertex) +{ + myVertexSet.Add(theVertex); +} + +void +GEOM_VertexSource:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TVertexSet::Iterator anIter(myVertexSet); + for(; anIter.More(); anIter.Next()){ + const TopoDS_Vertex& aVertex = anIter.Value(); + OCC2VTK(aVertex,aPolyData,aPts); + } +} + +void +GEOM_VertexSource:: +OCC2VTK(const TopoDS_Vertex& theVertex, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + gp_Pnt aPnt = BRep_Tool::Pnt(theVertex); + vtkIdType anId = thePts->InsertNextPoint(aPnt.X(),aPnt.Y(),aPnt.Z()); + thePolyData->InsertNextCell(VTK_VERTEX,1,&anId); +} diff --git a/src/OCC2VTK/GEOM_VertexSource.h b/src/OCC2VTK/GEOM_VertexSource.h new file mode 100755 index 000000000..612e11237 --- /dev/null +++ b/src/OCC2VTK/GEOM_VertexSource.h @@ -0,0 +1,62 @@ +// 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 GEOM_VERTEXSOURCE_H +#define GEOM_VERTEXSOURCE_H + +#include "OCC2VTK.h" + +#include +#include + +typedef NCollection_Set TVertexSet; + +#include +#include + +class OCC2VTK_EXPORT GEOM_VertexSource: public vtkPolyDataSource +{ +public: + vtkTypeMacro(GEOM_VertexSource,vtkPolyDataSource); + static GEOM_VertexSource* New(); + + void AddVertex(const TopoDS_Vertex& theVertex); + void Clear(){ myVertexSet.Clear();} + + static + void OCC2VTK(const TopoDS_Vertex& theVertex, + vtkPolyData* thePolyData, + vtkPoints* thePts); + +protected: + TVertexSet myVertexSet; + + void Execute(); + + GEOM_VertexSource(); + ~GEOM_VertexSource(); + +private: + // Not implememnted + GEOM_VertexSource(const GEOM_VertexSource&); + void operator=(const GEOM_VertexSource&); +}; + + +#endif //GEOM_VERTEXSOURCE_H diff --git a/src/OCC2VTK/GEOM_WireframeFace.cxx b/src/OCC2VTK/GEOM_WireframeFace.cxx new file mode 100755 index 000000000..c3d3b4b59 --- /dev/null +++ b/src/OCC2VTK/GEOM_WireframeFace.cxx @@ -0,0 +1,509 @@ +// 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 "GEOM_WireframeFace.h" + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +vtkStandardNewMacro(GEOM_WireframeFace); + +GEOM_WireframeFace::GEOM_WireframeFace(): + Discret(15) +{ + NbIso[0] = 1; + NbIso[1] = 1; +} + +GEOM_WireframeFace::~GEOM_WireframeFace() +{ +} + +void +GEOM_WireframeFace:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TFaceSet::Iterator anIter(myFaceSet); + for(; anIter.More(); anIter.Next()){ + const TopoDS_Face& aFace = anIter.Value(); + OCC2VTK(aFace,aPolyData,aPts,NbIso,Discret); + } +} + +void GEOM_WireframeFace::SetNbIso(const int theNb[2]) +{ + if ( theNb[0] == NbIso[0] && theNb[1] == NbIso[1]) + return; + + NbIso[0] = theNb[0]; + NbIso[1] = theNb[1]; + + Modified(); +} + +void GEOM_WireframeFace::GetNbIso(int &theNbU,int &theNbV) +{ + theNbU = NbIso[0]; + theNbV = NbIso[1]; +} + +void +GEOM_WireframeFace:: +OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* thePolyData, + vtkPoints* thePts, + const int theNbIso[2], + const int theDiscret) +{ + TopoDS_Face aFace = theFace; + aFace.Orientation(TopAbs_FORWARD); + CreateIso(aFace,theNbIso,theDiscret,thePolyData,thePts); +} + +void +GEOM_WireframeFace:: +CreateIso(const TopoDS_Face& theFace, + const int theNbIso[2], + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + // Constants for iso building + static Standard_Real INTERSECTOR_CONFUSION = 1.e-10 ; // -8 ; + static Standard_Real INTERSECTOR_TANGENCY = 1.e-10 ; // -8 ; + + static Standard_Real HATHCER_CONFUSION_2D = 1.e-8 ; + static Standard_Real HATHCER_CONFUSION_3D = 1.e-8 ; + + Geom2dHatch_Hatcher + aHatcher(Geom2dHatch_Intersector(INTERSECTOR_CONFUSION, + INTERSECTOR_TANGENCY), + HATHCER_CONFUSION_2D, + HATHCER_CONFUSION_3D, + Standard_True, + Standard_False); + + Standard_Real anUMin, anUMax, aVMin, aVMax; + TColStd_Array1OfReal anUPrm(1, theNbIso[0]), aVPrm(1, theNbIso[1]); + TColStd_Array1OfInteger anUInd(1, theNbIso[0]), aVInd(1, theNbIso[1]); + + anUInd.Init(0); + aVInd.Init(0); + + //----------------------------------------------------------------------- + // If the Min Max bounds are infinite, there are bounded to Infinite + // value. + //----------------------------------------------------------------------- + BRepTools::UVBounds(theFace, anUMin, anUMax, aVMin, aVMax) ; + Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (anUMin) ; + Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (anUMax) ; + Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (aVMin) ; + Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (aVMax) ; + + static float VTKINFINITE = 1.0E38; + if(InfiniteUMin && InfiniteUMax){ + anUMin = - VTKINFINITE ; + anUMax = VTKINFINITE ; + }else if(InfiniteUMin){ + anUMin = anUMax - VTKINFINITE ; + }else if(InfiniteUMax){ + anUMax = anUMin + VTKINFINITE ; + } + + if(InfiniteVMin && InfiniteVMax){ + aVMin = - VTKINFINITE ; + aVMax = VTKINFINITE ; + }else if(InfiniteVMin){ + aVMin = aVMax - VTKINFINITE ; + }else if(InfiniteVMax){ + aVMax = aVMin + VTKINFINITE ; + } + + //----------------------------------------------------------------------- + // Retreiving the edges and loading them into the hatcher. + //----------------------------------------------------------------------- + TopExp_Explorer ExpEdges(theFace, TopAbs_EDGE); + for(; ExpEdges.More(); ExpEdges.Next()){ + const TopoDS_Edge& anEdge = TopoDS::Edge(ExpEdges.Current()); + Standard_Real U1, U2 ; + const Handle(Geom2d_Curve) PCurve = + BRep_Tool::CurveOnSurface(anEdge, theFace, U1, U2) ; + + if(PCurve.IsNull() || U1 == U2) + return; + + //-- Test if a TrimmedCurve is necessary + if(Abs(PCurve->FirstParameter()-U1) <= Precision::PConfusion() && + Abs(PCurve->LastParameter()-U2) <= Precision::PConfusion()) + { + aHatcher.AddElement(PCurve, anEdge.Orientation()) ; + }else{ + if(!PCurve->IsPeriodic()){ + Handle(Geom2d_TrimmedCurve) TrimPCurve = + Handle(Geom2d_TrimmedCurve)::DownCast(PCurve); + if(!TrimPCurve.IsNull()){ + Handle_Geom2d_Curve aBasisCurve = TrimPCurve->BasisCurve(); + if(aBasisCurve->FirstParameter()-U1 > Precision::PConfusion() || + U2-aBasisCurve->LastParameter() > Precision::PConfusion()) + { + aHatcher.AddElement(PCurve, anEdge.Orientation()) ; + return; + } + }else{ + if(PCurve->FirstParameter()-U1 > Precision::PConfusion()){ + U1=PCurve->FirstParameter(); + } + if(U2-PCurve->LastParameter() > Precision::PConfusion()){ + U2=PCurve->LastParameter(); + } + } + } + Handle(Geom2d_TrimmedCurve) TrimPCurve = + new Geom2d_TrimmedCurve(PCurve, U1, U2); + aHatcher.AddElement(TrimPCurve, anEdge.Orientation()); + } + } + + + //----------------------------------------------------------------------- + // Loading and trimming the hatchings. + //----------------------------------------------------------------------- + Standard_Integer IIso; + Standard_Real DeltaU = Abs(anUMax - anUMin) ; + Standard_Real DeltaV = Abs(aVMax - aVMin) ; + Standard_Real confusion = Min(DeltaU, DeltaV) * HATHCER_CONFUSION_3D ; + aHatcher.Confusion3d (confusion) ; + + if ( theNbIso[0] ) { + Standard_Real StepU = DeltaU / (Standard_Real)theNbIso[0]; + if(StepU > confusion){ + Standard_Real UPrm = anUMin + StepU / 2.; + gp_Dir2d Dir(0., 1.) ; + for(IIso = 1 ; IIso <= theNbIso[0] ; IIso++) { + anUPrm(IIso) = UPrm ; + gp_Pnt2d Ori (UPrm, 0.) ; + Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ; + anUInd(IIso) = aHatcher.AddHatching (HCur) ; + UPrm += StepU ; + } + } + } + + if ( theNbIso[1] ) { + Standard_Real StepV = DeltaV / (Standard_Real) theNbIso[1] ; + if(StepV > confusion){ + Standard_Real VPrm = aVMin + StepV / 2.; + gp_Dir2d Dir(1., 0.); + for(IIso = 1 ; IIso <= theNbIso[1] ; IIso++){ + aVPrm(IIso) = VPrm; + gp_Pnt2d Ori (0., VPrm); + Geom2dAdaptor_Curve HCur(new Geom2d_Line (Ori, Dir)); + aVInd(IIso) = aHatcher.AddHatching (HCur) ; + VPrm += StepV ; + } + } + } + + //----------------------------------------------------------------------- + // Computation. + //----------------------------------------------------------------------- + aHatcher.Trim() ; + + Standard_Integer aNbDom = 0 ; // for debug purpose + Standard_Integer Index ; + + for(IIso = 1 ; IIso <= theNbIso[0] ; IIso++){ + Index = anUInd(IIso) ; + if(Index != 0){ + if(aHatcher.TrimDone(Index) && !aHatcher.TrimFailed(Index)){ + aHatcher.ComputeDomains(Index); + if(aHatcher.IsDone (Index)) + aNbDom = aHatcher.NbDomains (Index); + } + } + } + + for(IIso = 1 ; IIso <= theNbIso[1] ; IIso++){ + Index = aVInd(IIso); + if(Index != 0){ + if(aHatcher.TrimDone (Index) && !aHatcher.TrimFailed(Index)){ + aHatcher.ComputeDomains (Index); + if(aHatcher.IsDone (Index)) + aNbDom = aHatcher.NbDomains (Index); + } + } + } + + //----------------------------------------------------------------------- + // Push iso lines in vtk kernel + //----------------------------------------------------------------------- + for(Standard_Integer UIso = anUPrm.Lower() ; UIso <= anUPrm.Upper(); UIso++){ + Standard_Integer UInd = anUInd.Value(UIso); + if(UInd != 0){ + Standard_Real UPrm = anUPrm.Value(UIso); + if(aHatcher.IsDone(UInd)){ + Standard_Integer NbDom = aHatcher.NbDomains(UInd); + for(Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++){ + const HatchGen_Domain& Dom = aHatcher.Domain(UInd, IDom) ; + Standard_Real V1 = Dom.HasFirstPoint()? Dom.FirstPoint().Parameter(): aVMin - VTKINFINITE; + Standard_Real V2 = Dom.HasSecondPoint()? Dom.SecondPoint().Parameter(): aVMax + VTKINFINITE; + CreateIso_(theFace, GeomAbs_IsoU, UPrm, V1, V2, theDiscret, thePolyData, thePts); + } + } + } + } + + for(Standard_Integer VIso = aVPrm.Lower() ; VIso <= aVPrm.Upper(); VIso++){ + Standard_Integer VInd = aVInd.Value(VIso); + if(VInd != 0){ + Standard_Real VPrm = aVPrm.Value(VIso); + if(aHatcher.IsDone (VInd)){ + Standard_Integer NbDom = aHatcher.NbDomains(VInd); + for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++){ + const HatchGen_Domain& Dom = aHatcher.Domain(VInd, IDom); + Standard_Real U1 = Dom.HasFirstPoint()? Dom.FirstPoint().Parameter(): aVMin - VTKINFINITE; + Standard_Real U2 = Dom.HasSecondPoint()? Dom.SecondPoint().Parameter(): aVMax + VTKINFINITE; + CreateIso_(theFace, GeomAbs_IsoV, VPrm, U1, U2, theDiscret, thePolyData, thePts); + } + } + } + } +} + + + +void +GEOM_WireframeFace:: +CreateIso_(const TopoDS_Face& theFace, + GeomAbs_IsoType theIsoType, + Standard_Real Par, + Standard_Real T1, + Standard_Real T2, + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + Standard_Real U1, U2, V1, V2, stepU=0., stepV=0.; + Standard_Integer j; + gp_Pnt P; + + TopLoc_Location aLoc; + const Handle(Geom_Surface)& S = BRep_Tool::Surface(theFace,aLoc); + + if(!S.IsNull()){ + BRepAdaptor_Surface S(theFace,Standard_False); + + GeomAbs_SurfaceType SurfType = S.GetType(); + + GeomAbs_CurveType CurvType = GeomAbs_OtherCurve; + + Standard_Integer Intrv, nbIntv; + Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN); + Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN); + TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1); + + if(theIsoType == GeomAbs_IsoU){ + S.VIntervals(TI, GeomAbs_CN); + V1 = Max(T1, TI(1)); + V2 = Min(T2, TI(2)); + U1 = Par; + U2 = Par; + stepU = 0; + nbIntv = nbVIntv; + }else{ + S.UIntervals(TI, GeomAbs_CN); + U1 = Max(T1, TI(1)); + U2 = Min(T2, TI(2)); + V1 = Par; + V2 = Par; + stepV = 0; + nbIntv = nbUIntv; + } + + S.D0(U1,V1,P); + MoveTo(P,thePts); + + for(Intrv = 1; Intrv <= nbIntv; Intrv++){ + if(TI(Intrv) <= T1 && TI(Intrv + 1) <= T1) + continue; + if(TI(Intrv) >= T2 && TI(Intrv + 1) >= T2) + continue; + if(theIsoType == GeomAbs_IsoU){ + V1 = Max(T1, TI(Intrv)); + V2 = Min(T2, TI(Intrv + 1)); + stepV = (V2 - V1) / theDiscret; + }else{ + U1 = Max(T1, TI(Intrv)); + U2 = Min(T2, TI(Intrv + 1)); + stepU = (U2 - U1) / theDiscret; + } + + switch (SurfType) { + case GeomAbs_Plane : + break; + case GeomAbs_Cylinder : + case GeomAbs_Cone : + if(theIsoType == GeomAbs_IsoV){ + for(j = 1; j < theDiscret; j++){ + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + } + break; + case GeomAbs_Sphere : + case GeomAbs_Torus : + case GeomAbs_OffsetSurface : + case GeomAbs_OtherSurface : + for(j = 1; j < theDiscret; j++){ + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + break; + case GeomAbs_BezierSurface : + case GeomAbs_BSplineSurface : + for(j = 1; j <= theDiscret/2; j++){ + Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.; + CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts); + U1 += stepU*2.; + V1 += stepV*2.; + } + break; + case GeomAbs_SurfaceOfExtrusion : + case GeomAbs_SurfaceOfRevolution : + if((theIsoType == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) || + (theIsoType == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) + { + if(SurfType == GeomAbs_SurfaceOfExtrusion) + break; + for(j = 1; j < theDiscret; j++){ + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + }else{ + CurvType = (S.BasisCurve())->GetType(); + switch(CurvType){ + case GeomAbs_Line : + break; + case GeomAbs_Circle : + case GeomAbs_Ellipse : + for (j = 1; j < theDiscret; j++) { + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + break; + case GeomAbs_Parabola : + case GeomAbs_Hyperbola : + case GeomAbs_BezierCurve : + case GeomAbs_BSplineCurve : + case GeomAbs_OtherCurve : + for(j = 1; j <= theDiscret/2; j++){ + Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.; + CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts); + U1 += stepU*2.; + V1 += stepV*2.; + } + break; + } + } + } + } + S.D0(U2,V2,P); + DrawTo(P,thePolyData,thePts); + } +} + + + + +void +GEOM_WireframeFace:: +CreateIso__(const BRepAdaptor_Surface& theSurface, + GeomAbs_IsoType theIsoType, + Standard_Real& theU, + Standard_Real& theV, + Standard_Real theStep, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + gp_Pnt Pl, Pr, Pm; + if (theIsoType == GeomAbs_IsoU) { + theSurface.D0(theU, theV, Pl); + theSurface.D0(theU, theV + theStep/2., Pm); + theSurface.D0(theU, theV + theStep, Pr); + } else { + theSurface.D0(theU, theV, Pl); + theSurface.D0(theU + theStep/2., theV, Pm); + theSurface.D0(theU + theStep, theV, Pr); + } + + static Standard_Real ISO_RATIO = 1.001; + if (Pm.Distance(Pl) + Pm.Distance(Pr) <= ISO_RATIO*Pl.Distance(Pr)) { + DrawTo(Pr,thePolyData,thePts); + } else { + if (theIsoType == GeomAbs_IsoU) { + CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts); + Standard_Real aLocalV = theV + theStep/2 ; + CreateIso__(theSurface, theIsoType, theU, aLocalV , theStep/2, thePolyData, thePts); + } else { + CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts); + Standard_Real aLocalU = theU + theStep/2 ; + CreateIso__(theSurface, theIsoType, aLocalU , theV, theStep/2, thePolyData, thePts); + } + } +} diff --git a/src/OCC2VTK/GEOM_WireframeFace.h b/src/OCC2VTK/GEOM_WireframeFace.h new file mode 100755 index 000000000..1b506f95d --- /dev/null +++ b/src/OCC2VTK/GEOM_WireframeFace.h @@ -0,0 +1,100 @@ +// 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 GEOM_WIREFRAME_FACE_H +#define GEOM_WIREFRAME_FACE_H + +#include "OCC2VTK.h" +#include "GEOM_FaceSource.h" + +#include +#include + +#include + +class OCC2VTK_EXPORT GEOM_WireframeFace: public GEOM_FaceSource +{ +public: + vtkTypeMacro(GEOM_WireframeFace,GEOM_FaceSource); + static GEOM_WireframeFace* New(); + + /* vtkSetMacro(NbIso,int); + vtkGetMacro(NbIso,int);*/ + + vtkSetMacro(Discret,int); + vtkGetMacro(Discret,int); + + static + void OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* thePolyData, + vtkPoints* thePts, + const int theNbIso[2], + const int theDiscret = 15); + + //! IsoLines management + // theNb[0] - number of U lines + // theNb[1] - number of V lines + virtual void SetNbIso(const int theNb[2]); + virtual void GetNbIso(int &theNbU,int &theNbV); + +protected: + int NbIso[2], Discret; + + static + void + CreateIso(const TopoDS_Face& theFace, + const int theNbIso[2], + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + static + void + CreateIso_(const TopoDS_Face& theFace, + GeomAbs_IsoType theIsoType, + Standard_Real Par, + Standard_Real T1, + Standard_Real T2, + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + static + void + CreateIso__(const BRepAdaptor_Surface& theSurface, + GeomAbs_IsoType theIsoType, + Standard_Real& theU, + Standard_Real& theV, + Standard_Real theStep, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + void Execute(); + + GEOM_WireframeFace(); + ~GEOM_WireframeFace(); + +private: + // Not implememnted + GEOM_WireframeFace(const GEOM_WireframeFace&); + void operator=(const GEOM_WireframeFace&); +}; + + +#endif //GEOM_WFACEACTOR_H 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