1 // Copyright (C) 2010-2014 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 vtkUnstructuredGrid* grid = mesh->getGrid();
48 myMeshId = mesh->getMeshId();
49 vtkIdType aType = VTK_TRIANGLE;
50 switch (nodeIds.size())
59 aType = VTK_QUADRATIC_TRIANGLE;
62 aType = VTK_QUADRATIC_QUAD;
65 aType = VTK_BIQUADRATIC_QUAD;
68 aType = VTK_BIQUADRATIC_TRIANGLE;
74 myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
75 mesh->setMyModified();
76 //MESSAGE("SMDS_VtkFace::init myVtkID " << myVtkID);
79 void SMDS_VtkFace::initPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
81 SMDS_MeshFace::init();
82 vtkUnstructuredGrid* grid = mesh->getGrid();
83 myMeshId = mesh->getMeshId();
84 myVtkID = grid->InsertNextLinkedCell(VTK_POLYGON, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
85 mesh->setMyModified();
88 bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
90 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
93 grid->GetCellPoints(myVtkID, npts, pts);
96 MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
99 for (int i = 0; i < nbNodes; i++)
101 pts[i] = nodes[i]->getVtkId();
103 SMDS_Mesh::_meshList[myMeshId]->setMyModified();
107 void SMDS_VtkFace::Print(std::ostream & OS) const
109 OS << "face <" << GetID() << "> : ";
112 int SMDS_VtkFace::NbEdges() const
114 // TODO quadratic polygons ?
115 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
116 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
121 case VTK_QUADRATIC_TRIANGLE:
122 case VTK_BIQUADRATIC_TRIANGLE:
126 case VTK_QUADRATIC_QUAD:
127 case VTK_BIQUADRATIC_QUAD:
132 nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints();
138 int SMDS_VtkFace::NbFaces() const
143 int SMDS_VtkFace::NbNodes() const
145 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
146 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
151 * \brief Return node by its index
152 * \param ind - node index
153 * \retval const SMDS_MeshNode* - the node
156 SMDS_VtkFace::GetNode(const int ind) const
158 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
159 vtkIdType npts, *pts;
160 grid->GetCellPoints( this->myVtkID, npts, pts );
161 return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]);
165 * \brief Check if a node belongs to the element
166 * \param node - the node to check
167 * \retval int - node index within the element, -1 if not found
169 int SMDS_VtkFace::GetNodeIndex( const SMDS_MeshNode* node ) const
171 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
172 vtkIdType npts, *pts;
173 grid->GetCellPoints( this->myVtkID, npts, pts );
174 for ( vtkIdType i = 0; i < npts; ++i )
175 if ( pts[i] == node->getVtkId() )
180 bool SMDS_VtkFace::IsQuadratic() const
182 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
183 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
184 // TODO quadratic polygons ?
187 case VTK_QUADRATIC_TRIANGLE:
188 case VTK_QUADRATIC_QUAD:
189 case VTK_BIQUADRATIC_QUAD:
190 case VTK_BIQUADRATIC_TRIANGLE:
198 bool SMDS_VtkFace::IsPoly() const
200 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
201 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
202 return (aVtkType == VTK_POLYGON);
205 bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
207 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
208 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
209 int rankFirstMedium = 0;
212 case VTK_QUADRATIC_TRIANGLE:
213 case VTK_BIQUADRATIC_TRIANGLE:
214 rankFirstMedium = 3; // medium nodes are of rank 3,4,5
216 case VTK_QUADRATIC_QUAD:
217 case VTK_BIQUADRATIC_QUAD:
218 rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
221 //MESSAGE("wrong element type " << aVtkType);
226 grid->GetCellPoints(myVtkID, npts, pts);
227 vtkIdType nodeId = node->getVtkId();
228 for (int rank = 0; rank < npts; rank++)
230 if (pts[rank] == nodeId)
232 //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium));
233 if (rank < rankFirstMedium)
239 //throw SALOME_Exception(LOCALIZED("node does not belong to this element"));
240 MESSAGE("======================================================");
241 MESSAGE("= IsMediumNode: node does not belong to this element =");
242 MESSAGE("======================================================");
246 int SMDS_VtkFace::NbCornerNodes() const
248 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
249 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
250 vtkIdType aVtkType = grid->GetCellType(myVtkID);
251 if ( aVtkType != VTK_POLYGON )
252 return nbPoints <= 4 ? nbPoints : nbPoints / 2;
256 SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
258 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
259 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
260 return SMDS_MeshCell::toSmdsType( VTKCellType( aVtkType ));
263 SMDSAbs_GeometryType SMDS_VtkFace::GetGeomType() const
265 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
266 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
267 switch ( aVtkType ) {
269 case VTK_QUADRATIC_TRIANGLE:
270 case VTK_BIQUADRATIC_TRIANGLE: return SMDSGeom_TRIANGLE;
273 case VTK_QUADRATIC_QUAD:
274 case VTK_BIQUADRATIC_QUAD: return SMDSGeom_QUADRANGLE;
276 case VTK_POLYGON: return SMDSGeom_POLYGON;
279 return SMDSGeom_NONE;
282 vtkIdType SMDS_VtkFace::GetVtkType() const
284 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
285 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
289 SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
294 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
296 MESSAGE("ERROR : Iterator not implemented")
298 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
302 SMDS_NodeIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const
304 return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
307 SMDS_NodeIteratorPtr SMDS_VtkFace::interlacedNodesIterator() const
309 return nodesIteratorToUNV();
312 //! change only the first node, used for temporary triangles in quadrangle to triangle adaptor
313 void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node)
315 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
318 grid->GetCellPoints(myVtkID, npts, pts);
319 grid->RemoveReferenceToCell(pts[0], myVtkID);
320 pts[0] = node->getVtkId();
321 node->AddInverseElement(this),
322 SMDS_Mesh::_meshList[myMeshId]->setMyModified();