Version: 6.3.1

src/SMDS/SMDS_VtkFace.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2010-2011  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_VtkFace.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 
00029 using namespace std;
00030 
00031 SMDS_VtkFace::SMDS_VtkFace()
00032 {
00033 }
00034 
00035 SMDS_VtkFace::SMDS_VtkFace(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
00036 {
00037   init(nodeIds, mesh);
00038 }
00039 
00040 SMDS_VtkFace::~SMDS_VtkFace()
00041 {
00042 }
00043 
00044 void SMDS_VtkFace::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
00045 {
00046   SMDS_MeshFace::init();
00047   vtkUnstructuredGrid* grid = mesh->getGrid();
00048   myMeshId = mesh->getMeshId();
00049   vtkIdType aType = VTK_TRIANGLE;
00050   switch (nodeIds.size())
00051   {
00052     case 3:
00053       aType = VTK_TRIANGLE;
00054       break;
00055     case 4:
00056       aType = VTK_QUAD;
00057       break;
00058     case 6:
00059       aType = VTK_QUADRATIC_TRIANGLE;
00060       break;
00061     case 8:
00062       aType = VTK_QUADRATIC_QUAD;
00063       break;
00064     default:
00065       aType = VTK_POLYGON;
00066       break;
00067   }
00068   myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
00069   mesh->setMyModified();
00070   //MESSAGE("SMDS_VtkFace::init myVtkID " << myVtkID);
00071 }
00072 
00073 void SMDS_VtkFace::initPoly(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
00074 {
00075   SMDS_MeshFace::init();
00076   vtkUnstructuredGrid* grid = mesh->getGrid();
00077   myMeshId = mesh->getMeshId();
00078   myVtkID = grid->InsertNextLinkedCell(VTK_POLYGON, nodeIds.size(), &nodeIds[0]);
00079   mesh->setMyModified();
00080 }
00081 
00082 bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
00083 {
00084   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00085   vtkIdType npts = 0;
00086   vtkIdType* pts = 0;
00087   grid->GetCellPoints(myVtkID, npts, pts);
00088   if (nbNodes != npts)
00089     {
00090       MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
00091       return false;
00092     }
00093   for (int i = 0; i < nbNodes; i++)
00094     {
00095       pts[i] = nodes[i]->getVtkId();
00096     }
00097   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
00098   return true;
00099 }
00100 
00101 void SMDS_VtkFace::Print(std::ostream & OS) const
00102 {
00103   OS << "face <" << GetID() << "> : ";
00104 }
00105 
00106 int SMDS_VtkFace::NbEdges() const
00107 {
00108   // TODO quadratic polygons ?
00109   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00110   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00111   int nbEdges = 3;
00112   switch (aVtkType)
00113   {
00114     case VTK_TRIANGLE:
00115     case VTK_QUADRATIC_TRIANGLE:
00116       nbEdges = 3;
00117       break;
00118     case VTK_QUAD:
00119     case VTK_QUADRATIC_QUAD:
00120       nbEdges = 4;
00121       break;
00122     case VTK_POLYGON:
00123     default:
00124       nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints();
00125       break;
00126   }
00127   return nbEdges;
00128 }
00129 
00130 int SMDS_VtkFace::NbFaces() const
00131 {
00132   return 1;
00133 }
00134 
00135 int SMDS_VtkFace::NbNodes() const
00136 {
00137   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00138   int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
00139   return nbPoints;
00140 }
00141 
00147 const SMDS_MeshNode*
00148 SMDS_VtkFace::GetNode(const int ind) const
00149 {
00150   return SMDS_MeshElement::GetNode(ind); // --- a optimiser !
00151 }
00152 
00153 bool SMDS_VtkFace::IsQuadratic() const
00154 {
00155   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00156   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00157   // TODO quadratic polygons ?
00158   switch (aVtkType)
00159   {
00160     case VTK_QUADRATIC_TRIANGLE:
00161     case VTK_QUADRATIC_QUAD:
00162       return true;
00163       break;
00164     default:
00165       return false;
00166   }
00167 }
00168 
00169 bool SMDS_VtkFace::IsPoly() const
00170 {
00171   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00172   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00173   return (aVtkType == VTK_POLYGON);
00174 }
00175 
00176 bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
00177 {
00178   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00179   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00180   int rankFirstMedium = 0;
00181   switch (aVtkType)
00182   {
00183     case VTK_QUADRATIC_TRIANGLE:
00184       rankFirstMedium = 3; // medium nodes are of rank 3,4,5
00185       break;
00186     case VTK_QUADRATIC_QUAD:
00187       rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
00188       break;
00189     default:
00190       //MESSAGE("wrong element type " << aVtkType);
00191       return false;
00192   }
00193   vtkIdType npts = 0;
00194   vtkIdType* pts = 0;
00195   grid->GetCellPoints(myVtkID, npts, pts);
00196   vtkIdType nodeId = node->getVtkId();
00197   for (int rank = 0; rank < npts; rank++)
00198     {
00199       if (pts[rank] == nodeId)
00200         {
00201           //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium));
00202           if (rank < rankFirstMedium)
00203             return false;
00204           else
00205             return true;
00206         }
00207     }
00208   //throw SALOME_Exception(LOCALIZED("node does not belong to this element"));
00209   MESSAGE("======================================================");
00210   MESSAGE("= IsMediumNode: node does not belong to this element =");
00211   MESSAGE("======================================================");
00212   return false;
00213 }
00214 
00215 SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
00216 {
00217   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00218   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00219   SMDSAbs_EntityType aType = SMDSEntity_Polygon;
00220   switch (aVtkType)
00221   {
00222     case VTK_TRIANGLE:
00223       aType = SMDSEntity_Triangle;
00224       break;
00225     case VTK_QUAD:
00226       aType = SMDSEntity_Quadrangle;
00227       break;
00228     case VTK_QUADRATIC_TRIANGLE:
00229       aType = SMDSEntity_Quad_Triangle;
00230       break;
00231     case VTK_QUADRATIC_QUAD:
00232       aType = SMDSEntity_Quad_Quadrangle;
00233       break;
00234     default:
00235       aType = SMDSEntity_Polygon;
00236   }
00237   return aType;
00238 }
00239 
00240 vtkIdType SMDS_VtkFace::GetVtkType() const
00241 {
00242   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00243   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00244   return aVtkType;
00245 }
00246 
00247 SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
00248 {
00249   switch (type)
00250   {
00251     case SMDSAbs_Node:
00252       return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00253     default:
00254       MESSAGE("ERROR : Iterator not implemented")
00255       ;
00256       return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
00257   }
00258 }
00259 
00260 SMDS_ElemIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const
00261 {
00262   return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00263 }
00264 
00265 SMDS_ElemIteratorPtr SMDS_VtkFace::interlacedNodesElemIterator() const
00266 {
00267   return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00268 }
00269 
00271 void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node)
00272 {
00273   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00274   vtkIdType npts = 0;
00275   vtkIdType* pts = 0;
00276   grid->GetCellPoints(myVtkID, npts, pts);
00277   grid->RemoveReferenceToCell(pts[0], myVtkID);
00278   pts[0] = node->getVtkId();
00279   node->AddInverseElement(this),
00280   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
00281 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS