Back to index

salome-paravis  6.5.0
vtkMedMesh.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 "vtkMedMesh.h"
00021 
00022 #include "vtkObjectFactory.h"
00023 #include "vtkSmartPointer.h"
00024 #include "vtkDataArray.h"
00025 
00026 #include "vtkMedFamily.h"
00027 #include "vtkMedFamilyOnEntity.h"
00028 #include "vtkMedGroup.h"
00029 #include "vtkMedGrid.h"
00030 #include "vtkMedUtilities.h"
00031 #include "vtkMedIntArray.h"
00032 #include "vtkMedFile.h"
00033 
00034 #include <sstream>
00035 
00036 vtkCxxGetObjectVectorMacro(vtkMedMesh, CellFamily, vtkMedFamily);
00037 vtkCxxSetObjectVectorMacro(vtkMedMesh, CellFamily, vtkMedFamily);
00038 vtkCxxGetObjectVectorMacro(vtkMedMesh, PointFamily, vtkMedFamily);
00039 vtkCxxSetObjectVectorMacro(vtkMedMesh, PointFamily, vtkMedFamily);
00040 
00041 vtkCxxGetObjectVectorMacro(vtkMedMesh, PointGroup, vtkMedGroup);
00042 vtkCxxSetObjectVectorMacro(vtkMedMesh, PointGroup, vtkMedGroup);
00043 vtkCxxGetObjectVectorMacro(vtkMedMesh, CellGroup, vtkMedGroup);
00044 vtkCxxSetObjectVectorMacro(vtkMedMesh, CellGroup, vtkMedGroup);
00045 
00046 vtkCxxSetObjectMacro(vtkMedMesh, ParentFile, vtkMedFile);
00047 
00048 vtkCxxRevisionMacro(vtkMedMesh, "$Revision: 1.1.4.7.2.1 $")
00049 vtkStandardNewMacro(vtkMedMesh)
00050 
00051 vtkMedMesh::vtkMedMesh()
00052 {
00053   this->GridStep = new vtkMedComputeStepMap<vtkMedGrid> ();
00054   this->Name = NULL;
00055   this->UniversalName = NULL;
00056   this->Description = NULL;
00057   this->TimeUnit = NULL;
00058   this->CellFamily = new vtkObjectVector<vtkMedFamily> ();
00059   this->PointFamily = new vtkObjectVector<vtkMedFamily> ();
00060   this->PointGroup = new vtkObjectVector<vtkMedGroup> ();
00061   this->CellGroup = new vtkObjectVector<vtkMedGroup> ();
00062   this->AxisName = vtkStringArray::New();
00063   this->AxisUnit = vtkStringArray::New();
00064   this->AxisName->SetNumberOfValues(3);
00065   this->AxisUnit->SetNumberOfValues(3);
00066   this->MedIterator = -1;
00067   this->MeshType = MED_UNDEF_MESH_TYPE;
00068   this->StructuredGridType = MED_UNDEF_GRID_TYPE;
00069   this->ParentFile = NULL;
00070   this->AxisType = MED_CARTESIAN;
00071   this->SortingType = MED_SORT_DTIT;
00072   this->MeshDimension = 3;
00073   this->SpaceDimension = 3;
00074   this->IsSupportMesh = 0;
00075 }
00076 
00077 vtkMedMesh::~vtkMedMesh()
00078 {
00079   this->SetName(NULL);
00080   this->SetUniversalName(NULL);
00081   this->SetDescription(NULL);
00082   delete this->CellFamily;
00083   delete this->PointFamily;
00084   delete this->PointGroup;
00085   delete this->CellGroup;
00086   this->AxisName->Delete();
00087   this->AxisUnit->Delete();
00088   delete this->GridStep;
00089 }
00090 
00091 vtkMedGroup* vtkMedMesh::GetOrCreateGroup(int pointOrCell, const char* name)
00092 {
00093   if(pointOrCell == vtkMedUtilities::OnCell)
00094     {
00095     for(int g = 0; g < this->CellGroup->size(); g++)
00096       {
00097       vtkMedGroup* group = this->CellGroup->at(g);
00098       if(group != NULL && strcmp(name, group->GetName()) == 0)
00099         {
00100         return group;
00101         }
00102       }
00103     vtkMedGroup* group = vtkMedGroup::New();
00104     this->CellGroup->push_back(group);
00105     //group->SetPointOrCell(vtkMedUtilities::OnCell);
00106     group->SetName(name);
00107     group->Delete();
00108     return group;
00109     }
00110   else
00111     {
00112     for(int g = 0; g < this->PointGroup->size(); g++)
00113       {
00114       vtkMedGroup* group = this->PointGroup->at(g);
00115       if(group != NULL && strcmp(name, group->GetName()) == 0)
00116         {
00117         return group;
00118         }
00119       }
00120     vtkMedGroup* group = vtkMedGroup::New();
00121     this->CellGroup->push_back(group);
00122     //group->SetPointOrCell(vtkMedUtilities::OnPoint);
00123     group->SetName(name);
00124     group->Delete();
00125     return group;
00126     }
00127   return NULL;
00128 }
00129 
00130 int vtkMedMesh::GetNumberOfFamily()
00131 {
00132   return this->GetNumberOfCellFamily() + this->GetNumberOfPointFamily();
00133 }
00134 
00135 vtkMedFamily* vtkMedMesh::GetFamily(int index)
00136 {
00137   if(index < 0)
00138     return NULL;
00139   if(index < this->GetNumberOfCellFamily())
00140     return this->GetCellFamily(index);
00141   else if(index < GetNumberOfFamily())
00142     return this->GetPointFamily(index - this->GetNumberOfCellFamily());
00143   else return NULL;
00144 }
00145 
00146 vtkMedFamily* vtkMedMesh::GetOrCreateCellFamilyById(med_int id)
00147 {
00148   for(int i = 0; i < this->GetNumberOfCellFamily(); i++)
00149     {
00150     vtkMedFamily* family = this->GetCellFamily(i);
00151     if(family->GetId() == id)
00152       {
00153       return family;
00154       }
00155     }
00156   vtkMedFamily* family = vtkMedFamily::New();
00157   family->SetId(id);
00158   vtkstd::ostringstream sstr;
00159   sstr << "UNDEFINED_CELL_FAMILY_" << id;
00160   family->SetName(sstr.str().c_str());
00161   family->SetPointOrCell(vtkMedUtilities::OnCell);
00162   family->SetMedIterator(-1);
00163   this->AppendCellFamily(family);
00164   family->Delete();
00165   return family;
00166 }
00167 
00168 void  vtkMedMesh::SetNumberOfAxis(int naxis)
00169 {
00170   this->AxisName->SetNumberOfValues(naxis);
00171   this->AxisUnit->SetNumberOfValues(naxis);
00172 }
00173 
00174 int  vtkMedMesh::GetNumberOfAxis()
00175 {
00176   return this->AxisName->GetNumberOfValues();
00177 }
00178 
00179 vtkMedFamily* vtkMedMesh::GetOrCreatePointFamilyById(med_int id)
00180 {
00181   for(int i = 0; i < this->GetNumberOfPointFamily(); i++)
00182     {
00183     vtkMedFamily* family = this->GetPointFamily(i);
00184 
00185     if(family->GetId() == id)
00186       return family;
00187     }
00188   vtkMedFamily* family = vtkMedFamily::New();
00189   family->SetId(id);
00190   vtkstd::ostringstream sstr;
00191   sstr << "UNDEFINED_POINT_FAMILY_" << id;
00192   family->SetName(sstr.str().c_str());
00193   family->SetPointOrCell(vtkMedUtilities::OnPoint);
00194   this->AppendPointFamily(family);
00195   family->Delete();
00196   return family;
00197 }
00198 
00199 void  vtkMedMesh::AddGridStep(vtkMedGrid* grid)
00200 {
00201   this->GridStep->AddObject(grid->GetComputeStep(), grid);
00202 }
00203 
00204 void  vtkMedMesh::ClearGridStep()
00205 {
00206   this->GridStep->clear();
00207 }
00208 
00209 vtkMedGrid* vtkMedMesh::GetGridStep(const vtkMedComputeStep& cs)
00210 {
00211   return this->GridStep->GetObject(cs);
00212 }
00213 
00214 vtkMedGrid* vtkMedMesh::FindGridStep(const vtkMedComputeStep& cs,
00215                                      int strategy)
00216 {
00217   return this->GridStep->FindObject(cs, strategy);
00218 }
00219 
00220 void  vtkMedMesh::GatherGridTimes(std::set<med_float>& timeset)
00221 {
00222   this->GridStep->GatherTimes(timeset);
00223 }
00224 
00225 void  vtkMedMesh::GatherGridIterations(med_float time,
00226                                        std::set<med_int>& iterationset)
00227 {
00228   this->GridStep->GatherIterations(time, iterationset);
00229 }
00230 
00231 void  vtkMedMesh::ClearMedSupports()
00232 {
00233   med_int stepnb = this->GridStep->GetNumberOfObject();
00234   for(med_int stepid = 0; stepid<stepnb; stepid++ )
00235     {
00236     vtkMedGrid* grid = this->GridStep->GetObject(stepid);
00237     grid->ClearMedSupports();
00238     }
00239 }
00240 
00241 med_int vtkMedMesh::GetNumberOfGridStep()
00242 {
00243   return this->GridStep->GetNumberOfObject();
00244 }
00245 
00246 vtkMedGrid* vtkMedMesh::GetGridStep(med_int id)
00247 {
00248   return this->GridStep->GetObject(id);
00249 }
00250 
00251 void  vtkMedMesh::GatherMedEntities(std::set<vtkMedEntity>& entities)
00252 {
00253   vtkMedGrid* firstStep = this->GetGridStep(0);
00254   if(firstStep == NULL)
00255     return;
00256   
00257   firstStep->GatherMedEntities(entities);
00258 }
00259 
00260 void vtkMedMesh::PrintSelf(ostream& os, vtkIndent indent)
00261 {
00262   this->Superclass::PrintSelf(os, indent);
00263   PRINT_IVAR(os, indent, MedIterator);
00264   PRINT_OBJECT_VECTOR(os, indent, CellFamily);
00265   PRINT_OBJECT_VECTOR(os, indent, PointFamily);
00266   PRINT_OBJECT_VECTOR(os, indent, PointGroup);
00267   PRINT_OBJECT_VECTOR(os, indent, CellGroup);
00268 
00269 }