1 // Copyright (C) 2007-2010 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 = 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_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;
169 return this->GetMesh()->FindNode(theObjID)->getVtkId();
172 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
176 TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID);
177 return i == myVTK2SMDSElems.end() ? -1 : i->second;
179 return this->GetMesh()->fromVtkToSmds(theVTKID);
182 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
186 TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID);
187 return i == mySMDS2VTKElems.end() ? -1 : i->second;
189 return this->GetMesh()->FindElement(theObjID)->getVtkId();
190 //return this->GetMesh()->fromSmdsToVtk(theObjID);
193 //=================================================================================
194 // function : SMESH_VisualObjDef::createPoints
195 // purpose : Create points from nodes
196 //=================================================================================
197 /*! fills a vtkPoints structure for a submesh.
198 * fills a std::list of SMDS_MeshElements*, then extract the points.
199 * fills also conversion id maps between SMDS and VTK.
201 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
203 if ( thePoints == 0 )
207 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
208 thePoints->SetNumberOfPoints( nbNodes );
212 TEntityList::const_iterator anIter;
213 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
215 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
218 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
219 int anId = aNode->GetID();
220 mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
221 myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
226 if ( nbPoints != nbNodes )
227 thePoints->SetNumberOfPoints( nbPoints );
230 //=================================================================================
231 // function : buildPrs
232 // purpose : create VTK cells( fill unstructured grid )
233 //=================================================================================
234 void SMESH_VisualObjDef::buildPrs(bool buildGrid)
236 MESSAGE("----------------------------------------------------------SMESH_VisualObjDef::buildPrs " << buildGrid);
242 mySMDS2VTKNodes.clear();
243 myVTK2SMDSNodes.clear();
244 mySMDS2VTKElems.clear();
245 myVTK2SMDSElems.clear();
254 mySMDS2VTKNodes.clear();
255 myVTK2SMDSNodes.clear();
256 mySMDS2VTKElems.clear();
257 myVTK2SMDSElems.clear();
259 myGrid->SetPoints( 0 );
260 myGrid->SetCells( 0, 0, 0, 0, 0 );
267 if (!GetMesh()->isCompacted())
269 MESSAGE("*** buildPrs ==> compactMesh!");
270 GetMesh()->compactMesh();
272 vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
273 myGrid->ShallowCopy(theGrid);
274 //MESSAGE(myGrid->GetReferenceCount());
275 //MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
276 //MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints() );
277 if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"buildPrs.vtu" );
281 //=================================================================================
282 // function : buildNodePrs
283 // purpose : create VTK cells for nodes
284 //=================================================================================
286 void SMESH_VisualObjDef::buildNodePrs()
288 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
289 // so check remaining memory size for safety
290 // SMDS_Mesh::CheckMemory(); // PAL16631
291 vtkPoints* aPoints = vtkPoints::New();
292 createPoints( aPoints );
293 // SMDS_Mesh::CheckMemory();
294 myGrid->SetPoints( aPoints );
297 myGrid->SetCells( 0, 0, 0, 0, 0 );
300 //=================================================================================
301 // function : buildElemPrs
302 // purpose : Create VTK cells for elements
303 //=================================================================================
306 typedef std::vector<const SMDS_MeshElement*> TConnect;
308 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
309 TConnect& theConnect)
312 for(; theNodesIter->more();)
313 theConnect.push_back(theNodesIter->next());
314 return theConnect.size();
318 void SetId(vtkIdList *theIdList,
319 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
320 const TConnect& theConnect,
324 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
330 void SMESH_VisualObjDef::buildElemPrs()
334 vtkPoints* aPoints = vtkPoints::New();
335 createPoints( aPoints );
336 myGrid->SetPoints( aPoints );
340 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
342 // Calculate cells size
344 static SMDSAbs_ElementType aTypes[ 4 ] =
345 { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
348 map<SMDSAbs_ElementType,int> nbEnts;
349 map<SMDSAbs_ElementType,TEntityList> anEnts;
351 for ( int i = 0; i <= 3; i++ )
352 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
354 // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
355 // so check remaining memory size for safety
356 // SMDS_Mesh::CheckMemory(); // PAL16631
358 vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
360 for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes
362 if ( nbEnts[ aTypes[ i ] ] )
364 const TEntityList& aList = anEnts[ aTypes[ i ] ];
365 TEntityList::const_iterator anIter;
366 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
367 aCellsSize += (*anIter)->NbNodes() + 1;
371 vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] +
372 nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
375 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
379 vtkCellArray* aConnectivity = vtkCellArray::New();
380 aConnectivity->Allocate( aCellsSize, 0 );
382 // SMDS_Mesh::CheckMemory(); // PAL16631
384 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
385 aCellTypesArray->SetNumberOfComponents( 1 );
386 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
388 // SMDS_Mesh::CheckMemory(); // PAL16631
390 vtkIdList *anIdList = vtkIdList::New();
394 aConnect.reserve(VTK_CELL_SIZE);
396 // SMDS_Mesh::CheckMemory(); // PAL16631
398 for ( int i = 0; i <= 3; i++ ) // iterate through 0d elements, edges, faces and volumes
400 if ( nbEnts[ aTypes[ i ] ] > 0 )
402 const SMDSAbs_ElementType& aType = aTypes[ i ];
403 const TEntityList& aList = anEnts[ aType ];
404 TEntityList::const_iterator anIter;
405 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
407 const SMDS_MeshElement* anElem = *anIter;
409 vtkIdType aNbNodes = anElem->NbNodes();
410 anIdList->SetNumberOfIds( aNbNodes );
412 int anId = anElem->GetID();
414 mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
415 myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
417 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
419 case SMDSAbs_Volume:{
421 std::vector<int> aConnectivities;
422 // Convertions connectivities from SMDS to VTK
423 if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
425 if ( const SMDS_VtkVolume* ph =
426 dynamic_cast<const SMDS_VtkVolume*> (anElem))
428 aNbNodes = GetConnect(ph->uniqueNodesIterator(),aConnect);
429 anIdList->SetNumberOfIds( aNbNodes );
431 for (int k = 0; k < aNbNodes; k++)
432 aConnectivities.push_back(k);
434 } else if (aNbNodes == 4) {
435 static int anIds[] = {0,2,1,3};
436 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
438 } else if (aNbNodes == 5) {
439 static int anIds[] = {0,3,2,1,4};
440 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
442 } else if (aNbNodes == 6) {
443 static int anIds[] = {0,1,2,3,4,5};
444 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
447 else if (aNbNodes == 8) {
448 static int anIds[] = {0,3,2,1,4,7,6,5};
449 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
452 else if (aNbNodes == 10) {
453 static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
454 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
456 else if (aNbNodes == 13) {
457 static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
458 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
460 else if (aNbNodes == 15) {
461 //static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
462 static int anIds[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
463 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
464 //for (int k = 0; k < aNbNodes; k++) {
465 // int nn = aConnectivities[k];
466 // const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
467 // cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
470 else if (aNbNodes == 20) {
471 static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
472 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
477 if ( aConnect.empty() )
478 GetConnect(aNodesIter,aConnect);
480 if (aConnectivities.size() > 0) {
481 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
482 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
487 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
488 const SMDS_MeshElement* aNode = aNodesIter->next();
489 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
493 aConnectivity->InsertNextCell( anIdList );
494 aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
499 // SMDS_Mesh::CheckMemory(); // PAL16631
502 // Insert cells in grid
504 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
505 aCellLocationsArray->SetNumberOfComponents( 1 );
506 aCellLocationsArray->SetNumberOfTuples( aNbCells );
508 // SMDS_Mesh::CheckMemory(); // PAL16631
510 aConnectivity->InitTraversal();
511 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
512 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
514 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
516 aCellLocationsArray->Delete();
517 aCellTypesArray->Delete();
518 aConnectivity->Delete();
521 // SMDS_Mesh::CheckMemory(); // PAL16631
524 //=================================================================================
525 // function : GetEdgeNodes
526 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
527 //=================================================================================
528 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
529 const int theEdgeNum,
531 int& theNodeId2 ) const
533 const SMDS_Mesh* aMesh = GetMesh();
537 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
541 int nbNodes = anElem->NbNodes();
543 if ( theEdgeNum < 0 || theEdgeNum > 3 || nbNodes != 3 && nbNodes != 4 || theEdgeNum > nbNodes )
546 vector<int> anIds( nbNodes );
547 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
549 while( anIter->more() )
550 anIds[ i++ ] = anIter->next()->GetID();
552 if ( theEdgeNum < nbNodes - 1 )
554 theNodeId1 = anIds[ theEdgeNum ];
555 theNodeId2 = anIds[ theEdgeNum + 1 ];
559 theNodeId1 = anIds[ nbNodes - 1 ];
560 theNodeId2 = anIds[ 0 ];
566 vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid()
568 //MESSAGE("SMESH_VisualObjDef::GetUnstructuredGrid " << myGrid);
573 //=================================================================================
574 // function : IsValid
575 // purpose : Return true if there are some entities
576 //=================================================================================
577 bool SMESH_VisualObjDef::IsValid() const
579 //MESSAGE("SMESH_VisualObjDef::IsValid");
580 return GetNbEntities(SMDSAbs_Node) > 0 ||
581 GetNbEntities(SMDSAbs_0DElement) > 0 ||
582 GetNbEntities(SMDSAbs_Edge) > 0 ||
583 GetNbEntities(SMDSAbs_Face) > 0 ||
584 GetNbEntities(SMDSAbs_Volume) > 0 ;
588 Class : SMESH_MeshObj
589 Description : Class for visualisation of mesh
592 //=================================================================================
593 // function : SMESH_MeshObj
594 // purpose : Constructor
595 //=================================================================================
596 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
597 myClient(SalomeApp_Application::orb(),theMesh)
601 MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
604 //=================================================================================
605 // function : ~SMESH_MeshObj
606 // purpose : Destructor
607 //=================================================================================
608 SMESH_MeshObj::~SMESH_MeshObj()
611 MESSAGE("SMESH_MeshObj - this = "<<this<<"\n");
614 //=================================================================================
616 // purpose : Update mesh and fill grid with new values if necessary
617 //=================================================================================
618 bool SMESH_MeshObj::Update( int theIsClear )
620 // Update SMDS_Mesh on client part
621 MESSAGE("SMESH_MeshObj::Update " << this);
622 if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) {
624 buildPrs(); // Fill unstructured grid
630 bool SMESH_MeshObj::NulData()
632 MESSAGE ("SMESH_MeshObj::NulData() ==================================================================================");
635 myEmptyGrid = SMDS_UnstructuredGrid::New();
636 myEmptyGrid->Initialize();
637 myEmptyGrid->Allocate();
638 vtkPoints* points = vtkPoints::New();
639 points->SetNumberOfPoints(0);
640 myEmptyGrid->SetPoints( points );
642 myEmptyGrid->BuildLinks();
644 myGrid->ShallowCopy(myEmptyGrid);
646 //=================================================================================
647 // function : GetElemDimension
648 // purpose : Get dimension of element
649 //=================================================================================
650 int SMESH_MeshObj::GetElemDimension( const int theObjId )
652 const SMDS_MeshElement* anElem = myClient->FindElement( theObjId );
656 int aType = anElem->GetType();
659 case SMDSAbs_0DElement : return 0;
660 case SMDSAbs_Edge : return 1;
661 case SMDSAbs_Face : return 2;
662 case SMDSAbs_Volume: return 3;
667 //=================================================================================
668 // function : GetEntities
669 // purpose : Get entities of specified type. Return number of entities
670 //=================================================================================
671 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
677 return myClient->NbNodes();
680 case SMDSAbs_0DElement:
682 return myClient->Nb0DElements();
687 return myClient->NbEdges();
692 return myClient->NbFaces();
697 return myClient->NbVolumes();
706 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
714 SMDS_NodeIteratorPtr anIter = myClient->nodesIterator();
715 while ( anIter->more() ) theObjs.push_back( anIter->next() );
718 case SMDSAbs_0DElement:
720 SMDS_0DElementIteratorPtr anIter = myClient->elements0dIterator();
721 while ( anIter->more() ) theObjs.push_back( anIter->next() );
726 SMDS_EdgeIteratorPtr anIter = myClient->edgesIterator();
727 while ( anIter->more() ) theObjs.push_back( anIter->next() );
732 SMDS_FaceIteratorPtr anIter = myClient->facesIterator();
733 while ( anIter->more() ) theObjs.push_back( anIter->next() );
738 SMDS_VolumeIteratorPtr anIter = myClient->volumesIterator();
739 while ( anIter->more() ) theObjs.push_back( anIter->next() );
746 return theObjs.size();
749 //=================================================================================
750 // function : UpdateFunctor
751 // purpose : Update functor in accordance with current mesh
752 //=================================================================================
753 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
755 theFunctor->SetMesh( GetMesh() );
758 //=================================================================================
759 // function : IsNodePrs
760 // purpose : Return true if node presentation is used
761 //=================================================================================
762 bool SMESH_MeshObj::IsNodePrs() const
764 return myClient->Nb0DElements() == 0 && myClient->NbEdges() == 0 && myClient->NbFaces() == 0 && myClient->NbVolumes() == 0 ;
769 Class : SMESH_SubMeshObj
770 Description : Base class for visualisation of submeshes and groups
773 //=================================================================================
774 // function : SMESH_SubMeshObj
775 // purpose : Constructor
776 //=================================================================================
777 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
779 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
781 myMeshObj = theMeshObj;
784 SMESH_SubMeshObj::~SMESH_SubMeshObj()
788 //=================================================================================
789 // function : GetElemDimension
790 // purpose : Get dimension of element
791 //=================================================================================
792 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
794 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
797 //=================================================================================
798 // function : UpdateFunctor
799 // purpose : Update functor in accordance with current mesh
800 //=================================================================================
801 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
803 theFunctor->SetMesh( myMeshObj->GetMesh() );
806 //=================================================================================
808 // purpose : Update mesh object and fill grid with new values
809 //=================================================================================
810 bool SMESH_SubMeshObj::Update( int theIsClear )
812 MESSAGE("SMESH_SubMeshObj::Update " << this)
813 bool changed = myMeshObj->Update( theIsClear );
820 Class : SMESH_GroupObj
821 Description : Class for visualisation of groups
824 //=================================================================================
825 // function : SMESH_GroupObj
826 // purpose : Constructor
827 //=================================================================================
828 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
829 SMESH_MeshObj* theMeshObj )
830 : SMESH_SubMeshObj( theMeshObj ),
831 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
833 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
834 myGroupServer->Register();
837 SMESH_GroupObj::~SMESH_GroupObj()
839 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
840 myGroupServer->Destroy();
843 //=================================================================================
844 // function : IsNodePrs
845 // purpose : Return true if node presentation is used
846 //=================================================================================
847 bool SMESH_GroupObj::IsNodePrs() const
849 return myGroupServer->GetType() == SMESH::NODE;
852 //=================================================================================
853 // function : GetElementType
854 // purpose : Return type of elements of group
855 //=================================================================================
856 SMDSAbs_ElementType SMESH_GroupObj::GetElementType() const
858 return SMDSAbs_ElementType(myGroupServer->GetType());
861 //=================================================================================
862 // function : getNodesFromElems
863 // purpose : Retrieve nodes from elements
864 //=================================================================================
865 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
866 const SMDS_Mesh* theMesh,
867 std::list<const SMDS_MeshElement*>& theResList )
869 set<const SMDS_MeshElement*> aNodeSet;
871 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
873 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
876 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
877 while ( anIter->more() )
879 const SMDS_MeshElement* aNode = anIter->next();
881 aNodeSet.insert( aNode );
886 set<const SMDS_MeshElement*>::const_iterator anIter;
887 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
888 theResList.push_back( *anIter );
890 return theResList.size();
893 //=================================================================================
894 // function : getPointers
895 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
896 //=================================================================================
897 static int getPointers( const SMDSAbs_ElementType theRequestType,
898 SMESH::long_array_var& theElemIds,
899 const SMDS_Mesh* theMesh,
900 std::list<const SMDS_MeshElement*>& theResList )
902 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
904 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
905 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
908 theResList.push_back( anElem );
911 return theResList.size();
915 //=================================================================================
916 // function : GetEntities
917 // purpose : Get entities of specified type. Return number of entities
918 //=================================================================================
919 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
921 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType){
922 return myGroupServer->Size();
927 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
930 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
932 if ( myGroupServer->Size() == 0 || aMesh == 0 )
935 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
936 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
938 if ( aGrpType == theType )
939 return getPointers( theType, anIds, aMesh, theResList );
940 else if ( theType == SMDSAbs_Node )
941 return getNodesFromElems( anIds, aMesh, theResList );
949 Class : SMESH_subMeshObj
950 Description : Class for visualisation of submeshes
953 //=================================================================================
954 // function : SMESH_subMeshObj
955 // purpose : Constructor
956 //=================================================================================
957 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
958 SMESH_MeshObj* theMeshObj )
959 : SMESH_SubMeshObj( theMeshObj ),
960 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
962 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
964 mySubMeshServer->Register();
967 SMESH_subMeshObj::~SMESH_subMeshObj()
969 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
970 mySubMeshServer->Destroy();
973 //=================================================================================
974 // function : GetEntities
975 // purpose : Get entities of specified type. Return number of entities
976 //=================================================================================
977 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
983 return mySubMeshServer->GetNumberOfNodes( false );
986 case SMDSAbs_0DElement:
991 SMESH::long_array_var anIds =
992 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
993 return anIds->length();
1001 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
1005 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
1009 bool isNodal = IsNodePrs();
1013 if ( theType == SMDSAbs_Node )
1015 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
1016 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
1021 if ( theType == SMDSAbs_Node )
1023 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
1024 return getNodesFromElems( anIds, aMesh, theResList );
1028 SMESH::long_array_var anIds =
1029 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1030 return getPointers( theType, anIds, aMesh, theResList );
1037 //=================================================================================
1038 // function : IsNodePrs
1039 // purpose : Return true if node presentation is used
1040 //=================================================================================
1041 bool SMESH_subMeshObj::IsNodePrs() const
1043 return mySubMeshServer->GetNumberOfElements() == 0;