コード例 #1
0
    public override bool Read(GH_IReader reader)
    {
        var       nn = new BinaryFormatter();
        var       f  = new List <Owl.Learning.NeuronFunctions.NeuronFunctionBase>();
        int       fc = reader.GetInt32("FunctionCount");
        TensorSet w  = default;
        TensorSet b  = default;

        for (int i = 0, loopTo = fc - 1; i <= loopTo; i += 1)
        {
            using (var mstr = new MemoryStream(reader.GetByteArray("Function_" + i)))
            {
                f.Add(nn.Deserialize(mstr));
            }
        }

        using (var mstr = new MemoryStream(reader.GetByteArray("Biases")))
        {
            b = Owl.Core.IO.ReadTensors(mstr);
        }

        using (var mstr = new MemoryStream(reader.GetByteArray("Weigths")))
        {
            w = Owl.Core.IO.ReadTensors(mstr);
        }

        this.Value = new Owl.Learning.Networks.Network(w, b, f);
        return(true);
    }
コード例 #2
0
        public override bool Read(GH_IReader reader)
        {
            try
            {
                var serialisedClient = reader.GetByteArray("speckleclient");
                var copy             = serialisedClient;
                using (var ms = new MemoryStream())
                {
                    ms.Write(serialisedClient, 0, serialisedClient.Length);
                    ms.Seek(0, SeekOrigin.Begin);
                    mySender = (SpeckleApiClient) new BinaryFormatter().Deserialize(ms);
                    var x = mySender;
                    RestApi       = mySender.BaseUrl;
                    StreamId      = mySender.StreamId;
                    WasSerialised = true;
                }

                reader.TryGetBoolean("remotecontroller", ref EnableRemoteControl);
                reader.TryGetBoolean("manualmode", ref ManualMode);
            }
            catch (Exception err)
            {
                throw err;
            }
            return(base.Read(reader));
        }
コード例 #3
0
        public override bool Read(GH_IReader reader)
        {
            try
            {
                var serialisedClient = reader.GetByteArray("speckleclient");
                var copy             = serialisedClient;
                using (var ms = new MemoryStream())
                {
                    ms.Write(serialisedClient, 0, serialisedClient.Length);
                    ms.Seek(0, SeekOrigin.Begin);
                    Client            = (SpeckleApiClient) new BinaryFormatter().Deserialize(ms);
                    Client.ClientType = "Grasshopper";
                    RestApi           = Client.BaseUrl;
                    StreamId          = Client.StreamId;
                    WasSerialised     = true;
                }

                reader.TryGetBoolean("remotecontroller", ref EnableRemoteControl);
                reader.TryGetBoolean("manualmode", ref ManualMode);
                reader.TryGetBoolean("DebouncingDisabled", ref DebouncingDisabled);
            }
            catch (Exception err)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Failed to reinitialise sender.");
            }
            return(base.Read(reader));
        }
コード例 #4
0
        private static GeometryBase ReadGeometryBase(GH_IReader reader)
        {
            var bytes         = reader.GetByteArray("Data");
            var valueInstance = GH_Convert.ByteArrayToCommonObject <GeometryBase>(bytes);

            return(valueInstance);
        }
コード例 #5
0
        /// <summary>
        /// De-serialization. Required by Grasshopper for data internalization.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>True when successful.</returns>
        public bool Read(GH_IReader reader)
        {
            var formatter = new BinaryFormatter();

            if (reader.ItemExists("SlotData"))
            {
                var slotBytes = reader.GetByteArray("SlotData");
                using (var slotDataStream = new System.IO.MemoryStream(slotBytes)) {
                    try {
                        var slot = (Slot)formatter.Deserialize(slotDataStream);
                        BasePlane          = slot.BasePlane;
                        RelativeCenter     = slot.RelativeCenter;
                        Diagonal           = slot.Diagonal;
                        AllowsAnyModule    = slot.AllowsAnyModule;
                        AllowedModuleNames = slot.AllowedModuleNames;
                        AllowedPartNames   = slot.AllowedPartNames;
                        AllPartsCount      = slot.AllPartsCount;
                        return(true);
                    } catch (SerializationException e) {
                        throw e;
                    }
                }
            }

            return(false);
        }
コード例 #6
0
        public override bool Read(GH_IReader reader)
        {
            try
            {
                Debug.WriteLine("Trying to read client!");
                var serialisedClient = reader.GetByteArray("speckleclient");
                using (var ms = new MemoryStream())
                {
                    ms.Write(serialisedClient, 0, serialisedClient.Length);
                    ms.Seek(0, SeekOrigin.Begin);
                    myReceiver = (SpeckleApiClient) new BinaryFormatter().Deserialize(ms);

                    StreamId  = myReceiver.StreamId;
                    AuthToken = myReceiver.AuthToken;
                    RestApi   = myReceiver.BaseUrl;

                    InitReceiverEventsAndGlobals();
                }
            }
            catch
            {
                Debug.WriteLine("No client was present.");
            }
            return(base.Read(reader));
        }
コード例 #7
0
        /// <summary>
        /// Makes sure we deserialise correctly, and reinstate everything there is to reinstate:
        /// - type properties
        /// - optional properties
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public override bool Read(GH_IReader reader)
        {
            bool isInit = reader.GetBoolean("init");

            if (isInit)
            {
                var selectedTypeName     = reader.GetString("type");
                var selectedTypeAssembly = reader.GetString("assembly");
                var myOptionalProps      = SpeckleCore.Converter.getObjFromBytes(reader.GetByteArray("optionalmask")) as Dictionary <string, bool>;

                var selectedType = SpeckleCore.SpeckleInitializer.GetTypes().FirstOrDefault(t => t.Name == selectedTypeName && t.AssemblyQualifiedName == selectedTypeAssembly);
                if (selectedType != null)
                {
                    SwitchToType(selectedType);
                    OptionalPropsMask = myOptionalProps;

                    var optionalProps = typeof(SpeckleCore.SpeckleObject).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(pinfo => pinfo.Name != "Type");
                    foreach (var kvp in OptionalPropsMask)
                    {
                        if (kvp.Value)
                        {
                            RegisterPropertyAsInputParameter(optionalProps.First(p => p.Name == kvp.Key), Params.Input.Count);
                        }
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Type {0} from the {1} kit was not found. Are you sure you have it installed?", selectedTypeName, selectedTypeAssembly));
                }
            }

            return(base.Read(reader));
        }
コード例 #8
0
        public static CrossSectionOrientation ReadCrossSectionOrientation(GH_IReader reader)
        {
            var type = reader.GetString("orientation");

            switch (type)
            {
            case "RmfOrientation":
                return(new RmfOrientation());

            case "PlanarOrientation":
                var plane = reader.GetPlane("orientation_plane");

                return(new PlanarOrientation(new Plane(
                                                 new Point3d(plane.Origin.x, plane.Origin.y, plane.Origin.z),
                                                 new Vector3d(plane.XAxis.x, plane.XAxis.y, plane.XAxis.z),
                                                 new Vector3d(plane.YAxis.x, plane.YAxis.y, plane.YAxis.z))));

            case "VectorOrientation":
                var pt = reader.GetPoint3D("orientation_vector");
                return(new VectorOrientation(new Vector3d(pt.x, pt.y, pt.z)));

            case "SurfaceOrientation":
                var srf_bytes = reader.GetByteArray("orientation_surface");
                var srf       = GH_Convert.ByteArrayToCommonObject <Brep>(srf_bytes);
                return(new SurfaceOrientation(srf));

            case "VectorListOrientation":
                var vlguide = reader.GetByteArray("orientation_guide");

                var             num_vecs   = reader.GetInt32("orientation_num_vectors");
                List <Vector3d> vectors    = new List <Vector3d>();
                List <double>   parameters = new List <double>();

                for (int i = 0; i < num_vecs; ++i)
                {
                    var v = reader.GetPoint3D("orientation_vector", i);
                    var t = reader.GetDouble("orientation_parameter", i);
                    vectors.Add(new Vector3d(v.x, v.y, v.z));
                }
                return(new VectorListOrientation(GH_Convert.ByteArrayToCommonObject <Curve>(vlguide), parameters, vectors));

            default:
                return(new RmfOrientation());
            }
        }
コード例 #9
0
        /// <summary>
        /// This method is called whenever the instance is required to deserialize itself.
        /// </summary>
        /// <param name="reader"> Reader object to deserialize from. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool Read(GH_IReader reader)
        {
            if (!reader.ItemExists(IoKey))
            {
                this.Value = null;
                return(true);
            }

            byte[] array = reader.GetByteArray(IoKey);
            this.Value = (RobotJointPosition)HelperMethods.ByteArrayToObject(array);

            return(true);
        }
コード例 #10
0
        /// <summary>
        /// This method is called whenever the instance is required to deserialize itself.
        /// </summary>
        /// <param name="reader"> Reader object to deserialize from. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool Read(GH_IReader reader)
        {
            if (!reader.ItemExists(IoKey))
            {
                this.Value = null;
                return(true);
            }

            byte[] array = reader.GetByteArray(IoKey);
            this.Value = (ExternalRotationalAxis)HelperMethods.ByteArrayToObject(array);

            return(true);
        }
コード例 #11
0
        /// <summary>
        /// This method is called whenever the instance is required to deserialize itself.
        /// </summary>
        /// <param name="reader"> Reader object to deserialize from. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool Read(GH_IReader reader)
        {
            if (!reader.ItemExists(IoKey))
            {
                this.Value = null;
                return(true);
            }

            byte[] array = reader.GetByteArray(IoKey);
            this.Value = (LinearConfigurationControl)HelperMethods.ByteArrayToObject(array);

            return(true);
        }
コード例 #12
0
        public override bool Read(GH_IReader reader)
        {
            try
            {
                SelectedConstructor = ByteArrayToObject <ConstructorInfo>(reader.GetByteArray("SelectedConstructor"));
            }
            catch { }

            try
            {
                Seed = reader.GetString("seed");
            }
            catch { }
            return(base.Read(reader));
        }
コード例 #13
0
 public override bool Read(GH_IReader reader)
 {
     try
     {
         var objectType = reader.GetByteArray("objectype");
         var copy       = objectType;
         using (var ms = new MemoryStream())
         {
             ms.Write(objectType, 0, objectType.Length);
             ms.Seek(0, SeekOrigin.Begin);
             ObjectType = (Type) new BinaryFormatter().Deserialize(ms);
             var x = ObjectType;
         }
         UpdateInputs();
     }
     catch (Exception err)
     {
         this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Failed to reinitialise sender.");
         //throw err;
     }
     return(base.Read(reader));
 }
コード例 #14
0
 public override bool Read(GH_IReader reader)
 {
     try
     {
         var serialisedClient = reader.GetByteArray("speckleclient");
         var copy             = serialisedClient;
         using (var ms = new MemoryStream())
         {
             ms.Write(serialisedClient, 0, serialisedClient.Length);
             ms.Seek(0, SeekOrigin.Begin);
             mySender = (SpeckleApiClient) new BinaryFormatter().Deserialize(ms);
             var x = mySender;
             RestApi  = mySender.BaseUrl;
             StreamId = mySender.StreamId;
         }
     }
     catch (Exception err)
     {
         throw err;
     }
     return(base.Read(reader));
 }
コード例 #15
0
        public override bool Read(GH_IReader reader)
        {
            if (!reader.ItemExists("guide"))
            {
                Value = null;
                throw new Exception("Couldn't retrieve 'guide'.");
            }

            Curve guide = GH_Convert.ByteArrayToCommonObject <Curve>(reader.GetByteArray("guide"));

            if (guide == null)
            {
                throw new Exception("Failed to convert 'guide'.");
            }

            CrossSectionOrientation ori = GH_Glulam.ReadCrossSectionOrientation(reader);
            GlulamData data             = GH_GlulamData.ReadGlulamData(reader);

            Value = Glulam.CreateGlulam(guide, ori, data);

            return(base.Read(reader));
        }
コード例 #16
0
        /// <summary>
        /// Makes sure we deserialise correctly, and reinstate everything there is to reinstate:
        /// - selected type properties
        /// - optional properties
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public override bool Read(GH_IReader reader)
        {
            bool isInit = reader.GetBoolean("init");

            if (isInit)
            {
                var selectedTypeName     = reader.GetString("type");
                var selectedTypeAssembly = reader.GetString("assembly");
                var myOptionalProps      = SpeckleCore.Converter.getObjFromBytes(reader.GetByteArray("optionalmask")) as Dictionary <string, bool>;

                var selectedType = SpeckleCore.SpeckleInitializer.GetTypes().FirstOrDefault(t => t.Name == selectedTypeName); //&& t.AssemblyQualifiedName == selectedTypeAssembly );
                SelectedType = selectedType;
                Message      = SelectedType.Name;

                GenerateOptionalPropsMenu(myOptionalProps);

                if (selectedType == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Type {0} from the {1} kit was not found. Are you sure you have it installed?", selectedTypeName, selectedTypeAssembly));
                }
            }

            return(base.Read(reader));
        }
コード例 #17
0
        public override bool Read(GH_IReader reader)
        {
            if (!reader.ItemExists("guide"))
            {
                Value = null;
                throw new Exception("Couldn't retrieve 'guide'.");
            }

            byte[] rawGuide = reader.GetByteArray("guide");

            Curve guide = GH_Convert.ByteArrayToCommonObject <Curve>(rawGuide);

            if (guide == null)
            {
                throw new Exception("Failed to convert 'guide'.");
            }

            int N = reader.GetInt32("num_frames");

            Plane[] frames = new Plane[N];

            for (int i = 0; i < N; ++i)
            {
                var gp = reader.GetPlane("frames", i);
                frames[i] = new Plane(
                    new Point3d(
                        gp.Origin.x,
                        gp.Origin.y,
                        gp.Origin.z),
                    new Vector3d(
                        gp.XAxis.x,
                        gp.XAxis.y,
                        gp.XAxis.z),
                    new Vector3d(
                        gp.YAxis.x,
                        gp.YAxis.y,
                        gp.YAxis.z)
                    );
            }

            int    lcx           = reader.GetInt32("lcx");
            int    lcy           = reader.GetInt32("lcy");
            double lsx           = reader.GetDouble("lsx");
            double lsy           = reader.GetDouble("lsy");
            int    interpolation = reader.GetInt32("interpolation");
            int    samples       = reader.GetInt32("samples");

            GlulamData data = new GlulamData(lcx, lcy, lsx, lsy, samples);

            data.InterpolationType = (GlulamData.Interpolation)interpolation;

            Value = Glulam.CreateGlulam(guide, frames, data);

            if (Value == null)
            {
                throw new Exception("What in the Lord's name...");
            }
            //DisplayMesh = Value.GetBoundingMesh();

            return(true);
        }
コード例 #18
0
 /// <summary>
 /// Read our own fields. Needed for (de)serialization of the variable input parameters.
 /// </summary>
 /// <param name="reader"> Provides access to a subset of GH_Chunk methods used for reading archives. </param>
 /// <returns> True on success, false on failure. </returns>
 public override bool Read(GH_IReader reader)
 {
     byte[] array = reader.GetByteArray("Robot Preset");
     _robotPreset = (RobotPreset)RobotComponents.Utils.HelperMethods.ByteArrayToObject(array);
     return(base.Read(reader));
 }