Back to index

salome-smesh  6.5.0
SMDS_VtkFace.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_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(const 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(const 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     case 9:
00065       aType = VTK_BIQUADRATIC_QUAD;
00066       break;
00067     default:
00068       aType = VTK_POLYGON;
00069       break;
00070   }
00071   myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
00072   mesh->setMyModified();
00073   //MESSAGE("SMDS_VtkFace::init myVtkID " << myVtkID);
00074 }
00075 
00076 void SMDS_VtkFace::initPoly(const std::vector<vtkIdType>& nodeIds, SMDS_Mesh* mesh)
00077 {
00078   SMDS_MeshFace::init();
00079   vtkUnstructuredGrid* grid = mesh->getGrid();
00080   myMeshId = mesh->getMeshId();
00081   myVtkID = grid->InsertNextLinkedCell(VTK_POLYGON, nodeIds.size(), (vtkIdType*) &nodeIds[0]);
00082   mesh->setMyModified();
00083 }
00084 
00085 bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
00086 {
00087   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00088   vtkIdType npts = 0;
00089   vtkIdType* pts = 0;
00090   grid->GetCellPoints(myVtkID, npts, pts);
00091   if (nbNodes != npts)
00092     {
00093       MESSAGE("ChangeNodes problem: not the same number of nodes " << npts << " -> " << nbNodes);
00094       return false;
00095     }
00096   for (int i = 0; i < nbNodes; i++)
00097     {
00098       pts[i] = nodes[i]->getVtkId();
00099     }
00100   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
00101   return true;
00102 }
00103 
00104 void SMDS_VtkFace::Print(std::ostream & OS) const
00105 {
00106   OS << "face <" << GetID() << "> : ";
00107 }
00108 
00109 int SMDS_VtkFace::NbEdges() const
00110 {
00111   // TODO quadratic polygons ?
00112   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00113   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00114   int nbEdges = 3;
00115   switch (aVtkType)
00116   {
00117     case VTK_TRIANGLE:
00118     case VTK_QUADRATIC_TRIANGLE:
00119       nbEdges = 3;
00120       break;
00121     case VTK_QUAD:
00122     case VTK_QUADRATIC_QUAD:
00123     case VTK_BIQUADRATIC_QUAD:
00124       nbEdges = 4;
00125       break;
00126     case VTK_POLYGON:
00127     default:
00128       nbEdges = grid->GetCell(myVtkID)->GetNumberOfPoints();
00129       break;
00130   }
00131   return nbEdges;
00132 }
00133 
00134 int SMDS_VtkFace::NbFaces() const
00135 {
00136   return 1;
00137 }
00138 
00139 int SMDS_VtkFace::NbNodes() const
00140 {
00141   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00142   int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
00143   return nbPoints;
00144 }
00145 
00151 const SMDS_MeshNode*
00152 SMDS_VtkFace::GetNode(const int ind) const
00153 {
00154   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00155   vtkIdType npts, *pts;
00156   grid->GetCellPoints( this->myVtkID, npts, pts );
00157   return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ ind ]);
00158 }
00159 
00160 bool SMDS_VtkFace::IsQuadratic() const
00161 {
00162   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00163   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00164   // TODO quadratic polygons ?
00165   switch (aVtkType)
00166   {
00167     case VTK_QUADRATIC_TRIANGLE:
00168     case VTK_QUADRATIC_QUAD:
00169     case VTK_BIQUADRATIC_QUAD:
00170       return true;
00171       break;
00172     default:
00173       return false;
00174   }
00175 }
00176 
00177 bool SMDS_VtkFace::IsPoly() const
00178 {
00179   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00180   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00181   return (aVtkType == VTK_POLYGON);
00182 }
00183 
00184 bool SMDS_VtkFace::IsMediumNode(const SMDS_MeshNode* node) const
00185 {
00186   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00187   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00188   int rankFirstMedium = 0;
00189   switch (aVtkType)
00190   {
00191     case VTK_QUADRATIC_TRIANGLE:
00192       rankFirstMedium = 3; // medium nodes are of rank 3,4,5
00193       break;
00194     case VTK_QUADRATIC_QUAD:
00195     case VTK_BIQUADRATIC_QUAD:
00196       rankFirstMedium = 4; // medium nodes are of rank 4,5,6,7
00197       break;
00198     default:
00199       //MESSAGE("wrong element type " << aVtkType);
00200       return false;
00201   }
00202   vtkIdType npts = 0;
00203   vtkIdType* pts = 0;
00204   grid->GetCellPoints(myVtkID, npts, pts);
00205   vtkIdType nodeId = node->getVtkId();
00206   for (int rank = 0; rank < npts; rank++)
00207     {
00208       if (pts[rank] == nodeId)
00209         {
00210           //MESSAGE("rank " << rank << " is medium node " << (rank < rankFirstMedium));
00211           if (rank < rankFirstMedium)
00212             return false;
00213           else
00214             return true;
00215         }
00216     }
00217   //throw SALOME_Exception(LOCALIZED("node does not belong to this element"));
00218   MESSAGE("======================================================");
00219   MESSAGE("= IsMediumNode: node does not belong to this element =");
00220   MESSAGE("======================================================");
00221   return false;
00222 }
00223 
00224 int SMDS_VtkFace::NbCornerNodes() const
00225 {
00226   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00227   int       nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
00228   vtkIdType aVtkType = grid->GetCellType(myVtkID);
00229   if ( aVtkType != VTK_POLYGON )
00230     return nbPoints <= 4 ? nbPoints : nbPoints / 2;
00231   return nbPoints;
00232 }
00233 
00234 SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
00235 {
00236   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00237   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00238   return SMDS_MeshCell::toSmdsType( VTKCellType( aVtkType ));
00239 }
00240 
00241 vtkIdType SMDS_VtkFace::GetVtkType() const
00242 {
00243   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00244   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
00245   return aVtkType;
00246 }
00247 
00248 SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
00249 {
00250   switch (type)
00251   {
00252     case SMDSAbs_Node:
00253       return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00254     default:
00255       MESSAGE("ERROR : Iterator not implemented")
00256       ;
00257       return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
00258   }
00259 }
00260 
00261 SMDS_ElemIteratorPtr SMDS_VtkFace::nodesIteratorToUNV() const
00262 {
00263   return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00264 }
00265 
00266 SMDS_ElemIteratorPtr SMDS_VtkFace::interlacedNodesElemIterator() const
00267 {
00268   return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
00269 }
00270 
00272 void SMDS_VtkFace::ChangeApex(SMDS_MeshNode* node)
00273 {
00274   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
00275   vtkIdType npts = 0;
00276   vtkIdType* pts = 0;
00277   grid->GetCellPoints(myVtkID, npts, pts);
00278   grid->RemoveReferenceToCell(pts[0], myVtkID);
00279   pts[0] = node->getVtkId();
00280   node->AddInverseElement(this),
00281   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
00282 }