Beispiel #1
0
    private void Awake()
    {
        _repo           = new SaveClassRepo();
        _saveAttributes = _repo.Get();

        _record = _saveAttributes.Records[_difficultyManager.DifficultyLevel];
    }
        private void Awake()
        {
            _repo           = new SaveClassRepo();
            _saveAttributes = _repo.Get();

            for (int i = 0; i < _recordTexts.Length; i++)
            {
                _recordTexts[i].text = $"{_saveAttributes.Records[i]}";
            }
        }
Beispiel #3
0
    void loadFile()
    {
        if (!File.Exists(fileLocation))
        {
            return;
        }
        BinaryFormatter formatter = new BinaryFormatter();

        using (FileStream stream = new FileStream(fileLocation, FileMode.Open))
        {
            saveAttributes = formatter.Deserialize(stream) as SaveAttributes;
        }
        fileLoaded.Invoke();
    }
Beispiel #4
0
    protected override void Awake()
    {
        base.Awake();
        fileLocation   = Application.persistentDataPath + "/saveFile.dat";
        saveAttributes = new SaveAttributes();
        loadFile();
        var player = FindObjectOfType <Player>();

        if (player)
        {
            player.died.AddListener(addDeath);
        }
        SceneManager.sceneLoaded += SceneManager_sceneLoaded;
    }
Beispiel #5
0
        private byte[] SnapshotCanvas(Canvas canvas, SaveAttributes saveAtts)
        {
            var target = new RenderTargetBitmap(1182, 1020, 96 /** (float)(256d / 1182d)*/, 96 /** (float)(256d / 1020d)*/, PixelFormats.Pbgra32);
            var bmpEncoder = new PngBitmapEncoder();
            target.Render(canvas);

            bmpEncoder.Frames.Add(BitmapFrame.Create(target));
            using (var file = File.OpenWrite(@"C:\ImageData\" + saveAtts.FileName + ".png"))
            {
                bmpEncoder.Save(file);
            }

            System.Drawing.Image imageDcm = System.Drawing.Image.FromFile(@"C:\ImageData\"+saveAtts.FileName+".png");

            Bitmap bmpImage = new Bitmap(imageDcm);
            Bitmap gryBmpImage = MakeGrayscale(bmpImage);
            //gryBmpImage.Save(@"C:\ImageData\TestCheck.bmp");
            byte[] grayArray = ImageToArray(gryBmpImage);


            /*
            System.Windows.Controls.Image image = new System.Windows.Controls.Image();

            ImageConverter imgConv = new ImageConverter();

            MemoryStream ms = new MemoryStream(grayArray);
            BitmapImage bmpImg = new BitmapImage();
            bmpImg.BeginInit();
            bmpImg.StreamSource = ms;
            bmpImg.EndInit();
            image.Source = bmpImg;
            image.Width = image.Width * (float)(256d/1182d);
            image.Height = image.Height * (float)(256d/1020d);
            MemoryStream stream = (image.Source as BitmapImage).StreamSource as MemoryStream;
            byte[] imgArray = stream.ToArray();
            */


            //TODO delete code below
            ///////////////////////////////////////////////////////////////////
            //Need to save as 16 bit image.
            //Check to make sure image is properly converted and captured.
            //MemoryStream ms = new MemoryStream(grayArray);
            //var bencoder = new BmpBitmapEncoder();
            //bencoder.Frames.Add(BitmapFrame.Create(ms));
            //using(var file = File.OpenWrite(@"C:\ImageData\TestCheck.bmp"))
            //{
            //    bencoder.Save(file);
            //}
            ///////////////////////////////////////////////////////////////////


            //Uncomment?
            /*
            MemoryByteBuffer buffer = new MemoryByteBuffer(grayArray);
            DicomDataset dataSet = new DicomDataset();
            FillDataset(dataSet);
            dataSet.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Monochrome2.Value);
            dataSet.Add(DicomTag.Rows, (ushort)gryBmpImage.Height);
            dataSet.Add(DicomTag.Columns, (ushort)gryBmpImage.Width);
            DicomPixelData pixelData = DicomPixelData.Create(dataSet, true);
            pixelData.BitsStored = 16;
            pixelData.BitsAllocated = 16;
            pixelData.SamplesPerPixel = 1;
            pixelData.HighBit = 15;
            pixelData.PixelRepresentation = 0;
            pixelData.PlanarConfiguration = 0;
            pixelData.AddFrame(buffer);

            DicomFile dcmFile = new DicomFile(dataSet);
            dcmFile.Save(@"C:\ImageData\" + saveAtts.FileName + ".dcm");
            */
            return grayArray;
        }
Beispiel #6
0
 private DICOMObject CreateDICOMObject(byte[] image, SaveAttributes saveAtts, Canvas canvas, DICOMObject dcmObj)
 {
     try
     {
     DICOMObject dicomObj = UpdateDicomData(image, saveAtts, canvas, dcmObj);
         return dicomObj;
     }
     catch { return null; }
 }
Beispiel #7
0
 public bool WriteFile(DICOMObject dcmObj, SaveAttributes saveAtts)
 {
     try
     {
         DICOMFileWriter.WriteLittleEndian(@"C:\ImageData\" + saveAtts.FileName /*+ ".dcm"*/ + "_dcm.png", dcmObj);
         return true;
     }
     catch(Exception e) { System.Windows.MessageBox.Show(e.Message); return false; }
 }
Beispiel #8
0
        private DICOMObject UpdateDicomData(byte [] image, SaveAttributes saveAtts, Canvas canvas, DICOMObject dcmObj)
        {
            /*
            MemoryStream stream = new MemoryStream(image);
            stream.Seek(0, SeekOrigin.Begin);
            stream.Position = 0;
            System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
            Bitmap bmp = new Bitmap(img);
            bmp = GetValidImage(bmp);
            int rows, columns;
            byte[] pixels = GetPixels(bmp, out rows, out columns);
            MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);
            DicomDataset dataSet = new DicomDataset();
            FillDataset(dataSet);
            dataSet.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Monochrome2.Value);
            dataSet.Add(DicomTag.Rows, (ushort)rows);
            dataSet.Add(DicomTag.Columns, (ushort)columns);
            DicomPixelData pixelData = DicomPixelData.Create(dataSet, true);
            pixelData.BitsStored = 8;
            pixelData.BitsAllocated = 8;
            pixelData.SamplesPerPixel = 3;
            pixelData.HighBit = 7;
            pixelData.PixelRepresentation = 0;
            pixelData.PlanarConfiguration = 0;
            pixelData.AddFrame(buffer);

            DicomFile file = new DicomFile(dataSet);
            file.Save(@"C:\ImageData\"+saveAtts.FileName + ".dcm");
            */
            
            //try
            //{
            DICOMObject dicomObj = null;
            List<IDICOMElement> elem = new List<IDICOMElement>();
                IDICOMElement img = new EvilDICOM.Core.Element.OtherWordString(TagHelper.PIXEL_DATA, image);
                //IDICOMElement im = ElementFactory.GenerateElement(TagHelper.PIXEL_DATA, VR.OtherWordString, image, TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN);
                //dicomObj.Remove(TagHelper.PIXEL_DATA);
                //dicomObj.Elements.Add(img);
                elem.Add(img);
                IDICOMElement imageID = new EvilDICOM.Core.Element.ShortString(TagHelper.IMAGE_ID, saveAtts.FileName);
                //dicomObj.Remove(TagHelper.IMAGE_ID);
                //dicomObj.Elements.Add(imageID);
                elem.Add(imageID);
                IDICOMElement rows = new EvilDICOM.Core.Element.UnsignedShort(TagHelper.ROWS, 256);
                //dicomObj.Remove(TagHelper.ROWS);
                //dicomObj.Elements.Add(rows);
                elem.Add(rows);
                IDICOMElement columns = new EvilDICOM.Core.Element.UnsignedShort(TagHelper.COLUMNS, 256);
                //dicomObj.Remove(TagHelper.COLUMNS);
                //dicomObj.Elements.Add(columns);
                elem.Add(columns);
                IDICOMElement tranSynt = new EvilDICOM.Core.Element.UniqueIdentifier(TagHelper.TRANSFER_SYNTAX_UID, "1.2.840.10008.1.2.1");
                //dicomObj.Remove(TagHelper.TRANSFER_SYNTAX_UID);
                //dicomObj.Elements.Add(tranSynt);
                elem.Add(tranSynt);
                IDICOMElement pixSpace = new EvilDICOM.Core.Element.DecimalString(TagHelper.PIXEL_SPACING, 0);
                //dicomObj.Remove(TagHelper.PIXEL_SPACING);
                elem.Add(pixSpace);
                IDICOMElement sopID = new EvilDICOM.Core.Element.UniqueIdentifier(TagHelper.SOPCLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
                //dicomObj.Remove(TagHelper.SOPCLASS_UID);
                elem.Add(sopID);

                IDICOMElement photoMetrics = null, bitsAll = null, bitsStored = null, highBit = null, sampPerPix = null, numFrames = null;
                IDICOMElement windowCenter = null, windowWidth = null;
                switch(saveAtts.Color)
                {
                    case RadSysColor.MONOCHROME2:
                        photoMetrics = new EvilDICOM.Core.Element.CodeString(TagHelper.PHOTOMETRIC_INTERPRETATION, saveAtts.Color.ToString());
                        bitsAll = new EvilDICOM.Core.Element.UnsignedShort(TagHelper.BITS_ALLOCATED, 16);
                        bitsStored = new EvilDICOM.Core.Element.UnsignedShort(TagHelper.BITS_STORED, 16);
                        highBit = new EvilDICOM.Core.Element.UnsignedShort(TagHelper.HIGH_BIT, 15);
                        sampPerPix = new EvilDICOM.Core.Element.UnsignedShort(TagHelper.SAMPLES_PER_PIXEL, 1);
                        float center = float.Parse((dcmObj.FindFirst(TagHelper.WINDOW_CENTER) as EvilDICOM.Core.Element.DecimalString).UntypedData.ToString());
                        windowCenter = new EvilDICOM.Core.Element.DecimalString(TagHelper.WINDOW_CENTER, 128);
                        float wWidth = float.Parse((dcmObj.FindFirst(TagHelper.WINDOW_WIDTH) as EvilDICOM.Core.Element.DecimalString).UntypedData.ToString());
                        windowWidth = new EvilDICOM.Core.Element.DecimalString(TagHelper.WINDOW_WIDTH, 256);

                        break;
               //     default:
               //         System.Windows.MessageBox.Show("Unable to find a match for color scheme defined");
               //         return null;
                }
                switch (saveAtts.Type)
                {
                    case ImageType.PLANAR:
                        numFrames = new EvilDICOM.Core.Element.IntegerString(TagHelper.NUMBER_OF_FRAMES, 1);
                        break;
                    case ImageType.DYNAMIC:
                        break;
              //      default:
              //         System.Windows.MessageBox.Show("Unable to find a match for image type");
              //          return null;
                }
                //dicomObj.Remove(TagHelper.NUMBER_OF_FRAMES);
                //dicomObj.Elements.Add(numFrames);
                elem.Add(numFrames);
                //dicomObj.Remove(TagHelper.BITS_ALLOCATED);
                //dicomObj.Elements.Add(bitsAll);
                elem.Add(bitsAll);
                //dicomObj.Remove(TagHelper.BITS_STORED);
                //dicomObj.Elements.Add(bitsStored);
                elem.Add(bitsStored);
                //dicomObj.Remove(TagHelper.HIGH_BIT);
                //dicomObj.Elements.Add(highBit);
                elem.Add(highBit);
                //dicomObj.Remove(TagHelper.PHOTOMETRIC_INTERPRETATION);
                //dicomObj.Elements.Add(photoMetrics);
                elem.Add(photoMetrics);
                //dicomObj.Remove(TagHelper.SAMPLES_PER_PIXEL);
                //dicomObj.Elements.Add(sampPerPix);
                elem.Add(sampPerPix);
                //
                //dicomObj.Elements.Add(windowCenter);
                elem.Add(windowCenter);
                //  
                //dicomObj.Elements.Add(windowWidth);
                elem.Add(windowWidth);
            //dicomObj.Elements.AddRange(elem);
                dicomObj = new DICOMObject(elem);
                return dicomObj;
            //}
            //catch { return null; }*/
        }
Beispiel #9
0
        ///////////////////////////////////////////////////////////////////////////////
        #endregion

        #region Save Image Methods
        /******************************************************************************
         * Save Image Use Case 
         *****************************************************************************/
        public bool SaveAsNewImage(Canvas canvas, IExam exam, SaveAttributes saveAtts)
        {
            byte[] image = SnapshotCanvas(canvas, saveAtts);
            DICOMObject dicomObj = CreateDICOMObject(image, saveAtts, canvas, exam.Images[0].DicomObj);
            if (dicomObj != null && WriteFile(dicomObj, saveAtts))
            {
                NMImage nmImage = new NMImage(saveAtts, Exam.ExamID, Exam.TechInitials);
                if (nmImage.UpdateDB(saveAtts))
                    return true;

                System.Windows.MessageBox.Show("Not Working");
            }
            return false;
        }