Пример #1
0
        public static bool deciferImageDataFromBody(String msgBody, out ImageDataRequest imageData)
        {
            imageData = new ImageDataRequest();

            String jsonString = Utils.DecodeFrom64(msgBody);

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var jsonObject = serializer.DeserializeObject(jsonString) as Dictionary<string, object>;
            Dictionary<String, Object> jsonDict = (Dictionary<String, Object>)jsonObject;

            if (!jsonDict.ContainsKey("operation"))
            {
                Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"operation\"))");
                return false;
            }
            else imageData.operation = (String)jsonDict["operation"];

            if (!jsonDict.ContainsKey("gh_file"))
            {
                Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"gh_file\"))");
                return false;
            }
            else imageData.gh_fileName = (String)jsonDict["gh_file"];

            if (!jsonDict.ContainsKey("item_id"))
            {
                Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"item_id\"))");
                return false;
            }
            else imageData.item_id = (String)jsonDict["item_id"];

            if (jsonDict.ContainsKey("scene"))
            {
                imageData.scene = (String)jsonDict["scene"];
            }
            else imageData.scene = null;

            if (!jsonDict.ContainsKey("bake"))
            {
                Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"bake\"))");
                return false;
            }
            else imageData.bake = (String)jsonDict["bake"];

            if (!jsonDict.ContainsKey("width"))
            {
                Console.WriteLine("INFO - (!jsonDict.ContainsKey(\"width\"))");
                imageData.imageSize.Width = 180;
            }
            else imageData.imageSize.Width = (int)jsonDict["width"];

            if (!jsonDict.ContainsKey("height"))
            {
                Console.WriteLine("INFO - (!jsonDict.ContainsKey(\"height\"))");
                imageData.imageSize.Height = 180;
            }
            else imageData.imageSize.Height = (int)jsonDict["height"];

            if (!jsonDict.ContainsKey("layer_name"))
            {
                imageData.layerName = "Default";
            }
            else
            {
                imageData.layerName = (String)jsonDict["layer_name"];
            }

            if (!jsonDict.ContainsKey("params"))
            {
                Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"params\"))");
                return false;
            }
            else
            {

                Dictionary<String, Double> paramValues = new Dictionary<string, double>();
                imageData.propValues = (Dictionary<String, Object>)jsonDict["params"];
            }
            return true;
        }
Пример #2
0
        private bool Render(ImageDataRequest imageData, out String outputPath)
        {
            outputPath = Runing_Form.images_DirPath + Path.DirectorySeparatorChar + "yofi_" + imageData.item_id + ".jpg";
            try
            {

                DateTime beforeTime = DateTime.Now;
                String captureCommand = "-FlamingoRenderTo f " + outputPath + " " + imageData.imageSize.Width + " " + imageData.imageSize.Height;
                int captureCommandRes = rhino_wrapper.rhino_app.RunScript(captureCommand, 1);

                int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds);
                MyLog("After rendering by: " + captureCommand + "  into" + outputPath + " After " + fromStart + " milliseconds");

            }
            catch (Exception e)
            {
                MyLog("Excpetion in Render(imageData=" + imageData.ToString() + ", String outputPath=" + outputPath + ", e.Message=" + e.Message);
                return false;
            }

            return true;
        }
Пример #3
0
        public bool Set_GH_Params(ImageDataRequest imageData)
        {
            MyLog("Starting Set_Params_And_Render(ImageData imageData=" + imageData.ToString() + ")");
            DateTime beforeTime = DateTime.Now;
            String logLine;
            int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds);

            foreach (String paramName in imageData.propValues.Keys)
            {
                Object value = imageData.propValues[paramName];
                if (!rhino_wrapper.grasshopper.AssignDataToParameter(paramName, value))
                {
                    fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds);
                    logLine = "grasshopper.AssignDataToParameter(paramName=" + paramName + ", value=" + value + ") returned false After " + fromStart + " milliseconds";
                    MyLog(logLine);
                    return false;
                }

                fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds);
                logLine = "After assigning param:" + paramName + " the value=" + value + " After " + fromStart + " milliseconds";
                MyLog(logLine);

            }

            rhino_wrapper.grasshopper.RunSolver(true);

            Object objRes = rhino_wrapper.grasshopper.BakeDataInObject(imageData.bake);

            fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds);
            logLine = "After baking object:" + imageData.bake + " After " + fromStart + " milliseconds";
            MyLog(logLine);

            return true;
        }
Пример #4
0
        private bool Process_Into_Image_File(ImageDataRequest imageData, out String localImageFilePath, out TimeSpan renderTime, out TimeSpan buildTime, out TimeSpan waitTime)
        {
            DateTime beforeTime = DateTime.Now;

            String logLine = "Starting Get_Pictures()";
            MyLog(logLine);
            localImageFilePath = String.Empty;
            renderTime = new TimeSpan();
            buildTime = new TimeSpan();
            waitTime = new TimeSpan();

            if ((current_Rhino_File != null) && (imageData.scene != current_Rhino_File))
            {
                // Close previous rhino
                try
                {
                    brutally_killPrivRhino();
                }
                catch (Exception e)
                {
                    MyLog("Exception in Process_Into_Image_File(1). e.Message=" + e.Message);
                    return false;
                }

                DateTime beforeWait = DateTime.Now;

                if (!waitForRhinoFromQueue(out rhino_wrapper, 150, 100))
                {
                    MyLog("waitForRhinoFromQueue() failed!!!");
                    return false;
                }

                waitTime = DateTime.Now - beforeWait;

                current_Rhino_File = null;
                current_GH_file = null;
            }
            if (imageData.scene != null)
            {
                if (imageData.scene != current_Rhino_File)
                {
                    String sceneFilePath = Runing_Form.scenes_DirPath + Path.DirectorySeparatorChar + imageData.scene;
                    if (!File.Exists(sceneFilePath))
                    {
                        return false;
                    }

                    Console.WriteLine("Loading scene Rhino # " + id + " at " + DateTime.Now);
                    String openCommand = "-Open " + sceneFilePath;
                    int openCommandRes = rhino_wrapper.rhino_app.RunScript(openCommand, 1);

                    int isInitialized = rhino_wrapper.rhino_app.IsInitialized();
                    if (isInitialized != 1)
                    {
                        MyLog("ERROR!!: " + isInitialized + "==isInitialized != 1)");
                        return false;
                    }

                    current_Rhino_File = imageData.scene;
                }
            }

            if (!DeleteAll())
            {
                MyLog("ERROR!!: DeleteAll() failed !!!");
                return false;
            }

            if (!setDefaultLayer(imageData.layerName))
            {
                MyLog("ERROR!!: setDefaultLayer(layerName=" + imageData.layerName + ") failed !!!");
                return false;
            }

            if (imageData.gh_fileName.EndsWith(".gh") || imageData.gh_fileName.EndsWith(".ghx"))
            {

                if (current_GH_file == imageData.gh_fileName)
                {
                    logLine = "Skipping Open_GH_File(imageData[imageData.gh_filePath=" + imageData.gh_fileName + ")";
                    MyLog(logLine);
                }
                else
                {
                    if (!Open_GH_File(Runing_Form.GH_DirPath + Path.DirectorySeparatorChar + imageData.gh_fileName))
                    {
                        logLine = "Open_GH_File(imageData[imageData.gh_filePath=" + imageData.gh_fileName + "); failed";
                        MyLog(logLine);
                        return false;
                    }
                    current_GH_file = imageData.gh_fileName;
                }

                if (!Set_GH_Params(imageData))
                {
                    logLine = "Set_Params(imageData=" + imageData.ToString() + "]) failed !!!";
                    MyLog(logLine);
                    return false;
                }
            }
            else
            {
                if (!Run_Script(imageData))
                {
                    logLine = "Run_Script(imageData=" + imageData.ToString() + "]) failed !!!";
                    MyLog(logLine);
                    return false;
                }
            }

            buildTime = DateTime.Now - beforeTime;

            String resultingImagePath;
            if (!Render(imageData, out resultingImagePath))
            {
                MyLog("Render(imageData=" + imageData.ToString() + ") failed !!!");
                return false;
            }

            renderTime = (DateTime.Now - beforeTime) - buildTime;
            localImageFilePath = resultingImagePath;

            DateTime afterTime = DateTime.Now;
            int timed = (int)((afterTime - beforeTime).TotalMilliseconds);
            MyLog("Total Get_Pictures() call took " + timed + " millseconds");
            return true;
        }
Пример #5
0
        public bool Run_Script(ImageDataRequest imageData)
        {
            MyLog("Starting Run_Script_And_Render(ImageData imageData=" + imageData.ToString() + "))");
            DateTime beforeTime = DateTime.Now;
            try
            {
                String commParams = "";
                List<String> stringValues = new List<string>();
                foreach (String paramName in imageData.propValues.Keys)
                {
                    Object propValue = imageData.propValues[paramName];
                    Type propValueType = propValue.GetType();
                    if (propValueType == typeof(Double) || propValueType == typeof(Decimal))
                    {
                        commParams = commParams + " " + paramName + "=" + imageData.propValues[paramName].ToString();
                    }
                    else if (propValue.GetType() == typeof(String))
                    {
                        stringValues.Add((String)propValue);
                    }
                }

                //String runCommand = "vase1 rad1=0.2 rad2=0.42 rad3=0.6 rad4=0.5 Enter";
                String runCommand = imageData.gh_fileName + " " + commParams + " Enter";
                foreach (String value in stringValues)
                {
                    runCommand += " " + value + " Enter";
                }
                rhino_wrapper.rhino_app.RunScript(runCommand, 1);
            }
            catch (Exception e)
            {
                MyLog("Exception in Run_Script_And_Render(). e.Message=" + e.Message);
                return false;
            }

            int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds);
            MyLog("Script ran After " + fromStart + " milliseconds");

            return true;
        }