1 // Copyright (C) 2010-2011 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.
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(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
40 SMDS_VtkFace::~SMDS_VtkFace()
44 void SMDS_VtkFace::init(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;
68 myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
69 mesh->setMyModified();
70 //MESSAGE("SMDS_VtkFace::init myVtkID " << myVtkID);
73 void SMDS_VtkFace::initPoly(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
75 SMDS_MeshFace::init();
76 vtkUnstructuredGrid* grid = mesh->getGrid();
77 myMeshId = mesh->getMeshId();
78 myVtkID = grid->InsertNextLinkedCell(VTK_POLYGON, nodeIds.size(), &nodeIds[0]);
79 mesh->setMyModified();
82 bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
84 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
87 grid->GetCellPoints(myVtkID, npts, pts);
90 MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
93 for (int i = 0; i < nbNodes; i++)
95 pts[i] = nodes[i]->getVtkId();
97 SMDS_Mesh::_meshList[myMeshId]->setMyModified();
101 void SMDS_VtkFace::Print(std::ostream & OS) const
103 OS << "face <" << GetID() << "> : ";
106 int SMDS_VtkFace::NbEdges() const
108 // TODO quadratic polygons ?
109 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
110 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
115 case VTK_QUADRATIC_TRIANGLE:
119 case VTK_QUADRATIC_QUAD:
124 nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints();
130 int SMDS_VtkFace::NbFaces() const
135 int SMDS_VtkFace::NbNodes() const
137 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
138 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
143 * \brief Return node by its index
144 * \param ind - node index
145 * \retval const SMDS_MeshNode* - the node
148 SMDS_VtkFace::GetNode(const int ind) const
150 return SMDS_MeshElement::GetNode(ind); // --- a optimiser !
153 bool SMDS_VtkFace::IsQuadratic() const
155 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
156 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
157 // TODO quadratic polygons ?
160 case VTK_QUADRATIC_TRIANGLE:
161 case VTK_QUADRATIC_QUAD:
169 bool SMDS_VtkFace::IsPoly() const
171 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
172 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
173 return (aVtkType == VTK_POLYGON);
176 bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
178 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
179 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
180 int rankFirstMedium = 0;
183 case VTK_QUADRATIC_TRIANGLE:
184 rankFirstMedium = 3; // medium nodes are of rank 3,4,5
186 case VTK_QUADRATIC_QUAD:
187 rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
190 //MESSAGE("wrong element type " << aVtkType);
195 grid->GetCellPoints(myVtkID, npts, pts);
196 vtkIdType nodeId = node->getVtkId();
197 for (int rank = 0; rank < npts; rank++)
199 if (pts[rank] == nodeId)
201 //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium));
202 if (rank < rankFirstMedium)
208 //throw SALOME_Exception(LOCALIZED("node does not belong to this element"));
209 MESSAGE("======================================================");
210 MESSAGE("= IsMediumNode: node does not belong to this element =");
211 MESSAGE("======================================================");
215 SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
217 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
218 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
219 SMDSAbs_EntityType aType = SMDSEntity_Polygon;
223 aType = SMDSEntity_Triangle;
226 aType = SMDSEntity_Quadrangle;
228 case VTK_QUADRATIC_TRIANGLE:
229 aType = SMDSEntity_Quad_Triangle;
231 case VTK_QUADRATIC_QUAD:
232 aType = SMDSEntity_Quad_Quadrangle;
235 aType = SMDSEntity_Polygon;
240 vtkIdType SMDS_VtkFace::GetVtkType() const
242 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
243 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
247 SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
252 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
254 MESSAGE("ERROR : Iterator not implemented")
256 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
260 SMDS_ElemIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const
262 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
265 SMDS_ElemIteratorPtr SMDS_VtkFace::interlacedNodesElemIterator() const
267 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
270 //! change only the first node, used for temporary triangles in quadrangle to triangle adaptor
271 void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node)
273 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
276 grid->GetCellPoints(myVtkID, npts, pts);
277 grid->RemoveReferenceToCell(pts[0], myVtkID);
278 pts[0] = node->getVtkId();
279 node->AddInverseElement(this),
280 SMDS_Mesh::_meshList[myMeshId]->setMyModified();