1 // Copyright (C) 2010-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SMDS_VtkFace.hxx"
21 #include "SMDS_MeshNode.hxx"
22 #include "SMDS_Mesh.hxx"
23 #include "SMDS_VtkCellIterator.hxx"
25 #include "utilities.h"
31 SMDS_VtkFace::SMDS_VtkFace()
35 SMDS_VtkFace::SMDS_VtkFace(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
40 SMDS_VtkFace::~SMDS_VtkFace()
44 void SMDS_VtkFace::init(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
46 SMDS_MeshFace::init();
47 myMeshId = mesh->getMeshId();
48 vtkIdType aType = VTK_TRIANGLE;
49 switch (nodeIds.size())
51 case 3: aType = VTK_TRIANGLE; break;
52 case 4: aType = VTK_QUAD; break;
53 case 6: aType = VTK_QUADRATIC_TRIANGLE; break;
54 case 8: aType = VTK_QUADRATIC_QUAD; break;
55 case 9: aType = VTK_BIQUADRATIC_QUAD; break;
56 case 7: aType = VTK_BIQUADRATIC_TRIANGLE;break;
57 default: aType = VTK_POLYGON;
59 myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
60 mesh->setMyModified();
63 void SMDS_VtkFace::initPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
65 SMDS_MeshFace::init();
66 myMeshId = mesh->getMeshId();
67 vtkIdType aType = VTK_POLYGON;
68 myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
69 mesh->setMyModified();
72 void SMDS_VtkFace::initQuadPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
74 SMDS_MeshFace::init();
75 myMeshId = mesh->getMeshId();
76 vtkIdType aType = VTK_QUADRATIC_POLYGON;
77 myVtkID = mesh->getGrid()->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
78 mesh->setMyModified();
81 bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
83 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
86 grid->GetCellPoints(myVtkID, npts, pts);
89 MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
92 for (int i = 0; i < nbNodes; i++)
94 pts[i] = nodes[i]->getVtkId();
96 SMDS_Mesh::_meshList[myMeshId]->setMyModified();
100 void SMDS_VtkFace::Print(std::ostream & OS) const
102 OS << "face <" << GetID() << "> : ";
105 int SMDS_VtkFace::NbEdges() const
107 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
108 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
113 case VTK_QUADRATIC_TRIANGLE:
114 case VTK_BIQUADRATIC_TRIANGLE:
118 case VTK_QUADRATIC_QUAD:
119 case VTK_BIQUADRATIC_QUAD:
122 case VTK_QUADRATIC_POLYGON:
123 nbEdges = NbNodes() / 2;
133 int SMDS_VtkFace::NbFaces() const
138 int SMDS_VtkFace::NbNodes() const
140 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
141 vtkIdType *pts, npts;
142 grid->GetCellPoints( myVtkID, npts, pts );
147 * \brief Return node by its index
148 * \param ind - node index
149 * \retval const SMDS_MeshNode* - the node
152 SMDS_VtkFace::GetNode(const int ind) const
154 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
155 vtkIdType npts, *pts;
156 grid->GetCellPoints( this->myVtkID, npts, pts );
157 return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]);
161 * \brief Check if a node belongs to the element
162 * \param node - the node to check
163 * \retval int - node index within the element, -1 if not found
165 int SMDS_VtkFace::GetNodeIndex( const SMDS_MeshNode* node ) const
167 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
168 vtkIdType npts, *pts;
169 grid->GetCellPoints( this->myVtkID, npts, pts );
170 for ( vtkIdType i = 0; i < npts; ++i )
171 if ( pts[i] == node->getVtkId() )
176 bool SMDS_VtkFace::IsQuadratic() const
178 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
179 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
180 // TODO quadratic polygons ?
183 case VTK_QUADRATIC_TRIANGLE:
184 case VTK_QUADRATIC_QUAD:
185 case VTK_QUADRATIC_POLYGON:
186 case VTK_BIQUADRATIC_QUAD:
187 case VTK_BIQUADRATIC_TRIANGLE:
195 bool SMDS_VtkFace::IsPoly() const
197 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
198 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
199 return ( aVtkType == VTK_POLYGON || aVtkType == VTK_QUADRATIC_POLYGON );
202 bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
204 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
207 grid->GetCellPoints(myVtkID, npts, pts);
209 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
210 int rankFirstMedium = 0;
213 case VTK_QUADRATIC_TRIANGLE:
214 case VTK_BIQUADRATIC_TRIANGLE:
215 rankFirstMedium = 3; // medium nodes are of rank 3,4,5
217 case VTK_QUADRATIC_QUAD:
218 case VTK_BIQUADRATIC_QUAD:
219 rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
221 case VTK_QUADRATIC_POLYGON:
222 rankFirstMedium = npts / 2;
225 //MESSAGE("wrong element type " << aVtkType);
228 vtkIdType nodeId = node->getVtkId();
229 for (int rank = 0; rank < npts; rank++)
231 if (pts[rank] == nodeId)
233 //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium));
234 if (rank < rankFirstMedium)
240 //throw SALOME_Exception(LOCALIZED("node does not belong to this element"));
241 MESSAGE("======================================================");
242 MESSAGE("= IsMediumNode: node does not belong to this element =");
243 MESSAGE("======================================================");
247 int SMDS_VtkFace::NbCornerNodes() const
249 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
250 int nbPoints = NbNodes();
251 vtkIdType aVtkType = grid->GetCellType(myVtkID);
256 case VTK_QUADRATIC_POLYGON:
266 SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
268 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
269 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
270 return SMDS_MeshCell::toSmdsType( VTKCellType( aVtkType ));
273 SMDSAbs_GeometryType SMDS_VtkFace::GetGeomType() const
275 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
276 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
277 switch ( aVtkType ) {
279 case VTK_QUADRATIC_TRIANGLE:
280 case VTK_BIQUADRATIC_TRIANGLE: return SMDSGeom_TRIANGLE;
283 case VTK_QUADRATIC_QUAD:
284 case VTK_BIQUADRATIC_QUAD: return SMDSGeom_QUADRANGLE;
287 case VTK_QUADRATIC_POLYGON: return SMDSGeom_POLYGON;
290 return SMDSGeom_NONE;
293 vtkIdType SMDS_VtkFace::GetVtkType() const
295 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
296 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
300 SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
305 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
307 MESSAGE("ERROR : Iterator not implemented")
309 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
313 SMDS_NodeIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const
315 return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
318 SMDS_NodeIteratorPtr SMDS_VtkFace::interlacedNodesIterator() const
320 return nodesIteratorToUNV();
323 //! change only the first node, used for temporary triangles in quadrangle to triangle adaptor
324 void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node)
326 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
329 grid->GetCellPoints(myVtkID, npts, pts);
330 grid->RemoveReferenceToCell(pts[0], myVtkID);
331 pts[0] = node->getVtkId();
332 node->AddInverseElement(this),
333 SMDS_Mesh::_meshList[myMeshId]->setMyModified();