Skip to content

Commit

Permalink
Fem: add feature off vtk unstructured mesh import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
qingfengxia authored and wwmayer committed Oct 29, 2016
1 parent 9ff8260 commit 72be909
Show file tree
Hide file tree
Showing 6 changed files with 869 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Mod/Fem/App/AppFemPy.cpp
Expand Up @@ -67,6 +67,7 @@
#include "FemMeshPy.h"
#ifdef FC_USE_VTK
#include "FemPostPipeline.h"
#include "FemVTKTools.h"
#endif

#include <cstdlib>
Expand All @@ -93,6 +94,11 @@ class Module : public Py::ExtensionModule<Module>
add_varargs_method("read",&Module::read,
"Read a mesh from a file and returns a Mesh object."
);
#ifdef FC_USE_VTK
add_varargs_method("readCfdResult",&Module::readCfdResult,
"Read a CFD result from a file and returns a Result object."
);
#endif
add_varargs_method("show",&Module::show,
"show(shape) -- Add the shape to the active document or create one if no document exists."
);
Expand Down Expand Up @@ -236,6 +242,30 @@ class Module : public Py::ExtensionModule<Module>
mesh->read(EncodedName.c_str());
return Py::asObject(new FemMeshPy(mesh.release()));
}

#ifdef FC_USE_VTK
Py::Object readCfdResult(const Py::Tuple& args)
{
PyObject *pcObj;
char* Name; // PythonFeatureT<FemResultObject> is of type `App::DocumentObjectPy`
if (!PyArg_ParseTuple(args.ptr(), "etO","utf-8", &Name, &(App::DocumentObjectPy::Type), &pcObj))
throw Py::Exception();
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
// this function needs the second parameter: App::DocumentObjectPy, since it is created in python
if (pcObj)
{
//App::DocumentObjectPy objpy(pcObj);
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(pcObj)->getDocumentObjectPtr();
FemVTKTools::readFluidicResult(EncodedName.c_str(), obj);
}
else
FemVTKTools::readFluidicResult(EncodedName.c_str());

return Py::None();
}
#endif

Py::Object show(const Py::Tuple& args)
{
PyObject *pcObj;
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Fem/App/CMakeLists.txt
Expand Up @@ -240,6 +240,8 @@ if(BUILD_FEM_VTK)
FemPostFilter.cpp
FemPostFunction.h
FemPostFunction.cpp
FemVTKTools.h
FemVTKTools.cpp
)
SOURCE_GROUP("PostObjects" FILES ${FemPost_SRCS})
endif(BUILD_FEM_VTK)
Expand Down
15 changes: 15 additions & 0 deletions src/Mod/Fem/App/FemMesh.cpp
Expand Up @@ -49,6 +49,9 @@
#include <Mod/Mesh/App/Core/Iterator.h>

#include "FemMesh.h"
#ifdef FC_USE_VTK
#include "FemVTKTools.h"
#endif

#include <boost/assign/list_of.hpp>
#include <SMESH_Gen.hxx>
Expand Down Expand Up @@ -898,6 +901,12 @@ void FemMesh::read(const char *FileName)
// read Nastran-file
readNastran(File.filePath());
}
#ifdef FC_USE_VTK
else if (File.hasExtension("vtk") || File.hasExtension("vtu")) {
// read *.vtk legacy format or *.vtu XML unstructure Mesh
FemVTKTools::readVTKMesh(File.filePath().c_str(), this);
}
#endif
else{
throw Base::Exception("Unknown extension");
}
Expand Down Expand Up @@ -1185,6 +1194,12 @@ void FemMesh::write(const char *FileName) const
// write ABAQUS Output
writeABAQUS(File.filePath());
}
#ifdef FC_USE_VTK
else if (File.hasExtension("vtk") || File.hasExtension("vtu") ) {
// write unstructure mesh to VTK format *.vtk and *.vtu
FemVTKTools::writeVTKMesh(File.filePath().c_str(), this);
}
#endif
else{
throw Base::Exception("Unknown extension");
}
Expand Down

0 comments on commit 72be909

Please sign in to comment.