Skip to content

Commit

Permalink
[DefaultType] Extract inner classes from SolidTypes in files (sofa-fr…
Browse files Browse the repository at this point in the history
…amework#4513)

* Move SpatialVector in its own file

* Move Transform in its own file

* Move both files in Sofa.Type

* Change types from inner class of SolidTypes to its true type
  • Loading branch information
alxbilger authored Feb 27, 2024
1 parent 3300c00 commit 251fd89
Show file tree
Hide file tree
Showing 21 changed files with 839 additions and 635 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void ForceFeedback::init()
context = sofa::simulation::node::getNodeFrom(getContext());
}

void ForceFeedback::setReferencePosition(sofa::defaulttype::SolidTypes<SReal>::Transform& referencePosition)
void ForceFeedback::setReferencePosition(sofa::type::Transform<SReal>& referencePosition)
{
SOFA_UNUSED(referencePosition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <sofa/simulation/fwd.h>
#include <sofa/core/behavior/BaseController.h>
#include <sofa/defaulttype/SolidTypes.h>
#include <sofa/type/Transform.h>
#include <sofa/defaulttype/RigidTypes.h>

namespace sofa::component::haptics
Expand All @@ -48,11 +48,11 @@ class SOFA_COMPONENT_HAPTICS_API ForceFeedback : public virtual core::behavior::
SReal u, SReal v, SReal w,
SReal q, SReal& fx, SReal& fy, SReal& fz) = 0;

virtual void computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &,
const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &,
sofa::defaulttype::SolidTypes<SReal>::SpatialVector & )=0;
virtual void computeWrench(const sofa::type::Transform<SReal> &,
const sofa::type::SpatialVector<SReal> &,
sofa::type::SpatialVector<SReal> & )=0;

virtual void setReferencePosition(sofa::defaulttype::SolidTypes<SReal>::Transform& referencePosition);
virtual void setReferencePosition(sofa::type::Transform<SReal>& referencePosition);
virtual bool isEnabled();

/// Abstract method to lock or unlock the force feedback computation. To be implemented by child class if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void LCPForceFeedback< Rigid3Types >::computeForce(SReal x, SReal y, SReal z, SR


template <>
void LCPForceFeedback< Rigid3Types >::computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &world_H_tool,
const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &/*V_tool_world*/,
sofa::defaulttype::SolidTypes<SReal>::SpatialVector &W_tool_world )
void LCPForceFeedback< Rigid3Types >::computeWrench(const sofa::type::Transform<SReal> &world_H_tool,
const sofa::type::SpatialVector<SReal> &/*V_tool_world*/,
sofa::type::SpatialVector<SReal> &W_tool_world )
{
if (!this->d_activate.getValue())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class LCPForceFeedback : public MechanicalStateForceFeedback<TDataTypes>
void computeForce(SReal x, SReal y, SReal z,
SReal u, SReal v, SReal w,
SReal q, SReal& fx, SReal& fy, SReal& fz) override;
void computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &world_H_tool,
const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &V_tool_world,
sofa::defaulttype::SolidTypes<SReal>::SpatialVector &W_tool_world ) override;
void computeWrench(const sofa::type::Transform<SReal> &world_H_tool,
const sofa::type::SpatialVector<SReal> &V_tool_world,
sofa::type::SpatialVector<SReal> &W_tool_world ) override;
void computeForce(const VecCoord& state, VecDeriv& forces) override;

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ void LCPForceFeedback<DataTypes>::computeForce(SReal , SReal, SReal, SReal, SRea


template <typename DataTypes>
void LCPForceFeedback<DataTypes>::computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &,
const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &,
sofa::defaulttype::SolidTypes<SReal>::SpatialVector & )
void LCPForceFeedback<DataTypes>::computeWrench(const sofa::type::Transform<SReal> &,
const sofa::type::SpatialVector<SReal> &,
sofa::type::SpatialVector<SReal> & )
{

}
Expand All @@ -425,9 +425,9 @@ template <>
void SOFA_COMPONENT_HAPTICS_API LCPForceFeedback< sofa::defaulttype::Rigid3Types >::computeForce(SReal x, SReal y, SReal z, SReal, SReal, SReal, SReal, SReal& fx, SReal& fy, SReal& fz);

template <>
void SOFA_COMPONENT_HAPTICS_API LCPForceFeedback< sofa::defaulttype::Rigid3Types >::computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &world_H_tool,
const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &/*V_tool_world*/,
sofa::defaulttype::SolidTypes<SReal>::SpatialVector &W_tool_world );
void SOFA_COMPONENT_HAPTICS_API LCPForceFeedback< sofa::defaulttype::Rigid3Types >::computeWrench(const sofa::type::Transform<SReal> &world_H_tool,
const sofa::type::SpatialVector<SReal> &/*V_tool_world*/,
sofa::type::SpatialVector<SReal> &W_tool_world );



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class SOFA_COMPONENT_HAPTICS_API MechanicalStateForceFeedback : public ForceFeed

void init() override {context = sofa::simulation::node::getNodeFrom(getContext());}
void computeForce(SReal x, SReal y, SReal z, SReal u, SReal v, SReal w, SReal q, SReal& fx, SReal& fy, SReal& fz) override = 0;
void computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &, const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &, sofa::defaulttype::SolidTypes<SReal>::SpatialVector & ) override = 0;
void setReferencePosition(sofa::defaulttype::SolidTypes<SReal>::Transform& /*referencePosition*/) override {}
void computeWrench(const sofa::type::Transform<SReal> &, const sofa::type::SpatialVector<SReal> &, sofa::type::SpatialVector<SReal> & ) override = 0;
void setReferencePosition(sofa::type::Transform<SReal>& /*referencePosition*/) override {}

protected:
MechanicalStateForceFeedback(void) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void NullForceFeedback::computeForce(SReal /*x*/, SReal /*y*/, SReal /*z*/, SRea
fx = fy = fz = 0.0;
}

void NullForceFeedback::computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &/*world_H_tool*/, const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &/*V_tool_world*/, sofa::defaulttype::SolidTypes<SReal>::SpatialVector &W_tool_world )
void NullForceFeedback::computeWrench(const sofa::type::Transform<SReal> &/*world_H_tool*/, const sofa::type::SpatialVector<SReal> &/*V_tool_world*/, sofa::type::SpatialVector<SReal> &W_tool_world )
{
W_tool_world.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SOFA_COMPONENT_HAPTICS_API NullForceFeedback : public ForceFeedback
void init() override;

void computeForce(SReal x, SReal y, SReal z, SReal u, SReal v, SReal w, SReal q, SReal& fx, SReal& fy, SReal& fz) override;
void computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &world_H_tool, const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &V_tool_world, sofa::defaulttype::SolidTypes<SReal>::SpatialVector &W_tool_world ) override;
void computeWrench(const sofa::type::Transform<SReal> &world_H_tool, const sofa::type::SpatialVector<SReal> &V_tool_world, sofa::type::SpatialVector<SReal> &W_tool_world ) override;
};

} // namespace sofa::component::haptics
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SOFA_COMPONENT_HAPTICS_API NullForceFeedbackT : public MechanicalStateForc
fx = fy = fz = 0.0;
}
void computeForce(const VecCoord &, VecDeriv &) override {}
void computeWrench(const sofa::defaulttype::SolidTypes<SReal>::Transform &, const sofa::defaulttype::SolidTypes<SReal>::SpatialVector &, sofa::defaulttype::SolidTypes<SReal>::SpatialVector &W_tool_world ) override {W_tool_world.clear();}
void computeWrench(const sofa::type::Transform<SReal> &, const sofa::type::SpatialVector<SReal> &, sofa::type::SpatialVector<SReal> &W_tool_world ) override {W_tool_world.clear();}
};

} // namespace sofa::component::haptics
16 changes: 8 additions & 8 deletions Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using Mat3 = sofa::type::Mat3x3;
using Mat4 = sofa::type::Mat4x4;

#include <sofa/defaulttype/SolidTypes.h>
#include <sofa/type/Transform.h>
#include <sofa/simulation/AnimateBeginEvent.h>

#include <sofa/helper/rmath.h>
Expand Down Expand Up @@ -369,7 +369,7 @@ type::Vec2 BaseCamera::worldToScreenCoordinates(const type::Vec3& pos)

void BaseCamera::getModelViewMatrix(double mat[16])
{
const defaulttype::SolidTypes<SReal>::Transform world_H_cam(p_position.getValue(), this->getOrientation());
const sofa::type::Transform<SReal> world_H_cam(p_position.getValue(), this->getOrientation());
Mat3 rot = world_H_cam.inversed().getRotationMatrix();

//rotation
Expand All @@ -392,7 +392,7 @@ void BaseCamera::getModelViewMatrix(double mat[16])

void BaseCamera::getOpenGLModelViewMatrix(double mat[16])
{
const defaulttype::SolidTypes<SReal>::Transform world_H_cam(p_position.getValue(), this->getOrientation());
const sofa::type::Transform<SReal> world_H_cam(p_position.getValue(), this->getOrientation());
world_H_cam.inversed().writeOpenGlMatrix(mat);
}

Expand Down Expand Up @@ -548,10 +548,10 @@ void BaseCamera::rotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point,
rotation.quatToAxis(tempAxis, tempAngle);
const Quat tempQuat (orientationCam.rotate(-tempAxis), tempAngle);

const defaulttype::SolidTypes<SReal>::Transform world_H_cam(positionCam, orientationCam);
const defaulttype::SolidTypes<SReal>::Transform world_H_pivot(point, Quat());
const defaulttype::SolidTypes<SReal>::Transform pivotBefore_R_pivotAfter(type::Vec3(0.0,0.0,0.0), tempQuat);
const defaulttype::SolidTypes<SReal>::Transform camera_H_WorldAfter = world_H_cam.inversed() * world_H_pivot * pivotBefore_R_pivotAfter * world_H_pivot.inversed();
const sofa::type::Transform<SReal> world_H_cam(positionCam, orientationCam);
const sofa::type::Transform<SReal> world_H_pivot(point, Quat());
const sofa::type::Transform<SReal> pivotBefore_R_pivotAfter(type::Vec3(0.0,0.0,0.0), tempQuat);
const sofa::type::Transform<SReal> camera_H_WorldAfter = world_H_cam.inversed() * world_H_pivot * pivotBefore_R_pivotAfter * world_H_pivot.inversed();
//defaulttype::SolidTypes<double>::Transform camera_H_WorldAfter = worldBefore_H_cam.inversed()*worldBefore_R_worldAfter;

positionCam = camera_H_WorldAfter.inversed().getOrigin();
Expand Down Expand Up @@ -662,7 +662,7 @@ void BaseCamera::computeZ()
if (p_computeZClip.getValue())
{
//modelview transform
defaulttype::SolidTypes<SReal>::Transform world_H_cam(p_position.getValue(), this->getOrientation());
sofa::type::Transform<SReal> world_H_cam(p_position.getValue(), this->getOrientation());

//double distanceCamToCenter = fabs((world_H_cam.inversed().projectPoint(sceneCenter))[2]);
const double distanceCamToCenter = (p_position.getValue() - sceneCenter).norm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#pragma once
#include <sofa/gl/component/shader/config.h>

#include <sofa/defaulttype/SolidTypes.h>
#include <sofa/gl/component/shader/Light.h>
#include <sofa/core/visual/VisualManager.h>
#include <sofa/type/Mat.h>
Expand Down
Loading

0 comments on commit 251fd89

Please sign in to comment.