Exemple #1
0
        //args0 - filepath
        //args1 - resolution
        //args2 - xaxis
        //args3 - yaxis
        //args4 - zaxis
        //args5 - isoLevel
        public static void Main(string[] args)
        {
            DebugLog.resetLog();
            DebugLog.setDebug(true);
            int   resolution;
            float isoLevel;

            #region cmd args handling
            if (args.Length > 6 || args.Length < 1)
            {
                Console.Out.WriteLine(numArgs);
                Console.In.ReadLine();
                return;
            }
            if (args.Length == 1 && (args[0].ToLower() == "--help" || args[0].ToLower() == "help" || args[0].ToLower() == "?" || args[0].ToLower() == "h"))
            {
                Console.Out.WriteLine(help);
                Console.In.ReadLine();
                return;
            }

            if (!File.Exists(args[0]))
            {
                DebugLog.logConsole("Could not find file. Are you sure you are passing in the right string?");
                throw new Exception("Could not find file. Are you sure you are passing in the right string?");
            }
            try
            {
                resolution = Int32.Parse(args[1]);
            }
            catch
            {
                DebugLog.logConsole("Resolution not a number");
                throw new Exception("Resolution not a number");
            }
            try
            {
                isoLevel = float.Parse(args[5]);
            }
            catch
            {
                DebugLog.logConsole("IsoLevel is not a float");
                throw new Exception("IsoLevel is not a float");
            }
            if (resolution < 1)
            {
                DebugLog.logConsole("Resolution cannot be less than 1");
                throw new Exception("Resolution cannot be less than 1");
            }
            #endregion
            SingularMesh mcAlg       = new SingularMesh();
            string       dir         = Directory.GetParent(Directory.GetParent(Directory.GetParent(args[0]).FullName).FullName).Name;
            List <float> minMaxArray = generateMinMaxArray(new string[] { args[2], args[3], args[4] }, dir);


            VoxelArray array = mcAlg.createPointCloud(args[0], resolution, args[2], args[3], args[4], minMaxArray.ToArray());
            //VoxelArray.WriteFloatArray(mcAlg.outputPath + ".FARA", array);
            MarchingCubes test = new MarchingCubes();
            test.SetTarget(isoLevel);
            IM intermediate = test.CreateMesh(array.toFloatArray());
            if (intermediate.verts.Count > 64999)
            {
                IM[] divs = intermediate.divideIntoSmall();
                for (int i = 0; i < divs.Length; i++)
                {
                    divs[i].WriteIntermediateToFile(mcAlg.outputPath + "_" + i + ".IMF");
                }
            }
            else
            {
                intermediate.WriteIntermediateToFile(mcAlg.outputPath + ".IMF");
            }
        }
Exemple #2
0
        public void createMesh(ConcurrentStack <string> stack, int resolution, string[] axis, float[] minMaxArray, float isoLevel)
        {
            DebugLog.logConsole("Mesh creation thread started");
            totalMeshes = stack.Count;
            while (!stack.IsEmpty)
            {
                //If we fail popping, we may be attempting to access
                //at the same time as someone else. This means the stack
                //might have emptied since we last checked so we check again
                if (!stack.TryPop(out string file))
                {
                    continue;
                }
                //If we got this far, then we have a file
                DebugLog.logConsole(file + " has been selected");
                SingularMesh alg   = alg = new SingularMesh();
                VoxelArray   array = null;
                try
                {
                    array = alg.createPointCloud(file, resolution, axis[0], axis[1], axis[2], minMaxArray);
                }
                catch (Exception) { DebugLog.logConsole("Threading failed at array creation for " + file); }
                MarchingCubes test = new MarchingCubes();
                test.SetTarget(isoLevel);
                IM intermediate = null;
                try
                {
                    intermediate = test.CreateMesh(array.toFloatArray());
                }
                catch (Exception) { DebugLog.logConsole("Threading failed at intermediate creation for " + file); }
                try
                {
                    if (intermediate.verts.Count > 64999)
                    {
                        DebugLog.logConsole("Dividing " + file);
                        IM[] divs = intermediate.divideIntoSmall();
                        for (int i = 0; i < divs.Length; i++)
                        {
                            divs[i].WriteIntermediateToFile(alg.outputPath + "_" + i + ".IMF");
                        }
                    }
                    else
                    {
                        intermediate.WriteIntermediateToFile(alg.outputPath + ".IMF");
                    }
                    DebugLog.logConsole(alg.outputPath + ".IMF");
                }
                catch (Exception e) { DebugLog.logConsole(e.Message + "\n" + e.StackTrace + "\n" + file + "\n--------------------------------------------"); }

                array        = null;
                alg          = null;
                intermediate = null;

                try
                {
                    double perc = ((double)(totalMeshes - stack.Count) / (double)totalMeshes) * 100;
                    PercentageClass.UpdatePercentage("Creating Mesh", perc);
                    DebugLog.logConsole("Mesh Creation: " + perc.ToString("#.##") + "% total");
                }
                catch (Exception) { DebugLog.logConsole("Threading failed at percentage writing for " + file); }
            }
        }