Skip to content
Snippets Groups Projects
Commit b8704028 authored by Alexis Girault's avatar Alexis Girault
Browse files

ENH: Get rid of AnalyticalGeometry class

This base class was needed for storing position and
orientation of the geometries. Those global transformation
can also be applied to discrete geometries, therefore
Geometry and AnalyticalGeometry classes were merged.
parent cfbf57fb
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,11 @@ include(imstkAddLibrary)
imstk_add_library( Geometry
H_FILES
imstkGeometry.h
imstkAnalyticalGeometry.h
imstkPlane.h
imstkSphere.h
imstkCube.h
CPP_FILES
imstkGeometry.cpp
imstkAnalyticalGeometry.cpp
imstkPlane.cpp
imstkSphere.cpp
imstkCube.cpp
......
/*=========================================================================
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 "imstkAnalyticalGeometry.h"
namespace imstk {
void
AnalyticalGeometry::translate(const Vec3d& t)
{
m_position += t;
}
void
AnalyticalGeometry::translate(const double& x,
const double& y,
const double& z)
{
this->translate(Vec3d(x, y, z));
}
void
AnalyticalGeometry::rotate(const Quatd& r)
{
m_orientation = r * m_orientation;
}
void
AnalyticalGeometry::rotate(const Mat3d& r)
{
this->rotate(Quatd(r));
}
void
AnalyticalGeometry::rotate(const Vec3d& axis, const double& angle)
{
this->rotate(Quatd(Eigen::AngleAxisd(angle, axis)));
}
const Vec3d&
AnalyticalGeometry::getPosition() const
{
return m_position;
}
void
AnalyticalGeometry::setPosition(const Vec3d& position)
{
m_position = position;
}
void
AnalyticalGeometry::setPosition(const double& x,
const double& y,
const double& z)
{
this->setPosition(Vec3d(x, y, z));
}
const Quatd&
AnalyticalGeometry::getOrientation() const
{
return m_orientation;
}
void
AnalyticalGeometry::setOrientation(const Quatd& orientation)
{
m_orientation = orientation;
}
void
AnalyticalGeometry::setOrientation(const Mat3d& orientation)
{
this->setOrientation(Quatd(orientation));
}
void
AnalyticalGeometry::setOrientation(const Vec3d& axis, const double& angle)
{
this->setOrientation(Quatd(Eigen::AngleAxisd(angle, axis)));
}
}
/*=========================================================================
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 imstkAnalyticalGeometry_h
#define imstkAnalyticalGeometry_h
#include "imstkGeometry.h"
namespace imstk {
class AnalyticalGeometry : public Geometry
{
public:
~AnalyticalGeometry() = default;
void translate(const Vec3d& t) override;
void translate(const double& x,
const double& y,
const double& z) override;
void rotate(const Quatd& r) override;
void rotate(const Mat3d& r) override;
void rotate(const Vec3d & axis,
const double& angle) override;
const Vec3d& getPosition() const;
void setPosition(const Vec3d& position);
void setPosition(const double& x,
const double& y,
const double& z);
const Quatd& getOrientation() const;
void setOrientation(const Quatd& orientation);
void setOrientation(const Mat3d& orientation);
void setOrientation(const Vec3d & axis,
const double& angle);
protected:
AnalyticalGeometry(GeometryType type,
const Vec3d& position = Vec3d(),
const Quatd& orientation = Quatd()) :
Geometry(type),
m_position(position),
m_orientation(orientation)
{}
Vec3d m_position;
Quatd m_orientation;
};
}
#endif // ifndef imstkAnalyticalGeometry_h
......@@ -22,18 +22,18 @@
#ifndef imstkCube_h
#define imstkCube_h
#include "imstkAnalyticalGeometry.h"
#include "imstkGeometry.h"
namespace imstk {
class Cube : public AnalyticalGeometry
class Cube : public Geometry
{
public:
Cube(const Vec3d & position = ORIGIN,
const double& width = 10) :
AnalyticalGeometry(GeometryType::Cube,
position,
Quatd()),
Geometry(GeometryType::Cube,
position,
Quatd()),
m_width(width)
{}
......
......@@ -22,6 +22,82 @@
#include "imstkGeometry.h"
namespace imstk {
void
Geometry::translate(const Vec3d& t)
{
m_position += t;
}
void
Geometry::translate(const double& x,
const double& y,
const double& z)
{
this->translate(Vec3d(x, y, z));
}
void
Geometry::rotate(const Quatd& r)
{
m_orientation = r * m_orientation;
}
void
Geometry::rotate(const Mat3d& r)
{
this->rotate(Quatd(r));
}
void
Geometry::rotate(const Vec3d& axis, const double& angle)
{
this->rotate(Quatd(Eigen::AngleAxisd(angle, axis)));
}
const Vec3d&
Geometry::getPosition() const
{
return m_position;
}
void
Geometry::setPosition(const Vec3d& position)
{
m_position = position;
}
void
Geometry::setPosition(const double& x,
const double& y,
const double& z)
{
this->setPosition(Vec3d(x, y, z));
}
const Quatd&
Geometry::getOrientation() const
{
return m_orientation;
}
void
Geometry::setOrientation(const Quatd& orientation)
{
m_orientation = orientation;
}
void
Geometry::setOrientation(const Mat3d& orientation)
{
this->setOrientation(Quatd(orientation));
}
void
Geometry::setOrientation(const Vec3d& axis, const double& angle)
{
this->setOrientation(Quatd(Eigen::AngleAxisd(angle, axis)));
}
const GeometryType&
Geometry::getType() const
{
......
......@@ -41,22 +41,42 @@ public:
~Geometry() = default;
virtual void translate(const Vec3d& t) = 0;
virtual void translate(const double& x,
const double& y,
const double& z) = 0;
virtual void rotate(const Quatd& r) = 0;
virtual void rotate(const Vec3d & axis,
const double& angle) = 0;
virtual void rotate(const Mat3d& r) = 0;
void translate(const Vec3d& t);
void translate(const double& x,
const double& y,
const double& z);
void rotate(const Quatd& r);
void rotate(const Mat3d& r);
void rotate(const Vec3d & axis,
const double& angle);
const Vec3d& getPosition() const;
void setPosition(const Vec3d& position);
void setPosition(const double& x,
const double& y,
const double& z);
const Quatd & getOrientation() const;
void setOrientation(const Quatd& orientation);
void setOrientation(const Mat3d& orientation);
void setOrientation(const Vec3d & axis,
const double& angle);
const GeometryType& getType() const;
protected:
Geometry(GeometryType type) : m_type(type) {}
Geometry(GeometryType type,
const Vec3d& position = Vec3d(),
const Quatd& orientation = Quatd()) :
m_type(type),
m_position(position),
m_orientation(orientation)
{}
GeometryType m_type;
Vec3d m_position;
Quatd m_orientation;
};
}
......
......@@ -22,19 +22,19 @@
#ifndef imstkPlane_h
#define imstkPlane_h
#include "imstkAnalyticalGeometry.h"
#include "imstkGeometry.h"
namespace imstk {
class Plane : public AnalyticalGeometry
class Plane : public Geometry
{
public:
Plane(const Vec3d & position = ORIGIN,
const Vec3d & normal = UP,
const double& width = 100) :
AnalyticalGeometry(GeometryType::Plane,
position,
Quatd::FromTwoVectors(UP, normal)),
Geometry(GeometryType::Plane,
position,
Quatd::FromTwoVectors(UP, normal)),
m_width(width)
{}
......
......@@ -22,18 +22,18 @@
#ifndef imstkSphere_h
#define imstkSphere_h
#include "imstkAnalyticalGeometry.h"
#include "imstkGeometry.h"
namespace imstk {
class Sphere : public AnalyticalGeometry
class Sphere : public Geometry
{
public:
Sphere(const Vec3d & position = ORIGIN,
const double& radius = 10) :
AnalyticalGeometry(GeometryType::Sphere,
position,
Quatd()),
Geometry(GeometryType::Sphere,
position,
Quatd()),
m_radius(radius)
{}
......
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