annotate OrthancServer/FromDcmtkBridge.cpp @ 788:7ebe4bf87196

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 May 2014 18:39:36 +0200
parents efd0215736d9
children 55dae8c5a6ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 682
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
21 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
448
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
32
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
33
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
34 /*=========================================================================
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
35
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
36 This file is based on portions of the following project:
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
37
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
38 Program: GDCM (Grassroots DICOM). A DICOM library
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
39 Module: http://gdcm.sourceforge.net/Copyright.html
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
40
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
41 Copyright (c) 2006-2011 Mathieu Malaterre
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
42 Copyright (c) 1993-2005 CREATIS
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
43 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image)
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
44 All rights reserved.
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
45
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
46 Redistribution and use in source and binary forms, with or without
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
47 modification, are permitted provided that the following conditions are met:
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
48
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
49 * Redistributions of source code must retain the above copyright notice,
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
50 this list of conditions and the following disclaimer.
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
51
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
52 * Redistributions in binary form must reproduce the above copyright notice,
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
53 this list of conditions and the following disclaimer in the documentation
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
54 and/or other materials provided with the distribution.
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
55
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
56 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
57 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
58 endorse or promote products derived from this software without specific
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
59 prior written permission.
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
60
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
61 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
62 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
63 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
64 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
65 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
66 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
67 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
68 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
69 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
70 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
71
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
72 =========================================================================*/
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
73
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
74
71
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
75 #ifndef NOMINMAX
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
76 #define NOMINMAX
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
77 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 #include "FromDcmtkBridge.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 #include "ToDcmtkBridge.h"
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 106
diff changeset
82 #include "../Core/Toolbox.h"
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
83 #include "../Core/OrthancException.h"
454
6f47a4262618 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 448
diff changeset
84 #include "../Core/FileFormats/PngWriter.h"
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
85 #include "../Core/Uuid.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 #include "../Core/DicomFormat/DicomString.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 #include "../Core/DicomFormat/DicomNullValue.h"
79
297bad4e1019 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
88 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
90 #include <list>
71
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
91 #include <limits>
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
92
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 #include <boost/lexical_cast.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
95 #include <dcmtk/dcmdata/dcchrstr.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 #include <dcmtk/dcmdata/dcdicent.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 #include <dcmtk/dcmdata/dcdict.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 #include <dcmtk/dcmdata/dcfilefo.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 #include <dcmtk/dcmdata/dcistrmb.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
100 #include <dcmtk/dcmdata/dcuid.h>
661
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
101 #include <dcmtk/dcmdata/dcmetinf.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
102
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
103 #include <dcmtk/dcmdata/dcvrae.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
104 #include <dcmtk/dcmdata/dcvras.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
105 #include <dcmtk/dcmdata/dcvrcs.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
106 #include <dcmtk/dcmdata/dcvrda.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
107 #include <dcmtk/dcmdata/dcvrds.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
108 #include <dcmtk/dcmdata/dcvrdt.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 #include <dcmtk/dcmdata/dcvrfd.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 #include <dcmtk/dcmdata/dcvrfl.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
111 #include <dcmtk/dcmdata/dcvris.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
112 #include <dcmtk/dcmdata/dcvrlo.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
113 #include <dcmtk/dcmdata/dcvrlt.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
114 #include <dcmtk/dcmdata/dcvrpn.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
115 #include <dcmtk/dcmdata/dcvrsh.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 #include <dcmtk/dcmdata/dcvrsl.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 #include <dcmtk/dcmdata/dcvrss.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
118 #include <dcmtk/dcmdata/dcvrst.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
119 #include <dcmtk/dcmdata/dcvrtm.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
120 #include <dcmtk/dcmdata/dcvrui.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 #include <dcmtk/dcmdata/dcvrul.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 #include <dcmtk/dcmdata/dcvrus.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
123 #include <dcmtk/dcmdata/dcvrut.h>
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
124 #include <dcmtk/dcmdata/dcpixel.h>
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
125 #include <dcmtk/dcmdata/dcpixseq.h>
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
126 #include <dcmtk/dcmdata/dcpxitem.h>
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
127
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
129 #include <boost/math/special_functions/round.hpp>
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
130 #include <glog/logging.h>
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
131 #include <dcmtk/dcmdata/dcostrmb.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
133
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
134 static const char* CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
135
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
136
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
137
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
138 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
140 void ParsedDicomFile::Setup(const char* buffer, size_t size)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
141 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
142 DcmInputBufferStream is;
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
143 if (size > 0)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
144 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
145 is.setBuffer(buffer, size);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
146 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
147 is.setEos();
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
148
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
149 file_.reset(new DcmFileFormat);
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
150 file_->transferInit();
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
151 if (!file_->read(is).good())
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
152 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
153 throw OrthancException(ErrorCode_BadFileFormat);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
154 }
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
155 file_->loadAllDataIntoMemory();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
156 file_->transferEnd();
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
157 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
158
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
159
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
160 static void SendPathValueForDictionary(RestApiOutput& output,
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
161 DcmItem& dicom)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
162 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
163 Json::Value v = Json::arrayValue;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
164
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
165 for (unsigned long i = 0; i < dicom.card(); i++)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
166 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
167 DcmElement* element = dicom.getElement(i);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
168 if (element)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
169 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
170 char buf[16];
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
171 sprintf(buf, "%04x-%04x", element->getTag().getGTag(), element->getTag().getETag());
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
172 v.append(buf);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
173 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
174 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
175
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
176 output.AnswerJson(v);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
177 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
178
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
179 static inline uint16_t GetCharValue(char c)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
180 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
181 if (c >= '0' && c <= '9')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
182 return c - '0';
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
183 else if (c >= 'a' && c <= 'f')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
184 return c - 'a' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
185 else if (c >= 'A' && c <= 'F')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
186 return c - 'A' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
187 else
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
188 return 0;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
189 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
190
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
191 static inline uint16_t GetTagValue(const char* c)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
192 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
193 return ((GetCharValue(c[0]) << 12) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
194 (GetCharValue(c[1]) << 8) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
195 (GetCharValue(c[2]) << 4) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
196 GetCharValue(c[3]));
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
197 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
198
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
199 static void ParseTagAndGroup(DcmTagKey& key,
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
200 const std::string& tag)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
201 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
202 DicomTag t = FromDcmtkBridge::ParseTag(tag);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
203 key = DcmTagKey(t.GetGroup(), t.GetElement());
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
204 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
205
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
206
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
207 static void SendSequence(RestApiOutput& output,
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
208 DcmSequenceOfItems& sequence)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
209 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
210 // This element is a sequence
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
211 Json::Value v = Json::arrayValue;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
212
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
213 for (unsigned long i = 0; i < sequence.card(); i++)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
214 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
215 v.append(boost::lexical_cast<std::string>(i));
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
216 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
217
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
218 output.AnswerJson(v);
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
219 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
220
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
221
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
222 static unsigned int GetPixelDataBlockCount(DcmPixelData& pixelData,
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
223 E_TransferSyntax transferSyntax)
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
224 {
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
225 DcmPixelSequence* pixelSequence = NULL;
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
226 if (pixelData.getEncapsulatedRepresentation
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
227 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
228 {
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
229 return pixelSequence->card();
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
230 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
231 else
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
232 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
233 return 1;
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
234 }
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
235 }
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
236
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
237
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
238 static void AnswerDicomField(RestApiOutput& output,
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
239 DcmElement& element,
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
240 E_TransferSyntax transferSyntax)
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
241 {
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
242 // This element is nor a sequence, neither a pixel-data
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
243 std::string buffer;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
244 buffer.resize(65536);
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
245 Uint32 length = element.getLength(transferSyntax);
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
246 Uint32 offset = 0;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
247
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
248 output.GetLowLevelOutput().SendOkHeader(CONTENT_TYPE_OCTET_STREAM, true, length, NULL);
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
249
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
250 while (offset < length)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
251 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
252 Uint32 nbytes;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
253 if (length - offset < buffer.size())
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
254 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
255 nbytes = length - offset;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
256 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
257 else
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
258 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
259 nbytes = buffer.size();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
260 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
261
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
262 OFCondition cond = element.getPartialValue(&buffer[0], offset, nbytes);
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
263
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
264 if (cond.good())
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
265 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
266 output.GetLowLevelOutput().Send(&buffer[0], nbytes);
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
267 offset += nbytes;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
268 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
269 else
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
270 {
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
271 LOG(ERROR) << "Error while sending a DICOM field: " << cond.text();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
272 return;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
273 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
274 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
275
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
276 output.MarkLowLevelOutputDone();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
277 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
278
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
279
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
280 static bool AnswerPixelData(RestApiOutput& output,
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
281 DcmItem& dicom,
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
282 E_TransferSyntax transferSyntax,
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
283 const std::string* blockUri)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
284 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
285 DcmTag k(DICOM_TAG_PIXEL_DATA.GetGroup(),
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
286 DICOM_TAG_PIXEL_DATA.GetElement());
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
287
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
288 DcmElement *element = NULL;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
289 if (!dicom.findAndGetElement(k, element).good() ||
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
290 element == NULL)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
291 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
292 return false;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
293 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
294
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
295 try
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
296 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
297 DcmPixelData& pixelData = dynamic_cast<DcmPixelData&>(*element);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
298 if (blockUri == NULL)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
299 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
300 // The user asks how many blocks are presents in this pixel data
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
301 unsigned int blocks = GetPixelDataBlockCount(pixelData, transferSyntax);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
302
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
303 Json::Value result(Json::arrayValue);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
304 for (unsigned int i = 0; i < blocks; i++)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
305 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
306 result.append(boost::lexical_cast<std::string>(i));
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
307 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
308
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
309 output.AnswerJson(result);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
310 return true;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
311 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
312
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
313
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
314 unsigned int block = boost::lexical_cast<unsigned int>(*blockUri);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
315
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
316 if (block < GetPixelDataBlockCount(pixelData, transferSyntax))
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
317 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
318 DcmPixelSequence* pixelSequence = NULL;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
319 if (pixelData.getEncapsulatedRepresentation
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
320 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
321 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
322 // This is the case for JPEG transfer syntaxes
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
323 if (block < pixelSequence->card())
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
324 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
325 DcmPixelItem* pixelItem = NULL;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
326 if (pixelSequence->getItem(pixelItem, block).good() && pixelItem)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
327 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
328 if (pixelItem->getLength() == 0)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
329 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
330 output.AnswerBuffer(NULL, 0, CONTENT_TYPE_OCTET_STREAM);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
331 return true;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
332 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
333
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
334 Uint8* buffer = NULL;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
335 if (pixelItem->getUint8Array(buffer).good() && buffer)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
336 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
337 output.AnswerBuffer(buffer, pixelItem->getLength(), CONTENT_TYPE_OCTET_STREAM);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
338 return true;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
339 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
340 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
341 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
342 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
343 else
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
344 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
345 // This is the case for raw, uncompressed image buffers
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
346 assert(*blockUri == "0");
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
347 AnswerDicomField(output, *element, transferSyntax);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
348 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
349 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
350 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
351 catch (boost::bad_lexical_cast&)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
352 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
353 // The URI entered by the user is not a number
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
354 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
355 catch (std::bad_cast&)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
356 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
357 // This should never happen
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
358 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
359
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
360 return false;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
361 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
362
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
363
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
364
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
365 static void SendPathValueForLeaf(RestApiOutput& output,
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
366 const std::string& tag,
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
367 DcmItem& dicom,
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
368 E_TransferSyntax transferSyntax)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
369 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
370 DcmTagKey k;
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
371 ParseTagAndGroup(k, tag);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
372
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
373 DcmSequenceOfItems* sequence = NULL;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
374 if (dicom.findAndGetSequence(k, sequence).good() &&
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
375 sequence != NULL &&
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
376 sequence->getVR() == EVR_SQ)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
377 {
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
378 SendSequence(output, *sequence);
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
379 return;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
380 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
381
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
382 DcmElement* element = NULL;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
383 if (dicom.findAndGetElement(k, element).good() &&
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
384 element != NULL &&
318
b83d85a85d69 fix for private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
385 //element->getVR() != EVR_UNKNOWN && // This would forbid private tags
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
386 element->getVR() != EVR_SQ)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
387 {
676
aa5ca7a2166f experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 661
diff changeset
388 AnswerDicomField(output, *element, transferSyntax);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
389 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
390 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
391
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
392 void ParsedDicomFile::SendPathValue(RestApiOutput& output,
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
393 const UriComponents& uri)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
394 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
395 DcmItem* dicom = file_->getDataset();
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
396 E_TransferSyntax transferSyntax = file_->getDataset()->getOriginalXfer();
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
397
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
398 // Special case: Accessing the pixel data
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
399 if (uri.size() == 1 ||
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
400 uri.size() == 2)
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
401 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
402 DcmTagKey tag;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
403 ParseTagAndGroup(tag, uri[0]);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
404
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
405 if (tag.getGroup() == DICOM_TAG_PIXEL_DATA.GetGroup() &&
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
406 tag.getElement() == DICOM_TAG_PIXEL_DATA.GetElement())
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
407 {
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
408 AnswerPixelData(output, *dicom, transferSyntax, uri.size() == 1 ? NULL : &uri[1]);
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
409 return;
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
410 }
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
411 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
412
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
413 // Go down in the tag hierarchy according to the URI
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
414 for (size_t pos = 0; pos < uri.size() / 2; pos++)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
415 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
416 size_t index;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
417 try
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
418 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
419 index = boost::lexical_cast<size_t>(uri[2 * pos + 1]);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
420 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
421 catch (boost::bad_lexical_cast&)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
422 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
423 return;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
424 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
425
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
426 DcmTagKey k;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
427 DcmItem *child = NULL;
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
428 ParseTagAndGroup(k, uri[2 * pos]);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
429 if (!dicom->findAndGetSequenceItem(k, child, index).good() ||
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
430 child == NULL)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
431 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
432 return;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
433 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
434
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
435 dicom = child;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
436 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
437
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
438 // We have reached the end of the URI
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
439 if (uri.size() % 2 == 0)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
440 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
441 SendPathValueForDictionary(output, *dicom);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
442 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
443 else
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
444 {
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
445 SendPathValueForLeaf(output, uri.back(), *dicom, transferSyntax);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
446 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
447 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
448
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
449
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
450
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
451
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
452
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
453 static DcmElement* CreateElementForTag(const DicomTag& tag)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
454 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
455 DcmTag key(tag.GetGroup(), tag.GetElement());
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
456
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
457 switch (key.getEVR())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
458 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
459 // http://support.dcmtk.org/docs/dcvr_8h-source.html
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
460
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
461 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
462 * TODO.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
463 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
464
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
465 case EVR_OB: // other byte
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
466 case EVR_OF: // other float
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
467 case EVR_OW: // other word
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
468 case EVR_AT: // attribute tag
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
469 throw OrthancException(ErrorCode_NotImplemented);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
470
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
471 case EVR_UN: // unknown value representation
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
472 throw OrthancException(ErrorCode_ParameterOutOfRange);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
473
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
474
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
475 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
476 * String types.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
477 * http://support.dcmtk.org/docs/classDcmByteString.html
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
478 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
479
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
480 case EVR_AS: // age string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
481 return new DcmAgeString(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
482
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
483 case EVR_AE: // application entity title
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
484 return new DcmApplicationEntity(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
485
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
486 case EVR_CS: // code string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
487 return new DcmCodeString(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
488
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
489 case EVR_DA: // date string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
490 return new DcmDate(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
491
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
492 case EVR_DT: // date time string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
493 return new DcmDateTime(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
494
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
495 case EVR_DS: // decimal string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
496 return new DcmDecimalString(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
497
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
498 case EVR_IS: // integer string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
499 return new DcmIntegerString(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
500
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
501 case EVR_TM: // time string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
502 return new DcmTime(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
503
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
504 case EVR_UI: // unique identifier
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
505 return new DcmUniqueIdentifier(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
506
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
507 case EVR_ST: // short text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
508 return new DcmShortText(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
509
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
510 case EVR_LO: // long string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
511 return new DcmLongString(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
512
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
513 case EVR_LT: // long text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
514 return new DcmLongText(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
515
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
516 case EVR_UT: // unlimited text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
517 return new DcmUnlimitedText(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
518
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
519 case EVR_SH: // short string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
520 return new DcmShortString(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
521
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
522 case EVR_PN: // person name
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
523 return new DcmPersonName(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
524
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
525
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
526 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
527 * Numerical types
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
528 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
529
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
530 case EVR_SL: // signed long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
531 return new DcmSignedLong(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
532
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
533 case EVR_SS: // signed short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
534 return new DcmSignedShort(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
535
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
536 case EVR_UL: // unsigned long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
537 return new DcmUnsignedLong(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
538
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
539 case EVR_US: // unsigned short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
540 return new DcmUnsignedShort(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
541
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
542 case EVR_FL: // float single-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
543 return new DcmFloatingPointSingle(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
544
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
545 case EVR_FD: // float double-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
546 return new DcmFloatingPointDouble(key);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
547
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
548
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
549 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
550 * Sequence types, should never occur at this point.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
551 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
552
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
553 case EVR_SQ: // sequence of items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
554 throw OrthancException(ErrorCode_ParameterOutOfRange);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
555
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
556
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
557 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
558 * Internal to DCMTK.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
559 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
560
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
561 case EVR_ox: // OB or OW depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
562 case EVR_xs: // SS or US depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
563 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
564 case EVR_na: // na="not applicable", for data which has no VR
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
565 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
566 case EVR_item: // used internally for items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
567 case EVR_metainfo: // used internally for meta info datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
568 case EVR_dataset: // used internally for datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
569 case EVR_fileFormat: // used internally for DICOM files
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
570 case EVR_dicomDir: // used internally for DICOMDIR objects
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
571 case EVR_dirRecord: // used internally for DICOMDIR records
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
572 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
573 case EVR_pixelItem: // used internally for pixel items in a compressed image
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
574 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
575 case EVR_PixelData: // used internally for uncompressed pixeld data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
576 case EVR_OverlayData: // used internally for overlay data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
577 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
578 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
579 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
580 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
581
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
582 throw OrthancException(ErrorCode_InternalError);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
583 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
584
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
585
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
586
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
587 static void FillElementWithString(DcmElement& element,
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
588 const DicomTag& tag,
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
589 const std::string& value)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
590 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
591 DcmTag key(tag.GetGroup(), tag.GetElement());
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
592 bool ok = false;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
593
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
594 try
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
595 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
596 switch (key.getEVR())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
597 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
598 // http://support.dcmtk.org/docs/dcvr_8h-source.html
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
599
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
600 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
601 * TODO.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
602 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
603
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
604 case EVR_OB: // other byte
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
605 case EVR_OF: // other float
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
606 case EVR_OW: // other word
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
607 case EVR_AT: // attribute tag
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
608 throw OrthancException(ErrorCode_NotImplemented);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
609
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
610 case EVR_UN: // unknown value representation
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
611 throw OrthancException(ErrorCode_ParameterOutOfRange);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
612
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
613
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
614 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
615 * String types.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
616 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
617
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
618 case EVR_DS: // decimal string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
619 case EVR_IS: // integer string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
620 case EVR_AS: // age string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
621 case EVR_DA: // date string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
622 case EVR_DT: // date time string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
623 case EVR_TM: // time string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
624 case EVR_AE: // application entity title
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
625 case EVR_CS: // code string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
626 case EVR_SH: // short string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
627 case EVR_LO: // long string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
628 case EVR_ST: // short text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
629 case EVR_LT: // long text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
630 case EVR_UT: // unlimited text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
631 case EVR_PN: // person name
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
632 case EVR_UI: // unique identifier
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
633 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
634 ok = element.putString(value.c_str()).good();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
635 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
636 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
637
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
638
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
639 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
640 * Numerical types
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
641 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
642
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
643 case EVR_SL: // signed long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
644 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
645 ok = element.putSint32(boost::lexical_cast<Sint32>(value)).good();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
646 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
647 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
648
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
649 case EVR_SS: // signed short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
650 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
651 ok = element.putSint16(boost::lexical_cast<Sint16>(value)).good();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
652 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
653 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
654
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
655 case EVR_UL: // unsigned long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
656 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
657 ok = element.putUint32(boost::lexical_cast<Uint32>(value)).good();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
658 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
659 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
660
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
661 case EVR_US: // unsigned short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
662 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
663 ok = element.putUint16(boost::lexical_cast<Uint16>(value)).good();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
664 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
665 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
666
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
667 case EVR_FL: // float single-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
668 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
669 ok = element.putFloat32(boost::lexical_cast<float>(value)).good();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
670 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
671 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
672
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
673 case EVR_FD: // float double-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
674 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
675 ok = element.putFloat64(boost::lexical_cast<double>(value)).good();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
676 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
677 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
678
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
679
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
680 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
681 * Sequence types, should never occur at this point.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
682 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
683
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
684 case EVR_SQ: // sequence of items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
685 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
686 ok = false;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
687 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
688 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
689
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
690
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
691 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
692 * Internal to DCMTK.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
693 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
694
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
695 case EVR_ox: // OB or OW depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
696 case EVR_xs: // SS or US depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
697 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
698 case EVR_na: // na="not applicable", for data which has no VR
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
699 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
700 case EVR_item: // used internally for items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
701 case EVR_metainfo: // used internally for meta info datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
702 case EVR_dataset: // used internally for datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
703 case EVR_fileFormat: // used internally for DICOM files
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
704 case EVR_dicomDir: // used internally for DICOMDIR objects
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
705 case EVR_dirRecord: // used internally for DICOMDIR records
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
706 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
707 case EVR_pixelItem: // used internally for pixel items in a compressed image
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
708 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
709 case EVR_PixelData: // used internally for uncompressed pixeld data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
710 case EVR_OverlayData: // used internally for overlay data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
711 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
712 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
713 break;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
714 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
715 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
716 catch (boost::bad_lexical_cast&)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
717 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
718 ok = false;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
719 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
720
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
721 if (!ok)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
722 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
723 throw OrthancException(ErrorCode_InternalError);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
724 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
725 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
726
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
727
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
728 void ParsedDicomFile::Remove(const DicomTag& tag)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
729 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
730 DcmTagKey key(tag.GetGroup(), tag.GetElement());
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
731 DcmElement* element = file_->getDataset()->remove(key);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
732 if (element != NULL)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
733 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
734 delete element;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
735 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
736 }
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
737
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
738
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
739
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
740 void ParsedDicomFile::RemovePrivateTags()
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
741 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
742 typedef std::list<DcmElement*> Tags;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
743
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
744 Tags privateTags;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
745
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
746 DcmDataset& dataset = *file_->getDataset();
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
747 for (unsigned long i = 0; i < dataset.card(); i++)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
748 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
749 DcmElement* element = dataset.getElement(i);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
750 DcmTag tag(element->getTag());
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
751 if (!strcmp("PrivateCreator", tag.getTagName()) || // TODO - This may change with future versions of DCMTK
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
752 tag.getPrivateCreator() != NULL)
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
753 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
754 privateTags.push_back(element);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
755 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
756 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
757
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
758 for (Tags::iterator it = privateTags.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
759 it != privateTags.end(); ++it)
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
760 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
761 DcmElement* tmp = dataset.remove(*it);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
762 if (tmp != NULL)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
763 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
764 delete tmp;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
765 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
766 }
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
767 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
768
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
769
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
770
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
771 void ParsedDicomFile::Insert(const DicomTag& tag,
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
772 const std::string& value)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
773 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
774 std::auto_ptr<DcmElement> element(CreateElementForTag(tag));
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
775 FillElementWithString(*element, tag, value);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
776
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
777 if (!file_->getDataset()->insert(element.release(), false, false).good())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
778 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
779 // This field already exists
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
780 throw OrthancException(ErrorCode_InternalError);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
781 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
782 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
783
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
784
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
785 void ParsedDicomFile::Replace(const DicomTag& tag,
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
786 const std::string& value,
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
787 FromDcmtkBridge::ReplaceMode mode)
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
788 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
789 DcmTagKey key(tag.GetGroup(), tag.GetElement());
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
790 DcmElement* element = NULL;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
791
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
792 if (!file_->getDataset()->findAndGetElement(key, element).good() ||
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
793 element == NULL)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
794 {
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
795 // This field does not exist, act wrt. the specified "mode"
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
796 switch (mode)
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
797 {
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
798 case FromDcmtkBridge::ReplaceMode_InsertIfAbsent:
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
799 Insert(tag, value);
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
800 break;
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
801
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
802 case FromDcmtkBridge::ReplaceMode_ThrowIfAbsent:
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
803 throw OrthancException(ErrorCode_InexistentItem);
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
804
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
805 case FromDcmtkBridge::ReplaceMode_IgnoreIfAbsent:
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
806 return;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
807 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
808 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
809 else
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
810 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
811 FillElementWithString(*element, tag, value);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
812 }
303
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
813
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
814
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
815 /**
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
816 * dcmodify will automatically correct 'Media Storage SOP Class
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
817 * UID' and 'Media Storage SOP Instance UID' in the metaheader, if
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
818 * you make changes to the related tags in the dataset ('SOP Class
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
819 * UID' and 'SOP Instance UID') via insert or modify mode
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
820 * options. You can disable this behaviour by using the -nmu
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
821 * option.
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
822 **/
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
823
303
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
824 if (tag == DICOM_TAG_SOP_CLASS_UID)
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
825 {
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
826 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value,
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
827 FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
828 }
303
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
829
c76a35a85c69 ready for anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
830 if (tag == DICOM_TAG_SOP_INSTANCE_UID)
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
831 {
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
832 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value,
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
833 FromDcmtkBridge::ReplaceMode_InsertIfAbsent);
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
834 }
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
835 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
836
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
837
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
838 void ParsedDicomFile::Answer(RestApiOutput& output)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
839 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
840 std::string serialized;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
841 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, file_->getDataset()))
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
842 {
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
843 output.AnswerBuffer(serialized, CONTENT_TYPE_OCTET_STREAM);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
844 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
845 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
846
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
847
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
848
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
849 bool ParsedDicomFile::GetTagValue(std::string& value,
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
850 const DicomTag& tag)
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
851 {
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
852 DcmTagKey k(tag.GetGroup(), tag.GetElement());
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
853 DcmDataset& dataset = *file_->getDataset();
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
854 DcmElement* element = NULL;
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
855 if (!dataset.findAndGetElement(k, element).good() ||
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
856 element == NULL)
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
857 {
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
858 return false;
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
859 }
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
860
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
861 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element));
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
862
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
863 if (v.get() == NULL)
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
864 {
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
865 value = "";
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
866 }
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
867 else
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
868 {
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
869 value = v->AsString();
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
870 }
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
871
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
872 return true;
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
873 }
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
874
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
875
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
876
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
877 DicomInstanceHasher ParsedDicomFile::GetHasher()
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
878 {
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
879 std::string patientId, studyUid, seriesUid, instanceUid;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
880
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
881 if (!GetTagValue(patientId, DICOM_TAG_PATIENT_ID) ||
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
882 !GetTagValue(studyUid, DICOM_TAG_STUDY_INSTANCE_UID) ||
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
883 !GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID) ||
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
884 !GetTagValue(instanceUid, DICOM_TAG_SOP_INSTANCE_UID))
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
885 {
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
886 throw OrthancException(ErrorCode_BadFileFormat);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
887 }
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
888
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
889 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
890 }
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
891
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
892
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 void FromDcmtkBridge::Convert(DicomMap& target, DcmDataset& dataset)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 target.Clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 for (unsigned long i = 0; i < dataset.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 DcmElement* element = dataset.getElement(i);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 if (element && element->isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 target.SetValue(element->getTag().getGTag(),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 element->getTag().getETag(),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 ConvertLeafElement(*element));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 return DicomTag(element.getGTag(), element.getETag());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 if (!element.isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
919 throw OrthancException("Only applicable to leaf elements");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 if (element.isaString())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 char *c;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 if (element.getString(c).good() &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 c != NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 std::string s(c);
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 106
diff changeset
929 std::string utf8 = Toolbox::ConvertToUtf8(s, "ISO-8859-1"); // TODO Parameter?
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 return new DicomString(utf8);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 return new DicomNullValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 // http://support.dcmtk.org/docs/dcvr_8h-source.html
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 switch (element.getVR())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 /**
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 * TODO.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 **/
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
947
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
948 case EVR_OB: // other byte
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
949 case EVR_OF: // other float
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
950 case EVR_OW: // other word
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
951 case EVR_AT: // attribute tag
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
952 case EVR_UN: // unknown value representation
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
953 return new DicomNullValue();
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
954
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
955 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
956 * String types, should never happen at this point because of
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
957 * "element.isaString()".
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
958 **/
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
959
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
960 case EVR_DS: // decimal string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
961 case EVR_IS: // integer string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
962 case EVR_AS: // age string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
963 case EVR_DA: // date string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
964 case EVR_DT: // date time string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
965 case EVR_TM: // time string
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
966 case EVR_AE: // application entity title
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
967 case EVR_CS: // code string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
968 case EVR_SH: // short string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
969 case EVR_LO: // long string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
970 case EVR_ST: // short text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
971 case EVR_LT: // long text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
972 case EVR_UT: // unlimited text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
973 case EVR_PN: // person name
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
974 case EVR_UI: // unique identifier
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
975 return new DicomNullValue();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
978 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
979 * Numerical types
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
980 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
982 case EVR_SL: // signed long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
983 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
984 Sint32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
985 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
986 return new DicomString(boost::lexical_cast<std::string>(f));
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
987 else
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
988 return new DicomNullValue();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
989 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
990
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
991 case EVR_SS: // signed short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
992 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
993 Sint16 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
994 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
995 return new DicomString(boost::lexical_cast<std::string>(f));
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
996 else
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
997 return new DicomNullValue();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
998 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
999
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1000 case EVR_UL: // unsigned long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1001 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1002 Uint32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1003 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1004 return new DicomString(boost::lexical_cast<std::string>(f));
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1005 else
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1006 return new DicomNullValue();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1007 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1008
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1009 case EVR_US: // unsigned short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1010 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1011 Uint16 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1012 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1013 return new DicomString(boost::lexical_cast<std::string>(f));
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1014 else
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1015 return new DicomNullValue();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1016 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1017
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1018 case EVR_FL: // float single-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1019 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1020 Float32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1021 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1022 return new DicomString(boost::lexical_cast<std::string>(f));
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1023 else
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1024 return new DicomNullValue();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1025 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1026
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1027 case EVR_FD: // float double-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1028 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1029 Float64 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1030 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good())
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1031 return new DicomString(boost::lexical_cast<std::string>(f));
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1032 else
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1033 return new DicomNullValue();
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1034 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 /**
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1038 * Sequence types, should never occur at this point because of
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1039 * "element.isLeaf()".
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1040 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1042 case EVR_SQ: // sequence of items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1043 return new DicomNullValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1046 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1047 * Internal to DCMTK.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1048 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1050 case EVR_ox: // OB or OW depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1051 case EVR_xs: // SS or US depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1052 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1053 case EVR_na: // na="not applicable", for data which has no VR
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1054 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1055 case EVR_item: // used internally for items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1056 case EVR_metainfo: // used internally for meta info datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1057 case EVR_dataset: // used internally for datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1058 case EVR_fileFormat: // used internally for DICOM files
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1059 case EVR_dicomDir: // used internally for DICOMDIR objects
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1060 case EVR_dirRecord: // used internally for DICOMDIR records
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1061 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1062 case EVR_pixelItem: // used internally for pixel items in a compressed image
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1063 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1064 case EVR_PixelData: // used internally for uncompressed pixeld data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1065 case EVR_OverlayData: // used internally for overlay data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1066 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1067 return new DicomNullValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1070 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1071 * Default case.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1072 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1074 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1075 return new DicomNullValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 catch (boost::bad_lexical_cast)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 return new DicomNullValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 }
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1082 catch (std::bad_cast)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1083 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1084 return new DicomNullValue;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1085 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 static void StoreElement(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 DcmElement& element,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 unsigned int maxStringLength);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 static void StoreItem(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 DcmItem& item,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 unsigned int maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 target = Json::Value(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 for (unsigned long i = 0; i < item.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101 DcmElement* element = item.getElement(i);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 StoreElement(target, *element, maxStringLength);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 static void StoreElement(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 DcmElement& element,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 unsigned int maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 assert(target.type() == Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1113 DicomTag tag(FromDcmtkBridge::GetTag(element));
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1114 const std::string formattedTag = tag.Format();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1115
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1116 #if 0
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1117 const std::string tagName = FromDcmtkBridge::GetName(tag);
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1118 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1119 // This version of the code gives access to the name of the private tags
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1120 DcmTag tagbis(element.getTag());
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1121 const std::string tagName(tagbis.getTagName());
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1122 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 if (element.isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1126 Json::Value value(Json::objectValue);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1127 value["Name"] = tagName;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1128
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1129 if (tagbis.getPrivateCreator() != NULL)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1130 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1131 value["PrivateCreator"] = tagbis.getPrivateCreator();
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1132 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1133
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135 if (v->IsNull())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1137 value["Type"] = "Null";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1138 value["Value"] = Json::nullValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 std::string s = v->AsString();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 if (maxStringLength == 0 ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 s.size() <= maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1146 value["Type"] = "String";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1147 value["Value"] = s;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1151 value["Type"] = "TooLong";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1152 value["Value"] = Json::nullValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 }
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1155
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1156 target[formattedTag] = value;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1160 Json::Value children(Json::arrayValue);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 // "All subclasses of DcmElement except for DcmSequenceOfItems
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 // etc. are not." The following cast is thus OK.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 for (unsigned long i = 0; i < sequence.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 DcmItem* child = sequence.getItem(i);
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1170 Json::Value& v = children.append(Json::objectValue);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 StoreItem(v, *child, maxStringLength);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 }
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1173
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1174 target[formattedTag]["Name"] = tagName;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1175 target[formattedTag]["Type"] = "Sequence";
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
1176 target[formattedTag]["Value"] = children;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181 void FromDcmtkBridge::ToJson(Json::Value& root,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182 DcmDataset& dataset,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 unsigned int maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 StoreItem(root, dataset, maxStringLength);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 void FromDcmtkBridge::ToJson(Json::Value& target,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 const std::string& path,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 unsigned int maxStringLength)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 DcmFileFormat dicom;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195 if (!dicom.loadFile(path.c_str()).good())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
1197 throw OrthancException(ErrorCode_BadFileFormat);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1206 static void ExtractPngImageColorPreview(std::string& result,
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1207 DicomIntegerPixelAccessor& accessor)
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1208 {
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1209 assert(accessor.GetChannelCount() == 3);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1210 PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1211
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1212 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight() * 3, 0);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1213 uint8_t* pixel = &image[0];
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1214
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1215 for (unsigned int y = 0; y < accessor.GetHeight(); y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1216 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1217 for (unsigned int x = 0; x < accessor.GetWidth(); x++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1218 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1219 for (unsigned int c = 0; c < 3; c++, pixel++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1220 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1221 int32_t v = accessor.GetValue(x, y, c);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1222 if (v < 0)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1223 *pixel = 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1224 else if (v > 255)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1225 *pixel = 255;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1226 else
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1227 *pixel = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1228 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1229 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1230 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1231
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1232 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(),
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1233 accessor.GetWidth() * 3, PixelFormat_RGB24, &image[0]);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1234 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1235
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1236
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1237 static void ExtractPngImageGrayscalePreview(std::string& result,
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1238 DicomIntegerPixelAccessor& accessor)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1239 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1240 assert(accessor.GetChannelCount() == 1);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1241 PngWriter w;
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1242
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1243 int32_t min, max;
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1244 accessor.GetExtremeValues(min, max);
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1245
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1246 std::vector<uint8_t> image(accessor.GetWidth() * accessor.GetHeight(), 0);
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1247 if (min != max)
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1248 {
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1249 uint8_t* pixel = &image[0];
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1250 for (unsigned int y = 0; y < accessor.GetHeight(); y++)
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1251 {
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1252 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++)
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1253 {
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1254 int32_t v = accessor.GetValue(x, y);
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1255 *pixel = static_cast<uint8_t>(
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1256 boost::math::lround(static_cast<float>(v - min) /
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1257 static_cast<float>(max - min) * 255.0f));
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1258 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1259 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1260 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1261
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1262 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(),
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1263 accessor.GetWidth(), PixelFormat_Grayscale8, &image[0]);
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1264 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1265
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1266
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1267 template <typename T>
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1268 static void ExtractPngImageTruncate(std::string& result,
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1269 DicomIntegerPixelAccessor& accessor,
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1270 PixelFormat format)
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1271 {
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1272 assert(accessor.GetChannelCount() == 1);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1273
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1274 PngWriter w;
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1275
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1276 std::vector<T> image(accessor.GetWidth() * accessor.GetHeight(), 0);
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1277 T* pixel = &image[0];
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1278 for (unsigned int y = 0; y < accessor.GetHeight(); y++)
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1279 {
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1280 for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++)
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1281 {
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1282 int32_t v = accessor.GetValue(x, y);
464
5987dd8e0776 fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
1283 if (v < static_cast<int32_t>(std::numeric_limits<T>::min()))
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1284 *pixel = std::numeric_limits<T>::min();
464
5987dd8e0776 fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
1285 else if (v > static_cast<int32_t>(std::numeric_limits<T>::max()))
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1286 *pixel = std::numeric_limits<T>::max();
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1287 else
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1288 *pixel = static_cast<T>(v);
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1289 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1290 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1291
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1292 w.WriteToMemory(result, accessor.GetWidth(), accessor.GetHeight(),
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1293 accessor.GetWidth() * sizeof(T), format, &image[0]);
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1294 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1295
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1296
319
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1297 static bool DecodePsmctRle1(std::string& output,
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1298 DcmDataset& dataset)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1299 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1300 static const DicomTag tagContent(0x07a1, 0x100a);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1301 static const DicomTag tagCompressionType(0x07a1, 0x1011);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1302
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1303 DcmElement* e;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1304 char* c;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1305
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1306 // Check whether the DICOM instance contains an image encoded with
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1307 // the PMSCT_RLE1 scheme.
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1308 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(tagCompressionType), e).good() ||
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1309 e == NULL ||
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1310 !e->isaString() ||
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1311 !e->getString(c).good() ||
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1312 c == NULL ||
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1313 strcmp("PMSCT_RLE1", c))
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1314 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1315 return false;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1316 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1317
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1318 // OK, this is a custom RLE encoding from Philips. Get the pixel
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1319 // data from the appropriate private DICOM tag.
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1320 Uint8* pixData = NULL;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1321 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(tagContent), e).good() ||
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1322 e == NULL ||
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1323 e->getUint8Array(pixData) != EC_Normal)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1324 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1325 return false;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1326 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1327
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1328 // The "unsigned" below IS VERY IMPORTANT
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1329 const uint8_t* inbuffer = reinterpret_cast<const uint8_t*>(pixData);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1330 const size_t length = e->getLength();
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1331
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1332 /**
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1333 * The code below is an adaptation of a sample code for GDCM by
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1334 * Mathieu Malaterre (under a BSD license).
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1335 * http://gdcm.sourceforge.net/html/rle2img_8cxx-example.html
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1336 **/
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1337
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1338 // RLE pass
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1339 std::vector<uint8_t> temp;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1340 temp.reserve(length);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1341 for (size_t i = 0; i < length; i++)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1342 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1343 if (inbuffer[i] == 0xa5)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1344 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1345 temp.push_back(inbuffer[i+2]);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1346 for (uint8_t repeat = inbuffer[i + 1]; repeat != 0; repeat--)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1347 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1348 temp.push_back(inbuffer[i+2]);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1349 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1350 i += 2;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1351 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1352 else
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1353 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1354 temp.push_back(inbuffer[i]);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1355 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1356 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1357
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1358 // Delta encoding pass
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1359 uint16_t delta = 0;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1360 output.clear();
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1361 output.reserve(temp.size());
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1362 for (size_t i = 0; i < temp.size(); i++)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1363 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1364 uint16_t value;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1365
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1366 if (temp[i] == 0x5a)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1367 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1368 uint16_t v1 = temp[i + 1];
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1369 uint16_t v2 = temp[i + 2];
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1370 value = (v2 << 8) + v1;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1371 i += 2;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1372 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1373 else
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1374 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1375 value = delta + (int8_t) temp[i];
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1376 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1377
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1378 output.push_back(value & 0xff);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1379 output.push_back(value >> 8);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1380 delta = value;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1381 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1382
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1383 if (output.size() % 2)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1384 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1385 output.resize(output.size() - 1);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1386 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1387
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1388 return true;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1389 }
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1390
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1391
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1392 void FromDcmtkBridge::ExtractPngImage(std::string& result,
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1393 DcmDataset& dataset,
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
1394 unsigned int frame,
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1395 ImageExtractionMode mode)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 std::auto_ptr<DicomIntegerPixelAccessor> accessor;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 FromDcmtkBridge::Convert(m, dataset);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403
319
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1404 std::string privateContent;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1405
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406 DcmElement* e;
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 79
diff changeset
1407 if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() &&
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 e != NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410 Uint8* pixData = NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 if (e->getUint8Array(pixData) == EC_Normal)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength()));
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
1414 accessor->SetCurrentFrame(frame);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 }
319
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1417 else if (DecodePsmctRle1(privateContent, dataset))
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1418 {
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1419 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded";
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1420 Uint8* pixData = NULL;
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1421 if (privateContent.size() > 0)
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1422 pixData = reinterpret_cast<Uint8*>(&privateContent[0]);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1423 accessor.reset(new DicomIntegerPixelAccessor(m, pixData, privateContent.size()));
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1424 accessor->SetCurrentFrame(frame);
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1425 }
419
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1426
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1427 if (accessor.get() == NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1428 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1429 throw OrthancException(ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1430 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1431
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1432 PixelFormat format;
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1433 bool supported = false;
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1434
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1435 if (accessor->GetChannelCount() == 1)
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1436 {
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1437 switch (mode)
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1438 {
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1439 case ImageExtractionMode_Preview:
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1440 supported = true;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1441 format = PixelFormat_Grayscale8;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1442 break;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1443
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1444 case ImageExtractionMode_UInt8:
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1445 supported = true;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1446 format = PixelFormat_Grayscale8;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1447 break;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1448
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1449 case ImageExtractionMode_UInt16:
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1450 supported = true;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1451 format = PixelFormat_Grayscale16;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1452 break;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1453
465
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1454 case ImageExtractionMode_Int16:
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1455 supported = true;
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1456 format = PixelFormat_SignedGrayscale16;
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1457 break;
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1458
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1459 default:
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1460 supported = false;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1461 break;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1462 }
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1463 }
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1464 else if (accessor->GetChannelCount() == 3)
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1465 {
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1466 switch (mode)
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1467 {
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1468 case ImageExtractionMode_Preview:
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1469 supported = true;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1470 format = PixelFormat_RGB24;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1471 break;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1472
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1473 default:
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1474 supported = false;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1475 break;
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1476 }
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1477 }
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1478
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1479 if (!supported)
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1480 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1481 throw OrthancException(ErrorCode_NotImplemented);
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
1482 }
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1483
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 if (accessor.get() == NULL ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485 accessor->GetWidth() == 0 ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 accessor->GetHeight() == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487 {
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1488 PngWriter w;
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1489 w.WriteToMemory(result, 0, 0, 0, format, NULL);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 {
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1493 switch (mode)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1494 {
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1495 case ImageExtractionMode_Preview:
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1496 if (format == PixelFormat_Grayscale8)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1497 ExtractPngImageGrayscalePreview(result, *accessor);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1498 else
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
1499 ExtractPngImageColorPreview(result, *accessor);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1500 break;
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1501
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1502 case ImageExtractionMode_UInt8:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1503 ExtractPngImageTruncate<uint8_t>(result, *accessor, format);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1504 break;
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1505
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1506 case ImageExtractionMode_UInt16:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1507 ExtractPngImageTruncate<uint16_t>(result, *accessor, format);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1508 break;
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1509
465
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1510 case ImageExtractionMode_Int16:
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1511 ExtractPngImageTruncate<int16_t>(result, *accessor, format);
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1512 break;
7a966b440f19 signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 464
diff changeset
1513
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1514 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1515 throw OrthancException(ErrorCode_NotImplemented);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1516 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1519
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1520
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1521 void FromDcmtkBridge::ExtractPngImage(std::string& result,
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1522 const std::string& dicomContent,
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
1523 unsigned int frame,
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
1524 ImageExtractionMode mode)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1525 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1526 DcmInputBufferStream is;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1527 if (dicomContent.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1528 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529 is.setBuffer(&dicomContent[0], dicomContent.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 is.setEos();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533 DcmFileFormat dicom;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534 if (dicom.read(is).good())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
1536 ExtractPngImage(result, *dicom.getDataset(), frame, mode);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
1540 throw OrthancException(ErrorCode_BadFileFormat);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 std::string FromDcmtkBridge::GetName(const DicomTag& t)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 {
106
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
1548 // Some patches for important tags because of different DICOM
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
1549 // dictionaries between DCMTK versions
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1550 std::string n = t.GetMainTagsName();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1551 if (n.size() != 0)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1552 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1553 return n;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1554 }
106
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
1555 // End of patches
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
1556
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1557 #if 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 DcmTagKey tag(t.GetGroup(), t.GetElement());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560 const DcmDictEntry* entry = dict.findEntry(tag, NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1562 std::string s(DcmTag_ERROR_TagName);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 if (entry != NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 s = std::string(entry->getTagName());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 return s;
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1570 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1571 DcmTag tag(t.GetGroup(), t.GetElement());
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1572 const char* name = tag.getTagName();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1573 if (name == NULL)
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1574 {
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1575 return DcmTag_ERROR_TagName;
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1576 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1577 else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1578 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1579 return std::string(name);
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1580 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1581 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1582 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1585 DicomTag FromDcmtkBridge::ParseTag(const char* name)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1586 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1587 if (strlen(name) == 9 &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1588 isxdigit(name[0]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1589 isxdigit(name[1]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1590 isxdigit(name[2]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1591 isxdigit(name[3]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1592 name[4] == '-' &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1593 isxdigit(name[5]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1594 isxdigit(name[6]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1595 isxdigit(name[7]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1596 isxdigit(name[8]))
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1597 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1598 uint16_t group = GetTagValue(name);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1599 uint16_t element = GetTagValue(name + 5);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1600 return DicomTag(group, element);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1601 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1602
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1603 #if 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1604 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1605 const DcmDictEntry* entry = dict.findEntry(name);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1606
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1607 if (entry == NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1608 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1609 dcmDataDict.unlock();
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
1610 throw OrthancException("Unknown DICOM tag");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1611 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1612 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1613 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1614 DcmTagKey key = entry->getKey();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1615 DicomTag tag(key.getGroup(), key.getElement());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1616 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1617 return tag;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1618 }
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1619 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1620 DcmTag tag;
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1621 if (DcmTag::findTagFromName(name, tag).good())
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1622 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1623 return DicomTag(tag.getGTag(), tag.getETag());
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1624 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1625 else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1626 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1627 throw OrthancException("Unknown DICOM tag");
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1628 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1629 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1630 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1631
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1632
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1634 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1635 for (DicomMap::Map::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
1636 it = m.map_.begin(); it != m.map_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638 DicomTag t = it->first;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1639 std::string s = it->second->AsString();
319
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
1640 fprintf(fp, "0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1641 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1642 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1644
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645 void FromDcmtkBridge::ToJson(Json::Value& result,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646 const DicomMap& values)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1648 if (result.type() != Json::objectValue)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1649 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
1650 throw OrthancException(ErrorCode_BadParameterType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1651 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1652
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1653 result.clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1654
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1655 for (DicomMap::Map::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
1656 it = values.map_.begin(); it != values.map_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1657 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1658 result[GetName(it->first)] = it->second->AsString();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1659 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1660 }
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1661
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1662
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1663 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level)
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1664 {
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1665 char uid[100];
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1666
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1667 switch (level)
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1668 {
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1669 case ResourceType_Patient:
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1670 // The "PatientID" field is of type LO (Long String), 64
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1671 // Bytes Maximum. An UUID is of length 36, thus it can be used
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1672 // as a random PatientID.
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1673 return Toolbox::GenerateUuid();
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1674
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1675 case ResourceType_Instance:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1676 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1677
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1678 case ResourceType_Series:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1679 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1680
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1681 case ResourceType_Study:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1682 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1683
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1684 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1685 throw OrthancException(ErrorCode_ParameterOutOfRange);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1686 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1687 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1688
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1689 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1690 DcmDataset* dataSet)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1691 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1692 // Determine the transfer syntax which shall be used to write the
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1693 // information to the file. We always switch to the Little Endian
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1694 // syntax, with explicit length.
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1695
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1696 // http://support.dcmtk.org/docs/dcxfer_8h-source.html
661
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1697
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1698
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1699 /**
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1700 * Note that up to Orthanc 0.7.1 (inclusive), the
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1701 * "EXS_LittleEndianExplicit" was always used to save the DICOM
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1702 * dataset into memory. We now keep the original transfer syntax
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1703 * (if available).
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1704 **/
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1705 E_TransferSyntax xfer = dataSet->getOriginalXfer();
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1706 if (xfer == EXS_Unknown)
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1707 {
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1708 // No information about the original transfer syntax: This is
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1709 // most probably a DICOM dataset that was read from memory.
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1710 xfer = EXS_LittleEndianExplicit;
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1711 }
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1712
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1713 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1714
661
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1715 // Create the meta-header information
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1716 DcmFileFormat ff(dataSet);
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1717 ff.validateMetaInfo(xfer);
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1718
661
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1719 // Create a memory buffer with the proper size
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1720 uint32_t s = ff.calcElementLength(xfer, encodingType);
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1721 buffer.resize(s);
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1722 DcmOutputBufferStream ob(&buffer[0], s);
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1723
661
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1724 // Fill the memory buffer with the meta-header and the dataset
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1725 ff.transferInit();
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1726 OFCondition c = ff.write(ob, xfer, encodingType, NULL,
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1727 /*opt_groupLength*/ EGL_recalcGL,
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1728 /*opt_paddingType*/ EPD_withoutPadding);
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1729 ff.transferEnd();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1730
661
d233b5090105 accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
1731 // Handle errors
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1732 if (c.good())
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1733 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1734 return true;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1735 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1736 else
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1737 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1738 buffer.clear();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1739 return false;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1740 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1741 }
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1742
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1743
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1744 void ParsedDicomFile::SaveToFile(const std::string& path)
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1745 {
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1746 // TODO Avoid using a temporary memory buffer, write directly on disk
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1747 std::string content;
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1748 SaveToMemoryBuffer(content);
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1749 Toolbox::WriteFile(content, path);
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1750 }
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1751
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1752
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1753 ParsedDicomFile::ParsedDicomFile()
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1754 {
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1755 file_.reset(new DcmFileFormat);
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1756 Replace(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient));
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1757 Replace(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study));
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1758 Replace(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series));
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1759 Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1760 }
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1761
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1762 }