-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// 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
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// See http://www.salome-platform.org/
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
// File : SMDS_VolumeTool.cxx
// Created : Tue Jul 13 12:22:13 2004
// Author : Edward AGAPOV (eap)
-// Copyright : Open CASCADE
-
+//
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_PolyhedralVolumeOfNodes.hxx"
+#include "SMDS_Mesh.hxx"
#include "utilities.h"
// ========================================================
// to perform some calculations without linkage to CASCADE
// ========================================================
+namespace
+{
struct XYZ {
double x;
double y;
XYZ( double X, double Y, double Z ) { x = X; y = Y; z = Z; }
XYZ( const XYZ& other ) { x = other.x; y = other.y; z = other.z; }
XYZ( const SMDS_MeshNode* n ) { x = n->X(); y = n->Y(); z = n->Z(); }
- XYZ operator-( const XYZ& other );
- XYZ Crossed( const XYZ& other );
- double Dot( const XYZ& other );
- double Magnitude();
+ inline XYZ operator-( const XYZ& other );
+ inline XYZ Crossed( const XYZ& other );
+ inline double Dot( const XYZ& other );
+ inline double Magnitude();
};
-XYZ XYZ::operator-( const XYZ& Right ) {
+inline XYZ XYZ::operator-( const XYZ& Right ) {
return XYZ(x - Right.x, y - Right.y, z - Right.z);
}
-XYZ XYZ::Crossed( const XYZ& Right ) {
+inline XYZ XYZ::Crossed( const XYZ& Right ) {
return XYZ (y * Right.z - z * Right.y,
z * Right.x - x * Right.z,
x * Right.y - y * Right.x);
}
-double XYZ::Dot( const XYZ& Other ) {
+inline double XYZ::Dot( const XYZ& Other ) {
return(x * Other.x + y * Other.y + z * Other.z);
}
-double XYZ::Magnitude() {
+inline double XYZ::Magnitude() {
return sqrt (x * x + y * y + z * z);
}
+}
//=======================================================================
//function : SMDS_VolumeTool
SMDS_VolumeTool::~SMDS_VolumeTool()
{
- if (myVolumeNodes != NULL) {
- delete [] myVolumeNodes;
- myVolumeNodes = NULL;
- }
- if (myFaceNodes != NULL) {
- delete [] myFaceNodes;
- myFaceNodes = NULL;
- }
+ if ( myVolumeNodes != NULL ) delete [] myVolumeNodes;
+ if ( myFaceNodes != NULL ) delete [] myFaceNodes;
+
+ myFaceNodeIndices = NULL;
+ myVolumeNodes = myFaceNodes = NULL;
}
//=======================================================================
// define volume orientation
XYZ botNormal;
GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z );
- const SMDS_MeshNode* topNode = myVolumeNodes[ myVolumeNbNodes - 1 ];
const SMDS_MeshNode* botNode = myVolumeNodes[ 0 ];
+ int topNodeIndex = myVolume->NbCornerNodes() - 1;
+ while ( !IsLinked( 0, topNodeIndex, /*ignoreMediumNodes=*/true )) --topNodeIndex;
+ const SMDS_MeshNode* topNode = myVolumeNodes[ topNodeIndex ];
XYZ upDir (topNode->X() - botNode->X(),
topNode->Y() - botNode->Y(),
topNode->Z() - botNode->Z() );
return true;
}
+//================================================================================
+/*!
+ * \brief Classify a point
+ * \param tol - thickness of faces
+ */
+//================================================================================
+
+bool SMDS_VolumeTool::IsOut(double X, double Y, double Z, double tol)
+{
+ // LIMITATION: for convex volumes only
+ XYZ p( X,Y,Z );
+ for ( int iF = 0; iF < myNbFaces; ++iF )
+ {
+ XYZ faceNormal;
+ if ( !GetFaceNormal( iF, faceNormal.x, faceNormal.y, faceNormal.z ))
+ continue;
+ if ( !IsFaceExternal( iF ))
+ faceNormal = XYZ() - faceNormal; // reverse
+
+ XYZ face2p( p - XYZ( myFaceNodes[0] ));
+ if ( face2p.Dot( faceNormal ) > tol )
+ return true;
+ }
+ return false;
+}
+
//=======================================================================
//function : SetExternalNormal
//purpose : Node order will be so that faces normals are external
const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex )
{
- if (myVolume->IsPoly()) {
- MESSAGE("Warning: attempt to obtain FaceNodesIndices of polyhedral volume");
- return NULL;
- }
if ( !setFace( faceIndex ))
return 0;
+
+ if (myVolume->IsPoly())
+ {
+ myPolyIndices.resize( myFaceNbNodes + 1 );
+ myFaceNodeIndices = & myPolyIndices[0];
+ for ( int i = 0; i <= myFaceNbNodes; ++i )
+ myFaceNodeIndices[i] = myVolume->GetNodeIndex( myFaceNodes[i] );
+ }
return myFaceNodeIndices;
}
return true;
}
+//================================================================================
+/*!
+ * \brief Return barycenter of a face
+ */
+//================================================================================
+
+bool SMDS_VolumeTool::GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z)
+{
+ if ( !setFace( faceIndex ))
+ return false;
+
+ X = Y = Z = 0.0;
+ for ( int i = 0; i < myFaceNbNodes; ++i )
+ {
+ X += myFaceNodes[i]->X() / myFaceNbNodes;
+ Y += myFaceNodes[i]->Y() / myFaceNbNodes;
+ Z += myFaceNodes[i]->Z() / myFaceNbNodes;
+ }
+ return true;
+}
+
//=======================================================================
//function : GetFaceArea
//purpose : Return face area
//=======================================================================
//function : IsLinked
//purpose : return true if theNode1 is linked with theNode2
+// If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
//=======================================================================
bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
- const SMDS_MeshNode* theNode2) const
+ const SMDS_MeshNode* theNode2,
+ const bool theIgnoreMediumNodes) const
{
if ( !myVolume )
return false;
//function : IsLinked
//purpose : return true if the node with theNode1Index is linked
// with the node with theNode2Index
+// If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
//=======================================================================
bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
- const int theNode2Index) const
+ const int theNode2Index,
+ bool theIgnoreMediumNodes) const
{
if ( myVolume->IsPoly() ) {
return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
}
- int minInd = theNode1Index < theNode2Index ? theNode1Index : theNode2Index;
- int maxInd = theNode1Index < theNode2Index ? theNode2Index : theNode1Index;
+ int minInd = min( theNode1Index, theNode2Index );
+ int maxInd = max( theNode1Index, theNode2Index );
if ( minInd < 0 || maxInd > myVolumeNbNodes - 1 || maxInd == minInd )
return false;
- switch ( myVolumeNbNodes ) {
- case 4:
+ SMDSAbs_EntityType type = myVolume->GetEntityType();
+ if ( myVolume->IsQuadratic() )
+ {
+ int firstMediumInd = myVolume->NbCornerNodes();
+ if ( minInd >= firstMediumInd )
+ return false; // medium nodes are not linked
+ if ( maxInd < firstMediumInd ) // both nodes are corners
+ if ( theIgnoreMediumNodes )
+ type = SMDSAbs_EntityType( int(type)-1 ); // check linkage of corner nodes
+ else
+ return false; // corner nodes are not linked directly in a quadratic cell
+ }
+
+ switch ( type ) {
+ case SMDSEntity_Tetra:
return true;
- case 5:
+ case SMDSEntity_Hexa:
+ switch ( maxInd - minInd ) {
+ case 1: return minInd != 3;
+ case 3: return minInd == 0 || minInd == 4;
+ case 4: return true;
+ default:;
+ }
+ break;
+ case SMDSEntity_Pyramid:
if ( maxInd == 4 )
return true;
switch ( maxInd - minInd ) {
default:;
}
break;
- case 6:
+ case SMDSEntity_Penta:
switch ( maxInd - minInd ) {
case 1: return minInd != 2;
case 2: return minInd == 0 || minInd == 3;
default:;
}
break;
- case 8:
- switch ( maxInd - minInd ) {
- case 1: return minInd != 3;
- case 3: return minInd == 0 || minInd == 4;
- case 4: return true;
- default:;
- }
- break;
- case 10:
+ case SMDSEntity_Quad_Tetra:
{
switch ( minInd ) {
case 0: if( maxInd==4 || maxInd==6 || maxInd==7 ) return true;
}
break;
}
- case 13:
+ case SMDSEntity_Quad_Hexa:
+ {
+ switch ( minInd ) {
+ case 0: if( maxInd==8 || maxInd==11 || maxInd==16 ) return true;
+ case 1: if( maxInd==8 || maxInd==9 || maxInd==17 ) return true;
+ case 2: if( maxInd==9 || maxInd==10 || maxInd==18 ) return true;
+ case 3: if( maxInd==10 || maxInd==11 || maxInd==19 ) return true;
+ case 4: if( maxInd==12 || maxInd==15 || maxInd==16 ) return true;
+ case 5: if( maxInd==12 || maxInd==13 || maxInd==17 ) return true;
+ case 6: if( maxInd==13 || maxInd==14 || maxInd==18 ) return true;
+ case 7: if( maxInd==14 || maxInd==15 || maxInd==19 ) return true;
+ default:;
+ }
+ break;
+ }
+ case SMDSEntity_Quad_Pyramid:
{
switch ( minInd ) {
case 0: if( maxInd==5 || maxInd==8 || maxInd==9 ) return true;
}
break;
}
- case 15:
+ case SMDSEntity_Quad_Penta:
{
switch ( minInd ) {
case 0: if( maxInd==6 || maxInd==8 || maxInd==12 ) return true;
}
break;
}
- case 20:
- {
- switch ( minInd ) {
- case 0: if( maxInd==8 || maxInd==11 || maxInd==16 ) return true;
- case 1: if( maxInd==8 || maxInd==9 || maxInd==17 ) return true;
- case 2: if( maxInd==9 || maxInd==10 || maxInd==18 ) return true;
- case 3: if( maxInd==10 || maxInd==11 || maxInd==19 ) return true;
- case 4: if( maxInd==12 || maxInd==15 || maxInd==16 ) return true;
- case 5: if( maxInd==12 || maxInd==13 || maxInd==17 ) return true;
- case 6: if( maxInd==13 || maxInd==14 || maxInd==18 ) return true;
- case 7: if( maxInd==14 || maxInd==15 || maxInd==19 ) return true;
- default:;
- }
- break;
- }
default:;
}
return false;
return -1;
}
+//================================================================================
+/*!
+ * \brief Fill vector with boundary faces existing in the mesh
+ * \param faces - vector of found nodes
+ * \retval int - nb of found faces
+ */
+//================================================================================
+
+int SMDS_VolumeTool::GetAllExistingFaces(vector<const SMDS_MeshElement*> & faces)
+{
+ faces.clear();
+ faces.reserve( NbFaces() );
+ for ( int iF = 0; iF < NbFaces(); ++iF ) {
+ const SMDS_MeshFace* face = 0;
+ const SMDS_MeshNode** nodes = GetFaceNodes( iF );
+ switch ( NbFaceNodes( iF )) {
+ case 3:
+ face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2] ); break;
+ case 4:
+ face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break;
+ case 6:
+ face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2],
+ nodes[3], nodes[4], nodes[5]); break;
+ case 8:
+ face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3],
+ nodes[4], nodes[5], nodes[6], nodes[7]); break;
+ }
+ if ( face )
+ faces.push_back( face );
+ }
+ return faces.size();
+}
+
+
+//================================================================================
+/*!
+ * \brief Fill vector with boundary edges existing in the mesh
+ * \param edges - vector of found edges
+ * \retval int - nb of found faces
+ */
+//================================================================================
+
+int SMDS_VolumeTool::GetAllExistingEdges(vector<const SMDS_MeshElement*> & edges) const
+{
+ edges.clear();
+ edges.reserve( myVolumeNbNodes * 2 );
+ for ( int i = 0; i < myVolumeNbNodes; ++i ) {
+ for ( int j = i + 1; j < myVolumeNbNodes; ++j ) {
+ if ( IsLinked( i, j )) {
+ const SMDS_MeshElement* edge =
+ SMDS_Mesh::FindEdge( myVolumeNodes[i], myVolumeNodes[j] );
+ if ( edge )
+ edges.push_back( edge );
+ }
+ }
+ }
+ return edges.size();
+}
+
//=======================================================================
//function : IsFreeFace
//purpose : check that only one volume is build on the face nodes
continue; // opposite side
}
// remove a volume from volNbShared map
- volNbShared.erase( vNbIt );
+ volNbShared.erase( vNbIt-- );
}
// here volNbShared contains only volumes laying on the
}
}
+//================================================================================
+/*!
+ * \brief Useful to know nb of corner nodes of a quadratic volume
+ * \param type - volume type
+ * \retval int - nb of corner nodes
+ */
+//================================================================================
+
+int SMDS_VolumeTool::NbCornerNodes(VolumeType type)
+{
+ switch ( type ) {
+ case TETRA :
+ case QUAD_TETRA: return 4;
+ case PYRAM :
+ case QUAD_PYRAM: return 5;
+ case PENTA :
+ case QUAD_PENTA: return 6;
+ case HEXA :
+ case QUAD_HEXA : return 8;
+ default: return 0;
+ }
+ return 0;
+}
+ //
+
//=======================================================================
//function : GetFaceNodesIndices
//purpose : Return the array of face nodes indices
return 0;
}
+//=======================================================================
+//function : Get
+//purpose : return element
+//=======================================================================
+
+const SMDS_MeshVolume* SMDS_VolumeTool::Element() const
+{
+ return static_cast<const SMDS_MeshVolume*>( myVolume );
+}
+
+//=======================================================================
+//function : ID
+//purpose : return element ID
+//=======================================================================
+
+int SMDS_VolumeTool::ID() const
+{
+ return myVolume ? myVolume->GetID() : 0;
+}