Commit 14d8ae9e authored by Alexis Girault's avatar Alexis Girault
Browse files

ENH: Implement ismtkVegaMeshReader

parent e106bdeb
......@@ -22,6 +22,7 @@
#include "imstkMeshReader.h"
#include "imstkVTKMeshReader.h"
#include "imstkVegaMeshReader.h"
#include "g3log/g3log.hpp"
......@@ -46,8 +47,7 @@ MeshReader::read(const std::string& filePath)
return VTKMeshReader::read(filePath, meshType);
break;
case FileType::VEG :
LOG(WARNING) << "MeshReader::read error: vega reader not yet implemented.";
return nullptr;
return VegaMeshReader::read(filePath, meshType);
break;
}
......
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#include "imstkVegaMeshReader.h"
#include "imstkMeshReader.h"
#include "imstkTetrahedralMesh.h"
#include "imstkHexahedralMesh.h"
// Vega
#include "volumetricMeshLoader.h"
#include "volumetricMesh.h"
#include "g3log/g3log.hpp"
namespace imstk{
std::shared_ptr<VolumetricMesh>
VegaMeshReader::read(const std::string& filePath, MeshReader::FileType meshType)
{
if (meshType != MeshReader::FileType::VEG)
{
LOG(WARNING) << "VegaMeshReader::read error: file type not supported";
return nullptr;
}
// Vega VolumetricMesh (not imstk::)
auto fileName = const_cast<char*>(filePath.c_str());
std::shared_ptr<vega::VolumetricMesh> vegaMesh(vega::VolumetricMeshLoader::load(fileName));
// Copy vertices
std::vector<Vec3d> vertices;
for(size_t i = 0; i < vegaMesh->getNumVertices(); ++i)
{
auto pos = *vegaMesh->getVertex(i);
vertices.emplace_back(pos[0], pos[1], pos[2]);
}
// Check
auto cellType = vegaMesh->getElementType();
if(cellType == vega::VolumetricMesh::TET)
{
std::vector<TetrahedralMesh::TetraArray> cells;
TetrahedralMesh::TetraArray cell;
for(size_t cellId = 0; cellId < vegaMesh->getNumElements(); ++cellId)
{
for (size_t i = 0; i < vegaMesh->getNumElementVertices(); ++i)
{
cell[i] = vegaMesh->getVertexIndex(cellId,i);
}
cells.emplace_back(cell);
}
auto mesh = std::make_shared<TetrahedralMesh>();
mesh->initialize(vertices, cells, false);
return mesh;
}
else if(cellType == vega::VolumetricMesh::CUBIC)
{
std::vector<HexahedralMesh::HexaArray> cells;
HexahedralMesh::HexaArray cell;
for(size_t cellId = 0; cellId < vegaMesh->getNumElements(); ++cellId)
{
for (size_t i = 0; i < vegaMesh->getNumElementVertices(); ++i)
{
cell[i] = vegaMesh->getVertexIndex(cellId,i);
}
cells.emplace_back(cell);
}
auto mesh = std::make_shared<HexahedralMesh>();
mesh->initialize(vertices, cells, false);
return mesh;
}
else
{
vegaMesh.reset();
LOG(WARNING) << "VegaMeshReader::read error: invalid cell type.";
return nullptr;
}
}
}
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#ifndef imstkVegaMeshReader_h
#define imstkVegaMeshReader_h
#include <memory>
#include "imstkMeshReader.h"
#include "imstkVolumetricMesh.h"
namespace imstk {
///
/// \class VegaMeshReader
///
/// \brief
///
class VegaMeshReader
{
public:
VegaMeshReader() = default;
~VegaMeshReader() = default;
///
/// \brief
///
static std::shared_ptr<VolumetricMesh> read(const std::string& filePath, MeshReader::FileType meshType);
};
}
#endif // ifndef imstkVegaMeshReader_h
......@@ -62,24 +62,24 @@ void testReadMesh()
scene->setLoopDelay(1000);
// Read surface mesh
/*
auto objMesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/asianDragon/asianDragon.obj");
auto plyMesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/Cube/models/cube.ply");
auto stlMesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/Cube/models/cube.stl");
auto vtkMesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/Cube/models/cube.vtk");
auto vtpMesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/Cube/models/cube.vtp");
*/
// Read volumetricMesh
auto mesh = imstk::MeshReader::read("nidus10KTet.vtk");
auto volumeMesh = std::dynamic_pointer_cast<imstk::VolumetricMesh>(mesh);
auto vtkMesh2 = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/AVM/nidus-model/nidus10KTet.vtk");
auto vegaMesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/asianDragon/asianDragon.veg");
// Extract surface mesh
auto volumeMesh = std::dynamic_pointer_cast<imstk::VolumetricMesh>(vegaMesh); // change to any volumetric mesh above
volumeMesh->computeAttachedSurfaceMesh();
auto surfaceMesh = volumeMesh->getAttachedSurfaceMesh();
// Create object and add to scene
auto object = std::make_shared<imstk::VisualObject>("meshObject");
object->setVisualGeometry(surfaceMesh);
object->setVisualGeometry(surfaceMesh); // change to any mesh created above
scene->addSceneObject(object);
// Run
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment