00001
00055 #define _EXPORT_CCL_
00056
00057 #include "CigiViewDefV2.h"
00058 #include "CigiSwapping.h"
00059 #include "CigiExceptions.h"
00060
00061 #include <memory.h>
00062
00063 #ifdef CIGI_LITTLE_ENDIAN
00064 #define CIGI_SCOPY2 CigiSwap2
00065 #define CIGI_SCOPY4 CigiSwap4
00066 #define CIGI_SCOPY8 CigiSwap8
00067 #else
00068 #define CIGI_SCOPY2 CigiCopy2
00069 #define CIGI_SCOPY4 CigiCopy4
00070 #define CIGI_SCOPY8 CigiCopy8
00071 #endif
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 CigiViewDefV2::CigiViewDefV2()
00084 {
00085
00086 PacketID = CIGI_VIEW_DEF_PACKET_ID_V2;
00087 PacketSize = CIGI_VIEW_DEF_PACKET_SIZE_V2;
00088 Version = 2;
00089 MinorVersion = 0;
00090
00091 ViewID = 0;
00092 GroupID = 0;
00093 FOVNearEn = false;
00094 FOVFarEn = false;
00095 FOVLeftEn = false;
00096 FOVRightEn = false;
00097 FOVTopEn = false;
00098 FOVBottomEn = false;
00099 MirrorMode = MirrorNone;
00100 PixelReplicateMode = ReplicateNone;
00101 ProjectionType = Perspective;
00102 Reorder = false;
00103 ViewType = 0;
00104 TrackerAssigned = false;
00105 FOVNear = 0.0;
00106 FOVFar = 0.0;
00107 FOVLeft = 0.0;
00108 FOVRight = 0.0;
00109 FOVTop = 0.0;
00110 FOVBottom = 0.0;
00111
00112 }
00113
00114
00115
00116
00117 CigiViewDefV2::~CigiViewDefV2()
00118 {
00119
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129 int CigiViewDefV2::Pack(CigiBasePacket * Base, Cigi_uint8 * Buff, void *Spec) const
00130 {
00131 double DBuf[6];
00132
00133 Cigi_uint8 *tBuf = (Cigi_uint8 *)DBuf;
00134
00135 PackPointer CDta;
00136
00137 CigiBaseViewDef * Data = ( CigiBaseViewDef *)Base;
00138
00139 CDta.d = DBuf;
00140
00141 *CDta.c++ = PacketID;
00142 *CDta.c++ = PacketSize;
00143
00144 Cigi_uint8 HDta = 0;
00145 if(Data->ViewID < 32)
00146 HDta = (Cigi_uint8)(Data->ViewID << 3);
00147 else
00148 HDta = (Cigi_uint8)0xf8;
00149
00150 if(Data->GroupID < 8)
00151 HDta |= (Cigi_uint8)Data->GroupID;
00152 else
00153 HDta |= 7;
00154
00155 *CDta.c++ = HDta;
00156
00157 HDta = (Data->ViewType << 5) & 0xe0;
00158 HDta |= (Cigi_uint8)((Data->PixelReplicateMode << 2) & 0x1c);
00159 HDta |= (Cigi_uint8)(Data->MirrorMode & 0x03);
00160
00161 *CDta.c++ = HDta;
00162
00163 HDta = (Data->TrackerAssigned) ? 0x80 : 0;
00164
00165 if(Data->FOVNearEn)
00166 HDta |= 0x40;
00167
00168 if(Data->FOVFarEn)
00169 HDta |= 0x20;
00170
00171 if(Data->FOVLeftEn)
00172 HDta |= 0x10;
00173
00174 if(Data->FOVRightEn)
00175 HDta |= 0x08;
00176
00177 if(Data->FOVTopEn)
00178 HDta |= 0x04;
00179
00180 if(Data->FOVBottomEn)
00181 HDta |= 0x02;
00182
00183 *CDta.c++ = HDta;
00184 *CDta.c++ = 0;
00185 *CDta.c++ = 0;
00186 *CDta.c++ = 0;
00187
00188 CIGI_SCOPY4(CDta.f++, &Data->FOVNear);
00189 CIGI_SCOPY4(CDta.f++, &Data->FOVFar);
00190 CIGI_SCOPY4(CDta.f++, &Data->FOVLeft);
00191 CIGI_SCOPY4(CDta.f++, &Data->FOVRight);
00192 CIGI_SCOPY4(CDta.f++, &Data->FOVTop);
00193 CIGI_SCOPY4(CDta.f++, &Data->FOVBottom);
00194
00195 memcpy(Buff,tBuf,CIGI_VIEW_DEF_PACKET_SIZE_V2);
00196
00197 return(PacketSize);
00198
00199 }
00200
00201
00202
00203
00204 int CigiViewDefV2::Unpack(Cigi_uint8 * Buff, bool Swap, void *Spec)
00205 {
00206 double DBuf[6];
00207
00208 Cigi_uint8 *tBuf = (Cigi_uint8 *)DBuf;
00209
00210 PackPointer CDta;
00211
00212 memcpy(tBuf,Buff,CIGI_VIEW_DEF_PACKET_SIZE_V2);
00213
00214 CDta.d = DBuf;
00215
00216 CDta.c += 2;
00217
00218 Cigi_uint8 HDta = *CDta.c++;
00219
00220 ViewID = (Cigi_uint8)((HDta >> 3) & 0x1f);
00221 GroupID = (Cigi_uint8)(HDta & 0x07);
00222
00223 HDta = *CDta.c++;
00224
00225 ViewType = (Cigi_uint8)((HDta >> 5) & 0x07);
00226 PixelReplicateMode = (PixelReplicateModeGrp)((HDta >> 2) & 0x07);
00227 MirrorMode = (MirrorModeGrp)(HDta & 0x03);
00228
00229 HDta = *CDta.c++;
00230
00231 TrackerAssigned = ((HDta & 0x80) != 0);
00232 FOVNearEn = ((HDta & 0x40) != 0);
00233 FOVFarEn = ((HDta & 0x20) != 0);
00234 FOVLeftEn = ((HDta & 0x10) != 0);
00235 FOVRightEn = ((HDta & 0x08) != 0);
00236 FOVTopEn = ((HDta & 0x04) != 0);
00237 FOVBottomEn = ((HDta & 0x02) != 0);
00238
00239 CDta.c += 3;
00240
00241 CIGI_SCOPY4(&FOVNear, CDta.f++);
00242 CIGI_SCOPY4(&FOVFar, CDta.f++);
00243 CIGI_SCOPY4(&FOVLeft, CDta.f++);
00244 CIGI_SCOPY4(&FOVRight, CDta.f++);
00245 CIGI_SCOPY4(&FOVTop, CDta.f++);
00246 CIGI_SCOPY4(&FOVBottom, CDta.f++);
00247
00248 return(PacketSize);
00249
00250
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 int CigiViewDefV2::SetViewID(const Cigi_uint8 ViewIDIn, bool bndchk)
00264 {
00265
00266 #ifndef CIGI_NO_BND_CHK
00267 if(bndchk && ((ViewIDIn < 0)||(ViewIDIn > 31)))
00268 {
00269 #ifndef CIGI_NO_EXCEPT
00270 throw CigiValueOutOfRangeException("ViewID",(Cigi_uint16)ViewIDIn,0,31);
00271 #endif
00272 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00273 }
00274 #endif
00275
00276 ViewID = (Cigi_uint16)ViewIDIn;
00277 return(CIGI_SUCCESS);
00278
00279 }
00280
00281
00282
00283
00284
00285 int CigiViewDefV2::SetGroupID(const Cigi_uint8 GroupIDIn, bool bndchk)
00286 {
00287
00288 #ifndef CIGI_NO_BND_CHK
00289 if(bndchk && ((GroupIDIn < 0)||(GroupIDIn > 7)))
00290 {
00291 #ifndef CIGI_NO_EXCEPT
00292 throw CigiValueOutOfRangeException("GroupID",(Cigi_uint16)GroupIDIn,0,7);
00293 #endif
00294 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00295 }
00296 #endif
00297
00298 GroupID = GroupIDIn;
00299 return(CIGI_SUCCESS);
00300
00301 }
00302