Fem: Read material info from .frd file
This commit is contained in:
committed by
Benjamin Nauck
parent
2777999d03
commit
3ae8d45506
@@ -33,6 +33,7 @@
|
||||
#include <SMESH_Mesh.hxx>
|
||||
|
||||
#include <vtkCellArray.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkDataArray.h>
|
||||
#include <vtkDataSetReader.h>
|
||||
#include <vtkDataSetWriter.h>
|
||||
@@ -1177,7 +1178,7 @@ void valueFromLine<double>(const std::string_view::iterator& it, int digits, dou
|
||||
|
||||
// add cell from sorted nodes
|
||||
template<typename T>
|
||||
void addCell(vtkSmartPointer<vtkCellArray>& cellArray, const std::vector<int>& topoElem)
|
||||
void addCell(vtkCellArray* cellArray, const std::vector<int>& topoElem)
|
||||
{
|
||||
vtkSmartPointer<T> cell = vtkSmartPointer<T>::New();
|
||||
cell->GetPointIds()->SetNumberOfIds(topoElem.size());
|
||||
@@ -1190,7 +1191,7 @@ void addCell(vtkSmartPointer<vtkCellArray>& cellArray, const std::vector<int>& t
|
||||
|
||||
// fill cell array
|
||||
void fillCell(
|
||||
vtkSmartPointer<vtkCellArray>& cellArray,
|
||||
vtkCellArray* cellArray,
|
||||
std::vector<int>& topoElem,
|
||||
std::vector<int>& vtkType,
|
||||
ElementType elemType
|
||||
@@ -1363,7 +1364,9 @@ std::vector<int> readElements(
|
||||
std::ifstream& ifstr,
|
||||
const std::string& lines,
|
||||
const std::map<int, int>& mapNodes,
|
||||
vtkSmartPointer<vtkCellArray>& cellArray
|
||||
vtkCellArray* cellArray,
|
||||
vtkIntArray* material,
|
||||
vtkIntArray* group
|
||||
)
|
||||
{
|
||||
std::string line;
|
||||
@@ -1380,6 +1383,12 @@ std::vector<int> readElements(
|
||||
std::vector<int> topoElem;
|
||||
std::vector<int> vtkType;
|
||||
|
||||
material->SetNumberOfComponents(1);
|
||||
material->SetName("Material");
|
||||
|
||||
group->SetNumberOfComponents(1);
|
||||
group->SetName("Group");
|
||||
|
||||
std::string_view view {lines};
|
||||
|
||||
std::string_view sub = view.substr(keyCode.length() + 18);
|
||||
@@ -1412,6 +1421,8 @@ std::vector<int> readElements(
|
||||
// add cell to cellArray
|
||||
if (topoElem.size() == mapCcxTypeNodes[static_cast<ElementType>(info[0])]) {
|
||||
fillCell(cellArray, topoElem, vtkType, static_cast<ElementType>(info[0]));
|
||||
group->InsertNextValue(info[1]);
|
||||
material->InsertNextValue(info[2]);
|
||||
topoElem.clear();
|
||||
mapElem[elem] = elemID++;
|
||||
}
|
||||
@@ -1657,6 +1668,8 @@ vtkSmartPointer<vtkMultiBlockDataSet> readFRD(std::ifstream& ifstr)
|
||||
std::string line;
|
||||
std::map<int, int> mapNodes;
|
||||
std::vector<int> cellTypes;
|
||||
auto materialArray = vtkSmartPointer<vtkIntArray>::New();
|
||||
auto groupArray = vtkSmartPointer<vtkIntArray>::New();
|
||||
|
||||
while (std::getline(ifstr, line)) {
|
||||
std::string keyCode = " 2C";
|
||||
@@ -1669,7 +1682,7 @@ vtkSmartPointer<vtkMultiBlockDataSet> readFRD(std::ifstream& ifstr)
|
||||
keyCode = " 3C";
|
||||
if (view.rfind(keyCode, 0) == 0) {
|
||||
// read elements block
|
||||
cellTypes = readElements(ifstr, line, mapNodes, cells);
|
||||
cellTypes = readElements(ifstr, line, mapNodes, cells, materialArray, groupArray);
|
||||
}
|
||||
keyCode = " 1P";
|
||||
if (view.rfind(keyCode, 0) == 0) {
|
||||
@@ -1699,6 +1712,8 @@ vtkSmartPointer<vtkMultiBlockDataSet> readFRD(std::ifstream& ifstr)
|
||||
grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
grid->SetPoints(points);
|
||||
grid->SetCells(cellTypes.data(), cells);
|
||||
grid->GetCellData()->AddArray(materialArray);
|
||||
grid->GetCellData()->AddArray(groupArray);
|
||||
|
||||
// create TimeValue metadata
|
||||
auto stepValue = createTimeValue(info.value);
|
||||
|
||||
@@ -433,10 +433,11 @@ void ViewProviderFemPostObject::updateProperties()
|
||||
}
|
||||
}
|
||||
|
||||
vtkCellData* cell = poly->GetCellData();
|
||||
for (int i = 0; i < cell->GetNumberOfArrays(); ++i) {
|
||||
colorArrays.emplace_back(cell->GetArrayName(i));
|
||||
}
|
||||
// don't add cell data arrays until they are supported in the 3d view
|
||||
// vtkCellData* cell = poly->GetCellData();
|
||||
// for (int i = 0; i < cell->GetNumberOfArrays(); ++i) {
|
||||
// colorArrays.emplace_back(cell->GetArrayName(i));
|
||||
//}
|
||||
|
||||
App::Enumeration empty;
|
||||
Field.setValue(empty);
|
||||
|
||||
Reference in New Issue
Block a user