Commit d6136d80 authored by Ricardo Ortiz's avatar Ricardo Ortiz
Browse files

ENH: Refactoring and cleaning SceneObject.

* Remove custom renderers
* Remove local storage for vertices
* Documenting

Small format changes all over the place.
parent 2a84d7c1
Pipeline #4817 passed with stage
......@@ -74,10 +74,6 @@ void ViewerBase::initObjects()
{
i->initDraw();
}
else
{
continue;
}
}
}
......@@ -92,11 +88,6 @@ void ViewerBase::initScenes()
for (const auto &sceneObject : scene->getSceneObjects())
{
//initialize the custom Render if there is any
if ( sceneObject->customRender != nullptr && sceneObject->getType() != core::ClassType::Shader )
{
sceneObject->customRender->initDraw();
}
sceneObject->initDraw();
}
}//scene traverse
......
......@@ -26,77 +26,162 @@
SceneObject::SceneObject()
{
type = core::ClassType::Unknown;
isActive = true;
objectSim = nullptr;
customRender = nullptr;
flags.isViewerInit = false;
flags.isSimulatorInit = false;
name = "SceneObject" + std::to_string(this->getUniqueId()->getId());
hasContactForces = false;
this->hasContactForces = false;
this->isActive = true;
this->flags.isViewerInit = false;
this->flags.isSimulatorInit = false;
this->type = core::ClassType::Unknown;
this->objectSim = nullptr;
this->name = "SceneObject" + std::to_string(this->getUniqueId()->getId());
}
SceneObject::~SceneObject()
//---------------------------------------------------------------------------
bool SceneObject::configure(const std::string &)
{
return false;
}
//---------------------------------------------------------------------------
void SceneObject::attachObjectSimulator(std::shared_ptr<ObjectSimulator> p_objectSim)
{
p_objectSim->addObject(safeDownCast<SceneObject>());
if(!p_objectSim)
{
// Log this
return;
}
this->objectSim = p_objectSim;
}
//---------------------------------------------------------------------------
void SceneObject::releaseObjectSimulator()
{
objectSim->removeObject(safeDownCast<SceneObject>());
objectSim = nullptr;
if(!this->objectSim)
{
// Log this
return;
}
this->objectSim->removeObject(safeDownCast<SceneObject>());
this->objectSim = nullptr;
}
std::shared_ptr<ObjectSimulator> SceneObject::getObjectSimulator()
{
return objectSim;
}
void SceneObject::attachCustomRenderer(std::shared_ptr<CustomRenderer> p_customeRenderer)
//---------------------------------------------------------------------------
void SceneObject::freeze()
{
customRender = p_customeRenderer;
this->isActive = false;
}
void SceneObject::releaseCustomeRenderer()
//---------------------------------------------------------------------------
std::shared_ptr<ObjectSimulator> SceneObject::getObjectSimulator()
{
customRender = nullptr;
return this->objectSim;
}
//---------------------------------------------------------------------------
int SceneObject::getObjectId()
{
return this->getUniqueId()->getId();
}
//---------------------------------------------------------------------------
UnifiedId::Pointer SceneObject::getObjectUnifiedID()
{
return std::make_shared<UnifiedId>();
}
std::vector<core::Vec3d> & SceneObject::getLocalVertices()
//---------------------------------------------------------------------------
ObjectInitFlags & SceneObject::getFlags()
{
return localVertices;
return this->flags;
}
ObjectInitFlags & SceneObject::getFlags()
//---------------------------------------------------------------------------
void SceneObject::activate()
{
return flags;
this->isActive = true;
}
std::shared_ptr<CustomRenderer> SceneObject::getRenderer()
//---------------------------------------------------------------------------
bool SceneObject::computeContactForce()
{
return customRender;
return this->hasContactForces;
}
void SceneObject::freeze()
//---------------------------------------------------------------------------
void SceneObject::setContactForcesOff()
{
this->isActive = false;
this->hasContactForces = false;
}
void SceneObject::activate()
//---------------------------------------------------------------------------
void SceneObject::setContactForcesOn()
{
this->hasContactForces = true;
}
//---------------------------------------------------------------------------
std::unordered_map< int, core::Vec3d> &SceneObject::getContactForces()
{
return this->contactForces;
}
//---------------------------------------------------------------------------
const std::unordered_map< int,core::Vec3d> &SceneObject::getContactForces() const
{
return this->contactForces;
}
//---------------------------------------------------------------------------
std::unordered_map< int,core::Vec3d> &SceneObject::getContactPoints()
{
return this->contactPoints;
}
//---------------------------------------------------------------------------
const std::unordered_map< int,core::Vec3d> &SceneObject::getContactPoints() const
{
return this->contactPoints;
}
//---------------------------------------------------------------------------
core::Vec3d SceneObject::getVelocity(const int) const
{
return core::Vec3d::Zero();
}
//---------------------------------------------------------------------------
void SceneObject::setContactForcesToZero()
{
this->contactForces.clear();
this->contactPoints.clear();
}
//---------------------------------------------------------------------------
void SceneObject::setContactForce(const int dofID, const core::Vec3d &force)
{
this->contactForces[dofID] = force;
}
//---------------------------------------------------------------------------
void SceneObject::
setContactForce(const int dofID, const core::Vec3d &point, const core::Vec3d &force)
{
this->contactPoints[dofID] = point;
this->contactForces[dofID] = force;
}
//---------------------------------------------------------------------------
void SceneObject::setModel(std::shared_ptr< Model > m)
{
this->model = m;
}
//---------------------------------------------------------------------------
std::shared_ptr< Model > SceneObject::getModel()
{
return this->model;
}
//---------------------------------------------------------------------------
void SceneObject::update(const double)
{
this->isActive = true;
}
......@@ -53,178 +53,183 @@ struct ObjectInitFlags
class SceneObject : public CoreClass
{
friend class SDK;
friend class ViewerBase;
friend class OpenGLViewer;
friend class Scene;
friend class ObjectSimulator;
public:
/// \brief constructor
///
/// \brief Constructor.
///
SceneObject();
/// \brief destructor
~SceneObject();
///
/// \brief Destructor.
///
~SceneObject() = default;
/// \brief Abstract object initialization
///
/// \brief Abstract object initialization.
///
virtual void initialize() = 0;
virtual bool configure(const std::string &/*ConfigFile*/)
{
return false;
};
///
/// \brief Load the initial posiitons, velocities etc.,
///
virtual void loadInitialStates() = 0;
/// \brief attach simulator to the object.
/// This function that needs to be called to associate the simulator to the object
///
/// \brief serialize function explicity writes the object to the memory block
/// each scene object should know how to write itself to a memory block.
///
virtual void serialize(void *p_memoryBlock) = 0;
///
/// \brief Unserialize function can recover the object from the memory location.
///
virtual void unSerialize(void *p_memoryBlock) = 0;
///
/// \brief This function may not be used
/// every Scene Object should know how to clone itself. Since the data structures
/// will be in the beginning of the modules(such as simulator, viewer,
/// collision etc.)
///
virtual std::shared_ptr<SceneObject> clone() = 0;
///
/// \brief print information related the scene object.
///
virtual void printInfo() const = 0;
///
/// \brief Define this function if you want to configure this scene model with using
/// an external file.
///
virtual bool configure(const std::string &/*ConfigFile*/);
///
/// \brief Attach simulator to the object.
/// This function that needs to be called to associate the simulator
/// to the object.
///
virtual void attachObjectSimulator(std::shared_ptr<ObjectSimulator> p_objectSim);
/// \brief to release the simulator
///
/// \brief To release the simulator.
///
virtual void releaseObjectSimulator();
/// \brief freeze the scene object by stopping any further updates
///
/// \brief Freeze the scene object by stopping any further updates.
///
void freeze();
/// \brief activate the scene object
void activate();
/// \brief get object simulator
///
/// \brief Get object simulator.
///
std::shared_ptr<ObjectSimulator> getObjectSimulator();
/// \brief attach custome renderer for the object.
/// If the default rendering is not helpful
void attachCustomRenderer(std::shared_ptr<CustomRenderer> p_customeRenderer);
/// \brief release the renderer
void releaseCustomeRenderer();
/// \brief returns object id
///
/// \brief Returns object id.
///
int getObjectId();
/// \brief get unified object id
///
/// \brief Get unified object id.
///
UnifiedId::Pointer getObjectUnifiedID();
std::vector<core::Vec3d> &getLocalVertices();
///
/// \brief Get local initialization flags.
///
ObjectInitFlags &getFlags();
std::shared_ptr<CustomRenderer> getRenderer();
///serialize function explicity writes the object to the memory block
///each scene object should know how to write itself to a memory block
virtual void serialize(void *p_memoryBlock) = 0;
///Unserialize function can recover the object from the memory location
virtual void unSerialize(void *p_memoryBlock) = 0;
///this function may not be used
///every Scene Object should know how to clone itself. Since the data structures will be
///in the beginning of the modules(such as simulator, viewer, collision etc.)
virtual std::shared_ptr<SceneObject> clone() = 0;
/// \brief print information related the scene object
virtual void printInfo() const = 0;
///
/// \brief Set to activate this scene model.
///
void activate();
///
/// \brief Set to compute contact forces
/// \brief Set to compute contact forces.
///
bool computeContactForce()
{
return this->hasContactForces;
}
bool computeContactForce();
///
/// \brief Set to not compute contact forces
/// \brief Set to not compute contact forces.
///
void setContactForcesOff()
{
this->hasContactForces = false;
}
void setContactForcesOff();
///
/// \brief Set to not compute contact forces
/// \brief Set to not compute contact forces.
///
void setContactForcesOn()
{
this->hasContactForces = true;
}
void setContactForcesOn();
// Get contact forces vector
std::unordered_map<int,core::Vec3d> &getContactForces()
{
return this->contactForces;
}
///
/// \brief Get contact forces vector.
///
std::unordered_map<int,core::Vec3d> &getContactForces();
const std::unordered_map<int,core::Vec3d> &getContactForces() const
{
return this->contactForces;
}
///
/// \brief Get the map of contact forces.
///
/// \return Map containing indices with contact points.
///
const std::unordered_map<int,core::Vec3d> &getContactForces() const;
// Get contact forces vector
std::unordered_map<int,core::Vec3d> &getContactPoints()
{
return this->contactPoints;
}
///
/// \brief Get contact forces vector
///
std::unordered_map<int,core::Vec3d> &getContactPoints();
const std::unordered_map<int,core::Vec3d> &getContactPoints() const
{
return this->contactPoints;
}
///
/// \brief Get contact forces vector
///
const std::unordered_map<int,core::Vec3d> &getContactPoints() const;
/// \brief returns velocity of at a given location
/// (not given node) in contact force vector
virtual core::Vec3d getVelocity(const int) const
{
return core::Vec3d::Zero();
}
///
/// \brief Returns velocity of at a given location
/// (not given node) in contact force vector
///
virtual core::Vec3d getVelocity(const int) const;
///
/// \brief Set all contact forces to zero (if any)
void setContactForcesToZero()
{
this->contactForces.clear();
this->contactPoints.clear();
}
///
void setContactForcesToZero();
void setContactForce(const int dofID, const core::Vec3d &force)
{
this->contactForces[dofID] = force;
}
///
/// \brief Get contact forces vector
///
void setContactForce(const int dofID, const core::Vec3d &force);
///
/// \brief Get contact forces vector
///
void setContactForce(const int dofID,
const core::Vec3d &point,
const core::Vec3d &force)
{
this->contactPoints[dofID] = point;
this->contactForces[dofID] = force;
}
const core::Vec3d &force);
void setModel(std::shared_ptr<Model> m)
{
this->model = m;
}
///
/// \brief Get contact forces vector
///
void setModel(std::shared_ptr<Model> m);
std::shared_ptr<Model> getModel()
{
return this->model;
}
///
/// \brief Get contact forces vector
///
std::shared_ptr<Model> getModel();
virtual void update(const double /*dt*/)
{
}
///
/// \brief Get contact forces vector
///
virtual void update(const double /*dt*/);
protected:
bool hasContactForces;
bool isActive;
std::shared_ptr<ObjectSimulator> objectSim; //!< object simulator that will simulate the object
std::shared_ptr<CustomRenderer> customRender;
std::vector<core::Vec3d> localVertices; //!< local copy of vertices
ObjectInitFlags flags;
bool hasContactForces;
std::shared_ptr<Model> model; //!< model attached to this scene object
std::shared_ptr<ObjectSimulator> objectSim; //!< object simulator that will simulate the object
std::unordered_map<int,core::Vec3d> contactForces;
std::unordered_map<int,core::Vec3d> contactPoints;
std::shared_ptr<Model> model; //!< model attached to this scene object
};
#endif
......@@ -71,12 +71,6 @@ public:
///
virtual void handleEvent(std::shared_ptr<core::Event>) override {}
///
///
///
void update(const double /*dt*/) override
{}
///
/// \brief Initialize mesh for this model
///
......
......@@ -270,7 +270,8 @@ VegaConfiguration::VegaConfiguration(const std::string &configurationFile, bool
//---------------------------------------------------------------------------
VegaFEMDeformableSceneObject::
VegaFEMDeformableSceneObject(const std::string &meshFilename,
const std::string &vegaConfigFileName)
const std::string &vegaConfigFileName
)
{
this->loadVolumeMesh(meshFilename);
if(!this->volumetricMesh)
......@@ -284,7 +285,9 @@ VegaFEMDeformableSceneObject(const std::string &meshFilename,
}
//---------------------------------------------------------------------------
VegaFEMDeformableSceneObject::~VegaFEMDeformableSceneObject() {}
VegaFEMDeformableSceneObject::~VegaFEMDeformableSceneObject()
{ // This destructor must be defined here
}
//---------------------------------------------------------------------------
void VegaFEMDeformableSceneObject::loadVolumeMesh(const std::string &fileName)
......
......@@ -28,6 +28,7 @@
#include "Core/Config.h"
#include "Simulators/ObjectSimulator.h"
#include "Core/ErrorLog.h"
#include "Core/Vector.h"
class ToolCoupler;
class VegaFemSceneObject;
......
......@@ -1005,13 +1005,6 @@ void VegaFemSceneObject::printInfo() const
std::cout << "\t-------------------------------------\n";
}
core::Vec3d VegaFemSceneObject::getVelocity(const int dofID) const
{
core::Vec3d vel(uvel[dofID], uvel[dofID + 1], uvel[dofID + 2]);
return vel;
}
core::Vec3d VegaFemSceneObject::getDisplacementOfNodeWithDofID(const int dofID) const
{
core::Vec3d disp(u[dofID], u[dofID + 1], u[dofID + 2]);
......
......@@ -150,10 +150,6 @@ public:
/// certain threshold and set it to be the pulled vertex
void setPulledVertex(const core::Vec3d &userPos);
/// \brief returns velocity given the
/// localtion in the global velocity vector
core::Vec3d getVelocity(const int dofID) const override;
/// \brief returns displacement given the
/// localtion in the global displacement vector
core::Vec3d getDisplacementOfNodeWithDofID(const int dofID) const;
......
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