/// <summary>
        /// Return a copy of this object.
        /// </summary>
        /// <returns>A new copy of the object is returned.</returns>
        public DataLabelMappingParameter Clone()
        {
            DataLabelMappingParameter p = new DataLabelMappingParameter(Active);

            p.Copy(this);
            return(p);
        }
        /** @copydoc LayerParameterBase::Copy */
        public override void Copy(LayerParameterBase src)
        {
            TransformationParameter p = (TransformationParameter)src;

            m_bUseImageDbMean          = p.m_bUseImageDbMean;
            m_bForceColor              = p.m_bForceColor;
            m_bForceGray               = p.m_bForceGray;
            m_bMirror                  = p.m_bMirror;
            m_dfScale                  = p.m_dfScale;
            m_scaleOperator            = p.m_scaleOperator;
            m_nCropSize                = p.m_nCropSize;
            m_rgMeanValue              = Utility.Clone <double>(p.m_rgMeanValue);
            m_dfForcedPositiveRangeMax = p.m_dfForcedPositiveRangeMax;
            m_nRandomSeed              = p.m_nRandomSeed;
            m_strMeanFile              = p.m_strMeanFile;
            m_colorOrder               = p.m_colorOrder;

            m_resize         = (p.resize_param == null) ? null : p.resize_param.Clone();
            m_noise          = (p.noise_param == null) ? null : p.noise_param.Clone();
            m_distortion     = (p.distortion_param == null) ? null : p.distortion_param.Clone();
            m_expansion      = (p.expansion_param == null) ? null : p.expansion_param.Clone();
            m_emitConstraint = (p.emit_constraint == null) ? null : p.emit_constraint.Clone();

            if (p.mask_param != null)
            {
                m_mask = p.mask_param.Clone();
            }

            if (p.label_mapping != null)
            {
                m_labelMapping = p.label_mapping.Clone();
            }
        }
        /// <summary>
        /// Copies the specified source data label mapping parameter to this one.
        /// </summary>
        /// <param name="src">Specifies the source data label mapping parameter.</param>
        public override void Copy(OptionalParameter src)
        {
            base.Copy(src);

            if (src is DataLabelMappingParameter)
            {
                DataLabelMappingParameter p = (DataLabelMappingParameter)src;
                m_rgMapping = p.m_rgMapping.Clone();
            }
        }
        /// <summary>
        /// Load the and return a new DataLabelMappingParameter.
        /// </summary>
        /// <param name="br"></param>
        /// <param name="bNewInstance"></param>
        /// <returns>The new object is returned.</returns>
        public DataLabelMappingParameter Load(BinaryReader br, bool bNewInstance = true)
        {
            RawProto proto = RawProto.Parse(br.ReadString());
            DataLabelMappingParameter p = FromProto(proto);

            if (!bNewInstance)
            {
                Copy(p);
            }

            return(p);
        }
        /// <summary>
        /// Parses the parameter from a RawProto.
        /// </summary>
        /// <param name="rp">Specifies the RawProto to parse.</param>
        /// <returns>A new instance of the parameter is returned.</returns>
        public static new DataLabelMappingParameter FromProto(RawProto rp)
        {
            DataLabelMappingParameter p = new DataLabelMappingParameter(true);

            RawProto rpOption = rp.FindChild("option");

            if (rpOption != null)
            {
                ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption));
            }

            p.m_rgMapping = LabelMappingCollection.Parse(rp.FindArray <string>("mapping"));

            return(p);
        }
        /// <summary>
        /// Parses the parameter from a RawProto.
        /// </summary>
        /// <param name="rp">Specifies the RawProto to parse.</param>
        /// <returns>A new instance of the parameter is returned.</returns>
        public static TransformationParameter FromProto(RawProto rp)
        {
            string strVal;
            TransformationParameter p = new TransformationParameter();

            if ((strVal = rp.FindValue("scale")) != null)
            {
                p.scale = ParseDouble(strVal);
            }

            if ((strVal = rp.FindValue("scale_operator")) != null)
            {
                if (strVal == SCALE_OPERATOR.MUL.ToString())
                {
                    p.scale_operator = SCALE_OPERATOR.MUL;
                }
                else if (strVal == SCALE_OPERATOR.POW.ToString())
                {
                    p.scale_operator = SCALE_OPERATOR.POW;
                }
                else
                {
                    p.scale_operator = SCALE_OPERATOR.NONE;
                }
            }
            else
            {
                p.scale_operator = null;
            }

            if ((strVal = rp.FindValue("mirror")) != null)
            {
                p.mirror = bool.Parse(strVal);
            }

            if ((strVal = rp.FindValue("crop_size")) != null)
            {
                p.crop_size = uint.Parse(strVal);
            }

            if ((strVal = rp.FindValue("use_image_mean")) != null ||
                (strVal = rp.FindValue("use_imagedb_mean")) != null)
            {
                p.use_imagedb_mean = bool.Parse(strVal);
            }

            if ((strVal = rp.FindValue("mean_file")) != null)
            {
                p.use_imagedb_mean = true;
            }

            p.mean_value = rp.FindArray <double>("mean_value");

            if ((strVal = rp.FindValue("force_color")) != null)
            {
                p.force_color = bool.Parse(strVal);
            }

            if ((strVal = rp.FindValue("force_gray")) != null)
            {
                p.force_gray = bool.Parse(strVal);
            }

            if ((strVal = rp.FindValue("force_positive_range_max")) != null)
            {
                p.forced_positive_range_max = ParseDouble(strVal);
            }

            if ((strVal = rp.FindValue("mean_file")) != null)
            {
                p.mean_file = strVal;
            }

            if ((strVal = rp.FindValue("color_order")) != null)
            {
                if (strVal == COLOR_ORDER.BGR.ToString())
                {
                    p.color_order = COLOR_ORDER.BGR;
                }
                else
                {
                    p.color_order = COLOR_ORDER.RGB;
                }
            }

            RawProto rpResize = rp.FindChild("resize_param");

            if (rpResize != null)
            {
                p.resize_param = ResizeParameter.FromProto(rpResize);
            }
            else
            {
                p.resize_param = null;
            }

            RawProto rpNoise = rp.FindChild("noise_param");

            if (rpNoise != null)
            {
                p.noise_param = NoiseParameter.FromProto(rpNoise);
            }
            else
            {
                p.noise_param = null;
            }

            RawProto rpDistort = rp.FindChild("distortion_param");

            if (rpDistort != null)
            {
                p.distortion_param = DistortionParameter.FromProto(rpDistort);
            }

            RawProto rpExpand = rp.FindChild("expansion_param");

            if (rpExpand != null)
            {
                p.expansion_param = ExpansionParameter.FromProto(rpExpand);
            }
            else
            {
                p.expansion_param = null;
            }

            RawProto rpEmitCon = rp.FindChild("emit_constraint");

            if (rpEmitCon != null)
            {
                p.emit_constraint = EmitConstraint.FromProto(rpEmitCon);
            }
            else
            {
                p.emit_constraint = null;
            }

            RawProto rpMask = rp.FindChild("mask_param");

            if (rpMask != null)
            {
                p.mask_param = MaskParameter.FromProto(rpMask);
            }

            RawProto rpLabelMapping = rp.FindChild("label_mapping");

            if (rpLabelMapping != null)
            {
                p.label_mapping = DataLabelMappingParameter.FromProto(rpLabelMapping);
            }

            return(p);
        }