Example #1
0
        public override byte[] CreateSlicePixelData(Vector3D imagePositionPatient)
        {
            var rowOrientation    = RowOrientationPatient;
            var columnOrientation = ColumnOrientationPatient;
            var stackOrientation  = rowOrientation.Cross(columnOrientation).Normalize();

            // VTK reslice axes are in the volume coordinate system and should be positioned at the center of the desired output image
            var reslicePosition = imagePositionPatient + Columns * ColumnSpacing / 2f * rowOrientation + Rows * RowSpacing / 2f * columnOrientation;

            reslicePosition = VolumeReference.ConvertToVolume(reslicePosition);

            var resliceAxes = new Matrix(new[, ]
            {
                { rowOrientation.X, rowOrientation.Y, rowOrientation.Z, 0 },
                { columnOrientation.X, columnOrientation.Y, columnOrientation.Z, 0 },
                { stackOrientation.X, stackOrientation.Y, stackOrientation.Z, 0 },
                { 0, 0, 0, 1 }
            });

            resliceAxes = VolumeReference.RotateToVolumeOrientation(resliceAxes).Transpose();
            resliceAxes.SetColumn(3, reslicePosition.X, reslicePosition.Y, reslicePosition.Z, 1);

            if (Subsamples > 1)
            {
                // if subsampling is required, extract the thick slice ("slab") from the volume and then aggregate it using the specified projection method
                return(GetSlabPixelData(VolumeReference, resliceAxes, stackOrientation, Rows, Columns, Subsamples, RowSpacing, ColumnSpacing, SliceThickness, Interpolation, Projection));
            }
            else
            {
                // extract the (thin) slice from the volume
                return(GetSlicePixelData(VolumeReference, resliceAxes, Rows, Columns, RowSpacing, ColumnSpacing, Interpolation));
            }
        }
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, VolumeReference obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.Name, "name", JsonWriterExtensions.WriteStringValue);
            writer.WriteProperty(obj.DestinationPath, "destinationPath", JsonWriterExtensions.WriteStringValue);
            if (obj.ReadOnly != null)
            {
                writer.WriteProperty(obj.ReadOnly, "readOnly", JsonWriterExtensions.WriteBoolValue);
            }

            writer.WriteEndObject();
        }