示例#1
0
    public void Prediction(Vector3 direction, float ratio)
    {
        double timeBeforeTotal = Time.realtimeSinceStartup;

        client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        client.Connect(IP, Port);
        sendData = System.Text.Encoding.ASCII.GetBytes(direction[0].ToString("G4") + "," + direction[1].ToString("G4") + "," + direction[2].ToString("G4") + "," + ratio.ToString("G4"));

        client.Send(sendData);
        byte[] b = new byte[100];

        int k = client.Receive(b);

        //   Debug.Log("Time for receiving data: " + (timeAfter - timeBefore).ToString());
        double timeAfterTotal = Time.realtimeSinceStartup;
        //    Debug.Log("Time for sending data1: " + (timeAfterTotal - timeBeforeTotal).ToString());

        string     tumorInfor  = System.Text.Encoding.ASCII.GetString(b, 0, k);
        GameObject tumor       = GameObject.Find("Tumor");
        Tumor      tumorScript = tumor.GetComponent <Tumor>();

        tumorScript.PredictionLocationParse(tumorInfor);

        string  szReceived = " ";
        Vector3 vertex;

        StreamReader reader = Reader("F:/Research/FEA simulation for NN/train_patient_specific/disp_prediction.txt");

        szReceived = reader.ReadLine();

        reader.Close();
        //    Debug.Log("Time for sending data2: " + (Time.realtimeSinceStartup - timeBeforeTotal).ToString());

        List <int> indices = new List <int>();
        ColorCode  newClor = new ColorCode();

        if (client.Connected)
        {
            disp = new List <Vector3>();
            string[] words = szReceived.Split(',');

            for (int i = 0; i < words.Length - 4; i += 4)
            {
                int   index = int.Parse(words[i]);
                float x     = float.Parse(words[i + 1]) * scale;
                float y     = float.Parse(words[i + 2]) * scale;
                float z     = float.Parse(words[i + 3]) * scale;
                disp.Add(new Vector3(x, y, z));
                indices.Add(index);
            }
            double timeAfter = Time.realtimeSinceStartup;

            List <Vector3> verticesAfterDisp = MoveVerticesThreshold(vertices, disp, indices);

            double timeBefore = Time.realtimeSinceStartup;
            mesh.vertices = verticesAfterDisp.ToArray();
            newClor.AddColor(mesh, disp, indices, trianglesUnique);
        }
        else
        {
            Debug.Log(" Not Connected");
        }
        // Debug.Log("Time for sending data3: " + (Time.realtimeSinceStartup - timeBeforeTotal).ToString());
        client.Close();
    }