1 // Copyright (C) 2010-2015 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 void SMDS_VtkFace::initQuadPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
90 SMDS_MeshFace::init();
91 vtkUnstructuredGrid* grid = mesh->getGrid();
92 myMeshId = mesh->getMeshId();
93 myVtkID = grid->InsertNextLinkedCell(VTK_QUADRATIC_POLYGON, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
94 mesh->setMyModified();
97 bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
99 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
102 grid->GetCellPoints(myVtkID, npts, pts);
105 MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
108 for (int i = 0; i < nbNodes; i++)
110 pts[i] = nodes[i]->getVtkId();
112 SMDS_Mesh::_meshList[myMeshId]->setMyModified();
116 void SMDS_VtkFace::Print(std::ostream & OS) const
118 OS << "face <" << GetID() << "> : ";
121 int SMDS_VtkFace::NbEdges() const
123 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
124 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
129 case VTK_QUADRATIC_TRIANGLE:
130 case VTK_BIQUADRATIC_TRIANGLE:
134 case VTK_QUADRATIC_QUAD:
135 case VTK_BIQUADRATIC_QUAD:
138 case VTK_QUADRATIC_POLYGON:
139 nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints() / 2;
143 nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints();
149 int SMDS_VtkFace::NbFaces() const
154 int SMDS_VtkFace::NbNodes() const
156 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
157 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
162 * \brief Return node by its index
163 * \param ind - node index
164 * \retval const SMDS_MeshNode* - the node
167 SMDS_VtkFace::GetNode(const int ind) const
169 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
170 vtkIdType npts, *pts;
171 grid->GetCellPoints( this->myVtkID, npts, pts );
172 return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]);
176 * \brief Check if a node belongs to the element
177 * \param node - the node to check
178 * \retval int - node index within the element, -1 if not found
180 int SMDS_VtkFace::GetNodeIndex( const SMDS_MeshNode* node ) const
182 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
183 vtkIdType npts, *pts;
184 grid->GetCellPoints( this->myVtkID, npts, pts );
185 for ( vtkIdType i = 0; i < npts; ++i )
186 if ( pts[i] == node->getVtkId() )
191 bool SMDS_VtkFace::IsQuadratic() const
193 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
194 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
195 // TODO quadratic polygons ?
198 case VTK_QUADRATIC_TRIANGLE:
199 case VTK_QUADRATIC_QUAD:
200 case VTK_QUADRATIC_POLYGON:
201 case VTK_BIQUADRATIC_QUAD:
202 case VTK_BIQUADRATIC_TRIANGLE:
210 bool SMDS_VtkFace::IsPoly() const
212 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
213 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
214 return ( aVtkType == VTK_POLYGON || aVtkType == VTK_QUADRATIC_POLYGON );
217 bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
219 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
220 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
221 int rankFirstMedium = 0;
224 case VTK_QUADRATIC_TRIANGLE:
225 case VTK_BIQUADRATIC_TRIANGLE:
226 rankFirstMedium = 3; // medium nodes are of rank 3,4,5
228 case VTK_QUADRATIC_QUAD:
229 case VTK_BIQUADRATIC_QUAD:
230 rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
232 case VTK_QUADRATIC_POLYGON:
233 rankFirstMedium = grid->GetCell(myVtkID)->GetNumberOfPoints() / 2;
236 //MESSAGE("wrong element type " << aVtkType);
241 grid->GetCellPoints(myVtkID, npts, pts);
242 vtkIdType nodeId = node->getVtkId();
243 for (int rank = 0; rank < npts; rank++)
245 if (pts[rank] == nodeId)
247 //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium));
248 if (rank < rankFirstMedium)
254 //throw SALOME_Exception(LOCALIZED("node does not belong to this element"));
255 MESSAGE("======================================================");
256 MESSAGE("= IsMediumNode: node does not belong to this element =");
257 MESSAGE("======================================================");
261 int SMDS_VtkFace::NbCornerNodes() const
263 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
264 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
265 vtkIdType aVtkType = grid->GetCellType(myVtkID);
270 case VTK_QUADRATIC_POLYGON:
280 SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
282 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
283 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
284 return SMDS_MeshCell::toSmdsType( VTKCellType( aVtkType ));
287 SMDSAbs_GeometryType SMDS_VtkFace::GetGeomType() const
289 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
290 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
291 switch ( aVtkType ) {
293 case VTK_QUADRATIC_TRIANGLE:
294 case VTK_BIQUADRATIC_TRIANGLE: return SMDSGeom_TRIANGLE;
297 case VTK_QUADRATIC_QUAD:
298 case VTK_BIQUADRATIC_QUAD: return SMDSGeom_QUADRANGLE;
301 case VTK_QUADRATIC_POLYGON: return SMDSGeom_POLYGON;
304 return SMDSGeom_NONE;
307 vtkIdType SMDS_VtkFace::GetVtkType() const
309 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
310 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
314 SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
319 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
321 MESSAGE("ERROR : Iterator not implemented")
323 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
327 SMDS_NodeIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const
329 return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
332 SMDS_NodeIteratorPtr SMDS_VtkFace::interlacedNodesIterator() const
334 return nodesIteratorToUNV();
337 //! change only the first node, used for temporary triangles in quadrangle to triangle adaptor
338 void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node)
340 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
343 grid->GetCellPoints(myVtkID, npts, pts);
344 grid->RemoveReferenceToCell(pts[0], myVtkID);
345 pts[0] = node->getVtkId();
346 node->AddInverseElement(this),
347 SMDS_Mesh::_meshList[myMeshId]->setMyModified();