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_VtkEdge.hxx"
21 #include "SMDS_MeshNode.hxx"
22 #include "SMDS_Mesh.hxx"
23 #include "SMDS_VtkCellIterator.hxx"
25 #include "utilities.h"
32 SMDS_VtkEdge::SMDS_VtkEdge()
36 SMDS_VtkEdge::SMDS_VtkEdge(std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
41 SMDS_VtkEdge::~SMDS_VtkEdge()
45 void SMDS_VtkEdge::init(std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
47 SMDS_MeshEdge::init();
48 vtkUnstructuredGrid* grid = mesh->getGrid();
49 myMeshId = mesh->getMeshId();
50 vtkIdType aType = VTK_LINE;
51 if (nodeIds.size() == 3)
52 aType = VTK_QUADRATIC_EDGE;
53 myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
54 mesh->setMyModified();
55 //MESSAGE("SMDS_VtkEdge::init myVtkID " << myVtkID);
58 bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2)
60 const SMDS_MeshNode* nodes[] = { node1, node2 };
61 SMDS_Mesh::_meshList[myMeshId]->setMyModified();
62 return ChangeNodes(nodes, 2);
65 bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
67 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
70 grid->GetCellPoints(myVtkID, npts, pts);
73 MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
76 for (int i = 0; i < nbNodes; i++)
78 pts[i] = nodes[i]->getVtkId();
80 SMDS_Mesh::_meshList[myMeshId]->setMyModified();
84 bool SMDS_VtkEdge::IsMediumNode(const SMDS_MeshNode* node) const
86 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
89 grid->GetCellPoints(myVtkID, npts, pts);
90 //MESSAGE("IsMediumNode " << npts << " " << (node->getVtkId() == pts[npts-1]));
91 return ((npts == 3) && (node->getVtkId() == pts[2]));
94 void SMDS_VtkEdge::Print(std::ostream & OS) const
96 OS << "edge <" << GetID() << "> : ";
99 int SMDS_VtkEdge::NbNodes() const
101 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
102 int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
103 assert(nbPoints >= 2);
107 int SMDS_VtkEdge::NbEdges() const
112 SMDSAbs_EntityType SMDS_VtkEdge::GetEntityType() const
115 return SMDSEntity_Edge;
117 return SMDSEntity_Quad_Edge;
120 vtkIdType SMDS_VtkEdge::GetVtkType() const
125 return VTK_QUADRATIC_EDGE;
130 * \brief Return node by its index
131 * \param ind - node index
132 * \retval const SMDS_MeshNode* - the node
135 SMDS_VtkEdge::GetNode(const int ind) const
137 vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
138 vtkIdType npts, *pts;
139 grid->GetCellPoints( this->myVtkID, npts, pts );
140 return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]);
143 bool SMDS_VtkEdge::IsQuadratic() const
145 if (this->NbNodes() > 2)
151 SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) const
156 return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
158 MESSAGE("ERROR : Iterator not implemented");
159 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
163 SMDS_NodeIteratorPtr SMDS_VtkEdge::nodesIteratorToUNV() const
165 return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
168 SMDS_NodeIteratorPtr SMDS_VtkEdge::interlacedNodesIterator() const
170 return nodesIteratorToUNV();