public virtual bool TryParse(string xiRawData, out object xoData)
        {
            Assert.NonEmptyString(xiRawData, "xiRawData");

            xoData = null;

            bool result = false;

            if (xiRawData.IndexOf('%') < 0 && xiRawData.IndexOf('#') < 0)
            {
                string [] vals = xiRawData.Split(Text.kComma, StringSplitOptions.RemoveEmptyEntries);

                if (vals.Length > 7) // track,2,fields|time, track_id, track_status, existence_probability, meas_id, x_pos, x_vel, y_pos, y_vel, turn_rate, P(5 x 5)|<EOL>
                {
                    xoData = new Data.Estimate();

                    Data.Estimate estimate = xoData as Data.Estimate;

                    estimate.timestamp = DateTime.Now;

                    double timestamp;

                    if (double.TryParse(vals[5], out timestamp))
                    {
                        estimate.rawTimestamp = (long)timestamp;
                    }

                    double val;

                    if (double.TryParse(vals[1], out val))
                    {
                        estimate.trackNumber = (int)val;
                    }

                    if (double.TryParse(vals[5], out val))
                    {
                        estimate.xPos = val;
                    }

                    if (double.TryParse(vals[7], out val))
                    {
                        estimate.yPos = val;
                    }

                    result = true;
                }
            }

            return(result);
        }
        // track,2,fields,time, track_id, track_status, existence_probability, meas_id, x_pos, x_vel, y_pos, y_vel, turn_rate, P(5 x 5),<EOL>
        // 0      1  2                3         4             5                      6        7            8           9             10          11         12          13
        // track, 2, time,            track_id, track_status, existence_probability, meas_id, x_pos,       x_vel,      y_pos,        y_vel,      turn_rate, P(5 x 5),   <EOL>
        // track, 2, 1294754983.4190, 2,        1,            0.500000,              1,       -578.262943, 0.00000000, -1688.746768, 0.00000000, 0.000000,  0.00000000, <EOL>
        public virtual bool TryParse(string xiRawData, out object xoData)
        {
            Assert.NonEmptyString(xiRawData, "xiRawData");

            xoData = null;

            bool result = false;

            string [] values = xiRawData.Split(new char [] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (values.Length > 0 && values[0].Trim().CompareTo("track") == 0)
            {
                bool eol = false;
                bool eot = false;
                bool eos = false;

                bool hasFields = values.Length > 2 && values[2].Trim().CompareTo("fields") == 0;

                if (!hasFields)
                {
                    eol = values[values.Length - 1].CompareTo(DataProvider.kEol) == 0;

                    if (!eol)
                    {
                        eot = values[values.Length - 1].CompareTo(DataProvider.kEot) == 0;

                        if (!eot)
                        {
                            eos = values[values.Length - 1].CompareTo(DataProvider.kEos) == 0;
                        }
                    }
                }

                if (eol || eot || eos || hasFields)
                {
                    Data.Estimate estimate = new Data.Estimate();

                    estimate.timestamp = DateTime.Now;

                    if (eol || eot)
                    {
                        if (values.Length > 9)
                        {
                            int trackNumber;

                            if (int.TryParse(values[3], out trackNumber))
                            {
                                estimate.trackNumber = trackNumber;
                            }

                            if (eol)
                            {
                                long timestamp;

                                if (long.TryParse(values[4], out timestamp))
                                {
                                    estimate.rawTimestamp = timestamp;
                                }

                                double value;

                                if (double.TryParse(values[7], out value))
                                {
                                    estimate.xPos = value;
                                }

                                if (double.TryParse(values[9], out value))
                                {
                                    estimate.yPos = value;
                                }

                                estimate.operation = EDataOperation.eUpdateData;
                            }
                            else
                            {
                                estimate.operation = EDataOperation.eRemoveData;
                            }

                            xoData = estimate;

                            result = true;
                        }
                    }
                    else if (hasFields)
                    {
                        estimate.operation = EDataOperation.eAddData;

                        xoData = estimate;

                        result = true;
                    }
                    else if (eos)
                    {
                        estimate.operation = EDataOperation.eClearData;

                        xoData = estimate;

                        result = true;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public virtual bool TryParse(string xiRawData, out object xoData)
        {
            Assert.NonEmptyString(xiRawData, "xiRawData");

            xoData = null;

            bool result = false;

            if (xiRawData.IndexOf('%') > -1 || xiRawData.IndexOf('#') > -1)
            {
            }
            else if (xiRawData.IndexOf("coordinate_system_dimension") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out coordinate_system_dimension);
                }
            }
            else if (xiRawData.IndexOf("max_mode_order") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out max_mode_order);
                }
            }
            else if (xiRawData.IndexOf("has_coord_turn") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out has_coord_turn);
                }
            }
            else if (xiRawData.IndexOf("state_size") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out state_size);
                }
            }
            else if (xiRawData.IndexOf("back_scan_list_dimension") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out back_scan_list_dimension);
                }
            }
            else if (xiRawData.IndexOf("number_of_sub_hypotheses") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out number_of_sub_hypotheses);
                }
            }
            else if (xiRawData.IndexOf("IMM_mode_count") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out IMM_mode_count);
                }
            }
            else if (xiRawData.IndexOf("filter_module_types") > -1) // collect header data
            {
            }
            else if (xiRawData.IndexOf("initialization_method") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out initialization_method);
                }
            }
            else if (xiRawData.IndexOf("np") > -1) // collect header data
            {
                int equalSignIndex = xiRawData.IndexOf('=');
                int semicolonIndex = xiRawData.IndexOf(';');

                if (equalSignIndex > -1 && semicolonIndex > -1)
                {
                    string data = xiRawData.Substring(++equalSignIndex, semicolonIndex - equalSignIndex);
                    int.TryParse(data, out np);
                }
            }
            else
            {
                //   0       1         2          3         4             5           6            7                  8
                // % run_no, frame_no, sensor_no, track_id, track_status, cluster_id, num_updates, last_update_frame, last_update_time,

                //  9                                                                                            10
                //  [sensor_no frame_no associated_meas](number_of_sub_hypotheses x 3*back_scan_list_dimension), unique_associations((number_of_sub_hypotheses+1) x back_scan_list_dimension),

                //  11
                //  association_weights((number_of_sub_hypotheses+1) x back_scan_list_dimension),

                //  12                 13                          14                      15                               16                 17                  18                           19
                //  X(1 x state_size), P(state_size x state_size), mu(1 x IMM_mode_count), existence_probabilities(1 x np), common_track_time, Xk(1 x state_size), Pk(state_size x state_size), muk(1 x IMM_mode_count)
                string rawData = xiRawData.Replace(',', ' ');

                string [] vals = rawData.Split(Text.kWhiteSpace, StringSplitOptions.RemoveEmptyEntries);

                if (vals.Length > 20)
                {
                    xoData = new Data.Estimate();

                    Data.Estimate estimate = xoData as Data.Estimate;

                    estimate.timestamp = DateTime.Now;

                    double run;

                    if (double.TryParse(vals[0], out run))
                    {
                        estimate.run = (int)run;
                    }

                    double frameNo;

                    if (double.TryParse(vals[1], out frameNo))
                    {
                        estimate.frameNo = (int)frameNo;
                    }

                    double sensorId;

                    if (double.TryParse(vals[2], out sensorId))
                    {
                        estimate.sensorId = (int)sensorId + 1;
                    }

                    int xPosIndex;
                    int xVelIndex;
                    int yPosIndex;
                    int yVelIndex;
                    int timeIndex;

                    IList <int> covarianceMatrixIndeces = new List <int>();

                    CalculateIndeces(out xPosIndex, out xVelIndex, out yPosIndex, out yVelIndex, out timeIndex, ref covarianceMatrixIndeces);

                    double time;

                    if (timeIndex < vals.Length && double.TryParse(vals[timeIndex], out time))
                    {
                        estimate.time = time;
                    }

                    double val;

                    if (xPosIndex < vals.Length && double.TryParse(vals[xPosIndex], out val))
                    {
                        estimate.xPos = val;
                    }

                    if (xVelIndex < vals.Length && double.TryParse(vals[xVelIndex], out val))
                    {
                        estimate.xVel = val;
                    }

                    if (yPosIndex < vals.Length && double.TryParse(vals[yPosIndex], out val))
                    {
                        estimate.yPos = val;
                    }

                    if (yVelIndex < vals.Length && double.TryParse(vals[yVelIndex], out val))
                    {
                        estimate.yVel = val;
                    }

                    int trackId;

                    if (int.TryParse(vals[3], out trackId))
                    {
                        estimate.trackNumber = trackId;
                    }

                    int trackStatus;

                    if (int.TryParse(vals[4], out trackStatus))
                    {
                        estimate.trackStatus = trackStatus;
                    }

                    int    index;
                    double value;

                    const int rank = 4;

                    estimate.covarianceMatrix = new double [rank, rank];

                    for (int j = 0, m = rank; j < m; j++)
                    {
                        for (int i = 0, n = rank; i < n; i++)
                        {
                            index = covarianceMatrixIndeces[i + rank * j];

                            if (double.TryParse(vals[index], out value))
                            {
                                estimate.covarianceMatrix[j, i] = value;
                            }
                        }
                    }

                    result = true;
                }
            }

            return(result);
        }