devices/deviceopticalhybrid/ordeviceopticalhybrid_hardware.h

devices/deviceopticalhybrid/ordeviceopticalhybrid_hardware.h
#ifndef __ORDEVICE_OPTICAL_HARDWARE_H__
#define __ORDEVICE_OPTICAL_HARDWARE_H__
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Maximum number of markers detected.
#define MAX_MARKER 100
//--- SDK include
#include <fbsdk/fbsdk.h>
// Port number to use for server
const int PORTNUMBER = 8889; // Port number for communication
const int SIM_FPS = 60; // Tested for 30,60,120
const int ChannelCount = 30;
#if defined( WIN32 )
typedef unsigned __int64 nsTime;
#else
typedef unsigned long long nsTime;
#endif
struct sSkDataBuffer
{
nsTime mTime;
int mCounter;
struct
{
double mT[3];
double mR[3];
} mChannel[ChannelCount];
sSkDataBuffer()
{
mTime = 0;
mCounter = 0;
}
void Simulate(nsTime pTime)
{
mTime = pTime;
// Send last data + 0.5 degree global rotation in the Y direction
FBMatrix lTransformation, lChannelTransformation;
FBRotationToMatrix(lTransformation,FBRVector(0,0.5,0));
for(int i = 0; i < ChannelCount; i++)
{
FBRotationToMatrix(lChannelTransformation, mChannel[i].mR);
memcpy(&lChannelTransformation[12], mChannel[i].mT,sizeof(mChannel[i].mT));
FBMatrixMult(lChannelTransformation,lTransformation,lChannelTransformation);
FBMatrixToRotation((FBRVector&)*mChannel[i].mR,lChannelTransformation);
memcpy(&mChannel[i].mT,&lChannelTransformation[12],sizeof(mChannel[i].mT));
}
mCounter++;
}
void SetupBuffer()
{
//0:Hips
mChannel[0].mT[0] = 5.52507944791e-15;
mChannel[0].mT[1] = 90.2313919067;
mChannel[0].mT[2] = 0.0;
mChannel[0].mR[0] = 0.0;
mChannel[0].mR[1] = 0.0;
mChannel[0].mR[2] = 0.0;
//1:LeftUpLeg
mChannel[1].mT[0] = 10.8919000626;
mChannel[1].mT[1] = 90.2313919067;
mChannel[1].mT[2] = 0.0;
mChannel[1].mR[0] = 0.0;
mChannel[1].mR[1] = 0.0;
mChannel[1].mR[2] = 0.0;
//2:LeftLeg
mChannel[2].mT[0] = 10.8919000626;
mChannel[2].mT[1] = 46.1967926025;
mChannel[2].mT[2] = 0.0;
mChannel[2].mR[0] = 0.0;
mChannel[2].mR[1] = 0.0;
mChannel[2].mR[2] = 0.0;
//3:LeftFoot
mChannel[3].mT[0] = 10.8919000626;
mChannel[3].mT[1] = 4.74909210205;
mChannel[3].mT[2] = 0.0;
mChannel[3].mR[0] = 14.9999777807;
mChannel[3].mR[1] = 0.0;
mChannel[3].mR[2] = 0.0;
//4:LeftToeBase
mChannel[4].mT[0] = 10.8919000626;
mChannel[4].mT[1] = 1.05947666894;
mChannel[4].mT[2] = 13.7698536165;
mChannel[4].mR[0] = 0.0;
mChannel[4].mR[1] = 0.0;
mChannel[4].mR[2] = 0.0;
//5:L_Toe_End
mChannel[5].mT[0] = 10.8919000626;
mChannel[5].mT[1] = 1.05947666894;
mChannel[5].mT[2] = 21.2698536165;
mChannel[5].mR[0] = 0.0;
mChannel[5].mR[1] = 0.0;
mChannel[5].mR[2] = 0.0;
//6:RightUpLeg
mChannel[6].mT[0] = -10.8919000626;
mChannel[6].mT[1] = 90.2313919067;
mChannel[6].mT[2] = 0.0;
mChannel[6].mR[0] = 0.0;
mChannel[6].mR[1] = 0.0;
mChannel[6].mR[2] = 0.0;
//7:RightLeg
mChannel[7].mT[0] = -10.8919000626;
mChannel[7].mT[1] = 46.1967926025;
mChannel[7].mT[2] = 0.0;
mChannel[7].mR[0] = 0.0;
mChannel[7].mR[1] = 0.0;
mChannel[7].mR[2] = 0.0;
//8:RightFoot
mChannel[8].mT[0] = -10.8919000626;
mChannel[8].mT[1] = 4.74909210205;
mChannel[8].mT[2] = 0.0;
mChannel[8].mR[0] = 14.9999777807;
mChannel[8].mR[1] = 0.0;
mChannel[8].mR[2] = 0.0;
//9:RightToeBase
mChannel[9].mT[0] = -10.8919000626;
mChannel[9].mT[1] = 1.05947666894;
mChannel[9].mT[2] = 13.7698536165;
mChannel[9].mR[0] = 0.0;
mChannel[9].mR[1] = 0.0;
mChannel[9].mR[2] = 0.0;
//10:R_Toe_End
mChannel[10].mT[0] = -10.8919000626;
mChannel[10].mT[1] = 1.05947666894;
mChannel[10].mT[2] = 21.2698536165;
mChannel[10].mR[0] = 0.0;
mChannel[10].mR[1] = 0.0;
mChannel[10].mR[2] = 0.0;
//11:Spine
mChannel[11].mT[0] = 5.52507944791e-15;
mChannel[11].mT[1] = 90.3313919082;
mChannel[11].mT[2] = 0.0;
mChannel[11].mR[0] = 0.0;
mChannel[11].mR[1] = 0.0;
mChannel[11].mR[2] = 0.0;
//12:Spine1
mChannel[12].mT[0] = 5.52507944791e-15;
mChannel[12].mT[1] = 109.028892137;
mChannel[12].mT[2] = 0.0;
mChannel[12].mR[0] = 0.0;
mChannel[12].mR[1] = 0.0;
mChannel[12].mR[2] = 0.0;
//13:Neck
mChannel[13].mT[0] = 5.52507944791e-15;
mChannel[13].mT[1] = 133.325692751;
mChannel[13].mT[2] = 0.0;
mChannel[13].mR[0] = 0.0;
mChannel[13].mR[1] = 0.0;
mChannel[13].mR[2] = 0.0;
//14:Head
mChannel[14].mT[0] = 5.52507944791e-15;
mChannel[14].mT[1] = 145.887693025;
mChannel[14].mT[2] = 0.0;
mChannel[14].mR[0] = 0.0;
mChannel[14].mR[1] = 0.0;
mChannel[14].mR[2] = 0.0;
//15:Head_End
mChannel[15].mT[0] = 5.52507944791e-15;
mChannel[15].mT[1] = 157.387693025;
mChannel[15].mT[2] = 0.0;
mChannel[15].mR[0] = 0.0;
mChannel[15].mR[1] = 0.0;
mChannel[15].mR[2] = 0.0;
//16:LeftShoulder
mChannel[16].mT[0] = 5.52507944791e-15;
mChannel[16].mT[1] = 133.325692751;
mChannel[16].mT[2] = 0.0;
mChannel[16].mR[0] = 0.0;
mChannel[16].mR[1] = 0.0;
mChannel[16].mR[2] = -90.0002104591;
//17:LeftArm
mChannel[17].mT[0] = 21.7077007292;
mChannel[17].mT[1] = 133.325613014;
mChannel[17].mT[2] = 0.0;
mChannel[17].mR[0] = 0.0;
mChannel[17].mR[1] = 0.0;
mChannel[17].mR[2] = -90.0002104591;
//18:LeftForeArm
mChannel[18].mT[0] = 48.0103015896;
mChannel[18].mT[1] = 133.325516399;
mChannel[18].mT[2] = 0.0;
mChannel[18].mR[0] = 0.0;
mChannel[18].mR[1] = 0.0;
mChannel[18].mR[2] = -90.0002104591;
//19:LeftHand
mChannel[19].mT[0] = 75.5387020106;
mChannel[19].mT[1] = 133.325415281;
mChannel[19].mT[2] = 0.0;
mChannel[19].mR[0] = 0.0;
mChannel[19].mR[1] = 0.0;
mChannel[19].mR[2] = -90.0002104591;
//20:LeftHandThumb
mChannel[20].mT[0] = 75.5387020106;
mChannel[20].mT[1] = 133.325415281;
mChannel[20].mT[2] = 0.0;
mChannel[20].mR[0] = 0.0;
mChannel[20].mR[1] = 0.0;
mChannel[20].mR[2] = -90.0002104591;
//21:L_Thumb_End
mChannel[21].mT[0] = 75.5387020106;
mChannel[21].mT[1] = 133.325415281;
mChannel[21].mT[2] = 10.0;
mChannel[21].mR[0] = 0.0;
mChannel[21].mR[1] = 0.0;
mChannel[21].mR[2] = -90.0002104591;
//22:L_Wrist_End
mChannel[22].mT[0] = 85.5387020105;
mChannel[22].mT[1] = 133.325378549;
mChannel[22].mT[2] = 0.0;
mChannel[22].mR[0] = 0.0;
mChannel[22].mR[1] = 0.0;
mChannel[22].mR[2] = -90.0002104591;
//23:RightShoulder
mChannel[23].mT[0] = 5.52507944791e-15;
mChannel[23].mT[1] = 133.325692751;
mChannel[23].mT[2] = 0.0;
mChannel[23].mR[0] = 0.0;
mChannel[23].mR[1] = 0.0;
mChannel[23].mR[2] = 90.0002104591;
//24:RightArm
mChannel[24].mT[0] = -21.7077007292;
mChannel[24].mT[1] = 133.325613014;
mChannel[24].mT[2] = 0.0;
mChannel[24].mR[0] = 0.0;
mChannel[24].mR[1] = 0.0;
mChannel[24].mR[2] = 90.0002104591;
//25:RightForeArm
mChannel[25].mT[0] = -48.0103015896;
mChannel[25].mT[1] = 133.325516399;
mChannel[25].mT[2] = 0.0;
mChannel[25].mR[0] = 0.0;
mChannel[25].mR[1] = 0.0;
mChannel[25].mR[2] = 90.0002104591;
//26:RightHand
mChannel[26].mT[0] = -75.5387020106;
mChannel[26].mT[1] = 133.325415281;
mChannel[26].mT[2] = 0.0;
mChannel[26].mR[0] = 0.0;
mChannel[26].mR[1] = 0.0;
mChannel[26].mR[2] = 90.0002104591;
//27:RightHandThumb
mChannel[27].mT[0] = -75.5387020106;
mChannel[27].mT[1] = 133.325415281;
mChannel[27].mT[2] = 0.0;
mChannel[27].mR[0] = 0.0;
mChannel[27].mR[1] = 0.0;
mChannel[27].mR[2] = 90.0002104591;
//28:R_Thumb_End
mChannel[28].mT[0] = -75.5387020106;
mChannel[28].mT[1] = 133.325415281;
mChannel[28].mT[2] = 10.0;
mChannel[28].mR[0] = 0.0;
mChannel[28].mR[1] = 0.0;
mChannel[28].mR[2] = 90.0002104591;
//29:R_Wrist_End
mChannel[29].mT[0] = -89.2387018198;
mChannel[29].mT[1] = 133.325364958;
mChannel[29].mT[2] = 0.0;
mChannel[29].mR[0] = 0.0;
mChannel[29].mR[1] = 0.0;
mChannel[29].mR[2] = 90.0002104591;
}
};
struct sOpDataBuffer
{
nsTime mTime;
int mCounter;
double mMarkerData[4][4];
sOpDataBuffer()
{
mTime = 0;
mCounter = 0;
}
void Simulate(nsTime pTime)
{
mTime = pTime;
for(int i=0;i<4;i++)
{
mMarkerData[i][3] = 0.0; //Occlusion
}
double a = 10.0;
int b = (int)(mTime/10000000);
mMarkerData[0][0] = (double)(b%300)-150;
mMarkerData[0][1] = 0.0;
mMarkerData[0][2] = 0.0;
mMarkerData[1][0] = mMarkerData[0][0] + a;
mMarkerData[1][1] = 0.0;
mMarkerData[1][2] = 0.0;
mMarkerData[2][0] = mMarkerData[0][0];
mMarkerData[2][1] = a;
mMarkerData[2][2] = 0.0;
mMarkerData[3][0] = mMarkerData[0][0];
mMarkerData[3][1] = 0.0;
mMarkerData[3][2] = a;
// Simulate an occlusion
if(mMarkerData[0][0] > 0.0 && mMarkerData[0][0] < 50.0)
{
mMarkerData[0][0] = 0.0;
mMarkerData[0][1] = 20.0;
mMarkerData[0][2] = 0.0;
mMarkerData[0][3] = 1.0;
}
mCounter++;
}
};
class ORDeviceOpticalHybrid_Template_Hardware
{
public:
//--- Constructor & destructor
ORDeviceOpticalHybrid_Template_Hardware();
~ORDeviceOpticalHybrid_Template_Hardware();
//--- Client/server calls
// Opens and closes connection with data server. returns true if successful
bool Open();
bool Close();
bool GetSetupInfo();
// Streaming functions
// Once connection is established and information packets have been received
// these functions start and stops the data streaming
bool StartDataStream();
bool StopDataStream();
void ResetPacketTimeOffset(FBTime &pTime);
bool FetchDataPacket(FBTime &pTime);
//--- Attribute management
void SetNetworkUse(bool pUse) { mNetworkUse = pUse; }
bool GetNetworkUse() { return mNetworkUse; }
void SetNetworkAddress (const char *pIPAddress){ mNetworkAddress = pIPAddress; }
const char* GetNetworkAddress () { return mNetworkAddress; }
void SetNetworkPort (int pPort) { mNetworkPort = pPort; }
int GetNetworkPort () { return mNetworkPort; }
const char* GetMarkerName (int pMarkerIndex) { return mMarkerName[pMarkerIndex]; }
int GetMarkerCount () { return mMarkerCount; }
//--- Device data
double GetDataX (int pMarker) { return mOpDataBuffer.mMarkerData[pMarker][0]; }
double GetDataY (int pMarker) { return mOpDataBuffer.mMarkerData[pMarker][1]; }
double GetDataZ (int pMarker) { return mOpDataBuffer.mMarkerData[pMarker][2]; }
double GetDataO (int pMarker) { return mOpDataBuffer.mMarkerData[pMarker][3]; }
int GetChannelCount () { return mChannelCount; }
const char* GetChannelName (int pChannel) { return mChannel[pChannel].mName; }
int GetChannelParent(int pChannel) { return mChannel[pChannel].mParentChannel; }
FBVector3d GetDefaultT (int pChannel) { SkeletonNodeInfo& lSI = mChannel[pChannel]; return FBVector3d(lSI.mDefaultT[0],lSI.mDefaultT[1],lSI.mDefaultT[2]); }
FBVector3d GetDefaultR (int pChannel) { SkeletonNodeInfo& lSI = mChannel[pChannel]; return FBVector3d(lSI.mDefaultR[0],lSI.mDefaultR[1],lSI.mDefaultR[2]); }
double GetDataTX (int pChannel) { return mChannel[pChannel].mT[0]; }
double GetDataTY (int pChannel) { return mChannel[pChannel].mT[1]; }
double GetDataTZ (int pChannel) { return mChannel[pChannel].mT[2]; }
double GetDataRX (int pChannel) { return mChannel[pChannel].mR[0]; }
double GetDataRY (int pChannel) { return mChannel[pChannel].mR[1]; }
double GetDataRZ (int pChannel) { return mChannel[pChannel].mR[2]; }
private:
FBString mMarkerName[MAX_MARKER];
sOpDataBuffer mOpDataBuffer;
int mMarkerCount;
struct SkeletonNodeInfo
{
const char* mName;
int mParentChannel;
double mDefaultT[3];
double mDefaultR[3];
double mT[3];
double mR[3];
};
SkeletonNodeInfo mChannel[ChannelCount];
int mChannelCount;
sSkDataBuffer mSkDataBuffer;
nsTime mPacketTimeOffset;
FBTime mStartRecordingTime;
FBTime mLastSimulationTime;
int mPassCount;
bool mNetworkUse;
FBString mNetworkAddress;
int mNetworkPort;
FBSystem mSystem;
int mSocket;
FBTCPIP mTCP;
};
#endif /* __ORDEVICE_OPTICAL_HARDWARE_H__ */