1 // Copyright (C) 2007-2013 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: return VTK_VERTEX;
92 case SMDSAbs_Ball: return VTK_POLY_VERTEX;
95 if( theNbNodes == 2 ) return VTK_LINE;
96 else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE;
97 else return VTK_EMPTY_CELL;
100 if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
101 else if ( theNbNodes == 3 ) return VTK_TRIANGLE;
102 else if ( theNbNodes == 4 ) return VTK_QUAD;
103 else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE;
104 else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD;
105 else if ( theNbNodes == 9 ) return VTK_BIQUADRATIC_QUAD;
106 else return VTK_EMPTY_CELL;
109 if (thePoly && theNbNodes>3 ) return VTK_POLYHEDRON; //VTK_CONVEX_POINT_SET;
110 else if ( theNbNodes == 4 ) return VTK_TETRA;
111 else if ( theNbNodes == 5 ) return VTK_PYRAMID;
112 else if ( theNbNodes == 6 ) return VTK_WEDGE;
113 else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON;
114 else if ( theNbNodes == 12 ) return VTK_HEXAGONAL_PRISM;
115 else if ( theNbNodes == 10 ) return VTK_QUADRATIC_TETRA;
116 else if ( theNbNodes == 20 ) return VTK_QUADRATIC_HEXAHEDRON;
117 else if ( theNbNodes == 27 ) return VTK_TRIQUADRATIC_HEXAHEDRON;
118 else if ( theNbNodes == 15 ) return VTK_QUADRATIC_WEDGE;
119 else if ( theNbNodes == 13 ) return VTK_QUADRATIC_PYRAMID; //VTK_CONVEX_POINT_SET;
120 else return VTK_EMPTY_CELL;
122 default: return VTK_EMPTY_CELL;
126 //=================================================================================
127 // functions : SMESH_VisualObjDef
128 // purpose : Constructor
129 //=================================================================================
130 SMESH_VisualObjDef::SMESH_VisualObjDef()
132 MESSAGE("---------------------------------------------SMESH_VisualObjDef::SMESH_VisualObjDef");
133 myGrid = vtkUnstructuredGrid::New();
135 ClearEntitiesFlags();
136 SMESH::GetEntitiesFromObject(NULL);
138 SMESH_VisualObjDef::~SMESH_VisualObjDef()
140 MESSAGE("---------------------------------------------SMESH_VisualObjDef::~SMESH_VisualObjDef");
142 MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
146 //=================================================================================
147 // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId
148 // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa
149 //=================================================================================
150 vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
154 TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID);
155 return i == myVTK2SMDSNodes.end() ? -1 : i->second;
157 return this->GetMesh()->FindNodeVtk(theVTKID)->GetID();
160 vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
164 TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID);
165 return i == mySMDS2VTKNodes.end() ? -1 : i->second;
168 const SMDS_MeshNode* aNode = 0;
169 if( this->GetMesh() ) {
170 aNode = this->GetMesh()->FindNode(theObjID);
172 return aNode ? aNode->getVtkId() : -1;
175 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
179 TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID);
180 return i == myVTK2SMDSElems.end() ? -1 : i->second;
182 return this->GetMesh()->fromVtkToSmds(theVTKID);
185 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
189 TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID);
190 return i == mySMDS2VTKElems.end() ? -1 : i->second;
192 return this->GetMesh()->FindElement(theObjID)->getVtkId();
193 //return this->GetMesh()->fromSmdsToVtk(theObjID);
196 //=================================================================================
197 // function : SMESH_VisualObjDef::createPoints
198 // purpose : Create points from nodes
199 //=================================================================================
200 /*! fills a vtkPoints structure for a submesh.
201 * fills a std::list of SMDS_MeshElements*, then extract the points.
202 * fills also conversion id maps between SMDS and VTK.
204 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
206 if ( thePoints == 0 )
210 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
211 thePoints->SetNumberOfPoints( nbNodes );
215 TEntityList::const_iterator anIter;
216 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
218 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
221 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
222 int anId = aNode->GetID();
223 mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
224 myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
229 if ( nbPoints != nbNodes )
230 thePoints->SetNumberOfPoints( nbPoints );
233 //=================================================================================
234 // function : buildPrs
235 // purpose : create VTK cells( fill unstructured grid )
236 //=================================================================================
237 void SMESH_VisualObjDef::buildPrs(bool buildGrid)
239 MESSAGE("----------------------------------------------------------SMESH_VisualObjDef::buildPrs " << buildGrid);
245 mySMDS2VTKNodes.clear();
246 myVTK2SMDSNodes.clear();
247 mySMDS2VTKElems.clear();
248 myVTK2SMDSElems.clear();
257 mySMDS2VTKNodes.clear();
258 myVTK2SMDSNodes.clear();
259 mySMDS2VTKElems.clear();
260 myVTK2SMDSElems.clear();
262 myGrid->SetPoints( 0 );
263 myGrid->SetCells( 0, 0, 0, 0, 0 );
270 if (!GetMesh()->isCompacted())
272 MESSAGE("*** buildPrs ==> compactMesh!");
273 GetMesh()->compactMesh();
275 vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
276 updateEntitiesFlags();
277 myGrid->ShallowCopy(theGrid);
278 //MESSAGE(myGrid->GetReferenceCount());
279 //MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
280 //MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints() );
281 if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"buildPrs.vtu" );
285 //=================================================================================
286 // function : buildNodePrs
287 // purpose : create VTK cells for nodes
288 //=================================================================================
290 void SMESH_VisualObjDef::buildNodePrs()
292 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
293 // so check remaining memory size for safety
294 SMDS_Mesh::CheckMemory(); // PAL16631
295 vtkPoints* aPoints = vtkPoints::New();
296 createPoints( aPoints );
297 SMDS_Mesh::CheckMemory();
298 myGrid->SetPoints( aPoints );
301 myGrid->SetCells( 0, 0, 0, 0, 0 );
304 //=================================================================================
305 // function : buildElemPrs
306 // purpose : Create VTK cells for elements
307 //=================================================================================
310 typedef std::vector<const SMDS_MeshElement*> TConnect;
312 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
313 TConnect& theConnect)
316 for(; theNodesIter->more();)
317 theConnect.push_back(theNodesIter->next());
318 return theConnect.size();
322 void SetId(vtkIdList *theIdList,
323 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
324 const TConnect& theConnect,
328 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
334 void SMESH_VisualObjDef::buildElemPrs()
338 vtkPoints* aPoints = vtkPoints::New();
339 createPoints( aPoints );
340 myGrid->SetPoints( aPoints );
344 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
346 // Calculate cells size
348 const int nbTypes = 5;
349 static SMDSAbs_ElementType aTypes[ nbTypes ] =
350 { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume, SMDSAbs_Ball, SMDSAbs_0DElement };
353 map<SMDSAbs_ElementType,int> nbEnts;
354 map<SMDSAbs_ElementType,TEntityList> anEnts;
356 vtkIdType aNbCells = 0;
358 for ( int i = 0; i < nbTypes; i++ )
360 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
361 aNbCells += nbEnts[ aTypes [ i ]];
363 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
364 // so check remaining memory size for safety
365 SMDS_Mesh::CheckMemory(); // PAL16631
367 vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
368 aCellsSize += 2 * nbEnts[ SMDSAbs_Ball ];
370 for ( int i = 1; i <= 2; i++ ) // iterate through faces and volumes
372 if ( nbEnts[ aTypes[ i ] ] )
374 const TEntityList& aList = anEnts[ aTypes[ i ] ];
375 TEntityList::const_iterator anIter;
376 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter ) {
377 if((*anIter)->GetEntityType() != SMDSEntity_Polyhedra &&
378 (*anIter)->GetEntityType() != SMDSEntity_Quad_Polyhedra) {
379 aCellsSize += (*anIter)->NbNodes() + 1;
381 // Special case for the VTK_POLYHEDRON:
382 // itsinput cellArray is of special format.
383 // [nCellFaces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...]
385 if( const SMDS_VtkVolume* ph = dynamic_cast<const SMDS_VtkVolume*>(*anIter) ) {
386 int nbFaces = ph->NbFaces();
387 aCellsSize += (1 + ph->NbFaces());
388 for( int i = 1; i <= nbFaces; i++ ) {
389 aCellsSize += ph->NbFaceNodes(i);
397 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
401 vtkCellArray* aConnectivity = vtkCellArray::New();
402 aConnectivity->Allocate( aCellsSize, 0 );
404 SMDS_Mesh::CheckMemory(); // PAL16631
406 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
407 aCellTypesArray->SetNumberOfComponents( 1 );
408 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
410 SMDS_Mesh::CheckMemory(); // PAL16631
412 vtkIdList *anIdList = vtkIdList::New();
416 aConnect.reserve(VTK_CELL_SIZE);
418 SMDS_Mesh::CheckMemory(); // PAL16631
420 for ( int i = 0; i < nbTypes; i++ ) // iterate through all types of elements
422 if ( nbEnts[ aTypes[ i ] ] > 0 ) {
424 const SMDSAbs_ElementType& aType = aTypes[ i ];
425 const TEntityList& aList = anEnts[ aType ];
426 TEntityList::const_iterator anIter;
427 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
429 const SMDS_MeshElement* anElem = *anIter;
431 vtkIdType aNbNodes = anElem->NbNodes();
432 anIdList->SetNumberOfIds( aNbNodes );
433 const vtkIdType vtkElemType = getCellType( aType, anElem->IsPoly(), aNbNodes );
435 int anId = anElem->GetID();
437 mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
438 myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
440 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
442 // Convertions connectivities from SMDS to VTK
444 if (aType == SMDSAbs_Volume && anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
446 if ( const SMDS_VtkVolume* ph = dynamic_cast<const SMDS_VtkVolume*>(anElem) ) {
447 int nbFaces = ph->NbFaces();
448 anIdList->InsertNextId(nbFaces);
449 for( int i = 1; i <= nbFaces; i++ ) {
450 anIdList->InsertNextId(ph->NbFaceNodes(i));
451 for(int j = 1; j <= ph->NbFaceNodes(i); j++) {
452 const SMDS_MeshNode* n = ph->GetFaceNode(i,j);
454 anIdList->InsertNextId(mySMDS2VTKNodes[n->GetID()]);
461 const std::vector<int>& aConnectivities =
462 SMDS_MeshCell::toVtkOrder( VTKCellType( vtkElemType ));
463 if (aConnectivities.size() > 0) {
465 GetConnect(aNodesIter,aConnect);
466 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
467 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
470 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
471 const SMDS_MeshElement* aNode = aNodesIter->next();
472 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
477 aConnectivity->InsertNextCell( anIdList );
478 aCellTypesArray->InsertNextValue( vtkElemType );
483 SMDS_Mesh::CheckMemory(); // PAL16631
486 // Insert cells in grid
488 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
489 aCellLocationsArray->SetNumberOfComponents( 1 );
490 aCellLocationsArray->SetNumberOfTuples( aNbCells );
492 SMDS_Mesh::CheckMemory(); // PAL16631
494 aConnectivity->InitTraversal();
495 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
496 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
498 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
500 aCellLocationsArray->Delete();
501 aCellTypesArray->Delete();
502 aConnectivity->Delete();
505 SMDS_Mesh::CheckMemory(); // PAL16631
508 //=================================================================================
509 // function : GetEdgeNodes
510 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
511 //=================================================================================
512 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
513 const int theEdgeNum,
515 int& theNodeId2 ) const
517 const SMDS_Mesh* aMesh = GetMesh();
521 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
525 int nbNodes = anElem->NbNodes();
527 if ( theEdgeNum < 0 || theEdgeNum > 3 || (nbNodes != 3 && nbNodes != 4) || theEdgeNum > nbNodes )
530 vector<int> anIds( nbNodes );
531 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
533 while( anIter->more() )
534 anIds[ i++ ] = anIter->next()->GetID();
536 if ( theEdgeNum < nbNodes - 1 )
538 theNodeId1 = anIds[ theEdgeNum ];
539 theNodeId2 = anIds[ theEdgeNum + 1 ];
543 theNodeId1 = anIds[ nbNodes - 1 ];
544 theNodeId2 = anIds[ 0 ];
550 vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid()
552 if ( !myLocalGrid && !GetMesh()->isCompacted() )
554 GetMesh()->compactMesh();
555 updateEntitiesFlags();
556 vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
557 myGrid->ShallowCopy(theGrid);
563 //=================================================================================
564 // function : IsValid
565 // purpose : Return true if there are some entities
566 //=================================================================================
567 bool SMESH_VisualObjDef::IsValid() const
569 //MESSAGE("SMESH_VisualObjDef::IsValid");
570 return ( GetNbEntities(SMDSAbs_0DElement) > 0 ||
571 GetNbEntities(SMDSAbs_Ball ) > 0 ||
572 GetNbEntities(SMDSAbs_Edge ) > 0 ||
573 GetNbEntities(SMDSAbs_Face ) > 0 ||
574 GetNbEntities(SMDSAbs_Volume ) > 0 ||
575 GetNbEntities(SMDSAbs_Node ) > 0 );
578 //=================================================================================
579 // function : updateEntitiesFlags
580 // purpose : Update entities flags
581 //=================================================================================
582 void SMESH_VisualObjDef::updateEntitiesFlags() {
584 unsigned int tmp = myEntitiesState;
585 ClearEntitiesFlags();
587 map<SMDSAbs_ElementType,int> entities = SMESH::GetEntitiesFromObject(this);
590 if( myEntitiesCache[SMDSAbs_0DElement] != 0 || myEntitiesCache[SMDSAbs_0DElement] >= entities[SMDSAbs_0DElement] )
591 myEntitiesState &= ~SMESH_Actor::e0DElements;
593 if( myEntitiesCache[SMDSAbs_Ball] != 0 || myEntitiesCache[SMDSAbs_Ball] >= entities[SMDSAbs_Ball] )
594 myEntitiesState &= ~SMESH_Actor::eBallElem;
596 if( myEntitiesCache[SMDSAbs_Edge] != 0 || myEntitiesCache[SMDSAbs_Edge] >= entities[SMDSAbs_Edge] )
597 myEntitiesState &= ~SMESH_Actor::eEdges;
599 if( myEntitiesCache[SMDSAbs_Face] != 0 || myEntitiesCache[SMDSAbs_Face] >= entities[SMDSAbs_Face] )
600 myEntitiesState &= ~SMESH_Actor::eFaces;
602 if( myEntitiesCache[SMDSAbs_Volume] != 0 || myEntitiesCache[SMDSAbs_Volume] >= entities[SMDSAbs_Volume] )
603 myEntitiesState &= ~SMESH_Actor::eVolumes;
605 if( tmp != myEntitiesState ) {
606 myEntitiesFlag = true;
609 myEntitiesCache = entities;
612 //=================================================================================
613 // function : ClearEntitiesFlags
614 // purpose : Clear the entities flags
615 //=================================================================================
616 void SMESH_VisualObjDef::ClearEntitiesFlags() {
617 myEntitiesState = SMESH_Actor::eAllEntity;
618 myEntitiesFlag = false;
621 //=================================================================================
622 // function : GetEntitiesFlag
623 // purpose : Return the entities flag
624 //=================================================================================
625 bool SMESH_VisualObjDef::GetEntitiesFlag() {
626 return myEntitiesFlag;
629 //=================================================================================
630 // function : GetEntitiesState
631 // purpose : Return the entities state
632 //=================================================================================
633 unsigned int SMESH_VisualObjDef::GetEntitiesState() {
634 return myEntitiesState;
638 Class : SMESH_MeshObj
639 Description : Class for visualisation of mesh
642 //=================================================================================
643 // function : SMESH_MeshObj
644 // purpose : Constructor
645 //=================================================================================
646 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
647 myClient(SalomeApp_Application::orb(),theMesh)
651 MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
654 //=================================================================================
655 // function : ~SMESH_MeshObj
656 // purpose : Destructor
657 //=================================================================================
658 SMESH_MeshObj::~SMESH_MeshObj()
661 MESSAGE("SMESH_MeshObj - this = "<<this<<"\n");
663 myEmptyGrid->Delete();
666 //=================================================================================
668 // purpose : Update mesh and fill grid with new values if necessary
669 //=================================================================================
670 bool SMESH_MeshObj::Update( int theIsClear )
672 // Update SMDS_Mesh on client part
673 MESSAGE("SMESH_MeshObj::Update " << this);
674 if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) {
676 buildPrs(); // Fill unstructured grid
682 bool SMESH_MeshObj::NulData()
684 MESSAGE ("SMESH_MeshObj::NulData() ==================================================================================");
687 myEmptyGrid = SMDS_UnstructuredGrid::New();
688 myEmptyGrid->Initialize();
689 myEmptyGrid->Allocate();
690 vtkPoints* points = vtkPoints::New();
691 points->SetNumberOfPoints(0);
692 myEmptyGrid->SetPoints( points );
694 myEmptyGrid->BuildLinks();
696 myGrid->ShallowCopy(myEmptyGrid);
699 //=================================================================================
700 // function : GetElemDimension
701 // purpose : Get dimension of element
702 //=================================================================================
703 int SMESH_MeshObj::GetElemDimension( const int theObjId )
705 const SMDS_MeshElement* anElem = myClient->FindElement( theObjId );
709 int aType = anElem->GetType();
712 case SMDSAbs_0DElement : return 0;
713 case SMDSAbs_Ball : return 0;
714 case SMDSAbs_Edge : return 1;
715 case SMDSAbs_Face : return 2;
716 case SMDSAbs_Volume: return 3;
721 //=================================================================================
722 // function : GetEntities
723 // purpose : Get entities of specified type. Return number of entities
724 //=================================================================================
725 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
731 return myClient->NbNodes();
734 case SMDSAbs_0DElement:
736 return myClient->Nb0DElements();
740 return myClient->NbBalls();
745 return myClient->NbEdges();
750 return myClient->NbFaces();
755 return myClient->NbVolumes();
764 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
772 SMDS_NodeIteratorPtr anIter = myClient->nodesIterator();
773 while ( anIter->more() ) theObjs.push_back( anIter->next() );
776 case SMDSAbs_0DElement:
778 SMDS_ElemIteratorPtr anIter = myClient->elementsIterator(SMDSAbs_0DElement);
779 while ( anIter->more() ) theObjs.push_back( anIter->next() );
784 SMDS_ElemIteratorPtr anIter = myClient->elementGeomIterator(SMDSGeom_BALL);
785 while ( anIter->more() ) theObjs.push_back( anIter->next() );
790 SMDS_EdgeIteratorPtr anIter = myClient->edgesIterator();
791 while ( anIter->more() ) theObjs.push_back( anIter->next() );
796 SMDS_FaceIteratorPtr anIter = myClient->facesIterator();
797 while ( anIter->more() ) theObjs.push_back( anIter->next() );
802 SMDS_VolumeIteratorPtr anIter = myClient->volumesIterator();
803 while ( anIter->more() ) theObjs.push_back( anIter->next() );
810 return theObjs.size();
813 //=================================================================================
814 // function : UpdateFunctor
815 // purpose : Update functor in accordance with current mesh
816 //=================================================================================
817 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
819 theFunctor->SetMesh( GetMesh() );
822 //=================================================================================
823 // function : IsNodePrs
824 // purpose : Return true if node presentation is used
825 //=================================================================================
826 bool SMESH_MeshObj::IsNodePrs() const
828 return myClient->Nb0DElements() + myClient->NbEdges() + myClient->NbFaces() + myClient->NbVolumes() + myClient->NbBalls() == 0 ;
833 Class : SMESH_SubMeshObj
834 Description : Base class for visualisation of submeshes and groups
837 //=================================================================================
838 // function : SMESH_SubMeshObj
839 // purpose : Constructor
840 //=================================================================================
841 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
843 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
845 myMeshObj = theMeshObj;
848 SMESH_SubMeshObj::~SMESH_SubMeshObj()
852 //=================================================================================
853 // function : GetElemDimension
854 // purpose : Get dimension of element
855 //=================================================================================
856 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
858 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
861 //=================================================================================
862 // function : UpdateFunctor
863 // purpose : Update functor in accordance with current mesh
864 //=================================================================================
866 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
868 theFunctor->SetMesh( myMeshObj->GetMesh() );
871 //=================================================================================
873 // purpose : Update mesh object and fill grid with new values
874 //=================================================================================
875 bool SMESH_SubMeshObj::Update( int theIsClear )
877 MESSAGE("SMESH_SubMeshObj::Update " << this)
878 bool changed = myMeshObj->Update( theIsClear );
885 Class : SMESH_GroupObj
886 Description : Class for visualisation of groups
889 //=================================================================================
890 // function : SMESH_GroupObj
891 // purpose : Constructor
892 //=================================================================================
893 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
894 SMESH_MeshObj* theMeshObj )
895 : SMESH_SubMeshObj( theMeshObj ),
896 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
898 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
899 myGroupServer->Register();
902 SMESH_GroupObj::~SMESH_GroupObj()
904 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
905 myGroupServer->UnRegister();
908 //=================================================================================
909 // function : IsNodePrs
910 // purpose : Return true if node presentation is used
911 //=================================================================================
912 bool SMESH_GroupObj::IsNodePrs() const
914 return myGroupServer->GetType() == SMESH::NODE;
917 //=================================================================================
918 // function : GetElementType
919 // purpose : Return type of elements of group
920 //=================================================================================
921 SMDSAbs_ElementType SMESH_GroupObj::GetElementType() const
923 return SMDSAbs_ElementType(myGroupServer->GetType());
926 //=================================================================================
927 // function : getNodesFromElems
928 // purpose : Retrieve nodes from elements
929 //=================================================================================
930 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
931 const SMDS_Mesh* theMesh,
932 std::list<const SMDS_MeshElement*>& theResList )
934 set<const SMDS_MeshElement*> aNodeSet;
936 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
938 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
941 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
942 while ( anIter->more() )
944 const SMDS_MeshElement* aNode = anIter->next();
946 aNodeSet.insert( aNode );
951 set<const SMDS_MeshElement*>::const_iterator anIter;
952 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
953 theResList.push_back( *anIter );
955 return theResList.size();
958 //=================================================================================
959 // function : getPointers
960 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
961 //=================================================================================
962 static int getPointers( const SMDSAbs_ElementType theRequestType,
963 SMESH::long_array_var& theElemIds,
964 const SMDS_Mesh* theMesh,
965 std::list<const SMDS_MeshElement*>& theResList )
967 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
969 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
970 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
973 theResList.push_back( anElem );
976 return theResList.size();
980 //=================================================================================
981 // function : GetEntities
982 // purpose : Get entities of specified type. Return number of entities
983 //=================================================================================
984 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
986 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType) {
987 return myGroupServer->Size();
989 if ( theType == SMDSAbs_Node ) {
990 return myGroupServer->GetNumberOfNodes();
995 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
998 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
1003 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
1004 if ( aGrpType != theType && theType != SMDSAbs_Node )
1007 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
1008 if ( anIds->length() == 0 )
1011 if ( aGrpType == theType )
1012 return getPointers( theType, anIds, aMesh, theResList );
1013 else if ( theType == SMDSAbs_Node )
1014 return getNodesFromElems( anIds, aMesh, theResList );
1022 Class : SMESH_subMeshObj
1023 Description : Class for visualisation of submeshes
1026 //=================================================================================
1027 // function : SMESH_subMeshObj
1028 // purpose : Constructor
1029 //=================================================================================
1030 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
1031 SMESH_MeshObj* theMeshObj )
1032 : SMESH_SubMeshObj( theMeshObj ),
1033 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
1035 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
1037 mySubMeshServer->Register();
1040 SMESH_subMeshObj::~SMESH_subMeshObj()
1042 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
1043 mySubMeshServer->UnRegister();
1046 //=================================================================================
1047 // function : GetEntities
1048 // purpose : Get entities of specified type. Return number of entities
1049 //=================================================================================
1050 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
1056 return mySubMeshServer->GetNumberOfNodes( /*all=*/true );
1060 case SMDSAbs_0DElement:
1063 case SMDSAbs_Volume:
1065 SMESH::long_array_var anIds =
1066 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1067 return anIds->length();
1075 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
1079 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
1083 bool isNodal = IsNodePrs();
1087 if ( theType == SMDSAbs_Node )
1089 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
1090 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
1095 if ( theType == SMDSAbs_Node )
1097 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
1098 return getNodesFromElems( anIds, aMesh, theResList );
1102 SMESH::long_array_var anIds =
1103 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1104 return getPointers( theType, anIds, aMesh, theResList );
1111 //=================================================================================
1112 // function : IsNodePrs
1113 // purpose : Return true if node presentation is used
1114 //=================================================================================
1115 bool SMESH_subMeshObj::IsNodePrs() const
1117 return mySubMeshServer->GetNumberOfElements() == 0;