FEM: vtk tools, some comments, white spaces and changes from message to log
This commit is contained in:
@@ -438,12 +438,12 @@ void exportFemMeshCells(vtkSmartPointer<vtkUnstructuredGrid> grid, const SMDS_Vo
|
||||
void FemVTKTools::exportVTKMesh(const FemMesh* mesh, vtkSmartPointer<vtkUnstructuredGrid> grid, float scale)
|
||||
{
|
||||
|
||||
Base::Console().Message("Start: VTK mesh builder ======================\n");
|
||||
Base::Console().Log("Start: VTK mesh builder ======================\n");
|
||||
SMESH_Mesh* smesh = const_cast<SMESH_Mesh*>(mesh->getSMesh());
|
||||
SMESHDS_Mesh* meshDS = smesh->GetMeshDS();
|
||||
|
||||
// nodes
|
||||
Base::Console().Message(" Start: VTK mesh builder nodes.\n");
|
||||
Base::Console().Log(" Start: VTK mesh builder nodes.\n");
|
||||
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
SMDS_NodeIteratorPtr aNodeIter = meshDS->nodesIterator();
|
||||
@@ -451,15 +451,18 @@ void FemVTKTools::exportVTKMesh(const FemMesh* mesh, vtkSmartPointer<vtkUnstruct
|
||||
while (aNodeIter->more()) {
|
||||
const SMDS_MeshNode* node = aNodeIter->next(); // why float, not double?
|
||||
double coords[3] = {double(node->X()*scale), double(node->Y()*scale), double(node->Z()*scale)};
|
||||
points->InsertPoint(node->GetID()-1, coords); // memory is allocated by VTK points size = max node id, points will be inserted in SMESH point gaps too
|
||||
points->InsertPoint(node->GetID()-1, coords);
|
||||
// memory is allocated by VTK points size for max node id, not for point count
|
||||
// if the SMESH mesh has gaps in node numbering, points without any element assignement will be inserted in these point gaps too
|
||||
// this needs to be taken into account on node mapping when FreeCAD FEM results are exported to vtk
|
||||
}
|
||||
grid->SetPoints(points);
|
||||
// nodes debugging
|
||||
const SMDS_MeshInfo& info = meshDS->GetMeshInfo();
|
||||
Base::Console().Message(" Size of nodes in SMESH grid: %i.\n", info.NbNodes());
|
||||
Base::Console().Log(" Size of nodes in SMESH grid: %i.\n", info.NbNodes());
|
||||
const vtkIdType nNodes = grid->GetNumberOfPoints();
|
||||
Base::Console().Message(" Size of nodes in VTK grid: %i.\n", nNodes);
|
||||
Base::Console().Message(" End: VTK mesh builder nodes.\n");
|
||||
Base::Console().Log(" Size of nodes in VTK grid: %i.\n", nNodes);
|
||||
Base::Console().Log(" End: VTK mesh builder nodes.\n");
|
||||
|
||||
// faces
|
||||
SMDS_FaceIteratorPtr aFaceIter = meshDS->facesIterator();
|
||||
@@ -469,20 +472,20 @@ void FemVTKTools::exportVTKMesh(const FemMesh* mesh, vtkSmartPointer<vtkUnstruct
|
||||
SMDS_VolumeIteratorPtr aVolIter = meshDS->volumesIterator();
|
||||
exportFemMeshCells(grid, aVolIter);
|
||||
|
||||
Base::Console().Message("End: VTK mesh builder ======================\n");
|
||||
Base::Console().Log("End: VTK mesh builder ======================\n");
|
||||
}
|
||||
|
||||
void FemVTKTools::writeVTKMesh(const char* filename, const FemMesh* mesh)
|
||||
{
|
||||
|
||||
Base::TimeInfo Start;
|
||||
Base::Console().Message("Start: write FemMesh from VTK unstructuredGrid ======================\n");
|
||||
Base::Console().Log("Start: write FemMesh from VTK unstructuredGrid ======================\n");
|
||||
Base::FileInfo f(filename);
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
exportVTKMesh(mesh, grid);
|
||||
//vtkSmartPointer<vtkDataSet> dataset = vtkDataSet::SafeDownCast(grid);
|
||||
Base::Console().Message("Start: writing mesh data ======================\n");
|
||||
Base::Console().Log("Start: writing mesh data ======================\n");
|
||||
if(f.hasExtension("vtu")){
|
||||
writeVTKFile<vtkXMLUnstructuredGridWriter>(filename, grid);
|
||||
}
|
||||
@@ -493,7 +496,7 @@ void FemVTKTools::writeVTKMesh(const char* filename, const FemMesh* mesh)
|
||||
Base::Console().Error("file name extension is not supported to write VTK\n");
|
||||
}
|
||||
|
||||
Base::Console().Message(" %f: Done \n",Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
Base::Console().Log(" %f: Done \n",Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
}
|
||||
|
||||
|
||||
@@ -549,7 +552,7 @@ App::DocumentObject* createObjectByType(const Base::Type type)
|
||||
App::DocumentObject* FemVTKTools::readResult(const char* filename, App::DocumentObject* res)
|
||||
{
|
||||
Base::TimeInfo Start;
|
||||
Base::Console().Message("Start: read FemResult with FemMesh from VTK file ======================\n");
|
||||
Base::Console().Log("Start: read FemResult with FemMesh from VTK file ======================\n");
|
||||
Base::FileInfo f(filename);
|
||||
|
||||
vtkSmartPointer<vtkDataSet> ds;
|
||||
@@ -601,8 +604,8 @@ App::DocumentObject* FemVTKTools::readResult(const char* filename, App::Document
|
||||
importFreeCADResult(dataset, result);
|
||||
|
||||
pcDoc->recompute();
|
||||
Base::Console().Message(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
Base::Console().Message("End: read FemResult with FemMesh from VTK file ======================\n");
|
||||
Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
Base::Console().Log("End: read FemResult with FemMesh from VTK file ======================\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -625,7 +628,7 @@ void FemVTKTools::writeResult(const char* filename, const App::DocumentObject* r
|
||||
}
|
||||
|
||||
Base::TimeInfo Start;
|
||||
Base::Console().Message("Start: write FemResult to VTK unstructuredGrid dataset =======\n");
|
||||
Base::Console().Log("Start: write FemResult to VTK unstructuredGrid dataset =======\n");
|
||||
Base::FileInfo f(filename);
|
||||
|
||||
// mesh
|
||||
@@ -634,7 +637,7 @@ void FemVTKTools::writeResult(const char* filename, const App::DocumentObject* r
|
||||
const FemMesh& fmesh = static_cast<PropertyFemMesh*>(mesh->getPropertyByName("FemMesh"))->getValue();
|
||||
FemVTKTools::exportVTKMesh(&fmesh, grid);
|
||||
|
||||
Base::Console().Message(" %f: vtk mesh builder finished\n",Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
Base::Console().Log(" %f: vtk mesh builder finished\n",Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
|
||||
// result
|
||||
FemVTKTools::exportFreeCADResult(res, grid);
|
||||
@@ -650,8 +653,8 @@ void FemVTKTools::writeResult(const char* filename, const App::DocumentObject* r
|
||||
Base::Console().Error("file name extension is not supported to write VTK\n");
|
||||
}
|
||||
|
||||
Base::Console().Message(" %f: writing result object to vtk finished\n",Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
Base::Console().Message("End: write FemResult to VTK unstructuredGrid dataset =======\n");
|
||||
Base::Console().Log(" %f: writing result object to vtk finished\n",Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
|
||||
Base::Console().Log("End: write FemResult to VTK unstructuredGrid dataset =======\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -684,7 +687,7 @@ std::map<std::string, std::vector<std::string>> _getFreeCADMechResultProperties(
|
||||
|
||||
|
||||
void FemVTKTools::importFreeCADResult(vtkSmartPointer<vtkDataSet> dataset, App::DocumentObject* result) {
|
||||
Base::Console().Message("Start: import vtk result file data into a FreeCAD result object.\n");
|
||||
Base::Console().Log("Start: import vtk result file data into a FreeCAD result object.\n");
|
||||
|
||||
std::map<std::string, std::vector<std::string>> resFCProperties = _getFreeCADMechResultProperties();
|
||||
std::vector<std::string> vectors = resFCProperties["vectors"];
|
||||
@@ -707,7 +710,7 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer<vtkDataSet> dataset, App::
|
||||
nodeIds[i] = i+1;
|
||||
}
|
||||
static_cast<App::PropertyIntegerList*>(result->getPropertyByName("NodeNumbers"))->setValues(nodeIds);
|
||||
Base::Console().Message(" NodeNumbers have been filled with values.\n");
|
||||
Base::Console().Log(" NodeNumbers have been filled with values.\n");
|
||||
|
||||
// vectors
|
||||
int dim = 3; // Fixme: currently 3D only
|
||||
@@ -723,7 +726,7 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer<vtkDataSet> dataset, App::
|
||||
}
|
||||
// PropertyVectorList will not show up in PropertyEditor
|
||||
vector_list->setValues(vec);
|
||||
Base::Console().Message(" A PropertyVectorList has been filled with values: %s\n", it->c_str());
|
||||
Base::Console().Log(" A PropertyVectorList has been filled with values: %s\n", it->c_str());
|
||||
}
|
||||
else {
|
||||
Base::Console().Error("static_cast<App::PropertyVectorList*>((result->getPropertyByName(\"%s\")) failed.\n", it->c_str());
|
||||
@@ -754,7 +757,7 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer<vtkDataSet> dataset, App::
|
||||
if(v < vmin) vmin = v;
|
||||
}
|
||||
field->setValues(values);
|
||||
Base::Console().Message(" A PropertyFloatList has been filled with vales: %s\n", it->c_str());
|
||||
Base::Console().Log(" A PropertyFloatList has been filled with vales: %s\n", it->c_str());
|
||||
}
|
||||
else
|
||||
Base::Console().Message(" PropertyFloatList NOT found in vkt file data %s\n", it->c_str());
|
||||
@@ -763,12 +766,12 @@ void FemVTKTools::importFreeCADResult(vtkSmartPointer<vtkDataSet> dataset, App::
|
||||
// stats
|
||||
// stats are added by importVTKResults
|
||||
|
||||
Base::Console().Message("End: import vtk result file data into a FreeCAD result object.\n");
|
||||
Base::Console().Log("End: import vtk result file data into a FreeCAD result object.\n");
|
||||
}
|
||||
|
||||
|
||||
void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmartPointer<vtkDataSet> grid) {
|
||||
Base::Console().Message("Start: Create VTK result data from FreeCAD result data.\n");
|
||||
Base::Console().Log("Start: Create VTK result data from FreeCAD result data.\n");
|
||||
|
||||
std::map<std::string, std::vector<std::string>> resFCProperties = _getFreeCADMechResultProperties();
|
||||
std::vector<std::string> vectors = resFCProperties["vectors"];
|
||||
@@ -777,8 +780,8 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
|
||||
const Fem::FemResultObject* res = static_cast<const Fem::FemResultObject*>(result);
|
||||
const vtkIdType nPoints = grid->GetNumberOfPoints();
|
||||
|
||||
//we need the coresponding mesh to get the correct id for the result data (when the freecad mesh has gaps in the points
|
||||
//vtk has more, as it does not support it. Than the mapping must be correct)
|
||||
// we need the coresponding mesh to get the correct id for the result data (when the freecad smesh mesh has gaps in the points
|
||||
// vtk has more points. Vtk does not support point gaps, thus the gaps are filled with points. Then the mapping must be correct)
|
||||
App::DocumentObject* meshObj = res->Mesh.getValue();
|
||||
if (!meshObj || !meshObj->isDerivedFrom(FemMeshObject::getClassTypeId())) {
|
||||
Base::Console().Error("Result object does not correctly link to mesh");
|
||||
@@ -786,7 +789,7 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
|
||||
}
|
||||
SMESH_Mesh* smesh = const_cast<SMESH_Mesh*>(static_cast<FemMeshObject*>(meshObj)->FemMesh.getValue().getSMesh());
|
||||
SMESHDS_Mesh* meshDS = smesh->GetMeshDS();
|
||||
|
||||
|
||||
// vectors
|
||||
for (std::vector<std::string>::iterator it = vectors.begin(); it != vectors.end(); ++it ) {
|
||||
const int dim=3; //Fixme, detect dim
|
||||
@@ -812,7 +815,7 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
|
||||
data->SetTuple(i, tuple);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SMDS_NodeIteratorPtr aNodeIter = meshDS->nodesIterator();
|
||||
for (std::vector<Base::Vector3d>::const_iterator jt=vel.begin(); jt!=vel.end(); ++jt) {
|
||||
const SMDS_MeshNode* node = aNodeIter->next();
|
||||
@@ -820,7 +823,7 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
|
||||
data->SetTuple(node->GetID()-1, tuple);
|
||||
}
|
||||
grid->GetPointData()->AddArray(data);
|
||||
Base::Console().Message(" A PropertyVectorList was exported: %s\n", it->c_str());
|
||||
Base::Console().Log(" A PropertyVectorList was exported: %s\n", it->c_str());
|
||||
}
|
||||
else
|
||||
Base::Console().Message(" PropertyVectorList NOT exported to vtk: %s size is: %i\n", it->c_str(), field->getSize());
|
||||
@@ -840,7 +843,7 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
|
||||
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
data->SetNumberOfValues(nPoints);
|
||||
data->SetName(it->c_str());
|
||||
|
||||
|
||||
//we need to set values for the unused points.
|
||||
//TODO: ensure that the result bar does not include the used 0 if it is not part of the result (e.g. does the result bar show 0 as smallest value?)
|
||||
if (nPoints != field->getSize()) {
|
||||
@@ -856,13 +859,13 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
|
||||
}
|
||||
|
||||
grid->GetPointData()->AddArray(data);
|
||||
Base::Console().Message(" A PropertyFloatList was exported: %s\n", it->c_str(), it->c_str());
|
||||
Base::Console().Log(" A PropertyFloatList was exported: %s\n", it->c_str(), it->c_str());
|
||||
}
|
||||
else
|
||||
Base::Console().Message(" PropertyFloatList NOT exported to vtk: %s size is: %i\n", it->c_str(), field->getSize());
|
||||
}
|
||||
|
||||
Base::Console().Message("End: Create VTK result data from FreeCAD result data.\n");
|
||||
Base::Console().Log("End: Create VTK result data from FreeCAD result data.\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user