1 // Copyright (C) 2010-2012 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(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;
71 myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
72 mesh->setMyModified();
73 //MESSAGE("SMDS_VtkFace::init myVtkID " << myVtkID);
76 void SMDS_VtkFace::initPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
78 SMDS_MeshFace::init();
79 vtkUnstructuredGrid* grid = mesh->getGrid();
80 myMeshId = mesh->getMeshId();
81 myVtkID = grid->InsertNextLinkedCell(VTK_POLYGON, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
82 mesh->setMyModified();
85 bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
87 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
90 grid->GetCellPoints(myVtkID, npts, pts);
93 MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
96 for (int i = 0; i < nbNodes; i++)
98 pts[i] = nodes[i]->getVtkId();
100 SMDS_Mesh::_meshList[myMeshId]->setMyModified();
104 void SMDS_VtkFace::Print(std::ostream & OS) const
106 OS << "face <" << GetID() << "> : ";
109 int SMDS_VtkFace::NbEdges() const
111 // TODO quadratic polygons ?
112 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
113 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
118 case VTK_QUADRATIC_TRIANGLE:
122 case VTK_QUADRATIC_QUAD:
123 case VTK_BIQUADRATIC_QUAD:
128 nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints();
134 int SMDS_VtkFace::NbFaces() const
139 int SMDS_VtkFace::NbNodes() const
141 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
142 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
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 ]);
160 bool SMDS_VtkFace::IsQuadratic() const
162 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
163 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
164 // TODO quadratic polygons ?
167 case VTK_QUADRATIC_TRIANGLE:
168 case VTK_QUADRATIC_QUAD:
169 case VTK_BIQUADRATIC_QUAD:
177 bool SMDS_VtkFace::IsPoly() const
179 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
180 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
181 return (aVtkType == VTK_POLYGON);
184 bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
186 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
187 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
188 int rankFirstMedium = 0;
191 case VTK_QUADRATIC_TRIANGLE:
192 rankFirstMedium = 3; // medium nodes are of rank 3,4,5
194 case VTK_QUADRATIC_QUAD:
195 case VTK_BIQUADRATIC_QUAD:
196 rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
199 //MESSAGE("wrong element type " << aVtkType);
204 grid->GetCellPoints(myVtkID, npts, pts);
205 vtkIdType nodeId = node->getVtkId();
206 for (int rank = 0; rank < npts; rank++)
208 if (pts[rank] == nodeId)
210 //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium));
211 if (rank < rankFirstMedium)
217 //throw SALOME_Exception(LOCALIZED("node does not belong to this element"));
218 MESSAGE("======================================================");
219 MESSAGE("= IsMediumNode: node does not belong to this element =");
220 MESSAGE("======================================================");
224 int SMDS_VtkFace::NbCornerNodes() const
226 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
227 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
228 vtkIdType aVtkType = grid->GetCellType(myVtkID);
229 if ( aVtkType != VTK_POLYGON )
230 return nbPoints <= 4 ? nbPoints : nbPoints / 2;
234 SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
236 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
237 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
238 return SMDS_MeshCell::toSmdsType( VTKCellType( aVtkType ));
241 vtkIdType SMDS_VtkFace::GetVtkType() const
243 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
244 vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
248 SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
253 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
255 MESSAGE("ERROR : Iterator not implemented")
257 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
261 SMDS_ElemIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const
263 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
266 SMDS_ElemIteratorPtr SMDS_VtkFace::interlacedNodesElemIterator() const
268 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
271 //! change only the first node, used for temporary triangles in quadrangle to triangle adaptor
272 void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node)
274 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
277 grid->GetCellPoints(myVtkID, npts, pts);
278 grid->RemoveReferenceToCell(pts[0], myVtkID);
279 pts[0] = node->getVtkId();
280 node->AddInverseElement(this),
281 SMDS_Mesh::_meshList[myMeshId]->setMyModified();