Commit 8da261b0 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

ENH: Add support for Mesh (point set)

Point set (Mesh) is now a full and renderable class.
Scene objects can now be created that can utilize mesh
class for both physics and rendering.

A separate render delegate is created for Mesh class
parent 4098bd5e
Pipeline #65955 passed with stage
......@@ -34,11 +34,16 @@ namespace imstk
class Mesh : public Geometry
{
public:
///
/// \brief Protected constructor
///
Mesh(Geometry::Type type = Geometry::Type::PointSet) : Geometry(type) {}
///
/// \brief Destructor
///
~Mesh() = default;
//Mesh() = default;
///
/// \brief Initializes the data structure given vertex positions
......@@ -55,6 +60,11 @@ public:
///
virtual void print() const override;
///
/// \brief Returns the volume of the geometry (if valid)
///
virtual double getVolume() const { return 0; };
///
/// \brief Compute the bounding box for the entire mesh
///
......@@ -146,15 +156,11 @@ public:
protected:
///
/// \brief Protected constructor
///
Mesh(Type type) : Geometry(type) {}
friend class VTKSurfaceMeshRenderDelegate;
friend class VTKTetrahedralMeshRenderDelegate;
friend class VTKLineMeshRenderDelegate;
friend class VTKHexahedralMeshRenderDelegate;
friend class VTKPointSetRenderDelegate;
///
/// \brief Get vertices positions
......
......@@ -245,6 +245,16 @@ void
Geometry::setRenderMaterial(std::shared_ptr<RenderMaterial> renderMaterial)
{
m_renderMaterial = renderMaterial;
// Enforce RenderMaterial::DisplayMode::POINTS if the connectivity information is missing
if (m_type == Type::PointSet)
{
if (m_renderMaterial->getDisplayMode() != RenderMaterial::DisplayMode::POINTS)
{
LOG(WARNING) << "Geometry::setRenderMaterial: The mesh doesn't have a connectivity. Enforcing RenderMaterial::DisplayMode::POINTS display mode";
m_renderMaterial->setDisplayMode(RenderMaterial::DisplayMode::POINTS);
}
}
}
std::shared_ptr<RenderMaterial>
......
......@@ -46,6 +46,7 @@ public:
Sphere,
Cylinder,
Cube,
PointSet,
SurfaceMesh,
TetrahedralMesh,
HexahedralMesh,
......
......@@ -17,6 +17,7 @@ imstk_add_library( Rendering
RenderDelegate/imstkVTKSurfaceMeshRenderDelegate.h
RenderDelegate/imstkVTKTetrahedralMeshRenderDelegate.h
RenderDelegate/imstkVTKHexahedralMeshRenderDelegate.h
RenderDelegate/imstkVTKPointSetRenderDelegate.h
RenderDelegate/vtkCapsuleSource.h
CPP_FILES
......@@ -33,6 +34,7 @@ imstk_add_library( Rendering
RenderDelegate/imstkVTKSurfaceMeshRenderDelegate.cpp
RenderDelegate/imstkVTKTetrahedralMeshRenderDelegate.cpp
RenderDelegate/imstkVTKHexahedralMeshRenderDelegate.cpp
RenderDelegate/imstkVTKPointSetRenderDelegate.cpp
RenderDelegate/vtkCapsuleSource.cpp
SUBDIR_LIST
......
/*=========================================================================
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 "imstkVTKPointSetRenderDelegate.h"
#include "imstkMesh.h"
#include <vtkTrivialProducer.h>
#include <vtkDoubleArray.h>
#include <vtkVertexGlyphFilter.h>
namespace imstk
{
VTKPointSetRenderDelegate::VTKPointSetRenderDelegate(std::shared_ptr<Mesh> mesh) :
m_geometry(mesh),
m_mappedVertexArray(vtkSmartPointer<vtkDoubleArray>::New())
{
// Map vertices
StdVectorOfVec3d& vertices = m_geometry->getVertexPositionsNotConst();
double* vertData = reinterpret_cast<double*>(vertices.data());
m_mappedVertexArray->SetNumberOfComponents(3);
m_mappedVertexArray->SetArray(vertData, vertices.size()*3, 1);
// Create points
auto points = vtkSmartPointer<vtkPoints>::New();
points->SetNumberOfPoints(m_geometry->getNumVertices());
points->SetData(m_mappedVertexArray);
// Create PolyData
auto pointsPolydata = vtkSmartPointer<vtkPolyData>::New();
pointsPolydata->SetPoints(points);
auto vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
#if VTK_MAJOR_VERSION <= 5
vertexFilter->SetInputConnection(pointsPolydata->GetProducerPort());
#else
vertexFilter->SetInputData(pointsPolydata);
#endif
vertexFilter->Update();
m_geometry->m_dataModified = false;
// Update Transform, Render Properties
this->update();
// Setup custom mapper
m_mapper->SetInputConnection(vertexFilter->GetOutputPort());
auto mapper = VTKCustomPolyDataMapper::SafeDownCast(m_mapper.GetPointer());
if (!mesh->getRenderMaterial())
{
mesh->setRenderMaterial(std::make_shared<RenderMaterial>());
}
mapper->setGeometry(mesh);
}
void
VTKPointSetRenderDelegate::updateDataSource()
{
if (m_geometry->m_dataModified)
{
m_mappedVertexArray->Modified();
m_geometry->m_dataModified = false;
}
}
std::shared_ptr<Geometry>
VTKPointSetRenderDelegate::getGeometry() const
{
return m_geometry;
}
} // imstk
/*=========================================================================
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 imstkVTKPointSetRenderDelegate_h
#define imstkVTKPointSetRenderDelegate_h
#include <memory>
#include "imstkVTKRenderDelegate.h"
class vtkDoubleArray;
namespace imstk
{
class Mesh;
///
/// \class PointSetRenderDelegate
///
/// \brief
///
class VTKPointSetRenderDelegate : public VTKRenderDelegate
{
public:
///
/// \brief Constructor
///
VTKPointSetRenderDelegate(std::shared_ptr<Mesh> mesh);
///
/// \brief Destructor
///
~VTKPointSetRenderDelegate() = default;
///
/// \brief Update polydata source based on the mesh geometry
///
void updateDataSource() override;
///
/// \brief Returns the surface mesh
///
std::shared_ptr<Geometry> getGeometry() const override;
protected:
std::shared_ptr<Mesh> m_geometry; ///> Geometry to render
vtkSmartPointer<vtkDoubleArray> m_mappedVertexArray; ///> Mapped array of vertices
};
}
#endif // ifndef imstkSurfaceMeshRenderDelegate_h
......@@ -28,6 +28,7 @@
#include "imstkCapsule.h"
#include "imstkCylinder.h"
#include "imstkCube.h"
#include "imstkMesh.h"
#include "imstkSurfaceMesh.h"
#include "imstkLineMesh.h"
#include "imstkTetrahedralMesh.h"
......@@ -43,6 +44,7 @@
#include "imstkVTKTetrahedralMeshRenderDelegate.h"
#include "imstkVTKHexahedralMeshRenderDelegate.h"
#include "imstkVTKCylinderRenderDelegate.h"
#include "imstkVTKPointSetRenderDelegate.h"
#include "vtkOpenGLPolyDataMapper.h"
#include "vtkOpenGLVertexBufferObject.h"
......@@ -69,8 +71,8 @@ VTKRenderDelegate::make_delegate(std::shared_ptr<Geometry> geom)
}
case Geometry::Type::Capsule:
{
auto sphere = std::dynamic_pointer_cast<Capsule>(geom);
return std::make_shared<VTKCapsuleRenderDelegate>(sphere);
auto capsule = std::dynamic_pointer_cast<Capsule>(geom);
return std::make_shared<VTKCapsuleRenderDelegate>(capsule);
}
case Geometry::Type::Cube:
{
......@@ -82,6 +84,11 @@ VTKRenderDelegate::make_delegate(std::shared_ptr<Geometry> geom)
auto cylinder = std::dynamic_pointer_cast<Cylinder>(geom);
return std::make_shared<VTKCylinderRenderDelegate>(cylinder);
}
case Geometry::Type::PointSet:
{
auto pointSet = std::dynamic_pointer_cast<Mesh>(geom);
return std::make_shared<VTKPointSetRenderDelegate>(pointSet);
}
case Geometry::Type::SurfaceMesh:
{
auto surface = std::dynamic_pointer_cast<SurfaceMesh>(geom);
......
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