Exchange Toolkit
ExchangeEigenBridge.h
1 #pragma once
2 
3 #include <Eigen/Dense>
4 #include "ExchangeToolkit.h"
5 
6 namespace ts3d {
10  using MatrixType = Eigen::Matrix4d;
11 
15  using VectorType = Eigen::Vector4d;
16 
20  using PositionType = Eigen::Vector4d;
21 
25  static inline VectorType getVector( A3DVector3dData const &vec ) {
26  return ts3d::VectorType( vec.m_dX, vec.m_dY, vec.m_dZ, 0. );
27  }
28 
32  static inline A3DVector3dData getExchangeVector( Eigen::Vector4d const &vec ) {
33  A3DVector3dData result;
34  A3D_INITIALIZE_DATA( A3DVector3dData, result );
35  result.m_dX = vec(0);
36  result.m_dY = vec(1);
37  result.m_dZ = vec(2);
38  return result;
39  }
40 
44  static inline PositionType getPosition( A3DVector3dData const &vec ) {
45  return ts3d::PositionType( vec.m_dX, vec.m_dY, vec.m_dZ, 1. );
46  }
47 }
48 
49 
50 namespace {
51  static inline ts3d::MatrixType getMatrixFromCartesian( A3DMiscCartesianTransformation *xform ) {
53  auto const mirror = (d->m_ucBehaviour & kA3DTransformationMirror) ? -1. : 1.;
54  auto const s = ts3d::getVector( d->m_sScale );
55  auto const o = ts3d::getPosition( d->m_sOrigin );
56  auto const x = ts3d::getVector( d->m_sXVector );
57  auto const y = ts3d::getVector( d->m_sYVector );
58  auto const z = x.cross3( y ) * mirror;
59 
60  ts3d::MatrixType result;
61  for(auto idx = 0u; idx < 4u; idx++) {
62  result( idx, 0 ) = x( idx ) * s( 0 );
63  result( idx, 1 ) = y( idx ) * s( 1 );
64  result( idx, 2 ) = z( idx ) * s( 2 );
65  result( idx, 3 ) = o( idx );
66  }
67 
68  return result;
69  }
70 
71  static inline ts3d::MatrixType getMatrixFromGeneralTransformation( A3DMiscGeneralTransformation *xform ) {
73 
74  auto const coeff = d->m_adCoeff;
75  ts3d::MatrixType result;
76  for(auto idx = 0u; idx < 16; ++idx) {
77  result( idx ) = coeff[idx];
78  }
79  return result;
80  }
81 
82 }
83 
84 
85 
86 namespace ts3d {
91  static inline MatrixType getMatrix( A3DMiscTransformation *xform ) {
92  if(nullptr == xform) {
93  return ts3d::MatrixType::Identity();
94  }
95 
96  auto t = kA3DTypeUnknown;
97  A3DEntityGetType( xform, &t );
98 
99  switch(t) {
100  case kA3DTypeMiscCartesianTransformation:
101  return getMatrixFromCartesian( xform );
102  break;
103  case kA3DTypeMiscGeneralTransformation:
104  break;
105  return getMatrixFromGeneralTransformation( xform );
106  default:
107  throw std::invalid_argument( "Unexpected argument type provided" );
108  break;
109  }
110  return ts3d::MatrixType::Identity();
111  }
112 
116  static inline MatrixType getMatrix( ts3d::Instance const &i ) {
117  auto const leaf_type = i.leafType();
118  if( kA3DTypeAsmProductOccurrence == leaf_type ) {
119  return ts3d::getMatrix( getLocation( i.leaf() ) );
120  } else if( isRepresentationItem( leaf_type ) ) {
122  A3DRiCoordinateSystemWrapper csw( d->m_pCoordinateSystem );
123  return ts3d::getMatrix( csw->m_pTransformation );
124  }
125  return MatrixType::Identity();
126  }
127 
136  static inline MatrixType getNetMatrix( ts3d::Instance const &i ) {
137  if(i.path().size() > 1) {
138  return getNetMatrix( i.owner() ) * getMatrix( i );
139  }
140  return getMatrix( i );
141  }
142 }
static VectorType getVector(A3DVector3dData const &vec)
Use this function to obtain a vector to be used with the matrix.
Definition: ExchangeEigenBridge.h:25
Eigen::Vector4d VectorType
Alias for a 4d vector type.
Definition: ExchangeEigenBridge.h:15
A3DEEntityType leafType(void) const
Gets the type of the leaf entity.
Definition: ExchangeToolkit.h:1733
InstancePath const & path(void) const
Gets the InstancePath this Instance references.
Definition: ExchangeToolkit.h:1693
static bool isRepresentationItem(A3DEEntityType const &t)
Check if type is Ri or derived Ri type.
Definition: ExchangeToolkit.h:832
static MatrixType getMatrix(A3DMiscTransformation *xform)
This function returns a matrix corresponding to the A3DMiscTranslformation. Both general and cartesia...
Definition: ExchangeEigenBridge.h:91
Instance owner(void) const
Gets an Instance object for the parent.
Definition: ExchangeToolkit.h:1699
An instance should be thought of as a specific path through the Exchange product structure to a parti...
Definition: ExchangeToolkit.h:1630
The ts3d namespace is used to contain all Exchange Toolkit functionality.
Definition: ExchangeEigenBridge.h:6
Provides a wrapper for accessing A3DRiRepresentationItemData.
Definition: ExchangeToolkit.h:736
static MatrixType getNetMatrix(ts3d::Instance const &i)
Gets the net matrix for a given instance.The matrix of each entry in the instance path is obtained an...
Definition: ExchangeEigenBridge.h:136
Eigen::Matrix4d MatrixType
Alias for a 4x4 matrix type.
Definition: ExchangeEigenBridge.h:10
static PositionType getPosition(A3DVector3dData const &vec)
Use this function to obtain a direction.
Definition: ExchangeEigenBridge.h:44
Provides a wrapper for accessing A3DMiscGeneralTransformationData.
Definition: ExchangeToolkit.h:716
static A3DVector3dData getExchangeVector(Eigen::Vector4d const &vec)
Use this function to obtain and Exchange Vector from an Eigen vector/position.
Definition: ExchangeEigenBridge.h:32
Eigen::Vector4d PositionType
Alias for a 4d position type.
Definition: ExchangeEigenBridge.h:20
Provides a wrapper for accessing A3DRiCoordinateSystemData.
Definition: ExchangeToolkit.h:729
A3DEntity * leaf(void) const
Gets the leaf entity pointer.
Definition: ExchangeToolkit.h:1727
Provides a wrapper for accessing A3DMiscCartesianTransformationData.
Definition: ExchangeToolkit.h:713