Skip to content

Commit

Permalink
SMESH: Make it compatibel to VTK 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ickby authored and wwmayer committed Jun 15, 2016
1 parent 2fc6cc5 commit 1ab9209
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 25 deletions.
38 changes: 24 additions & 14 deletions CMakeLists.txt
Expand Up @@ -648,21 +648,31 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

# Salome SMESH sources are under src/3rdParty now
IF(OCC_FOUND)
if(NOT FREECAD_USE_EXTERNAL_SMESH)
find_package(VTK REQUIRED)
find_package(HDF5 REQUIRED)
find_package(MEDFile REQUIRED)
set(SMESH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/3rdParty/salomesmesh/inc)
else()
find_package(SMESH)
if(NOT SMESH_FOUND)
message(ERROR "================\n"
"SMESH not found.\n"
"================\n")
#if we use smesh we definitly also need vtk, no matter of external or internal smesh
find_package(VTK REQUIRED) #don't check VERSION 6 as this would exclude version 7
if(${VTK_MAJOR_VERSION} LESS 6)
message( FATAL_ERROR "Found VTK version is <6, this is not compatible" )
endif()
include_directories(${SMESH_INCLUDE_DIR})
endif()
set(SMESH_FOUND TRUE)
if(${VTK_MAJOR_VERSION} EQUAL 6)
if(${VTK_MINOR_VERSION} LESS 2)
add_definitions(-DVTK_NO_QUAD_POLY )
endif()
endif()

if(NOT FREECAD_USE_EXTERNAL_SMESH)
find_package(HDF5 REQUIRED)
find_package(MEDFile REQUIRED)
set(SMESH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/3rdParty/salomesmesh/inc)
else()
find_package(SMESH)
if(NOT SMESH_FOUND)
message(ERROR "================\n"
"SMESH not found.\n"
"================\n")
endif()
include_directories(${SMESH_INCLUDE_DIR})
endif()
set(SMESH_FOUND TRUE)
ENDIF(OCC_FOUND)

# -------------------------------- Netgen --------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/3rdParty/salomesmesh/inc/SMDSAbs_ElementType.hxx
Expand Up @@ -88,7 +88,9 @@ enum SMDSAbs_EntityType {
SMDSEntity_Quad_Quadrangle,
SMDSEntity_BiQuad_Quadrangle,
SMDSEntity_Polygon,
#ifndef VTK_NO_QUAD_POLY
SMDSEntity_Quad_Polygon,
#endif
SMDSEntity_Tetra,
SMDSEntity_Quad_Tetra,
SMDSEntity_Pyramid,
Expand Down
8 changes: 8 additions & 0 deletions src/3rdParty/salomesmesh/inc/SMDS_MeshInfo.hxx
Expand Up @@ -221,7 +221,9 @@ inline void // addWithPoly
SMDS_MeshInfo::addWithPoly(const SMDS_MeshElement* el) {
switch ( el->GetEntityType() ) {
case SMDSEntity_Polygon: ++myNbPolygons; break;
#ifndef VTK_NO_QUAD_POLY
case SMDSEntity_Quad_Polygon: ++myNbQuadPolygons; break;
#endif
case SMDSEntity_Polyhedra: ++myNbPolyhedrons; break;
default: add(el);
}
Expand All @@ -234,7 +236,9 @@ inline void // RemoveFace
SMDS_MeshInfo::RemoveFace(const SMDS_MeshElement* el) {
switch ( el->GetEntityType() ) {
case SMDSEntity_Polygon: --myNbPolygons; break;
#ifndef VTK_NO_QUAD_POLY
case SMDSEntity_Quad_Polygon: --myNbQuadPolygons; break;
#endif
default: remove(el);
}
}
Expand Down Expand Up @@ -350,7 +354,9 @@ SMDS_MeshInfo::NbEntities(SMDSAbs_EntityType type) const
case SMDSEntity_Polyhedra: return myNbPolyhedrons;
case SMDSEntity_0D: return myNb0DElements;
case SMDSEntity_Ball: return myNbBalls;
#ifndef VTK_NO_QUAD_POLY
case SMDSEntity_Quad_Polygon: return myNbQuadPolygons;
#endif
case SMDSEntity_Quad_Polyhedra:
break;
}
Expand Down Expand Up @@ -422,7 +428,9 @@ SMDS_MeshInfo::setNb(const SMDSAbs_EntityType geomType, const int nb)
case SMDSEntity_Tetra: myNbTetras = nb; break;
case SMDSEntity_TriQuad_Hexa: myNbTriQuadHexas = nb; break;
case SMDSEntity_Triangle: myNbTriangles = nb; break;
#ifndef VTK_NO_QUAD_POLY
case SMDSEntity_Quad_Polygon: myNbQuadPolygons = nb; break;
#endif
case SMDSEntity_Quad_Polyhedra:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/3rdParty/salomesmesh/src/Controls/SMESH_Controls.cpp
Expand Up @@ -1717,13 +1717,15 @@ double Length2D::GetValue( long theElementId )
aVal = Min( aVal, getDistance( P( i ), P( i+1 )));
}
break;
#ifndef VTK_NO_QUAD_POLY
case SMDSEntity_Quad_Polygon:
if ( len > 2 ) {
aVal = getDistance( P(1), P( P.size() )) + getDistance( P(P.size()), P( P.size()-1 ));
for ( size_t i = 1; i < P.size()-1; i += 2 )
aVal = Min( aVal, getDistance( P( i ), P( i+1 )) + getDistance( P( i+1 ), P( i+2 )));
}
break;
#endif
case SMDSEntity_Hexagonal_Prism:
if (len == 12) { // hexagonal prism
double L1 = getDistance(P( 1 ),P( 2 ));
Expand Down
13 changes: 10 additions & 3 deletions src/3rdParty/salomesmesh/src/SMDS/SMDS_MeshCell.cpp
Expand Up @@ -56,7 +56,9 @@ VTKCellType SMDS_MeshCell::toVtkType (SMDSAbs_EntityType smdsType)
vtkTypes[ SMDSEntity_Quad_Quadrangle ] = VTK_QUADRATIC_QUAD;
vtkTypes[ SMDSEntity_BiQuad_Quadrangle ] = VTK_BIQUADRATIC_QUAD;
vtkTypes[ SMDSEntity_Polygon ] = VTK_POLYGON;
#ifndef VTK_NO_QUAD_POLY
vtkTypes[ SMDSEntity_Quad_Polygon ] = VTK_QUADRATIC_POLYGON;
#endif
vtkTypes[ SMDSEntity_Tetra ] = VTK_TETRA;
vtkTypes[ SMDSEntity_Quad_Tetra ] = VTK_QUADRATIC_TETRA;
vtkTypes[ SMDSEntity_Pyramid ] = VTK_PYRAMID;
Expand Down Expand Up @@ -268,6 +270,7 @@ const std::vector<int>& SMDS_MeshCell::reverseSmdsOrder(SMDSAbs_EntityType smdsT
reverseInterlaces[ smdsType ][i] = nbNodes - i - 1;
}
}
#ifndef VTK_NO_QUAD_POLY
else if ( smdsType == SMDSEntity_Quad_Polygon )
{
if ( reverseInterlaces[ smdsType ].size() != nbNodes )
Expand All @@ -282,6 +285,7 @@ const std::vector<int>& SMDS_MeshCell::reverseSmdsOrder(SMDSAbs_EntityType smdsT
reverseInterlaces[ smdsType ][pos++] = i;
}
}
#endif

return reverseInterlaces[smdsType];
}
Expand Down Expand Up @@ -315,7 +319,7 @@ const std::vector<int>& SMDS_MeshCell::interlacedSmdsOrder(SMDSAbs_EntityType sm
interlace[SMDSEntity_BiQuad_Quadrangle].assign( &ids[0], &ids[0]+9 );
}
}

#ifndef VTK_NO_QUAD_POLY
if ( smdsType == SMDSEntity_Quad_Polygon )
{
if ( interlace[smdsType].size() != nbNodes )
Expand All @@ -328,6 +332,7 @@ const std::vector<int>& SMDS_MeshCell::interlacedSmdsOrder(SMDSAbs_EntityType sm
}
}
}
#endif
return interlace[smdsType];
}

Expand Down Expand Up @@ -402,8 +407,10 @@ SMDSAbs_ElementType SMDS_MeshCell::toSmdsType(SMDSAbs_EntityType entityType)
case SMDSEntity_Quadrangle:
case SMDSEntity_Quad_Quadrangle:
case SMDSEntity_BiQuad_Quadrangle:
case SMDSEntity_Polygon:
case SMDSEntity_Quad_Polygon: return SMDSAbs_Face;
#ifndef VTK_NO_QUAD_POLY
case SMDSEntity_Quad_Polygon:
#endif
case SMDSEntity_Polygon: return SMDSAbs_Face;

case SMDSEntity_Tetra:
case SMDSEntity_Quad_Tetra:
Expand Down
2 changes: 2 additions & 0 deletions src/3rdParty/salomesmesh/src/SMDS/SMDS_VtkCellIterator.cpp
Expand Up @@ -129,7 +129,9 @@ SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCel
break;
}
case SMDSEntity_Polygon:
#ifndef VTK_NO_QUAD_POLY
case SMDSEntity_Quad_Polygon:
#endif
case SMDSEntity_Polyhedra:
case SMDSEntity_Quad_Polyhedra:
default:
Expand Down
26 changes: 22 additions & 4 deletions src/3rdParty/salomesmesh/src/SMDS/SMDS_VtkFace.cpp
Expand Up @@ -87,11 +87,15 @@ void SMDS_VtkFace::initPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* me

void SMDS_VtkFace::initQuadPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
{
#ifndef VTK_NO_QUAD_POLY
SMDS_MeshFace::init();
vtkUnstructuredGrid* grid = mesh->getGrid();
myMeshId = mesh->getMeshId();
myVtkID = grid->InsertNextLinkedCell(VTK_QUADRATIC_POLYGON, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
mesh->setMyModified();
#else
throw SALOME_Exception("Quadratic polygon not supported with VTK <6.2");
#endif
}

bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
Expand Down Expand Up @@ -135,9 +139,11 @@ int SMDS_VtkFace::NbEdges() const
case VTK_BIQUADRATIC_QUAD:
nbEdges = 4;
break;
#ifndef VTK_NO_QUAD_POLY
case VTK_QUADRATIC_POLYGON:
nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints() / 2;
break;
#endif
case VTK_POLYGON:
default:
nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints();
Expand Down Expand Up @@ -197,7 +203,9 @@ bool SMDS_VtkFace::IsQuadratic() const
{
case VTK_QUADRATIC_TRIANGLE:
case VTK_QUADRATIC_QUAD:
#ifndef VTK_NO_QUAD_POLY
case VTK_QUADRATIC_POLYGON:
#endif
case VTK_BIQUADRATIC_QUAD:
case VTK_BIQUADRATIC_TRIANGLE:
return true;
Expand All @@ -211,7 +219,11 @@ bool SMDS_VtkFace::IsPoly() const
{
vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
return ( aVtkType == VTK_POLYGON || aVtkType == VTK_QUADRATIC_POLYGON );
bool isPoly = aVtkType == VTK_POLYGON;
#ifndef VTK_NO_QUAD_POLY
isPoly = isPoly || aVtkType == VTK_QUADRATIC_POLYGON;
#endif
return isPoly;
}

bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
Expand All @@ -229,9 +241,11 @@ bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
case VTK_BIQUADRATIC_QUAD:
rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
break;
#ifndef VTK_NO_QUAD_POLY
case VTK_QUADRATIC_POLYGON:
rankFirstMedium = grid->GetCell(myVtkID)->GetNumberOfPoints() / 2;
break;
#endif
default:
//MESSAGE("wrong element type " << aVtkType);
return false;
Expand Down Expand Up @@ -267,9 +281,11 @@ int SMDS_VtkFace::NbCornerNodes() const
{
case VTK_POLYGON:
break;
#ifndef VTK_NO_QUAD_POLY
case VTK_QUADRATIC_POLYGON:
nbPoints /= 2;
break;
#endif
default:
if ( nbPoints > 4 )
nbPoints /= 2;
Expand All @@ -296,9 +312,11 @@ SMDSAbs_GeometryType SMDS_VtkFace::GetGeomType() const
case VTK_QUAD:
case VTK_QUADRATIC_QUAD:
case VTK_BIQUADRATIC_QUAD: return SMDSGeom_QUADRANGLE;

case VTK_POLYGON:
case VTK_QUADRATIC_POLYGON: return SMDSGeom_POLYGON;

#ifndef VTK_NO_QUAD_POLY
case VTK_QUADRATIC_POLYGON:
#endif
case VTK_POLYGON: return SMDSGeom_POLYGON;
default:;
}
return SMDSGeom_NONE;
Expand Down
Expand Up @@ -731,9 +731,13 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
{
if ( aElemTypeData->_geomType == ePOLYGONE )
elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
else
else {
#ifndef VTK_NO_QUAD_POLY
elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );

#else
throw SALOME_Exception("Quadratic polygon not supported with VTK <6.2");
#endif
}
if ( nbPolygonNodes == 0 ) {
// Count nb of nodes
while ( elemIterator->more() ) {
Expand Down
13 changes: 12 additions & 1 deletion src/3rdParty/salomesmesh/src/SMESH/SMESH_MeshEditor.cpp
Expand Up @@ -4614,11 +4614,13 @@ void SMESH_MeshEditor::sweepElement(const SMDS_MeshElement* elem,
if ( nbNodes == 3 ) baseType = SMDSEntity_Triangle;
else if ( nbNodes == 4 ) baseType = SMDSEntity_Quadrangle;
}
#ifndef VTK_NO_QUAD_POLY
else if ( baseType == SMDSEntity_Quad_Polygon )
{
if ( nbNodes == 6 ) baseType = SMDSEntity_Quad_Triangle;
else if ( nbNodes == 8 ) baseType = SMDSEntity_Quad_Quadrangle;
}
#endif

// make new elements
for (int iStep = 0; iStep < nbSteps; iStep++ )
Expand Down Expand Up @@ -7425,9 +7427,14 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes)
{
elemType.Init( elem );
const bool isQuad = elemType.myIsQuad;
if ( isQuad )
if ( isQuad ) {
#ifndef VTK_NO_QUAD_POLY
SMDS_MeshCell::applyInterlace // interlace medium and corner nodes
( SMDS_MeshCell::interlacedSmdsOrder( SMDSEntity_Quad_Polygon, nbNodes ), curNodes );
#else
throw SALOME_Exception("Quadratic polygon not supported with VTK <6.2");
#endif
}

// a polygon can divide into several elements
vector<const SMDS_MeshNode *> polygons_nodes;
Expand All @@ -7445,6 +7452,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes)
inode += nbNewNodes;
if ( isQuad ) // check if a result elem is a valid quadratic polygon
{
#ifndef VTK_NO_QUAD_POLY
bool isValid = ( nbNewNodes % 2 == 0 );
for ( int i = 0; i < nbNewNodes && isValid; ++i )
isValid = ( elem->IsMediumNode( face_nodes[i]) == bool( i % 2 ));
Expand All @@ -7453,6 +7461,9 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes)
SMDS_MeshCell::applyInterlaceRev
( SMDS_MeshCell::interlacedSmdsOrder( SMDSEntity_Quad_Polygon,
nbNewNodes ), face_nodes );
#else
throw SALOME_Exception("Quadratic polygon not supported with VTK <6.2");
#endif
}
elemType.SetPoly(( nbNewNodes / ( elemType.myIsQuad + 1 ) > 4 ));

Expand Down
Expand Up @@ -147,8 +147,15 @@ bool StdMeshers_PolygonPerFace_2D::Evaluate(SMESH_Mesh& theMesh,
break;
default:
if ( nbLinSegs + nbQuadSegs < 3 )
return error( COMPERR_BAD_INPUT_MESH, "Less that 3 nodes on the wire" );
return error( COMPERR_BAD_INPUT_MESH, "Less that 3 nodes on the wire" );
#ifndef VTK_NO_QUAD_POLY
aVec[ nbQuadSegs ? SMDSEntity_Quad_Polygon : SMDSEntity_Polygon ] = 1;
#else
if(nbQuadSegs)
throw SALOME_Exception("Quadratic polygon not supported with VTK <6.2");

aVec[ SMDSEntity_Polygon ] = 1;
#endif
}

SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
Expand Down

0 comments on commit 1ab9209

Please sign in to comment.