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 "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);
105 vtkgrid->SetDimensions(this->GetAxisSize(0),
106 this->GetAxisSize(1),
107 this->GetAxisSize(2));
109 this->LoadCoordinates();
111 if(this->GetDimension() == 3)
113 vtkgrid->GetPoints()->SetData(this->GetCoordinates());
117 if(this->GetDimension() == 1)
119 vtkgrid->SetDimensions(this->GetAxisSize(0),
124 if(this->GetDimension() == 2)
126 vtkgrid->SetDimensions(this->GetAxisSize(0),
127 this->GetAxisSize(1),
131 vtkDataArray* coords = vtkDataArray::SafeDownCast(
132 vtkAbstractArray::CreateArray(this->GetCoordinates()->GetDataType()));
133 coords->SetNumberOfComponents(3);
134 coords->SetNumberOfTuples(this->GetNumberOfPoints());
135 vtkgrid->GetPoints()->SetData(coords);
138 med_int npts = this->GetNumberOfPoints();
139 double coord[3] = {0, 0, 0};
140 for(med_int id=0; id<npts; id++)
142 double * tuple = this->Coordinates->GetTuple(id);
143 for(int dim=0; dim<this->GetDimension(); dim++)
145 coord[dim] = tuple[dim];
147 coords->SetTuple(id, coord);
151 if(foep->GetProfile() != NULL)
153 foep->GetProfile()->Load();
154 vtkMedIntArray* pids = foep->GetProfile()->GetIds();
156 for(med_int pid=0; pid<pids->GetNumberOfTuples(); pid++)
158 med_int id = pids->GetValue(pid) - 1;
159 for(med_int theid=previd+1; theid<id; theid++)
161 vtkgrid->BlankCell(theid);
168 if(foep->GetFamilyOnEntity()->GetEntityArray()->GetNumberOfFamilyOnEntity() > 1)
170 med_int famid = foep->GetFamilyOnEntity()->GetFamily()->GetId();
171 vtkMedEntityArray* ea = foep->GetFamilyOnEntity()->GetEntityArray();
172 for(med_int id=0; id<vtkgrid->GetNumberOfCells(); id++)
174 if(ea->GetFamilyId(id) != famid)
175 vtkgrid->BlankCell(id);
182 void vtkMedCurvilinearGrid::PrintSelf(ostream& os, vtkIndent indent)
184 this->Superclass::PrintSelf(os, indent);