Esempio n. 1
0
        private void ShowCurrentImage()
        {
            // Get the current image
            Shared <Imaging.Image> image = this.ImageVisualizationObject.CurrentValue.GetValueOrDefault().Data;

            if (image == null)
            {
                // There's no data, so use the default blank image
                using Shared <Imaging.Image> defaultImage = BlankImage.AddRef();
                this.DisplayImage.UpdateImage(defaultImage);
            }
            else if (this.ImageVisualizationObject.HorizontalFlip)
            {
                // Flip the image before displaying it
                Bitmap bitmap = image.Resource.ToBitmap(true);
                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
                using Shared <Imaging.Image> flippedImage = Shared.Create(Imaging.Image.FromBitmap(bitmap));
                this.DisplayImage.UpdateImage(flippedImage);
            }
            else
            {
                // Display the image normally
                this.DisplayImage.UpdateImage(image);
            }
        }
Esempio n. 2
0
        public void Serialize()
        {
            var buffer = new BufferWriter(100);
            var pool   = new SharedPool <byte[]>(() => new byte[10], 1);

            Shared <byte[]> s = pool.GetOrCreate();

            s.Resource[0] = 255;
            s.Resource[9] = 128;

            Shared <byte[]> s2 = pool.GetOrCreate();

            s2.Resource[0] = 1;
            s2.Resource[9] = 1;

            // serialize twice
            Serializer.Serialize(buffer, s, new SerializationContext());
            Serializer.Serialize(buffer, s2, new SerializationContext());
            Shared <byte[]> target = null;
            var             reader = new BufferReader(buffer.Buffer);

            Serializer.Deserialize(reader, ref target, new SerializationContext());

            Assert.AreEqual(255, target.Resource[0]);
            Assert.AreEqual(0, target.Resource[1]);
            Assert.AreEqual(0, target.Resource[8]);
            Assert.AreEqual(128, target.Resource[9]);

            // deserialize again reusing the first instance, make sure the first instance is not trampled over
            var firstTarget = target.AddRef();

            Serializer.Deserialize(reader, ref target, new SerializationContext());
            Assert.IsFalse(object.ReferenceEquals(firstTarget, target));
            Assert.IsFalse(object.ReferenceEquals(firstTarget.Inner, target.Inner));
            Assert.IsFalse(object.ReferenceEquals(firstTarget.Resource, target.Resource));
            Assert.AreEqual(1, target.Resource[0]);
            Assert.AreEqual(0, target.Resource[1]);
            Assert.AreEqual(0, target.Resource[8]);
            Assert.AreEqual(1, target.Resource[9]);

            // this should not throw, since refcount should be 1 on both
            firstTarget.Dispose();
            target.Dispose();
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageCameraView{T}"/> class.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="cameraIntrinsics">The camera intrinsics.</param>
 /// <param name="cameraPose">The camera pose.</param>
 public ImageCameraView(Shared <TImage> image, ICameraIntrinsics cameraIntrinsics, CoordinateSystem cameraPose)
     : base(image?.AddRef(), cameraIntrinsics, cameraPose)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageRectangle3D{T}"/> class.
 /// </summary>
 /// <param name="rectangle">The rectangle in 3D space to contain the image.</param>
 /// <param name="image">The image.</param>
 public ImageRectangle3D(Rectangle3D rectangle, Shared <T> image)
 {
     this.Rectangle3D = rectangle;
     this.Image       = image.AddRef();
 }