Back to index

salome-paravis  6.5.0
vtkMedField.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 "vtkMedField.h"
00021 
00022 #include "vtkObjectFactory.h"
00023 #include "vtkSmartPointer.h"
00024 #include "vtkStringArray.h"
00025 #include "vtkMedFieldOverEntity.h"
00026 #include "vtkMedFieldStep.h"
00027 #include "vtkMedUtilities.h"
00028 #include "vtkMedFieldOnProfile.h"
00029 #include "vtkMedInterpolation.h"
00030 #include "vtkMedFile.h"
00031 
00032 #include <string>
00033 #include <map>
00034 using namespace std;
00035 
00036 vtkCxxGetObjectVectorMacro(vtkMedField, Interpolation, vtkMedInterpolation);
00037 vtkCxxSetObjectVectorMacro(vtkMedField, Interpolation, vtkMedInterpolation);
00038 
00039 vtkCxxSetObjectMacro(vtkMedField, ParentFile, vtkMedFile);
00040 
00041 vtkCxxRevisionMacro(vtkMedField, "$Revision: 1.1.4.7.2.1 $")
00042 vtkStandardNewMacro(vtkMedField)
00043 
00044 vtkMedField::vtkMedField()
00045 {
00046   this->NumberOfComponent = -1;
00047   this->DataType = MED_FLOAT64;
00048   this->Name = NULL;
00049   this->MeshName = NULL;
00050   this->TimeUnit = NULL;
00051   this->FieldStep = new vtkMedComputeStepMap<vtkMedFieldStep> ();
00052   this->Unit = vtkStringArray::New();
00053   this->ComponentName = vtkStringArray::New();
00054   this->Interpolation = new vtkObjectVector<vtkMedInterpolation> ();
00055   this->MedIterator = -1;
00056   this->FieldType = UnknownFieldType;
00057   this->ParentFile = NULL;
00058   this->Local = 1;
00059 }
00060 
00061 vtkMedField::~vtkMedField()
00062 {
00063   this->SetName(NULL);
00064   this->SetMeshName(NULL);
00065   this->SetTimeUnit(NULL);
00066   delete this->FieldStep;
00067   this->Unit->Delete();
00068   this->ComponentName->Delete();
00069 }
00070 
00071 void vtkMedField::ComputeFieldType()
00072 {
00073   this->FieldType = UnknownFieldType;
00074 
00075   // look for the med_entity_type
00076   // on which this field is.
00077   for(int sid = 0; sid < this->GetNumberOfFieldStep(); sid++)
00078     {
00079     vtkMedFieldStep* step = this->GetFieldStep(sid);
00080   
00081     for(int eid = 0; eid < step->GetNumberOfFieldOverEntity(); eid++)
00082       {
00083       vtkMedFieldOverEntity* fieldOverEntity = step->GetFieldOverEntity(eid);
00084       med_entity_type type = fieldOverEntity->GetEntity().EntityType;
00085 
00086       if (type == MED_NODE)
00087         {
00088         this->FieldType |= PointField;
00089         }
00090       else if(type == MED_NODE_ELEMENT )
00091         {
00092         this->FieldType |= ElnoField;
00093         }
00094       else
00095         {
00096         for(int pid=0; pid<fieldOverEntity->GetNumberOfFieldOnProfile(); pid++)
00097           {
00098           vtkMedFieldOnProfile* fop = fieldOverEntity->GetFieldOnProfile(pid);
00099           const char* locname = fop->GetLocalizationName();
00100           if(strcmp(locname, MED_GAUSS_ELNO) == 0 )
00101             {
00102             this->FieldType = ElnoField;
00103             }
00104           else if(strcmp(locname, MED_NO_LOCALIZATION) != 0 )
00105             {
00106             this->FieldType |= QuadratureField;
00107             }
00108           else
00109             {
00110             this->FieldType |= CellField;
00111             }
00112           }
00113         }
00114       }
00115     }
00116     
00117   if(this->FieldType == UnknownFieldType) 
00118     this->FieldType = PointField;
00119 }
00120 
00121 int vtkMedField::HasManyFieldTypes()
00122 {
00123   int numberOfTypes = 0;
00124   numberOfTypes += (this->FieldType & vtkMedField::PointField) != 0;
00125   numberOfTypes += (this->FieldType & vtkMedField::CellField) != 0;
00126   numberOfTypes += (this->FieldType & vtkMedField::QuadratureField) != 0;
00127   numberOfTypes += (this->FieldType & vtkMedField::ElnoField) != 0;
00128 
00129   return numberOfTypes > 1;
00130 }
00131 
00132 int vtkMedField::GetFirstType()
00133 {
00134   if((this->FieldType & vtkMedField::PointField) != 0)
00135     return vtkMedField::PointField;
00136 
00137   if((this->FieldType & vtkMedField::CellField) != 0)
00138     return vtkMedField::CellField;
00139 
00140   if((this->FieldType & vtkMedField::QuadratureField) != 0)
00141     return vtkMedField::QuadratureField;
00142 
00143   if((this->FieldType & vtkMedField::ElnoField) != 0)
00144     return vtkMedField::ElnoField;
00145 }
00146 
00147 void  vtkMedField::ExtractFieldType(vtkMedField* otherfield, int type)
00148 {
00149   this->SetName(otherfield->GetName());
00150   this->SetLocal(otherfield->GetLocal());
00151   this->SetMedIterator(otherfield->GetMedIterator());
00152   this->SetDataType(otherfield->GetDataType());
00153   this->SetMeshName(otherfield->GetMeshName());
00154   this->SetTimeUnit(otherfield->GetTimeUnit());
00155   this->SetParentFile(otherfield->GetParentFile());
00156 
00157   this->SetNumberOfComponent(otherfield->GetNumberOfComponent());
00158   for(int i=0; i< this->GetNumberOfComponent(); i++)
00159     {
00160     this->GetComponentName()->SetValue(i, otherfield->
00161                                        GetComponentName()->GetValue(i));
00162     }
00163 
00164   this->AllocateNumberOfInterpolation(otherfield->GetNumberOfInterpolation());
00165   for(int i=0; i<this->GetNumberOfInterpolation(); i++)
00166     {
00167     this->SetInterpolation(i, otherfield->GetInterpolation(i));
00168     }
00169 
00170   this->GetUnit()->SetNumberOfValues(
00171       otherfield->GetUnit()->GetNumberOfValues());
00172   for(int i=0; i<this->GetUnit()->GetNumberOfValues(); i++)
00173     {
00174     this->GetUnit()->SetValue(i, otherfield->GetUnit()->GetValue(i));
00175     }
00176 
00177   int nstep = otherfield->GetNumberOfFieldStep();
00178   map<vtkMedFieldStep*, vtkMedFieldStep*> stepmap;
00179   for(int stepid=0; stepid<nstep; stepid++)
00180     {
00181     vtkMedFieldStep* otherstep = otherfield->GetFieldStep(stepid);
00182     vtkMedFieldStep* step = vtkMedFieldStep::New();
00183     step->SetComputeStep(otherstep->GetComputeStep());
00184     this->AddFieldStep(step);
00185     step->Delete();
00186 
00187     stepmap[otherstep] = step;
00188 
00189     vtkMedFieldStep* previousstep = NULL;
00190     if(stepmap.find(otherstep->GetPreviousStep()) != stepmap.end())
00191       {
00192       previousstep = stepmap[otherstep->GetPreviousStep()];
00193       }
00194     step->SetPreviousStep(previousstep);
00195     step->SetParentField(this);
00196     step->SetMeshComputeStep(otherstep->GetMeshComputeStep());
00197 
00198     for(int eid=0; eid<otherstep->GetNumberOfFieldOverEntity(); eid++)
00199       {
00200       vtkMedFieldOverEntity* fieldOverEntity = otherstep->GetFieldOverEntity(eid);
00201 
00202       if(type == vtkMedField::PointField)
00203         {
00204         if(fieldOverEntity->GetEntity().EntityType != MED_NODE)
00205           {
00206           continue;
00207           }
00208         step->AppendFieldOverEntity(fieldOverEntity);
00209         otherstep->RemoveFieldOverEntity(fieldOverEntity);
00210         fieldOverEntity->SetParentStep(step);
00211         }
00212       else if(type == vtkMedField::ElnoField)
00213         {
00214         if(fieldOverEntity->GetEntity().EntityType != MED_NODE_ELEMENT)
00215           {
00216           continue;
00217           }
00218 
00219         step->AppendFieldOverEntity(fieldOverEntity);
00220         otherstep->RemoveFieldOverEntity(fieldOverEntity);
00221         eid--;
00222         fieldOverEntity->SetParentStep(step);
00223         }
00224       else
00225         {
00226         if(fieldOverEntity->GetEntity().EntityType == MED_NODE)
00227           {
00228           continue;
00229           }
00230         vtkMedFieldOverEntity* newfoe = vtkMedFieldOverEntity::New();
00231         newfoe->SetEntity(fieldOverEntity->GetEntity());
00232         newfoe->SetHasProfile(fieldOverEntity->GetHasProfile());
00233         newfoe->SetParentStep(step);
00234         step->AppendFieldOverEntity(newfoe);
00235         newfoe->Delete();
00236         for(int pid=0; pid<fieldOverEntity->GetNumberOfFieldOnProfile(); pid++)
00237           {
00238           vtkMedFieldOnProfile* fop = fieldOverEntity->GetFieldOnProfile(pid);
00239           const char* locname = fop->GetLocalizationName();
00240           if((type == vtkMedField::QuadratureField
00241              && strcmp(locname, MED_NO_LOCALIZATION) != 0) ||
00242              (type == vtkMedField::CellField
00243              && strcmp(locname, MED_NO_LOCALIZATION) == 0 ))
00244             {
00245             newfoe->AppendFieldOnProfile(fop);
00246             fieldOverEntity->RemoveFieldOnProfile(fop);
00247             pid--;
00248             fop->SetParentFieldOverEntity(newfoe);
00249             }
00250           }
00251         if(fieldOverEntity->GetNumberOfFieldOnProfile() == 0)
00252           {
00253           otherstep->RemoveFieldOverEntity(fieldOverEntity);
00254           eid--;
00255           }
00256         }
00257       }
00258     }
00259 
00260   this->ComputeFieldType();
00261   otherfield->ComputeFieldType();
00262 }
00263 
00264 void vtkMedField::SetNumberOfComponent(int ncomp)
00265 {
00266   if (this->NumberOfComponent == ncomp)
00267     return;
00268 
00269   this->NumberOfComponent = ncomp;
00270   this->GetUnit()->SetNumberOfValues(this->NumberOfComponent);
00271   this->GetComponentName()->SetNumberOfValues(this->NumberOfComponent);
00272 
00273   this->Modified();
00274 }
00275 
00276 void  vtkMedField::AddFieldStep(vtkMedFieldStep* step)
00277 {
00278   this->FieldStep->AddObject(step->GetComputeStep(), step);
00279 }
00280 
00281 void  vtkMedField::ClearFieldStep()
00282 {
00283   this->FieldStep->clear();
00284 }
00285 
00286 vtkMedFieldStep* vtkMedField::GetFieldStep(const vtkMedComputeStep& cs)
00287 {
00288   return this->FieldStep->GetObject(cs);
00289 }
00290 
00291 vtkMedFieldStep* vtkMedField::FindFieldStep(const vtkMedComputeStep& cs,
00292                                             int strategy)
00293 {
00294   return this->FieldStep->FindObject(cs, strategy);
00295 }
00296 
00297 med_int vtkMedField::GetNumberOfFieldStep()
00298 {
00299   return this->FieldStep->GetNumberOfObject();
00300 }
00301 
00302 vtkMedFieldStep* vtkMedField::GetFieldStep(med_int id)
00303 {
00304   return this->FieldStep->GetObject(id);
00305 }
00306 
00307 void  vtkMedField::GatherFieldTimes(std::set<med_float>& times)
00308 {
00309   this->FieldStep->GatherTimes(times);
00310 }
00311 
00312 void  vtkMedField::GatherFieldIterations(med_float time,
00313                                          std::set<med_int>& iterations)
00314 {
00315   this->FieldStep->GatherIterations(time, iterations);
00316 }
00317 
00318 void vtkMedField::PrintSelf(ostream& os, vtkIndent indent)
00319 {
00320   this->Superclass::PrintSelf(os, indent);
00321   PRINT_IVAR(os, indent, MedIterator);
00322   PRINT_IVAR(os, indent, NumberOfComponent);
00323   PRINT_IVAR(os, indent, FieldType);
00324   PRINT_IVAR(os, indent, DataType);
00325   PRINT_IVAR(os, indent, Local);
00326 }