Back to index

salome-paravis  6.5.0
vtkMedRegularGrid.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "vtkMedRegularGrid.h"
00021 
00022 #include "vtkObjectFactory.h"
00023 #include "vtkDataArray.h"
00024 #include "vtkStructuredGrid.h"
00025 
00026 #include "vtkMedUtilities.h"
00027 #include "vtkMedFile.h"
00028 #include "vtkMedDriver.h"
00029 #include "vtkMedMesh.h"
00030 #include "vtkMedFamilyOnEntityOnProfile.h"
00031 #include "vtkMedFamilyOnEntity.h"
00032 #include "vtkMedEntityArray.h"
00033 #include "vtkMedProfile.h"
00034 #include "vtkMedFamily.h"
00035 
00036 vtkCxxGetObjectVectorMacro(vtkMedRegularGrid, AxisCoordinate, vtkDataArray);
00037 vtkCxxSetAbstractObjectVectorMacro(vtkMedRegularGrid, AxisCoordinate, vtkDataArray);
00038 
00039 vtkCxxRevisionMacro(vtkMedRegularGrid, "$Revision: 1.1.4.6.2.1 $")
00040 vtkStandardNewMacro(vtkMedRegularGrid)
00041 
00042 vtkMedRegularGrid::vtkMedRegularGrid()
00043 {
00044   this->AxisCoordinate = new vtkObjectVector<vtkDataArray>();
00045 }
00046 
00047 vtkMedRegularGrid::~vtkMedRegularGrid()
00048 {
00049   delete this->AxisCoordinate;
00050 }
00051 
00052 void vtkMedRegularGrid::SetDimension(med_int dim)
00053 {
00054   if(dim < 0)
00055     dim = 0;
00056   this->AxisSize.resize(dim);
00057   this->SetNumberOfAxisCoordinate(dim);
00058 }
00059 
00060 int vtkMedRegularGrid::GetDimension()
00061 {
00062   return this->AxisSize.size();
00063 }
00064 
00065 void  vtkMedRegularGrid::SetAxisSize(int axis, med_int size)
00066 {
00067   if(axis < 0)
00068     return;
00069 
00070   if(axis >= this->GetDimension())
00071     {
00072     this->SetDimension(axis+1);
00073     }
00074 
00075   this->AxisSize[axis] = size;
00076 }
00077 
00078 med_int vtkMedRegularGrid::GetAxisSize(int dim)
00079 {
00080   if(dim < 0 || dim >= this->AxisSize.size())
00081     return 0;
00082   return this->AxisSize[dim];
00083 }
00084 
00085 med_int vtkMedRegularGrid::GetNumberOfPoints()
00086 {
00087   med_int npts = 1;
00088   for(int dim = 0; dim < this->AxisSize.size(); dim++)
00089     {
00090     npts *= this->AxisSize[dim];
00091     }
00092   return npts;
00093 }
00094 
00095 void  vtkMedRegularGrid::LoadCoordinates()
00096 {
00097   this->GetParentMesh()->GetParentFile()->GetMedDriver()->LoadCoordinates(this);
00098 }
00099 
00100 int vtkMedRegularGrid::IsCoordinatesLoaded()
00101 {
00102   bool res =  this->GetDimension() == this->AxisSize.size() &&
00103       this->GetDimension() == this->AxisCoordinate->size();
00104 
00105   if(!res)
00106     return 0;
00107 
00108   med_int nloadedcoords = 1;
00109   for(int axis=0; axis < this->GetDimension(); axis++)
00110     {
00111     vtkDataArray* axiscoords = this->GetAxisCoordinate(axis);
00112     if(axiscoords != NULL)
00113       nloadedcoords *= axiscoords->GetNumberOfTuples();
00114     else
00115       nloadedcoords = 0;
00116     }
00117   return nloadedcoords == this->GetNumberOfPoints();
00118 }
00119 
00120 double* vtkMedRegularGrid::GetCoordTuple(med_int index)
00121 {
00122   this->CoordTuple[0] = 0;
00123   this->CoordTuple[1] = 0;
00124   this->CoordTuple[2] = 0;
00125   med_int prevmod = 1;
00126   for(int axis=0; axis < this->GetDimension(); axis++)
00127     {
00128     med_int modulo = prevmod * this->AxisSize[axis];
00129     med_int axisindex = (index % modulo) / prevmod;
00130     prevmod = modulo;
00131     vtkDataArray* coords = this->GetAxisCoordinate(axis);
00132     this->CoordTuple[axis] = coords->
00133                              GetTuple1(axisindex);
00134     }
00135 
00136   return this->CoordTuple;
00137 }
00138 
00139 vtkDataSet* vtkMedRegularGrid::CreateVTKDataSet(vtkMedFamilyOnEntityOnProfile* foep)
00140 {
00141   vtkStructuredGrid* vtkgrid = vtkStructuredGrid::New();
00142 
00143   vtkPoints* points = vtkPoints::New();
00144   vtkgrid->SetPoints(points);
00145   points->Delete();
00146 
00147   vtkIdType dims[3] = {this->GetAxisSize(0),
00148                     this->GetAxisSize(1),
00149                     this->GetAxisSize(2)};
00150 
00151   for(int dim=0; dim<3; dim++)
00152     dims[dim] = (dims[dim] >= 1 ? dims[dim] : 1);
00153 
00154   vtkgrid->SetDimensions(dims[0], dims[1], dims[2]);
00155 
00156   this->LoadCoordinates();
00157 
00158   if(this->GetAxisCoordinate(0) == NULL)
00159     {
00160     vtkgrid->Delete();
00161     return NULL;
00162     }
00163 
00164   vtkDataArray* coords = vtkMedUtilities::NewCoordArray();
00165   coords->SetNumberOfComponents(3);
00166   coords->SetNumberOfTuples(this->GetNumberOfPoints());
00167   vtkgrid->GetPoints()->SetData(coords);
00168   coords->Delete();
00169 
00170   med_int npts;
00171   double coord[3] = {0, 0, 0};
00172 
00173   npts = this->GetNumberOfPoints();
00174   for(med_int id=0; id<npts; id++)
00175     {
00176     double * tuple = this->GetCoordTuple(id);
00177     for(int dim=0; dim<this->GetDimension(); dim++)
00178       {
00179       coord[dim] = tuple[dim];
00180       }
00181     coords->SetTuple(id, coord);
00182     }
00183 
00184   if(foep->GetProfile() != NULL)
00185     {
00186     foep->GetProfile()->Load();
00187     vtkMedIntArray* pids = foep->GetProfile()->GetIds();
00188     med_int previd = -1;
00189     for(med_int pid=0; pid<pids->GetNumberOfTuples(); pid++)
00190       {
00191       med_int id = pids->GetValue(pid) - 1;
00192       for(med_int theid=previd+1; theid<id; theid++)
00193         {
00194         vtkgrid->BlankCell(theid);
00195         }
00196 
00197       previd = id;
00198       }
00199     }
00200 
00201   if(foep->GetFamilyOnEntity()->GetEntityArray()->GetNumberOfFamilyOnEntity() > 1)
00202     {
00203     med_int famid = foep->GetFamilyOnEntity()->GetFamily()->GetId();
00204     vtkMedEntityArray* ea = foep->GetFamilyOnEntity()->GetEntityArray();
00205     for(med_int id=0; id<vtkgrid->GetNumberOfCells(); id++)
00206       {
00207       if(ea->GetFamilyId(id) != famid)
00208         vtkgrid->BlankCell(id);
00209       }
00210     }
00211   return vtkgrid;
00212 }
00213 
00214 void vtkMedRegularGrid::PrintSelf(ostream& os, vtkIndent indent)
00215 {
00216   this->Superclass::PrintSelf(os, indent);
00217 }