示例#1
0
    public override bool Write(GH_IWriter writer)
    {
        var nn = new BinaryFormatter();

        writer.SetInt32("FunctionCount", this.Value.NeuronFunctions.Count);
        for (int i = 0, loopTo = this.Value.NeuronFunctions.Count - 1; i <= loopTo; i += 1)
        {
            using (var mstr = new MemoryStream())
            {
                nn.Serialize(mstr, this.Value.NeuronFunctions(i));
                writer.SetByteArray("Function_" + i, mstr.ToArray());
            }
        }

        using (var mstr = new MemoryStream())
        {
            Owl.Core.IO.WriteTensors(mstr, this.Value.Biases);
            writer.SetByteArray("Biases", mstr.ToArray());
        }

        using (var mstr = new MemoryStream())
        {
            Owl.Core.IO.WriteTensors(mstr, this.Value.Weights);
            writer.SetByteArray("Weights", mstr.ToArray());
        }

        return(true);
    }
示例#2
0
 public override bool Write(GH_IWriter writer)
 {
     try
     {
         if (Client != null)
         {
             using (var ms = new MemoryStream())
             {
                 var formatter = new BinaryFormatter();
                 formatter.Serialize(ms, Client);
                 var arr  = ms.ToArray();
                 var arrr = arr;
                 writer.SetByteArray("speckleclient", ms.ToArray());
                 writer.SetBoolean("remotecontroller", EnableRemoteControl);
                 writer.SetBoolean("manualmode", ManualMode);
                 writer.SetBoolean("DebouncingDisabled", DebouncingDisabled);
             }
         }
     }
     catch (Exception err)
     {
         throw err;
     }
     return(base.Write(writer));
 }
示例#3
0
        /*
         * public void DrawViewportMeshes(GH_PreviewMeshArgs args)
         * {
         *  if (DisplayMesh != null)
         *      args.Pipeline.DrawMeshShaded(DisplayMesh, args.Material);
         * }
         *
         * public void DrawViewportWires(GH_PreviewWireArgs args)
         * {
         *  if (DisplayMesh != null)
         *      args.Pipeline.DrawMeshWires(DisplayMesh, args.Color);
         * }
         */
        #region Serialization

        public override bool Write(GH_IWriter writer)
        {
            if (Value == null)
            {
                return(false);
            }
            byte[] centrelineBytes = GH_Convert.CommonObjectToByteArray(Value.Centreline);
            writer.SetByteArray("guide", centrelineBytes);

            //writer.SetInt32("num_frames", Value.Frames.Count);

            //for (int i = 0; i < Value.Frames.Count; ++i)
            //{
            //    Plane p = Value.Frames[i].Item2;
            //
            //    writer.SetPlane("frames", i, new GH_IO.Types.GH_Plane(
            //        p.OriginX, p.OriginY, p.OriginZ, p.XAxis.X, p.XAxis.Y, p.XAxis.Z, p.YAxis.X, p.YAxis.Y, p.YAxis.Z));
            //}

            writer.SetInt32("lcx", Value.Data.NumWidth);
            writer.SetInt32("lcy", Value.Data.NumHeight);
            writer.SetDouble("lsx", Value.Data.LamWidth);
            writer.SetDouble("lsy", Value.Data.LamHeight);
            writer.SetInt32("interpolation", (int)Value.Data.InterpolationType);
            writer.SetInt32("samples", Value.Data.Samples);


            return(true);
        }
示例#4
0
        /// <summary>
        /// This method is called whenever the instance is required to serialize itself.
        /// </summary>
        /// <param name="writer"> Writer object to serialize with. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool Write(GH_IWriter writer)
        {
            if (this.Value != null)
            {
                byte[] array = HelperMethods.ObjectToByteArray(this.Value);
                writer.SetByteArray(IoKey, array);
            }

            return(true);
        }
示例#5
0
        public override bool Write(GH_IWriter writer)
        {
            if (SelectedConstructor != null)
            {
                writer.SetByteArray("SelectedConstructor", ObjectToByteArray(SelectedConstructor));
            }

            writer.SetString("seed", Seed);
            return(base.Write(writer));
        }
示例#6
0
        public static void WriteCrossSectionOrientation(GH_IWriter writer, CrossSectionOrientation ori)
        {
            writer.SetString("orientation", ori.ToString());

            switch (ori)
            {
            case RmfOrientation rmf:
                return;

            case PlanarOrientation plan:
                var plane = plan.Plane;
                writer.SetPlane("orientation_plane", new GH_IO.Types.GH_Plane(
                                    plane.Origin.X, plane.Origin.Y, plane.Origin.Z,
                                    plane.XAxis.X, plane.XAxis.Y, plane.XAxis.Z,
                                    plane.YAxis.X, plane.YAxis.Y, plane.YAxis.Z

                                    ));
                return;

            case VectorOrientation vec:
                var v = (Vector3d)vec.GetDriver();
                writer.SetPoint3D("orientation_vector", new GH_IO.Types.GH_Point3D(v.X, v.Y, v.Z));
                return;

            case SurfaceOrientation srf:
                writer.SetByteArray("orientation_surface", GH_Convert.CommonObjectToByteArray(srf.GetDriver() as Brep));
                return;

            case VectorListOrientation vlist:
                writer.SetInt32("orientation_num_vectors", vlist.Vectors.Count);
                writer.SetByteArray("orientation_guide", GH_Convert.CommonObjectToByteArray(vlist.GetCurve()));
                for (int i = 0; i < vlist.Parameters.Count; ++i)
                {
                    writer.SetDouble("orientation_parameter", i, vlist.Parameters[i]);
                    writer.SetPoint3D("orientation_vector", i, new GH_IO.Types.GH_Point3D(
                                          vlist.Vectors[i].X, vlist.Vectors[i].Y, vlist.Vectors[i].Z));
                }
                return;

            default:
                return;
            }
        }
示例#7
0
        /// <summary>
        /// Serialization. Required by Grasshopper for data internalization.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <returns>True when successful.</returns>
        public bool Write(GH_IWriter writer)
        {
            var formatter = new BinaryFormatter();

            using (var dataStream = new System.IO.MemoryStream()) {
                try {
                    formatter.Serialize(dataStream, this);
                    writer.SetByteArray("SlotData", dataStream.ToArray());
                    return(true);
                } catch (SerializationException e) {
                    throw e;
                }
            }
        }
示例#8
0
        /*
         * public void DrawViewportMeshes(GH_PreviewMeshArgs args)
         * {
         *  if (DisplayMesh != null)
         *      args.Pipeline.DrawMeshShaded(DisplayMesh, args.Material);
         * }
         *
         * public void DrawViewportWires(GH_PreviewWireArgs args)
         * {
         *  if (DisplayMesh != null)
         *      args.Pipeline.DrawMeshWires(DisplayMesh, args.Color);
         * }
         */

        #region Serialization
        public override bool Write(GH_IWriter writer)
        {
            if (Value == null)
            {
                throw new Exception("GlulamParameter.Value is null.");
            }

            writer.SetByteArray("guide", GH_Convert.CommonObjectToByteArray(Value.Centreline));

            GH_Glulam.WriteCrossSectionOrientation(writer, Value.Orientation);
            GH_GlulamData.WriteGlulamData(writer, Value.Data);

            return(base.Write(writer));
        }
示例#9
0
        /// <summary>
        /// Serialises the current state of the component, making sure we save:
        /// - the optional property dictionary
        /// - the current type.
        /// </summary>
        /// <param name="writer"></param>
        /// <returns></returns>
        public override bool Write(GH_IWriter writer)
        {
            if (InputType != null)
            {
                writer.SetBoolean("init", true);
                writer.SetString("type", InputType.Name);
                writer.SetString("assembly", InputType.AssemblyQualifiedName);
                writer.SetByteArray("optionalmask", SpeckleCore.Converter.getBytes(OptionalPropsMask));
            }
            else
            {
                writer.SetBoolean("init", false);
            }

            return(base.Write(writer));
        }
 public override bool Write(GH_IWriter writer)
 {
     try
     {
         if (myReceiver != null)
         {
             using (var ms = new MemoryStream())
             {
                 var formatter = new BinaryFormatter();
                 formatter.Serialize(ms, myReceiver);
                 writer.SetByteArray("speckleclient", ms.ToArray());
             }
         }
     }
     catch { }
     return(base.Write(writer));
 }
 public override bool Write(GH_IWriter writer)
 {
     try
     {
         if (Client != null)
         {
             using (var ms = new MemoryStream())
             {
                 var formatter = new BinaryFormatter();
                 formatter.Serialize(ms, Client);
                 writer.SetByteArray("speckleclient", ms.ToArray());
             }
         }
         writer.SetBoolean("deserialize", this.Deserialize);
     }
     catch { }
     return(base.Write(writer));
 }
示例#12
0
 public override bool Write(GH_IWriter writer)
 {
     try
     {
         if (mySender != null)
         {
             using (var ms = new MemoryStream())
             {
                 var formatter = new BinaryFormatter();
                 formatter.Serialize(ms, mySender);
                 var arr  = ms.ToArray();
                 var arrr = arr;
                 writer.SetByteArray("speckleclient", ms.ToArray());
             }
         }
     }
     catch (Exception err)
     {
         throw err;
     }
     return(base.Write(writer));
 }
示例#13
0
 public override bool Write(GH_IWriter writer)
 {
     try
     {
         if (ObjectType != null)
         {
             using (var ms = new MemoryStream())
             {
                 var formatter = new BinaryFormatter();
                 formatter.Serialize(ms, ObjectType);
                 var arr  = ms.ToArray();
                 var arrr = arr;
                 writer.SetByteArray("objectype", ms.ToArray());
             }
         }
     }
     catch (Exception err)
     {
         throw err;
     }
     return(base.Write(writer));
 }
 /// <summary>
 /// Add our own fields. Needed for (de)serialization of the variable input parameters.
 /// </summary>
 /// <param name="writer"> Provides access to a subset of GH_Chunk methods used for writing archives. </param>
 /// <returns> True on success, false on failure. </returns>
 public override bool Write(GH_IWriter writer)
 {
     byte[] array = RobotComponents.Utils.HelperMethods.ObjectToByteArray(_robotPreset);
     writer.SetByteArray("Robot Preset", array);
     return(base.Write(writer));
 }
示例#15
0
 private static void WriteGeometryBase(GH_IWriter writer, GeometryBase data)
 {
     writer.SetString("DataType", "GeometryBase");
     byte[] bytes = GH_Convert.CommonObjectToByteArray(data);
     writer.SetByteArray("Data", bytes);
 }