Beispiel #1
0
        public Dataset Load(FileInfo file)
        {
            Stream ins = null;
            DcmParser parser = null;
            Dataset ds = null;

            try
            {
                try
                {
                    ins = new BufferedStream(new FileStream(file.FullName, FileMode.Open, FileAccess.Read));
                    parser = new DcmParser(ins);
                    FileFormat format = parser.DetectFileFormat();
                    if (format != null)
                    {
                        ds = new Dataset();
                        parser.DcmHandler = ds.DcmHandler;
                        parser.ParseDcmFile(format, Tags.PixelData);

                        //MessageBox.Show("Pomyślnie!");

                        return ds;
                    }
                    else
                    {
                        //MessageBox.Show("failed!");
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.StackTrace);
                }
            }
            finally
            {
                if (ins != null)
                {
                    try
                    {
                        ins.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }

            return null;
        }
Beispiel #2
0
 public virtual void ReadFile(Stream ins, FileFormat format, uint stopTag)
 {
     DcmParser Parser = new DcmParser(ins);
     Parser.DcmHandler = DcmHandler;
     Parser.ParseDcmFile(format, stopTag);
 }
Beispiel #3
0
 public virtual void ReadDataset(Stream ins, DcmDecodeParam param, uint stopTag)
 {
     DcmParser Parser = new DcmParser(ins);
     Parser.DcmHandler = DcmHandler;
     Parser.ParseDataset(param, stopTag);
 }
Beispiel #4
0
 public FileDataSource(DcmParser parser, Dataset ds, byte[] buffer)
 {
     this.parser = parser;
     this.ds = ds;
     this.buffer = buffer;
 }
Beispiel #5
0
        private FutureRSP SendDataset(ActiveAssociation active, DcmParser parser, Dataset ds)
        {
            String sopInstUID = ds.GetString(Tags.SOPInstanceUID);
            if (sopInstUID == null)
            {
                log.Error( "SOP instance UID is null" );
                return null;
            }
            String sopClassUID = ds.GetString(Tags.SOPClassUID);
            if (sopClassUID == null)
            {
                log.Error( "SOP class UID is null" );
                return null;
            }
            PresContext pc = null;
            Association assoc = active.Association;

            if (parser != null)
            {
                if (parser.DcmDecodeParam.encapsulated)
                {
                    String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID;
                    if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null)
                    {
                        log.Error( "SOP class UID not supported" );
                        return null;
                    }
                }
                else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null)
                {
                    log.Error( "SOP class UID not supported" );
                    return null;
                }

                return active.Invoke(aFact.NewDimse(pc.pcid(), oFact.NewCommand().InitCStoreRQ(assoc.NextMsgID(), sopClassUID, sopInstUID, 0), new FileDataSource(parser, ds, new byte[2048])));
            }
            else
            {
                if ((ds.GetFileMetaInfo() != null)
                &&	(ds.GetFileMetaInfo().TransferSyntaxUID != null))
                {
                    String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID;
                    if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null)
                    {
                        log.Error( "SOP class UID not supported" );
                        return null;
                    }
                }
                else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null)
                {
                    log.Error( "SOP class UID not supported" );
                    return null;
                }

                return active.Invoke(aFact.NewDimse(pc.pcid(), oFact.NewCommand().InitCStoreRQ(assoc.NextMsgID(), sopClassUID, sopInstUID, 0), ds));
            }

            return null;
        }
Beispiel #6
0
        /// <summary>
        /// Perform a WADO-GET
        /// </summary>
        public Dataset WADOGet(string url, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID)
        {
            if ((studyInstanceUID != null)
            &&	(seriesInstanceUID == null)
            ||	(sopInstanceUID == null))
            {
                if (seriesInstanceUID == null)
                {
                    Dataset[] ds = CFindSeries(studyInstanceUID, null);
                    if ((ds != null)
                    &&  (ds.Length == 1))
                    {
                        seriesInstanceUID = ds[0].GetString(Tags.SeriesInstanceUID);
                    }
                }

                if (seriesInstanceUID != null)
                {
                    Dataset[] ds = CFindInstance(seriesInstanceUID);
                    if ((ds != null)
                    &&  (ds.Length == 1))
                    {
                        sopInstanceUID = ds[0].GetString(Tags.SOPInstanceUID);
                    }
                }
            }

            if ((url == null)
            ||	(studyInstanceUID == null)
            ||	(seriesInstanceUID == null)
            ||	(sopInstanceUID == null)
            ||	(url.IndexOf('?') >= 0))
                return null;

            Dataset ret = null;
            System.Net.WebResponse response = null;

            try
            {
                StringBuilder sb = new StringBuilder(url);

                sb.Append("?requestType=WADO&studyUID=");
                sb.Append(System.Web.HttpUtility.UrlEncode(studyInstanceUID));
                sb.Append("&seriesUID=");
                sb.Append(System.Web.HttpUtility.UrlEncode(seriesInstanceUID));
                sb.Append("&objectUID=");
                sb.Append(System.Web.HttpUtility.UrlEncode(sopInstanceUID));

                System.Net.WebRequest request = System.Net.WebRequest.Create(sb.ToString());

                response = request.GetResponse();

                if (string.Compare(response.ContentType, "application/dicom") == 0)
                {
                    DcmParser parser = new DcmParser(response.GetResponseStream());

                    FileFormat format = parser.DetectFileFormat();
                    if (format != null)
                    {
                        ret = new Dataset();
                        parser.DcmHandler = ret.DcmHandler;
                        parser.ParseDcmFile(format, Tags.PixelData);
                    }
                }
            }
            finally
            {
                if (response != null)
                    response.Close();
            }

            return ret;
        }
Beispiel #7
0
        public void Load( FileInfo file )
        {
            Stream ins = null;
            DcmParser parser = null;
            Dataset ds = null;

            try
            {
                try
                {
                    ins = new BufferedStream(new FileStream(file.FullName, FileMode.Open, FileAccess.Read));
                    parser = new DcmParser(ins);
                    FileFormat format = parser.DetectFileFormat();
                    if (format != null)
                    {
                        ds = new Dataset();
                        parser.DcmHandler = ds.DcmHandler;
                        parser.ParseDcmFile(format, Tags.PixelData);

                        Console.WriteLine( "success!" );
                    }
                    else
                    {
                        Console.WriteLine( "failed!" );
                    }
                }
                catch( Exception e)
                {
                    Console.WriteLine( e.StackTrace );
                }
            }
            finally
            {
                if (ins != null)
                {
                    try
                    {
                        ins.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
        }
Beispiel #8
0
 private void storeToFile(DcmParser parser, Dataset ds, FileInfo file, DcmEncodeParam encParam)
 {
     Stream outs = openOutputStream(file);
     try
     {
         ds.WriteFile(outs, encParam);
         if (parser.ReadTag == Tags.PixelData)
         {
             ds.WriteHeader(outs, encParam, parser.ReadTag, parser.ReadVR, parser.ReadLength);
             copy(parser.InputStream, outs);
         }
     }
     finally
     {
         try
         {
             outs.Close();
         }
         catch (IOException ignore)
         {
         }
     }
 }
Beispiel #9
0
 public void Read(Stream ins)
 {
     DcmParser Parser = new DcmParser(ins);
     Parser.DcmHandler = DcmHandler;
     Parser.ParseCommand();
 }