| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using CoreOSC; |
| | 4 | | using ReFlex.Core.Common.Components; |
| | 5 | |
|
| | 6 | | namespace ReFlex.Core.Tuio.Util |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Data Storage to build <see cref="OscBundle"/> for TUIO Communication |
| | 10 | | /// </summary> |
| | 11 | | public class TuioParameters |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Dimension (in /tuio2/frm) |
| | 15 | | /// </summary> |
| 8 | 16 | | public int Dimension { get; } |
| | 17 | | /// <summary> |
| | 18 | | /// Source (in /tuio2/frm and "source" property in TUIO 1.1) |
| | 19 | | /// </summary> |
| 16 | 20 | | public string Source { get; } |
| | 21 | | /// <summary> |
| | 22 | | /// Session Id for alive messages |
| | 23 | | /// </summary> |
| 40 | 24 | | public int SessionId { get; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// FrameId (in /tuio2/frm and "fseq" property in TUIO 1.1) |
| | 28 | | /// </summary> |
| 13 | 29 | | public int FrameId { get; } |
| | 30 | |
|
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Time for Bundle and in /tuio2/frm |
| | 34 | | /// </summary> |
| 14 | 35 | | public Timetag Time { get; } |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Contains List of Interaction with Position and TouchId in the Foomat: [Item1, Item2, Item3, Item4] = [TouchI |
| | 39 | | /// </summary> |
| 112 | 40 | | public List<Tuple<int, float, float, float>> Positions { get; } = new List<Tuple<int, float, float, float>>(); |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Constructs Parameters. |
| | 44 | | /// <see cref="Time"/> is derived from <see><cref>DateTime.Now.Ticks</cref></see> |
| | 45 | | /// <see cref="Dimension"/> is computed from <see cref="TuioConfiguration.SensorWidth"/> * <see cref="TuioConfi |
| | 46 | | /// <see cref="Source"/> is $"ReFlex@{clientAddress} [{config.SensorDescription}]" |
| | 47 | | /// For each interaction, the Coordinates are transformed, if the provided <see cref="TuioInterpretation"/> is |
| | 48 | | /// Position.Z = (Position.Z + 1) / 2 (to fit from [-1 | 1] ]in the range [0.0. | 1.0 ] with 0.0 -> 0.5 |
| | 49 | | /// </summary> |
| | 50 | | /// <param name="clientAddress">IP Address for specifying the Source</param> |
| | 51 | | /// <param name="config">for computing dimension and transformation of coordinates</param> |
| | 52 | | /// <param name="interactions">interactions from Reflex server, transformed and stored in <see cref="Positions" |
| | 53 | | /// <param name="frameId">frame Id for TUIO message bundle. used to maintain correct order of messages</param> |
| 16 | 54 | | public TuioParameters(string clientAddress, TuioConfiguration config, List<Interaction> interactions, int frameI |
| 16 | 55 | | { |
| 16 | 56 | | Time = new Timetag((ulong)DateTime.Now.Ticks); |
| 16 | 57 | | Dimension = config.SensorWidth * config.SensorHeight; |
| 16 | 58 | | Source = $"ReFlex@{clientAddress} [{config.SensorDescription}]"; |
| 16 | 59 | | SessionId = config.SessionId; |
| 16 | 60 | | FrameId = frameId; |
| | 61 | |
|
| 16 | 62 | | interactions.ForEach(interaction => |
| 86 | 63 | | { |
| 86 | 64 | | var xPos = interaction.Position.X; |
| 86 | 65 | | var yPos = interaction.Position.Y; |
| 86 | 66 | | var zPos = interaction.Position.Z; |
| 16 | 67 | |
|
| 86 | 68 | | if (config.Interpretation == TuioInterpretation.Point3D) |
| 34 | 69 | | zPos = (zPos + 1.0f) * 0.5f; // decode range [-1.0 | 1.0] into [0.0. | 1.0 ] with 0.0 -> 0.5 |
| 16 | 70 | |
|
| 86 | 71 | | Positions.Add(new Tuple<int, float, float, float>(interaction.TouchId, xPos, yPos, zPos)); |
| 102 | 72 | | }); |
| 16 | 73 | | } |
| | 74 | | } |
| | 75 | | } |