imstkVRPNDeviceClient.h 3.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*=========================================================================

   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.

20
=========================================================================*/
21

22
#pragma once
23 24 25 26

#include <map>

#include "imstkDeviceClient.h"
27
#include "imstkModule.h"
28

29 30
#include <memory>

31 32 33 34 35 36
#include <vrpn_Configure.h>
#include <vrpn_Tracker.h>
#include <vrpn_Analog.h>
#include <vrpn_Button.h>
#include <vrpn_ForceDevice.h>

37 38
namespace imstk
{
39 40 41 42
///
/// \class VRPNDeviceClient
/// \brief Subclass of DeviceClient using VRPN
///
43
class VRPNDeviceClient : public DeviceClient, public Module
44 45 46
{
public:

47 48 49
    ///
    /// \brief Constructor
    ///
50
    VRPNDeviceClient(std::string deviceName, std::string ip) :
51
        DeviceClient(deviceName, ip),
52
        Module(deviceName + "@" + ip)
53 54
    {}

55 56 57 58 59
    ///
    /// \brief Destructor
    ///
    virtual ~VRPNDeviceClient()
    {}
60 61

protected:
62 63 64
    ///
    /// \brief Initialize device client module
    ///
65
    void initModule() override;
66 67 68 69

    ///
    /// \brief Run the device client
    ///
70
    void runModule() override;
71 72 73 74

    ///
    /// \brief Clean the device client module
    ///
75 76 77 78 79 80 81 82 83 84 85
    void cleanUpModule() override;

private:

    ///
    /// \brief VRPN call back for position and orientation data
    /// \param userData Pointer to this to allow updating
    /// internal data
    /// \param b VRPN callback structure containing new position and
    /// orientation data
    ///
86
    static void VRPN_CALLBACK trackerChangeHandler(void* userData, const _vrpn_TRACKERCB t);
87 88 89 90 91 92 93 94

    ///
    /// \brief VRPN call back for position and orientation data
    /// \param userData Pointer to this to allow updating
    /// internal data
    /// \param b VRPN callback structure containing new position and
    /// orientation data
    ///
95
    static void VRPN_CALLBACK analogChangeHandler(void* userData, const _vrpn_ANALOGCB a);
96 97 98 99 100 101 102 103

    ///
    /// \brief VRPN call back for velocity data
    /// \param userData Pointer to this to allow updating
    /// internal data
    /// \param v VRPN callback structure containing new position and
    /// orientation data
    ///
104
    static void VRPN_CALLBACK velocityChangeHandler(void* userData, const _vrpn_TRACKERVELCB v);
105 106 107 108 109 110 111

    ///
    /// \brief VRPN call back for button changed (pressed or released)
    /// \param userData Pointer to this to allow updating
    /// internal data
    /// \param b VRPN callback structure containing new button data
    ///
112
    static void VRPN_CALLBACK buttonChangeHandler(void* userData, const _vrpn_BUTTONCB b);
113 114 115 116 117 118 119

    ///
    /// \brief VRPN call back for force data
    /// \param userData Pointer to this to allow updating
    /// internal data
    /// \param f VRPN callback structure containing new force data
    ///
120
    static void VRPN_CALLBACK forceChangeHandler(void* userData, const _vrpn_FORCECB f);
121

122 123 124
    std::shared_ptr<vrpn_Tracker_Remote>     m_vrpnTracker;     //!< VRPN position/orientation interface
    std::shared_ptr<vrpn_Analog_Remote>      m_vrpnAnalog;      //!< VRPN position/orientation interface
    std::shared_ptr<vrpn_Button_Remote>      m_vrpnButton;      //!< VRPN button interface
125 126 127
    std::shared_ptr<vrpn_ForceDevice_Remote> m_vrpnForceDevice; //!< VRPN force interface
};
}