Exemplo n.º 1
0
        private void reconstrucionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string       exportPath = "";
            DialogResult dr         = folderBrowserDialog1.ShowDialog();

            if (dr == DialogResult.OK)
            {
                exportPath = this.folderBrowserDialog1.SelectedPath;
            }
            int nSliceSize = VOIInfo.nWidth * VOIInfo.nHeight;

            this.toolStripStatusLabel1.Text = "正在保存...";
            if (Directory.Exists(exportPath))
            {
                for (int i = 0; i < VOIInfo.nDepth; i++)
                {
                    FileStream fs = new FileStream((exportPath + "\\" + (i + 1) + ".raw"), FileMode.Create);
                    unsafe
                    {
                        System.UInt16 *exportPointer = Reconstruction.Reconstruction.ExportBySlice(i);
                        for (int pointernum = 0; pointernum < nSliceSize; pointernum++)
                        {
                            System.Byte[] word = BitConverter.GetBytes(exportPointer[pointernum]);
                            fs.Write(word, 0, 2);
                        }
                    }
                }
                this.toolStripStatusLabel1.Text = "重建结果已输出并保存到硬盘,通过Loaddata->Reconstruction载入以查看不同层面重建结果。";
            }
            else
            {
                this.toolStripStatusLabel1.Text = "保存失败";
            }
        }
Exemplo n.º 2
0
 public void Write(System.UInt16 data)
 {
     unsafe
     {
         System.UInt16 *pPtr = &data;
         Write((IntPtr)pPtr, sizeof(System.UInt16));
     }
 }
            public int RecvMessage(System.UInt16 *connectionId, System.Byte *payload, System.UInt16 maxPayloadSize)
            {
                if (this.tcpClient == null || !this.tcpClient.Connected)
                {
                    return(0);
                }

                // Data buffer for incoming data.
                byte[] bytes = new Byte[maxPayloadSize];

                // Try to get the data from the socket.
                try
                {
                    if (this.tcpClient.Available <= 0)
                    {
                        return(0);
                    }
                    // An incoming connection needs to be processed.
                    int bytesRec = this.tcpClient.Receive(bytes);
                    if (bytesRec <= 0)
                    {
                        return(0);
                    }


                    // Copy from the unsafe pointer to a Byte array.
                    byte[] message = new byte[bytesRec];
                    Marshal.Copy(bytes, 0, (IntPtr)payload, bytesRec);

                    // Debug Show the data on the console.
                    Console.WriteLine("FYI: Recived {0} bytes from {1}", bytesRec, this.tcpClient.RemoteEndPoint.ToString());
                    Console.Write("    ");
                    Console.WriteLine(BitConverter.ToString(bytes).Replace("-", " ").Substring(0, bytesRec * 3)); // Convert bytes to HEX string.
                    return(bytesRec);
                }
                catch (System.Net.Sockets.SocketException e)
                {
                    if (e.ErrorCode == 10054)
                    {
                        // Client disconnected. This is normal.
                        return(0);
                    }
                    Console.WriteLine(e.ToString());
                    return(0);
                }
            }
Exemplo n.º 4
0
        public Geometry(IntPtr pRenderModel, out int nTexId)
        {
            unsafe
            {
                // Unpack all the RenderModel data
                void * ptr         = pRenderModel.ToPointer();
                IntPtr pVertexData = *(IntPtr *)ptr;
                ptr = (void *)((IntPtr *)ptr + 1);
                uint unVertexCount = *(uint *)pRenderModel.ToPointer();
                ptr = (void *)((uint *)ptr + 1);
                IntPtr pIndexData = *(IntPtr *)pRenderModel.ToPointer();
                ptr = (void *)((IntPtr *)ptr + 1);
                uint unIndexCount = *(uint *)pRenderModel.ToPointer();
                ptr    = (void *)((uint *)ptr + 1);
                nTexId = *(int *)pRenderModel.ToPointer();

                mGeometry = new float[3 * unVertexCount];
                mNormals  = new float[3 * unVertexCount];
                mUvs      = new float[2 * unVertexCount];

                Valve.VR.RenderModel_Vertex_t *vertexPtr = (Valve.VR.RenderModel_Vertex_t *)pVertexData.ToPointer();
                Valve.VR.RenderModel_Vertex_t  v;
                System.UInt16 *idxPtr = (System.UInt16 *)pIndexData.ToPointer();

                for (uint i = 0; i < unVertexCount; i++)
                {
                    v = *(vertexPtr + i);
                    mGeometry[3 * i + 0] = v.vPosition.v0;
                    mGeometry[3 * i + 1] = v.vPosition.v1;
                    mGeometry[3 * i + 2] = v.vPosition.v2;
                    mNormals[3 * i + 0]  = v.vNormal.v0;
                    mNormals[3 * i + 1]  = v.vNormal.v1;
                    mNormals[3 * i + 2]  = v.vNormal.v2;
                    mUvs[3 * i + 0]      = v.rfTextureCoord0;
                    mUvs[3 * i + 1]      = v.rfTextureCoord1;
                }

                for (uint i = 0; i < unIndexCount; i++)
                {
                    mGeometryIndices[i] = (int)*(idxPtr + i);
                }

                mNumPrimitives = (int)unIndexCount / 3;
                primitiveType  = OpenTK.Graphics.OpenGL4.BeginMode.Triangles;
            }
        }
            public int RecvMessage(System.UInt16 *connectionId, System.Byte *payload, System.UInt16 maxPayloadSize)
            {
                if (!_serialPort.IsOpen)
                {
                    return(0); // Serial port is not open, can't recive any bytes.
                }

                try
                {
                    byte[] incommingMessage     = new byte[maxPayloadSize];
                    int    incommingMessageSize = _serialPort.Read(incommingMessage, 0, maxPayloadSize);
                    if (incommingMessageSize <= 0)
                    {
                        // Nothing recived.
                        return(0);
                    }

                    // Copy from the unsafe pointer to a Byte array.
                    byte[] message = new byte[incommingMessageSize];
                    Marshal.Copy(incommingMessage, 0, (IntPtr)payload, incommingMessageSize);

                    // Debug Show the data on the console.
                    Console.WriteLine("FYI: Recived {0} bytes", incommingMessageSize);
                    Console.Write("    ");
                    Console.WriteLine(BitConverter.ToString(incommingMessage).Replace("-", " ").Substring(0, incommingMessageSize * 3)); // Convert bytes to HEX string.
                    return(incommingMessageSize);
                }
                catch (TimeoutException) {
                    // Timeout while wating
                    return(0);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return(0);
                }
            }