1 #include "vtkGenerateStructElement.h"
3 #include "vtkObjectFactory.h"
4 #include "vtkInformation.h"
5 #include "vtkInformationVector.h"
6 #include "vtkUnstructuredGrid.h"
7 #include "vtkCellData.h"
8 #include "vtkIdTypeArray.h"
10 #include "vtkMedUtilities.h"
11 #include "vtkMedStructElement.h"
12 #include "vtkMedConstantAttribute.h"
13 #include "vtkMedVariableAttribute.h"
15 class vtkGenerateStructElementCache
18 vtkGenerateStructElementCache(vtkMedStructElement* strelem, vtkUnstructuredGrid* ug)
20 for(int attid = 0; attid < strelem->GetNumberOfConstantAttribute(); attid++)
22 vtkMedConstantAttribute* att = strelem->GetConstantAttribute(attid);
23 this->cstAttribute[att->GetName()] = att;
26 for(int attid = 0; attid < strelem->GetNumberOfVariableAttribute(); attid++)
28 vtkMedVariableAttribute* att = strelem->GetVariableAttribute(attid);
29 vtkDataArray* array = ug->GetFieldData()->GetArray(att->GetName());
31 this->varAttribute[att->GetName()] = array;
35 bool HasParameter(const char* name)
37 return this->cstAttribute.find(name) != this->cstAttribute.end()
38 || this->varAttribute.find(name) != this->varAttribute.end();
41 double GetParameter1(const char* name, vtkIdType id)
43 if(this->cstAttribute.find(name) != this->cstAttribute.end())
45 vtkMedConstantAttribute* att = this->cstAttribute[name];
46 return att->GetValues()->GetVariantValue(0).ToDouble();
48 if(this->varAttribute.find(name) != this->varAttribute.end())
50 vtkDataArray* array = this->varAttribute[name];
51 return array->GetTuple1(id);
57 std::map<std::string, vtkMedConstantAttribute*> cstAttribute;
58 std::map<std::string, vtkDataArray*> varAttribute;
61 // vtkCxxRevisionMacro(vtkGenerateStructElement, "$Revision$");
62 vtkStandardNewMacro(vtkGenerateStructElement);
64 vtkGenerateStructElement::vtkGenerateStructElement()
69 vtkGenerateStructElement::~vtkGenerateStructElement()
74 int vtkGenerateStructElement::RequestData(vtkInformation* request,
75 vtkInformationVector** inputVector,
76 vtkInformationVector* outputVector)
78 vtkInformation* outInfo=outputVector->GetInformationObject(0);
80 vtkInformation* inputInfo=inputVector[0]->GetInformationObject(0);
82 vtkUnstructuredGrid* inug = vtkUnstructuredGrid::SafeDownCast(
83 inputInfo->Get(vtkDataObject::DATA_OBJECT()));
85 vtkUnstructuredGrid* outug = vtkUnstructuredGrid::SafeDownCast(
86 outInfo->Get(vtkDataObject::DATA_OBJECT()));
89 vtkMedStructElement* strelem = vtkMedStructElement::SafeDownCast(
90 inug->GetInformation()->Get(vtkMedUtilities::STRUCT_ELEMENT()));
92 std::cout << "Inside vtkGenerateStructElement::RequestData" << std::endl;
96 vtkDebugMacro("vtkGenerateStructElement needs a vtkMedStructElement information");
100 vtkIdTypeArray* strelemindex = vtkIdTypeArray::SafeDownCast(
101 inug->GetCellData()->GetArray("STRUCT_ELEMENT_INDEX"));
102 if(strelemindex == NULL)
104 vtkDebugMacro("vtkGenerateStructElement needs some information on the structural elements");
108 // loop over input cells.
109 // struct elements support are a set cells of same type following each other.
110 vtkIdType medid = -1;
111 vtkGenerateStructElementCache cache(strelem, inug);
113 std::string name = strelem->GetName();
115 if(name == MED_BALL_NAME)
117 std::cout << "vtkGenerateStructElement::RequestData ... if(name == MED_BALL_NAME)" << std::endl;
118 // sanity check : is the diameter defined?
119 if(!cache.HasParameter(MED_BALL_DIAMETER))
121 vtkErrorMacro("MED_BALL elements need a diameter");
124 std::cout << "inug->GetNumberOfCells() = " << inug->GetNumberOfCells() << std::endl;
125 for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
127 vtkIdType ballMedId = strelemindex->GetValue(2*cellId);
128 double balldiam = this->GetParameter1(MED_BALL_DIAMETER, ballMedId, cache);
129 std::cout << balldiam << " - ";
131 //this->GenerateBall(inug, cellId, balldiam, outug);
133 std::cout << std::endl;
135 else if(name == MED_PARTICLE_NAME)
137 bool hasLabel = cache.HasParameter(MED_PARTICLE_LABEL);
138 for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
142 vtkIdType particleMedId = strelemindex->GetValue(2*cellId);
143 double particlelabel = this->GetParameter1(MED_PARTICLE_LABEL, particleMedId, cache);
146 // this->GenerateParticle(inug, cellId, particlelabel, outug);
151 // this->GenerateParticle(inug, cellId, outug);
155 else if(name == MED_BEAM_NAME)
157 // sanity check : is the diameter defined?
158 if(!cache.HasParameter(MED_BEAM_THICKNESS))
160 vtkErrorMacro("MED_BEAM elements need a thickness");
163 for(vtkIdType cellId = 0; cellId < inug->GetNumberOfCells(); cellId++)
165 vtkIdType cellmedid = strelemindex->GetValue(2*cellId);
166 if(cellmedid != medid)
168 // this means that a new beam begins
170 double thickness = this->GetParameter1(MED_BEAM_THICKNESS, medid, cache);
172 //TODO : generate a beam.
173 // rem : a beam can span several segments.
180 vtkErrorMacro("structural elements of type " << name << " are not supported");
186 double vtkGenerateStructElement::GetParameter1(const char* name,
188 vtkGenerateStructElementCache& cache)
190 #ifdef WIN32 //rnv : Avoid compliation error in the VS under windows.
195 void vtkGenerateStructElement::PrintSelf(ostream& os, vtkIndent indent)
197 this->Superclass::PrintSelf(os, indent);