Salome HOME
fd3859681325b9784447cf98be9a954d34516b46
[modules/smesh.git] / src / SMDS / SMDS_BallElement.cxx
1 // Copyright (C) 2010-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMDS : implementation of Salome mesh data structure
21 //  Module     : SMESH
22 //  File       : SMDS_BallElement.cxx
23 //  Author     : Edward AGAPOV (eap)
24
25 #include "SMDS_BallElement.hxx"
26
27 #include "SMDS_ElemIterator.hxx"
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_VtkCellIterator.hxx"
31
32 SMDS_BallElement::SMDS_BallElement()
33 {
34   SMDS_MeshCell::init();
35 }
36
37 SMDS_BallElement::SMDS_BallElement (const SMDS_MeshNode * node, double diameter)
38 {
39   init( node->getVtkId(), diameter, SMDS_Mesh::_meshList[ node->getMeshId() ] );
40 }
41
42 SMDS_BallElement::SMDS_BallElement(vtkIdType nodeId, double diameter, SMDS_Mesh* mesh)
43 {
44   init( nodeId, diameter, mesh );
45 }
46
47 void SMDS_BallElement::init(vtkIdType nodeId, double diameter, SMDS_Mesh* mesh)
48 {
49   SMDS_MeshCell::init();
50   myMeshId = mesh->getMeshId();
51   myVtkID = mesh->getGrid()->InsertNextLinkedCell( GetVtkType(), 1, &nodeId );
52   mesh->getGrid()->SetBallDiameter( myVtkID, diameter );
53   mesh->setMyModified();
54 }
55
56 double SMDS_BallElement::GetDiameter() const
57 {
58   return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetBallDiameter( myVtkID );
59 }
60
61 void SMDS_BallElement::SetDiameter(double diameter)
62 {
63   SMDS_Mesh::_meshList[myMeshId]->getGrid()->SetBallDiameter( myVtkID, diameter );
64 }
65
66 bool SMDS_BallElement::ChangeNode (const SMDS_MeshNode * node)
67 {
68   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
69   vtkIdType npts = 0;
70   vtkIdType* pts = 0;
71   grid->GetCellPoints(myVtkID, npts, pts);
72   pts[0] = node->getVtkId();
73   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
74   return true;
75 }
76
77 void SMDS_BallElement::Print (std::ostream & OS) const
78 {
79   OS << "ball<" << GetID() << "> : ";
80 }
81
82 const SMDS_MeshNode* SMDS_BallElement::GetNode (const int ind) const
83 {
84   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
85   vtkIdType npts, *pts;
86   grid->GetCellPoints( myVtkID, npts, pts );
87   return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ 0 ]);
88 }
89
90 SMDS_ElemIteratorPtr SMDS_BallElement::elementsIterator (SMDSAbs_ElementType type) const
91 {
92   switch (type)
93   {
94     case SMDSAbs_Node:
95       return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
96     default:
97       ;
98       return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
99   }
100 }
101