7 #include "imstkMeshIO.h" 8 #include "imstkAssimpMeshIO.h" 9 #include "imstkLogger.h" 10 #include "imstkMshMeshIO.h" 11 #include "imstkSurfaceMesh.h" 12 #include "imstkTetrahedralMesh.h" 13 #include "imstkVegaMeshIO.h" 14 #include "imstkVTKMeshIO.h" 18 #include <unordered_map> 22 static std::unordered_map<std::string, MeshFileType> extToType =
24 {
"vtk", MeshFileType::VTK },
25 {
"vtp", MeshFileType::VTP },
26 {
"vtu", MeshFileType::VTU },
27 {
"obj", MeshFileType::OBJ },
28 {
"stl", MeshFileType::STL },
29 {
"ply", MeshFileType::PLY },
30 {
"dae", MeshFileType::DAE },
31 {
"fbx", MeshFileType::FBX },
32 {
"3ds", MeshFileType::_3DS },
33 {
"veg", MeshFileType::VEG },
34 {
"msh", MeshFileType::MSH },
35 {
"dcm", MeshFileType::DCM },
36 {
"nrrd", MeshFileType::NRRD },
37 {
"nii", MeshFileType::NII },
38 {
"mhd", MeshFileType::MHD },
39 {
"jpg", MeshFileType::JPG },
40 {
"jpeg", MeshFileType::JPG },
41 {
"png", MeshFileType::PNG },
42 {
"bmp", MeshFileType::BMP },
45 std::shared_ptr<PointSet>
48 bool isDirectory =
false;
49 bool exists =
fileExists(filePath, isDirectory);
51 CHECK(exists && !isDirectory) <<
"File " << filePath <<
" doesn't exist or is a directory.";
56 case MeshFileType::VTK:
57 case MeshFileType::VTU:
58 case MeshFileType::VTP:
59 case MeshFileType::STL:
60 case MeshFileType::PLY:
61 case MeshFileType::NRRD:
62 case MeshFileType::NII:
63 case MeshFileType::DCM:
64 case MeshFileType::MHD:
65 case MeshFileType::JPG:
66 case MeshFileType::PNG:
67 case MeshFileType::BMP:
68 return VTKMeshIO::read(filePath, meshType);
70 case MeshFileType::OBJ:
71 case MeshFileType::DAE:
72 case MeshFileType::FBX:
73 case MeshFileType::_3DS:
76 case MeshFileType::VEG:
79 case MeshFileType::MSH:
82 case MeshFileType::UNKNOWN:
86 LOG(FATAL) <<
"Error: file type not supported for input " << filePath;
94 if (stat(file.c_str(), &buf) == 0)
96 if (buf.st_mode & S_IFDIR)
115 std::string extString = filePath.substr(filePath.find_last_of(
".") + 1);
117 CHECK(!extString.empty()) <<
"Error: invalid file name " << filePath;
120 std::transform(extString.begin(), extString.end(), extString.begin(),
121 [](
unsigned char c) {
return static_cast<unsigned char>(std::tolower(c)); });
123 if (extToType.count(extString) == 0)
125 LOG(FATAL) <<
"Error: unknown file extension " << extString;
128 return extToType[extString];
132 MeshIO::write(
const std::shared_ptr<imstk::PointSet> imstkMesh,
const std::string& filePath)
134 if (imstkMesh ==
nullptr)
136 LOG(WARNING) <<
"Error: Mesh object supplied is not valid!";
143 case MeshFileType::VEG:
146 case MeshFileType::NII:
147 case MeshFileType::NRRD:
148 case MeshFileType::VTU:
149 case MeshFileType::VTK:
150 case MeshFileType::VTP:
151 case MeshFileType::STL:
152 case MeshFileType::PLY:
153 case MeshFileType::OBJ:
154 case MeshFileType::MHD:
155 case MeshFileType::BMP:
156 case MeshFileType::PNG:
157 case MeshFileType::JPG:
160 case MeshFileType::UNKNOWN:
165 LOG(FATAL) <<
"Error: file type not supported for input " << filePath;
static std::shared_ptr< PointSet > read(const std::string &filePath, MeshFileType type)
Ensures file can be read and reads it if possible.
MeshFileType
Enumeration the mesh file type.
static std::shared_ptr< PointSet > read(const std::string &filePath)
Read and generate a volumetric mesh given a external msh file.
static bool write(const std::shared_ptr< PointSet > imstkMesh, const std::string &filePath, const MeshFileType meshType)
Writes the given mesh to the specified file path.
static std::shared_ptr< PointSet > read(const std::string &filePath)
Read external file.
static const MeshFileType getFileType(const std::string &filePath)
Returns the type of the file.
static bool write(const std::shared_ptr< imstk::PointSet > imstkMesh, const std::string &filePath, const MeshFileType meshType)
Write a volumetric mesh in vega file format.
static std::shared_ptr< PointSet > read(const std::string &filePath, MeshFileType meshType)
Read and generate volumetric mesh given a external vega mesh file.
static bool fileExists(const std::string &file, bool &isDirectory)
Returns true if the file exists, else false. Also sets isDirectory to true if the path is a directory...
static bool write(const std::shared_ptr< imstk::PointSet > imstkMesh, const std::string &filePath)
Write external file.