-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First hollow class for mouse interaction using performer
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <sofa/igtlink/utils/iGTLinkMouseInteractor.inl> | ||
#include <sofa/core/ObjectFactory.h> | ||
|
||
namespace sofa::openigtlink { | ||
|
||
SOFA_DECL_CLASS(iGTLinkMouseInteractor) | ||
|
||
int iGTLinkMouseInteractorClass = core::RegisterObject("") | ||
.add<iGTLinkMouseInteractor>(true); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
#include <sofa/gui/component/config.h> | ||
|
||
#include <sofa/gui/component/performer/InteractionPerformer.h> | ||
#include <sofa/component/collision/geometry/RayModel.h> | ||
#include <sofa/component/statecontainer/MechanicalObject.h> | ||
|
||
#include <sofa/core/collision/DetectionOutput.h> | ||
#include <sofa/core/BehaviorModel.h> | ||
#include <sofa/gui/component/performer/MouseInteractor.h> | ||
#include <sofa/helper/OptionsGroup.h> | ||
#include <sofa/core/objectmodel/DataCallback.h> | ||
#include <chrono> | ||
|
||
|
||
namespace sofa::openigtlink { | ||
|
||
class iGTLinkMouseInteractor : public sofa::gui::component::performer::MouseInteractor<defaulttype::Vec3Types> { | ||
public: | ||
SOFA_CLASS(iGTLinkMouseInteractor, SOFA_TEMPLATE(sofa::gui::component::performer::MouseInteractor, defaulttype::Vec3Types)); | ||
|
||
Data<type::Vec3> d_positions; | ||
Data< sofa::helper::OptionsGroup > d_pickingType; | ||
Data< double > d_springStiffness; | ||
Data< unsigned > d_reactionTime; | ||
|
||
iGTLinkMouseInteractor(); | ||
|
||
void updatePosition( SReal dt) override; | ||
|
||
void positionChanged(); | ||
void attachmentChanged(); | ||
void handleEvent(sofa::core::objectmodel::Event *event); | ||
|
||
private: | ||
sofa::core::objectmodel::DataCallback c_positions; | ||
sofa::core::objectmodel::DataCallback c_attachmentType; | ||
std::chrono::high_resolution_clock::time_point m_lastChange; | ||
|
||
|
||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include <sofa/igtlink/utils/iGTLinkMouseInteractor.h> | ||
#include <sofa/simulation/AnimateBeginEvent.h> | ||
|
||
|
||
namespace sofa::openigtlink | ||
{ | ||
|
||
iGTLinkMouseInteractor::iGTLinkMouseInteractor() | ||
: d_pickingType(initData(&d_pickingType,"pickingType","Mouse interaction type, could be \'constraint\' or \'spring\'")) | ||
, d_positions(initData(&d_positions, "position", "Position")) | ||
, d_springStiffness(initData(&d_springStiffness,10.0,"springStiffness","Stiffness of attachment spring used for interaction")) | ||
, d_reactionTime(initData(&d_reactionTime,20u, "reactionTime", "Time in milisecond of no change in the position to output a null stiffness")) | ||
{ | ||
sofa::helper::OptionsGroup m_newoptiongroup{"constraint","spring"}; | ||
m_newoptiongroup.setSelectedItem("spring"); | ||
d_pickingType.setValue(m_newoptiongroup); | ||
|
||
this->f_listening.setValue(true); | ||
|
||
c_positions.addInput(&d_positions); | ||
c_positions.addCallback(std::bind(&iGTLinkMouseInteractor::positionChanged,this)); | ||
|
||
c_attachmentType.addInput(&d_pickingType); | ||
c_attachmentType.addCallback(std::bind(&iGTLinkMouseInteractor::attachmentChanged,this)); | ||
|
||
m_lastChange = std::chrono::high_resolution_clock::now(); | ||
//Make sure the constraint is inactive | ||
|
||
} | ||
|
||
|
||
void iGTLinkMouseInteractor::positionChanged() | ||
{ | ||
m_lastChange = std::chrono::high_resolution_clock::now(); | ||
} | ||
|
||
void iGTLinkMouseInteractor::attachmentChanged() | ||
{ | ||
//Change performer | ||
} | ||
|
||
|
||
void iGTLinkMouseInteractor::updatePosition( SReal dt) | ||
{ | ||
SOFA_UNUSED(dt); | ||
//Do nothing | ||
} | ||
|
||
|
||
void iGTLinkMouseInteractor::handleEvent(sofa::core::objectmodel::Event *event) | ||
{ | ||
if (dynamic_cast<sofa::simulation::AnimateBeginEvent*>(event)) | ||
{ | ||
std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); | ||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastChange).count() > d_reactionTime.getValue()) | ||
{ | ||
//Deactivate the constraint | ||
//Reproduce the start emthod from performer here. | ||
} | ||
else | ||
{ | ||
//Activate the constraint | ||
//Clear the performer | ||
} | ||
} | ||
} | ||
|
||
} |