Ejemplo n.º 1
0
    void StartImp()
    {
        if (ImpType == ImpTypeEnum.ILamp)
        {
            ImpPlugin.Imp_Create_ILamp();
            ImpPlugin.Imp_ILamp_Setup(ILampParams.KdTreeCount, ILampParams.NumNeighbours, ILampParams.KnnSearchChecks);
        }
        else
        {
            ImpPlugin.Imp_Create_Rbp();
            ImpPlugin.Imp_Rbf_Setup((ushort)(RbfParams.Function), RbfParams.Constant);
        }


        System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
        customCulture.NumberFormat.NumberDecimalSeparator    = ".";
        System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;


        if (!ImpPlugin.Imp_ExecutePcaImages(FileNameImageList, FileNameNd))
        {
            Debug.LogError("Could not execute pca for images: " + FileNameImageList);
            enabled = false;
            return;
        }

        if (!ImpPlugin.Imp_ExecuteLamp(FileNameNd, FileName2d))
        {
            Debug.LogError("Could not run lamp for " + FileNameNd + ' ' + FileName2d);
            enabled = false;
            return;
        }


        if (!ImpPlugin.Imp_LoadInputFiles(FileName2d, FileNameNd))
        {
            Debug.LogError("Could not load input files: " + FileName2d + ' ' + FileNameNd);
            enabled = false;
            return;
        }

        if (!ImpPlugin.Imp_Build())
        {
            Debug.LogError("Could not build imp");
            enabled = false;
            return;
        }


        using (System.IO.TextReader reader = System.IO.File.OpenText(FileName2d))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                string[] v_str = line.Split();

                float x, y = 0;
                if (float.TryParse(v_str[0], out x) && float.TryParse(v_str[1], out y))
                {
                    vertices2d.Add(new Vector2(x, y));
                }
            }

            reader.Close();
        }



        if (ImpPlugin.Imp_Execute(vertices2d[0].x, vertices2d[0].y))
        {
            if (q_data == null) // q_data.Count must be (3 * vertices.Length)
            {
                q_data   = new float[ImpPlugin.Imp_QRows() * ImpPlugin.Imp_QCols()];
                q_handle = GCHandle.Alloc(q_data, GCHandleType.Pinned);
            }
        }
        else
        {
            Debug.LogError("Could not run imp");
            enabled = false;
            return;
        }


        impUI = (ImpUI)FindObjectOfType(typeof(ImpUI));
        if (impUI)
        {
            impUI.Setup(vertices2d, MinCoords, MaxCoords);
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        if (templateMesh == null)
        {
            Debug.LogError("Template Mesh is null. Did you forget to fill inspector fields?");
            enabled = false;
            return;
        }

        //
        // Check if the number of meshes and vertices matches
        //
        foreach (var m in baseMeshes)
        {
            if (m == null)
            {
                Debug.LogError("Mesh is null. Did you forget to fill inspector fields?");
                enabled = false;
                return;
            }
        }
        foreach (var ml in laplaceMeshes)
        {
            if (baseMeshes.Length != ml.MeshList.Length)
            {
                Debug.LogError("The number of meshes does not match: " + baseMeshes.Length + " != " + ml.MeshList.Length);
                enabled = false;
                return;
            }

            if (ml.MeshList[0] == null)
            {
                Debug.LogError("Mesh is null. Did you forget to fill inspector fields?");
                enabled = false;
                return;
            }

            var vertCount = ml.MeshList[0].mesh.vertexCount;
            for (int i = 1; i < ml.MeshList.Length; ++i)
            {
                if (ml.MeshList[i] == null)
                {
                    Debug.LogError("Mesh null. Did you forget to fill inspector fields?");
                    enabled = false;
                    return;
                }

                if (vertCount != ml.MeshList[i].mesh.vertexCount)
                {
                    Debug.LogError("The number of vertices does not match: " + ml.MeshList[i].name);
                    enabled = false;
                    return;
                }
            }
        }

        //Debug.Log("Building ILamp for base meshes: " + FileNameNd);
        if (!BuildILamp(baseMeshes, FileName2d, FileNameNd))
        {
            enabled = false;
            return;
        }

        foreach (var ml in laplaceMeshes)
        {
            //Debug.Log("Building ILamp for laplace meshes: " + ml.FileName);
            if (!BuildILamp(ml.MeshList, FileName2d, ml.FileName))
            {
                enabled = false;
                return;
            }
        }
        ImpPlugin.Imp_SetCurrent(0);


        using (System.IO.TextReader reader = System.IO.File.OpenText(FileName2d))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                string[] v_str = line.Split();

                float x, y = 0;
                if (float.TryParse(v_str[0], out x) && float.TryParse(v_str[1], out y))
                {
                    vertices2d.Add(new Vector2(x, y));
                }
            }

            reader.Close();
        }


        if (ImpPlugin.Imp_Execute(vertices2d[0].x, vertices2d[0].y))
        {
            if (q_data == null) // q_data.Count must be (3 * vertices.Length)
            {
                //q_data = new float[ImpPlugin.Imp_QRows() * ImpPlugin.Imp_QCols()];
                q_data   = new Vector3[templateMesh.mesh.vertexCount];
                q_handle = GCHandle.Alloc(q_data, GCHandleType.Pinned);
            }

            if (q_data_laplace == null)
            {
                q_data_laplace   = new Vector3[templateMesh.mesh.vertexCount];
                q_handle_laplace = GCHandle.Alloc(q_data_laplace, GCHandleType.Pinned);
            }
        }
        else
        {
            Debug.LogError("Could not run imp");
            enabled = false;
            return;
        }


        impUI = (ImpUI)FindObjectOfType(typeof(ImpUI));
        if (impUI)
        {
            impUI.Setup(vertices2d, MinCoords, MaxCoords);
        }
    }