1 // SMESH OBJECT : interactive object for SMESH visualization
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 "SMESH_Actor.h"
33 #include "SMESH_ControlsDef.hxx"
34 #include <VTKViewer_ExtractUnstructuredGrid.h>
36 #include CORBA_SERVER_HEADER(SALOME_Exception)
39 #include <vtkIdList.h>
40 #include <vtkIntArray.h>
41 #include <vtkCellArray.h>
42 #include <vtkUnsignedCharArray.h>
44 #include <vtkUnstructuredGrid.h>
51 #include "utilities.h"
56 #define EXCEPTION(TYPE, MSG) {\
57 std::ostringstream aStream;\
58 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
59 throw TYPE(aStream.str());\
64 static int MYDEBUG = 0;
65 static int MYDEBUGWITHFILES = 0;
67 static int MYDEBUG = 0;
68 static int MYDEBUGWITHFILES = 0;
74 //=======================================================================
76 //=======================================================================
77 inline const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, int theId){
78 if(const SMDS_MeshNode* anElem = theMesh->FindNode(theId)) return anElem;
79 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
83 //=======================================================================
84 //function : FindElement
85 //=======================================================================
86 inline const SMDS_MeshElement* FindElement(const SMDS_Mesh* theMesh, int theId){
87 if(const SMDS_MeshElement* anElem = theMesh->FindElement(theId)) return anElem;
88 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot find a SMDS_MeshElement for ID = "<<theId);
92 //=======================================================================
93 //function : AddNodesWithID
94 //=======================================================================
95 inline void AddNodesWithID(SMDS_Mesh* theMesh,
96 SMESH::log_array_var& theSeq,
99 const SMESH::double_array& aCoords = theSeq[theId].coords;
100 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
101 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
102 if(3*aNbElems != aCoords.length())
103 EXCEPTION(runtime_error,"AddNodesWithID - 3*aNbElems != aCoords.length()");
104 for(CORBA::Long aCoordId = 0; anElemId < aNbElems; anElemId++, aCoordId+=3){
105 SMDS_MeshElement* anElem = theMesh->AddNodeWithID(aCoords[aCoordId],
108 anIndexes[anElemId]);
110 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddNodeWithID for ID = "<<anElemId);
115 //=======================================================================
116 //function : AddEdgesWithID
117 //=======================================================================
118 inline void AddEdgesWithID(SMDS_Mesh* theMesh,
119 SMESH::log_array_var& theSeq,
122 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
123 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
124 if(3*aNbElems != anIndexes.length())
125 EXCEPTION(runtime_error,"AddEdgeWithID - 3*aNbElems != aCoords.length()");
126 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=3){
127 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
128 anIndexes[anIndexId+2],
129 anIndexes[anIndexId]);
131 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
136 //=======================================================================
137 //function : AddTriasWithID
138 //=======================================================================
139 inline void AddTriasWithID(SMDS_Mesh* theMesh,
140 SMESH::log_array_var& theSeq,
143 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
144 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
145 if(4*aNbElems != anIndexes.length())
146 EXCEPTION(runtime_error,"AddTriasWithID - 4*aNbElems != anIndexes.length()");
147 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
148 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
149 anIndexes[anIndexId+2],
150 anIndexes[anIndexId+3],
151 anIndexes[anIndexId]);
153 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
158 //=======================================================================
159 //function : AddQuadsWithID
160 //=======================================================================
161 inline void AddQuadsWithID(SMDS_Mesh* theMesh,
162 SMESH::log_array_var theSeq,
165 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
166 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
167 if(5*aNbElems != anIndexes.length())
168 EXCEPTION(runtime_error,"AddQuadsWithID - 4*aNbElems != anIndexes.length()");
169 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
170 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
171 anIndexes[anIndexId+2],
172 anIndexes[anIndexId+3],
173 anIndexes[anIndexId+4],
174 anIndexes[anIndexId]);
176 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
181 //=======================================================================
182 //function : AddPolygonsWithID
183 //=======================================================================
184 inline void AddPolygonsWithID(SMDS_Mesh* theMesh,
185 SMESH::log_array_var& theSeq,
188 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
189 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
191 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
192 int aFaceId = anIndexes[anIndexId++];
194 int aNbNodes = anIndexes[anIndexId++];
195 std::vector<int> nodes_ids (aNbNodes);
196 for (int i = 0; i < aNbNodes; i++) {
197 nodes_ids[i] = anIndexes[anIndexId++];
200 SMDS_MeshElement* anElem = theMesh->AddPolygonalFaceWithID(nodes_ids, aFaceId);
202 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolygonalFaceWithID for ID = "
208 //=======================================================================
209 //function : AddTetrasWithID
210 //=======================================================================
211 inline void AddTetrasWithID(SMDS_Mesh* theMesh,
212 SMESH::log_array_var& theSeq,
215 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
216 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
217 if(5*aNbElems != anIndexes.length())
218 EXCEPTION(runtime_error,"AddTetrasWithID - 5*aNbElems != anIndexes.length()");
219 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
220 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
221 anIndexes[anIndexId+2],
222 anIndexes[anIndexId+3],
223 anIndexes[anIndexId+4],
224 anIndexes[anIndexId]);
226 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
231 //=======================================================================
232 //function : AddPiramidsWithID
233 //=======================================================================
234 inline void AddPiramidsWithID(SMDS_Mesh* theMesh,
235 SMESH::log_array_var& theSeq,
238 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
239 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
240 if(6*aNbElems != anIndexes.length())
241 EXCEPTION(runtime_error,"AddPiramidsWithID - 6*aNbElems != anIndexes.length()");
242 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=6){
243 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
244 anIndexes[anIndexId+2],
245 anIndexes[anIndexId+3],
246 anIndexes[anIndexId+4],
247 anIndexes[anIndexId+5],
248 anIndexes[anIndexId]);
250 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
255 //=======================================================================
256 //function : AddPrismsWithID
257 //=======================================================================
258 inline void AddPrismsWithID(SMDS_Mesh* theMesh,
259 SMESH::log_array_var& theSeq,
262 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
263 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
264 if(7*aNbElems != anIndexes.length())
265 EXCEPTION(runtime_error,"AddPrismsWithID - 7*aNbElems != anIndexes.length()");
266 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
267 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
268 anIndexes[anIndexId+2],
269 anIndexes[anIndexId+3],
270 anIndexes[anIndexId+4],
271 anIndexes[anIndexId+5],
272 anIndexes[anIndexId+6],
273 anIndexes[anIndexId]);
275 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
280 //=======================================================================
281 //function : AddHexasWithID
282 //=======================================================================
283 inline void AddHexasWithID(SMDS_Mesh* theMesh,
284 SMESH::log_array_var& theSeq,
287 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
288 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
289 if(9*aNbElems != anIndexes.length())
290 EXCEPTION(runtime_error,"AddHexasWithID - 9*aNbElems != anIndexes.length()");
291 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
292 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
293 anIndexes[anIndexId+2],
294 anIndexes[anIndexId+3],
295 anIndexes[anIndexId+4],
296 anIndexes[anIndexId+5],
297 anIndexes[anIndexId+6],
298 anIndexes[anIndexId+7],
299 anIndexes[anIndexId+8],
300 anIndexes[anIndexId]);
302 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
307 //=======================================================================
308 //function : AddPolyhedronsWithID
309 //=======================================================================
310 inline void AddPolyhedronsWithID (SMDS_Mesh* theMesh,
311 SMESH::log_array_var& theSeq,
314 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
315 CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
317 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
318 int aFaceId = anIndexes[anIndexId++];
320 int aNbNodes = anIndexes[anIndexId++];
321 std::vector<int> nodes_ids (aNbNodes);
322 for (int i = 0; i < aNbNodes; i++) {
323 nodes_ids[i] = anIndexes[anIndexId++];
326 int aNbFaces = anIndexes[anIndexId++];
327 std::vector<int> quantities (aNbFaces);
328 for (int i = 0; i < aNbFaces; i++) {
329 quantities[i] = anIndexes[anIndexId++];
332 SMDS_MeshElement* anElem =
333 theMesh->AddPolyhedralVolumeWithID(nodes_ids, quantities, aFaceId);
335 EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolyhedralVolumeWithID for ID = "
341 //=======================================================================
342 //function : AddQuadEdgesWithID
343 //=======================================================================
344 inline void AddQuadEdgesWithID(SMDS_Mesh* theMesh,
345 SMESH::log_array_var& theSeq,
348 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
349 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
350 if(4*aNbElems != anIndexes.length())
351 EXCEPTION(runtime_error,"AddQuadEdgeWithID - 4*aNbElems != aCoords.length()");
352 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
353 SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
354 anIndexes[anIndexId+2],
355 anIndexes[anIndexId+3],
356 anIndexes[anIndexId]);
358 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
363 //=======================================================================
364 //function : AddQuadTriasWithID
365 //=======================================================================
366 inline void AddQuadTriasWithID(SMDS_Mesh* theMesh,
367 SMESH::log_array_var& theSeq,
370 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
371 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
372 if(7*aNbElems != anIndexes.length())
373 EXCEPTION(runtime_error,"AddQuadTriasWithID - 7*aNbElems != anIndexes.length()");
374 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
375 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
376 anIndexes[anIndexId+2],
377 anIndexes[anIndexId+3],
378 anIndexes[anIndexId+4],
379 anIndexes[anIndexId+5],
380 anIndexes[anIndexId+6],
381 anIndexes[anIndexId]);
383 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
388 //=======================================================================
389 //function : AddQuadQuadsWithID
390 //=======================================================================
391 inline void AddQuadQuadsWithID(SMDS_Mesh* theMesh,
392 SMESH::log_array_var theSeq,
395 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
396 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
397 if(9*aNbElems != anIndexes.length())
398 EXCEPTION(runtime_error,"AddQuadQuadsWithID - 9*aNbElems != anIndexes.length()");
399 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
400 SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
401 anIndexes[anIndexId+2],
402 anIndexes[anIndexId+3],
403 anIndexes[anIndexId+4],
404 anIndexes[anIndexId+5],
405 anIndexes[anIndexId+6],
406 anIndexes[anIndexId+7],
407 anIndexes[anIndexId+8],
408 anIndexes[anIndexId]);
410 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
415 //=======================================================================
416 //function : AddQuadTetrasWithID
417 //=======================================================================
418 inline void AddQuadTetrasWithID(SMDS_Mesh* theMesh,
419 SMESH::log_array_var& theSeq,
422 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
423 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
424 if(11*aNbElems != anIndexes.length())
425 EXCEPTION(runtime_error,"AddQuadTetrasWithID - 11*aNbElems != anIndexes.length()");
426 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=11){
427 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
428 anIndexes[anIndexId+2],
429 anIndexes[anIndexId+3],
430 anIndexes[anIndexId+4],
431 anIndexes[anIndexId+5],
432 anIndexes[anIndexId+6],
433 anIndexes[anIndexId+7],
434 anIndexes[anIndexId+8],
435 anIndexes[anIndexId+9],
436 anIndexes[anIndexId+10],
437 anIndexes[anIndexId]);
439 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
444 //=======================================================================
445 //function : AddQuadPiramidsWithID
446 //=======================================================================
447 inline void AddQuadPiramidsWithID(SMDS_Mesh* theMesh,
448 SMESH::log_array_var& theSeq,
451 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
452 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
453 if(14*aNbElems != anIndexes.length())
454 EXCEPTION(runtime_error,"AddQuadPiramidsWithID - 14*aNbElems != anIndexes.length()");
455 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=14){
456 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
457 anIndexes[anIndexId+2],
458 anIndexes[anIndexId+3],
459 anIndexes[anIndexId+4],
460 anIndexes[anIndexId+5],
461 anIndexes[anIndexId+6],
462 anIndexes[anIndexId+7],
463 anIndexes[anIndexId+8],
464 anIndexes[anIndexId+9],
465 anIndexes[anIndexId+10],
466 anIndexes[anIndexId+11],
467 anIndexes[anIndexId+12],
468 anIndexes[anIndexId+13],
469 anIndexes[anIndexId]);
471 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
476 //=======================================================================
477 //function : AddQuadPentasWithID
478 //=======================================================================
479 inline void AddQuadPentasWithID(SMDS_Mesh* theMesh,
480 SMESH::log_array_var& theSeq,
483 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
484 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
485 if(16*aNbElems != anIndexes.length())
486 EXCEPTION(runtime_error,"AddQuadPentasWithID - 16*aNbElems != anIndexes.length()");
487 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=16){
488 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
489 anIndexes[anIndexId+2],
490 anIndexes[anIndexId+3],
491 anIndexes[anIndexId+4],
492 anIndexes[anIndexId+5],
493 anIndexes[anIndexId+6],
494 anIndexes[anIndexId+7],
495 anIndexes[anIndexId+8],
496 anIndexes[anIndexId+9],
497 anIndexes[anIndexId+10],
498 anIndexes[anIndexId+11],
499 anIndexes[anIndexId+12],
500 anIndexes[anIndexId+13],
501 anIndexes[anIndexId+14],
502 anIndexes[anIndexId+15],
503 anIndexes[anIndexId]);
505 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
510 //=======================================================================
511 //function : AddQuadHexasWithID
512 //=======================================================================
513 inline void AddQuadHexasWithID(SMDS_Mesh* theMesh,
514 SMESH::log_array_var& theSeq,
517 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
518 CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
519 if(21*aNbElems != anIndexes.length())
520 EXCEPTION(runtime_error,"AddQuadHexasWithID - 21*aNbElems != anIndexes.length()");
521 for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=21){
522 SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
523 anIndexes[anIndexId+2],
524 anIndexes[anIndexId+3],
525 anIndexes[anIndexId+4],
526 anIndexes[anIndexId+5],
527 anIndexes[anIndexId+6],
528 anIndexes[anIndexId+7],
529 anIndexes[anIndexId+8],
530 anIndexes[anIndexId+9],
531 anIndexes[anIndexId+10],
532 anIndexes[anIndexId+11],
533 anIndexes[anIndexId+12],
534 anIndexes[anIndexId+13],
535 anIndexes[anIndexId+14],
536 anIndexes[anIndexId+15],
537 anIndexes[anIndexId+16],
538 anIndexes[anIndexId+17],
539 anIndexes[anIndexId+18],
540 anIndexes[anIndexId+19],
541 anIndexes[anIndexId+20],
542 anIndexes[anIndexId]);
544 EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
549 //=======================================================================
550 //function : ChangePolyhedronNodes
551 //=======================================================================
552 inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh,
553 SMESH::log_array_var& theSeq,
556 const SMESH::long_array& anIndexes = theSeq[theId].indexes;
557 CORBA::Long iind = 0, aNbElems = theSeq[theId].number;
559 for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++)
562 const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]);
564 int nbNodes = anIndexes[iind++];
566 std::vector<const SMDS_MeshNode*> aNodes (nbNodes);
567 for (int iNode = 0; iNode < nbNodes; iNode++) {
568 aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]);
571 int nbFaces = anIndexes[iind++];
573 std::vector<int> quantities (nbFaces);
574 for (int iFace = 0; iFace < nbFaces; iFace++) {
575 quantities[iFace] = anIndexes[iind++];
578 theMesh->ChangePolyhedronNodes(elem, aNodes, quantities);
585 Class : SMESH_VisualObjDef
586 Description : Base class for all mesh objects to be visuilised
589 //=================================================================================
590 // function : getCellType
591 // purpose : Get type of VTK cell
592 //=================================================================================
593 static inline vtkIdType getCellType( const SMDSAbs_ElementType theType,
595 const int theNbNodes )
600 if( theNbNodes == 2 ) return VTK_LINE;
601 else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE;
602 else return VTK_EMPTY_CELL;
605 if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
606 else if ( theNbNodes == 3 ) return VTK_TRIANGLE;
607 else if ( theNbNodes == 4 ) return VTK_QUAD;
608 else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE;
609 else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD;
610 else return VTK_EMPTY_CELL;
613 if (thePoly && theNbNodes>3 ) return VTK_CONVEX_POINT_SET;
614 else if ( theNbNodes == 4 ) return VTK_TETRA;
615 else if ( theNbNodes == 5 ) return VTK_PYRAMID;
616 else if ( theNbNodes == 6 ) return VTK_WEDGE;
617 else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON;
618 else if ( theNbNodes == 10 ) {
619 cout<<"QUADRATIC_TETRA"<<endl;
620 return VTK_QUADRATIC_TETRA;
622 else if ( theNbNodes == 20 ) {
623 cout<<"QUADRATIC_HEXAHEDRON"<<endl;
624 return VTK_QUADRATIC_HEXAHEDRON;
626 else if ( theNbNodes==13 || theNbNodes==15 ) {
627 cout<<"QUADRATIC - CONVEX_POINT_SET"<<endl;
628 return VTK_CONVEX_POINT_SET;
630 else return VTK_EMPTY_CELL;
632 default: return VTK_EMPTY_CELL;
636 //=================================================================================
637 // functions : SMESH_VisualObjDef
638 // purpose : Constructor
639 //=================================================================================
640 SMESH_VisualObjDef::SMESH_VisualObjDef()
642 myGrid = vtkUnstructuredGrid::New();
644 SMESH_VisualObjDef::~SMESH_VisualObjDef()
647 MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
651 //=================================================================================
652 // functions : GetNodeObjId, GetNodeVTKId, GetElemObjId, GetElemVTKId
653 // purpose : Methods for retrieving VTK IDs by SMDS IDs and vice versa
654 //=================================================================================
655 vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
657 return myVTK2SMDSNodes.find(theVTKID) == myVTK2SMDSNodes.end() ? -1 : myVTK2SMDSNodes[theVTKID];
660 vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
662 return mySMDS2VTKNodes.find(theObjID) == mySMDS2VTKNodes.end() ? -1 : mySMDS2VTKNodes[theObjID];
665 vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
667 return myVTK2SMDSElems.find(theVTKID) == myVTK2SMDSElems.end() ? -1 : myVTK2SMDSElems[theVTKID];
670 vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
672 return mySMDS2VTKElems.find(theObjID) == mySMDS2VTKElems.end() ? -1 : mySMDS2VTKElems[theObjID];
675 //=================================================================================
676 // function : SMESH_VisualObjDef::createPoints
677 // purpose : Create points from nodes
678 //=================================================================================
679 void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
681 if ( thePoints == 0 )
685 vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
686 thePoints->SetNumberOfPoints( nbNodes );
690 TEntityList::const_iterator anIter;
691 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
693 const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
696 thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
697 int anId = aNode->GetID();
698 mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
699 myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
704 if ( nbPoints != nbNodes )
705 thePoints->SetNumberOfPoints( nbPoints );
708 //=================================================================================
709 // function : buildPrs
710 // purpose : create VTK cells( fill unstructured grid )
711 //=================================================================================
712 void SMESH_VisualObjDef::buildPrs()
716 mySMDS2VTKNodes.clear();
717 myVTK2SMDSNodes.clear();
718 mySMDS2VTKElems.clear();
719 myVTK2SMDSElems.clear();
726 catch( const std::exception& exc )
728 INFOS("Follow exception was cought:\n\t"<<exc.what());
732 INFOS("Unknown exception was cought !!!");
735 if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
736 if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
739 //=================================================================================
740 // function : buildNodePrs
741 // purpose : create VTK cells for nodes
742 //=================================================================================
743 void SMESH_VisualObjDef::buildNodePrs()
745 vtkPoints* aPoints = vtkPoints::New();
746 createPoints( aPoints );
747 myGrid->SetPoints( aPoints );
750 myGrid->SetCells( 0, 0, 0 );
754 int nbPoints = aPoints->GetNumberOfPoints();
755 vtkIdList *anIdList = vtkIdList::New();
756 anIdList->SetNumberOfIds( 1 );
758 vtkCellArray *aCells = vtkCellArray::New();
759 aCells->Allocate( 2 * nbPoints, 0 );
761 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
762 aCellTypesArray->SetNumberOfComponents( 1 );
763 aCellTypesArray->Allocate( nbPoints );
765 for( vtkIdType aCellId = 0; aCellId < nbPoints; aCellId++ )
767 anIdList->SetId( 0, aCellId );
768 aCells->InsertNextCell( anIdList );
769 aCellTypesArray->InsertNextValue( VTK_VERTEX );
772 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
773 aCellLocationsArray->SetNumberOfComponents( 1 );
774 aCellLocationsArray->SetNumberOfTuples( nbPoints );
776 aCells->InitTraversal();
777 for( vtkIdType i = 0, *pts, npts; aCells->GetNextCell( npts, pts ); i++ )
778 aCellLocationsArray->SetValue( i, aCells->GetTraversalLocation( npts ) );
780 myGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
782 aCellLocationsArray->Delete();
783 aCellTypesArray->Delete();
789 //=================================================================================
790 // function : buildElemPrs
791 // purpose : Create VTK cells for elements
792 //=================================================================================
795 typedef std::vector<const SMDS_MeshElement*> TConnect;
797 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
798 TConnect& theConnect)
801 for(; theNodesIter->more();)
802 theConnect.push_back(theNodesIter->next());
803 return theConnect.size();
807 void SetId(vtkIdList *theIdList,
808 const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes,
809 const TConnect& theConnect,
813 theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second);
819 void SMESH_VisualObjDef::buildElemPrs()
823 vtkPoints* aPoints = vtkPoints::New();
824 createPoints( aPoints );
825 myGrid->SetPoints( aPoints );
829 MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
831 // Calculate cells size
833 static SMDSAbs_ElementType aTypes[ 3 ] = { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
836 map<SMDSAbs_ElementType,int> nbEnts;
837 map<SMDSAbs_ElementType,TEntityList> anEnts;
839 for ( int i = 0; i <= 2; i++ )
840 nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
842 vtkIdType aCellsSize = 3 * nbEnts[ SMDSAbs_Edge ];
844 for ( int i = 1; i <= 2; i++ ) // iterate through faces and volumes
846 if ( nbEnts[ aTypes[ i ] ] )
848 const TEntityList& aList = anEnts[ aTypes[ i ] ];
849 TEntityList::const_iterator anIter;
850 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
851 aCellsSize += (*anIter)->NbNodes() + 1;
855 vtkIdType aNbCells = nbEnts[ SMDSAbs_Edge ] + nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
858 MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
862 vtkCellArray* aConnectivity = vtkCellArray::New();
863 aConnectivity->Allocate( aCellsSize, 0 );
865 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
866 aCellTypesArray->SetNumberOfComponents( 1 );
867 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
869 vtkIdList *anIdList = vtkIdList::New();
873 aConnect.reserve(VTK_CELL_SIZE);
875 for ( int i = 0; i <= 2; i++ ) // iterate through edges, faces and volumes
877 if( nbEnts[ aTypes[ i ] ] > 0 )
879 const SMDSAbs_ElementType& aType = aTypes[ i ];
880 const TEntityList& aList = anEnts[ aType ];
881 TEntityList::const_iterator anIter;
882 for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
884 const SMDS_MeshElement* anElem = *anIter;
886 vtkIdType aNbNodes = anElem->NbNodes();
887 anIdList->SetNumberOfIds( aNbNodes );
889 int anId = anElem->GetID();
891 mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
892 myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
894 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
896 case SMDSAbs_Volume:{
897 std::vector<int> aConnectivities;
898 GetConnect(aNodesIter,aConnect);
899 // Convertions connectivities from SMDS to VTK
900 if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
901 for (int k = 0; k < aNbNodes; k++) {
902 aConnectivities.push_back(k);
905 } else if (aNbNodes == 4) {
906 static int anIds[] = {0,2,1,3};
907 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
909 } else if (aNbNodes == 5) {
910 static int anIds[] = {0,3,2,1,4};
911 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
913 } else if (aNbNodes == 6) {
914 static int anIds[] = {0,1,2,3,4,5};
915 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
918 else if (aNbNodes == 8) {
919 static int anIds[] = {0,3,2,1,4,7,6,5};
920 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
923 else if (aNbNodes == 10) {
924 static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
925 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
927 else if (aNbNodes == 13) {
928 static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
929 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
931 else if (aNbNodes == 15) {
932 static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
933 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
934 //for (int k = 0; k < aNbNodes; k++) {
935 // int nn = aConnectivities[k];
936 // const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
937 // cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
940 else if (aNbNodes == 20) {
941 static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
942 for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
947 if (aConnectivities.size() > 0) {
948 for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
949 SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
954 for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
955 const SMDS_MeshElement* aNode = aNodesIter->next();
956 anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
960 aConnectivity->InsertNextCell( anIdList );
961 aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
968 // Insert cells in grid
970 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
971 aCellLocationsArray->SetNumberOfComponents( 1 );
972 aCellLocationsArray->SetNumberOfTuples( aNbCells );
974 aConnectivity->InitTraversal();
975 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
976 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
978 myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
980 aCellLocationsArray->Delete();
981 aCellTypesArray->Delete();
982 aConnectivity->Delete();
986 //=================================================================================
987 // function : GetEdgeNodes
988 // purpose : Retrieve ids of nodes from edge of elements ( edge is numbered from 1 )
989 //=================================================================================
990 bool SMESH_VisualObjDef::GetEdgeNodes( const int theElemId,
991 const int theEdgeNum,
993 int& theNodeId2 ) const
995 const SMDS_Mesh* aMesh = GetMesh();
999 const SMDS_MeshElement* anElem = aMesh->FindElement( theElemId );
1003 int nbNodes = anElem->NbNodes();
1005 if ( theEdgeNum < 0 || theEdgeNum > 3 || nbNodes != 3 && nbNodes != 4 || theEdgeNum > nbNodes )
1008 int anIds[ nbNodes ];
1009 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
1011 while( anIter->more() )
1012 anIds[ i++ ] = anIter->next()->GetID();
1014 if ( theEdgeNum < nbNodes - 1 )
1016 theNodeId1 = anIds[ theEdgeNum ];
1017 theNodeId2 = anIds[ theEdgeNum + 1 ];
1021 theNodeId1 = anIds[ nbNodes - 1 ];
1022 theNodeId2 = anIds[ 0 ];
1029 Class : SMESH_MeshObj
1030 Description : Class for visualisation of mesh
1033 //=================================================================================
1034 // function : SMESH_MeshObj
1035 // purpose : Constructor
1036 //=================================================================================
1037 SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh)
1040 MESSAGE("SMESH_MeshObj - theMesh->_is_nil() = "<<theMesh->_is_nil());
1042 myMeshServer = SMESH::SMESH_Mesh::_duplicate( theMesh );
1043 myMeshServer->Register();
1044 myMesh = new SMDS_Mesh();
1047 //=================================================================================
1048 // function : ~SMESH_MeshObj
1049 // purpose : Destructor
1050 //=================================================================================
1051 SMESH_MeshObj::~SMESH_MeshObj()
1053 myMeshServer->Destroy();
1057 //=================================================================================
1058 // function : Update
1059 // purpose : Update mesh and fill grid with new values if necessary
1060 //=================================================================================
1061 void SMESH_MeshObj::Update( int theIsClear )
1063 // Update SMDS_Mesh on client part
1067 SMESH::log_array_var aSeq = myMeshServer->GetLog( theIsClear );
1068 CORBA::Long aLength = aSeq->length();
1070 if( MYDEBUG ) MESSAGE( "Update: length of the script is "<<aLength );
1075 for ( CORBA::Long anId = 0; anId < aLength; anId++)
1077 const SMESH::double_array& aCoords = aSeq[anId].coords;
1078 const SMESH::long_array& anIndexes = aSeq[anId].indexes;
1079 CORBA::Long anElemId = 0, aNbElems = aSeq[anId].number;
1080 CORBA::Long aCommand = aSeq[anId].commandType;
1084 case SMESH::ADD_NODE : AddNodesWithID ( myMesh, aSeq, anId ); break;
1085 case SMESH::ADD_EDGE : AddEdgesWithID ( myMesh, aSeq, anId ); break;
1086 case SMESH::ADD_TRIANGLE : AddTriasWithID ( myMesh, aSeq, anId ); break;
1087 case SMESH::ADD_QUADRANGLE : AddQuadsWithID ( myMesh, aSeq, anId ); break;
1088 case SMESH::ADD_POLYGON : AddPolygonsWithID ( myMesh, aSeq, anId ); break;
1089 case SMESH::ADD_TETRAHEDRON: AddTetrasWithID ( myMesh, aSeq, anId ); break;
1090 case SMESH::ADD_PYRAMID : AddPiramidsWithID ( myMesh, aSeq, anId ); break;
1091 case SMESH::ADD_PRISM : AddPrismsWithID ( myMesh, aSeq, anId ); break;
1092 case SMESH::ADD_HEXAHEDRON : AddHexasWithID ( myMesh, aSeq, anId ); break;
1093 case SMESH::ADD_POLYHEDRON : AddPolyhedronsWithID( myMesh, aSeq, anId ); break;
1095 case SMESH::ADD_QUADEDGE : AddQuadEdgesWithID ( myMesh, aSeq, anId ); break;
1096 case SMESH::ADD_QUADTRIANGLE : AddQuadTriasWithID ( myMesh, aSeq, anId ); break;
1097 case SMESH::ADD_QUADQUADRANGLE : AddQuadQuadsWithID ( myMesh, aSeq, anId ); break;
1098 case SMESH::ADD_QUADTETRAHEDRON: AddQuadTetrasWithID ( myMesh, aSeq, anId ); break;
1099 case SMESH::ADD_QUADPYRAMID : AddQuadPiramidsWithID( myMesh, aSeq, anId ); break;
1100 case SMESH::ADD_QUADPENTAHEDRON: AddQuadPentasWithID ( myMesh, aSeq, anId ); break;
1101 case SMESH::ADD_QUADHEXAHEDRON : AddQuadHexasWithID ( myMesh, aSeq, anId ); break;
1103 case SMESH::REMOVE_NODE:
1104 for( ; anElemId < aNbElems; anElemId++ )
1105 myMesh->RemoveNode( FindNode( myMesh, anIndexes[anElemId] ) );
1108 case SMESH::REMOVE_ELEMENT:
1109 for( ; anElemId < aNbElems; anElemId++ )
1110 myMesh->RemoveElement( FindElement( myMesh, anIndexes[anElemId] ) );
1113 case SMESH::MOVE_NODE:
1114 for(CORBA::Long aCoordId=0; anElemId < aNbElems; anElemId++, aCoordId+=3)
1116 SMDS_MeshNode* node =
1117 const_cast<SMDS_MeshNode*>( FindNode( myMesh, anIndexes[anElemId] ));
1118 node->setXYZ( aCoords[aCoordId], aCoords[aCoordId+1], aCoords[aCoordId+2] );
1122 case SMESH::CHANGE_ELEMENT_NODES:
1123 for ( CORBA::Long i = 0; anElemId < aNbElems; anElemId++ )
1126 const SMDS_MeshElement* elem = FindElement( myMesh, anIndexes[i++] );
1128 int nbNodes = anIndexes[i++];
1130 //ASSERT( nbNodes < 9 );
1131 const SMDS_MeshNode* aNodes[ nbNodes ];
1132 for ( int iNode = 0; iNode < nbNodes; iNode++ )
1133 aNodes[ iNode ] = FindNode( myMesh, anIndexes[i++] );
1135 myMesh->ChangeElementNodes( elem, aNodes, nbNodes );
1139 case SMESH::CHANGE_POLYHEDRON_NODES:
1140 ChangePolyhedronNodes(myMesh, aSeq, anId);
1142 case SMESH::RENUMBER:
1143 for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3)
1145 myMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] );
1153 catch ( SALOME::SALOME_Exception& exc )
1155 INFOS("Following exception was cought:\n\t"<<exc.details.text);
1157 catch( const std::exception& exc)
1159 INFOS("Following exception was cought:\n\t"<<exc.what());
1163 INFOS("Unknown exception was cought !!!");
1168 MESSAGE("Update - myMesh->NbNodes() = "<<myMesh->NbNodes());
1169 MESSAGE("Update - myMesh->NbEdges() = "<<myMesh->NbEdges());
1170 MESSAGE("Update - myMesh->NbFaces() = "<<myMesh->NbFaces());
1171 MESSAGE("Update - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
1174 // Fill unstructured grid
1178 //=================================================================================
1179 // function : GetElemDimension
1180 // purpose : Get dimension of element
1181 //=================================================================================
1182 int SMESH_MeshObj::GetElemDimension( const int theObjId )
1184 const SMDS_MeshElement* anElem = myMesh->FindElement( theObjId );
1188 int aType = anElem->GetType();
1191 case SMDSAbs_Edge : return 1;
1192 case SMDSAbs_Face : return 2;
1193 case SMDSAbs_Volume: return 3;
1198 //=================================================================================
1199 // function : GetEntities
1200 // purpose : Get entities of specified type. Return number of entities
1201 //=================================================================================
1202 int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
1208 return myMesh->NbNodes();
1213 return myMesh->NbEdges();
1218 return myMesh->NbFaces();
1221 case SMDSAbs_Volume:
1223 return myMesh->NbVolumes();
1232 int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theObjs ) const
1240 SMDS_NodeIteratorPtr anIter = myMesh->nodesIterator();
1241 while ( anIter->more() ) theObjs.push_back( anIter->next() );
1246 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
1247 while ( anIter->more() ) theObjs.push_back( anIter->next() );
1252 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
1253 while ( anIter->more() ) theObjs.push_back( anIter->next() );
1256 case SMDSAbs_Volume:
1258 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
1259 while ( anIter->more() ) theObjs.push_back( anIter->next() );
1266 return theObjs.size();
1269 //=================================================================================
1270 // function : UpdateFunctor
1271 // purpose : Update functor in accordance with current mesh
1272 //=================================================================================
1273 void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
1275 theFunctor->SetMesh( GetMesh() );
1278 //=================================================================================
1279 // function : IsNodePrs
1280 // purpose : Return true if node presentation is used
1281 //=================================================================================
1282 bool SMESH_MeshObj::IsNodePrs() const
1284 return myMesh->NbEdges() == 0 &&myMesh->NbFaces() == 0 &&myMesh->NbVolumes() == 0 ;
1289 Class : SMESH_SubMeshObj
1290 Description : Base class for visualisation of submeshes and groups
1293 //=================================================================================
1294 // function : SMESH_SubMeshObj
1295 // purpose : Constructor
1296 //=================================================================================
1297 SMESH_SubMeshObj::SMESH_SubMeshObj( SMESH_MeshObj* theMeshObj )
1299 if ( MYDEBUG ) MESSAGE( "SMESH_SubMeshObj - theMeshObj = " << theMeshObj );
1301 myMeshObj = theMeshObj;
1304 SMESH_SubMeshObj::~SMESH_SubMeshObj()
1308 //=================================================================================
1309 // function : GetElemDimension
1310 // purpose : Get dimension of element
1311 //=================================================================================
1312 int SMESH_SubMeshObj::GetElemDimension( const int theObjId )
1314 return myMeshObj == 0 ? 0 : myMeshObj->GetElemDimension( theObjId );
1317 //=================================================================================
1318 // function : UpdateFunctor
1319 // purpose : Update functor in accordance with current mesh
1320 //=================================================================================
1321 void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor )
1323 theFunctor->SetMesh( myMeshObj->GetMesh() );
1326 //=================================================================================
1327 // function : Update
1328 // purpose : Update mesh object and fill grid with new values
1329 //=================================================================================
1330 void SMESH_SubMeshObj::Update( int theIsClear )
1332 myMeshObj->Update( theIsClear );
1338 Class : SMESH_GroupObj
1339 Description : Class for visualisation of groups
1342 //=================================================================================
1343 // function : SMESH_GroupObj
1344 // purpose : Constructor
1345 //=================================================================================
1346 SMESH_GroupObj::SMESH_GroupObj( SMESH::SMESH_GroupBase_ptr theGroup,
1347 SMESH_MeshObj* theMeshObj )
1348 : SMESH_SubMeshObj( theMeshObj ),
1349 myGroupServer( SMESH::SMESH_GroupBase::_duplicate(theGroup) )
1351 if ( MYDEBUG ) MESSAGE("SMESH_GroupObj - theGroup->_is_nil() = "<<theGroup->_is_nil());
1352 myGroupServer->Register();
1355 SMESH_GroupObj::~SMESH_GroupObj()
1357 if ( MYDEBUG ) MESSAGE("~SMESH_GroupObj");
1358 myGroupServer->Destroy();
1361 //=================================================================================
1362 // function : IsNodePrs
1363 // purpose : Return true if node presentation is used
1364 //=================================================================================
1365 bool SMESH_GroupObj::IsNodePrs() const
1367 return myGroupServer->GetType() == SMESH::NODE;
1370 //=================================================================================
1371 // function : getNodesFromElems
1372 // purpose : Retrieve nodes from elements
1373 //=================================================================================
1374 static int getNodesFromElems( SMESH::long_array_var& theElemIds,
1375 const SMDS_Mesh* theMesh,
1376 std::list<const SMDS_MeshElement*>& theResList )
1378 set<const SMDS_MeshElement*> aNodeSet;
1380 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
1382 const SMDS_MeshElement* anElem = theMesh->FindElement( theElemIds[ i ] );
1385 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
1386 while ( anIter->more() )
1388 const SMDS_MeshElement* aNode = anIter->next();
1390 aNodeSet.insert( aNode );
1395 set<const SMDS_MeshElement*>::const_iterator anIter;
1396 for ( anIter = aNodeSet.begin(); anIter != aNodeSet.end(); ++anIter )
1397 theResList.push_back( *anIter );
1399 return theResList.size();
1402 //=================================================================================
1403 // function : getPointers
1404 // purpose : Get std::list<const SMDS_MeshElement*> from list of IDs
1405 //=================================================================================
1406 static int getPointers( const SMDSAbs_ElementType theRequestType,
1407 SMESH::long_array_var& theElemIds,
1408 const SMDS_Mesh* theMesh,
1409 std::list<const SMDS_MeshElement*>& theResList )
1411 for ( CORBA::Long i = 0, n = theElemIds->length(); i < n; i++ )
1413 const SMDS_MeshElement* anElem = theRequestType == SMDSAbs_Node
1414 ? theMesh->FindNode( theElemIds[ i ] ) : theMesh->FindElement( theElemIds[ i ] );
1417 theResList.push_back( anElem );
1420 return theResList.size();
1424 //=================================================================================
1425 // function : GetEntities
1426 // purpose : Get entities of specified type. Return number of entities
1427 //=================================================================================
1428 int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const
1430 if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType){
1431 return myGroupServer->Size();
1436 int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
1439 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
1441 if ( myGroupServer->Size() == 0 || aMesh == 0 )
1444 SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType());
1445 SMESH::long_array_var anIds = myGroupServer->GetListOfID();
1447 if ( aGrpType == theType )
1448 return getPointers( theType, anIds, aMesh, theResList );
1449 else if ( theType == SMDSAbs_Node )
1450 return getNodesFromElems( anIds, aMesh, theResList );
1458 Class : SMESH_subMeshObj
1459 Description : Class for visualisation of submeshes
1462 //=================================================================================
1463 // function : SMESH_subMeshObj
1464 // purpose : Constructor
1465 //=================================================================================
1466 SMESH_subMeshObj::SMESH_subMeshObj( SMESH::SMESH_subMesh_ptr theSubMesh,
1467 SMESH_MeshObj* theMeshObj )
1468 : SMESH_SubMeshObj( theMeshObj ),
1469 mySubMeshServer( SMESH::SMESH_subMesh::_duplicate( theSubMesh ) )
1471 if ( MYDEBUG ) MESSAGE( "SMESH_subMeshObj - theSubMesh->_is_nil() = " << theSubMesh->_is_nil() );
1473 mySubMeshServer->Register();
1476 SMESH_subMeshObj::~SMESH_subMeshObj()
1478 if ( MYDEBUG ) MESSAGE( "~SMESH_subMeshObj" );
1479 mySubMeshServer->Destroy();
1482 //=================================================================================
1483 // function : GetEntities
1484 // purpose : Get entities of specified type. Return number of entities
1485 //=================================================================================
1486 int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const
1492 return mySubMeshServer->GetNumberOfNodes( false );
1497 case SMDSAbs_Volume:
1499 SMESH::long_array_var anIds =
1500 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1501 return anIds->length();
1509 int SMESH_subMeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList ) const
1513 SMDS_Mesh* aMesh = myMeshObj->GetMesh();
1517 bool isNodal = IsNodePrs();
1521 if ( theType == SMDSAbs_Node )
1523 SMESH::long_array_var anIds = mySubMeshServer->GetNodesId();
1524 return getPointers( SMDSAbs_Node, anIds, aMesh, theResList );
1529 if ( theType == SMDSAbs_Node )
1531 SMESH::long_array_var anIds = mySubMeshServer->GetElementsId();
1532 return getNodesFromElems( anIds, aMesh, theResList );
1536 SMESH::long_array_var anIds =
1537 mySubMeshServer->GetElementsByType( SMESH::ElementType(theType) );
1538 return getPointers( theType, anIds, aMesh, theResList );
1545 //=================================================================================
1546 // function : IsNodePrs
1547 // purpose : Return true if node presentation is used
1548 //=================================================================================
1549 bool SMESH_subMeshObj::IsNodePrs() const
1551 return mySubMeshServer->GetNumberOfElements() == 0;