1 // Copyright (C) 2010-2011 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkMedMesh.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkSmartPointer.h"
24 #include "vtkDataArray.h"
26 #include "vtkMedFamily.h"
27 #include "vtkMedFamilyOnEntity.h"
28 #include "vtkMedGroup.h"
29 #include "vtkMedGrid.h"
30 #include "vtkMedUtilities.h"
31 #include "vtkMedIntArray.h"
32 #include "vtkMedFile.h"
36 vtkCxxGetObjectVectorMacro(vtkMedMesh, CellFamily, vtkMedFamily);
37 vtkCxxSetObjectVectorMacro(vtkMedMesh, CellFamily, vtkMedFamily);
38 vtkCxxGetObjectVectorMacro(vtkMedMesh, PointFamily, vtkMedFamily);
39 vtkCxxSetObjectVectorMacro(vtkMedMesh, PointFamily, vtkMedFamily);
41 vtkCxxGetObjectVectorMacro(vtkMedMesh, PointGroup, vtkMedGroup);
42 vtkCxxSetObjectVectorMacro(vtkMedMesh, PointGroup, vtkMedGroup);
43 vtkCxxGetObjectVectorMacro(vtkMedMesh, CellGroup, vtkMedGroup);
44 vtkCxxSetObjectVectorMacro(vtkMedMesh, CellGroup, vtkMedGroup);
46 vtkCxxSetObjectMacro(vtkMedMesh, ParentFile, vtkMedFile);
48 // vtkCxxRevisionMacro(vtkMedMesh, "$Revision$")
49 vtkStandardNewMacro(vtkMedMesh)
51 vtkMedMesh::vtkMedMesh()
53 this->GridStep = new vtkMedComputeStepMap<vtkMedGrid> ();
55 this->UniversalName = NULL;
56 this->Description = NULL;
57 this->TimeUnit = NULL;
58 this->CellFamily = new vtkObjectVector<vtkMedFamily> ();
59 this->PointFamily = new vtkObjectVector<vtkMedFamily> ();
60 this->PointGroup = new vtkObjectVector<vtkMedGroup> ();
61 this->CellGroup = new vtkObjectVector<vtkMedGroup> ();
62 this->AxisName = vtkStringArray::New();
63 this->AxisUnit = vtkStringArray::New();
64 this->AxisName->SetNumberOfValues(3);
65 this->AxisUnit->SetNumberOfValues(3);
66 this->MedIterator = -1;
67 this->MeshType = MED_UNDEF_MESH_TYPE;
68 this->StructuredGridType = MED_UNDEF_GRID_TYPE;
69 this->ParentFile = NULL;
70 this->AxisType = MED_CARTESIAN;
71 this->SortingType = MED_SORT_DTIT;
72 this->MeshDimension = 3;
73 this->SpaceDimension = 3;
74 this->IsSupportMesh = 0;
77 vtkMedMesh::~vtkMedMesh()
80 this->SetUniversalName(NULL);
81 this->SetDescription(NULL);
82 delete this->CellFamily;
83 delete this->PointFamily;
84 delete this->PointGroup;
85 delete this->CellGroup;
86 this->AxisName->Delete();
87 this->AxisUnit->Delete();
88 delete this->GridStep;
91 vtkMedGroup* vtkMedMesh::GetOrCreateGroup(int pointOrCell, const char* name)
93 if(pointOrCell == vtkMedUtilities::OnCell)
95 for(int g = 0; g < this->CellGroup->size(); g++)
97 vtkMedGroup* group = this->CellGroup->at(g);
98 if(group != NULL && strcmp(name, group->GetName()) == 0)
103 vtkMedGroup* group = vtkMedGroup::New();
104 this->CellGroup->push_back(group);
105 //group->SetPointOrCell(vtkMedUtilities::OnCell);
106 group->SetName(name);
112 for(int g = 0; g < this->PointGroup->size(); g++)
114 vtkMedGroup* group = this->PointGroup->at(g);
115 if(group != NULL && strcmp(name, group->GetName()) == 0)
120 vtkMedGroup* group = vtkMedGroup::New();
121 this->CellGroup->push_back(group);
122 //group->SetPointOrCell(vtkMedUtilities::OnPoint);
123 group->SetName(name);
130 int vtkMedMesh::GetNumberOfFamily()
132 return this->GetNumberOfCellFamily() + this->GetNumberOfPointFamily();
135 vtkMedFamily* vtkMedMesh::GetFamily(int index)
139 if(index < this->GetNumberOfCellFamily())
140 return this->GetCellFamily(index);
141 else if(index < GetNumberOfFamily())
142 return this->GetPointFamily(index - this->GetNumberOfCellFamily());
146 vtkMedFamily* vtkMedMesh::GetOrCreateCellFamilyById(med_int id)
148 for(int i = 0; i < this->GetNumberOfCellFamily(); i++)
150 vtkMedFamily* family = this->GetCellFamily(i);
151 if(family->GetId() == id)
156 vtkMedFamily* family = vtkMedFamily::New();
158 std::ostringstream sstr;
159 sstr << "UNDEFINED_CELL_FAMILY_" << id;
160 family->SetName(sstr.str().c_str());
161 family->SetPointOrCell(vtkMedUtilities::OnCell);
162 family->SetMedIterator(-1);
163 this->AppendCellFamily(family);
168 void vtkMedMesh::SetNumberOfAxis(int naxis)
170 this->AxisName->SetNumberOfValues(naxis);
171 this->AxisUnit->SetNumberOfValues(naxis);
174 int vtkMedMesh::GetNumberOfAxis()
176 return this->AxisName->GetNumberOfValues();
179 vtkMedFamily* vtkMedMesh::GetOrCreatePointFamilyById(med_int id)
181 for(int i = 0; i < this->GetNumberOfPointFamily(); i++)
183 vtkMedFamily* family = this->GetPointFamily(i);
185 if(family->GetId() == id)
188 vtkMedFamily* family = vtkMedFamily::New();
190 std::ostringstream sstr;
191 sstr << "UNDEFINED_POINT_FAMILY_" << id;
192 family->SetName(sstr.str().c_str());
193 family->SetPointOrCell(vtkMedUtilities::OnPoint);
194 this->AppendPointFamily(family);
199 void vtkMedMesh::AddGridStep(vtkMedGrid* grid)
201 this->GridStep->AddObject(grid->GetComputeStep(), grid);
204 void vtkMedMesh::ClearGridStep()
206 this->GridStep->clear();
209 vtkMedGrid* vtkMedMesh::GetGridStep(const vtkMedComputeStep& cs)
211 return this->GridStep->GetObject(cs);
214 vtkMedGrid* vtkMedMesh::FindGridStep(const vtkMedComputeStep& cs,
217 return this->GridStep->FindObject(cs, strategy);
220 void vtkMedMesh::GatherGridTimes(std::set<med_float>& timeset)
222 this->GridStep->GatherTimes(timeset);
225 void vtkMedMesh::GatherGridIterations(med_float time,
226 std::set<med_int>& iterationset)
228 this->GridStep->GatherIterations(time, iterationset);
231 void vtkMedMesh::ClearMedSupports()
233 med_int stepnb = this->GridStep->GetNumberOfObject();
234 for(med_int stepid = 0; stepid<stepnb; stepid++ )
236 vtkMedGrid* grid = this->GridStep->GetObject(stepid);
237 grid->ClearMedSupports();
241 med_int vtkMedMesh::GetNumberOfGridStep()
243 return this->GridStep->GetNumberOfObject();
246 vtkMedGrid* vtkMedMesh::GetGridStep(med_int id)
248 return this->GridStep->GetObject(id);
251 void vtkMedMesh::GatherMedEntities(std::set<vtkMedEntity>& entities)
253 vtkMedGrid* firstStep = this->GetGridStep(0);
254 if(firstStep == NULL)
257 firstStep->GatherMedEntities(entities);
260 void vtkMedMesh::PrintSelf(ostream& os, vtkIndent indent)
262 this->Superclass::PrintSelf(os, indent);
263 PRINT_IVAR(os, indent, MedIterator);
264 PRINT_OBJECT_VECTOR(os, indent, CellFamily);
265 PRINT_OBJECT_VECTOR(os, indent, PointFamily);
266 PRINT_OBJECT_VECTOR(os, indent, PointGroup);
267 PRINT_OBJECT_VECTOR(os, indent, CellGroup);