Salome HOME
Copyrights update 2015.
[modules/smesh.git] / src / SMDS / SMDS_BallElement.cxx
1 // Copyright (C) 2010-2015  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 : implementaion 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   SMDS_UnstructuredGrid* grid = mesh->getGrid();
51   myVtkID = grid->InsertNextLinkedCell( GetVtkType(), 1, &nodeId );
52   myMeshId = mesh->getMeshId();
53   grid->SetBallDiameter( myVtkID, diameter );
54   mesh->setMyModified();
55 }
56
57 double SMDS_BallElement::GetDiameter() const
58 {
59   return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetBallDiameter( myVtkID );
60 }
61
62 void SMDS_BallElement::SetDiameter(double diameter)
63 {
64   SMDS_Mesh::_meshList[myMeshId]->getGrid()->SetBallDiameter( myVtkID, diameter );
65 }
66
67 bool SMDS_BallElement::ChangeNode (const SMDS_MeshNode * node)
68 {
69   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
70   vtkIdType npts = 0;
71   vtkIdType* pts = 0;
72   grid->GetCellPoints(myVtkID, npts, pts);
73   pts[0] = node->getVtkId();
74   SMDS_Mesh::_meshList[myMeshId]->setMyModified();
75   return true;
76 }
77
78 void SMDS_BallElement::Print (std::ostream & OS) const
79 {
80   OS << "ball<" << GetID() << "> : ";
81 }
82
83 const SMDS_MeshNode* SMDS_BallElement::GetNode (const int ind) const
84 {
85   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
86   vtkIdType npts, *pts;
87   grid->GetCellPoints( myVtkID, npts, pts );
88   return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ 0 ]);
89 }
90
91 SMDS_ElemIteratorPtr SMDS_BallElement::elementsIterator (SMDSAbs_ElementType type) const
92 {
93   switch (type)
94   {
95     case SMDSAbs_Node:
96       return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
97     default:
98       ;
99       return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
100   }
101 }
102