Beispiel #1
0
            public override byte[] Serialize(bool partofsomethingelse)
            {
                int  currentIndex = 0, length = 0;
                bool hasmetacomponents = false;

                byte[]        thischunk, scratch1, scratch2;
                List <byte[]> pieces = new List <byte[]>();
                GCHandle      h;

                //map
                if (map == null)
                {
                    map = new Messages.sensor_msgs.PointCloud2();
                }
                pieces.Add(map.Serialize(true));
                //combine every array in pieces into one array and return it
                int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
                int __a_b__e = 0;

                byte[] __a_b__d = new byte[__a_b__f];
                foreach (var __p__ in pieces)
                {
                    Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                    __a_b__e += __p__.Length;
                }
                return(__a_b__d);
            }
Beispiel #2
0
            public override void Randomize()
            {
                int    arraylength = -1;
                Random rand        = new Random();
                int    strlength;

                byte[] strbuf, myByte;

                //map
                map = new Messages.sensor_msgs.PointCloud2();
                map.Randomize();
            }
Beispiel #3
0
            //[System.Diagnostics.DebuggerStepThrough]
            public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
            {
                int  arraylength       = -1;
                bool hasmetacomponents = false;
                int  piecesize         = 0;

                byte[] thischunk, scratch1, scratch2;
                IntPtr h;
                object __thing;

                //map
                map = new Messages.sensor_msgs.PointCloud2(SERIALIZEDSTUFF, ref currentIndex);
            }
        public void subCallback(Messages.sensor_msgs.PointCloud2 msg)
        {
            //msg = recentMsg;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            //print("in callback");
            if (!theCloud[current_cloud_buffer].isStarted)
            {
                print("theCloud is not started");
                return;
            }
            Dictionary <string, uint> fieldOffset = new Dictionary <string, uint>();

            for (int i = 0; i < msg.fields.Length; i++)
            {
                fieldOffset.Add(msg.fields[i].name, msg.fields[i].offset);
                //print(msg.fields[i].name + " " + msg.fields[i].offset + " " + msg.fields[i].datatype);
            }
            uint offset_x           = fieldOffset["x"];
            uint offset_y           = fieldOffset["y"];
            uint offset_z           = fieldOffset["z"];
            uint offset_rgb         = fieldOffset["rgb"];
            int  shape_vertex_count = vertexCount[pointShape];
            int  numPoints          = (msg.data.Length / ((int)msg.point_step)) + 1;
            //print(numPoints);
            bool shouldIncreaseTriangles = theCloud[current_cloud_buffer].numPoints_in_triangle_buffer < numPoints;

            if (shouldIncreaseTriangles || hard_recalculate_triangles)
            {
                theCloud[current_cloud_buffer].recalculateTriangles(numPoints, indices[pointShape], vertexCount[pointShape]);
                hard_recalculate_triangles = false;
            }
            stopWatch.Stop();
            //print("Triangle Calculation Run Time " + stopWatch.ElapsedMilliseconds);
            stopWatch.Reset();
            stopWatch.Start();
            //print("---------------------------------------------------------------------------------------------------------------");
            //print(vertexAccumulation.Length);
            theCloud[current_cloud_buffer].vertexBuffers[theCloud[current_cloud_buffer].whichBuffer] = new Vector3[theCloud[current_cloud_buffer].numPoints_in_triangle_buffer * vertexCount[pointShape]];
            theCloud[current_cloud_buffer].colorBuffers[theCloud[current_cloud_buffer].whichBuffer]  = new Color[theCloud[current_cloud_buffer].numPoints_in_triangle_buffer * vertexCount[pointShape]];
            //print("---------------------------------------------------------------------------------------------------------------");
            pointNum = 0;
            //print("---------------------------------------------------------------------------------------------------------------");
            for (int i = 0; i < msg.data.Length; i += (int)msg.point_step)
            {
                float x = ToFloat(msg.data[i + offset_x + 0], msg.data[i + offset_x + 1], msg.data[i + offset_x + 2], msg.data[i + offset_x + 3]);
                float y = -1 * ToFloat(msg.data[i + offset_y + 0], msg.data[i + offset_y + 1], msg.data[i + offset_y + 2], msg.data[i + offset_y + 3]);// + 1.2F;
                float z = ToFloat(msg.data[i + offset_z + 0], msg.data[i + offset_z + 1], msg.data[i + offset_z + 2], msg.data[i + offset_z + 3]);
                float b = ToInt(0, 0, 0, msg.data[i + offset_rgb + 0]) * 0.00392156862F;
                float g = ToInt(0, 0, 0, msg.data[i + offset_rgb + 1]) * 0.00392156862F;
                float r = ToInt(0, 0, 0, msg.data[i + offset_rgb + 2]) * 0.00392156862F;
                Color c = new Color(r, g, b, 1);
                addPoint(x, y, z, c);
            }
            //print("---------------------------------------------------------------------------------------------------------------");
            theCloud[current_cloud_buffer].whichBuffer      = (theCloud[current_cloud_buffer].whichBuffer + 1) % 2;
            theCloud[current_cloud_buffer].updateVertexData = true;
            if (include_color)
            {
                theCloud[current_cloud_buffer].updateColorData = true;
            }
            if (shouldIncreaseTriangles)
            {
                theCloud[current_cloud_buffer].updateTriangleData = true;
            }
            current_cloud_buffer++;
            if (current_cloud_buffer >= theCloud.Length)
            {
                current_cloud_buffer = 0;
            }
            stopWatch.Stop();
            //print("Vertex Calculation Run Time " + stopWatch.ElapsedMilliseconds);
            //print("------------------------------------------------------------------finished callback" + pointNum);
        }