1 // Copyright (C) 2010-2012 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 "vtkMedCurvilinearGrid.h"
22 #include "vtkMedMesh.h"
23 #include "vtkMedFile.h"
24 #include "vtkMedDriver.h"
25 #include "vtkMedFamilyOnEntityOnProfile.h"
26 #include "vtkMedFamilyOnEntity.h"
27 #include "vtkMedEntityArray.h"
28 #include "vtkMedProfile.h"
29 #include "vtkMedFamily.h"
31 #include "vtkObjectFactory.h"
32 #include "vtkDataArray.h"
33 #include "vtkStructuredGrid.h"
35 vtkCxxSetObjectMacro(vtkMedCurvilinearGrid, Coordinates, vtkDataArray);
37 vtkCxxRevisionMacro(vtkMedCurvilinearGrid, "$Revision$")
38 vtkStandardNewMacro(vtkMedCurvilinearGrid)
40 vtkMedCurvilinearGrid::vtkMedCurvilinearGrid()
42 this->Coordinates = NULL;
43 this->NumberOfPoints = 0;
46 vtkMedCurvilinearGrid::~vtkMedCurvilinearGrid()
48 this->SetCoordinates(NULL);
51 void vtkMedCurvilinearGrid::SetDimension(int dim)
53 this->AxisSize.resize(dim);
56 int vtkMedCurvilinearGrid::GetDimension()
58 return this->AxisSize.size();
61 void vtkMedCurvilinearGrid::SetAxisSize(int axis, med_int size)
66 if(axis >= this->AxisSize.size())
67 this->AxisSize.resize(axis+1);
69 this->AxisSize[axis] = size;
72 med_int vtkMedCurvilinearGrid::GetAxisSize(int axis)
74 if(axis < 0 || axis >= this->AxisSize.size())
77 return this->AxisSize[axis];
80 void vtkMedCurvilinearGrid::LoadCoordinates()
82 vtkMedDriver* driver = this->GetParentMesh()->GetParentFile()->GetMedDriver();
83 driver->LoadCoordinates(this);
86 int vtkMedCurvilinearGrid::IsCoordinatesLoaded()
88 return this->Coordinates != NULL && this->Coordinates->GetNumberOfTuples()
89 == this->NumberOfPoints;
92 double* vtkMedCurvilinearGrid::GetCoordTuple(med_int index)
94 return this->Coordinates->GetTuple(index);
97 vtkDataSet* vtkMedCurvilinearGrid::CreateVTKDataSet(
98 vtkMedFamilyOnEntityOnProfile* foep)
100 vtkStructuredGrid* vtkgrid = vtkStructuredGrid::New();
102 vtkPoints* points = vtkPoints::New();
103 vtkgrid->SetPoints(points);
106 vtkgrid->SetDimensions(this->GetAxisSize(0),
107 this->GetAxisSize(1),
108 this->GetAxisSize(2));
110 this->LoadCoordinates();
112 if(this->GetDimension() == 3)
114 vtkgrid->GetPoints()->SetData(this->GetCoordinates());
118 vtkDataArray* coords = vtkDataArray::SafeDownCast(
119 vtkAbstractArray::CreateArray(this->GetCoordinates()->GetDataType()));
120 coords->SetNumberOfComponents(3);
121 coords->SetNumberOfTuples(this->GetNumberOfPoints());
122 vtkgrid->GetPoints()->SetData(coords);
125 med_int npts = this->GetNumberOfPoints();
126 double coord[3] = {0, 0, 0};
127 for(med_int id=0; id<npts; id++)
129 double * tuple = this->Coordinates->GetTuple(id);
130 for(int dim=0; dim<this->GetDimension(); dim++)
132 coord[dim] = tuple[dim];
134 coords->SetTuple(id, coord);
138 if(foep->GetProfile() != NULL)
140 foep->GetProfile()->Load();
141 vtkMedIntArray* pids = foep->GetProfile()->GetIds();
143 for(med_int pid=0; pid<pids->GetNumberOfTuples(); pid++)
145 med_int id = pids->GetValue(pid) - 1;
146 for(med_int theid=previd+1; theid<id; theid++)
148 vtkgrid->BlankCell(theid);
155 if(foep->GetFamilyOnEntity()->GetEntityArray()->GetNumberOfFamilyOnEntity() > 1)
157 med_int famid = foep->GetFamilyOnEntity()->GetFamily()->GetId();
158 vtkMedEntityArray* ea = foep->GetFamilyOnEntity()->GetEntityArray();
159 for(med_int id=0; id<vtkgrid->GetNumberOfCells(); id++)
161 if(ea->GetFamilyId(id) != famid)
162 vtkgrid->BlankCell(id);
169 void vtkMedCurvilinearGrid::PrintSelf(ostream& os, vtkIndent indent)
171 this->Superclass::PrintSelf(os, indent);