Starting API adaption

parent db13fabd
......@@ -14,8 +14,8 @@
#include "VAMatlabConnection.h"
#include "VAMatlabTracking.h"
#include <VANetClient.h>
#include <VACore.h>
#include <VA.h>
#include <VANet.h>
CVAMatlabConnection::CVAMatlabConnection()
{
......
......@@ -18,7 +18,7 @@
#include <string>
#include <vector>
class IVACore;
class IVAInterface;
class CVAMatlabTracker;
class IVANetClient;
......@@ -27,7 +27,7 @@ class CVAMatlabConnection
{
public:
IVANetClient* pClient;
IVACore* pCoreInterface;
IVAInterface* pCoreInterface;
CVAMatlabTracker* pVAMatlabTracker;
CVAMatlabConnection();
......
This diff is collapsed.
......@@ -89,7 +89,7 @@ bool matlabGetBoolScalar( const mxArray* arg, const char* argname )
return ( *p == true );
}
if( mxIsNumeric( arg ) && !mxIsComplex( arg ) && matlabIsScalar( arg ) )
if( mxIsNumeric( arg ) && !mxIsComplex( arg ) && matlabIsScalar( arg ) )
{
void* p = mxGetData( arg );
......@@ -102,10 +102,9 @@ bool matlabGetBoolScalar( const mxArray* arg, const char* argname )
// Unsupported datatype
sprintf_s( buf, buflen, "Argument '%s' could not be interpreted as a logical scalar", argname );
VA_EXCEPT1( buf );
return false;
}
if( mxIsChar( arg ) && matlabIsRowVector( arg ) )
if( mxIsChar( arg ) && matlabIsRowVector( arg ) )
{
mxGetString( arg, buf, buflen );
std::string s( buf );
......@@ -122,8 +121,6 @@ bool matlabGetBoolScalar( const mxArray* arg, const char* argname )
sprintf_s( buf, buflen, "Argument '%s' must be a logical scalar", argname );
VA_EXCEPT1( buf );
return false;
}
int matlabGetIntegerScalar( const mxArray* arg, const char* argname )
......@@ -155,13 +152,10 @@ int matlabGetIntegerScalar( const mxArray* arg, const char* argname )
// Unsupported datatype
sprintf_s( buf, 1024, "Argument '%s' could not be interpreted as an integer scalar", argname );
VA_EXCEPT1( buf );
return -1;
}
sprintf_s( buf, 1024, "Argument '%s' must be an integer scalar", argname );
VA_EXCEPT1( buf );
return -1;
}
double matlabGetRealScalar( const mxArray* arg, const char* argname )
......@@ -185,13 +179,10 @@ double matlabGetRealScalar( const mxArray* arg, const char* argname )
// Unsupported datatype
sprintf_s( buf, 1024, "Argument '%s' could not be interpreted as a real-valued scalar", argname );
VA_EXCEPT1( buf );
return -1;
}
sprintf_s( buf, 1024, "Argument '%s' must be a real-valued scalar", argname );
VA_EXCEPT1( buf );
return -1;
}
void matlabGetRealVector3( const mxArray* arg, const char* argname, double& x, double& y, double& z )
......@@ -202,45 +193,45 @@ void matlabGetRealVector3( const mxArray* arg, const char* argname, double& x, d
if( mxIsNumeric( arg ) && !mxIsComplex( arg ) && matlabIsVector( arg, size ) )
if( size == 3 ) {
if( mxIsInt16( arg ) ) {
int16_t* p = ( int16_t* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsInt16( arg ) ) {
int16_t* p = ( int16_t* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsInt32( arg ) ) {
int32_t* p = ( int32_t* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsInt32( arg ) ) {
int32_t* p = ( int32_t* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsInt64( arg ) ) {
int64_t* p = ( int64_t* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsInt64( arg ) ) {
int64_t* p = ( int64_t* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsSingle( arg ) ) {
float* p = ( float* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsSingle( arg ) ) {
float* p = ( float* ) mxGetData( arg );
x = ( double ) p[ 0 ];
y = ( double ) p[ 1 ];
z = ( double ) p[ 2 ];
return;
}
if( mxIsDouble( arg ) ) {
double* p = ( double* ) mxGetData( arg );
x = p[ 0 ];
y = p[ 1 ];
z = p[ 2 ];
return;
}
if( mxIsDouble( arg ) ) {
double* p = ( double* ) mxGetData( arg );
x = p[ 0 ];
y = p[ 1 ];
z = p[ 2 ];
return;
}
}
sprintf_s( buf, 1024, "Argument '%s' must be a real-valued vector with exactly three elements", argname );
......@@ -330,7 +321,6 @@ std::string matlabGetString( const mxArray* arg, const char* argname )
sprintf_s( buf, 1024, "Argument '%s' must be a string", argname );
VA_EXCEPT1( buf );
return std::string();
}
mxArray* matlabCreateRealVector3( double x, double y, double z )
......@@ -343,7 +333,8 @@ mxArray* matlabCreateRealVector3( double x, double y, double z )
return p;
}
mxArray* matlabCreateID( int iID ) {
mxArray* matlabCreateID( int iID )
{
mwSize d[ 2 ] = { 1, 1 };
mxArray* p = mxCreateNumericArray( 2, d, mxINT32_CLASS, mxREAL );
*( ( int* ) mxGetData( p ) ) = iID;
......@@ -367,93 +358,27 @@ mxArray* matlabCreateIDList( const std::vector<int>& viID )
mxArray* matlabCreateDirectivityInfo( const CVADirectivityInfo& di )
{
/*
int iID; // ID
std::string sName; // Name (optional)
std::string sFilename; // Filename
double dAlphaResDEG; // Alpha resolution []
double dBetaResDEG; // Beta resolution []
int iReferences; // Number of references
// TODO: Auflsung usw.
*/
const mwSize nFields = 5;
const char* ppszFieldNames[] = { "id", "name", "filename", "description", "references" };
const char* ppszFieldNames[] = { "id", "name", "class", "description", "references" };
mxArray* pStruct = mxCreateStructMatrix( 1, 1, nFields, ppszFieldNames );
mxSetField( pStruct, 0, ppszFieldNames[ 0 ], matlabCreateID( di.iID ) );
mxSetField( pStruct, 0, ppszFieldNames[ 1 ], mxCreateString( di.sName.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 2 ], mxCreateString( di.sFilename.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 2 ], matlabCreateID( di.iClass ) );
mxSetField( pStruct, 0, ppszFieldNames[ 3 ], mxCreateString( di.sDesc.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 4 ], mxCreateDoubleScalar( di.iReferences ) ); // no of references as double-value in matlab
return pStruct;
}
mxArray* matlabCreateHRIRInfo( const CVAHRIRInfo& hriri )
mxArray* matlabCreateSignalSourceInfo( const CVASignalSourceInfo& ssi )
{
/*
int iID; // ID
std::string sName; // Name (optional)
std::string sFilename; // Filename
double dAlphaResDEG; // Alpha resolution []
double dBetaResDEG; // Beta resolution []
int iReferences; // Number of references
// TODO: More fields?
*/
const mwSize nFields = 5;
const char* ppszFieldNames[] = { "id", "name", "filename", "alphaResDeg", "betaResDeg", "references" };
mxArray* pStruct = mxCreateStructMatrix( 1, 1, nFields, ppszFieldNames );
mxSetField( pStruct, 0, ppszFieldNames[ 0 ], matlabCreateID( hriri.iID ) );
mxSetField( pStruct, 0, ppszFieldNames[ 1 ], mxCreateString( hriri.sName.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 2 ], mxCreateString( hriri.sFilename.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 3 ], mxCreateString( hriri.sDesc.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 4 ], mxCreateDoubleScalar( hriri.iReferences ) ); // no of references as double-value in matlab
return pStruct;
}
mxArray* matlabCreateSoundInfo( const CVASoundInfo& si )
{
/*
int iID; // ID
std::string sName; // Name (optional)
std::string sFilename; // Filename
int iLength; // Length [Samples]
double dDuration; // Duration [s]
*/
const mwSize nFields = 5;
const char* ppszFieldNames[] = { "id", "name", "filename", "nsamples", "duration" };
mxArray* pStruct = mxCreateStructMatrix( 1, 1, nFields, ppszFieldNames );
mxSetField( pStruct, 0, ppszFieldNames[ 0 ], matlabCreateID( si.iID ) );
mxSetField( pStruct, 0, ppszFieldNames[ 1 ], mxCreateString( si.sName.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 2 ], mxCreateString( si.sFilename.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 3 ], mxCreateDoubleScalar( si.iLength ) ); // Anzahl Samples als Double in Matlab
mxSetField( pStruct, 0, ppszFieldNames[ 4 ], mxCreateDoubleScalar( si.dDuration ) );
return pStruct;
}
mxArray* matlabCreateSignalSourceInfo( const CVASignalSourceInfo& ssi ) {
/*
std::string sID; // ID (z.B. "af1")
std::string sType; // Typ (Datei|Sampler|Gerte-Eingang|Netzwerkstream)
std::string sName; // Name (z.B. "Trompete 1")
std::string sDesc; // Beschreibung
std::string sState; // Zustandsbeschreibung
int iReferences; // Anzahl Referenzen
*/
const mwSize nFields = 6;
const char* ppszFieldNames[] = { "id", "type", "name", "description", "state", "references" };
mxArray* pStruct = mxCreateStructMatrix( 1, 1, nFields, ppszFieldNames );
mxSetField( pStruct, 0, ppszFieldNames[ 0 ], mxCreateString( ssi.sID.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 1 ], mxCreateString( ssi.sType.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 1 ], mxCreateDoubleScalar( ssi.iType ) );
mxSetField( pStruct, 0, ppszFieldNames[ 2 ], mxCreateString( ssi.sName.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 3 ], mxCreateString( ssi.sDesc.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 4 ], mxCreateString( ssi.sState.c_str() ) );
......@@ -465,19 +390,12 @@ mxArray* matlabCreateSignalSourceInfo( const CVASignalSourceInfo& ssi ) {
mxArray* matlabCreateSceneInfo( const CVASceneInfo& sci )
{
// TODO: Implementieren
/*
//std::string sName; // Name (optional)
//std::string sFilename; // Scene filename (e.g. RAVEN project file)
// TODO: More fields, num polygons, num portals, num rooms, etc.
*/
const mwSize nFields = 2;
const char* ppszFieldNames[] = { "name", "filename" };
const char* ppszFieldNames[] = { "id", "name" };
mxArray* pStruct = mxCreateStructMatrix( 1, 1, nFields, ppszFieldNames );
//mxSetField(pStruct, 0, ppszFieldNames[0], mxCreateString(sci.sName.c_str()));
//mxSetField(pStruct, 0, ppszFieldNames[1], mxCreateString(sci.sFilename.c_str()));
mxSetField( pStruct, 0, ppszFieldNames[ 0 ], mxCreateString( sci.sID.c_str() ) );
mxSetField( pStruct, 0, ppszFieldNames[ 0 ], mxCreateString( sci.sName.c_str() ) );
return pStruct;
}
......
......@@ -72,12 +72,6 @@ mxArray* matlabCreateIDList(const std::vector<int>& viID);
// CVADirectivityInfo in Matlab struct konvertieren
mxArray* matlabCreateDirectivityInfo(const CVADirectivityInfo& di);
// CVAHRIRInfo in Matlab struct konvertieren
mxArray* matlabCreateHRIRInfo(const CVAHRIRInfo& hriri);
// CVASoundInfo in Matlab struct konvertieren
mxArray* matlabCreateSoundInfo(const CVASoundInfo& si);
// CVASignalSourceInfo in Matlab struct konvertieren
mxArray* matlabCreateSignalSourceInfo(const CVASignalSourceInfo& ssi);
......
......@@ -14,8 +14,7 @@
#include "VAMatlabTracking.h"
#include "VAMatlabConnection.h"
#include <VACore.h>
#include <VAException.h>
#include <VA.h>
// NatNet includes
#include <NatNetTypes.h>
......@@ -29,22 +28,22 @@ void TrackerDataHandler( sFrameOfMocapData* sFrame, void* pUserData )
if( !pVAMatlabTracker )
return;
IVACore* pVACore = pVAMatlabTracker->pVACore;
IVAInterface* pVACore = pVAMatlabTracker->pVACore;
if( !pVACore )
return;
// Listener
int iTrackedListenerID = pVAMatlabTracker->iTrackedListenerID;
int iTrackedListenerRigidBodyIndex = pVAMatlabTracker->iTrackedListenerRigidBodyIndex;
int iTrackedReceiverID = pVAMatlabTracker->iTrackedListenerID;
int iTrackedReceiverRigidBodyIndex = pVAMatlabTracker->iTrackedListenerRigidBodyIndex;
if( ( iTrackedListenerID != -1 ) && ( iTrackedListenerRigidBodyIndex <= sFrame->nRigidBodies ) && ( iTrackedListenerRigidBodyIndex > 0 ) )
if( ( iTrackedReceiverID != -1 ) && ( iTrackedReceiverRigidBodyIndex <= sFrame->nRigidBodies ) && ( iTrackedReceiverRigidBodyIndex > 0 ) )
{
try
{
VistaVector3D vPosOffsetLocalCoordinateSystem = pVAMatlabTracker->vTrackedListenerTranslation;
VistaQuaternion qOrientRotation = pVAMatlabTracker->qTrackedListenerRotation;
const sRigidBodyData& oBodyData( sFrame->RigidBodies[ iTrackedListenerRigidBodyIndex - 1 ] );
const sRigidBodyData& oBodyData( sFrame->RigidBodies[ iTrackedReceiverRigidBodyIndex - 1 ] );
VistaVector3D vPosPivotPoint( oBodyData.x, oBodyData.y, oBodyData.z );
VistaQuaternion qOrientRaw( oBodyData.qx, oBodyData.qy, oBodyData.qz, oBodyData.qw );
......@@ -55,8 +54,8 @@ void TrackerDataHandler( sFrameOfMocapData* sFrame, void* pUserData )
VistaVector3D vPosOffsetGlobalCoordinateSystem = qOrientRigidBody.Rotate( vPosOffsetLocalCoordinateSystem );
VistaVector3D vPosRigidBody = vPosPivotPoint + vPosOffsetGlobalCoordinateSystem;
pVACore->SetListenerPosition( iTrackedListenerID, vPosRigidBody[ 0 ], vPosRigidBody[ 1 ], vPosRigidBody[ 2 ] );
pVACore->SetListenerOrientationVU( iTrackedListenerID, vViewRigidBody[ 0 ], vViewRigidBody[ 1 ], vViewRigidBody[ 2 ], vUpRigidBody[ 0 ], vUpRigidBody[ 1 ], vUpRigidBody[ 2 ] );
pVACore->SetSoundReceiverPosition( iTrackedReceiverID, VAVec3( vPosRigidBody[ 0 ], vPosRigidBody[ 1 ], vPosRigidBody[ 2 ] ) );
pVACore->SetSoundReceiverOrientationVU( iTrackedReceiverID, VAVec3( vViewRigidBody[ 0 ], vViewRigidBody[ 1 ], vViewRigidBody[ 2 ] ), VAVec3( vUpRigidBody[ 0 ], vUpRigidBody[ 1 ], vUpRigidBody[ 2 ] ) );
}
catch( ... )
{
......@@ -64,10 +63,10 @@ void TrackerDataHandler( sFrameOfMocapData* sFrame, void* pUserData )
}
// Real-world listener
int iTrackedRealWorldListenerID = pVAMatlabTracker->iTrackedRealWorldListenerID;
int iTrackedRealWorldSoundReceiverID = pVAMatlabTracker->iTrackedRealWorldListenerID;
int iTrackedRealWorldListenerRigidBodyIndex = pVAMatlabTracker->iTrackedRealWorldListenerRigidBodyIndex;
if( ( iTrackedRealWorldListenerID != -1 ) && ( iTrackedRealWorldListenerRigidBodyIndex <= sFrame->nRigidBodies ) && ( iTrackedRealWorldListenerRigidBodyIndex > 0 ) )
if( ( iTrackedRealWorldSoundReceiverID != -1 ) && ( iTrackedRealWorldListenerRigidBodyIndex <= sFrame->nRigidBodies ) && ( iTrackedRealWorldListenerRigidBodyIndex > 0 ) )
{
try
{
......@@ -85,7 +84,7 @@ void TrackerDataHandler( sFrameOfMocapData* sFrame, void* pUserData )
VistaVector3D vPosOffsetGlobalCoordinateSystem = qOrientRigidBody.Rotate( vPosOffsetLocalCoordinateSystem );
VistaVector3D vPosRigidBody = vPosPivotPoint + vPosOffsetGlobalCoordinateSystem;
pVACore->SetListenerRealWorldHeadPositionOrientationVU( iTrackedRealWorldListenerID, vPosRigidBody[ 0 ], vPosRigidBody[ 1 ], vPosRigidBody[ 2 ], vViewRigidBody[ 0 ], vViewRigidBody[ 1 ], vViewRigidBody[ 2 ], vUpRigidBody[ 0 ], vUpRigidBody[ 1 ], vUpRigidBody[ 2 ] );
pVACore->SetSoundReceiverRealWorldPositionOrientationVU( iTrackedRealWorldSoundReceiverID, VAVec3( vPosRigidBody[ 0 ], vPosRigidBody[ 1 ], vPosRigidBody[ 2 ] ), VAVec3( vViewRigidBody[ 0 ], vViewRigidBody[ 1 ], vViewRigidBody[ 2 ] ), VAVec3( vUpRigidBody[ 0 ], vUpRigidBody[ 1 ], vUpRigidBody[ 2 ] ) );
}
catch( ... )
{
......@@ -114,8 +113,8 @@ void TrackerDataHandler( sFrameOfMocapData* sFrame, void* pUserData )
VistaVector3D vPosOffsetGlobalCoordinateSystem = qOrientRigidBody.Rotate( vPosOffsetLocalCoordinateSystem );
VistaVector3D vPosRigidBody = vPosPivotPoint + vPosOffsetGlobalCoordinateSystem;
pVACore->SetSoundSourcePosition( iTrackedSourceID, vPosRigidBody[ 0 ], vPosRigidBody[ 1 ], vPosRigidBody[ 2 ] );
pVACore->SetSoundSourceOrientationVU( iTrackedSourceID, vViewRigidBody[ 0 ], vViewRigidBody[ 1 ], vViewRigidBody[ 2 ], vUpRigidBody[ 0 ], vUpRigidBody[ 1 ], vUpRigidBody[ 2 ] );
pVACore->SetSoundSourcePosition( iTrackedSourceID, VAVec3( vPosRigidBody[ 0 ], vPosRigidBody[ 1 ], vPosRigidBody[ 2 ] ) );
pVACore->SetSoundSourceOrientationVU( iTrackedSourceID, VAVec3( vViewRigidBody[ 0 ], vViewRigidBody[ 1 ], vViewRigidBody[ 2 ] ), VAVec3( vUpRigidBody[ 0 ], vUpRigidBody[ 1 ], vUpRigidBody[ 2 ] ) );
}
catch( ... )
{
......
......@@ -23,7 +23,7 @@
#include <VistaBase/VistaQuaternion.h>
class NatNetClient;
class IVACore;
class IVAInterface;
//! Wrapper class for NatNet tracking client
class CVAMatlabTracker
......@@ -35,7 +35,7 @@ public:
bool Uninitialize();
bool IsConnected() const;
IVACore* pVACore; //!< Pointer to (networked) core instance
IVAInterface* pVACore; //!< Pointer to (networked) core instance
int iTrackedListenerID; //!< -1 if deactivated, will be preferred over source
int iTrackedListenerRigidBodyIndex; //!< Starts with 1 (default)
......
Markdown is supported
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