1 // Copyright (C) 2010-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkGenerateStructElement.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkInformation.h"
24 #include "vtkInformationVector.h"
25 #include "vtkUnstructuredGrid.h"
26 #include "vtkCellData.h"
27 #include "vtkIdTypeArray.h"
29 #include "vtkMedUtilities.h"
30 #include "vtkMedStructElement.h"
31 #include "vtkMedConstantAttribute.h"
32 #include "vtkMedVariableAttribute.h"
34 class vtkGenerateStructElementCache
37 vtkGenerateStructElementCache(vtkMedStructElement* strelem, vtkUnstructuredGrid* ug)
39 for(int attid = 0; attid < strelem->GetNumberOfConstantAttribute(); attid++)
41 vtkMedConstantAttribute* att = strelem->GetConstantAttribute(attid);
42 this->cstAttribute[att->GetName()] = att;
45 for(int attid = 0; attid < strelem->GetNumberOfVariableAttribute(); attid++)
47 vtkMedVariableAttribute* att = strelem->GetVariableAttribute(attid);
48 vtkDataArray* array = ug->GetFieldData()->GetArray(att->GetName());
50 this->varAttribute[att->GetName()] = array;
54 bool HasParameter(const char* name)
56 return this->cstAttribute.find(name) != this->cstAttribute.end()
57 || this->varAttribute.find(name) != this->varAttribute.end();
60 double GetParameter1(const char* name, vtkIdType id)
62 if(this->cstAttribute.find(name) != this->cstAttribute.end())
64 vtkMedConstantAttribute* att = this->cstAttribute[name];
65 return att->GetValues()->GetVariantValue(0).ToDouble();
67 if(this->varAttribute.find(name) != this->varAttribute.end())
69 vtkDataArray* array = this->varAttribute[name];
70 return array->GetTuple1(id);
76 std::map<std::string, vtkMedConstantAttribute*> cstAttribute;
77 std::map<std::string, vtkDataArray*> varAttribute;
80 // vtkCxxRevisionMacro(vtkGenerateStructElement, "$Revision$");
81 vtkStandardNewMacro(vtkGenerateStructElement);
83 vtkGenerateStructElement::vtkGenerateStructElement()
88 vtkGenerateStructElement::~vtkGenerateStructElement()
93 int vtkGenerateStructElement::RequestData(vtkInformation* request,
94 vtkInformationVector** inputVector,
95 vtkInformationVector* outputVector)
97 vtkInformation* outInfo=outputVector->GetInformationObject(0);
99 vtkInformation* inputInfo=inputVector[0]->GetInformationObject(0);
101 vtkUnstructuredGrid* inug = vtkUnstructuredGrid::SafeDownCast(
102 inputInfo->Get(vtkDataObject::DATA_OBJECT()));
104 vtkUnstructuredGrid* outug = vtkUnstructuredGrid::SafeDownCast(
105 outInfo->Get(vtkDataObject::DATA_OBJECT()));
108 vtkMedStructElement* strelem = vtkMedStructElement::SafeDownCast(
109 inug->GetInformation()->Get(vtkMedUtilities::STRUCT_ELEMENT()));
111 std::cout << "Inside vtkGenerateStructElement::RequestData" << std::endl;
115 vtkDebugMacro("vtkGenerateStructElement needs a vtkMedStructElement information");
119 vtkIdTypeArray* strelemindex = vtkIdTypeArray::SafeDownCast(
120 inug->GetCellData()->GetArray("STRUCT_ELEMENT_INDEX"));
121 if(strelemindex == NULL)
123 vtkDebugMacro("vtkGenerateStructElement needs some information on the structural elements");
127 // loop over input cells.
128 // struct elements support are a set cells of same type following each other.
129 vtkIdType medid = -1;
130 vtkGenerateStructElementCache cache(strelem, inug);
132 std::string name = strelem->GetName();
134 if(name == MED_BALL_NAME)
136 std::cout << "vtkGenerateStructElement::RequestData ... if(name == MED_BALL_NAME)" << std::endl;
137 // sanity check : is the diameter defined?
138 if(!cache.HasParameter(MED_BALL_DIAMETER))
140 vtkErrorMacro("MED_BALL elements need a diameter");
143 std::cout << "inug->GetNumberOfCells() = " << inug->GetNumberOfCells() << std::endl;
144 for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
146 vtkIdType ballMedId = strelemindex->GetValue(2*cellId);
147 double balldiam = this->GetParameter1(MED_BALL_DIAMETER, ballMedId, cache);
148 std::cout << balldiam << " - ";
150 //this->GenerateBall(inug, cellId, balldiam, outug);
152 std::cout << std::endl;
154 else if(name == MED_PARTICLE_NAME)
156 bool hasLabel = cache.HasParameter(MED_PARTICLE_LABEL);
157 for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
161 vtkIdType particleMedId = strelemindex->GetValue(2*cellId);
162 double particlelabel = this->GetParameter1(MED_PARTICLE_LABEL, particleMedId, cache);
165 // this->GenerateParticle(inug, cellId, particlelabel, outug);
170 // this->GenerateParticle(inug, cellId, outug);
174 else if(name == MED_BEAM_NAME)
176 // sanity check : is the diameter defined?
177 if(!cache.HasParameter(MED_BEAM_THICKNESS))
179 vtkErrorMacro("MED_BEAM elements need a thickness");
182 for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
184 vtkIdType cellmedid = strelemindex->GetValue(2*cellId);
185 if(cellmedid != medid)
187 // this means that a new beam begins
189 double thickness = this->GetParameter1(MED_BEAM_THICKNESS, medid, cache);
191 //TODO : generate a beam.
192 // rem : a beam can span several segments.
199 vtkErrorMacro("structural elements of type " << name << " are not supported");
205 double vtkGenerateStructElement::GetParameter1(const char* name,
207 vtkGenerateStructElementCache& cache)
209 #ifdef WIN32 //rnv : Avoid compliation error in the VS under windows.
214 void vtkGenerateStructElement::PrintSelf(ostream& os, vtkIndent indent)
216 this->Superclass::PrintSelf(os, indent);