From 4c16067d4281f56bd07d3f92fb63fff9c0c1d169 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 22 Dec 2017 14:14:24 +0300 Subject: [PATCH] 23418: [OCC] Mesh: Minimization of memory usage of SMESH --- src/Controls/SMESH_Controls.cxx | 207 +- src/Driver/CMakeLists.txt | 1 + src/DriverCGNS/DriverCGNS_Read.cxx | 5 +- src/DriverCGNS/DriverCGNS_Write.cxx | 8 +- src/DriverDAT/DriverDAT_W_SMDS_Mesh.cxx | 6 +- src/DriverGMF/DriverGMF_Read.cxx | 3 + src/DriverMED/DriverMED_Family.cxx | 18 + src/DriverMED/DriverMED_Family.h | 4 +- src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx | 12 +- src/DriverMED/DriverMED_W_Field.cxx | 3 +- src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx | 22 +- src/DriverMED/DriverMED_W_SMESHDS_Mesh.h | 1 + src/DriverSTL/DriverSTL_R_SMDS_Mesh.cxx | 3 + src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx | 179 +- src/DriverUNV/DriverUNV_R_SMDS_Mesh.h | 16 +- src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx | 3 - src/DriverUNV/UNV2417_Structure.hxx | 10 +- src/OBJECT/SMESH_Object.cxx | 95 +- src/SMDS/CMakeLists.txt | 98 +- src/SMDS/Notes | 235 -- src/SMDS/ObjectPool.hxx | 4 +- src/SMDS/SMDS_BallElement.cxx | 70 +- src/SMDS/SMDS_BallElement.hxx | 37 +- ...SMDS_MeshFace.cxx => SMDS_CellOfNodes.cxx} | 37 +- ...mentIDFactory.hxx => SMDS_CellOfNodes.hxx} | 62 +- src/SMDS/SMDS_Downward.cxx | 16 +- src/SMDS/SMDS_EdgePosition.cxx | 67 - src/SMDS/SMDS_EdgePosition.hxx | 17 +- src/SMDS/SMDS_ElementFactory.cxx | 880 +++++ src/SMDS/SMDS_ElementFactory.hxx | 559 +++ src/SMDS/SMDS_ElementHolder.cxx | 122 + src/SMDS/SMDS_ElementHolder.hxx | 93 + src/SMDS/SMDS_FaceOfEdges.cxx | 196 - src/SMDS/SMDS_FaceOfEdges.hxx | 68 - src/SMDS/SMDS_FaceOfNodes.cxx | 111 +- src/SMDS/SMDS_FaceOfNodes.hxx | 61 +- src/SMDS/SMDS_FacePosition.cxx | 41 +- src/SMDS/SMDS_FacePosition.hxx | 23 +- src/SMDS/SMDS_Iterator.hxx | 27 +- src/SMDS/SMDS_IteratorOfElements.cxx | 109 - src/SMDS/SMDS_IteratorOfElements.hxx | 57 - src/SMDS/SMDS_LinearEdge.cxx | 100 +- src/SMDS/SMDS_LinearEdge.hxx | 46 +- src/SMDS/SMDS_Mesh.cxx | 3386 ++++------------- src/SMDS/SMDS_Mesh.hxx | 253 +- src/SMDS/SMDS_Mesh0DElement.cxx | 164 - src/SMDS/SMDS_Mesh0DElement.hxx | 23 +- src/SMDS/SMDS_MeshCell.cxx | 454 ++- src/SMDS/SMDS_MeshCell.hxx | 63 +- src/SMDS/SMDS_MeshEdge.cxx | 30 - src/SMDS/SMDS_MeshEdge.hxx | 10 +- src/SMDS/SMDS_MeshElement.cxx | 334 +- src/SMDS/SMDS_MeshElement.hxx | 139 +- src/SMDS/SMDS_MeshElementIDFactory.cxx | 176 - src/SMDS/SMDS_MeshFace.hxx | 34 +- src/SMDS/SMDS_MeshGroup.cxx | 117 +- src/SMDS/SMDS_MeshGroup.hxx | 96 +- src/SMDS/SMDS_MeshIDFactory.cxx | 113 - src/SMDS/SMDS_MeshIDFactory.hxx | 56 - src/SMDS/SMDS_MeshNode.cxx | 250 +- src/SMDS/SMDS_MeshNode.hxx | 53 +- src/SMDS/SMDS_MeshNodeIDFactory.cxx | 161 - src/SMDS/SMDS_MeshNodeIDFactory.hxx | 65 - src/SMDS/SMDS_MeshVolume.cxx | 242 +- src/SMDS/SMDS_MeshVolume.hxx | 41 +- src/SMDS/SMDS_PolygonalFaceOfNodes.cxx | 112 +- src/SMDS/SMDS_PolygonalFaceOfNodes.hxx | 30 +- src/SMDS/SMDS_PolyhedralVolumeOfNodes.cxx | 265 -- src/SMDS/SMDS_PolyhedralVolumeOfNodes.hxx | 91 - src/SMDS/SMDS_Position.cxx | 58 - src/SMDS/SMDS_Position.hxx | 63 +- src/SMDS/SMDS_QuadraticEdge.cxx | 160 - src/SMDS/SMDS_QuadraticEdge.hxx | 64 - src/SMDS/SMDS_QuadraticFaceOfNodes.cxx | 290 -- src/SMDS/SMDS_QuadraticFaceOfNodes.hxx | 83 - src/SMDS/SMDS_QuadraticVolumeOfNodes.cxx | 389 -- src/SMDS/SMDS_QuadraticVolumeOfNodes.hxx | 131 - src/SMDS/SMDS_SpacePosition.cxx | 13 +- src/SMDS/SMDS_SpacePosition.hxx | 13 +- src/SMDS/SMDS_UnstructuredGrid.cxx | 195 +- src/SMDS/SMDS_UnstructuredGrid.hxx | 9 +- src/SMDS/SMDS_VertexPosition.cxx | 48 - src/SMDS/SMDS_VertexPosition.hxx | 10 +- src/SMDS/SMDS_VolumeOfFaces.cxx | 169 - src/SMDS/SMDS_VolumeOfFaces.hxx | 71 - src/SMDS/SMDS_VolumeOfNodes.cxx | 240 +- src/SMDS/SMDS_VolumeOfNodes.hxx | 97 +- src/SMDS/SMDS_VolumeTool.cxx | 46 +- src/SMDS/SMDS_VolumeTool.hxx | 3 +- src/SMDS/SMDS_VtkCellIterator.cxx | 124 +- src/SMDS/SMDS_VtkCellIterator.hxx | 74 +- src/SMDS/SMDS_VtkEdge.cxx | 167 - src/SMDS/SMDS_VtkEdge.hxx | 59 - src/SMDS/SMDS_VtkFace.cxx | 334 -- src/SMDS/SMDS_VtkFace.hxx | 64 - src/SMDS/SMDS_VtkVolume.cxx | 698 ---- src/SMDS/SMDS_VtkVolume.hxx | 80 - src/SMESH/SMESH_Algo.cxx | 37 +- src/SMESH/SMESH_Algo.hxx | 1 + src/SMESH/SMESH_Gen.cxx | 11 +- src/SMESH/SMESH_Mesh.cxx | 47 +- src/SMESH/SMESH_MeshEditor.cxx | 356 +- src/SMESH/SMESH_MesherHelper.cxx | 40 +- src/SMESH/SMESH_Pattern.cxx | 12 +- src/SMESH/SMESH_ProxyMesh.cxx | 62 +- src/SMESH/SMESH_ProxyMesh.hxx | 27 +- src/SMESH/SMESH_subMesh.cxx | 33 +- src/SMESHClient/SMESH_Client.cxx | 56 +- src/SMESHDS/SMESHDS_Group.cxx | 32 +- src/SMESHDS/SMESHDS_GroupOnFilter.cxx | 47 +- src/SMESHDS/SMESHDS_GroupOnFilter.hxx | 12 +- src/SMESHDS/SMESHDS_Mesh.cxx | 392 +- src/SMESHDS/SMESHDS_Mesh.hxx | 28 +- src/SMESHDS/SMESHDS_SubMesh.cxx | 298 +- src/SMESHDS/SMESHDS_SubMesh.hxx | 31 +- src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx | 4 +- src/SMESHGUI/SMESHGUI_GroupDlg.cxx | 18 +- src/SMESHGUI/SMESHGUI_MeshInfo.cxx | 24 +- src/SMESHGUI/SMESHGUI_PreVisualObj.cxx | 6 +- src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx | 2 +- src/SMESHUtils/SMESH_ComputeError.hxx | 38 +- src/SMESHUtils/SMESH_FillHole.cxx | 3 +- src/SMESHUtils/SMESH_FreeBorders.cxx | 2 +- src/SMESHUtils/SMESH_MeshAlgos.cxx | 18 +- src/SMESHUtils/SMESH_TryCatch.cxx | 27 +- src/SMESH_I/SMESH_Gen_i.cxx | 88 +- src/SMESH_I/SMESH_Measurements_i.cxx | 11 +- src/SMESH_I/SMESH_MeshEditor_i.cxx | 9 +- src/SMESH_I/SMESH_MeshPartDS.hxx | 26 +- src/SMESH_I/SMESH_Mesh_i.cxx | 196 +- src/SMESH_I/SMESH_PreMeshInfo.cxx | 8 +- src/StdMeshers/StdMeshers_Cartesian_3D.cxx | 2 +- src/StdMeshers/StdMeshers_FaceSide.cxx | 3 +- src/StdMeshers/StdMeshers_HexaFromSkin_3D.cxx | 2 +- src/StdMeshers/StdMeshers_Import_1D2D.cxx | 6 +- src/StdMeshers/StdMeshers_MEFISTO_2D.cxx | 7 +- src/StdMeshers/StdMeshers_Penta_3D.cxx | 15 +- src/StdMeshers/StdMeshers_Prism_3D.cxx | 7 +- src/StdMeshers/StdMeshers_ProjectionUtils.cxx | 8 +- src/StdMeshers/StdMeshers_Projection_1D2D.cxx | 6 +- src/StdMeshers/StdMeshers_Projection_2D.cxx | 6 +- src/StdMeshers/StdMeshers_Projection_3D.cxx | 4 +- .../StdMeshers_QuadToTriaAdaptor.cxx | 11 +- src/StdMeshers/StdMeshers_Quadrangle_2D.cxx | 24 +- src/StdMeshers/StdMeshers_ViscousLayers.cxx | 155 +- src/StdMeshers/StdMeshers_ViscousLayers2D.cxx | 6 +- 146 files changed, 5606 insertions(+), 10900 deletions(-) delete mode 100644 src/SMDS/Notes rename src/SMDS/{SMDS_MeshFace.cxx => SMDS_CellOfNodes.cxx} (61%) rename src/SMDS/{SMDS_MeshElementIDFactory.hxx => SMDS_CellOfNodes.hxx} (55%) delete mode 100644 src/SMDS/SMDS_EdgePosition.cxx create mode 100644 src/SMDS/SMDS_ElementFactory.cxx create mode 100644 src/SMDS/SMDS_ElementFactory.hxx create mode 100644 src/SMDS/SMDS_ElementHolder.cxx create mode 100644 src/SMDS/SMDS_ElementHolder.hxx delete mode 100644 src/SMDS/SMDS_FaceOfEdges.cxx delete mode 100644 src/SMDS/SMDS_FaceOfEdges.hxx delete mode 100644 src/SMDS/SMDS_IteratorOfElements.cxx delete mode 100644 src/SMDS/SMDS_IteratorOfElements.hxx delete mode 100644 src/SMDS/SMDS_Mesh0DElement.cxx delete mode 100644 src/SMDS/SMDS_MeshEdge.cxx delete mode 100644 src/SMDS/SMDS_MeshElementIDFactory.cxx delete mode 100644 src/SMDS/SMDS_MeshIDFactory.cxx delete mode 100644 src/SMDS/SMDS_MeshIDFactory.hxx delete mode 100644 src/SMDS/SMDS_MeshNodeIDFactory.cxx delete mode 100644 src/SMDS/SMDS_MeshNodeIDFactory.hxx delete mode 100644 src/SMDS/SMDS_PolyhedralVolumeOfNodes.cxx delete mode 100644 src/SMDS/SMDS_PolyhedralVolumeOfNodes.hxx delete mode 100644 src/SMDS/SMDS_Position.cxx delete mode 100644 src/SMDS/SMDS_QuadraticEdge.cxx delete mode 100644 src/SMDS/SMDS_QuadraticEdge.hxx delete mode 100644 src/SMDS/SMDS_QuadraticFaceOfNodes.cxx delete mode 100644 src/SMDS/SMDS_QuadraticFaceOfNodes.hxx delete mode 100644 src/SMDS/SMDS_QuadraticVolumeOfNodes.cxx delete mode 100644 src/SMDS/SMDS_QuadraticVolumeOfNodes.hxx delete mode 100644 src/SMDS/SMDS_VertexPosition.cxx delete mode 100644 src/SMDS/SMDS_VolumeOfFaces.cxx delete mode 100644 src/SMDS/SMDS_VolumeOfFaces.hxx delete mode 100644 src/SMDS/SMDS_VtkEdge.cxx delete mode 100644 src/SMDS/SMDS_VtkEdge.hxx delete mode 100644 src/SMDS/SMDS_VtkFace.cxx delete mode 100644 src/SMDS/SMDS_VtkFace.hxx delete mode 100644 src/SMDS/SMDS_VtkVolume.cxx delete mode 100644 src/SMDS/SMDS_VtkVolume.hxx diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index b1279a659..1ccd96f99 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -28,8 +28,6 @@ #include "SMDS_Mesh.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" -#include "SMDS_QuadraticEdge.hxx" -#include "SMDS_QuadraticFaceOfNodes.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_GroupBase.hxx" #include "SMESHDS_GroupOnFilter.hxx" @@ -253,26 +251,7 @@ bool NumericalFunctor::GetPoints(const SMDS_MeshElement* anElem, theRes.setElement( anElem ); // Get nodes of the element - SMDS_ElemIteratorPtr anIter; - - if ( anElem->IsQuadratic() ) { - switch ( anElem->GetType() ) { - case SMDSAbs_Edge: - anIter = dynamic_cast - (anElem)->interlacedNodesElemIterator(); - break; - case SMDSAbs_Face: - anIter = dynamic_cast - (anElem)->interlacedNodesElemIterator(); - break; - default: - anIter = anElem->nodesIterator(); - } - } - else { - anIter = anElem->nodesIterator(); - } - + SMDS_NodeIteratorPtr anIter= anElem->interlacedNodesIterator(); if ( anIter ) { SMESH_NodeXYZ p; while( anIter->more() ) { @@ -771,8 +750,8 @@ double AspectRatio::GetValue( long theId ) if ( myCurrElement && myCurrElement->GetVtkType() == VTK_QUAD ) { // issue 21723 - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid(); - if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() )) + vtkUnstructuredGrid* grid = const_cast( myMesh )->GetGrid(); + if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() )) aVal = Round( vtkMeshQuality::QuadAspectRatio( avtkCell )); } else @@ -1015,8 +994,8 @@ double AspectRatio3D::GetValue( long theId ) // Action from CoTech | ACTION 31.3: // EURIWARE BO: Homogenize the formulas used to calculate the Controls in SMESH to fit with // those of ParaView. The library used by ParaView for those calculations can be reused in SMESH. - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myCurrElement->getMeshId()]->getGrid(); - if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->getVtkId() )) + vtkUnstructuredGrid* grid = const_cast( myMesh )->GetGrid(); + if ( vtkCell* avtkCell = grid->GetCell( myCurrElement->GetVtkID() )) aVal = Round( vtkMeshQuality::TetAspectRatio( avtkCell )); } else @@ -1035,7 +1014,7 @@ double AspectRatio3D::GetValue( const TSequenceOfXYZ& P ) int nbNodes = P.size(); - if(myCurrElement->IsQuadratic()) { + if( myCurrElement->IsQuadratic() ) { if(nbNodes==10) nbNodes=4; // quadratic tetrahedron else if(nbNodes==13) nbNodes=5; // quadratic pyramid else if(nbNodes==15) nbNodes=6; // quadratic pentahedron @@ -1827,35 +1806,33 @@ bool Length2D::Value::operator<(const Length2D::Value& x) const void Length2D::GetValues(TValues& theValues) { TValues aValues; - SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); - for(; anIter->more(); ){ + for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); ) + { const SMDS_MeshFace* anElem = anIter->next(); - - if(anElem->IsQuadratic()) { - const SMDS_VtkFace* F = - dynamic_cast(anElem); + if ( anElem->IsQuadratic() ) + { // use special nodes iterator - SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator(); + SMDS_NodeIteratorPtr anIter = anElem->interlacedNodesIterator(); long aNodeId[4] = { 0,0,0,0 }; gp_Pnt P[4]; double aLength = 0; - const SMDS_MeshElement* aNode; - if(anIter->more()){ - aNode = anIter->next(); - const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode; - P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z()); + if ( anIter->more() ) + { + const SMDS_MeshNode* aNode = anIter->next(); + P[0] = P[1] = SMESH_NodeXYZ( aNode ); aNodeId[0] = aNodeId[1] = aNode->GetID(); aLength = 0; } - for(; anIter->more(); ){ - const SMDS_MeshNode* N1 = static_cast (anIter->next()); - P[2] = gp_Pnt(N1->X(),N1->Y(),N1->Z()); + for ( ; anIter->more(); ) + { + const SMDS_MeshNode* N1 = anIter->next(); + P[2] = SMESH_NodeXYZ( N1 ); aNodeId[2] = N1->GetID(); aLength = P[1].Distance(P[2]); if(!anIter->more()) break; - const SMDS_MeshNode* N2 = static_cast (anIter->next()); - P[3] = gp_Pnt(N2->X(),N2->Y(),N2->Z()); + const SMDS_MeshNode* N2 = anIter->next(); + P[3] = SMESH_NodeXYZ( N2 ); aNodeId[3] = N2->GetID(); aLength += P[2].Distance(P[3]); Value aValue1(aLength,aNodeId[1],aNodeId[2]); @@ -1872,28 +1849,28 @@ void Length2D::GetValues(TValues& theValues) theValues.insert(aValue2); } else { - SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); + SMDS_NodeIteratorPtr aNodesIter = anElem->nodeIterator(); long aNodeId[2] = {0,0}; gp_Pnt P[3]; double aLength; const SMDS_MeshElement* aNode; - if(aNodesIter->more()){ + if ( aNodesIter->more()) + { aNode = aNodesIter->next(); - const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode; - P[0] = P[1] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z()); + P[0] = P[1] = SMESH_NodeXYZ( aNode ); aNodeId[0] = aNodeId[1] = aNode->GetID(); aLength = 0; } - for(; aNodesIter->more(); ){ + for( ; aNodesIter->more(); ) + { aNode = aNodesIter->next(); - const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode; long anId = aNode->GetID(); - - P[2] = gp_Pnt(aNodes->X(),aNodes->Y(),aNodes->Z()); - + + P[2] = SMESH_NodeXYZ( aNode ); + aLength = P[1].Distance(P[2]); - + Value aValue(aLength,aNodeId[1],anId); aNodeId[1] = anId; P[1] = P[2]; @@ -1947,8 +1924,7 @@ double Deflection2D::GetValue( const TSequenceOfXYZ& P ) { gc += P(i+1); - if ( const SMDS_FacePosition* fPos = dynamic_cast - ( P.getElement()->GetNode( i )->GetPosition() )) + if ( SMDS_FacePositionPtr fPos = P.getElement()->GetNode( i )->GetPosition() ) { uv.ChangeCoord(1) += fPos->GetUParameter(); uv.ChangeCoord(2) += fPos->GetVParameter(); @@ -2124,59 +2100,24 @@ bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) cons void MultiConnection2D::GetValues(MValues& theValues) { if ( !myMesh ) return; - SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); - for(; anIter->more(); ){ - const SMDS_MeshFace* anElem = anIter->next(); - SMDS_ElemIteratorPtr aNodesIter; - if ( anElem->IsQuadratic() ) - aNodesIter = dynamic_cast - (anElem)->interlacedNodesElemIterator(); - else - aNodesIter = anElem->nodesIterator(); - long aNodeId[3] = {0,0,0}; + for ( SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); anIter->more(); ) + { + const SMDS_MeshFace* anElem = anIter->next(); + SMDS_NodeIteratorPtr aNodesIter = anElem->interlacedNodesIterator(); - //int aNbConnects=0; - const SMDS_MeshNode* aNode0; - const SMDS_MeshNode* aNode1; + const SMDS_MeshNode* aNode1 = anElem->GetNode( anElem->NbNodes() - 1 ); const SMDS_MeshNode* aNode2; - if(aNodesIter->more()){ - aNode0 = (SMDS_MeshNode*) aNodesIter->next(); - aNode1 = aNode0; - const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1; - aNodeId[0] = aNodeId[1] = aNodes->GetID(); - } - for(; aNodesIter->more(); ) { - aNode2 = (SMDS_MeshNode*) aNodesIter->next(); - long anId = aNode2->GetID(); - aNodeId[2] = anId; - - Value aValue(aNodeId[1],aNodeId[2]); - MValues::iterator aItr = theValues.find(aValue); - if (aItr != theValues.end()){ - aItr->second += 1; - //aNbConnects = nb; - } - else { - theValues[aValue] = 1; - //aNbConnects = 1; - } - //cout << "NodeIds: "<nodesIterator( /*idInceasingOrder=*/true ); + nIt = myMesh->nodesIterator(); for ( int i = 0; nIt->more(); ++i ) coords[i] = nIt->next()->Y(); if ( cg_coord_write( _fn, iBase, iZone, CGNS_ENUMV(RealDouble), "CoordinateY", &coords[0], &iC) != CG_OK ) return addMessage( cg_get_error(), /*fatal = */true ); // Z - nIt = myMesh->nodesIterator( /*idInceasingOrder=*/true ); + nIt = myMesh->nodesIterator(); for ( int i = 0; nIt->more(); ++i ) coords[i] = nIt->next()->Z(); if ( cg_coord_write( _fn, iBase, iZone, CGNS_ENUMV(RealDouble), "CoordinateZ", &coords[0], &iC) != CG_OK ) return addMessage( cg_get_error(), /*fatal = */true ); // store CGNS ids of nodes - nIt = myMesh->nodesIterator( /*idInceasingOrder=*/true ); + nIt = myMesh->nodesIterator(); for ( int i = 0; nIt->more(); ++i ) { const SMDS_MeshElement* n = nIt->next(); diff --git a/src/DriverDAT/DriverDAT_W_SMDS_Mesh.cxx b/src/DriverDAT/DriverDAT_W_SMDS_Mesh.cxx index 7ab288f86..403dad4f5 100644 --- a/src/DriverDAT/DriverDAT_W_SMDS_Mesh.cxx +++ b/src/DriverDAT/DriverDAT_W_SMDS_Mesh.cxx @@ -117,7 +117,7 @@ Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform() } SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator(); - const SMDS_VtkVolume* v; + const SMDS_MeshVolume* v; while(itVolumes->more()) { const SMDS_MeshElement * elem = itVolumes->next(); @@ -125,7 +125,7 @@ Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform() { fprintf(aFileId, "%d %d ", elem->GetID(), 500+elem->NbNodes()); - if (( v = dynamic_cast< const SMDS_VtkVolume*>( elem ))) + if (( v = myMesh->DownCast< SMDS_MeshVolume >( elem ))) { std::vector quant = v->GetQuantities(); if ( !quant.empty() ) @@ -146,7 +146,7 @@ Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform() fprintf(aFileId, "\n"); } - + fclose(aFileId); return aResult; diff --git a/src/DriverGMF/DriverGMF_Read.cxx b/src/DriverGMF/DriverGMF_Read.cxx index 54edf6a9c..420b1495b 100644 --- a/src/DriverGMF/DriverGMF_Read.cxx +++ b/src/DriverGMF/DriverGMF_Read.cxx @@ -444,6 +444,9 @@ Driver_Mesh::Status DriverGMF_Read::Perform() } } + myMesh->Modified(); + myMesh->CompactMesh(); + return status; } diff --git a/src/DriverMED/DriverMED_Family.cxx b/src/DriverMED/DriverMED_Family.cxx index a11ba4860..a31488e4a 100644 --- a/src/DriverMED/DriverMED_Family.cxx +++ b/src/DriverMED/DriverMED_Family.cxx @@ -574,3 +574,21 @@ void DriverMED_Family::Split (DriverMED_FamilyPtr by, common->myType = myType; } } + +//================================================================================ +/*! + * \brief Return a number of elements of a given type + */ +//================================================================================ + +size_t DriverMED_Family::NbElements( SMDSAbs_ElementType theType ) const +{ + if ( myTypes.size() < 2 ) + return myElements.size(); + + int nb = 0; + for ( ElementsSet::iterator e = myElements.begin(); e != myElements.end(); ++e ) + nb += ( theType == (*e)->GetType() ); + + return nb; +} diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h index c71ea7254..97157a2a3 100644 --- a/src/DriverMED/DriverMED_Family.h +++ b/src/DriverMED/DriverMED_Family.h @@ -119,9 +119,11 @@ class MESHDRIVERMED_EXPORT DriverMED_Family bool MemberOf(std::string theGroupName) const; - int GetGroupAttributVal() const; + int GetGroupAttributVal() const; void SetGroupAttributVal( int theValue); + size_t NbElements( SMDSAbs_ElementType ) const; + private: //! Initialize the tool by SMESHDS_GroupBase void Init (SMESHDS_GroupBase* group); diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index 000316955..14a648c8a 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -273,7 +273,7 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() if ( anIsElemNum && !aBallInfo->myElemNum->empty() ) maxID = *std::max_element( aBallInfo->myElemNum->begin(), aBallInfo->myElemNum->end() ); - myMesh->getGrid()->AllocateDiameters( maxID ); // performance optimization + myMesh->GetGrid()->AllocateDiameters( maxID ); // performance optimization // create balls SMDS_MeshElement* anElement; @@ -1038,8 +1038,6 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() aResult = addMessage( "Unknown exception", /*isFatal=*/true ); } #endif - if (myMesh) - myMesh->compactMesh(); // Mantis issue 0020483 if (aResult == DRS_OK && isDescConn) { @@ -1137,6 +1135,14 @@ void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup) if (( famVecPtr = myGroups2FamiliesMap.ChangeSeek( aGroupName ))) { + size_t groupSize = 0; + for ( size_t i = 0; i < famVecPtr->size(); ++i ) + { + DriverMED_FamilyPtr aFamily = (*famVecPtr)[i]; + groupSize += aFamily->NbElements( theGroup->GetType() ); + } + theGroup->SMDSGroup().Reserve( groupSize ); + for ( size_t i = 0; i < famVecPtr->size(); ++i ) { DriverMED_FamilyPtr aFamily = (*famVecPtr)[i]; diff --git a/src/DriverMED/DriverMED_W_Field.cxx b/src/DriverMED/DriverMED_W_Field.cxx index 57e8edf19..8317ae96b 100644 --- a/src/DriverMED/DriverMED_W_Field.cxx +++ b/src/DriverMED/DriverMED_W_Field.cxx @@ -33,7 +33,6 @@ #include "MED_Wrapper.hxx" #include "SMDS_IteratorOnIterators.hxx" #include "SMDS_MeshElement.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMDS_SetIterator.hxx" #include "SMESHDS_Mesh.hxx" @@ -101,7 +100,7 @@ bool DriverMED_W_Field::Set(SMESHDS_Mesh * mesh, for ( int iG = 0; iG < SMDSEntity_Last; ++iG ) { SMDSAbs_EntityType geom = (SMDSAbs_EntityType) iG; - SMDSAbs_ElementType t = SMDS_MeshCell::toSmdsType( geom ); + SMDSAbs_ElementType t = SMDS_MeshCell::ElemType( geom ); if ( t != _elemType ) continue; nbElems = mesh->GetMeshInfo().NbElements( geom ); diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index 75ebf667a..c33517ca0 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -31,9 +31,7 @@ #include "MED_Factory.hxx" #include "MED_Utilities.hxx" #include "SMDS_IteratorOnIterators.hxx" -#include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMDS_SetIterator.hxx" #include "SMESHDS_Mesh.hxx" @@ -360,10 +358,6 @@ namespace Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() { Status aResult = DRS_OK; - if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) { - INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!"); - return DRS_FAIL; - } try { //MESSAGE("Perform - myFile : "<next(); aBounds[0] = min(aBounds[0],aNode->X()); aBounds[1] = max(aBounds[1],aNode->X()); - + aBounds[2] = min(aBounds[2],aNode->Y()); aBounds[3] = max(aBounds[3],aNode->Y()); @@ -454,7 +448,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() } } - SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true); + SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(); switch ( aSpaceDimension ) { case 3: aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName)); @@ -857,7 +851,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() // Treat POLYEDREs // ---------------- - else if (aElemTypeData->_geomType == ePOLYEDRE ) + else if ( aElemTypeData->_geomType == ePOLYEDRE ) { elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA ); @@ -865,10 +859,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() // Count nb of nodes while ( elemIterator->more() ) { const SMDS_MeshElement* anElem = elemIterator->next(); - const SMDS_VtkVolume *aPolyedre = dynamic_cast(anElem); - if ( !aPolyedre ) continue; - nbPolyhedronNodes += aPolyedre->NbNodes(); - nbPolyhedronFaces += aPolyedre->NbFaces(); + nbPolyhedronNodes += anElem->NbNodes(); + nbPolyhedronFaces += anElem->NbFaces(); if ( ++iElem == aElemTypeData->_nbElems ) break; } @@ -893,8 +885,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() TInt iFace = 0, iNode = 0; while ( elemIterator->more() ) { - const SMDS_MeshElement* anElem = elemIterator->next(); - const SMDS_VtkVolume *aPolyedre = dynamic_cast(anElem); + const SMDS_MeshElement* anElem = elemIterator->next(); + const SMDS_MeshVolume *aPolyedre = myMesh->DownCast< SMDS_MeshVolume >( anElem ); if ( !aPolyedre ) continue; // index TInt aNbFaces = aPolyedre->NbFaces(); diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h index a9539b9e8..9c24099b4 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h @@ -40,6 +40,7 @@ class SMESHDS_Mesh; class SMESHDS_GroupBase; class SMESHDS_SubMesh; +class SMDS_MeshElement; class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh { diff --git a/src/DriverSTL/DriverSTL_R_SMDS_Mesh.cxx b/src/DriverSTL/DriverSTL_R_SMDS_Mesh.cxx index ae7e48cca..f1e1ea6ac 100644 --- a/src/DriverSTL/DriverSTL_R_SMDS_Mesh.cxx +++ b/src/DriverSTL/DriverSTL_R_SMDS_Mesh.cxx @@ -142,6 +142,9 @@ Driver_Mesh::Status DriverSTL_R_SMDS_Mesh::Perform() else aResult = readBinary( file ); + myMesh->Modified(); + myMesh->CompactMesh(); + return aResult; } diff --git a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx index 27576a613..10f7567f0 100644 --- a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx +++ b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx @@ -93,11 +93,11 @@ namespace DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh() { - if (myGroup != 0) - delete myGroup; + TGroupNamesMap::iterator grp2name = myGroupNames.begin(); + for ( ; grp2name != myGroupNames.end(); ++grp2name ) + delete grp2name->first; } - Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() { Kernel_Utils::Localizer loc; @@ -137,7 +137,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() } } // Move nodes to SI unit system - const double lenFactor = aUnitsRecord.factors[ UNV164::LENGTH_FACTOR ]; + const double lenFactor = aUnitsRecord.factors[ UNV164::LENGTH_FACTOR ]; if ( lenFactor != 1. ) { TDataSet::iterator nodeIter = aDataSet2411.begin(), nodeEnd; @@ -187,23 +187,23 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() else if(IsFace(aRec.fe_descriptor_id)) { //MESSAGE("add face " << aRec.label); switch(aRec.fe_descriptor_id){ - case 41: // Plane Stress Linear Triangle - case 51: // Plane Strain Linear Triangle - case 61: // Plate Linear Triangle - case 74: // Membrane Linear Triangle - case 81: // Axisymetric Solid Linear Triangle - case 91: // Thin Shell Linear Triangle + case 41: // Plane Stress Linear Triangle + case 51: // Plane Strain Linear Triangle + case 61: // Plate Linear Triangle + case 74: // Membrane Linear Triangle + case 81: // Axisymetric Solid Linear Triangle + case 91: // Thin Shell Linear Triangle anElement = myMesh->AddFaceWithID(aRec.node_labels[0], aRec.node_labels[1], aRec.node_labels[2], aRec.label); break; - case 42: // Plane Stress Parabolic Triangle - case 52: // Plane Strain Parabolic Triangle - case 62: // Plate Parabolic Triangle - case 72: // Membrane Parabolic Triangle - case 82: // Axisymetric Solid Parabolic Triangle + case 42: // Plane Stress Parabolic Triangle + case 52: // Plane Strain Parabolic Triangle + case 62: // Plate Parabolic Triangle + case 72: // Membrane Parabolic Triangle + case 82: // Axisymetric Solid Parabolic Triangle case 92: // Thin Shell Parabolic Triangle if ( aRec.node_labels.size() == 7 ) anElement = myMesh->AddFaceWithID(aRec.node_labels[0], @@ -224,12 +224,12 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() aRec.label); break; - case 44: // Plane Stress Linear Quadrilateral - case 54: // Plane Strain Linear Quadrilateral - case 64: // Plate Linear Quadrilateral - case 71: // Membrane Linear Quadrilateral + case 44: // Plane Stress Linear Quadrilateral + case 54: // Plane Strain Linear Quadrilateral + case 64: // Plate Linear Quadrilateral + case 71: // Membrane Linear Quadrilateral case 84: // Axisymetric Solid Linear Quadrilateral - case 94: // Thin Shell Linear Quadrilateral + case 94: // Thin Shell Linear Quadrilateral anElement = myMesh->AddFaceWithID(aRec.node_labels[0], aRec.node_labels[1], aRec.node_labels[2], @@ -237,12 +237,12 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() aRec.label); break; - case 45: // Plane Stress Parabolic Quadrilateral - case 55: // Plane Strain Parabolic Quadrilateral - case 65: // Plate Parabolic Quadrilateral - case 75: // Membrane Parabolic Quadrilateral - case 85: // Axisymetric Solid Parabolic Quadrilateral - case 95: // Thin Shell Parabolic Quadrilateral + case 45: // Plane Stress Parabolic Quadrilateral + case 55: // Plane Strain Parabolic Quadrilateral + case 65: // Plate Parabolic Quadrilateral + case 75: // Membrane Parabolic Quadrilateral + case 85: // Axisymetric Solid Parabolic Quadrilateral + case 95: // Thin Shell Parabolic Quadrilateral if ( aRec.node_labels.size() == 9 ) anElement = myMesh->AddFaceWithID(aRec.node_labels[0], aRec.node_labels[2], @@ -295,7 +295,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() aRec.node_labels[7], aRec.label); break; - + case 112: // Solid Linear Prism - PRISM6 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0], aRec.node_labels[2], @@ -305,7 +305,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() aRec.node_labels[4], aRec.label); break; - + case 113: // Solid Quadratic Prism - PRISM15 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0], aRec.node_labels[4], @@ -328,7 +328,7 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() aRec.node_labels[7], aRec.label); break; - + case 115: // Solid Linear Brick - HEX8 anElement = myMesh->AddVolumeWithID(aRec.node_labels[0], aRec.node_labels[3], @@ -396,101 +396,63 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() } } { - using namespace UNV2417; + using namespace UNV2417; TDataSet aDataSet2417; UNV2417::Read(in_stream,aDataSet2417); if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "< 0) { - myGroup = new SMDS_MeshGroup(myMesh); + if (aDataSet2417.size() > 0) + { TDataSet::const_iterator anIter = aDataSet2417.begin(); - for(; anIter != aDataSet2417.end(); anIter++){ - const TGroupId& aLabel = anIter->first; + for ( ; anIter != aDataSet2417.end(); anIter++ ) + { const TRecord& aRec = anIter->second; - - int aNodesNb = aRec.NodeList.size(); - int aElementsNb = aRec.ElementList.size(); + int aNodesNb = aRec.NodeList.size(); + int aElementsNb = aRec.ElementList.size(); bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0)); - int i; - if (aNodesNb > 0) { - SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node); + if ( aNodesNb > 0 ) + { + SMDS_MeshGroup* aNodesGroup = new SMDS_MeshGroup( myMesh ); std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName; int i = aGrName.find( "\r" ); if (i > 0) aGrName.erase (i, 2); - myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName)); - myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel)); + myGroupNames.insert( std::make_pair( aNodesGroup, aGrName )); - for (i = 0; i < aNodesNb; i++) { - const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]); - if (aNode) - aNodesGroup->Add(aNode); - } + for ( int i = 0; i < aNodesNb; i++ ) + if ( const SMDS_MeshNode* aNode = myMesh->FindNode( aRec.NodeList[i] )) + aNodesGroup->Add( aNode ); } - if (aElementsNb > 0){ - SMDS_MeshGroup* aEdgesGroup = 0; - SMDS_MeshGroup* aFacesGroup = 0; - SMDS_MeshGroup* aVolumeGroup = 0; + if ( aElementsNb > 0 ) + { + std::vector< SMDS_MeshGroup* > aGroupVec( SMDSAbs_NbElementTypes, (SMDS_MeshGroup*)0 ); + const char* aSuffix[] = { "", "", "_Edges", "_Faces", "_Volumes", "_0D", "_Balls" }; bool createdGroup = false; - - for (i = 0; i < aElementsNb; i++) { - const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]); - if (aElement) { - switch (aElement->GetType()) { - - case SMDSAbs_Edge: - if (!aEdgesGroup) { - aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge); - if (!useSuffix && createdGroup) useSuffix = true; - std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName; - int i = aEdgesGrName.find( "\r" ); - if (i > 0) - aEdgesGrName.erase (i, 2); - myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName)); - myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel)); - createdGroup = true; - } - aEdgesGroup->Add(aElement); - break; - - case SMDSAbs_Face: - if (!aFacesGroup) { - aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face); - if (!useSuffix && createdGroup) useSuffix = true; - std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName; - int i = aFacesGrName.find( "\r" ); - if (i > 0) - aFacesGrName.erase (i, 2); - myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName)); - myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel)); - createdGroup = true; - } - aFacesGroup->Add(aElement); - break; - - case SMDSAbs_Volume: - if (!aVolumeGroup) { - aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume); - if (!useSuffix && createdGroup) useSuffix = true; - std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName; - int i = aVolumeGrName.find( "\r" ); - if (i > 0) - aVolumeGrName.erase (i, 2); - myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName)); - myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel)); - createdGroup = true; - } - aVolumeGroup->Add(aElement); - break; - - default:; - } - } + for ( int i = 0; i < aElementsNb; i++) + { + const SMDS_MeshElement* aElement = myMesh->FindElement( aRec.ElementList[i] ); + if ( !aElement ) continue; + + SMDS_MeshGroup * & aGroup = aGroupVec[ aElement->GetType() ]; + if ( !aGroup ) + { + aGroup = new SMDS_MeshGroup( myMesh ); + if (!useSuffix && createdGroup) useSuffix = true; + std::string aGrName = aRec.GroupName; + int i = aGrName.find( "\r" ); + if ( i > 0 ) + aGrName.erase (i, 2); + if ( useSuffix ) + aGrName += aSuffix[ aElement->GetType() ]; + myGroupNames.insert( std::make_pair( aGroup, aGrName )); + createdGroup = true; + } + aGroup->Add(aElement); } } } } - } + } } catch(const std::exception& exc){ INFOS("Follow exception was cought:\n\t"<compactMesh(); + { + myMesh->Modified(); + myMesh->CompactMesh(); + } return aResult; } diff --git a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h index 4f7407dbb..42de629ca 100644 --- a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h +++ b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h @@ -30,32 +30,22 @@ #include -class SMDS_Mesh; class SMDS_MeshGroup; - -typedef std::map TGroupNamesMap; -typedef std::map TGroupIdMap; - typedef std::map TGroupNamesMap; -typedef std::map TGroupIdMap; class MESHDRIVERUNV_EXPORT DriverUNV_R_SMDS_Mesh: public Driver_SMDS_Mesh { public: - DriverUNV_R_SMDS_Mesh():Driver_SMDS_Mesh(),myGroup(0) {}; + DriverUNV_R_SMDS_Mesh():Driver_SMDS_Mesh() {}; ~DriverUNV_R_SMDS_Mesh(); - + virtual Status Perform(); - const SMDS_MeshGroup* GetGroup() const { return myGroup;} - const TGroupNamesMap& GetGroupNamesMap() const { return myGroupNames; } - const TGroupIdMap& GetGroupIdMap() const { return myGroupId; } + TGroupNamesMap& GetGroupNamesMap() { return myGroupNames; } private: - SMDS_MeshGroup* myGroup; TGroupNamesMap myGroupNames; - TGroupIdMap myGroupId; }; #endif diff --git a/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx b/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx index d8bca84a0..02ec7588b 100644 --- a/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx +++ b/src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx @@ -25,9 +25,6 @@ #include "DriverUNV_W_SMDS_Mesh.h" #include "SMDS_Mesh.hxx" -#include "SMDS_QuadraticEdge.hxx" -#include "SMDS_QuadraticFaceOfNodes.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMESHDS_GroupBase.hxx" #include "utilities.h" diff --git a/src/DriverUNV/UNV2417_Structure.hxx b/src/DriverUNV/UNV2417_Structure.hxx index c2868486b..183c0e4dc 100644 --- a/src/DriverUNV/UNV2417_Structure.hxx +++ b/src/DriverUNV/UNV2417_Structure.hxx @@ -25,8 +25,8 @@ #include #include -#include -#include +#include +#include namespace UNV2417{ @@ -34,9 +34,9 @@ namespace UNV2417{ typedef std::vector TListOfId; // Nodal connectivitiesList of Id struct TRecord{ - std::string GroupName; - TListOfId NodeList; - TListOfId ElementList; + std::string GroupName; + TListOfId NodeList; + TListOfId ElementList; }; typedef int TGroupId; // type of element label diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index a1a69ff3f..3f64bf4ab 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -31,7 +31,6 @@ #include "SMDS_BallElement.hxx" #include "SMDS_Mesh.hxx" #include "SMDS_MeshCell.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESHDS_Script.hxx" #include "SMESH_Actor.h" @@ -81,54 +80,6 @@ static int MYDEBUGWITHFILES = 0; Class : SMESH_VisualObjDef Description : Base class for all mesh objects to be visuilised */ - -//================================================================================= -// function : getCellType -// purpose : Get type of VTK cell -//================================================================================= -// static inline vtkIdType getCellType( const SMDSAbs_ElementType theType, -// const bool thePoly, -// const int theNbNodes ) -// { -// switch( theType ) -// { -// case SMDSAbs_0DElement: return VTK_VERTEX; - -// case SMDSAbs_Ball: return VTK_POLY_VERTEX; - -// case SMDSAbs_Edge: -// if( theNbNodes == 2 ) return VTK_LINE; -// else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE; -// else return VTK_EMPTY_CELL; - -// case SMDSAbs_Face : -// if (thePoly && theNbNodes>2 ) return VTK_POLYGON; -// else if ( theNbNodes == 3 ) return VTK_TRIANGLE; -// else if ( theNbNodes == 4 ) return VTK_QUAD; -// else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE; -// else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD; -// else if ( theNbNodes == 9 ) return VTK_BIQUADRATIC_QUAD; -// else if ( theNbNodes == 7 ) return VTK_BIQUADRATIC_TRIANGLE; -// else return VTK_EMPTY_CELL; - -// case SMDSAbs_Volume: -// if (thePoly && theNbNodes>3 ) return VTK_POLYHEDRON; //VTK_CONVEX_POINT_SET; -// else if ( theNbNodes == 4 ) return VTK_TETRA; -// else if ( theNbNodes == 5 ) return VTK_PYRAMID; -// else if ( theNbNodes == 6 ) return VTK_WEDGE; -// else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON; -// else if ( theNbNodes == 12 ) return VTK_HEXAGONAL_PRISM; -// else if ( theNbNodes == 10 ) return VTK_QUADRATIC_TETRA; -// else if ( theNbNodes == 20 ) return VTK_QUADRATIC_HEXAHEDRON; -// else if ( theNbNodes == 27 ) return VTK_TRIQUADRATIC_HEXAHEDRON; -// else if ( theNbNodes == 15 ) return VTK_QUADRATIC_WEDGE; -// else if ( theNbNodes == 13 ) return VTK_QUADRATIC_PYRAMID; //VTK_CONVEX_POINT_SET; -// else return VTK_EMPTY_CELL; - -// default: return VTK_EMPTY_CELL; -// } -// } - //================================================================================= // functions : SMESH_VisualObjDef // purpose : Constructor @@ -178,7 +129,7 @@ vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID ) if( this->GetMesh() ) { aNode = this->GetMesh()->FindNode(theObjID); } - return aNode ? aNode->getVtkId() : -1; + return aNode ? aNode->GetVtkID() : -1; } vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID ) @@ -188,7 +139,7 @@ vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID ) TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID); return i == myVTK2SMDSElems.end() ? -1 : i->second; } - return this->GetMesh()->fromVtkToSmds(theVTKID); + return this->GetMesh()->FromVtkToSmds(theVTKID); } vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID ) @@ -203,7 +154,7 @@ vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID ) if ( this->GetMesh() ) e = this->GetMesh()->FindElement(theObjID); - return e ? e->getVtkId() : -1; + return e ? e->GetVtkID() : -1; } //================================================================================= @@ -280,15 +231,15 @@ void SMESH_VisualObjDef::buildPrs(bool buildGrid) else { myLocalGrid = false; - if (!GetMesh()->isCompacted()) + if (!GetMesh()->IsCompacted()) { NulData(); // detach from the SMDS grid to allow immediate memory de-allocation in compactMesh() if ( MYDEBUG ) MESSAGE("*** buildPrs ==> compactMesh!"); - GetMesh()->compactMesh(); + GetMesh()->CompactMesh(); if ( SMESHDS_Mesh* m = dynamic_cast( GetMesh() )) // IPAL53915 m->GetScript()->SetModified(false); // drop IsModified set in compactMesh() } - vtkUnstructuredGrid *theGrid = GetMesh()->getGrid(); + vtkUnstructuredGrid *theGrid = GetMesh()->GetGrid(); updateEntitiesFlags(); myGrid->ShallowCopy(theGrid); //MESSAGE(myGrid->GetReferenceCount()); @@ -395,17 +346,16 @@ void SMESH_VisualObjDef::buildElemPrs() if((*anIter)->GetEntityType() != SMDSEntity_Polyhedra && (*anIter)->GetEntityType() != SMDSEntity_Quad_Polyhedra) { aCellsSize += (*anIter)->NbNodes() + 1; - } + } // Special case for the VTK_POLYHEDRON: // itsinput cellArray is of special format. - // [nCellFaces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...] + // [nCellFaces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...] else { - if( const SMDS_VtkVolume* ph = dynamic_cast(*anIter) ) { + if ( const SMDS_MeshVolume* ph = SMDS_Mesh::DownCast( *anIter )) { int nbFaces = ph->NbFaces(); aCellsSize += (1 + ph->NbFaces()); - for( int i = 1; i <= nbFaces; i++ ) { + for( int i = 1; i <= nbFaces; i++ ) aCellsSize += ph->NbFaceNodes(i); - } } } } @@ -467,16 +417,14 @@ void SMESH_VisualObjDef::buildElemPrs() if (aType == SMDSAbs_Volume && anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE anIdList->Reset(); - if ( const SMDS_VtkVolume* ph = dynamic_cast(anElem) ) { + if ( const SMDS_MeshVolume* ph = SMDS_Mesh::DownCast( anElem )) { int nbFaces = ph->NbFaces(); anIdList->InsertNextId(nbFaces); for( int i = 1; i <= nbFaces; i++ ) { anIdList->InsertNextId(ph->NbFaceNodes(i)); for(int j = 1; j <= ph->NbFaceNodes(i); j++) { - const SMDS_MeshNode* n = ph->GetFaceNode(i,j); - if(n) { - anIdList->InsertNextId(mySMDS2VTKNodes[n->GetID()]); - } + if ( const SMDS_MeshNode* n = ph->GetFaceNode( i, j )) + anIdList->InsertNextId( mySMDS2VTKNodes[ n->GetID() ]); } } } @@ -504,11 +452,8 @@ void SMESH_VisualObjDef::buildElemPrs() //Store diameters of the balls if(aScalars) { double aDiam = 0; - if(aType == SMDSAbs_Ball) { - if (const SMDS_BallElement* ball = dynamic_cast(anElem) ) { - aDiam = ball->GetDiameter(); - } - } + if (const SMDS_BallElement* ball = SMDS_Mesh::DownCast(anElem) ) + aDiam = ball->GetDiameter(); aScalars->SetTuple(aCurId,&aDiam); } @@ -573,14 +518,14 @@ bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId, vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid() { - if ( !myLocalGrid && !GetMesh()->isCompacted() ) + if ( !myLocalGrid && !GetMesh()->IsCompacted() ) { - NulData(); // detach from the SMDS grid to allow immediate memory de-allocation in compactMesh() - GetMesh()->compactMesh(); + NulData(); // detach from the SMDS grid to allow immediate memory de-allocation in CompactMesh() + GetMesh()->CompactMesh(); if ( SMESHDS_Mesh* m = dynamic_cast( GetMesh() )) // IPAL53915 - m->GetScript()->SetModified(false); // drop IsModified set in compactMesh() + m->GetScript()->SetModified(false); // drop IsModified set in CompactMesh() updateEntitiesFlags(); - vtkUnstructuredGrid *theGrid = GetMesh()->getGrid(); + vtkUnstructuredGrid *theGrid = GetMesh()->GetGrid(); myGrid->ShallowCopy(theGrid); } return myGrid; diff --git a/src/SMDS/CMakeLists.txt b/src/SMDS/CMakeLists.txt index e46dbf829..d05091e4e 100644 --- a/src/SMDS/CMakeLists.txt +++ b/src/SMDS/CMakeLists.txt @@ -42,96 +42,72 @@ SET(_link_LIBRARIES # header files / no moc processing SET(SMDS_HEADERS ObjectPool.hxx - SMDS_TypeOfPosition.hxx SMDSAbs_ElementType.hxx + SMDS_BallElement.hxx + SMDS_CellOfNodes.hxx + SMDS_Downward.hxx SMDS_EdgePosition.hxx SMDS_ElemIterator.hxx + SMDS_ElementFactory.hxx + SMDS_FaceOfNodes.hxx SMDS_FacePosition.hxx + SMDS_Iterator.hxx + SMDS_IteratorOnIterators.hxx + SMDS_LinearEdge.hxx SMDS_Mesh.hxx SMDS_Mesh0DElement.hxx - SMDS_LinearEdge.hxx + SMDS_MeshCell.hxx SMDS_MeshEdge.hxx SMDS_MeshElement.hxx - SMDS_MeshElementIDFactory.hxx - SMDS_MeshCell.hxx SMDS_MeshFace.hxx SMDS_MeshGroup.hxx - SMDS_MeshIDFactory.hxx + SMDS_MeshInfo.hxx SMDS_MeshNode.hxx - SMDS_MeshNodeIDFactory.hxx SMDS_MeshObject.hxx SMDS_MeshVolume.hxx + SMDS_PolygonalFaceOfNodes.hxx SMDS_Position.hxx + SMDS_SetIterator.hxx SMDS_SpacePosition.hxx + SMDS_StdIterator.hxx + SMDS_TypeOfPosition.hxx + SMDS_UnstructuredGrid.hxx SMDS_VertexPosition.hxx - SMDS_Iterator.hxx - SMDS_IteratorOfElements.hxx - SMDS_VolumeOfFaces.hxx SMDS_VolumeOfNodes.hxx - SMDS_VtkEdge.hxx - SMDS_VtkFace.hxx - SMDS_VtkVolume.hxx - SMDS_VtkCellIterator.hxx - SMDS_PolyhedralVolumeOfNodes.hxx - SMDS_FaceOfEdges.hxx - SMDS_FaceOfNodes.hxx - SMDS_PolygonalFaceOfNodes.hxx SMDS_VolumeTool.hxx - SMDS_QuadraticEdge.hxx - SMDS_QuadraticFaceOfNodes.hxx - SMDS_QuadraticVolumeOfNodes.hxx - SMDS_SetIterator.hxx + SMDS_VtkCellIterator.hxx + SMDS_ElementHolder.hxx SMESH_SMDS.hxx - SMDS_MeshInfo.hxx - SMDS_UnstructuredGrid.hxx - SMDS_Downward.hxx - SMDS_StdIterator.hxx - SMDS_IteratorOnIterators.hxx - SMDS_BallElement.hxx -) + chrono.hxx + ) # --- sources --- # sources / static SET(SMDS_SOURCES - chrono.cxx - SMDS_MeshObject.cxx - SMDS_MeshElement.cxx - SMDS_MeshCell.cxx - SMDS_Position.cxx - SMDS_EdgePosition.cxx + SMDS_BallElement.cxx + SMDS_Downward.cxx + SMDS_CellOfNodes.cxx + SMDS_ElementFactory.cxx + SMDS_FaceOfNodes.cxx SMDS_FacePosition.cxx - SMDS_SpacePosition.cxx - SMDS_VertexPosition.cxx - SMDS_MeshNode.cxx - SMDS_Mesh0DElement.cxx SMDS_LinearEdge.cxx - SMDS_MeshEdge.cxx - SMDS_MeshFace.cxx - SMDS_MeshVolume.cxx - SMDS_MeshNodeIDFactory.cxx - SMDS_MeshElementIDFactory.cxx - SMDS_MeshGroup.cxx - SMDS_MeshIDFactory.cxx + SMDS_MemoryLimit.cxx SMDS_Mesh.cxx - SMDS_IteratorOfElements.cxx - SMDS_VolumeOfFaces.cxx - SMDS_VolumeOfNodes.cxx - SMDS_VtkEdge.cxx - SMDS_VtkFace.cxx - SMDS_VtkVolume.cxx - SMDS_VtkCellIterator.cxx - SMDS_PolyhedralVolumeOfNodes.cxx - SMDS_FaceOfEdges.cxx - SMDS_FaceOfNodes.cxx + SMDS_MeshCell.cxx + SMDS_MeshElement.cxx + SMDS_MeshGroup.cxx + SMDS_MeshNode.cxx + SMDS_MeshObject.cxx + SMDS_MeshVolume.cxx SMDS_PolygonalFaceOfNodes.cxx - SMDS_VolumeTool.cxx - SMDS_QuadraticEdge.cxx - SMDS_QuadraticFaceOfNodes.cxx - SMDS_QuadraticVolumeOfNodes.cxx + SMDS_SpacePosition.cxx SMDS_UnstructuredGrid.cxx - SMDS_Downward.cxx - SMDS_BallElement.cxx + SMDS_VolumeOfNodes.cxx + SMDS_VolumeTool.cxx + SMDS_VtkCellIterator.cxx + SMDS_ElementHolder.cxx + chrono.cxx ) # bin programs diff --git a/src/SMDS/Notes b/src/SMDS/Notes deleted file mode 100644 index 830ffb5ae..000000000 --- a/src/SMDS/Notes +++ /dev/null @@ -1,235 +0,0 @@ ---> Branche V6_main - -Problemes en cours -================== -- a faire -+ en cours, OK mais perfectible -* OK - -+ visualisation de groupe (type d'element): on voit tout le maillage, mais le groupe est OK - creation d'une structure vtkUnstructuredGrid locale : iteration un peu lourde, et pas de partage avec la structure du maillage (pas evident) -- inversion d'un volume (tetra): exception -- script de creation de noeuds et d'elements: OK, mais pas compatible avec version precedente (numerotation noeuds differente) -+ affichage numeros noeuds: numeros en trop sur (O,0,0) pas systematique, trouver la condition (enlever dans vtkUnstructuredGrid ?) - ==> purge systematique noeuds et cellules en trop dans compactage grid. -+ gestion du mode embedded mal faite lors d'un script python : journal commandes intempestif -- affichage des noeuds apres changement lineaire <--> quadratique à l'IHM : pas pris en compte, alors que maillage OK, - mais script OK - ==> cassé apres mode embedded ou elimination noeuds en trop ? -- extrusion elements 2D along a path : affichage apres calcul pas toujours OK (filaire) -- branche git a ouvrir pour merge avec V5_1_4_BR tag V5_1_4rc1 - -A tester, non pris en compte -============================ -- engine standalone -- polyedres (attendre vtk) - - -=============================== Hypothese de refonte de l'API de SMDS - -n'utiliser que vtkUnstructuredGrid, ne pas avor d'objets SMDS_MeshElement mais seulement des index de vtkUnstructuredGrid. -2987 usages de SMDS_MeshNodes -810 SMDS_MeshElement -... -==> en dernier ressort, lourd -================================================================================ - -Essai a API SMDS a peu pres constante -===================================== - -SMDS_Mesh - static vector _meshList; --> retrouver un SMDS_Mesh - vtkUnstructuredGrid* myGrid; - - vector myNodes; --> meme index que dans le pointSet de myGrid - vector myCells; --> index = ID client, pas le meme index que dans le cellTypes de myGrid (ID vtk) - - - -SMDS_MeshElement - int myID; --> index dans la structure geree par SMDS_Mesh - int myMeshId; --> pour retrouver SMDS_Mesh* dans _meshList - int myShapeId; --> pour retrouver la subShape - - -SMDS_MeshNode: SMDS_MeshElement - SMDS_PositionPtr myPosition; --> A REVOIR : objet position dans la shape geom - ##vector myInverseElements; --> SUPPRIME : pour retrouver les elements, vtkCellLinks - - -SMDS_MeshCell: SMDS_MeshElement --> generique pour tous les elements (cells) - int myVtkID --> A SUPPRIMER - -SMDS_MeshVolume: SMDS_MeshCell - -SMDS_VolumeOfNodes: SMDS_MeshVolume --> Garder temporairement, utilisation dans StdMesher et SMDS_VolumeTool - const SMDS_MeshNode **myNodes; --> Couteux - int myNbNodes; --> "" - -SMDS_VolumeVtkNodes: SMDS_MeshVolume --> Utiliser systematiquement dans SMDS, - --> IMPLEMENTER. - - -SMDS_MeshElementIDFactory: SMDS_MeshNodeIDFactory - vector myIDElements; // index = ID client, value = ID vtk --> A SUPPRIMER, ne sert que dans SMDS_MeshElementIDFactory - vector myVtkIndex; // index = ID vtk, value = ID client --> A REPORTER dans SMDS_Mesh - - - - -========= TODO ============ - -enlever vtkId de SMDS_MeshCell, utiliser SMDS_MeshElementIDFactory. - -ajouter ID dans SMDS_Mesh::createTriangle -verifier ID dans SMDS_Mesh::Find*OrCreate - -=================================================== -occupation memoire cube 100*100*100 sans affichage -NOTES: -- sur Debian Sarge 64 bits, les mesures malloc_stat() semblent coherentes - avec une mesure externe globale(recherche du passage en swap du process). -- sur Ubuntu 9.10 64 bits, les mesures malloc_stat() donnent des resultats bizarres (surestimation ?), - mais la mesure avec l'outil KDE de surveillance systeme est OK avec la recherche du swap. - - -Reference : V513 Debian Sarge 64 bits: --> 463 - 33 = 430 Mo -------------------------------------- -Total (incl. mmap): -system bytes = 43757568 -in use bytes = 32909584 = 33M -max mmap regions = 41 -max mmap bytes = 16371712 ----- -Total (incl. mmap): -system bytes = 464670720 -in use bytes = 463105120 = 463M -max mmap regions = 47 -max mmap bytes = 28188672 - -Debian Sarge 64 bits, vtkUnstructuredGrid nodes et hexa, 4 janvier 2010 --> 512 - 41 = 471M ------------------------------------ - -Total (incl. mmap): -system bytes = 52133888 -in use bytes = 41340320 : 41M -max mmap regions = 72 -max mmap bytes = 24625152 ----- -Total (incl. mmap): -system bytes = 520560640 -in use bytes = 518735584 : 512M -max mmap regions = 88 -max mmap bytes = 198385664 - -idem avec pool SMDS_MeshNodes --> 483 -33 = 450M ------------------------------ -Total (incl. mmap): -system bytes = 43696128 -in use bytes = 32915184 : 33M -max mmap regions = 41 -max mmap bytes = 16371712 ----- -Total (incl. mmap): -system bytes = 484806656 -in use bytes = 482980992 : 483M -max mmap regions = 58 -max mmap bytes = 184557568 - -idem ci-dessus + pool SMDS_VolumeVtkNodes --> 475 -33 = 442M (git: add ObjectPool.hxx) ------------------------------------------ - -Total (incl. mmap): -system bytes = 43200512 -in use bytes = 32908576 : 33M -max mmap regions = 41 -max mmap bytes = 16371712 ----- -Total (incl. mmap): -system bytes = 478068736 -in use bytes = 475144400 : 475M -max mmap regions = 59 -max mmap bytes = 184692736 - -remplacement SMDS_PositionPtr: (boost::shared_ptr --> SMDS_Position*) --> 436 - 35 = 401M (git SMDS_Position) ------------------------------------------------------------------------------------- -Total (incl. mmap): -system bytes = 45408256 -in use bytes = 35097680 : 35M -max mmap regions = 47 -max mmap bytes = 18116608 ----- -Total (incl. mmap): -system bytes = 438935552 -in use bytes = 436116560 : 436M -max mmap regions = 65 -max mmap bytes = 186437632 - -simplification SMDS_SpacePosition (pas de double[3]) --> 418 -33 = 385M (git SMDS_SpacePosition) ----------------------------------------------------- -Total (incl. mmap): -system bytes = 42582016 -in use bytes = 32883552 : 33M -max mmap regions = 41 -max mmap bytes = 16371712 ----- -Total (incl. mmap): -system bytes = 421728256 -in use bytes = 418378000 : 418M -max mmap regions = 58 -max mmap bytes = 183640064 - -sizeof(SMDS_MeshElement) 16 -sizeof(SMDS_MeshNode) 24 -sizeof(SMDS_MeshCell) 24 -sizeof(SMDS_VolumeVtkNodes) 24 -sizeof(SMDS_Position) 16 -sizeof(SMDS_SpacePosition) 16 - -impact d'un int en plus dans SMDS_MeshElement --> 426 - 33 = 393M ---------------------------------------------- - -sizeof(SMDS_MeshElement) 24 -sizeof(SMDS_MeshNode) 32 --> on retrouve bien les 8M -sizeof(SMDS_MeshCell) 24 -sizeof(SMDS_VolumeVtkNodes) 24 -sizeof(SMDS_Position) 16 -sizeof(SMDS_SpacePosition) 16 - -Total (incl. mmap): -system bytes = 43192320 -in use bytes = 32681088 : 33M -max mmap regions = 41 -max mmap bytes = 16371712 ----- -Total (incl. mmap): -system bytes = 429334528 -in use bytes = 426424576 : 426M -max mmap regions = 59 -max mmap bytes = 184692736 - -remplacement std::set par std::vector dans SMESHDS_SubMesh --> 347 - 35 = 312M ----------------------------------------------------------- -sizeof(SMDS_MeshElement) 24 -sizeof(SMDS_MeshNode) 32 -sizeof(SMDS_MeshCell) 24 -sizeof(SMDS_VolumeVtkNodes) 24 -sizeof(SMDS_Position) 16 -sizeof(SMDS_SpacePosition) 16 - -Total (incl. mmap): -system bytes = 45404160 -in use bytes = 35132160 --> 35M -max mmap regions = 49 -max mmap bytes = 17723392 ----- -Total (incl. mmap): -system bytes = 349831168 -in use bytes = 346885424 --> 347M -max mmap regions = 73 -max mmap bytes = 204148736 - -Ce resultat est coherent avec une recherche de swap sur une machine a 8Go de memoire: -Cube a 270**3 mailles (~20M mailles) --> 6.2 Go (idem Debian Sarge et Ubuntu 9.10, 64 bits) -Le meme avec V5.1.3 --> 14 Go (swap) - diff --git a/src/SMDS/ObjectPool.hxx b/src/SMDS/ObjectPool.hxx index ef514b353..d7eea28c3 100644 --- a/src/SMDS/ObjectPool.hxx +++ b/src/SMDS/ObjectPool.hxx @@ -28,9 +28,9 @@ namespace { // assure deallocation of memory of a vector - template void clearVector(std::vector& v ) + template void clearVector(Y & v ) { - std::vector emptyVec; v.swap( emptyVec ); + Y emptyVec; v.swap( emptyVec ); } } diff --git a/src/SMDS/SMDS_BallElement.cxx b/src/SMDS/SMDS_BallElement.cxx index fd3859681..7a10f79d3 100644 --- a/src/SMDS/SMDS_BallElement.cxx +++ b/src/SMDS/SMDS_BallElement.cxx @@ -24,78 +24,24 @@ #include "SMDS_BallElement.hxx" -#include "SMDS_ElemIterator.hxx" #include "SMDS_Mesh.hxx" #include "SMDS_MeshNode.hxx" -#include "SMDS_VtkCellIterator.hxx" -SMDS_BallElement::SMDS_BallElement() +void SMDS_BallElement::init(const SMDS_MeshNode * node, double diameter ) { - SMDS_MeshCell::init(); -} - -SMDS_BallElement::SMDS_BallElement (const SMDS_MeshNode * node, double diameter) -{ - init( node->getVtkId(), diameter, SMDS_Mesh::_meshList[ node->getMeshId() ] ); -} - -SMDS_BallElement::SMDS_BallElement(vtkIdType nodeId, double diameter, SMDS_Mesh* mesh) -{ - init( nodeId, diameter, mesh ); -} - -void SMDS_BallElement::init(vtkIdType nodeId, double diameter, SMDS_Mesh* mesh) -{ - SMDS_MeshCell::init(); - myMeshId = mesh->getMeshId(); - myVtkID = mesh->getGrid()->InsertNextLinkedCell( GetVtkType(), 1, &nodeId ); - mesh->getGrid()->SetBallDiameter( myVtkID, diameter ); - mesh->setMyModified(); + int nodeVtkID = node->GetVtkID(); + int vtkID = getGrid()->InsertNextLinkedCell( toVtkType( SMDSEntity_Ball ), 1, &nodeVtkID ); + setVtkID( vtkID ); + getGrid()->SetBallDiameter( GetVtkID(), diameter ); } double SMDS_BallElement::GetDiameter() const { - return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetBallDiameter( myVtkID ); + return getGrid()->GetBallDiameter( GetVtkID() ); } void SMDS_BallElement::SetDiameter(double diameter) { - SMDS_Mesh::_meshList[myMeshId]->getGrid()->SetBallDiameter( myVtkID, diameter ); -} - -bool SMDS_BallElement::ChangeNode (const SMDS_MeshNode * node) -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - pts[0] = node->getVtkId(); - SMDS_Mesh::_meshList[myMeshId]->setMyModified(); - return true; -} - -void SMDS_BallElement::Print (std::ostream & OS) const -{ - OS << "ball<" << GetID() << "> : "; + getGrid()->SetBallDiameter( GetVtkID(), diameter ); + GetMesh()->setMyModified(); } - -const SMDS_MeshNode* SMDS_BallElement::GetNode (const int ind) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts, *pts; - grid->GetCellPoints( myVtkID, npts, pts ); - return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ 0 ]); -} - -SMDS_ElemIteratorPtr SMDS_BallElement::elementsIterator (SMDSAbs_ElementType type) const -{ - switch (type) - { - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); - default: - ; - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); - } -} - diff --git a/src/SMDS/SMDS_BallElement.hxx b/src/SMDS/SMDS_BallElement.hxx index c62034de7..4e7c6346e 100644 --- a/src/SMDS/SMDS_BallElement.hxx +++ b/src/SMDS/SMDS_BallElement.hxx @@ -27,34 +27,23 @@ #include "SMESH_SMDS.hxx" #include "SMDS_MeshCell.hxx" -#include - +/*! + * \brief Ball element. This type is not allocated. + * It is only used as function argument type to provide more clear semantic + * and to provide API specific to ball element + */ class SMDS_EXPORT SMDS_BallElement: public SMDS_MeshCell { + void init(const SMDS_MeshNode * node, double diameter); + + friend class SMDS_Mesh; + public: - SMDS_BallElement(); - SMDS_BallElement (const SMDS_MeshNode * node, double diameter); - SMDS_BallElement(vtkIdType nodeId, double diameter, SMDS_Mesh* mesh); - void init(vtkIdType nodeId, double diameter, SMDS_Mesh* mesh); + double GetDiameter() const; - void SetDiameter(double diameter); - bool ChangeNode (const SMDS_MeshNode * node); - - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes) { return ChangeNode( nodes[0] ); } - virtual void Print (std::ostream & OS) const; - - virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Ball; } - virtual vtkIdType GetVtkType() const { return VTK_POLY_VERTEX; } - virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Ball; } - virtual SMDSAbs_GeometryType GetGeomType() const { return SMDSGeom_BALL; } - virtual int NbNodes() const { return 1; } - virtual int NbEdges() const { return 0; } - virtual int NbFaces() const { return 0; } - virtual const SMDS_MeshNode* GetNode (const int ind) const; - - protected: - SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const; + void SetDiameter(double diameter); + + static SMDSAbs_ElementType Type() { return SMDSAbs_Ball; } }; #endif diff --git a/src/SMDS/SMDS_MeshFace.cxx b/src/SMDS/SMDS_CellOfNodes.cxx similarity index 61% rename from src/SMDS/SMDS_MeshFace.cxx rename to src/SMDS/SMDS_CellOfNodes.cxx index 126945596..bea007ff0 100644 --- a/src/SMDS/SMDS_MeshFace.cxx +++ b/src/SMDS/SMDS_CellOfNodes.cxx @@ -22,14 +22,41 @@ // SMESH SMDS : implementation of Salome mesh data structure // -#include "SMDS_MeshFace.hxx" -SMDSAbs_ElementType SMDS_MeshFace::GetType() const +#include "SMDS_CellOfNodes.hxx" + +SMDS_CellOfNodes::SMDS_CellOfNodes( int id, int shapeID ) + : myID( id ) +{ + setShapeID( shapeID ); +} + +void SMDS_CellOfNodes::setID(const int id) +{ + myID = id; +} + +int SMDS_CellOfNodes::GetID() const +{ + return myID; +} + +void SMDS_CellOfNodes::setShapeID( const int shapeID ) +{ + myShapeID = ( shapeID << BITS_SHIFT ) | ( myShapeID & BIT_IS_MARKED ); +} + +int SMDS_CellOfNodes::GetShapeID() const +{ + return myShapeID >> BITS_SHIFT; +} + +void SMDS_CellOfNodes::setIsMarked( bool is ) const { - return SMDSAbs_Face; + const_cast< SMDS_CellOfNodes* >( this )->myShapeID = ( myShapeID & ~BIT_IS_MARKED ) | is; } -vtkIdType SMDS_MeshFace::GetVtkType() const +bool SMDS_CellOfNodes::isMarked() const { - return VTK_POLY_LINE; // --- must be reimplemented in derived classes + return myShapeID & BIT_IS_MARKED; } diff --git a/src/SMDS/SMDS_MeshElementIDFactory.hxx b/src/SMDS/SMDS_CellOfNodes.hxx similarity index 55% rename from src/SMDS/SMDS_MeshElementIDFactory.hxx rename to src/SMDS/SMDS_CellOfNodes.hxx index f75d24f5c..4880d0746 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.hxx +++ b/src/SMDS/SMDS_CellOfNodes.hxx @@ -21,42 +21,48 @@ // // SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_MeshElementIDFactory.hxx +// File : SMDS_CellOfNodes.hxx // Module : SMESH // -#ifndef _SMDS_MeshElementIDFactory_HeaderFile -#define _SMDS_MeshElementIDFactory_HeaderFile +#ifndef _SMDS_CellOfNodes_HeaderFile +#define _SMDS_CellOfNodes_HeaderFile #include "SMESH_SMDS.hxx" + +#include "SMDS_MeshElement.hxx" -#include "SMDS_MeshNodeIDFactory.hxx" +// ============================================================ +/*! + * \brief Base class for elements of not contained in the mesh + */ +// ============================================================ -#include -class SMDS_MeshElement; -class SMDS_Mesh; - -class SMDS_EXPORT SMDS_MeshElementIDFactory:public SMDS_MeshNodeIDFactory +class SMDS_EXPORT SMDS_CellOfNodes : public SMDS_MeshElement { public: - friend class SMDS_Mesh; - - SMDS_MeshElementIDFactory(); - bool BindID(int ID, SMDS_MeshElement * elem); - int SetInVtkGrid(SMDS_MeshElement * elem); - SMDS_MeshElement * MeshElement(int ID); - virtual int GetFreeID(); - virtual void ReleaseID(int ID, int vtkId = -1); - SMDS_ElemIteratorPtr elementsIterator() const; - virtual void Clear(); - -protected: - virtual void updateMinMax() const; - void updateMinMax(int id) const - { - if (id > myMax) myMax = id; - if (id < myMin) myMin = id; - } -}; + virtual int GetID() const; + virtual int GetShapeID() const; + + virtual void setIsMarked( bool is ) const; + virtual bool isMarked() const; + + virtual VTKCellType GetVtkType() const { return VTK_EMPTY_CELL; } + + protected: + + SMDS_CellOfNodes( int id = -1, int shapeID = 0); + + virtual void setID( const int id); + virtual void setShapeID( const int shapeID ); + + int myID; + int myShapeID; + + enum Bits { // use the 1st right bit of myShapeId to set/unset a mark + BIT_IS_MARKED = 1, + BITS_SHIFT = 1 + }; +}; #endif diff --git a/src/SMDS/SMDS_Downward.cxx b/src/SMDS/SMDS_Downward.cxx index c4ead4dac..1955fa892 100644 --- a/src/SMDS/SMDS_Downward.cxx +++ b/src/SMDS/SMDS_Downward.cxx @@ -1145,7 +1145,7 @@ void SMDS_DownTetra::getOrderedNodesOfFace(int cellId, std::vector& o return; } } - MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); } @@ -1253,7 +1253,7 @@ void SMDS_DownQuadTetra::getOrderedNodesOfFace(int cellId, std::vector_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); } @@ -1387,7 +1387,7 @@ void SMDS_DownPyramid::getOrderedNodesOfFace(int cellId, std::vector& return; } } - MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); } @@ -1531,7 +1531,7 @@ void SMDS_DownQuadPyramid::getOrderedNodesOfFace(int cellId, std::vector_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2] << " " << orderedNodes[3]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); } @@ -1694,7 +1694,7 @@ void SMDS_DownPenta::getOrderedNodesOfFace(int cellId, std::vector& o return; } } - MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); } @@ -1845,7 +1845,7 @@ void SMDS_DownQuadPenta::getOrderedNodesOfFace(int cellId, std::vector_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); } @@ -2000,7 +2000,7 @@ void SMDS_DownHexa::getOrderedNodesOfFace(int cellId, std::vector& or return; } } - MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2] << " " << orderedNodes[3]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); MESSAGE(nodes[4] << " " << nodes[5] << " " << nodes[6] << " " << nodes[7]); @@ -2132,7 +2132,7 @@ void SMDS_DownQuadHexa::getOrderedNodesOfFace(int cellId, std::vector return; } } - MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->fromVtkToSmds(_vtkCellIds[cellId])); + MESSAGE("=== Problem volume " << _vtkCellIds[cellId] << " " << _grid->_mesh->FromVtkToSmds(_vtkCellIds[cellId])); MESSAGE(orderedNodes[0] << " " << orderedNodes[1] << " " << orderedNodes[2] << " " << orderedNodes[3]); MESSAGE(nodes[0] << " " << nodes[1] << " " << nodes[2] << " " << nodes[3]); } diff --git a/src/SMDS/SMDS_EdgePosition.cxx b/src/SMDS/SMDS_EdgePosition.cxx deleted file mode 100644 index 9ac728d64..000000000 --- a/src/SMDS/SMDS_EdgePosition.cxx +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_EdgePosition.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#include "SMDS_EdgePosition.hxx" - -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : SMDS_EdgePosition -//purpose : -//======================================================================= - -SMDS_EdgePosition::SMDS_EdgePosition(const double aUParam): myUParameter(aUParam) -{ - //MESSAGE("********************************* SMDS_EdgePosition " << myUParameter); -} - -/** -*/ -SMDS_TypeOfPosition SMDS_EdgePosition::GetTypeOfPosition() const -{ - //MESSAGE("###################################### SMDS_EdgePosition::GetTypeOfPosition"); - return SMDS_TOP_EDGE; -} - -void SMDS_EdgePosition::SetUParameter(double aUparam) -{ - //MESSAGE("############################### SMDS_EdgePosition::SetUParameter " << aUparam); - myUParameter = aUparam; -} - -//======================================================================= -//function : GetUParameter -//purpose : -//======================================================================= - -double SMDS_EdgePosition::GetUParameter() const -{ - //MESSAGE("########################## SMDS_EdgePosition::GetUParameter " << myUParameter); - return myUParameter; -} diff --git a/src/SMDS/SMDS_EdgePosition.hxx b/src/SMDS/SMDS_EdgePosition.hxx index f0870e970..e2c9cf19e 100644 --- a/src/SMDS/SMDS_EdgePosition.hxx +++ b/src/SMDS/SMDS_EdgePosition.hxx @@ -31,18 +31,19 @@ #include "SMDS_Position.hxx" -class SMDS_EXPORT SMDS_EdgePosition:public SMDS_Position +class SMDS_EXPORT SMDS_EdgePosition : public SMDS_Position { - public: - SMDS_EdgePosition(const double aUParam=0); - SMDS_TypeOfPosition GetTypeOfPosition() const; - void SetUParameter(double aUparam); - double GetUParameter() const; + public: + SMDS_EdgePosition(const double aUParam=0) : myUParameter( aUParam ) {} + virtual SMDS_TypeOfPosition GetTypeOfPosition() const { return SMDS_TOP_EDGE; } + virtual void SetUParameter(double aUparam) { myUParameter = aUparam; } + virtual double GetUParameter() const { return myUParameter; } + virtual const double* GetParameters() const { return &myUParameter; } - private: + private: - double myUParameter; + double myUParameter; }; diff --git a/src/SMDS/SMDS_ElementFactory.cxx b/src/SMDS/SMDS_ElementFactory.cxx new file mode 100644 index 000000000..a6d61e849 --- /dev/null +++ b/src/SMDS/SMDS_ElementFactory.cxx @@ -0,0 +1,880 @@ +// Copyright (C) 2007-2016 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, or (at your option) any later version. +// +// 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 : SMDS_ElementFactory.cxx +// Module : SMESH +// + +#include "SMDS_ElementFactory.hxx" + +#include "ObjectPool.hxx" +#include "SMDS_EdgePosition.hxx" +#include "SMDS_FacePosition.hxx" +#include "SMDS_Mesh.hxx" +#include "SMDS_SpacePosition.hxx" +#include "SMDS_VertexPosition.hxx" + +namespace +{ + // nb of elements allocated by SMDS_ElementChunk at once + const int theChunkSize = 1024; + + const int theDefaultShapeDim = 3; + + // classes allowing to modify parameters of SMDS_Position stored in SMDS_ElementFactory + + struct _EdgePosition : public SMDS_EdgePosition + { + TParam* myUParameter; + + _EdgePosition( TParam* aUParam ) : myUParameter( aUParam ) + { SMDS_EdgePosition::SetUParameter( aUParam[0]); } + virtual void SetUParameter(double aUparam) + { *myUParameter = (TParam) aUparam; SMDS_EdgePosition::SetUParameter( aUparam ); } + }; + + struct _FacePosition : public SMDS_FacePosition + { + TParam* myParameter; + + _FacePosition(TParam* aParam) : myParameter( aParam ) + { SMDS_FacePosition::SetParameters( aParam[0], aParam[1] ); } + virtual void SetUParameter(double aUparam) + { myParameter[0] = (TParam) aUparam; SMDS_FacePosition::SetUParameter( aUparam ); } + virtual void SetVParameter(double aVparam) + { myParameter[1] = (TParam) aVparam; SMDS_FacePosition::SetVParameter( aVparam ); } + virtual void SetParameters(double aU, double aV) + { myParameter[0] = aU; myParameter[1] = aV; SMDS_FacePosition::SetParameters( aU, aV ); } + }; +} + +//================================================================================ +/*! + * \brief Create a factory of cells or nodes in a given mesh + */ +//================================================================================ + +SMDS_ElementFactory::SMDS_ElementFactory( SMDS_Mesh* mesh, const bool isNodal ) + : myIsNodal( isNodal ), myMesh( mesh ), myNbUsedElements( 0 ) +{ +} + +//================================================================================ +/*! + * \brief Destructor + */ +//================================================================================ + +SMDS_ElementFactory::~SMDS_ElementFactory() +{ + myChunksWithUnused.clear(); + myChunks.clear(); +} + +//================================================================================ +/*! + * \brief Return a number of elements in a chunk + * \return int - chunk size + */ +//================================================================================ + +int SMDS_ElementFactory::ChunkSize() +{ + return theChunkSize; +} + +//================================================================================ +/*! + * \brief Return minimal ID of a non-used element + * \return int - minimal element ID + */ +//================================================================================ + +int SMDS_ElementFactory::GetFreeID() +{ + if ( myChunksWithUnused.empty() ) + { + int id0 = myChunks.size() * theChunkSize + 1; + myChunks.push_back( new SMDS_ElementChunk( this, id0 )); + } + SMDS_ElementChunk * chunk = (*myChunksWithUnused.begin()); + return chunk->GetUnusedID(); +} + +//================================================================================ +/*! + * \brief Return maximal ID of an used element + * \return int - element ID + */ +//================================================================================ + +int SMDS_ElementFactory::GetMaxID() +{ + int id = 0; + TIndexRanges usedRanges; + for ( int i = myChunks.size() - 1; i >= 0; --i ) + if ( myChunks[i].GetUsedRanges().GetIndices( true, usedRanges )) + { + int index = usedRanges.back().second-1; + id = myChunks[i].Get1stID() + index; + break; + } + return id; +} + +//================================================================================ +/*! + * \brief Return minimal ID of an used element + * \return int - element ID + */ +//================================================================================ + +int SMDS_ElementFactory::GetMinID() +{ + int id = 0; + TIndexRanges usedRanges; + for ( size_t i = 0; i < myChunks.size(); ++i ) + if ( myChunks[i].GetUsedRanges().GetIndices( true, usedRanges )) + { + int index = usedRanges[0].first; + id = myChunks[i].Get1stID() + index; + break; + } + return id; +} + +//================================================================================ +/*! + * \brief Return an element by ID. NULL if the element with the given ID is already used + * \param [in] id - element ID + * \return SMDS_MeshElement* - element pointer + */ +//================================================================================ + +SMDS_MeshElement* SMDS_ElementFactory::NewElement( const int id ) +{ + int iChunk = ( id - 1 ) / theChunkSize; + int index = ( id - 1 ) % theChunkSize; + while ((int) myChunks.size() <= iChunk ) + { + int id0 = myChunks.size() * theChunkSize + 1; + myChunks.push_back( new SMDS_ElementChunk( this, id0 )); + } + SMDS_MeshElement* e = myChunks[iChunk].Element( index ); + if ( !e->IsNull() ) + return 0; // element with given ID already exists + + myChunks[iChunk].UseElement( index ); + ++myNbUsedElements; + + e->myHolder = & myChunks[iChunk]; + + myMesh->setMyModified(); + + return e; +} + +//================================================================================ +/*! + * \brief Return an used element by ID. NULL if the element with the given ID is not yet used + * \param [in] id - element ID + * \return const SMDS_MeshElement* - element pointer + */ +//================================================================================ + +const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const int id ) const +{ + if ( id > 0 ) + { + int iChunk = ( id - 1 ) / theChunkSize; + int index = ( id - 1 ) % theChunkSize; + if ( iChunk < (int) myChunks.size() ) + { + const SMDS_MeshElement* e = myChunks[iChunk].Element( index ); + return e->IsNull() ? 0 : e; + } + } + return 0; +} + +//================================================================================ +/*! + * \brief Return an SMDS ID by a Vtk one + * \param [inout] vtkID - Vtk ID + * \return int - SMDS ID + */ +//================================================================================ + +int SMDS_ElementFactory::FromVtkToSmds( vtkIdType vtkID ) +{ + if ( vtkID >= 0 && vtkID < (vtkIdType)mySmdsIDs.size() ) + return mySmdsIDs[vtkID] + 1; + return vtkID + 1; +} + +//================================================================================ +/*! + * \brief Mark the element as non-used + * \param [in] e - element + */ +//================================================================================ + +void SMDS_ElementFactory::Free( const SMDS_MeshElement* e ) +{ + if ( !myVtkIDs.empty() ) + { + size_t id = e->GetID() - 1; + size_t vtkID = e->GetVtkID(); + if ( id < myVtkIDs.size() ) + myVtkIDs[ id ] = -1; + if ( vtkID < mySmdsIDs.size() ) + mySmdsIDs[ vtkID ] = -1; + } + e->myHolder->Free( e ); + const_cast< SMDS_MeshElement*>( e )->myHolder = 0; + --myNbUsedElements; + + myMesh->setMyModified(); +} + +//================================================================================ +/*! + * \brief De-allocate all elements + */ +//================================================================================ + +void SMDS_ElementFactory::Clear() +{ + myChunksWithUnused.clear(); + clearVector( myChunks ); + clearVector( myVtkIDs ); + clearVector( mySmdsIDs ); + myNbUsedElements = 0; +} + +//================================================================================ +/*! + * \brief Remove unused elements located not at the end of the last chunk. + * Minimize allocated memory + * \param [out] theVtkIDsNewToOld - theVtkIDsNewToOld[ new VtkID ] = old VtkID + */ +//================================================================================ + +void SMDS_ElementFactory::Compact( std::vector& theVtkIDsNewToOld ) +{ + int newNbCells = NbUsedElements(); + int maxCellID = GetMaxID(); + int newNbChunks = newNbCells / theChunkSize + bool ( newNbCells % theChunkSize ); + + theVtkIDsNewToOld.resize( newNbCells ); + + if ( newNbCells == 0 ) // empty mesh + { + clearVector( myChunks ); + } + else if ( newNbCells == maxCellID ) // no holes + { + int newID, minLastID = std::min( myVtkIDs.size(), theVtkIDsNewToOld.size() ); + for ( newID = 0; newID < minLastID; ++newID ) + theVtkIDsNewToOld[ newID ] = myVtkIDs[ newID ]; + for ( ; newID < newNbCells; ++newID ) + theVtkIDsNewToOld[ newID ] = newID; + } + else // there are holes in SMDS IDs + { + int newVtkID = 0; // same as new smds ID (-1) + for ( int oldID = 1; oldID <= maxCellID; ++oldID ) // smds IDs + { + const SMDS_MeshElement* oldElem = FindElement( oldID ); + if ( !oldElem ) continue; + theVtkIDsNewToOld[ newVtkID++ ] = oldElem->GetVtkID(); // now newVtkID == new smds ID + if ( oldID != newVtkID ) + { + const SMDS_MeshElement* newElem = FindElement( newVtkID ); + if ( !newElem ) + newElem = NewElement( newVtkID ); + if ( int shapeID = oldElem->GetShapeID() ) + const_cast< SMDS_MeshElement* >( newElem )->setShapeID( shapeID ); + if ( oldID > newNbCells ) + Free( oldElem ); + } + } + } + myChunks.resize( newNbChunks ); + + myChunksWithUnused.clear(); + if ( !myChunks.empty() && myChunks.back().GetUsedRanges().Size() > 1 ) + myChunksWithUnused.insert( & myChunks.back() ); + + for ( size_t i = 0; i < myChunks.size(); ++i ) + myChunks[i].Compact(); + + clearVector( myVtkIDs ); + clearVector( mySmdsIDs ); +} + + +//================================================================================ +/*! + * \brief Return true if Compact() will change IDs of elements + */ +//================================================================================ + +bool SMDS_ElementFactory::CompactChangePointers() +{ + // there can be VTK_EMPTY_CELL's in the VTK grid as well as "holes" in SMDS numeration + return ( NbUsedElements() != GetMaxID() ); +} + +//================================================================================ +/*! + * \brief Create a factory of nodes in a given mesh + */ +//================================================================================ + +SMDS_NodeFactory::SMDS_NodeFactory( SMDS_Mesh* mesh ) + : SMDS_ElementFactory( mesh, /*isNodal=*/true ) +{ +} + +//================================================================================ +/*! + * \brief Destructor + */ +//================================================================================ + +SMDS_NodeFactory::~SMDS_NodeFactory() +{ + Clear(); +} + +//================================================================================ +/*! + * \brief Remove unused nodes located not at the end of the last chunk. + * Minimize allocated memory + * \param [out] theVtkIDsOldToNew - vector storing change of vtk IDs + */ +//================================================================================ + +void SMDS_NodeFactory::Compact( std::vector& theVtkIDsOldToNew ) +{ + // IDs of VTK nodes always correspond to SMDS IDs but there can be "holes" + // in the chunks. So we remove holes and report relocation in theVtkIDsOldToNew: + // theVtkIDsOldToNew[ old VtkID ] = new VtkID + + int oldNbNodes = myMesh->GetGrid()->GetNumberOfPoints(); + int newNbNodes = NbUsedElements(); + int newNbChunks = newNbNodes / theChunkSize + bool ( newNbNodes % theChunkSize ); + int maxNodeID = GetMaxID(); + + theVtkIDsOldToNew.resize( oldNbNodes, -1 ); + + if ( newNbNodes == 0 ) // empty mesh + { + clearVector( myChunks ); + } + else if ( maxNodeID > newNbNodes ) // there are holes + { + size_t newID = 0; + for ( size_t oldID = 0; oldID < theVtkIDsOldToNew.size(); ++oldID ) + { + const SMDS_MeshElement* oldNode = FindNode( oldID+1 ); + if ( !oldNode ) + continue; + theVtkIDsOldToNew[ oldID ] = newID; + if ( oldID != newID ) + { + const SMDS_MeshElement* newNode = FindElement( newID+1 ); + if ( !newNode ) + newNode = NewElement( newID+1 ); + int shapeID = oldNode->GetShapeID(); + int shapeDim = GetShapeDim( shapeID ); + int iChunk = newID / theChunkSize; + myChunks[ iChunk ].SetShapeID( newNode, shapeID ); + if ( shapeDim == 2 || shapeDim == 1 ) + { + int iChunkOld = oldID / theChunkSize; + TParam* oldPos = myChunks[ iChunkOld ].GetPositionPtr( oldNode ); + TParam* newPos = myChunks[ iChunk ].GetPositionPtr( newNode, /*allocate=*/true ); + if ( oldPos ) + { + newPos[0] = oldPos[0]; + newPos[1] = oldPos[1]; + } + } + if ( oldNode->GetID() > newNbNodes ) + Free( oldNode ); + } + ++newID; + } + } + else // no holes + { + for ( int i = 0; i < newNbNodes; ++i ) + theVtkIDsOldToNew[ i ] = i; + } + myChunks.resize( newNbChunks ); + + myChunksWithUnused.clear(); + if ( !myChunks.empty() && myChunks.back().GetUsedRanges().Size() > 1 ) + myChunksWithUnused.insert( & myChunks.back() ); + + for ( size_t i = 0; i < myChunks.size(); ++i ) + myChunks[i].Compact(); + + ASSERT( newNbNodes == GetMaxID() ); + ASSERT( newNbNodes == NbUsedElements() ); +} + +//================================================================================ +/*! + * \brief Return true if Compact() will change IDs of elements + */ +//================================================================================ + +bool SMDS_NodeFactory::CompactChangePointers() +{ + // IDs of VTK nodes always correspond to SMDS IDs but there can be "holes" in SMDS numeration + return ( NbUsedElements() != GetMaxID() ); +} + +//================================================================================ +/*! + * \brief De-allocate all nodes + */ +//================================================================================ + +void SMDS_NodeFactory::Clear() +{ + SMDS_ElementFactory::Clear(); +} + +//================================================================================ +/*! + * \brief Set a total number of sub-shapes in the main shape + */ +//================================================================================ + +void SMDS_NodeFactory::SetNbShapes( size_t nbShapes ) +{ + clearVector( myShapeDim ); + myShapeDim.resize( nbShapes+1, theDefaultShapeDim ); +} + +//================================================================================ +/*! + * \brief Return a dimension of a shape + */ +//================================================================================ + +int SMDS_NodeFactory::GetShapeDim( int shapeID ) const +{ + return shapeID < (int)myShapeDim.size() ? myShapeDim[ shapeID ] : theDefaultShapeDim; +} + +//================================================================================ +/*! + * \brief Set a dimension of a shape + */ +//================================================================================ + +void SMDS_NodeFactory::SetShapeDim( int shapeID, int dim ) +{ + if ( shapeID >= (int)myShapeDim.size() ) + myShapeDim.resize( shapeID + 10, theDefaultShapeDim ); + myShapeDim[ shapeID ] = dim; +} + +//================================================================================ +/*! + * \brief SMDS_ElementChunk constructor + * \param [in] factory - the factory + * \param [in] id0 - ID of the 1st element + */ +//================================================================================ + +SMDS_ElementChunk::SMDS_ElementChunk( SMDS_ElementFactory* factory, int id0 ): + myFactory( factory ), + my1stID( id0 ), + myMinSubID( std::numeric_limits::max() ), + myMaxSubID( 0 ) +{ + if ( !myFactory ) + return; + if ( myFactory->myIsNodal ) + myElements = new SMDS_MeshNode[ theChunkSize ]; + else + myElements = new SMDS_MeshCell[ theChunkSize ]; + + myUsedRanges.mySet.reserve(2); + mySubIDRanges.mySet.insert( _ShapeIDRange( 0, 0 )); + myUsedRanges.mySet.insert( _UsedRange( 0, false )); + myFactory->myChunksWithUnused.insert( this ); +} + +//================================================================================ +/*! + * \brief SMDS_ElementChunk destructor + */ +//================================================================================ + +SMDS_ElementChunk::~SMDS_ElementChunk() +{ + delete [] myElements; + myFactory->myChunksWithUnused.erase( this ); +} + +//================================================================================ +/*! + * \brief Mark an element as used + */ +//================================================================================ + +void SMDS_ElementChunk::UseElement( const int index ) +{ + myUsedRanges.SetValue( index, true ); + if ( myUsedRanges.Size() == 1 ) // all elements used + myFactory->myChunksWithUnused.erase( this ); +} + +//================================================================================ +/*! + * \brief Return ID of the first non-used element + */ +//================================================================================ + +int SMDS_ElementChunk::GetUnusedID() const +{ + TUsedRangeSet::set_iterator r = myUsedRanges.mySet.begin(); + for ( ; r != myUsedRanges.mySet.end(); ++r ) + if ( !IsUsed( *r )) + break; + + return my1stID + r->my1st; +} + +//================================================================================ +/*! + * \brief Mark an element as non-used + */ +//================================================================================ + +void SMDS_ElementChunk::Free( const SMDS_MeshElement* e ) +{ + bool hasHoles = ( myUsedRanges.Size() > 1 ); + myUsedRanges.SetValue( Index( e ), false ); + SetShapeID( e, 0 ); // sub-mesh must do it? + SetIsMarked( e, false ); + if ( !hasHoles ) + myFactory->myChunksWithUnused.insert( this ); + + if ( myUsedRanges.Size() == 1 ) + { + clearVector( myMarkedSet ); + clearVector( myPositions ); + } +} + +//================================================================================ +/*! + * \brief Return an SMDS ID of an element + */ +//================================================================================ + +int SMDS_ElementChunk::GetID( const SMDS_MeshElement* e ) const +{ + return my1stID + Index( e ); +} + +//================================================================================ +/*! + * \brief Set a Vtk ID of an element + */ +//================================================================================ + +void SMDS_ElementChunk::SetVTKID( const SMDS_MeshElement* e, const vtkIdType vtkID ) +{ + if ( e->GetID() - 1 != vtkID ) + { + if ((int) myFactory->myVtkIDs.size() <= e->GetID() - 1 ) + { + size_t i = myFactory->myVtkIDs.size(); + myFactory->myVtkIDs.resize( e->GetID() + 100 ); + for ( ; i < myFactory->myVtkIDs.size(); ++i ) + myFactory->myVtkIDs[i] = i; + } + myFactory->myVtkIDs[ e->GetID() - 1 ] = vtkID; + + if ((vtkIdType) myFactory->mySmdsIDs.size() <= vtkID ) + { + size_t i = myFactory->mySmdsIDs.size(); + myFactory->mySmdsIDs.resize( vtkID + 100 ); + for ( ; i < myFactory->mySmdsIDs.size(); ++i ) + myFactory->mySmdsIDs[i] = i; + } + myFactory->mySmdsIDs[ vtkID ] = e->GetID() - 1; + } +} + +//================================================================================ +/*! + * \brief Return a Vtk ID of an element + */ +//================================================================================ + +int SMDS_ElementChunk::GetVtkID( const SMDS_MeshElement* e ) const +{ + size_t dfltVtkID = e->GetID() - 1; + return ( dfltVtkID < myFactory->myVtkIDs.size() ) ? myFactory->myVtkIDs[ dfltVtkID ] : dfltVtkID; +} + +//================================================================================ +/*! + * \brief Return ID of a shape an element is assigned to + */ +//================================================================================ + +int SMDS_ElementChunk::GetShapeID( const SMDS_MeshElement* e ) const +{ + return mySubIDRanges.GetValue( Index( e )); +} + +//================================================================================ +/*! + * \brief Set ID of a shape an element is assigned to + */ +//================================================================================ + +void SMDS_ElementChunk::SetShapeID( const SMDS_MeshElement* e, int shapeID ) const +{ + const size_t nbRanges = mySubIDRanges.Size(); + + SMDS_ElementChunk* me = const_cast( this ); + int oldShapeID = me->mySubIDRanges.SetValue( Index( e ), shapeID ); + if ( oldShapeID == shapeID ) return; + + if ( const SMDS_MeshNode* n = dynamic_cast< const SMDS_MeshNode* >( e )) + if ( TParam* uv = me->GetPositionPtr( n )) + { + uv[0] = 0.; + uv[1] = 0.; + } + // update min/max + if (( nbRanges > mySubIDRanges.Size() ) && + ( myMinSubID == oldShapeID || myMaxSubID == oldShapeID )) + { + me->myMinSubID = ( std::numeric_limits::max() ); + me->myMaxSubID = 0; + TSubIDRangeSet::set_iterator it; + for ( it = mySubIDRanges.mySet.begin(); it < mySubIDRanges.mySet.end(); ++it ) + if ( it->myValue > 0 ) + { + me->myMinSubID = std::min( myMinSubID, it->myValue ); + me->myMaxSubID = std::max( myMaxSubID, it->myValue ); + } + } + else if ( shapeID > 0 ) + { + me->myMinSubID = std::min( myMinSubID, shapeID ); + me->myMaxSubID = std::max( myMaxSubID, shapeID ); + } +} + +//================================================================================ +/*! + * \brief Set isMarked flag of an element + */ +//================================================================================ + +bool SMDS_ElementChunk::IsMarked( const SMDS_MeshElement* e ) const +{ + return ( !myMarkedSet.empty() && myMarkedSet[ Index( e )]); +} + +//================================================================================ +/*! + * \brief Return isMarked flag of an element + */ +//================================================================================ + +void SMDS_ElementChunk::SetIsMarked( const SMDS_MeshElement* e, bool is ) +{ + if ( !is && myMarkedSet.empty() ) return; + if ( myMarkedSet.empty() ) myMarkedSet.resize( theChunkSize, false ); + myMarkedSet[ Index( e )] = is; +} + +//================================================================================ +/*! + * \brief Return SMDS_Position of a node on a shape + */ +//================================================================================ + +SMDS_PositionPtr SMDS_ElementChunk::GetPosition( const SMDS_MeshNode* n ) const +{ + int shapeID = GetShapeID( n ); + int shapeDim = static_cast< SMDS_NodeFactory* >( myFactory )->GetShapeDim( shapeID ); + + SMDS_ElementChunk* me = const_cast< SMDS_ElementChunk* >( this ); + + switch ( shapeDim ) { + case 2: + { + return SMDS_PositionPtr( new _FacePosition( me->GetPositionPtr( n ))); + } + case 1: + { + return SMDS_PositionPtr( new _EdgePosition( me->GetPositionPtr( n ))); + } + case 0: + return SMDS_VertexPosition::StaticPosition(); + } + + return SMDS_SpacePosition::originSpacePosition(); +} + +//================================================================================ +/*! + * \brief Set SMDS_Position of a node on a shape + */ +//================================================================================ + +void SMDS_ElementChunk::SetPosition( const SMDS_MeshNode* n, const SMDS_PositionPtr& pos, int shapeID ) +{ + int shapeDim = pos ? pos->GetDim() : theDefaultShapeDim; + if ( shapeID < 1 ) + { + if ( shapeDim == theDefaultShapeDim ) + return; + shapeID = GetShapeID( n ); + if ( shapeID < 1 ) + throw SALOME_Exception("SetPosition() No shape ID provided"); + } + + static_cast< SMDS_NodeFactory* >( myFactory )->SetShapeDim( shapeID, shapeDim ); + + switch ( shapeDim ) { + case 2: + { + TParam* uv = GetPositionPtr( n, /*allocate=*/true ); + uv[0] = (TParam) pos->GetParameters()[0]; + uv[1] = (TParam) pos->GetParameters()[1]; + break; + } + case 1: + { + GetPositionPtr( n, /*allocate=*/true )[0] = (TParam) pos->GetParameters()[0]; + break; + } + } +} + +//================================================================================ +/*! + * \brief Return pointer to on-shape-parameters of a node + */ +//================================================================================ + +TParam* SMDS_ElementChunk::GetPositionPtr( const SMDS_MeshElement* n, bool allocate ) +{ + if ( myPositions.empty() && !allocate ) + return 0; + + myPositions.resize( theChunkSize * 2 ); + return myPositions.data() + 2 * Index( n ); +} + +//================================================================================ +/*! + * \brief Minimize allocated memory + */ +//================================================================================ + +void SMDS_ElementChunk::Compact() +{ + mySubIDRanges.mySet.shrink_to_fit(); + if ( myUsedRanges.mySet.capacity() > 2 ) + myUsedRanges.mySet.shrink_to_fit(); + + clearVector( myMarkedSet ); + + if ( !myPositions.empty() ) + { + // look for the last position that must be kept + TSubIDRangeSet::set_t::reverse_iterator it; + for ( it = mySubIDRanges.mySet.rbegin(); it != mySubIDRanges.mySet.rend(); ++it ) + { + int shapeDim = static_cast< SMDS_NodeFactory* >( myFactory )->GetShapeDim( it->myValue ); + if ( shapeDim == 1 || shapeDim == 2 ) + break; + } + if ( it == mySubIDRanges.mySet.rend() ) + { + clearVector( myPositions ); + } + else if ( it != mySubIDRanges.mySet.rbegin() ) + { + int nbNodes = (it-1)->my1st; + myPositions.resize( nbNodes * 2 ); + std::vector newPos( myPositions.begin(), myPositions.end() ); + myPositions.swap( newPos ); + } + } +} + +//================================================================================ +/*! + * \brief Print some data for debug purposes + */ +//================================================================================ + +void SMDS_ElementChunk::Dump() const +{ + std::cout << "1stID: " << my1stID << std::endl; + + std::cout << "SubID min/max: " << myMinSubID << ", " << myMaxSubID << std::endl; + std::cout << "SubIDRanges: " << mySubIDRanges.Size() << " "; + { + TSubIDRangeSet::set_iterator i = mySubIDRanges.mySet.begin(); + for ( int cnt = 0; i != mySubIDRanges.mySet.end(); ++i, ++cnt ) + std::cout << "|" << cnt << " - (" << i->my1st << ", " << i->myValue << ") "; + std::cout << std::endl; + } + { + std::cout << "UsedRanges: " << myUsedRanges.Size() << " "; + TUsedRangeSet::set_iterator i = myUsedRanges.mySet.begin(); + for ( int cnt = 0; i != myUsedRanges.mySet.end(); ++i, ++cnt ) + std::cout << cnt << " - (" << i->my1st << ", " << i->myValue << ") "; + std::cout << std::endl; + } +} + +//================================================================================ +/*! + * \brief Compare SMDS_ElementChunk's + */ +//================================================================================ + +bool _ChunkCompare::operator () (const SMDS_ElementChunk* e1, const SMDS_ElementChunk* e2) const +{ + return e1->Get1stID() < e2->Get1stID(); +} + diff --git a/src/SMDS/SMDS_ElementFactory.hxx b/src/SMDS/SMDS_ElementFactory.hxx new file mode 100644 index 000000000..b25b635c8 --- /dev/null +++ b/src/SMDS/SMDS_ElementFactory.hxx @@ -0,0 +1,559 @@ +// Copyright (C) 2007-2016 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, or (at your option) any later version. +// +// 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 : SMDS_ElementFactory.hxx +// Module : SMESH +// +#ifndef _SMDS_ElementFactory_HeaderFile +#define _SMDS_ElementFactory_HeaderFile + +#include "SMDS_MeshCell.hxx" +#include "SMDS_Position.hxx" + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +class SMDS_ElementChunk; +class SMDS_Mesh; +class SMDS_MeshCell; +class SMDS_MeshNode; + +struct _ChunkCompare { + bool operator () (const SMDS_ElementChunk* c1, const SMDS_ElementChunk* c2) const; +}; +typedef boost::ptr_vector TChunkVector; +typedef std::set TChunkPtrSet; + +//------------------------------------------------------------------------------------ +/*! + * \brief Allocate SMDS_MeshElement's (SMDS_MeshCell's or SMDS_MeshNode's ) + * and bind some attributes to elements: + * element ID, element VTK ID, sub-mesh ID, position on shape. + * + * Elements are allocated by chunks, so there are used and non-used elements + */ +class SMDS_ElementFactory +{ +protected: + bool myIsNodal; // what to allocate: nodes or cells + SMDS_Mesh* myMesh; + TChunkVector myChunks; // array of chunks of elements + TChunkPtrSet myChunksWithUnused; // sorted chunks having unused elements + std::vector< vtkIdType > myVtkIDs; // myVtkIDs[ smdsID-1 ] == vtkID + std::vector< int > mySmdsIDs; // mySmdsIDs[ vtkID ] == smdsID - 1 + int myNbUsedElements; // counter of elements + + friend class SMDS_ElementChunk; + +public: + + SMDS_ElementFactory( SMDS_Mesh* mesh, const bool isNodal=false ); + virtual ~SMDS_ElementFactory(); + + //! Return minimal ID of a non-used element + int GetFreeID(); + + //! Return maximal ID of an used element + int GetMaxID(); + + //! Return minimal ID of an used element + int GetMinID(); + + //! Return an element by ID. NULL if the element with the given ID is already used + SMDS_MeshElement* NewElement( const int id ); + + //! Return a SMDS_MeshCell by ID. NULL if the cell with the given ID is already used + SMDS_MeshCell* NewCell( const int id ) { return static_cast( NewElement( id )); } + + //! Return an used element by ID. NULL if the element with the given ID is not yet used + const SMDS_MeshElement* FindElement( const int id ) const; + + //! Return a number of used elements + int NbUsedElements() const { return myNbUsedElements; } + + //! Return an iterator on all element filtered using a given filter. + // nbElemsToReturn is used to optimize by stopping the iteration as soon as + // all elements satisfying filtering condition encountered. + template< class ElemIterator > + boost::shared_ptr< ElemIterator > GetIterator( SMDS_MeshElement::Filter* filter, + size_t nbElemsToReturn = -1 ); + + //! Return an iterator on all element assigned to a given shape. + // nbElemsToReturn is used to optimize by stopping the iteration as soon as + // all elements assigned to the shape encountered. + template< class ElemIterator > + boost::shared_ptr< ElemIterator > GetShapeIterator( int shapeID, size_t nbElemsToReturn ); + + //! Mark the element as non-used + void Free( const SMDS_MeshElement* ); + + //! Return an SMDS ID by a Vtk one + int FromVtkToSmds( vtkIdType vtkID ); + + //! De-allocate all elements + virtual void Clear(); + + //! Remove unused elements located not at the end of the last chunk. + // Minimize allocated memory + virtual void Compact(std::vector& idCellsOldToNew); + + //! Return true if Compact() will change IDs of elements + virtual bool CompactChangePointers(); + + //! Return a number of elements in a chunk + static int ChunkSize(); +}; + +//------------------------------------------------------------------------------------ +/*! + * \brief Allocate SMDS_MeshNode's + */ +class SMDS_NodeFactory : public SMDS_ElementFactory +{ + std::vector myShapeDim; // dimension of shapes + +public: + + SMDS_NodeFactory( SMDS_Mesh* mesh ); + ~SMDS_NodeFactory(); + + //! Return a SMDS_MeshNode by ID. NULL if the node with the given ID is already used + SMDS_MeshNode* NewNode( int id ) { return (SMDS_MeshNode*) NewElement(id); } + + //! Return an used node by ID. NULL if the node with the given ID is not yet used + const SMDS_MeshNode* FindNode( int id ) { return (const SMDS_MeshNode*) FindElement(id); } + + //! Set a total number of sub-shapes in the main shape + void SetNbShapes( size_t nbShapes ); + + //! Return a dimension of a shape + int GetShapeDim( int shapeID ) const; + + //! Set a dimension of a shape + void SetShapeDim( int shapeID, int dim ); + + //! De-allocate all nodes + virtual void Clear(); + + //! Remove unused nodes located not at the end of the last chunk. + // Minimize allocated memory + virtual void Compact(std::vector& idNodesOldToNew); + + //! Return true if Compact() will change IDs of node + virtual bool CompactChangePointers(); +}; + +//------------------------------------------------------------------------------------ +/*! + * \brief Range of elements in a chunk having the same attribute value + */ +template< typename ATTR> +struct _Range +{ + typedef ATTR attr_t; + + attr_t myValue; // common attribute value + int my1st; // index in the chunk of the 1st element + _Range( int i0 = 0, attr_t v = 0 ): myValue( v ), my1st( i0 ) {} + + bool operator < (const _Range& other) const { return my1st < other.my1st; } +}; + +typedef std::vector< std::pair< int, int > > TIndexRanges; + +//------------------------------------------------------------------------------------ +/*! + * \brief Sorted set of ranges + */ +template< class RANGE > +struct _RangeSet +{ + typedef typename RANGE::attr_t attr_t; + typedef boost::container::flat_set< RANGE > set_t; + typedef typename set_t::const_iterator set_iterator; + + set_t mySet; + + _RangeSet() { mySet.insert( RANGE( 0, 0 )); } + + /*! + * \brief Return a number of ranges + */ + size_t Size() const { return mySet.size(); } + + /*! + * \brief Return a mutable _Range::my1st of a range pointed by an iterator + */ + int& First( set_iterator rangePtr ) { return const_cast< int& >( rangePtr->my1st ); } + + /*! + * \brief Return a number of elements in a range pointed by an iterator + */ + size_t Size( set_iterator rangePtr ) const + { + int next1st = + ( rangePtr + 1 == mySet.end() ) ? SMDS_ElementFactory::ChunkSize() : ( rangePtr + 1 )->my1st; + return next1st - rangePtr->my1st; + } + + /*! + * \brief Return ranges of indices (from,to) of elements having a given value + */ + bool GetIndices( const attr_t theValue, TIndexRanges & theIndices, + const attr_t* theMinValue = 0, const attr_t* theMaxValue = 0) const + { + bool isFound = false; + + if ( sizeof( attr_t ) == sizeof( int ) && theMinValue ) + if ( theValue < *theMinValue || theValue > *theMaxValue ) + return isFound; + + for ( set_iterator it = mySet.begin(); it < mySet.end(); ++it ) + { + if ( it->myValue == theValue ) + { + theIndices.push_back( std::make_pair( it->my1st, it->my1st + Size( it ))); + isFound = true; + ++it; // the next range value differs from theValue + } + } + return isFound; + } + + /*! + * \brief Return value of an element attribute + * \param [in] theIndex - element index + * \return attr_t - attribute value + */ + attr_t GetValue( int theIndex ) const + { + set_iterator r = mySet.upper_bound( theIndex ) - 1; + return r->myValue; + } + + /*! + * \brief Change value of an element attribute + * \param [in] theIndex - element index + * \param [in] theValue - attribute value + * \return attr_t - previous value + */ + attr_t SetValue( int theIndex, attr_t theValue ) + { + set_iterator rNext = mySet.upper_bound( theIndex ); + set_iterator r = rNext - 1; + int rSize = Size( r ); // range size + attr_t rValue = r->myValue; + if ( rValue == theValue ) + return rValue; // it happens while compacting + + if ( r->my1st == theIndex ) // theIndex is the first in the range + { + bool joinPrev = // can join theIndex to the previous range + ( r->my1st > 0 && ( r-1 )->myValue == theValue ); + + if ( rSize == 1 ) + { + bool joinNext = // can join to the next range + ( rNext != mySet.end() && rNext->myValue == theValue ); + + if ( joinPrev ) + { + if ( joinNext ) // && joinPrev + { + mySet.erase( r, r + 2 ); + } + else // joinPrev && !joinNext + { + mySet.erase( r ); + } + } + else + { + if ( joinNext ) // && !joinPrev + { + r = mySet.erase( r ); // then r points to the next range + First( r )--; + } + else // !joinPrev && !joinNext + { + const_cast< attr_t & >( r->myValue ) = theValue; + } + } + } + else // if rSize > 1 + { + if ( joinPrev ) + { + First( r )++; + } + else + { + r = mySet.insert( r, RANGE( theIndex + 1, rValue )) - 1; + const_cast< attr_t & >( r->myValue ) = theValue; + } + } + } + else if ( r->my1st + rSize - 1 == theIndex ) // theIndex is last in the range + { + if ( rNext != mySet.end() && rNext->myValue == theValue ) // join to the next + { + First( rNext )--; + } + else + { + mySet.insert( r, RANGE( theIndex, theValue )); + } + } + else // theIndex in the middle of the range + { + r = mySet.insert( r, RANGE( theIndex, theValue )); + r = mySet.insert( r, RANGE( theIndex + 1, rValue )); + } + return rValue; + } +}; // struct _RangeSet + + +typedef _Range< int > _ShapeIDRange; // sub-mesh ID range +typedef _Range< bool > _UsedRange; // range of used elements + +typedef _RangeSet< _ShapeIDRange > TSubIDRangeSet; +typedef _RangeSet< _UsedRange > TUsedRangeSet; +typedef boost::dynamic_bitset<> TBitSet; +typedef float TParam; + +//------------------------------------------------------------------------------------ +/*! + * \brief Allocate SMDS_MeshElement's (SMDS_MeshCell's or SMDS_MeshNode's ) + * and bind some attributes to elements: + * element ID, sub-shape ID, isMarked flag, parameters on shape + */ +class SMDS_ElementChunk +{ + SMDS_ElementFactory* myFactory; // holder of this chunk + SMDS_MeshElement* myElements; // array of elements + int my1stID; // ID of myElements[0] + TBitSet myMarkedSet; // mark some elements + TUsedRangeSet myUsedRanges; // ranges of used/unused elements + TSubIDRangeSet mySubIDRanges; // ranges of elements on the same sub-shape + int myMinSubID; // min sub-shape ID + int myMaxSubID; // max sub-shape ID + std::vector myPositions; // UV parameters on shape: 2*param_t per an element + +public: + + SMDS_ElementChunk( SMDS_ElementFactory* factory = 0, int id0 = 0 ); + ~SMDS_ElementChunk(); + + //! Return an element by an index [0,ChunkSize()] + SMDS_MeshElement* Element(int index) { return & myElements[index]; } + + //! Return an element by an index [0,ChunkSize()] + const SMDS_MeshElement* Element(int index) const { return & myElements[index]; } + + //! Return ID of the first non-used element + int GetUnusedID() const; + + //! Mark an element as used + void UseElement( const int index ); + + //! Mark an element as non-used + void Free( const SMDS_MeshElement* e ); + + //! Check if a given range holds used or non-used elements + static bool IsUsed( const _UsedRange& r ) { return r.myValue; } + + //! Return index of an element in the chunk + int Index( const SMDS_MeshElement* e ) const { return e - myElements; } + + //! Return ID of the 1st element in the chunk + int Get1stID() const { return my1stID; } + + //! Return pointer to on-shape-parameters of a node + TParam* GetPositionPtr( const SMDS_MeshElement* node, bool allocate=false ); + + //! Return ranges of used/non-used elements + const TUsedRangeSet& GetUsedRanges() const { return myUsedRanges; } + const TUsedRangeSet& GetUsedRangesMinMax( bool& min, bool& max ) const + { min = false; max = true; return myUsedRanges; } + + //! Return ranges of elements assigned to sub-shapes and min/max of sub-shape IDs + const TSubIDRangeSet& GetSubIDRangesMinMax( int& min, int& max ) const + { min = myMinSubID; max = myMaxSubID; return mySubIDRanges; } + + //! Minimize allocated memory + void Compact(); + + //! Print some data + void Dump() const; // debug + + + // Methods called by SMDS_MeshElement + + int GetID( const SMDS_MeshElement* e ) const; + + int GetVtkID( const SMDS_MeshElement* e ) const; + void SetVTKID( const SMDS_MeshElement* e, const vtkIdType id ); + + int GetShapeID( const SMDS_MeshElement* e ) const; + void SetShapeID( const SMDS_MeshElement* e, int shapeID ) const; + + bool IsMarked ( const SMDS_MeshElement* e ) const; + void SetIsMarked( const SMDS_MeshElement* e, bool is ); + + SMDS_PositionPtr GetPosition( const SMDS_MeshNode* n ) const; + void SetPosition( const SMDS_MeshNode* n, const SMDS_PositionPtr& pos, int shapeID ); + + SMDS_Mesh* GetMesh() { return myFactory->myMesh; } +}; + +//------------------------------------------------------------------------------------ +/*! + * \brief Iterator on elements in chunks + */ +template< class ELEM_ITERATOR, class RANGE_SET > +struct _ChunkIterator : public ELEM_ITERATOR +{ + typedef typename ELEM_ITERATOR::value_type element_type; + typedef SMDS_MeshElement::Filter* filter_ptr; + typedef typename RANGE_SET::attr_t attr_type; + typedef const RANGE_SET& (SMDS_ElementChunk::*get_rangeset_fun)(attr_type&, attr_type&) const; + + const SMDS_MeshElement* myElement; + TIndexRanges myRanges; + int myRangeIndex; + const TChunkVector& myChunks; + int myChunkIndex; + get_rangeset_fun myGetRangeSetFun; + attr_type myValue; + attr_type myMinValue; + attr_type myMaxValue; + filter_ptr myFilter; + size_t myNbElemsToReturn; + size_t myNbReturned; + + _ChunkIterator( const TChunkVector & theChunks, + get_rangeset_fun theGetRangeSetFun, + attr_type theAttrValue, + SMDS_MeshElement::Filter* theFilter, + size_t theNbElemsToReturn = -1): + myElement( 0 ), + myRangeIndex( 0 ), + myChunks( theChunks ), + myChunkIndex( -1 ), + myGetRangeSetFun( theGetRangeSetFun ), + myValue( theAttrValue ), + myFilter( theFilter ), + myNbElemsToReturn( theNbElemsToReturn ), + myNbReturned( 0 ) + { + next(); + } + ~_ChunkIterator() + { + delete myFilter; + } + + virtual bool more() + { + return myElement; + } + + virtual element_type next() + { + element_type result = (element_type) myElement; + myNbReturned += bool( result ); + + myElement = 0; + if ( myNbReturned < myNbElemsToReturn ) + while ( ! nextInRange() ) + { + if ( ++myRangeIndex >= (int)myRanges.size() ) + { + myRanges.clear(); + myRangeIndex = 0; + while ( ++myChunkIndex < (int)myChunks.size() && + !getRangeSet().GetIndices( myValue, myRanges, &myMinValue, &myMaxValue )) + ; + if ( myChunkIndex >= (int)myChunks.size() ) + break; + } + } + return result; + } + + bool nextInRange() + { + if ( myRangeIndex < (int)myRanges.size() ) + { + std::pair< int, int > & range = myRanges[ myRangeIndex ]; + while ( range.first < range.second && !myElement ) + { + myElement = myChunks[ myChunkIndex ].Element( range.first++ ); + if ( !(*myFilter)( myElement )) + myElement = 0; + } + } + return myElement; + } + + const RANGE_SET& getRangeSet() + { + return ( myChunks[ myChunkIndex ].*myGetRangeSetFun )( myMinValue, myMaxValue ); + } +}; // struct _ChunkIterator + + +template< class ElemIterator > +boost::shared_ptr< ElemIterator > +SMDS_ElementFactory::GetIterator( SMDS_MeshElement::Filter* filter, + size_t nbElemsToReturn ) +{ + typedef _ChunkIterator< ElemIterator, TUsedRangeSet > TChuckIterator; + return boost::make_shared< TChuckIterator >( myChunks, + & SMDS_ElementChunk::GetUsedRangesMinMax, + /*isUsed=*/true, + filter, + nbElemsToReturn ); +} + +template< class ElemIterator > +boost::shared_ptr< ElemIterator > +SMDS_ElementFactory::GetShapeIterator( int shapeID, size_t nbElemsToReturn ) +{ + typedef _ChunkIterator< ElemIterator, TSubIDRangeSet > TChuckIterator; + return boost::make_shared< TChuckIterator >( myChunks, + & SMDS_ElementChunk::GetSubIDRangesMinMax, + /*shapeID=*/shapeID, + new SMDS_MeshElement::NonNullFilter(), + nbElemsToReturn ); +} + +#endif diff --git a/src/SMDS/SMDS_ElementHolder.cxx b/src/SMDS/SMDS_ElementHolder.cxx new file mode 100644 index 000000000..091359044 --- /dev/null +++ b/src/SMDS/SMDS_ElementHolder.cxx @@ -0,0 +1,122 @@ +// Copyright (C) 2007-2016 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, or (at your option) any later version. +// +// 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 : SMDS_ElementHolder.cxx +// Module : SMESH +// + +#include "SMDS_ElementHolder.hxx" + +#include "ObjectPool.hxx" +#include "SMDS_CellOfNodes.hxx" +#include "SMDS_Mesh.hxx" + +//======================================================================= +//function : SMDS_ElementHolder +//purpose : register self in the mesh +//======================================================================= + +SMDS_ElementHolder::SMDS_ElementHolder( const SMDS_Mesh* mesh ) + : myMesh( const_cast< SMDS_Mesh* >( mesh )) +{ + myPtrInMesh = myMesh->myElemHolders.insert( this ).first; +} + +//======================================================================= +//function : ~SMDS_ElementHolder +//purpose : un-register self from the mesh +//======================================================================= + +SMDS_ElementHolder::~SMDS_ElementHolder() +{ + myMesh->myElemHolders.erase( myPtrInMesh ); +} + +//======================================================================= +//function : beforeCompacting +//purpose : store vtkIDs of elements +//======================================================================= + +void SMDS_ElementHolder::beforeCompacting() +{ + int i = 0; + for ( SMDS_ElemIteratorPtr it = getElements(); it->more(); ++i ) + { + const SMDS_MeshElement* e = it->next(); + if ( !e ) continue; + if ( e->IsNull() && !dynamic_cast( e )) + continue; // removed element + myIsNode.push_back( e->GetType() == SMDSAbs_Node ); + if ( myMesh->Contains( e )) + { + myVtkIDs.push_back( e->GetVtkID() ); + } + else + { + myExternalElems.push_back( e ); + myVtkIDs.push_back( -1 * (int)myExternalElems.size() ); + } + } +} + +//======================================================================= +//function : restoreElements +//purpose : restore pointers to elements +//======================================================================= + +void SMDS_ElementHolder::restoreElements( const std::vector& idNodesOldToNew, + const std::vector& idCellsOldToNew ) +{ + tmpClear(); + + const SMDS_MeshElement* elem; + + std::vector< bool >::iterator isNode = myIsNode.begin(); + for ( size_t i = 0; i < myVtkIDs.size(); ++i, ++isNode ) + { + int vtkID = myVtkIDs[i]; + if ( vtkID < 0 ) + { + elem = myExternalElems[ (-vtkID)-1 ]; + } + else if ( *isNode ) + { + if ( vtkID < (int)idNodesOldToNew.size() ) + elem = myMesh->FindNodeVtk( idNodesOldToNew[ vtkID ]); + else + elem = myMesh->FindNodeVtk( vtkID ); + } + else + { + if ( vtkID < (int)idCellsOldToNew.size() ) + elem = myMesh->FindElementVtk( idCellsOldToNew[ vtkID ]); + else + elem = myMesh->FindElementVtk( vtkID ); + } + if ( elem ) + add( elem ); + } + clearVector( myExternalElems ); + clearVector( myVtkIDs ); + clearVector( myIsNode ); + + compact(); +} diff --git a/src/SMDS/SMDS_ElementHolder.hxx b/src/SMDS/SMDS_ElementHolder.hxx new file mode 100644 index 000000000..f05774b11 --- /dev/null +++ b/src/SMDS/SMDS_ElementHolder.hxx @@ -0,0 +1,93 @@ +// Copyright (C) 2007-2016 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, or (at your option) any later version. +// +// 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 : SMDS_ElementHolder.hxx +// Module : SMESH +// +#ifndef _SMDS_ElementHolder_HeaderFile +#define _SMDS_ElementHolder_HeaderFile + +#include "SMESH_SMDS.hxx" + +#include "SMDS_ElemIterator.hxx" + +#include +#include + +class SMDS_Mesh; +class SMDS_MeshElement; + +//------------------------------------------------------------------------------------ +/*! + * \brief Base class of object holding SMDS_MeshElement pointers. + * Registering such an object in SMDS_Mesh assures that the + * pointers remain valid after compacting the mesh + */ +class SMDS_EXPORT SMDS_ElementHolder +{ + public: + + //! register self in the mesh + SMDS_ElementHolder( const SMDS_Mesh* mesh ); + + //! un-register self from the mesh + virtual ~SMDS_ElementHolder(); + + + protected: + + //!< the descendant object return its elements just before the mesh compacting + virtual SMDS_ElemIteratorPtr getElements() = 0; + + //!< the descendant object temporary remove its elements + virtual void tmpClear() = 0; + + //!< the descendant object re-add its elements after the mesh compacting + virtual void add( const SMDS_MeshElement* element ) = 0; + + //!< the descendant squeeze its element storage after re-adding elements + virtual void compact() = 0; + + //!< allow the descendant treat its elements before mesh clearing + virtual void clear() {} + + SMDS_Mesh* myMesh; + + + private: // methods called by SMDS_Mesh + + friend class SMDS_Mesh; + + //! store vtkIDs of elements + void beforeCompacting(); + + //! restore pointers to elements + void restoreElements( const std::vector& idNodessOldToNew, + const std::vector& idCellsOldToNew ); + + + std::vector myExternalElems; //!< elements not contained in the mesh + std::vector< int > myVtkIDs; //!< vtk IDs of elements + std::vector< bool > myIsNode; + std::set< SMDS_ElementHolder* >::iterator myPtrInMesh; +}; + +#endif diff --git a/src/SMDS/SMDS_FaceOfEdges.cxx b/src/SMDS/SMDS_FaceOfEdges.cxx deleted file mode 100644 index 67ff4f6d1..000000000 --- a/src/SMDS/SMDS_FaceOfEdges.cxx +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include "SMDS_FaceOfEdges.hxx" -#include "SMDS_IteratorOfElements.hxx" -#include "SMDS_MeshNode.hxx" -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : NbEdges -//purpose : -//======================================================================= - -int SMDS_FaceOfEdges::NbEdges() const -{ - return myNbEdges; -} - -int SMDS_FaceOfEdges::NbFaces() const -{ - return 1; -} -//======================================================================= -//function : Print -//purpose : -//======================================================================= - -void SMDS_FaceOfEdges::Print(ostream & OS) const -{ - OS << "face <" << GetID() << " > : "; - int i; - for (i = 0; i < NbEdges() - 1; i++) OS << myEdges[i] << ","; - OS << myEdges[i] << ") " << endl; -} - -SMDSAbs_ElementType SMDS_FaceOfEdges::GetType() const -{ - return SMDSAbs_Face; -} - -//======================================================================= -//function : elementsIterator -//purpose : -//======================================================================= - -class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator -{ - const SMDS_MeshEdge* const *mySet; - int myLength; - int index; - public: - SMDS_FaceOfEdges_MyIterator(const SMDS_MeshEdge* const *s, int l): - mySet(s),myLength(l),index(0) {} - - bool more() - { - return index set1,set2; - SMDS_ElemIteratorPtr it; - const SMDS_MeshNode * n; - - it=f1.nodesIterator(); - - while(it->more()) - { - n=static_cast(it->next()); - set1.insert(*n); - } - - delete it; - it=f2.nodesIterator(); - - while(it->more()) - { - n=static_cast(it->next()); - set2.insert(*n); - } - - delete it; - return set1NbNodes() + myEdges[1]->NbNodes() + myEdges[2]->NbNodes() + - ( myNbEdges == 4 ? myEdges[3]->NbNodes() : 0 ) - myNbEdges; -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* SMDS_FaceOfEdges::GetNode(const int ind) const -{ - int index = ind; - for ( int i = 0; i < myNbEdges; ++i ) { - if ( index >= myEdges[ i ]->NbNodes() ) - index -= myEdges[ i ]->NbNodes(); - else - return myEdges[ i ]->GetNode( index ); - } - return 0; -} - -SMDSAbs_EntityType SMDS_FaceOfEdges::GetEntityType() const -{ - return myNbEdges == 3 ? SMDSEntity_Triangle : SMDSEntity_Quadrangle; -} - -SMDSAbs_GeometryType SMDS_FaceOfEdges::GetGeomType() const -{ - return myNbEdges == 3 ? SMDSGeom_TRIANGLE : SMDSGeom_QUADRANGLE; -} diff --git a/src/SMDS/SMDS_FaceOfEdges.hxx b/src/SMDS/SMDS_FaceOfEdges.hxx deleted file mode 100644 index 8bfc1d321..000000000 --- a/src/SMDS/SMDS_FaceOfEdges.hxx +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// -#ifndef _SMDS_FaceOfEdges_HeaderFile -#define _SMDS_FaceOfEdges_HeaderFile - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshFace.hxx" -#include "SMDS_MeshEdge.hxx" -#include "SMDS_Iterator.hxx" - -#include - - -class SMDS_EXPORT SMDS_FaceOfEdges:public SMDS_MeshFace -{ - public: - void Print(std::ostream & OS) const; - SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1, - const SMDS_MeshEdge* edge2, - const SMDS_MeshEdge* edge3); - SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1, - const SMDS_MeshEdge* edge2, - const SMDS_MeshEdge* edge3, - const SMDS_MeshEdge* edge4); - - virtual SMDSAbs_ElementType GetType() const; - virtual SMDSAbs_EntityType GetEntityType() const; - virtual SMDSAbs_GeometryType GetGeomType() const; - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes) {return false;} - virtual int NbNodes() const; - virtual int NbEdges() const; - virtual int NbFaces() const; - virtual const SMDS_MeshNode* GetNode(const int ind) const; - - protected: - virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - - private: - const SMDS_MeshEdge* myEdges[4]; - int myNbEdges; - -}; - -#endif diff --git a/src/SMDS/SMDS_FaceOfNodes.cxx b/src/SMDS/SMDS_FaceOfNodes.cxx index dfd3b7385..0b7f9acf9 100644 --- a/src/SMDS/SMDS_FaceOfNodes.cxx +++ b/src/SMDS/SMDS_FaceOfNodes.cxx @@ -26,15 +26,15 @@ #pragma warning(disable:4786) #endif -#include "SMDS_SetIterator.hxx" #include "SMDS_FaceOfNodes.hxx" -#include "SMDS_IteratorOfElements.hxx" + +#include "SMDS_SetIterator.hxx" #include "SMDS_MeshNode.hxx" #include "SMDS_Mesh.hxx" -#include "utilities.h" +#include -using namespace std; +#include //======================================================================= //function : NbEdges @@ -43,17 +43,25 @@ using namespace std; int SMDS_FaceOfNodes::NbEdges() const { - return NbNodes(); + return NbNodes(); } int SMDS_FaceOfNodes::NbFaces() const { - return 1; + return 1; } int SMDS_FaceOfNodes::NbNodes() const { - return myNbNodes; + return myNbNodes; +} + +int SMDS_FaceOfNodes::GetNodeIndex( const SMDS_MeshNode* node ) const +{ + for ( int i = 0; i < myNbNodes; ++i ) + if ( myNodes[i] == node ) + return i; + return -1; } //======================================================================= @@ -63,81 +71,31 @@ int SMDS_FaceOfNodes::NbNodes() const void SMDS_FaceOfNodes::Print(ostream & OS) const { - OS << "face <" << GetID() << " > : "; - int i; - for (i = 0; i < NbNodes() - 1; i++) OS << myNodes[i] << ","; - OS << myNodes[i] << ") " << endl; + OS << "face <" << GetID() << " > : "; + int i; + for (i = 0; i < NbNodes() - 1; i++) OS << myNodes[i] << ","; + OS << myNodes[i] << ") " << endl; } -//======================================================================= -//function : elementsIterator -//purpose : -//======================================================================= - -class SMDS_FaceOfNodes_MyIterator:public SMDS_NodeArrayElemIterator +SMDS_ElemIteratorPtr SMDS_FaceOfNodes::nodesIterator() const { - public: - SMDS_FaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l): - SMDS_NodeArrayElemIterator( s, & s[ l ] ) {} -}; - -/// =================================================================== -/*! - * \brief Iterator on edges of face - */ -/// =================================================================== + return boost::make_shared< SMDS_NodeArrayElemIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); +} -class _MyEdgeIterator : public SMDS_ElemIterator -{ - vector< const SMDS_MeshElement* > myElems; - size_t myIndex; -public: - _MyEdgeIterator(const SMDS_FaceOfNodes* face):myIndex(0) { - myElems.reserve( face->NbNodes() ); - for ( int i = 0; i < face->NbNodes(); ++i ) { - const SMDS_MeshElement* edge = - SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNodeWrap( i + 1 )); - if ( edge ) - myElems.push_back( edge ); - } - } - /// Return true if and only if there are other object in this iterator - virtual bool more() { return myIndex < myElems.size(); } - - /// Return the current object and step to the next one - virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; } -}; - -SMDS_ElemIteratorPtr SMDS_FaceOfNodes::elementsIterator( SMDSAbs_ElementType type ) const +SMDS_NodeIteratorPtr SMDS_FaceOfNodes::nodeIterator() const { - switch(type) - { - case SMDSAbs_Face: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Face); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes)); - case SMDSAbs_Edge: - return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this )); - break; - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements - (this,type,SMDS_ElemIteratorPtr - (new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes)))); - } - return SMDS_ElemIteratorPtr(); + return boost::make_shared< SMDS_NodeArrayIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); } SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1, const SMDS_MeshNode* node2, const SMDS_MeshNode* node3) { - //MESSAGE("******************************************************* SMDS_FaceOfNodes"); - myNbNodes = 3; - myNodes[0]=node1; - myNodes[1]=node2; - myNodes[2]=node3; - myNodes[3]=0; + myNbNodes = 3; + myNodes[0]=node1; + myNodes[1]=node2; + myNodes[2]=node3; + myNodes[3]=0; } SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1, @@ -145,12 +103,11 @@ SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1, const SMDS_MeshNode* node3, const SMDS_MeshNode* node4) { - //MESSAGE("******************************************************* SMDS_FaceOfNodes"); - myNbNodes = 4; - myNodes[0]=node1; - myNodes[1]=node2; - myNodes[2]=node3; - myNodes[3]=node4; + myNbNodes = 4; + myNodes[0]=node1; + myNodes[1]=node2; + myNodes[2]=node3; + myNodes[3]=node4; } bool SMDS_FaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) diff --git a/src/SMDS/SMDS_FaceOfNodes.hxx b/src/SMDS/SMDS_FaceOfNodes.hxx index fec0b0999..7e25a90f5 100644 --- a/src/SMDS/SMDS_FaceOfNodes.hxx +++ b/src/SMDS/SMDS_FaceOfNodes.hxx @@ -27,46 +27,43 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshFace.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_Iterator.hxx" +#include "SMDS_CellOfNodes.hxx" -#include - -class SMDS_EXPORT SMDS_FaceOfNodes:public SMDS_MeshFace +class SMDS_EXPORT SMDS_FaceOfNodes: public SMDS_CellOfNodes { - public: - void Print(std::ostream & OS) const; - SMDS_FaceOfNodes(const SMDS_MeshNode* node1, - const SMDS_MeshNode* node2, - const SMDS_MeshNode* node3); - SMDS_FaceOfNodes(const SMDS_MeshNode* node1, - const SMDS_MeshNode* node2, - const SMDS_MeshNode* node3, - const SMDS_MeshNode* node4); - bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes); - int NbEdges() const; - int NbFaces() const; - int NbNodes() const; + public: + void Print(std::ostream & OS) const; + SMDS_FaceOfNodes(const SMDS_MeshNode* node1, + const SMDS_MeshNode* node2, + const SMDS_MeshNode* node3); + SMDS_FaceOfNodes(const SMDS_MeshNode* node1, + const SMDS_MeshNode* node2, + const SMDS_MeshNode* node3, + const SMDS_MeshNode* node4); + virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], + const int nbNodes); + virtual int NbEdges() const; + virtual int NbFaces() const; + virtual int NbNodes() const; + + virtual int NbCornerNodes() const { return NbNodes(); } + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; + + virtual bool IsPoly() const { return false; } + virtual bool IsQuadratic() const { return false; } + + virtual SMDS_ElemIteratorPtr nodesIterator() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; - /*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ virtual const SMDS_MeshNode* GetNode(const int ind) const; + virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Face; } virtual SMDSAbs_EntityType GetEntityType() const; virtual SMDSAbs_GeometryType GetGeomType() const; - protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; - - private: - const SMDS_MeshNode* myNodes[4]; - int myNbNodes; + private: + const SMDS_MeshNode* myNodes[4]; + int myNbNodes; }; diff --git a/src/SMDS/SMDS_FacePosition.cxx b/src/SMDS/SMDS_FacePosition.cxx index ae12dc313..3eb3c16df 100644 --- a/src/SMDS/SMDS_FacePosition.cxx +++ b/src/SMDS/SMDS_FacePosition.cxx @@ -26,63 +26,62 @@ // Module : SMESH // #include "SMDS_FacePosition.hxx" - -#include "utilities.h" - -using namespace std; +#include "SMDS_EdgePosition.hxx" //======================================================================= //function : SMDS_FacePosition -//purpose : +//purpose : //======================================================================= SMDS_FacePosition::SMDS_FacePosition(const double aUParam, const double aVParam) - : myUParameter(aUParam),myVParameter(aVParam) { - //MESSAGE("******************************************************** SMDS_FacePosition"); + SetParameters( aUParam,aVParam ); } -/** -*/ +//======================================================================= +//function : GetTypeOfPosition +//purpose : +//======================================================================= + SMDS_TypeOfPosition SMDS_FacePosition::GetTypeOfPosition() const { - return SMDS_TOP_FACE; + return SMDS_TOP_FACE; } void SMDS_FacePosition::SetUParameter(double aUparam) { - myUParameter = aUparam; + myParameter[0] = aUparam; } //======================================================================= //function : SetVParameter -//purpose : +//purpose : //======================================================================= void SMDS_FacePosition::SetVParameter(double aVparam) { - myVParameter = aVparam; + myParameter[1] = aVparam; } //======================================================================= //function : GetUParameter -//purpose : +//purpose : //======================================================================= -double SMDS_FacePosition::GetUParameter() const +double SMDS_FacePosition::GetUParameter() const { - return myUParameter; + return myParameter[0]; } //======================================================================= //function : GetVParameter -//purpose : +//purpose : //======================================================================= -double SMDS_FacePosition::GetVParameter() const +double SMDS_FacePosition::GetVParameter() const { - return myVParameter; + return myParameter[1]; } //======================================================================= @@ -92,6 +91,6 @@ double SMDS_FacePosition::GetVParameter() const void SMDS_FacePosition::SetParameters(double aUparam, double aVparam) { - myUParameter = aUparam; - myVParameter = aVparam; + myParameter[0] = aUparam; + myParameter[1] = aVparam; } diff --git a/src/SMDS/SMDS_FacePosition.hxx b/src/SMDS/SMDS_FacePosition.hxx index 45015887d..a36e300ad 100644 --- a/src/SMDS/SMDS_FacePosition.hxx +++ b/src/SMDS/SMDS_FacePosition.hxx @@ -33,18 +33,17 @@ class SMDS_EXPORT SMDS_FacePosition:public SMDS_Position { + public: + SMDS_FacePosition(double aUParam=0, double aVParam=0); + SMDS_TypeOfPosition GetTypeOfPosition() const; + virtual void SetUParameter(double aUparam); + virtual void SetVParameter(double aVparam); + virtual void SetParameters(double aUparam, double aVparam); + virtual double GetUParameter() const; + virtual double GetVParameter() const; + virtual const double* GetParameters() const { return &myParameter[0]; } - public: - SMDS_FacePosition(double aUParam=0, double aVParam=0); - SMDS_TypeOfPosition GetTypeOfPosition() const; - void SetUParameter(double aUparam); - void SetVParameter(double aVparam); - void SetParameters(double aUparam, double aVparam); - double GetUParameter() const; - double GetVParameter() const; - - private: - double myUParameter; - double myVParameter; + private: + double myParameter[2]; }; #endif diff --git a/src/SMDS/SMDS_Iterator.hxx b/src/SMDS/SMDS_Iterator.hxx index f20d7062e..561324930 100644 --- a/src/SMDS/SMDS_Iterator.hxx +++ b/src/SMDS/SMDS_Iterator.hxx @@ -25,27 +25,28 @@ #ifndef _SMDS_Iterator_HeaderFile #define _SMDS_Iterator_HeaderFile -#include "SMESH_SMDS.hxx" - /////////////////////////////////////////////////////////////////////////////// ///Abstract class for iterators ///@author Jerome Robert /////////////////////////////////////////////////////////////////////////////// template class SMDS_Iterator { - public: - /// Return true if and only if there are other object in this iterator - virtual bool more()=0; - - /// Return the current object and step to the next one - virtual VALUE next()=0; +public: + + typedef VALUE value_type; + + /// Return true if and only if there are other object in this iterator + virtual bool more()=0; + + /// Return the current object and step to the next one + virtual VALUE next()=0; - /// Delete the current element and step to the next one - virtual void remove(){} + /// Delete the current element and step to the next one + virtual void remove(){} - /// Provide virtual destructor just for case if some derived iterator - /// must have a destructor - virtual ~SMDS_Iterator(){} + /// Provide virtual destructor just for case if some derived iterator + /// must have a destructor + virtual ~SMDS_Iterator(){} }; #endif diff --git a/src/SMDS/SMDS_IteratorOfElements.cxx b/src/SMDS/SMDS_IteratorOfElements.cxx deleted file mode 100644 index 3d125fcfb..000000000 --- a/src/SMDS/SMDS_IteratorOfElements.cxx +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include "SMDS_IteratorOfElements.hxx" - -bool SMDS_IteratorOfElements::subMore() -{ - if((t2Iterator.get()==NULL)||(!t2Iterator->more())) - { - if(t1Iterator->more()) - { - t2Iterator=t1Iterator->next()->elementsIterator(myType); - return subMore(); - } - else return false; - } - else return true; -} - -const SMDS_MeshElement * SMDS_IteratorOfElements::subNext() -{ - if((t2Iterator.get()==NULL)||(!t2Iterator->more())) - if(t1Iterator->more()) - t2Iterator=t1Iterator->next()->elementsIterator(myType); - return t2Iterator->next(); -} - -///////////////////////////////////////////////////////////////////////////// -/// Create an iterator which look for elements of type type which are linked -/// to the element element. it is the iterator to get connectivity of element -////////////////////////////////////////////////////////////////////////////// -SMDS_IteratorOfElements::SMDS_IteratorOfElements(const SMDS_MeshElement * element, - SMDSAbs_ElementType type, - const SMDS_ElemIteratorPtr& it) - : t1Iterator(it), - t2Iterator(SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL)), - myType(type), myElement(element), - myProxyElement(NULL) -{ - while(subMore()) - alreadyReturnedElements.insert(subNext()); - itAlreadyReturned= alreadyReturnedElements.begin(); - switch(myElement->GetType()) - { - case SMDSAbs_Node: - case SMDSAbs_Edge: myReverseIteration=true; break; - case SMDSAbs_Face: myReverseIteration=(type==SMDSAbs_Volume); break; - default: myReverseIteration=false; - } -} - -bool SMDS_IteratorOfElements::more() -{ - if(myProxyElement==NULL) - { - while(itAlreadyReturned!=alreadyReturnedElements.end()) - { - myProxyElement=*itAlreadyReturned; - itAlreadyReturned++; - - if(myReverseIteration) - { - SMDS_ElemIteratorPtr it= - myProxyElement->elementsIterator(myElement->GetType()); - while(it->more()) - { - if(it->next()==myElement) return true; - } - } - else return true; - } - myProxyElement=NULL; - return false; - } - else return true; -} - -const SMDS_MeshElement * SMDS_IteratorOfElements::next() -{ - more(); - const SMDS_MeshElement *e=myProxyElement; - myProxyElement=NULL; - return e; -} diff --git a/src/SMDS/SMDS_IteratorOfElements.hxx b/src/SMDS/SMDS_IteratorOfElements.hxx deleted file mode 100644 index f2d73d8c7..000000000 --- a/src/SMDS/SMDS_IteratorOfElements.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// -#include "SMESH_SMDS.hxx" - -#include "SMDS_Iterator.hxx" -#include "SMDS_MeshElement.hxx" -#include - - -class SMDS_EXPORT SMDS_IteratorOfElements:public SMDS_ElemIterator -{ - public: -///////////////////////////////////////////////////////////////////////////// -/// Create an iterator which look for elements of type type which are linked -/// to the element element. it is the iterator to get connectivity of element -////////////////////////////////////////////////////////////////////////////// - SMDS_IteratorOfElements(const SMDS_MeshElement * element, - SMDSAbs_ElementType type, - const SMDS_ElemIteratorPtr& it); - bool more(); - const SMDS_MeshElement * next(); - - private: - SMDS_ElemIteratorPtr t1Iterator; - SMDS_ElemIteratorPtr t2Iterator; - SMDSAbs_ElementType myType; - const SMDS_MeshElement * myElement; - const SMDS_MeshElement * myProxyElement; - bool myReverseIteration; - - std::set alreadyReturnedElements; - std::set::iterator itAlreadyReturned; - bool subMore(); - const SMDS_MeshElement * subNext(); -}; diff --git a/src/SMDS/SMDS_LinearEdge.cxx b/src/SMDS/SMDS_LinearEdge.cxx index 8b87a9a44..1d58368d4 100644 --- a/src/SMDS/SMDS_LinearEdge.cxx +++ b/src/SMDS/SMDS_LinearEdge.cxx @@ -28,11 +28,10 @@ #endif #include "SMDS_LinearEdge.hxx" -#include "SMDS_IteratorOfElements.hxx" #include "SMDS_MeshNode.hxx" -#include "utilities.h" +#include "SMDS_SetIterator.hxx" -using namespace std; +#include //======================================================================= //function : SMDS_LinearEdge @@ -42,22 +41,10 @@ using namespace std; SMDS_LinearEdge::SMDS_LinearEdge(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2) { - //MESSAGE("SMDS_LinearEdge " << GetID()); myNodes[0] = node1; myNodes[1] = node2; } -//======================================================================= -//function : Print -//purpose : -//======================================================================= - -void SMDS_LinearEdge::Print(ostream & OS) const -{ - OS << "edge <" << GetID() << "> : (" << myNodes[0] << " , " << myNodes[1] - << ") " << endl; -} - int SMDS_LinearEdge::NbNodes() const { return 2; @@ -68,75 +55,29 @@ int SMDS_LinearEdge::NbEdges() const return 1; } -class SMDS_LinearEdge_MyNodeIterator: public SMDS_ElemIterator +int SMDS_LinearEdge::NbFaces() const { - const SMDS_MeshNode * const * myNodes; - int myIndex; -public: - SMDS_LinearEdge_MyNodeIterator(const SMDS_MeshNode * const * nodes) : - myNodes(nodes), myIndex(0) - { - } - - bool more() - { - return myIndex < 2; - } - - const SMDS_MeshElement* next() - { - myIndex++; - return myNodes[myIndex - 1]; - } -}; + return 0; +} -SMDS_ElemIteratorPtr SMDS_LinearEdge::elementsIterator(SMDSAbs_ElementType type) const +int SMDS_LinearEdge::GetNodeIndex( const SMDS_MeshNode* node ) const { - switch (type) - { - case SMDSAbs_Edge: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes)); - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements(this, - type, - SMDS_ElemIteratorPtr - (new SMDS_LinearEdge_MyNodeIterator(myNodes)))); - } + if ( node == myNodes[0] ) return 0; + if ( node == myNodes[1] ) return 1; + return -1; } -bool operator<(const SMDS_LinearEdge & e1, const SMDS_LinearEdge & e2) +SMDS_ElemIteratorPtr SMDS_LinearEdge::nodesIterator() const { - int id11 = e1.myNodes[0]->getVtkId(); - int id21 = e2.myNodes[0]->getVtkId(); - int id12 = e1.myNodes[1]->getVtkId(); - int id22 = e2.myNodes[1]->getVtkId(); - int tmp; - - if (id11 >= id12) - { - tmp = id11; - id11 = id12; - id12 = tmp; - } - if (id21 >= id22) - { - tmp = id21; - id21 = id22; - id22 = tmp; - } + return boost::make_shared< SMDS_NodeArrayElemIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); +} - if (id11 < id21) - return true; - else if (id11 == id21) - return (id21 < id22); - else - return false; +SMDS_NodeIteratorPtr SMDS_LinearEdge::nodeIterator() const +{ + return boost::make_shared< SMDS_NodeArrayIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); } -/*! +/* * \brief Return node by its index * \param ind - node index * \retval const SMDS_MeshNode* - the node @@ -151,10 +92,9 @@ const SMDS_MeshNode* SMDS_LinearEdge::GetNode(const int ind) const //purpose : //======================================================================= -bool SMDS_LinearEdge::ChangeNodes(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2) +bool SMDS_LinearEdge::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) { - myNodes[0] = node1; - myNodes[1] = node2; - return true; + myNodes[0] = nodes[0]; + myNodes[1] = nodes[1]; + return nbNodes == 2; } diff --git a/src/SMDS/SMDS_LinearEdge.hxx b/src/SMDS/SMDS_LinearEdge.hxx index 1ac80ee8a..75d984e3f 100644 --- a/src/SMDS/SMDS_LinearEdge.hxx +++ b/src/SMDS/SMDS_LinearEdge.hxx @@ -27,42 +27,34 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshEdge.hxx" -#include +#include "SMDS_CellOfNodes.hxx" -class SMDS_EXPORT SMDS_LinearEdge: public SMDS_MeshEdge +class SMDS_EXPORT SMDS_LinearEdge: public SMDS_CellOfNodes { - public: SMDS_LinearEdge(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2); - bool ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2); - void Print(std::ostream & OS) const; - virtual SMDSAbs_EntityType GetEntityType() const - { - return SMDSEntity_Edge; - } - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) - { - return false; - } - int NbNodes() const; - int NbEdges() const; - friend bool operator<(const SMDS_LinearEdge& e1, const SMDS_LinearEdge& e2); + virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Edge; } + virtual SMDSAbs_GeometryType GetGeomType() const { return SMDSGeom_EDGE; } + virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Edge; } + virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); + virtual int NbNodes() const; + virtual int NbEdges() const; + virtual int NbFaces() const; - /*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ - virtual const SMDS_MeshNode* GetNode(const int ind) const; + virtual int NbCornerNodes() const { return NbNodes(); } + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; -protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; + virtual bool IsPoly() const { return false; } + virtual bool IsQuadratic() const { return false; } + + virtual SMDS_ElemIteratorPtr nodesIterator() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; + + virtual const SMDS_MeshNode* GetNode(const int ind) const; protected: - const SMDS_MeshNode* myNodes[3]; + const SMDS_MeshNode* myNodes[2]; }; #endif diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index 40caa2c88..1d7ba140b 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -26,35 +26,28 @@ #pragma warning(disable:4786) #endif -#include "SMDS_FaceOfEdges.hxx" -#include "SMDS_FaceOfNodes.hxx" #include "SMDS_Mesh.hxx" -#include "SMDS_PolygonalFaceOfNodes.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" -#include "SMDS_QuadraticEdge.hxx" -#include "SMDS_QuadraticFaceOfNodes.hxx" -#include "SMDS_QuadraticVolumeOfNodes.hxx" + +#include "SMDS_ElementFactory.hxx" +#include "SMDS_ElementHolder.hxx" #include "SMDS_SetIterator.hxx" #include "SMDS_SpacePosition.hxx" #include "SMDS_UnstructuredGrid.hxx" -#include "SMDS_VolumeOfFaces.hxx" -#include "SMDS_VolumeOfNodes.hxx" -#include "utilities.h" +#include #include -#include -#include +//#include #include +#include #include #include #include -#include #include #include -#include -using namespace std; + +#include #if !defined WIN32 && !defined __APPLE__ #include @@ -63,9 +56,9 @@ using namespace std; // number of added entities to check memory after #define CHECKMEMORY_INTERVAL 100000 -vector SMDS_Mesh::_meshList = vector(); -int SMDS_Mesh::chunkSize = 1024; +#define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified")); +int SMDS_Mesh::chunkSize = 1024; //================================================================================ /*! @@ -77,6 +70,7 @@ int SMDS_Mesh::chunkSize = 1024; int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) { + return -1; #if !defined WIN32 && !defined __APPLE__ struct sysinfo si; int err = sysinfo( &si ); @@ -87,13 +81,16 @@ int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) static int limit = -1; if ( limit < 0 ) { - int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM - if (status >= 0 ) { - limit = WEXITSTATUS(status); - } - else { - double factor = ( si.totalswap == 0 ) ? 0.1 : 0.2; - limit = int(( factor * si.totalram * si.mem_unit ) / Mbyte ); + if ( si.totalswap == 0 ) + { + int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM + if (status >= 0 ) { + limit = WEXITSTATUS(status); + } + else { + double factor = ( si.totalswap == 0 ) ? 0.1 : 0.2; + limit = int(( factor * si.totalram * si.mem_unit ) / Mbyte ); + } } if ( limit < 20 ) limit = 20; @@ -106,7 +103,6 @@ int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) int freeMb = ( si.freeram * si.mem_unit ) / Mbyte + ( si.freeswap * si.mem_unit ) / Mbyte; - //cout << "freeMb = " << freeMb << " limit = " << limit << endl; if ( freeMb > limit ) return freeMb - limit; @@ -125,29 +121,12 @@ int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) /// Create a new mesh object /////////////////////////////////////////////////////////////////////////////// SMDS_Mesh::SMDS_Mesh(): - myNodePool(0), myVolumePool(0), myFacePool(0), myEdgePool(0), myBallPool(0), + myNodeFactory( new SMDS_NodeFactory( this )), + myCellFactory( new SMDS_ElementFactory( this )), myParent(NULL), - myNodeIDFactory(new SMDS_MeshNodeIDFactory()), - myElementIDFactory(new SMDS_MeshElementIDFactory()), myModified(false), myModifTime(0), myCompactTime(0), - myHasConstructionEdges(false), myHasConstructionFaces(false), - myHasInverseElements(true), xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0) { - myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector - myNodeIDFactory->SetMesh(this); - myElementIDFactory->SetMesh(this); - _meshList.push_back(this); - myNodePool = new ObjectPool(SMDS_Mesh::chunkSize); - myEdgePool = new ObjectPool(SMDS_Mesh::chunkSize); - myFacePool = new ObjectPool(SMDS_Mesh::chunkSize); - myVolumePool = new ObjectPool(SMDS_Mesh::chunkSize); - myBallPool = new ObjectPool(SMDS_Mesh::chunkSize); - - myNodes.clear(); - myCells.clear(); - //myCellIdSmdsToVtk.clear(); - myCellIdVtkToSmds.clear(); myGrid = SMDS_UnstructuredGrid::New(); myGrid->setSMDS_mesh(this); myGrid->Initialize(); @@ -156,22 +135,13 @@ SMDS_Mesh::SMDS_Mesh(): // bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion" // Use double type for storing coordinates of nodes instead of float. points->SetDataType(VTK_DOUBLE); - points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/); + points->SetNumberOfPoints( 0 ); myGrid->SetPoints( points ); points->Delete(); - //myGrid->BuildLinks(); this->Modified(); // initialize static maps in SMDS_MeshCell, to be thread-safe - if ( myMeshId == 0 ) - { - SMDS_MeshCell::toVtkType( SMDSEntity_Node ); - SMDS_MeshCell::toVtkOrder( SMDSEntity_Node ); - SMDS_MeshCell::reverseSmdsOrder( SMDSEntity_Node ); - SMDS_MeshCell::interlacedSmdsOrder( SMDSEntity_Node ); - SMDS_MeshCell::toSmdsType( VTK_VERTEX ); - SMDS_MeshCell::fromVtkOrder( SMDSEntity_Node ); - } + SMDS_MeshCell::InitStaticMembers(); } /////////////////////////////////////////////////////////////////////////////// @@ -180,15 +150,9 @@ SMDS_Mesh::SMDS_Mesh(): /// (2003-09-08) of SMESH /////////////////////////////////////////////////////////////////////////////// SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent): - myNodePool(parent->myNodePool), - myVolumePool(parent->myVolumePool), - myFacePool(parent->myFacePool), - myEdgePool(parent->myEdgePool), - myBallPool(parent->myBallPool), - myParent(parent), myNodeIDFactory(parent->myNodeIDFactory), - myElementIDFactory(parent->myElementIDFactory), - myHasConstructionEdges(false), myHasConstructionFaces(false), - myHasInverseElements(true) + myNodeFactory( new SMDS_NodeFactory( this )), + myCellFactory( new SMDS_ElementFactory( this )), + myParent(parent) { } @@ -211,7 +175,7 @@ SMDS_Mesh *SMDS_Mesh::AddSubMesh() SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z) { - return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID()); + return SMDS_Mesh::AddNodeWithID( x,y,z, myNodeFactory->GetFreeID() ); } /////////////////////////////////////////////////////////////////////////////// @@ -219,33 +183,18 @@ SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z) ///@param ID : The ID of the MeshNode to create ///@return : The created node or NULL if a node with this ID already exists /////////////////////////////////////////////////////////////////////////////// -SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID) +SMDS_MeshNode * SMDS_Mesh::AddNodeWithID( double x, double y, double z, int ID ) { // find the MeshNode corresponding to ID - const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID); - if(!node){ - if (ID < 1) - { - MESSAGE("=============> Bad Node Id: " << ID); - ID = myNodeIDFactory->GetFreeID(); - } - myNodeIDFactory->adjustMaxId(ID); - SMDS_MeshNode * node = myNodePool->getNew(); - node->init(ID, myMeshId, 0, x, y, z); - - if (ID >= (int)myNodes.size()) - { - myNodes.resize(ID+SMDS_Mesh::chunkSize, 0); -// MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize); - } - myNodes[ID] = node; - myNodeIDFactory->BindID(ID,node); + SMDS_MeshNode *node = myNodeFactory->NewNode( ID ); + if ( node ) + { + node->init( x, y, z ); myInfo.myNbNodes++; myModified = true; this->adjustBoundingBox(x, y, z); - return node; - }else - return NULL; + } + return node; } /////////////////////////////////////////////////////////////////////////////// @@ -254,7 +203,7 @@ SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID) /////////////////////////////////////////////////////////////////////////////// SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID) { - SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode); + const SMDS_MeshNode * node = myNodeFactory->FindNode(idnode); if (!node) return NULL; return SMDS_Mesh::Add0DElementWithID(node, ID); } @@ -265,7 +214,7 @@ SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID) /////////////////////////////////////////////////////////////////////////////// SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node) { - return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::Add0DElementWithID( node, myCellFactory->GetFreeID() ); } /////////////////////////////////////////////////////////////////////////////// @@ -280,30 +229,26 @@ SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int I if (!n) return 0; if (Nb0DElements() % CHECKMEMORY_INTERVAL == 0) CheckMemory(); - //MESSAGE("Add0DElementWithID" << ID) - SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n); - if (myElementIDFactory->BindID(ID, el0d)) { - //SMDS_MeshNode *node = const_cast(n); - //node->AddInverseElement(el0d);// --- fait avec BindID - adjustmyCellsCapacity(ID); - myCells[ID] = el0d; + + if ( SMDS_MeshCell * cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_0D, /*nbNodes=*/1, n ); myInfo.myNb0DElements++; - return el0d; + return static_cast< SMDS_Mesh0DElement*> ( cell ); } - delete el0d; - return NULL; + return 0; } /////////////////////////////////////////////////////////////////////////////// /// create a Ball and add it to the current Mesh /// @return : The created Ball /////////////////////////////////////////////////////////////////////////////// -SMDS_BallElement* SMDS_Mesh::AddBallWithID(int idnode, double diameter, int ID) +SMDS_BallElement* SMDS_Mesh::AddBallWithID( int idnode, double diameter, int ID ) { - SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode); + const SMDS_MeshNode * node = myNodeFactory->FindNode( idnode ); if (!node) return NULL; - return SMDS_Mesh::AddBallWithID(node, diameter, ID); + return SMDS_Mesh::AddBallWithID( node, diameter, ID ); } /////////////////////////////////////////////////////////////////////////////// @@ -312,7 +257,7 @@ SMDS_BallElement* SMDS_Mesh::AddBallWithID(int idnode, double diameter, int ID) /////////////////////////////////////////////////////////////////////////////// SMDS_BallElement* SMDS_Mesh::AddBall(const SMDS_MeshNode * node, double diameter) { - return SMDS_Mesh::AddBallWithID(node, diameter, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::AddBallWithID(node, diameter, myCellFactory->GetFreeID()); } /////////////////////////////////////////////////////////////////////////////// @@ -329,17 +274,12 @@ SMDS_BallElement* SMDS_Mesh::AddBallWithID(const SMDS_MeshNode * n, double diame if (NbBalls() % CHECKMEMORY_INTERVAL == 0) CheckMemory(); - SMDS_BallElement *ball = myBallPool->getNew(); - ball->init(n->getVtkId(), diameter, this); - if (!this->registerElement(ID,ball)) + SMDS_BallElement* ball = static_cast< SMDS_BallElement*>( myCellFactory->NewElement( ID )); + if ( ball ) { - this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL); - myBallPool->destroy(ball); - return 0; + ball->init( n, diameter ); + myInfo.myNbBalls++; } - adjustmyCellsCapacity(ID); - myCells[ID] = ball; - myInfo.myNbBalls++; return ball; } @@ -350,8 +290,8 @@ SMDS_BallElement* SMDS_Mesh::AddBallWithID(const SMDS_MeshNode * n, double diame SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID) { - SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); + const SMDS_MeshNode * node1 = myNodeFactory->FindNode(idnode1); + const SMDS_MeshNode * node2 = myNodeFactory->FindNode(idnode2); if(!node1 || !node2) return NULL; return SMDS_Mesh::AddEdgeWithID(node1, node2, ID); } @@ -364,7 +304,7 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID) SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2) { - return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::AddEdgeWithID(node1, node2, myCellFactory->GetFreeID()); } /////////////////////////////////////////////////////////////////////////////// @@ -378,36 +318,17 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1, SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n2, - int ID) + int ID) { if ( !n1 || !n2 ) return 0; - SMDS_MeshEdge * edge = 0; - - // --- retrieve nodes ID - vector nodeIds; - nodeIds.clear(); - nodeIds.push_back(n1->getVtkId()); - nodeIds.push_back(n2->getVtkId()); - - SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); - edgevtk->init(nodeIds, this); - if (!this->registerElement(ID,edgevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL); - myEdgePool->destroy(edgevtk); - return 0; - } - edge = edgevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = edge; - myInfo.myNbEdges++; -// if (edge && !registerElement(ID, edge)) -// { -// RemoveElement(edge, false); -// edge = NULL; -// } - return edge; + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Edge, /*nbNodes=*/2, n1, n2 ); + myInfo.myNbEdges++; + return static_cast( cell ); + } + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -419,7 +340,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, const SMDS_MeshNode * n2, const SMDS_MeshNode * n3) { - return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myCellFactory->GetFreeID()); } /////////////////////////////////////////////////////////////////////////////// @@ -428,9 +349,9 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID) { - SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); - SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3); + const SMDS_MeshNode * node1 = myNodeFactory->FindNode(idnode1); + const SMDS_MeshNode * node2 = myNodeFactory->FindNode(idnode2); + const SMDS_MeshNode * node3 = myNodeFactory->FindNode(idnode3); if(!node1 || !node2 || !node3) return NULL; return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID); } @@ -444,14 +365,16 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n3, int ID) { - //MESSAGE("AddFaceWithID " << ID) - SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID); + if ( !n1 || !n2 || !n3 ) return 0; + if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); -// if (face && !registerElement(ID, face)) { -// RemoveElement(face, false); -// face = NULL; -// } - return face; + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Triangle, /*nbNodes=*/3, n1, n2, n3 ); + myInfo.myNbTriangles++; + return static_cast( cell ); + } + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -464,7 +387,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, const SMDS_MeshNode * n3, const SMDS_MeshNode * n4) { - return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myCellFactory->GetFreeID()); } /////////////////////////////////////////////////////////////////////////////// @@ -477,12 +400,12 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode4, int ID) { - SMDS_MeshNode *node1, *node2, *node3, *node4; - node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); - node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3); - node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4); - if(!node1 || !node2 || !node3 || !node4) return NULL; + const SMDS_MeshNode *node1, *node2, *node3, *node4; + node1 = myNodeFactory->FindNode(idnode1); + node2 = myNodeFactory->FindNode(idnode2); + node3 = myNodeFactory->FindNode(idnode3); + node4 = myNodeFactory->FindNode(idnode4); + if ( !node1 || !node2 || !node3 || !node4 ) return NULL; return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID); } @@ -496,100 +419,16 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n4, int ID) { - //MESSAGE("AddFaceWithID " << ID); - SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID); - -// if (face && !registerElement(ID, face)) { -// RemoveElement(face, false); -// face = NULL; -// } - return face; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Add a triangle defined by its edges. An ID is automatically assigned to the -/// Created face -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3) -{ - if (!hasConstructionEdges()) - return NULL; - //MESSAGE("AddFaceWithID"); - return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID()); -} - -/////////////////////////////////////////////////////////////////////////////// -/// Add a triangle defined by its edges -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3, - int ID) -{ - if (!hasConstructionEdges()) - return NULL; - if ( !e1 || !e2 || !e3 ) return 0; - - if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - - SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3); - adjustmyCellsCapacity(ID); - myCells[ID] = face; - myInfo.myNbTriangles++; - - if (!registerElement(ID, face)) { - registerElement(myElementIDFactory->GetFreeID(), face); - //RemoveElement(face, false); - //face = NULL; - } - return face; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Add a quadrangle defined by its edges. An ID is automatically assigned to the -/// Created face -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3, - const SMDS_MeshEdge * e4) -{ - if (!hasConstructionEdges()) - return NULL; - return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID()); -} - -/////////////////////////////////////////////////////////////////////////////// -/// Add a quadrangle defined by its edges -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3, - const SMDS_MeshEdge * e4, - int ID) -{ - if (!hasConstructionEdges()) - return NULL; - if ( !e1 || !e2 || !e3 || !e4 ) return 0; + if ( !n1 || !n2 || !n3 || !n4 ) return 0; if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4); - adjustmyCellsCapacity(ID); - myCells[ID] = face; - myInfo.myNbQuadrangles++; - if (!registerElement(ID, face)) + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - registerElement(myElementIDFactory->GetFreeID(), face); - //RemoveElement(face, false); - //face = NULL; + cell->init( SMDSEntity_Quadrangle, /*nbNodes=*/4, n1, n2, n3, n4 ); + myInfo.myNbQuadrangles++; + return static_cast( cell ); } - return face; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -602,10 +441,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n3, const SMDS_MeshNode * n4) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, myCellFactory->GetFreeID() ); } /////////////////////////////////////////////////////////////////////////////// @@ -621,11 +457,11 @@ SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1, int idnode4, int ID) { - SMDS_MeshNode *node1, *node2, *node3, *node4; - node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); - node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3); - node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4); + const SMDS_MeshNode *node1, *node2, *node3, *node4; + node1 = myNodeFactory->FindNode(idnode1); + node2 = myNodeFactory->FindNode(idnode2); + node3 = myNodeFactory->FindNode(idnode3); + node4 = myNodeFactory->FindNode(idnode4); if(!node1 || !node2 || !node3 || !node4) return NULL; return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID); } @@ -642,49 +478,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n4, int ID) { - SMDS_MeshVolume* volume = 0; - if ( !n1 || !n2 || !n3 || !n4) return volume; + if ( !n1 || !n2 || !n3 || !n4 ) return 0; if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if(hasConstructionFaces()) { - SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3); - SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4); - SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4); - SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4); - volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4); - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbTetras++; - } - else if(hasConstructionEdges()) { - return NULL; - } - else { - // --- retrieve nodes ID - myNodeIds.resize(4); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n3->getVtkId(); // order SMDS-->VTK - myNodeIds[2] = n2->getVtkId(); - myNodeIds[3] = n4->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - volume = volvtk; - adjustmyCellsCapacity(ID); - myCells[ID] = volume; + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Tetra, /*nbNodes=*/4, n1, n2, n3, n4 ); myInfo.myNbTetras++; + return static_cast( cell ); } - - // if (!registerElement(ID, volume)) { - // RemoveElement(volume, false); - // volume = NULL; - // } - return volume; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -699,10 +502,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n4, const SMDS_MeshNode * n5) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, myCellFactory->GetFreeID() ); } /////////////////////////////////////////////////////////////////////////////// @@ -720,12 +520,12 @@ SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1, int idnode5, int ID) { - SMDS_MeshNode *node1, *node2, *node3, *node4, *node5; - node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); - node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3); - node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4); - node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5); + const SMDS_MeshNode *node1, *node2, *node3, *node4, *node5; + node1 = myNodeFactory->FindNode(idnode1); + node2 = myNodeFactory->FindNode(idnode2); + node3 = myNodeFactory->FindNode(idnode3); + node4 = myNodeFactory->FindNode(idnode4); + node5 = myNodeFactory->FindNode(idnode5); if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL; return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID); } @@ -744,50 +544,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n5, int ID) { - SMDS_MeshVolume* volume = 0; - if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume; + if ( !n1 || !n2 || !n3 || !n4 || !n5 ) return 0; if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if(hasConstructionFaces()) { - SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4); - SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5); - SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5); - SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5); - volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4); - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbPyramids++; - } - else if(hasConstructionEdges()) { - return NULL; - } - else { - // --- retrieve nodes ID - myNodeIds.resize(5); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n4->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n2->getVtkId(); - myNodeIds[4] = n5->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - volume = volvtk; - adjustmyCellsCapacity(ID); - myCells[ID] = volume; + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Pyramid, /*nbNodes=*/5, n1, n2, n3, n4, n5 ); myInfo.myNbPyramids++; + return static_cast( cell ); } - - // if (!registerElement(ID, volume)) { - // RemoveElement(volume, false); - // volume = NULL; - // } - return volume; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -803,10 +569,8 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n5, const SMDS_MeshNode * n6) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + int ID = myCellFactory->GetFreeID(); + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID); } /////////////////////////////////////////////////////////////////////////////// @@ -825,14 +589,13 @@ SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1, int idnode6, int ID) { - SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6; - node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); - node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3); - node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4); - node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5); - node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6); - if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL; + const SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6; + node1 = myNodeFactory->FindNode(idnode1); + node2 = myNodeFactory->FindNode(idnode2); + node3 = myNodeFactory->FindNode(idnode3); + node4 = myNodeFactory->FindNode(idnode4); + node5 = myNodeFactory->FindNode(idnode5); + node6 = myNodeFactory->FindNode(idnode6); return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID); } @@ -851,52 +614,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n6, int ID) { - SMDS_MeshVolume* volume = 0; - if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume; + if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 ) return 0; if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if(hasConstructionFaces()) { - SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3); - SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6); - SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2); - SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3); - SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1); - volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5); - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbPrisms++; - } - else if(hasConstructionEdges()) { - return NULL; - } - else { - // --- retrieve nodes ID - myNodeIds.resize(6); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n4->getVtkId(); - myNodeIds[4] = n5->getVtkId(); - myNodeIds[5] = n6->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - volume = volvtk; - adjustmyCellsCapacity(ID); - myCells[ID] = volume; + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Penta, /*nbNodes=*/6, n1, n2, n3, n4, n5, n6 ); myInfo.myNbPrisms++; + return static_cast( cell ); } - - // if (!registerElement(ID, volume)) { - // RemoveElement(volume, false); - // volume = NULL; - // } - return volume; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -917,12 +644,9 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n11, const SMDS_MeshNode * n12) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, - n7, n8, n9, n10, n11, n12, - ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, + n7, n8, n9, n10, n11, n12, + myCellFactory->GetFreeID() ); } /////////////////////////////////////////////////////////////////////////////// @@ -946,18 +670,18 @@ SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1, int idnode12, int ID) { - SMDS_MeshNode *node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - SMDS_MeshNode *node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); - SMDS_MeshNode *node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3); - SMDS_MeshNode *node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4); - SMDS_MeshNode *node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5); - SMDS_MeshNode *node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6); - SMDS_MeshNode *node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7); - SMDS_MeshNode *node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8); - SMDS_MeshNode *node9 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode9); - SMDS_MeshNode *node10 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode10); - SMDS_MeshNode *node11 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode11); - SMDS_MeshNode *node12 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode12); + const SMDS_MeshNode *node1 = myNodeFactory->FindNode(idnode1); + const SMDS_MeshNode *node2 = myNodeFactory->FindNode(idnode2); + const SMDS_MeshNode *node3 = myNodeFactory->FindNode(idnode3); + const SMDS_MeshNode *node4 = myNodeFactory->FindNode(idnode4); + const SMDS_MeshNode *node5 = myNodeFactory->FindNode(idnode5); + const SMDS_MeshNode *node6 = myNodeFactory->FindNode(idnode6); + const SMDS_MeshNode *node7 = myNodeFactory->FindNode(idnode7); + const SMDS_MeshNode *node8 = myNodeFactory->FindNode(idnode8); + const SMDS_MeshNode *node9 = myNodeFactory->FindNode(idnode9); + const SMDS_MeshNode *node10 = myNodeFactory->FindNode(idnode10); + const SMDS_MeshNode *node11 = myNodeFactory->FindNode(idnode11); + const SMDS_MeshNode *node12 = myNodeFactory->FindNode(idnode12); return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, node7, node8, node9, node10, node11, node12, ID); @@ -988,44 +712,15 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, !n7 || !n8 || !n9 || !n10 || !n11 || !n12 ) return volume; if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if(hasConstructionFaces()) { - return NULL; - } - else if(hasConstructionEdges()) { - return NULL; - } - else { - // --- retrieve nodes ID - myNodeIds.resize(12); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n6->getVtkId(); - myNodeIds[2] = n5->getVtkId(); - myNodeIds[3] = n4->getVtkId(); - myNodeIds[4] = n3->getVtkId(); - myNodeIds[5] = n2->getVtkId(); - - myNodeIds[6] = n7->getVtkId(); - myNodeIds[7] = n12->getVtkId(); - myNodeIds[8] = n11->getVtkId(); - myNodeIds[9] = n10->getVtkId(); - myNodeIds[10] = n9->getVtkId(); - myNodeIds[11] = n8->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - volume = volvtk; - adjustmyCellsCapacity(ID); - myCells[ID] = volume; + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Hexagonal_Prism, + /*nbNodes=*/12, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12 ); myInfo.myNbHexPrism++; + return static_cast( cell ); } - - return volume; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -1043,10 +738,8 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n7, const SMDS_MeshNode * n8) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + int ID = myCellFactory->GetFreeID(); + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID); } /////////////////////////////////////////////////////////////////////////////// @@ -1067,17 +760,15 @@ SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1, int idnode8, int ID) { - SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8; - node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1); - node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2); - node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3); - node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4); - node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5); - node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6); - node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7); - node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8); - if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6 || !node7 || !node8) - return NULL; + const SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6, *node7, *node8; + node1 = myNodeFactory->FindNode(idnode1); + node2 = myNodeFactory->FindNode(idnode2); + node3 = myNodeFactory->FindNode(idnode3); + node4 = myNodeFactory->FindNode(idnode4); + node5 = myNodeFactory->FindNode(idnode5); + node6 = myNodeFactory->FindNode(idnode6); + node7 = myNodeFactory->FindNode(idnode7); + node8 = myNodeFactory->FindNode(idnode8); return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, node7, node8, ID); } @@ -1103,203 +794,28 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, SMDS_MeshVolume* volume = 0; if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume; if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if(hasConstructionFaces()) { - SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4); - SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8); - SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n8,n5); - SMDS_MeshFace * f4=FindFaceOrCreate(n1,n2,n6,n5); - SMDS_MeshFace * f5=FindFaceOrCreate(n2,n3,n7,n6); - SMDS_MeshFace * f6=FindFaceOrCreate(n3,n4,n8,n7); - volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6); - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbHexas++; - } - else if(hasConstructionEdges()) { - return NULL; - } - else { - // --- retrieve nodes ID - myNodeIds.resize(8); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n4->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n2->getVtkId(); - myNodeIds[4] = n5->getVtkId(); - myNodeIds[5] = n8->getVtkId(); - myNodeIds[6] = n7->getVtkId(); - myNodeIds[7] = n6->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - volume = volvtk; - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbHexas++; - } - - // if (!registerElement(ID, volume)) { - // RemoveElement(volume, false); - // volume = NULL; - // } - return volume; -} - -/////////////////////////////////////////////////////////////////////////////// -///Create a new tetrahedron defined by its faces and add it to the mesh. -///@return The created tetrahedron -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4) -{ - if (!hasConstructionFaces()) - return NULL; - return AddVolumeWithID(f1,f2,f3,f4, myElementIDFactory->GetFreeID()); -} - -/////////////////////////////////////////////////////////////////////////////// -///Create a new tetrahedron defined by its faces and add it to the mesh. -///@param ID The ID of the new volume -///@return The created tetrahedron -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - int ID) -{ - if (!hasConstructionFaces()) - return NULL; - if ( !f1 || !f2 || !f3 || !f4) return 0; - if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4); - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbTetras++; - - if (!registerElement(ID, volume)) { - registerElement(myElementIDFactory->GetFreeID(), volume); - //RemoveElement(volume, false); - //volume = NULL; - } - return volume; -} - -/////////////////////////////////////////////////////////////////////////////// -///Create a new pyramid defined by its faces and add it to the mesh. -///@return The created pyramid -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5) -{ - if (!hasConstructionFaces()) - return NULL; - return AddVolumeWithID(f1,f2,f3,f4,f5, myElementIDFactory->GetFreeID()); -} - -/////////////////////////////////////////////////////////////////////////////// -///Create a new pyramid defined by its faces and add it to the mesh. -///@param ID The ID of the new volume -///@return The created pyramid -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5, - int ID) -{ - if (!hasConstructionFaces()) - return NULL; - if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0; - if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5); - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbPyramids++; - - if (!registerElement(ID, volume)) { - registerElement(myElementIDFactory->GetFreeID(), volume); - //RemoveElement(volume, false); - //volume = NULL; - } - return volume; -} - -/////////////////////////////////////////////////////////////////////////////// -///Create a new prism defined by its faces and add it to the mesh. -///@return The created prism -/////////////////////////////////////////////////////////////////////////////// - -SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5, - const SMDS_MeshFace * f6) -{ - if (!hasConstructionFaces()) - return NULL; - return AddVolumeWithID(f1,f2,f3,f4,f5,f6, myElementIDFactory->GetFreeID()); -} - -/////////////////////////////////////////////////////////////////////////////// -///Create a new prism defined by its faces and add it to the mesh. -///@param ID The ID of the new volume -///@return The created prism -/////////////////////////////////////////////////////////////////////////////// -SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5, - const SMDS_MeshFace * f6, - int ID) -{ - if (!hasConstructionFaces()) - return NULL; - if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0; - if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6); - adjustmyCellsCapacity(ID); - myCells[ID] = volume; - myInfo.myNbPrisms++; - - if (!registerElement(ID, volume)) { - registerElement(myElementIDFactory->GetFreeID(), volume); - //RemoveElement(volume, false); - //volume = NULL; + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Hexa, + /*nbNodes=*/8, n1, n2, n3, n4, n5, n6, n7, n8 ); + myInfo.myNbHexas++; + return static_cast( cell ); } - return volume; + return 0; } /////////////////////////////////////////////////////////////////////////////// /// Add a polygon defined by its nodes IDs /////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (const vector & nodes_ids, - const int ID) +SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (const std::vector & nodes_ids, + const int ID) { int nbNodes = nodes_ids.size(); - vector nodes (nbNodes); + std::vector nodes (nbNodes); for (int i = 0; i < nbNodes; i++) { - nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]); + nodes[i] = myNodeFactory->FindNode( nodes_ids[i] ); if (!nodes[i]) return NULL; } return SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID); @@ -1310,38 +826,18 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID (const vector & nodes_ids, /////////////////////////////////////////////////////////////////////////////// SMDS_MeshFace* -SMDS_Mesh::AddPolygonalFaceWithID (const vector & nodes, - const int ID) +SMDS_Mesh::AddPolygonalFaceWithID (const std::vector & nodes, + const int ID) { - SMDS_MeshFace * face; - if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if (hasConstructionEdges()) - { - return NULL; - } - else - { - myNodeIds.resize( nodes.size() ); - for ( size_t i = 0; i < nodes.size(); ++i ) - myNodeIds[i] = nodes[i]->getVtkId(); - - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->initPoly(myNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) + { + cell->init( SMDSEntity_Polygon, nodes ); myInfo.myNbPolygons++; + return static_cast( cell ); } - - return face; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -1349,21 +845,21 @@ SMDS_Mesh::AddPolygonalFaceWithID (const vector & nodes, /// An ID is automatically affected to the created face. /////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (const vector & nodes) +SMDS_MeshFace* SMDS_Mesh::AddPolygonalFace (const std::vector & nodes) { - return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::AddPolygonalFaceWithID(nodes, myCellFactory->GetFreeID()); } /////////////////////////////////////////////////////////////////////////////// /// Add a quadratic polygon defined by its nodes IDs /////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector & nodes_ids, - const int ID) +SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector & nodes_ids, + const int ID) { - vector nodes( nodes_ids.size() ); + std::vector nodes( nodes_ids.size() ); for ( size_t i = 0; i < nodes.size(); i++) { - nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]); + nodes[i] = myNodeFactory->FindNode(nodes_ids[i]); if (!nodes[i]) return NULL; } return SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, ID); @@ -1374,36 +870,17 @@ SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector & nodes_ /////////////////////////////////////////////////////////////////////////////// SMDS_MeshFace* -SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector & nodes, - const int ID) +SMDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector & nodes, + const int ID) { - SMDS_MeshFace * face; - if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if (hasConstructionEdges()) - { - return NULL; - } - else + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - myNodeIds.resize( nodes.size() ); - for ( size_t i = 0; i < nodes.size(); ++i ) - myNodeIds[i] = nodes[i]->getVtkId(); - - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->initQuadPoly(myNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; + cell->init( SMDSEntity_Quad_Polygon, nodes ); myInfo.myNbQuadPolygons++; + return static_cast( cell ); } - return face; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -1411,9 +888,9 @@ SMDS_Mesh::AddQuadPolygonalFaceWithID (const vector & node /// An ID is automatically affected to the created face. /////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFace (const vector & nodes) +SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFace (const std::vector & nodes) { - return SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, myCellFactory->GetFreeID()); } /////////////////////////////////////////////////////////////////////////////// @@ -1423,15 +900,14 @@ SMDS_MeshFace* SMDS_Mesh::AddQuadPolygonalFace (const vector & nodes_ids, - const vector & quantities, - const int ID) +SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID (const std::vector & nodes_ids, + const std::vector & quantities, + const int ID) { int nbNodes = nodes_ids.size(); - vector nodes (nbNodes); + std::vector nodes (nbNodes); for (int i = 0; i < nbNodes; i++) { - nodes[i] = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nodes_ids[i]); + nodes[i] = myNodeFactory->FindNode(nodes_ids[i]); if (!nodes[i]) return NULL; } return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID); @@ -1444,57 +920,22 @@ SMDS_MeshVolume * SMDS_Mesh::AddPolyhedralVolumeWithID /////////////////////////////////////////////////////////////////////////////// SMDS_MeshVolume* -SMDS_Mesh::AddPolyhedralVolumeWithID (const vector& nodes, - const vector & quantities, +SMDS_Mesh::AddPolyhedralVolumeWithID (const std::vector& nodes, + const std::vector & quantities, const int ID) { - SMDS_MeshVolume* volume = 0; if ( nodes.empty() || quantities.empty() ) return NULL; if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if (hasConstructionFaces()) - { - return NULL; - } - else if (hasConstructionEdges()) - { - return NULL; - } - else + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - //#ifdef VTK_HAVE_POLYHEDRON - myNodeIds.resize( nodes.size() ); - for ( size_t i = 0; i < nodes.size(); ++i ) - myNodeIds[i] = nodes[i]->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->initPoly(myNodeIds, quantities, this); - if (!this->registerElement(ID, volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - volume = volvtk; - //#else - // for ( int i = 0; i < nodes.size(); ++i ) - // if ( !nodes[ i ] ) return 0; - // volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities); - //#endif - adjustmyCellsCapacity(ID); - myCells[ID] = volume; + SMDS_MeshVolume* volume = static_cast( cell ); + volume->init( nodes, quantities ); myInfo.myNbPolyhedrons++; + return volume; } - - //#ifndef VTK_HAVE_POLYHEDRON - // if (!registerElement(ID, volume)) - // { - // registerElement(myElementIDFactory->GetFreeID(), volume); - // //RemoveElement(volume, false); - // //volume = NULL; - // } - //#endif - return volume; + return 0; } /////////////////////////////////////////////////////////////////////////////// @@ -1503,160 +944,31 @@ SMDS_Mesh::AddPolyhedralVolumeWithID (const vector& nodes, /////////////////////////////////////////////////////////////////////////////// SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume - (const vector & nodes, - const vector & quantities) +(const std::vector & nodes, + const std::vector & quantities) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID); - if (v == NULL) myElementIDFactory->ReleaseID(ID); - return v; + int ID = myCellFactory->GetFreeID(); + return SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID); } SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector& vtkNodeIds) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeFromVtkIdsWithID(vtkNodeIds, ID); - if (v == NULL) myElementIDFactory->ReleaseID(ID); - return v; -} - -SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIdsWithID(const std::vector& vtkNodeIds, const int ID) -{ - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(vtkNodeIds, this); - if (!this->registerElement(ID,volvtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; - } - adjustmyCellsCapacity(ID); - myCells[ID] = volvtk; - vtkIdType aVtkType = volvtk->GetVtkType(); - switch (aVtkType) - { - case VTK_TETRA: - myInfo.myNbTetras++; - break; - case VTK_PYRAMID: - myInfo.myNbPyramids++; - break; - case VTK_WEDGE: - myInfo.myNbPrisms++; - break; - case VTK_HEXAHEDRON: - myInfo.myNbHexas++; - break; - case VTK_QUADRATIC_TETRA: - myInfo.myNbQuadTetras++; - break; - case VTK_QUADRATIC_PYRAMID: - myInfo.myNbQuadPyramids++; - break; - case VTK_QUADRATIC_WEDGE: - myInfo.myNbQuadPrisms++; - break; - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - myInfo.myNbBiQuadPrisms++; - break; - case VTK_QUADRATIC_HEXAHEDRON: - myInfo.myNbQuadHexas++; - break; - case VTK_TRIQUADRATIC_HEXAHEDRON: - myInfo.myNbTriQuadHexas++; - break; -//#ifdef VTK_HAVE_POLYHEDRON - case VTK_POLYHEDRON: - myInfo.myNbPolyhedrons++; - break; -//#endif - default: - myInfo.myNbPolyhedrons++; - break; - } - return volvtk; + SMDS_MeshCell* cell = myCellFactory->NewCell( myCellFactory->GetFreeID() ); + SMDS_MeshVolume * vol = static_cast( cell ); + vol->init( vtkNodeIds ); + myInfo.add( cell ); + return vol; } SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIds(const std::vector& vtkNodeIds) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshFace * f = SMDS_Mesh::AddFaceFromVtkIdsWithID(vtkNodeIds, ID); - if (f == NULL) myElementIDFactory->ReleaseID(ID); + SMDS_MeshCell* cell = myCellFactory->NewCell( myCellFactory->GetFreeID() ); + SMDS_MeshFace * f = static_cast( cell ); + f->init( vtkNodeIds ); + myInfo.add( cell ); return f; } -SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIdsWithID(const std::vector& vtkNodeIds, const int ID) -{ - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(vtkNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - adjustmyCellsCapacity(ID); - myCells[ID] = facevtk; - vtkIdType aVtkType = facevtk->GetVtkType(); - switch (aVtkType) - { - case VTK_TRIANGLE: - myInfo.myNbTriangles++; - break; - case VTK_QUAD: - myInfo.myNbQuadrangles++; - break; - case VTK_QUADRATIC_TRIANGLE: - myInfo.myNbQuadTriangles++; - break; - case VTK_QUADRATIC_QUAD: - myInfo.myNbQuadQuadrangles++; - break; - case VTK_BIQUADRATIC_QUAD: - myInfo.myNbBiQuadQuadrangles++; - break; - case VTK_BIQUADRATIC_TRIANGLE: - myInfo.myNbBiQuadTriangles++; - break; - case VTK_POLYGON: - myInfo.myNbPolygons++; - break; - default: - myInfo.myNbPolygons++; - } - return facevtk; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Registers element with the given ID, maintains inverse connections -/////////////////////////////////////////////////////////////////////////////// -bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element) -{ - if ((ID >=0) && (ID < (int)myCells.size()) && myCells[ID]) // --- already bound - { - MESSAGE(" ------------------ already bound "<< ID << " " << myCells[ID]->getVtkId()); - return false; - } - - element->myID = ID; - element->myMeshId = myMeshId; - - SMDS_MeshCell *cell = dynamic_cast(element); - MYASSERT(cell); - int vtkId = cell->getVtkId(); - if (vtkId == -1) - vtkId = myElementIDFactory->SetInVtkGrid(element); - - if (vtkId >= (int)myCellIdVtkToSmds.size()) // --- resize local vector - { - myCellIdVtkToSmds.resize(vtkId + SMDS_Mesh::chunkSize, -1); - } - myCellIdVtkToSmds[vtkId] = ID; - - myElementIDFactory->updateMinMax(ID); - return true; -} - //======================================================================= //function : MoveNode //purpose : @@ -1673,11 +985,7 @@ void SMDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z) /////////////////////////////////////////////////////////////////////////////// const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const { - if (ID < 1 || ID >= (int)myNodes.size()) - { - return 0; - } - return (const SMDS_MeshNode *)myNodes[ID]; + return myNodeFactory->FindNode( ID ); } /////////////////////////////////////////////////////////////////////////////// @@ -1685,117 +993,12 @@ const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const /////////////////////////////////////////////////////////////////////////////// const SMDS_MeshNode * SMDS_Mesh::FindNodeVtk(int vtkId) const { - // TODO if needed use mesh->nodeIdFromVtkToSmds - if ( vtkId < 0 || vtkId+1 >= (int) myNodes.size() ) - { - MESSAGE("------------------------------------------------------------------------- "); - MESSAGE("---------------------------- bad VTK ID " << vtkId << " " << myNodes.size()); - MESSAGE("------------------------------------------------------------------------- "); - return 0; - } - return (const SMDS_MeshNode *)myNodes[vtkId+1]; + return myNodeFactory->FindNode( vtkId + 1 ); } -////////////////////////////////////////////////////////////////////////////// -///Create a triangle and add it to the current mesh. This method does not bind -///an ID to the create triangle. -////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - int ID) +const SMDS_MeshElement * SMDS_Mesh::FindElementVtk(int IDelem) const { - if ( !node1 || !node2 || !node3) return 0; - if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if(hasConstructionEdges()) - { - SMDS_MeshEdge *edge1, *edge2, *edge3; - edge1=FindEdgeOrCreate(node1,node2); - edge2=FindEdgeOrCreate(node2,node3); - edge3=FindEdgeOrCreate(node3,node1); - - //int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element - SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3); - adjustmyCellsCapacity(ID); - myCells[ID] = face; - myInfo.myNbTriangles++; - return face; - } - else - { - // --- retrieve nodes ID - myNodeIds.resize(3); - myNodeIds[0] = node1->getVtkId(); - myNodeIds[1] = node2->getVtkId(); - myNodeIds[2] = node3->getVtkId(); - - SMDS_MeshFace * face = 0; - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(myNodeIds, this); // put in vtkUnstructuredGrid - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; - myInfo.myNbTriangles++; - return face; - } -} - -//////////////////////////////////////////////////////////////////////////////// -///Create a quadrangle and add it to the current mesh. This method does not bind -///an ID to the create triangle. -//////////////////////////////////////////////////////////////////////////////// -SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - int ID) -{ - if ( !node1 || !node2 || !node3 || !node4 ) return 0; - if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - if(hasConstructionEdges()) - { - SMDS_MeshEdge *edge1, *edge2, *edge3, *edge4; - edge1=FindEdgeOrCreate(node1,node2); - edge2=FindEdgeOrCreate(node2,node3); - edge3=FindEdgeOrCreate(node3,node4); - edge4=FindEdgeOrCreate(node4,node1); - - SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3,edge4); - adjustmyCellsCapacity(ID); - myCells[ID] = face; - myInfo.myNbQuadrangles++; - return face; - } - else - { - // --- retrieve nodes ID - myNodeIds.resize(4); - myNodeIds[0] = node1->getVtkId(); - myNodeIds[1] = node2->getVtkId(); - myNodeIds[2] = node3->getVtkId(); - myNodeIds[3] = node4->getVtkId(); - - SMDS_MeshFace * face = 0; - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(myNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; - myInfo.myNbQuadrangles++; - return face; - } + return myCellFactory->FindElement( FromVtkToSmds( IDelem )); } /////////////////////////////////////////////////////////////////////////////// @@ -1807,42 +1010,6 @@ void SMDS_Mesh::RemoveNode(const SMDS_MeshNode * node) RemoveElement(node, true); } -/////////////////////////////////////////////////////////////////////////////// -/// Remove an edge and all the elements which own this edge -/////////////////////////////////////////////////////////////////////////////// - -void SMDS_Mesh::Remove0DElement(const SMDS_Mesh0DElement * elem0d) -{ - RemoveElement(elem0d,true); -} - -/////////////////////////////////////////////////////////////////////////////// -/// Remove an edge and all the elements which own this edge -/////////////////////////////////////////////////////////////////////////////// - -void SMDS_Mesh::RemoveEdge(const SMDS_MeshEdge * edge) -{ - RemoveElement(edge,true); -} - -/////////////////////////////////////////////////////////////////////////////// -/// Remove an face and all the elements which own this face -/////////////////////////////////////////////////////////////////////////////// - -void SMDS_Mesh::RemoveFace(const SMDS_MeshFace * face) -{ - RemoveElement(face, true); -} - -/////////////////////////////////////////////////////////////////////////////// -/// Remove a volume -/////////////////////////////////////////////////////////////////////////////// - -void SMDS_Mesh::RemoveVolume(const SMDS_MeshVolume * volume) -{ - RemoveElement(volume, true); -} - //======================================================================= //function : RemoveFromParent //purpose : @@ -1863,7 +1030,7 @@ bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh) { bool found = false; - list::iterator itmsh=myChildren.begin(); + std::list::iterator itmsh=myChildren.begin(); for (; itmsh!=myChildren.end() && !found; itmsh++) { SMDS_Mesh * submesh = *itmsh; @@ -1886,28 +1053,27 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, const SMDS_MeshNode * nodes[], const int nbnodes) { - // keep current nodes of elem - set oldNodes( element->begin_nodes(), element->end_nodes() ); + // keep current nodes of element + std::set oldNodes( element->begin_nodes(), element->end_nodes() ); // change nodes bool Ok = false; - SMDS_MeshCell* cell = dynamic_cast((SMDS_MeshElement*) element); - if (cell) - { - Ok = cell->vtkOrder(nodes, nbnodes); + if ( SMDS_MeshCell* cell = dynamic_cast((SMDS_MeshElement*) element)) Ok = cell->ChangeNodes(nodes, nbnodes); - } - if ( Ok ) { // update InverseElements + if ( Ok ) + setMyModified(); - set::iterator it; + if ( Ok && GetGrid()->HasLinks() ) // update InverseElements + { + std::set::iterator it; // AddInverseElement to new nodes for ( int i = 0; i < nbnodes; i++ ) { it = oldNodes.find( nodes[i] ); if ( it == oldNodes.end() ) // new node - const_cast( nodes[i] )->AddInverseElement( cell ); + const_cast( nodes[i] )->AddInverseElement( element ); else // remove from oldNodes a node that remains in elem oldNodes.erase( it ); @@ -1916,84 +1082,13 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, for ( it = oldNodes.begin(); it != oldNodes.end(); it++ ) { SMDS_MeshNode * n = const_cast( *it ); - n->RemoveInverseElement( cell ); + n->RemoveInverseElement( element ); } } return Ok; } -//======================================================================= -//function : ChangePolyhedronNodes -//purpose : to change nodes of polyhedral volume -//======================================================================= -bool SMDS_Mesh::ChangePolyhedronNodes (const SMDS_MeshElement * elem, - const vector& nodes, - const vector & quantities) -{ - if (elem->GetType() != SMDSAbs_Volume) { - MESSAGE("WRONG ELEM TYPE"); - return false; - } - - const SMDS_VtkVolume* vol = dynamic_cast(elem); - if (!vol) { - return false; - } - - // keep current nodes of elem - set oldNodes; - SMDS_ElemIteratorPtr itn = elem->nodesIterator(); - while (itn->more()) { - oldNodes.insert(itn->next()); - } - - // change nodes - // TODO remove this function - //bool Ok = const_cast(vol)->ChangeNodes(nodes, quantities); - bool Ok = false; - if (!Ok) { - return false; - } - - // update InverseElements - - // AddInverseElement to new nodes - int nbnodes = nodes.size(); - set::iterator it; - for (int i = 0; i < nbnodes; i++) { - it = oldNodes.find(nodes[i]); - if (it == oldNodes.end()) { - // new node - const_cast(nodes[i])->AddInverseElement(elem); - } else { - // remove from oldNodes a node that remains in elem - oldNodes.erase(it); - } - } - - // RemoveInverseElement from the nodes removed from elem - for (it = oldNodes.begin(); it != oldNodes.end(); it++) { - SMDS_MeshNode * n = static_cast - (const_cast( *it )); - n->RemoveInverseElement(elem); - } - - return Ok; -} - - -//======================================================================= -//function : Find0DElement -//purpose : -//======================================================================= -const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(int idnode) const -{ - const SMDS_MeshNode * node = FindNode(idnode); - if(node == NULL) return NULL; - return Find0DElement(node); -} - const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node) { if (!node) return 0; @@ -2008,18 +1103,6 @@ const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node) return toReturn; } -//======================================================================= -//function : FindBall -//purpose : -//======================================================================= - -const SMDS_BallElement* SMDS_Mesh::FindBall(int idnode) const -{ - const SMDS_MeshNode * node = FindNode(idnode); - if(node == NULL) return NULL; - return FindBall(node); -} - const SMDS_BallElement* SMDS_Mesh::FindBall(const SMDS_MeshNode * node) { if (!node) return 0; @@ -2033,49 +1116,12 @@ const SMDS_BallElement* SMDS_Mesh::FindBall(const SMDS_MeshNode * node) return toReturn; } -//======================================================================= -//function : Find0DElementOrCreate -//purpose : -//======================================================================= -//SMDS_Mesh0DElement* SMDS_Mesh::Find0DElementOrCreate(const SMDS_MeshNode * node) -//{ -// if (!node) return 0; -// SMDS_Mesh0DElement * toReturn = NULL; -// toReturn = const_cast(Find0DElement(node)); -// if (toReturn == NULL) { -// //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory(); -// toReturn = new SMDS_Mesh0DElement(node); -// my0DElements.Add(toReturn); -// myInfo.myNb0DElements++; -// } -// return toReturn; -//} - - -//======================================================================= -//function : FindEdge -//purpose : -//======================================================================= - -const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2) const -{ - const SMDS_MeshNode * node1=FindNode(idnode1); - const SMDS_MeshNode * node2=FindNode(idnode2); - if((node1==NULL)||(node2==NULL)) return NULL; - return FindEdge(node1,node2); -} - -//#include "Profiler.h" const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2) { if ( !node1 ) return 0; const SMDS_MeshEdge * toReturn=NULL; - //PROFILER_Init(); - //PROFILER_Set(); SMDS_ElemIteratorPtr it1=node1->GetInverseElementIterator(SMDSAbs_Edge); - //PROFILER_Get(0); - //PROFILER_Set(); while(it1->more()) { const SMDS_MeshElement * e = it1->next(); if ( e->NbNodes() == 2 && e->GetNodeIndex( node2 ) >= 0 ) { @@ -2083,60 +1129,9 @@ const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1, break; } } - //PROFILER_Get(1); return toReturn; } - -//======================================================================= -//function : FindEdgeOrCreate -//purpose : -//======================================================================= - -SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2) -{ - if ( !node1 || !node2) return 0; - SMDS_MeshEdge * toReturn=NULL; - toReturn=const_cast(FindEdge(node1,node2)); - if(toReturn==NULL) { - if ( NbEdges() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element - adjustmyCellsCapacity(ID); - myNodeIds.resize(2); - myNodeIds[0] = node1->getVtkId(); - myNodeIds[1] = node2->getVtkId(); - - SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); - edgevtk->init(myNodeIds, this); - if (!this->registerElement(ID,edgevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL); - myEdgePool->destroy(edgevtk); - return 0; - } - toReturn = edgevtk; - myCells[ID] = toReturn; - myInfo.myNbEdges++; - } - return toReturn; -} - - -//======================================================================= -//function : FindEdge -//purpose : -//======================================================================= - -const SMDS_MeshEdge* SMDS_Mesh::FindEdge(int idnode1, int idnode2, - int idnode3) const -{ - const SMDS_MeshNode * node1=FindNode(idnode1); - const SMDS_MeshNode * node2=FindNode(idnode2); - const SMDS_MeshNode * node3=FindNode(idnode3); - return FindEdge(node1,node2,node3); -} - const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2, const SMDS_MeshNode * node3) @@ -2164,21 +1159,11 @@ const SMDS_MeshEdge* SMDS_Mesh::FindEdge(const SMDS_MeshNode * node1, return 0; } - //======================================================================= //function : FindFace //purpose : //======================================================================= -const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2, - int idnode3) const -{ - const SMDS_MeshNode * node1=FindNode(idnode1); - const SMDS_MeshNode * node2=FindNode(idnode2); - const SMDS_MeshNode * node3=FindNode(idnode3); - return FindFace(node1, node2, node3); -} - const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, const SMDS_MeshNode *node2, const SMDS_MeshNode *node3) @@ -2206,35 +1191,11 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, return 0; } -SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1, - const SMDS_MeshNode *node2, - const SMDS_MeshNode *node3) -{ - SMDS_MeshFace * toReturn=NULL; - toReturn = const_cast(FindFace(node1,node2,node3)); - if(toReturn==NULL) { - int ID = myElementIDFactory->GetFreeID(); - toReturn = createTriangle(node1,node2,node3, ID); - } - return toReturn; -} - - //======================================================================= //function : FindFace //purpose : //======================================================================= -const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2, - int idnode3, int idnode4) const -{ - const SMDS_MeshNode * node1=FindNode(idnode1); - const SMDS_MeshNode * node2=FindNode(idnode2); - const SMDS_MeshNode * node3=FindNode(idnode3); - const SMDS_MeshNode * node4=FindNode(idnode4); - return FindFace(node1, node2, node3, node4); -} - const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, const SMDS_MeshNode *node2, const SMDS_MeshNode *node3, @@ -2264,39 +1225,11 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, return 0; } -SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1, - const SMDS_MeshNode *node2, - const SMDS_MeshNode *node3, - const SMDS_MeshNode *node4) -{ - SMDS_MeshFace * toReturn=NULL; - toReturn=const_cast(FindFace(node1,node2,node3,node4)); - if(toReturn==NULL) { - int ID = myElementIDFactory->GetFreeID(); - toReturn=createQuadrangle(node1,node2,node3,node4,ID); - } - return toReturn; -} - - //======================================================================= //function : FindFace //purpose :quadratic triangle //======================================================================= -const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2, - int idnode3, int idnode4, - int idnode5, int idnode6) const -{ - const SMDS_MeshNode * node1 = FindNode(idnode1); - const SMDS_MeshNode * node2 = FindNode(idnode2); - const SMDS_MeshNode * node3 = FindNode(idnode3); - const SMDS_MeshNode * node4 = FindNode(idnode4); - const SMDS_MeshNode * node5 = FindNode(idnode5); - const SMDS_MeshNode * node6 = FindNode(idnode6); - return FindFace(node1, node2, node3, node4, node5, node6); -} - const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, const SMDS_MeshNode *node2, const SMDS_MeshNode *node3, @@ -2336,22 +1269,6 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, //purpose : quadratic quadrangle //======================================================================= -const SMDS_MeshFace* SMDS_Mesh::FindFace(int idnode1, int idnode2, - int idnode3, int idnode4, - int idnode5, int idnode6, - int idnode7, int idnode8) const -{ - const SMDS_MeshNode * node1 = FindNode(idnode1); - const SMDS_MeshNode * node2 = FindNode(idnode2); - const SMDS_MeshNode * node3 = FindNode(idnode3); - const SMDS_MeshNode * node4 = FindNode(idnode4); - const SMDS_MeshNode * node5 = FindNode(idnode5); - const SMDS_MeshNode * node6 = FindNode(idnode6); - const SMDS_MeshNode * node7 = FindNode(idnode7); - const SMDS_MeshNode * node8 = FindNode(idnode8); - return FindFace(node1, node2, node3, node4, node5, node6, node7, node8); -} - const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, const SMDS_MeshNode *node2, const SMDS_MeshNode *node3, @@ -2397,11 +1314,7 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const { - if ( IDelem <= 0 || IDelem >= (int)myCells.size() ) - { - return 0; - } - return myCells[IDelem]; + return myCellFactory->FindElement( IDelem ); } //======================================================================= @@ -2409,19 +1322,8 @@ const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const //purpose : find polygon //======================================================================= -const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector& nodes_ids) const -{ - int nbnodes = nodes_ids.size(); - vector poly_nodes (nbnodes); - for (int inode = 0; inode < nbnodes; inode++) { - const SMDS_MeshNode * node = FindNode(nodes_ids[inode]); - if (node == NULL) return NULL; - poly_nodes[inode] = node; - } - return FindFace(poly_nodes); -} -const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector& nodes) +const SMDS_MeshFace* SMDS_Mesh::FindFace (const std::vector& nodes) { return (const SMDS_MeshFace*) FindElement( nodes, SMDSAbs_Face ); } @@ -2437,7 +1339,7 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace (const vector& n */ //================================================================================ -const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector& nodes, +const SMDS_MeshElement* SMDS_Mesh::FindElement (const std::vector& nodes, const SMDSAbs_ElementType type, const bool noMedium) { @@ -2507,110 +1409,6 @@ int SMDS_Mesh::GetElementsByNodes(const std::vector& node return foundElems.size(); } -//======================================================================= -//function : DumpNodes -//purpose : -//======================================================================= - -void SMDS_Mesh::DumpNodes() const -{ - SMDS_NodeIteratorPtr itnode=nodesIterator(); - while(itnode->more()) ; //MESSAGE(itnode->next()); -} - -//======================================================================= -//function : Dump0DElements -//purpose : -//======================================================================= -void SMDS_Mesh::Dump0DElements() const -{ - SMDS_ElemIteratorPtr it0d = elementsIterator(SMDSAbs_0DElement); - while(it0d->more()) ; //MESSAGE(it0d->next()); -} - -//======================================================================= -//function : DumpEdges -//purpose : -//======================================================================= - -void SMDS_Mesh::DumpEdges() const -{ - SMDS_EdgeIteratorPtr itedge=edgesIterator(); - while(itedge->more()) ; //MESSAGE(itedge->next()); -} - -//======================================================================= -//function : DumpFaces -//purpose : -//======================================================================= - -void SMDS_Mesh::DumpFaces() const -{ - SMDS_FaceIteratorPtr itface=facesIterator(); - while(itface->more()) ; //MESSAGE(itface->next()); -} - -//======================================================================= -//function : DumpVolumes -//purpose : -//======================================================================= - -void SMDS_Mesh::DumpVolumes() const -{ - SMDS_VolumeIteratorPtr itvol=volumesIterator(); - while(itvol->more()) ; //MESSAGE(itvol->next()); -} - -//======================================================================= -//function : DebugStats -//purpose : -//======================================================================= - -void SMDS_Mesh::DebugStats() const -{ - MESSAGE("Debug stats of mesh : "); - - MESSAGE("===== NODES ====="<more()) - { - const SMDS_MeshNode *node = itnode->next(); - - sizeofnodes += sizeof(*node); - - SMDS_ElemIteratorPtr it = node->GetInverseElementIterator(); - while(it->more()) - { - const SMDS_MeshElement *me = it->next(); - sizeofnodes += sizeof(me); - } - } - - SMDS_FaceIteratorPtr itface=facesIterator(); - while(itface->more()) - { - const SMDS_MeshElement *face = itface->next(); - sizeoffaces += sizeof(*face); - } - - MESSAGE("total size of node elements = " << sizeofnodes);; - MESSAGE("total size of face elements = " << sizeoffaces);; - - //#endif -} - /////////////////////////////////////////////////////////////////////////////// /// Return the number of nodes /////////////////////////////////////////////////////////////////////////////// @@ -2681,91 +1479,35 @@ int SMDS_Mesh::NbSubMesh() const /////////////////////////////////////////////////////////////////////////////// SMDS_Mesh::~SMDS_Mesh() { - list::iterator itc=myChildren.begin(); + std::list::iterator itc=myChildren.begin(); while(itc!=myChildren.end()) { delete *itc; itc++; } - if(myParent==NULL) - { - delete myNodeIDFactory; - delete myElementIDFactory; - } - else - { - SMDS_ElemIteratorPtr eIt = elementsIterator(); - while ( eIt->more() ) - { - const SMDS_MeshElement *elem = eIt->next(); - myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId()); - } - SMDS_NodeIteratorPtr itn = nodesIterator(); - while (itn->more()) - { - const SMDS_MeshNode *node = itn->next(); - ((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition()); - myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId()); - } - } - myGrid->Delete(); + delete myNodeFactory; + delete myCellFactory; - delete myNodePool; - delete myVolumePool; - delete myFacePool; - delete myEdgePool; - delete myBallPool; + myGrid->Delete(); } -//================================================================================ -/*! - * \brief Clear all data - */ -//================================================================================ - -void SMDS_Mesh::Clear() -{ - if (myParent!=NULL) - { - SMDS_ElemIteratorPtr eIt = elementsIterator(); - while ( eIt->more() ) - { - const SMDS_MeshElement *elem = eIt->next(); - myElementIDFactory->ReleaseID(elem->GetID(), elem->getVtkId()); - } - SMDS_NodeIteratorPtr itn = nodesIterator(); - while (itn->more()) - { - const SMDS_MeshNode *node = itn->next(); - myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId()); - } - } - else - { - myNodeIDFactory->Clear(); - myElementIDFactory->Clear(); - } - - myVolumePool->clear(); - myFacePool->clear(); - myEdgePool->clear(); - myBallPool->clear(); +//================================================================================ +/*! + * \brief Clear all data + */ +//================================================================================ - clearVector( myCells ); - clearVector( myCellIdVtkToSmds ); +void SMDS_Mesh::Clear() +{ + std::set< SMDS_ElementHolder* >::iterator holder = myElemHolders.begin(); + for ( ; holder != myElemHolders.end(); ++holder ) + (*holder)->clear(); - SMDS_NodeIteratorPtr itn = nodesIterator(); - while (itn->more()) - { - SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next()); - node->SetPosition(SMDS_SpacePosition::originSpacePosition()); - //myNodePool->destroy(node); - } - myNodePool->clear(); - clearVector( myNodes ); + myNodeFactory->Clear(); + myCellFactory->Clear(); - list::iterator itc=myChildren.begin(); + std::list::iterator itc=myChildren.begin(); while(itc!=myChildren.end()) (*itc)->Clear(); @@ -2789,182 +1531,29 @@ void SMDS_Mesh::Clear() myGrid->DeleteLinks(); } -/////////////////////////////////////////////////////////////////////////////// -/// Return true if this mesh create faces with edges. -/// A false returned value mean that faces are created with nodes. A concequence -/// is, iteration on edges (SMDS_Element::edgesIterator) will be unavailable. -/////////////////////////////////////////////////////////////////////////////// -bool SMDS_Mesh::hasConstructionEdges() -{ - return myHasConstructionEdges; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Return true if this mesh create volumes with faces -/// A false returned value mean that volumes are created with nodes or edges. -/// (see hasConstructionEdges) -/// A concequence is, iteration on faces (SMDS_Element::facesIterator) will be -/// unavailable. -/////////////////////////////////////////////////////////////////////////////// -bool SMDS_Mesh::hasConstructionFaces() -{ - return myHasConstructionFaces; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Return true if nodes are linked to the finit elements, they are belonging to. -/// Currently, It always return true. -/////////////////////////////////////////////////////////////////////////////// -bool SMDS_Mesh::hasInverseElements() -{ - return myHasInverseElements; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Make this mesh creating construction edges (see hasConstructionEdges) -/// @param b true to have construction edges, else false. -/////////////////////////////////////////////////////////////////////////////// -void SMDS_Mesh::setConstructionEdges(bool b) -{ - myHasConstructionEdges=b; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Make this mesh creating construction faces (see hasConstructionFaces) -/// @param b true to have construction faces, else false. -/////////////////////////////////////////////////////////////////////////////// -void SMDS_Mesh::setConstructionFaces(bool b) -{ - myHasConstructionFaces=b; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Make this mesh creating link from nodes to elements (see hasInverseElements) -/// @param b true to link nodes to elements, else false. -/////////////////////////////////////////////////////////////////////////////// -void SMDS_Mesh::setInverseElements(bool b) -{ - if(!b) MESSAGE("Error : inverseElement=false not implemented"); - myHasInverseElements=b; -} - -namespace { - - //================================================================================ - /*! - * \brief Iterator on elements in id increasing order - */ - //================================================================================ - - template - class IdSortedIterator : public SMDS_Iterator - { - SMDS_MeshElementIDFactory& myIDFact; - int myID, myMaxID, myNbFound, myTotalNb; - SMDSAbs_ElementType myType; - ELEM myElem; - - public: - IdSortedIterator(const SMDS_MeshElementIDFactory& fact, - const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!! - const int totalNb) - :myIDFact( const_cast(fact) ), - myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ), - myType( type ), - myElem(0) - { - next(); - } - bool more() - { - return myElem; - } - ELEM next() - { - ELEM current = myElem; - - for ( myElem = 0; !myElem && myNbFound < myTotalNb && myID <= myMaxID; ++myID ) - if ((myElem = (ELEM) myIDFact.MeshElement( myID )) - && myElem->GetType() != myType ) - myElem = 0; - - myNbFound += bool(myElem); - - return current; - } - }; - - //================================================================================ - /*! - * \brief Iterator on vector of elements, possibly being resized while iteration - */ - //================================================================================ - - template > - class ElemVecIterator: public SMDS_Iterator - { - const std::vector& _vector; - size_t _index; - bool _more; - VALUE_FILTER _filter; - public: - ElemVecIterator(const std::vector& vec, - const VALUE_FILTER& filter=VALUE_FILTER() ) - :_vector( vec ), _index(0), _more( !vec.empty() ), _filter( filter ) - { - if ( _more && !_filter( _vector[ _index ])) - next(); - } - virtual bool more() - { - return _more; - } - virtual RETURN_VALUE next() - { - if ( !_more ) return NULL; - VECTOR_VALUE current = _vector[ _index ]; - _more = 0; - while ( !_more && ++_index < _vector.size() ) - _more = _filter( _vector[ _index ]); - return (RETURN_VALUE) current; - } - }; -} - /////////////////////////////////////////////////////////////////////////////// /// Return an iterator on nodes of the current mesh factory /////////////////////////////////////////////////////////////////////////////// -SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const +SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator() const { - // naturally always sorted by ID - typedef ElemVecIterator TIterator; - return SMDS_NodeIteratorPtr( new TIterator(myNodes)); + return myNodeFactory->GetIterator< SMDS_NodeIterator >( new SMDS_MeshElement::NonNullFilter ); } SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) const { - // naturally always sorted by ID - typedef ElemVecIterator - < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::GeomFilter > TIterator; - return SMDS_ElemIteratorPtr - (new TIterator(myCells, SMDS_MeshElement::GeomFilter( type ))); + return myCellFactory->GetIterator< SMDS_ElemIterator >( new SMDS_MeshElement::GeomFilter( type ), + myInfo.NbElements( type )); } SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const { if ( type == SMDSEntity_Node ) { - typedef ElemVecIterator TIterator; - return SMDS_ElemIteratorPtr( new TIterator(myNodes)); + return myNodeFactory->GetIterator< SMDS_ElemIterator >( new SMDS_MeshElement::NonNullFilter ); } - // naturally always sorted by ID - typedef ElemVecIterator - < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::EntityFilter > TIterator; - return SMDS_ElemIteratorPtr - (new TIterator(myCells, SMDS_MeshElement::EntityFilter( type ))); + return myCellFactory->GetIterator( new SMDS_MeshElement::EntityFilter( type ), + myInfo.NbElements( type )); } /////////////////////////////////////////////////////////////////////////////// @@ -2972,20 +1561,18 @@ SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) c /////////////////////////////////////////////////////////////////////////////// SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const { - // naturally always sorted by ID + typedef SMDS_ElemIterator TIterator; switch ( type ) { case SMDSAbs_All: - return SMDS_ElemIteratorPtr (new ElemVecIterator(myCells)); + return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::NonNullFilter ); case SMDSAbs_Node: - return SMDS_ElemIteratorPtr - ( new ElemVecIterator( myNodes )); + return myNodeFactory->GetIterator< TIterator >( new SMDS_MeshElement::NonNullFilter ); default: - typedef ElemVecIterator - < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator; - return SMDS_ElemIteratorPtr (new TIterator(myCells, SMDS_MeshElement::TypeFilter( type ))); + return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( type ), + myInfo.NbElements( type )); } return SMDS_ElemIteratorPtr(); } @@ -2994,118 +1581,113 @@ SMDS_ElemIteratorPtr SMDS_Mesh::elementsIterator(SMDSAbs_ElementType type) const ///Return an iterator on edges of the current mesh. /////////////////////////////////////////////////////////////////////////////// -SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator(bool idInceasingOrder) const +SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const { - // naturally always sorted by ID - typedef ElemVecIterator - < const SMDS_MeshEdge*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator; - return SMDS_EdgeIteratorPtr - (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Edge ))); + typedef SMDS_EdgeIterator TIterator; + return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( SMDSAbs_Edge ), + myInfo.NbEdges()); } /////////////////////////////////////////////////////////////////////////////// ///Return an iterator on faces of the current mesh. /////////////////////////////////////////////////////////////////////////////// -SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator(bool idInceasingOrder) const +SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const { - // naturally always sorted by ID - typedef ElemVecIterator - < const SMDS_MeshFace*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator; - return SMDS_FaceIteratorPtr - (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Face ))); + typedef SMDS_FaceIterator TIterator; + return myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( SMDSAbs_Face ), + myInfo.NbFaces()); } /////////////////////////////////////////////////////////////////////////////// ///Return an iterator on volumes of the current mesh. /////////////////////////////////////////////////////////////////////////////// -SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator(bool idInceasingOrder) const +SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const +{ + typedef SMDS_VolumeIterator TIterator; + return + myCellFactory->GetIterator< TIterator >( new SMDS_MeshElement::TypeFilter( SMDSAbs_Volume ), + myInfo.NbVolumes()); +} + +SMDS_NodeIteratorPtr SMDS_Mesh::shapeNodesIterator(int shapeID, size_t nbElemsToReturn) const +{ + return myNodeFactory->GetShapeIterator< SMDS_NodeIterator >( shapeID, nbElemsToReturn ); +} + +SMDS_ElemIteratorPtr SMDS_Mesh::shapeElementsIterator(int shapeID, size_t nbElemsToReturn) const { - // naturally always sorted by ID - typedef ElemVecIterator - < const SMDS_MeshVolume*, SMDS_MeshCell*, SMDS_MeshElement::TypeFilter > TIterator; - return SMDS_VolumeIteratorPtr - (new TIterator(myCells, SMDS_MeshElement::TypeFilter( SMDSAbs_Volume ))); + return myCellFactory->GetShapeIterator< SMDS_ElemIterator >( shapeID, nbElemsToReturn ); } /////////////////////////////////////////////////////////////////////////////// /// Do intersection of sets (more than 2) /////////////////////////////////////////////////////////////////////////////// -static set * intersectionOfSets( - set vs[], int numberOfSets) +static std::set * +intersectionOfSets( std::set vs[], int numberOfSets ) { - set* rsetA=new set(vs[0]); - set* rsetB; + std::set* rsetA = new std::set(vs[0]); + std::set* rsetB; - for(int i=0; i(); - set_intersection( - rsetA->begin(), rsetA->end(), - vs[i+1].begin(), vs[i+1].end(), - inserter(*rsetB, rsetB->begin())); - delete rsetA; - rsetA=rsetB; - } - return rsetA; + for(int i=0; i(); + set_intersection(rsetA->begin(), rsetA->end(), + vs[i+1].begin(), vs[i+1].end(), + inserter(*rsetB, rsetB->begin())); + delete rsetA; + rsetA=rsetB; + } + return rsetA; } - /////////////////////////////////////////////////////////////////////////////// /// Return the list of finite elements owning the given element: elements /// containing all the nodes of the given element, for instance faces and /// volumes containing a given edge. /////////////////////////////////////////////////////////////////////////////// -static set * getFinitElements(const SMDS_MeshElement * element) +static std::set * getFinitElements(const SMDS_MeshElement * element) { int numberOfSets=element->NbNodes(); - set *initSet = new set[numberOfSets]; + std::set *initSet = new std::set[numberOfSets]; - SMDS_ElemIteratorPtr itNodes=element->nodesIterator(); + SMDS_NodeIteratorPtr itNodes = element->nodeIterator(); int i = 0; while ( itNodes->more() ) { - const SMDS_MeshElement* node = itNodes->next(); - MYASSERT(node); - const SMDS_MeshNode * n=static_cast(node); - SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator(); - - while ( itFe->more() ) - { - const SMDS_MeshElement* elem = itFe->next(); - MYASSERT(elem); - initSet[i].insert(elem); - } - + const SMDS_MeshNode * n = itNodes->next(); + for ( SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator(); itFe->more(); ) + initSet[i].insert( itFe->next() ); i++; } - set *retSet = intersectionOfSets( initSet, numberOfSets ); + std::set *retSet = intersectionOfSets( initSet, numberOfSets ); delete [] initSet; return retSet; } /////////////////////////////////////////////////////////////////////////////// -/// Return the list of nodes used only by the given elements +/// Return the std::list of nodes used only by the given elements /////////////////////////////////////////////////////////////////////////////// -static set * getExclusiveNodes(set& elements) +static +std::set *getExclusiveNodes(std::set& elements) { - set * toReturn=new set(); - set::iterator itElements=elements.begin(); + std::set * toReturn = new std::set(); + std::set::iterator itElements = elements.begin(); - while(itElements!=elements.end()) + while( itElements != elements.end() ) { - SMDS_ElemIteratorPtr itNodes = (*itElements)->nodesIterator(); + SMDS_NodeIteratorPtr itNodes = (*itElements)->nodeIterator(); itElements++; - while(itNodes->more()) + while( itNodes->more() ) { - const SMDS_MeshNode * n=static_cast(itNodes->next()); + const SMDS_MeshNode * n = itNodes->next(); SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator(); - set s; - while(itFe->more()) - s.insert(itFe->next()); - if(s==elements) toReturn->insert(n); + std::set s; + while ( itFe->more() ) + s.insert( itFe->next() ); + if ( s == elements ) toReturn->insert(n); } } return toReturn; @@ -3117,14 +1699,14 @@ static set * getExclusiveNodes(set& setOfChildren, - const SMDS_MeshElement * element, - set& nodes) +void SMDS_Mesh::addChildrenWithNodes(std::set& setOfChildren, + const SMDS_MeshElement * element, + std::set& nodes) { switch(element->GetType()) { case SMDSAbs_Node: - MESSAGE("Internal Error: This should not happen"); + throw SALOME_Exception("Internal Error: This should not happen"); break; case SMDSAbs_0DElement: case SMDSAbs_Ball: @@ -3156,28 +1738,8 @@ void SMDS_Mesh::addChildrenWithNodes(set& setOfChildren break; } } - if(hasConstructionEdges()) - { - SMDS_ElemIteratorPtr ite=element->edgesIterator(); - while(ite->more()) - addChildrenWithNodes(setOfChildren, ite->next(), nodes); - } } break; case SMDSAbs_Volume: - { - if(hasConstructionFaces()) - { - SMDS_ElemIteratorPtr ite=element->facesIterator(); - while(ite->more()) - addChildrenWithNodes(setOfChildren, ite->next(), nodes); - } - else if(hasConstructionEdges()) - { - SMDS_ElemIteratorPtr ite=element->edgesIterator(); - while(ite->more()) - addChildrenWithNodes(setOfChildren, ite->next(), nodes); - } - } case SMDSAbs_NbElementTypes: case SMDSAbs_All: break; } @@ -3188,10 +1750,10 @@ void SMDS_Mesh::addChildrenWithNodes(set& setOfChildren ///@param removenodes if true remaining nodes will be removed /////////////////////////////////////////////////////////////////////////////// void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, - const bool removenodes) + const bool removenodes) { - list removedElems; - list removedNodes; + std::vector removedElems; + std::vector removedNodes; RemoveElement( elem, removedElems, removedNodes, removenodes ); } @@ -3201,169 +1763,91 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, ///@param removedNodes to be filled with all removed nodes ///@param removenodes if true remaining nodes will be removed /////////////////////////////////////////////////////////////////////////////// -void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, - list& removedElems, - list& removedNodes, - bool removenodes) +void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, + std::vector& removedElems, + std::vector& removedNodes, + bool removenodes) { // get finite elements built on elem - set * s1; + std::set * s1; if ( (elem->GetType() == SMDSAbs_0DElement) - || ((elem->GetType() == SMDSAbs_Edge) && !hasConstructionEdges()) - || ((elem->GetType() == SMDSAbs_Face) && !hasConstructionFaces()) - || (elem->GetType() == SMDSAbs_Volume) ) - { - s1 = new set (); - s1->insert(elem); - } + || (elem->GetType() == SMDSAbs_Ball) + || (elem->GetType() == SMDSAbs_Edge) + || (elem->GetType() == SMDSAbs_Face) + || (elem->GetType() == SMDSAbs_Volume) ) + { + s1 = new std::set (); + s1->insert(elem); + } else s1 = getFinitElements(elem); // get exclusive nodes (which would become free afterwards) - set * s2; + std::set * s2; if (elem->GetType() == SMDSAbs_Node) // a node is removed - { - // do not remove nodes except elem - s2 = new set (); - s2->insert(elem); - removenodes = true; - } + { + // do not remove nodes except elem + s2 = new std::set (); + s2->insert(elem); + removenodes = true; + } else s2 = getExclusiveNodes(*s1); // form the set of finite and construction elements to remove - set s3; - set::iterator it = s1->begin(); + std::set s3; + std::set::iterator it = s1->begin(); while (it != s1->end()) - { - addChildrenWithNodes(s3, *it, *s2); - s3.insert(*it); - it++; - } + { + addChildrenWithNodes(s3, *it, *s2); + s3.insert(*it); + it++; + } if (elem->GetType() != SMDSAbs_Node) s3.insert(elem); // remove finite and construction elements - it = s3.begin(); - while (it != s3.end()) + for( it = s3.begin();it != s3.end(); ++it ) + { + // Remove element from of its nodes + SMDS_NodeIteratorPtr itn = (*it)->nodeIterator(); + while (itn->more()) { - // Remove element from of its nodes - SMDS_ElemIteratorPtr itn = (*it)->nodesIterator(); - while (itn->more()) - { - SMDS_MeshNode * n = static_cast (const_cast (itn->next())); - n->RemoveInverseElement((*it)); - } - int IdToRemove = (*it)->GetID(); - int vtkid = (*it)->getVtkId(); - switch ((*it)->GetType()) - { - case SMDSAbs_Node: - MYASSERT("Internal Error: This should not happen"); - break; - case SMDSAbs_0DElement: - if (IdToRemove >= 0) - { - myCells[IdToRemove] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ? - myInfo.remove(*it); - } - removedElems.push_back((*it)); - myElementIDFactory->ReleaseID(IdToRemove, vtkid); - delete (*it); - break; - case SMDSAbs_Edge: - if (IdToRemove >= 0) - { - myCells[IdToRemove] = 0; - myInfo.RemoveEdge(*it); - } - removedElems.push_back((*it)); - myElementIDFactory->ReleaseID(IdToRemove, vtkid); - if (const SMDS_VtkEdge* vtkElem = dynamic_cast(*it)) - myEdgePool->destroy((SMDS_VtkEdge*) vtkElem); - else { - ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse - delete (*it); - } - break; - case SMDSAbs_Face: - if (IdToRemove >= 0) - { - myCells[IdToRemove] = 0; - myInfo.RemoveFace(*it); - } - removedElems.push_back((*it)); - myElementIDFactory->ReleaseID(IdToRemove, vtkid); - if (const SMDS_VtkFace* vtkElem = dynamic_cast(*it)) - myFacePool->destroy((SMDS_VtkFace*) vtkElem); - else { - ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse - delete (*it); - } - break; - case SMDSAbs_Volume: - if (IdToRemove >= 0) - { - myCells[IdToRemove] = 0; - myInfo.RemoveVolume(*it); - } - removedElems.push_back((*it)); - myElementIDFactory->ReleaseID(IdToRemove, vtkid); - if (const SMDS_VtkVolume* vtkElem = dynamic_cast(*it)) - myVolumePool->destroy((SMDS_VtkVolume*) vtkElem); - else { - ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse - delete (*it); - } - break; - case SMDSAbs_Ball: - if (IdToRemove >= 0) - { - myCells[IdToRemove] = 0; - myInfo.remove(*it); - } - removedElems.push_back((*it)); - myElementIDFactory->ReleaseID(IdToRemove, vtkid); - if (const SMDS_BallElement* vtkElem = dynamic_cast(*it)) - myBallPool->destroy(const_cast( vtkElem )); - else { - ((SMDS_MeshElement*) *it)->init( 0, -1, -1 ); // avoid reuse - delete (*it); - } - break; + SMDS_MeshNode * n = const_cast (itn->next()); + n->RemoveInverseElement((*it)); + } - case SMDSAbs_All: // avoid compilation warning - case SMDSAbs_NbElementTypes: break; - } - if (vtkid >= 0) - { - this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL); - } - it++; + int vtkid = (*it)->GetVtkID(); + + switch ((*it)->GetType()) { + case SMDSAbs_Node: + throw SALOME_Exception(LOCALIZED("Internal Error: This should not happen")); + break; + case SMDSAbs_Edge: myInfo.RemoveEdge(*it); break; + case SMDSAbs_Face: myInfo.RemoveFace(*it); break; + case SMDSAbs_Volume: myInfo.RemoveVolume(*it); break; + case SMDSAbs_Ball: myInfo.myNbBalls--; break; + case SMDSAbs_0DElement: myInfo.myNb0DElements--; break; + case SMDSAbs_All: // avoid compilation warning + case SMDSAbs_NbElementTypes: break; + } + + myCellFactory->Free( static_cast< const SMDS_MeshCell*>( *it )); + + if (vtkid >= 0) + { + this->myGrid->GetCellTypesArray()->SetValue(vtkid, VTK_EMPTY_CELL); } + } // remove exclusive (free) nodes if (removenodes) { - it = s2->begin(); - while (it != s2->end()) + for ( it = s2->begin(); it != s2->end(); ++it ) { - int IdToRemove = (*it)->GetID(); - if (IdToRemove >= 0) - { - myNodes[IdToRemove] = 0; - myInfo.myNbNodes--; - } - myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId()); + myInfo.myNbNodes--; + myNodeFactory->Free( (*it) ); removedNodes.push_back((*it)); - if (const SMDS_MeshNode* vtkElem = dynamic_cast(*it)) - { - ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition()); - myNodePool->destroy((SMDS_MeshNode*) vtkElem); - } - else - delete (*it); - it++; } } @@ -3377,95 +1861,60 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, /////////////////////////////////////////////////////////////////////////////// void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem) { - int elemId = elem->GetID(); - int vtkId = elem->getVtkId(); + const int vtkId = elem->GetVtkID(); SMDSAbs_ElementType aType = elem->GetType(); - SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem); if ( aType == SMDSAbs_Node ) { // only free node can be removed by this method - const SMDS_MeshNode* n = static_cast(todest); + const SMDS_MeshNode* n = static_cast( elem ); if ( n->NbInverseElements() == 0 ) { // free node - myNodes[elemId] = 0; myInfo.myNbNodes--; - ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition()); - ((SMDS_MeshNode*) n)->SMDS_MeshElement::init( 0, -1, -1 ); // avoid reuse - myNodePool->destroy(static_cast(todest)); - myNodeIDFactory->ReleaseID(elemId, vtkId); + myNodeFactory->Free( n ); + } + else + { + throw SALOME_Exception( LOCALIZED( "RemoveFreeElement: not a free node" )); } } else { - if (hasConstructionEdges() || hasConstructionFaces()) - // this methods is only for meshes without descendants - return; - // Remove element from of its nodes - SMDS_ElemIteratorPtr itn = elem->nodesIterator(); + SMDS_NodeIteratorPtr itn = elem->nodeIterator(); while (itn->more()) { - SMDS_MeshNode * n = static_cast - (const_cast(itn->next())); + SMDS_MeshNode * n = const_cast(itn->next()); n->RemoveInverseElement(elem); } // in meshes without descendants elements are always free switch (aType) { - case SMDSAbs_0DElement: - myCells[elemId] = 0; - myInfo.remove(elem); - delete elem; - elem = 0; - break; - case SMDSAbs_Edge: - myCells[elemId] = 0; - myInfo.RemoveEdge(elem); - myEdgePool->destroy(static_cast(todest)); - break; - case SMDSAbs_Face: - myCells[elemId] = 0; - myInfo.RemoveFace(elem); - myFacePool->destroy(static_cast(todest)); - break; - case SMDSAbs_Volume: - myCells[elemId] = 0; - myInfo.RemoveVolume(elem); - myVolumePool->destroy(static_cast(todest)); - break; - case SMDSAbs_Ball: - myCells[elemId] = 0; - myInfo.remove(elem); - myBallPool->destroy(static_cast(todest)); - break; - default: - break; + case SMDSAbs_0DElement: myInfo.remove(elem); break; + case SMDSAbs_Edge: myInfo.RemoveEdge(elem); break; + case SMDSAbs_Face: myInfo.RemoveFace(elem); break; + case SMDSAbs_Volume: myInfo.RemoveVolume(elem); break; + case SMDSAbs_Ball: myInfo.remove(elem); break; + default: break; } - myElementIDFactory->ReleaseID(elemId, vtkId); + myCellFactory->Free( elem ); this->myGrid->GetCellTypesArray()->SetValue(vtkId, VTK_EMPTY_CELL); - // --- to do: keep vtkid in a list of reusable cells - - if ( elem ) - ((SMDS_MeshElement*) elem)->init( 0, -1, -1 ); // avoid reuse } } +//======================================================================= /*! * Checks if the element is present in mesh. - * Useful to determine dead pointers. */ +//======================================================================= + bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const { - // we should not rely on validity of *elem, so iterate on containers - // of all types in the hope of finding somewhere there - SMDS_NodeIteratorPtr itn = nodesIterator(); - while (itn->more()) - if (elem == itn->next()) - return true; - SMDS_ElemIteratorPtr ite = elementsIterator(); - while (ite->more()) - if (elem == ite->next()) - return true; - return false; + if ( !elem || elem->IsNull() ) + return false; + + if ( elem->GetType() == SMDSAbs_Node ) + return ( elem == myNodeFactory->FindElement( elem->GetID() )); + + return ( elem == myCellFactory->FindElement( elem->GetID() )); } //======================================================================= @@ -3475,7 +1924,7 @@ bool SMDS_Mesh::Contains (const SMDS_MeshElement* elem) const int SMDS_Mesh::MaxNodeID() const { - return myNodeIDFactory->GetMaxID(); + return myNodeFactory->GetMaxID(); } //======================================================================= @@ -3485,7 +1934,7 @@ int SMDS_Mesh::MaxNodeID() const int SMDS_Mesh::MinNodeID() const { - return myNodeIDFactory->GetMinID(); + return myNodeFactory->GetMinID(); } //======================================================================= @@ -3495,7 +1944,7 @@ int SMDS_Mesh::MinNodeID() const int SMDS_Mesh::MaxElementID() const { - return myElementIDFactory->GetMaxID(); + return myCellFactory->GetMaxID(); } //======================================================================= @@ -3505,7 +1954,7 @@ int SMDS_Mesh::MaxElementID() const int SMDS_Mesh::MinElementID() const { - return myElementIDFactory->GetMinID(); + return myCellFactory->GetMinID(); } //======================================================================= @@ -3513,39 +1962,12 @@ int SMDS_Mesh::MinElementID() const //purpose : Renumber all nodes or elements. //======================================================================= -void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID) -{ - if ( deltaID == 0 ) - return; - - SMDS_MeshNodeIDFactory * idFactory = - isNodes ? myNodeIDFactory : myElementIDFactory; +// void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID) +// { +// if ( deltaID == 0 ) +// return; - // get existing elements in the order of ID increasing - map elemMap; - SMDS_ElemIteratorPtr idElemIt = idFactory->elementsIterator(); - while ( idElemIt->more() ) { - SMDS_MeshElement* elem = const_cast(idElemIt->next()); - int id = elem->GetID(); - elemMap.insert(map::value_type(id, elem)); - } - // release their ids - map::iterator elemIt = elemMap.begin(); - idFactory->Clear(); -// for ( ; elemIt != elemMap.end(); elemIt++ ) -// { -// int id = (*elemIt).first; -// idFactory->ReleaseID( id ); -// } - // set new IDs - int ID = startID; - elemIt = elemMap.begin(); - for ( ; elemIt != elemMap.end(); elemIt++ ) - { - idFactory->BindID( ID, (*elemIt).second ); - ID += deltaID; - } -} +// } //======================================================================= //function : GetElementType @@ -3554,19 +1976,13 @@ void SMDS_Mesh::Renumber (const bool isNodes, const int startID, const int del SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) const { - SMDS_MeshElement* elem = 0; + const SMDS_MeshElement* elem = 0; if( iselem ) - elem = myElementIDFactory->MeshElement( id ); + elem = myCellFactory->FindElement( id ); else - elem = myNodeIDFactory->MeshElement( id ); + elem = myNodeFactory->FindElement( id ); - if( !elem ) - { - //throw SALOME_Exception(LOCALIZED ("this element isn't exist")); - return SMDSAbs_All; - } - else - return elem->GetType(); + return elem ? elem->GetType() : SMDSAbs_All; } @@ -3585,11 +2001,10 @@ SMDSAbs_ElementType SMDS_Mesh::GetElementType( const int id, const bool iselem ) //======================================================================= SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID) { - return SMDS_Mesh::AddEdgeWithID - ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12), - ID); + return SMDS_Mesh::AddEdgeWithID (myNodeFactory->FindNode(n1), + myNodeFactory->FindNode(n2), + myNodeFactory->FindNode(n12), + ID); } //======================================================================= @@ -3600,7 +2015,7 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1, const SMDS_MeshNode* n2, const SMDS_MeshNode* n12) { - return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myElementIDFactory->GetFreeID()); + return SMDS_Mesh::AddEdgeWithID(n1, n2, n12, myCellFactory->GetFreeID()); } //======================================================================= @@ -3610,36 +2025,17 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode* n1, SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n2, const SMDS_MeshNode * n12, - int ID) + int ID) { if ( !n1 || !n2 || !n12 ) return 0; - // --- retrieve nodes ID - myNodeIds.resize(3); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n12->getVtkId(); - - SMDS_MeshEdge * edge = 0; - SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); - edgevtk->init(myNodeIds, this); - if (!this->registerElement(ID,edgevtk)) + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL); - myEdgePool->destroy(edgevtk); - return 0; + cell->init( SMDSEntity_Quad_Edge, /*nbNodes=*/3, n1, n2, n12 ); + myInfo.myNbQuadEdges++; + return static_cast( cell ); } - edge = edgevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = edge; - myInfo.myNbQuadEdges++; - - // if (!registerElement(ID, edge)) { - // RemoveElement(edge, false); - // edge = NULL; - // } - return edge; - + return 0; } @@ -3655,7 +2051,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, const SMDS_MeshNode * n31) { return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31, - myElementIDFactory->GetFreeID()); + myCellFactory->GetFreeID()); } //======================================================================= @@ -3665,14 +2061,13 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n12,int n23,int n31, int ID) { - return SMDS_Mesh::AddFaceWithID - ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31), - ID); + return SMDS_Mesh::AddFaceWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n31), + ID); } //======================================================================= @@ -3687,42 +2082,16 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n31, int ID) { - if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31) return 0; - if(hasConstructionEdges()) { - // creation quadratic edges - not implemented - return 0; - } - else + if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31 ) return 0; + if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - // --- retrieve nodes ID - myNodeIds.resize(6); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n12->getVtkId(); - myNodeIds[4] = n23->getVtkId(); - myNodeIds[5] = n31->getVtkId(); - - SMDS_MeshFace * face = 0; - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(myNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; + cell->init( SMDSEntity_Quad_Triangle, /*nbNodes=*/6, n1, n2, n3, n12, n23, n31 ); myInfo.myNbQuadTriangles++; - - // if (!registerElement(ID, face)) { - // RemoveElement(face, false); - // face = NULL; - // } - return face; + return static_cast( cell ); } + return 0; } @@ -3739,7 +2108,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, const SMDS_MeshNode * nCenter) { return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,nCenter, - myElementIDFactory->GetFreeID()); + myCellFactory->GetFreeID()); } //======================================================================= @@ -3749,15 +2118,14 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n12,int n23,int n31, int nCenter, int ID) { - return SMDS_Mesh::AddFaceWithID - ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter), - ID); + return SMDS_Mesh::AddFaceWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n31), + myNodeFactory->FindNode(nCenter), + ID); } //======================================================================= @@ -3774,42 +2142,15 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, int ID) { if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31 || !nCenter) return 0; - if(hasConstructionEdges()) { - // creation quadratic edges - not implemented - return 0; - } - else + if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - // --- retrieve nodes ID - myNodeIds.resize(7); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n12->getVtkId(); - myNodeIds[4] = n23->getVtkId(); - myNodeIds[5] = n31->getVtkId(); - myNodeIds[6] = nCenter->getVtkId(); - - SMDS_MeshFace * face = 0; - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(myNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; + cell->init( SMDSEntity_BiQuad_Triangle, /*nbNodes=*/7, n1, n2, n3, n12, n23, n31, nCenter ); myInfo.myNbBiQuadTriangles++; - - // if (!registerElement(ID, face)) { - // RemoveElement(face, false); - // face = NULL; - // } - return face; + return static_cast( cell ); } + return 0; } @@ -3827,7 +2168,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, const SMDS_MeshNode * n41) { return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41, - myElementIDFactory->GetFreeID()); + myCellFactory->GetFreeID()); } //======================================================================= @@ -3837,16 +2178,15 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int n12,int n23,int n34,int n41, int ID) { - return SMDS_Mesh::AddFaceWithID - ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41), - ID); + return SMDS_Mesh::AddFaceWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n4) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n34), + myNodeFactory->FindNode(n41), + ID); } //======================================================================= @@ -3864,43 +2204,15 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, int ID) { if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0; - if(hasConstructionEdges()) { - // creation quadratic edges - not implemented - return 0; - } - else + if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - // --- retrieve nodes ID - myNodeIds.resize(8); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n4->getVtkId(); - myNodeIds[4] = n12->getVtkId(); - myNodeIds[5] = n23->getVtkId(); - myNodeIds[6] = n34->getVtkId(); - myNodeIds[7] = n41->getVtkId(); - - SMDS_MeshFace * face = 0; - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(myNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; + cell->init( SMDSEntity_Quad_Quadrangle, /*nbNodes=*/8, n1, n2, n3, n4, n12, n23, n34, n41 ); myInfo.myNbQuadQuadrangles++; - - // if (!registerElement(ID, face)) { - // RemoveElement(face, false); - // face = NULL; - // } - return face; + return static_cast( cell ); } + return 0; } //======================================================================= @@ -3918,7 +2230,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, const SMDS_MeshNode * nCenter) { return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter, - myElementIDFactory->GetFreeID()); + myCellFactory->GetFreeID()); } //======================================================================= @@ -3928,17 +2240,16 @@ SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1, SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int n12,int n23,int n34,int n41, int nCenter, int ID) { - return SMDS_Mesh::AddFaceWithID - ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n4) , - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n34), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n41), - (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter), - ID); + return SMDS_Mesh::AddFaceWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n4) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n34), + myNodeFactory->FindNode(n41), + myNodeFactory->FindNode(nCenter), + ID); } //======================================================================= @@ -3957,44 +2268,16 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, int ID) { if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41 || !nCenter) return 0; - if(hasConstructionEdges()) { - // creation quadratic edges - not implemented - return 0; - } - else + if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - // --- retrieve nodes ID - myNodeIds.resize(9); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n4->getVtkId(); - myNodeIds[4] = n12->getVtkId(); - myNodeIds[5] = n23->getVtkId(); - myNodeIds[6] = n34->getVtkId(); - myNodeIds[7] = n41->getVtkId(); - myNodeIds[8] = nCenter->getVtkId(); - - SMDS_MeshFace * face = 0; - SMDS_VtkFace *facevtk = myFacePool->getNew(); - facevtk->init(myNodeIds, this); - if (!this->registerElement(ID,facevtk)) - { - this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL); - myFacePool->destroy(facevtk); - return 0; - } - face = facevtk; - adjustmyCellsCapacity(ID); - myCells[ID] = face; + cell->init( SMDSEntity_BiQuad_Quadrangle, + /*nbNodes=*/9, n1, n2, n3, n4, n12, n23, n34, n41, nCenter ); myInfo.myNbBiQuadQuadrangles++; - - // if (!registerElement(ID, face)) { - // RemoveElement(face, false); - // face = NULL; - // } - return face; + return static_cast( cell ); } + return 0; } @@ -4013,11 +2296,8 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n24, const SMDS_MeshNode * n34) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23, - n31, n14, n24, n34, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n12, n23, + n31, n14, n24, n34, myCellFactory->GetFreeID()); } //======================================================================= @@ -4028,18 +2308,17 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n12,int n23,int n31, int n14,int n24,int n34, int ID) { - return SMDS_Mesh::AddVolumeWithID - ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n24), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34), - ID); + return SMDS_Mesh::AddVolumeWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n4) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n31), + myNodeFactory->FindNode(n14), + myNodeFactory->FindNode(n24), + myNodeFactory->FindNode(n34), + ID); } //======================================================================= @@ -4060,42 +2339,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, { if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n31 || !n14 || !n24 || !n34) return 0; - if(hasConstructionFaces()) { - // creation quadratic faces - not implemented - return 0; - } - // --- retrieve nodes ID - myNodeIds.resize(10); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n3->getVtkId(); - myNodeIds[2] = n2->getVtkId(); - myNodeIds[3] = n4->getVtkId(); - - myNodeIds[4] = n31->getVtkId(); - myNodeIds[5] = n23->getVtkId(); - myNodeIds[6] = n12->getVtkId(); - - myNodeIds[7] = n14->getVtkId(); - myNodeIds[8] = n34->getVtkId(); - myNodeIds[9] = n24->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) + if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; + cell->init( SMDSEntity_Quad_Tetra, + /*nbNodes=*/10, n1, n2, n3, n4, n12, n23, n31, n14, n24, n34 ); + myInfo.myNbQuadTetras++; + return static_cast( cell ); } - adjustmyCellsCapacity(ID); - myCells[ID] = volvtk; - myInfo.myNbQuadTetras++; - - // if (!registerElement(ID, volvtk)) { - // RemoveElement(volvtk, false); - // volvtk = NULL; - // } - return volvtk; + return 0; } @@ -4117,12 +2370,8 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n35, const SMDS_MeshNode * n45) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = - SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41, - n15, n25, n35, n45, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n12, n23, n34, n41, + n15, n25, n35, n45, myCellFactory->GetFreeID()); } //======================================================================= @@ -4133,21 +2382,20 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int int n12,int n23,int n34,int n41, int n15,int n25,int n35,int n45, int ID) { - return SMDS_Mesh::AddVolumeWithID - ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n35), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45), - ID); + return SMDS_Mesh::AddVolumeWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n4) , + myNodeFactory->FindNode(n5) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n34), + myNodeFactory->FindNode(n41), + myNodeFactory->FindNode(n15), + myNodeFactory->FindNode(n25), + myNodeFactory->FindNode(n35), + myNodeFactory->FindNode(n45), + ID); } //======================================================================= @@ -4172,45 +2420,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, if (!n1 || !n2 || !n3 || !n4 || !n5 || !n12 || !n23 || !n34 || !n41 || !n15 || !n25 || !n35 || !n45) return 0; - if(hasConstructionFaces()) { - // creation quadratic faces - not implemented - return 0; - } - // --- retrieve nodes ID - myNodeIds.resize(13); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n4->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n2->getVtkId(); - myNodeIds[4] = n5->getVtkId(); - - myNodeIds[5] = n41->getVtkId(); - myNodeIds[6] = n34->getVtkId(); - myNodeIds[7] = n23->getVtkId(); - myNodeIds[8] = n12->getVtkId(); - - myNodeIds[9] = n15->getVtkId(); - myNodeIds[10] = n45->getVtkId(); - myNodeIds[11] = n35->getVtkId(); - myNodeIds[12] = n25->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) + if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; + cell->init( SMDSEntity_Quad_Pyramid, + /*nbNodes=*/13, n1, n2, n3, n4, n5, n12, n23, n34, n41, n15, n25, n35, n45); + myInfo.myNbQuadPyramids++; + return static_cast( cell ); } - adjustmyCellsCapacity(ID); - myCells[ID] = volvtk; - myInfo.myNbQuadPyramids++; - - // if (!registerElement(ID, volvtk)) { - // RemoveElement(volvtk, false); - // volvtk = NULL; - // } - return volvtk; + return 0; } @@ -4234,12 +2453,8 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n25, const SMDS_MeshNode * n36) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = - SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31, - n45, n56, n64, n14, n25, n36, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31, + n45, n56, n64, n14, n25, n36, myCellFactory->GetFreeID()); } //======================================================================= @@ -4252,23 +2467,22 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n45,int n56,int n64, int n14,int n25,int n36, int ID) { - return SMDS_Mesh::AddVolumeWithID - ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36), - ID); + return SMDS_Mesh::AddVolumeWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n4) , + myNodeFactory->FindNode(n5) , + myNodeFactory->FindNode(n6) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n31), + myNodeFactory->FindNode(n45), + myNodeFactory->FindNode(n56), + myNodeFactory->FindNode(n64), + myNodeFactory->FindNode(n14), + myNodeFactory->FindNode(n25), + myNodeFactory->FindNode(n36), + ID); } //======================================================================= @@ -4295,49 +2509,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 || !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36) return 0; - if(hasConstructionFaces()) { - // creation quadratic faces - not implemented - return 0; - } - // --- retrieve nodes ID - myNodeIds.resize(15); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - - myNodeIds[3] = n4->getVtkId(); - myNodeIds[4] = n5->getVtkId(); - myNodeIds[5] = n6->getVtkId(); - - myNodeIds[6] = n12->getVtkId(); - myNodeIds[7] = n23->getVtkId(); - myNodeIds[8] = n31->getVtkId(); - - myNodeIds[9] = n45->getVtkId(); - myNodeIds[10] = n56->getVtkId(); - myNodeIds[11] = n64->getVtkId(); - - myNodeIds[12] = n14->getVtkId(); - myNodeIds[13] = n25->getVtkId(); - myNodeIds[14] = n36->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) + if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; + cell->init( SMDSEntity_Quad_Penta, /*nbNodes=*/15, + n1, n2, n3, n4, n5, n6, n12, n23, n31, n45, n56, n64, n14, n25, n36 ); + myInfo.myNbQuadPrisms++; + return static_cast( cell ); } - adjustmyCellsCapacity(ID); - myCells[ID] = volvtk; - myInfo.myNbQuadPrisms++; - - // if (!registerElement(ID, volvtk)) { - // RemoveElement(volvtk, false); - // volvtk = NULL; - // } - return volvtk; + return 0; } //======================================================================= @@ -4363,13 +2544,9 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n2356, const SMDS_MeshNode * n1346) { - //MESSAGE("AddVolume penta18"); - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = - SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31, - n45, n56, n64, n14, n25, n36, n1245, n2356, n1346, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n12, n23, n31, + n45, n56, n64, n14, n25, n36, n1245, n2356, n1346, + myCellFactory->GetFreeID()); } //======================================================================= @@ -4383,27 +2560,25 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n14,int n25,int n36, int n1245, int n2356, int n1346, int ID) { - //MESSAGE("AddVolumeWithID penta18 " << ID); - return SMDS_Mesh::AddVolumeWithID - ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6) , - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n31), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n45), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n64), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n14), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n25), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n36), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1245), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2356), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1346), - ID); + return SMDS_Mesh::AddVolumeWithID (myNodeFactory->FindNode(n1) , + myNodeFactory->FindNode(n2) , + myNodeFactory->FindNode(n3) , + myNodeFactory->FindNode(n4) , + myNodeFactory->FindNode(n5) , + myNodeFactory->FindNode(n6) , + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n31), + myNodeFactory->FindNode(n45), + myNodeFactory->FindNode(n56), + myNodeFactory->FindNode(n64), + myNodeFactory->FindNode(n14), + myNodeFactory->FindNode(n25), + myNodeFactory->FindNode(n36), + myNodeFactory->FindNode(n1245), + myNodeFactory->FindNode(n2356), + myNodeFactory->FindNode(n1346), + ID); } //======================================================================= @@ -4434,53 +2609,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n12 || !n23 || !n31 || !n45 || !n56 || !n64 || !n14 || !n25 || !n36 || !n1245 || !n2356 || !n1346) return 0; - if(hasConstructionFaces()) { - // creation quadratic faces - not implemented - return 0; - } - // --- retrieve nodes ID - myNodeIds.resize(18); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n2->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - - myNodeIds[3] = n4->getVtkId(); - myNodeIds[4] = n5->getVtkId(); - myNodeIds[5] = n6->getVtkId(); - - myNodeIds[6] = n12->getVtkId(); - myNodeIds[7] = n23->getVtkId(); - myNodeIds[8] = n31->getVtkId(); - - myNodeIds[9] = n45->getVtkId(); - myNodeIds[10] = n56->getVtkId(); - myNodeIds[11] = n64->getVtkId(); - - myNodeIds[12] = n14->getVtkId(); - myNodeIds[13] = n25->getVtkId(); - myNodeIds[14] = n36->getVtkId(); - - myNodeIds[15] = n1245->getVtkId(); - myNodeIds[16] = n2356->getVtkId(); - myNodeIds[17] = n1346->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) + if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; + cell->init( SMDSEntity_BiQuad_Penta, /*nbNodes=*/18, n1, n2, n3, n4, n5, n6, + n12, n23, n31, n45, n56, n64, n14, n25, n36, n1245, n2356, n1346 ); + myInfo.myNbBiQuadPrisms++; + return static_cast( cell ); } - adjustmyCellsCapacity(ID); - myCells[ID] = volvtk; - myInfo.myNbBiQuadPrisms++; - - // if (!registerElement(ID, volvtk)) { - // RemoveElement(volvtk, false); - // volvtk = NULL; - // } - return volvtk; + return 0; } @@ -4509,12 +2647,9 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n37, const SMDS_MeshNode * n48) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = - SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41, - n56, n67, n78, n85, n15, n26, n37, n48, ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41, + n56, n67, n78, n85, n15, n26, n37, n48, + myCellFactory->GetFreeID()); } //======================================================================= @@ -4527,28 +2662,27 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n56,int n67,int n78,int n85, int n15,int n26,int n37,int n48, int ID) { - return SMDS_Mesh::AddVolumeWithID - ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48), - ID); + return SMDS_Mesh::AddVolumeWithID (myNodeFactory->FindNode(n1), + myNodeFactory->FindNode(n2), + myNodeFactory->FindNode(n3), + myNodeFactory->FindNode(n4), + myNodeFactory->FindNode(n5), + myNodeFactory->FindNode(n6), + myNodeFactory->FindNode(n7), + myNodeFactory->FindNode(n8), + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n34), + myNodeFactory->FindNode(n41), + myNodeFactory->FindNode(n56), + myNodeFactory->FindNode(n67), + myNodeFactory->FindNode(n78), + myNodeFactory->FindNode(n85), + myNodeFactory->FindNode(n15), + myNodeFactory->FindNode(n26), + myNodeFactory->FindNode(n37), + myNodeFactory->FindNode(n48), + ID); } //======================================================================= @@ -4580,54 +2714,16 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, if (!n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8 || !n12 || !n23 || !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48) return 0; - if(hasConstructionFaces()) { - return 0; - // creation quadratic faces - not implemented - } - // --- retrieve nodes ID - myNodeIds.resize(20); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n4->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n2->getVtkId(); - - myNodeIds[4] = n5->getVtkId(); - myNodeIds[5] = n8->getVtkId(); - myNodeIds[6] = n7->getVtkId(); - myNodeIds[7] = n6->getVtkId(); - - myNodeIds[8] = n41->getVtkId(); - myNodeIds[9] = n34->getVtkId(); - myNodeIds[10] = n23->getVtkId(); - myNodeIds[11] = n12->getVtkId(); - - myNodeIds[12] = n85->getVtkId(); - myNodeIds[13] = n78->getVtkId(); - myNodeIds[14] = n67->getVtkId(); - myNodeIds[15] = n56->getVtkId(); - - myNodeIds[16] = n15->getVtkId(); - myNodeIds[17] = n48->getVtkId(); - myNodeIds[18] = n37->getVtkId(); - myNodeIds[19] = n26->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) + if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; + cell->init( SMDSEntity_Quad_Hexa, /*nbNodes=*/20, n1, n2, n3, n4, n5, n6, n7, n8, + n12, n23, n34, n41, n56, n67, n78, n85, n15, n26, n37, n48 ); + myInfo.myNbQuadHexas++; + return static_cast( cell ); } - adjustmyCellsCapacity(ID); - myCells[ID] = volvtk; - myInfo.myNbQuadHexas++; - - // if (!registerElement(ID, volvtk)) { - // RemoveElement(volvtk, false); - // volvtk = NULL; - // } - return volvtk; + return 0; } //======================================================================= @@ -4662,14 +2758,10 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1, const SMDS_MeshNode * n5678, const SMDS_MeshNode * nCenter) { - int ID = myElementIDFactory->GetFreeID(); - SMDS_MeshVolume * v = - SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41, - n56, n67, n78, n85, n15, n26, n37, n48, - n1234, n1256, n2367, n3478, n1458, n5678, nCenter, - ID); - if(v==NULL) myElementIDFactory->ReleaseID(ID); - return v; + return SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n12, n23, n34, n41, + n56, n67, n78, n85, n15, n26, n37, n48, + n1234, n1256, n2367, n3478, n1458, n5678, nCenter, + myCellFactory->GetFreeID()); } //======================================================================= @@ -4684,40 +2776,39 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n1234,int n1256,int n2367,int n3478, int n1458,int n5678,int nCenter, int ID) { - return SMDS_Mesh::AddVolumeWithID - ((SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n4), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n6), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n7), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n8), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n12), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n23), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n34), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n41), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n56), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n67), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n78), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n85), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n15), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n26), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n37), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n48), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1234), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1256), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n2367), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n3478), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n1458), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(n5678), - (SMDS_MeshNode*) myNodeIDFactory->MeshElement(nCenter), - ID); + return SMDS_Mesh::AddVolumeWithID (myNodeFactory->FindNode(n1), + myNodeFactory->FindNode(n2), + myNodeFactory->FindNode(n3), + myNodeFactory->FindNode(n4), + myNodeFactory->FindNode(n5), + myNodeFactory->FindNode(n6), + myNodeFactory->FindNode(n7), + myNodeFactory->FindNode(n8), + myNodeFactory->FindNode(n12), + myNodeFactory->FindNode(n23), + myNodeFactory->FindNode(n34), + myNodeFactory->FindNode(n41), + myNodeFactory->FindNode(n56), + myNodeFactory->FindNode(n67), + myNodeFactory->FindNode(n78), + myNodeFactory->FindNode(n85), + myNodeFactory->FindNode(n15), + myNodeFactory->FindNode(n26), + myNodeFactory->FindNode(n37), + myNodeFactory->FindNode(n48), + myNodeFactory->FindNode(n1234), + myNodeFactory->FindNode(n1256), + myNodeFactory->FindNode(n2367), + myNodeFactory->FindNode(n3478), + myNodeFactory->FindNode(n1458), + myNodeFactory->FindNode(n5678), + myNodeFactory->FindNode(nCenter), + ID); } //======================================================================= //function : AddVolumeWithID -//purpose : 2d order Hexahedrons with 20 nodes +//purpose : 2d order Hexahedrons with 27 nodes //======================================================================= SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n2, @@ -4752,61 +2843,20 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, !n34 || !n41 || !n56 || !n67 || !n78 || !n85 || !n15 || !n26 || !n37 || !n48 || !n1234 || !n1256 || !n2367 || !n3478 || !n1458 || !n5678 || !nCenter ) return 0; - if(hasConstructionFaces()) { - return 0; - // creation quadratic faces - not implemented - } - // --- retrieve nodes ID - myNodeIds.resize(27); - myNodeIds[0] = n1->getVtkId(); - myNodeIds[1] = n4->getVtkId(); - myNodeIds[2] = n3->getVtkId(); - myNodeIds[3] = n2->getVtkId(); - - myNodeIds[4] = n5->getVtkId(); - myNodeIds[5] = n8->getVtkId(); - myNodeIds[6] = n7->getVtkId(); - myNodeIds[7] = n6->getVtkId(); - - myNodeIds[8] = n41->getVtkId(); - myNodeIds[9] = n34->getVtkId(); - myNodeIds[10] = n23->getVtkId(); - myNodeIds[11] = n12->getVtkId(); - - myNodeIds[12] = n85->getVtkId(); - myNodeIds[13] = n78->getVtkId(); - myNodeIds[14] = n67->getVtkId(); - myNodeIds[15] = n56->getVtkId(); - - myNodeIds[16] = n15->getVtkId(); - myNodeIds[17] = n48->getVtkId(); - myNodeIds[18] = n37->getVtkId(); - myNodeIds[19] = n26->getVtkId(); - - myNodeIds[20] = n1256->getVtkId(); - myNodeIds[21] = n3478->getVtkId(); - myNodeIds[22] = n1458->getVtkId(); - myNodeIds[23] = n2367->getVtkId(); - myNodeIds[24] = n1234->getVtkId(); - myNodeIds[25] = n5678->getVtkId(); - myNodeIds[26] = nCenter->getVtkId(); - - SMDS_VtkVolume *volvtk = myVolumePool->getNew(); - volvtk->init(myNodeIds, this); - if (!this->registerElement(ID,volvtk)) + if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); + + if ( SMDS_MeshCell* cell = myCellFactory->NewCell( ID )) { - this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL); - myVolumePool->destroy(volvtk); - return 0; + cell->init( SMDSEntity_TriQuad_Hexa, /*nbNodes=*/27, n1, n2, n3, n4, n5, n6, n7, n8, + n12, n23, n34, n41, n56, n67, n78, n85, n15, n26, n37, n48, + n1234, n1256, n2367, n3478, n1458, n5678, nCenter); + myInfo.myNbTriQuadHexas++; + return static_cast( cell ); } - adjustmyCellsCapacity(ID); - myCells[ID] = volvtk; - myInfo.myNbTriQuadHexas++; - - return volvtk; + return 0; } -void SMDS_Mesh::dumpGrid(string ficdump) +void SMDS_Mesh::dumpGrid(std::string ficdump) { // vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); // aWriter->SetFileName(ficdump.c_str()); @@ -4817,7 +2867,7 @@ void SMDS_Mesh::dumpGrid(string ficdump) // } // aWriter->Delete(); ficdump = ficdump + "_connectivity"; - ofstream ficcon(ficdump.c_str(), ios::out); + std::ofstream ficcon(ficdump.c_str(), ios::out); int nbPoints = myGrid->GetNumberOfPoints(); ficcon << "-------------------------------- points " << nbPoints << endl; for (int i=0; imyCompactTime = this->myModifTime; + + bool idsChange = ( myNodeFactory->CompactChangePointers() || + myCellFactory->CompactChangePointers() ); + if ( idsChange ) + { + std::set< SMDS_ElementHolder* >::iterator holder = myElemHolders.begin(); + for ( ; holder != myElemHolders.end(); ++holder ) + (*holder)->beforeCompacting(); + } + + // remove "holes" in SMDS numeration + std::vector idNodesOldToNew, idCellsNewToOld; + myNodeFactory->Compact( idNodesOldToNew ); + myCellFactory->Compact( idCellsNewToOld ); + + // make VTK IDs correspond to SMDS IDs + int newNodeSize = myNodeFactory->NbUsedElements(); + int newCellSize = myCellFactory->NbUsedElements(); + myGrid->compactGrid( idNodesOldToNew, newNodeSize, idCellsNewToOld, newCellSize ); + + std::set< SMDS_ElementHolder* >::iterator holder = myElemHolders.begin(); + for ( ; holder != myElemHolders.end(); ++holder ) + if ( idsChange ) + (*holder)->restoreElements( idNodesOldToNew, idCellsNewToOld ); + else + (*holder)->compact(); + + return; } -int SMDS_Mesh::fromVtkToSmds(int vtkid) +int SMDS_Mesh::FromVtkToSmds( int vtkid ) const { - if (vtkid >= 0 && vtkid < (int)myCellIdVtkToSmds.size()) - return myCellIdVtkToSmds[vtkid]; - throw SALOME_Exception(LOCALIZED ("vtk id out of bounds")); + return myCellFactory->FromVtkToSmds( vtkid ); } -// void SMDS_Mesh::updateBoundingBox() -// { -// xmin = 0; xmax = 0; -// ymin = 0; ymax = 0; -// zmin = 0; zmax = 0; -// vtkPoints *points = myGrid->GetPoints(); -// int myNodesSize = this->myNodes.size(); -// for (int i = 0; i < myNodesSize; i++) -// { -// if (SMDS_MeshNode *n = myNodes[i]) -// { -// double coords[3]; -// points->GetPoint(n->myVtkID, coords); -// if (coords[0] < xmin) xmin = coords[0]; -// else if (coords[0] > xmax) xmax = coords[0]; -// if (coords[1] < ymin) ymin = coords[1]; -// else if (coords[1] > ymax) ymax = coords[1]; -// if (coords[2] < zmin) zmin = coords[2]; -// else if (coords[2] > zmax) zmax = coords[2]; -// } -// } -// } - double SMDS_Mesh::getMaxDim() { double dmax = 1.e-3; @@ -4914,7 +2967,12 @@ vtkMTimeType SMDS_Mesh::GetMTime() const return this->myModifTime; } -bool SMDS_Mesh::isCompacted() +bool SMDS_Mesh::IsCompacted() +{ + return ( this->myCompactTime == this->myModifTime ); +} + +void SMDS_Mesh::setNbShapes( size_t nbShapes ) { - return this->myCompactTime == this->myModifTime; + myNodeFactory->SetNbShapes( nbShapes ); } diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index 00b31a33c..38952f78c 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -29,62 +29,46 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_MeshCell.hxx" +#include "SMDS_BallElement.hxx" +#include "SMDS_ElemIterator.hxx" #include "SMDS_Mesh0DElement.hxx" +#include "SMDS_MeshCell.hxx" #include "SMDS_MeshEdge.hxx" #include "SMDS_MeshFace.hxx" -#include "SMDS_MeshVolume.hxx" -#include "SMDS_MeshNodeIDFactory.hxx" -#include "SMDS_MeshElementIDFactory.hxx" #include "SMDS_MeshInfo.hxx" -#include "SMDS_ElemIterator.hxx" -#include "SMDS_VolumeOfNodes.hxx" -#include "SMDS_VtkEdge.hxx" -#include "SMDS_VtkFace.hxx" -#include "SMDS_VtkVolume.hxx" -#include "ObjectPool.hxx" +#include "SMDS_MeshNode.hxx" +#include "SMDS_MeshVolume.hxx" #include "SMDS_UnstructuredGrid.hxx" -#include "SMDS_BallElement.hxx" -#include #include #include #include -#include -#include -#include "Utils_SALOME_Exception.hxx" - -#define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified")); +class SMDS_ElementHolder; +class SMDS_ElementFactory; +class SMDS_NodeFactory; class SMDS_EXPORT SMDS_Mesh : public SMDS_MeshObject { public: - friend class SMDS_MeshIDFactory; - friend class SMDS_MeshNodeIDFactory; - friend class SMDS_MeshElementIDFactory; - friend class SMDS_MeshVolumeVtkNodes; - friend class SMDS_MeshNode; SMDS_Mesh(); - //! to retrieve this SMDS_Mesh instance from its elements (index stored in SMDS_Elements) - static std::vector _meshList; - //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid - inline SMDS_UnstructuredGrid* getGrid() { return myGrid; } - inline int getMeshId() { return myMeshId; } + inline SMDS_UnstructuredGrid* GetGrid() { return myGrid; } - virtual SMDS_NodeIteratorPtr nodesIterator (bool idInceasingOrder=false) const; - virtual SMDS_EdgeIteratorPtr edgesIterator (bool idInceasingOrder=false) const; - virtual SMDS_FaceIteratorPtr facesIterator (bool idInceasingOrder=false) const; - virtual SMDS_VolumeIteratorPtr volumesIterator (bool idInceasingOrder=false) const; + virtual SMDS_NodeIteratorPtr nodesIterator () const; + virtual SMDS_EdgeIteratorPtr edgesIterator () const; + virtual SMDS_FaceIteratorPtr facesIterator () const; + virtual SMDS_VolumeIteratorPtr volumesIterator() const; virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const; virtual SMDS_ElemIteratorPtr elementGeomIterator(SMDSAbs_GeometryType type) const; virtual SMDS_ElemIteratorPtr elementEntityIterator(SMDSAbs_EntityType type) const; + virtual SMDS_NodeIteratorPtr shapeNodesIterator (int shapeID, size_t nbElemsToReturn=-1) const; + virtual SMDS_ElemIteratorPtr shapeElementsIterator(int shapeID, size_t nbElemsToReturn=-1) const; + SMDSAbs_ElementType GetElementType( const int id, const bool iselem ) const; SMDS_Mesh *AddSubMesh(); @@ -137,21 +121,6 @@ public: const SMDS_MeshNode * n3, const SMDS_MeshNode * n4); - virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3, int ID); - virtual SMDS_MeshFace* AddFace(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3); - - virtual SMDS_MeshFace* AddFaceWithID(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3, - const SMDS_MeshEdge * e4, int ID); - virtual SMDS_MeshFace* AddFace(const SMDS_MeshEdge * e1, - const SMDS_MeshEdge * e2, - const SMDS_MeshEdge * e3, - const SMDS_MeshEdge * e4); // 2d order triangle of 6 nodes virtual SMDS_MeshFace* AddFaceWithID(int n1, int n2, int n3, @@ -293,38 +262,6 @@ public: const SMDS_MeshNode * n7, const SMDS_MeshNode * n8); - virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, int ID); - virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4); - - virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5, int ID); - virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5); - - virtual SMDS_MeshVolume* AddVolumeWithID(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5, - const SMDS_MeshFace * f6, int ID); - virtual SMDS_MeshVolume* AddVolume(const SMDS_MeshFace * f1, - const SMDS_MeshFace * f2, - const SMDS_MeshFace * f3, - const SMDS_MeshFace * f4, - const SMDS_MeshFace * f5, - const SMDS_MeshFace * f6); // hexagonal prism virtual SMDS_MeshVolume* AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, @@ -639,33 +576,24 @@ public: virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID (const std::vector & nodes, const std::vector & quantities, - const int ID); + const int ID); virtual SMDS_MeshVolume* AddPolyhedralVolume - (const std::vector & nodes, - const std::vector & quantities); + (const std::vector & nodes, + const std::vector & quantities); virtual SMDS_MeshVolume* AddVolumeFromVtkIds(const std::vector& vtkNodeIds); - virtual SMDS_MeshVolume* AddVolumeFromVtkIdsWithID(const std::vector& vtkNodeIds, - const int ID); - virtual SMDS_MeshFace* AddFaceFromVtkIds(const std::vector& vtkNodeIds); - virtual SMDS_MeshFace* AddFaceFromVtkIdsWithID(const std::vector& vtkNodeIds, - const int ID); virtual void MoveNode(const SMDS_MeshNode *n, double x, double y, double z); - virtual void RemoveElement(const SMDS_MeshElement * elem, - std::list& removedElems, - std::list& removedNodes, - const bool removenodes = false); + virtual void RemoveElement(const SMDS_MeshElement * elem, + std::vector& removedElems, + std::vector& removedNodes, + const bool removenodes = false); virtual void RemoveElement(const SMDS_MeshElement * elem, bool removenodes = false); virtual void RemoveNode(const SMDS_MeshNode * node); - virtual void Remove0DElement(const SMDS_Mesh0DElement * elem0d); - virtual void RemoveEdge(const SMDS_MeshEdge * edge); - virtual void RemoveFace(const SMDS_MeshFace * face); - virtual void RemoveVolume(const SMDS_MeshVolume * volume); /*! Remove only the given element and only if it is free. * Method does not work for meshes with descendants. @@ -681,27 +609,23 @@ public: bool ChangeElementNodes(const SMDS_MeshElement * elem, const SMDS_MeshNode * nodes[], const int nbnodes); - bool ChangePolyhedronNodes(const SMDS_MeshElement * elem, - const std::vector& nodes, - const std::vector & quantities); - virtual void Renumber (const bool isNodes, const int startID = 1, const int deltaID = 1); + //virtual void Renumber (const bool isNodes, const int startID = 1, const int deltaID = 1); // Renumber all nodes or elements. - virtual void compactMesh(); - virtual void CompactMesh() { compactMesh(); } + + virtual void CompactMesh(); + bool IsCompacted(); + + template + static const ELEMTYPE* DownCast( const SMDS_MeshElement* e ) + { + return (( e && !e->IsNull() && ELEMTYPE::Type() == e->GetType() ) ? + static_cast(e) : 0 ); + } const SMDS_MeshNode *FindNode(int idnode) const; const SMDS_MeshNode *FindNodeVtk(int idnode) const; - const SMDS_Mesh0DElement* Find0DElement(int idnode) const; - const SMDS_BallElement* FindBall(int idnode) const; - const SMDS_MeshEdge *FindEdge(int idnode1, int idnode2) const; - const SMDS_MeshEdge *FindEdge(int idnode1, int idnode2, int idnode3) const; - const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3) const; - const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3, int idnode4) const; - const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3, - int idnode4, int idnode5, int idnode6) const; - const SMDS_MeshFace *FindFace(int idnode1, int idnode2, int idnode3, int idnode4, - int idnode5, int idnode6, int idnode7, int idnode8) const; + const SMDS_MeshElement *FindElementVtk(int IDelem) const; virtual const SMDS_MeshElement * FindElement(int IDelem) const; static const SMDS_Mesh0DElement* Find0DElement(const SMDS_MeshNode * n); static const SMDS_BallElement* FindBall(const SMDS_MeshNode * n); @@ -732,8 +656,7 @@ public: const SMDS_MeshNode *n7, const SMDS_MeshNode *n8); - const SMDS_MeshFace *FindFace(const std::vector& nodes_ids) const; - static const SMDS_MeshFace* FindFace(const std::vector& nodes); + static const SMDS_MeshFace* FindFace (const std::vector& nodes); static const SMDS_MeshElement* FindElement(const std::vector& nodes, const SMDSAbs_ElementType type=SMDSAbs_All, const bool noMedium=true); @@ -741,6 +664,8 @@ public: std::vector& foundElems, const SMDSAbs_ElementType type=SMDSAbs_All); + virtual bool Contains( const SMDS_MeshElement* elem ) const; + /*! * \brief Raise an exception if free memory (ram+swap) too low * \param doNotRaise - if true, suppres exception, just return free memory size @@ -764,36 +689,10 @@ public: virtual int NbVolumes() const; virtual int NbSubMesh() const; - void DumpNodes() const; - void Dump0DElements() const; - void DumpEdges() const; - void DumpFaces() const; - void DumpVolumes() const; - void DebugStats() const; - virtual ~SMDS_Mesh(); - bool hasConstructionEdges(); - bool hasConstructionFaces(); - bool hasInverseElements(); - void setConstructionEdges(bool); - void setConstructionFaces(bool); - void setInverseElements(bool); - - /*! - * Checks if the element is present in mesh. - * Useful to determine dead pointers. - * Use this function for debug purpose only! Do not check in the code - * using it even in _DEBUG_ mode - */ - bool Contains (const SMDS_MeshElement* elem) const; - - typedef std::vector SetOfNodes; - typedef std::vector SetOfCells; - - //void updateBoundingBox(); double getMaxDim(); - int fromVtkToSmds(int vtkid); + int FromVtkToSmds(int vtkid) const; void dumpGrid(std::string ficdump="dumpGrid"); static int chunkSize; @@ -803,44 +702,14 @@ public: void Modified(); vtkMTimeType GetMTime() const; - bool isCompacted(); protected: SMDS_Mesh(SMDS_Mesh * parent); - SMDS_MeshFace * createTriangle(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - int ID); - SMDS_MeshFace * createQuadrangle(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - int ID); - SMDS_MeshEdge* FindEdgeOrCreate(const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2); - SMDS_MeshFace* FindFaceOrCreate(const SMDS_MeshNode *n1, - const SMDS_MeshNode *n2, - const SMDS_MeshNode *n3); - SMDS_MeshFace* FindFaceOrCreate(const SMDS_MeshNode *n1, - const SMDS_MeshNode *n2, - const SMDS_MeshNode *n3, - const SMDS_MeshNode *n4); - - bool registerElement(int ID, SMDS_MeshElement * element); - void addChildrenWithNodes(std::set& setOfChildren, const SMDS_MeshElement * element, std::set& nodes); - inline void adjustmyCellsCapacity(int ID) - { - assert(ID >= 0); - myElementIDFactory->adjustMaxId(ID); - if (ID >= (int)myCells.size()) - myCells.resize(ID+SMDS_Mesh::chunkSize,0); - } - inline void adjustBoundingBox(double x, double y, double z) { if (x > xmax) xmax = x; @@ -851,47 +720,29 @@ protected: else if (z < zmin) zmin = z; } - // Fields PRIVATE + void setNbShapes( size_t nbShapes ); - //! index of this SMDS_mesh in the static vector _meshList - int myMeshId; + + // Fields PRIVATE //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid - SMDS_UnstructuredGrid* myGrid; + SMDS_UnstructuredGrid* myGrid; //! Small objects like SMDS_MeshNode are allocated by chunks to limit memory costs of new - ObjectPool* myNodePool; - - //! Small objects like SMDS_VtkVolume are allocated by chunks to limit memory costs of new - ObjectPool* myVolumePool; - ObjectPool* myFacePool; - ObjectPool* myEdgePool; - ObjectPool* myBallPool; - - //! SMDS_MeshNodes refer to vtk nodes (vtk id != index in myNodes),store reference to this mesh, and sub-shape - SetOfNodes myNodes; - SetOfCells myCells; - - //! a buffer to speed up elements addition by excluding some memory allocation - std::vector myNodeIds; - - //! for cells only: index = ID in vtkUnstructuredGrid, value = ID for SMDS users - std::vector myCellIdVtkToSmds; + SMDS_NodeFactory* myNodeFactory; + SMDS_ElementFactory* myCellFactory; - SMDS_Mesh * myParent; - std::list myChildren; - SMDS_MeshNodeIDFactory * myNodeIDFactory; - SMDS_MeshElementIDFactory * myElementIDFactory; - SMDS_MeshInfo myInfo; + SMDS_Mesh * myParent; + std::list myChildren; + SMDS_MeshInfo myInfo; //! any add, remove or change of node or cell - bool myModified; + bool myModified; //! use a counter to keep track of modifications - unsigned long myModifTime, myCompactTime; + unsigned long myModifTime, myCompactTime; - bool myHasConstructionEdges; - bool myHasConstructionFaces; - bool myHasInverseElements; + friend class SMDS_ElementHolder; + std::set< SMDS_ElementHolder* > myElemHolders; double xmin; double xmax; diff --git a/src/SMDS/SMDS_Mesh0DElement.cxx b/src/SMDS/SMDS_Mesh0DElement.cxx deleted file mode 100644 index 8ac7bcc18..000000000 --- a/src/SMDS/SMDS_Mesh0DElement.cxx +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_Mesh0DElement.cxx -// Module : SMESH -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include "SMDS_Mesh0DElement.hxx" -#include "SMDS_IteratorOfElements.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_Mesh.hxx" - -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : SMDS_Mesh0DElement -//purpose : -//======================================================================= -SMDS_Mesh0DElement::SMDS_Mesh0DElement (const SMDS_MeshNode * node) -{ - myNode = node; -} - -//======================================================================= -//function : Print -//purpose : -//======================================================================= -void SMDS_Mesh0DElement::Print (ostream & OS) const -{ - OS << "0D Element <" << GetID() << "> : (" << myNode << ") " << endl; -} - -//======================================================================= -//function : NbNodes -//purpose : -//======================================================================= -int SMDS_Mesh0DElement::NbNodes() const -{ - return 1; -} - -//======================================================================= -//function : NbEdges -//purpose : -//======================================================================= -int SMDS_Mesh0DElement::NbEdges() const -{ - return 0; -} - -//======================================================================= -//function : GetType -//purpose : -//======================================================================= -SMDSAbs_ElementType SMDS_Mesh0DElement::GetType() const -{ - return SMDSAbs_0DElement; -} - -vtkIdType SMDS_Mesh0DElement::GetVtkType() const -{ - return VTK_VERTEX; -} - -//======================================================================= -//function : elementsIterator -//purpose : -//======================================================================= -class SMDS_Mesh0DElement_MyNodeIterator: public SMDS_ElemIterator -{ - const SMDS_MeshNode * myNode; - int myIndex; - public: - SMDS_Mesh0DElement_MyNodeIterator(const SMDS_MeshNode * node): - myNode(node),myIndex(0) {} - - bool more() - { - return myIndex < 1; - } - - const SMDS_MeshElement* next() - { - myIndex++; - if (myIndex == 1) - return myNode; - return NULL; - } -}; - -SMDS_ElemIteratorPtr SMDS_Mesh0DElement::elementsIterator (SMDSAbs_ElementType type) const -{ - switch(type) - { - case SMDSAbs_0DElement: - return SMDS_MeshElement::elementsIterator(SMDSAbs_0DElement); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_Mesh0DElement_MyNodeIterator(myNode)); - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements - (this,type, SMDS_ElemIteratorPtr(new SMDS_Mesh0DElement_MyNodeIterator(myNode)))); - } -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* SMDS_Mesh0DElement::GetNode(const int ind) const -{ - if (ind == 0) - return myNode; - return NULL; -} - -//======================================================================= -//function : ChangeNode -//purpose : -//======================================================================= -bool SMDS_Mesh0DElement::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) -{ - if ( nbNodes == 1 ) - { - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - if (nbNodes != npts) - { - MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); - return false; - } - myNode = nodes[0]; - pts[0] = myNode->getVtkId(); - - SMDS_Mesh::_meshList[myMeshId]->setMyModified(); - return true; - } - return false; -} diff --git a/src/SMDS/SMDS_Mesh0DElement.hxx b/src/SMDS/SMDS_Mesh0DElement.hxx index f4b9fa2dd..1ba4d4b57 100644 --- a/src/SMDS/SMDS_Mesh0DElement.hxx +++ b/src/SMDS/SMDS_Mesh0DElement.hxx @@ -28,28 +28,15 @@ #include "SMDS_MeshCell.hxx" -#include - +/*! + * \brief 0D mesh element. This type is not allocated. + * It is only used as function argument type to provide more clear semantic. + */ class SMDS_EXPORT SMDS_Mesh0DElement: public SMDS_MeshCell { public: - SMDS_Mesh0DElement (const SMDS_MeshNode * node); - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); - virtual void Print (std::ostream & OS) const; - - virtual SMDSAbs_ElementType GetType() const; - virtual vtkIdType GetVtkType() const; - virtual SMDSAbs_EntityType GetEntityType() const {return SMDSEntity_0D;} - virtual SMDSAbs_GeometryType GetGeomType() const { return SMDSGeom_POINT; } - virtual const SMDS_MeshNode* GetNode (const int ind) const; - virtual int NbNodes() const; - virtual int NbEdges() const; - - protected: - virtual SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const; - protected: - const SMDS_MeshNode* myNode; + static SMDSAbs_ElementType Type() { return SMDSAbs_0DElement; } }; #endif diff --git a/src/SMDS/SMDS_MeshCell.cxx b/src/SMDS/SMDS_MeshCell.cxx index 7175ae5d4..ae6d99fad 100644 --- a/src/SMDS/SMDS_MeshCell.cxx +++ b/src/SMDS/SMDS_MeshCell.cxx @@ -18,21 +18,383 @@ // #include "SMDS_MeshCell.hxx" -#include "utilities.h" -int SMDS_MeshCell::nbCells = 0; +#include "SMDS_Mesh.hxx" +#include "SMDS_VtkCellIterator.hxx" -SMDS_MeshCell::SMDS_MeshCell() : - SMDS_MeshElement(-1) +#include + +#include + +#include + +#include + +namespace +{ + /*! + * \brief Cell type features + */ + struct CellProps + { + SMDSAbs_EntityType myEntity; + SMDSAbs_ElementType myType; + SMDSAbs_GeometryType myGeom; + bool myIsPoly; + int myNbCornerNodes; + int myNbNodes; + int myNbEdges; + int myNbFaces; + + CellProps() : + myEntity( SMDSEntity_Last ), myType( SMDSAbs_All ), myGeom( SMDSGeom_NONE ), + myIsPoly( 0 ), myNbCornerNodes( 0 ), + myNbNodes( 0 ), myNbEdges( 0 ), myNbFaces ( 0 ) + { + } + void Set( SMDSAbs_EntityType Entity, + SMDSAbs_ElementType Type, + SMDSAbs_GeometryType Geom, + bool IsPoly, + int NbCornerNodes, + int NbNodes, + int NbEdges, + int NbFaces) + { + myEntity = Entity; + myType = Type; + myGeom = Geom; + myIsPoly = IsPoly; + myNbCornerNodes = NbCornerNodes; + myNbNodes = NbNodes; + myNbEdges = NbEdges; + myNbFaces = NbFaces; + } + bool IsQuadratic() const { return myNbNodes > myNbCornerNodes; } + }; + + //! return vector a CellProps + const CellProps& getCellProps( VTKCellType vtkType ) + { + static std::vector< CellProps > theCellProps; + if ( theCellProps.empty() ) + { + theCellProps.resize( VTK_NUMBER_OF_CELL_TYPES ); + CellProps* p = & theCellProps[0]; + p[ VTK_VERTEX ]. + Set( SMDSEntity_0D, SMDSAbs_0DElement, SMDSGeom_POINT, + /*isPoly=*/0,/*nbCN=*/1,/*nbN=*/1,/*nbE=*/0,/*nbF=*/0 ); + p[ VTK_LINE ]. + Set( SMDSEntity_Edge, SMDSAbs_Edge, SMDSGeom_EDGE, + /*isPoly=*/0,/*nbCN=*/2,/*nbN=*/2,/*nbE=*/1,/*nbF=*/0 ); + p[ VTK_QUADRATIC_EDGE ]. + Set( SMDSEntity_Quad_Edge, SMDSAbs_Edge, SMDSGeom_EDGE, + /*isPoly=*/0,/*nbCN=*/2,/*nbN=*/3,/*nbE=*/1,/*nbF=*/0 ); + p[ VTK_TRIANGLE ]. + Set( SMDSEntity_Triangle, SMDSAbs_Face, SMDSGeom_TRIANGLE, + /*isPoly=*/0,/*nbCN=*/3,/*nbN=*/3,/*nbE=*/3,/*nbF=*/1 ); + p[ VTK_QUADRATIC_TRIANGLE ]. + Set( SMDSEntity_Quad_Triangle, SMDSAbs_Face, SMDSGeom_TRIANGLE, + /*isPoly=*/0,/*nbCN=*/3,/*nbN=*/6,/*nbE=*/3,/*nbF=*/1 ); + p[ VTK_BIQUADRATIC_TRIANGLE ]. + Set( SMDSEntity_BiQuad_Triangle, SMDSAbs_Face, SMDSGeom_TRIANGLE, + /*isPoly=*/0,/*nbCN=*/3,/*nbN=*/7,/*nbE=*/3,/*nbF=*/1 ); + p[ VTK_QUAD]. + Set( SMDSEntity_Quadrangle, SMDSAbs_Face, SMDSGeom_QUADRANGLE, + /*isPoly=*/0,/*nbCN=*/4,/*nbN=*/4,/*nbE=*/4,/*nbF=*/1 ); + p[ VTK_QUADRATIC_QUAD]. + Set( SMDSEntity_Quad_Quadrangle, SMDSAbs_Face, SMDSGeom_QUADRANGLE, + /*isPoly=*/0,/*nbCN=*/4,/*nbN=*/8,/*nbE=*/4,/*nbF=*/1 ); + p[ VTK_BIQUADRATIC_QUAD]. + Set( SMDSEntity_BiQuad_Quadrangle, SMDSAbs_Face, SMDSGeom_QUADRANGLE, + /*isPoly=*/0,/*nbCN=*/4,/*nbN=*/9,/*nbE=*/4,/*nbF=*/1 ); + p[ VTK_POLYGON ]. + Set( SMDSEntity_Polygon, SMDSAbs_Face, SMDSGeom_POLYGON, + /*isPoly=*/1,/*nbCN=*/-1,/*nbN=*/-1,/*nbE=*/-1,/*nbF=*/1 ); + p[ VTK_QUADRATIC_POLYGON ]. + Set( SMDSEntity_Quad_Polygon, SMDSAbs_Face, SMDSGeom_POLYGON, + /*isPoly=*/1,/*nbCN=*/-2,/*nbN=*/-1,/*nbE=*/-1,/*nbF=*/1 ); + p[ VTK_TETRA ]. + Set( SMDSEntity_Tetra, SMDSAbs_Volume, SMDSGeom_TETRA, + /*isPoly=*/0,/*nbCN=*/4,/*nbN=*/4,/*nbE=*/6,/*nbF=*/4 ); + p[ VTK_QUADRATIC_TETRA ]. + Set( SMDSEntity_Quad_Tetra, SMDSAbs_Volume, SMDSGeom_TETRA, + /*isPoly=*/0,/*nbCN=*/4,/*nbN=*/10,/*nbE=*/6,/*nbF=*/4 ); + p[ VTK_PYRAMID ]. + Set( SMDSEntity_Pyramid, SMDSAbs_Volume, SMDSGeom_PYRAMID, + /*isPoly=*/0,/*nbCN=*/5,/*nbN=*/5,/*nbE=*/8,/*nbF=*/5 ); + p[ VTK_QUADRATIC_PYRAMID]. + Set( SMDSEntity_Quad_Pyramid, SMDSAbs_Volume, SMDSGeom_PYRAMID, + /*isPoly=*/0,/*nbCN=*/5,/*nbN=*/13,/*nbE=*/8,/*nbF=*/5 ); + p[ VTK_HEXAHEDRON ]. + Set( SMDSEntity_Hexa, SMDSAbs_Volume, SMDSGeom_HEXA, + /*isPoly=*/0,/*nbCN=*/8,/*nbN=*/8,/*nbE=*/12,/*nbF=*/6 ); + p[ VTK_QUADRATIC_HEXAHEDRON ]. + Set( SMDSEntity_Quad_Hexa, SMDSAbs_Volume, SMDSGeom_HEXA, + /*isPoly=*/0,/*nbCN=*/8,/*nbN=*/20,/*nbE=*/12,/*nbF=*/6 ); + p[ VTK_TRIQUADRATIC_HEXAHEDRON ]. + Set( SMDSEntity_TriQuad_Hexa, SMDSAbs_Volume, SMDSGeom_HEXA, + /*isPoly=*/0,/*nbCN=*/8,/*nbN=*/27,/*nbE=*/12,/*nbF=*/6 ); + p[ VTK_WEDGE ]. + Set( SMDSEntity_Penta, SMDSAbs_Volume, SMDSGeom_PENTA, + /*isPoly=*/0,/*nbCN=*/6,/*nbN=*/6,/*nbE=*/9,/*nbF=*/5 ); + p[ VTK_QUADRATIC_WEDGE ]. + Set( SMDSEntity_Quad_Penta, SMDSAbs_Volume, SMDSGeom_PENTA, + /*isPoly=*/0,/*nbCN=*/6,/*nbN=*/15,/*nbE=*/9,/*nbF=*/5 ); + p[ VTK_BIQUADRATIC_QUADRATIC_WEDGE ]. + Set( SMDSEntity_BiQuad_Penta, SMDSAbs_Volume, SMDSGeom_PENTA, + /*isPoly=*/0,/*nbCN=*/6,/*nbN=*/21,/*nbE=*/9,/*nbF=*/5 ); + p[ VTK_HEXAGONAL_PRISM]. + Set( SMDSEntity_Hexagonal_Prism, SMDSAbs_Volume, SMDSGeom_HEXAGONAL_PRISM, + /*isPoly=*/0,/*nbCN=*/12,/*nbN=*/12,/*nbE=*/18,/*nbF=*/8 ); + p[ VTK_POLYHEDRON ]. + Set( SMDSEntity_Polyhedra, SMDSAbs_Volume, SMDSGeom_POLYHEDRA, + /*isPoly=*/1,/*nbCN=*/-1,/*nbN=*/-1,/*nbE=*/-1,/*nbF=*/-1 ); + p[ VTK_POLY_VERTEX]. + Set( SMDSEntity_Ball, SMDSAbs_Ball, SMDSGeom_BALL, + /*isPoly=*/0,/*nbCN=*/1,/*nbN=*/1,/*nbE=*/0,/*nbF=*/0 ); + } + return theCellProps[ vtkType ]; + + } // getCellProps() + + //! return vector a CellProps + const CellProps& getCellProps( SMDSAbs_EntityType entity ) + { + return getCellProps( SMDS_MeshCell::toVtkType( entity )); + } + +} // namespace + +void SMDS_MeshCell::InitStaticMembers() +{ + getCellProps( SMDSEntity_Ball ); + toVtkOrder( SMDSEntity_Ball ); + reverseSmdsOrder( SMDSEntity_Ball, 1 ); + interlacedSmdsOrder( SMDSEntity_Ball, 1 ); + fromVtkOrder( SMDSEntity_Ball ); +} + +void SMDS_MeshCell::init( SMDSAbs_EntityType theEntity, int theNbNodes, ... ) +{ + ASSERT( getCellProps( theEntity ).myNbNodes == theNbNodes || + getCellProps( theEntity ).myIsPoly); + + va_list vl; + va_start( vl, theNbNodes ); + + vtkIdType vtkIds[ VTK_CELL_SIZE ]; + typedef const SMDS_MeshNode* node_t; + + const std::vector& interlace = toVtkOrder( theEntity ); + if ((int) interlace.size() == theNbNodes ) + { + const SMDS_MeshNode* nodes[ VTK_CELL_SIZE ]; + for ( int i = 0; i < theNbNodes; i++ ) + nodes[i] = va_arg( vl, node_t ); + + for ( int i = 0; i < theNbNodes; i++ ) + vtkIds[i] = nodes[ interlace[i] ]->GetVtkID(); + } + else + { + for ( int i = 0; i < theNbNodes; i++ ) + vtkIds[i] = va_arg( vl, node_t )->GetVtkID(); + } + va_end( vl ); + + int vtkType = toVtkType( theEntity ); + int vtkID = getGrid()->InsertNextLinkedCell( vtkType, theNbNodes, vtkIds ); + setVtkID( vtkID ); +} + +void SMDS_MeshCell::init( SMDSAbs_EntityType theEntity, + const std::vector& nodes ) +{ + std::vector< vtkIdType > vtkIds( nodes.size() ); + for ( size_t i = 0; i < nodes.size(); ++i ) + vtkIds[i] = nodes[i]->GetVtkID(); + + int vtkType = toVtkType( theEntity ); + int vtkID = getGrid()->InsertNextLinkedCell( vtkType, nodes.size(), &vtkIds[0] ); + setVtkID( vtkID ); +} + +void SMDS_MeshCell::init( SMDSAbs_EntityType theEntity, + const std::vector& vtkNodeIds ) +{ + int vtkType = toVtkType( theEntity ); + int vtkID = getGrid()->InsertNextLinkedCell( vtkType, vtkNodeIds.size(), + const_cast< vtkIdType* > ( &vtkNodeIds[0] )); + setVtkID( vtkID ); +} + +bool SMDS_MeshCell::ChangeNodes(const SMDS_MeshNode* nodes[], const int theNbNodes) +{ + vtkIdType npts = 0; + vtkIdType* pts = 0; + getGrid()->GetCellPoints( GetVtkID(), npts, pts ); + if ( theNbNodes != npts ) + { + MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << theNbNodes); + return false; + } + const std::vector& interlace = toVtkOrder((VTKCellType) GetVtkType() ); + if ((int) interlace.size() != theNbNodes ) + for ( int i = 0; i < theNbNodes; i++ ) + { + pts[i] = nodes[i]->GetVtkID(); + } + else + for ( int i = 0; i < theNbNodes; i++ ) + { + pts[i] = nodes[ interlace[i] ]->GetVtkID(); + } + + return true; +} + +/////////////////////////////////////////////////////////////////////////////// +///Return The number of nodes owned by the current element +/////////////////////////////////////////////////////////////////////////////// +int SMDS_MeshCell::NbNodes() const { - nbCells++; - myVtkID = -1; + if ( GetEntityType() == SMDSEntity_Polyhedra ) + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::NbNodes(); + vtkIdType *pts, npts; + getGrid()->GetCellPoints( GetVtkID(), npts, pts ); + return npts; } -SMDS_MeshCell::~SMDS_MeshCell() +int SMDS_MeshCell::NbFaces() const { - nbCells--; + if ( GetEntityType() == SMDSEntity_Polyhedra ) + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::NbFaces(); + return getCellProps( GetVtkType() ).myNbFaces; } + +int SMDS_MeshCell::NbEdges() const +{ + switch ( GetEntityType() ) + { + case SMDSEntity_Polyhedra: + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::NbEdges(); + case SMDSEntity_Polygon: + return NbNodes(); + case SMDSEntity_Quad_Polygon: + return NbNodes() / 2; + default:; + } + return getCellProps( GetVtkType() ).myNbEdges; +} + +int SMDS_MeshCell::NbCornerNodes() const +{ + switch ( GetEntityType() ) + { + case SMDSEntity_Polyhedra: + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::NbCornerNodes(); + case SMDSEntity_Polygon: + return NbNodes(); + case SMDSEntity_Quad_Polygon: + return NbNodes() / 2; + default:; + } + return getCellProps( GetVtkType() ).myNbCornerNodes; +} + +/////////////////////////////////////////////////////////////////////////////// +/// Create an iterator which iterate on nodes owned by the element. +/////////////////////////////////////////////////////////////////////////////// +SMDS_ElemIteratorPtr SMDS_MeshCell::nodesIterator() const +{ + if ( GetEntityType() == SMDSEntity_Polyhedra ) + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::nodesIterator(); + + return boost::make_shared< SMDS_VtkCellIterator<> >( GetMesh(), GetVtkID(), GetEntityType()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// Create an iterator which iterate on nodes owned by the element. +/////////////////////////////////////////////////////////////////////////////// +SMDS_NodeIteratorPtr SMDS_MeshCell::nodeIterator() const +{ + if ( GetEntityType() == SMDSEntity_Polyhedra ) + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::nodeIterator(); + + return SMDS_NodeIteratorPtr + (new SMDS_VtkCellIterator( GetMesh(), GetVtkID(), GetEntityType())); +} + +SMDS_NodeIteratorPtr SMDS_MeshCell::interlacedNodesIterator() const +{ + bool canInterlace = ( GetType() == SMDSAbs_Face || GetType() == SMDSAbs_Edge ); + return canInterlace ? nodesIteratorToUNV() : nodeIterator(); +} + +SMDS_NodeIteratorPtr SMDS_MeshCell::nodesIteratorToUNV() const +{ + return SMDS_NodeIteratorPtr + (new SMDS_VtkCellIteratorToUNV( GetMesh(), GetVtkID(), GetEntityType())); +} + +SMDSAbs_ElementType SMDS_MeshCell::GetType() const +{ + return ElemType( GetEntityType() ); +} + +SMDSAbs_EntityType SMDS_MeshCell::GetEntityType() const +{ + return toSmdsType( (VTKCellType) GetVtkType() ); +} + +SMDSAbs_GeometryType SMDS_MeshCell::GetGeomType() const +{ + return getCellProps( GetVtkType() ).myGeom; +} + +VTKCellType SMDS_MeshCell::GetVtkType() const +{ + return (VTKCellType) getGrid()->GetCellType( GetVtkID() ); +} + +bool SMDS_MeshCell::IsPoly() const +{ + return getCellProps( GetVtkType() ).myIsPoly; +} + +bool SMDS_MeshCell::IsQuadratic() const +{ + return getCellProps( GetVtkType() ).IsQuadratic(); +} + +const SMDS_MeshNode* SMDS_MeshCell::GetNode(const int ind) const +{ + if ( GetEntityType() == SMDSEntity_Polyhedra ) + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::GetNode( ind ); + + vtkIdType npts, *pts; + getGrid()->GetCellPoints( GetVtkID(), npts, pts ); + const std::vector& interlace = SMDS_MeshCell::fromVtkOrder( VTKCellType( GetVtkType() )); + return GetMesh()->FindNodeVtk( pts[ interlace.empty() ? ind : interlace[ ind ]]); +} + +int SMDS_MeshCell::GetNodeIndex( const SMDS_MeshNode* node ) const +{ + if ( GetEntityType() == SMDSEntity_Polyhedra ) + return static_cast< const SMDS_MeshVolume* >( this )->SMDS_MeshVolume::GetNodeIndex( node ); + + vtkIdType npts, *pts; + getGrid()->GetCellPoints( GetVtkID(), npts, pts ); + for ( vtkIdType i = 0; i < npts; ++i ) + if ( pts[i] == node->GetVtkID() ) + { + const std::vector& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( GetVtkType() )); + return interlace.empty() ? i : interlace[i]; + } + return -1; +} + //================================================================================ /*! * \brief Return VTKCellType corresponding to SMDSAbs_EntityType @@ -262,7 +624,7 @@ const std::vector& SMDS_MeshCell::reverseSmdsOrder(SMDSAbs_EntityType smdsT const int ids[] = {0,2,1,3,5,4, 8,7,6,11,10,9,12,14,13,15,16,17}; reverseInterlaces[SMDSEntity_BiQuad_Penta].assign( &ids[0], &ids[0]+18 ); } - { + { const int ids[] = {0,5,4,3,2,1,6,11,10,9,8,7}; reverseInterlaces[SMDSEntity_Hexagonal_Prism].assign( &ids[0], &ids[0]+12 ); } @@ -348,14 +710,7 @@ const std::vector& SMDS_MeshCell::interlacedSmdsOrder(SMDSAbs_EntityType sm SMDSAbs_EntityType SMDS_MeshCell::toSmdsType(VTKCellType vtkType) { - static std::vector< SMDSAbs_EntityType > smdsTypes; - if ( smdsTypes.empty() ) - { - smdsTypes.resize( VTK_NUMBER_OF_CELL_TYPES, SMDSEntity_Last ); - for ( int iSMDS = 0; iSMDS < SMDSEntity_Last; ++iSMDS ) - smdsTypes[ toVtkType( SMDSAbs_EntityType( iSMDS ))] = SMDSAbs_EntityType( iSMDS ); - } - return smdsTypes[ vtkType ]; + return getCellProps( vtkType ).myEntity; } //================================================================================ @@ -364,7 +719,7 @@ SMDSAbs_EntityType SMDS_MeshCell::toSmdsType(VTKCellType vtkType) */ //================================================================================ -SMDSAbs_ElementType SMDS_MeshCell::toSmdsType(SMDSAbs_GeometryType geomType) +SMDSAbs_ElementType SMDS_MeshCell::ElemType(SMDSAbs_GeometryType geomType) { switch ( geomType ) { case SMDSGeom_POINT: return SMDSAbs_0DElement; @@ -395,46 +750,45 @@ SMDSAbs_ElementType SMDS_MeshCell::toSmdsType(SMDSAbs_GeometryType geomType) */ //================================================================================ -SMDSAbs_ElementType SMDS_MeshCell::toSmdsType(SMDSAbs_EntityType entityType) +SMDSAbs_ElementType SMDS_MeshCell::ElemType(SMDSAbs_EntityType entityType) { - switch ( entityType ) { - case SMDSEntity_Node: return SMDSAbs_Node; + return getCellProps( entityType ).myType; +} + +SMDSAbs_GeometryType SMDS_MeshCell::GeomType( SMDSAbs_EntityType entityType ) +{ + return getCellProps( entityType ).myGeom; +} - case SMDSEntity_0D: return SMDSAbs_0DElement; +bool SMDS_MeshCell::IsPoly( SMDSAbs_EntityType entityType ) +{ + return getCellProps( entityType ).myIsPoly; +} - case SMDSEntity_Edge: - case SMDSEntity_Quad_Edge: return SMDSAbs_Edge; +bool SMDS_MeshCell::IsQuadratic( SMDSAbs_EntityType entityType ) +{ + return getCellProps( entityType ).IsQuadratic(); +} - case SMDSEntity_Triangle: - case SMDSEntity_Quad_Triangle: - case SMDSEntity_BiQuad_Triangle: - case SMDSEntity_Quadrangle: - case SMDSEntity_Quad_Quadrangle: - case SMDSEntity_BiQuad_Quadrangle: - case SMDSEntity_Polygon: - case SMDSEntity_Quad_Polygon: return SMDSAbs_Face; - - case SMDSEntity_Tetra: - case SMDSEntity_Quad_Tetra: - case SMDSEntity_Pyramid: - case SMDSEntity_Quad_Pyramid: - case SMDSEntity_Hexa: - case SMDSEntity_Quad_Hexa: - case SMDSEntity_TriQuad_Hexa: - case SMDSEntity_Penta: - case SMDSEntity_Quad_Penta: - case SMDSEntity_BiQuad_Penta: - case SMDSEntity_Hexagonal_Prism: - case SMDSEntity_Polyhedra: - case SMDSEntity_Quad_Polyhedra: return SMDSAbs_Volume; +int SMDS_MeshCell::NbCornerNodes( SMDSAbs_EntityType entityType ) +{ + return getCellProps( entityType ).myNbCornerNodes; +} - case SMDSEntity_Ball: return SMDSAbs_Ball; +int SMDS_MeshCell::NbNodes( SMDSAbs_EntityType entityType ) +{ + return getCellProps( entityType ).myNbNodes; +} - case SMDSEntity_Last:; - } - return SMDSAbs_All; +int SMDS_MeshCell::NbEdges( SMDSAbs_EntityType entityType ) +{ + return getCellProps( entityType ).myNbEdges; } +int SMDS_MeshCell::NbFaces( SMDSAbs_EntityType entityType ) +{ + return getCellProps( entityType ).myNbFaces; +} //================================================================================ /*! diff --git a/src/SMDS/SMDS_MeshCell.hxx b/src/SMDS/SMDS_MeshCell.hxx index 413b1265a..568cbbbc9 100644 --- a/src/SMDS/SMDS_MeshCell.hxx +++ b/src/SMDS/SMDS_MeshCell.hxx @@ -28,17 +28,52 @@ class SMDS_EXPORT SMDS_MeshCell: public SMDS_MeshElement { -public: - SMDS_MeshCell(); - virtual ~SMDS_MeshCell(); + protected: - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)= 0; - virtual bool vtkOrder(const SMDS_MeshNode* nodes[], const int nbNodes) { return true; } + void init( SMDSAbs_EntityType entityType, int nbNodes, ... ); - static VTKCellType toVtkType (SMDSAbs_EntityType vtkType); - static SMDSAbs_EntityType toSmdsType(VTKCellType vtkType); - static SMDSAbs_ElementType toSmdsType(SMDSAbs_GeometryType geomType); - static SMDSAbs_ElementType toSmdsType(SMDSAbs_EntityType entityType); + void init( SMDSAbs_EntityType entityType, const std::vector& nodes ); + + void init( SMDSAbs_EntityType entityType, const std::vector& vtkNodeIds ); + + friend class SMDS_Mesh; + + public: + + virtual int NbEdges() const; + virtual int NbFaces() const; + virtual int NbNodes() const; + virtual int NbCornerNodes() const; + virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; + virtual const SMDS_MeshNode* GetNode(const int ind) const; + + virtual SMDSAbs_ElementType GetType() const; + virtual SMDSAbs_EntityType GetEntityType() const; + virtual SMDSAbs_GeometryType GetGeomType() const; + virtual VTKCellType GetVtkType() const; + + virtual bool IsPoly() const; + virtual bool IsQuadratic() const; + + virtual SMDS_ElemIteratorPtr nodesIterator() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; + virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const; + virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const; + + + static void InitStaticMembers(); + static VTKCellType toVtkType ( SMDSAbs_EntityType entityType ); + static SMDSAbs_EntityType toSmdsType ( VTKCellType vtkType ); + static SMDSAbs_ElementType ElemType ( SMDSAbs_GeometryType geomType ); + static SMDSAbs_ElementType ElemType ( SMDSAbs_EntityType entityType ); + static SMDSAbs_GeometryType GeomType ( SMDSAbs_EntityType entityType ); + static bool IsPoly ( SMDSAbs_EntityType entityType ); + static bool IsQuadratic ( SMDSAbs_EntityType entityType ); + static int NbCornerNodes( SMDSAbs_EntityType entityType ); + static int NbNodes ( SMDSAbs_EntityType entityType ); + static int NbEdges ( SMDSAbs_EntityType entityType ); + static int NbFaces ( SMDSAbs_EntityType entityType ); static const std::vector& toVtkOrder(VTKCellType vtkType); static const std::vector& toVtkOrder(SMDSAbs_EntityType smdsType); @@ -50,6 +85,7 @@ public: static const std::vector& interlacedSmdsOrder(SMDSAbs_EntityType smdsType, const size_t nbNodes=0); + template< class VECT > // interlacedIDs[i] = smdsIDs[ indices[ i ]] static void applyInterlace( const std::vector& interlace, VECT & data) { @@ -69,15 +105,6 @@ public: data.swap( tmpData ); } - static int nbCells; - -protected: - inline void exchange(const SMDS_MeshNode* nodes[],int a, int b) - { - const SMDS_MeshNode* noda = nodes[a]; - nodes[a] = nodes[b]; - nodes[b] = noda; - } }; #endif diff --git a/src/SMDS/SMDS_MeshEdge.cxx b/src/SMDS/SMDS_MeshEdge.cxx deleted file mode 100644 index 672adee4f..000000000 --- a/src/SMDS/SMDS_MeshEdge.cxx +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2010-2016 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, or (at your option) any later version. -// -// 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 "SMDS_MeshEdge.hxx" - -SMDSAbs_ElementType SMDS_MeshEdge::GetType() const -{ - return SMDSAbs_Edge; -} - -vtkIdType SMDS_MeshEdge::GetVtkType() const -{ - return VTK_POLY_VERTEX; // --- must be reimplemented in derived classes -} diff --git a/src/SMDS/SMDS_MeshEdge.hxx b/src/SMDS/SMDS_MeshEdge.hxx index 423d96241..462028e91 100644 --- a/src/SMDS/SMDS_MeshEdge.hxx +++ b/src/SMDS/SMDS_MeshEdge.hxx @@ -28,12 +28,16 @@ #include "SMDS_MeshCell.hxx" +/*! + * \brief Edge mesh element. This type is not allocated. + * It is only used as function argument type to provide more clear semantic. + */ class SMDS_EXPORT SMDS_MeshEdge: public SMDS_MeshCell { - public: - virtual SMDSAbs_ElementType GetType() const; - virtual vtkIdType GetVtkType() const; + virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Edge; } virtual SMDSAbs_GeometryType GetGeomType() const { return SMDSGeom_EDGE; } + + static SMDSAbs_ElementType Type() { return SMDSAbs_Edge; } }; #endif diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index 31119a8ed..48221c7c6 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -27,282 +27,190 @@ #endif #include "SMDS_MeshElement.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_MeshEdge.hxx" -#include "SMDS_MeshFace.hxx" -#include "SMDS_MeshVolume.hxx" + +#include "SMDS_Mesh.hxx" +#include "SMDS_ElementFactory.hxx" + #include "utilities.h" -using namespace std; +//================================================================================ +/*! + * \brief Constructor of a non-used element + */ +//================================================================================ -SMDS_MeshElement::SMDS_MeshElement(int ID) +SMDS_MeshElement::SMDS_MeshElement(): myHolder(0) { - init(ID); } -SMDS_MeshElement::SMDS_MeshElement(int id, ShortType meshId, LongType shapeId) -{ - init(id, meshId, shapeId); -} +//================================================================================ +/*! + * \brief Check if a node is a medium node of a quadratic cell + */ +//================================================================================ -void SMDS_MeshElement::init(int id, ShortType meshId, LongType shapeId ) +bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const { - myID = id; - myMeshId = meshId; - myShapeId = shapeId; - myIdInShape = -1; + return !( GetNodeIndex( node ) < NbCornerNodes() ); } -void SMDS_MeshElement::Print(ostream & OS) const -{ - OS << "dump of mesh element" << endl; -} +//================================================================================ +/*! + * \brief Return true if index of node is valid (0 <= ind < NbNodes()) + * \param ind - node index + * \retval bool - index check result + */ +//================================================================================ -ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) +bool SMDS_MeshElement::IsValidIndex(const int ind) const { - ME->Print(OS); - return OS; + return ( ind>-1 && ind= NbCornerNodes() ) return ind % NbCornerNodes(); + return ind; } -/////////////////////////////////////////////////////////////////////////////// -/// Create an iterator which iterate on faces linked with or owned by the element. -/// This method call elementsIterator(). -/////////////////////////////////////////////////////////////////////////////// -SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const -{ - return elementsIterator(SMDSAbs_Face); -} +//================================================================================ +/*! + * \brief Check if a node belongs to the element + * \param node - the node to check + * \retval int - node index within the element, -1 if not found + */ +//================================================================================ -/////////////////////////////////////////////////////////////////////////////// -///Return The number of nodes owned by the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbNodes() const +int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const { - int nbnodes=0; - SMDS_ElemIteratorPtr it=nodesIterator(); - while(it->more()) - { - it->next(); - nbnodes++; - } - return nbnodes; + SMDS_ElemIteratorPtr nIt = nodesIterator(); + for ( int i = 0; nIt->more(); ++i ) + if ( nIt->next() == node ) + return i; + return -1; } -/////////////////////////////////////////////////////////////////////////////// -///Return the number of edges owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbEdges() const -{ - int nbedges=0; - SMDS_ElemIteratorPtr it=edgesIterator(); - while(it->more()) - { - it->next(); - nbedges++; - } - return nbedges; -} +//================================================================================ +/*! + * \brief Return ID of an element + */ +//================================================================================ -/////////////////////////////////////////////////////////////////////////////// -///Return the number of faces owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbFaces() const +int SMDS_MeshElement::GetID() const { - int nbfaces=0; - SMDS_ElemIteratorPtr it=facesIterator(); - while(it->more()) - { - it->next(); - nbfaces++; - } - return nbfaces; + return myHolder ? myHolder->GetID( this ) : -1; } -/////////////////////////////////////////////////////////////////////////////// -///Create an iterator which iterate on elements linked with the current element. -///@param type The of elements on which you want to iterate -///@return A smart pointer to iterator, you are not to take care of freeing memory -/////////////////////////////////////////////////////////////////////////////// -class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator -{ - const SMDS_MeshElement * myElement; - bool myMore; -public: - SMDS_MeshElement_MyIterator(const SMDS_MeshElement * element): - myElement(element),myMore(true) {} - - bool more() - { - return myMore; - } - - const SMDS_MeshElement* next() - { - myMore=false; - return myElement; - } -}; - -SMDS_ElemIteratorPtr -SMDS_MeshElement::elementsIterator(SMDSAbs_ElementType type) const -{ - /** @todo Check that iterator in the child classes return elements - in the same order for each different implementation (i.e: SMDS_VolumeOfNodes - and SMDS_VolumeOfFaces */ - if(type==GetType()) - return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this)); - else - { - MESSAGE("Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); - } -} +//================================================================================ +/*! + * \brief Set ID of a shape this element was generated on + */ +//================================================================================ -//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes -SMDS_NodeIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const +void SMDS_MeshElement::setShapeID( const int shapeID ) const { - return nodeIterator(); + const_cast( myHolder )->SetShapeID( this, shapeID ); } -//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes -SMDS_NodeIteratorPtr SMDS_MeshElement::interlacedNodesIterator() const -{ - return nodeIterator(); -} +//================================================================================ +/*! + * \brief Return ID of a shape this element was generated on + */ +//================================================================================ -namespace +int SMDS_MeshElement::GetShapeID() const { - //======================================================================= - //class : _MyNodeIteratorFromElemIterator - //======================================================================= - class _MyNodeIteratorFromElemIterator : public SMDS_NodeIterator - { - SMDS_ElemIteratorPtr myItr; - public: - _MyNodeIteratorFromElemIterator(SMDS_ElemIteratorPtr elemItr):myItr( elemItr ) {} - bool more() { return myItr->more(); } - const SMDS_MeshNode* next() { return static_cast< const SMDS_MeshNode*>( myItr->next() ); } - }; - //======================================================================= - //class : _MyElemIteratorFromNodeIterator - //======================================================================= - class _MyElemIteratorFromNodeIterator : public SMDS_ElemIterator - { - SMDS_NodeIteratorPtr myItr; - public: - _MyElemIteratorFromNodeIterator(SMDS_NodeIteratorPtr nodeItr): myItr( nodeItr ) {} - bool more() { return myItr->more(); } - const SMDS_MeshElement* next() { return myItr->next(); } - }; + return myHolder->GetShapeID( this ); } -SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const -{ - return SMDS_ElemIteratorPtr - ( new _MyElemIteratorFromNodeIterator( interlacedNodesIterator() )); -} +//================================================================================ +/*! + * \brief Return VTK ID of this element + */ +//================================================================================ -SMDS_NodeIteratorPtr SMDS_MeshElement::nodeIterator() const +int SMDS_MeshElement::GetVtkID() const { - return SMDS_NodeIteratorPtr - ( new _MyNodeIteratorFromElemIterator( nodesIterator() )); + return myHolder->GetVtkID( this ); } -bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2) -{ - if(e1.GetType()!=e2.GetType()) return false; - switch(e1.GetType()) - { - case SMDSAbs_Node: - return static_cast(e1) < - static_cast(e2); - - case SMDSAbs_Edge: - return static_cast(e1) < - static_cast(e2); - - case SMDSAbs_Face: - return static_cast(e1) < - static_cast(e2); - - case SMDSAbs_Volume: - return static_cast(e1) < - static_cast(e2); - - default : MESSAGE("Internal Error"); - } - return false; -} +//================================================================================ +/*! + * \brief Mark this element + */ +//================================================================================ -bool SMDS_MeshElement::IsValidIndex(const int ind) const +void SMDS_MeshElement::setIsMarked( bool is ) const { - return ( ind>-1 && ind( myHolder )->SetIsMarked( this, is ); } -const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const +//================================================================================ +/*! + * \brief Check if this element is marked + */ +//================================================================================ + +bool SMDS_MeshElement::isMarked() const { - if ( ind >= 0 ) { - SMDS_ElemIteratorPtr it = nodesIterator(); - for ( int i = 0; i < ind; ++i ) - it->next(); - if ( it->more() ) - return static_cast (it->next()); - } - return 0; + return myHolder->IsMarked( this ); } -bool SMDS_MeshElement::IsQuadratic() const +//================================================================================ +/*! + * \brief Store VTK ID + */ +//================================================================================ + +void SMDS_MeshElement::setVtkID( const int vtkID ) { - return false; + myHolder->SetVTKID( this, vtkID ); } -bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const +//================================================================================ +/*! + * \brief Return the mesh this element belongs to + */ +//================================================================================ + +SMDS_Mesh* SMDS_MeshElement::GetMesh() const { - return false; + return const_cast( myHolder )->GetMesh(); } //================================================================================ /*! - * \brief Return number of nodes excluding medium ones + * \brief Return a SMDS_UnstructuredGrid */ //================================================================================ -int SMDS_MeshElement::NbCornerNodes() const +SMDS_UnstructuredGrid* SMDS_MeshElement::getGrid() const { - return IsQuadratic() ? NbNodes() - NbEdges() : NbNodes(); + return const_cast( myHolder )->GetMesh()->GetGrid(); } //================================================================================ /*! - * \brief Check if a node belongs to the element - * \param node - the node to check - * \retval int - node index within the element, -1 if not found + * \brief Print self */ //================================================================================ -int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const +void SMDS_MeshElement::Print(ostream & OS) const { - SMDS_ElemIteratorPtr nIt = nodesIterator(); - for ( int i = 0; nIt->more(); ++i ) - if ( nIt->next() == node ) - return i; - return -1; + OS << "dump of mesh element" << endl; +} + +ostream & operator <<(ostream & OS, const SMDS_MeshElement * e) +{ + e->Print(OS); + return OS; } diff --git a/src/SMDS/SMDS_MeshElement.hxx b/src/SMDS/SMDS_MeshElement.hxx index 4634548aa..63fc8cecf 100644 --- a/src/SMDS/SMDS_MeshElement.hxx +++ b/src/SMDS/SMDS_MeshElement.hxx @@ -32,23 +32,17 @@ #include "SMDSAbs_ElementType.hxx" #include "SMDS_MeshObject.hxx" #include "SMDS_ElemIterator.hxx" -#include "SMDS_MeshElementIDFactory.hxx" #include "SMDS_StdIterator.hxx" -#include #include #include #include -//typedef unsigned short UShortType; -typedef short ShortType; -typedef int LongType; - -class SMDS_MeshNode; -class SMDS_MeshEdge; -class SMDS_MeshFace; +class SMDS_ElementChunk; class SMDS_Mesh; +class SMDS_MeshNode; +class SMDS_UnstructuredGrid; // ============================================================ /*! @@ -61,43 +55,36 @@ class SMDS_EXPORT SMDS_MeshElement : public SMDS_MeshObject { public: - SMDS_ElemIteratorPtr nodesIterator() const; - SMDS_ElemIteratorPtr edgesIterator() const; - SMDS_ElemIteratorPtr facesIterator() const; - virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - virtual SMDS_ElemIteratorPtr interlacedNodesElemIterator() const; + // =========================== + // Access to nodes + // =========================== + virtual SMDS_ElemIteratorPtr nodesIterator() const = 0; - virtual SMDS_NodeIteratorPtr nodeIterator() const; - virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const; - virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const = 0; + virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const { return nodeIterator(); } + virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const { return nodeIterator(); } // std-like iteration on nodes - typedef SMDS_StdIterator< const SMDS_MeshNode*, SMDS_ElemIteratorPtr > iterator; - iterator begin_nodes() const { return iterator( nodesIterator() ); } + typedef SMDS_StdIterator< const SMDS_MeshNode*, SMDS_NodeIteratorPtr > iterator; + iterator begin_nodes() const { return iterator( nodeIterator() ); } iterator end_nodes() const { return iterator(); } - virtual int NbNodes() const; - virtual int NbEdges() const; - virtual int NbFaces() const; - inline int GetID() const { return myID; } + // =========================== + // Type of element + // =========================== + virtual int NbNodes() const = 0; + virtual int NbEdges() const = 0; + virtual int NbFaces() const = 0; - ///Return the type of the current element virtual SMDSAbs_ElementType GetType() const = 0; virtual SMDSAbs_EntityType GetEntityType() const = 0; virtual SMDSAbs_GeometryType GetGeomType() const = 0; - virtual vtkIdType GetVtkType() const = 0; + virtual VTKCellType GetVtkType() const = 0; - virtual bool IsPoly() const { return false; } - virtual bool IsQuadratic() const; + virtual bool IsPoly() const = 0; + virtual bool IsQuadratic() const = 0; virtual bool IsMediumNode(const SMDS_MeshNode* node) const; - virtual int NbCornerNodes() const; - - friend SMDS_EXPORT std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *); - friend SMDS_EXPORT bool SMDS_MeshElementIDFactory::BindID(int ID,SMDS_MeshElement* elem); - friend class SMDS_Mesh; - friend class SMESHDS_Mesh; - friend class SMESHDS_SubMesh; - friend class SMDS_MeshElementIDFactory; + virtual int NbCornerNodes() const = 0; // =========================== // Access to nodes by index @@ -107,14 +94,14 @@ public: * \param ind - node index * \retval const SMDS_MeshNode* - the node */ - virtual const SMDS_MeshNode* GetNode(const int ind) const; + virtual const SMDS_MeshNode* GetNode(const int ind) const = 0; /*! * \brief Return node by its index * \param ind - node index * \retval const SMDS_MeshNode* - the node * - * Index is wrapped if it is out of a valid range + * Index is wrapped if it is out of a valid range of corner nodes */ const SMDS_MeshNode* GetNodeWrap(const int ind) const { return GetNode( WrappedIndex( ind )); } @@ -126,15 +113,11 @@ public: virtual bool IsValidIndex(const int ind) const; /*! - * \brief Return a valid node index, fixing the given one if necessary + * \brief Return a valid corner node index, fixing the given one if necessary * \param ind - node index * \retval int - valid node index */ - int WrappedIndex(const int ind) const { - if ( ind < 0 ) return NbNodes() + ind % NbNodes(); - if ( ind >= NbNodes() ) return ind % NbNodes(); - return ind; - } + int WrappedIndex(const int ind) const; /*! * \brief Check if a node belongs to the element @@ -143,14 +126,26 @@ public: */ virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; - inline ShortType getMeshId() const { return myMeshId; } - inline LongType getshapeId() const { return myShapeId >> BITS_SHIFT; } - inline int getIdInShape() const { return myIdInShape; } - inline int getVtkId() const { return myVtkID; } + + virtual int GetID() const; + virtual int GetVtkID() const; + virtual int getshapeId() const { return GetShapeID(); } + virtual int GetShapeID() const; // mark this element; to be used in algos - inline void setIsMarked( bool is ) const; - inline bool isMarked() const; + virtual void setIsMarked( bool is ) const; + virtual bool isMarked() const; + + // element can be allocated but "not used" + bool IsNull() const { return myHolder == 0; } + + SMDS_Mesh* GetMesh() const; + + void Print(std::ostream & OS) const; + + friend SMDS_EXPORT std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *); + friend class SMDS_ElementFactory; + friend class SMESHDS_SubMesh; /*! * \brief Filters of elements, to be used with SMDS_SetIterator @@ -183,41 +178,19 @@ public: bool operator()(const SMDS_MeshElement* e) const { return e && e->GetGeomType() == _type; } }; -protected: - inline void setId(int id) { myID = id; } - inline void setVtkId(int vtkId) { myVtkID = vtkId; } - inline void setIdInShape(int id) { myIdInShape = id; } - inline void setShapeId(LongType shapeId) { myShapeId = ( shapeId << BITS_SHIFT ) | ( myShapeId & BIT_IS_MARKED ); } - SMDS_MeshElement(int ID=-1); - SMDS_MeshElement(int id, ShortType meshId, LongType shapeId = 0); - virtual void init(int id = -1, ShortType meshId = -1, LongType shapeId = 0); - virtual void Print(std::ostream & OS) const; - - //! Element index in vector SMDS_Mesh::myNodes or SMDS_Mesh::myCells - int myID; - //! index in vtkUnstructuredGrid - int myVtkID; - //! SMDS_Mesh identification in SMESH - ShortType myMeshId; - //! SubShape and SubMesh identification in SMESHDS; one bit is used to mark the element - LongType myShapeId; - //! Element index in SMESHDS_SubMesh vector - int myIdInShape; - - enum Bits { // use the 1st right bit of myShapeId to set/unset a mark - BIT_IS_MARKED = 1, - BITS_SHIFT = 1 - }; -}; + protected: -inline void SMDS_MeshElement::setIsMarked( bool is ) const -{ - const_cast< SMDS_MeshElement* >( this )->myShapeId = ( myShapeId & ~BIT_IS_MARKED ) | is; -} -inline bool SMDS_MeshElement::isMarked() const -{ - return myShapeId & BIT_IS_MARKED; -} + SMDS_MeshElement(); + + void setVtkID(const int vtkID ); + virtual void setShapeID( const int shapeID ) const; + + SMDS_UnstructuredGrid* getGrid() const; + + protected: + + SMDS_ElementChunk* myHolder; +}; // ============================================================ /*! diff --git a/src/SMDS/SMDS_MeshElementIDFactory.cxx b/src/SMDS/SMDS_MeshElementIDFactory.cxx deleted file mode 100644 index c7fc45eb6..000000000 --- a/src/SMDS/SMDS_MeshElementIDFactory.cxx +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_MeshElementIDFactory.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include "SMDS_MeshElementIDFactory.hxx" -#include "SMDS_MeshElement.hxx" -#include "SMDS_Mesh.hxx" - -#include "utilities.h" - -#include "SMDS_UnstructuredGrid.hxx" -#include - -#include - -using namespace std; - -//======================================================================= -//function : SMDS_MeshElementIDFactory -//purpose : -//======================================================================= -SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory(): - SMDS_MeshNodeIDFactory() -{ -} - -int SMDS_MeshElementIDFactory::SetInVtkGrid(SMDS_MeshElement * elem) -{ - // --- retrieve nodes ID - - SMDS_MeshCell *cell = dynamic_cast(elem); - assert(cell); - vector nodeIds( elem->NbNodes() ); - SMDS_ElemIteratorPtr it = elem->nodesIterator(); - for( int i = 0; it->more(); ++i ) - { - int nodeId = (static_cast(it->next()))->getVtkId(); - nodeIds[i] = nodeId; - } - - // --- insert cell in vtkUnstructuredGrid - - int typ = VTK_VERTEX; - int cellId = myMesh->getGrid()->InsertNextLinkedCell(typ, nodeIds.size(), &nodeIds[0]); - cell->setVtkId(cellId); - return cellId; -} - -//======================================================================= -//function : BindID -//purpose : -//======================================================================= - -bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem) -{ - SetInVtkGrid(elem); - return myMesh->registerElement(ID, elem); -} - -//======================================================================= -//function : MeshElement -//purpose : -//======================================================================= -SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID) -{ - if ( ID<1 || ID >= (int) myMesh->myCells.size() ) - return NULL; - const SMDS_MeshElement* elem = GetMesh()->FindElement(ID); - return (SMDS_MeshElement*)(elem); -} - -//======================================================================= -//function : GetFreeID -//purpose : -//======================================================================= - -int SMDS_MeshElementIDFactory::GetFreeID() -{ - int ID; - do { - ID = SMDS_MeshIDFactory::GetFreeID(); - } while ( MeshElement( ID )); - return ID; -} - -//======================================================================= -//function : ReleaseID -//purpose : -//======================================================================= -void SMDS_MeshElementIDFactory::ReleaseID(int ID, int vtkId) -{ - if (ID < 1) // TODO check case ID == O - { - MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID); - return; - } - if (vtkId >= 0) - { - assert(vtkId < (int)myMesh->myCellIdVtkToSmds.size()); - myMesh->myCellIdVtkToSmds[vtkId] = -1; - myMesh->setMyModified(); - } - SMDS_MeshIDFactory::ReleaseID(ID); - if (ID == myMax) - myMax = 0; - if (ID == myMin) - myMax = 0; -} - -//======================================================================= -//function : updateMinMax -//purpose : -//======================================================================= - -void SMDS_MeshElementIDFactory::updateMinMax() const -{ - myMin = INT_MAX; - myMax = 0; - for (size_t i = 0; i < myMesh->myCells.size(); i++) - { - if (myMesh->myCells[i]) - { - int id = myMesh->myCells[i]->GetID(); - if (id > myMax) - myMax = id; - if (id < myMin) - myMin = id; - } - } - if (myMin == INT_MAX) - myMin = 0; -} - -//======================================================================= -//function : elementsIterator -//purpose : Return an iterator on elements of the factory -//======================================================================= - -SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const -{ - return myMesh->elementsIterator(SMDSAbs_All); -} - -void SMDS_MeshElementIDFactory::Clear() -{ - myMesh->myCellIdVtkToSmds.clear(); - myMin = myMax = 0; - SMDS_MeshIDFactory::Clear(); -} diff --git a/src/SMDS/SMDS_MeshFace.hxx b/src/SMDS/SMDS_MeshFace.hxx index 92f2f9b4f..11e1f32c6 100644 --- a/src/SMDS/SMDS_MeshFace.hxx +++ b/src/SMDS/SMDS_MeshFace.hxx @@ -31,11 +31,37 @@ #include "SMDS_MeshCell.hxx" -class SMDS_EXPORT SMDS_MeshFace:public SMDS_MeshCell +#include "Utils_SALOME_Exception.hxx" + +/*! + * \brief Mesh face. This type is not allocated. + * It is only used as function argument type to provide more clear semantic. + */ +class SMDS_EXPORT SMDS_MeshFace : public SMDS_MeshCell { - public: - SMDSAbs_ElementType GetType() const; - virtual vtkIdType GetVtkType() const; + void init( const std::vector& vtkNodeIds ) + { + SMDSAbs_EntityType entity = SMDSEntity_Triangle; + switch ( vtkNodeIds.size()) + { + case 3: entity = SMDSEntity_Triangle; break; + case 4: entity = SMDSEntity_Quadrangle; break; + case 6: entity = SMDSEntity_Quad_Triangle; break; + case 8: entity = SMDSEntity_Quad_Quadrangle; break; + case 7: entity = SMDSEntity_BiQuad_Triangle; break; + case 9: entity = SMDSEntity_BiQuad_Quadrangle; break; + default: throw SALOME_Exception("wrong face nodes"); + } + SMDS_MeshCell::init( entity, vtkNodeIds ); + } + + friend class SMDS_Mesh; + + public: + + virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Face; } + + static SMDSAbs_ElementType Type() { return SMDSAbs_Face; } }; #endif diff --git a/src/SMDS/SMDS_MeshGroup.cxx b/src/SMDS/SMDS_MeshGroup.cxx index 4040a3e1d..80e7c6080 100644 --- a/src/SMDS/SMDS_MeshGroup.cxx +++ b/src/SMDS/SMDS_MeshGroup.cxx @@ -30,89 +30,33 @@ #endif #include "SMDS_MeshGroup.hxx" -#include "utilities.h" -using namespace std; +#include "SMDS_SetIterator.hxx" +#include "ObjectPool.hxx" -//======================================================================= -//function : SMDS_MeshGroup -//purpose : -//======================================================================= +#include -SMDS_MeshGroup::SMDS_MeshGroup(const SMDS_Mesh * theMesh, - const SMDSAbs_ElementType theType) - :myMesh(theMesh),myType(theType), myParent(NULL), myTic(0) -{ -} +#include //======================================================================= //function : SMDS_MeshGroup -//purpose : +//purpose : //======================================================================= -SMDS_MeshGroup::SMDS_MeshGroup(SMDS_MeshGroup * theParent, +SMDS_MeshGroup::SMDS_MeshGroup(const SMDS_Mesh * theMesh, const SMDSAbs_ElementType theType) - :myMesh(theParent->myMesh),myType(theType), myParent(theParent) + : SMDS_ElementHolder( theMesh ), myType(theType), myTic(0) { } -//======================================================================= -//function : AddSubGroup -//purpose : -//======================================================================= - -const SMDS_MeshGroup *SMDS_MeshGroup::AddSubGroup - (const SMDSAbs_ElementType theType) -{ - const SMDS_MeshGroup * subgroup = new SMDS_MeshGroup(this,theType); - myChildren.insert(myChildren.end(),subgroup); - return subgroup; -} - -//======================================================================= -//function : RemoveSubGroup -//purpose : -//======================================================================= - -bool SMDS_MeshGroup::RemoveSubGroup(const SMDS_MeshGroup * theGroup) -{ - bool found = false; - list::iterator itgroup; - for(itgroup=myChildren.begin(); itgroup!=myChildren.end(); itgroup++) - { - const SMDS_MeshGroup* subgroup=*itgroup; - if (subgroup == theGroup) - { - found = true; - myChildren.erase(itgroup); - } - } - - return found; -} - -//======================================================================= -//function : RemoveFromParent -//purpose : -//======================================================================= - -bool SMDS_MeshGroup::RemoveFromParent() -{ - - if (myParent==NULL) return false; - else - { - return (myParent->RemoveSubGroup(this)); - } -} //======================================================================= //function : Clear -//purpose : +//purpose : //======================================================================= void SMDS_MeshGroup::Clear() { - myElements.clear(); + clearVector( myElements ); myType = SMDSAbs_All; ++myTic; } @@ -132,8 +76,8 @@ bool SMDS_MeshGroup::Add(const SMDS_MeshElement * theElem) MESSAGE("SMDS_MeshGroup::Add : Type Mismatch "<GetType()<<"!="<::iterator found = myElements.find(theElem); + TElementSet::iterator found = myElements.find(theElem); if ( found != myElements.end() ) { myElements.erase(found); if (myElements.empty()) myType = SMDSAbs_All; @@ -176,3 +120,38 @@ void SMDS_MeshGroup::SetType(const SMDSAbs_ElementType theType) if (IsEmpty()) myType = theType; } + +//======================================================================= +//function : GetElements +//purpose : +//======================================================================= + +SMDS_ElemIteratorPtr SMDS_MeshGroup::GetElements() const +{ + typedef SMDS_SetIterator< const SMDS_MeshElement*, TIterator > TSetIterator; + return boost::make_shared< TSetIterator >( myElements.begin(), myElements.end() ); +} + +//======================================================================= +//function : Move contents of another group +//purpose : +//======================================================================= + +void SMDS_MeshGroup::operator=( SMDS_MeshGroup && other ) +{ + myMesh = other.myMesh; + myType = other.myType; + myElements = std::move( other.myElements ); + ++myTic; +} + +//======================================================================= +//function : tmpClear +//purpose : temporary remove its elements before mesh compacting +//======================================================================= + +void SMDS_MeshGroup::tmpClear() +{ + compact(); + myElements.clear(); +} diff --git a/src/SMDS/SMDS_MeshGroup.hxx b/src/SMDS/SMDS_MeshGroup.hxx index 7ba1375ad..b605737bf 100644 --- a/src/SMDS/SMDS_MeshGroup.hxx +++ b/src/SMDS/SMDS_MeshGroup.hxx @@ -29,65 +29,49 @@ #include "SMESH_SMDS.hxx" +#include "SMDS_ElementHolder.hxx" #include "SMDS_Mesh.hxx" #include -class SMDS_EXPORT SMDS_MeshGroup:public SMDS_MeshObject -{ - public: - SMDS_MeshGroup(const SMDS_Mesh * theMesh, - const SMDSAbs_ElementType theType = SMDSAbs_All); - const SMDS_MeshGroup * AddSubGroup - (const SMDSAbs_ElementType theType = SMDSAbs_All); - virtual bool RemoveSubGroup(const SMDS_MeshGroup* theGroup); - virtual bool RemoveFromParent(); - - const SMDS_Mesh* GetMesh() const { return myMesh; } - - void SetType (const SMDSAbs_ElementType theType); - void Clear(); - bool Add(const SMDS_MeshElement * theElem); - bool Remove(const SMDS_MeshElement * theElem); - bool IsEmpty() const { return myElements.empty(); } - int Extent() const { return myElements.size(); } - int Tic() const { return myTic; } - - int SubGroupsNb() const { return myChildren.size(); } - - SMDSAbs_ElementType GetType() const { return myType; } - - bool Contains(const SMDS_MeshElement * theElem) const; - - void InitIterator() const - { const_cast(myIterator) = myElements.begin(); } - - bool More() const { return myIterator != myElements.end(); } +#include - const SMDS_MeshElement* Next() const - { return *(const_cast(myIterator))++; } - - void InitSubGroupsIterator() const - { const_cast(myGroupIterator) = myChildren.begin(); } - - bool MoreSubGroups() const { return myGroupIterator != myChildren.end(); } - - const SMDS_MeshGroup* NextSubGroup() const - { return *(const_cast(myGroupIterator))++; } - - private: - SMDS_MeshGroup(SMDS_MeshGroup* theParent, - const SMDSAbs_ElementType theType = SMDSAbs_All); - - typedef std::set::const_iterator TIterator; - typedef std::list::const_iterator TGroupIterator; - - const SMDS_Mesh * myMesh; - SMDSAbs_ElementType myType; - std::set myElements; /* - not sorted by ID because it */ - SMDS_MeshGroup * myParent; /* can contain deleted elements */ - std::list myChildren; - TIterator myIterator; - TGroupIterator myGroupIterator; - int myTic; // to track changes +class SMDS_EXPORT SMDS_MeshGroup: public SMDS_MeshObject, SMDS_ElementHolder +{ + public: + SMDS_MeshGroup(const SMDS_Mesh * theMesh, + const SMDSAbs_ElementType theType = SMDSAbs_All); + + void SetType (const SMDSAbs_ElementType theType); + void Clear(); + void Reserve(size_t nbElems) { myElements.reserve( nbElems ); } + bool Add(const SMDS_MeshElement * theElem); + bool Remove(const SMDS_MeshElement * theElem); + bool IsEmpty() const { return myElements.empty(); } + int Extent() const { return myElements.size(); } + int Tic() const { return myTic; } + bool Contains(const SMDS_MeshElement * theElem) const; + + const SMDS_Mesh* GetMesh() const { return myMesh; } + SMDSAbs_ElementType GetType() const { return myType; } + SMDS_ElemIteratorPtr GetElements() const; // WARNING: iterator becomes invalid if group changes + + void operator=( SMDS_MeshGroup && other ); + + protected: // methods of SMDS_ElementHolder + + virtual SMDS_ElemIteratorPtr getElements() { return GetElements(); } + virtual void tmpClear(); + virtual void add( const SMDS_MeshElement* element ) { Add( element ); } + virtual void compact() { myElements.shrink_to_fit(); } + + private: + + typedef boost::container::flat_set< const SMDS_MeshElement* > TElementSet; + typedef TElementSet::const_iterator TIterator; + + const SMDS_Mesh * myMesh; + SMDSAbs_ElementType myType; + TElementSet myElements; // not sorted by ID because it can contain deleted elements + int myTic; // to track changes }; #endif diff --git a/src/SMDS/SMDS_MeshIDFactory.cxx b/src/SMDS/SMDS_MeshIDFactory.cxx deleted file mode 100644 index ea74aa576..000000000 --- a/src/SMDS/SMDS_MeshIDFactory.cxx +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_MeshIDFactory.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#include "SMDS_MeshIDFactory.hxx" -#include "SMDS_Mesh.hxx" -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : SMDS_MeshIDFactory -//purpose : -//======================================================================= - -SMDS_MeshIDFactory::SMDS_MeshIDFactory():myMaxID(0), myMesh(0) -{ -} - -int SMDS_MeshIDFactory::GetFreeID() -{ - int newid; - if (myPoolOfID.empty()) - { - newid = ++myMaxID; - } - else - { - set::iterator i = myPoolOfID.begin(); - newid = *i; - myPoolOfID.erase( i ); - } - return newid; -} - -//======================================================================= -//function : ReleaseID -//purpose : -//======================================================================= -void SMDS_MeshIDFactory::ReleaseID(int ID, int vtkId) -{ - if ( ID > 0 ) - { - if ( ID < myMaxID ) - { - myPoolOfID.insert(ID); - } - else if ( ID == myMaxID ) - { - --myMaxID; - if ( !myPoolOfID.empty() ) // assure that myMaxID is not in myPoolOfID - { - set::iterator i = --myPoolOfID.end(); - while ( i != myPoolOfID.begin() && myMaxID == *i ) { - --myMaxID; --i; - } - if ( myMaxID == *i ) { - --myMaxID; // begin of myPoolOfID reached - myPoolOfID.clear(); - } - else if ( myMaxID < ID-1 ) { - myPoolOfID.erase( ++i, myPoolOfID.end() ); - } - } - } - } -} - -void SMDS_MeshIDFactory::Clear() -{ - myMaxID = 0; - myPoolOfID.clear(); -} - -void SMDS_MeshIDFactory::SetMesh(SMDS_Mesh *mesh) -{ - myMesh = mesh; -} - -SMDS_Mesh* SMDS_MeshIDFactory::GetMesh() -{ - return myMesh; -} - -void SMDS_MeshIDFactory::emptyPool(int maxId) -{ - myMaxID = maxId; - myPoolOfID.clear(); -} - diff --git a/src/SMDS/SMDS_MeshIDFactory.hxx b/src/SMDS/SMDS_MeshIDFactory.hxx deleted file mode 100644 index 35be69bd9..000000000 --- a/src/SMDS/SMDS_MeshIDFactory.hxx +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_MeshIDFactory.hxx -// Module : SMESH -// -#ifndef _SMDS_MeshIDFactory_HeaderFile -#define _SMDS_MeshIDFactory_HeaderFile - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshObject.hxx" -#include - -class SMDS_Mesh; - -class SMDS_EXPORT SMDS_MeshIDFactory:public SMDS_MeshObject -{ -public: - int GetFreeID(); - virtual void ReleaseID(int ID, int vtkId = -1); - virtual void Clear(); - - void SetMesh(SMDS_Mesh *mesh); - SMDS_Mesh* GetMesh(); - inline bool isPoolIdEmpty() { return myPoolOfID.empty(); }; - virtual void emptyPool(int maxId); - inline void adjustMaxId(int ID) { if (ID > myMaxID) myMaxID = ID;}; -protected: - SMDS_MeshIDFactory(); - int myMaxID; - std::set myPoolOfID; - SMDS_Mesh *myMesh; -}; - -#endif diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index 554f0fa71..542798277 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -27,55 +27,25 @@ #endif #include "SMDS_MeshNode.hxx" -#include "SMDS_SpacePosition.hxx" -#include "SMDS_IteratorOfElements.hxx" + +#include "SMDS_ElementFactory.hxx" #include "SMDS_Mesh.hxx" -#include +#include "SMDS_SetIterator.hxx" +#include "SMDS_SpacePosition.hxx" -#include "utilities.h" -#include "Utils_SALOME_Exception.hxx" +#include +#include #include -using namespace std; - -int SMDS_MeshNode::nbNodes =0; - -//======================================================================= -//function : SMDS_MeshNode -//purpose : -//======================================================================= -SMDS_MeshNode::SMDS_MeshNode() : - SMDS_MeshElement(-1, -1, 0), - myPosition(SMDS_SpacePosition::originSpacePosition()) -{ - nbNodes++; -} - -SMDS_MeshNode::SMDS_MeshNode(int id, int meshId, int shapeId, double x, double y, double z): - SMDS_MeshElement(id, meshId, shapeId), - myPosition(SMDS_SpacePosition::originSpacePosition()) -{ - nbNodes++; - init(id, meshId, shapeId, x, y ,z); -} +#include -void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, double z) +void SMDS_MeshNode::init(double x, double y, double z) { - SMDS_MeshElement::init(id, meshId, shapeId); - myVtkID = id - 1; - assert(myVtkID >= 0); - SMDS_UnstructuredGrid * grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + SMDS_UnstructuredGrid * grid = getGrid(); vtkPoints *points = grid->GetPoints(); - points->InsertPoint(myVtkID, x, y, z); + points->InsertPoint( GetVtkID(), x, y, z ); if ( grid->HasLinks() ) - grid->GetLinks()->ResizeForPoint( myVtkID ); -} - -SMDS_MeshNode::~SMDS_MeshNode() -{ - nbNodes--; - if ( myPosition && myPosition != SMDS_SpacePosition::originSpacePosition() ) - delete myPosition, myPosition = 0; + grid->GetLinks()->ResizeForPoint( GetVtkID() ); } //======================================================================= @@ -85,8 +55,8 @@ SMDS_MeshNode::~SMDS_MeshNode() void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * elem) { - if ( SMDS_Mesh::_meshList[myMeshId]->getGrid()->HasLinks() ) - SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myVtkID, elem->getVtkId()); + if ( getGrid()->HasLinks() ) + getGrid()->RemoveReferenceToCell( GetVtkID(), elem->GetVtkID()); } //======================================================================= @@ -96,7 +66,7 @@ void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * elem) void SMDS_MeshNode::Print(ostream & OS) const { - OS << "Node <" << myID << "> : X = " << X() << " Y = " + OS << "Node <" << GetID() << "> : X = " << X() << " Y = " << Y() << " Z = " << Z() << endl; } @@ -105,23 +75,20 @@ void SMDS_MeshNode::Print(ostream & OS) const //purpose : //======================================================================= -void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos) +void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos, int shapeID) { - if ( myPosition && - myPosition != SMDS_SpacePosition::originSpacePosition() && - myPosition != aPos ) - delete myPosition; - myPosition = aPos; + myHolder->SetPosition( this, aPos, shapeID ); } //======================================================================= //function : GetPosition -//purpose : +//purpose : Return a position of this node on shape +//warning : result is std::unique_ptr ! //======================================================================= -const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const +SMDS_PositionPtr SMDS_MeshNode::GetPosition() const { - return myPosition; + return myHolder->GetPosition( this ); } //======================================================================= @@ -130,94 +97,120 @@ const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const */ //======================================================================= -class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator +namespace { -private: - SMDS_Mesh* myMesh; - vtkIdType* myCells; - int myNcells; - SMDSAbs_ElementType myType; - int iter; - vector cellList; - -public: - SMDS_MeshNode_MyInvIterator(SMDS_Mesh *mesh, vtkIdType* cells, int ncells, SMDSAbs_ElementType type) : - myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0) + struct InverseIterator: public SMDS_ElemIterator { - if ( ncells ) + const SMDS_Mesh* myMesh; + size_t myIter; + std::vector myCellList; + + InverseIterator(const SMDS_Mesh * mesh = 0, + const vtkIdType* cells = 0, + const int ncells = 0, + SMDSAbs_ElementType type = SMDSAbs_All) + : myMesh(mesh), myIter(0) { - cellList.reserve( ncells ); - if (type == SMDSAbs_All) - { - cellList.assign( cells, cells + ncells ); - } - else + if ( ncells ) { - for (int i = 0; i < ncells; i++) + myCellList.reserve( ncells ); + if (type == SMDSAbs_All) + { + myCellList.assign( cells, cells + ncells ); + } + else { - int vtkId = cells[i]; - int smdsId = myMesh->fromVtkToSmds(vtkId); - const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); - if (elem->GetType() == type) + for (int i = 0; i < ncells; i++) { - cellList.push_back(vtkId); + int vtkId = cells[i]; + int smdsId = myMesh->FromVtkToSmds( vtkId ); + const SMDS_MeshElement* elem = myMesh->FindElement( smdsId ); + if ( elem->GetType() == type ) + { + myCellList.push_back(vtkId); + } } } } - myCells = cellList.empty() ? 0 : &cellList[0]; - myNcells = cellList.size(); } - } - bool more() - { - return (iter < myNcells); - } + bool more() + { + return ( myIter < myCellList.size() ); + } + + const SMDS_MeshElement* next() + { + int vtkId = myCellList[ myIter++ ]; + int smdsId = myMesh->FromVtkToSmds( vtkId ); + const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); + if (!elem) + { + MESSAGE("InverseIterator problem Null element"); + throw SALOME_Exception("InverseIterator problem Null element"); + } + return elem; + } + }; + + //======================================================================= + /*! + * \brief Iterator on a node + */ + //======================================================================= - const SMDS_MeshElement* next() + template< class ELEM_ITERATOR > + struct Iterator : public ELEM_ITERATOR { - int vtkId = myCells[iter]; - int smdsId = myMesh->fromVtkToSmds(vtkId); - const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); - if (!elem) + typedef typename ELEM_ITERATOR::value_type element_type; + const SMDS_MeshNode* myNode; + + Iterator( const SMDS_MeshNode* n ): myNode( n ) {} + + virtual bool more() { - MESSAGE("SMDS_MeshNode_MyInvIterator problem Null element"); - throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element"); + return myNode; } - iter++; - return elem; - } -}; + virtual element_type next() + { + element_type res = static_cast( myNode ); + myNode = 0; + return res; + } + }; +} SMDS_ElemIteratorPtr SMDS_MeshNode::GetInverseElementIterator(SMDSAbs_ElementType type) const { - if ( SMDS_Mesh::_meshList[myMeshId]->NbElements() > 0 ) // avoid building links + if ( GetMesh()->NbElements() > 0 ) // avoid building links { - vtkCellLinks::Link& l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetLinks()->GetLink(myVtkID); - return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], l.cells, l.ncells, type)); + vtkCellLinks::Link& l = getGrid()->GetLinks()->GetLink( GetVtkID() ); + return boost::make_shared< InverseIterator >( GetMesh(), l.cells, l.ncells, type ); } else { - return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], 0, 0, type)); + return boost::make_shared< InverseIterator >(); } } -SMDS_ElemIteratorPtr SMDS_MeshNode::elementsIterator(SMDSAbs_ElementType type) const +SMDS_ElemIteratorPtr SMDS_MeshNode::nodesIterator() const { - if ( type == SMDSAbs_Node ) - return SMDS_MeshElement::elementsIterator( SMDSAbs_Node ); - else - return GetInverseElementIterator( type ); + return boost::make_shared< Iterator< SMDS_ElemIterator > >( this ); +} + +SMDS_NodeIteratorPtr SMDS_MeshNode::nodeIterator() const +{ + return boost::make_shared< Iterator< SMDS_NodeIterator > >( this ); } -int SMDS_MeshNode::NbNodes() const +const SMDS_MeshNode* SMDS_MeshNode::GetNode(const int ind) const { - return 1; + return ind == 0 ? this : 0; } double* SMDS_MeshNode::getCoord() const { - return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID); + return getGrid()->GetPoint( GetVtkID() ); } double SMDS_MeshNode::X() const @@ -246,41 +239,30 @@ double SMDS_MeshNode::Z() const void SMDS_MeshNode::GetXYZ(double xyz[3]) const { - return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID,xyz); + return getGrid()->GetPoint( GetVtkID(), xyz ); } //================================================================================ -void SMDS_MeshNode::setXYZ(double x, double y, double z) -{ - SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId]; - vtkPoints *points = mesh->getGrid()->GetPoints(); - points->InsertPoint(myVtkID, x, y, z); - mesh->adjustBoundingBox(x, y, z); - mesh->setMyModified(); -} - -SMDSAbs_ElementType SMDS_MeshNode::GetType() const -{ - return SMDSAbs_Node; -} - -vtkIdType SMDS_MeshNode::GetVtkType() const +void SMDS_MeshNode::setXYZ( double x, double y, double z ) { - return VTK_VERTEX; + vtkPoints *points = getGrid()->GetPoints(); + points->InsertPoint( GetVtkID(), x, y, z ); + //GetMesh()->adjustBoundingBox(x, y, z); + GetMesh()->setMyModified(); } //======================================================================= //function : AddInverseElement //purpose : //======================================================================= -void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) +void SMDS_MeshNode::AddInverseElement( const SMDS_MeshElement* elem ) { - SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + SMDS_UnstructuredGrid* grid = getGrid(); if ( grid->HasLinks() ) { vtkCellLinks *Links = grid->GetLinks(); - Links->ResizeCellList(myVtkID, 1); - Links->AddCellReference(ME->getVtkId(), myVtkID); + Links->ResizeCellList( GetVtkID(), 1 ); + Links->AddCellReference( elem->GetVtkID(), GetVtkID() ); } } @@ -290,7 +272,7 @@ void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) //======================================================================= void SMDS_MeshNode::ClearInverseElements() { - SMDS_Mesh::_meshList[myMeshId]->getGrid()->ResizeCellList(myVtkID, 0); + getGrid()->ResizeCellList( GetVtkID(), 0); } //================================================================================ @@ -302,17 +284,17 @@ void SMDS_MeshNode::ClearInverseElements() int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const { int nb = 0; - if ( SMDS_Mesh::_meshList[myMeshId]->NbElements() > 0 ) // avoid building links + SMDS_Mesh *mesh = GetMesh(); + if ( mesh->NbElements() > 0 ) // avoid building links { - vtkCellLinks::Link& l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetLinks()->GetLink(myVtkID); + vtkCellLinks::Link& l = mesh->GetGrid()->GetLinks()->GetLink( GetVtkID() ); if ( type == SMDSAbs_All ) return l.ncells; - SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId]; for ( int i = 0; i < l.ncells; i++ ) { - const SMDS_MeshElement* elem = mesh->FindElement( mesh->fromVtkToSmds( l.cells[i] )); + const SMDS_MeshElement* elem = mesh->FindElement( mesh->FromVtkToSmds( l.cells[i] )); nb += ( elem->GetType() == type ); } } diff --git a/src/SMDS/SMDS_MeshNode.hxx b/src/SMDS/SMDS_MeshNode.hxx index 2c8bad7be..b156b911c 100644 --- a/src/SMDS/SMDS_MeshNode.hxx +++ b/src/SMDS/SMDS_MeshNode.hxx @@ -31,50 +31,53 @@ #include "SMDS_MeshElement.hxx" #include "SMDS_Position.hxx" -#include "ObjectPool.hxx" class SMDS_EXPORT SMDS_MeshNode: public SMDS_MeshElement { -public: - friend class SMESHDS_Mesh; - friend class SMDS_Mesh; - friend class ObjectPool; - friend class SMDS_VtkFace; + public: - void Print(std::ostream & OS) const; + void setXYZ(double x, double y, double z); double X() const; // ! NOT thread safe methods ! double Y() const; double Z() const; void GetXYZ(double xyz[3]) const; // thread safe getting coords + SMDS_ElemIteratorPtr GetInverseElementIterator(SMDSAbs_ElementType type=SMDSAbs_All) const; int NbInverseElements(SMDSAbs_ElementType type=SMDSAbs_All) const; - const SMDS_PositionPtr& GetPosition() const; - virtual SMDSAbs_ElementType GetType() const; - virtual vtkIdType GetVtkType() const; + + SMDS_PositionPtr GetPosition() const; // WARNING result is std::unique_ptr ! + void SetPosition(const SMDS_PositionPtr& aPos, int shapeID = 0 ); + + virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Node; } + virtual VTKCellType GetVtkType() const { return VTK_VERTEX; } virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Node;} virtual SMDSAbs_GeometryType GetGeomType() const { return SMDSGeom_NONE; } - virtual int NbNodes() const; + virtual int NbNodes() const { return 1; } + virtual int NbEdges() const { return 0; } + virtual int NbFaces() const { return 0; } - void SetPosition(const SMDS_PositionPtr& aPos); - void setXYZ(double x, double y, double z); + virtual SMDS_ElemIteratorPtr nodesIterator() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; + virtual const SMDS_MeshNode* GetNode(const int ind) const; + + virtual bool IsPoly() const { return false; } + virtual bool IsQuadratic() const { return false; } + virtual bool IsMediumNode(const SMDS_MeshNode* node) const { return false; } + virtual int NbCornerNodes() const { return 1; } + + void Print(std::ostream & OS) const; + + private: - static int nbNodes; + void init(double x=0, double y=0, double z=0); -protected: - SMDS_MeshNode(); - SMDS_MeshNode(int id, int meshId, int shapeId = -1, double x=0, double y=0, double z=0); - virtual ~SMDS_MeshNode(); - void init(int id, int meshId, int shapeId = -1, double x=0, double y=0, double z=0); double* getCoord() const; - void AddInverseElement(const SMDS_MeshElement * ME); - void RemoveInverseElement(const SMDS_MeshElement * parent); + void AddInverseElement (const SMDS_MeshElement * elem); + void RemoveInverseElement(const SMDS_MeshElement * elem); void ClearInverseElements(); - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; + friend class SMDS_Mesh; -private: - SMDS_PositionPtr myPosition; }; #endif diff --git a/src/SMDS/SMDS_MeshNodeIDFactory.cxx b/src/SMDS/SMDS_MeshNodeIDFactory.cxx deleted file mode 100644 index 64b7baed1..000000000 --- a/src/SMDS/SMDS_MeshNodeIDFactory.cxx +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 : SMDS_MeshNodeIDFactory.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include "SMDS_MeshNodeIDFactory.hxx" -#include "SMDS_MeshElement.hxx" -#include "SMDS_Mesh.hxx" - -#include -#include - -using namespace std; - -//======================================================================= -//function : SMDS_MeshNodeIDFactory -//purpose : -//======================================================================= -SMDS_MeshNodeIDFactory::SMDS_MeshNodeIDFactory() : - SMDS_MeshIDFactory(), myMin(0), myMax(0) -{ -} - -//======================================================================= -//function : BindID -//purpose : -//======================================================================= -bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem) -{ - updateMinMax(ID); - return true; -} - -//======================================================================= -//function : MeshElement -//purpose : -//======================================================================= -SMDS_MeshElement* SMDS_MeshNodeIDFactory::MeshElement(int ID) -{ - // commented since myMax can be 0 after ReleaseID() -// if ((ID < 1) || (ID > myMax)) -// return NULL; - const SMDS_MeshElement* elem = GetMesh()->FindNode(ID); - return (SMDS_MeshElement*) (elem); -} - -//======================================================================= -//function : GetFreeID -//purpose : -//======================================================================= -int SMDS_MeshNodeIDFactory::GetFreeID() -{ - int ID; - do { - ID = SMDS_MeshIDFactory::GetFreeID(); - } while ( MeshElement( ID )); - return ID; -} - -//======================================================================= -//function : ReleaseID -//purpose : -//======================================================================= -void SMDS_MeshNodeIDFactory::ReleaseID(const int ID, int vtkId) -{ - SMDS_MeshIDFactory::ReleaseID(ID); - myMesh->setMyModified(); - if (ID == myMax) - myMax = 0; // --- force updateMinMax - if (ID == myMin) - myMax = 0; // --- force updateMinMax -} - -//======================================================================= -//function : GetMaxID -//purpose : -//======================================================================= - -int SMDS_MeshNodeIDFactory::GetMaxID() const -{ - if (myMax == 0) - updateMinMax(); - return myMax; -} - -//======================================================================= -//function : GetMinID -//purpose : -//======================================================================= - -int SMDS_MeshNodeIDFactory::GetMinID() const -{ - if (myMax == 0) - updateMinMax(); - return myMin; -} - -//======================================================================= -//function : updateMinMax -//purpose : -//======================================================================= - -void SMDS_MeshNodeIDFactory::updateMinMax() const -{ - myMin = INT_MAX; - myMax = 0; - for (size_t i = 0; i < myMesh->myNodes.size(); i++) - { - if (myMesh->myNodes[i]) - { - int id = myMesh->myNodes[i]->GetID(); - if (id > myMax) - myMax = id; - if (id < myMin) - myMin = id; - } - } - if (myMin == INT_MAX) - myMin = 0; -} - -SMDS_ElemIteratorPtr SMDS_MeshNodeIDFactory::elementsIterator() const -{ - return myMesh->elementsIterator(SMDSAbs_Node); -} - -void SMDS_MeshNodeIDFactory::Clear() -{ - myMin = myMax = 0; - SMDS_MeshIDFactory::Clear(); -} - -void SMDS_MeshNodeIDFactory::emptyPool(int maxId) -{ - SMDS_MeshIDFactory::emptyPool(maxId); - myMax = maxId; -} diff --git a/src/SMDS/SMDS_MeshNodeIDFactory.hxx b/src/SMDS/SMDS_MeshNodeIDFactory.hxx deleted file mode 100644 index 80c12716b..000000000 --- a/src/SMDS/SMDS_MeshNodeIDFactory.hxx +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 : SMDS_MeshElementIDFactory.hxx -// Module : SMESH -// -#ifndef _SMDS_MeshNodeIDFactory_HeaderFile -#define _SMDS_MeshNodeIDFactory_HeaderFile - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshIDFactory.hxx" -#include "SMDS_ElemIterator.hxx" - -#include - -class SMDS_MeshElement; - -class SMDS_EXPORT SMDS_MeshNodeIDFactory: public SMDS_MeshIDFactory -{ -public: - SMDS_MeshNodeIDFactory(); - bool BindID(int ID, SMDS_MeshElement * elem); - SMDS_MeshElement * MeshElement(int ID); - virtual int GetFreeID(); - virtual void ReleaseID(int ID, int vtkId = -1); - int GetMaxID() const; - int GetMinID() const; - SMDS_ElemIteratorPtr elementsIterator() const; - virtual void Clear(); - virtual void emptyPool(int maxId); - -protected: - virtual void updateMinMax() const; - void updateMinMax(int id) const - { - if (id > myMax) - myMax = id; - if (id < myMin) - myMin = id; - } - - mutable int myMin, myMax; - -}; - -#endif diff --git a/src/SMDS/SMDS_MeshVolume.cxx b/src/SMDS/SMDS_MeshVolume.cxx index a56c119b7..755285447 100644 --- a/src/SMDS/SMDS_MeshVolume.cxx +++ b/src/SMDS/SMDS_MeshVolume.cxx @@ -25,18 +25,244 @@ // Author : Jean-Michel BOULCOURT // Module : SMESH // + #include "SMDS_MeshVolume.hxx" -//======================================================================= -//function : Print -//purpose : -//======================================================================= -SMDSAbs_ElementType SMDS_MeshVolume::GetType() const +#include "SMDS_Mesh.hxx" +#include "SMDS_VolumeTool.hxx" +#include "SMDS_VtkCellIterator.hxx" + +#include + +// init a polyherdon +void SMDS_MeshVolume::init( const std::vector& nodes, + const std::vector& nbNodesPerFace ) +{ + std::vector ptIds; + ptIds.reserve( nodes.size() + nbNodesPerFace.size() + 1 ); + + size_t nbFaces = nbNodesPerFace.size(); + for ( size_t iN = 0, iF = 0; iF < nbFaces; iF++ ) + { + int nf = nbNodesPerFace[iF]; + ptIds.push_back(nf); + for (int n = 0; n < nf; n++) + ptIds.push_back( nodes[ iN++ ]->GetVtkID() ); + } + + int vtkID = getGrid()->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]); + setVtkID( vtkID ); +} + +void SMDS_MeshVolume::init( const std::vector& vtkNodeIds ) +{ + SMDSAbs_EntityType aType = SMDSEntity_Tetra; + switch ( vtkNodeIds.size()) // cases are in order of usage frequency + { + case 4: aType = SMDSEntity_Tetra; break; + case 5: aType = SMDSEntity_Pyramid; break; + case 8: aType = SMDSEntity_Hexa; break; + case 6: aType = SMDSEntity_Penta; break; + case 10: aType = SMDSEntity_Quad_Tetra; break; + case 20: aType = SMDSEntity_Quad_Hexa; break; + case 13: aType = SMDSEntity_Quad_Pyramid; break; + case 27: aType = SMDSEntity_TriQuad_Hexa; break; + case 15: aType = SMDSEntity_Quad_Penta; break; + case 18: aType = SMDSEntity_BiQuad_Penta; break; + case 12: aType = SMDSEntity_Hexagonal_Prism; break; + default: throw SALOME_Exception("wrong volume nodes"); + } + SMDS_MeshCell::init( aType, vtkNodeIds ); +} + +const SMDS_MeshNode* SMDS_MeshVolume::GetNode(const int ind) const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::GetNode( ind ); + + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds ); + int id = 0, nbPoints = 0; + for (int i = 0; i < nFaces; i++) + { + int nodesInFace = ptIds[id]; + if ( ind < nbPoints + nodesInFace ) + return GetMesh()->FindNodeVtk( ptIds[ ind + i ]); + nbPoints += nodesInFace; + id += (nodesInFace + 1); + } + return 0; +} +int SMDS_MeshVolume::NbNodes() const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::NbNodes(); + + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds ); + int id = 0, nbPoints = 0; + for (int i = 0; i < nFaces; i++) + { + int nodesInFace = ptIds[id]; + nbPoints += nodesInFace; + id += (nodesInFace + 1); + } + return nbPoints; +} + +int SMDS_MeshVolume::NbFaces() const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::NbFaces(); + + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds ); + return nFaces; + +} +int SMDS_MeshVolume::NbEdges() const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::NbEdges(); + + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds ); + int id = 0, nbEdges = 0; + for (int i = 0; i < nFaces; i++) + { + int edgesInFace = ptIds[id]; + id += (edgesInFace + 1); + nbEdges += edgesInFace; + } + nbEdges = nbEdges / 2; + return nbEdges; +} + +int SMDS_MeshVolume::GetNodeIndex( const SMDS_MeshNode* node ) const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::GetNodeIndex( node ); + + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds ); + int id = 0; + for (int iF = 0; iF < nFaces; iF++) + { + int nodesInFace = ptIds[id]; + for ( vtkIdType i = 0; i < nodesInFace; ++i ) + if ( ptIds[id+i+1] == node->GetVtkID() ) + return id+i-iF; + id += (nodesInFace + 1); + } + return -1; +} +bool SMDS_MeshVolume::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) +{ + return false; +} + +bool SMDS_MeshVolume::IsMediumNode(const SMDS_MeshNode* node) const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::IsMediumNode( node ); + + return false; +} + +int SMDS_MeshVolume::NbCornerNodes() const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::NbCornerNodes(); + + return NbNodes(); +} + +int SMDS_MeshVolume::NbFaceNodes (const int face_ind) const { - return SMDSAbs_Volume; + if ( !IsPoly() ) + return SMDS_VolumeTool( this ).NbFaceNodes( face_ind-1 ); + + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds ); + int id = 0, nbNodes = 0; + for (int i = 0; i < nFaces; i++) + { + int nodesInFace = ptIds[id]; + id += (nodesInFace + 1); + if (i == face_ind - 1) + { + nbNodes = nodesInFace; + break; + } + } + return nbNodes; } -vtkIdType SMDS_MeshVolume::GetVtkType() const +const SMDS_MeshNode* SMDS_MeshVolume::GetFaceNode (const int face_ind, const int node_ind) const { - return VTK_CONVEX_POINT_SET; // --- must be reimplemented in derived classes + if ( !IsPoly() ) + return SMDS_VolumeTool( this ).GetFaceNodes( face_ind-1 )[ node_ind - 1 ]; + + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds); + int id = 0; + for (int i = 0; i < nFaces; i++) + { + int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace] + if (i == face_ind - 1) // first face is number 1 + { + if ((node_ind > 0) && (node_ind <= nodesInFace)) + return GetMesh()->FindNodeVtk(ptIds[id + node_ind]); // ptIds[id+1] : first node + } + id += (nodesInFace + 1); + } + return 0; +} + +std::vector SMDS_MeshVolume::GetQuantities() const +{ + std::vector quantities; + if ( IsPoly() ) + { + vtkIdType nFaces = 0; + vtkIdType* ptIds = 0; + getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds ); + int id = 0; + for (int i = 0; i < nFaces; i++) + { + int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace] + quantities.push_back( nodesInFace ); + id += (nodesInFace + 1); + } + } + return quantities; +} + +/////////////////////////////////////////////////////////////////////////////// +/// Create an iterator which iterate on nodes owned by the element. +/////////////////////////////////////////////////////////////////////////////// +SMDS_ElemIteratorPtr SMDS_MeshVolume::nodesIterator() const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::nodesIterator(); + + return boost::make_shared< SMDS_VtkCellIteratorPolyH<> >( GetMesh(), GetVtkID(), GetEntityType()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// Create an iterator which iterate on nodes owned by the element. +/////////////////////////////////////////////////////////////////////////////// +SMDS_NodeIteratorPtr SMDS_MeshVolume::nodeIterator() const +{ + if ( !IsPoly() ) + return SMDS_MeshCell::nodeIterator(); + + return boost::make_shared< SMDS_VtkCellIteratorPolyH< SMDS_NodeIterator> >( GetMesh(), GetVtkID(), GetEntityType()); } diff --git a/src/SMDS/SMDS_MeshVolume.hxx b/src/SMDS/SMDS_MeshVolume.hxx index 15887bdcd..7a69da0a6 100644 --- a/src/SMDS/SMDS_MeshVolume.hxx +++ b/src/SMDS/SMDS_MeshVolume.hxx @@ -31,11 +31,42 @@ #include "SMDS_MeshCell.hxx" -class SMDS_EXPORT SMDS_MeshVolume:public SMDS_MeshCell +/*! + * \brief Mesh volume. This type is not allocated. + * It is only used as function argument type to provide more clear semantic + * and to provide API specific to polyherdal volume + */ +class SMDS_EXPORT SMDS_MeshVolume : public SMDS_MeshCell { - - public: - SMDSAbs_ElementType GetType() const; - virtual vtkIdType GetVtkType() const; + void init( const std::vector& nodes, + const std::vector& nbNodesPerFace ); // init a polyherdon + + void init( const std::vector& vtkNodeIds ); + + friend class SMDS_Mesh; + + public: + virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Volume; } + virtual const SMDS_MeshNode* GetNode(const int ind) const; + virtual int NbNodes() const; + virtual int NbFaces() const; + virtual int NbEdges() const; + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; + virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); + virtual bool IsMediumNode(const SMDS_MeshNode* node) const; + virtual int NbCornerNodes() const; + + virtual SMDS_ElemIteratorPtr nodesIterator() const = 0; + virtual SMDS_NodeIteratorPtr nodeIterator() const = 0; + + // 1 <= face_ind <= NbFaces() + int NbFaceNodes (const int face_ind) const; + // 1 <= face_ind <= NbFaces() + // 1 <= node_ind <= NbFaceNodes() + const SMDS_MeshNode* GetFaceNode (const int face_ind, const int node_ind) const; + + std::vector GetQuantities() const; + + static SMDSAbs_ElementType Type() { return SMDSAbs_Volume; } }; #endif diff --git a/src/SMDS/SMDS_PolygonalFaceOfNodes.cxx b/src/SMDS/SMDS_PolygonalFaceOfNodes.cxx index 54ead2af0..2ddc79d87 100644 --- a/src/SMDS/SMDS_PolygonalFaceOfNodes.cxx +++ b/src/SMDS/SMDS_PolygonalFaceOfNodes.cxx @@ -28,22 +28,20 @@ #include "SMDS_PolygonalFaceOfNodes.hxx" -#include "SMDS_IteratorOfElements.hxx" #include "SMDS_SetIterator.hxx" #include "SMDS_Mesh.hxx" -#include "utilities.h" +#include -using namespace std; +#include //======================================================================= //function : Constructor //purpose : //======================================================================= -SMDS_PolygonalFaceOfNodes::SMDS_PolygonalFaceOfNodes - (const std::vector& nodes) +SMDS_PolygonalFaceOfNodes:: +SMDS_PolygonalFaceOfNodes (const std::vector& nodes) { - //MESSAGE("******************************************** SMDS_PolygonalFaceOfNodes"); myNodes = nodes; } @@ -54,41 +52,40 @@ SMDS_PolygonalFaceOfNodes::SMDS_PolygonalFaceOfNodes SMDSAbs_ElementType SMDS_PolygonalFaceOfNodes::GetType() const { return SMDSAbs_Face; - //return SMDSAbs_PolygonalFace; } //======================================================================= //function : ChangeNodes //purpose : //======================================================================= -bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector nodes) -{ - if (nodes.size() < 3) - return false; +// bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector nodes) +// { +// if (nodes.size() < 3) +// return false; - myNodes = nodes; +// myNodes = nodes; - return true; -} +// return true; +// } //======================================================================= //function : ChangeNodes //purpose : to support the same interface, as SMDS_FaceOfNodes //======================================================================= -bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[], - const int nbNodes) -{ - if (nbNodes < 3) - return false; +// bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[], +// const int nbNodes) +// { +// if (nbNodes < 3) +// return false; - myNodes.resize(nbNodes); - int i = 0; - for (; i < nbNodes; i++) { - myNodes[i] = nodes[i]; - } +// myNodes.resize(nbNodes); +// int i = 0; +// for (; i < nbNodes; i++) { +// myNodes[i] = nodes[i]; +// } - return true; -} +// return true; +// } //======================================================================= //function : NbNodes @@ -130,65 +127,12 @@ void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const OS << myNodes[i] << ") " << endl; } -//======================================================================= -//function : elementsIterator -//purpose : -//======================================================================= -class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_NodeVectorElemIterator -{ - public: - SMDS_PolygonalFaceOfNodes_MyIterator(const vector& s): - SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {} -}; - /// =================================================================== /*! * \brief Iterator on edges of face */ /// =================================================================== -class _MyEdgeIterator : public SMDS_ElemIterator -{ - vector< const SMDS_MeshElement* > myElems; - size_t myIndex; -public: - _MyEdgeIterator(const SMDS_MeshFace* face):myIndex(0) { - myElems.reserve( face->NbNodes() ); - for ( int i = 0; i < face->NbNodes(); ++i ) { - const SMDS_MeshElement* edge = - SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNodeWrap( i + 1 )); - if ( edge ) - myElems.push_back( edge ); - } - } - /// Return true if and only if there are other object in this iterator - virtual bool more() { return myIndex < myElems.size(); } - - /// Return the current object and step to the next one - virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; } -}; - -SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator - (SMDSAbs_ElementType type) const -{ - switch(type) - { - case SMDSAbs_Face: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Face); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes)); - case SMDSAbs_Edge: - return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this )); - break; - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements - (this,type,SMDS_ElemIteratorPtr - (new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes)))); - } - return SMDS_ElemIteratorPtr(); -} - /*! * \brief Return node by its index * \param ind - node index @@ -198,3 +142,13 @@ const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const { return myNodes[ WrappedIndex( ind )]; } + +SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::nodesIterator() const +{ + return boost::make_shared< SMDS_NodeArrayElemIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); +} + +SMDS_NodeIteratorPtr SMDS_PolygonalFaceOfNodes::nodeIterator() const +{ + return boost::make_shared< SMDS_NodeArrayIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); +} diff --git a/src/SMDS/SMDS_PolygonalFaceOfNodes.hxx b/src/SMDS/SMDS_PolygonalFaceOfNodes.hxx index 33dd39d0f..f06352ede 100644 --- a/src/SMDS/SMDS_PolygonalFaceOfNodes.hxx +++ b/src/SMDS/SMDS_PolygonalFaceOfNodes.hxx @@ -27,15 +27,9 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshFace.hxx" -//#include "SMDS_FaceOfNodes.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_Iterator.hxx" +#include "SMDS_CellOfNodes.hxx" -#include - -//class SMDS_PolygonalFaceOfNodes:public SMDS_FaceOfNodes -class SMDS_EXPORT SMDS_PolygonalFaceOfNodes:public SMDS_MeshFace +class SMDS_EXPORT SMDS_PolygonalFaceOfNodes : public SMDS_CellOfNodes { public: SMDS_PolygonalFaceOfNodes (const std::vector& nodes); @@ -43,13 +37,10 @@ class SMDS_EXPORT SMDS_PolygonalFaceOfNodes:public SMDS_MeshFace virtual SMDSAbs_ElementType GetType() const; virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Polygon; } virtual SMDSAbs_GeometryType GetGeomType() const { return SMDSGeom_POLYGON; } - virtual bool IsPoly() const { return true; }; - - bool ChangeNodes (std::vector nodes); - - bool ChangeNodes (const SMDS_MeshNode* nodes[], - const int nbNodes); - // to support the same interface, as SMDS_FaceOfNodes + virtual bool IsPoly() const { return true; } + virtual bool IsQuadratic() const { return false; } + virtual bool IsMediumNode(const SMDS_MeshNode* node) const { return false; } + virtual int NbCornerNodes() const { return NbNodes(); } virtual int NbNodes() const; virtual int NbEdges() const; @@ -57,15 +48,12 @@ class SMDS_EXPORT SMDS_PolygonalFaceOfNodes:public SMDS_MeshFace virtual void Print (std::ostream & OS) const; - /*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ virtual const SMDS_MeshNode* GetNode(const int ind) const; + virtual SMDS_ElemIteratorPtr nodesIterator() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; + protected: - virtual SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const; std::vector myNodes; }; diff --git a/src/SMDS/SMDS_PolyhedralVolumeOfNodes.cxx b/src/SMDS/SMDS_PolyhedralVolumeOfNodes.cxx deleted file mode 100644 index 20c948ba1..000000000 --- a/src/SMDS/SMDS_PolyhedralVolumeOfNodes.cxx +++ /dev/null @@ -1,265 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include "SMDS_PolyhedralVolumeOfNodes.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_SetIterator.hxx" -#include "SMDS_VolumeTool.hxx" -#include "utilities.h" - -#include - -using namespace std; - -//======================================================================= -//function : Constructor -//purpose : Create a volume of many faces -//======================================================================= -SMDS_PolyhedralVolumeOfNodes::SMDS_PolyhedralVolumeOfNodes - (vector nodes, - vector quantities) -: SMDS_VolumeOfNodes(NULL, NULL, NULL, NULL) -{ - //MESSAGE("****************************************** SMDS_PolyhedralVolumeOfNodes"); - ChangeNodes(nodes, quantities); -} - -//======================================================================= -//function : GetType -//purpose : -//======================================================================= -SMDSAbs_ElementType SMDS_PolyhedralVolumeOfNodes::GetType() const -{ -// return SMDSAbs_PolyhedralVolume; - return SMDSAbs_Volume; -} - -//======================================================================= -//function : ChangeNodes -//purpose : -//======================================================================= -bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const vector& nodes, - const vector& quantities) -{ - myNodesByFaces = nodes; - myQuantities = quantities; - - // Init fields of parent class, it allows to get only unique nodes(?) - - set aSet; - aSet.insert( nodes.begin(), nodes.end()); - //SMDS_VolumeOfNodes::ChangeNodes(aNodes, aNbNodes); - delete [] myNodes; - myNbNodes = aSet.size(); - myNodes = new const SMDS_MeshNode* [myNbNodes]; - set::iterator anIter = aSet.begin(); - for (int k=0; anIter != aSet.end(); anIter++, k++) - myNodes[k] = *anIter; - - return true; -} - -//======================================================================= -//function : NbEdges -//purpose : -//======================================================================= -int SMDS_PolyhedralVolumeOfNodes::NbNodes() const -{ - return myNodesByFaces.size(); -} - -//======================================================================= -//function : NbEdges -//purpose : -//======================================================================= -int SMDS_PolyhedralVolumeOfNodes::NbEdges() const -{ - int nbEdges = 0; - - for ( size_t ifa = 0; ifa < myQuantities.size(); ifa++) { - nbEdges += myQuantities[ifa]; - } - nbEdges /= 2; - - return nbEdges; -} - -//======================================================================= -//function : NbFaces -//purpose : -//======================================================================= -int SMDS_PolyhedralVolumeOfNodes::NbFaces() const -{ - return myQuantities.size(); -} - -//======================================================================= -//function : NbFaceNodes -//purpose : -//======================================================================= -int SMDS_PolyhedralVolumeOfNodes::NbFaceNodes (const int face_ind) const -{ - if (face_ind < 1 || (int)myQuantities.size() < face_ind) - return 0; - return myQuantities[face_ind - 1]; -} - -//======================================================================= -//function : GetFaceNode -//purpose : -//======================================================================= -const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetFaceNode (const int face_ind, - const int node_ind) const -{ - if (node_ind < 1 || NbFaceNodes(face_ind) < node_ind) - return NULL; - - int i, first_node = 0; - for (i = 0; i < face_ind - 1; i++) { - first_node += myQuantities[i]; - } - - return myNodesByFaces[first_node + node_ind - 1]; -} - -//======================================================================= -//function : Print -//purpose : -//======================================================================= -void SMDS_PolyhedralVolumeOfNodes::Print (ostream & OS) const -{ - OS << "polyhedral volume <" << GetID() << "> : "; - - int faces_len = myQuantities.size(); - //int nodes_len = myNodesByFaces.size(); - int cur_first_node = 0; - - int i, j; - for (i = 0; i < faces_len; i++) { - OS << "face_" << i << " ("; - for (j = 0; j < myQuantities[i] - 1; j++) { - OS << myNodesByFaces[cur_first_node + j] << ","; - } - OS << myNodesByFaces[cur_first_node + j] << ") "; - cur_first_node += myQuantities[i]; - } -} - -//======================================================================= -//function : ChangeNodes -//purpose : usage disabled -//======================================================================= -bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[], - const int nbNodes) -{ - return false; -} - -/// =================================================================== -/*! - * \brief Iterator on node of volume - */ -/// =================================================================== - -struct _MyIterator:public SMDS_NodeVectorElemIterator -{ - _MyIterator(const vector& nodes): - SMDS_NodeVectorElemIterator( nodes.begin(), nodes.end()) {} -}; - -/// =================================================================== -/*! - * \brief Iterator on faces or edges of volume - */ -/// =================================================================== - -class _MySubIterator : public SMDS_ElemIterator -{ - vector< const SMDS_MeshElement* > myElems; - size_t myIndex; -public: - _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) { - SMDS_VolumeTool vTool(vol); - if (type == SMDSAbs_Face) - vTool.GetAllExistingFaces( myElems ); - else - vTool.GetAllExistingEdges( myElems ); - } - /// Return true if and only if there are other object in this iterator - virtual bool more() { return myIndex < myElems.size(); } - - /// Return the current object and step to the next one - virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; } -}; - -//================================================================================ -/*! - * \brief Return Iterator of sub elements - */ -//================================================================================ - -SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const -{ - switch(type) - { - case SMDSAbs_Volume: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new _MyIterator(myNodesByFaces)); - case SMDSAbs_Face: - return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face)); - case SMDSAbs_Edge: - return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge)); - default: - MESSAGE("ERROR : Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); - } -} - -//================================================================================ -/*! - * \brief Return iterator on unique nodes - */ -//================================================================================ - -SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::uniqueNodesIterator() const -{ - return SMDS_ElemIteratorPtr - (new SMDS_NodeArrayElemIterator( myNodes, & myNodes[ myNbNodes ])); -} - -//================================================================================ -/*! - * \brief Return node by its index - */ -//================================================================================ - -const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetNode(const int ind) const -{ - return myNodesByFaces[ ind ]; -} diff --git a/src/SMDS/SMDS_PolyhedralVolumeOfNodes.hxx b/src/SMDS/SMDS_PolyhedralVolumeOfNodes.hxx deleted file mode 100644 index cba8a9169..000000000 --- a/src/SMDS/SMDS_PolyhedralVolumeOfNodes.hxx +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_PolyhedralVolumeOfNodes.hxx -// Module : SMESH -// -#ifndef _SMDS_PolyhedralVolumeOfNodes_HeaderFile -#define _SMDS_PolyhedralVolumeOfNodes_HeaderFile - -#include "SMESH_SMDS.hxx" - -#include "SMDS_VolumeOfNodes.hxx" - -class SMDS_EXPORT SMDS_PolyhedralVolumeOfNodes:public SMDS_VolumeOfNodes -{ - public: - SMDS_PolyhedralVolumeOfNodes (std::vector nodes, - std::vector quantities); - - //virtual ~SMDS_PolyhedralVolumeOfNodes(); - - virtual SMDSAbs_ElementType GetType() const; - virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Polyhedra; } - virtual bool IsPoly() const { return true; }; - - bool ChangeNodes (const std::vector & nodes, - const std::vector & quantities); - - virtual int NbNodes() const; - virtual int NbEdges() const; - virtual int NbFaces() const; - - int NbFaceNodes (const int face_ind) const; - // 1 <= face_ind <= NbFaces() - - const SMDS_MeshNode* GetFaceNode (const int face_ind, const int node_ind) const; - // 1 <= face_ind <= NbFaces() - // 1 <= node_ind <= NbFaceNodes() - - const std::vector & GetQuanities() const { return myQuantities; } - - virtual void Print (std::ostream & OS) const; - - /*! - * \brief Return node by its index - */ - virtual const SMDS_MeshNode* GetNode(const int ind) const; - - /*! - * \brief Return iterator on unique nodes - */ - SMDS_ElemIteratorPtr uniqueNodesIterator() const; - /*! - * \brief Return nb of unique nodes - */ - int NbUniqueNodes() const { return myNbNodes; } - -protected: - SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - - private: - // usage disabled - bool ChangeNodes (const SMDS_MeshNode* nodes[], - const int nbNodes); - - private: - std::vector myNodesByFaces; - std::vector myQuantities; -}; - -#endif diff --git a/src/SMDS/SMDS_Position.cxx b/src/SMDS/SMDS_Position.cxx deleted file mode 100644 index e7c408f07..000000000 --- a/src/SMDS/SMDS_Position.cxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_Position.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#include "SMDS_Position.hxx" -#include "utilities.h" - -//======================================================================= -//function : SMDS_Position -//purpose : -//======================================================================= - -SMDS_Position::SMDS_Position() -{ - //MESSAGE("########################## SMDS_Position "); -} - -//======================================================================= -//function : GetDim -//purpose : -//======================================================================= - -int SMDS_Position::GetDim() const -{ -// switch ( GetTypeOfPosition() ) { -// case SMDS_TOP_UNSPEC: return -1; -// case SMDS_TOP_VERTEX: return 0; -// case SMDS_TOP_EDGE: return 1; -// case SMDS_TOP_FACE: return 2; -// case SMDS_TOP_3DSPACE: return 3; -// } - return GetTypeOfPosition(); -} - - diff --git a/src/SMDS/SMDS_Position.hxx b/src/SMDS/SMDS_Position.hxx index b6976677d..62c4042d3 100644 --- a/src/SMDS/SMDS_Position.hxx +++ b/src/SMDS/SMDS_Position.hxx @@ -30,23 +30,68 @@ #include "SMESH_SMDS.hxx" #include "SMDS_TypeOfPosition.hxx" -#include +#include -class SMDS_Position; +//class SMDS_Position; //typedef boost::shared_ptr SMDS_PositionPtr; -typedef SMDS_Position* SMDS_PositionPtr; +//typedef SMDS_Position* SMDS_PositionPtr; class SMDS_EXPORT SMDS_Position { - public: - virtual SMDS_TypeOfPosition GetTypeOfPosition() const = 0; - virtual int GetDim() const; - virtual ~SMDS_Position() {} + public: + virtual SMDS_TypeOfPosition GetTypeOfPosition() const = 0; + int GetDim() const { return GetTypeOfPosition(); } + virtual const double* GetParameters() const = 0; + virtual ~SMDS_Position() {} +}; + +/*! + * \brief Replace "typedef SMDS_Position* SMDS_PositionPtr" by a smart + * pointer allowing implicit casting to derived types; e.g. + * if ( SMDS_FacePositionPtr fPos = node->GetPosition() ) + * fPos->SetUParameter(0); + */ + +template +class SMDS_EXPORT SMDS_Ptr : public std::unique_ptr< T > +{ + bool myIsOwner; + + public: + SMDS_Ptr( T * pos = (T *) 0, bool isOwner=true ): + std::unique_ptr< T >( pos ), myIsOwner( isOwner ) {} + + SMDS_Ptr( const SMDS_Ptr& from ) : myIsOwner( from.myIsOwner ) + { this->swap( const_cast( from )); } + + SMDS_Ptr& operator=( const SMDS_Ptr& from ) + { + myIsOwner = from.myIsOwner; + this->swap( const_cast( from )); + return *this; + } + + template + SMDS_Ptr( const SMDS_Ptr< Y >& base ): myIsOwner( true ) + { + if ( const T* p = dynamic_cast( base.get() )) + { + this->reset( const_cast( p )); + this->myIsOwner = base.IsOwner(); + const_cast< SMDS_Ptr< Y >& >( base ).release(); + } + } + ~SMDS_Ptr() { if ( !myIsOwner ) this->release(); } - protected: - SMDS_Position(); + operator bool () const { return bool( this->get() ); } + bool IsOwner() const { return myIsOwner; } }; +class SMDS_EdgePosition; +class SMDS_FacePosition; +typedef SMDS_Ptr< SMDS_Position > SMDS_PositionPtr; +typedef SMDS_Ptr< SMDS_EdgePosition > SMDS_EdgePositionPtr; +typedef SMDS_Ptr< SMDS_FacePosition > SMDS_FacePositionPtr; #endif diff --git a/src/SMDS/SMDS_QuadraticEdge.cxx b/src/SMDS/SMDS_QuadraticEdge.cxx deleted file mode 100644 index 9f6cf94df..000000000 --- a/src/SMDS/SMDS_QuadraticEdge.cxx +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File: SMDS_QuadraticEdge.cxx -// Created: 16.01.06 16:25:42 -// Author: Sergey KUUL -// -#include "SMDS_QuadraticEdge.hxx" - -#include "SMDS_SetIterator.hxx" -#include "SMDS_IteratorOfElements.hxx" -#include "SMDS_MeshNode.hxx" -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : SMDS_QuadraticEdge -//purpose : -//======================================================================= - -SMDS_QuadraticEdge::SMDS_QuadraticEdge(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node12) - :SMDS_LinearEdge(node1,node2) -{ - //MESSAGE("******************************************************* SMDS_QuadraticEdge"); - myNodes[2]=node12; -} - - -//======================================================================= -//function : Print -//purpose : -//======================================================================= - -void SMDS_QuadraticEdge::Print(ostream & OS) const -{ - OS << "quadratic edge <" << GetID() << "> : ( first-" << myNodes[0] - << " , last-" << myNodes[1] << " , medium-" << myNodes[2] << ") " << endl; -} - - -//======================================================================= -//function : NbNodes -//purpose : -//======================================================================= - -int SMDS_QuadraticEdge::NbNodes() const -{ - return 3; -} - -//======================================================================= -//function : ChangeNodes -//purpose : -//======================================================================= - -bool SMDS_QuadraticEdge::ChangeNodes(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node12) -{ - myNodes[0]=node1; - myNodes[1]=node2; - myNodes[2]=node12; - return true; -} - -//======================================================================= -//function : IsMediumNode -//purpose : -//======================================================================= - -bool SMDS_QuadraticEdge::IsMediumNode(const SMDS_MeshNode * node) const -{ - return (myNodes[2]==node); -} - -namespace -{ - //======================================================================= - //class : _MyInterlacedNodeIterator - //purpose : - //======================================================================= - - class _MyInterlacedNodeIterator: public SMDS_NodeArrayIterator - { - const SMDS_MeshNode * myNodes[3]; - public: - _MyInterlacedNodeIterator(const SMDS_MeshNode * const * nodes): - SMDS_NodeArrayIterator( myNodes, & myNodes[3] ) - { - myNodes[0] = nodes[0]; - myNodes[1] = nodes[2]; - myNodes[2] = nodes[1]; - } - }; - - //======================================================================= - //class : _MyNodeIterator - //purpose : - //======================================================================= - - class _MyNodeIterator:public SMDS_NodeArrayElemIterator - { - public: - _MyNodeIterator(const SMDS_MeshNode * const * nodes): - SMDS_NodeArrayElemIterator( nodes, & nodes[3] ) {} - }; -} - -//======================================================================= -//function : interlacedNodesIterator -//purpose : -//======================================================================= - -SMDS_NodeIteratorPtr SMDS_QuadraticEdge::interlacedNodesIterator() const -{ - return SMDS_NodeIteratorPtr (new _MyInterlacedNodeIterator (myNodes)); -} - -//======================================================================= -//function : elementsIterator -//purpose : -//======================================================================= - -SMDS_ElemIteratorPtr SMDS_QuadraticEdge::elementsIterator(SMDSAbs_ElementType type) const -{ - switch(type) - { - case SMDSAbs_Edge: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes)); - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements - (this,type, SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes)))); - } -} diff --git a/src/SMDS/SMDS_QuadraticEdge.hxx b/src/SMDS/SMDS_QuadraticEdge.hxx deleted file mode 100644 index 7eeabf65a..000000000 --- a/src/SMDS/SMDS_QuadraticEdge.hxx +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_QuadraticEdge.hxx -// Module : SMESH -// -#ifndef _SMDS_QuadraticEdge_HeaderFile -#define _SMDS_QuadraticEdge_HeaderFile - -#include "SMESH_SMDS.hxx" - -#include "SMDS_LinearEdge.hxx" -#include - -class SMDS_EXPORT SMDS_QuadraticEdge: public SMDS_LinearEdge -{ - -public: - SMDS_QuadraticEdge(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node12); - - bool ChangeNodes(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node12); - - void Print(std::ostream & OS) const; - - int NbNodes() const; - - virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Quad_Edge; } - - virtual bool IsQuadratic() const { return true; } - - virtual bool IsMediumNode(const SMDS_MeshNode* node) const; - - SMDS_NodeIteratorPtr interlacedNodesIterator() const; - -protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; - -}; -#endif diff --git a/src/SMDS/SMDS_QuadraticFaceOfNodes.cxx b/src/SMDS/SMDS_QuadraticFaceOfNodes.cxx deleted file mode 100644 index 49066ac82..000000000 --- a/src/SMDS/SMDS_QuadraticFaceOfNodes.cxx +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File: SMDS_QuadraticFaceOfNodes.cxx -// Created: 16.01.06 17:12:58 -// Author: Sergey KUUL -// -#include "SMDS_QuadraticFaceOfNodes.hxx" - -#include "SMDS_SetIterator.hxx" -#include "SMDS_IteratorOfElements.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_Mesh.hxx" - -#include "utilities.h" - -using namespace std; - - -//======================================================================= -//function : SMDS_QuadraticFaceOfNodes() -//purpose : Constructor -//======================================================================= - -SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n31) -{ - //MESSAGE("********************************************** SMDS_QuadraticFaceOfNodes 1"); - myNodes.resize( 6 ); - myNodes[ 0 ] = n1; - myNodes[ 1 ] = n2; - myNodes[ 2 ] = n3; - myNodes[ 3 ] = n12; - myNodes[ 4 ] = n23; - myNodes[ 5 ] = n31; -} - - -//======================================================================= -//function : SMDS_QuadraticFaceOfNodes() -//purpose : Constructor -//======================================================================= - -SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n34, - const SMDS_MeshNode * n41) -{ - //MESSAGE("********************************************* SMDS_QuadraticFaceOfNodes 2"); - myNodes.resize( 8 ); - myNodes[ 0 ] = n1; - myNodes[ 1 ] = n2; - myNodes[ 2 ] = n3; - myNodes[ 3 ] = n4; - myNodes[ 4 ] = n12; - myNodes[ 5 ] = n23; - myNodes[ 6 ] = n34; - myNodes[ 7 ] = n41; -} - - -//======================================================================= -//function : IsMediumNode -//purpose : -//======================================================================= - -bool SMDS_QuadraticFaceOfNodes::IsMediumNode(const SMDS_MeshNode * node) const -{ - int i=NbNodes()/2; - for(; i : "; - int i, nbNodes = myNodes.size(); - for (i = 0; i < nbNodes - 1; i++) - OS << myNodes[i] << ","; - OS << myNodes[i] << ") " << endl; -} - -namespace { - - //======================================================================= - //class : _MyInterlacedNodeIterator - //purpose : - //======================================================================= - - class _MyInterlacedNodeIterator:public SMDS_NodeIterator - { - const vector& mySet; - size_t myIndex; - const int * myInterlace; - public: - _MyInterlacedNodeIterator(const vector& s, - const int * interlace): - mySet(s),myIndex(0),myInterlace(interlace) {} - - bool more() - { - return myIndex < mySet.size(); - } - - const SMDS_MeshNode* next() - { - return mySet[ myInterlace[ myIndex++ ]]; - } - }; - - //======================================================================= - //class : _MyNodeIterator - //purpose : - //======================================================================= - - class _MyNodeIterator : public SMDS_NodeVectorElemIterator - { - public: - _MyNodeIterator(const vector& s): - SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {} - }; - -} - -//======================================================================= -//function : interlacedNodesIterator -//purpose : -//======================================================================= - -SMDS_NodeIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesIterator() const -{ - static int triaInterlace [] = { 0, 3, 1, 4, 2, 5 }; - static int quadInterlace [] = { 0, 4, 1, 5, 2, 6, 3, 7 }; - return SMDS_NodeIteratorPtr - (new _MyInterlacedNodeIterator (myNodes, myNodes.size()==6 ? triaInterlace : quadInterlace)); -} - -/// =================================================================== -/*! - * \brief Iterator on edges of face - */ -/// =================================================================== - -class _MyEdgeIterator : public SMDS_ElemIterator -{ - vector< const SMDS_MeshElement* > myElems; - size_t myIndex; -public: - _MyEdgeIterator(const SMDS_QuadraticFaceOfNodes* face):myIndex(0) { - myElems.reserve( face->NbNodes() ); - SMDS_NodeIteratorPtr nIt = face->interlacedNodesIterator(); - const SMDS_MeshNode* n0 = face->GetNodeWrap( -1 ); - while ( nIt->more() ) { - const SMDS_MeshNode* n1 = nIt->next(); - const SMDS_MeshElement* edge = SMDS_Mesh::FindEdge( n0, n1 ); - if ( edge ) - myElems.push_back( edge ); - n0 = n1; - } - } - /// Return true if and only if there are other object in this iterator - virtual bool more() { return myIndex < myElems.size(); } - - /// Return the current object and step to the next one - virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; } -}; - -//======================================================================= -//function : elementsIterator -//purpose : -//======================================================================= - -SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::elementsIterator - (SMDSAbs_ElementType type) const -{ - switch(type) - { - case SMDSAbs_Face: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Face); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes)); - case SMDSAbs_Edge: - return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this )); - break; - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements - (this,type,SMDS_ElemIteratorPtr (new _MyNodeIterator(myNodes)))); - } - return SMDS_ElemIteratorPtr(); -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* SMDS_QuadraticFaceOfNodes::GetNode(const int ind) const -{ - return myNodes[ ind ]; -} - -SMDSAbs_EntityType SMDS_QuadraticFaceOfNodes::GetEntityType() const -{ - return NbNodes() == 6 ? SMDSEntity_Quad_Triangle : SMDSEntity_Quad_Quadrangle; -} diff --git a/src/SMDS/SMDS_QuadraticFaceOfNodes.hxx b/src/SMDS/SMDS_QuadraticFaceOfNodes.hxx deleted file mode 100644 index 8ef0a9da8..000000000 --- a/src/SMDS/SMDS_QuadraticFaceOfNodes.hxx +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_QuadraticVolumeOfNodes.hxx -// Module : SMESH -// -#ifndef _SMDS_QuadraticFaceOfNodes_HeaderFile -#define _SMDS_QuadraticFaceOfNodes_HeaderFile - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshFace.hxx" - -class SMDS_EXPORT SMDS_QuadraticFaceOfNodes:public SMDS_MeshFace -{ -public: - SMDS_QuadraticFaceOfNodes (const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n31); - - SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n34, - const SMDS_MeshNode * n41); - - virtual SMDSAbs_EntityType GetEntityType() const; - virtual bool IsQuadratic() const { return true; } - - virtual bool IsMediumNode(const SMDS_MeshNode* node) const; - - bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes); - - virtual int NbNodes() const; - virtual int NbEdges() const; - virtual int NbFaces() const; - - virtual void Print (std::ostream & OS) const; - - SMDS_NodeIteratorPtr interlacedNodesIterator() const; - - /*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ - virtual const SMDS_MeshNode* GetNode(const int ind) const; - -protected: - virtual SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const; - - private: - std::vector myNodes; -}; - -#endif diff --git a/src/SMDS/SMDS_QuadraticVolumeOfNodes.cxx b/src/SMDS/SMDS_QuadraticVolumeOfNodes.cxx deleted file mode 100644 index 0248ba86b..000000000 --- a/src/SMDS/SMDS_QuadraticVolumeOfNodes.cxx +++ /dev/null @@ -1,389 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File: SMDS_QuadraticVolumeOfNodes.cxx -// Created: 17.01.06 09:46:11 -// Author: Sergey KUUL -// -#include "SMDS_QuadraticVolumeOfNodes.hxx" - -#include "SMDS_IteratorOfElements.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_SetIterator.hxx" -#include "SMDS_VolumeTool.hxx" - -#include "utilities.h" - -using namespace std; - - -//======================================================================= -//function : SMDS_QuadraticVolumeOfNodes() -//purpose : Constructor tetrahedron of 10 nodes -//======================================================================= - -SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes - (const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n31, - const SMDS_MeshNode * n14, - const SMDS_MeshNode * n24, - const SMDS_MeshNode * n34) -{ - //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes"); - myNodes.resize( 10 ); - myNodes[ 0 ] = n1; - myNodes[ 1 ] = n2; - myNodes[ 2 ] = n3; - myNodes[ 3 ] = n4; - myNodes[ 4 ] = n12; - myNodes[ 5 ] = n23; - myNodes[ 6 ] = n31; - myNodes[ 7 ] = n14; - myNodes[ 8 ] = n24; - myNodes[ 9 ] = n34; -} - - -//======================================================================= -//function : SMDS_QuadraticVolumeOfNodes() -//purpose : Constructor pyramid of 13 nodes -//======================================================================= - -SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes - (const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n5, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n34, - const SMDS_MeshNode * n41, - const SMDS_MeshNode * n15, - const SMDS_MeshNode * n25, - const SMDS_MeshNode * n35, - const SMDS_MeshNode * n45) -{ - //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes"); - myNodes.resize( 13 ); - myNodes[ 0 ] = n1; - myNodes[ 1 ] = n2; - myNodes[ 2 ] = n3; - myNodes[ 3 ] = n4; - myNodes[ 4 ] = n5; - myNodes[ 5 ] = n12; - myNodes[ 6 ] = n23; - myNodes[ 7 ] = n34; - myNodes[ 8 ] = n41; - myNodes[ 9 ] = n15; - myNodes[ 10 ] = n25; - myNodes[ 11 ] = n35; - myNodes[ 12 ] = n45; -} - - -//======================================================================= -//function : SMDS_QuadraticVolumeOfNodes() -//purpose : Constructor Pentahedron with 15 nodes -//======================================================================= - -SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes - (const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n5, - const SMDS_MeshNode * n6, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n31, - const SMDS_MeshNode * n45, - const SMDS_MeshNode * n56, - const SMDS_MeshNode * n64, - const SMDS_MeshNode * n14, - const SMDS_MeshNode * n25, - const SMDS_MeshNode * n36) -{ - //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes"); - myNodes.resize( 15 ); - myNodes[ 0 ] = n1; - myNodes[ 1 ] = n2; - myNodes[ 2 ] = n3; - myNodes[ 3 ] = n4; - myNodes[ 4 ] = n5; - myNodes[ 5 ] = n6; - myNodes[ 6 ] = n12; - myNodes[ 7 ] = n23; - myNodes[ 8 ] = n31; - myNodes[ 9 ] = n45; - myNodes[ 10 ] = n56; - myNodes[ 11 ] = n64; - myNodes[ 12 ] = n14; - myNodes[ 13 ] = n25; - myNodes[ 14 ] = n36; -} - - -//======================================================================= -//function : SMDS_QuadraticVolumeOfNodes() -//purpose : Constructor Hexahedrons with 20 nodes -//======================================================================= - -SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes - (const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n5, - const SMDS_MeshNode * n6, - const SMDS_MeshNode * n7, - const SMDS_MeshNode * n8, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n34, - const SMDS_MeshNode * n41, - const SMDS_MeshNode * n56, - const SMDS_MeshNode * n67, - const SMDS_MeshNode * n78, - const SMDS_MeshNode * n85, - const SMDS_MeshNode * n15, - const SMDS_MeshNode * n26, - const SMDS_MeshNode * n37, - const SMDS_MeshNode * n48) -{ - //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes"); - myNodes.resize( 20 ); - myNodes[ 0 ] = n1; - myNodes[ 1 ] = n2; - myNodes[ 2 ] = n3; - myNodes[ 3 ] = n4; - myNodes[ 4 ] = n5; - myNodes[ 5 ] = n6; - myNodes[ 6 ] = n7; - myNodes[ 7 ] = n8; - myNodes[ 8 ] = n12; - myNodes[ 9 ] = n23; - myNodes[ 10 ] = n34; - myNodes[ 11 ] = n41; - myNodes[ 12 ] = n56; - myNodes[ 13 ] = n67; - myNodes[ 14 ] = n78; - myNodes[ 15 ] = n85; - myNodes[ 16 ] = n15; - myNodes[ 17 ] = n26; - myNodes[ 18 ] = n37; - myNodes[ 19 ] = n48; -} - - -//======================================================================= -//function : IsMediumNode -//purpose : -//======================================================================= - -bool SMDS_QuadraticVolumeOfNodes::IsMediumNode(const SMDS_MeshNode* node) const -{ - int nbCorners = 0; - switch (myNodes.size()) { - case 10: nbCorners = 4; break; - case 13: nbCorners = 5; break; - case 15: nbCorners = 6; break; - default: nbCorners = 8; - } - for ( size_t i = nbCorners; i : "; - int i, nbNodes = myNodes.size(); - for (i = 0; i < nbNodes - 1; i++) - OS << myNodes[i] << ","; - OS << myNodes[i] << ") " << endl; -} - - -//======================================================================= -//private class : SMDS_QuadraticVolumeOfNodes_MyIterator -//purpose : -//======================================================================= - -class SMDS_QuadraticVolumeOfNodes_MyIterator : public SMDS_NodeVectorElemIterator -{ -public: - SMDS_QuadraticVolumeOfNodes_MyIterator(const vector& s): - SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {} -}; - -/// =================================================================== -/*! - * \brief Iterator on faces or edges of volume - */ -/// =================================================================== - -class _MySubIterator : public SMDS_ElemIterator -{ - vector< const SMDS_MeshElement* > myElems; - size_t myIndex; -public: - _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) { - SMDS_VolumeTool vTool(vol); - if (type == SMDSAbs_Face) - vTool.GetAllExistingFaces( myElems ); - else - vTool.GetAllExistingFaces( myElems ); - } - /// Return true if and only if there are other object in this iterator - virtual bool more() { return myIndex < myElems.size(); } - - /// Return the current object and step to the next one - virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; } -}; - -//======================================================================= -//function : elementsIterator -//purpose : -//======================================================================= - -SMDS_ElemIteratorPtr SMDS_QuadraticVolumeOfNodes::elementsIterator - (SMDSAbs_ElementType type) const -{ - switch(type) - { - case SMDSAbs_Volume: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes)); - case SMDSAbs_Edge: - return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge)); - break; - case SMDSAbs_Face: - return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face)); - break; - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements - (this,type,SMDS_ElemIteratorPtr - (new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes)))); - } - return SMDS_ElemIteratorPtr(); -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* SMDS_QuadraticVolumeOfNodes::GetNode(const int ind) const -{ - return myNodes[ ind ]; -} - -SMDSAbs_EntityType SMDS_QuadraticVolumeOfNodes::GetEntityType() const -{ - SMDSAbs_EntityType aType = SMDSEntity_Quad_Tetra; - switch(NbNodes()) - { - case 10: aType = SMDSEntity_Quad_Tetra; break; - case 13: aType = SMDSEntity_Quad_Pyramid; break; - case 15: aType = SMDSEntity_Quad_Penta; break; - case 18: aType = SMDSEntity_BiQuad_Penta; break; - case 20: - default: aType = SMDSEntity_Quad_Hexa; break; - } - return aType; -} diff --git a/src/SMDS/SMDS_QuadraticVolumeOfNodes.hxx b/src/SMDS/SMDS_QuadraticVolumeOfNodes.hxx deleted file mode 100644 index 0f3d6a8e6..000000000 --- a/src/SMDS/SMDS_QuadraticVolumeOfNodes.hxx +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_QuadraticVolumeOfNodes.hxx -// Module : SMESH -// -#ifndef _SMDS_QuadraticVolumeOfNodes_HeaderFile -#define _SMDS_QuadraticVolumeOfNodes_HeaderFile - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshVolume.hxx" - -class SMDS_EXPORT SMDS_QuadraticVolumeOfNodes: public SMDS_MeshVolume -{ -public: - // tetrahedron of 10 nodes - SMDS_QuadraticVolumeOfNodes (const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n31, - const SMDS_MeshNode * n14, - const SMDS_MeshNode * n24, - const SMDS_MeshNode * n34); - - // pyramid of 13 nodes - SMDS_QuadraticVolumeOfNodes(const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n5, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n34, - const SMDS_MeshNode * n41, - const SMDS_MeshNode * n15, - const SMDS_MeshNode * n25, - const SMDS_MeshNode * n35, - const SMDS_MeshNode * n45); - - // Pentahedron with 15 nodes - SMDS_QuadraticVolumeOfNodes(const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n5, - const SMDS_MeshNode * n6, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n31, - const SMDS_MeshNode * n45, - const SMDS_MeshNode * n56, - const SMDS_MeshNode * n64, - const SMDS_MeshNode * n14, - const SMDS_MeshNode * n25, - const SMDS_MeshNode * n36); - - // Hexahedrons with 20 nodes - SMDS_QuadraticVolumeOfNodes(const SMDS_MeshNode * n1, - const SMDS_MeshNode * n2, - const SMDS_MeshNode * n3, - const SMDS_MeshNode * n4, - const SMDS_MeshNode * n5, - const SMDS_MeshNode * n6, - const SMDS_MeshNode * n7, - const SMDS_MeshNode * n8, - const SMDS_MeshNode * n12, - const SMDS_MeshNode * n23, - const SMDS_MeshNode * n34, - const SMDS_MeshNode * n41, - const SMDS_MeshNode * n56, - const SMDS_MeshNode * n67, - const SMDS_MeshNode * n78, - const SMDS_MeshNode * n85, - const SMDS_MeshNode * n15, - const SMDS_MeshNode * n26, - const SMDS_MeshNode * n37, - const SMDS_MeshNode * n48); - - virtual SMDSAbs_EntityType GetEntityType() const; - virtual bool IsQuadratic() const { return true; } - - virtual bool IsMediumNode(const SMDS_MeshNode* node) const; - - bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes); - - virtual int NbNodes() const; - virtual int NbEdges() const; - virtual int NbFaces() const; - - virtual void Print (std::ostream & OS) const; - - /*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ - virtual const SMDS_MeshNode* GetNode(const int ind) const; - - protected: - virtual SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const; - - private: - std::vector myNodes; -}; - -#endif diff --git a/src/SMDS/SMDS_SpacePosition.cxx b/src/SMDS/SMDS_SpacePosition.cxx index b2b9a7f2e..b7bcec930 100644 --- a/src/SMDS/SMDS_SpacePosition.cxx +++ b/src/SMDS/SMDS_SpacePosition.cxx @@ -27,19 +27,18 @@ // #include "SMDS_SpacePosition.hxx" +#include "SMDS_VertexPosition.hxx" SMDS_SpacePosition* SMDS_SpacePosition::_originPosition = new SMDS_SpacePosition(); -SMDS_SpacePosition::SMDS_SpacePosition(double x, double y, double z) +SMDS_PositionPtr SMDS_SpacePosition::originSpacePosition() { + return SMDS_PositionPtr( _originPosition, /*isOwner=*/false ); } -SMDS_TypeOfPosition SMDS_SpacePosition::GetTypeOfPosition() const +SMDS_PositionPtr SMDS_VertexPosition::StaticPosition() { - return SMDS_TOP_3DSPACE; + static SMDS_Position* _vertexPosition = new SMDS_VertexPosition; + return SMDS_PositionPtr( _vertexPosition, /*isOwner=*/false ); } -SMDS_PositionPtr SMDS_SpacePosition::originSpacePosition() -{ - return _originPosition; -} diff --git a/src/SMDS/SMDS_SpacePosition.hxx b/src/SMDS/SMDS_SpacePosition.hxx index fc2d22cc3..1bbac7b1f 100644 --- a/src/SMDS/SMDS_SpacePosition.hxx +++ b/src/SMDS/SMDS_SpacePosition.hxx @@ -31,14 +31,15 @@ #include "SMDS_Position.hxx" -class SMDS_EXPORT SMDS_SpacePosition:public SMDS_Position +class SMDS_EXPORT SMDS_SpacePosition : public SMDS_Position { + public: -public: - SMDS_SpacePosition(double x=0, double y=0, double z=0); - virtual inline SMDS_TypeOfPosition GetTypeOfPosition() const; - static SMDS_PositionPtr originSpacePosition(); -private: + virtual SMDS_TypeOfPosition GetTypeOfPosition() const { return SMDS_TOP_3DSPACE; } + static SMDS_PositionPtr originSpacePosition(); + virtual const double* GetParameters() const { return 0; } + + private: static SMDS_SpacePosition* _originPosition; }; diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx index bf9df36cf..03bff2d66 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.cxx +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -36,8 +36,6 @@ #include #include -using namespace std; - SMDS_CellLinks* SMDS_CellLinks::New() { return new SMDS_CellLinks(); @@ -150,7 +148,7 @@ int SMDS_UnstructuredGrid::InsertNextLinkedCell(int type, int npts, vtkIdType *p // --- type = VTK_POLYHEDRON int cellid = this->InsertNextCell(type, npts, pts); - set setOfNodes; + std::set setOfNodes; setOfNodes.clear(); int nbfaces = npts; int i = 0; @@ -165,7 +163,7 @@ int SMDS_UnstructuredGrid::InsertNextLinkedCell(int type, int npts, vtkIdType *p } } - set::iterator it = setOfNodes.begin(); + std::set::iterator it = setOfNodes.begin(); for (; it != setOfNodes.end(); ++it) { this->Links->ResizeCellList(*it, 1); @@ -181,25 +179,24 @@ void SMDS_UnstructuredGrid::setSMDS_mesh(SMDS_Mesh *mesh) } void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int newNodeSize, - std::vector& idCellsOldToNew, int newCellSize) + std::vector& idCellsNewToOld, int newCellSize) { - int alreadyCopied = 0; - this->DeleteLinks(); - // --- if newNodeSize, create a new compacted vtkPoints + // IDs of VTK nodes always correspond to SMDS IDs but there can be "holes" in SMDS numeration. + // We compact only if there were holes - if ( newNodeSize ) + int oldNodeSize = this->GetNumberOfPoints(); + bool updateNodes = ( oldNodeSize > newNodeSize ); + if ( true /*updateNodes*/ ) { - // rnv: to fix bug "21125: EDF 1233 SMESH: Degradation of precision in a test case for quadratic conversion" - // using double type for storing coordinates of nodes instead float. + // 21125: EDF 1233 SMESH: Degradation of precision in a test case for quadratic conversion + // Use double type for storing coordinates of nodes instead float. vtkPoints *newPoints = vtkPoints::New(); - newPoints->SetDataType(VTK_DOUBLE); - newPoints->SetNumberOfPoints(newNodeSize); - - int oldNodeSize = idNodesOldToNew.size(); + newPoints->SetDataType( VTK_DOUBLE ); + newPoints->SetNumberOfPoints( newNodeSize ); - int i = 0; + int i = 0, alreadyCopied = 0; while ( i < oldNodeSize ) { // skip a hole if any @@ -215,13 +212,20 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n this->SetPoints(newPoints); newPoints->Delete(); } - this->Points->Squeeze(); + else + { + this->Points->Squeeze(); + this->Points->Modified(); + } - // --- create new compacted Connectivity, Locations and Types + // Compact cells if VTK IDs do not correspond to SMDS IDs or nodes compacted - int oldCellSize = this->Types->GetNumberOfTuples(); + int oldCellSize = this->Types->GetNumberOfTuples(); + bool updateCells = ( updateNodes || newCellSize != oldCellSize ); + for ( int newID = 0, nbIDs = idCellsNewToOld.size(); newID < nbIDs && !updateCells; ++newID ) + updateCells = ( idCellsNewToOld[ newID ] != newID ); - if ( !newNodeSize && oldCellSize == newCellSize ) // no holes in elements + if ( false /*!updateCells*/ ) // no holes in elements { this->Connectivity->Squeeze(); this->Locations->Squeeze(); @@ -231,14 +235,28 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n this->FaceLocations->Squeeze(); this->Faces->Squeeze(); } - for ( int i = 0; i < oldCellSize; ++i ) - idCellsOldToNew[i] = i; + this->Connectivity->Modified(); return; } + + if ((int) idNodesOldToNew.size() < oldNodeSize ) + { + idNodesOldToNew.reserve( oldNodeSize ); + for ( int i = idNodesOldToNew.size(); i < oldNodeSize; ++i ) + idNodesOldToNew.push_back( i ); + } + + // --- create new compacted Connectivity, Locations and Types + + int newConnectivitySize = this->Connectivity->GetNumberOfConnectivityEntries(); + if ( newCellSize != oldCellSize ) + for ( int i = 0; i < oldCellSize - 1; ++i ) + if ( this->Types->GetValue( i ) == VTK_EMPTY_CELL ) + newConnectivitySize -= this->Locations->GetValue( i+1 ) - this->Locations->GetValue( i ); + vtkCellArray *newConnectivity = vtkCellArray::New(); newConnectivity->Initialize(); - int oldCellDataSize = this->Connectivity->GetData()->GetSize(); - newConnectivity->Allocate(oldCellDataSize); + newConnectivity->Allocate( newConnectivitySize ); vtkUnsignedCharArray *newTypes = vtkUnsignedCharArray::New(); newTypes->Initialize(); @@ -248,41 +266,24 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n newLocations->Initialize(); newLocations->SetNumberOfValues(newCellSize); - // TODO some polyhedron may be huge (only in some tests) - vtkIdType tmpid[NBMAXNODESINCELL]; - vtkIdType *pointsCell = &tmpid[0]; // --- points id to fill a new cell + std::vector< vtkIdType > pointsCell(1024); // --- points id to fill a new cell - alreadyCopied = 0; - int i = 0; - while ( i < oldCellSize ) - { - // skip a hole if any - while ( i < oldCellSize && this->Types->GetValue(i) == VTK_EMPTY_CELL ) - ++i; - int startBloc = i; - // look for a block end - while ( i < oldCellSize && this->Types->GetValue(i) != VTK_EMPTY_CELL ) - ++i; - int endBloc = i; - if ( endBloc > startBloc ) - copyBloc(newTypes, - idCellsOldToNew, idNodesOldToNew, - newConnectivity, newLocations, - pointsCell, alreadyCopied, - startBloc, endBloc); - } - newConnectivity->Squeeze(); + copyBloc(newTypes, idCellsNewToOld, idNodesOldToNew, + newConnectivity, newLocations, pointsCell ); if (vtkDoubleArray* diameters = vtkDoubleArray::SafeDownCast( vtkDataSet::CellData->GetScalars() )) // Balls { - for (int oldCellID = 0; oldCellID < oldCellSize; oldCellID++) + vtkDoubleArray* newDiameters = vtkDoubleArray::New(); + newDiameters->SetNumberOfComponents(1); + for ( int newCellID = 0; newCellID < newCellSize; newCellID++ ) { - if (this->Types->GetValue(oldCellID) == VTK_EMPTY_CELL) - continue; - int newCellId = idCellsOldToNew[ oldCellID ]; - if (newTypes->GetValue(newCellId) == VTK_POLY_VERTEX) - diameters->SetValue( newCellId, diameters->GetValue( oldCellID )); + if ( newTypes->GetValue( newCellID ) == VTK_POLY_VERTEX ) + { + int oldCellID = idCellsNewToOld[ newCellID ]; + newDiameters->InsertValue( newCellID, diameters->GetValue( oldCellID )); + } + vtkDataSet::CellData->SetScalars( newDiameters ); } } @@ -294,25 +295,23 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n vtkIdTypeArray *newFaces = vtkIdTypeArray::New(); newFaces->Initialize(); newFaces->Allocate(this->Faces->GetSize()); - for (int i = 0; i < oldCellSize; i++) + for ( int newCellID = 0; newCellID < newCellSize; newCellID++ ) { - if (this->Types->GetValue(i) == VTK_EMPTY_CELL) - continue; - int newCellId = idCellsOldToNew[i]; - if (newTypes->GetValue(newCellId) == VTK_POLYHEDRON) + if ( newTypes->GetValue( newCellID ) == VTK_POLYHEDRON ) { - newFaceLocations->InsertNextValue(newFaces->GetMaxId()+1); - int oldFaceLoc = this->FaceLocations->GetValue(i); - int nCellFaces = this->Faces->GetValue(oldFaceLoc++); - newFaces->InsertNextValue(nCellFaces); - for (int n=0; nInsertNextValue( newFaces->GetMaxId()+1 ); + int oldFaceLoc = this->FaceLocations->GetValue( oldCellId ); + int nCellFaces = this->Faces->GetValue( oldFaceLoc++ ); + newFaces->InsertNextValue( nCellFaces ); + for ( int n = 0; n < nCellFaces; n++ ) { - int nptsInFace = this->Faces->GetValue(oldFaceLoc++); - newFaces->InsertNextValue(nptsInFace); - for (int k=0; kFaces->GetValue( oldFaceLoc++ ); + newFaces->InsertNextValue( nptsInFace ); + for ( int k = 0; k < nptsInFace; k++ ) { - int oldpt = this->Faces->GetValue(oldFaceLoc++); - newFaces->InsertNextValue(idNodesOldToNew[oldpt]); + int oldpt = this->Faces->GetValue( oldFaceLoc++ ); + newFaces->InsertNextValue( idNodesOldToNew[ oldpt ]); } } } @@ -323,13 +322,13 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n } newFaceLocations->Squeeze(); newFaces->Squeeze(); - this->SetCells(newTypes, newLocations, newConnectivity, newFaceLocations, newFaces); + this->SetCells( newTypes, newLocations, newConnectivity, newFaceLocations, newFaces ); newFaceLocations->Delete(); newFaces->Delete(); } else { - this->SetCells(newTypes, newLocations, newConnectivity, FaceLocations, Faces); + this->SetCells( newTypes, newLocations, newConnectivity, FaceLocations, Faces ); } newTypes->Delete(); @@ -349,39 +348,35 @@ void SMDS_UnstructuredGrid::copyNodes(vtkPoints * newPoints, if (nbPoints > 0) { memcpy(target, source, 3 * sizeof(double) * nbPoints); - for (int j = start; j < end; j++) - idNodesOldToNew[j] = alreadyCopied++; // old vtkId --> new vtkId + alreadyCopied += nbPoints; } } -void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes, - std::vector& idCellsOldToNew, - std::vector& idNodesOldToNew, - vtkCellArray* newConnectivity, - vtkIdTypeArray* newLocations, - vtkIdType* pointsCell, - int& alreadyCopied, - int start, - int end) +void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray * newTypes, + const std::vector& idCellsNewToOld, + const std::vector& idNodesOldToNew, + vtkCellArray* newConnectivity, + vtkIdTypeArray* newLocations, + std::vector& pointsCell) { - for (int j = start; j < end; j++) + for ( size_t iNew = 0; iNew < idCellsNewToOld.size(); iNew++ ) { - newTypes->SetValue(alreadyCopied, this->Types->GetValue(j)); - idCellsOldToNew[j] = alreadyCopied; // old vtkId --> new vtkId - vtkIdType oldLoc = this->Locations->GetValue(j); + int iOld = idCellsNewToOld[ iNew ]; + newTypes->SetValue( iNew, this->Types->GetValue( iOld )); + vtkIdType oldLoc = this->Locations->GetValue( iOld ); vtkIdType nbpts; vtkIdType *oldPtsCell = 0; - this->Connectivity->GetCell(oldLoc, nbpts, oldPtsCell); - assert(nbpts < NBMAXNODESINCELL); - for (int l = 0; l < nbpts; l++) + this->Connectivity->GetCell( oldLoc, nbpts, oldPtsCell ); + if ((vtkIdType) pointsCell.size() < nbpts ) + pointsCell.resize( nbpts ); + for ( int l = 0; l < nbpts; l++ ) { int oldval = oldPtsCell[l]; pointsCell[l] = idNodesOldToNew[oldval]; } - /*int newcnt = */newConnectivity->InsertNextCell(nbpts, pointsCell); - int newLoc = newConnectivity->GetInsertLocation(nbpts); - newLocations->SetValue(alreadyCopied, newLoc); - alreadyCopied++; + /*int newcnt = */newConnectivity->InsertNextCell( nbpts, pointsCell.data() ); + int newLoc = newConnectivity->GetInsertLocation( nbpts ); + newLocations->SetValue( iNew, newLoc ); } } @@ -656,7 +651,7 @@ void SMDS_UnstructuredGrid::BuildDownwardConnectivity(bool withEdges) int connEdgeId = _downArray[vtkEdgeType]->addCell(vtkEdgeId); SMDS_Down1D* downEdge = static_cast (_downArray[vtkEdgeType]); downEdge->setNodes(connEdgeId, vtkEdgeId); - vector vtkIds; + std::vector vtkIds; int nbVtkCells = downEdge->computeVtkCells(connEdgeId, vtkIds); int downFaces[1000]; unsigned char downTypes[1000]; @@ -705,7 +700,7 @@ void SMDS_UnstructuredGrid::BuildDownwardConnectivity(bool withEdges) // --- check if the edge is already registered by exploration of the faces //CHRONO(41); - vector vtkIds; + std::vector vtkIds; unsigned char vtkEdgeType = edgesWithNodes.elems[iedge].vtkType; int *pts = &edgesWithNodes.elems[iedge].nodeIds[0]; SMDS_Down1D* downEdge = static_cast (_downArray[vtkEdgeType]); @@ -759,7 +754,7 @@ void SMDS_UnstructuredGrid::BuildDownwardConnectivity(bool withEdges) CHRONOSTOP(23);CHRONO(24); - // compact downward connectivity structure: adjust downward arrays size, replace vector> by a single vector + // compact downward connectivity structure: adjust downward arrays size, replace std::vector> by a single std::vector // 3D first then 2D and last 1D to release memory before edge upCells reorganization, (temporary memory use) for (int vtkType = VTK_QUADRATIC_PYRAMID; vtkType >= 0; vtkType--) @@ -1073,15 +1068,11 @@ SMDS_UnstructuredGrid::extrudeVolumeFromFace(int vtkVolId, std::map >& nodeQuadDomains) { //MESSAGE("extrudeVolumeFromFace " << vtkVolId); - vector orderedOriginals; - orderedOriginals.clear(); - set::const_iterator it = originalNodes.begin(); - for (; it != originalNodes.end(); ++it) - orderedOriginals.push_back(*it); + std::vector orderedOriginals( originalNodes.begin(), originalNodes.end() ); int dim = 0; int nbNodes = this->getOrderedNodesOfFace(vtkVolId, dim, orderedOriginals); - vector orderedNodes; + std::vector orderedNodes; bool isQuadratic = false; switch (orderedOriginals.size()) @@ -1130,7 +1121,7 @@ SMDS_UnstructuredGrid::extrudeVolumeFromFace(int vtkVolId, { double *coords = this->GetPoint(oldId); SMDS_MeshNode *newNode = _mesh->AddNode(coords[0], coords[1], coords[2]); - newId = newNode->getVtkId(); + newId = newNode->GetVtkID(); if (! nodeQuadDomains.count(oldId)) { std::map emptyMap; diff --git a/src/SMDS/SMDS_UnstructuredGrid.hxx b/src/SMDS/SMDS_UnstructuredGrid.hxx index 5936e9759..448fed72d 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.hxx +++ b/src/SMDS/SMDS_UnstructuredGrid.hxx @@ -116,9 +116,12 @@ protected: SMDS_UnstructuredGrid(); ~SMDS_UnstructuredGrid(); void copyNodes(vtkPoints *newPoints, std::vector& idNodesOldToNew, int& alreadyCopied, int start, int end); - void copyBloc(vtkUnsignedCharArray *newTypes, std::vector& idCellsOldToNew, std::vector& idNodesOldToNew, - vtkCellArray* newConnectivity, vtkIdTypeArray* newLocations, vtkIdType* pointsCell, int& alreadyCopied, - int start, int end); + void copyBloc(vtkUnsignedCharArray *newTypes, + const std::vector& idCellsOldToNew, + const std::vector& idNodesOldToNew, + vtkCellArray* newConnectivity, + vtkIdTypeArray* newLocations, + std::vector& pointsCell); std::vector _cellIdToDownId; //!< convert vtk Id to downward[vtkType] id, initialized with -1 std::vector _downTypes; diff --git a/src/SMDS/SMDS_VertexPosition.cxx b/src/SMDS/SMDS_VertexPosition.cxx deleted file mode 100644 index 0e2d183e2..000000000 --- a/src/SMDS/SMDS_VertexPosition.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_VertexPosition.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#include "SMDS_VertexPosition.hxx" - -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : SMDS_VertexPosition -//purpose : -//======================================================================= - -SMDS_VertexPosition:: SMDS_VertexPosition() -{ - //MESSAGE("*********************************************** SMDS_VertexPosition " << aVertexId); -} - -SMDS_TypeOfPosition SMDS_VertexPosition::GetTypeOfPosition() const -{ - //MESSAGE("################################################# GetTypeOfPosition"); - return SMDS_TOP_VERTEX; -} diff --git a/src/SMDS/SMDS_VertexPosition.hxx b/src/SMDS/SMDS_VertexPosition.hxx index 0943de91c..4db67d527 100644 --- a/src/SMDS/SMDS_VertexPosition.hxx +++ b/src/SMDS/SMDS_VertexPosition.hxx @@ -31,12 +31,12 @@ #include "SMDS_Position.hxx" -class SMDS_EXPORT SMDS_VertexPosition:public SMDS_Position +class SMDS_EXPORT SMDS_VertexPosition : public SMDS_Position { - - public: - SMDS_TypeOfPosition GetTypeOfPosition() const; - SMDS_VertexPosition(); + public: + SMDS_TypeOfPosition GetTypeOfPosition() const { return SMDS_TOP_VERTEX; } + virtual const double* GetParameters() const { return 0; } + static SMDS_PositionPtr StaticPosition(); }; #endif diff --git a/src/SMDS/SMDS_VolumeOfFaces.cxx b/src/SMDS/SMDS_VolumeOfFaces.cxx deleted file mode 100644 index 929c54675..000000000 --- a/src/SMDS/SMDS_VolumeOfFaces.cxx +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (C) 2007-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_VolumeOfFaces.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#include "SMDS_VolumeOfFaces.hxx" -#include "SMDS_IteratorOfElements.hxx" -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : Print -//purpose : -//======================================================================= - -void SMDS_VolumeOfFaces::Print(ostream & OS) const -{ - OS << "volume <" << GetID() << "> : "; - int i; - for (i = 0; i < NbFaces()-1; ++i) OS << myFaces[i] << ","; - OS << myFaces[i]<< ") " << endl; -} - - -int SMDS_VolumeOfFaces::NbFaces() const -{ - return myNbFaces; -} - -class SMDS_VolumeOfFaces_MyIterator:public SMDS_ElemIterator -{ - const SMDS_MeshFace* const *mySet; - int myLength; - int index; - public: - SMDS_VolumeOfFaces_MyIterator(const SMDS_MeshFace* const *s, int l): - mySet(s),myLength(l),index(0) {} - - bool more() - { - return index - - -class SMDS_EXPORT SMDS_VolumeOfFaces:public SMDS_MeshVolume -{ - - public: - SMDS_VolumeOfFaces(const SMDS_MeshFace * face1, - const SMDS_MeshFace * face2, - const SMDS_MeshFace * face3, - const SMDS_MeshFace * face4); - SMDS_VolumeOfFaces(const SMDS_MeshFace * face1, - const SMDS_MeshFace * face2, - const SMDS_MeshFace * face3, - const SMDS_MeshFace * face4, - const SMDS_MeshFace * face5); - SMDS_VolumeOfFaces(const SMDS_MeshFace * face1, - const SMDS_MeshFace * face2, - const SMDS_MeshFace * face3, - const SMDS_MeshFace * face4, - const SMDS_MeshFace * face5, - const SMDS_MeshFace * face6); - - virtual SMDSAbs_EntityType GetEntityType() const; - virtual SMDSAbs_GeometryType GetGeomType() const; - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes) {return false;} - virtual void Print(std::ostream & OS) const; - - virtual int NbFaces() const; - - protected: - virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - const SMDS_MeshFace * myFaces[6]; - int myNbFaces; -}; -#endif diff --git a/src/SMDS/SMDS_VolumeOfNodes.cxx b/src/SMDS/SMDS_VolumeOfNodes.cxx index 3f76d5322..f652eeaf2 100644 --- a/src/SMDS/SMDS_VolumeOfNodes.cxx +++ b/src/SMDS/SMDS_VolumeOfNodes.cxx @@ -27,90 +27,82 @@ #endif #include "SMDS_VolumeOfNodes.hxx" + #include "SMDS_MeshNode.hxx" #include "SMDS_SetIterator.hxx" -#include "SMDS_VolumeTool.hxx" -#include "SMDS_Mesh.hxx" -#include "utilities.h" -using namespace std; +#include + +#include /////////////////////////////////////////////////////////////////////////////// /// Create an hexahedron. node 1,2,3,4 and 5,6,7,8 are quadrangle and /// 5,1 and 7,3 are an edges. /////////////////////////////////////////////////////////////////////////////// -SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - const SMDS_MeshNode * node5, - const SMDS_MeshNode * node6, - const SMDS_MeshNode * node7, - const SMDS_MeshNode * node8) -{ - //MESSAGE("***************************************************** SMDS_VolumeOfNodes"); - myNbNodes = 8; - myNodes = new const SMDS_MeshNode* [myNbNodes]; - myNodes[0]=node1; - myNodes[1]=node2; - myNodes[2]=node3; - myNodes[3]=node4; - myNodes[4]=node5; - myNodes[5]=node6; - myNodes[6]=node7; - myNodes[7]=node8; +SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4, + const SMDS_MeshNode * node5, + const SMDS_MeshNode * node6, + const SMDS_MeshNode * node7, + const SMDS_MeshNode * node8) +{ + myNbNodes = 8; + myNodes = new const SMDS_MeshNode* [myNbNodes]; + myNodes[0]=node1; + myNodes[1]=node2; + myNodes[2]=node3; + myNodes[3]=node4; + myNodes[4]=node5; + myNodes[5]=node6; + myNodes[6]=node7; + myNodes[7]=node8; } -SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4) +SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4) { - //MESSAGE("***************************************************** SMDS_VolumeOfNodes"); - myNbNodes = 4; - myNodes = new const SMDS_MeshNode* [myNbNodes]; - myNodes[0]=node1; - myNodes[1]=node2; - myNodes[2]=node3; - myNodes[3]=node4; + myNbNodes = 4; + myNodes = new const SMDS_MeshNode* [myNbNodes]; + myNodes[0]=node1; + myNodes[1]=node2; + myNodes[2]=node3; + myNodes[3]=node4; } -SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - const SMDS_MeshNode * node5) +SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4, + const SMDS_MeshNode * node5) { - //MESSAGE("***************************************************** SMDS_VolumeOfNodes"); - myNbNodes = 5; - myNodes = new const SMDS_MeshNode* [myNbNodes]; - myNodes[0]=node1; - myNodes[1]=node2; - myNodes[2]=node3; - myNodes[3]=node4; - myNodes[4]=node5; + myNbNodes = 5; + myNodes = new const SMDS_MeshNode* [myNbNodes]; + myNodes[0]=node1; + myNodes[1]=node2; + myNodes[2]=node3; + myNodes[3]=node4; + myNodes[4]=node5; } -SMDS_VolumeOfNodes::SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - const SMDS_MeshNode * node5, - const SMDS_MeshNode * node6) +SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4, + const SMDS_MeshNode * node5, + const SMDS_MeshNode * node6) { - //MESSAGE("***************************************************** SMDS_VolumeOfNodes"); - myNbNodes = 6; - myNodes = new const SMDS_MeshNode* [myNbNodes]; - myNodes[0]=node1; - myNodes[1]=node2; - myNodes[2]=node3; - myNodes[3]=node4; - myNodes[4]=node5; - myNodes[5]=node6; + myNbNodes = 6; + myNodes = new const SMDS_MeshNode* [myNbNodes]; + myNodes[0]=node1; + myNodes[1]=node2; + myNodes[2]=node3; + myNodes[3]=node4; + myNodes[4]=node5; + myNodes[5]=node6; } bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[], @@ -136,98 +128,49 @@ SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes() } } -void SMDS_VolumeOfNodes::Print(ostream & OS) const +void SMDS_VolumeOfNodes::Print(std::ostream & OS) const { - OS << "volume <" << GetID() << "> : "; - int i; - for (i = 0; i < NbNodes()-1; ++i) OS << myNodes[i] << ","; - OS << myNodes[NbNodes()-1]<< ") " << endl; + OS << "volume <" << GetID() << "> : "; + int i; + for (i = 0; i < NbNodes()-1; ++i) OS << myNodes[i] << ","; + OS << myNodes[NbNodes()-1]<< ") " << std::endl; } int SMDS_VolumeOfNodes::NbFaces() const { - switch(NbNodes()) - { - case 4: return 4; - case 5: return 5; - case 6: return 5; - case 8: return 6; - default: MESSAGE("invalid number of nodes"); - } - return 0; + switch(NbNodes()) + { + case 4: return 4; + case 5: return 5; + case 6: return 5; + case 8: return 6; + default: MESSAGE("invalid number of nodes"); + } + return 0; } int SMDS_VolumeOfNodes::NbNodes() const { - return myNbNodes; + return myNbNodes; } int SMDS_VolumeOfNodes::NbEdges() const { - switch(NbNodes()) - { - case 4: return 6; - case 5: return 8; - case 6: return 9; - case 8: return 12; - default: MESSAGE("invalid number of nodes"); - } - return 0; -} - -/*! - * \brief Iterator on node of volume - */ -class SMDS_VolumeOfNodes_MyIterator:public SMDS_NodeArrayElemIterator -{ - public: - SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l): - SMDS_NodeArrayElemIterator( s, & s[ l ]) {} -}; - -/*! - * \brief Iterator on faces or edges of volume - */ -class _MySubIterator : public SMDS_ElemIterator -{ - vector< const SMDS_MeshElement* > myElems; - size_t myIndex; -public: - _MySubIterator(const SMDS_VolumeOfNodes* vol, SMDSAbs_ElementType type):myIndex(0) { - SMDS_VolumeTool vTool(vol); - if (type == SMDSAbs_Face) - vTool.GetAllExistingFaces( myElems ); - else - vTool.GetAllExistingFaces( myElems ); - } - /// Return true if and only if there are other object in this iterator - virtual bool more() { return myIndex < myElems.size(); } - - /// Return the current object and step to the next one - virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; } -}; - -SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const -{ - switch(type) + switch(NbNodes()) { - case SMDSAbs_Volume: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes)); - case SMDSAbs_Face: - return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face)); - case SMDSAbs_Edge: - return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge)); - default: - MESSAGE("ERROR : Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); + case 4: return 6; + case 5: return 8; + case 6: return 9; + case 8: return 12; + default: MESSAGE("invalid number of nodes"); } + return 0; } + SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const { - return SMDSAbs_Volume; + return SMDSAbs_Volume; } /*! @@ -269,3 +212,20 @@ SMDSAbs_GeometryType SMDS_VolumeOfNodes::GetGeomType() const return aType; } +int SMDS_VolumeOfNodes::GetNodeIndex( const SMDS_MeshNode* node ) const +{ + for ( int i = 0; i < myNbNodes; ++i ) + if ( myNodes[i] == node ) + return i; + return -1; +} + +SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::nodesIterator() const +{ + return boost::make_shared< SMDS_NodeArrayElemIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); +} + +SMDS_NodeIteratorPtr SMDS_VolumeOfNodes::nodeIterator() const +{ + return boost::make_shared< SMDS_NodeArrayIterator >( &myNodes[0], &myNodes[0] + NbNodes() ); +} diff --git a/src/SMDS/SMDS_VolumeOfNodes.hxx b/src/SMDS/SMDS_VolumeOfNodes.hxx index 485ea7eda..15f0058c6 100644 --- a/src/SMDS/SMDS_VolumeOfNodes.hxx +++ b/src/SMDS/SMDS_VolumeOfNodes.hxx @@ -29,63 +29,66 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshVolume.hxx" +#include "SMDS_CellOfNodes.hxx" -class SMDS_EXPORT SMDS_VolumeOfNodes:public SMDS_MeshVolume +class SMDS_EXPORT SMDS_VolumeOfNodes: public SMDS_CellOfNodes { - public: - SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4); - SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - const SMDS_MeshNode * node5); - SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - const SMDS_MeshNode * node5, - const SMDS_MeshNode * node6); - SMDS_VolumeOfNodes( - const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3, - const SMDS_MeshNode * node4, - const SMDS_MeshNode * node5, - const SMDS_MeshNode * node6, - const SMDS_MeshNode * node7, - const SMDS_MeshNode * node8); - bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes); - ~SMDS_VolumeOfNodes(); + public: + SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4); + SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4, + const SMDS_MeshNode * node5); + SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4, + const SMDS_MeshNode * node5, + const SMDS_MeshNode * node6); + SMDS_VolumeOfNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2, + const SMDS_MeshNode * node3, + const SMDS_MeshNode * node4, + const SMDS_MeshNode * node5, + const SMDS_MeshNode * node6, + const SMDS_MeshNode * node7, + const SMDS_MeshNode * node8); + bool ChangeNodes(const SMDS_MeshNode* nodes[], + const int nbNodes); + ~SMDS_VolumeOfNodes(); - void Print(std::ostream & OS) const; - int NbFaces() const; - int NbNodes() const; - int NbEdges() const; - virtual SMDSAbs_ElementType GetType() const; - virtual SMDSAbs_EntityType GetEntityType() const; - virtual SMDSAbs_GeometryType GetGeomType() const; + void Print(std::ostream & OS) const; + int NbFaces() const; + int NbNodes() const; + int NbEdges() const; + virtual SMDSAbs_ElementType GetType() const; + virtual SMDSAbs_EntityType GetEntityType() const; + virtual SMDSAbs_GeometryType GetGeomType() const; + virtual bool IsPoly() const { return false; } + virtual bool IsQuadratic() const { return false; } /*! * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node + * \param ind - node index + * \retval const SMDS_MeshNode* - the node */ virtual const SMDS_MeshNode* GetNode(const int ind) const; - protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; - const SMDS_MeshNode** myNodes; - int myNbNodes; + virtual int NbCornerNodes() const { return NbNodes(); } + virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; + + virtual SMDS_ElemIteratorPtr nodesIterator() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; + + protected: + + const SMDS_MeshNode** myNodes; + int myNbNodes; }; diff --git a/src/SMDS/SMDS_VolumeTool.cxx b/src/SMDS/SMDS_VolumeTool.cxx index 9e144a620..6de1ac68e 100644 --- a/src/SMDS/SMDS_VolumeTool.cxx +++ b/src/SMDS/SMDS_VolumeTool.cxx @@ -32,10 +32,9 @@ #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" -#include "SMDS_VtkVolume.hxx" #include "SMDS_Mesh.hxx" -#include "utilities.h" +#include #include #include @@ -43,8 +42,6 @@ #include #include -using namespace std; - namespace { // ====================================================== @@ -506,7 +503,7 @@ bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume, myNbFaces = theVolume->NbFaces(); if ( myVolume->IsPoly() ) { - myPolyedre = dynamic_cast( myVolume ); + myPolyedre = SMDS_Mesh::DownCast( myVolume ); myPolyFacetOri.resize( myNbFaces, 0 ); } @@ -522,10 +519,7 @@ bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume, } else { - int iNode = 0; - SMDS_ElemIteratorPtr nodeIt = myVolume->nodesIterator(); - while ( nodeIt->more() ) - myVolumeNodes[ iNode++ ] = static_cast( nodeIt->next() ); + myVolumeNodes.assign( myVolume->begin_nodes(), myVolume->end_nodes() ); } // check validity @@ -954,8 +948,8 @@ const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex ) const //purpose : Return a set of face nodes. //======================================================================= -bool SMDS_VolumeTool::GetFaceNodes (int faceIndex, - set& theFaceNodes ) const +bool SMDS_VolumeTool::GetFaceNodes (int faceIndex, + std::set& theFaceNodes ) const { if ( !setFace( faceIndex )) return false; @@ -1060,7 +1054,7 @@ bool SMDS_VolumeTool::IsFaceExternal( int faceIndex ) const { ori = ( -minProj < maxProj ? -1 : +1 ); double convexity = std::min( -minProj, maxProj ) / std::max( -minProj, maxProj ); - convexity2face.insert( make_pair( convexity, iF * ori )); + convexity2face.insert( std::make_pair( convexity, iF * ori )); } } if ( faceMostConvex < 0 ) // none facet has nodes on the same side @@ -1089,7 +1083,7 @@ bool SMDS_VolumeTool::IsFaceExternal( int faceIndex ) const // compare orientation of links of the facet with myFwdLinks ori = 0; setFace( faceIndex ); - vector< NLink > links( myCurFace.myNbNodes ), links2; + std::vector< NLink > links( myCurFace.myNbNodes ), links2; for ( int i = 0; i < myCurFace.myNbNodes && !ori; ++i ) { NLink link( myCurFace.myNodes[i], myCurFace.myNodes[i+1] ); @@ -1210,7 +1204,7 @@ bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, doub } double size = cross.Magnitude(); - if ( size <= numeric_limits::min() ) + if ( size <= std::numeric_limits::min() ) return false; X = cross.x / size; @@ -1382,7 +1376,7 @@ bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1, } else { d2 = 0; } - vector::const_iterator i; + std::vector::const_iterator i; for (int iface = 0; iface < myNbFaces; iface++) { from = to; @@ -1429,8 +1423,8 @@ bool SMDS_VolumeTool::IsLinked (const int theNode1Index, return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]); } - int minInd = min( theNode1Index, theNode2Index ); - int maxInd = max( theNode1Index, theNode2Index ); + int minInd = std::min( theNode1Index, theNode2Index ); + int maxInd = std::max( theNode1Index, theNode2Index ); if ( minInd < 0 || maxInd > (int)myVolumeNodes.size() - 1 || maxInd == minInd ) return false; @@ -1565,7 +1559,7 @@ int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const */ //================================================================================ -int SMDS_VolumeTool::GetAllExistingFaces(vector & faces) const +int SMDS_VolumeTool::GetAllExistingFaces(std::vector & faces) const { faces.clear(); SaveFacet savedFacet( myCurFace ); @@ -1606,7 +1600,7 @@ int SMDS_VolumeTool::GetAllExistingFaces(vector & faces */ //================================================================================ -int SMDS_VolumeTool::GetAllExistingEdges(vector & edges) const +int SMDS_VolumeTool::GetAllExistingEdges(std::vector & edges) const { edges.clear(); edges.reserve( myVolumeNodes.size() * 2 ); @@ -1717,7 +1711,7 @@ bool SMDS_VolumeTool::IsFreeFace( int faceIndex, const SMDS_MeshElement** otherV // int nb = myCurFace.myNbNodes; // if ( myVolume->GetEntityType() != vol->GetEntityType() ) // nb -= ( GetCenterNodeIndex(0) > 0 ); - // set faceNodes( nodes, nodes + nb ); + // std::set faceNodes( nodes, nodes + nb ); // if ( SMDS_VolumeTool( vol ).GetFaceIndex( faceNodes ) < 0 ) // continue; // } @@ -1747,7 +1741,7 @@ bool SMDS_VolumeTool::IsFreeFaceAdv( int faceIndex, const SMDS_MeshElement** oth // evaluate nb of face nodes shared by other volumes int maxNbShared = -1; - typedef map< const SMDS_MeshElement*, int > TElemIntMap; + typedef std::map< const SMDS_MeshElement*, int > TElemIntMap; TElemIntMap volNbShared; TElemIntMap::iterator vNbIt; for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) { @@ -1756,7 +1750,7 @@ bool SMDS_VolumeTool::IsFreeFaceAdv( int faceIndex, const SMDS_MeshElement** oth while ( eIt->more() ) { const SMDS_MeshElement* elem = eIt->next(); if ( elem != myVolume ) { - vNbIt = volNbShared.insert( make_pair( elem, 0 )).first; + vNbIt = volNbShared.insert( std::make_pair( elem, 0 )).first; (*vNbIt).second++; if ( vNbIt->second > maxNbShared ) maxNbShared = vNbIt->second; @@ -1855,7 +1849,7 @@ bool SMDS_VolumeTool::IsFreeFaceAdv( int faceIndex, const SMDS_MeshElement** oth //purpose : Return index of a face formed by theFaceNodes //======================================================================= -int SMDS_VolumeTool::GetFaceIndex( const set& theFaceNodes, +int SMDS_VolumeTool::GetFaceIndex( const std::set& theFaceNodes, const int theFaceIndexHint ) const { if ( theFaceIndexHint >= 0 ) @@ -1898,12 +1892,12 @@ int SMDS_VolumeTool::GetFaceIndex( const set& theFaceNodes //purpose : Return index of a face formed by theFaceNodes //======================================================================= -/*int SMDS_VolumeTool::GetFaceIndex( const set& theFaceNodesIndices ) +/*int SMDS_VolumeTool::GetFaceIndex( const std::set& theFaceNodesIndices ) { for ( int iFace = 0; iFace < myNbFaces; iFace++ ) { const int* nodes = GetFaceNodesIndices( iFace ); int nbFaceNodes = NbFaceNodes( iFace ); - set nodeSet; + std::set nodeSet; for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) nodeSet.insert( nodes[ iNode ] ); if ( theFaceNodesIndices == nodeSet ) @@ -1932,7 +1926,7 @@ bool SMDS_VolumeTool::setFace( int faceIndex ) const if (myVolume->IsPoly()) { - if (!myPolyedre) { + if ( !myPolyedre ) { MESSAGE("Warning: bad volumic element"); return false; } diff --git a/src/SMDS/SMDS_VolumeTool.hxx b/src/SMDS/SMDS_VolumeTool.hxx index 271ab4af5..d0a1f3121 100644 --- a/src/SMDS/SMDS_VolumeTool.hxx +++ b/src/SMDS/SMDS_VolumeTool.hxx @@ -33,7 +33,6 @@ class SMDS_MeshElement; class SMDS_MeshNode; -class SMDS_VtkVolume; class SMDS_MeshVolume; #include @@ -252,7 +251,7 @@ class SMDS_EXPORT SMDS_VolumeTool bool projectNodesToNormal( int faceIndex, double& minProj, double& maxProj ) const; const SMDS_MeshElement* myVolume; - const SMDS_VtkVolume* myPolyedre; + const SMDS_MeshVolume* myPolyedre; bool myIgnoreCentralNodes; bool myVolForward; diff --git a/src/SMDS/SMDS_VtkCellIterator.cxx b/src/SMDS/SMDS_VtkCellIterator.cxx index a0f0d3784..0f4744925 100644 --- a/src/SMDS/SMDS_VtkCellIterator.cxx +++ b/src/SMDS/SMDS_VtkCellIterator.cxx @@ -20,59 +20,40 @@ #include "SMDS_VtkCellIterator.hxx" #include "utilities.h" -SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) : - _mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType) +#include +#include + +_GetVtkNodes::_GetVtkNodes( vtkIdList* _vtkIdList, + SMDS_Mesh* mesh, + int vtkCellId, + SMDSAbs_EntityType aType ) { - vtkUnstructuredGrid* grid = _mesh->getGrid(); - _vtkIdList = vtkIdList::New(); + vtkUnstructuredGrid* grid = mesh->GetGrid(); const std::vector& interlace = SMDS_MeshCell::fromVtkOrder( aType ); if ( interlace.empty() ) { - grid->GetCellPoints(_cellId, _vtkIdList); - _nbNodes = _vtkIdList->GetNumberOfIds(); + grid->GetCellPoints( vtkCellId, _vtkIdList ); } else { vtkIdType npts, *pts; - grid->GetCellPoints( _cellId, npts, pts ); - _vtkIdList->SetNumberOfIds( _nbNodes = npts ); - for (int i = 0; i < _nbNodes; i++) + grid->GetCellPoints( vtkCellId, npts, pts ); + _vtkIdList->SetNumberOfIds( npts ); + for (int i = 0; i < npts; i++) _vtkIdList->SetId(i, pts[interlace[i]]); } } -SMDS_VtkCellIterator::~SMDS_VtkCellIterator() -{ - _vtkIdList->Delete(); -} - -bool SMDS_VtkCellIterator::more() -{ - return (_index < _nbNodes); -} - -const SMDS_MeshElement* SMDS_VtkCellIterator::next() +_GetVtkNodesToUNV::_GetVtkNodesToUNV( vtkIdList* _vtkIdList, + SMDS_Mesh* mesh, + int vtkCellId, + SMDSAbs_EntityType aType ) { - vtkIdType id = _vtkIdList->GetId(_index++); - return _mesh->FindNodeVtk(id); -} - -SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) : - SMDS_VtkCellIterator() -{ - _mesh = mesh; - _cellId = vtkCellId; - _index = 0; - _type = aType; - //MESSAGE("SMDS_VtkCellInterlacedIterator (UNV)" << _type); - - _vtkIdList = vtkIdList::New(); - vtkIdType* pts; - vtkUnstructuredGrid* grid = _mesh->getGrid(); - grid->GetCellPoints((vtkIdType)_cellId, (vtkIdType&)_nbNodes, pts); - _vtkIdList->SetNumberOfIds(_nbNodes); + vtkIdType * pts, npts; + vtkUnstructuredGrid* grid = mesh->GetGrid(); + grid->GetCellPoints( (vtkIdType)vtkCellId, npts, pts ); const int *ids = 0; - switch (_type) + switch (aType) { case SMDSEntity_Quad_Edge: { @@ -85,7 +66,7 @@ SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCel { static int id[] = { 0, 3, 1, 4, 2, 5 }; ids = id; - _nbNodes = 6; + npts = 6; break; } case SMDSEntity_Quad_Quadrangle: @@ -93,7 +74,7 @@ SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCel { static int id[] = { 0, 4, 1, 5, 2, 6, 3, 7 }; ids = id; - _nbNodes = 8; + npts = 8; break; } case SMDSEntity_Quad_Tetra: @@ -126,7 +107,7 @@ SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCel { static int id[] = { 0, 8, 1, 9, 2, 10, 3, 11, 16, 17, 18, 19, 4, 12, 5, 13, 6, 14, 7, 15 }; ids = id; - _nbNodes = 20; + npts = 20; break; } case SMDSEntity_Polygon: @@ -134,62 +115,42 @@ SMDS_VtkCellIteratorToUNV::SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCel case SMDSEntity_Polyhedra: case SMDSEntity_Quad_Polyhedra: default: - const std::vector& i = SMDS_MeshCell::interlacedSmdsOrder(aType, _nbNodes); + const std::vector& i = SMDS_MeshCell::interlacedSmdsOrder( aType, npts ); if ( !i.empty() ) ids = & i[0]; } + _vtkIdList->SetNumberOfIds( npts ); + if ( ids ) - for (int i = 0; i < _nbNodes; i++) + for (int i = 0; i < npts; i++) _vtkIdList->SetId(i, pts[ids[i]]); else - for (int i = 0; i < _nbNodes; i++) + for (int i = 0; i < npts; i++) _vtkIdList->SetId(i, pts[i]); } -bool SMDS_VtkCellIteratorToUNV::more() +_GetVtkNodesPolyh::_GetVtkNodesPolyh( vtkIdList* _vtkIdList, + SMDS_Mesh* mesh, + int vtkCellId, + SMDSAbs_EntityType aType ) { - return SMDS_VtkCellIterator::more(); -} - -const SMDS_MeshNode* SMDS_VtkCellIteratorToUNV::next() -{ - return static_cast< const SMDS_MeshNode* >( SMDS_VtkCellIterator::next() ); -} - -SMDS_VtkCellIteratorToUNV::~SMDS_VtkCellIteratorToUNV() -{ -} - -SMDS_VtkCellIteratorPolyH::SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) : - SMDS_VtkCellIterator() -{ - _mesh = mesh; - _cellId = vtkCellId; - _index = 0; - _type = aType; - //MESSAGE("SMDS_VtkCellIteratorPolyH " << _type); - _vtkIdList = vtkIdList::New(); - vtkUnstructuredGrid* grid = _mesh->getGrid(); - grid->GetCellPoints(_cellId, _vtkIdList); - _nbNodes = _vtkIdList->GetNumberOfIds(); - switch (_type) + vtkUnstructuredGrid* grid = mesh->GetGrid(); + switch (aType) { case SMDSEntity_Polyhedra: { - //MESSAGE("SMDS_VtkCellIterator Polyhedra"); vtkIdType nFaces = 0; vtkIdType* ptIds = 0; - grid->GetFaceStream(_cellId, nFaces, ptIds); - int id = 0; - _nbNodesInFaces = 0; + grid->GetFaceStream( vtkCellId, nFaces, ptIds ); + int id = 0, nbNodesInFaces = 0; for (int i = 0; i < nFaces; i++) { int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace] - _nbNodesInFaces += nodesInFace; + nbNodesInFaces += nodesInFace; id += (nodesInFace + 1); } - _vtkIdList->SetNumberOfIds(_nbNodesInFaces); + _vtkIdList->SetNumberOfIds( nbNodesInFaces ); id = 0; int n = 0; for (int i = 0; i < nFaces; i++) @@ -205,12 +166,3 @@ SMDS_VtkCellIteratorPolyH::SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCel assert(0); } } - -SMDS_VtkCellIteratorPolyH::~SMDS_VtkCellIteratorPolyH() -{ -} - -bool SMDS_VtkCellIteratorPolyH::more() -{ - return (_index < _nbNodesInFaces); -} diff --git a/src/SMDS/SMDS_VtkCellIterator.hxx b/src/SMDS/SMDS_VtkCellIterator.hxx index 30ddadee5..92fdc17a2 100644 --- a/src/SMDS/SMDS_VtkCellIterator.hxx +++ b/src/SMDS/SMDS_VtkCellIterator.hxx @@ -27,48 +27,68 @@ #include #include -class SMDS_VtkCellIterator: public SMDS_ElemIterator +//-------------------------------------------------------------------------------- +/*! + * \brief Retrieve nodes of a cell + */ +struct _GetVtkNodes +{ + _GetVtkNodes( vtkIdList* nodeIds, SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType type); +}; +struct _GetVtkNodesToUNV +{ + _GetVtkNodesToUNV( vtkIdList* nodeIds, SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType type); +}; +struct _GetVtkNodesPolyh +{ + _GetVtkNodesPolyh( vtkIdList* nodeIds, SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType type); +}; + +//-------------------------------------------------------------------------------- +/*! + * \brief Iterator on nodes of a cell + */ +template< class SMDS_ITERATOR = SMDS_ElemIterator, class GET_VTK_NODES = _GetVtkNodes > +class SMDS_VtkCellIterator: public SMDS_ITERATOR { public: - SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType); - virtual ~SMDS_VtkCellIterator(); - virtual bool more(); - virtual const SMDS_MeshElement* next(); - inline void exchange(vtkIdType a, vtkIdType b) + typedef typename SMDS_ITERATOR::value_type result_type; + + SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) + : _mesh(mesh), _index(0), _vtkIdList( vtkIdList::New() ) { - vtkIdType t = _vtkIdList->GetId(a); - _vtkIdList->SetId(a, _vtkIdList->GetId(b)); - _vtkIdList->SetId(b, t); + GET_VTK_NODES getNodes( _vtkIdList, mesh, vtkCellId, aType ); + } + virtual ~SMDS_VtkCellIterator() { _vtkIdList->Delete(); } + virtual bool more() { return ( _index < _vtkIdList->GetNumberOfIds() ); } + virtual result_type next() { + vtkIdType id = _vtkIdList->GetId( _index++ ); + return static_cast( _mesh->FindNodeVtk( id )); } - protected: - SMDS_VtkCellIterator() {}; - SMDS_Mesh* _mesh; - int _cellId; - int _index; - int _nbNodes; - SMDSAbs_EntityType _type; + int _index; vtkIdList* _vtkIdList; }; -class SMDS_VtkCellIteratorToUNV: public SMDS_NodeIterator, protected SMDS_VtkCellIterator +//-------------------------------------------------------------------------------- +template< class SMDS_ITERATOR = SMDS_ElemIterator > +class SMDS_VtkCellIteratorToUNV: public SMDS_VtkCellIterator< SMDS_ITERATOR, _GetVtkNodesToUNV > { + typedef SMDS_VtkCellIterator< SMDS_ITERATOR, _GetVtkNodesToUNV > parent_t; public: - SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType); - virtual const SMDS_MeshNode* next(); - virtual bool more(); - virtual ~SMDS_VtkCellIteratorToUNV(); + SMDS_VtkCellIteratorToUNV(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType type): + parent_t( mesh, vtkCellId, type ) {} }; -class SMDS_VtkCellIteratorPolyH: public SMDS_VtkCellIterator +//-------------------------------------------------------------------------------- +template< class SMDS_ITERATOR = SMDS_ElemIterator > +class SMDS_VtkCellIteratorPolyH: public SMDS_VtkCellIterator< SMDS_ITERATOR, _GetVtkNodesPolyh > { + typedef SMDS_VtkCellIterator< SMDS_ITERATOR, _GetVtkNodesPolyh > parent_t; public: - SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType); - virtual ~SMDS_VtkCellIteratorPolyH(); - virtual bool more(); -protected: - int _nbNodesInFaces; + SMDS_VtkCellIteratorPolyH(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType type): + parent_t( mesh, vtkCellId, type ) {} }; #endif diff --git a/src/SMDS/SMDS_VtkEdge.cxx b/src/SMDS/SMDS_VtkEdge.cxx deleted file mode 100644 index edf40f78f..000000000 --- a/src/SMDS/SMDS_VtkEdge.cxx +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2010-2016 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, or (at your option) any later version. -// -// 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 "SMDS_VtkEdge.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_Mesh.hxx" -#include "SMDS_VtkCellIterator.hxx" - -#include "utilities.h" - -#include -#include - -using namespace std; - -SMDS_VtkEdge::SMDS_VtkEdge() -{ -} - -SMDS_VtkEdge::SMDS_VtkEdge(std::vector& nodeIds, SMDS_Mesh* mesh) -{ - init(nodeIds, mesh); -} - -SMDS_VtkEdge::~SMDS_VtkEdge() -{ -} - -void SMDS_VtkEdge::init(std::vector& nodeIds, SMDS_Mesh* mesh) -{ - SMDS_MeshEdge::init(); - myMeshId = mesh->getMeshId(); - vtkIdType aType = ( nodeIds.size() == 3 ) ? VTK_QUADRATIC_EDGE : VTK_LINE; - myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); - mesh->setMyModified(); -} - -bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2) -{ - const SMDS_MeshNode* nodes[] = { node1, node2 }; - SMDS_Mesh::_meshList[myMeshId]->setMyModified(); - return ChangeNodes(nodes, 2); -} - -bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - if (nbNodes != npts) - { - MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); - return false; - } - for (int i = 0; i < nbNodes; i++) - { - pts[i] = nodes[i]->getVtkId(); - } - SMDS_Mesh::_meshList[myMeshId]->setMyModified(); - return true; -} - -bool SMDS_VtkEdge::IsMediumNode(const SMDS_MeshNode* node) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - return ((npts == 3) && (node->getVtkId() == pts[2])); -} - -void SMDS_VtkEdge::Print(std::ostream & OS) const -{ - OS << "edge <" << GetID() << "> : "; -} - -int SMDS_VtkEdge::NbNodes() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType *pts, npts; - grid->GetCellPoints( myVtkID, npts, pts ); - assert(npts >= 2); - return npts; -} - -int SMDS_VtkEdge::NbEdges() const -{ - return 1; -} - -SMDSAbs_EntityType SMDS_VtkEdge::GetEntityType() const -{ - if (NbNodes() == 2) - return SMDSEntity_Edge; - else - return SMDSEntity_Quad_Edge; -} - -vtkIdType SMDS_VtkEdge::GetVtkType() const -{ - if (NbNodes() == 2) - return VTK_LINE; - else - return VTK_QUADRATIC_EDGE; - -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* -SMDS_VtkEdge::GetNode(const int ind) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts, *pts; - grid->GetCellPoints( this->myVtkID, npts, pts ); - return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]); -} - -bool SMDS_VtkEdge::IsQuadratic() const -{ - if (this->NbNodes() > 2) - return true; - else - return false; -} - -SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) const -{ - switch (type) - { - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); - default: - MESSAGE("ERROR : Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); - } -} - -SMDS_NodeIteratorPtr SMDS_VtkEdge::nodesIteratorToUNV() const -{ - return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); -} - -SMDS_NodeIteratorPtr SMDS_VtkEdge::interlacedNodesIterator() const -{ - return nodesIteratorToUNV(); -} diff --git a/src/SMDS/SMDS_VtkEdge.hxx b/src/SMDS/SMDS_VtkEdge.hxx deleted file mode 100644 index aebfb6e0b..000000000 --- a/src/SMDS/SMDS_VtkEdge.hxx +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2010-2016 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, or (at your option) any later version. -// -// 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 -// - -// SMESH SMDS : implementation of Salome mesh data structure -// File : SMDS_VtkEdge.hxx -// Module : SMESH - -#ifndef _SMDS_VTKEDGE_HXX_ -#define _SMDS_VTKEDGE_HXX_ - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshEdge.hxx" -#include -#include - -class SMDS_EXPORT SMDS_VtkEdge: public SMDS_MeshEdge -{ - -public: - SMDS_VtkEdge(); - SMDS_VtkEdge(std::vector& nodeIds, SMDS_Mesh* mesh); - ~SMDS_VtkEdge(); - void init(std::vector& nodeIds, SMDS_Mesh* mesh); - bool ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2); - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); - virtual bool IsMediumNode(const SMDS_MeshNode* node) const; - - virtual void Print(std::ostream & OS) const; - virtual int NbNodes() const; - virtual int NbEdges() const; - - virtual vtkIdType GetVtkType() const; - virtual SMDSAbs_EntityType GetEntityType() const; - virtual const SMDS_MeshNode* GetNode(const int ind) const; - virtual bool IsQuadratic() const; - - virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const; - virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const; -protected: -}; -#endif diff --git a/src/SMDS/SMDS_VtkFace.cxx b/src/SMDS/SMDS_VtkFace.cxx deleted file mode 100644 index 724a7ec21..000000000 --- a/src/SMDS/SMDS_VtkFace.cxx +++ /dev/null @@ -1,334 +0,0 @@ -// Copyright (C) 2010-2016 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, or (at your option) any later version. -// -// 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 "SMDS_VtkFace.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_Mesh.hxx" -#include "SMDS_VtkCellIterator.hxx" - -#include "utilities.h" - -#include - -using namespace std; - -SMDS_VtkFace::SMDS_VtkFace() -{ -} - -SMDS_VtkFace::SMDS_VtkFace(const std::vector& nodeIds, SMDS_Mesh* mesh) -{ - init(nodeIds, mesh); -} - -SMDS_VtkFace::~SMDS_VtkFace() -{ -} - -void SMDS_VtkFace::init(const std::vector& nodeIds, SMDS_Mesh* mesh) -{ - SMDS_MeshFace::init(); - myMeshId = mesh->getMeshId(); - vtkIdType aType = VTK_TRIANGLE; - switch (nodeIds.size()) - { - case 3: aType = VTK_TRIANGLE; break; - case 4: aType = VTK_QUAD; break; - case 6: aType = VTK_QUADRATIC_TRIANGLE; break; - case 8: aType = VTK_QUADRATIC_QUAD; break; - case 9: aType = VTK_BIQUADRATIC_QUAD; break; - case 7: aType = VTK_BIQUADRATIC_TRIANGLE;break; - default: aType = VTK_POLYGON; - } - myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]); - mesh->setMyModified(); -} - -void SMDS_VtkFace::initPoly(const std::vector& nodeIds, SMDS_Mesh* mesh) -{ - SMDS_MeshFace::init(); - myMeshId = mesh->getMeshId(); - vtkIdType aType = VTK_POLYGON; - myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]); - mesh->setMyModified(); -} - -void SMDS_VtkFace::initQuadPoly(const std::vector& nodeIds, SMDS_Mesh* mesh) -{ - SMDS_MeshFace::init(); - myMeshId = mesh->getMeshId(); - vtkIdType aType = VTK_QUADRATIC_POLYGON; - myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]); - mesh->setMyModified(); -} - -bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - if (nbNodes != npts) - { - MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); - return false; - } - for (int i = 0; i < nbNodes; i++) - { - pts[i] = nodes[i]->getVtkId(); - } - SMDS_Mesh::_meshList[myMeshId]->setMyModified(); - return true; -} - -void SMDS_VtkFace::Print(std::ostream & OS) const -{ - OS << "face <" << GetID() << "> : "; -} - -int SMDS_VtkFace::NbEdges() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - int nbEdges = 3; - switch (aVtkType) - { - case VTK_TRIANGLE: - case VTK_QUADRATIC_TRIANGLE: - case VTK_BIQUADRATIC_TRIANGLE: - nbEdges = 3; - break; - case VTK_QUAD: - case VTK_QUADRATIC_QUAD: - case VTK_BIQUADRATIC_QUAD: - nbEdges = 4; - break; - case VTK_QUADRATIC_POLYGON: - nbEdges = NbNodes() / 2; - break; - case VTK_POLYGON: - default: - nbEdges = NbNodes(); - break; - } - return nbEdges; -} - -int SMDS_VtkFace::NbFaces() const -{ - return 1; -} - -int SMDS_VtkFace::NbNodes() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType *pts, npts; - grid->GetCellPoints( myVtkID, npts, pts ); - return npts; -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* -SMDS_VtkFace::GetNode(const int ind) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts, *pts; - grid->GetCellPoints( this->myVtkID, npts, pts ); - return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]); -} - -/*! - * \brief Check if a node belongs to the element - * \param node - the node to check - * \retval int - node index within the element, -1 if not found - */ -int SMDS_VtkFace::GetNodeIndex( const SMDS_MeshNode* node ) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts, *pts; - grid->GetCellPoints( this->myVtkID, npts, pts ); - for ( vtkIdType i = 0; i < npts; ++i ) - if ( pts[i] == node->getVtkId() ) - return i; - return -1; -} - -bool SMDS_VtkFace::IsQuadratic() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - // TODO quadratic polygons ? - switch (aVtkType) - { - case VTK_QUADRATIC_TRIANGLE: - case VTK_QUADRATIC_QUAD: - case VTK_QUADRATIC_POLYGON: - case VTK_BIQUADRATIC_QUAD: - case VTK_BIQUADRATIC_TRIANGLE: - return true; - break; - default: - return false; - } -} - -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 SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - int rankFirstMedium = 0; - switch (aVtkType) - { - case VTK_QUADRATIC_TRIANGLE: - case VTK_BIQUADRATIC_TRIANGLE: - rankFirstMedium = 3; // medium nodes are of rank 3,4,5 - break; - case VTK_QUADRATIC_QUAD: - case VTK_BIQUADRATIC_QUAD: - rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7 - break; - case VTK_QUADRATIC_POLYGON: - rankFirstMedium = npts / 2; - break; - default: - //MESSAGE("wrong element type " << aVtkType); - return false; - } - vtkIdType nodeId = node->getVtkId(); - for (int rank = 0; rank < npts; rank++) - { - if (pts[rank] == nodeId) - { - //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium)); - if (rank < rankFirstMedium) - return false; - else - return true; - } - } - //throw SALOME_Exception(LOCALIZED("node does not belong to this element")); - MESSAGE("======================================================"); - MESSAGE("= IsMediumNode: node does not belong to this element ="); - MESSAGE("======================================================"); - return false; -} - -int SMDS_VtkFace::NbCornerNodes() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - int nbPoints = NbNodes(); - vtkIdType aVtkType = grid->GetCellType(myVtkID); - switch ( aVtkType ) - { - case VTK_POLYGON: - break; - case VTK_QUADRATIC_POLYGON: - nbPoints /= 2; - break; - default: - if ( nbPoints > 4 ) - nbPoints /= 2; - } - return nbPoints; -} - -SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - return SMDS_MeshCell::toSmdsType( VTKCellType( aVtkType )); -} - -SMDSAbs_GeometryType SMDS_VtkFace::GetGeomType() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - switch ( aVtkType ) { - case VTK_TRIANGLE: - case VTK_QUADRATIC_TRIANGLE: - case VTK_BIQUADRATIC_TRIANGLE: return SMDSGeom_TRIANGLE; - - case VTK_QUAD: - case VTK_QUADRATIC_QUAD: - case VTK_BIQUADRATIC_QUAD: return SMDSGeom_QUADRANGLE; - - case VTK_POLYGON: - case VTK_QUADRATIC_POLYGON: return SMDSGeom_POLYGON; - default:; - } - return SMDSGeom_NONE; -} - -vtkIdType SMDS_VtkFace::GetVtkType() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - return aVtkType; -} - -SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const -{ - switch (type) - { - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); - default: - MESSAGE("ERROR : Iterator not implemented") - ; - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); - } -} - -SMDS_NodeIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const -{ - return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); -} - -SMDS_NodeIteratorPtr SMDS_VtkFace::interlacedNodesIterator() const -{ - return nodesIteratorToUNV(); -} - -//! change only the first node, used for temporary triangles in quadrangle to triangle adaptor -void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node) -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - grid->RemoveReferenceToCell(pts[0], myVtkID); - pts[0] = node->getVtkId(); - node->AddInverseElement(this), - SMDS_Mesh::_meshList[myMeshId]->setMyModified(); -} diff --git a/src/SMDS/SMDS_VtkFace.hxx b/src/SMDS/SMDS_VtkFace.hxx deleted file mode 100644 index 50c49a0a8..000000000 --- a/src/SMDS/SMDS_VtkFace.hxx +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2010-2016 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, or (at your option) any later version. -// -// 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 _SMDS_VTKFACE_HXX_ -#define _SMDS_VTKFACE_HXX_ - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshFace.hxx" -#include -#include - -class SMDS_EXPORT SMDS_VtkFace: public SMDS_MeshFace -{ -public: - SMDS_VtkFace(); - SMDS_VtkFace(const std::vector& nodeIds, SMDS_Mesh* mesh); - ~SMDS_VtkFace(); - void init(const std::vector& nodeIds, SMDS_Mesh* mesh); - void initPoly(const std::vector& nodeIds, SMDS_Mesh* mesh); - void initQuadPoly(const std::vector& nodeIds, SMDS_Mesh* mesh); - - bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); - void ChangeApex(SMDS_MeshNode* node); // to use only for tmp triangles - - virtual void Print(std::ostream & OS) const; - virtual int NbEdges() const; - virtual int NbFaces() const; - virtual int NbNodes() const; - - virtual vtkIdType GetVtkType() const; - virtual SMDSAbs_EntityType GetEntityType() const; - virtual SMDSAbs_GeometryType GetGeomType() const; - virtual const SMDS_MeshNode* GetNode(const int ind) const; - virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; - - virtual bool IsQuadratic() const; - virtual bool IsPoly() const; - virtual bool IsMediumNode(const SMDS_MeshNode* node) const; - virtual int NbCornerNodes() const; - - virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const; - virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const; -protected: -}; - -#endif diff --git a/src/SMDS/SMDS_VtkVolume.cxx b/src/SMDS/SMDS_VtkVolume.cxx deleted file mode 100644 index ecbcd928d..000000000 --- a/src/SMDS/SMDS_VtkVolume.cxx +++ /dev/null @@ -1,698 +0,0 @@ -// Copyright (C) 2010-2016 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, or (at your option) any later version. -// -// 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 "SMDS_VtkVolume.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_Mesh.hxx" -#include "SMDS_VtkCellIterator.hxx" - -#include "utilities.h" - -#include - -SMDS_VtkVolume::SMDS_VtkVolume() -{ -} - -SMDS_VtkVolume::SMDS_VtkVolume(const std::vector& nodeIds, SMDS_Mesh* mesh) -{ - init(nodeIds, mesh); -} -/*! - * typed used are vtk types (@see vtkCellType.h) - * see GetEntityType() for conversion in SMDS type (@see SMDSAbs_ElementType.hxx) - */ -void SMDS_VtkVolume::init(const std::vector& nodeIds, SMDS_Mesh* mesh) -{ - SMDS_MeshVolume::init(); - myMeshId = mesh->getMeshId(); - vtkIdType aType = VTK_TETRA; - switch (nodeIds.size()) // cases are in order of usage frequency - { - case 4: aType = VTK_TETRA; break; - case 8: aType = VTK_HEXAHEDRON; break; - case 5: aType = VTK_PYRAMID; break; - case 6: aType = VTK_WEDGE; break; - case 10: aType = VTK_QUADRATIC_TETRA; break; - case 20: aType = VTK_QUADRATIC_HEXAHEDRON; break; - case 13: aType = VTK_QUADRATIC_PYRAMID; break; - case 15: aType = VTK_QUADRATIC_WEDGE; break; - case 18: aType = VTK_BIQUADRATIC_QUADRATIC_WEDGE; break; - case 12: aType = VTK_HEXAGONAL_PRISM; break; - case 27: aType = VTK_TRIQUADRATIC_HEXAHEDRON; break; - default: aType = VTK_HEXAHEDRON; - } - myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType *) &nodeIds[0]); - mesh->setMyModified(); -} - -void SMDS_VtkVolume::initPoly(const std::vector& nodeIds, - const std::vector& nbNodesPerFace, - SMDS_Mesh* mesh) -{ - SMDS_MeshVolume::init(); - SMDS_UnstructuredGrid* grid = mesh->getGrid(); - //double center[3]; - //this->gravityCenter(grid, &nodeIds[0], nodeIds.size(), ¢er[0]); - std::vector ptIds; - vtkIdType nbFaces = nbNodesPerFace.size(); - int k = 0; - for (int i = 0; i < nbFaces; i++) - { - int nf = nbNodesPerFace[i]; - ptIds.push_back(nf); - // EAP: a right approach is: - // - either the user should care of order of nodes or - // - the user should use a service method arranging nodes if he - // don't want or can't to do it by him-self - // The method below works OK only with planar faces and convex polyhedrones - // - // double a[3]; - // double b[3]; - // double c[3]; - // grid->GetPoints()->GetPoint(nodeIds[k], a); - // grid->GetPoints()->GetPoint(nodeIds[k + 1], b); - // grid->GetPoints()->GetPoint(nodeIds[k + 2], c); - // bool isFaceForward = this->isForward(a, b, c, center); - const vtkIdType *facePts = &nodeIds[k]; - //if (isFaceForward) - for (int n = 0; n < nf; n++) - ptIds.push_back(facePts[n]); - // else - // for (int n = nf - 1; n >= 0; n--) - // ptIds.push_back(facePts[n]); - k += nf; - } - myVtkID = grid->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]); - mesh->setMyModified(); -} - -bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - if (nbNodes != npts) - { - MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes); - return false; - } - for (int i = 0; i < nbNodes; i++) - { - pts[i] = nodes[i]->getVtkId(); - } - SMDS_Mesh::_meshList[myMeshId]->setMyModified(); - return true; -} - -/*! - * Reorder in VTK order a list of nodes given in SMDS order. - * To be used before ChangeNodes: lists are given or computed in SMDS order. - */ -bool SMDS_VtkVolume::vtkOrder(const SMDS_MeshNode* nodes[], const int nbNodes) -{ - if (nbNodes != this->NbNodes()) - { - MESSAGE("vtkOrder, wrong number of nodes " << nbNodes << " instead of "<< this->NbNodes()); - return false; - } - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - const std::vector& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( aVtkType )); - if ( !interlace.empty() ) - { - ASSERT( (int)interlace.size() == nbNodes ); - std::vector initNodes( nodes, nodes+nbNodes ); - for ( size_t i = 0; i < interlace.size(); ++i ) - nodes[i] = initNodes[ interlace[i] ]; - } - return true; -} - -SMDS_VtkVolume::~SMDS_VtkVolume() -{ -} - -void SMDS_VtkVolume::Print(ostream & OS) const -{ - OS << "volume <" << GetID() << "> : "; -} - -int SMDS_VtkVolume::NbFaces() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - int nbFaces = 4; - switch (aVtkType) - { - case VTK_TETRA: - case VTK_QUADRATIC_TETRA: - nbFaces = 4; - break; - case VTK_PYRAMID: - case VTK_WEDGE: - case VTK_QUADRATIC_PYRAMID: - case VTK_QUADRATIC_WEDGE: - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - nbFaces = 5; - break; - case VTK_HEXAHEDRON: - case VTK_QUADRATIC_HEXAHEDRON: - case VTK_TRIQUADRATIC_HEXAHEDRON: - nbFaces = 6; - break; - case VTK_POLYHEDRON: - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - nbFaces = nFaces; - break; - } - case VTK_HEXAGONAL_PRISM: - nbFaces = 8; - break; - default: - MESSAGE("invalid volume type") - ; - nbFaces = 0; - break; - } - return nbFaces; -} - -int SMDS_VtkVolume::NbNodes() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - vtkIdType nbPoints = 0; - if (aVtkType != VTK_POLYHEDRON) - { - vtkIdType *pts; - grid->GetCellPoints( myVtkID, nbPoints, pts ); - } - else - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - int id = 0; - for (int i = 0; i < nFaces; i++) - { - int nodesInFace = ptIds[id]; - nbPoints += nodesInFace; - id += (nodesInFace + 1); - } - } - return nbPoints; -} - -int SMDS_VtkVolume::NbEdges() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - int nbEdges = 6; - switch (aVtkType) - { - case VTK_TETRA: - case VTK_QUADRATIC_TETRA: - nbEdges = 6; - break; - case VTK_PYRAMID: - case VTK_QUADRATIC_PYRAMID: - nbEdges = 8; - break; - case VTK_WEDGE: - case VTK_QUADRATIC_WEDGE: - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - nbEdges = 9; - break; - case VTK_HEXAHEDRON: - case VTK_QUADRATIC_HEXAHEDRON: - case VTK_TRIQUADRATIC_HEXAHEDRON: - nbEdges = 12; - break; - case VTK_POLYHEDRON: - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - nbEdges = 0; - int id = 0; - for (int i = 0; i < nFaces; i++) - { - int edgesInFace = ptIds[id]; - id += (edgesInFace + 1); - nbEdges += edgesInFace; - } - nbEdges = nbEdges / 2; - break; - } - case VTK_HEXAGONAL_PRISM: - nbEdges = 18; - break; - default: - MESSAGE("invalid volume type") - ; - nbEdges = 0; - break; - } - return nbEdges; -} - -/*! polyhedron only, - * 1 <= face_ind <= NbFaces() - */ -int SMDS_VtkVolume::NbFaceNodes(const int face_ind) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - int nbNodes = 0; - if (aVtkType == VTK_POLYHEDRON) - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - int id = 0; - for (int i = 0; i < nFaces; i++) - { - int nodesInFace = ptIds[id]; - id += (nodesInFace + 1); - if (i == face_ind - 1) - { - nbNodes = nodesInFace; - break; - } - } - } - return nbNodes; -} - -/*! polyhedron only, - * 1 <= face_ind <= NbFaces() - * 1 <= node_ind <= NbFaceNodes() - */ -const SMDS_MeshNode* SMDS_VtkVolume::GetFaceNode(const int face_ind, const int node_ind) const -{ - SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId]; - vtkUnstructuredGrid* grid = mesh->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - const SMDS_MeshNode* node = 0; - if (aVtkType == VTK_POLYHEDRON) - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - int id = 0; - for (int i = 0; i < nFaces; i++) - { - int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace] - if (i == face_ind - 1) // first face is number 1 - { - if ((node_ind > 0) && (node_ind <= nodesInFace)) - node = mesh->FindNodeVtk(ptIds[id + node_ind]); // ptIds[id+1] : first node - break; - } - id += (nodesInFace + 1); - } - } - return node; -} - -/*! polyhedron only, - * return number of nodes for each face - */ -std::vector SMDS_VtkVolume::GetQuantities() const -{ - std::vector quantities; - SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId]; - vtkUnstructuredGrid* grid = mesh->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - if (aVtkType == VTK_POLYHEDRON) - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - int id = 0; - for (int i = 0; i < nFaces; i++) - { - int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace] - quantities.push_back(nodesInFace); - id += (nodesInFace + 1); - } - } - return quantities; -} - -SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) const -{ - switch (type) - { - case SMDSAbs_Node: - { - SMDSAbs_EntityType aType = this->GetEntityType(); - if (aType == SMDSEntity_Polyhedra) - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorPolyH(SMDS_Mesh::_meshList[myMeshId], myVtkID, aType)); - else - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, aType)); - } - default: - MESSAGE("ERROR : Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); - } -} - -SMDS_NodeIteratorPtr SMDS_VtkVolume::nodesIteratorToUNV() const -{ - return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); -} - -SMDS_NodeIteratorPtr SMDS_VtkVolume::interlacedNodesIterator() const -{ - return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); -} - -SMDSAbs_ElementType SMDS_VtkVolume::GetType() const -{ - return SMDSAbs_Volume; -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - if ( aVtkType == VTK_POLYHEDRON) - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - int id = 0, nbPoints = 0; - for (int i = 0; i < nFaces; i++) - { - int nodesInFace = ptIds[id]; - if ( ind < nbPoints + nodesInFace ) - return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( ptIds[ ind + i ]); - nbPoints += nodesInFace; - id += (nodesInFace + 1); - } - return 0; - } - vtkIdType npts, *pts; - grid->GetCellPoints( this->myVtkID, npts, pts ); - const std::vector& interlace = SMDS_MeshCell::fromVtkOrder( VTKCellType( aVtkType )); - return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ interlace.empty() ? ind : interlace[ind]] ); -} -/*! - * \brief Check if a node belongs to the element - * \param node - the node to check - * \retval int - node index within the element, -1 if not found - */ -int SMDS_VtkVolume::GetNodeIndex( const SMDS_MeshNode* node ) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - const vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - if ( aVtkType == VTK_POLYHEDRON) - { - vtkIdType nFaces = 0; - vtkIdType* ptIds = 0; - grid->GetFaceStream(this->myVtkID, nFaces, ptIds); - int id = 0; - for (int iF = 0; iF < nFaces; iF++) - { - int nodesInFace = ptIds[id]; - for ( vtkIdType i = 0; i < nodesInFace; ++i ) - if ( ptIds[id+i+1] == node->getVtkId() ) - return id+i-iF; - id += (nodesInFace + 1); - } - return -1; - } - vtkIdType npts, *pts; - grid->GetCellPoints( this->myVtkID, npts, pts ); - for ( vtkIdType i = 0; i < npts; ++i ) - if ( pts[i] == node->getVtkId() ) - { - const std::vector& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( aVtkType )); - return interlace.empty() ? i : interlace[i]; - } - return -1; -} - -bool SMDS_VtkVolume::IsQuadratic() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - // TODO quadratic polyhedrons ? - switch (aVtkType) - { - case VTK_QUADRATIC_TETRA: - case VTK_QUADRATIC_PYRAMID: - case VTK_QUADRATIC_WEDGE: - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - case VTK_QUADRATIC_HEXAHEDRON: - case VTK_TRIQUADRATIC_HEXAHEDRON: - return true; - break; - default: - return false; - } -} - -bool SMDS_VtkVolume::IsPoly() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - return (aVtkType == VTK_POLYHEDRON); -} - -bool SMDS_VtkVolume::IsMediumNode(const SMDS_MeshNode* node) const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - int rankFirstMedium = 0; - switch (aVtkType) - { - case VTK_QUADRATIC_TETRA: - rankFirstMedium = 4; // medium nodes are of rank 4 to 9 - break; - case VTK_QUADRATIC_PYRAMID: - rankFirstMedium = 5; // medium nodes are of rank 5 to 12 - break; - case VTK_QUADRATIC_WEDGE: - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - rankFirstMedium = 6; // medium nodes are of rank 6 to 14 - break; - case VTK_QUADRATIC_HEXAHEDRON: - case VTK_TRIQUADRATIC_HEXAHEDRON: - rankFirstMedium = 8; // medium nodes are of rank 8 to 19 - break; - default: - return false; - } - vtkIdType npts = 0; - vtkIdType* pts = 0; - grid->GetCellPoints(myVtkID, npts, pts); - vtkIdType nodeId = node->getVtkId(); - for (int rank = 0; rank < npts; rank++) - { - if (pts[rank] == nodeId) - { - if (rank < rankFirstMedium) - return false; - else - return true; - } - } - MESSAGE("======================================================"); - MESSAGE("= IsMediumNode: node does not belong to this element ="); - MESSAGE("======================================================"); - return false; -} - -int SMDS_VtkVolume::NbCornerNodes() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(myVtkID); - switch (aVtkType) - { - case VTK_QUADRATIC_TETRA: return 4; - case VTK_QUADRATIC_PYRAMID: return 5; - case VTK_QUADRATIC_WEDGE: - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: return 6; - case VTK_QUADRATIC_HEXAHEDRON: - case VTK_TRIQUADRATIC_HEXAHEDRON: return 8; - default:; - } - return NbNodes(); -} - -SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - - SMDSAbs_EntityType aType = SMDSEntity_Tetra; - switch (aVtkType) - { - case VTK_TETRA: - aType = SMDSEntity_Tetra; - break; - case VTK_PYRAMID: - aType = SMDSEntity_Pyramid; - break; - case VTK_WEDGE: - aType = SMDSEntity_Penta; - break; - case VTK_HEXAHEDRON: - aType = SMDSEntity_Hexa; - break; - case VTK_QUADRATIC_TETRA: - aType = SMDSEntity_Quad_Tetra; - break; - case VTK_QUADRATIC_PYRAMID: - aType = SMDSEntity_Quad_Pyramid; - break; - case VTK_QUADRATIC_WEDGE: - aType = SMDSEntity_Quad_Penta; - break; - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - aType = SMDSEntity_BiQuad_Penta; - break; - case VTK_QUADRATIC_HEXAHEDRON: - aType = SMDSEntity_Quad_Hexa; - break; - case VTK_TRIQUADRATIC_HEXAHEDRON: - aType = SMDSEntity_TriQuad_Hexa; - break; - case VTK_HEXAGONAL_PRISM: - aType = SMDSEntity_Hexagonal_Prism; - break; - case VTK_POLYHEDRON: - aType = SMDSEntity_Polyhedra; - break; - default: - aType = SMDSEntity_Polyhedra; - break; - } - return aType; -} - -SMDSAbs_GeometryType SMDS_VtkVolume::GetGeomType() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aVtkType = grid->GetCellType(this->myVtkID); - - SMDSAbs_GeometryType aType = SMDSGeom_NONE; - switch (aVtkType) - { - case VTK_TETRA: - case VTK_QUADRATIC_TETRA: - aType = SMDSGeom_TETRA; - break; - case VTK_PYRAMID: - case VTK_QUADRATIC_PYRAMID: - aType = SMDSGeom_PYRAMID; - break; - case VTK_WEDGE: - case VTK_QUADRATIC_WEDGE: - case VTK_BIQUADRATIC_QUADRATIC_WEDGE: - aType = SMDSGeom_PENTA; - break; - case VTK_HEXAHEDRON: - case VTK_QUADRATIC_HEXAHEDRON: - case VTK_TRIQUADRATIC_HEXAHEDRON: - aType = SMDSGeom_HEXA; - break; - case VTK_HEXAGONAL_PRISM: - aType = SMDSGeom_HEXAGONAL_PRISM; - break; - case VTK_POLYHEDRON: - aType = SMDSGeom_POLYHEDRA; - break; - default: - aType = SMDSGeom_POLYHEDRA; - break; - } - return aType; -} - -vtkIdType SMDS_VtkVolume::GetVtkType() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkIdType aType = grid->GetCellType(myVtkID); - return aType; -} - -void SMDS_VtkVolume::gravityCenter(SMDS_UnstructuredGrid* grid, - const vtkIdType * nodeIds, - int nbNodes, - double* result) -{ - for (int j = 0; j < 3; j++) - result[j] = 0; - if (nbNodes <= 0) - return; - for (int i = 0; i < nbNodes; i++) - { - double *coords = grid->GetPoint(nodeIds[i]); - for (int j = 0; j < 3; j++) - result[j] += coords[j]; - } - for (int j = 0; j < 3; j++) - result[j] = result[j] / nbNodes; - return; -} - -bool SMDS_VtkVolume::isForward(double* a, double* b, double* c, double* d) -{ - double u[3], v[3], w[3]; - for (int j = 0; j < 3; j++) - { - u[j] = b[j] - a[j]; - v[j] = c[j] - a[j]; - w[j] = d[j] - a[j]; - } - double prodmixte = ((u[1]*v[2] - u[2]*v[1]) * w[0] - + (u[2]*v[0] - u[0]*v[2]) * w[1] - + (u[0]*v[1] - u[1]*v[0]) * w[2] ); - return (prodmixte < 0); -} - -/*! For polyhedron only - * @return actual number of nodes (not the sum of nodes of all faces) - */ -int SMDS_VtkVolume::NbUniqueNodes() const -{ - vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - return grid->GetCell(myVtkID)->GetNumberOfPoints(); -} - -/*! For polyhedron use only - * @return iterator on actual nodes (not through the faces) - */ -SMDS_ElemIteratorPtr SMDS_VtkVolume::uniqueNodesIterator() const -{ - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); -} diff --git a/src/SMDS/SMDS_VtkVolume.hxx b/src/SMDS/SMDS_VtkVolume.hxx deleted file mode 100644 index 02f86ce2a..000000000 --- a/src/SMDS/SMDS_VtkVolume.hxx +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2010-2016 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, or (at your option) any later version. -// -// 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 _SMDS_VTKVOLUME_HXX_ -#define _SMDS_VTKVOLUME_HXX_ - -#include "SMESH_SMDS.hxx" - -#include "SMDS_MeshVolume.hxx" -#include "SMDS_UnstructuredGrid.hxx" -#include - -class SMDS_EXPORT SMDS_VtkVolume: public SMDS_MeshVolume -{ -public: - SMDS_VtkVolume(); - SMDS_VtkVolume(const std::vector& nodeIds, SMDS_Mesh* mesh); - ~SMDS_VtkVolume(); - void init(const std::vector& nodeIds, SMDS_Mesh* mesh); -//#ifdef VTK_HAVE_POLYHEDRON - void initPoly(const std::vector& nodeIds, - const std::vector& nbNodesPerFace, SMDS_Mesh* mesh); -//#endif - virtual bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); - virtual bool vtkOrder(const SMDS_MeshNode* nodes[], const int nbNodes); - - virtual void Print(std::ostream & OS) const; - virtual int NbFaces() const; - virtual int NbNodes() const; - virtual int NbEdges() const; - - // 1 <= face_ind <= NbFaces() - int NbFaceNodes (const int face_ind) const; - // 1 <= face_ind <= NbFaces() - // 1 <= node_ind <= NbFaceNodes() - const SMDS_MeshNode* GetFaceNode (const int face_ind, const int node_ind) const; - - virtual SMDSAbs_ElementType GetType() const; - virtual vtkIdType GetVtkType() const; - virtual SMDSAbs_EntityType GetEntityType() const; - virtual SMDSAbs_GeometryType GetGeomType() const; - virtual const SMDS_MeshNode* GetNode(const int ind) const; - virtual int GetNodeIndex( const SMDS_MeshNode* node ) const; - virtual bool IsQuadratic() const; - virtual bool IsPoly() const; - virtual bool IsMediumNode(const SMDS_MeshNode* node) const; - virtual int NbCornerNodes() const; - static void gravityCenter(SMDS_UnstructuredGrid* grid, - const vtkIdType *nodeIds, - int nbNodes, - double* result); - static bool isForward(double* a,double* b,double* c,double* d); - int NbUniqueNodes() const; - SMDS_ElemIteratorPtr uniqueNodesIterator() const; - std::vector GetQuantities() const; - - virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const; - virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const; - -protected: -}; - -#endif diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 561f64471..d0ee85cb8 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -358,12 +358,9 @@ bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh, SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes(); while ( nIt->more() ) { - const SMDS_MeshNode* node = nIt->next(); - const SMDS_PositionPtr& pos = node->GetPosition(); - if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE ) + SMDS_EdgePositionPtr epos = nIt->next()->GetPosition(); + if ( !epos ) return false; - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition()); if ( !paramSet.insert( epos->GetUParameter() ).second ) return false; // equal parameters } @@ -424,11 +421,9 @@ bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theM const SMDS_MeshNode* node = nIt->next(); if ( ignoreMediumNodes && SMESH_MesherHelper::IsMedium( node, typeToCheck )) continue; - const SMDS_PositionPtr& pos = node->GetPosition(); - if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE ) + SMDS_EdgePositionPtr epos = node->GetPosition(); + if ( ! epos ) return false; - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition()); theNodes.insert( theNodes.end(), make_pair( epos->GetUParameter(), node )); ++nbNodes; } @@ -914,7 +909,12 @@ bool SMESH_Algo::error(SMESH_ComputeErrorPtr error) if ( error ) { _error = error->myName; _comment = error->myComment; - _badInputElements = error->myBadElements; + if ( error->HasBadElems() ) + { + SMESH_BadInputElements* badElems = static_cast( error.get() ); + _badInputElements = badElems->GetElements(); + _mesh = badElems->GetMesh(); + } return error->IsOK(); } return true; @@ -928,11 +928,15 @@ bool SMESH_Algo::error(SMESH_ComputeErrorPtr error) SMESH_ComputeErrorPtr SMESH_Algo::GetComputeError() const { - SMESH_ComputeErrorPtr err = SMESH_ComputeError::New( _error, _comment, this ); - // hope this method is called by only SMESH_subMesh after this->Compute() - err->myBadElements.splice( err->myBadElements.end(), - (list&) _badInputElements ); - return err; + if ( !_badInputElements.empty() && _mesh ) + { + SMESH_BadInputElements* err = new SMESH_BadInputElements( _mesh, _error, _comment, this ); + // hope this method is called by only SMESH_subMesh after this->Compute() + err->myBadElements.splice( err->myBadElements.end(), + (list&) _badInputElements ); + return SMESH_ComputeErrorPtr( err ); + } + return SMESH_ComputeError::New( _error, _comment, this ); } //================================================================================ @@ -950,6 +954,7 @@ void SMESH_Algo::InitComputeError() if ( (*elem)->GetID() < 1 ) delete *elem; _badInputElements.clear(); + _mesh = 0; _computeCanceled = false; _progressTic = 0; @@ -1243,7 +1248,7 @@ bool SMESH_2D_Algo::FixInternalNodes(const SMESH_ProxyMesh& mesh, gp_Pnt p = S->Value( uv.Coord(1), uv.Coord(2)); const SMDS_MeshNode* n = nodeRows[iRow][iCol]; meshDS->MoveNode( n, p.X(), p.Y(), p.Z() ); - if ( SMDS_FacePosition* pos = dynamic_cast< SMDS_FacePosition*>( n->GetPosition() )) + if ( SMDS_FacePositionPtr pos = n->GetPosition() ) pos->SetParameters( uv.Coord(1), uv.Coord(2) ); } } diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index 81ff8eb3a..cceb370ef 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -462,6 +462,7 @@ protected: int _error; //!< SMESH_ComputeErrorName or anything algo specific std::string _comment; //!< any text explaining what is wrong in Compute() std::list _badInputElements; //!< to explain COMPERR_BAD_INPUT_MESH + const SMDS_Mesh* _mesh; //!< mesh being computed, needed to create SMESH_BadInputElements volatile bool _computeCanceled; //!< is set to True while computing to stop it diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index c62e70e32..f87162e45 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -54,9 +54,6 @@ using namespace std; -//#include - - //============================================================================= /*! * Constructor @@ -68,9 +65,7 @@ SMESH_Gen::SMESH_Gen() _localId = 0; _hypId = 0; _segmentation = _nbSegments = 10; - SMDS_Mesh::_meshList.clear(); _compute_canceled = false; - //vtkDebugLeaks::SetExitError(0); } namespace @@ -407,8 +402,10 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, } if ( aCompactMesh ) - aMesh.GetMeshDS()->compactMesh(); - + { + aMesh.GetMeshDS()->Modified(); + aMesh.GetMeshDS()->CompactMesh(); + } return ret; } diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 3e21e9a11..1dcdd5359 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -450,7 +450,7 @@ void SMESH_Mesh::Clear() void SMESH_Mesh::ClearSubMesh(const int theShapeId) { - // clear sub-meshes; get ready to re-compute as a side-effect + // clear sub-meshes; get ready to re-compute as a side-effect if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) ) { SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, @@ -458,7 +458,7 @@ void SMESH_Mesh::ClearSubMesh(const int theShapeId) while ( smIt->more() ) { sm = smIt->next(); - TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); + TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID ) // all other shapes depends on vertices so they are already cleaned sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); @@ -470,7 +470,7 @@ void SMESH_Mesh::ClearSubMesh(const int theShapeId) //======================================================================= //function : UNVToMesh -//purpose : +//purpose : //======================================================================= int SMESH_Mesh::UNVToMesh(const char* theFileName) @@ -485,32 +485,19 @@ int SMESH_Mesh::UNVToMesh(const char* theFileName) myReader.SetMeshId(-1); myReader.Perform(); - if ( SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup() ) + TGroupNamesMap& aGroupNames = myReader.GetGroupNamesMap(); + TGroupNamesMap::iterator gr2names; + int anId = 1 + ( _mapGroup.empty() ? 0 : _mapGroup.rbegin()->first ); + for ( gr2names = aGroupNames.begin(); gr2names != aGroupNames.end(); ++gr2names ) { - TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap(); - aGroup->InitSubGroupsIterator(); - while (aGroup->MoreSubGroups()) - { - SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup(); - string aName = aGroupNames[aSubGroup]; - int aId; - if ( SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId )) - { - SMESHDS_Group* aGroupDS = dynamic_cast( aSMESHGroup->GetGroupDS() ); - if ( aGroupDS ) { - aGroupDS->SetStoreName(aName.c_str()); - aSubGroup->InitIterator(); - const SMDS_MeshElement* aElement = 0; - while ( aSubGroup->More() ) - if (( aElement = aSubGroup->Next() )) - aGroupDS->SMDSGroup().Add( aElement ); - - if (aElement) - aGroupDS->SetType( aElement->GetType() ); - } - } - } + SMDS_MeshGroup* aGroup = gr2names->first; + const std::string& aName = gr2names->second; + SMESHDS_Group* aGroupDS = new SMESHDS_Group( anId++, _myMeshDS, aGroup->GetType() ); + aGroupDS->SMDSGroup() = std::move( *aGroup ); + aGroupDS->SetStoreName( aName.c_str() ); + AddGroup( aGroupDS ); } + return 1; } @@ -551,12 +538,16 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName) } } } + + _myMeshDS->Modified(); + _myMeshDS->CompactMesh(); + return (int) status; } //======================================================================= //function : STLToMesh -//purpose : +//purpose : //======================================================================= std::string SMESH_Mesh::STLToMesh(const char* theFileName) diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index 9b581c9ce..e9dbc5a32 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -162,7 +162,7 @@ SMESH_MeshEditor::ElemFeatures::Init( const SMDS_MeshElement* elem, bool basicOn myIsQuad = elem->IsQuadratic(); if ( myType == SMDSAbs_Volume && !basicOnly ) { - vector quant = static_cast( elem )->GetQuantities(); + vector quant = static_cast( elem )->GetQuantities(); myPolyhedQuantities.swap( quant ); } } @@ -682,16 +682,16 @@ bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshElement * theTria1, { ClearLastCreated(); - if (!theTria1 || !theTria2) + if ( !theTria1 || !theTria2 || + !dynamic_cast( theTria1 ) || + !dynamic_cast( theTria2 ) || + theTria1->GetType() != SMDSAbs_Face || + theTria2->GetType() != SMDSAbs_Face ) return false; - const SMDS_VtkFace* F1 = dynamic_cast( theTria1 ); - if (!F1) return false; - const SMDS_VtkFace* F2 = dynamic_cast( theTria2 ); - if (!F2) return false; if ((theTria1->GetEntityType() == SMDSEntity_Triangle) && - (theTria2->GetEntityType() == SMDSEntity_Triangle)) { - + (theTria2->GetEntityType() == SMDSEntity_Triangle)) + { // 1 +--+ A theTria1: ( 1 A B ) A->2 ( 1 2 B ) 1 +--+ A // | /| theTria2: ( B A 2 ) B->1 ( 1 A 2 ) |\ | // |/ | | \| @@ -805,9 +805,9 @@ bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshElement * theTria1, gp_Pnt xyz; if ( F.IsNull() ) { - xyz = ( SMESH_TNodeXYZ( nodes[3] ) + - SMESH_TNodeXYZ( nodes[4] ) + - SMESH_TNodeXYZ( nodes[5] )) / 3.; + xyz = ( SMESH_NodeXYZ( nodes[3] ) + + SMESH_NodeXYZ( nodes[4] ) + + SMESH_NodeXYZ( nodes[5] )) / 3.; } else { @@ -886,10 +886,10 @@ bool SMESH_MeshEditor::InverseDiag (const SMDS_MeshNode * theNode1, if ( !findTriangles( theNode1, theNode2, tr1, tr2 )) return false; - const SMDS_VtkFace* F1 = dynamic_cast( tr1 ); - if (!F1) return false; - const SMDS_VtkFace* F2 = dynamic_cast( tr2 ); - if (!F2) return false; + if ( !dynamic_cast( tr1 ) || + !dynamic_cast( tr2 )) + return false; + if ((tr1->GetEntityType() == SMDSEntity_Triangle) && (tr2->GetEntityType() == SMDSEntity_Triangle)) { @@ -1006,15 +1006,15 @@ bool SMESH_MeshEditor::DeleteDiag (const SMDS_MeshNode * theNode1, if ( !findTriangles( theNode1, theNode2, tr1, tr2 )) return false; - const SMDS_VtkFace* F1 = dynamic_cast( tr1 ); - if (!F1) return false; - const SMDS_VtkFace* F2 = dynamic_cast( tr2 ); - if (!F2) return false; + if ( !dynamic_cast( tr1 ) || + !dynamic_cast( tr2 )) + return false; + SMESHDS_Mesh * aMesh = GetMeshDS(); if ((tr1->GetEntityType() == SMDSEntity_Triangle) && - (tr2->GetEntityType() == SMDSEntity_Triangle)) { - + (tr2->GetEntityType() == SMDSEntity_Triangle)) + { const SMDS_MeshNode* aNodes [ 4 ]; if ( ! getQuadrangleNodes( aNodes, theNode1, theNode2, tr1, tr2 )) return false; @@ -1025,9 +1025,8 @@ bool SMESH_MeshEditor::DeleteDiag (const SMDS_MeshNode * theNode1, AddToSameGroups( newElem, tr1, aMesh ); int aShapeId = tr1->getshapeId(); if ( aShapeId ) - { aMesh->SetMeshElementOnShape( newElem, aShapeId ); - } + aMesh->RemoveElement( tr1 ); aMesh->RemoveElement( tr2 ); @@ -1109,8 +1108,7 @@ bool SMESH_MeshEditor::Reorient (const SMDS_MeshElement * theElem) const SMDSAbs_EntityType geomType = theElem->GetEntityType(); if ( geomType == SMDSEntity_Polyhedra ) // polyhedron { - const SMDS_VtkVolume* aPolyedre = - dynamic_cast( theElem ); + const SMDS_MeshVolume* aPolyedre = SMDS_Mesh::DownCast< SMDS_MeshVolume >( theElem ); if (!aPolyedre) { MESSAGE("Warning: bad volumic element"); return false; @@ -1168,7 +1166,7 @@ int SMESH_MeshEditor::Reorient2D (TIDSortedElemSet & theFaces, if ( theFaces.empty() ) { - SMDS_FaceIteratorPtr fIt = GetMeshDS()->facesIterator(/*idInceasingOrder=*/true); + SMDS_FaceIteratorPtr fIt = GetMeshDS()->facesIterator(/*idInceasingOrder=true*/); while ( fIt->more() ) theFaces.insert( theFaces.end(), fIt->next() ); } @@ -1556,7 +1554,7 @@ void SMESH_MeshEditor::QuadTo4Tri (TIDSortedElemSet & theElems) if ( F.IsNull() ) { for ( ; iN < nodes.size(); ++iN ) - xyz[ iN ] = SMESH_TNodeXYZ( nodes[ iN ] ); + xyz[ iN ] = SMESH_NodeXYZ( nodes[ iN ] ); for ( ; iN < 8; ++iN ) // mid-side points of a linear qudrangle xyz[ iN ] = 0.5 * ( xyz[ iN - 4 ] + xyz[( iN - 3 )%4 ] ); @@ -2361,7 +2359,7 @@ void SMESH_MeshEditor::SplitVolumes (const TFacetOfElem & theElems, if ( fSubMesh ) // update position of the bary node on geometry { if ( subMesh ) - subMesh->RemoveNode( baryNode, false ); + subMesh->RemoveNode( baryNode ); GetMeshDS()->SetNodeOnFace( baryNode, fSubMesh->GetID() ); const TopoDS_Shape& s = GetMeshDS()->IndexToShape( fSubMesh->GetID() ); if ( !s.IsNull() && s.ShapeType() == TopAbs_FACE ) @@ -3830,7 +3828,7 @@ void SMESH_MeshEditor::Smooth (TIDSortedElemSet & theElems, // } if ( project ) { // compute new UV gp_XY newUV; - gp_Pnt pNode = SMESH_TNodeXYZ( node ); + gp_Pnt pNode = SMESH_NodeXYZ( node ); if ( !getClosestUV( projector, pNode, newUV )) { MESSAGE("Node Projection Failed " << node); } @@ -4085,7 +4083,7 @@ void SMESH_MeshEditor::Smooth (TIDSortedElemSet & theElems, const SMDS_MeshElement* QF = *elemIt; if ( QF->IsQuadratic() ) { - nodes.assign( SMDS_MeshElement::iterator( QF->interlacedNodesElemIterator() ), + nodes.assign( SMDS_MeshElement::iterator( QF->interlacedNodesIterator() ), SMDS_MeshElement::iterator() ); nodes.push_back( nodes[0] ); gp_Pnt xyz; @@ -4099,9 +4097,9 @@ void SMESH_MeshEditor::Smooth (TIDSortedElemSet & theElems, xyz = surface->Value( uv.X(), uv.Y() ); } else { - xyz = 0.5 * ( SMESH_TNodeXYZ( nodes[i-1] ) + SMESH_TNodeXYZ( nodes[i+1] )); + xyz = 0.5 * ( SMESH_NodeXYZ( nodes[i-1] ) + SMESH_NodeXYZ( nodes[i+1] )); } - if (( SMESH_TNodeXYZ( nodes[i] ) - xyz.XYZ() ).Modulus() > disttol ) + if (( SMESH_NodeXYZ( nodes[i] ) - xyz.XYZ() ).Modulus() > disttol ) // we have to move a medium node aMesh->MoveNode( nodes[i], xyz.X(), xyz.Y(), xyz.Z() ); } @@ -4129,8 +4127,8 @@ namespace const int iNotSame) { - SMESH_TNodeXYZ pP = prevNodes[ iNotSame ]; - SMESH_TNodeXYZ pN = nextNodes[ iNotSame ]; + SMESH_NodeXYZ pP = prevNodes[ iNotSame ]; + SMESH_NodeXYZ pN = nextNodes[ iNotSame ]; gp_XYZ extrDir( pN - pP ), faceNorm; SMESH_MeshAlgos::FaceNormal( face, faceNorm, /*normalized=*/false ); @@ -4834,9 +4832,9 @@ void SMESH_MeshEditor::makeWalls (TNodeOfNodeListMap & mapNewNodes, SMDS_VolumeTool vTool( *v, /*ignoreCentralNodes=*/false ); int iF, nbF = vTool.NbFaces(); for ( iF = 0; iF < nbF; iF ++ ) { - if (vTool.IsFreeFace( iF ) && - vTool.GetFaceNodes( iF, faceNodeSet ) && - initNodeSet != faceNodeSet) // except an initial face + if ( vTool.IsFreeFace( iF ) && + vTool.GetFaceNodes( iF, faceNodeSet ) && + initNodeSet != faceNodeSet) // except an initial face { if ( nbSteps == 1 && faceNodeSet == topNodeSet ) continue; @@ -5325,7 +5323,7 @@ void SMESH_MeshEditor::ExtrusParam::SetElementsToUse( const TIDSortedElemSet& el while ( itN->more() ) { const SMDS_MeshElement* node = itN->next(); if ( newNodes.insert( node ).second ) - myBaseP += SMESH_TNodeXYZ( node ); + myBaseP += SMESH_NodeXYZ( node ); } } } @@ -5391,7 +5389,7 @@ makeNodesByDir( SMESHDS_Mesh* mesh, std::list & newNodes, const bool makeMediumNodes) { - gp_XYZ p = SMESH_TNodeXYZ( srcNode ); + gp_XYZ p = SMESH_NodeXYZ( srcNode ); int nbNodes = 0; for ( beginStepIter( makeMediumNodes ); moreSteps(); ++nbNodes ) // loop on steps @@ -5428,7 +5426,7 @@ makeNodesByDir( SMESHDS_Mesh* mesh, iSc += int( makeMediumNodes ); ScaleIt& scale = scales[ iSc % 2 ]; - gp_XYZ xyz = SMESH_TNodeXYZ( *nIt ); + gp_XYZ xyz = SMESH_NodeXYZ( *nIt ); xyz = ( *scale * ( xyz - center )) + center; mesh->MoveNode( *nIt, xyz.X(), xyz.Y(), xyz.Z() ); @@ -5449,7 +5447,7 @@ makeNodesByDirAndSew( SMESHDS_Mesh* mesh, std::list & newNodes, const bool makeMediumNodes) { - gp_XYZ P1 = SMESH_TNodeXYZ( srcNode ); + gp_XYZ P1 = SMESH_NodeXYZ( srcNode ); int nbNodes = 0; for ( beginStepIter( makeMediumNodes ); moreSteps(); ++nbNodes ) // loop on steps @@ -5460,10 +5458,11 @@ makeNodesByDirAndSew( SMESHDS_Mesh* mesh, // if myNodes.size()>0 we 'nave to use given sequence // else - use all nodes of mesh const SMDS_MeshNode * node = 0; - if ( myNodes.Length() > 0 ) { - int i; - for ( i = 1; i <= myNodes.Length(); i++ ) { - gp_XYZ P2 = SMESH_TNodeXYZ( myNodes.Value(i) ); + if ( myNodes.Length() > 0 ) + { + for ( int i = 1; i <= myNodes.Length(); i++ ) + { + SMESH_NodeXYZ P2 = myNodes.Value(i); if (( P1 - P2 ).SquareModulus() < myTolerance * myTolerance ) { node = myNodes.Value(i); @@ -5471,10 +5470,12 @@ makeNodesByDirAndSew( SMESHDS_Mesh* mesh, } } } - else { + else + { SMDS_NodeIteratorPtr itn = mesh->nodesIterator(); - while(itn->more()) { - SMESH_TNodeXYZ P2( itn->next() ); + while(itn->more()) + { + SMESH_NodeXYZ P2 = itn->next(); if (( P1 - P2 ).SquareModulus() < myTolerance * myTolerance ) { node = P2._node; @@ -5506,7 +5507,7 @@ makeNodesByNormal2D( SMESHDS_Mesh* mesh, { const bool alongAvgNorm = ( myFlags & EXTRUSION_FLAG_BY_AVG_NORMAL ); - gp_XYZ p = SMESH_TNodeXYZ( srcNode ); + gp_XYZ p = SMESH_NodeXYZ( srcNode ); // get normals to faces sharing srcNode vector< gp_XYZ > norms, baryCenters; @@ -5526,7 +5527,7 @@ makeNodesByNormal2D( SMESHDS_Mesh* mesh, gp_XYZ bc(0,0,0); int nbN = 0; for ( SMDS_ElemIteratorPtr nIt = face->nodesIterator(); nIt->more(); ++nbN ) - bc += SMESH_TNodeXYZ( nIt->next() ); + bc += SMESH_NodeXYZ( nIt->next() ); baryCenters.push_back( bc / nbN ); } } @@ -5794,9 +5795,8 @@ SMESH_MeshEditor::ExtrusionAlongTrack (TIDSortedElemSet theElements[2], return EXTR_BAD_STARTING_NODE; aItN = pSubMeshDS->GetNodes(); while ( aItN->more() ) { - const SMDS_MeshNode* pNode = aItN->next(); - const SMDS_EdgePosition* pEPos = - static_cast( pNode->GetPosition() ); + const SMDS_MeshNode* pNode = aItN->next(); + SMDS_EdgePositionPtr pEPos = pNode->GetPosition(); double aT = pEPos->GetUParameter(); aPrms.push_back( aT ); } @@ -5839,8 +5839,7 @@ SMESH_MeshEditor::ExtrusionAlongTrack (TIDSortedElemSet theElements[2], aItN = locMeshDS->GetNodes(); while ( aItN->more() ) { const SMDS_MeshNode* pNode = aItN->next(); - const SMDS_EdgePosition* pEPos = - static_cast( pNode->GetPosition() ); + SMDS_EdgePositionPtr pEPos = pNode->GetPosition(); double aT = pEPos->GetUParameter(); aPrms.push_back( aT ); } @@ -5962,7 +5961,7 @@ SMESH_MeshEditor::ExtrusionAlongTrack (TIDSortedElemSet theElements[2], SMDS_ElemIteratorPtr nIt; //check start node - if( !theTrack->GetMeshDS()->Contains(theN1) ) { + if( !theTrack->GetMeshDS()->Contains( theN1 )) { return EXTR_BAD_STARTING_NODE; } @@ -6022,8 +6021,8 @@ SMESH_MeshEditor::ExtrusionAlongTrack (TIDSortedElemSet theElements[2], int startNid = theN1->GetID(); for ( size_t i = 1; i < aNodesList.size(); i++ ) { - gp_Pnt p1 = SMESH_TNodeXYZ( aNodesList[i-1] ); - gp_Pnt p2 = SMESH_TNodeXYZ( aNodesList[i] ); + gp_Pnt p1 = SMESH_NodeXYZ( aNodesList[i-1] ); + gp_Pnt p2 = SMESH_NodeXYZ( aNodesList[i] ); TopoDS_Edge e = BRepBuilderAPI_MakeEdge( p1, p2 ); list LPP; aPrms.clear(); @@ -6079,8 +6078,7 @@ SMESH_MeshEditor::ExtrusionAlongTrack (TIDSortedElemSet theElements[2], while ( aItN->more() ) { const SMDS_MeshNode* pNode = aItN->next(); if( pNode==aN1 || pNode==aN2 ) continue; - const SMDS_EdgePosition* pEPos = - static_cast( pNode->GetPosition() ); + SMDS_EdgePositionPtr pEPos = pNode->GetPosition(); double aT = pEPos->GetUParameter(); aPrms.push_back( aT ); } @@ -6136,9 +6134,8 @@ SMESH_MeshEditor::ExtrusionAlongTrack (TIDSortedElemSet theElements[2], aPrms.clear(); aItN = locMeshDS->GetNodes(); while ( aItN->more() ) { - const SMDS_MeshNode* pNode = aItN->next(); - const SMDS_EdgePosition* pEPos = - static_cast( pNode->GetPosition() ); + const SMDS_MeshNode* pNode = aItN->next(); + SMDS_EdgePositionPtr pEPos = pNode->GetPosition(); double aT = pEPos->GetUParameter(); aPrms.push_back( aT ); } @@ -6296,7 +6293,7 @@ SMESH_MeshEditor::makeExtrElements(TIDSortedElemSet theElemSets while ( itN->more() ) { const SMDS_MeshElement* node = itN->next(); if ( newNodes.insert( node ).second ) - aGC += SMESH_TNodeXYZ( node ); + aGC += SMESH_NodeXYZ( node ); } } } @@ -6340,7 +6337,7 @@ SMESH_MeshEditor::makeExtrElements(TIDSortedElemSet theElemSets aTolAng=1.e-4; aV0x = aV0; - aPN0 = SMESH_TNodeXYZ( node ); + aPN0 = SMESH_NodeXYZ( node ); const SMESH_MeshEditor_PathPoint& aPP0 = aPPs[0]; aP0x = aPP0.Pnt(); @@ -6660,8 +6657,8 @@ SMESH_MeshEditor::Transform (TIDSortedElemSet & theElems, if ( geomType == SMDSGeom_POLYHEDRA ) // ------------------ polyhedral volume { - const SMDS_VtkVolume* aPolyedre = dynamic_cast( elem ); - if (!aPolyedre) + const SMDS_MeshVolume* aPolyedre = SMDS_Mesh::DownCast< SMDS_MeshVolume >( elem ); + if ( !aPolyedre ) continue; nodes.clear(); bool allTransformed = true; @@ -7035,7 +7032,7 @@ void SMESH_MeshEditor::FindCoincidentNodes (TIDSortedNodeSet & theNodes, if ( theNodes.empty() ) // get all nodes in the mesh { TIDSortedNodeSet* nodes[2] = { &corners, &medium }; - SMDS_NodeIteratorPtr nIt = GetMeshDS()->nodesIterator(/*idInceasingOrder=*/true); + SMDS_NodeIteratorPtr nIt = GetMeshDS()->nodesIterator(); if ( theSeparateCornersAndMedium ) while ( nIt->more() ) { @@ -7223,7 +7220,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes, AddToSameGroups( nToKeep, nToRemove, mesh ); // set _alwaysComputed to a sub-mesh of VERTEX to enable further mesh computing // w/o creating node in place of merged ones. - const SMDS_PositionPtr& pos = nToRemove->GetPosition(); + SMDS_PositionPtr pos = nToRemove->GetPosition(); if ( pos && pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) if ( SMESH_subMesh* sm = myMesh->GetSubMeshContaining( nToRemove->getshapeId() )) sm->SetIsAlwaysComputed( true ); @@ -7411,7 +7408,7 @@ bool SMESH_MeshEditor::applyMerge( const SMDS_MeshElement* elem, if ( nbUniqueNodes >= 4 ) { // each face has to be analyzed in order to check volume validity - if ( const SMDS_VtkVolume* aPolyedre = dynamic_cast( elem )) + if ( const SMDS_MeshVolume* aPolyedre = SMDS_Mesh::DownCast< SMDS_MeshVolume >( elem )) { int nbFaces = aPolyedre->NbFaces(); @@ -7956,24 +7953,11 @@ bool SMESH_MeshEditor::FindFreeBorder (const SMDS_MeshNode* theFirst if ( e == curElem || foundElems.insert( e ).second ) { // get nodes int iNode = 0, nbNodes = e->NbNodes(); - vector nodes(nbNodes+1); - - if ( e->IsQuadratic() ) { - const SMDS_VtkFace* F = - dynamic_cast(e); - if (!F) throw SALOME_Exception(LOCALIZED("not an SMDS_VtkFace")); - // use special nodes iterator - SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator(); - while( anIter->more() ) { - nodes[ iNode++ ] = cast2Node(anIter->next()); - } - } - else { - SMDS_ElemIteratorPtr nIt = e->nodesIterator(); - while ( nIt->more() ) - nodes[ iNode++ ] = static_cast( nIt->next() ); - } - nodes[ iNode ] = nodes[ 0 ]; + vector nodes( nbNodes+1 ); + nodes.assign( SMDS_MeshElement::iterator( e->interlacedNodesIterator() ), + SMDS_MeshElement::iterator() ); + nodes.push_back( nodes[ 0 ]); + // check 2 links for ( iNode = 0; iNode < nbNodes; iNode++ ) if (((nodes[ iNode ] == nStart && nodes[ iNode + 1] != nIgnore ) || @@ -8230,27 +8214,13 @@ SMESH_MeshEditor::SewFreeBorder (const SMDS_MeshNode* theBordFirstNode, const SMDS_MeshNode** nodes = isVolume ? volume.GetNodes() : & faceNodes[0]; if ( isVolume ) // --volume hasVolumes = true; - else if ( elem->GetType()==SMDSAbs_Face ) { // --face + else if ( elem->GetType() == SMDSAbs_Face ) { // --face // retrieve all face nodes and find iPrevNode - an index of the prevSideNode - if(elem->IsQuadratic()) { - const SMDS_VtkFace* F = - dynamic_cast(elem); - if (!F) throw SALOME_Exception(LOCALIZED("not an SMDS_VtkFace")); - // use special nodes iterator - SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator(); - while( anIter->more() ) { - nodes[ iNode ] = cast2Node(anIter->next()); - if ( nodes[ iNode++ ] == prevSideNode ) - iPrevNode = iNode - 1; - } - } - else { - SMDS_ElemIteratorPtr nIt = elem->nodesIterator(); - while ( nIt->more() ) { - nodes[ iNode ] = cast2Node( nIt->next() ); - if ( nodes[ iNode++ ] == prevSideNode ) - iPrevNode = iNode - 1; - } + SMDS_NodeIteratorPtr nIt = elem->interlacedNodesIterator(); + while ( nIt->more() ) { + nodes[ iNode ] = cast2Node( nIt->next() ); + if ( nodes[ iNode++ ] == prevSideNode ) + iPrevNode = iNode - 1; } // there are 2 links to check nbNodes = 2; @@ -8710,48 +8680,21 @@ void SMESH_MeshEditor::InsertNodesIntoLink(const SMDS_MeshElement* theElemen // add nodes of face up to first node of link bool isFLN = false; - - if ( theFace->IsQuadratic() ) { - const SMDS_VtkFace* F = dynamic_cast(theFace); - if (!F) throw SALOME_Exception(LOCALIZED("not an SMDS_VtkFace")); - // use special nodes iterator - SMDS_ElemIteratorPtr anIter = F->interlacedNodesElemIterator(); - while( anIter->more() && !isFLN ) { - const SMDS_MeshNode* n = cast2Node(anIter->next()); - poly_nodes[iNode++] = n; - if (n == nodes[il1]) { - isFLN = true; - } - } - // add nodes to insert - list::iterator nIt = aNodesToInsert.begin(); - for (; nIt != aNodesToInsert.end(); nIt++) { - poly_nodes[iNode++] = *nIt; - } - // add nodes of face starting from last node of link - while ( anIter->more() ) { - poly_nodes[iNode++] = cast2Node(anIter->next()); - } + SMDS_NodeIteratorPtr nodeIt = theFace->interlacedNodesIterator(); + while ( nodeIt->more() && !isFLN ) { + const SMDS_MeshNode* n = nodeIt->next(); + poly_nodes[iNode++] = n; + isFLN = ( n == nodes[il1] ); } - else { - SMDS_ElemIteratorPtr nodeIt = theFace->nodesIterator(); - while ( nodeIt->more() && !isFLN ) { - const SMDS_MeshNode* n = static_cast( nodeIt->next() ); - poly_nodes[iNode++] = n; - if (n == nodes[il1]) { - isFLN = true; - } - } - // add nodes to insert - list::iterator nIt = aNodesToInsert.begin(); - for (; nIt != aNodesToInsert.end(); nIt++) { - poly_nodes[iNode++] = *nIt; - } - // add nodes of face starting from last node of link - while ( nodeIt->more() ) { - const SMDS_MeshNode* n = static_cast( nodeIt->next() ); - poly_nodes[iNode++] = n; - } + // add nodes to insert + list::iterator nIt = aNodesToInsert.begin(); + for (; nIt != aNodesToInsert.end(); nIt++) { + poly_nodes[iNode++] = *nIt; + } + // add nodes of face starting from last node of link + while ( nodeIt->more() ) { + const SMDS_MeshNode* n = static_cast( nodeIt->next() ); + poly_nodes[iNode++] = n; } // make a new face @@ -9093,7 +9036,7 @@ int SMESH_MeshEditor::convertElemToQuadratic(SMESHDS_SubMesh * theSm, const int nbNodes = elem->NbCornerNodes(); nodes.assign(elem->begin_nodes(), elem->end_nodes()); if ( aGeomType == SMDSEntity_Polyhedra ) - nbNodeInFaces = static_cast( elem )->GetQuantities(); + nbNodeInFaces = static_cast( elem )->GetQuantities(); else if ( aGeomType == SMDSEntity_Hexagonal_Prism ) volumeToPolyhedron( elem, nodes, nbNodeInFaces ); @@ -9314,7 +9257,7 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d, const bool theT const int id = volume->GetID(); vector nodes (volume->begin_nodes(), volume->end_nodes()); if ( type == SMDSEntity_Polyhedra ) - nbNodeInFaces = static_cast(volume)->GetQuantities(); + nbNodeInFaces = static_cast(volume)->GetQuantities(); else if ( type == SMDSEntity_Hexagonal_Prism ) volumeToPolyhedron( volume, nodes, nbNodeInFaces ); @@ -10076,20 +10019,8 @@ SMESH_MeshEditor::SewSideElements (TIDSortedElemSet& theSide1, //cout << " F " << face[ iSide]->GetID() <erase( face[ iSide ]); // put face nodes to fnodes - if ( face[ iSide ]->IsQuadratic() ) - { - // use interlaced nodes iterator - const SMDS_VtkFace* F = dynamic_cast( face[ iSide ]); - if (!F) throw SALOME_Exception(LOCALIZED("not an SMDS_VtkFace")); - SMDS_ElemIteratorPtr nIter = F->interlacedNodesElemIterator(); - while ( nIter->more() ) - fnodes[ iSide ].push_back( cast2Node( nIter->next() )); - } - else - { - fnodes[ iSide ].assign( face[ iSide ]->begin_nodes(), - face[ iSide ]->end_nodes() ); - } + SMDS_MeshElement::iterator nIt( face[ iSide ]->interlacedNodesIterator() ), nEnd; + fnodes[ iSide ].assign( nIt, nEnd ); fnodes[ iSide ].push_back( fnodes[ iSide ].front()); } } @@ -10985,9 +10916,9 @@ void SMESH_MeshEditor::DoubleElements( const TIDSortedElemSet& theElements ) if ( mesh->GetMeshInfo().NbElements( types[i] )) { type = types[i]; + elemIt = mesh->elementsIterator( type ); break; } - elemIt = mesh->elementsIterator( type ); } else { @@ -11206,8 +11137,7 @@ namespace { const double theTol) { gp_XYZ centerXYZ (0, 0, 0); - SMDS_ElemIteratorPtr aNodeItr = theElem->nodesIterator(); - while ( aNodeItr->more() ) + for ( SMDS_ElemIteratorPtr aNodeItr = theElem->nodesIterator(); aNodeItr->more(); ) centerXYZ += SMESH_NodeXYZ( aNodeItr->next() ); gp_Pnt aPnt = centerXYZ / theElem->NbNodes(); @@ -11432,7 +11362,7 @@ bool SMESH_MeshEditor::DoubleNodesOnGroupBoundaries( const std::vectormyMesh->GetMeshDS(); meshDS->BuildDownWardConnectivity(true); CHRONO(50); - SMDS_UnstructuredGrid *grid = meshDS->getGrid(); + SMDS_UnstructuredGrid *grid = meshDS->GetGrid(); // --- build the list of faces shared by 2 domains (group of elements), with their domain and volume indexes // build the list of cells with only a node or an edge on the border, with their domain and volume indexes @@ -11498,7 +11428,7 @@ bool SMESH_MeshEditor::DoubleNodesOnGroupBoundaries( const std::vectorgetVtkId(); + int vtkId = anElem->GetVtkID(); //MESSAGE(" vtkId " << vtkId << " smdsId " << anElem->GetID()); int neighborsVtkIds[NBMAXNEIGHBORS]; int downIds[NBMAXNEIGHBORS]; @@ -11506,7 +11436,7 @@ bool SMESH_MeshEditor::DoubleNodesOnGroupBoundaries( const std::vectorGetNeighbors(neighborsVtkIds, downIds, downTypes, vtkId); for (int n = 0; n < nbNeighbors; n++) { - int smdsId = meshDS->fromVtkToSmds(neighborsVtkIds[n]); + int smdsId = meshDS->FromVtkToSmds(neighborsVtkIds[n]); const SMDS_MeshElement* elem = meshDS->FindElement(smdsId); if (elem && ! domain.count(elem)) // neighbor is in another domain : face is shared { @@ -11569,7 +11499,7 @@ bool SMESH_MeshEditor::DoubleNodesOnGroupBoundaries( const std::vectorFindElement(GetMeshDS()->fromVtkToSmds(vtkId)); + const SMDS_MeshElement* anElem = GetMeshDS()->FindElement(GetMeshDS()->FromVtkToSmds(vtkId)); if (!domain.count(anElem)) continue; int vtkType = grid->GetCellType(vtkId); @@ -11653,7 +11583,7 @@ bool SMESH_MeshEditor::DoubleNodesOnGroupBoundaries( const std::vectorGetPoint(oldId); SMDS_MeshNode *newNode = meshDS->AddNode(coords[0], coords[1], coords[2]); copyPosition( meshDS->FindNodeVtk( oldId ), newNode ); - int newId = newNode->getVtkId(); + int newId = newNode->GetVtkID(); nodeDomains[oldId][idom] = newId; // cloned node for other domains //MESSAGE("-+-+-c oldNode " << oldId << " domain " << idomain << " newNode " << newId << " domain " << idom << " size=" < domvol; // domain --> a volume with the edge + map domvol; // domain --> a volume with the edge map angleDom; // oriented angles between planes defined by edge and volume centers int nbvol = grid->GetParentVolumes(vtkVolIds, downEdgeIds[ie], edgeType[ie]); for ( size_t id = 0; id < doms.size(); id++ ) @@ -11735,26 +11665,31 @@ bool SMESH_MeshEditor::DoubleNodesOnGroupBoundaries( const std::vectorfromVtkToSmds(vtkVolIds[ivol]); - SMDS_MeshElement* elem = (SMDS_MeshElement*)meshDS->FindElement(smdsId); + int smdsId = meshDS->FromVtkToSmds(vtkVolIds[ivol]); + const SMDS_MeshElement* elem = meshDS->FindElement(smdsId); if (domain.count(elem)) { - SMDS_VtkVolume* svol = dynamic_cast(elem); - domvol[idom] = svol; + const SMDS_MeshVolume* svol = SMDS_Mesh::DownCast(elem); + domvol[idom] = (SMDS_MeshVolume*) svol; //MESSAGE(" domain " << idom << " volume " << elem->GetID()); - double values[3]; + double values[3] = { 0,0,0 }; vtkIdType npts = 0; vtkIdType* pts = 0; grid->GetCellPoints(vtkVolIds[ivol], npts, pts); - SMDS_VtkVolume::gravityCenter(grid, pts, npts, values); - if (id ==0) + for ( vtkIdType i = 0; i < npts; ++i ) + { + double *coords = grid->GetPoint( pts[i] ); + for ( int j = 0; j < 3; ++j ) + values[j] += coords[j] / npts; + } + if ( id == 0 ) { - gref.SetXYZ(gp_XYZ(values[0], values[1], values[2])); + gref.SetCoord( values[0], values[1], values[2] ); angleDom[idom] = 0; } else { - gp_Pnt g(values[0], values[1], values[2]); + gp_Pnt g( values[0], values[1], values[2] ); angleDom[idom] = OrientedAngle(p0, p1, gref, g); // -piGetMeshDS()->fromVtkToSmds(vtkId) << " domain " << idomain + //MESSAGE("affect cell " << this->GetMeshDS()->FromVtkToSmds(vtkId) << " domain " << idomain // << " type " << vtkType << " downId " << downId); } } @@ -11975,7 +11910,7 @@ bool SMESH_MeshEditor::DoubleNodesOnGroupBoundaries( const std::vectorfirst; int vtkVolId = itdom->second; - //MESSAGE("modify nodes of cell " << this->GetMeshDS()->fromVtkToSmds(vtkVolId) << " domain " << idom); + //MESSAGE("modify nodes of cell " << this->GetMeshDS()->FromVtkToSmds(vtkVolId) << " domain " << idom); localClonedNodeIds.clear(); for (itn = oldNodes.begin(); itn != oldNodes.end(); ++itn) { @@ -12042,8 +11977,7 @@ bool SMESH_MeshEditor::CreateFlatElementsOnFacesGroups(const std::vector (anElem); + const SMDS_MeshFace* aFace = meshDS->DownCast ( *elemItr ); if (!aFace) continue; // MESSAGE("aFace=" << aFace->GetID()); @@ -12052,11 +11986,11 @@ bool SMESH_MeshEditor::CreateFlatElementsOnFacesGroups(const std::vectornodesIterator(); + SMDS_NodeIteratorPtr nodeIt = aFace->nodeIterator(); while (nodeIt->more()) { - const SMDS_MeshNode* node = static_cast (nodeIt->next()); - bool isMedium = isQuad && (aFace->IsMediumNode(node)); + const SMDS_MeshNode* node = nodeIt->next(); + bool isMedium = ( isQuad && aFace->IsMediumNode( node )); if (isMedium) ln2.push_back(node); else @@ -12164,7 +12098,7 @@ bool SMESH_MeshEditor::CreateFlatElementsOnFacesGroups(const std::vectorChangeNodes(&ln[0], ln.size()); + const_cast( aFace )->ChangeNodes( &ln[0], ln.size() ); } } return true; @@ -12275,7 +12209,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, SMESHDS_Mesh *meshDS = this->myMesh->GetMeshDS(); meshDS->BuildDownWardConnectivity(true); - SMDS_UnstructuredGrid* grid = meshDS->getGrid(); + SMDS_UnstructuredGrid* grid = meshDS->GetGrid(); // --- set of volumes detected inside @@ -12302,7 +12236,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, while (volItr->more()) { vol = (SMDS_MeshElement*)volItr->next(); - setOfInsideVol.insert(vol->getVtkId()); + setOfInsideVol.insert(vol->GetVtkID()); sgrp->Add(vol->GetID()); } } @@ -12357,7 +12291,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, while (volItr->more()) { startVol = (SMDS_MeshElement*)volItr->next(); - setOfVolToCheck.insert(startVol->getVtkId()); + setOfVolToCheck.insert(startVol->GetVtkID()); } if (setOfVolToCheck.empty()) { @@ -12376,7 +12310,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, { std::set::iterator it = setOfVolToCheck.begin(); int vtkId = *it; - //MESSAGE("volume to check, vtkId " << vtkId << " smdsId " << meshDS->fromVtkToSmds(vtkId)); + //MESSAGE("volume to check, vtkId " << vtkId << " smdsId " << meshDS->FromVtkToSmds(vtkId)); bool volInside = false; vtkIdType npts = 0; vtkIdType* pts = 0; @@ -12410,14 +12344,14 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, if (distance2 < radius2) { volInside = true; // one or more nodes inside the domain - sgrp->Add(meshDS->fromVtkToSmds(vtkId)); + sgrp->Add(meshDS->FromVtkToSmds(vtkId)); break; } } if (volInside) { setOfInsideVol.insert(vtkId); - //MESSAGE(" volume inside, vtkId " << vtkId << " smdsId " << meshDS->fromVtkToSmds(vtkId)); + //MESSAGE(" volume inside, vtkId " << vtkId << " smdsId " << meshDS->FromVtkToSmds(vtkId)); int neighborsVtkIds[NBMAXNEIGHBORS]; int downIds[NBMAXNEIGHBORS]; unsigned char downTypes[NBMAXNEIGHBORS]; @@ -12429,7 +12363,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, else { setOfOutsideVol.insert(vtkId); - //MESSAGE(" volume outside, vtkId " << vtkId << " smdsId " << meshDS->fromVtkToSmds(vtkId)); + //MESSAGE(" volume outside, vtkId " << vtkId << " smdsId " << meshDS->FromVtkToSmds(vtkId)); } setOfVolToCheck.erase(vtkId); } @@ -12464,7 +12398,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, int vtkId = *it; if (grid->GetCellType(vtkId) == VTK_HEXAHEDRON) { - //MESSAGE("volume to recheck, vtkId " << vtkId << " smdsId " << meshDS->fromVtkToSmds(vtkId)); + //MESSAGE("volume to recheck, vtkId " << vtkId << " smdsId " << meshDS->FromVtkToSmds(vtkId)); int countInside = 0; int neighborsVtkIds[NBMAXNEIGHBORS]; int downIds[NBMAXNEIGHBORS]; @@ -12476,9 +12410,9 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, //MESSAGE("countInside " << countInside); if (countInside > 1) { - //MESSAGE(" volume inside, vtkId " << vtkId << " smdsId " << meshDS->fromVtkToSmds(vtkId)); + //MESSAGE(" volume inside, vtkId " << vtkId << " smdsId " << meshDS->FromVtkToSmds(vtkId)); setOfInsideVol.insert(vtkId); - sgrp->Add(meshDS->fromVtkToSmds(vtkId)); + sgrp->Add(meshDS->FromVtkToSmds(vtkId)); addedInside = true; } else @@ -12499,7 +12433,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, for (; it != setOfInsideVol.end(); ++it) { int vtkId = *it; - //MESSAGE(" vtkId " << vtkId << " smdsId " << meshDS->fromVtkToSmds(vtkId)); + //MESSAGE(" vtkId " << vtkId << " smdsId " << meshDS->FromVtkToSmds(vtkId)); int neighborsVtkIds[NBMAXNEIGHBORS]; int downIds[NBMAXNEIGHBORS]; unsigned char downTypes[NBMAXNEIGHBORS]; @@ -12518,7 +12452,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, int vtkFaceId = grid->getDownArray(downTypes[n])->getVtkCellId(downIds[n]); if (vtkFaceId >= 0) { - sgrpi->Add(meshDS->fromVtkToSmds(vtkFaceId)); + sgrpi->Add(meshDS->FromVtkToSmds(vtkFaceId)); // find also the smds edges on this face int nbEdges = grid->getDownArray(downTypes[n])->getNumberOfDownCells(downIds[n]); const int* dEdges = grid->getDownArray(downTypes[n])->getDownCells(downIds[n]); @@ -12527,7 +12461,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, { int vtkEdgeId = grid->getDownArray(dTypes[i])->getVtkCellId(dEdges[i]); if (vtkEdgeId >= 0) - sgrpei->Add(meshDS->fromVtkToSmds(vtkEdgeId)); + sgrpei->Add(meshDS->FromVtkToSmds(vtkEdgeId)); } } } @@ -12537,7 +12471,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, skinFaces[face] = vtkId; int vtkFaceId = grid->getDownArray(downTypes[n])->getVtkCellId(downIds[n]); if (vtkFaceId >= 0) - sgrps->Add(meshDS->fromVtkToSmds(vtkFaceId)); + sgrps->Add(meshDS->FromVtkToSmds(vtkFaceId)); } } } @@ -12556,7 +12490,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, { const SMDS_MeshElement *elem = itelem->next(); int shapeId = elem->getshapeId(); - int vtkId = elem->getVtkId(); + int vtkId = elem->GetVtkID(); if (!shapeIdToVtkIdSet.count(shapeId)) { shapeIdToVtkIdSet[shapeId] = emptySet; @@ -12591,7 +12525,7 @@ void SMESH_MeshEditor::CreateHoleSkin(double radius, { if (neighborsVtkIds[n]<0) // only smds faces are considered as neighbors here continue; - int smdsId = meshDS->fromVtkToSmds(neighborsVtkIds[n]); + int smdsId = meshDS->FromVtkToSmds(neighborsVtkIds[n]); const SMDS_MeshElement* elem = meshDS->FindElement(smdsId); if ( shapeIds.count(elem->getshapeId()) && !sgrps->Contains(elem)) // edge : neighbor in the set of shape, not in the group { @@ -12831,7 +12765,7 @@ int SMESH_MeshEditor::MakeBoundaryMesh(const TIDSortedElemSet& elements, if (elements.empty()) eIt = aMesh->elementsIterator(elemType); else eIt = SMESHUtils::elemSetIterator( elements ); - while (eIt->more()) + while ( eIt->more() ) { const SMDS_MeshElement* elem = eIt->next(); const int iQuad = elem->IsQuadratic(); @@ -12912,7 +12846,7 @@ int SMESH_MeshEditor::MakeBoundaryMesh(const TIDSortedElemSet& elements, else if ( elem->GetType() == SMDSAbs_Face ) // elem is a face ------------------------ { avoidSet.clear(), avoidSet.insert( elem ); - elemNodes.assign( SMDS_MeshElement::iterator( elem->interlacedNodesElemIterator() ), + elemNodes.assign( SMDS_MeshElement::iterator( elem->interlacedNodesIterator() ), SMDS_MeshElement::iterator() ); elemNodes.push_back( elemNodes[0] ); nodes.resize( 2 + iQuad ); @@ -13066,7 +13000,7 @@ void SMESH_MeshEditor::copyPosition( const SMDS_MeshNode* from, case SMDS_TOP_FACE: { - const SMDS_FacePosition* fPos = static_cast< const SMDS_FacePosition* >( pos ); + SMDS_FacePositionPtr fPos = pos; GetMeshDS()->SetNodeOnFace( to, from->getshapeId(), fPos->GetUParameter(), fPos->GetVParameter() ); break; @@ -13074,7 +13008,7 @@ void SMESH_MeshEditor::copyPosition( const SMDS_MeshNode* from, case SMDS_TOP_EDGE: { // WARNING: it is dangerous to set equal nodes on one EDGE!!!!!!!! - const SMDS_EdgePosition* ePos = static_cast< const SMDS_EdgePosition* >( pos ); + SMDS_EdgePositionPtr ePos = pos; GetMeshDS()->SetNodeOnEdge( to, from->getshapeId(), ePos->GetUParameter() ); break; } diff --git a/src/SMESH/SMESH_MesherHelper.cxx b/src/SMESH/SMESH_MesherHelper.cxx index 242900a74..ad48bd49d 100644 --- a/src/SMESH/SMESH_MesherHelper.cxx +++ b/src/SMESH/SMESH_MesherHelper.cxx @@ -643,22 +643,22 @@ gp_XY SMESH_MesherHelper::GetNodeUV(const TopoDS_Face& F, { gp_Pnt2d uv( Precision::Infinite(), Precision::Infinite() ); - const SMDS_PositionPtr Pos = n->GetPosition(); + SMDS_PositionPtr pos = n->GetPosition(); bool uvOK = false; - if ( Pos->GetTypeOfPosition() == SMDS_TOP_FACE ) + if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE ) { // node has position on face - const SMDS_FacePosition* fpos = static_cast( Pos ); + SMDS_FacePositionPtr fpos = pos; uv.SetCoord( fpos->GetUParameter(), fpos->GetVParameter() ); if ( check ) uvOK = CheckNodeUV( F, n, uv.ChangeCoord(), 2.*getFaceMaxTol( F )); // 2. from 22830 } - else if ( Pos->GetTypeOfPosition() == SMDS_TOP_EDGE ) + else if ( pos->GetTypeOfPosition() == SMDS_TOP_EDGE ) { // node has position on EDGE => it is needed to find // corresponding EDGE from FACE, get pcurve for this // EDGE and retrieve value from this pcurve - const SMDS_EdgePosition* epos = static_cast( Pos ); + SMDS_EdgePositionPtr epos = pos; const int edgeID = n->getshapeId(); const TopoDS_Edge& E = TopoDS::Edge( GetMeshDS()->IndexToShape( edgeID )); double f, l, u = epos->GetUParameter(); @@ -699,7 +699,7 @@ gp_XY SMESH_MesherHelper::GetNodeUV(const TopoDS_Face& F, uv = newUV; } } - else if ( Pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) + else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) { if ( int vertexID = n->getshapeId() ) { const TopoDS_Vertex& V = TopoDS::Vertex(GetMeshDS()->IndexToShape(vertexID)); @@ -1031,8 +1031,7 @@ double SMESH_MesherHelper::GetNodeU(const TopoDS_Edge& E, const SMDS_PositionPtr pos = n->GetPosition(); if ( pos->GetTypeOfPosition()==SMDS_TOP_EDGE ) { - const SMDS_EdgePosition* epos = static_cast( pos ); - param = epos->GetUParameter(); + param = pos->GetParameters()[0]; } else if( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) { @@ -4562,8 +4561,16 @@ namespace { // Structures used by FixQuadraticElements() TopoDS_Shape shape = theHelper.GetSubShape().Oriented( TopAbs_FORWARD ); if ( shape.IsNull() ) return; - if ( !theError ) theError = SMESH_ComputeError::New(); - + if ( !dynamic_cast( theError.get() )) + { + if ( !theError ) + theError.reset( new SMESH_BadInputElements( meshDS )); + else + theError.reset( new SMESH_BadInputElements( meshDS, + theError->myName, + theError->myComment, + theError->myAlgo)); + } gp_XYZ faceNorm; if ( shape.ShapeType() == TopAbs_FACE ) // 2D @@ -4681,13 +4688,13 @@ namespace { // Structures used by FixQuadraticElements() gp_XYZ pMid3D = 0.5 * ( pN0 + SMESH_TNodeXYZ( nOnEdge[1] )); meshDS->MoveNode( n, pMid3D.X(), pMid3D.Y(), pMid3D.Z() ); MSG( "move OUT of face " << n ); - theError->myBadElements.push_back( f ); + static_cast( theError.get() )->add( f ); } } } } } - if ( !theError->myBadElements.empty() ) + if ( theError->HasBadElems() ) theError->myName = EDITERR_NO_MEDIUM_ON_GEOM; return; @@ -4875,13 +4882,13 @@ namespace { // Structures used by FixQuadraticElements() MSG( "move OUT of solid " << nMedium ); } } - theError->myBadElements.push_back( vol ); + static_cast( theError.get() )->add( vol ); } } // loop on volumes sharing a node on FACE } // loop on nodes on FACE } // loop on FACEs of a SOLID - if ( !theError->myBadElements.empty() ) + if ( theError->HasBadElems() ) theError->myName = EDITERR_NO_MEDIUM_ON_GEOM; } // 3D case } @@ -4893,7 +4900,7 @@ namespace { // Structures used by FixQuadraticElements() * \brief Move medium nodes of faces and volumes to fix distorted elements * \param error - container of fixed distorted elements * \param volumeOnly - to fix nodes on faces or not, if the shape is solid - * + * * Issue 0020307: EDF 992 SMESH : Linea/Quadratic with Medium Node on Geometry */ //======================================================================= @@ -5268,8 +5275,7 @@ void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& compError, gp_XY newUV = ApplyIn2D( s, oldUV, gp_XY( move.X(),move.Y()), gp_XY_Added ); gp_Pnt newPnt = s->Value( newUV.X(), newUV.Y()); move = gp_Vec( XYZ((*link1)->_mediumNode), newPnt.Transformed(loc) ); - if ( SMDS_FacePosition* nPos = - dynamic_cast< SMDS_FacePosition* >((*link1)->_mediumNode->GetPosition())) + if ( SMDS_FacePositionPtr nPos = (*link1)->_mediumNode->GetPosition()) nPos->SetParameters( newUV.X(), newUV.Y() ); #ifdef _DEBUG_ if ( (XYZ((*link1)->node1()) - XYZ((*link1)->node2())).SquareModulus() < diff --git a/src/SMESH/SMESH_Pattern.cxx b/src/SMESH/SMESH_Pattern.cxx index b307ba31c..f032ae475 100644 --- a/src/SMESH/SMESH_Pattern.cxx +++ b/src/SMESH/SMESH_Pattern.cxx @@ -801,8 +801,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, ++nbMeduimNodes; continue; } - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition()); + SMDS_EdgePositionPtr epos = node->GetPosition(); double u = epos->GetUParameter(); paramNodeMap.insert( make_pair( u, node )); } @@ -929,8 +928,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, if ( theProject || edgesUVBox.IsOut( p->myInitUV ) ) p->myInitUV = project( node, projector ); else { - const SMDS_FacePosition* pos = - static_cast(node->GetPosition()); + SMDS_FacePositionPtr pos = node->GetPosition(); p->myInitUV.SetCoord( pos->GetUParameter(), pos->GetVParameter() ); } p->myInitXYZ.SetCoord( p->myInitUV.X(), p->myInitUV.Y(), 0 ); @@ -3288,8 +3286,7 @@ bool SMESH_Pattern::Load (SMESH_Mesh* theMesh, const SMDS_MeshNode* node = nIt->next(); if ( isQuadMesh && SMESH_MeshEditor::IsMedium( node, SMDSAbs_Edge )) continue; - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition()); + SMDS_EdgePositionPtr epos = node->GetPosition(); double u = ( epos->GetUParameter() - f ) / ( l - f ); (*pIt)->myInitXYZ.SetCoord( iCoord, isForward ? u : 1 - u ); } @@ -4172,7 +4169,8 @@ bool SMESH_Pattern::MakeMesh(SMESH_Mesh* theMesh, createElements( theMesh, nodesVector, myElemPointIDs, myElements ); } - aMeshDS->compactMesh(); + aMeshDS->Modified(); + aMeshDS->CompactMesh(); if ( myToKeepNodes ) myOutNodes.swap( nodesVector ); diff --git a/src/SMESH/SMESH_ProxyMesh.cxx b/src/SMESH/SMESH_ProxyMesh.cxx index a28033fda..9e2e34792 100644 --- a/src/SMESH/SMESH_ProxyMesh.cxx +++ b/src/SMESH/SMESH_ProxyMesh.cxx @@ -38,9 +38,21 @@ */ //================================================================================ -SMESH_ProxyMesh::SMESH_ProxyMesh():_mesh(0) +SMESH_ProxyMesh::SMESH_ProxyMesh():_mesh(0), _subContainer(0) { } +//================================================================================ +/*! + * \brief Constructor + */ +//================================================================================ + +SMESH_ProxyMesh::SMESH_ProxyMesh(const SMESH_Mesh& mesh) + : _mesh( &mesh ), + _subContainer( new SubMesh( GetMeshDS() ) ) +{ +} + //================================================================================ /*! * \brief Make a proxy mesh from components. Components become empty @@ -59,7 +71,7 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(std::vector& components): takeTmpElemsInMesh( m ); - if ( !_mesh ) _mesh = m->_mesh; + if ( !_mesh && m->_mesh ) setMesh( *( m->_mesh )); if ( _allowedTypes.empty() ) _allowedTypes = m->_allowedTypes; if ( _subMeshes.size() < m->_subMeshes.size() ) @@ -101,6 +113,8 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(std::vector& components): SMESH_ProxyMesh::~SMESH_ProxyMesh() { + delete _subContainer; + for ( size_t i = 0; i < _subMeshes.size(); ++i ) delete _subMeshes[i]; _subMeshes.clear(); @@ -111,6 +125,19 @@ SMESH_ProxyMesh::~SMESH_ProxyMesh() _elemsInMesh.clear(); } +//================================================================================ +/*! + * \brief Set mesh + */ +//================================================================================ + +void SMESH_ProxyMesh::setMesh(const SMESH_Mesh& mesh) +{ + _mesh = &mesh; + if ( _mesh ) + _subContainer = new SubMesh( GetMeshDS() ); +} + //================================================================================ /*! * \brief Returns index of a shape @@ -122,6 +149,19 @@ int SMESH_ProxyMesh::shapeIndex(const TopoDS_Shape& shape) const return ( shape.IsNull() || !_mesh->HasShapeToMesh() ? 0 : GetMeshDS()->ShapeToIndex(shape)); } +//================================================================================ +/*! + * \brief Create a SubMesh + * \param [ino] index - shape index + * \return SubMesh* - new SubMesh + */ +//================================================================================ + +SMESH_ProxyMesh::SubMesh* SMESH_ProxyMesh::newSubmesh(int index) const +{ + return new SubMesh( GetMeshDS(),index ); +} + //================================================================================ /*! * \brief Returns the submesh of a shape; it can be a proxy sub-mesh @@ -245,15 +285,15 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetFaces(const TopoDS_Shape& shape) const if ( !_mesh->HasShapeToMesh() ) return SMDS_ElemIteratorPtr(); - _subContainer.RemoveAllSubmeshes(); + _subContainer->RemoveAllSubmeshes(); TopTools_IndexedMapOfShape FF; TopExp::MapShapes( shape, TopAbs_FACE, FF ); for ( int i = 1; i <= FF.Extent(); ++i ) if ( const SMESHDS_SubMesh* sm = GetSubMesh( FF(i))) - _subContainer.AddSubMesh( sm ); + _subContainer->AddSubMesh( sm ); - return _subContainer.SMESHDS_SubMesh::GetElements(); + return _subContainer->SMESHDS_SubMesh::GetElements(); } //================================================================================ @@ -268,16 +308,16 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetFaces() const if ( _mesh->HasShapeToMesh() ) return SMDS_ElemIteratorPtr(); - _subContainer.RemoveAllSubmeshes(); + _subContainer->RemoveAllSubmeshes(); for ( unsigned i = 0; i < _subMeshes.size(); ++i ) if ( _subMeshes[i] ) - _subContainer.AddSubMesh( _subMeshes[i] ); + _subContainer->AddSubMesh( _subMeshes[i] ); - if ( _subContainer.NbSubMeshes() == 0 ) // no elements substituted + if ( _subContainer->NbSubMeshes() == 0 ) // no elements substituted return GetMeshDS()->elementsIterator(SMDSAbs_Face); // if _allowedTypes is empty, only elements from _subMeshes are returned,... - SMDS_ElemIteratorPtr proxyIter = _subContainer.SMESHDS_SubMesh::GetElements(); + SMDS_ElemIteratorPtr proxyIter = _subContainer->SMESHDS_SubMesh::GetElements(); if ( _allowedTypes.empty() || NbFaces() == _mesh->NbFaces() ) return proxyIter; @@ -533,7 +573,7 @@ int SMESH_ProxyMesh::SubMesh::NbElements() const */ //================================================================================ -SMDS_ElemIteratorPtr SMESH_ProxyMesh::SubMesh::GetElements(bool reverse) const +SMDS_ElemIteratorPtr SMESH_ProxyMesh::SubMesh::GetElements() const { return SMDS_ElemIteratorPtr ( new SMDS_ElementVectorIterator( _elements.begin(), _elements.end() )); @@ -558,7 +598,7 @@ int SMESH_ProxyMesh::SubMesh::NbNodes() const */ //================================================================================ -SMDS_NodeIteratorPtr SMESH_ProxyMesh::SubMesh::GetNodes(bool reverse) const +SMDS_NodeIteratorPtr SMESH_ProxyMesh::SubMesh::GetNodes() const { if ( !_uvPtStructVec.empty() ) return SMDS_NodeIteratorPtr ( new SMDS_SetIterator diff --git a/src/SMESH/SMESH_ProxyMesh.hxx b/src/SMESH/SMESH_ProxyMesh.hxx index a64002e02..35a4c3a97 100644 --- a/src/SMESH/SMESH_ProxyMesh.hxx +++ b/src/SMESH/SMESH_ProxyMesh.hxx @@ -26,6 +26,7 @@ #include "SMESH_SMESH.hxx" +#include "SMDS_ElementHolder.hxx" #include "SMESHDS_SubMesh.hxx" #include "SMESH_TypeDefs.hxx" @@ -56,7 +57,7 @@ public: /*! * \brief Proxy sub-mesh */ - class SMESH_EXPORT SubMesh : public SMESHDS_SubMesh + class SMESH_EXPORT SubMesh : public SMESHDS_SubMesh, SMDS_ElementHolder { public: @@ -66,19 +67,20 @@ public: virtual void AddElement(const SMDS_MeshElement * e); virtual int NbElements() const; virtual int NbNodes() const; - virtual SMDS_ElemIteratorPtr GetElements(bool reverse=false) const; - virtual SMDS_NodeIteratorPtr GetNodes(bool reverse=false) const; + virtual SMDS_ElemIteratorPtr GetElements() const; + virtual SMDS_NodeIteratorPtr GetNodes() const; virtual void Clear(); virtual bool Contains(const SMDS_MeshElement * ME) const; template< class ITERATOR > - void ChangeElements( ITERATOR it, ITERATOR end ) + void ChangeElements( ITERATOR it, ITERATOR end ) { // change SubMesh contents without deleting tmp elements // for which the caller is responsible _elements.assign( it, end ); } - SubMesh(int index=0):SMESHDS_SubMesh(0,index),_n2n(0) {} + SubMesh(const SMDS_Mesh* mesh, int index=0) + :SMESHDS_SubMesh(0,index), SMDS_ElementHolder(mesh), _n2n(0) {} virtual ~SubMesh() { Clear(); } protected: @@ -86,13 +88,20 @@ public: TN2NMap* _n2n; UVPtStructVec _uvPtStructVec; // for SubMesh of EDGE friend class SMESH_ProxyMesh; + + protected: // methods of SMDS_ElementHolder; remove elements before mesh compacting or clearing + virtual SMDS_ElemIteratorPtr getElements() { Clear(); return GetElements(); } + virtual void tmpClear() {} + virtual void add( const SMDS_MeshElement* element ) {} + virtual void compact() {} + virtual void clear() { Clear(); } }; //-------------------------------------------------------------------------------- // Public interface SMESH_ProxyMesh(); SMESH_ProxyMesh(std::vector& components); - SMESH_ProxyMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; } + SMESH_ProxyMesh(const SMESH_Mesh& mesh); virtual ~SMESH_ProxyMesh(); // Returns the submesh of a shape; it can be a proxy sub-mesh @@ -129,11 +138,11 @@ public: // Interface for descendants protected: - void setMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; } + void setMesh(const SMESH_Mesh& mesh); int shapeIndex(const TopoDS_Shape& shape) const; - virtual SubMesh* newSubmesh(int index=0) const { return new SubMesh(index); } + virtual SubMesh* newSubmesh(int index=0) const; // returns a proxy sub-mesh; zero index is for the case of mesh w/o shape SubMesh* findProxySubMesh(int shapeIndex=0) const; @@ -177,7 +186,7 @@ public: std::set< const SMDS_MeshElement* > _elemsInMesh; // Complex submesh used to iterate over elements in other sub-meshes - mutable SubMesh _subContainer; + mutable SubMesh* _subContainer; }; #endif diff --git a/src/SMESH/SMESH_subMesh.cxx b/src/SMESH/SMESH_subMesh.cxx index 05800491b..e8a61f295 100644 --- a/src/SMESH/SMESH_subMesh.cxx +++ b/src/SMESH/SMESH_subMesh.cxx @@ -1293,40 +1293,19 @@ static void cleanSubMesh( SMESH_subMesh * subMesh ) SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS(); int nbElems = subMeshDS->NbElements(); if ( nbElems > 0 ) - { - // start from elem with max ID to avoid filling the pool of IDs - bool rev = true; - SMDS_ElemIteratorPtr ite = subMeshDS->GetElements( rev ); - const SMDS_MeshElement * lastElem = ite->next(); - rev = ( lastElem->GetID() == meshDS->MaxElementID() ); - if ( !rev ) - ite = subMeshDS->GetElements( rev ); - else - meshDS->RemoveFreeElement( lastElem, subMeshDS ); - while (ite->more()) { - const SMDS_MeshElement * elt = ite->next(); - meshDS->RemoveFreeElement( elt, subMeshDS ); - } - } + for ( SMDS_ElemIteratorPtr ite = subMeshDS->GetElements(); ite->more(); ) + meshDS->RemoveFreeElement( ite->next(), subMeshDS ); + int nbNodes = subMeshDS->NbNodes(); if ( nbNodes > 0 ) - { - bool rev = true; - SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes( rev ); - const SMDS_MeshNode * lastNode = itn->next(); - rev = ( lastNode->GetID() == meshDS->MaxNodeID() ); - if ( !rev ) - itn = subMeshDS->GetNodes( rev ); - else - meshDS->RemoveNode( lastNode ); - while (itn->more()) { + for ( SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes(); itn->more() ; ) + { const SMDS_MeshNode * node = itn->next(); if ( node->NbInverseElements() == 0 ) meshDS->RemoveFreeNode( node, subMeshDS ); else // for StdMeshers_CompositeSegment_1D: node in one submesh, edge in another - meshDS->RemoveNode(node); + meshDS->RemoveNode( node ); } - } subMeshDS->Clear(); } } diff --git a/src/SMESHClient/SMESH_Client.cxx b/src/SMESHClient/SMESH_Client.cxx index f556f1a92..73ad16111 100644 --- a/src/SMESHClient/SMESH_Client.cxx +++ b/src/SMESHClient/SMESH_Client.cxx @@ -749,30 +749,30 @@ namespace SMESH::log_array_var& theSeq, CORBA::Long theId) { - const SMESH::long_array& anIndexes = theSeq[theId].indexes; - CORBA::Long iind = 0, aNbElems = theSeq[theId].number; - - for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) - { - // find element - const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]); - // nb nodes - int nbNodes = anIndexes[iind++]; - // nodes - std::vector aNodes (nbNodes); - for (int iNode = 0; iNode < nbNodes; iNode++) { - aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]); - } - // nb faces - int nbFaces = anIndexes[iind++]; - // quantities - std::vector quantities (nbFaces); - for (int iFace = 0; iFace < nbFaces; iFace++) { - quantities[iFace] = anIndexes[iind++]; - } - // change - theMesh->ChangePolyhedronNodes(elem, aNodes, quantities); - } + // const SMESH::long_array& anIndexes = theSeq[theId].indexes; + // CORBA::Long iind = 0, aNbElems = theSeq[theId].number; + + // for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) + // { + // // find element + // const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]); + // // nb nodes + // int nbNodes = anIndexes[iind++]; + // // nodes + // std::vector aNodes (nbNodes); + // for (int iNode = 0; iNode < nbNodes; iNode++) { + // aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]); + // } + // // nb faces + // int nbFaces = anIndexes[iind++]; + // // quantities + // std::vector quantities (nbFaces); + // for (int iFace = 0; iFace < nbFaces; iFace++) { + // quantities[iFace] = anIndexes[iind++]; + // } + // // change + // theMesh->ChangePolyhedronNodes(elem, aNodes, quantities); + // } } } @@ -986,10 +986,10 @@ SMESH_Client::Update(bool theIsClear) ChangePolyhedronNodes(mySMDSMesh, aSeq, anId); break; case SMESH::RENUMBER: - for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3) - { - mySMDSMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] ); - } + // for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3) + // { + // mySMDSMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] ); + // } break; default:; diff --git a/src/SMESHDS/SMESHDS_Group.cxx b/src/SMESHDS/SMESHDS_Group.cxx index 6ffa1b19c..e6df602ff 100644 --- a/src/SMESHDS/SMESHDS_Group.cxx +++ b/src/SMESHDS/SMESHDS_Group.cxx @@ -19,17 +19,13 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - -// SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes // File : SMESHDS_Group.cxx // Module : SMESH -// $Header$ // + #include "SMESHDS_Group.hxx" #include "SMESHDS_Mesh.hxx" -using namespace std; - //============================================================================= /*! * @@ -39,8 +35,8 @@ using namespace std; SMESHDS_Group::SMESHDS_Group (const int theID, const SMESHDS_Mesh* theMesh, const SMDSAbs_ElementType theType) - : SMESHDS_GroupBase(theID,theMesh,theType), - myGroup(theMesh,theType) + : SMESHDS_GroupBase(theID,theMesh,theType), + myGroup(theMesh,theType) { } @@ -147,20 +143,7 @@ void SMESHDS_Group::Clear() myGroup.Clear(); resetIterator(); } - -// ===================== -// class MyGroupIterator -// ===================== - -class MyGroupIterator: public SMDS_ElemIterator -{ - const SMDS_MeshGroup& myGroup; - public: - MyGroupIterator(const SMDS_MeshGroup& group): myGroup(group) { myGroup.InitIterator(); } - bool more() { return myGroup.More(); } - const SMDS_MeshElement* next() { return myGroup.Next(); } -}; - + //======================================================================= //function : GetElements //purpose : @@ -168,7 +151,7 @@ class MyGroupIterator: public SMDS_ElemIterator SMDS_ElemIteratorPtr SMESHDS_Group::GetElements() const { - return SMDS_ElemIteratorPtr( new MyGroupIterator ( myGroup )); + return myGroup.GetElements(); } //================================================================================ @@ -189,11 +172,14 @@ int SMESHDS_Group::GetTic() const void SMESHDS_Group::SetType(SMDSAbs_ElementType theType) { - if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All ) { + if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All ) + { SMESHDS_GroupBase::SetType( theType ); myGroup.SetType ( theType ); } else + { SMESHDS_GroupBase::SetType( myGroup.GetType() ); + } } diff --git a/src/SMESHDS/SMESHDS_GroupOnFilter.cxx b/src/SMESHDS/SMESHDS_GroupOnFilter.cxx index 7653e176c..e5b2fb736 100644 --- a/src/SMESHDS/SMESHDS_GroupOnFilter.cxx +++ b/src/SMESHDS/SMESHDS_GroupOnFilter.cxx @@ -26,11 +26,14 @@ #include "SMESHDS_GroupOnFilter.hxx" #include "SMDS_SetIterator.hxx" +#include "ObjectPool.hxx" #include "SMESHDS_Mesh.hxx" #include #include +#include + using namespace std; //#undef WITH_TBB @@ -45,11 +48,12 @@ SMESHDS_GroupOnFilter::SMESHDS_GroupOnFilter (const int theID, const SMESHDS_Mesh* theMesh, const SMDSAbs_ElementType theType, const SMESH_PredicatePtr& thePredicate) - : SMESHDS_GroupBase(theID,theMesh,theType), + : SMESHDS_GroupBase( theID, theMesh, theType ), + SMDS_ElementHolder( theMesh ), myMeshInfo( SMDSEntity_Last, 0 ), - myMeshModifTime(0), - myPredicateTic(0), - myNbElemToSkip(0) + myMeshModifTime( 0 ), + myPredicateTic( 0 ), + myNbElemToSkip( 0 ) { SetPredicate( thePredicate ); } @@ -532,3 +536,38 @@ SMESHDS_GroupOnFilter::setNbElemToSkip( SMDS_ElemIteratorPtr& okElemIt ) } return firstOkElem; } + +//================================================================================ +/*! + * \brief Return elements before mesh compacting + */ +//================================================================================ + +SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::getElements() +{ + return boost::make_shared< SMDS_ElementVectorIterator >( myElements.begin(), myElements.end() ); +} + +//================================================================================ +/*! + * \brief clear myElements before re-filling after mesh compacting + */ +//================================================================================ + +void SMESHDS_GroupOnFilter::tmpClear() +{ + std::vector< const SMDS_MeshElement*> newElems( myElements.size() ); + myElements.swap( newElems ); + myElements.clear(); +} + +//================================================================================ +/*! + * \brief Re-fill myElements after mesh compacting + */ +//================================================================================ + +void SMESHDS_GroupOnFilter::add( const SMDS_MeshElement* element ) +{ + myElements.push_back( element ); +} diff --git a/src/SMESHDS/SMESHDS_GroupOnFilter.hxx b/src/SMESHDS/SMESHDS_GroupOnFilter.hxx index 94bc25af4..9b235c1a3 100644 --- a/src/SMESHDS/SMESHDS_GroupOnFilter.hxx +++ b/src/SMESHDS/SMESHDS_GroupOnFilter.hxx @@ -27,13 +27,14 @@ #include "SMESH_SMESHDS.hxx" +#include "SMDS_ElementHolder.hxx" #include "SMESHDS_GroupBase.hxx" #include "SMESH_Controls.hxx" - + /*! * \brief Groups whose contents is dynamically updated using the filter */ -class SMESHDS_EXPORT SMESHDS_GroupOnFilter: public SMESHDS_GroupBase +class SMESHDS_EXPORT SMESHDS_GroupOnFilter: public SMESHDS_GroupBase, SMDS_ElementHolder { public: @@ -69,6 +70,13 @@ class SMESHDS_EXPORT SMESHDS_GroupOnFilter: public SMESHDS_GroupBase bool IsUpToDate() const; + protected: // methods of SMDS_ElementHolder + + virtual SMDS_ElemIteratorPtr getElements(); + virtual void tmpClear(); + virtual void add( const SMDS_MeshElement* element ); + virtual void compact() {}; + private: void update() const; diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index 865e700c1..e973495bf 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -50,8 +50,6 @@ #include "utilities.h" -using namespace std; - class SMESHDS_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< const SMESHDS_SubMesh > { }; @@ -105,7 +103,7 @@ int SMESHDS_Mesh::GetPersistentId() const //======================================================================= void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S) { - if ( !myShape.IsNull() && S.IsNull() ) + if ( !myShape.IsNull() && S.IsNull() ) // case: "save study" after geometry removal { // removal of a shape to mesh, delete ... // - hypotheses @@ -116,7 +114,7 @@ void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S) if ( !sm->IsComplexSubmesh() ) { SMDS_NodeIteratorPtr nIt = sm->GetNodes(); while ( nIt->more() ) - sm->RemoveNode(nIt->next(), false); + sm->RemoveNode(nIt->next()); } } // - sub-meshes @@ -124,7 +122,7 @@ void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S) myIndexToShape.Clear(); // - groups on geometry - set::iterator gr = myGroups.begin(); + std::set::iterator gr = myGroups.begin(); while ( gr != myGroups.end() ) { if ( dynamic_cast( *gr )) myGroups.erase( gr++ ); @@ -137,6 +135,8 @@ void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S) if ( !S.IsNull() ) TopExp::MapShapes(myShape, myIndexToShape); } + + SMDS_Mesh::setNbShapes( MaxShapeIndex() ); } //======================================================================= @@ -148,14 +148,14 @@ bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS, const SMESHDS_Hypothesis * H) { if (!myShapeToHypothesis.IsBound(SS/*.Oriented(TopAbs_FORWARD)*/)) { - list aList; + std::list aList; myShapeToHypothesis.Bind(SS/*.Oriented(TopAbs_FORWARD)*/, aList); } - list& alist = + std::list& alist = myShapeToHypothesis(SS/*.Oriented(TopAbs_FORWARD)*/); // ignore orientation of SS //Check if the Hypothesis is still present - list::iterator ith = find(alist.begin(),alist.end(), H ); + std::list::iterator ith = find(alist.begin(),alist.end(), H ); if (alist.end() != ith) return false; @@ -173,8 +173,8 @@ bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S, { if( myShapeToHypothesis.IsBound( S/*.Oriented(TopAbs_FORWARD)*/ ) ) { - list& alist=myShapeToHypothesis.ChangeFind( S/*.Oriented(TopAbs_FORWARD)*/ ); - list::iterator ith=find(alist.begin(),alist.end(), H ); + std::list& alist=myShapeToHypothesis.ChangeFind( S/*.Oriented(TopAbs_FORWARD)*/ ); + std::list::iterator ith=find(alist.begin(),alist.end(), H ); if (ith != alist.end()) { alist.erase(ith); @@ -223,7 +223,7 @@ bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem, if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes )) return false; - vector IDs( nbnodes ); + std::vector IDs( nbnodes ); for ( int i = 0; i < nbnodes; i++ ) IDs [ i ] = nodes[ i ]->GetID(); myScript->ChangeElementNodes( elem->GetID(), &IDs[0], nbnodes); @@ -236,8 +236,8 @@ bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem, //purpose : //======================================================================= bool SMESHDS_Mesh::ChangePolygonNodes - (const SMDS_MeshElement * elem, - vector nodes) +(const SMDS_MeshElement * elem, + std::vector nodes) { ASSERT(nodes.size() > 3); @@ -249,14 +249,14 @@ bool SMESHDS_Mesh::ChangePolygonNodes //purpose : //======================================================================= bool SMESHDS_Mesh::ChangePolyhedronNodes - (const SMDS_MeshElement * elem, - std::vector nodes, - std::vector quantities) +(const SMDS_MeshElement * elem, + std::vector nodes, + std::vector quantities) { ASSERT(nodes.size() > 3); - if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities)) - return false; + //if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities)) + return false; int i, len = nodes.size(); std::vector nodes_ids (len); @@ -276,10 +276,10 @@ bool SMESHDS_Mesh::ChangePolyhedronNodes void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID) { // TODO not possible yet to have node numbers not starting to O and continuous. - if (!this->isCompacted()) - this->compactMesh(); -// SMDS_Mesh::Renumber( isNodes, startID, deltaID ); -// myScript->Renumber( isNodes, startID, deltaID ); + if ( !this->IsCompacted() ) + this->CompactMesh(); + // SMDS_Mesh::Renumber( isNodes, startID, deltaID ); + // myScript->Renumber( isNodes, startID, deltaID ); } //======================================================================= @@ -294,7 +294,7 @@ SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID(int nodeID, int ID) } SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID - (const SMDS_MeshNode * node, int ID) +(const SMDS_MeshNode * node, int ID) { return Add0DElementWithID(node->GetID(), ID); } @@ -801,9 +801,9 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (const std::vector } SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID - (const std::vector& nodes, - const std::vector& quantities, - const int ID) +(const std::vector& nodes, + const std::vector& quantities, + const int ID) { SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID); if (anElem) { @@ -818,8 +818,8 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID } SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume - (const std::vector& nodes, - const std::vector& quantities) +(const std::vector& nodes, + const std::vector& quantities) { SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities); if (anElem) { @@ -838,10 +838,9 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume //purpose : //======================================================================= -static void removeFromContainers (SMESHDS_Mesh* theMesh, - set& theGroups, - list& theElems, - const bool isNode) +static void removeFromContainers (SMESHDS_Mesh* theMesh, + std::set& theGroups, + std::vector& theElems) { if ( theElems.empty() ) return; @@ -850,13 +849,13 @@ static void removeFromContainers (SMESHDS_Mesh* theMesh, // Element can belong to several groups if ( !theGroups.empty() ) { - set::iterator GrIt = theGroups.begin(); + std::set::iterator GrIt = theGroups.begin(); for ( ; GrIt != theGroups.end(); GrIt++ ) { SMESHDS_Group* group = dynamic_cast( *GrIt ); if ( !group || group->IsEmpty() ) continue; - list::iterator elIt = theElems.begin(); + std::vector::iterator elIt = theElems.begin(); for ( ; elIt != theElems.end(); elIt++ ) { group->SMDSGroup().Remove( *elIt ); @@ -865,24 +864,24 @@ static void removeFromContainers (SMESHDS_Mesh* theMesh, } } - const bool deleted=true; + //const bool deleted=true; // Rm from sub-meshes // Element should belong to only one sub-mesh - if ( theMesh->SubMeshes()->more() ) - { - list::iterator elIt = theElems.begin(); - if ( isNode ) { - for ( ; elIt != theElems.end(); ++elIt ) - if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() )) - sm->RemoveNode( static_cast (*elIt), deleted ); - } - else { - for ( ; elIt != theElems.end(); ++elIt ) - if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() )) - sm->RemoveElement( *elIt, deleted ); - } - } + // if ( theMesh->SubMeshes()->more() ) + // { + // std::list::iterator elIt = theElems.begin(); + // if ( isNode ) { + // for ( ; elIt != theElems.end(); ++elIt ) + // if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() )) + // sm->RemoveNode( static_cast (*elIt), deleted ); + // } + // else { + // for ( ; elIt != theElems.end(); ++elIt ) + // if ( SMESHDS_SubMesh* sm = theMesh->MeshElements( (*elIt)->getshapeId() )) + // sm->RemoveElement( *elIt, deleted ); + // } + // } } //======================================================================= @@ -891,56 +890,69 @@ static void removeFromContainers (SMESHDS_Mesh* theMesh, //======================================================================= void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n) { - if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces())) - { - RemoveFreeNode( n, 0, true ); + if ( RemoveFreeNode( n, 0, true )) return; - } myScript->RemoveNode(n->GetID()); - list removedElems; - list removedNodes; + // remove inverse elements from the sub-meshes + for ( SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator(); eIt->more() ; ) + { + const SMDS_MeshElement* e = eIt->next(); + if ( SMESHDS_SubMesh * sm = MeshElements( e->getshapeId() )) + sm->RemoveElement( e ); + } + if ( SMESHDS_SubMesh * sm = MeshElements( n->getshapeId() )) + sm->RemoveNode( n ); + + + std::vector removedElems; + std::vector removedNodes; SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true ); - removeFromContainers( this, myGroups, removedElems, false ); - removeFromContainers( this, myGroups, removedNodes, true ); + removeFromContainers( this, myGroups, removedElems ); + removeFromContainers( this, myGroups, removedNodes ); } //======================================================================= //function : RemoveFreeNode //purpose : //======================================================================= -void SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n, +bool SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n, SMESHDS_SubMesh * subMesh, bool fromGroups) { + if ( n->NbInverseElements() > 0 ) + return false; + myScript->RemoveNode(n->GetID()); // Rm from group // Node can belong to several groups - if (fromGroups && !myGroups.empty()) { - set::iterator GrIt = myGroups.begin(); + if ( fromGroups && !myGroups.empty() ) { + std::set::iterator GrIt = myGroups.begin(); for (; GrIt != myGroups.end(); GrIt++) { SMESHDS_Group* group = dynamic_cast(*GrIt); - if (group && !group->IsEmpty()) + if (group && group->GetType() == SMDSAbs_Node ) group->SMDSGroup().Remove(n); } } // Rm from sub-mesh // Node should belong to only one sub-mesh - if ( !subMesh || !subMesh->RemoveNode(n,/*deleted=*/false)) + if ( !subMesh || !subMesh->RemoveNode( n )) if (( subMesh = MeshElements( n->getshapeId() ))) - subMesh->RemoveNode(n,/*deleted=*/false ); + subMesh->RemoveNode(n); SMDS_Mesh::RemoveFreeElement(n); + + return true; } //======================================================================= //function : RemoveElement -//purpose : +//purpose : //======================================================================== void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt) { @@ -949,7 +961,7 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt) RemoveNode( static_cast( elt )); return; } - if (!hasConstructionEdges() && !hasConstructionFaces()) + //if (!hasConstructionEdges() && !hasConstructionFaces()) { SMESHDS_SubMesh* subMesh=0; if ( elt->getshapeId() > 0 ) @@ -961,12 +973,12 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt) myScript->RemoveElement(elt->GetID()); - list removedElems; - list removedNodes; + std::vector removedElems; + std::vector removedNodes; - SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false ); + SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes ); - removeFromContainers( this, myGroups, removedElems, false ); + removeFromContainers( this, myGroups, removedElems ); } //======================================================================= @@ -982,16 +994,16 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, return; } - if (hasConstructionEdges() || hasConstructionFaces()) - // this methods is only for meshes without descendants - return; + // if (hasConstructionEdges() || hasConstructionFaces()) + // // this methods is only for meshes without descendants + // return; myScript->RemoveElement(elt->GetID()); // Rm from group // Element can belong to several groups if ( fromGroups && !myGroups.empty() ) { - set::iterator GrIt = myGroups.begin(); + std::set::iterator GrIt = myGroups.begin(); for (; GrIt != myGroups.end(); GrIt++) { SMESHDS_Group* group = dynamic_cast(*GrIt); if (group && !group->IsEmpty()) @@ -1004,7 +1016,7 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, if ( !subMesh && elt->getshapeId() > 0 ) subMesh = MeshElements( elt->getshapeId() ); if ( subMesh ) - subMesh->RemoveElement( elt, /*deleted=*/false ); + subMesh->RemoveElement( elt ); SMDS_Mesh::RemoveFreeElement( elt ); } @@ -1043,8 +1055,8 @@ void SMESHDS_Mesh::ClearMesh() //================================================================================ /*! * \brief return submesh by shape - * \param shape - the sub-shape - * \retval SMESHDS_SubMesh* - the found submesh + * \param shape - the sub-shape + * \retval SMESHDS_SubMesh* - the found submesh */ //================================================================================ @@ -1059,84 +1071,81 @@ SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const TopoDS_Shape & shape ) //================================================================================ /*! * \brief Add element or node to submesh - * \param elem - element to add - * \param subMesh - submesh to be filled in + * \param elem - element to add + * \param subMesh - submesh to be filled in */ //================================================================================ -bool SMESHDS_Mesh::add(const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh ) +int SMESHDS_Mesh::add(const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh ) { if ( elem && subMesh ) { - if ( elem->GetType() == SMDSAbs_Node ) - subMesh->AddNode( static_cast( elem )); - else - subMesh->AddElement( elem ); - return true; + subMesh->AddElement( elem ); + return subMesh->GetID(); } - return false; + return 0; } //======================================================================= //function : SetNodeOnVolume -//purpose : +//purpose : //======================================================================= void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, const TopoDS_Shell & S) { - if ( add( aNode, getSubmesh(S) )) + if ( int shapeID = add( aNode, getSubmesh( S ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition( SMDS_SpacePosition::originSpacePosition() ); + ( aNode )->SetPosition( SMDS_SpacePosition::originSpacePosition(), shapeID ); } //======================================================================= //function : SetNodeOnVolume -//purpose : +//purpose : //======================================================================= void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode * aNode, const TopoDS_Solid & S) { - if ( add( aNode, getSubmesh(S) )) + if ( int shapeID = add( aNode, getSubmesh( S ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition( SMDS_SpacePosition::originSpacePosition() ); + ( aNode )->SetPosition( SMDS_SpacePosition::originSpacePosition(), shapeID ); } //======================================================================= //function : SetNodeOnFace -//purpose : +//purpose : //======================================================================= -void SMESHDS_Mesh::SetNodeOnFace(const SMDS_MeshNode * aNode, - const TopoDS_Face & S, - double u, - double v) +void SMESHDS_Mesh::SetNodeOnFace(const SMDS_MeshNode * aNode, + const TopoDS_Face & S, + double u, + double v) { - if ( add( aNode, getSubmesh(S) )) + if ( int shapeID = add( aNode, getSubmesh( S ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v))); + ( aNode )->SetPosition(SMDS_PositionPtr( new SMDS_FacePosition( u, v )), shapeID ); } //======================================================================= //function : SetNodeOnEdge -//purpose : +//purpose : //======================================================================= -void SMESHDS_Mesh::SetNodeOnEdge(const SMDS_MeshNode * aNode, - const TopoDS_Edge & S, - double u) +void SMESHDS_Mesh::SetNodeOnEdge(const SMDS_MeshNode * aNode, + const TopoDS_Edge & S, + double u) { - if ( add( aNode, getSubmesh(S) )) + if ( int shapeID = add( aNode, getSubmesh( S ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u))); + ( aNode )->SetPosition(SMDS_PositionPtr( new SMDS_EdgePosition( u )), shapeID ); } //======================================================================= //function : SetNodeOnVertex -//purpose : +//purpose : //======================================================================= -void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode * aNode, +void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode * aNode, const TopoDS_Vertex & S) { - if ( add( aNode, getSubmesh(S) )) + if ( int shapeID = add( aNode, getSubmesh( S ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition())); + ( aNode )->SetPosition(SMDS_PositionPtr( new SMDS_VertexPosition()), shapeID ); } //======================================================================= @@ -1148,12 +1157,12 @@ void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode) int shapeId = aNode->getshapeId(); if (shapeId > 0) if ( SMESHDS_SubMesh* sm = MeshElements( shapeId )) - sm->RemoveNode(aNode, /*deleted=*/false); + sm->RemoveNode(aNode); } //======================================================================= //function : SetMeshElementOnShape -//purpose : +//purpose : //======================================================================= void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement, const TopoDS_Shape & S) @@ -1169,12 +1178,7 @@ void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem, const TopoDS_Shape & S) { if ( SMESHDS_SubMesh* sm = MeshElements( S )) - { - if (elem->GetType() == SMDSAbs_Node) - sm->RemoveNode(static_cast (elem), /*deleted=*/false); - else - sm->RemoveElement(elem, /*deleted=*/false); - } + sm->RemoveElement(elem); } //======================================================================= @@ -1226,9 +1230,9 @@ SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index) const //function : SubMeshIndices //purpose : //======================================================================= -list SMESHDS_Mesh::SubMeshIndices() const +std::list SMESHDS_Mesh::SubMeshIndices() const { - list anIndices; + std::list anIndices; SMESHDS_SubMeshIteratorPtr smIt = SubMeshes(); while ( const SMESHDS_SubMesh* sm = smIt->next() ) anIndices.push_back( sm->GetID() ); @@ -1251,13 +1255,13 @@ SMESHDS_SubMeshIteratorPtr SMESHDS_Mesh::SubMeshes() const //purpose : //======================================================================= -const list& +const std::list& SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape & S) const { if ( myShapeToHypothesis.IsBound( S/*.Oriented(TopAbs_FORWARD)*/ ) ) // ignore orientation of S - return myShapeToHypothesis.Find( S/*.Oriented(TopAbs_FORWARD)*/ ); + return myShapeToHypothesis.Find( S/*.Oriented(TopAbs_FORWARD)*/ ); - static list empty; + static std::list empty; return empty; } @@ -1282,7 +1286,7 @@ bool SMESHDS_Mesh::IsUsedHypothesis(const SMESHDS_Hypothesis * H) const //======================================================================= SMESHDS_Script* SMESHDS_Mesh::GetScript() { - return myScript; + return myScript; } //======================================================================= @@ -1291,7 +1295,7 @@ SMESHDS_Script* SMESHDS_Mesh::GetScript() //======================================================================= void SMESHDS_Mesh::ClearScript() { - myScript->Clear(); + myScript->Clear(); } //======================================================================= @@ -1408,46 +1412,46 @@ int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const //======================================================================= void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index) { - if ( add( aNode, NewSubMesh( Index ))) - ((SMDS_MeshNode*) aNode)->SetPosition( SMDS_SpacePosition::originSpacePosition()); + if ( int shapeID = add( aNode, NewSubMesh( Index ))) + ((SMDS_MeshNode*) aNode)->SetPosition( SMDS_SpacePosition::originSpacePosition(), shapeID ); } //======================================================================= //function : SetNodeOnFace -//purpose : +//purpose : //======================================================================= void SMESHDS_Mesh::SetNodeOnFace(const SMDS_MeshNode* aNode, int Index, double u, double v) { //Set Position on Node - if ( add( aNode, NewSubMesh( Index ))) + if ( int shapeID = add( aNode, NewSubMesh( Index ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v))); + ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v )), shapeID ); } //======================================================================= //function : SetNodeOnEdge -//purpose : +//purpose : //======================================================================= void SMESHDS_Mesh::SetNodeOnEdge(const SMDS_MeshNode* aNode, int Index, double u) { //Set Position on Node - if ( add( aNode, NewSubMesh( Index ))) + if ( int shapeID = add( aNode, NewSubMesh( Index ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u))); + ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition( u )), shapeID ); } //======================================================================= //function : SetNodeOnVertex -//purpose : +//purpose : //======================================================================= void SMESHDS_Mesh::SetNodeOnVertex(const SMDS_MeshNode* aNode, int Index) { //Set Position on Node - if ( add( aNode, NewSubMesh( Index ))) + if ( int shapeID = add( aNode, NewSubMesh( Index ))) const_cast< SMDS_MeshNode* > - ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition())); + ( aNode )->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition()), shapeID ); } //======================================================================= @@ -2213,7 +2217,7 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, const SMDS_MeshNode * n15, const SMDS_MeshNode * n26, const SMDS_MeshNode * n37, - const SMDS_MeshNode * n48, + const SMDS_MeshNode * n48, const SMDS_MeshNode * n1234, const SMDS_MeshNode * n1256, const SMDS_MeshNode * n2367, @@ -2232,126 +2236,14 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, n1458->GetID(),n5678->GetID(),nCenter->GetID(), ID); } -void SMESHDS_Mesh::compactMesh() +void SMESHDS_Mesh::CompactMesh() { - if ( isCompacted() ) + if ( IsCompacted() ) return; - SMDS_Mesh::compactMesh(); - - int newNodeSize = 0; - int nbNodes = myNodes.size(); - int nbVtkNodes = myGrid->GetNumberOfPoints(); - int nbNodeTemp = Max( nbVtkNodes, nbNodes ); - vector idNodesOldToNew(nbNodeTemp, -1); // all unused id will be -1 - - for (int i = 0; i < nbNodes; i++) - { - if (myNodes[i]) - { - int vtkid = myNodes[i]->getVtkId(); - idNodesOldToNew[vtkid] = i; // old vtkId --> old smdsId (valid smdsId are >= 0) - newNodeSize++; - } - } - bool areNodesModified = (newNodeSize != nbVtkNodes); - areNodesModified = true; - - int newCellSize = 0; - int nbCells = myCells.size(); - int nbVtkCells = myGrid->GetNumberOfCells(); - int nbCellTemp = Max( nbVtkCells, nbCells ); - vector idCellsOldToNew(nbCellTemp, -1); // all unused id will be -1 - - for (int i = 0; i < nbCells; i++) - { - if (myCells[i]) - { - newCellSize++; - } - } - if (areNodesModified) - myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize); - else - myGrid->compactGrid(idNodesOldToNew, 0, idCellsOldToNew, newCellSize); - - int nbVtkPts = myGrid->GetNumberOfPoints(); - nbVtkCells = myGrid->GetNumberOfCells(); - if (nbVtkPts != newNodeSize) - { - MESSAGE("===> nbVtkPts != newNodeSize " << nbVtkPts << " " << newNodeSize); - if (nbVtkPts > newNodeSize) newNodeSize = nbVtkPts; // several points with same SMDS Id - } - if (nbVtkCells != newCellSize) - { - MESSAGE("===> nbVtkCells != newCellSize " << nbVtkCells << " " << newCellSize); - if (nbVtkCells > newCellSize) newCellSize = nbVtkCells; // several cells with same SMDS Id - } - // --- SMDS_MeshNode and myNodes, myNodeIdFactory - - if ( true ) - { - SetOfNodes newNodes(newNodeSize+1,NULL); // 0 not used, SMDS numbers 1..n - int newSmdsId = 0; - for (int i = 0; i < nbNodes; i++) - { - if (myNodes[i]) - { - newSmdsId++; // SMDS id starts from 1 - int oldVtkId = myNodes[i]->getVtkId(); - int newVtkId = idNodesOldToNew[oldVtkId]; - myNodes[i]->setVtkId(newVtkId); - myNodes[i]->setId(newSmdsId); - newNodes[newSmdsId] = myNodes[i]; - } - } - myNodes.swap(newNodes); - this->myNodeIDFactory->emptyPool(newSmdsId); // newSmdsId = number of nodes - } - - // --- SMDS_MeshCell, myCellIdVtkToSmds, myCellIdSmdsToVtk, myCells - - int vtkIndexSize = myCellIdVtkToSmds.size(); - for (int oldVtkId = 0; oldVtkId < vtkIndexSize; oldVtkId++) - { - int oldSmdsId = this->myCellIdVtkToSmds[oldVtkId]; - if (oldSmdsId > 0) - { - int newVtkId = idCellsOldToNew[oldVtkId]; - myCells[oldSmdsId]->setVtkId(newVtkId); - } - } - - SetOfCells newCells(newCellSize+1, NULL); // 0 not used, SMDS numbers 1..n - vector newVtkToSmds(newCellSize+1, -1); - - int myCellsSize = myCells.size(); - int newSmdsId = 0; - for (int i = 0; i < myCellsSize; i++) - { - if ( myCells[i] ) - { - newSmdsId++; // SMDS id starts from 1 - assert(newSmdsId <= newCellSize); - newCells[newSmdsId] = myCells[i]; - newCells[newSmdsId]->setId(newSmdsId); - int idvtk = myCells[i]->getVtkId(); - assert(idvtk < newCellSize); - newVtkToSmds[idvtk] = newSmdsId; - } - } - - myCells.swap(newCells); - myCellIdVtkToSmds.swap(newVtkToSmds); - this->myElementIDFactory->emptyPool(newSmdsId); + SMDS_Mesh::CompactMesh(); this->myScript->SetModified(true); // notify GUI client for buildPrs when update - - // --- compact list myNodes and myElements in submeshes - - SMESHDS_SubMeshIteratorPtr smIt = SubMeshes(); - while ( SMESHDS_SubMesh* sm = const_cast< SMESHDS_SubMesh* >( smIt->next() )) - sm->compactList(); } void SMESHDS_Mesh::CleanDownWardConnectivity() diff --git a/src/SMESHDS/SMESHDS_Mesh.hxx b/src/SMESHDS/SMESHDS_Mesh.hxx index 92f631890..51baee630 100644 --- a/src/SMESHDS/SMESHDS_Mesh.hxx +++ b/src/SMESHDS/SMESHDS_Mesh.hxx @@ -66,7 +66,7 @@ class DownIdType; class SMESHDS_EXPORT SMESHDS_Mesh : public SMDS_Mesh { -public: + public: SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode); bool IsEmbeddedMode(); void SetPersistentId(int id); @@ -566,18 +566,18 @@ public: virtual SMDS_MeshFace* AddQuadPolygonalFace(const std::vector & nodes); virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID - (const std::vector& nodes_ids, - const std::vector& quantities, - const int ID); + (const std::vector& nodes_ids, + const std::vector& quantities, + const int ID); virtual SMDS_MeshVolume* AddPolyhedralVolumeWithID - (const std::vector& nodes, - const std::vector& quantities, - const int ID); + (const std::vector& nodes, + const std::vector& quantities, + const int ID); virtual SMDS_MeshVolume* AddPolyhedralVolume - (const std::vector& nodes, - const std::vector& quantities); + (const std::vector& nodes, + const std::vector& quantities); virtual void MoveNode(const SMDS_MeshNode *, double x, double y, double z); virtual void RemoveNode(const SMDS_MeshNode *); @@ -587,7 +587,7 @@ public: * Methods do not work for meshes with descendants. * Implemented for fast cleaning of meshes. */ - void RemoveFreeNode (const SMDS_MeshNode *, SMESHDS_SubMesh *, bool fromGroups=true); + bool RemoveFreeNode (const SMDS_MeshNode *, SMESHDS_SubMesh *, bool fromGroups=true); void RemoveFreeElement(const SMDS_MeshElement *, SMESHDS_SubMesh *, bool fromGroups=true); void ClearMesh(); @@ -646,13 +646,13 @@ public: bool IsGroupOfSubShapes (const TopoDS_Shape& aSubShape) const; - virtual void compactMesh(); + virtual void CompactMesh(); void CleanDownWardConnectivity(); void BuildDownWardConnectivity(bool withEdges); ~SMESHDS_Mesh(); -private: + private: ShapeToHypothesis myShapeToHypothesis; @@ -665,12 +665,12 @@ private: TopTools_IndexedMapOfShape myIndexToShape; typedef std::set TGroups; - TGroups myGroups; + TGroups myGroups; SMESHDS_Script* myScript; bool myIsEmbeddedMode; - bool add( const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh ); + int add( const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh ); SMESHDS_SubMesh* getSubmesh( const TopoDS_Shape & shape); }; diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index 892873016..4a086e3b7 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -27,15 +27,12 @@ // $Header: // #include "SMESHDS_SubMesh.hxx" -#include "SMESHDS_Mesh.hxx" -#include "utilities.h" +#include "SMESHDS_Mesh.hxx" #include "SMDS_SetIterator.hxx" -#include -#include - -using namespace std; +#include "SMDS_ElementFactory.hxx" +#include //================================================================================ /*! @@ -47,8 +44,8 @@ SMESHDS_SubMesh::SMESHDS_SubMesh(SMESHDS_Mesh *parent, int index) { myParent = parent; myIndex = index; - myUnusedIdNodes = 0; - myUnusedIdElements = 0; + myNbElements = 0; + myNbNodes = 0; } //================================================================================ @@ -66,16 +63,16 @@ SMESHDS_SubMesh::~SMESHDS_SubMesh() //purpose : //======================================================================= -void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME) +void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * elem) { if (!IsComplexSubmesh()) { - if ( ME->GetType() == SMDSAbs_Node ) + if ( elem->GetType() == SMDSAbs_Node ) { - AddNode( static_cast< const SMDS_MeshNode* >( ME )); + AddNode( static_cast< const SMDS_MeshNode* >( elem )); return; } - int oldShapeId = ME->getshapeId(); + int oldShapeId = elem->GetShapeID(); if ( oldShapeId > 0 ) { if (oldShapeId != myIndex) @@ -83,28 +80,10 @@ void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME) throw SALOME_Exception (LOCALIZED("add element in subshape already belonging to a subshape")); } - int idInSubShape = ME->getIdInShape(); - if (idInSubShape >= 0) - { - MESSAGE("add element in subshape already belonging to that subshape " - << ME->GetID() << " " << oldShapeId << " " << idInSubShape); - // check if ok: do nothing if ok - if (idInSubShape >= (int)myElements.size()) - { - throw SALOME_Exception(LOCALIZED("out of bounds")); - } - if (ME != myElements[idInSubShape]) - { - throw SALOME_Exception(LOCALIZED("not the same element")); - } - return; - } } - SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME); - elem->setShapeId(myIndex); - elem->setIdInShape(myElements.size()); - myElements.push_back(ME); + elem->setShapeID( myIndex ); + myNbElements++; } } @@ -113,41 +92,17 @@ void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME) //purpose : //======================================================================= -bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted) +bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * elem ) { - if (!ME) + if ( !elem || elem->IsNull() || elem->getshapeId() != myIndex ) { return false; } - if (!IsComplexSubmesh()) + if ( !IsComplexSubmesh() ) { - if ( ME->getshapeId() != myIndex ) // elem not in a pool can loose it's data already - { - if ( isElemDeleted ) - for ( size_t i = 0; i < myElements.size(); ++i ) - if ( myElements[i] == ME ) - { - myElements[i] = 0; - ++myUnusedIdElements; - return true; - } - return false; - } - int idInSubShape = ME->getIdInShape(); - SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME); - elem->setShapeId(0); - elem->setIdInShape(-1); - if ((idInSubShape >= 0) && (idInSubShape < (int) myElements.size())) - { - myElements[idInSubShape] = 0; // this vector entry is no more used - if ( ++myUnusedIdElements == (int) myElements.size() ) - { - clearVector( myElements ); - myUnusedIdElements = 0; - } - return true; - } - return false; + elem->setShapeID( 0 ); + myNbElements--; + return true; } return false; } @@ -161,22 +116,16 @@ void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N) { if ( !IsComplexSubmesh() ) { - const int idInSubShape = N->getIdInShape(); - const int shapeId = N->getshapeId(); - if ((shapeId > 0) && (idInSubShape >= 0)) + const int shapeId = N->getshapeId(); + if ( shapeId > 0 ) { if ( shapeId != myIndex ) throw SALOME_Exception (LOCALIZED("a node being in sub-mesh is added to another sub-mesh")); - if ( idInSubShape >= (int)myNodes.size() || myNodes[ idInSubShape ] != N ) - throw SALOME_Exception - (LOCALIZED("a node with wrong idInSubShape is re-added to the same sub-mesh")); return; // already in } - SMDS_MeshNode* node = (SMDS_MeshNode*)(N); - node->setShapeId(myIndex); - node->setIdInShape(myNodes.size()); - myNodes.push_back(N); + N->setShapeID( myIndex ); + myNbNodes++; } } @@ -185,38 +134,18 @@ void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N) //purpose : //======================================================================= -bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted) +bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N) { - if (!IsComplexSubmesh()) + if ( !N || N->getshapeId() != myIndex ) { - if ( N->getshapeId() != myIndex ) - { - if ( isNodeDeleted ) - for ( size_t i = 0; i < myNodes.size(); ++i ) - if ( myNodes[i] == N ) - { - myNodes[i] = 0; - ++myUnusedIdNodes; - return true; - } - return false; - } - int idInSubShape = N->getIdInShape(); - SMDS_MeshNode* node = (SMDS_MeshNode*) (N); - node->setShapeId(0); - node->setIdInShape(-1); - if ((idInSubShape >= 0) && (idInSubShape < (int) myNodes.size())) - { - myNodes[idInSubShape] = 0; // this vector entry is no more used - if ( ++myUnusedIdNodes == (int) myNodes.size() ) - { - clearVector( myNodes ); - myUnusedIdNodes = 0; - } - return true; - } return false; } + if ( !IsComplexSubmesh() ) + { + N->setShapeID( 0 ); + myNbNodes--; + return true; + } return false; } @@ -228,10 +157,10 @@ bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted) int SMESHDS_SubMesh::NbElements() const { if ( !IsComplexSubmesh() ) - return myElements.size() - myUnusedIdElements; + return myNbElements; int nbElems = 0; - set::const_iterator it = mySubMeshes.begin(); + TSubMeshSet::const_iterator it = mySubMeshes.begin(); for ( ; it != mySubMeshes.end(); it++ ) nbElems += (*it)->NbElements(); @@ -246,10 +175,10 @@ int SMESHDS_SubMesh::NbElements() const int SMESHDS_SubMesh::NbNodes() const { if ( !IsComplexSubmesh() ) - return myNodes.size() - myUnusedIdNodes; + return myNbNodes; int nbElems = 0; - set::const_iterator it = mySubMeshes.begin(); + TSubMeshSet::const_iterator it = mySubMeshes.begin(); for ( ; it != mySubMeshes.end(); it++ ) nbElems += (*it)->NbNodes(); @@ -306,7 +235,7 @@ public: template class MyIterator : public SMDS_Iterator { public: - MyIterator (const set& theSubMeshes) + MyIterator (const TSubMeshSet& theSubMeshes) : myMore(false), mySubIt( theSubMeshes.begin() ), mySubEnd( theSubMeshes.end() ) {} bool more() @@ -331,9 +260,9 @@ protected: getElements(const SMESHDS_SubMesh*) const = 0; private: - bool myMore; - set::const_iterator mySubIt, mySubEnd; - boost::shared_ptr< SMDS_Iterator > myElemIt; + bool myMore; + TSubMeshSet::const_iterator mySubIt, mySubEnd; + boost::shared_ptr< SMDS_Iterator > myElemIt; }; // ===================== @@ -343,7 +272,7 @@ private: class MyElemIterator: public MyIterator { public: - MyElemIterator (const set& theSubMeshes) + MyElemIterator (const TSubMeshSet& theSubMeshes) :MyIterator( theSubMeshes ) {} SMDS_ElemIteratorPtr getElements(const SMESHDS_SubMesh* theSubMesh) const { return theSubMesh->GetElements(); } @@ -356,7 +285,7 @@ public: class MyNodeIterator: public MyIterator { public: - MyNodeIterator (const set& theSubMeshes) + MyNodeIterator (const TSubMeshSet& theSubMeshes) :MyIterator( theSubMeshes ) {} SMDS_NodeIteratorPtr getElements(const SMESHDS_SubMesh* theSubMesh) const { return theSubMesh->GetNodes(); } @@ -367,13 +296,12 @@ public: //purpose : //======================================================================= -SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements( bool reverse ) const +SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements() const { if ( IsComplexSubmesh() ) return SMDS_ElemIteratorPtr( new MyElemIterator( mySubMeshes )); - typedef MySetIterator< const SMDS_MeshElement*, std::vector > TIter; - return SMDS_ElemIteratorPtr( new TIter( myElements, reverse )); + return myParent->shapeElementsIterator( myIndex, myNbElements ); } //======================================================================= @@ -381,13 +309,12 @@ SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements( bool reverse ) const //purpose : //======================================================================= -SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes( bool reverse ) const +SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes() const { if ( IsComplexSubmesh() ) return SMDS_NodeIteratorPtr( new MyNodeIterator( mySubMeshes )); - typedef MySetIterator< const SMDS_MeshNode*, std::vector > TIter; - return SMDS_NodeIteratorPtr( new TIter( myNodes, reverse )); + return myParent->shapeNodesIterator( myIndex, myNbNodes ); } //======================================================================= @@ -397,35 +324,18 @@ SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes( bool reverse ) const bool SMESHDS_SubMesh::Contains(const SMDS_MeshElement * ME) const { - // DO NOT TRY TO FIND A REMOVED ELEMENT !! - //if ( IsComplexSubmesh() || !ME ) - if (!ME) + if ( !ME || ME->IsNull() ) return false; if ( IsComplexSubmesh() ) { - set::const_iterator aSubIt = mySubMeshes.begin(); + TSubMeshSet::const_iterator aSubIt = mySubMeshes.begin(); for (; aSubIt != mySubMeshes.end(); aSubIt++) if ((*aSubIt)->Contains(ME)) return true; return false; } - - if (ME->GetType() == SMDSAbs_Node) - { - int idInShape = ME->getIdInShape(); - if ((idInShape >= 0) && (idInShape < (int) myNodes.size())) - if (myNodes[idInShape] == ME) - return true; - } - else - { - int idInShape = ME->getIdInShape(); - if ((idInShape >= 0) && (idInShape < (int) myElements.size())) - if (myElements[idInShape] == ME) - return true; - } - return false; + return ME->getshapeId() == myIndex; } //======================================================================= @@ -437,18 +347,18 @@ bool SMESHDS_SubMesh::IsQuadratic() const { if ( IsComplexSubmesh() ) { - set::const_iterator aSubIt = mySubMeshes.begin(); + TSubMeshSet::const_iterator aSubIt = mySubMeshes.begin(); for (; aSubIt != mySubMeshes.end(); aSubIt++) if ((*aSubIt)->IsQuadratic()) return true; return false; } - for ( size_t i = 0; i < myElements.size(); ++i ) - if ( myElements[i] ) - return myElements[i]->IsQuadratic(); + if ( myNbElements == 0 ) + return false; - return false; + SMDS_ElemIteratorPtr it = GetElements(); + return it->more() && it->next()->IsQuadratic(); } //======================================================================= @@ -499,10 +409,8 @@ bool SMESHDS_SubMesh::ContainsSubMesh( const SMESHDS_SubMesh* theSubMesh ) const SMESHDS_SubMeshIteratorPtr SMESHDS_SubMesh::GetSubMeshIterator() const { - typedef set::const_iterator TIterator; - return SMESHDS_SubMeshIteratorPtr - ( new SMDS_SetIterator< const SMESHDS_SubMesh*, TIterator >( mySubMeshes.begin(), - mySubMeshes.end())); + typedef SMDS_SetIterator< const SMESHDS_SubMesh*, TSubMeshSet::const_iterator > TIterator; + return boost::make_shared< TIterator >( mySubMeshes.begin(), mySubMeshes.end()); } //======================================================================= @@ -514,26 +422,22 @@ void SMESHDS_SubMesh::Clear() { if ( myParent && myParent->NbNodes() > 0 ) { - for ( size_t i = 0; i < myElements.size(); ++i ) - { - if ( myElements[i] && - myElements[i]->GetID() > 0 && - myElements[i] == myParent->FindElement( myElements[i]->GetID() )) // not deleted - const_cast< SMDS_MeshElement* >( myElements[i] )->setShapeId( 0 ); - } - for ( size_t i = 0; i < myNodes.size(); ++i ) - { - if ( myNodes[i] && - myNodes[i]->GetID() > 0 && - myNodes[i] == myParent->FindNode( myNodes[i]->GetID() )) // not deleted - const_cast< SMDS_MeshNode* >( myNodes[i] )->setShapeId( 0 ); - } + if ( myNbElements > 0 ) + for ( SMDS_ElemIteratorPtr it = GetElements(); it->more(); ) + { + const SMDS_MeshElement * elem = it->next(); + elem->setShapeID( 0 ); + } + if ( myNbNodes > 0 ) + for ( SMDS_NodeIteratorPtr it = GetNodes(); it->more(); ) + { + const SMDS_MeshNode * elem = it->next(); + elem->setShapeID( 0 ); + } } - clearVector( myElements ); - clearVector( myNodes ); - myUnusedIdNodes = 0; - myUnusedIdElements = 0; + myNbElements = 0; + myNbNodes = 0; if ( NbSubMeshes() > 0 ) { SMESHDS_SubMeshIteratorPtr sub = GetSubMeshIterator(); @@ -543,71 +447,3 @@ void SMESHDS_SubMesh::Clear() } } } - -int SMESHDS_SubMesh::getSize() -{ - int c = NbNodes(); - int d = NbElements(); - return c+d; -} - -void SMESHDS_SubMesh::compactList() -{ - if ( myUnusedIdElements > 0 ) - { - std::vector newElems; - newElems.reserve( myElements.size() - myUnusedIdElements ); - for ( size_t i = 0; i < myElements.size(); i++) - if ( myElements[i] ) - { - SMDS_MeshElement* elem = (SMDS_MeshElement*)myElements[i]; - elem->setIdInShape( newElems.size() ); - newElems.push_back( elem ); - } - myElements.swap(newElems); - myUnusedIdElements = 0; - } - else - { - std::vector( myElements ).swap( myElements ); - } - - if ( myUnusedIdNodes > 0 ) - { - std::vector newNodes; - newNodes.reserve( myNodes.size() - myUnusedIdNodes ); - for ( size_t i = 0; i < myNodes.size(); i++ ) - if ( myNodes[i] ) - { - SMDS_MeshNode* node = (SMDS_MeshNode*)myNodes[i]; - node->setIdInShape( newNodes.size() ); - newNodes.push_back( node ); - } - myNodes.swap(newNodes); - myUnusedIdNodes = 0; - } - else - { - std::vector( myNodes ).swap( myNodes ); - } -} - -//======================================================================= -//function : GetElement -//purpose : Return an element by its IdInShape -//======================================================================= - -const SMDS_MeshElement* SMESHDS_SubMesh::GetElement( size_t idInShape ) const -{ - return ( !IsComplexSubmesh() && idInShape < myElements.size() ) ? myElements[idInShape] : 0; -} - -//======================================================================= -//function : GetElement -//purpose : Return a node by its IdInShape -//======================================================================= - -const SMDS_MeshNode* SMESHDS_SubMesh::GetNode( size_t idInShape ) const -{ - return ( !IsComplexSubmesh() && idInShape < myNodes.size() ) ? myNodes[idInShape] : 0; -} diff --git a/src/SMESHDS/SMESHDS_SubMesh.hxx b/src/SMESHDS/SMESHDS_SubMesh.hxx index 9a9d61f63..2caffb10b 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.hxx +++ b/src/SMESHDS/SMESHDS_SubMesh.hxx @@ -30,9 +30,12 @@ #include "SMESH_SMESHDS.hxx" #include "SMDS_Mesh.hxx" -#include #include +#include +class SMESHDS_SubMesh; +typedef boost::container::flat_set< const SMESHDS_SubMesh* > TSubMeshSet; + class SMESHDS_SubMesh; typedef SMDS_Iterator SMESHDS_SubMeshIterator; typedef boost::shared_ptr< SMESHDS_SubMeshIterator > SMESHDS_SubMeshIteratorPtr; @@ -49,11 +52,11 @@ class SMESHDS_EXPORT SMESHDS_SubMesh // if !IsComplexSubmesh() virtual void AddElement(const SMDS_MeshElement * ME); - virtual bool RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted); // ret true if ME was in + virtual bool RemoveElement(const SMDS_MeshElement * ME); // ret true if ME was in virtual void AddNode(const SMDS_MeshNode * ME); - virtual bool RemoveNode(const SMDS_MeshNode * ME, bool isNodeDeleted); // ret true if ME was in - virtual const SMDS_MeshElement* GetElement( size_t idInShape ) const; - virtual const SMDS_MeshNode* GetNode ( size_t idInShape ) const; + virtual bool RemoveNode(const SMDS_MeshNode * ME); // ret true if ME was in + //virtual const SMDS_MeshElement* GetElement( size_t idInShape ) const; + //virtual const SMDS_MeshNode* GetNode ( size_t idInShape ) const; // if IsComplexSubmesh() void AddSubMesh( const SMESHDS_SubMesh* theSubMesh ); @@ -65,29 +68,25 @@ class SMESHDS_EXPORT SMESHDS_SubMesh // for both types virtual int NbElements() const; - virtual SMDS_ElemIteratorPtr GetElements(bool reverse=false) const; virtual int NbNodes() const; - virtual SMDS_NodeIteratorPtr GetNodes(bool reverse=false) const; + virtual SMDS_ElemIteratorPtr GetElements() const; + virtual SMDS_NodeIteratorPtr GetNodes() const; virtual bool Contains(const SMDS_MeshElement * ME) const; // check if elem or node is in virtual bool IsQuadratic() const; // clear the contents virtual void Clear(); - int getSize(); - void compactList(); SMESHDS_Mesh* GetParent() const { return const_cast< SMESHDS_Mesh*>( myParent ); } int GetID() const { return myIndex; } private: - SMESHDS_Mesh * myParent; - std::vector myElements; - std::vector myNodes; - int myUnusedIdNodes; - int myUnusedIdElements; - int myIndex; + int myIndex; + int myNbElements; + int myNbNodes; + SMESHDS_Mesh * myParent; + TSubMeshSet mySubMeshes; - std::set mySubMeshes; }; #endif diff --git a/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx b/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx index 30ab3e6d0..0491cfef9 100644 --- a/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ExtrusionDlg.cxx @@ -1289,7 +1289,7 @@ void SMESHGUI_ExtrusionDlg::ClickOnHelp() #endif SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", + arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)). arg(myHelpFileName)); } @@ -1323,7 +1323,7 @@ void SMESHGUI_ExtrusionDlg::SelectionIntoArgument() return; const SMDS_MeshFace* face = - dynamic_cast(aMesh->FindElement(aMapIndex(1))); + aMesh->DownCast< SMDS_MeshFace >(aMesh->FindElement(aMapIndex(1))); if (!face) return; diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index 4f9b3cce3..7b9f4974f 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -1426,8 +1426,8 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() aGroupMainShape = aGeomGroup; aGroupMainShape->Register(); } - _PTR(SObject) aGroupMainShapeSO = - aStudy->FindObjectID(aGroupMainShape->GetStudyEntry()); + CORBA::String_var entry = aGroupMainShape->GetStudyEntry(); + _PTR(SObject) aGroupMainShapeSO = aStudy->FindObjectID( entry.in() ); _PTR(SObject) anObj, aRef; bool isRefOrSubShape = false; @@ -1451,10 +1451,10 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() myGeomObjects->length(i); if ( i == 0 ) - { - myIsBusy = false; - return; - } + { + myIsBusy = false; + return; + } aNbSel = i; } @@ -2453,9 +2453,9 @@ void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op) GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape(); if ( !aGeomVar->_is_nil() ) { - QString ID = aGeomVar->GetStudyEntry(); - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) { + CORBA::String_var ID = aGeomVar->GetStudyEntry(); + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.in() )) { SALOME_ListIO anIOList; Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() ); diff --git a/src/SMESHGUI/SMESHGUI_MeshInfo.cxx b/src/SMESHGUI/SMESHGUI_MeshInfo.cxx index 03e542d6a..57bd8236d 100644 --- a/src/SMESHGUI/SMESHGUI_MeshInfo.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshInfo.cxx @@ -1121,7 +1121,7 @@ SMESHGUI_ElemInfo::XYZ SMESHGUI_ElemInfo::gravityCenter( const SMDS_MeshElement* */ SMESHGUI_ElemInfo::XYZ SMESHGUI_ElemInfo::normal( const SMDS_MeshElement* element ) { - gp_XYZ n = SMESH::getNormale( dynamic_cast( element )); + gp_XYZ n = SMESH::getNormale( SMDS_Mesh::DownCast( element )); return XYZ(n.X(), n.Y(), n.Z()); } @@ -1397,7 +1397,7 @@ void SMESHGUI_SimpleElemInfo::information( const QList& ids ) if ( e->GetEntityType() > SMDSEntity_0D && e->GetEntityType() < SMDSEntity_Ball ) { myInfo->append( QString( "%1? %2" ).arg( SMESHGUI_ElemInfo::tr( "QUADRATIC" )).arg( e->IsQuadratic() ? SMESHGUI_ElemInfo::tr( "YES" ) : SMESHGUI_ElemInfo::tr( "NO" )) ); } - if ( const SMDS_BallElement* ball = dynamic_cast( e )) { + if ( const SMDS_BallElement* ball = SMDS_Mesh::DownCast( e )) { // Ball diameter myInfo->append( QString( "%1: %2" ).arg( SMESHGUI_ElemInfo::tr( "BALL_DIAMETER" )).arg( ball->GetDiameter() )); } @@ -1915,7 +1915,7 @@ void SMESHGUI_TreeElemInfo::information( const QList& ids ) case SMDSEntity_Polyhedra: case SMDSEntity_Quad_Polyhedra: gtype = SMESHGUI_ElemInfo::tr( "POLYHEDRON" ); break; - default: + default: break; } if ( !gtype.isEmpty() ) { @@ -1930,7 +1930,7 @@ void SMESHGUI_TreeElemInfo::information( const QList& ids ) quadItem->setText( 0, SMESHGUI_ElemInfo::tr( "QUADRATIC" )); quadItem->setText( 1, e->IsQuadratic() ? SMESHGUI_ElemInfo::tr( "YES" ) : SMESHGUI_ElemInfo::tr( "NO" )); } - if ( const SMDS_BallElement* ball = dynamic_cast( e )) { + if ( const SMDS_BallElement* ball = SMDS_Mesh::DownCast< SMDS_BallElement >( e )) { // ball diameter QTreeWidgetItem* diamItem = createItem( elemItem, Bold ); diamItem->setText( 0, SMESHGUI_ElemInfo::tr( "BALL_DIAMETER" )); @@ -1949,12 +1949,14 @@ void SMESHGUI_TreeElemInfo::information( const QList& ids ) } } else { - const SMDS_VtkVolume* aVtkVolume = dynamic_cast(e); - SMDS_ElemIteratorPtr nodeIt = aVtkVolume->uniqueNodesIterator(); + SMDS_NodeIteratorPtr nodeIt = e->nodeIterator(); + std::set< const SMDS_MeshNode* > addedNodes; QList uniqueNodes; - while ( nodeIt->more() ) - uniqueNodes.append( nodeIt->next() ); - + while ( nodeIt->more() ) { + const SMDS_MeshNode* node = nodeIt->next(); + if ( addedNodes.insert( node ).second ) + uniqueNodes.append( nodeIt->next() ); + } SMDS_VolumeTool vtool( e ); const int nbFaces = vtool.NbFaces(); for( int face_id = 0; face_id < nbFaces; face_id++ ) { @@ -1963,10 +1965,10 @@ void SMESHGUI_TreeElemInfo::information( const QList& ids ) faceItem->setExpanded( true ); const SMDS_MeshNode** aNodeIds = vtool.GetFaceNodes( face_id ); - const int nbNodes = vtool.NbFaceNodes( face_id ); + const int nbNodes = vtool.NbFaceNodes ( face_id ); for( int node_id = 0; node_id < nbNodes; node_id++ ) { const SMDS_MeshNode* node = aNodeIds[node_id]; - nodeInfo( node, uniqueNodes.indexOf(node) + 1, aVtkVolume->NbUniqueNodes(), faceItem ); + nodeInfo( node, uniqueNodes.indexOf(node) + 1, uniqueNodes.size(), faceItem ); } } } diff --git a/src/SMESHGUI/SMESHGUI_PreVisualObj.cxx b/src/SMESHGUI/SMESHGUI_PreVisualObj.cxx index 5b350d06e..1aa8e927e 100644 --- a/src/SMESHGUI/SMESHGUI_PreVisualObj.cxx +++ b/src/SMESHGUI/SMESHGUI_PreVisualObj.cxx @@ -98,7 +98,7 @@ bool SMESHGUI_PreVisualObj::IsValid() const vtkUnstructuredGrid* SMESHGUI_PreVisualObj::GetUnstructuredGrid() { - return myMesh->getGrid(); + return myMesh->GetGrid(); } @@ -116,13 +116,13 @@ vtkIdType SMESHGUI_PreVisualObj::GetNodeVTKId( int theObjID ) vtkIdType SMESHGUI_PreVisualObj::GetElemObjId( int theVTKID ) { - return this->GetMesh()->fromVtkToSmds(theVTKID); + return this->GetMesh()->FromVtkToSmds(theVTKID); } vtkIdType SMESHGUI_PreVisualObj::GetElemVTKId( int theObjID ) { const SMDS_MeshElement* e = myMesh->FindElement(theObjID); - return e ? e->getVtkId() : -1; + return e ? e->GetVtkID() : -1; } void SMESHGUI_PreVisualObj::ClearEntitiesFlags() diff --git a/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx b/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx index 33787322d..9e7554e1e 100644 --- a/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_RevolutionDlg.cxx @@ -641,7 +641,7 @@ void SMESHGUI_RevolutionDlg::SelectionIntoArgument() else if ( isFaceSelected ) { const SMDS_MeshFace* face = - dynamic_cast(aMesh->FindElement(aMapIndex(1))); + SMDS_Mesh::DownCast( aMesh->FindElement( aMapIndex( 1 ))); if (!face) return; gp_XYZ aNormale = SMESH::getNormale(face); diff --git a/src/SMESHUtils/SMESH_ComputeError.hxx b/src/SMESHUtils/SMESH_ComputeError.hxx index 4055741ff..cf78362b2 100644 --- a/src/SMESHUtils/SMESH_ComputeError.hxx +++ b/src/SMESHUtils/SMESH_ComputeError.hxx @@ -25,6 +25,7 @@ #define SMESH_ComputeError_HeaderFile #include "SMESH_Utils.hxx" +#include "SMDS_ElementHolder.hxx" #include #include @@ -75,22 +76,20 @@ struct SMESHUtils_EXPORT SMESH_ComputeError std::string myComment; const SMESH_Algo* myAlgo; - std::list myBadElements; //!< to explain COMPERR_BAD_INPUT_MESH - static SMESH_ComputeErrorPtr New( int error = COMPERR_OK, std::string comment = "", const SMESH_Algo* algo = 0) { return SMESH_ComputeErrorPtr( new SMESH_ComputeError( error, comment, algo )); } - SMESH_ComputeError(int error = COMPERR_OK, - std::string comment = "", - const SMESH_Algo* algo = 0) - :myName(error),myComment(comment),myAlgo(algo) {} + SMESH_ComputeError( int error = COMPERR_OK, + std::string comment = "", + const SMESH_Algo* algo = 0) + : myName(error), myComment(comment), myAlgo(algo) {} bool IsOK() const { return myName == COMPERR_OK; } bool IsKO() const { return myName != COMPERR_OK && myName != COMPERR_WARNING; } bool IsCommon() const { return myName < 0 && myName > COMPERR_LAST_ALGO_ERROR; } - bool HasBadElems() const { return !myBadElements.empty(); } + virtual bool HasBadElems() const { return false; } // not inline methods are implemented in src/SMESHUtils/SMESH_TryCatch.cxx @@ -100,6 +99,31 @@ struct SMESHUtils_EXPORT SMESH_ComputeError // Return the most severe error static SMESH_ComputeErrorPtr Worst( SMESH_ComputeErrorPtr er1, SMESH_ComputeErrorPtr er2 ); + + virtual ~SMESH_ComputeError() {} +}; + +struct SMESHUtils_EXPORT SMESH_BadInputElements : public SMESH_ComputeError, SMDS_ElementHolder +{ + typedef std::list TElemList; + TElemList myBadElements; //!< to explain COMPERR_BAD_INPUT_MESH + + SMESH_BadInputElements(const SMDS_Mesh* mesh, + int error = COMPERR_OK, + std::string comment = "", + const SMESH_Algo* algo = 0) + :SMESH_ComputeError(error, comment ,algo), SMDS_ElementHolder(mesh) {} + + const SMDS_Mesh* GetMesh() const { return myMesh; } + const TElemList& GetElements() { return myBadElements; } + + virtual bool HasBadElems() const { return !myBadElements.empty(); } + + // methods of SMDS_ElementHolder + virtual SMDS_ElemIteratorPtr getElements(); + virtual void tmpClear(); + virtual void add( const SMDS_MeshElement* element ); + virtual void compact() { } }; #endif diff --git a/src/SMESHUtils/SMESH_FillHole.cxx b/src/SMESHUtils/SMESH_FillHole.cxx index ee22ef944..cc724d3ce 100644 --- a/src/SMESHUtils/SMESH_FillHole.cxx +++ b/src/SMESHUtils/SMESH_FillHole.cxx @@ -28,8 +28,9 @@ #include "SMESH_Comment.hxx" -#include "SMESH_TypeDefs.hxx" +#include "ObjectPool.hxx" #include "SMDS_Mesh.hxx" +#include "SMESH_TypeDefs.hxx" #include diff --git a/src/SMESHUtils/SMESH_FreeBorders.cxx b/src/SMESHUtils/SMESH_FreeBorders.cxx index d09860465..2793d4cda 100644 --- a/src/SMESHUtils/SMESH_FreeBorders.cxx +++ b/src/SMESHUtils/SMESH_FreeBorders.cxx @@ -92,7 +92,7 @@ namespace myNodes[0] = node1->Node(); myNodes[1] = node2->Node(); myFace = face; - setId( ID ); // mesh element ID + setID( ID ); // mesh element ID } bool IsInGroup() const { diff --git a/src/SMESHUtils/SMESH_MeshAlgos.cxx b/src/SMESHUtils/SMESH_MeshAlgos.cxx index 646fb7bff..c953da515 100644 --- a/src/SMESHUtils/SMESH_MeshAlgos.cxx +++ b/src/SMESHUtils/SMESH_MeshAlgos.cxx @@ -28,6 +28,7 @@ #include "SMESH_MeshAlgos.hxx" +#include "ObjectPool.hxx" #include "SMDS_FaceOfNodes.hxx" #include "SMDS_LinearEdge.hxx" #include "SMDS_Mesh.hxx" @@ -69,7 +70,7 @@ struct SMESH_NodeSearcherImpl: public SMESH_NodeSearcher TIDSortedNodeSet nodes; if ( theMesh ) { - SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(/*idInceasingOrder=*/true); + SMDS_NodeIteratorPtr nIt = theMesh->nodesIterator(); while ( nIt->more() ) nodes.insert( nodes.end(), nIt->next() ); } @@ -1292,7 +1293,7 @@ bool SMESH_MeshAlgos::IsOut( const SMDS_MeshElement* element, const gp_Pnt& poin std::vector< SMESH_TNodeXYZ > xyz; xyz.reserve( element->NbNodes()+1 ); - SMDS_ElemIteratorPtr nodeIt = element->interlacedNodesElemIterator(); + SMDS_NodeIteratorPtr nodeIt = element->interlacedNodesIterator(); for ( int i = 0; nodeIt->more(); ++i ) xyz.push_back( SMESH_TNodeXYZ( nodeIt->next() )); @@ -1528,11 +1529,11 @@ double SMESH_MeshAlgos::GetDistance( const SMDS_MeshElement* elem, switch ( elem->GetType() ) { case SMDSAbs_Volume: - return GetDistance( dynamic_cast( elem ), point, closestPnt ); + return GetDistance( static_cast( elem ), point, closestPnt ); case SMDSAbs_Face: - return GetDistance( dynamic_cast( elem ), point, closestPnt ); + return GetDistance( static_cast( elem ), point, closestPnt ); case SMDSAbs_Edge: - return GetDistance( dynamic_cast( elem ), point, closestPnt ); + return GetDistance( static_cast( elem ), point, closestPnt ); case SMDSAbs_Node: if ( closestPnt ) *closestPnt = SMESH_TNodeXYZ( elem ); return point.Distance( SMESH_TNodeXYZ( elem )); @@ -1664,9 +1665,8 @@ double SMESH_MeshAlgos::GetDistance( const SMDS_MeshEdge* seg, int i = 0, nbNodes = seg->NbNodes(); std::vector< SMESH_TNodeXYZ > xyz( nbNodes ); - SMDS_ElemIteratorPtr nodeIt = seg->interlacedNodesElemIterator(); - while ( nodeIt->more() ) - xyz[ i++ ].Set( nodeIt->next() ); + for ( SMDS_NodeIteratorPtr nodeIt = seg->interlacedNodesIterator(); nodeIt->more(); i++ ) + xyz[ i ].Set( nodeIt->next() ); for ( i = 1; i < nbNodes; ++i ) { @@ -1836,7 +1836,7 @@ SMESH_MeshAlgos::FindFaceInSet(const SMDS_MeshNode* n1, if ( !face && elem->IsQuadratic()) { // analysis for quadratic elements using all nodes - SMDS_ElemIteratorPtr anIter = elem->interlacedNodesElemIterator(); + SMDS_NodeIteratorPtr anIter = elem->interlacedNodesIterator(); const SMDS_MeshNode* prevN = static_cast( anIter->next() ); for ( i1 = -1, i2 = 0; anIter->more() && !face; i1++, i2++ ) { diff --git a/src/SMESHUtils/SMESH_TryCatch.cxx b/src/SMESHUtils/SMESH_TryCatch.cxx index 71e587caa..b026cdd6b 100644 --- a/src/SMESHUtils/SMESH_TryCatch.cxx +++ b/src/SMESHUtils/SMESH_TryCatch.cxx @@ -39,7 +39,10 @@ const char* SMESH::returnError(const char* txt) } // ------------------------------------------------------------------ + #include "SMESH_ComputeError.hxx" +#include "SMDS_SetIterator.hxx" +#include #define _case2char(err) case err: return #err; @@ -78,11 +81,31 @@ SMESH_ComputeErrorPtr SMESH_ComputeError::Worst( SMESH_ComputeErrorPtr er1, if ( !er1->IsKO() ) return er2; if ( !er2->IsKO() ) return er1; // both KO - bool hasInfo1 = er1->myComment.size() || !er1->myBadElements.empty(); - bool hasInfo2 = er2->myComment.size() || !er2->myBadElements.empty(); + bool hasInfo1 = er1->myComment.size() || er1->HasBadElems(); + bool hasInfo2 = er2->myComment.size() || er2->HasBadElems(); if ( er1->myName == er2->myName || hasInfo1 != hasInfo2 ) return hasInfo1 < hasInfo2 ? er2 : er1; return er1->myName == COMPERR_CANCELED ? er2 : er1; } + +// Return bad elements +SMDS_ElemIteratorPtr SMESH_BadInputElements::getElements() +{ + typedef SMDS_SetIterator< const SMDS_MeshElement*, + std::list< const SMDS_MeshElement* >::const_iterator> TIterator; + return boost::make_shared< TIterator >( myBadElements.begin(), myBadElements.end() ); +} + +// Temporary remove its elements before the mesh compacting +void SMESH_BadInputElements::tmpClear() +{ + myBadElements.clear(); +} + +// Re-add elements after the mesh compacting +void SMESH_BadInputElements::add( const SMDS_MeshElement* element ) +{ + myBadElements.push_back( element ); +} diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 2e11e27e5..ea45c41ce 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -85,7 +85,6 @@ #include "MED_Factory.hxx" #include "SMDS_EdgePosition.hxx" #include "SMDS_FacePosition.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMDS_SetIterator.hxx" #include "SMDS_SpacePosition.hxx" #include "SMDS_VertexPosition.hxx" @@ -1639,7 +1638,7 @@ SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr else { errStruct.algoName = error->myAlgo->GetName(); } - errStruct.hasBadMesh = !error->myBadElements.empty(); + errStruct.hasBadMesh = error->HasBadElems(); } } error_array->length( nbErr ); @@ -1681,7 +1680,7 @@ SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh, { // compute error SMESH_ComputeErrorPtr error = sm->GetComputeError(); - if ( error && !error->myBadElements.empty()) + if ( error && error->HasBadElems() ) { typedef map TNode2LocalIDMap; typedef TNode2LocalIDMap::iterator TNodeLocalID; @@ -1691,8 +1690,10 @@ SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh, list< TNodeLocalID > connectivity; int i, nbElements = 0, nbConnNodes = 0; - list::iterator elemIt = error->myBadElements.begin(); - list::iterator elemEnd = error->myBadElements.end(); + const list& badElems = + static_cast( error.get() )->myBadElements; + list::const_iterator elemIt = badElems.begin(); + list::const_iterator elemEnd = badElems.end(); for ( ; elemIt != elemEnd; ++elemIt, ++nbElements ) { SMDS_ElemIteratorPtr nIt = (*elemIt)->nodesIterator(); @@ -1719,7 +1720,7 @@ SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh, } // fill element types result->elementTypes.length( nbElements ); - for ( i = 0, elemIt = error->myBadElements.begin(); i elementTypes[i].SMDS_ElementType = (SMESH::ElementType) elem->GetType(); @@ -3126,8 +3127,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( !myHyp->_is_nil() ) { SMESH_Hypothesis_i* myImpl = dynamic_cast( GetServant( myHyp ).in() ); if ( myImpl ) { - string hypname = string( myHyp->GetName() ); - string libname = string( myHyp->GetLibName() ); + CORBA::String_var hn = myHyp->GetName(), ln = myHyp->GetLibName(); + std::string hypname = hn.in(); + std::string libname = ln.in(); // BUG SWP13062 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for // WIN32 and ".so" for X-system) must be deleted @@ -3139,13 +3141,13 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // PAL17753 (Regression: missing hypothesis in restored study) // "lib" also should be removed from the beginning //if( libname_len > 3 ) - //libname.resize( libname_len - 3 ); + //libname.resize( libname_len - 3 ); if( libname_len > 6 ) libname = libname.substr( 3, libname_len - 3 - 3 ); #endif - CORBA::String_var objStr = GetORB()->object_to_string( anObject ); - int id = myStudyContext->findId( string( objStr.in() ) ); - string hypdata = string( myImpl->SaveTo() ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + CORBA::String_var hypdata = myImpl->SaveTo(); + int id = myStudyContext->findId( string( objStr.in() )); // for each hypothesis create HDF group basing on its id char hypGrpName[30]; @@ -3165,10 +3167,10 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, aDataset->WriteOnDisk( ( char* )( libname.c_str() ) ); aDataset->CloseOnDisk(); // --> persistent data of hypothesis - aSize[ 0 ] = hypdata.length() + 1; + aSize[ 0 ] = strlen( hypdata.in() ) + 1; aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 ); aDataset->CreateOnDisk(); - aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) ); + aDataset->WriteOnDisk( ( char* )( hypdata.in() ) ); aDataset->CloseOnDisk(); // close hypothesis HDF group aGroup->CloseOnDisk(); @@ -3195,8 +3197,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( !myHyp->_is_nil() ) { SMESH_Hypothesis_i* myImpl = dynamic_cast( GetServant( myHyp ).in() ); if ( myImpl ) { - string hypname = string( myHyp->GetName() ); - string libname = string( myHyp->GetLibName() ); + CORBA::String_var hn = myHyp->GetName(), ln = myHyp->GetLibName(); + std::string hypname = hn.in(); + std::string libname = ln.in(); // BUG SWP13062 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for // WIN32 and ".so" for X-system) must be deleted @@ -3208,13 +3211,13 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // PAL17753 (Regression: missing hypothesis in restored study) // "lib" also should be removed from the beginning //if( libname_len > 3 ) - //libname.resize( libname_len - 3 ); + //libname.resize( libname_len - 3 ); if( libname_len > 6 ) libname = libname.substr( 3, libname_len - 3 - 3 ); #endif - CORBA::String_var objStr = GetORB()->object_to_string( anObject ); - int id = myStudyContext->findId( string( objStr.in() ) ); - string hypdata = string( myImpl->SaveTo() ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + CORBA::String_var hypdata = myImpl->SaveTo(); + int id = myStudyContext->findId( string( objStr.in() ) ); // for each algorithm create HDF group basing on its id char hypGrpName[30]; @@ -3234,10 +3237,10 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, aDataset->WriteOnDisk( ( char* )( libname.c_str() ) ); aDataset->CloseOnDisk(); // --> persistent data of algorithm - aSize[0] = hypdata.length() + 1; + aSize[0] = strlen( hypdata.in() ) + 1; aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 ); aDataset->CreateOnDisk(); - aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) ); + aDataset->WriteOnDisk( ( char* )( hypdata.in() )); aDataset->CloseOnDisk(); // close algorithm HDF group aGroup->CloseOnDisk(); @@ -3319,13 +3322,14 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, SALOMEDS::SObject_wrap myShape; bool ok = myRef->ReferencedObject( myShape.inout() ); if ( ok ) { - shapeRefFound = (! CORBA::is_nil( myShape->GetObject() )); - string myRefOnObject = myShape->GetID(); - if ( shapeRefFound && myRefOnObject.length() > 0 ) { - aSize[ 0 ] = myRefOnObject.length() + 1; + CORBA::Object_var shapeObj = myShape->GetObject(); + shapeRefFound = (! CORBA::is_nil( shapeObj )); + CORBA::String_var myRefOnObject = myShape->GetID(); + if ( shapeRefFound && myRefOnObject.in()[0] ) { + aSize[ 0 ] = strlen( myRefOnObject.in() ) + 1; aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 ); aDataset->CreateOnDisk(); - aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) ); + aDataset->WriteOnDisk( ( char* )( myRefOnObject.in() ) ); aDataset->CloseOnDisk(); } } @@ -3334,7 +3338,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // write applied hypotheses if exist SALOMEDS::SObject_wrap myHypBranch; found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() ); - if ( found && !shapeRefFound && hasShape) { // remove applied hyps + if ( found && !shapeRefFound && hasShape ) { // remove applied hyps myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch ); } if ( found && (shapeRefFound || !hasShape) ) { @@ -3671,8 +3675,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // For each group, create a dataset named "Group " // and store the group's user name into it - const char* grpName = aGrpBaseDS->GetStoreName(); - char* aUserName = myGroupImpl->GetName(); + const char* grpName = aGrpBaseDS->GetStoreName(); + CORBA::String_var aUserName = myGroupImpl->GetName(); aSize[ 0 ] = strlen( aUserName ) + 1; aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 ); @@ -3710,14 +3714,14 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, mySubRef->ReferencedObject( myShape.inout() ) && !CORBA::is_nil( myShape->GetObject() )) { - string myRefOnObject = myShape->GetID(); - if ( myRefOnObject.length() > 0 ) { + CORBA::String_var myRefOnObject = myShape->GetID(); + if ( myRefOnObject.in()[0] ) { char aRefName[ 30 ]; sprintf( aRefName, "Ref on shape %d", anId); - aSize[ 0 ] = myRefOnObject.length() + 1; + aSize[ 0 ] = strlen( myRefOnObject.in() ) + 1; aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1); aDataset->CreateOnDisk(); - aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) ); + aDataset->WriteOnDisk( ( char* )( myRefOnObject.in() )); aDataset->CloseOnDisk(); } } @@ -3865,8 +3869,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // Position const SMDS_PositionPtr pos = node->GetPosition(); if ( onFace ) { // on FACE - const SMDS_FacePosition* fPos = - dynamic_cast( pos ); + SMDS_FacePositionPtr fPos = pos; if ( fPos ) { aUPos[ iNode ] = fPos->GetUParameter(); aVPos[ iNode ] = fPos->GetVParameter(); @@ -3876,8 +3879,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, nbNodes--; } else { // on EDGE - const SMDS_EdgePosition* ePos = - dynamic_cast( pos ); + SMDS_EdgePositionPtr ePos = pos; if ( ePos ) { aUPos[ iNode ] = ePos->GetUParameter(); iNode++; @@ -4558,6 +4560,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myStudyContext->mapOldToNew( subid, newSubId ); } } + delete [] refFromFile; } if ( aSubMesh->_is_nil() ) @@ -4592,6 +4595,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp ); } } + delete [] refFromFile; } } // close "applied algorithms" HDF group @@ -4627,6 +4631,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp ); } } + delete [] refFromFile; } } // close "APPLIED HYPOTHESES" hdf group @@ -4708,6 +4713,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, aShape = GeomObjectToShape( aShapeObject ); } } + delete [] refFromFile; } // Try to read a filter of SMESH_GroupOnFilter SMESH::Filter_var filter; @@ -4726,12 +4732,14 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, predicate = SMESH_GroupOnFilter_i::GetPredicate( filter ); filters.push_back( filter ); } + delete [] persistStr; } // Create group servant SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1); SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate ( myNewMeshImpl->createGroup( type, nameFromFile, aShape, predicate ) ); + delete [] nameFromFile; // Obtain a SMESHDS_Group object if ( aNewGroup->_is_nil() ) continue; @@ -4770,6 +4778,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, aDataset->CloseOnDisk(); Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB ); aGroupBaseDS->SetColor( aColor ); + delete [] anRGB; } } } @@ -4787,7 +4796,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, } // read Sub-Mesh ORDER if any - if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) { + if ( aTopGroup->ExistInternalObject( "Mesh Order" )) { aDataset = new HDFdataset( "Mesh Order", aTopGroup ); aDataset->OpenOnDisk(); size = aDataset->GetSize(); @@ -4803,6 +4812,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, anOrderIds.back().push_back(smIDs[ i ]); myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds ); + delete [] smIDs; } } // loop on meshes diff --git a/src/SMESH_I/SMESH_Measurements_i.cxx b/src/SMESH_I/SMESH_Measurements_i.cxx index ca0103c01..2fcac5a7f 100644 --- a/src/SMESH_I/SMESH_Measurements_i.cxx +++ b/src/SMESH_I/SMESH_Measurements_i.cxx @@ -255,16 +255,13 @@ static void enlargeBoundingBox(const SMESH::SMESH_IDSource_ptr theObject, enlargeBoundingBox( aMesh->FindNode( aElementsId[i] ), theMeasure); else { - const SMDS_MeshElement* elem = aMesh->FindElement( aElementsId[i] ); - if (!elem) - continue; - SMDS_ElemIteratorPtr aNodeIter = elem->nodesIterator(); - while( aNodeIter->more() ) - enlargeBoundingBox( dynamic_cast( aNodeIter->next() ), theMeasure); + if ( const SMDS_MeshElement* elem = aMesh->FindElement( aElementsId[i] )) + for (SMDS_NodeIteratorPtr aNodeIter = elem->nodeIterator(); aNodeIter->more(); ) + enlargeBoundingBox( aNodeIter->next(), theMeasure); } } } - + //======================================================================= // name : BoundingBox // Purpose : compute common bounding box of entities diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index d7afbed39..2bd604063 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -42,7 +42,6 @@ #include "SMDS_Mesh0DElement.hxx" #include "SMDS_MeshFace.hxx" #include "SMDS_MeshVolume.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMDS_SetIterator.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_Group.hxx" @@ -534,7 +533,9 @@ SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData() SMESHDS_Mesh* aMeshDS; std::unique_ptr< SMESH_MeshPartDS > aMeshPartDS; if ( hasBadElems ) { - aMeshPartDS.reset( new SMESH_MeshPartDS( getEditor().GetError()->myBadElements )); + const list& badElems = + static_cast( getEditor().GetError().get() )->myBadElements; + aMeshPartDS.reset( new SMESH_MeshPartDS( badElems )); aMeshDS = aMeshPartDS.get(); } else { @@ -680,7 +681,7 @@ SMESH::ComputeError* SMESH_MeshEditor_i::GetLastError() errOut->code = -( errIn->myName < 0 ? errIn->myName + 1: errIn->myName ); // -1 -> 0 errOut->comment = errIn->myComment.c_str(); errOut->subShapeID = -1; - errOut->hasBadMesh = !errIn->myBadElements.empty(); + errOut->hasBadMesh = errIn->HasBadElems(); } else { @@ -6963,7 +6964,7 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim, // group of boundary elements SMESH_Group* smesh_group = 0; SMDSAbs_ElementType elemType = (dim == SMESH::BND_2DFROM3D) ? SMDSAbs_Volume : SMDSAbs_Face; - if ( strlen(groupName) ) + if ( strlen( groupName )) { SMESH::ElementType groupType = SMESH::ElementType( int(elemType)-1 ); group_var = mesh_i->CreateGroup( groupType, groupName ); diff --git a/src/SMESH_I/SMESH_MeshPartDS.hxx b/src/SMESH_I/SMESH_MeshPartDS.hxx index 986ee3c06..4c81674a2 100644 --- a/src/SMESH_I/SMESH_MeshPartDS.hxx +++ b/src/SMESH_I/SMESH_MeshPartDS.hxx @@ -47,10 +47,10 @@ public: SMESH_MeshPartDS(SMESH::SMESH_IDSource_ptr meshPart); SMESH_MeshPartDS(const std::list< const SMDS_MeshElement* > & badElems ); - virtual SMDS_NodeIteratorPtr nodesIterator (bool idInceasingOrder=false) const; - virtual SMDS_EdgeIteratorPtr edgesIterator (bool idInceasingOrder=false) const; - virtual SMDS_FaceIteratorPtr facesIterator (bool idInceasingOrder=false) const; - virtual SMDS_VolumeIteratorPtr volumesIterator (bool idInceasingOrder=false) const; + virtual SMDS_NodeIteratorPtr nodesIterator () const; + virtual SMDS_EdgeIteratorPtr edgesIterator () const; + virtual SMDS_FaceIteratorPtr facesIterator () const; + virtual SMDS_VolumeIteratorPtr volumesIterator() const; virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const; virtual SMDS_ElemIteratorPtr elementGeomIterator(SMDSAbs_GeometryType type) const; @@ -61,24 +61,6 @@ public: private: TIDSortedElemSet _elements[ SMDSAbs_NbElementTypes ]; SMESHDS_Mesh* _meshDS; - /*! - * \brief Class used to access to protected data of SMDS_MeshInfo - */ - struct TMeshInfo : public SMDS_MeshInfo - { - void Add(const SMDS_MeshElement* e) { SMDS_MeshInfo::addWithPoly( e ); } - }; - /*! - * \brief Element holing its ID only - */ - struct TElemID : public SMDS_MeshElement - { - TElemID(int ID) : SMDS_MeshElement( ID ) {} - virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_All; } - virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Last; } - virtual SMDSAbs_GeometryType GetGeomType() const { return SMDSGeom_NONE; } - virtual vtkIdType GetVtkType() const { return -1; } - }; }; #endif diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index a170d36d5..f97541aef 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -29,12 +29,14 @@ #include "DriverMED_W_Field.h" #include "DriverMED_W_SMESHDS_Mesh.h" #include "MED_Factory.hxx" +#include "SMDS_LinearEdge.hxx" #include "SMDS_EdgePosition.hxx" #include "SMDS_ElemIterator.hxx" #include "SMDS_FacePosition.hxx" #include "SMDS_IteratorOnIterators.hxx" #include "SMDS_MeshGroup.hxx" #include "SMDS_SetIterator.hxx" +#include "SMDS_StdIterator.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_Command.hxx" #include "SMESHDS_CommandType.hxx" @@ -1102,7 +1104,8 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup return; vector nodeIds; // to remove nodes becoming free - if ( !theGroup->IsEmpty() ) + bool isNodal = ( theGroup->GetType() == SMESH::NODE ); + if ( !isNodal && !theGroup->IsEmpty() ) { CORBA::Long elemID = theGroup->GetID( 1 ); int nbElemNodes = GetElemNbNodes( elemID ); @@ -1110,36 +1113,44 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup nodeIds.reserve( theGroup->Size() * nbElemNodes ); } - // Remove contents + // Retrieve contents SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( theGroup ); SMDS_ElemIteratorPtr elemIt = GetElements( idSrc, theGroup->GetType() ); - while ( elemIt->more() ) - { - const SMDS_MeshElement* e = elemIt->next(); + SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > elemBeg( elemIt ), elemEnd; + std::vector< const SMDS_MeshElement* > elems( theGroup->Size() ); + elems.assign( elemBeg, elemEnd ); - SMDS_ElemIteratorPtr nIt = e->nodesIterator(); - while ( nIt->more() ) - nodeIds.push_back( nIt->next()->GetID() ); + TPythonDump pyDump; // Suppress dump from RemoveGroup() - _impl->GetMeshDS()->RemoveElement( e ); + // Remove group + RemoveGroup( theGroup ); + + // Remove contents + for ( size_t i = 0; i < elems.size(); ++i ) + { + if ( !isNodal ) + { + for ( SMDS_ElemIteratorPtr nIt = elems[i]->nodesIterator(); nIt->more(); ) + nodeIds.push_back( nIt->next()->GetID() ); + + _impl->GetMeshDS()->RemoveFreeElement( elems[i], /*sm=*/0 ); + } + else + { + _impl->GetMeshDS()->RemoveElement( elems[i] ); + } } // Remove free nodes - if ( theGroup->GetType() != SMESH::NODE ) - for ( size_t i = 0 ; i < nodeIds.size(); ++i ) - if ( const SMDS_MeshNode* n = _impl->GetMeshDS()->FindNode( nodeIds[i] )) - if ( n->NbInverseElements() == 0 ) - _impl->GetMeshDS()->RemoveFreeNode( n, /*sm=*/0 ); - - TPythonDump pyDump; // Suppress dump from RemoveGroup() + for ( size_t i = 0 ; i < nodeIds.size(); ++i ) + if ( const SMDS_MeshNode* n = _impl->GetMeshDS()->FindNode( nodeIds[i] )) + if ( n->NbInverseElements() == 0 ) + _impl->GetMeshDS()->RemoveFreeNode( n, /*sm=*/0 ); // Update Python script (theGroup must be alive for this) pyDump << SMESH::SMESH_Mesh_var(_this()) << ".RemoveGroupWithContents( " << theGroup << " )"; - // Remove group - RemoveGroup( theGroup ); - SMESH_CATCH( SMESH::throwCorbaException ); } @@ -2552,7 +2563,7 @@ SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType const SMESH_PredicatePtr& thePredicate ) { std::string newName; - if ( !theName || strlen( theName ) == 0 ) + if ( !theName || !theName[0] ) { std::set< std::string > presentNames; std::map::const_iterator i_gr = _mapGroups.begin(); @@ -4099,14 +4110,14 @@ SMESH::long_array* SMESH_Mesh_i::GetNodesId() _preMeshInfo->FullLoadFromFile(); SMESH::long_array_var aResult = new SMESH::long_array(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) + if ( aMeshDS == NULL ) return aResult._retn(); long nbNodes = NbNodes(); aResult->length( nbNodes ); - SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator(/*idInceasingOrder=*/true); + SMDS_NodeIteratorPtr anIt = aMeshDS->nodesIterator(); for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ ) aResult[i] = anIt->next()->GetID(); @@ -4326,12 +4337,12 @@ SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id) _preMeshInfo->FullLoadFromFile(); SMESH::double_array_var aResult = new SMESH::double_array(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return aResult._retn(); // find node - const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id); + const SMDS_MeshNode* aNode = aMeshDS->FindNode(id); if(!aNode) return aResult._retn(); @@ -4357,12 +4368,12 @@ SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id) _preMeshInfo->FullLoadFromFile(); SMESH::long_array_var aResult = new SMESH::long_array(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return aResult._retn(); // find node - const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id); + const SMDS_MeshNode* aNode = aMeshDS->FindNode(id); if(!aNode) return aResult._retn(); @@ -4404,17 +4415,16 @@ SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID) case SMDS_TOP_EDGE: aNodePosition->shapeType = GEOM::EDGE; aNodePosition->params.length(1); - aNodePosition->params[0] = - static_cast( pos )->GetUParameter(); + aNodePosition->params[0] = SMDS_EdgePositionPtr( pos )->GetUParameter(); break; - case SMDS_TOP_FACE: + case SMDS_TOP_FACE: { + SMDS_FacePositionPtr fPos = pos; aNodePosition->shapeType = GEOM::FACE; aNodePosition->params.length(2); - aNodePosition->params[0] = - static_cast( pos )->GetUParameter(); - aNodePosition->params[1] = - static_cast( pos )->GetVParameter(); + aNodePosition->params[0] = fPos->GetUParameter(); + aNodePosition->params[1] = fPos->GetVParameter(); break; + } case SMDS_TOP_VERTEX: aNodePosition->shapeType = GEOM::VERTEX; break; @@ -4489,12 +4499,12 @@ CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id) if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return -1; // try to find node - const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id); + const SMDS_MeshNode* aNode = aMeshDS->FindNode(id); if(aNode) { return aNode->getshapeId(); } @@ -4516,12 +4526,12 @@ CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id) if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return -1; // try to find element - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return -1; @@ -4546,10 +4556,10 @@ CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id) if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return -1; + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return -1; // try to find element - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return -1; return elem->NbNodes(); } @@ -4568,9 +4578,9 @@ CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long in if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return -1; - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return -1; + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return -1; if( index>=elem->NbNodes() || index<0 ) return -1; return elem->GetNode(index)->GetID(); @@ -4588,9 +4598,9 @@ SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id) _preMeshInfo->FullLoadFromFile(); SMESH::long_array_var aResult = new SMESH::long_array(); - if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() ) + if ( SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS() ) { - if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) ) + if ( const SMDS_MeshElement* elem = aMeshDS->FindElement(id) ) { aResult->length( elem->NbNodes() ); for ( int i = 0; i < elem->NbNodes(); ++i ) @@ -4612,13 +4622,13 @@ CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Lo if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return false; + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return false; // try to find node - const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn); + const SMDS_MeshNode* aNode = aMeshDS->FindNode(idn); if(!aNode) return false; // try to find element - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide); + const SMDS_MeshElement* elem = aMeshDS->FindElement(ide); if(!elem) return false; return elem->IsMediumNode(aNode); @@ -4638,11 +4648,11 @@ CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn, if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return false; + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return false; // try to find node - const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn); + const SMDS_MeshNode* aNode = aMeshDS->FindNode(idn); if(!aNode) return false; SMESH_MesherHelper aHelper( *(_impl) ); @@ -4668,9 +4678,9 @@ CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id) if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return -1; - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return -1; + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return -1; return elem->NbEdges(); } @@ -4687,9 +4697,9 @@ CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id) if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return -1; - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return -1; + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return -1; return elem->NbFaces(); } @@ -4706,9 +4716,9 @@ SMESH::long_array* SMESH_Mesh_i::GetElemFaceNodes(CORBA::Long elemId, _preMeshInfo->FullLoadFromFile(); SMESH::long_array_var aResult = new SMESH::long_array(); - if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() ) + if ( SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS() ) { - if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(elemId) ) + if ( const SMDS_MeshElement* elem = aMeshDS->FindElement(elemId) ) { SMDS_VolumeTool vtool( elem ); if ( faceIndex < vtool.NbFaces() ) @@ -4819,9 +4829,9 @@ CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id) if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return false; - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return false; + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return false; return elem->IsPoly(); } @@ -4838,9 +4848,9 @@ CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id) if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) return false; - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return false; + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return false; return elem->IsQuadratic(); } @@ -4857,7 +4867,7 @@ CORBA::Double SMESH_Mesh_i::GetBallDiameter(CORBA::Long id) _preMeshInfo->FullLoadFromFile(); if ( const SMDS_BallElement* ball = - dynamic_cast( _impl->GetMeshDS()->FindElement( id ))) + SMDS_Mesh::DownCast( _impl->GetMeshDS()->FindElement( id ))) return ball->GetDiameter(); return 0; @@ -4875,11 +4885,11 @@ SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id) _preMeshInfo->FullLoadFromFile(); SMESH::double_array_var aResult = new SMESH::double_array(); - SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS(); - if ( aSMESHDS_Mesh == NULL ) + SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS(); + if ( aMeshDS == NULL ) return aResult._retn(); - const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id); + const SMDS_MeshElement* elem = aMeshDS->FindElement(id); if(!elem) return aResult._retn(); @@ -4939,12 +4949,14 @@ SMESH_Mesh_i::MakeGroupsOfBadInputElements( int theSubShapeID, { // compute error SMESH_ComputeErrorPtr error = sm->GetComputeError(); - if ( error && !error->myBadElements.empty()) + if ( error && error->HasBadElems() ) { // sort bad elements by type vector< const SMDS_MeshElement* > elemsByType[ SMDSAbs_NbElementTypes ]; - list::iterator elemIt = error->myBadElements.begin(); - list::iterator elemEnd = error->myBadElements.end(); + const list& badElems = + static_cast( error.get() )->myBadElements; + list::const_iterator elemIt = badElems.begin(); + list::const_iterator elemEnd = badElems.end(); for ( ; elemIt != elemEnd; ++elemIt ) { const SMDS_MeshElement* elem = *elemIt; @@ -5313,7 +5325,7 @@ SALOMEDS::TMPFile* SMESH_Mesh_i::GetVtkUgStream() { SALOMEDS::TMPFile_var SeqFile; if ( SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS() ) { - SMDS_UnstructuredGrid* aGrid = aMeshDS->getGrid(); + SMDS_UnstructuredGrid* aGrid = aMeshDS->GetGrid(); if(aGrid) { vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); aWriter->WriteToOutputStringOn(); @@ -6112,6 +6124,24 @@ void SMESH_Mesh_i::convertMeshOrder (const TListOfListOfInt& theIdsOrder, } } +namespace // utils used by SMESH_MeshPartDS +{ + /*! + * \brief Class used to access to protected data of SMDS_MeshInfo + */ + struct TMeshInfo : public SMDS_MeshInfo + { + void Add(const SMDS_MeshElement* e) { SMDS_MeshInfo::addWithPoly( e ); } + }; + /*! + * \brief Element holing its ID only + */ + struct TElemID : public SMDS_LinearEdge + { + TElemID(int ID) : SMDS_LinearEdge(0,0) { setID( ID ); } + }; +} + //================================================================================ // // Implementation of SMESH_MeshPartDS @@ -6218,7 +6248,7 @@ SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementGeomIterator(SMDSAbs_GeometryType SMDS_MeshElement::GeomFilter > TIter; - SMDSAbs_ElementType type = SMDS_MeshCell::toSmdsType( geomType ); + SMDSAbs_ElementType type = SMDS_MeshCell::ElemType( geomType ); return SMDS_ElemIteratorPtr( new TIter( _elements[type].begin(), _elements[type].end(), @@ -6236,7 +6266,7 @@ SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementEntityIterator(SMDSAbs_EntityType SMDS_MeshElement::EntityFilter > TIter; - SMDSAbs_ElementType type = SMDS_MeshCell::toSmdsType( entity ); + SMDSAbs_ElementType type = SMDS_MeshCell::ElemType( entity ); return SMDS_ElemIteratorPtr( new TIter( _elements[type].begin(), _elements[type].end(), @@ -6263,10 +6293,10 @@ SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementsIterator(SMDSAbs_ElementType type } // ------------------------------------------------------------------------------------- #define _GET_ITER_DEFINE( iterType, methName, elem, elemType) \ - iterType SMESH_MeshPartDS::methName( bool idInceasingOrder) const \ + iterType SMESH_MeshPartDS::methName() const \ { \ typedef SMDS_SetIterator TIter; \ - return _meshDS ? _meshDS->methName(idInceasingOrder) : iterType \ + return _meshDS ? _meshDS->methName() : iterType \ ( new TIter( _elements[elemType].begin(), _elements[elemType].end() )); \ } // ------------------------------------------------------------------------------------- diff --git a/src/SMESH_I/SMESH_PreMeshInfo.cxx b/src/SMESH_I/SMESH_PreMeshInfo.cxx index c7e753d89..c2181296c 100644 --- a/src/SMESH_I/SMESH_PreMeshInfo.cxx +++ b/src/SMESH_I/SMESH_PreMeshInfo.cxx @@ -1059,8 +1059,7 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const // -- Most probably a bad study was saved when there were // not fixed bugs in SMDS_MeshInfo if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) { - SMDS_FacePosition* fPos = const_cast - ( static_cast( aPos )); + SMDS_FacePositionPtr fPos = aPos; fPos->SetUParameter( aUPos[ iNode ]); fPos->SetVParameter( aVPos[ iNode ]); } @@ -1068,9 +1067,8 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const else { // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182 if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) { - SMDS_EdgePosition* fPos = const_cast - ( static_cast( aPos )); - fPos->SetUParameter( aUPos[ iNode ]); + SMDS_EdgePositionPtr ePos = aPos; + ePos->SetUParameter( aUPos[ iNode ]); } } } diff --git a/src/StdMeshers/StdMeshers_Cartesian_3D.cxx b/src/StdMeshers/StdMeshers_Cartesian_3D.cxx index 2c1beefc8..b9c2e393f 100644 --- a/src/StdMeshers/StdMeshers_Cartesian_3D.cxx +++ b/src/StdMeshers/StdMeshers_Cartesian_3D.cxx @@ -3619,7 +3619,7 @@ bool StdMeshers_Cartesian_3D::Compute(SMESH_Mesh & theMesh, for ( ; solidExp.More() && volIt->more(); solidExp.Next() ) { const SMDS_MeshElement* vol = volIt->next(); - sm1->RemoveElement( vol, /*isElemDeleted=*/false ); + sm1->RemoveElement( vol ); meshDS->SetMeshElementOnShape( vol, solidExp.Current() ); } } diff --git a/src/StdMeshers/StdMeshers_FaceSide.cxx b/src/StdMeshers/StdMeshers_FaceSide.cxx index b0d36a59c..0b6848622 100644 --- a/src/StdMeshers/StdMeshers_FaceSide.cxx +++ b/src/StdMeshers/StdMeshers_FaceSide.cxx @@ -549,8 +549,7 @@ const std::vector& StdMeshers_FaceSide::GetUVPtStruct(bool isXCons uvPt.normParam = u_node->first; uvPt.x = uvPt.y = uvPt.normParam; // -- U ---------------------------------------------- - const SMDS_EdgePosition* epos = - dynamic_cast(uvPt.node->GetPosition()); + SMDS_EdgePositionPtr epos = uvPt.node->GetPosition(); if ( epos && uvPt.node->getshapeId() == myEdgeID[iE] ) { uvPt.param = epos->GetUParameter(); } diff --git a/src/StdMeshers/StdMeshers_HexaFromSkin_3D.cxx b/src/StdMeshers/StdMeshers_HexaFromSkin_3D.cxx index a32b65891..403de38f6 100644 --- a/src/StdMeshers/StdMeshers_HexaFromSkin_3D.cxx +++ b/src/StdMeshers/StdMeshers_HexaFromSkin_3D.cxx @@ -386,7 +386,7 @@ namespace // Find a node at any block corner - SMDS_NodeIteratorPtr nIt = meshDS->nodesIterator(/*idInceasingOrder=*/true); + SMDS_NodeIteratorPtr nIt = meshDS->nodesIterator(); if ( !nIt->more() ) return error("Empty mesh"); const SMDS_MeshNode* nCorner = 0; diff --git a/src/StdMeshers/StdMeshers_Import_1D2D.cxx b/src/StdMeshers/StdMeshers_Import_1D2D.cxx index 949bd3a90..b5da1cd52 100644 --- a/src/StdMeshers/StdMeshers_Import_1D2D.cxx +++ b/src/StdMeshers/StdMeshers_Import_1D2D.cxx @@ -581,7 +581,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & if ( Abs(u-f) < 2 * faceTol || Abs(u-l) < 2 * faceTol ) // duplicated node on vertex return error("Source elements overlap one another"); - tgtFaceSM->RemoveNode( n, /*isNodeDeleted=*/false ); + tgtFaceSM->RemoveNode( n ); tgtMesh->SetNodeOnEdge( n, edges[iE], u ); break; } @@ -634,7 +634,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & TopoDS_Edge geomEdge = TopoDS::Edge(bndShapes.back()); helper.CheckNodeU( geomEdge, link._medium, u, projTol, /*force=*/true ); - tgtFaceSM->RemoveNode( link._medium, /*isNodeDeleted=*/false ); + tgtFaceSM->RemoveNode( link._medium ); tgtMesh->SetNodeOnEdge( (SMDS_MeshNode*)link._medium, geomEdge, u ); } else @@ -747,7 +747,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & seamHelper.AddEdge( node1, node2 ); if ( node2->getshapeId() == helper.GetSubShapeID() ) { - tgtFaceSM->RemoveNode( node2, /*isNodeDeleted=*/false ); + tgtFaceSM->RemoveNode( node2 ); tgtMesh->SetNodeOnEdge( const_cast( node2 ), seamEdge, n2->first ); } } diff --git a/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx b/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx index 196dbe7da..4ea62de3e 100644 --- a/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx +++ b/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx @@ -516,8 +516,7 @@ static bool fixCommonVertexUV (R2 & theUV, // check if node is medium if ( theCreateQuadratic && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge )) continue; - const SMDS_EdgePosition* epos = - static_cast(node->GetPosition()); + SMDS_EdgePositionPtr epos = node->GetPosition(); double u = epos->GetUParameter(); if ( u < umin ) umin = u; @@ -535,10 +534,10 @@ static bool fixCommonVertexUV (R2 & theUV, } R2 uv0, uv1, uv2; uv0.x = thisUV.X(); uv0.y = thisUV.Y(); - uv1.x = nextUV.X(); uv1.y = nextUV.Y(); + uv1.x = nextUV.X(); uv1.y = nextUV.Y(); uv2.x = thisUV.X(); uv2.y = thisUV.Y(); - uv1.x *= theScaleX; uv1.y *= theScaleY; + uv1.x *= theScaleX; uv1.y *= theScaleY; if ( fixOverlappedLinkUV( uv0, uv1, uv2 )) { diff --git a/src/StdMeshers/StdMeshers_Penta_3D.cxx b/src/StdMeshers/StdMeshers_Penta_3D.cxx index 0223a7a07..f22b5fe67 100644 --- a/src/StdMeshers/StdMeshers_Penta_3D.cxx +++ b/src/StdMeshers/StdMeshers_Penta_3D.cxx @@ -234,8 +234,7 @@ void StdMeshers_Penta_3D::MakeNodes() aTNode.SetBaseNodeID(aNodeID); // if ( SMESH_Block::IsEdgeID (aSID)) { - const SMDS_EdgePosition* epos = - static_cast(aNode->GetPosition()); + SMDS_EdgePositionPtr epos = aNode->GetPosition(); myBlock.ComputeParameters( epos->GetUParameter(), aS, aCoords ); } else { @@ -1465,11 +1464,9 @@ bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes, node = nIt->next(); if(myTool->IsMedium(node)) continue; - const SMDS_EdgePosition* pos = - dynamic_cast( node->GetPosition() ); - if ( !pos ) { + SMDS_EdgePositionPtr pos = node->GetPosition(); + if ( !pos ) return false; - } double u = ( pos->GetUParameter() - f ) / range; vector & nVec = theIJNodes[ u ]; nVec.resize( vsize, nullNode ); @@ -1488,11 +1485,9 @@ bool StdMeshers_Penta_3D::LoadIJNodes(StdMeshers_IJNodeMap & theIJNodes, node = nIt->next(); if(myTool->IsMedium(node)) continue; - const SMDS_EdgePosition* pos = - dynamic_cast( node->GetPosition() ); - if ( !pos ) { + SMDS_EdgePositionPtr pos = node->GetPosition(); + if ( !pos ) return false; - } sortedNodes.insert( make_pair( pos->GetUParameter(), node )); } loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() ); diff --git a/src/StdMeshers/StdMeshers_Prism_3D.cxx b/src/StdMeshers/StdMeshers_Prism_3D.cxx index 9dde41365..f5807f09a 100644 --- a/src/StdMeshers/StdMeshers_Prism_3D.cxx +++ b/src/StdMeshers/StdMeshers_Prism_3D.cxx @@ -1798,9 +1798,8 @@ bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism) if ( myHelper->GetIsQuadratic() ) { // fill myHelper with medium nodes built by quadAlgo - SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements(); - while ( fIt->more() ) - myHelper->AddTLinks( dynamic_cast( fIt->next() )); + for ( SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements(); fIt->more(); ) + myHelper->AddTLinks( SMDS_Mesh::DownCast( fIt->next() )); } } } @@ -4847,7 +4846,7 @@ TPCurveOnHorFaceAdaptor::TPCurveOnHorFaceAdaptor( const TSideFace* sideFace, } if ( !C2d.IsNull() ) { - double u = static_cast< const SMDS_EdgePosition* >( n->GetPosition() )->GetUParameter(); + double u = SMDS_EdgePositionPtr( n->GetPosition() )->GetUParameter(); if ( f <= u && u <= l ) { uv = C2d->Value( u ).XY(); diff --git a/src/StdMeshers/StdMeshers_ProjectionUtils.cxx b/src/StdMeshers/StdMeshers_ProjectionUtils.cxx index 2070ef108..55a7214e8 100644 --- a/src/StdMeshers/StdMeshers_ProjectionUtils.cxx +++ b/src/StdMeshers/StdMeshers_ProjectionUtils.cxx @@ -2209,8 +2209,7 @@ FindMatchingNodesOnFaces( const TopoDS_Face& face1, SMDS_NodeIteratorPtr nIt = edgeSM->GetNodes(); while ( nIt->more() ) { const SMDS_MeshNode* node = nIt->next(); - const SMDS_EdgePosition* pos = - static_cast(node->GetPosition()); + SMDS_EdgePositionPtr pos = node->GetPosition(); pos2nodes.insert( make_pair( pos->GetUParameter(), node )); } if ((int) pos2nodes.size() != edgeSM->NbNodes() ) @@ -2886,7 +2885,6 @@ namespace StdMeshers_ProjectionUtils double bc[3]; // barycentric coordinates int nodeIDs[3]; // nodes of a delaunay triangle - const SMDS_FacePosition* pos; _delaunay.InitTraversal( nbSrcNodes ); @@ -2904,8 +2902,8 @@ namespace StdMeshers_ProjectionUtils tgtNode = n2n->second; tgtMesh->MoveNode( tgtNode, xyz.X(), xyz.Y(), xyz.Z() ); - if (( pos = dynamic_cast< const SMDS_FacePosition* >( tgtNode->GetPosition() ))) - const_cast( pos )->SetParameters( uvNew.X(), uvNew.Y() ); + if ( SMDS_FacePositionPtr pos = tgtNode->GetPosition() ) + pos->SetParameters( uvNew.X(), uvNew.Y() ); --nbSrcNodes; } diff --git a/src/StdMeshers/StdMeshers_Projection_1D2D.cxx b/src/StdMeshers/StdMeshers_Projection_1D2D.cxx index c0e53ceeb..ae15730cd 100644 --- a/src/StdMeshers/StdMeshers_Projection_1D2D.cxx +++ b/src/StdMeshers/StdMeshers_Projection_1D2D.cxx @@ -140,7 +140,7 @@ bool StdMeshers_Projection_1D2D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape { const SMDS_MeshElement* f = fIt->next(); //if ( !f->IsQuadratic() ) continue; - nodes.assign( SMDS_MeshElement::iterator( f->interlacedNodesElemIterator() ), + nodes.assign( SMDS_MeshElement::iterator( f->interlacedNodesIterator() ), SMDS_MeshElement::iterator() ); nodes.push_back( nodes[0] ); for ( size_t i = 2; i < nodes.size(); i += 2 ) @@ -149,8 +149,8 @@ bool StdMeshers_Projection_1D2D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape if ( idType.second == TopAbs_EDGE && idType.first != nodes[i-1]->getshapeId() ) { - faceSubMesh->RemoveNode( nodes[i-1], /*isDeleted=*/false ); - meshDS->SetNodeOnEdge( (SMDS_MeshNode*) nodes[i-1], idType.first ); + faceSubMesh->RemoveNode( nodes[i-1] ); + meshDS->SetNodeOnEdge( nodes[i-1], idType.first ); posFixer.SetSubShape( idType.first ); posFixer.CheckNodeU( TopoDS::Edge( posFixer.GetSubShape() ), nodes[i-1], dummyU=0., tol, /*force=*/true ); diff --git a/src/StdMeshers/StdMeshers_Projection_2D.cxx b/src/StdMeshers/StdMeshers_Projection_2D.cxx index 0686b165a..68ae8ea47 100644 --- a/src/StdMeshers/StdMeshers_Projection_2D.cxx +++ b/src/StdMeshers/StdMeshers_Projection_2D.cxx @@ -371,8 +371,7 @@ namespace { if ( node->GetPosition()->GetTypeOfPosition() != SMDS_TOP_EDGE ) RETURN_BAD_RESULT("Bad node position type: node " << node->GetID() << " pos type " << node->GetPosition()->GetTypeOfPosition()); - const SMDS_EdgePosition* pos = - static_cast(node->GetPosition()); + SMDS_EdgePositionPtr pos = node->GetPosition(); u2nodes.insert( make_pair( pos->GetUParameter(), node )); seamNodes.insert( node ); } @@ -1587,8 +1586,7 @@ bool StdMeshers_Projection_2D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& break; } case SMDS_TOP_EDGE: { - const SMDS_EdgePosition* pos = - static_cast(node->GetPosition()); + SMDS_EdgePositionPtr pos = node->GetPosition(); pos2nodes.insert( make_pair( pos->GetUParameter(), node )); break; } diff --git a/src/StdMeshers/StdMeshers_Projection_3D.cxx b/src/StdMeshers/StdMeshers_Projection_3D.cxx index 43a6c4c09..4284c1b36 100644 --- a/src/StdMeshers/StdMeshers_Projection_3D.cxx +++ b/src/StdMeshers/StdMeshers_Projection_3D.cxx @@ -31,7 +31,6 @@ #include "StdMeshers_ProjectionUtils.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_Hypothesis.hxx" #include "SMESHDS_Mesh.hxx" @@ -408,8 +407,7 @@ bool StdMeshers_Projection_3D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aS nodes[6], nodes[7], id, force3d); break; default: // polyhedron - const SMDS_VtkVolume * poly = - dynamic_cast( srcVol ); + const SMDS_MeshVolume * poly = tgtMeshDS->DownCast( srcVol ); if ( !poly ) RETURN_BAD_RESULT("Unexpected volume type"); if ( !poly->IsPoly()) diff --git a/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx b/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx index 2e4ea50b8..fd3a5bb10 100644 --- a/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx +++ b/src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx @@ -296,12 +296,13 @@ namespace SMESH_ComputeErrorPtr& err = sm->GetComputeError(); if ( !err || err->IsOK() ) { - err = SMESH_ComputeError::New( COMPERR_BAD_INPUT_MESH, msg, sm->GetAlgo() ); - err->myBadElements.push_back( face1 ); - err->myBadElements.push_back( face2 ); + SMESH_BadInputElements* badElems = + new SMESH_BadInputElements( mesh.GetMeshDS(),COMPERR_BAD_INPUT_MESH, msg, sm->GetAlgo() ); + badElems->add( face1 ); + badElems->add( face2 ); + err.reset( badElems ); } } - //throw SALOME_Exception( msg.c_str() ); return false; // == "algo fails" } @@ -1035,7 +1036,7 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh) vector FNodes(5); TColgp_SequenceOfPnt aContour; - SMDS_FaceIteratorPtr fIt = meshDS->facesIterator(/*idInceasingOrder=*/true); + SMDS_FaceIteratorPtr fIt = meshDS->facesIterator(); while( fIt->more()) { const SMDS_MeshElement* face = fIt->next(); diff --git a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx index ada3ab0cc..a9d275cfb 100644 --- a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx +++ b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx @@ -643,9 +643,11 @@ bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh, SMESH_ComputeErrorPtr& err = aMesh.GetSubMesh( aFace )->GetComputeError(); if ( !err || err->IsOK() || err->myName < COMPERR_WARNING ) { - err.reset( new SMESH_ComputeError( COMPERR_WARNING, - "Bad quality quad created")); - err->myBadElements.push_back( face ); + SMESH_BadInputElements* badElems = + new SMESH_BadInputElements( meshDS, COMPERR_WARNING, + "Bad quality quad created"); + badElems->add( face ); + err.reset( badElems ); } } --i; @@ -818,9 +820,11 @@ bool StdMeshers_Quadrangle_2D::computeQuadDominant(SMESH_Mesh& aMesh, SMESH_ComputeErrorPtr& err = aMesh.GetSubMesh( aFace )->GetComputeError(); if ( !err || err->IsOK() || err->myName < COMPERR_WARNING ) { - err.reset( new SMESH_ComputeError( COMPERR_WARNING, - "Bad quality quad created")); - err->myBadElements.push_back( face ); + SMESH_BadInputElements* badElems = + new SMESH_BadInputElements( meshDS, COMPERR_WARNING, + "Bad quality quad created"); + badElems->add( face ); + err.reset( badElems ); } } --i; @@ -4668,9 +4672,11 @@ bool StdMeshers_Quadrangle_2D::check() { SMESH_subMesh* fSM = myHelper->GetMesh()->GetSubMesh( geomFace ); SMESH_ComputeErrorPtr& err = fSM->GetComputeError(); - err.reset ( new SMESH_ComputeError( COMPERR_ALGO_FAILED, - "Inverted elements generated")); - err->myBadElements.swap( badFaces ); + SMESH_BadInputElements* badElems = + new SMESH_BadInputElements( meshDS, COMPERR_ALGO_FAILED, + "Inverted elements generated"); + badElems->myBadElements.swap( badFaces ); + err.reset( badElems ); return !isOK; } diff --git a/src/StdMeshers/StdMeshers_ViscousLayers.cxx b/src/StdMeshers/StdMeshers_ViscousLayers.cxx index f68c3cbee..72cdff35f 100644 --- a/src/StdMeshers/StdMeshers_ViscousLayers.cxx +++ b/src/StdMeshers/StdMeshers_ViscousLayers.cxx @@ -27,6 +27,7 @@ #include "SMDS_FaceOfNodes.hxx" #include "SMDS_FacePosition.hxx" #include "SMDS_MeshNode.hxx" +#include "SMDS_PolygonalFaceOfNodes.hxx" #include "SMDS_SetIterator.hxx" #include "SMESHDS_Group.hxx" #include "SMESHDS_Hypothesis.hxx" @@ -93,6 +94,7 @@ #include #include #include +#include #ifdef _DEBUG_ #define __myDEBUG @@ -660,7 +662,8 @@ namespace VISCOUS_3D vector< _EdgesOnShape* > _eosConcaVer; // edges at concave VERTEXes of a FACE vector< _EdgesOnShape* > _eosC1; // to smooth together several C1 continues shapes - vector< gp_XYZ > _faceNormals; // if _shape is FACE + typedef std::unordered_map< const SMDS_MeshElement*, gp_XYZ > TFace2NormMap; + TFace2NormMap _faceNormals; // if _shape is FACE vector< _EdgesOnShape* > _faceEOS; // to get _faceNormals of adjacent FACEs Handle(ShapeAnalysis_Surface) _offsetSurf; @@ -1098,24 +1101,23 @@ namespace VISCOUS_3D * We can't use SMDS_FaceOfNodes since it's impossible to set it's ID which is * needed because SMESH_ElementSearcher internaly uses set of elements sorted by ID */ - struct _TmpMeshFace : public SMDS_MeshElement + struct _TmpMeshFace : public SMDS_PolygonalFaceOfNodes { - vector _nn; + const SMDS_MeshElement* _srcFace; + _TmpMeshFace( const vector& nodes, - int id, int faceID=-1, int idInFace=-1): - SMDS_MeshElement(id), _nn(nodes) { setShapeId(faceID); setIdInShape(idInFace); } - virtual const SMDS_MeshNode* GetNode(const int ind) const { return _nn[ind]; } - virtual SMDSAbs_ElementType GetType() const { return SMDSAbs_Face; } - virtual vtkIdType GetVtkType() const { return -1; } - virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Last; } - virtual SMDSAbs_GeometryType GetGeomType() const - { return _nn.size() == 3 ? SMDSGeom_TRIANGLE : SMDSGeom_QUADRANGLE; } - virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType) const - { return SMDS_ElemIteratorPtr( new SMDS_NodeVectorElemIterator( _nn.begin(), _nn.end()));} + int ID, + int faceID=-1, + const SMDS_MeshElement* srcFace=0 ): + SMDS_PolygonalFaceOfNodes(nodes), _srcFace( srcFace ) { setID( ID ); setShapeID( faceID ); } + virtual SMDSAbs_EntityType GetEntityType() const + { return _srcFace ? _srcFace->GetEntityType() : SMDSEntity_Quadrangle; } + virtual SMDSAbs_GeometryType GetGeomType() const + { return _srcFace ? _srcFace->GetGeomType() : SMDSGeom_QUADRANGLE; } }; //-------------------------------------------------------------------------------- /*! - * \brief Class of temporary mesh face storing _LayerEdge it's based on + * \brief Class of temporary mesh quadrangle face storing _LayerEdge it's based on */ struct _TmpMeshFaceOnEdge : public _TmpMeshFace { @@ -1123,17 +1125,21 @@ namespace VISCOUS_3D _TmpMeshFaceOnEdge( _LayerEdge* le1, _LayerEdge* le2, int ID ): _TmpMeshFace( vector(4), ID ), _le1(le1), _le2(le2) { - _nn[0]=_le1->_nodes[0]; - _nn[1]=_le1->_nodes.back(); - _nn[2]=_le2->_nodes.back(); - _nn[3]=_le2->_nodes[0]; + myNodes[0]=_le1->_nodes[0]; + myNodes[1]=_le1->_nodes.back(); + myNodes[2]=_le2->_nodes.back(); + myNodes[3]=_le2->_nodes[0]; + } + const SMDS_MeshNode* n( size_t i ) const + { + return myNodes[ i ]; } gp_XYZ GetDir() const // return average direction of _LayerEdge's, normal to EDGE { - SMESH_TNodeXYZ p0s( _nn[0] ); - SMESH_TNodeXYZ p0t( _nn[1] ); - SMESH_TNodeXYZ p1t( _nn[2] ); - SMESH_TNodeXYZ p1s( _nn[3] ); + SMESH_TNodeXYZ p0s( myNodes[0] ); + SMESH_TNodeXYZ p0t( myNodes[1] ); + SMESH_TNodeXYZ p1t( myNodes[2] ); + SMESH_TNodeXYZ p1s( myNodes[3] ); gp_XYZ v0 = p0t - p0s; gp_XYZ v1 = p1t - p1s; gp_XYZ v01 = p1s - p0s; @@ -1144,10 +1150,10 @@ namespace VISCOUS_3D } gp_XYZ GetDir(_LayerEdge* le1, _LayerEdge* le2) // return average direction of _LayerEdge's { - _nn[0]=le1->_nodes[0]; - _nn[1]=le1->_nodes.back(); - _nn[2]=le2->_nodes.back(); - _nn[3]=le2->_nodes[0]; + myNodes[0]=le1->_nodes[0]; + myNodes[1]=le1->_nodes.back(); + myNodes[2]=le2->_nodes.back(); + myNodes[3]=le2->_nodes[0]; return GetDir(); } }; @@ -2641,7 +2647,7 @@ bool _ViscousBuilder::makeLayer(_SolidData& data) // create a temporary face const SMDS_MeshElement* newFace = - new _TmpMeshFace( newNodes, --_tmpFaceID, face->getshapeId(), face->getIdInShape() ); + new _TmpMeshFace( newNodes, --_tmpFaceID, face->GetShapeID(), face ); proxySub->AddElement( newFace ); // compute inflation step size by min size of element on a convex surface @@ -3313,19 +3319,18 @@ void _ViscousBuilder::setShapeData( _EdgesOnShape& eos, { SMESHDS_SubMesh* smDS = sm->GetSubMeshDS(); if ( !smDS ) return; - eos._faceNormals.resize( smDS->NbElements() ); + eos._faceNormals.reserve( smDS->NbElements() ); + double oriFactor = helper.IsReversedSubMesh( TopoDS::Face( eos._shape )) ? 1.: -1.; SMDS_ElemIteratorPtr eIt = smDS->GetElements(); - for ( int iF = 0; eIt->more(); ++iF ) + for ( ; eIt->more(); ) { const SMDS_MeshElement* face = eIt->next(); - if ( !SMESH_MeshAlgos::FaceNormal( face, eos._faceNormals[iF], /*normalized=*/true )) - eos._faceNormals[iF].SetCoord( 0,0,0 ); + gp_XYZ& norm = eos._faceNormals[face]; + if ( !SMESH_MeshAlgos::FaceNormal( face, norm, /*normalized=*/true )) + norm.SetCoord( 0,0,0 ); + norm *= oriFactor; } - - if ( !helper.IsReversedSubMesh( TopoDS::Face( eos._shape ))) - for ( size_t iF = 0; iF < eos._faceNormals.size(); ++iF ) - eos._faceNormals[iF].Reverse(); } else // find EOS of adjacent FACEs { @@ -3351,7 +3356,7 @@ void _ViscousBuilder::setShapeData( _EdgesOnShape& eos, bool _EdgesOnShape::GetNormal( const SMDS_MeshElement* face, gp_Vec& norm ) { bool ok = false; - const _EdgesOnShape* eos = 0; + _EdgesOnShape* eos = 0; if ( face->getshapeId() == _shapeID ) { @@ -3365,9 +3370,9 @@ bool _EdgesOnShape::GetNormal( const SMDS_MeshElement* face, gp_Vec& norm ) } if (( eos ) && - ( ok = ( face->getIdInShape() < (int) eos->_faceNormals.size() ))) + ( ok = ( eos->_faceNormals.count( face ) ))) { - norm = eos->_faceNormals[ face->getIdInShape() ]; + norm = eos->_faceNormals[ face ]; } else if ( !eos ) { @@ -3605,7 +3610,7 @@ bool _ViscousBuilder::setEdgeData(_LayerEdge& edge, { const SMDS_MeshNode* tgtNode = edge._nodes.back(); if ( SMESHDS_SubMesh* sm = getMeshDS()->MeshElements( data._solid )) - sm->RemoveNode( tgtNode , /*isNodeDeleted=*/false ); + sm->RemoveNode( tgtNode ); // set initial position which is parameters on _sWOL in this case if ( eos.SWOLType() == TopAbs_EDGE ) @@ -5107,14 +5112,13 @@ bool _ViscousBuilder::smoothAndCheck(_SolidData& data, eos._edges[i]->Set( _LayerEdge::INTERSECTED ); // not to intersect eos._edges[i]->Block( data ); // not to inflate - if ( _EdgesOnShape* eof = data.GetShapeEdges( intFace->getshapeId() )) + //if ( _EdgesOnShape* eof = data.GetShapeEdges( intFace->getshapeId() )) { // block _LayerEdge's, on top of which intFace is if ( const _TmpMeshFace* f = dynamic_cast< const _TmpMeshFace*>( intFace )) { - const SMDS_MeshElement* srcFace = - eof->_subMesh->GetSubMeshDS()->GetElement( f->getIdInShape() ); - SMDS_ElemIteratorPtr nIt = srcFace->nodesIterator(); + const SMDS_MeshElement* srcFace = f->_srcFace; + SMDS_ElemIteratorPtr nIt = srcFace->nodesIterator(); while ( nIt->more() ) { const SMDS_MeshNode* srcNode = static_cast( nIt->next() ); @@ -5781,7 +5785,7 @@ bool _Smoother1D::smoothAnalyticEdge( _SolidData& data, tgtNode->setXYZ( newPos.X(), newPos.Y(), newPos.Z() ); dumpMove( tgtNode ); - SMDS_FacePosition* pos = static_cast( tgtNode->GetPosition() ); + SMDS_FacePositionPtr pos = tgtNode->GetPosition(); pos->SetUParameter( newUV.X() ); pos->SetVParameter( newUV.Y() ); @@ -5893,7 +5897,7 @@ bool _Smoother1D::smoothAnalyticEdge( _SolidData& data, tgtNode->setXYZ( newPos.X(), newPos.Y(), newPos.Z() ); dumpMove( tgtNode ); - SMDS_FacePosition* pos = static_cast( tgtNode->GetPosition() ); + SMDS_FacePositionPtr pos = tgtNode->GetPosition(); pos->SetUParameter( newUV.X() ); pos->SetVParameter( newUV.Y() ); @@ -6501,10 +6505,10 @@ void _SolidData::PrepareEdgesToSmoothOnFace( _EdgesOnShape* eos, bool substitute { edge->Set( _LayerEdge::SMOOTHED_C1 ); isCurved = true; - SMDS_FacePosition* fPos = dynamic_cast( edge->_nodes[0]->GetPosition() ); + SMDS_FacePositionPtr fPos = edge->_nodes[0]->GetPosition(); if ( !fPos ) for ( size_t iS = 0; iS < edge->_simplices.size() && !fPos; ++iS ) - fPos = dynamic_cast( edge->_simplices[iS]._nPrev->GetPosition() ); + fPos = edge->_simplices[iS]._nPrev->GetPosition(); if ( fPos ) edge->_curvature->_uv.SetCoord( fPos->GetUParameter(), fPos->GetVParameter() ); } @@ -6801,9 +6805,9 @@ void _ViscousBuilder::findCollisionEdges( _SolidData& data, SMESH_MesherHelper& ( f->_le2->IsOnEdge() && f->_le2->_2neibors->include( edge ))) continue; } dist1 = dist2 = Precision::Infinite(); - if ( !edge->SegTriaInter( lastSegment, f->_nn[0], f->_nn[1], f->_nn[2], dist1, eps )) + if ( !edge->SegTriaInter( lastSegment, f->n(0), f->n(1), f->n(2), dist1, eps )) dist1 = Precision::Infinite(); - if ( !edge->SegTriaInter( lastSegment, f->_nn[3], f->_nn[2], f->_nn[0], dist2, eps )) + if ( !edge->SegTriaInter( lastSegment, f->n(3), f->n(2), f->n(0), dist2, eps )) dist2 = Precision::Infinite(); if (( dist1 > segLen ) && ( dist2 > segLen )) continue; @@ -6811,7 +6815,7 @@ void _ViscousBuilder::findCollisionEdges( _SolidData& data, SMESH_MesherHelper& if ( edge->IsOnEdge() ) { // skip perpendicular EDGEs - gp_Vec fSegDir = SMESH_TNodeXYZ( f->_nn[0] ) - SMESH_TNodeXYZ( f->_nn[3] ); + gp_Vec fSegDir = SMESH_TNodeXYZ( f->n(0) ) - SMESH_TNodeXYZ( f->n(3) ); bool isParallel = ( isLessAngle( eSegDir0, fSegDir, angle45 ) || isLessAngle( eSegDir1, fSegDir, angle45 ) || isLessAngle( eSegDir0, fSegDir.Reversed(), angle45 ) || @@ -8247,7 +8251,7 @@ void _LayerEdge::MoveNearConcaVer( const _EdgesOnShape* eov, prevPosV = surface.Value( prevPosV.X(), prevPosV.Y() ).XYZ(); } - SMDS_FacePosition* fPos; + SMDS_FacePositionPtr fPos; //double r = 1. - Min( 0.9, step / 10. ); for ( set< _LayerEdge* >::iterator e = edges.begin(); e != edges.end(); ++e ) { @@ -8261,7 +8265,7 @@ void _LayerEdge::MoveNearConcaVer( const _EdgesOnShape* eov, // set _curvature to make edgeF updated by putOnOffsetSurface() if ( !edgeF->_curvature ) - if (( fPos = dynamic_cast( edgeF->_nodes[0]->GetPosition() ))) + if (( fPos = edgeF->_nodes[0]->GetPosition() )) { edgeF->_curvature = new _Curvature; edgeF->_curvature->_r = 0; @@ -9482,7 +9486,7 @@ void _LayerEdge::SetNewLength( double len, _EdgesOnShape& eos, SMESH_MesherHelpe _pos.back().SetCoord( u, 0, 0 ); if ( _nodes.size() > 1 && uvOK ) { - SMDS_EdgePosition* pos = static_cast( n->GetPosition() ); + SMDS_EdgePositionPtr pos = n->GetPosition(); pos->SetUParameter( u ); } } @@ -9494,7 +9498,7 @@ void _LayerEdge::SetNewLength( double len, _EdgesOnShape& eos, SMESH_MesherHelpe _pos.back().SetCoord( uv.X(), uv.Y(), 0 ); if ( _nodes.size() > 1 && uvOK ) { - SMDS_FacePosition* pos = static_cast( n->GetPosition() ); + SMDS_FacePositionPtr pos = n->GetPosition(); pos->SetUParameter( uv.X() ); pos->SetVParameter( uv.Y() ); } @@ -9610,7 +9614,7 @@ void _LayerEdge::InvalidateStep( size_t curStep, const _EdgesOnShape& eos, bool TopLoc_Location loc; if ( eos.SWOLType() == TopAbs_EDGE ) { - SMDS_EdgePosition* pos = static_cast( n->GetPosition() ); + SMDS_EdgePositionPtr pos = n->GetPosition(); pos->SetUParameter( nXYZ.X() ); double f,l; Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( eos._sWOL ), loc, f,l); @@ -9618,7 +9622,7 @@ void _LayerEdge::InvalidateStep( size_t curStep, const _EdgesOnShape& eos, bool } else { - SMDS_FacePosition* pos = static_cast( n->GetPosition() ); + SMDS_FacePositionPtr pos = n->GetPosition(); pos->SetUParameter( nXYZ.X() ); pos->SetVParameter( nXYZ.Y() ); Handle(Geom_Surface) surface = BRep_Tool::Surface( TopoDS::Face(eos._sWOL), loc ); @@ -9983,12 +9987,12 @@ bool _ViscousBuilder::refine(_SolidData& data) SMDS_PositionPtr lastPos = tgtNode->GetPosition(); if ( isOnEdge ) { - SMDS_EdgePosition* epos = static_cast( lastPos ); + SMDS_EdgePositionPtr epos = lastPos; epos->SetUParameter( otherTgtPos.X() ); } else { - SMDS_FacePosition* fpos = static_cast( lastPos ); + SMDS_FacePositionPtr fpos = lastPos; fpos->SetUParameter( otherTgtPos.X() ); fpos->SetVParameter( otherTgtPos.Y() ); } @@ -10077,7 +10081,7 @@ bool _ViscousBuilder::refine(_SolidData& data) u = helper.GetNodeU( geomEdge, node ); pos = curve->Value( u ).Transformed(loc); - SMDS_EdgePosition* epos = static_cast( node->GetPosition() ); + SMDS_EdgePositionPtr epos = node->GetPosition(); epos->SetUParameter( u ); } else @@ -10087,7 +10091,7 @@ bool _ViscousBuilder::refine(_SolidData& data) uv = helper.GetNodeUV( geomFace, node ); pos = surface->Value( uv ); - SMDS_FacePosition* fpos = static_cast( node->GetPosition() ); + SMDS_FacePositionPtr fpos = node->GetPosition(); fpos->SetUParameter( uv.X() ); fpos->SetVParameter( uv.Y() ); } @@ -10262,10 +10266,11 @@ bool _ViscousBuilder::refine(_SolidData& data) SMESH_ComputeErrorPtr& err = _mesh->GetSubMesh( data._solid )->GetComputeError(); if ( !err || err->IsOK() ) { - err.reset( new SMESH_ComputeError( COMPERR_WARNING, - "Bad quality volumes created" )); - err->myBadElements.insert( err->myBadElements.end(), - degenVols.begin(),degenVols.end() ); + SMESH_BadInputElements* badElems = + new SMESH_BadInputElements( getMeshDS(), COMPERR_WARNING, "Bad quality volumes created" ); + badElems->myBadElements.insert( badElems->myBadElements.end(), + degenVols.begin(),degenVols.end() ); + err.reset( badElems ); } } @@ -10678,14 +10683,14 @@ bool _ViscousBuilder::shrink(_SolidData& theData) edge->Is( _LayerEdge::SHRUNK )) continue; if ( subEOS[iS]->SWOLType() == TopAbs_FACE ) { - SMDS_FacePosition* pos = static_cast( tgtNode->GetPosition() ); + SMDS_FacePositionPtr pos = tgtNode->GetPosition(); pos->SetUParameter( edge->_pos[0].X() ); pos->SetVParameter( edge->_pos[0].Y() ); p = surface->Value( edge->_pos[0].X(), edge->_pos[0].Y() ); } else { - SMDS_EdgePosition* pos = static_cast( tgtNode->GetPosition() ); + SMDS_EdgePositionPtr pos = tgtNode->GetPosition(); pos->SetUParameter( edge->_pos[0].Coord( U_TGT )); p = BRepAdaptor_Curve( TopoDS::Edge( subEOS[iS]->_sWOL )).Value( pos->GetUParameter() ); } @@ -10880,7 +10885,7 @@ bool _ViscousBuilder::prepareEdgeToShrink( _LayerEdge& edge, edge._pos[0].SetCoord( tgtUV.X(), tgtUV.Y(), 0 ); // set UV of source node to target node - SMDS_FacePosition* pos = static_cast( tgtNode->GetPosition() ); + SMDS_FacePositionPtr pos = tgtNode->GetPosition(); pos->SetUParameter( srcUV.X() ); pos->SetVParameter( srcUV.Y() ); } @@ -10930,7 +10935,7 @@ bool _ViscousBuilder::prepareEdgeToShrink( _LayerEdge& edge, edge._simplices[0]._nPrev = n2; // set U of source node to the target node - SMDS_EdgePosition* pos = static_cast( tgtNode->GetPosition() ); + SMDS_EdgePositionPtr pos = tgtNode->GetPosition(); pos->SetUParameter( uSrc ); } return true; @@ -10963,7 +10968,7 @@ void _ViscousBuilder::restoreNoShrink( _LayerEdge& edge ) const TopLoc_Location loc; Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( S ), loc, f, l ); if ( curve.IsNull() ) return; - SMDS_EdgePosition* ePos = static_cast( srcNode->GetPosition() ); + SMDS_EdgePositionPtr ePos = srcNode->GetPosition(); p = curve->Value( ePos->GetUParameter() ); break; } @@ -11189,7 +11194,7 @@ bool _LayerEdge::SetNewLength2d( Handle(Geom_Surface)& surface, { return true; } - SMDS_FacePosition* pos = static_cast( tgtNode->GetPosition() ); + SMDS_FacePositionPtr pos = tgtNode->GetPosition(); pos->SetUParameter( newUV.X() ); pos->SetVParameter( newUV.Y() ); @@ -11203,7 +11208,7 @@ bool _LayerEdge::SetNewLength2d( Handle(Geom_Surface)& surface, { const TopoDS_Edge& E = TopoDS::Edge( eos._sWOL ); const SMDS_MeshNode* n2 = _simplices[0]._nPrev; - SMDS_EdgePosition* tgtPos = static_cast( tgtNode->GetPosition() ); + SMDS_EdgePositionPtr tgtPos = tgtNode->GetPosition(); const double u2 = helper.GetNodeU( E, n2, tgtNode ); const double uSrc = _pos[0].Coord( U_SRC ); @@ -11323,7 +11328,7 @@ bool _SmoothNode::Smooth(int& nbBad, return false; } - SMDS_FacePosition* pos = static_cast( _node->GetPosition() ); + SMDS_FacePositionPtr pos = _node->GetPosition(); pos->SetUParameter( newPos.X() ); pos->SetVParameter( newPos.Y() ); @@ -11550,7 +11555,7 @@ void _Shrinker1D::Compute(bool set3D, SMESH_MesherHelper& helper) if ( !discret.IsDone() ) return throw SALOME_Exception(LOCALIZED("GCPnts_AbscissaPoint failed")); double u = discret.Parameter(); - SMDS_EdgePosition* pos = static_cast( _nodes[i]->GetPosition() ); + SMDS_EdgePositionPtr pos = _nodes[i]->GetPosition(); pos->SetUParameter( u ); gp_Pnt p = C->Value( u ); const_cast< SMDS_MeshNode*>( _nodes[i] )->setXYZ( p.X(), p.Y(), p.Z() ); @@ -11568,7 +11573,7 @@ void _Shrinker1D::Compute(bool set3D, SMESH_MesherHelper& helper) { if ( !_nodes[i] ) continue; double u = f * ( 1-_normPar[i] ) + l * _normPar[i]; - SMDS_EdgePosition* pos = static_cast( _nodes[i]->GetPosition() ); + SMDS_EdgePositionPtr pos = _nodes[i]->GetPosition(); pos->SetUParameter( u ); } } @@ -11586,7 +11591,7 @@ void _Shrinker1D::RestoreParams() for ( size_t i = 0; i < _nodes.size(); ++i ) { if ( !_nodes[i] ) continue; - SMDS_EdgePosition* pos = static_cast( _nodes[i]->GetPosition() ); + SMDS_EdgePositionPtr pos = _nodes[i]->GetPosition(); pos->SetUParameter( _initU[i] ); } _done = false; diff --git a/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx b/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx index 6cb97c538..98a30fa22 100644 --- a/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx +++ b/src/StdMeshers/StdMeshers_ViscousLayers2D.cxx @@ -110,7 +110,7 @@ namespace VISCOUS_2D // Proxy sub-mesh of an EDGE. It contains nodes in _uvPtStructVec. struct _EdgeSubMesh : public SMESH_ProxyMesh::SubMesh { - _EdgeSubMesh(int index=0): SubMesh(index) {} + _EdgeSubMesh(const SMDS_Mesh* mesh, int index=0): SubMesh(mesh,index) {} //virtual int NbElements() const { return _elements.size()+1; } virtual int NbNodes() const { return Max( 0, _uvPtStructVec.size()-2 ); } void SetUVPtStructVec(UVPtStructVec& vec) { _uvPtStructVec.swap( vec ); } @@ -118,7 +118,7 @@ namespace VISCOUS_2D }; _ProxyMeshOfFace(const SMESH_Mesh& mesh): SMESH_ProxyMesh(mesh) {} _EdgeSubMesh* GetEdgeSubMesh(int ID) { return (_EdgeSubMesh*) getProxySubMesh(ID); } - virtual SubMesh* newSubmesh(int index=0) const { return new _EdgeSubMesh(index); } + virtual SubMesh* newSubmesh(int index=0) const { return new _EdgeSubMesh( GetMeshDS(), index); } }; //-------------------------------------------------------------------------------- /*! @@ -1998,7 +1998,7 @@ bool _ViscousBuilder2D::shrink() throw SALOME_Exception(SMESH_Comment("ViscousBuilder2D: not SMDS_TOP_EDGE node position: ") << oldNode->GetPosition()->GetTypeOfPosition() << " of node " << oldNode->GetID()); - SMDS_EdgePosition* pos = static_cast( oldNode->GetPosition() ); + SMDS_EdgePositionPtr pos = oldNode->GetPosition(); pos->SetUParameter( nodeDataVec[iP].param ); gp_Pnt newP = curve.Value( nodeDataVec[iP].param ); -- 2.30.2