Back to index

salome-smesh  6.5.0
SMDS_VtkEdge.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "SMDS_VtkEdge.hxx"
00021 #include "SMDS_MeshNode.hxx"
00022 #include "SMDS_Mesh.hxx"
00023 #include "SMDS_VtkCellIterator.hxx"
00024 
00025 #include "utilities.h"
00026 
00027 #include <vector>
00028 #include <cassert>
00029 
00030 using namespace std;
00031 
00032 SMDS_VtkEdge::SMDS_VtkEdge()
00033 {
00034 }
00035 
00036 SMDS_VtkEdge::SMDS_VtkEdge(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
00037 {
00038   init(nodeIds, mesh);
00039 }
00040 
00041 SMDS_VtkEdge::~SMDS_VtkEdge()
00042 {
00043 }
00044 
00045 void SMDS_VtkEdge::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
00046 {
00047   SMDS_MeshEdge::init();
00048   vtkUnstructuredGrid* grid = mesh->getGrid();
00049   myMeshId = mesh->getMeshId();
00050   vtkIdType aType = VTK_LINE;
00051   if (nodeIds.size() == 3)
00052     aType = VTK_QUADRATIC_EDGE;
00053   myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
00054   mesh->setMyModified();
00055   //MESSAGE("SMDS_VtkEdge::init myVtkID " << myVtkID);
00056 }
00057 
00058 bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2)
00059 {
00060   const SMDS_MeshNode* nodes[] = { node1, node2 };
00061   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
00062   return ChangeNodes(nodes, 2);
00063 }
00064 
00065 bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
00066 {
00067   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00068   vtkIdType npts = 0;
00069   vtkIdType* pts = 0;
00070   grid->GetCellPoints(myVtkID, npts, pts);
00071   if (nbNodes != npts)
00072     {
00073       MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
00074       return false;
00075     }
00076   for (int i = 0; i < nbNodes; i++)
00077     {
00078       pts[i] = nodes[i]->getVtkId();
00079     }
00080   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
00081   return true;
00082 }
00083 
00084 bool SMDS_VtkEdge::IsMediumNode(const SMDS_MeshNode* node) const
00085 {
00086   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00087   vtkIdType npts = 0;
00088   vtkIdType* pts = 0;
00089   grid->GetCellPoints(myVtkID, npts, pts);
00090   //MESSAGE("IsMediumNode " << npts  << " " << (node->getVtkId() == pts[npts-1]));
00091   return ((npts == 3) && (node->getVtkId() == pts[2]));
00092 }
00093 
00094 void SMDS_VtkEdge::Print(std::ostream & OS) const
00095 {
00096   OS << "edge <" << GetID() << "> : ";
00097 }
00098 
00099 int SMDS_VtkEdge::NbNodes() const
00100 {
00101   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00102   int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
00103   assert(nbPoints >= 2);
00104   return nbPoints;
00105 }
00106 
00107 int SMDS_VtkEdge::NbEdges() const
00108 {
00109   return 1;
00110 }
00111 
00112 SMDSAbs_EntityType SMDS_VtkEdge::GetEntityType() const
00113 {
00114   if (NbNodes() == 2)
00115     return SMDSEntity_Edge;
00116   else
00117     return SMDSEntity_Quad_Edge;
00118 }
00119 
00120 vtkIdType SMDS_VtkEdge::GetVtkType() const
00121 {
00122   if (NbNodes() == 2)
00123     return VTK_LINE;
00124   else
00125     return VTK_QUADRATIC_EDGE;
00126 
00127 }
00128 
00134 const SMDS_MeshNode*
00135 SMDS_VtkEdge::GetNode(const int ind) const
00136 {
00137   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00138   vtkIdType npts, *pts;
00139   grid->GetCellPoints( this->myVtkID, npts, pts );
00140   return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]);
00141 }
00142 
00143 bool SMDS_VtkEdge::IsQuadratic() const
00144 {
00145   if (this->NbNodes() > 2)
00146     return true;
00147   else
00148     return false;
00149 }
00150 
00151 SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) const
00152 {
00153   switch (type)
00154   {
00155     case SMDSAbs_Node:
00156       return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00157     default:
00158       MESSAGE("ERROR : Iterator not implemented")
00159       ;
00160       return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
00161   }
00162 }
00163 
00164 SMDS_ElemIteratorPtr SMDS_VtkEdge::nodesIteratorToUNV() const
00165 {
00166   return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00167 }
00168 
00169 SMDS_ElemIteratorPtr SMDS_VtkEdge::interlacedNodesElemIterator() const
00170 {
00171   return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00172 }