1 // Copyright (C) 2010-2013 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 "vtkMedRegularGrid.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkDataArray.h"
24 #include "vtkStructuredGrid.h"
26 #include "vtkMedUtilities.h"
27 #include "vtkMedFile.h"
28 #include "vtkMedDriver.h"
29 #include "vtkMedMesh.h"
30 #include "vtkMedFamilyOnEntityOnProfile.h"
31 #include "vtkMedFamilyOnEntity.h"
32 #include "vtkMedEntityArray.h"
33 #include "vtkMedProfile.h"
34 #include "vtkMedFamily.h"
36 vtkCxxGetObjectVectorMacro(vtkMedRegularGrid, AxisCoordinate, vtkDataArray);
37 vtkCxxSetAbstractObjectVectorMacro(vtkMedRegularGrid, AxisCoordinate, vtkDataArray);
39 // vtkCxxRevisionMacro(vtkMedRegularGrid, "$Revision$")
40 vtkStandardNewMacro(vtkMedRegularGrid)
42 vtkMedRegularGrid::vtkMedRegularGrid()
44 this->AxisCoordinate = new vtkObjectVector<vtkDataArray>();
47 vtkMedRegularGrid::~vtkMedRegularGrid()
49 delete this->AxisCoordinate;
52 void vtkMedRegularGrid::SetDimension(med_int dim)
56 this->AxisSize.resize(dim);
57 this->SetNumberOfAxisCoordinate(dim);
60 int vtkMedRegularGrid::GetDimension()
62 return this->AxisSize.size();
65 void vtkMedRegularGrid::SetAxisSize(int axis, med_int size)
70 if(axis >= this->GetDimension())
72 this->SetDimension(axis+1);
75 this->AxisSize[axis] = size;
78 med_int vtkMedRegularGrid::GetAxisSize(int dim)
80 if(dim < 0 || dim >= this->AxisSize.size())
82 return this->AxisSize[dim];
85 med_int vtkMedRegularGrid::GetNumberOfPoints()
88 for(int dim = 0; dim < this->AxisSize.size(); dim++)
90 npts *= this->AxisSize[dim];
95 void vtkMedRegularGrid::LoadCoordinates()
97 this->GetParentMesh()->GetParentFile()->GetMedDriver()->LoadCoordinates(this);
100 int vtkMedRegularGrid::IsCoordinatesLoaded()
102 bool res = this->GetDimension() == this->AxisSize.size() &&
103 this->GetDimension() == this->AxisCoordinate->size();
108 med_int nloadedcoords = 1;
109 for(int axis=0; axis < this->GetDimension(); axis++)
111 vtkDataArray* axiscoords = this->GetAxisCoordinate(axis);
112 if(axiscoords != NULL)
113 nloadedcoords *= axiscoords->GetNumberOfTuples();
117 return nloadedcoords == this->GetNumberOfPoints();
120 double* vtkMedRegularGrid::GetCoordTuple(med_int index)
122 this->CoordTuple[0] = 0;
123 this->CoordTuple[1] = 0;
124 this->CoordTuple[2] = 0;
126 for(int axis=0; axis < this->GetDimension(); axis++)
128 med_int modulo = prevmod * this->AxisSize[axis];
129 med_int axisindex = (index % modulo) / prevmod;
131 vtkDataArray* coords = this->GetAxisCoordinate(axis);
132 this->CoordTuple[axis] = coords->
133 GetTuple1(axisindex);
136 return this->CoordTuple;
139 vtkDataSet* vtkMedRegularGrid::CreateVTKDataSet(vtkMedFamilyOnEntityOnProfile* foep)
141 vtkStructuredGrid* vtkgrid = vtkStructuredGrid::New();
143 vtkPoints* points = vtkPoints::New();
144 vtkgrid->SetPoints(points);
147 vtkIdType dims[3] = {this->GetAxisSize(0),
148 this->GetAxisSize(1),
149 this->GetAxisSize(2)};
151 for(int dim=0; dim<3; dim++)
152 dims[dim] = (dims[dim] >= 1 ? dims[dim] : 1);
154 vtkgrid->SetDimensions(dims[0], dims[1], dims[2]);
156 this->LoadCoordinates();
158 if(this->GetAxisCoordinate(0) == NULL)
164 vtkDataArray* coords = vtkMedUtilities::NewCoordArray();
165 coords->SetNumberOfComponents(3);
166 coords->SetNumberOfTuples(this->GetNumberOfPoints());
167 vtkgrid->GetPoints()->SetData(coords);
171 double coord[3] = {0, 0, 0};
173 npts = this->GetNumberOfPoints();
174 for(med_int id=0; id<npts; id++)
176 double * tuple = this->GetCoordTuple(id);
177 for(int dim=0; dim<this->GetDimension(); dim++)
179 coord[dim] = tuple[dim];
181 coords->SetTuple(id, coord);
184 if(foep->GetProfile() != NULL)
186 foep->GetProfile()->Load();
187 vtkMedIntArray* pids = foep->GetProfile()->GetIds();
189 for(med_int pid=0; pid<pids->GetNumberOfTuples(); pid++)
191 med_int id = pids->GetValue(pid) - 1;
192 for(med_int theid=previd+1; theid<id; theid++)
194 vtkgrid->BlankCell(theid);
201 if(foep->GetFamilyOnEntity()->GetEntityArray()->GetNumberOfFamilyOnEntity() > 1)
203 med_int famid = foep->GetFamilyOnEntity()->GetFamily()->GetId();
204 vtkMedEntityArray* ea = foep->GetFamilyOnEntity()->GetEntityArray();
205 for(med_int id=0; id<vtkgrid->GetNumberOfCells(); id++)
207 if(ea->GetFamilyId(id) != famid)
208 vtkgrid->BlankCell(id);
214 void vtkMedRegularGrid::PrintSelf(ostream& os, vtkIndent indent)
216 this->Superclass::PrintSelf(os, indent);