Back to index

salome-paravis  6.5.0
vtkMedCurvilinearGrid.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 "vtkMedCurvilinearGrid.h"
00021 
00022 #include "vtkMedMesh.h"
00023 #include "vtkMedFile.h"
00024 #include "vtkMedDriver.h"
00025 #include "vtkMedFamilyOnEntityOnProfile.h"
00026 #include "vtkMedFamilyOnEntity.h"
00027 #include "vtkMedEntityArray.h"
00028 #include "vtkMedProfile.h"
00029 #include "vtkMedFamily.h"
00030 
00031 #include "vtkObjectFactory.h"
00032 #include "vtkDataArray.h"
00033 #include "vtkStructuredGrid.h"
00034 
00035 vtkCxxSetObjectMacro(vtkMedCurvilinearGrid, Coordinates, vtkDataArray);
00036 
00037 vtkCxxRevisionMacro(vtkMedCurvilinearGrid, "$Revision: 1.1.4.5.2.1 $")
00038 vtkStandardNewMacro(vtkMedCurvilinearGrid)
00039 
00040 vtkMedCurvilinearGrid::vtkMedCurvilinearGrid()
00041 {
00042   this->Coordinates = NULL;
00043   this->NumberOfPoints = 0;
00044 }
00045 
00046 vtkMedCurvilinearGrid::~vtkMedCurvilinearGrid()
00047 {
00048   this->SetCoordinates(NULL);
00049 }
00050 
00051 void vtkMedCurvilinearGrid::SetDimension(int dim)
00052 {
00053   this->AxisSize.resize(dim);
00054 }
00055 
00056 int vtkMedCurvilinearGrid::GetDimension()
00057 {
00058   return this->AxisSize.size();
00059 }
00060 
00061 void  vtkMedCurvilinearGrid::SetAxisSize(int axis, med_int size)
00062 {
00063   if(axis < 0)
00064     return;
00065 
00066   if(axis >= this->AxisSize.size())
00067     this->AxisSize.resize(axis+1);
00068 
00069   this->AxisSize[axis] = size;
00070 }
00071 
00072 med_int vtkMedCurvilinearGrid::GetAxisSize(int axis)
00073 {
00074   if(axis < 0 || axis >= this->AxisSize.size())
00075     return 0;
00076 
00077   return this->AxisSize[axis];
00078 }
00079 
00080 void  vtkMedCurvilinearGrid::LoadCoordinates()
00081 {
00082   vtkMedDriver* driver = this->GetParentMesh()->GetParentFile()->GetMedDriver();
00083   driver->LoadCoordinates(this);
00084 }
00085 
00086 int vtkMedCurvilinearGrid::IsCoordinatesLoaded()
00087 {
00088   return this->Coordinates != NULL && this->Coordinates->GetNumberOfTuples()
00089      == this->NumberOfPoints;
00090 }
00091 
00092 double* vtkMedCurvilinearGrid::GetCoordTuple(med_int index)
00093 {
00094   return this->Coordinates->GetTuple(index);
00095 }
00096 
00097 vtkDataSet* vtkMedCurvilinearGrid::CreateVTKDataSet(
00098     vtkMedFamilyOnEntityOnProfile* foep)
00099 {
00100   vtkStructuredGrid* vtkgrid = vtkStructuredGrid::New();
00101 
00102   vtkPoints* points = vtkPoints::New();
00103   vtkgrid->SetPoints(points);
00104   points->Delete();
00105 
00106   vtkgrid->SetDimensions(this->GetAxisSize(0),
00107                          this->GetAxisSize(1),
00108                          this->GetAxisSize(2));
00109 
00110   this->LoadCoordinates();
00111 
00112   if(this->GetDimension() == 3)
00113     {
00114     vtkgrid->GetPoints()->SetData(this->GetCoordinates());
00115     }
00116   else
00117     {
00118     vtkDataArray* coords = vtkDataArray::SafeDownCast(
00119         vtkAbstractArray::CreateArray(this->GetCoordinates()->GetDataType()));
00120     coords->SetNumberOfComponents(3);
00121     coords->SetNumberOfTuples(this->GetNumberOfPoints());
00122     vtkgrid->GetPoints()->SetData(coords);
00123     coords->Delete();
00124 
00125     med_int npts = this->GetNumberOfPoints();
00126     double coord[3] = {0, 0, 0};
00127     for(med_int id=0; id<npts; id++)
00128       {
00129       double * tuple = this->Coordinates->GetTuple(id);
00130       for(int dim=0; dim<this->GetDimension(); dim++)
00131         {
00132         coord[dim] = tuple[dim];
00133         }
00134       coords->SetTuple(id, coord);
00135       }
00136     }
00137 
00138   if(foep->GetProfile() != NULL)
00139     {
00140     foep->GetProfile()->Load();
00141     vtkMedIntArray* pids = foep->GetProfile()->GetIds();
00142     med_int previd = -1;
00143     for(med_int pid=0; pid<pids->GetNumberOfTuples(); pid++)
00144       {
00145       med_int id = pids->GetValue(pid) - 1;
00146       for(med_int theid=previd+1; theid<id; theid++)
00147         {
00148         vtkgrid->BlankCell(theid);
00149         }
00150 
00151       previd = id;
00152       }
00153     }
00154 
00155   if(foep->GetFamilyOnEntity()->GetEntityArray()->GetNumberOfFamilyOnEntity() > 1)
00156     {
00157     med_int famid = foep->GetFamilyOnEntity()->GetFamily()->GetId();
00158     vtkMedEntityArray* ea = foep->GetFamilyOnEntity()->GetEntityArray();
00159     for(med_int id=0; id<vtkgrid->GetNumberOfCells(); id++)
00160       {
00161       if(ea->GetFamilyId(id) != famid)
00162         vtkgrid->BlankCell(id);
00163       }
00164     }
00165 
00166   return vtkgrid;
00167 }
00168 
00169 void vtkMedCurvilinearGrid::PrintSelf(ostream& os, vtkIndent indent)
00170 {
00171   this->Superclass::PrintSelf(os, indent);
00172 }