Пример #1
0
        // TODO: Avoid using SetPixel (since it takes out a lock on the image, changes pixel, unlocks.
        // This is super slow and we can just take out the lock once. Also there's a bunch of stuff we're doing
        // in the inner loop which we can just do up front.
        // Example code so I remember what to try again:
        //    var bmpData = slice.LockBits(new Rectangle(0, 0, slice.Width, slice.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
        //    unsafe
        //    {
        //        var u = (int*)bmpData.Scan0;
        //        ...
        //    }
        //    slick.UnlockBits(bmpData);
        public Bitmap GetSlice(int sliceIndex, SliceType sliceType)
        {
            if (Header.dim == null)
            {
                throw new NullReferenceException("Nifti file header dim is null");
            }
            if (Header.dim.Length < 8 ||
                Header.dim[0] < 3 ||
                Header.dim[1] < 1 || Header.dim[2] < 1 || Header.dim[3] < 1)
            {
                throw new NullReferenceException("Nifti file header dim 0,1,2,3 are not valid");
            }

            GetDimensions(sliceType, out var width, out var height, out var nSlices);
            if (sliceIndex >= nSlices)
            {
                throw new ArgumentOutOfRangeException($"Slice index out of range. No of slices = {nSlices}");
            }

            var slice = new Bitmap(width, height);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    //var color = Color.FromArgb(GetPixelColor(x, y, sliceIndex, sliceType)).SwapRedBlue();
                    slice.SetPixel(x, y, Color.FromArgb(GetPixelColor(x, y, sliceIndex, sliceType)));
                }
            }

            //var bmp = new Bitmap(slice.Bitmap);
            //slice.Dispose();
            return(slice);
        }
Пример #2
0
        public void GetDimensions(SliceType sliceType, out int width, out int height, out int nSlices)
        {
            switch (sliceType)
            {
            case SliceType.Sagittal:
                width   = Header.dim[2];
                height  = Header.dim[3];
                nSlices = Header.dim[1];
                break;

            case SliceType.Coronal:
                width   = Header.dim[1];
                height  = Header.dim[3];
                nSlices = Header.dim[2];
                break;

            case SliceType.Axial:
                width   = Header.dim[1];
                height  = Header.dim[2];
                nSlices = Header.dim[3];
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sliceType), sliceType, null);
            }
        }
Пример #3
0
        private static bool DicomFilesInRightOrder(string dicomFolderPath, SliceType sliceType)
        {
            var dicomFileWithLowestInstanceNo = GetDicomFileWithLowestInstanceNumber(dicomFolderPath);

            if (dicomFileWithLowestInstanceNo == null || string.IsNullOrEmpty(dicomFileWithLowestInstanceNo))
            {
                throw new Exception($"Failed to get the dicom file with lowest instance number in folder [{dicomFolderPath}]");
            }
            var headers = GetDicomTags(dicomFileWithLowestInstanceNo);

            if (headers == null)
            {
                throw new Exception($"Failed to get dicom headers for dicom file [{dicomFileWithLowestInstanceNo}]");
            }
            var imagePosition = headers.ImagePositionPatient.Values;

            if (imagePosition.Length < 3)
            {
                return(true);                          // disregard
            }
            var slicesFromLeftToRight = float.Parse(imagePosition[0]) > 0;
            var slicesFromBackToFront = float.Parse(imagePosition[1]) > 0;
            var slicesFromBottomToTop = float.Parse(imagePosition[2]) < 0;

            switch (sliceType)
            {
            case SliceType.Sagittal when !slicesFromLeftToRight:
            case SliceType.Coronal when !slicesFromBackToFront:
            case SliceType.Axial when !slicesFromBottomToTop:
                return(false);    // So later we reverse the order of files

            default:
                return(true);
            }
        }
Пример #4
0
        public override int GetVoxelIndex(int x, int y, int z, SliceType sliceType)
        {
            if (Header.dim[1] == 0 || Header.dim[2] == 0 || Header.dim[3] == 0)
            {
                throw new Exception("Nifti header dimensions not set!");
            }
            var ltRt   = Header.dim[1];
            var antPos = Header.dim[2];
            var infSup = Header.dim[3];

            // TODO : This is the problem with having a header that doesn't reflect our
            // data storage in memory. We should be able to index in based on the header.

            switch (sliceType)
            {
            case SliceType.Axial:
                return((ltRt - 1 - x) + ltRt * (antPos - 1 - y) + ltRt * antPos * z);

            case SliceType.Sagittal:
                return(z + ltRt * (antPos - 1 - x) + ltRt * antPos * (infSup - 1 - y));

            case SliceType.Coronal:
                return((ltRt - 1 - x) + ltRt * z + ltRt * antPos * (infSup - 1 - y));

            default:
                throw new Exception("Slice Type not supported");
            }
        }
Пример #5
0
    public void Create()
    {
        rotate = true;

        this.type = (SliceType)Random.Range(0, 2);
        this.sprite.transform.rotation = Quaternion.identity;

        GameObject firstLine  = Instantiate(linePrefab, transform.position, Quaternion.identity, transform);
        GameObject secondLine = Instantiate(linePrefab, transform.position, Quaternion.identity, transform);

        first  = firstLine.GetComponent <SlicerLine>();
        second = secondLine.GetComponent <SlicerLine>();

        if (this.type == SliceType.CORNER)
        {
            this.sprite.sprite = corner;
            first.Create(LineDirection.UP, this);
            second.Create(LineDirection.RIGHT, this);
        }
        else
        {
            this.sprite.sprite = straight;
            first.Create(LineDirection.LEFT, this);
            second.Create(LineDirection.RIGHT, this);
        }

        int rotateTime = Random.Range(0, 4);

        for (int i = 0; i < rotateTime; i++)
        {
            Rotate();
        }
    }
        /// <summary>
        /// Iterates the section until a top or bottom slice (as specified)
        /// is of requested area.
        /// </summary>
        /// <param name="Area"></param>
        /// <param name="sliceType"></param>
        /// <returns></returns>
        private IMoveableSection getSliceOfArea(double Area, SliceType sliceType)
        {
            double Atar       = 0; //target area
            double YOffsetTop = 0;

            if (Area > this.A)
            {
                throw new Exception("Section analysis failed. Area of section sub-part exceeds the total area of cross section.");
            }
            else
            {
                if (sliceType == SliceType.Top) // need to return the TOP portion of given area
                {
                    Atar = Area;
                }
                else // need to return the BOTTOM portion of given area
                {
                    Atar = this.A - Area;
                }
                YOffsetTop = GetSlicePlaneTopOffset(Atar);
            }
            double SlicePlaneYCoordinte;

            SlicePlaneYCoordinte = this.YMax - YOffsetTop;

            IMoveableSection s = getSliceAtCoordinate(SlicePlaneYCoordinte, sliceType);

            return(s);
        }
Пример #7
0
    public SliceHeader(Stream @is)
    {
        @is.ReadByte();
        CAVLCReader reader = new CAVLCReader(@is);

        first_mb_in_slice = reader.readUE("SliceHeader: first_mb_in_slice");
        switch (reader.readUE("SliceHeader: slice_type"))
        {
        case 0:
        case 5:
            slice_type = SliceType.P;
            break;

        case 1:
        case 6:
            slice_type = SliceType.B;
            break;

        case 2:
        case 7:
            slice_type = SliceType.I;
            break;

        case 3:
        case 8:
            slice_type = SliceType.SP;
            break;

        case 4:
        case 9:
            slice_type = SliceType.SI;
            break;
        }
    }
        private static ContoursPerSlice GenerateContoursPerSlice(
            Volume3D <byte> volume,
            bool fillContours,
            byte foregroundId,
            SliceType sliceType,
            bool filterEmptyContours,
            Region3D <int> regionOfInterest,
            ContourSmoothingType axialSmoothingType)
        {
            var region = regionOfInterest ?? new Region3D <int>(0, 0, 0, volume.DimX - 1, volume.DimY - 1, volume.DimZ - 1);

            int startPoint;
            int endPoint;

            // Only smooth the output on the axial slices
            var smoothingType = axialSmoothingType;

            switch (sliceType)
            {
            case SliceType.Axial:
                startPoint = region.MinimumZ;
                endPoint   = region.MaximumZ;
                break;

            case SliceType.Coronal:
                startPoint    = region.MinimumY;
                endPoint      = region.MaximumY;
                smoothingType = ContourSmoothingType.None;
                break;

            case SliceType.Sagittal:
                startPoint    = region.MinimumX;
                endPoint      = region.MaximumX;
                smoothingType = ContourSmoothingType.None;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sliceType), sliceType, null);
            }

            var numberOfSlices  = endPoint - startPoint + 1;
            var arrayOfContours = new Tuple <int, IReadOnlyList <ContourPolygon> > [numberOfSlices];

            for (var i = 0; i < arrayOfContours.Length; i++)
            {
                var z        = startPoint + i;
                var volume2D = ExtractSlice.Slice(volume, sliceType, z);
                var contours = fillContours ?
                               ContoursFilled(volume2D, foregroundId, smoothingType):
                               ContoursWithHoles(volume2D, foregroundId, smoothingType);

                arrayOfContours[i] = Tuple.Create(z, contours);
            }

            return(new ContoursPerSlice(
                       arrayOfContours
                       .Where(x => !filterEmptyContours || x.Item2.Count > 0)
                       .ToDictionary(x => x.Item1, x => x.Item2)));
        }
 /// <summary>
 /// Extracts contours from all slices of the given volume, searching for the given foreground value.
 /// Contour extraction will take holes into account.
 /// </summary>
 /// <param name="volume"></param>
 /// <param name="foregroundId">The voxel value that should be used in the contour search as foreground.</param>
 /// <param name="axialSmoothingType">The smoothing that should be applied when going from a point polygon to
 /// contours. This will only affect axial slice, for other slice types no smoothing will be applied.
 /// <param name="sliceType">The type of slice that should be used for contour extraction.</param>
 /// <param name="filterEmptyContours">If true, contours with no points are not extracted.</param>
 /// <param name="regionOfInterest"></param>
 /// <returns></returns>
 public static ContoursPerSlice ContoursWithHolesPerSlice(
     this Volume3D <byte> volume,
     byte foregroundId                       = ModelConstants.MaskForegroundIntensity,
     SliceType sliceType                     = SliceType.Axial,
     bool filterEmptyContours                = true,
     Region3D <int> regionOfInterest         = null,
     ContourSmoothingType axialSmoothingType = ContourSmoothingType.Small)
 => ExtractContours.ContoursWithHolesPerSlice(volume, foregroundId, sliceType, filterEmptyContours, regionOfInterest, axialSmoothingType);
Пример #10
0
        /// <summary>
        /// Handles texture update events.
        /// </summary>
        /// <param name="type">type of texture that was updated</param>
        /// <param name="index">index of the updated texture</param>
        public void TextureUpdated(SliceType type, int index)
        {
            if (CurrentSliceType == type && _selection[CurrentSliceType] == index)
            {
                Display.texture = _imageStack.GetTexture2D(CurrentSliceType, _selection[CurrentSliceType]);

                ResetClick();
            }
        }
Пример #11
0
        /// <summary>
        /// Handles Segment update events
        /// </summary>
        /// <param name="tex">actual texture that was updated</param>
        /// <param name="type">SliceType of the texture</param>
        /// <param name="index">index of the updated texture</param>
        public void SegmentTextureUpdated(Texture2D tex, SliceType type, int index)
        {
            if (CurrentSliceType != type || !_selection.ContainsKey(CurrentSliceType) || _selection[CurrentSliceType] != index)
            {
                return;
            }

            SegmentImage.texture = tex;
            SegmentImage.color   = _segmentTransparency;
        }
Пример #12
0
        //public bool CheckTimeStamp(ulong previous) {
        //  decimal duration = (decimal) TimeStamp - (decimal) previous;
        //  if (Math.Abs(SliceDuration - duration) > (SliceDuration/100)) // if discrepancy is more than 1%
        //    return false;
        //  else {
        //    return true;
        //  }
        //}

        public void Copy(StreamDataBlockInfo copyFrom)
        {
            this.StreamOffset  = copyFrom.StreamOffset;
            this.SliceSize     = copyFrom.SliceSize;
            this.SliceDuration = copyFrom.SliceDuration;
            this.TimeStampNew  = copyFrom.TimeStampNew;
            this.CTS           = copyFrom.CTS;
            this.index         = copyFrom.index;
            this.SliceType     = copyFrom.SliceType;
        }
Пример #13
0
 /// <summary>
 /// Extracts contours from all slices of the given volume, searching for the given foreground value.
 /// Contour extraction will take holes into account.
 /// </summary>
 /// <param name="volume"></param>
 /// <param name="foregroundId">The voxel value that should be used in the contour search as foreground.</param>
 /// <param name="axialSmoothingType">The smoothing that should be applied when going from a point polygon to
 /// contours. This will only affect axial slice, for other slice types no smoothing will be applied.
 /// <param name="sliceType">The type of slice that should be used for contour extraction.</param>
 /// <param name="filterEmptyContours">If true, contours with no points are not extracted.</param>
 /// <param name="regionOfInterest"></param>
 /// <returns></returns>
 public static ContoursPerSlice ContoursFilledPerSlice(
     Volume3D <byte> volume,
     byte foregroundId                       = ModelConstants.MaskForegroundIntensity,
     SliceType sliceType                     = SliceType.Axial,
     bool filterEmptyContours                = true,
     Region3D <int> regionOfInterest         = null,
     ContourSmoothingType axialSmoothingType = ContourSmoothingType.Small)
 {
     return(GenerateContoursPerSlice(volume, true, foregroundId, sliceType, filterEmptyContours, regionOfInterest, axialSmoothingType));
 }
Пример #14
0
        public static SliceType GetSliceType(Slice inSlice)
        {
            // tryout
            byte[] payload = new byte[inSlice.SliceBytes.Length];
            inSlice.SliceBytes.CopyTo(payload, 0);
            H264Utilities.ToH264Block(payload);
            SliceType sliceT = H264Utilities.GetSliceTypeFromH264Payload(payload);

            return(sliceT);
        }
        /// <summary>
        /// Calculate number of words to fit complete instruction bytecode.
        /// </summary>
        /// <returns>Number of words in instruction bytecode.</returns>
        public override uint GetWordCount()
        {
            uint wordCount = 0;

            wordCount += IdResultType.GetWordCount();
            wordCount += IdResult.GetWordCount();
            wordCount += SliceType.GetWordCount();
            wordCount += Qp.GetWordCount();
            return(wordCount);
        }
Пример #16
0
        /// <summary>
        /// Extracts a slice of a chosen type (orientation) from the present volume, and returns it as a
        /// <see cref="Volume2D"/> instance of correct size. Note that these slices are NOT extracted
        /// according to the patient-centric coordinate system, but in the coordinate system of the volume
        /// alone.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="volume"></param>
        /// <param name="sliceType"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static Volume2D <T> Slice <T>(Volume3D <T> volume, SliceType sliceType, int index)
        {
            var result = AllocateSlice <T, T>(volume, sliceType);

            if (result != null)
            {
                Extract(volume, sliceType, index, result.Array);
            }

            return(result);
        }
Пример #17
0
        public bool readMBSkipFlag(MDecoder mDecoder, SliceType slType, bool leftAvailable, bool topAvailable,
                                   int mbX)
        {
            int bbase = slType == SliceType.P ? 11 : 24;

            bool ret = mDecoder.decodeBin(bbase + (leftAvailable && !skipFlagLeft ? 1 : 0)
                                          + (topAvailable && !skipFlagsTop[mbX] ? 1 : 0)) == 1;

            skipFlagLeft = skipFlagsTop[mbX] = ret;

            return(ret);
        }
Пример #18
0
        private Slice slice; // TODO only one slice for now

        #endregion Fields

        #region Constructors

        protected Picture(VideoSequence videoSequence, int pictureNumber, int lastIdr)
        {
            number = pictureNumber;
            idrFlag = (pictureNumber == lastIdr);
            frameNum = idrFlag ? 0 : pictureNumber - lastIdr;
            qp = 28; // TODO QPISlice QP for I Slices must come from Control
            picSizeInMbs = videoSequence.FrameSizeInMbs; // frame picture
            width = videoSequence.FrameSize.Width;
            height = videoSequence.FrameSize.Height;
            type = SliceType.Slice; // TODO always set to Intra
            InitFrame();
        }
Пример #19
0
        /// <summary>
        /// Returns the maximum value for the given slice type, starting from 0.
        /// </summary>
        /// <param name="type">Requested SliceType</param>
        /// <returns>Max Value for the SliceType</returns>
        public int GetMaxValue(SliceType type)
        {
            switch (type)
            {
            case SliceType.Transversal: return(DicomFiles.Length - 1);

            case SliceType.Frontal: return(Height - 1);

            case SliceType.Sagittal: return(Width - 1);

            default: return(0);
            }
        }
Пример #20
0
    public int GetNumSlices(SliceType sliceType)
    {
        switch (sliceType)
        {
        case SliceType.Axial:
            return(_sizeZ);

        case SliceType.Coronal:
            return(_sizeY);

        case SliceType.Sagittal:
            return(_sizeX);
        }
        return(0);
    }
Пример #21
0
        /// <summary>
        /// Extracts a slice of a given type (orientation) from the present volume, and writes it to
        /// the provided array in <paramref name="outVolume"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="volume"></param>
        /// <param name="sliceType"></param>
        /// <param name="sliceIndex"></param>
        /// <param name="outVolume"></param>
        /// <param name="skip"></param>
        private static void Extract <T>(Volume3D <T> volume, SliceType sliceType, int sliceIndex, T[] outVolume, int skip = 1)
        {
            switch (sliceType)
            {
            case SliceType.Axial:
                if (sliceIndex < volume.DimZ && outVolume.Length == volume.DimXY * skip)
                {
                    Parallel.For(0, volume.DimY, y =>
                    {
                        for (var x = 0; x < volume.DimX; x++)
                        {
                            outVolume[(x + y * volume.DimX) * skip] = volume[(sliceIndex * volume.DimY + y) * volume.DimX + x];
                        }
                    });
                }

                break;

            case SliceType.Coronal:
                if (sliceIndex < volume.DimY && outVolume.Length == volume.DimZ * volume.DimX * skip)
                {
                    Parallel.For(0, volume.DimZ, z =>
                    {
                        for (var x = 0; x < volume.DimX; x++)
                        {
                            outVolume[(x + z * volume.DimX) * skip] = volume[(z * volume.DimY + sliceIndex) * volume.DimX + x];
                        }
                    });
                }

                break;

            case SliceType.Sagittal:
                if (sliceIndex < volume.DimX && outVolume.Length == volume.DimY * volume.DimZ * skip)
                {
                    Parallel.For(0, volume.DimZ, z =>
                    {
                        for (var y = 0; y < volume.DimY; y++)
                        {
                            outVolume[(y + z * volume.DimY) * skip] = volume[(z * volume.DimY + y) * volume.DimX + sliceIndex];
                        }
                    });
                }

                break;
            }
        }
        /// <summary>
        /// Calculates a section based on slicing criteria
        /// </summary>
        /// <param name="YCoordinate">Plane Y coordinate in local coordinate system</param>
        /// <param name="sliceType">Indicates whether top or bottom slice is returned</param>
        /// <returns></returns>
        private IMoveableSection getSliceAtCoordinate(double YCoordinate, SliceType sliceType)
        {
            ArbitraryCompoundShape newShape = new ArbitraryCompoundShape(null, null);

            if (sliceType == SliceType.Top)
            {
                var sortedRectanglesX = RectanglesXAxis.OrderByDescending(r => r.InsertionPoint.Y).ToList();
                foreach (var r in sortedRectanglesX)
                {
                    if (r.Ymax > YCoordinate && r.Ymin >= YCoordinate)
                    {
                        newShape.rectanglesXAxis.Add(r);
                    }
                    else if (r.Ymax >= YCoordinate && r.Ymin <= YCoordinate)
                    {
                        double thisRectHeight = r.Ymax - YCoordinate;
                        newShape.rectanglesXAxis.Add(new CompoundShapePart(r.b, thisRectHeight, new Point2D(0, r.Ymax - thisRectHeight / 2.0)));
                    }
                    else
                    {
                        //do nothing since this rectangle does not belong here
                    }
                }
            }
            else
            {
                var sortedRectanglesX = RectanglesXAxis.OrderBy(r => r.InsertionPoint.Y).ToList();
                foreach (var r in sortedRectanglesX)
                {
                    if (r.Ymax <= YCoordinate && r.Ymin < YCoordinate)
                    {
                        newShape.rectanglesXAxis.Add(r);
                    }
                    else if (r.Ymax > YCoordinate && r.Ymin <= YCoordinate)
                    {
                        double thisRectHeight = YCoordinate - r.Ymin;
                        newShape.rectanglesXAxis.Add(new CompoundShapePart(r.b, thisRectHeight, new Point2D(0, r.Ymin + thisRectHeight / 2.0)));
                    }
                    else
                    {
                        //do nothing since this rectangle does not belong here
                    }
                }
            }

            return(newShape);
        }
Пример #23
0
        bool IsAudio(SliceType sampType)
        {
            if (sampType == SliceType.AAC)
            {
                return(true);
            }
            if (sampType == SliceType.MP4A)
            {
                return(true);
            }
            if (sampType == SliceType.WMA)
            {
                return(true);
            }

            return(false);
        }
Пример #24
0
        /// <summary>
        /// Checks if the arrays containing the slices exist.
        /// </summary>
        /// <param name="type">Requested SliceType</param>
        /// <returns>True if the corresponding array is not null</returns>
        public bool HasData(SliceType type)
        {
            switch (type)
            {
            case SliceType.Transversal:
                return(_transversalTexture2Ds != null);

            case SliceType.Frontal:
                return(_frontalTexture2Ds != null);

            case SliceType.Sagittal:
                return(_sagittalTexture2Ds != null);

            default:
                return(false);
            }
        }
Пример #25
0
        int AverageIFrameCountPerBlockTimesTwo()
        {
            SliceType typeOfAnySlice = cache[readCache].SampleStreamLocations[0].SliceType;

            if (typeOfAnySlice != SliceType.IFrame && typeOfAnySlice != SliceType.DFrame)
            {
                return(0);
            }

            int iFrameCount = 0;

            for (int i = 0; i < CacheBufCount; i++)
            {
                iFrameCount += cache[i].SampleStreamLocations.Count(s => s.SliceType == SliceType.IFrame);
            }
            return((iFrameCount << 1) / CacheBufCount);
        }
        public static IPizzaCutting CreateCutting(SliceType type)
        {
            IPizzaCutting result = null;

            switch (type)
            {
            case SliceType.Base:
                result = new BaseCutting();
                break;

            case SliceType.Square:
                result = new SquareCutting();
                break;
            }

            return(result);
        }
Пример #27
0
    public static Texture2D Create9Slice(Texture2D sourceTex, Params param)
    {
        SliceType sliceType = SliceType.Slice9;

        if ((param.l <= 0 || param.r <= 0) && (param.t <= 0 || param.b <= 0))
        {
            Debug.LogWarning("l,t,r,b 设置异常 不能导出九宫格图");
            return(sourceTex);
        }

        if (param.l <= 0 || param.r <= 0)
        {
            sliceType = SliceType.SliceTB;
        }
        else if (param.t <= 0 || param.b <= 0)
        {
            sliceType = SliceType.SliceLR;
        }
        else
        {
            sliceType = SliceType.Slice9;
        }

        Texture2D destTex = new Texture2D(param.destWidth, param.destHeight);

        Color[] destPix = new Color[destTex.width * destTex.height];

        TextureParam tParam = new TextureParam(sourceTex, destTex, destPix);

        int y = 0;

        while (y < destTex.height)
        {
            int x = 0;
            while (x < destTex.width)
            {
                SetPixels(x, y, param, tParam, sliceType);
                x++;
            }
            y++;
        }

        destTex.SetPixels(destPix);
        return(destTex);
    }
Пример #28
0
    public Texture2D GetSlice(int sliceNum, SliceType sliceType, bool reversed = false)
    {
        if (_minWindow != 0 || _windowWidth != 255)
        {
            return(ConstructSlice(sliceNum, sliceType, reversed));
        }

        switch (sliceType)
        {
        case SliceType.Axial:
            if (reversed)
            {
                return(_axialTexturesReversed[sliceNum]);
            }
            else
            {
                return(_axialTextures[sliceNum]);
            }

        case SliceType.Coronal:
            if (reversed)
            {
                return(_coronalTexturesReversed[sliceNum]);
            }
            else
            {
                return(_coronalTextures[sliceNum]);
            }

        case SliceType.Sagittal:
            if (reversed)
            {
                return(_sagittalTexturesReversed[sliceNum]);
            }
            else
            {
                return(_sagittalTextures[sliceNum]);
            }
        }

        return(_axialTextures[sliceNum]);
    }
Пример #29
0
        public void ExportSlicesToBmps(string folderPath, SliceType sliceType)
        {
            if (Header.dim == null || Header.dim.Length < 4 || Header.dim[3] == 0)
            {
                throw new Exception("dim[3] in nifti file header not valid");
            }
            if (Directory.Exists(folderPath))
            {
                throw new Exception($"Folder already exists! [{folderPath}]");
            }
            Directory.CreateDirectory(folderPath);

            var sliceCount = Header.dim[(int)sliceType + 1];
            var digits     = (int)Math.Log10(sliceCount) + 1;

            for (var i = 0; i < sliceCount; i++)
            {
                GetSlice(i, sliceType).Save($@"{folderPath}\{(i + 1).ToString($"D{digits}")}.bmp", ImageFormat.Bmp);
            }
        }
Пример #30
0
        /// <summary>
        /// Writes segmentation data of the slice type into the given texture.
        /// </summary>
        /// <param name="texture2D">target texture2D</param>
        /// <param name="sliceType">type of slice to be displayed</param>
        /// <param name="index">index of the slice</param>
        public void WriteToTexture(Texture2D texture2D, SliceType sliceType, int index)
        {
            switch (sliceType)
            {
            case SliceType.Transversal:
                WriteToTransversal(texture2D, index);
                break;

            case SliceType.Sagittal:
                WriteToSagittal(texture2D, index);
                break;

            case SliceType.Frontal:
                WriteToFrontal(texture2D, index);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sliceType), sliceType, "Invalid SliceType");
            }
        }
Пример #31
0
        /// <summary>
        /// Swaps the displayed SliceType for the given SliceType
        /// </summary>
        /// <param name="type">SliceType to display.</param>
        public void Show(SliceType type)
        {
            CurrentSliceType         = type;
            _ignoreSliderChanges     = true;
            SliceSlider.MaximumValue = _imageStack.GetMaxValue(CurrentSliceType);
            _ignoreSliderChanges     = false;
            SliceSlider.CurrentInt   = _selection[CurrentSliceType];

            Display.texture = _imageStack.GetTexture2D(CurrentSliceType, _selection[CurrentSliceType]);

            if (ClickDisplay.texture.width != Display.texture.width ||
                ClickDisplay.texture.height != Display.texture.height)
            {
                ResetClickDisplay(Display.texture.width, Display.texture.height);
            }
            else
            {
                ResetClick();
            }
        }
Пример #32
0
        public SliceHeader(Slice slice, Nalu nalu, SequenceParameterSet sps, PictureParameterSet pps)
        {
            this.slice = slice;

            // BEGIN: parameters from Nalu, Picture Par Set and Sequence Par Set
            picParameterSetId = pps.PicParameterSetId;
            log2MaxFrameNumMinus4 = sps.Log2MaxFrameNumMinus4;
            frameMbsOnlyFlag = sps.FrameMbsOnlyFlag;
            picOrderCntType = sps.PicOrderCntType;
            log2MaxPicOrderCntLsbMinus4 = sps.Log2MaxPicOrderCntLsbMinus4;
            picInitQpMinus26 = pps.PicInitQpMinus26;
            nalRefIdc = nalu.NalRefIdc;
            nalUnitType = nalu.NalUnitType;
            // END: parameters from Nalu, Picture Par Set and Sequence Par Set

            sliceType = slice.Picture.TypeOfSlice;
            firstMbInSlice = slice.Picture.CurrentMbNr;
            noOutputOfPriorPicsFlag = false;
            longTermReferenceFlag = false;
            sliceQpDelta = (slice.Qp - 26 - picInitQpMinus26);
        }
Пример #33
0
 internal EncapsDecoder10(InputStream stream, Encaps encaps, bool sliceValues, ValueFactoryManager f,
                          ClassResolver cr)
     : base(stream, encaps, sliceValues, f, cr)
 {
     _sliceType = SliceType.NoSlice;
 }
Пример #34
0
        bool IsAudio(SliceType sampType)
        {
            if (sampType == SliceType.AAC)
            return true;
              if (sampType == SliceType.MP4A)
            return true;
              if (sampType == SliceType.WMA)
            return true;

              return false;
        }
Пример #35
0
        private void addSide(Texture2D src, Rectangle dstRect, int dx, int dy, int sx, int sy, SliceType st)
        {
            Rectangle srcRect = new Rectangle();
            srcRect.X = sx;
            srcRect.Y = sy;
            dstRect.X += dx;
            dstRect.Y += dy;

            switch (st) {
                case SliceType.Horizontal:
                    srcRect.Width = dstRect.Width = Tile.Size;
                    srcRect.Height = dstRect.Height = Tile.Size / 2;
                    TextureUtilities.blit(src, srcRect, atlas, dstRect);
                    break;
                case SliceType.Vertical:
                    srcRect.Width = dstRect.Width = Tile.Size / 2;
                    srcRect.Height = dstRect.Height = Tile.Size;
                    TextureUtilities.blit(src, srcRect, atlas, dstRect);
                    break;
            }
        }
Пример #36
0
 private void push(SliceType sliceType)
 {
     if(_current == null)
     {
         _current = new InstanceData(null);
     }
     else
     {
         _current = _current.next == null ? new InstanceData(_current) : _current.next;
     }
     _current.sliceType = sliceType;
     _current.skipFirstSlice = false;
 }
Пример #37
0
 internal abstract void startInstance(SliceType type);
Пример #38
0
        /// <summary>
        /// Iterates the section until a top or bottom slice (as specified) 
        /// is of requested area.
        /// </summary>
        /// <param name="Area"></param>
        /// <param name="sliceType"></param>
        /// <returns></returns>
        private IMoveableSection getSliceOfArea(double Area, SliceType sliceType)
        {
            double Atar = 0; //target area
            double YOffsetTop = 0;
            if (Area > this.A)
            {
                throw new Exception("Section analysis failed. Area of section sub-part exceeds the total area of cross section.");
            }
            else
            {
                if (sliceType == SliceType.Top) // need to return the TOP portion of given area
                {
                    Atar = Area;
                }
                else // need to return the BOTTOM portion of given area
                {
                    Atar = this.A - Area;
                }
                YOffsetTop = GetSlicePlaneTopOffset(Atar);
            }
            double SlicePlaneYCoordinte;

            SlicePlaneYCoordinte = this.YMax - YOffsetTop;
            
            IMoveableSection s = getSliceAtCoordinate(SlicePlaneYCoordinte, sliceType);
            return s;
        }
Пример #39
0
            internal override Ice.SlicedData endInstance(bool preserve)
            {
                //
                // Read the Ice::Object slice.
                //
                if(_sliceType == SliceType.ValueSlice)
                {
                    startSlice();
                    int sz = _stream.readSize(); // For compatibility with the old AFM.
                    if(sz != 0)
                    {
                        throw new Ice.MarshalException("invalid Object slice");
                    }
                    endSlice();
                }

                _sliceType = SliceType.NoSlice;
                return null;
            }
Пример #40
0
            internal override void throwException(UserExceptionFactory factory)
            {
                Debug.Assert(_sliceType == SliceType.NoSlice);

                //
                // User exception with the 1.0 encoding start with a bool flag
                // that indicates whether or not the exception has classes.
                //
                // This allows reading the pending instances even if some part of
                // the exception was sliced.
                //
                bool usesClasses = _stream.readBool();

                _sliceType = SliceType.ExceptionSlice;
                _skipFirstSlice = false;

                //
                // Read the first slice header.
                //
                startSlice();
                string mostDerivedId = _typeId;
                while(true)
                {
                    Ice.UserException userEx = null;

                    //
                    // Use a factory if one was provided.
                    //
                    if(factory != null)
                    {
                        try
                        {
                            factory(_typeId);
                        }
                        catch(Ice.UserException ex)
                        {
                            userEx = ex;
                        }
                    }

                    if(userEx == null)
                    {
                        userEx = _stream.createUserException(_typeId);
                    }

                    //
                    // We found the exception.
                    //
                    if(userEx != null)
                    {
                        userEx.read__(_stream);
                        if(usesClasses)
                        {
                            readPendingValues();
                        }
                        throw userEx;

                        // Never reached.
                    }

                    //
                    // Slice off what we don't understand.
                    //
                    skipSlice();
                    try
                    {
                        startSlice();
                    }
                    catch(Ice.UnmarshalOutOfBoundsException ex)
                    {
                        //
                        // An oversight in the 1.0 encoding means there is no marker to indicate
                        // the last slice of an exception. As a result, we just try to read the
                        // next type ID, which raises UnmarshalOutOfBoundsException when the
                        // input buffer underflows.
                        //
                        // Set the reason member to a more helpful message.
                        //
                        ex.reason = "unknown exception type `" + mostDerivedId + "'";
                        throw;
                    }
                }
            }
Пример #41
0
            private void readInstance()
            {
                int index = _stream.readInt();

                if(index <= 0)
                {
                    throw new Ice.MarshalException("invalid object id");
                }

                _sliceType = SliceType.ValueSlice;
                _skipFirstSlice = false;

                //
                // Read the first slice header.
                //
                startSlice();
                string mostDerivedId = _typeId;
                Ice.Object v = null;
                while(true)
                {
                    //
                    // For the 1.0 encoding, the type ID for the base Object class
                    // marks the last slice.
                    //
                    if(_typeId.Equals(Ice.ObjectImpl.ice_staticId()))
                    {
                        throw new NoValueFactoryException("", mostDerivedId);
                    }

                    v = newInstance(_typeId);

                    //
                    // We found a factory, we get out of this loop.
                    //
                    if(v != null)
                    {
                        break;
                    }

                    //
                    // If slicing is disabled, stop unmarshaling.
                    //
                    if(!_sliceValues)
                    {
                        throw new NoValueFactoryException("no value factory found and slicing is disabled", _typeId);
                    }

                    //
                    // Slice off what we don't understand.
                    //
                    skipSlice();
                    startSlice(); // Read next Slice header for next iteration.
                }

                //
                // Unmarshal the instance and add it to the map of unmarshaled instances.
                //
                unmarshal(index, v);
            }
Пример #42
0
 internal override void startInstance(SliceType sliceType)
 {
     Debug.Assert(_current.sliceType == sliceType);
     _current.skipFirstSlice = true;
 }
Пример #43
0
        /// <summary>
        /// Calculates a section based on slicing criteria
        /// </summary>
        /// <param name="YCoordinate">Plane Y coordinate in local coordinate system</param>
        /// <param name="sliceType">Indicates whether top or bottom slice is returned</param>
        /// <returns></returns>
        private IMoveableSection getSliceAtCoordinate(double YCoordinate, SliceType sliceType)
        {


            ArbitraryCompoundShape newShape = new ArbitraryCompoundShape(null, null);
            if (sliceType == SliceType.Top)
            {
                var sortedRectanglesX = RectanglesXAxis.OrderByDescending(r => r.InsertionPoint.Y).ToList();
                foreach (var r in sortedRectanglesX)
                {
                    if (r.Ymax > YCoordinate && r.Ymin >= YCoordinate)
                    {
                        newShape.rectanglesXAxis.Add(r);
                    }
                    else if (r.Ymax >= YCoordinate && r.Ymin <= YCoordinate)
                    {
                        double thisRectHeight = r.Ymax - YCoordinate;
                        newShape.rectanglesXAxis.Add(new CompoundShapePart(r.b, thisRectHeight, new Point2D(0, r.Ymax - thisRectHeight / 2)));
                    }
                    else
                    {
                        //do nothing since this rectangle does not belong here
                    }

                }
            }
            else
            {
                var sortedRectanglesX = RectanglesXAxis.OrderBy(r => r.InsertionPoint.Y).ToList();
                foreach (var r in sortedRectanglesX)
                {
                    if (r.Ymax <= YCoordinate && r.Ymin < YCoordinate)
                    {
                        newShape.rectanglesXAxis.Add(r);
                    }
                    else if (r.Ymax > YCoordinate && r.Ymin <= YCoordinate)
                    {
                        double thisRectHeight =  YCoordinate - r.Ymin;
                        newShape.rectanglesXAxis.Add(new CompoundShapePart(r.b, thisRectHeight, new Point2D(0, r.Ymin + thisRectHeight / 2)));
                    }
                    else
                    {
                        //do nothing since this rectangle does not belong here
                    }

                }
            }

            return newShape;

            
        }
Пример #44
0
 //private int sliceNr;
 public Slice(Picture picture, SliceType sliceType)
 {
     this.picture = picture;
     macroblocks = new List<Macroblock>();
     this.sliceType = sliceType;
 }
Пример #45
0
        public H264Mb(CommonMbH264 eltMb)
            : base(eltMb)
        {
            m_Mode = eltMb.getMode();
            m_SliceType = eltMb.getSliceType();
            m_MbType = eltMb.getMbType();
            m_QP = eltMb.getQP();
            m_QPC = eltMb.getQPC();
            m_CBP = eltMb.getCBP();
            m_IsIntra16x16 = eltMb.isIntra16x16();
            m_IsInter8x8 = eltMb.isInter8x8();
            m_IsIntra = eltMb.isIntra();
            m_NumMbPart = 1;
            m_MbPartSize = new Size(16, 16);

            if (m_Mode == MbMode.INTRA_4X4)
            {
                m_Intra4x4PredModes = new Intra4x4PredMode[16];
                eltMb.getIntra4x4PredMode(m_Intra4x4PredModes);
            }
            else if (m_IsIntra16x16)
            {
                m_I16x16Type = (m_SliceType == SliceType.P_SLICE) ? (I16x16Type)(m_MbType - 5) : (I16x16Type)m_MbType;
            }
            else if (m_SliceType == SliceType.P_SLICE)
            {
                if (m_MbType < 5 || m_Mode == MbMode.MODE_SKIP)
                {
                    if (m_Mode == MbMode.MODE_SKIP)
                    {
                        m_NumMbPart = 1;
                        m_MbPartSize = new Size(16, 16);
                    }
                    else
                    {
                        m_PType = (PType)m_MbType;
                        if (m_MbType < PartNumP.Length)
                        {
                            m_NumMbPart = PartNumP[m_MbType];
                        }
                        if (m_MbType < PartSizeP.Length)
                        {
                            m_MbPartSize = new Size((int)PartSizeP[m_MbType][0], (int)PartSizeP[m_MbType][1]);
                        }
                    }
                }
                else if (m_MbType == 5)
                {
                    // I_4x4
                    Debug.Assert(false);
                    m_IsIntra = true;
                }
                else
                {
                    // I_16x16
                    m_I16x16Type = (I16x16Type)(m_MbType - 5);
                    m_IsIntra = true;
                    m_IsIntra16x16 = true;
                }
            }
            else if (m_SliceType == SliceType.B_SLICE)
            {
                m_BType = (BType)m_MbType;
                if (m_MbType < PartNumB.Length)
                {
                    m_NumMbPart = PartNumB[m_MbType];
                }
                if (m_MbType < PartSizeP.Length)
                {
                    m_MbPartSize = new Size((int)PartSizeB[m_MbType][0], (int)PartSizeB[m_MbType][1]);
                }
            }

            if (m_IsInter8x8)
            {
                m_BlkModes = new BlkMode[4];
                eltMb.getBlkModes(m_BlkModes);
            }

            if (m_IsIntra)
            {
                m_IntraChromaPredMode = eltMb.getIntraChromaPredMode();
            }
            else
            {
                m_ref_idx_L0 = new Int32[4];
                m_POC0 = new Int32[4];
                m_mvd_l0 = eltMb.getMvdL0();
                m_mvL0 = eltMb.getMvL0();
                eltMb.getRefIdxL0(m_ref_idx_L0);
                eltMb.getPOC0(m_POC0);
                if (SliceType == SliceType.B_SLICE)
                {
                    m_ref_idx_L1 = new Int32[4];
                    m_POC1 = new Int32[4];
                    m_mvd_l1 = eltMb.getMvdL1();
                    m_mvL1 = eltMb.getMvL1();
                    eltMb.getRefIdxL1(m_ref_idx_L1);
                    eltMb.getPOC1(m_POC1);
                }
            }

            /*** SVC ***/
            m_IsInCropWindow = eltMb.isInCropWindow();
            m_IsResidualPredictionFlag = eltMb.isResidualPredictionFlag();
            m_IsBLSkippedFlag = eltMb.isBLSkippedFlag();
        }
Пример #46
0
        /// <summary>
        /// Convert slice to full unit name.
        /// </summary>
        /// <param name="slice">
        ///     Slice string should be the same format with the ones in array:
        ///         _nucleusTruncateRules, _unsetTruncateRules, _codaTruncateRules.
        ///     For example : a+t1+b
        ///     The slice contains phone and tone.
        /// </param>
        /// <param name="type">Slice Type.</param>
        /// <returns>Full unit name.</returns>
        public static string BuildFullUnitName(string slice, SliceType type)
        {
            if (string.IsNullOrEmpty(slice))
            {
                throw new ArgumentNullException("slice");
            }

            string fullName = slice.Replace(" ", TtsUnit.PhoneDelimiter);
            switch (type)
            {
                case SliceType.Onset:
                    fullName = TtsUnit.OnsetPrefix + fullName;
                    break;
                case SliceType.Nucleus:
                    fullName = TtsUnit.NucleusPrefix + fullName;
                    break;
                case SliceType.Coda:
                    fullName = TtsUnit.CodaPrefix + fullName;
                    break;
                case SliceType.Special:
                    fullName = TtsUnit.NucleusPrefix + "_" + fullName + "_";
                    break;
                default:
                    Debug.Assert(false);
                    string message = string.Format(CultureInfo.InvariantCulture,
                        "[{0}]: Invalid slice type. Only Onset, Nuclues, Coda and Speical are support",
                        type);
                    throw new NotSupportedException(message);
            }

            return fullName;
        }