Skip to content
Snippets Groups Projects
Commit cf5945f4 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

ENH: Adds geometry maps


Adds geometry map base class and isometriMap

Signed-off-by: default avatarSreekanth Arikatla <sreekanth.arikatla@kitware.com>
parent 2cfc317e
No related branches found
No related tags found
No related merge requests found
Showing
with 314 additions and 19 deletions
......@@ -48,16 +48,41 @@ using Quatf = Eigen::Quaternionf;
using Quatd = Eigen::Quaterniond;
// 3x3 Matrix
using Mat3f = Eigen::Matrix<float, 3, 3>;
using Mat3d = Eigen::Matrix<double, 3, 3>;
#define UP Vec3d(0.0, 1.0, 0.0)
#define DOWN Vec3d(0, -1, 0)
#define RIGHT Vec3d(1, 0, 0)
#define LEFT Vec3d(-1, 0, 0)
#define FORWARD Vec3d(0, 0, -1)
#define BACKWARD Vec3d(0, 0, 1)
using Mat3f = Eigen::Matrix3f;
using Mat3d = Eigen::Matrix3d;
// Rigid transform (translation and rotation)
using RigidTransform3f = Eigen::Isometry3f;
using RigidTransform3d = Eigen::Isometry3d;
// Affine transform (translation, rotation, scaling and shearing)
using AffineTransform3f = Eigen::Affine3f;
using AffineTransform3d = Eigen::Affine3d;
// Handy cartesian vectors in 3d
#define UP_VECTOR Vec3d(0.0, 1.0, 0.0)
#define DOWN_VECTOR Vec3d(0, -1, 0)
#define RIGHT_VECTOR Vec3d(1, 0, 0)
#define LEFT_VECTOR Vec3d(-1, 0, 0)
#define FORWARD_VECTOR Vec3d(0, 0, -1)
#define BACKWARD_VECTOR Vec3d(0, 0, 1)
#define WORLD_ORIGIN Vec3d::Zero()
// Some commonly used math constants
const double iMSTK_PI = 3.14159265358979323846;
const double iMSTK_PI_2 = 1.57079632679489661923;
const double iMSTK_PI_4 = 0.785398163397448309616;
const double iMSTK_1_PI = 0.318309886183790671538;
const double iMSTK_2_PI = 0.636619772367581343076;
const double iMSTK_2_SQRTPI = 1.12837916709551257390;
const double iMSTK_SQRT2 = 1.41421356237309504880;
const double iMSTK_SQRT1_2 = 0.707106781186547524401;
const double iMSTK_E = 2.71828182845904523536;
const double iMSTK_LOG2E = 1.44269504088896340736;
const double iMSTK_LOG10E = 0.434294481903251827651;
const double iMSTK_LN2 = 0.693147180559945309417;
const double iMSTK_LN10 = 2.30258509299404568402;
}
#endif // ifndef imstkMath_h
......@@ -13,6 +13,8 @@ imstk_add_library( Geometry
imstkVolumetricMesh.h
imstkTetrahedralMesh.h
imstkHexahedralMesh.h
imstkGeometryMap.h
imstkIsometricMap.h
CPP_FILES
imstkGeometry.cpp
imstkPlane.cpp
......@@ -23,6 +25,8 @@ imstk_add_library( Geometry
imstkVolumetricMesh.cpp
imstkTetrahedralMesh.cpp
imstkHexahedralMesh.cpp
imstkGeometryMap.cpp
imstkIsometricMap.cpp
LIBRARIES
Core
VegaFEM::volumetricMesh
......
......@@ -60,6 +60,13 @@ Geometry::scale(const double& scaling)
m_scaling *= scaling;
}
void
Geometry::transform(const RigidTransform3d& transform)
{
this->rotate(transform.rotation());
this->translate(transform.translation());
}
const Vec3d&
Geometry::getPosition() const
{
......
......@@ -51,6 +51,9 @@ public:
const double& angle);
void scale(const double& scaling);
void transform(const RigidTransform3d& transform);
// Accessors
const Vec3d& getPosition() const;
void setPosition(const Vec3d& position);
void setPosition(const double& x,
......
/*=========================================================================
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 "imstkGeometryMap.h"
namespace imstk {
void GeometryMap::muteMap()
{
m_isActive = false;
}
void GeometryMap::activateMap()
{
m_isActive = true;
}
const GeometryMapType& GeometryMap::getType() const
{
return m_type;
}
void GeometryMap::setMaster(std::shared_ptr<Geometry> master)
{
m_master = master;
}
std::shared_ptr<Geometry> GeometryMap::getMaster() const
{
return m_master;
}
void GeometryMap::setSlave(std::shared_ptr<Geometry> slave)
{
m_slave = slave;
}
std::shared_ptr<Geometry> GeometryMap::getSlave() const
{
return m_slave;
}
bool GeometryMap::isActive() const
{
return m_isActive;
}
}
\ No newline at end of file
/*=========================================================================
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 imstkGeometryMap_h
#define imstkGeometryMap_h
#include <memory>
#include "imstkGeometry.h"
namespace imstk {
enum class GeometryMapType
{
Isometric,
TetraTriangle,
HexaTriangle,
TetraTetra
};
class GeometryMap
{
public:
~GeometryMap() = default;
///
/// \brief Compute the map
///
virtual void computeMap() = 0;
///
/// \brief Apply the map
///
virtual void applyMap() = 0;
///
/// \brief Deactivate the map
///
void muteMap();
///
/// \brief Activate the map
///
void activateMap();
// Accessors
const GeometryMapType& getType() const;
void setMaster(std::shared_ptr<Geometry> master);
std::shared_ptr<Geometry> getMaster() const;
void setSlave(std::shared_ptr<Geometry> slave);
std::shared_ptr<Geometry> getSlave() const;
///
/// \brief Returns true if the map is actively applied at runtime, else false.
///
bool isActive() const;
protected:
GeometryMap(GeometryMapType type) : m_isActive(true) {}
GeometryMapType m_type; ///> type of the map
bool m_isActive; ///> true if the map us active at runtime
std::shared_ptr<Geometry> m_master; ///> the geometry which dictates the configuration
std::shared_ptr<Geometry> m_slave; ///> the geometry which follows the master
};
}
#endif // imstkGeometryMap_h
/*=========================================================================
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 "imstkIsometricMap.h"
namespace imstk {
void IsometricMap::setTransform(const RigidTransform3d& affineTransform)
{
m_rigidTransform = affineTransform;
}
const imstk::RigidTransform3d& IsometricMap::getTransform() const
{
return m_rigidTransform;
}
void IsometricMap::applyMap()
{
if (m_isActive)
{
// First set the follower mesh configuration to that of master
m_slave->setPosition(m_master->getPosition());
m_slave->setOrientation(m_master->getOrientation());
// Now, apply the offset transform
m_slave->transform(m_rigidTransform);
}
}
}
\ No newline at end of file
/*=========================================================================
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 imstkAffineMap_h
#define imstkAffineMap_h
#include "imstkGeometryMap.h"
namespace imstk {
class IsometricMap : public GeometryMap
{
public:
~IsometricMap() = default;
IsometricMap() : GeometryMap(GeometryMapType::Isometric), m_rigidTransform(RigidTransform3d::Identity()){}
void applyMap();
// Accessors
void setTransform(const RigidTransform3d& affineTransform);
const RigidTransform3d& getTransform() const;
protected:
RigidTransform3d m_rigidTransform;
};
}
#endif // imstkGeometryMap_h
......@@ -45,7 +45,7 @@ protected:
Mesh(GeometryType type) : Geometry(type, WORLD_ORIGIN, Quatd()) {}
// Orientation * Scaling * initialVertexPositions
// + Position
// + Position (Initial translation)
// + vertexDisplacements
// = vertexPositions
std::vector<Vec3d> m_initialVertexPositions;
......
......@@ -25,13 +25,13 @@ namespace imstk {
Vec3d
Plane::getNormal() const
{
return m_orientation._transformVector(UP);
return m_orientation._transformVector(UP_VECTOR);
}
void
Plane::setNormal(const Vec3d& normal)
{
this->setOrientation(Quatd::FromTwoVectors(UP, normal));
this->setOrientation(Quatd::FromTwoVectors(UP_VECTOR, normal));
}
const double&
......
......@@ -30,11 +30,11 @@ class Plane : public Geometry
public:
Plane(const Vec3d & position = WORLD_ORIGIN,
const Vec3d & normal = UP,
const Vec3d & normal = UP_VECTOR,
const double& width = 1) :
Geometry(GeometryType::Plane,
position,
Quatd::FromTwoVectors(UP, normal)),
Quatd::FromTwoVectors(UP_VECTOR, normal)),
m_width(width)
{}
......
......@@ -45,6 +45,7 @@ public:
void computeVertexNormals();
void computeVertexTangents();
// Accessors
void setTriangleVertices(
const std::vector<TriangleArray>& triangles);
......
......@@ -37,13 +37,14 @@ public:
~TetrahedralMesh() = default;
// Accessors
const std::vector<TetraArray>& getTetrahedronVertices() const;
void setTetrahedronVertices(
const std::vector<TetraArray>& tetrahedrons);
protected:
std::vector<TetraArray> m_tetrahedronVertices;
std::vector<TetraArray> m_tetrahedronVertices; ///< vertices of the tetrahedra
};
}
......
......@@ -34,7 +34,9 @@ public:
~VolumetricMesh() = default;
// Accessors
std::shared_ptr<SurfaceMesh>getAttachedSurfaceMesh();
void setAttachedSurfaceMesh(std::shared_ptr<SurfaceMesh>surfaceMesh);
protected:
......
......@@ -30,7 +30,7 @@ PlaneRenderDelegate::PlaneRenderDelegate(std::shared_ptr<Plane>plane) :
auto source = vtkSmartPointer<vtkPlaneSource>::New();
source->SetCenter(WORLD_ORIGIN[0], WORLD_ORIGIN[1], WORLD_ORIGIN[2]);
source->SetNormal(UP[0], UP[1], UP[2]);
source->SetNormal(UP_VECTOR[0], UP_VECTOR[1], UP_VECTOR[2]);
this->setActorMapper(source->GetOutputPort());
this->setActorTransform(m_geometry);
......
......@@ -58,7 +58,7 @@ protected:
SceneObjectType m_type = SceneObjectType::Visual;
std::string m_name;
std::shared_ptr<Geometry> m_visualGeometry;
std::shared_ptr<Geometry> m_visualGeometry; ///> Geometry for rendering
};
using VisualObject = SceneObject;
......
......@@ -31,8 +31,8 @@ int main()
auto cubeGeom = std::make_shared<imstk::Cube>();
cubeGeom->scale(0.5);
cubeGeom->rotate(imstk::UP, M_PI/4);
cubeGeom->rotate(imstk::RIGHT, M_PI/4);
cubeGeom->rotate(imstk::UP_VECTOR, M_PI/4);
cubeGeom->rotate(imstk::RIGHT_VECTOR, M_PI / 4);
cubeGeom->translate(2, 1, 0.5);
auto cubeObj = std::make_shared<imstk::VisualObject>("VisualCube");
cubeObj->setVisualGeometry(cubeGeom);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment