Commit fc95d1f3 authored by Alexis Girault's avatar Alexis Girault
Browse files

ENH: Add TetrahedralMeshRenderDelegate

parent a26712b2
......@@ -119,6 +119,7 @@ protected:
Mesh(GeometryType type) : Geometry(type, WORLD_ORIGIN, Quatd()) {}
friend class SurfaceMeshRenderDelegate;
friend class TetrahedralMeshRenderDelegate;
std::vector<Vec3d>& getVerticesPositionsNotConst()
{
return m_verticesPositions;
......
......@@ -43,11 +43,9 @@ MeshReader::read(const std::string& filePath)
case FileType::STL :
case FileType::PLY :
case FileType::OBJ :
LOG(DEBUG) << "MeshReader::read debug: Read using VTK Mesh reader.";
return VTKMeshReader::read(filePath, meshType);
break;
case FileType::VEG :
LOG(DEBUG) << "MeshReader::read debug: Read using Vega Mesh reader.";
LOG(WARNING) << "MeshReader::read error: vega reader not yet implemented.";
return nullptr;
break;
......
......@@ -27,12 +27,13 @@
#include "imstkSphere.h"
#include "imstkCube.h"
#include "imstkSurfaceMesh.h"
#include "imstkVolumetricMesh.h"
#include "imstkCube.h"
#include "imstkTetrahedralMesh.h"
#include "imstkHexahedralMesh.h"
#include "imstkPlaneRenderDelegate.h"
#include "imstkSphereRenderDelegate.h"
#include "imstkCubeRenderDelegate.h"
#include "imstkSurfaceMeshRenderDelegate.h"
#include "imstkTetrahedralMeshRenderDelegate.h"
#include "vtkPolyDataMapper.h"
#include "vtkTransform.h"
......@@ -64,12 +65,15 @@ RenderDelegate::make_delegate(std::shared_ptr<Geometry>geom)
return std::make_shared<SurfaceMeshRenderDelegate>(surface);
}
case GeometryType::TetrahedralMesh:
{
auto mesh = std::dynamic_pointer_cast<TetrahedralMesh>(geom);
return std::make_shared<TetrahedralMeshRenderDelegate>(mesh);
}
case GeometryType::HexahedralMesh:
{
auto mesh = std::dynamic_pointer_cast<VolumetricMesh>(geom);
LOG(WARNING) << "RenderDelegate::make_delegate error: VolumetricMeshRenderDelegate not implemented yet.";
auto mesh = std::dynamic_pointer_cast<TetrahedralMesh>(geom);
LOG(WARNING) << "RenderDelegate::make_delegate error: HexahedralMeshRenderDelegate not yet implemented";
return nullptr;
//return std::make_shared<VolumetricMeshRenderDelegate>(mesh);
}
default:
{
......
......@@ -28,8 +28,8 @@
#include "g3log/g3log.hpp"
namespace imstk {
SurfaceMeshRenderDelegate::SurfaceMeshRenderDelegate(std::shared_ptr<SurfaceMesh>SurfaceMesh) :
m_geometry(SurfaceMesh)
SurfaceMeshRenderDelegate::SurfaceMeshRenderDelegate(std::shared_ptr<SurfaceMesh> surfaceMesh) :
m_geometry(surfaceMesh)
{
// Map vertices
auto mappedVertexArray = vtkSmartPointer<MappedVertexArray>::New();
......
/*=========================================================================
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 "imstkTetrahedralMeshRenderDelegate.h"
#include "imstkMappedVertexArray.h"
#include <vtkCellArray.h>
#include <vtkTrivialProducer.h>
#include <vtkDataSetMapper.h>
#include "g3log/g3log.hpp"
namespace imstk {
TetrahedralMeshRenderDelegate::TetrahedralMeshRenderDelegate(std::shared_ptr<TetrahedralMesh> tetrahedralMesh) :
m_geometry(tetrahedralMesh)
{
const size_t dim = 4;
// Map vertices
auto mappedVertexArray = vtkSmartPointer<MappedVertexArray>::New();
mappedVertexArray->SetVertexArray(m_geometry->getVerticesPositionsNotConst());
// Create points
auto points = vtkSmartPointer<vtkPoints>::New();
points->SetNumberOfPoints(m_geometry->getNumVertices());
points->SetData(mappedVertexArray);
// Copy cells
auto cells = vtkSmartPointer<vtkCellArray>::New();
vtkIdType cell[dim];
for(const auto &t : m_geometry->getTetrahedraVertices())
{
for(size_t i = 0; i < dim; ++i)
{
cell[i] = t[i];
}
cells->InsertNextCell(dim,cell);
}
// Create PolyData
auto unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
unstructuredGrid->SetPoints(points);
unstructuredGrid->SetCells(VTK_TETRA, cells);
// Create Source
auto source = vtkSmartPointer<vtkTrivialProducer>::New();
source->SetOutput(unstructuredGrid);
// Set up mapper
auto mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputConnection(source->GetOutputPort());
m_actor->SetMapper(mapper);
this->setActorTransform(m_geometry);
}
std::shared_ptr<Geometry>
TetrahedralMeshRenderDelegate::getGeometry() const
{
return m_geometry;
}
}
/*=========================================================================
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 imstkTetrahedralMeshRenderDelegate_h
#define imstkTetrahedralMeshRenderDelegate_h
#include <memory>
#include "imstkRenderDelegate.h"
#include "imstkTetrahedralMesh.h"
#include "vtkUnstructuredGrid.h"
namespace imstk {
class TetrahedralMeshRenderDelegate : public RenderDelegate
{
public:
~TetrahedralMeshRenderDelegate() = default;
TetrahedralMeshRenderDelegate(std::shared_ptr<TetrahedralMesh> tetrahedralMesh);
std::shared_ptr<Geometry> getGeometry() const override;
protected:
std::shared_ptr<TetrahedralMesh> m_geometry;
};
}
#endif // ifndef imstkTetrahedralMeshRenderDelegate_h
......@@ -61,16 +61,23 @@ void testReadMesh()
auto scene = sdk->createNewScene("SceneTestMesh");
scene->setLoopDelay(1000);
// Read mesh
auto objMesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/Cube/models/cube.obj");
// 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");
*/
// Create and add object
// Read volumetricMesh
auto mesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/AVM/nidus-model/nidus10KTet.vtk");
auto volumeMesh = std::dynamic_pointer_cast<imstk::VolumetricMesh>(mesh);
auto surfaceMesh = volumeMesh->getAttachedSurfaceMesh();
// Create object and add to scene
auto object = std::make_shared<imstk::VisualObject>("meshObject");
object->setVisualGeometry(objMesh);
object->setVisualGeometry(surfaceMesh);
scene->addSceneObject(object);
// Run
......
Supports Markdown
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