-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// This library is 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// SMESH SMESH : implementaion of SMESH idl descriptions
// File : StdMeshers_QuadToTriaAdaptor.cxx
// Module : SMESH
// Created : Wen May 07 16:37:07 2008
// Author : Sergey KUUL (skl)
-//
+
#include "StdMeshers_QuadToTriaAdaptor.hxx"
#include "SMDS_SetIterator.hxx"
// Check angle between normals
double angle = nI.Angle( nJ );
- bool tooClose = ( angle < 15 * PI180 );
+ bool tooClose = ( angle < 15. * M_PI / 180. );
// Check if pyramids collide
if ( !tooClose && baI * baJ > 0 )
return tooClose;
}
+
+ //================================================================================
+ /*!
+ * \brief Move medium nodes of merged quadratic pyramids
+ */
+ //================================================================================
+
+ void UpdateQuadraticPyramids(const set<const SMDS_MeshNode*>& commonApex,
+ SMESHDS_Mesh* meshDS)
+ {
+ typedef SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > TStdElemIterator;
+ TStdElemIterator itEnd;
+
+ // shift of node index to get medium nodes between the 4 base nodes and the apex
+ const int base2MediumShift = 9;
+
+ set<const SMDS_MeshNode*>::const_iterator nIt = commonApex.begin();
+ for ( ; nIt != commonApex.end(); ++nIt )
+ {
+ SMESH_TNodeXYZ apex( *nIt );
+
+ vector< const SMDS_MeshElement* > pyrams // pyramids sharing the apex node
+ ( TStdElemIterator( apex._node->GetInverseElementIterator( SMDSAbs_Volume )), itEnd );
+
+ // Select medium nodes to keep and medium nodes to remove
+
+ typedef map < const SMDS_MeshNode*, const SMDS_MeshNode*, TIDCompare > TN2NMap;
+ TN2NMap base2medium; // to keep
+ vector< const SMDS_MeshNode* > nodesToRemove;
+
+ for ( unsigned i = 0; i < pyrams.size(); ++i )
+ for ( int baseIndex = 0; baseIndex < PYRAM_APEX; ++baseIndex )
+ {
+ SMESH_TNodeXYZ base = pyrams[i]->GetNode( baseIndex );
+ const SMDS_MeshNode* medium = pyrams[i]->GetNode( baseIndex + base2MediumShift );
+ TN2NMap::iterator b2m = base2medium.insert( make_pair( base._node, medium )).first;
+ if ( b2m->second != medium )
+ {
+ nodesToRemove.push_back( medium );
+ }
+ else
+ {
+ // move the kept medium node
+ gp_XYZ newXYZ = 0.5 * ( apex + base );
+ meshDS->MoveNode( medium, newXYZ.X(), newXYZ.Y(), newXYZ.Z() );
+ }
+ }
+
+ // Within pyramids, replace nodes to remove by nodes to keep
+
+ for ( unsigned i = 0; i < pyrams.size(); ++i )
+ {
+ vector< const SMDS_MeshNode* > nodes( pyrams[i]->begin_nodes(),
+ pyrams[i]->end_nodes() );
+ for ( int baseIndex = 0; baseIndex < PYRAM_APEX; ++baseIndex )
+ {
+ const SMDS_MeshNode* base = pyrams[i]->GetNode( baseIndex );
+ nodes[ baseIndex + base2MediumShift ] = base2medium[ base ];
+ }
+ meshDS->ChangeElementNodes( pyrams[i], &nodes[0], nodes.size());
+ }
+
+ // Remove the replaced nodes
+
+ if ( !nodesToRemove.empty() )
+ {
+ SMESHDS_SubMesh * sm = meshDS->MeshElements( nodesToRemove[0]->getshapeId() );
+ for ( unsigned i = 0; i < nodesToRemove.size(); ++i )
+ meshDS->RemoveFreeNode( nodesToRemove[i], sm, /*fromGroups=*/false);
+ }
+ }
+ }
+
}
//================================================================================
SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
int i, j, k, myShapeID = myPyramids[0]->GetNode(4)->getshapeId();
- if ( !myElemSearcher )
- myElemSearcher = SMESH_MeshEditor(&aMesh).GetElementSearcher();
+ if ( myElemSearcher ) delete myElemSearcher;
+ myElemSearcher = SMESH_MeshEditor(&aMesh).GetElementSearcher();
SMESH_ElementSearcher* searcher = const_cast<SMESH_ElementSearcher*>(myElemSearcher);
set<const SMDS_MeshNode*> nodesToMove;
vector<gp_Pnt> PsJ( xyzIt, TXyzIterator() );
gp_Pnt Pint;
- bool hasInt;
+ bool hasInt=false;
for(k=0; k<4 && !hasInt; k++) {
gp_Vec Vtmp(PsI[k],PsI[4]);
gp_Pnt Pshift = PsI[k].XYZ() + Vtmp.XYZ() * 0.01; // base node moved a bit to apex
gp_Vec VI2(PCj,Pint);
double ang1 = fabs(VN1.Angle(VI1));
double ang2 = fabs(VN2.Angle(VI2));
- double coef1 = 0.5 - (( ang1<PI/3 ) ? cos(ang1)*0.25 : 0 );
- double coef2 = 0.5 - (( ang2<PI/3 ) ? cos(ang2)*0.25 : 0 ); // cos(ang2) ?
+ double coef1 = 0.5 - (( ang1 < M_PI/3. ) ? cos(ang1)*0.25 : 0 );
+ double coef2 = 0.5 - (( ang2 < M_PI/3. ) ? cos(ang2)*0.25 : 0 ); // cos(ang2) ?
// double coef2 = 0.5;
// if(ang2<PI/3)
// coef2 -= cos(ang1)*0.25;
meshDS->MoveNode( *n, (*n)->X(), (*n)->Y(), (*n)->Z() );
}
+ // move medium nodes of merged quadratic pyramids
+ if ( myPyramids[0]->IsQuadratic() )
+ UpdateQuadraticPyramids( nodesToMove, GetMeshDS() );
+
// erase removed triangles from the proxy mesh
if ( !myRemovedTrias.empty() )
{
return true;
}
-
-//================================================================================
-/*!
- * \brief Return list of created triangles for given face
- */
-//================================================================================
-
-// const list<const SMDS_MeshFace* >* StdMeshers_QuadToTriaAdaptor::GetTriangles (const SMDS_MeshElement* aQuad)
-// {
-// TQuad2Trias::iterator it = myResMap.find(aQuad);
-// return ( it != myResMap.end() ? & it->second : 0 );
-// }