示例#1
0
        /// <summary>
        /// returns stereo feature data as a byte array suitable for broadcasting
        /// </summary>
        /// <returns>byte array containing stereo feature data</returns>
        private byte[] SerializedStereoFeatures()
        {
            byte[] serialized = null;
            
            if (features != null)
            {
                int n = 0;

                // limit the maximum number of features broadcast
                int max = features.Count;
                if (max > maximum_broadcast_features) max = maximum_broadcast_features;
                Random rnd = new Random();

                if (BroadcastStereoFeatureColours)
                {
                    // include colour data in the broadcast
                    for (int i = 0; i < max; i++)
                    {
                        int ii = i;
                        if (features.Count > maximum_broadcast_features)
                            ii = rnd.Next(features.Count-1);

                        BroadcastStereoFeatureColour data = new BroadcastStereoFeatureColour();
                        data.x = features[ii].x;
                        data.y = features[ii].y;
                        data.disparity = features[ii].disparity;
                        data.r = features[ii].colour[0];
                        data.g = features[ii].colour[1];
                        data.b = features[ii].colour[2];
                        byte[] serial_data = RawSerialize(data);
                        if (serialized == null)
                        {
                            serialized = new byte[(max * serial_data.Length) + 1];
                            serialized[n++] = 1; // first byte indicates colour info
                        }
                        for (int j = 0; j < serial_data.Length; j++, n++)
                            serialized[n] = serial_data[j];
                    }
                    
                }
                else
                {
                    // broadcast only the basics for each stereo feature
                    for (int i = 0; i < max; i++)
                    {
                        int ii = i;
                        if (features.Count > maximum_broadcast_features)
                            ii = rnd.Next(features.Count-1);

                        BroadcastStereoFeature data = new BroadcastStereoFeature();
                        data.x = features[ii].x;
                        data.y = features[ii].y;
                        data.disparity = features[ii].disparity;
                        byte[] serial_data = RawSerialize(data);
                        if (serialized == null)
                        {
                            serialized = new byte[(max * serial_data.Length) + 1];
                            serialized[n++] = 0;  // first byte indicates no colour info
                        }
                        for (int j = 0; j < serial_data.Length; j++, n++)
                            serialized[n] = serial_data[j];
                    }
                }
            }
            return(serialized);
        }
示例#2
0
        /// <summary>
        /// returns stereo feature data as a byte array suitable for broadcasting
        /// </summary>
        /// <returns>byte array containing stereo feature data</returns>
        private byte[] SerializedStereoFeatures()
        {
            byte[] serialized = null;

            if (features != null)
            {
                int n = 0;

                // limit the maximum number of features broadcast
                int max = features.Count;
                if (max > maximum_broadcast_features)
                {
                    max = maximum_broadcast_features;
                }
                Random rnd = new Random();

                if (BroadcastStereoFeatureColours)
                {
                    // include colour data in the broadcast
                    for (int i = 0; i < max; i++)
                    {
                        int ii = i;
                        if (features.Count > maximum_broadcast_features)
                        {
                            ii = rnd.Next(features.Count - 1);
                        }

                        BroadcastStereoFeatureColour data = new BroadcastStereoFeatureColour();
                        data.x         = features[ii].x;
                        data.y         = features[ii].y;
                        data.disparity = features[ii].disparity;
                        data.r         = features[ii].colour[0];
                        data.g         = features[ii].colour[1];
                        data.b         = features[ii].colour[2];
                        byte[] serial_data = RawSerialize(data);
                        if (serialized == null)
                        {
                            serialized      = new byte[(max * serial_data.Length) + 1];
                            serialized[n++] = 1; // first byte indicates colour info
                        }
                        for (int j = 0; j < serial_data.Length; j++, n++)
                        {
                            serialized[n] = serial_data[j];
                        }
                    }
                }
                else
                {
                    // broadcast only the basics for each stereo feature
                    for (int i = 0; i < max; i++)
                    {
                        int ii = i;
                        if (features.Count > maximum_broadcast_features)
                        {
                            ii = rnd.Next(features.Count - 1);
                        }

                        BroadcastStereoFeature data = new BroadcastStereoFeature();
                        data.x         = features[ii].x;
                        data.y         = features[ii].y;
                        data.disparity = features[ii].disparity;
                        byte[] serial_data = RawSerialize(data);
                        if (serialized == null)
                        {
                            serialized      = new byte[(max * serial_data.Length) + 1];
                            serialized[n++] = 0;  // first byte indicates no colour info
                        }
                        for (int j = 0; j < serial_data.Length; j++, n++)
                        {
                            serialized[n] = serial_data[j];
                        }
                    }
                }
            }
            return(serialized);
        }