${PROJECT_SOURCE_DIR}/src/BlockFix
${PROJECT_SOURCE_DIR}/src/GEOMAlgo
${PROJECT_SOURCE_DIR}/src/GEOMUtils
- ${PROJECT_SOURCE_DIR}/src/OCC2VTK
${PROJECT_SOURCE_DIR}/src/SKETCHER
${PROJECT_SOURCE_DIR}/src/ARCHIMEDE
${PROJECT_SOURCE_DIR}/src/XAO
${CAS_TKFeat}
${CAS_TKFillet}
${PYTHON_LIBRARIES}
- ShHealOper GEOMbasic BlockFix GEOMAlgo GEOMUtils GEOMSketcher GEOMArchimede XAO OCC2VTK
+ ShHealOper GEOMbasic BlockFix GEOMAlgo GEOMUtils GEOMSketcher GEOMArchimede XAO
${KERNEL_SALOMELocalTrace}
)
#include <GEOMAlgo_AlgoTools.hxx>
#include <GEOMAlgo_KindOfName.hxx>
#include <GEOMAlgo_ShapeInfoFiller.hxx>
-#include <OCC2VTK_Tools.h>
#include <GEOM_PythonDump.hxx>
GEOMAlgo_AlgoTools::CopyShape(aShape1, aScopy1);
GEOMAlgo_AlgoTools::CopyShape(aShape2, aScopy2);
- float aDeflection = (theDeflection <= 0.) ? 0.001 : theDeflection;
- GEOM::MeshShape(aScopy1, aDeflection);
- GEOM::MeshShape(aScopy2, aDeflection);
+ GEOMUtils::MeshShape(aScopy1, theDeflection);
+ GEOMUtils::MeshShape(aScopy2, theDeflection);
//
// Map sub-shapes and their indices
TopTools_IndexedMapOfShape anIndices1, anIndices2;
#include <Standard_NullObject.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
+#define MAX2(X, Y) (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y))
+#define MAX3(X, Y, Z) (MAX2(MAX2(X,Y), Z))
+
#define STD_SORT_ALGO 1
// When the following macro is defined, ShapeFix_ShapeTolerance function is used to set max tolerance of curve
return result;
}
+
+void GEOMUtils::MeshShape( const TopoDS_Shape shape,
+ double deflection, bool theForced )
+{
+ Standard_Real aDeflection = ( deflection <= 0 ) ? DefaultDeflection() : deflection;
+
+ // Is shape triangulated?
+ Standard_Boolean alreadyMeshed = true;
+ TopExp_Explorer ex;
+ TopLoc_Location aLoc;
+ for ( ex.Init( shape, TopAbs_FACE ); ex.More() && alreadyMeshed; ex.Next() ) {
+ const TopoDS_Face& aFace = TopoDS::Face( ex.Current() );
+ Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation( aFace, aLoc );
+ alreadyMeshed = !aPoly.IsNull();
+ }
+
+ if ( !alreadyMeshed || theForced ) {
+ // Compute bounding box
+ Bnd_Box B;
+ BRepBndLib::Add( shape, 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 );
+
+ // This magic line comes from Prs3d_ShadedShape.gxx in OCCT
+ aDeflection = MAX3(aXmax-aXmin, aYmax-aYmin, aZmax-aZmin) * aDeflection * 4;
+
+ // Clean triangulation before compute incremental mesh
+ BRepTools::Clean( shape );
+
+ // Compute triangulation
+ BRepMesh_IncrementalMesh mesh( shape, aDeflection );
+ }
+}
+
+double GEOMUtils::DefaultDeflection()
+{
+ return 0.001;
+}
* \retval TopoDS_Shape resulting shape
*/
Standard_EXPORT TopoDS_Shape ReduceCompound( const TopoDS_Shape& shape );
+
+ /*!
+ * \brief Generate triangulation for the shape.
+ *
+ * \param shape shape being meshed
+ * \param deflection deflection coefficient to be used
+ * \param forced if \c true, causes generation of mesh regardless it is already present in the shape
+ */
+ Standard_EXPORT void MeshShape( const TopoDS_Shape shape,
+ double deflection, bool forced = true );
+
+ /*!
+ * \brief Get default deflection coefficient used for triangulation
+ * \return default deflection value
+ */
+ Standard_EXPORT double DefaultDeflection();
};
#endif
#include "GEOM_WireframeFace.h"
#include "GEOM_ShadingFace.h"
#include "GEOM_PainterPolyDataMapper.h"
+#include "GEOMUtils.hxx"
#include "SVTK_Actor.h"
#include <OCC2VTK_Tools.h>
void
GEOM_Actor::
-SetDeflection(float theDeflection)
+SetDeflection(double theDeflection)
{
- if( myDeflection == theDeflection )
- return;
-
- myDeflection = theDeflection;
-
- GEOM::MeshShape(myShape,myDeflection);
-
- SetModified();
+ double aDeflection = ( theDeflection <= 0 ) ? GEOMUtils::DefaultDeflection() : theDeflection;
+
+ if ( myDeflection != aDeflection ) {
+ myDeflection = aDeflection;
+ GEOMUtils::MeshShape( myShape, myDeflection );
+ SetModified();
+ }
}
void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
- float theDeflection,
+ double theDeflection,
bool theIsVector)
{
myShape = theShape;
TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
- GEOM::SetShape(theShape,anEdgeMap,theIsVector,
- myStandaloneVertexSource.Get(),
- myIsolatedEdgeSource.Get(),
- myOneFaceEdgeSource.Get(),
- mySharedEdgeSource.Get(),
- myWireframeFaceSource.Get(),
- myShadingFaceSource.Get());
+ GEOM::ShapeToVTK(theShape,anEdgeMap,theIsVector,
+ myStandaloneVertexSource.Get(),
+ myIsolatedEdgeSource.Get(),
+ myOneFaceEdgeSource.Get(),
+ mySharedEdgeSource.Get(),
+ myWireframeFaceSource.Get(),
+ myShadingFaceSource.Get());
isOnlyVertex =
myIsolatedEdgeSource->IsEmpty() &&
myOneFaceEdgeSource->IsEmpty() &&
myAppendFilter->Update();
}
-// OLD METHODS
-void GEOM_Actor::setDeflection(double adef) {
-#ifdef MYDEBUG
- MESSAGE ( "GEOM_Actor::setDeflection" );
-#endif
- SetDeflection((float)adef);
-}
-
-
// warning! must be checked!
// SetHighlightProperty
// SetWireframeProperty
#endif
}
-double GEOM_Actor::getDeflection()
-{
-#ifdef MYDEBUG
- MESSAGE ( "GEOM_Actor::getDeflection" );
-#endif
- return (double) GetDeflection();
-}
-
-
double GEOM_Actor::isVector()
{
#ifdef MYDEBUG
static GEOM_Actor* New();
void SetShape(const TopoDS_Shape& theShape,
- float theDeflection,
+ double theDeflection,
bool theIsVector = false);
- void SetDeflection(float theDeflection);
- float GetDeflection() const{ return myDeflection;}
+ void SetDeflection(double theDeflection);
+ double GetDeflection() const{ return myDeflection;}
void AddToRender(vtkRenderer* theRenderer);
void RemoveFromRender(vtkRenderer* theRenderer);
vtkProperty* GetSharedEdgeProperty();
vtkProperty* GetFaceEdgeProperty();
- void setDeflection(double adef);
virtual void setDisplayMode(int thenewmode);
// Description:
const TopoDS_Shape& getTopo();
void setInputShape(const TopoDS_Shape& ashape, double adef1,
int imode, bool isVector = false);
- double getDeflection();
double isVector();
// SubShape
TopoDS_Shape myShape;
bool isOnlyVertex;
- float myDeflection;
+ double myDeflection;
bool myIsForced;
// EDisplayMode myDisplayMode;
#include "GEOM_EdgeSource.h"
#include "GEOM_WireframeFace.h"
#include "GEOM_ShadingFace.h"
+#include "GEOMUtils.hxx"
#include <Bnd_Box.hxx>
#include <BRep_Tool.hxx>
#include <vtkPolyData.h>
#include <BRepBuilderAPI_Copy.hxx>
-#define MAX2(X, Y) (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y))
-#define MAX3(X, Y, Z) (MAX2(MAX2(X,Y), Z))
-
-
-#define DEFAULT_DEFLECTION 0.001
-
namespace GEOM
{
- void MeshShape(const TopoDS_Shape theShape,
- float& theDeflection,
- bool theForced ) {
-
- Standard_Real aDeflection = theDeflection <= 0 ? DEFAULT_DEFLECTION : theDeflection;
-
- //If deflection <= 0, than return default deflection
- if(theDeflection <= 0)
- theDeflection = aDeflection;
-
- // Is shape triangulated?
- Standard_Boolean alreadymeshed = 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()) {
- alreadymeshed = Standard_False;
- break;
- }
- }
-
- if(!alreadymeshed || theForced) {
- 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);
-
- // This magic line comes from Prs3d_ShadedShape.gxx in OCCT
- aDeflection = MAX3(aXmax-aXmin, aYmax-aYmin, aZmax-aZmin) * aDeflection * 4;
-
- //Clean triangulation before compute incremental mesh
- BRepTools::Clean(theShape);
-
- //Compute triangulation
- BRepMesh_IncrementalMesh MESH(theShape,aDeflection);
- }
- }
-
- void SetShape(const TopoDS_Shape& theShape,
- const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
- bool theIsVector,
- GEOM_VertexSource* theStandaloneVertexSource,
- GEOM_EdgeSource* theIsolatedEdgeSource,
- GEOM_EdgeSource* theOneFaceEdgeSource,
- GEOM_EdgeSource* theSharedEdgeSource,
- GEOM_WireframeFace* theWireframeFaceSource,
- GEOM_ShadingFace* theShadingFaceSource)
+ void ShapeToVTK( const TopoDS_Shape& theShape,
+ const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
+ bool theIsVector,
+ GEOM_VertexSource* theStandaloneVertexSource,
+ 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,
- theStandaloneVertexSource,
- theIsolatedEdgeSource,
- theOneFaceEdgeSource,
- theSharedEdgeSource,
- theWireframeFaceSource,
- theShadingFaceSource);
+ ShapeToVTK( anItr.Value(),theEdgeMap,theIsVector,
+ theStandaloneVertexSource,
+ theIsolatedEdgeSource,
+ theOneFaceEdgeSource,
+ theSharedEdgeSource,
+ theWireframeFaceSource,
+ theShadingFaceSource );
}
}
}
}
- vtkPolyData* GetData(const TopoDS_Shape& theShape, float theDeflection) {
+ vtkPolyData* GetVTKData( const TopoDS_Shape& theShape, float theDeflection )
+ {
+ vtkPolyData* ret = 0;
+
BRepBuilderAPI_Copy aCopy(theShape);
- if(!aCopy.IsDone()) {
- return 0;
- }
+ if (aCopy.IsDone() ) {
- TopoDS_Shape aShape = aCopy.Shape();
-
- try {
- GEOM_VertexSource* myVertexSource = GEOM_VertexSource::New();
- GEOM_EdgeSource* myIsolatedEdgeSource = GEOM_EdgeSource::New();
- GEOM_EdgeSource* myOneFaceEdgeSource = GEOM_EdgeSource::New();
- GEOM_EdgeSource* mySharedEdgeSource = GEOM_EdgeSource::New();
- GEOM_WireframeFace* myWireframeFaceSource = GEOM_WireframeFace::New();
- GEOM_ShadingFace* myShadingFaceSource = GEOM_ShadingFace::New();
-
- vtkAppendPolyData* myAppendFilter = vtkAppendPolyData::New();
- myAppendFilter->AddInputConnection( myVertexSource->GetOutputPort() );
- myAppendFilter->AddInputConnection( myIsolatedEdgeSource->GetOutputPort() );
- myAppendFilter->AddInputConnection( myOneFaceEdgeSource->GetOutputPort() );
- myAppendFilter->AddInputConnection( mySharedEdgeSource->GetOutputPort() );
- myAppendFilter->AddInputConnection( myShadingFaceSource->GetOutputPort() );
+ TopoDS_Shape aShape = aCopy.Shape();
- bool anIsVector = false;
+ try {
+ GEOM_VertexSource* myVertexSource = GEOM_VertexSource::New();
+ GEOM_EdgeSource* myIsolatedEdgeSource = GEOM_EdgeSource::New();
+ GEOM_EdgeSource* myOneFaceEdgeSource = GEOM_EdgeSource::New();
+ GEOM_EdgeSource* mySharedEdgeSource = GEOM_EdgeSource::New();
+ GEOM_WireframeFace* myWireframeFaceSource = GEOM_WireframeFace::New();
+ GEOM_ShadingFace* myShadingFaceSource = GEOM_ShadingFace::New();
+
+ vtkAppendPolyData* myAppendFilter = vtkAppendPolyData::New();
+ myAppendFilter->AddInputConnection( myVertexSource->GetOutputPort() );
+ myAppendFilter->AddInputConnection( myIsolatedEdgeSource->GetOutputPort() );
+ myAppendFilter->AddInputConnection( myOneFaceEdgeSource->GetOutputPort() );
+ myAppendFilter->AddInputConnection( mySharedEdgeSource->GetOutputPort() );
+ myAppendFilter->AddInputConnection( myShadingFaceSource->GetOutputPort() );
+
+ bool anIsVector = false;
+
+ GEOMUtils::MeshShape( aShape, theDeflection );
+ TopExp_Explorer aVertexExp( aShape, TopAbs_VERTEX );
+ for( ; aVertexExp.More(); aVertexExp.Next() ) {
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex( aVertexExp.Current() );
+ myVertexSource->AddVertex( aVertex );
+ }
- GEOM::MeshShape( aShape, theDeflection );
- TopExp_Explorer aVertexExp( aShape, TopAbs_VERTEX );
- for( ; aVertexExp.More(); aVertexExp.Next() ) {
- const TopoDS_Vertex& aVertex = TopoDS::Vertex( aVertexExp.Current() );
- myVertexSource->AddVertex( aVertex );
+ TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
+ TopExp::MapShapesAndAncestors( aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap );
+
+ ShapeToVTK( aShape,
+ anEdgeMap,
+ anIsVector,
+ 0,
+ myIsolatedEdgeSource,
+ myOneFaceEdgeSource,
+ mySharedEdgeSource,
+ myWireframeFaceSource,
+ myShadingFaceSource );
+
+ myAppendFilter->Update();
+
+ myVertexSource->Delete();
+ myIsolatedEdgeSource->Delete();
+ myOneFaceEdgeSource->Delete();
+ mySharedEdgeSource->Delete();
+ myWireframeFaceSource->Delete();
+ myShadingFaceSource->Delete();
+
+ ret = vtkPolyData::New();
+ ret->ShallowCopy(myAppendFilter->GetOutput());
+ myAppendFilter->Delete();
+ }
+ catch(Standard_Failure) {
}
-
- TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
- TopExp::MapShapesAndAncestors( aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap );
-
- GEOM::SetShape( aShape,
- anEdgeMap,
- anIsVector,
- 0,
- myIsolatedEdgeSource,
- myOneFaceEdgeSource,
- mySharedEdgeSource,
- myWireframeFaceSource,
- myShadingFaceSource );
-
- myAppendFilter->Update();
-
- myVertexSource->Delete();
- myIsolatedEdgeSource->Delete();
- myOneFaceEdgeSource->Delete();
- mySharedEdgeSource->Delete();
- myWireframeFaceSource->Delete();
- myShadingFaceSource->Delete();
-
- vtkPolyData* ret = vtkPolyData::New();
- ret->ShallowCopy(myAppendFilter->GetOutput());
- myAppendFilter->Delete();
- return ret;
- }
- catch(Standard_Failure) {
- return 0;
}
- }
+ return ret;
+ }
}
class GEOM_WireframeFace;
class GEOM_ShadingFace;
class vtkPolyData;
+
namespace GEOM
{
- // moved from GEOM_AssemblyBuilder
- OCC2VTK_EXPORT void MeshShape(const TopoDS_Shape theShape,
- float& theDeflection,
- bool theForced = true);
-
- // moved from GEOM_Actor
- OCC2VTK_EXPORT void SetShape(const TopoDS_Shape& theShape,
- const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
- bool theIsVector,
- GEOM_VertexSource* theStandaloneVertexSource,
- GEOM_EdgeSource* theIsolatedEdgeSource,
- GEOM_EdgeSource* theOneFaceEdgeSource,
- GEOM_EdgeSource* theSharedEdgeSource,
- GEOM_WireframeFace* theWireframeFaceSource,
- GEOM_ShadingFace* theShadingFaceSource);
+ /*!
+ * \brief Convert shape to the VTK data sources
+ * \param theShape shape
+ * \param theEdgeMape map that stores face-to-edge relations
+ * \param theIsVector boolen flag, when \c true causes generating additional
+ * dataset for edges orientation vectors
+ * \param theStandaloneVertexSource output standalone vertices data source
+ * \param theIsolatedEdgeSource output standalone edges data source
+ * \param theOneFaceEdgeSource output face edges data source
+ * \param theSharedEdgeSource output face shared edges data source
+ * \param theWireframeFaceSource output wireframe mode faces data source
+ * \param theShadingFaceSource output shading mode faces data source
+ */
+ OCC2VTK_EXPORT void ShapeToVTK( const TopoDS_Shape& theShape,
+ const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
+ bool theIsVector,
+ GEOM_VertexSource* theStandaloneVertexSource,
+ GEOM_EdgeSource* theIsolatedEdgeSource,
+ GEOM_EdgeSource* theOneFaceEdgeSource,
+ GEOM_EdgeSource* theSharedEdgeSource,
+ GEOM_WireframeFace* theWireframeFaceSource,
+ GEOM_ShadingFace* theShadingFaceSource );
- OCC2VTK_EXPORT vtkPolyData* GetData(const TopoDS_Shape& theShape, float theDeflection);
+ /*!
+ * \brief Get VTK mesh data from the shape
+ * \param theShape shape
+ * \param theDeflection requested deflection coefficient
+ * \return VTK data set
+ */
+ OCC2VTK_EXPORT vtkPolyData* GetVTKData( const TopoDS_Shape& theShape, float theDeflection );
}
#endif // OCC2VTK_TOOLS_H
// Set "C" numeric locale to save numbers correctly
Kernel_Utils::Localizer loc;
- vtkPolyData* pd = GEOM::GetData( aShape, aDeflection );
+ vtkPolyData* pd = GEOM::GetVTKData( aShape, aDeflection );
vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
aWriter->SetInputData( pd );
aWriter->SetFileName( aFileName.ToCString() );