Back to index

salome-paravis  6.5.0
vtkGenerateStructElement.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 "vtkGenerateStructElement.h"
00021 
00022 #include "vtkObjectFactory.h"
00023 #include "vtkInformation.h"
00024 #include "vtkInformationVector.h"
00025 #include "vtkUnstructuredGrid.h"
00026 #include "vtkCellData.h"
00027 #include "vtkIdTypeArray.h"
00028 
00029 #include "vtkMedUtilities.h"
00030 #include "vtkMedStructElement.h"
00031 #include "vtkMedConstantAttribute.h"
00032 #include "vtkMedVariableAttribute.h"
00033 
00034 class vtkGenerateStructElementCache
00035 {
00036 public :
00037   vtkGenerateStructElementCache(vtkMedStructElement* strelem, vtkUnstructuredGrid* ug)
00038     {
00039     for(int attid = 0; attid < strelem->GetNumberOfConstantAttribute(); attid++)
00040       {
00041       vtkMedConstantAttribute* att = strelem->GetConstantAttribute(attid);
00042       this->cstAttribute[att->GetName()] = att;
00043       }
00044 
00045     for(int attid = 0; attid < strelem->GetNumberOfVariableAttribute(); attid++)
00046       {
00047       vtkMedVariableAttribute* att = strelem->GetVariableAttribute(attid);
00048       vtkDataArray* array = ug->GetFieldData()->GetArray(att->GetName());
00049       if(array != NULL)
00050         this->varAttribute[att->GetName()] = array;
00051       }
00052     }
00053 
00054   bool HasParameter(const char* name)
00055     {
00056     return this->cstAttribute.find(name) != this->cstAttribute.end()
00057         || this->varAttribute.find(name) != this->varAttribute.end();
00058     }
00059 
00060   double GetParameter1(const char* name, vtkIdType id)
00061     {
00062     if(this->cstAttribute.find(name) != this->cstAttribute.end())
00063       {
00064       vtkMedConstantAttribute* att = this->cstAttribute[name];
00065       return att->GetValues()->GetVariantValue(0).ToDouble();
00066       }
00067     if(this->varAttribute.find(name) != this->varAttribute.end())
00068       {
00069       vtkDataArray* array = this->varAttribute[name];
00070       return array->GetTuple1(id);
00071       }
00072     return 0.0;
00073     }
00074 
00075 protected :
00076   std::map<std::string, vtkMedConstantAttribute*> cstAttribute;
00077   std::map<std::string, vtkDataArray*> varAttribute;
00078 };
00079 
00080 vtkCxxRevisionMacro(vtkGenerateStructElement, "$Revision: 1.1.2.3.2.1 $");
00081 vtkStandardNewMacro(vtkGenerateStructElement);
00082 
00083 vtkGenerateStructElement::vtkGenerateStructElement()
00084 {
00085 
00086 }
00087 
00088 vtkGenerateStructElement::~vtkGenerateStructElement()
00089 {
00090 
00091 }
00092 
00093 int vtkGenerateStructElement::RequestData(vtkInformation* request,
00094                           vtkInformationVector** inputVector,
00095                           vtkInformationVector* outputVector)
00096 {
00097   vtkInformation* outInfo=outputVector->GetInformationObject(0);
00098 
00099   vtkInformation* inputInfo=inputVector[0]->GetInformationObject(0);
00100 
00101   vtkUnstructuredGrid* inug = vtkUnstructuredGrid::SafeDownCast(
00102       inputInfo->Get(vtkDataObject::DATA_OBJECT()));
00103 
00104   vtkUnstructuredGrid* outug = vtkUnstructuredGrid::SafeDownCast(
00105       outInfo->Get(vtkDataObject::DATA_OBJECT()));
00106   outug->Initialize();
00107 
00108   vtkMedStructElement* strelem = vtkMedStructElement::SafeDownCast(
00109       inug->GetInformation()->Get(vtkMedUtilities::STRUCT_ELEMENT()));
00110 
00111   if(strelem == NULL)
00112     {
00113     vtkDebugMacro("vtkGenerateStructElement needs a vtkMedStructElement information");
00114     return 1;
00115     }
00116 
00117   vtkIdTypeArray* strelemindex = vtkIdTypeArray::SafeDownCast(
00118       inug->GetCellData()->GetArray("STRUCT_ELEMENT_INDEX"));
00119   if(strelemindex == NULL)
00120     {
00121     vtkDebugMacro("vtkGenerateStructElement needs some information on the structural elements");
00122     return 1;
00123     }
00124 
00125   // loop over input cells.
00126   // struct elements support are a set cells of same type following each other.
00127   vtkIdType medid = -1;
00128   vtkGenerateStructElementCache cache(strelem, inug);
00129 
00130   std::string name = strelem->GetName();
00131 
00132   if(name == MED_BALL_NAME)
00133     {
00134     // sanity check : is the diameter defined?
00135     if(!cache.HasParameter(MED_BALL_DIAMETER))
00136       {
00137       vtkErrorMacro("MED_BALL elements need a diameter");
00138       return 1;
00139       }
00140     for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
00141       {
00142       vtkIdType ballMedId = strelemindex->GetValue(2*cellId);
00143       double balldiam = this->GetParameter1(MED_BALL_DIAMETER, ballMedId, cache);
00144 
00145       //TODO
00146       //this->GenerateBall(inug, cellId, balldiam, outug);
00147       }
00148     }
00149   else if(name == MED_PARTICLE_NAME)
00150     {
00151     bool hasLabel = cache.HasParameter(MED_PARTICLE_LABEL);
00152     for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
00153       {
00154       if(hasLabel)
00155         {
00156         vtkIdType particleMedId = strelemindex->GetValue(2*cellId);
00157         double particlelabel = this->GetParameter1(MED_PARTICLE_LABEL, particleMedId, cache);
00158 
00159         //TODO
00160         //  this->GenerateParticle(inug, cellId, particlelabel, outug);
00161         }
00162       else
00163         {
00164         //TODO
00165         //  this->GenerateParticle(inug, cellId, outug);
00166         }
00167       }
00168     }
00169   else if(name == MED_BEAM_NAME)
00170     {
00171     // sanity check : is the diameter defined?
00172     if(!cache.HasParameter(MED_BEAM_THICKNESS))
00173       {
00174       vtkErrorMacro("MED_BEAM elements need a thickness");
00175       return 1;
00176       }
00177     for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
00178       {
00179       vtkIdType cellmedid = strelemindex->GetValue(2*cellId);
00180       if(cellmedid != medid)
00181         {
00182         // this means that a new beam begins
00183         medid = cellmedid;
00184         double thickness = this->GetParameter1(MED_BEAM_THICKNESS, medid, cache);
00185 
00186         //TODO : generate a beam.
00187         // rem : a beam can span several segments.
00188 
00189         }
00190       }
00191     }
00192   else
00193     {
00194     vtkErrorMacro("structural elements of type " << name << " are not supported");
00195     }
00196 
00197   return 1;
00198 }
00199 
00200 double  vtkGenerateStructElement::GetParameter1(const char* name,
00201                               vtkIdType medid,
00202                               vtkGenerateStructElementCache& cache)
00203 {
00204 #ifdef WIN32 //rnv : Avoid compliation error in the VS under windows.
00205   return 0;
00206 #endif
00207 }
00208 
00209 void  vtkGenerateStructElement::PrintSelf(ostream& os, vtkIndent indent)
00210 {
00211   this->Superclass::PrintSelf(os, indent);
00212 }