Salome HOME
#16648 [CEA] RadialQuadrangle algorithm hypothesis change requires a Clear Mesh Data...
[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( TVtkIdList&        vtkIds,
27                             SMDS_Mesh*         mesh,
28                             int                vtkCellId,
29                             SMDSAbs_EntityType type )
30 {
31   vtkUnstructuredGrid*         grid = mesh->GetGrid();
32   const std::vector<int>& interlace = SMDS_MeshCell::fromVtkOrder( type );
33   vtkIdType npts, *pts;
34   grid->GetCellPoints( vtkCellId, npts, pts );
35   vtkIds.resize( npts );
36   if ( interlace.empty() )
37   {
38     vtkIds.assign( pts, pts + npts );
39   }
40   else
41   {
42     for (vtkIdType i = 0; i < npts; i++)
43       vtkIds[ i ] = pts[ interlace[i] ];
44   }
45 }
46
47 _GetVtkNodesToUNV::_GetVtkNodesToUNV( TVtkIdList&        vtkIds,
48                                       SMDS_Mesh*         mesh,
49                                       int                vtkCellId,
50                                       SMDSAbs_EntityType type )
51 {
52   vtkUnstructuredGrid* grid = mesh->GetGrid();
53   vtkIdType npts, *pts;
54   grid->GetCellPoints( vtkCellId, npts, pts );
55   const int *ids = 0;
56   switch ( type )
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( type, npts );
119     if ( !i.empty() )
120       ids = & i[0];
121   }
122
123   vtkIds.resize( npts );
124
125   if ( ids )
126     for (int i = 0; i < npts; i++)
127       vtkIds[ i ] =  pts[ ids[i] ];
128   else
129     vtkIds.assign( pts, pts + npts );
130 }
131
132 _GetVtkNodesPolyh::_GetVtkNodesPolyh( TVtkIdList&        vtkIds,
133                                       SMDS_Mesh*         mesh,
134                                       int                vtkCellId,
135                                       SMDSAbs_EntityType type )
136 {
137   vtkUnstructuredGrid* grid = mesh->GetGrid();
138   switch ( type )
139   {
140   case SMDSEntity_Polyhedra:
141   {
142     vtkIdType nFaces = 0;
143     vtkIdType* ptIds = 0;
144     grid->GetFaceStream( vtkCellId, nFaces, ptIds );
145     int id = 0, nbNodesInFaces = 0;
146     for ( int i = 0; i < nFaces; i++ )
147     {
148       int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
149       nbNodesInFaces += nodesInFace;
150       id += (nodesInFace + 1);
151     }
152     vtkIds.resize( nbNodesInFaces );
153     id = 0;
154     int n = 0;
155     for ( int i = 0; i < nFaces; i++ )
156     {
157       int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
158       for ( int k = 1; k <= nodesInFace; k++ )
159         vtkIds[ n++ ] = ptIds[ id + k ];
160       id += (nodesInFace + 1);
161     }
162     break;
163   }
164   default:
165     assert(0);
166   }
167 }