Example #1
0
        public HeaderMRC(BinaryReader reader)
        {
            Dimensions     = new int3(reader.ReadBytes(3 * sizeof(int)));
            Mode           = (MRCDataType)reader.ReadInt32();
            StartSubImage  = new int3(reader.ReadBytes(3 * sizeof(int)));
            Griddimensions = new int3(reader.ReadBytes(3 * sizeof(int)));
            Pixelsize      = new float3(reader.ReadBytes(3 * sizeof(float)));
            Angles         = new float3(reader.ReadBytes(3 * sizeof(float)));
            MapOrder       = new int3(reader.ReadBytes(3 * sizeof(int)));

            MinValue   = reader.ReadSingle();
            MaxValue   = reader.ReadSingle();
            MeanValue  = reader.ReadSingle();
            SpaceGroup = reader.ReadInt32();

            ExtendedBytes = reader.ReadInt32();
            CreatorID     = reader.ReadInt16();

            ExtraData1 = reader.ReadBytes(30);

            NInt  = reader.ReadInt16();
            NReal = reader.ReadInt16();

            ExtraData2 = reader.ReadBytes(28);

            IDType = reader.ReadInt16();
            Lens   = reader.ReadInt16();
            ND1    = reader.ReadInt16();
            ND2    = reader.ReadInt16();
            VD1    = reader.ReadInt16();
            VD2    = reader.ReadInt16();

            TiltOriginal = new float3(reader.ReadBytes(3 * sizeof(float)));
            TiltCurrent  = new float3(reader.ReadBytes(3 * sizeof(float)));
            Origin       = new float3(reader.ReadBytes(3 * sizeof(float)));

            CMap  = reader.ReadBytes(4);
            Stamp = reader.ReadBytes(4);

            StdDevValue = reader.ReadSingle();

            NumLabels = reader.ReadInt32();
            for (int i = 0; i < 10; i++)
            {
                Labels[i] = reader.ReadBytes(80);
            }

            Extended = reader.ReadBytes(ExtendedBytes);
        }
Example #2
0
 public override void SetValueType(Type t)
 {
     if (t == typeof(byte))
     {
         Mode = MRCDataType.Byte;
     }
     else if (t == typeof(float))
     {
         Mode = MRCDataType.Float;
     }
     else if (t == typeof(short))
     {
         Mode = MRCDataType.Short;
     }
     else if (t == typeof(ushort))
     {
         Mode = MRCDataType.UnsignedShort;
     }
     else
     {
         throw new Exception("Unknown data type.");
     }
 }
Example #3
0
File: MRC.cs Project: dtegunov/warp
        public HeaderMRC(BinaryReader reader)
        {
            Dimensions = new int3(reader.ReadBytes(3 * sizeof(int)));
            Mode = (MRCDataType)reader.ReadInt32();
            StartSubImage = new int3(reader.ReadBytes(3 * sizeof(int)));
            Griddimensions = new int3(reader.ReadBytes(3 * sizeof(int)));
            Pixelsize = new float3(reader.ReadBytes(3 * sizeof(float))) / new float3(Dimensions.X, Dimensions.Y, Dimensions.Z);
            Angles = new float3(reader.ReadBytes(3 * sizeof(float)));
            MapOrder = new int3(reader.ReadBytes(3 * sizeof(int)));

            MinValue = reader.ReadSingle();
            MaxValue = reader.ReadSingle();
            MeanValue = reader.ReadSingle();
            SpaceGroup = reader.ReadInt32();

            ExtendedBytes = reader.ReadInt32();
            CreatorID = reader.ReadInt16();

            ExtraData1 = reader.ReadBytes(30);

            NInt = reader.ReadInt16();
            NReal = reader.ReadInt16();

            ExtraData2 = reader.ReadBytes(28);

            IDType = reader.ReadInt16();
            Lens = reader.ReadInt16();
            ND1 = reader.ReadInt16();
            ND2 = reader.ReadInt16();
            VD1 = reader.ReadInt16();
            VD2 = reader.ReadInt16();

            TiltOriginal = new float3(reader.ReadBytes(3 * sizeof(float)));
            TiltCurrent = new float3(reader.ReadBytes(3 * sizeof(float)));
            Origin = new float3(reader.ReadBytes(3 * sizeof(float)));

            CMap = reader.ReadBytes(4);
            Stamp = reader.ReadBytes(4);

            StdDevValue = reader.ReadSingle();

            NumLabels = reader.ReadInt32();
            for (int i = 0; i < 10; i++)
                Labels[i] = reader.ReadBytes(80);

            // In case this is from SerialEM, check how big ExtendedBytes should be at least to read per-frame data
            ImodHasTilt = (NReal & (1 << 0)) > 0;
            ImodHasMontage = (NReal & (1 << 1)) > 0;
            ImodHasStagePos = (NReal & (1 << 2)) > 0;
            ImodHasMagnification = (NReal & (1 << 3)) > 0;
            ImodHasIntensity = (NReal & (1 << 4)) > 0;
            ImodHasExposure = (NReal & (1 << 5)) > 0;

            int BytesPerSection = (ImodHasTilt ? 2 : 0) +
                                  (ImodHasMontage ? 6 : 0) +
                                  (ImodHasStagePos ? 4 : 0) +
                                  (ImodHasMagnification ? 2 : 0) +
                                  (ImodHasIntensity ? 2 : 0) +
                                  (ImodHasExposure ? 4 : 0);

            if (BytesPerSection * Dimensions.Z > ExtendedBytes) // Not from SerialEM, ignore extended header
            {
                Extended = reader.ReadBytes(ExtendedBytes);
            }
            else    // SerialEM extended header, read one section per frame
            {
                if (ImodHasTilt)
                    ImodTilt = new float[Dimensions.Z];
                if (ImodHasMagnification)
                    ImodMagnification = new float[Dimensions.Z];
                if (ImodHasIntensity)
                    ImodIntensity = new float[Dimensions.Z];
                if (ImodHasExposure)
                    ImodExposure = new float[Dimensions.Z];

                for (int i = 0; i < Dimensions.Z; i++)
                {
                    if (ImodHasTilt)
                        ImodTilt[i] = reader.ReadInt16() / 100f;
                    if (ImodHasMontage)
                        reader.ReadBytes(6);
                    if (ImodHasStagePos)
                        reader.ReadBytes(4);
                    if (ImodHasMagnification)
                        ImodMagnification[i] = reader.ReadInt16() / 100f;
                    if (ImodHasIntensity)
                        ImodIntensity[i] = reader.ReadInt16() / 2500f;
                    if (ImodHasExposure)
                    {
                        float val = reader.ReadSingle();
                        /*int s1 = reader.ReadInt16();
                        int s2 = reader.ReadInt16();

                        float val = Math.Sign(s1) * (Math.Abs(s1) * 256 + (Math.Abs(s2) % 256)) * (float)Math.Pow(2, Math.Sign(s2) * (Math.Abs(s2) / 256f));*/
                        ImodExposure[i] = val;
                    }
                }
            }
        }
Example #4
0
File: MRC.cs Project: dtegunov/warp
 public override void SetValueType(Type t)
 {
     if (t == typeof(byte))
         Mode = MRCDataType.Byte;
     else if (t == typeof(float))
         Mode = MRCDataType.Float;
     else if (t == typeof(short))
         Mode = MRCDataType.Short;
     else if (t == typeof(ushort))
         Mode = MRCDataType.UnsignedShort;
     else
         throw new Exception("Unknown data type.");
 }
Example #5
0
        public HeaderMRC(BinaryReader reader)
        {
            Dimensions     = new int3(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
            Mode           = (MRCDataType)reader.ReadInt32();
            StartSubImage  = new int3(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
            Griddimensions = new int3(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
            PixelSize      = new float3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()) / new float3(Dimensions);
            Angles         = new float3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            MapOrder       = new int3(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());

            MinValue   = reader.ReadSingle();
            MaxValue   = reader.ReadSingle();
            MeanValue  = reader.ReadSingle();
            SpaceGroup = reader.ReadInt32();

            ExtendedBytes = reader.ReadInt32();
            CreatorID     = reader.ReadInt16();

            ExtraData10 = reader.ReadBytes(6);
            ExtID       = reader.ReadBytes(4);
            ExtraData11 = reader.ReadBytes(20);

            NInt  = reader.ReadInt16();
            NReal = reader.ReadInt16();

            ExtraData2 = reader.ReadBytes(28);

            IDType = reader.ReadInt16();
            Lens   = reader.ReadInt16();
            ND1    = reader.ReadInt16();
            ND2    = reader.ReadInt16();
            VD1    = reader.ReadInt16();
            VD2    = reader.ReadInt16();

            TiltOriginal = new float3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            TiltCurrent  = new float3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            Origin       = new float3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

            CMap  = reader.ReadBytes(4);
            Stamp = reader.ReadBytes(4);

            StdDevValue = reader.ReadSingle();

            NumLabels = reader.ReadInt32();
            for (int i = 0; i < 10; i++)
            {
                Labels[i] = reader.ReadBytes(80);
            }

            // In case this is from SerialEM, check how big ExtendedBytes should be at least to read per-frame data
            ImodHasTilt          = (NReal & (1 << 0)) > 0;
            ImodHasMontage       = (NReal & (1 << 1)) > 0;
            ImodHasStagePos      = (NReal & (1 << 2)) > 0;
            ImodHasMagnification = (NReal & (1 << 3)) > 0;
            ImodHasIntensity     = (NReal & (1 << 4)) > 0;
            ImodHasExposure      = (NReal & (1 << 5)) > 0;

            int BytesPerSection = (ImodHasTilt ? 2 : 0) +
                                  (ImodHasMontage ? 6 : 0) +
                                  (ImodHasStagePos ? 4 : 0) +
                                  (ImodHasMagnification ? 2 : 0) +
                                  (ImodHasIntensity ? 2 : 0) +
                                  (ImodHasExposure ? 4 : 0);

            if (BytesPerSection * Dimensions.Z > ExtendedBytes) // Not from SerialEM, ignore extended header
            {
                Extended = reader.ReadBytes(ExtendedBytes);
            }
            else    // SerialEM extended header, read one section per frame
            {
                if (ImodHasTilt)
                {
                    ImodTilt = new float[Dimensions.Z];
                }
                if (ImodHasMagnification)
                {
                    ImodMagnification = new float[Dimensions.Z];
                }
                if (ImodHasIntensity)
                {
                    ImodIntensity = new float[Dimensions.Z];
                }
                if (ImodHasExposure)
                {
                    ImodExposure = new float[Dimensions.Z];
                }

                for (int i = 0; i < Dimensions.Z; i++)
                {
                    if (ImodHasTilt)
                    {
                        ImodTilt[i] = reader.ReadInt16() / 100f;
                    }
                    if (ImodHasMontage)
                    {
                        reader.ReadBytes(6);
                    }
                    if (ImodHasStagePos)
                    {
                        reader.ReadBytes(4);
                    }
                    if (ImodHasMagnification)
                    {
                        ImodMagnification[i] = reader.ReadInt16() / 100f;
                    }
                    if (ImodHasIntensity)
                    {
                        ImodIntensity[i] = reader.ReadInt16() / 2500f;
                    }
                    if (ImodHasExposure)
                    {
                        float val = reader.ReadSingle();

                        /*int s1 = reader.ReadInt16();
                         * int s2 = reader.ReadInt16();
                         *
                         * float val = Math.Sign(s1) * (Math.Abs(s1) * 256 + (Math.Abs(s2) % 256)) * (float)Math.Pow(2, Math.Sign(s2) * (Math.Abs(s2) / 256f));*/
                        ImodExposure[i] = val;
                    }
                }
            }
        }