Exemplo n.º 1
0
        /// <summary>
        /// serialize coord-transform-chain to specific stream
        /// </summary>
        /// <param name="coordTx"></param>
        /// <param name="writer"></param>
        public static void Write(ICoordTransformer coordTx, System.IO.BinaryWriter writer)
        {
            //write transformation matrix to binary stream
            CoordTransformerKind txKind = coordTx.Kind;

            switch (txKind)
            {
            case CoordTransformerKind.Unknown:
            default:
                throw new System.NotSupportedException();

            case CoordTransformerKind.Affine3x2:
            {
                Affine aff = (Affine)coordTx;
                writer.Write((ushort)txKind);         //type
                AffineMat affMat = aff.GetInternalMat();
                //write elements
                writer.Write(affMat.sx); writer.Write(affMat.shy);
                writer.Write(affMat.shx); writer.Write(affMat.sy);
                writer.Write(affMat.tx); writer.Write(affMat.ty);
            }
            break;

            case CoordTransformerKind.Bilinear:
            {
                Bilinear binTx = (Bilinear)coordTx;
                writer.Write((ushort)txKind);
                //write elements
                BilinearMat binMat = binTx.GetInternalElements();
                writer.Write(binMat.rc00); writer.Write(binMat.rc01);
                writer.Write(binMat.rc10); writer.Write(binMat.rc11);
                writer.Write(binMat.rc20); writer.Write(binMat.rc21);
                writer.Write(binMat.rc30); writer.Write(binMat.rc31);
            }
            break;

            case CoordTransformerKind.Perspective:
            {
                Perspective perTx = (Perspective)coordTx;
                writer.Write((ushort)txKind);
                PerspectiveMat perMat = perTx.GetInternalElements();
                writer.Write(perMat.sx); writer.Write(perMat.shx); writer.Write(perMat.w0);
                writer.Write(perMat.shy); writer.Write(perMat.sy); writer.Write(perMat.w1);
                writer.Write(perMat.tx); writer.Write(perMat.ty); writer.Write(perMat.w2);

                //sx, shy, w0,
                //shx, sy, w1,
                //tx, ty, w2;
            }
            break;

            case CoordTransformerKind.TransformChain:
            {
                CoordTransformationChain chainTx = (CoordTransformationChain)coordTx;
                writer.Write((ushort)txKind);
                //*** left, right
                Write(chainTx.Left, writer);
                Write(chainTx.Right, writer);
            }
            break;
            }
        }