1 /*********************************************************************
2 Copyright 2013 Karl Jones
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 /********************************************************************
31 class: Gridded_Data_PDU
32 DIS: (6) 1278.1a - 1998
36 purpose: Information about global, spatially varying environmental
37 effects shall be communicated using one or more Gridded Data PDUs.
39 size: 512 bits / 64 octets - Min size
40 *********************************************************************/
46 #include "KDIS/DataTypes/EntityIdentifier.hpp"
47 #include "KDIS/DataTypes/EnvironmentType.hpp"
48 #include "KDIS/DataTypes/EulerAngles.hpp"
49 #include "KDIS/DataTypes/GridAxisIrregular.hpp"
50 #include "KDIS/DataTypes/GridDataType0.hpp"
51 #include "KDIS/DataTypes/GridDataType1.hpp"
52 #include "KDIS/DataTypes/GridDataType2.hpp"
53 #include "KDIS/Extras/KRef_Ptr.hpp"
54 #include "KDIS/PDU/Header.hpp"
60 // Some PDU specific data types.
61 typedef KDIS::UTILS::KRef_Ptr
<GridAxisRegular
> GridAxisDescriptor
;
62 typedef KDIS::UTILS::KRef_Ptr
<GridData
> GridDataPtr
;
64 } // END namespace DATA_TYPE
68 class KDIS_EXPORT Gridded_Data_PDU
: public Header
{
70 KDIS::DATA_TYPE::EntityIdentifier m_EnvProcID
;
72 KUINT16 m_ui16FieldNum
;
76 KUINT16 m_ui16PDUTotal
;
78 KUINT16 m_ui16CordSys
;
82 KUINT8 m_ui8ConstGrid
;
84 KDIS::DATA_TYPE::EnvironmentType m_EnvType
;
86 KDIS::DATA_TYPE::EulerAngles m_Ori
;
88 KUINT64 m_ui64SampleTime
;
90 KUINT32 m_ui32TotalValues
;
95 m_ui16Padding1
; // 24 bits unused for alignment of Grid Axis Descriptor
98 std::vector
<KDIS::DATA_TYPE::GridAxisDescriptor
> m_vpGridAxisDesc
;
100 std::vector
<KDIS::DATA_TYPE::GridDataPtr
> m_vGridData
;
103 static const KUINT16 GRIDDED_DATA_PDU_SIZE
= 64; // Min size
107 Gridded_Data_PDU(KDataStream
& stream
);
109 Gridded_Data_PDU(const Header
& H
, KDataStream
& stream
);
112 const KDIS::DATA_TYPE::EntityIdentifier
& EnvironmentalProcessID
,
113 KUINT16 FieldNumber
, KUINT16 PduNum
, KUINT16 PduTotal
,
114 KDIS::DATA_TYPE::ENUMS::CoordinateSystem CS
,
115 KDIS::DATA_TYPE::ENUMS::ConstantGrid CG
,
116 const KDIS::DATA_TYPE::EnvironmentType
& ET
,
117 const KDIS::DATA_TYPE::EulerAngles
& Ori
, KUINT64 SampleTime
);
119 virtual ~Gridded_Data_PDU();
121 //************************************
122 // FullName: KDIS::PDU::Gridded_Data_PDU::SetEnvironmentalProcessID
123 // KDIS::PDU::Gridded_Data_PDU::GetEnvironmentalProcessID
124 // Description: Identifies the environmental simulation application issuing
126 // This field is also known as "Environmental Simulation ID" in
128 // Parameter: const EntityIdentifier & ID
129 //************************************
130 void SetEnvironmentalProcessID(const KDIS::DATA_TYPE::EntityIdentifier
& ID
);
131 const KDIS::DATA_TYPE::EntityIdentifier
& GetEnvironmentalProcessID() const;
132 KDIS::DATA_TYPE::EntityIdentifier
& GetEnvironmentalProcessID();
134 //************************************
135 // FullName: KDIS::PDU::Gridded_Data_PDU::SetFieldNumber
136 // KDIS::PDU::Gridded_Data_PDU::GetFieldNumber
137 // Description: Specifies a unique identifier for each environmental variable
139 // during an exercise.
140 // Parameter: KUINT16 FN
141 //************************************
142 void SetFieldNumber(KUINT16 FN
);
143 KUINT16
GetFieldNumber() const;
145 //************************************
146 // FullName: KDIS::PDU::Gridded_Data_PDU::SetPDUNumber
147 // KDIS::PDU::Gridded_Data_PDU::GetPDUNumber
148 // Description: Specifies an index number of the current PDU within the total
150 // of PDUs used to transmit the environmental data.
151 // SetPDUNumberAndTotal will throw an exception if Num is greater
152 // than Total. No error checking is done if you use the 2
153 // separate accessors SetPDUNumber and SetPDUTotal so be careful
154 // not to make the PDU number greater than the total.
155 // Parameter: KUINT16 PN
156 //************************************
157 void SetPDUNumber(KUINT16 PN
);
158 KUINT16
GetPDUNumber() const;
159 void SetPDUNumberAndTotal(KUINT16 Num
, KUINT16 Total
);
161 //************************************
162 // FullName: KDIS::PDU::Gridded_Data_PDU::SetPDUTotal
163 // KDIS::PDU::Gridded_Data_PDU::GetPDUTotal
164 // Description: Specifies the total number of PDUs used to transmit this
165 // environmental data.
166 // This value should not be less than PDU number.
167 // Parameter: KUINT16 PT
168 //************************************
169 void SetPDUTotal(KUINT16 PT
);
170 KUINT16
GetPDUTotal() const;
172 //************************************
173 // FullName: KDIS::PDU::Gridded_Data_PDU::SetCoordinateSystem
174 // KDIS::PDU::Gridded_Data_PDU::GetCoordinateSystem
175 // Description: Specifies the coordinate system of the grid for the
177 // data contained in the Gridded Data PDU.
178 // Parameter: CoordinateSystem CS
179 //************************************
180 void SetCoordinateSystem(KDIS::DATA_TYPE::ENUMS::CoordinateSystem CS
);
181 KDIS::DATA_TYPE::ENUMS::CoordinateSystem
GetCoordinateSystem() const;
183 //************************************
184 // FullName: KDIS::PDU::Gridded_Data_PDU::Decode
185 // Description: Number of grid axis in the PDU.
186 // e.g. three grid axes for an x, y, z coordinate system.
187 //************************************
188 KUINT8
GetNumberAxis() const;
190 //************************************
191 // FullName: KDIS::PDU::Gridded_Data_PDU::SetConstantGrid
192 // KDIS::PDU::Gridded_Data_PDU::GetConstantGrid
193 // Description: Specifies whether the domain grid axes are identical to those
195 // domain update grid for the environmental data sample contained
197 // Parameter: ConstantGrid CG
198 //************************************
199 void SetConstantGrid(KDIS::DATA_TYPE::ENUMS::ConstantGrid CG
);
200 KDIS::DATA_TYPE::ENUMS::ConstantGrid
GetConstantGrid() const;
202 //************************************
203 // FullName: KDIS::PDU::Gridded_Data_PDU::SetEnvironmentType
204 // KDIS::PDU::Gridded_Data_PDU::GetEnvironmentType
205 // Description: DIS enumeration identifying the type of environmental effect
206 // being described. Parameter: const EnvironmentType & ET
207 //************************************
208 void SetEnvironmentType(const KDIS::DATA_TYPE::EnvironmentType
& ET
);
209 const KDIS::DATA_TYPE::EnvironmentType
& GetEnvironmentType() const;
210 KDIS::DATA_TYPE::EnvironmentType
& GetEnvironmentType();
212 //************************************
213 // FullName: KDIS::PDU::Gridded_Data_PDU::SetOrientation
214 // KDIS::PDU::Gridded_Data_PDU::GetOrientation
215 // Description: Specifies the orientation of the data grid.
216 // Parameter: const EulerAngles & O
217 //************************************
218 void SetOrientation(const KDIS::DATA_TYPE::EulerAngles
& O
);
219 const KDIS::DATA_TYPE::EulerAngles
& GetOrientation() const;
220 KDIS::DATA_TYPE::EulerAngles
& GetOrientation();
222 //************************************
223 // FullName: KDIS::PDU::Gridded_Data_PDU::SetSampleTime
224 // KDIS::PDU::Gridded_Data_PDU::GetSampleTime
225 // Description: Specifies the valid time of the environmental data sample
226 // contained in the PDU. Parameter: KUINT64 ST
227 //************************************
228 void SetSampleTime(KUINT64 ST
);
229 KUINT64
GetSampleTime() const;
231 //************************************
232 // FullName: KDIS::PDU::Gridded_Data_PDU::SetTotalValues
233 // KDIS::PDU::Gridded_Data_PDU::GetTotalValues
234 // Description: Specifies the total number of data values for all PDUs for an
236 // sample. This total includes vector-valued environmental data
237 // and equals the product of the vector dimension and the total
238 // number of grid points.
239 // Parameter: KUINT32 TV
240 //************************************
241 void SetTotalValues(KUINT32 TV
);
242 KUINT32
GetTotalValues() const;
244 //************************************
245 // FullName: KDIS::PDU::Gridded_Data_PDU::SetVectorDimension
246 // KDIS::PDU::Gridded_Data_PDU::GetVectorDimension
247 // Description: This field shall specify the total number of data values at
248 // each grid point and
249 // accommodates scalar or vector-valued environmental data.
250 // Vector Dimension shall be one for scalar data, and shall be
251 // greater than one when multiple enumerated environmental data
252 // values are sent for each grid location (e.g., u, v, w wind
253 // components have V = 3). (I.E Number of GridData values).
254 // Parameter: KUINT8 VD
255 //************************************
256 void SetVectorDimension(KUINT8 VD
);
257 KUINT8
GetVectorDimension() const;
259 //************************************
260 // FullName: KDIS::PDU::Gridded_Data_PDU::AddGridAxisDescriptor
261 // KDIS::PDU::Gridded_Data_PDU::SetGridAxisDescriptors
262 // KDIS::PDU::Gridded_Data_PDU::GetSetGridAxisDescriptors
263 // Description: Specifies the detailed information about the grid dimensions
265 // and coordinates for environmental state variables.
266 // More than one Grid Data record is allowed in a single Gridded
267 // Data PDU corresponding to each enumerated sample type.
268 // Parameter: const GridAxisDescriptor & GAD, const
269 // vector<GridAxisDescriptor> & GADS
270 //************************************
271 void AddGridAxisDescriptor(const KDIS::DATA_TYPE::GridAxisDescriptor
& GAD
);
272 void SetGridAxisDescriptors(
273 const std::vector
<KDIS::DATA_TYPE::GridAxisDescriptor
>& GADS
);
274 const std::vector
<KDIS::DATA_TYPE::GridAxisDescriptor
>&
275 GetSetGridAxisDescriptors() const;
277 //************************************
278 // FullName: KDIS::PDU::Gridded_Data_PDU::AddGridData
279 // KDIS::PDU::Gridded_Data_PDU::SetGridData
280 // KDIS::PDU::Gridded_Data_PDU::GetGridData
281 // Description: Specifies the environmental state data at the grid locations
283 // parameters in the Grid Axis Descriptor record.
284 // Parameter: const GridDataPtr & GD, const vector<GridDataPtr> & GD
285 //************************************
286 void AddGridData(const KDIS::DATA_TYPE::GridDataPtr
& GD
);
287 void SetGridData(const std::vector
<KDIS::DATA_TYPE::GridDataPtr
>& GD
);
288 const std::vector
<KDIS::DATA_TYPE::GridDataPtr
>& GetGridData() const;
290 //************************************
291 // FullName: KDIS::PDU::Gridded_Data_PDU::GetAsString
292 // Description: Returns a string representation of the PDU.
293 //************************************
294 virtual KString
GetAsString() const;
296 //************************************
297 // FullName: KDIS::PDU::Gridded_Data_PDU::Decode
298 // Description: Convert From Network Data.
299 // Parameter: KDataStream & stream
300 // Parameter: bool ignoreHeader = false - Decode the header from the stream?
301 //************************************
302 virtual void Decode(KDataStream
& stream
, bool ignoreHeader
= false);
304 //************************************
305 // FullName: KDIS::PDU::Gridded_Data_PDU::Encode
306 // Description: Convert To Network Data.
307 // Parameter: KDataStream & stream
308 //************************************
309 virtual KDataStream
Encode() const;
310 virtual void Encode(KDataStream
& stream
) const;
312 KBOOL
operator==(const Gridded_Data_PDU
& Value
) const;
313 KBOOL
operator!=(const Gridded_Data_PDU
& Value
) const;
316 } // END namespace PDU
317 } // END namespace KDIS