1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH OBJECT : interactive object for SMESH visualization
24 // File : SMESH_Grid.cxx
25 // Author : Nicolas REJNERI
28 #include "SMESH_ObjectDef.h"
29 #include "SMESH_ActorUtils.h"
31 #include "SMDS_Mesh.hxx"
32 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
33 #include "SMESH_Actor.h"
34 #include "SMESH_ControlsDef.hxx"
35 #include "SalomeApp_Application.h"
36 #include "VTKViewer_ExtractUnstructuredGrid.h"
37 #include "VTKViewer_CellLocationsArray.h"
39 #include CORBA_SERVER_HEADER(SMESH_Gen)
40 #include CORBA_SERVER_HEADER(SALOME_Exception)
43 #include <vtkIdList.h>
44 #include <vtkCellArray.h>
45 #include <vtkUnsignedCharArray.h>
47 #include <vtkUnstructuredGrid.h>
54 #include "utilities.h"
59 #define EXCEPTION(TYPE, MSG) {\
60 std::ostringstream aStream;\
61 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
62 throw TYPE(aStream.str());\
67 static int MYDEBUG = 1;
68 static int MYDEBUGWITHFILES = 0;//1;
70 static int MYDEBUG = 0;
71 static int MYDEBUGWITHFILES = 0;
76 Class : SMESH_VisualObjDef
77 Description : Base class for all mesh objects to be visuilised
80 //=================================================================================
81 // function : getCellType
82 // purpose : Get type of VTK cell
83 //=================================================================================
84 static inline vtkIdType getCellType( const SMDSAbs_ElementType theType,
86 const int theNbNodes )
90 case SMDSAbs_0DElement:
94 if( theNbNodes == 2 ) return VTK_LINE;
95 else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE;
96 else return VTK_EMPTY_CELL;
99 if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
100 else if ( theNbNodes == 3 ) return VTK_TRIANGLE;
101 else if ( theNbNodes == 4 ) return VTK_QUAD;
102 else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE;
103 else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD;
104 else return VTK_EMPTY_CELL;
107 if (thePoly && theNbNodes>3 ) return VTK_POLYHEDRON; //VTK_CONVEX_POINT_SET;
108 else if ( theNbNodes == 4 ) return VTK_TETRA;
109 else if ( theNbNodes == 5 ) return VTK_PYRAMID;
110 else if ( theNbNodes == 6 ) return VTK_WEDGE;
111 else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON;
112 else if ( theNbNodes == 10 ) {
113 return VTK_QUADRATIC_TETRA;
115 else if ( theNbNodes == 20 ) {
116 return VTK_QUADRATIC_HEXAHEDRON;
118 else if ( theNbNodes == 15 ) {
119 return VTK_QUADRATIC_WEDGE;
121 else if ( theNbNodes==13 ) {
122 return VTK_QUADRATIC_PYRAMID; //VTK_CONVEX_POINT_SET;
124 else return VTK_EMPTY_CELL;
126 default: return VTK_EMPTY_CELL;
130 //=================================================================================
131 // functions : SMESH_VisualObjDef
132 // purpose : Constructor
133 //=================================================================================
134 SMESH_VisualObjDef::SMESH_VisualObjDef()
136 MESSAGE("---------------------------------------------SMESH_VisualObjDef::SMESH_VisualObjDef");
137 myGrid = vtkUnstructuredGrid::New();
140 SMESH_VisualObjDef::~SMESH_VisualObjDef()
142 MESSAGE("---------------------------------------------SMESH_VisualObjDef::~SMESH_VisualObjDef");
144 MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
148 //=================================================================================
149 // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId
150 // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa
151 //=================================================================================
152 vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
156 TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID);
157 return i == myVTK2SMDSNodes.end() ? -1 : i->second;
159 return this->GetMesh()->FindNodeVtk(theVTKID)->GetID();
162 vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
166 TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID);
167 return i == mySMDS2VTKNodes.end() ? -1 : i->second;
170 const SMDS_MeshNode* aNode = 0;
171 if( this->GetMesh() ) {
172 aNode = this->GetMesh()->FindNode(theObjID);
174 return aNode ? aNode->getVtkId() : -1;
177 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
181 TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID);
182 return i == myVTK2SMDSElems.end() ? -1 : i->second;
184 return this->GetMesh()->fromVtkToSmds(theVTKID);
187 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
191 TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID);
192 return i == mySMDS2VTKElems.end() ? -1 : i->second;
194 return this->GetMesh()->FindElement(theObjID)->getVtkId();
195 //return this->GetMesh()->fromSmdsToVtk(theObjID);
198 //=================================================================================
199 // function : SMESH_VisualObjDef::createPoints
200 // purpose : Create points from nodes
201 //=================================================================================
202 /*! fills a vtkPoints structure for a submesh.
203 * fills a std::list of SMDS_MeshElements*, then extract the points.
204 * fills also conversion id maps between SMDS and VTK.
206 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
208 if ( thePoints == 0 )
212 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
213 thePoints->SetNumberOfPoints( nbNodes );
217 TEntityList::const_iterator anIter;
218 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
220 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
223 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
224 int anId = aNode->GetID();
225 mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
226 myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
231 if ( nbPoints != nbNodes )
232 thePoints->SetNumberOfPoints( nbPoints );
235 //=================================================================================
236 // function : buildPrs
237 // purpose : create VTK cells( fill unstructured grid )
238 //=================================================================================
239 void SMESH_VisualObjDef::buildPrs(bool buildGrid)
241 MESSAGE("----------------------------------------------------------SMESH_VisualObjDef::buildPrs " << buildGrid);
247 mySMDS2VTKNodes.clear();
248 myVTK2SMDSNodes.clear();
249 mySMDS2VTKElems.clear();
250 myVTK2SMDSElems.clear();
259 mySMDS2VTKNodes.clear();
260 myVTK2SMDSNodes.clear();
261 mySMDS2VTKElems.clear();
262 myVTK2SMDSElems.clear();
264 myGrid->SetPoints( 0 );
265 myGrid->SetCells( 0, 0, 0, 0, 0 );
272 if (!GetMesh()->isCompacted())
274 MESSAGE("*** buildPrs ==> compactMesh!");
275 GetMesh()->compactMesh();
277 vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
278 myGrid->ShallowCopy(theGrid);
279 //MESSAGE(myGrid->GetReferenceCount());
280 //MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
281 //MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints() );
282 if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"buildPrs.vtu" );
286 //=================================================================================
287 // function : buildNodePrs
288 // purpose : create VTK cells for nodes
289 //=================================================================================
291 void SMESH_VisualObjDef::buildNodePrs()
293 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
294 // so check remaining memory size for safety
295 SMDS_Mesh::CheckMemory(); // PAL16631
296 vtkPoints* aPoints = vtkPoints::New();
297 createPoints( aPoints );
298 SMDS_Mesh::CheckMemory();
299 myGrid->SetPoints( aPoints );
302 myGrid->SetCells( 0, 0, 0, 0, 0 );
305 //=================================================================================
306 // function : buildElemPrs
307 // purpose : Create VTK cells for elements
308 //=================================================================================
311 typedef std::vector<const SMDS_MeshElement*> TConnect;
313 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
314 TConnect& theConnect)
317 for(; theNodesIter->more();)
318 theConnect.push_back(theNodesIter->next());
319 return theConnect.size();
323 void SetId(vtkIdList *theIdList,
324 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
325 const TConnect& theConnect,
329 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
335 void SMESH_VisualObjDef::buildElemPrs()
339 vtkPoints* aPoints = vtkPoints::New();
340 createPoints( aPoints );
341 myGrid->SetPoints( aPoints );
345 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
347 // Calculate cells size
349 static SMDSAbs_ElementType aTypes[ 4 ] =
350 { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
353 map<SMDSAbs_ElementType,int> nbEnts;
354 map<SMDSAbs_ElementType,TEntityList> anEnts;
356 for ( int i = 0; i <= 3; i++ )
357 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
359 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
360 // so check remaining memory size for safety
361 SMDS_Mesh::CheckMemory(); // PAL16631
363 vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
365 for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes
367 if ( nbEnts[ aTypes[ i ] ] )
369 const TEntityList& aList = anEnts[ aTypes[ i ] ];
370 TEntityList::const_iterator anIter;
371 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter ) {
372 if((*anIter)->GetEntityType() != SMDSEntity_Polyhedra &&
373 (*anIter)->GetEntityType() != SMDSEntity_Quad_Polyhedra) {
374 aCellsSize += (*anIter)->NbNodes() + 1;
376 // Special case for the VTK_POLYHEDRON:
377 // itsinput cellArray is of special format.
378 // [nCellFaces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...]
380 if( const SMDS_VtkVolume* ph = dynamic_cast<const SMDS_VtkVolume*>(*anIter) ) {
381 int nbFaces = ph->NbFaces();
382 aCellsSize += (1 + ph->NbFaces());
383 for( int i = 1; i <= nbFaces; i++ ) {
384 aCellsSize += ph->NbFaceNodes(i);
392 vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] +
393 nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
396 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
400 vtkCellArray* aConnectivity = vtkCellArray::New();
401 aConnectivity->Allocate( aCellsSize, 0 );
403 SMDS_Mesh::CheckMemory(); // PAL16631
405 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
406 aCellTypesArray->SetNumberOfComponents( 1 );
407 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
409 SMDS_Mesh::CheckMemory(); // PAL16631
411 vtkIdList *anIdList = vtkIdList::New();
415 aConnect.reserve(VTK_CELL_SIZE);
417 SMDS_Mesh::CheckMemory(); // PAL16631
419 for ( int i = 0; i <= 3; i++ ) // iterate through 0d elements, edges, faces and volumes
421 if ( nbEnts[ aTypes[ i ] ] > 0 ) {
423 const SMDSAbs_ElementType& aType = aTypes[ i ];
424 const TEntityList& aList = anEnts[ aType ];
425 TEntityList::const_iterator anIter;
426 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
428 const SMDS_MeshElement* anElem = *anIter;
430 vtkIdType aNbNodes = anElem->NbNodes();
431 anIdList->SetNumberOfIds( aNbNodes );
433 int anId = anElem->GetID();
435 mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
436 myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
438 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
440 case SMDSAbs_Volume: {
442 std::vector<int> aConnectivities;
443 // Convertions connectivities from SMDS to VTK
445 if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
447 if ( const SMDS_VtkVolume* ph = dynamic_cast<const SMDS_VtkVolume*>(anElem) ) {
448 int nbFaces = ph->NbFaces();
449 anIdList->InsertNextId(nbFaces);
450 for( int i = 1; i <= nbFaces; i++ ) {
451 anIdList->InsertNextId(ph->NbFaceNodes(i));
452 for(int j = 1; j <= ph->NbFaceNodes(i); j++) {
453 const SMDS_MeshNode* n = ph->GetFaceNode(i,j);
455 anIdList->InsertNextId(mySMDS2VTKNodes[n->GetID()]);
461 } else if (aNbNodes == 4) {
462 static int anIds[] = {0,2,1,3};
463 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
465 } else if (aNbNodes == 5) {
466 static int anIds[] = {0,3,2,1,4};
467 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
469 } else if (aNbNodes == 6) {
470 static int anIds[] = {0,1,2,3,4,5};
471 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
474 else if (aNbNodes == 8) {
475 static int anIds[] = {0,3,2,1,4,7,6,5};
476 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
479 else if (aNbNodes == 10) {
480 static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
481 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
483 else if (aNbNodes == 13) {
484 static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
485 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
487 else if (aNbNodes == 15) {
488 //static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
489 static int anIds[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
490 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
491 //for (int k = 0; k < aNbNodes; k++) {
492 // int nn = aConnectivities[k];
493 // const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
494 // cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
497 else if (aNbNodes == 20) {
498 static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
499 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
504 if (!(anElem->IsPoly() && aNbNodes > 3)) {
505 if ( aConnect.empty() )
506 GetConnect(aNodesIter,aConnect);
508 if (aConnectivities.size() > 0) {
509 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
510 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
516 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
517 const SMDS_MeshElement* aNode = aNodesIter->next();
518 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
523 aConnectivity->InsertNextCell( anIdList );
524 aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
529 SMDS_Mesh::CheckMemory(); // PAL16631
532 // Insert cells in grid
534 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
535 aCellLocationsArray->SetNumberOfComponents( 1 );
536 aCellLocationsArray->SetNumberOfTuples( aNbCells );
538 SMDS_Mesh::CheckMemory(); // PAL16631
540 aConnectivity->InitTraversal();
541 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
542 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
544 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
546 aCellLocationsArray->Delete();
547 aCellTypesArray->Delete();
548 aConnectivity->Delete();
551 SMDS_Mesh::CheckMemory(); // PAL16631
554 //=================================================================================
555 // function : GetEdgeNodes
556 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
557 //=================================================================================
558 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
559 const int theEdgeNum,
561 int& theNodeId2 ) const
563 const SMDS_Mesh* aMesh = GetMesh();
567 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
571 int nbNodes = anElem->NbNodes();
573 if ( theEdgeNum < 0 || theEdgeNum > 3 || (nbNodes != 3 && nbNodes != 4) || theEdgeNum > nbNodes )
576 vector<int> anIds( nbNodes );
577 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
579 while( anIter->more() )
580 anIds[ i++ ] = anIter->next()->GetID();
582 if ( theEdgeNum < nbNodes - 1 )
584 theNodeId1 = anIds[ theEdgeNum ];
585 theNodeId2 = anIds[ theEdgeNum + 1 ];
589 theNodeId1 = anIds[ nbNodes - 1 ];
590 theNodeId2 = anIds[ 0 ];
596 vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid()
598 if ( !myLocalGrid && !GetMesh()->isCompacted() )
600 GetMesh()->compactMesh();
601 vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
602 myGrid->ShallowCopy(theGrid);
608 //=================================================================================
609 // function : IsValid
610 // purpose : Return true if there are some entities
611 //=================================================================================
612 bool SMESH_VisualObjDef::IsValid() const
614 //MESSAGE("SMESH_VisualObjDef::IsValid");
615 return GetNbEntities(SMDSAbs_Node) > 0 ||
616 GetNbEntities(SMDSAbs_0DElement) > 0 ||
617 GetNbEntities(SMDSAbs_Edge) > 0 ||
618 GetNbEntities(SMDSAbs_Face) > 0 ||
619 GetNbEntities(SMDSAbs_Volume) > 0 ;
623 Class : SMESH_MeshObj
624 Description : Class for visualisation of mesh
627 //=================================================================================
628 // function : SMESH_MeshObj
629 // purpose : Constructor
630 //=================================================================================
631 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
632 myClient(SalomeApp_Application::orb(),theMesh)
636 MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
639 //=================================================================================
640 // function : ~SMESH_MeshObj
641 // purpose : Destructor
642 //=================================================================================
643 SMESH_MeshObj::~SMESH_MeshObj()
646 MESSAGE("SMESH_MeshObj - this = "<<this<<"\n");
649 //=================================================================================
651 // purpose : Update mesh and fill grid with new values if necessary
652 //=================================================================================
653 bool SMESH_MeshObj::Update( int theIsClear )
655 // Update SMDS_Mesh on client part
656 MESSAGE("SMESH_MeshObj::Update " << this);
657 if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) {
659 buildPrs(); // Fill unstructured grid
665 bool SMESH_MeshObj::NulData()
667 MESSAGE ("SMESH_MeshObj::NulData() ==================================================================================");
670 myEmptyGrid = SMDS_UnstructuredGrid::New();
671 myEmptyGrid->Initialize();
672 myEmptyGrid->Allocate();
673 vtkPoints* points = vtkPoints::New();
674 points->SetNumberOfPoints(0);
675 myEmptyGrid->SetPoints( points );
677 myEmptyGrid->BuildLinks();
679 myGrid->ShallowCopy(myEmptyGrid);
682 //=================================================================================
683 // function : GetElemDimension
684 // purpose : Get dimension of element
685 //=================================================================================
686 int SMESH_MeshObj::GetElemDimension( const int theObjId )
688 const SMDS_MeshElement* anElem = myClient->FindElement( theObjId );
692 int aType = anElem->GetType();
695 case SMDSAbs_0DElement : return 0;
696 case SMDSAbs_Edge : return 1;
697 case SMDSAbs_Face : return 2;
698 case SMDSAbs_Volume: return 3;
703 //=================================================================================
704 // function : GetEntities
705 // purpose : Get entities of specified type. Return number of entities
706 //=================================================================================
707 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
713 return myClient->NbNodes();
716 case SMDSAbs_0DElement:
718 return myClient->Nb0DElements();
723 return myClient->NbEdges();
728 return myClient->NbFaces();
733 return myClient->NbVolumes();
742 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
750 SMDS_NodeIteratorPtr anIter = myClient->nodesIterator();
751 while ( anIter->more() ) theObjs.push_back( anIter->next() );
754 case SMDSAbs_0DElement:
756 SMDS_0DElementIteratorPtr anIter = myClient->elements0dIterator();
757 while ( anIter->more() ) theObjs.push_back( anIter->next() );
762 SMDS_EdgeIteratorPtr anIter = myClient->edgesIterator();
763 while ( anIter->more() ) theObjs.push_back( anIter->next() );
768 SMDS_FaceIteratorPtr anIter = myClient->facesIterator();
769 while ( anIter->more() ) theObjs.push_back( anIter->next() );
774 SMDS_VolumeIteratorPtr anIter = myClient->volumesIterator();
775 while ( anIter->more() ) theObjs.push_back( anIter->next() );
782 return theObjs.size();
785 //=================================================================================
786 // function : UpdateFunctor
787 // purpose : Update functor in accordance with current mesh
788 //=================================================================================
789 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
791 theFunctor->SetMesh( GetMesh() );
794 //=================================================================================
795 // function : IsNodePrs
796 // purpose : Return true if node presentation is used
797 //=================================================================================
798 bool SMESH_MeshObj::IsNodePrs() const
800 return myClient->Nb0DElements() == 0 && myClient->NbEdges() == 0 && myClient->NbFaces() == 0 && myClient->NbVolumes() == 0 ;
805 Class : SMESH_SubMeshObj
806 Description : Base class for visualisation of submeshes and groups
809 //=================================================================================
810 // function : SMESH_SubMeshObj
811 // purpose : Constructor
812 //=================================================================================
813 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
815 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
817 myMeshObj = theMeshObj;
820 SMESH_SubMeshObj::~SMESH_SubMeshObj()
824 //=================================================================================
825 // function : GetElemDimension
826 // purpose : Get dimension of element
827 //=================================================================================
828 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
830 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
833 //=================================================================================
834 // function : UpdateFunctor
835 // purpose : Update functor in accordance with current mesh
836 //=================================================================================
837 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
839 theFunctor->SetMesh( myMeshObj->GetMesh() );
842 //=================================================================================
844 // purpose : Update mesh object and fill grid with new values
845 //=================================================================================
846 bool SMESH_SubMeshObj::Update( int theIsClear )
848 MESSAGE("SMESH_SubMeshObj::Update " << this)
849 bool changed = myMeshObj->Update( theIsClear );
856 Class : SMESH_GroupObj
857 Description : Class for visualisation of groups
860 //=================================================================================
861 // function : SMESH_GroupObj
862 // purpose : Constructor
863 //=================================================================================
864 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
865 SMESH_MeshObj* theMeshObj )
866 : SMESH_SubMeshObj( theMeshObj ),
867 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
869 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
870 myGroupServer->Register();
873 SMESH_GroupObj::~SMESH_GroupObj()
875 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
876 myGroupServer->UnRegister();
879 //=================================================================================
880 // function : IsNodePrs
881 // purpose : Return true if node presentation is used
882 //=================================================================================
883 bool SMESH_GroupObj::IsNodePrs() const
885 return myGroupServer->GetType() == SMESH::NODE;
888 //=================================================================================
889 // function : GetElementType
890 // purpose : Return type of elements of group
891 //=================================================================================
892 SMDSAbs_ElementType SMESH_GroupObj::GetElementType() const
894 return SMDSAbs_ElementType(myGroupServer->GetType());
897 //=================================================================================
898 // function : getNodesFromElems
899 // purpose : Retrieve nodes from elements
900 //=================================================================================
901 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
902 const SMDS_Mesh* theMesh,
903 std::list<const SMDS_MeshElement*>& theResList )
905 set<const SMDS_MeshElement*> aNodeSet;
907 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
909 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
912 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
913 while ( anIter->more() )
915 const SMDS_MeshElement* aNode = anIter->next();
917 aNodeSet.insert( aNode );
922 set<const SMDS_MeshElement*>::const_iterator anIter;
923 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
924 theResList.push_back( *anIter );
926 return theResList.size();
929 //=================================================================================
930 // function : getPointers
931 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
932 //=================================================================================
933 static int getPointers( const SMDSAbs_ElementType theRequestType,
934 SMESH::long_array_var& theElemIds,
935 const SMDS_Mesh* theMesh,
936 std::list<const SMDS_MeshElement*>& theResList )
938 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
940 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
941 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
944 theResList.push_back( anElem );
947 return theResList.size();
951 //=================================================================================
952 // function : GetEntities
953 // purpose : Get entities of specified type. Return number of entities
954 //=================================================================================
955 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
957 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType){
958 return myGroupServer->Size();
963 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
966 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
968 if ( myGroupServer->Size() == 0 || aMesh == 0 )
971 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
972 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
974 if ( aGrpType == theType )
975 return getPointers( theType, anIds, aMesh, theResList );
976 else if ( theType == SMDSAbs_Node )
977 return getNodesFromElems( anIds, aMesh, theResList );
985 Class : SMESH_subMeshObj
986 Description : Class for visualisation of submeshes
989 //=================================================================================
990 // function : SMESH_subMeshObj
991 // purpose : Constructor
992 //=================================================================================
993 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
994 SMESH_MeshObj* theMeshObj )
995 : SMESH_SubMeshObj( theMeshObj ),
996 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
998 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
1000 mySubMeshServer->Register();
1003 SMESH_subMeshObj::~SMESH_subMeshObj()
1005 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
1006 mySubMeshServer->UnRegister();
1009 //=================================================================================
1010 // function : GetEntities
1011 // purpose : Get entities of specified type. Return number of entities
1012 //=================================================================================
1013 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
1019 return mySubMeshServer->GetNumberOfNodes( false );
1022 case SMDSAbs_0DElement:
1025 case SMDSAbs_Volume:
1027 SMESH::long_array_var anIds =
1028 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1029 return anIds->length();
1037 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
1041 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
1045 bool isNodal = IsNodePrs();
1049 if ( theType == SMDSAbs_Node )
1051 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
1052 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
1057 if ( theType == SMDSAbs_Node )
1059 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
1060 return getNodesFromElems( anIds, aMesh, theResList );
1064 SMESH::long_array_var anIds =
1065 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1066 return getPointers( theType, anIds, aMesh, theResList );
1073 //=================================================================================
1074 // function : IsNodePrs
1075 // purpose : Return true if node presentation is used
1076 //=================================================================================
1077 bool SMESH_subMeshObj::IsNodePrs() const
1079 return mySubMeshServer->GetNumberOfElements() == 0;