Salome HOME
55570417b330d78381b627a807b41c431ef8a48f
[modules/smesh.git] / src / SMDS / SMDS_VtkCellIterator.cxx
1 // Copyright (C) 2010-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SMDS_VtkCellIterator.hxx"
21 #include "utilities.h"
22
23 #include <vtkCell.h>
24 #include <vtkIdList.h>
25
26 _GetVtkNodes::_GetVtkNodes( vtkIdList*         _vtkIdList,
27                             SMDS_Mesh*         mesh,
28                             int                vtkCellId,
29                             SMDSAbs_EntityType aType )
30 {
31   vtkUnstructuredGrid* grid = mesh->GetGrid();
32   const std::vector<int>& interlace = SMDS_MeshCell::fromVtkOrder( aType );
33   if ( interlace.empty() )
34   {
35     grid->GetCellPoints( vtkCellId, _vtkIdList );
36   }
37   else
38   {
39     vtkIdType npts, *pts;
40     grid->GetCellPoints( vtkCellId, npts, pts );
41     _vtkIdList->SetNumberOfIds( npts );
42     for (int i = 0; i < npts; i++)
43       _vtkIdList->SetId(i, pts[interlace[i]]);
44   }
45 }
46
47 _GetVtkNodesToUNV::_GetVtkNodesToUNV( vtkIdList*         _vtkIdList,
48                                       SMDS_Mesh*         mesh,
49                                       int                vtkCellId,
50                                       SMDSAbs_EntityType aType )
51 {
52   vtkIdType * pts, npts;
53   vtkUnstructuredGrid* grid = mesh->GetGrid();
54   grid->GetCellPoints( (vtkIdType)vtkCellId, npts, pts );
55   const int *ids = 0;
56   switch (aType)
57   {
58   case SMDSEntity_Quad_Edge:
59   {
60     static int id[] = { 0, 2, 1 };
61     ids = id;
62     break;
63   }
64   case SMDSEntity_Quad_Triangle:
65   case SMDSEntity_BiQuad_Triangle:
66   {
67     static int id[] = { 0, 3, 1, 4, 2, 5 };
68     ids = id;
69     npts = 6;
70     break;
71   }
72   case SMDSEntity_Quad_Quadrangle:
73   case SMDSEntity_BiQuad_Quadrangle:
74   {
75     static int id[] = { 0, 4, 1, 5, 2, 6, 3, 7 };
76     ids = id;
77     npts = 8;
78     break;
79   }
80   case SMDSEntity_Quad_Tetra:
81   {
82     static int id[] = { 0, 4, 1, 5, 2, 6, 7, 8, 9, 3 };
83     ids = id;
84     break;
85   }
86   case SMDSEntity_Quad_Pyramid:
87   {
88     static int id[] = { 0, 5, 1, 6, 2, 7, 3, 8, 9, 10, 11, 12, 4 };
89     ids = id;
90     break;
91   }
92   case SMDSEntity_Penta:
93   {
94     static int id[] = { 0, 2, 1, 3, 5, 4 };
95     ids = id;
96     break;
97   }
98   case SMDSEntity_Quad_Penta:
99   case SMDSEntity_BiQuad_Penta: //TODO: check
100   {
101     static int id[] = { 0, 8, 2, 7, 1, 6, 12, 14, 13, 3, 11, 5, 10, 4, 9 };
102     ids = id;
103     break;
104   }
105   case SMDSEntity_Quad_Hexa:
106   case SMDSEntity_TriQuad_Hexa:
107   {
108     static int id[] = { 0, 8, 1, 9, 2, 10, 3, 11, 16, 17, 18, 19, 4, 12, 5, 13, 6, 14, 7, 15 };
109     ids = id;
110     npts = 20;
111     break;
112   }
113   case SMDSEntity_Polygon:
114   case SMDSEntity_Quad_Polygon:
115   case SMDSEntity_Polyhedra:
116   case SMDSEntity_Quad_Polyhedra:
117   default:
118     const std::vector<int>& i = SMDS_MeshCell::interlacedSmdsOrder( aType, npts );
119     if ( !i.empty() )
120       ids = & i[0];
121   }
122
123   _vtkIdList->SetNumberOfIds( npts );
124
125   if ( ids )
126     for (int i = 0; i < npts; i++)
127       _vtkIdList->SetId(i, pts[ids[i]]);
128   else
129     for (int i = 0; i < npts; i++)
130       _vtkIdList->SetId(i, pts[i]);
131 }
132
133 _GetVtkNodesPolyh::_GetVtkNodesPolyh( vtkIdList*         _vtkIdList,
134                                       SMDS_Mesh*         mesh,
135                                       int                vtkCellId,
136                                       SMDSAbs_EntityType aType )
137 {
138   vtkUnstructuredGrid* grid = mesh->GetGrid();
139   switch (aType)
140   {
141   case SMDSEntity_Polyhedra:
142   {
143     vtkIdType nFaces = 0;
144     vtkIdType* ptIds = 0;
145     grid->GetFaceStream( vtkCellId, nFaces, ptIds );
146     int id = 0, nbNodesInFaces = 0;
147     for (int i = 0; i < nFaces; i++)
148     {
149       int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
150       nbNodesInFaces += nodesInFace;
151       id += (nodesInFace + 1);
152     }
153     _vtkIdList->SetNumberOfIds( nbNodesInFaces );
154     id = 0;
155     int n = 0;
156     for (int i = 0; i < nFaces; i++)
157     {
158       int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
159       for (int k = 1; k <= nodesInFace; k++)
160         _vtkIdList->SetId(n++, ptIds[id + k]);
161       id += (nodesInFace + 1);
162     }
163     break;
164   }
165   default:
166     assert(0);
167   }
168 }