annotate OrthancServer/ParsedDicomFile.cpp @ 1655:e40fd0d925c5

/tools/create-dicom can create tags with unknown VR
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Sep 2015 14:54:24 +0200
parents 4e56b5a206b7
children 09be34b2f30e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
4 * Department, University Hospital of Liege, Belgium
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 /*=========================================================================
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 This file is based on portions of the following project:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 Program: GDCM (Grassroots DICOM). A DICOM library
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 Module: http://gdcm.sourceforge.net/Copyright.html
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 Copyright (c) 2006-2011 Mathieu Malaterre
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 Copyright (c) 1993-2005 CREATIS
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 All rights reserved.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 Redistribution and use in source and binary forms, with or without
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 modification, are permitted provided that the following conditions are met:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 * Redistributions of source code must retain the above copyright notice,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 this list of conditions and the following disclaimer.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 * Redistributions in binary form must reproduce the above copyright notice,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 this list of conditions and the following disclaimer in the documentation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 and/or other materials provided with the distribution.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 endorse or promote products derived from this software without specific
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 prior written permission.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 =========================================================================*/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
75 #include "PrecompiledHeadersServer.h"
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 817
diff changeset
76
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 #ifndef NOMINMAX
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 #define NOMINMAX
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 #endif
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 #include "ParsedDicomFile.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
83 #include "ServerToolbox.h"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 #include "FromDcmtkBridge.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 #include "ToDcmtkBridge.h"
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
86 #include "Internals/DicomImageDecoder.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1347
diff changeset
87 #include "../Core/Logging.h"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 #include "../Core/Toolbox.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 #include "../Core/OrthancException.h"
1612
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1566
diff changeset
90 #include "../Core/Images/ImageBuffer.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1566
diff changeset
91 #include "../Core/Images/PngWriter.h"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 #include "../Core/Uuid.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 #include "../Core/DicomFormat/DicomString.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 #include "../Core/DicomFormat/DicomNullValue.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h"
1612
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1566
diff changeset
96 #include "../Core/Images/PngReader.h"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 #include <list>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 #include <limits>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 #include <boost/lexical_cast.hpp>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 #include <dcmtk/dcmdata/dcchrstr.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 #include <dcmtk/dcmdata/dcdicent.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 #include <dcmtk/dcmdata/dcdict.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 #include <dcmtk/dcmdata/dcfilefo.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 #include <dcmtk/dcmdata/dcistrmb.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 #include <dcmtk/dcmdata/dcuid.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 #include <dcmtk/dcmdata/dcmetinf.h>
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
110 #include <dcmtk/dcmdata/dcdeftag.h>
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 #include <dcmtk/dcmdata/dcvrae.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 #include <dcmtk/dcmdata/dcvras.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 #include <dcmtk/dcmdata/dcvrcs.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 #include <dcmtk/dcmdata/dcvrda.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 #include <dcmtk/dcmdata/dcvrds.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 #include <dcmtk/dcmdata/dcvrdt.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 #include <dcmtk/dcmdata/dcvrfd.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 #include <dcmtk/dcmdata/dcvrfl.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 #include <dcmtk/dcmdata/dcvris.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 #include <dcmtk/dcmdata/dcvrlo.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 #include <dcmtk/dcmdata/dcvrlt.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 #include <dcmtk/dcmdata/dcvrpn.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 #include <dcmtk/dcmdata/dcvrsh.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 #include <dcmtk/dcmdata/dcvrsl.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 #include <dcmtk/dcmdata/dcvrss.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 #include <dcmtk/dcmdata/dcvrst.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 #include <dcmtk/dcmdata/dcvrtm.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 #include <dcmtk/dcmdata/dcvrui.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 #include <dcmtk/dcmdata/dcvrul.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 #include <dcmtk/dcmdata/dcvrus.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 #include <dcmtk/dcmdata/dcvrut.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 #include <dcmtk/dcmdata/dcpixel.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 #include <dcmtk/dcmdata/dcpixseq.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 #include <dcmtk/dcmdata/dcpxitem.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 #include <boost/math/special_functions/round.hpp>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 #include <dcmtk/dcmdata/dcostrmb.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 static const char* CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 namespace Orthanc
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
148 struct ParsedDicomFile::PImpl
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
149 {
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
150 std::auto_ptr<DcmFileFormat> file_;
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
151 Encoding encoding_;
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
152 };
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
153
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
154
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
155 // This method can only be called from the constructors!
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 void ParsedDicomFile::Setup(const char* buffer, size_t size)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 DcmInputBufferStream is;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 if (size > 0)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 is.setBuffer(buffer, size);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 is.setEos();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
165 pimpl_->file_.reset(new DcmFileFormat);
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
166 pimpl_->file_->transferInit();
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
167 if (!pimpl_->file_->read(is).good())
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
169 delete pimpl_; // Avoid a memory leak due to exception
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
170 // throwing, as we are in the constructor
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
171
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 throw OrthancException(ErrorCode_BadFileFormat);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
174 pimpl_->file_->loadAllDataIntoMemory();
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
175 pimpl_->file_->transferEnd();
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
176
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
177 pimpl_->encoding_ = FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset());
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 static void SendPathValueForDictionary(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 DcmItem& dicom)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 Json::Value v = Json::arrayValue;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 for (unsigned long i = 0; i < dicom.card(); i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 DcmElement* element = dicom.getElement(i);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 if (element)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 char buf[16];
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 sprintf(buf, "%04x-%04x", element->getTag().getGTag(), element->getTag().getETag());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 v.append(buf);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 output.AnswerJson(v);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 static inline uint16_t GetCharValue(char c)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 if (c >= '0' && c <= '9')
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 return c - '0';
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 else if (c >= 'a' && c <= 'f')
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 return c - 'a' + 10;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 else if (c >= 'A' && c <= 'F')
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 return c - 'A' + 10;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 return 0;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 static inline uint16_t GetTagValue(const char* c)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 return ((GetCharValue(c[0]) << 12) +
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 (GetCharValue(c[1]) << 8) +
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 (GetCharValue(c[2]) << 4) +
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 GetCharValue(c[3]));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 static void ParseTagAndGroup(DcmTagKey& key,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 const std::string& tag)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 DicomTag t = FromDcmtkBridge::ParseTag(tag);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 key = DcmTagKey(t.GetGroup(), t.GetElement());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 static void SendSequence(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 DcmSequenceOfItems& sequence)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 // This element is a sequence
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 Json::Value v = Json::arrayValue;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 for (unsigned long i = 0; i < sequence.card(); i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 v.append(boost::lexical_cast<std::string>(i));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 output.AnswerJson(v);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 static unsigned int GetPixelDataBlockCount(DcmPixelData& pixelData,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 E_TransferSyntax transferSyntax)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 DcmPixelSequence* pixelSequence = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 if (pixelData.getEncapsulatedRepresentation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 return pixelSequence->card();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 return 1;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
259 namespace
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
261 class DicomFieldStream : public IHttpStreamAnswer
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
262 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
263 private:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
264 DcmElement& element_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
265 uint32_t length_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
266 uint32_t offset_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
267 std::string chunk_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
268 size_t chunkSize_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
269
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
270 public:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
271 DicomFieldStream(DcmElement& element,
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
272 E_TransferSyntax transferSyntax) :
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
273 element_(element),
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
274 length_(element.getLength(transferSyntax)),
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
275 offset_(0),
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
276 chunkSize_(0)
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
277 {
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1520
diff changeset
278 static const size_t CHUNK_SIZE = 64 * 1024; // Use chunks of max 64KB
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
279 chunk_.resize(CHUNK_SIZE);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
280 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
1523
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
282 virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/,
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
283 bool /*deflateAllowed*/)
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
284 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
285 // No support for compression
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
286 return HttpCompression_None;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
287 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
289 virtual bool HasContentFilename(std::string& filename)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
291 return false;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 }
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
293
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
294 virtual std::string GetContentType()
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
296 return "";
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
299 virtual uint64_t GetContentLength()
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
301 return length_;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
303
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
304 virtual bool ReadNextChunk()
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
1520
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
306 assert(offset_ <= length_);
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
307
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
308 if (offset_ == length_)
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
309 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
310 return false;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
311 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
312 else
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
313 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
314 if (length_ - offset_ < chunk_.size())
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
315 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
316 chunkSize_ = length_ - offset_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
317 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
318 else
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
319 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
320 chunkSize_ = chunk_.size();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
321 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
322
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
323 OFCondition cond = element_.getPartialValue(&chunk_[0], offset_, chunkSize_);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
324
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
325 offset_ += chunkSize_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
326
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
327 if (!cond.good())
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
328 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
329 LOG(ERROR) << "Error while sending a DICOM field: " << cond.text();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
330 throw OrthancException(ErrorCode_InternalError);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
331 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
332
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
333 return true;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
334 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
336
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
337 virtual const char *GetChunkContent()
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
338 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
339 return chunk_.c_str();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
340 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
341
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
342 virtual size_t GetChunkSize()
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
343 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
344 return chunkSize_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
345 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
346 };
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 static bool AnswerPixelData(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 DcmItem& dicom,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 E_TransferSyntax transferSyntax,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 const std::string* blockUri)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 DcmTag k(DICOM_TAG_PIXEL_DATA.GetGroup(),
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 DICOM_TAG_PIXEL_DATA.GetElement());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 DcmElement *element = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 if (!dicom.findAndGetElement(k, element).good() ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 element == NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 return false;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 try
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 DcmPixelData& pixelData = dynamic_cast<DcmPixelData&>(*element);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 if (blockUri == NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 // The user asks how many blocks are presents in this pixel data
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 unsigned int blocks = GetPixelDataBlockCount(pixelData, transferSyntax);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 Json::Value result(Json::arrayValue);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 for (unsigned int i = 0; i < blocks; i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 result.append(boost::lexical_cast<std::string>(i));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 output.AnswerJson(result);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 return true;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 unsigned int block = boost::lexical_cast<unsigned int>(*blockUri);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 if (block < GetPixelDataBlockCount(pixelData, transferSyntax))
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 DcmPixelSequence* pixelSequence = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 if (pixelData.getEncapsulatedRepresentation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 // This is the case for JPEG transfer syntaxes
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 if (block < pixelSequence->card())
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 DcmPixelItem* pixelItem = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 if (pixelSequence->getItem(pixelItem, block).good() && pixelItem)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 if (pixelItem->getLength() == 0)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 output.AnswerBuffer(NULL, 0, CONTENT_TYPE_OCTET_STREAM);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 return true;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 Uint8* buffer = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 if (pixelItem->getUint8Array(buffer).good() && buffer)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 output.AnswerBuffer(buffer, pixelItem->getLength(), CONTENT_TYPE_OCTET_STREAM);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 return true;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 // This is the case for raw, uncompressed image buffers
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 assert(*blockUri == "0");
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
417 DicomFieldStream stream(*element, transferSyntax);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
418 output.AnswerStream(stream);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 catch (boost::bad_lexical_cast&)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 // The URI entered by the user is not a number
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 catch (std::bad_cast&)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 // This should never happen
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 return false;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 static void SendPathValueForLeaf(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 const std::string& tag,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 DcmItem& dicom,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 E_TransferSyntax transferSyntax)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 DcmTagKey k;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 ParseTagAndGroup(k, tag);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 DcmSequenceOfItems* sequence = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 if (dicom.findAndGetSequence(k, sequence).good() &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 sequence != NULL &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 sequence->getVR() == EVR_SQ)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 SendSequence(output, *sequence);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 DcmElement* element = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 if (dicom.findAndGetElement(k, element).good() &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 element != NULL &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 //element->getVR() != EVR_UNKNOWN && // This would forbid private tags
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 element->getVR() != EVR_SQ)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
459 DicomFieldStream stream(*element, transferSyntax);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
460 output.AnswerStream(stream);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 void ParsedDicomFile::SendPathValue(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 const UriComponents& uri)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
467 DcmItem* dicom = pimpl_->file_->getDataset();
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
468 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer();
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 // Special case: Accessing the pixel data
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 if (uri.size() == 1 ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 uri.size() == 2)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 DcmTagKey tag;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 ParseTagAndGroup(tag, uri[0]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 if (tag.getGroup() == DICOM_TAG_PIXEL_DATA.GetGroup() &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 tag.getElement() == DICOM_TAG_PIXEL_DATA.GetElement())
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 AnswerPixelData(output, *dicom, transferSyntax, uri.size() == 1 ? NULL : &uri[1]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 // Go down in the tag hierarchy according to the URI
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 for (size_t pos = 0; pos < uri.size() / 2; pos++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 size_t index;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 try
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 index = boost::lexical_cast<size_t>(uri[2 * pos + 1]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 catch (boost::bad_lexical_cast&)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 DcmTagKey k;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 DcmItem *child = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 ParseTagAndGroup(k, uri[2 * pos]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 if (!dicom->findAndGetSequenceItem(k, child, index).good() ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 child == NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 dicom = child;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 // We have reached the end of the URI
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 if (uri.size() % 2 == 0)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 SendPathValueForDictionary(output, *dicom);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 SendPathValueForLeaf(output, uri.back(), *dicom, transferSyntax);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 static DcmElement* CreateElementForTag(const DicomTag& tag)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 DcmTag key(tag.GetGroup(), tag.GetElement());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 switch (key.getEVR())
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 // http://support.dcmtk.org/docs/dcvr_8h-source.html
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 * TODO.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 case EVR_OB: // other byte
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 case EVR_OF: // other float
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 case EVR_OW: // other word
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 case EVR_AT: // attribute tag
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 throw OrthancException(ErrorCode_NotImplemented);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 case EVR_UN: // unknown value representation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 throw OrthancException(ErrorCode_ParameterOutOfRange);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 * String types.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 * http://support.dcmtk.org/docs/classDcmByteString.html
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 case EVR_AS: // age string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 return new DcmAgeString(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 case EVR_AE: // application entity title
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 return new DcmApplicationEntity(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 case EVR_CS: // code string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 return new DcmCodeString(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 case EVR_DA: // date string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 return new DcmDate(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 case EVR_DT: // date time string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 return new DcmDateTime(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 case EVR_DS: // decimal string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 return new DcmDecimalString(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 case EVR_IS: // integer string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 return new DcmIntegerString(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 case EVR_TM: // time string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 return new DcmTime(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 case EVR_UI: // unique identifier
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 return new DcmUniqueIdentifier(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 case EVR_ST: // short text
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 return new DcmShortText(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 case EVR_LO: // long string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 return new DcmLongString(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 case EVR_LT: // long text
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 return new DcmLongText(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 case EVR_UT: // unlimited text
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 return new DcmUnlimitedText(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 case EVR_SH: // short string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 return new DcmShortString(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 case EVR_PN: // person name
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 return new DcmPersonName(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 * Numerical types
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 case EVR_SL: // signed long
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 return new DcmSignedLong(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 case EVR_SS: // signed short
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 return new DcmSignedShort(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 case EVR_UL: // unsigned long
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 return new DcmUnsignedLong(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 case EVR_US: // unsigned short
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 return new DcmUnsignedShort(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 case EVR_FL: // float single-precision
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 return new DcmFloatingPointSingle(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 case EVR_FD: // float double-precision
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 return new DcmFloatingPointDouble(key);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 * Sequence types, should never occur at this point.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 case EVR_SQ: // sequence of items
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 throw OrthancException(ErrorCode_ParameterOutOfRange);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 * Internal to DCMTK.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 case EVR_ox: // OB or OW depending on context
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 case EVR_xs: // SS or US depending on context
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 case EVR_na: // na="not applicable", for data which has no VR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 case EVR_item: // used internally for items
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 case EVR_metainfo: // used internally for meta info datasets
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 case EVR_dataset: // used internally for datasets
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 case EVR_fileFormat: // used internally for DICOM files
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 case EVR_dicomDir: // used internally for DICOMDIR objects
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 case EVR_dirRecord: // used internally for DICOMDIR records
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 case EVR_pixelItem: // used internally for pixel items in a compressed image
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 case EVR_PixelData: // used internally for uncompressed pixeld data
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 case EVR_OverlayData: // used internally for overlay data
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 default:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 throw OrthancException(ErrorCode_InternalError);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 static void FillElementWithString(DcmElement& element,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 const DicomTag& tag,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 const std::string& value)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 DcmTag key(tag.GetGroup(), tag.GetElement());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 bool ok = false;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 try
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 switch (key.getEVR())
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 // http://support.dcmtk.org/docs/dcvr_8h-source.html
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 * TODO.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 case EVR_OB: // other byte
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 case EVR_OF: // other float
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 case EVR_OW: // other word
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 case EVR_AT: // attribute tag
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 throw OrthancException(ErrorCode_NotImplemented);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 case EVR_UN: // unknown value representation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 throw OrthancException(ErrorCode_ParameterOutOfRange);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 * String types.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 case EVR_DS: // decimal string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 case EVR_IS: // integer string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 case EVR_AS: // age string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 case EVR_DA: // date string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 case EVR_DT: // date time string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 case EVR_TM: // time string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 case EVR_AE: // application entity title
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 case EVR_CS: // code string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 case EVR_SH: // short string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 case EVR_LO: // long string
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 case EVR_ST: // short text
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 case EVR_LT: // long text
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 case EVR_UT: // unlimited text
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 case EVR_PN: // person name
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 case EVR_UI: // unique identifier
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 ok = element.putString(value.c_str()).good();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 * Numerical types
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 case EVR_SL: // signed long
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 ok = element.putSint32(boost::lexical_cast<Sint32>(value)).good();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 case EVR_SS: // signed short
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 ok = element.putSint16(boost::lexical_cast<Sint16>(value)).good();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 case EVR_UL: // unsigned long
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 ok = element.putUint32(boost::lexical_cast<Uint32>(value)).good();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 case EVR_US: // unsigned short
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 ok = element.putUint16(boost::lexical_cast<Uint16>(value)).good();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 case EVR_FL: // float single-precision
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 ok = element.putFloat32(boost::lexical_cast<float>(value)).good();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 case EVR_FD: // float double-precision
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 ok = element.putFloat64(boost::lexical_cast<double>(value)).good();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 * Sequence types, should never occur at this point.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 case EVR_SQ: // sequence of items
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 ok = false;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 * Internal to DCMTK.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 case EVR_ox: // OB or OW depending on context
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 case EVR_xs: // SS or US depending on context
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 case EVR_na: // na="not applicable", for data which has no VR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 case EVR_item: // used internally for items
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 case EVR_metainfo: // used internally for meta info datasets
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 case EVR_dataset: // used internally for datasets
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 case EVR_fileFormat: // used internally for DICOM files
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 case EVR_dicomDir: // used internally for DICOMDIR objects
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 case EVR_dirRecord: // used internally for DICOMDIR records
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 case EVR_pixelItem: // used internally for pixel items in a compressed image
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 case EVR_PixelData: // used internally for uncompressed pixeld data
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 case EVR_OverlayData: // used internally for overlay data
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 default:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 catch (boost::bad_lexical_cast&)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 ok = false;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 if (!ok)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 throw OrthancException(ErrorCode_InternalError);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 void ParsedDicomFile::Remove(const DicomTag& tag)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 DcmTagKey key(tag.GetGroup(), tag.GetElement());
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
803 DcmElement* element = pimpl_->file_->getDataset()->remove(key);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 if (element != NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 delete element;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
812 void ParsedDicomFile::RemovePrivateTagsInternal(const std::set<DicomTag>* toKeep)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 {
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
814 DcmDataset& dataset = *pimpl_->file_->getDataset();
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
815
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
816 // Loop over the dataset to detect its private tags
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 typedef std::list<DcmElement*> Tags;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 Tags privateTags;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 for (unsigned long i = 0; i < dataset.card(); i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 DcmElement* element = dataset.getElement(i);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 DcmTag tag(element->getTag());
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
824
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
825 // Is this a private tag?
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
826 if (FromDcmtkBridge::IsPrivateTag(tag))
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 {
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
828 bool remove = true;
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
829
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
830 // Check whether this private tag is to be kept
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
831 if (toKeep != NULL)
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
832 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
833 DicomTag tmp = FromDcmtkBridge::Convert(tag);
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
834 if (toKeep->find(tmp) != toKeep->end())
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
835 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
836 remove = false; // Keep it
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
837 }
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
838 }
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
839
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
840 if (remove)
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
841 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
842 privateTags.push_back(element);
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
843 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
847 // Loop over the detected private tags to remove them
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 for (Tags::iterator it = privateTags.begin();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 it != privateTags.end(); ++it)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 DcmElement* tmp = dataset.remove(*it);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 if (tmp != NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 delete tmp;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
861
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 void ParsedDicomFile::Insert(const DicomTag& tag,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 const std::string& value)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 {
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
865 OFCondition cond;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
866
1655
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1641
diff changeset
867 if (FromDcmtkBridge::IsPrivateTag(tag) ||
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1641
diff changeset
868 FromDcmtkBridge::IsUnknownTag(tag))
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
869 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
870 // This is a private tag
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
871 // http://support.dcmtk.org/redmine/projects/dcmtk/wiki/howto_addprivatedata
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
873 DcmTag key(tag.GetGroup(), tag.GetElement(), EVR_OB);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
874 cond = pimpl_->file_->getDataset()->putAndInsertUint8Array
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
875 (key, (const Uint8*) value.c_str(), value.size(), false);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
876 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
877 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
878 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
879 std::auto_ptr<DcmElement> element(CreateElementForTag(tag));
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
880 FillElementWithString(*element, tag, value);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
881
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
882 cond = pimpl_->file_->getDataset()->insert(element.release(), false, false);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
883 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
884
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
885 if (!cond.good())
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 // This field already exists
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 throw OrthancException(ErrorCode_InternalError);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 void ParsedDicomFile::Replace(const DicomTag& tag,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 const std::string& value,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 DicomReplaceMode mode)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 DcmTagKey key(tag.GetGroup(), tag.GetElement());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 DcmElement* element = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
900 if (!pimpl_->file_->getDataset()->findAndGetElement(key, element).good() ||
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 element == NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 // This field does not exist, act wrt. the specified "mode"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 switch (mode)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 case DicomReplaceMode_InsertIfAbsent:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 Insert(tag, value);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 break;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 case DicomReplaceMode_ThrowIfAbsent:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 throw OrthancException(ErrorCode_InexistentItem);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 case DicomReplaceMode_IgnoreIfAbsent:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 {
1655
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1641
diff changeset
919 if (FromDcmtkBridge::IsPrivateTag(tag) ||
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1641
diff changeset
920 FromDcmtkBridge::IsUnknownTag(tag))
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
921 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
922 if (!element->putUint8Array((const Uint8*) value.c_str(), value.size()).good())
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
923 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
924 throw OrthancException(ErrorCode_InternalError);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
925 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
926 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
927 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
928 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
929 FillElementWithString(*element, tag, value);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
930 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 * dcmodify will automatically correct 'Media Storage SOP Class
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 * UID' and 'Media Storage SOP Instance UID' in the metaheader, if
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 * you make changes to the related tags in the dataset ('SOP Class
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 * UID' and 'SOP Instance UID') via insert or modify mode
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 * options. You can disable this behaviour by using the -nmu
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 * option.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 if (tag == DICOM_TAG_SOP_CLASS_UID)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, DicomReplaceMode_InsertIfAbsent);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 if (tag == DICOM_TAG_SOP_INSTANCE_UID)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, DicomReplaceMode_InsertIfAbsent);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 void ParsedDicomFile::Answer(RestApiOutput& output)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 std::string serialized;
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
958 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset()))
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 output.AnswerBuffer(serialized, CONTENT_TYPE_OCTET_STREAM);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 bool ParsedDicomFile::GetTagValue(std::string& value,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 const DicomTag& tag)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 DcmTagKey k(tag.GetGroup(), tag.GetElement());
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
970 DcmDataset& dataset = *pimpl_->file_->getDataset();
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
971
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
972 if (FromDcmtkBridge::IsPrivateTag(tag) ||
1655
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1641
diff changeset
973 FromDcmtkBridge::IsUnknownTag(tag) ||
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
974 tag == DICOM_TAG_PIXEL_DATA ||
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
975 tag == DICOM_TAG_ENCAPSULATED_DOCUMENT)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 {
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
977 const Uint8* data = NULL; // This is freed in the destructor of the dataset
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
978 long unsigned int count = 0;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
980 if (dataset.findAndGetUint8Array(k, data, &count).good())
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
981 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
982 if (count > 0)
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
983 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
984 assert(data != NULL);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
985 value.assign(reinterpret_cast<const char*>(data), count);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
986 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
987 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
988 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
989 value.clear();
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
990 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
992 return true;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
993 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
994 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
995 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
996 return false;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
997 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 {
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1001 DcmElement* element = NULL;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1002 if (!dataset.findAndGetElement(k, element).good() ||
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1003 element == NULL)
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1004 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1005 return false;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1006 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1007
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1008 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_));
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1009
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1010 if (v.get() == NULL)
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1011 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1012 value = "";
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1013 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1014 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1015 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1016 value = v->AsString();
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1017 }
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1018
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1019 return true;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 DicomInstanceHasher ParsedDicomFile::GetHasher()
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 std::string patientId, studyUid, seriesUid, instanceUid;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 if (!GetTagValue(patientId, DICOM_TAG_PATIENT_ID) ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 !GetTagValue(studyUid, DICOM_TAG_STUDY_INSTANCE_UID) ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 !GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID) ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 !GetTagValue(instanceUid, DICOM_TAG_SOP_INSTANCE_UID))
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 throw OrthancException(ErrorCode_BadFileFormat);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 template <typename T>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 static void ExtractPngImageTruncate(std::string& result,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 DicomIntegerPixelAccessor& accessor,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043 PixelFormat format)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 {
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1045 assert(accessor.GetInformation().GetChannelCount() == 1);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 PngWriter w;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1049 std::vector<T> image(accessor.GetInformation().GetWidth() * accessor.GetInformation().GetHeight(), 0);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 T* pixel = &image[0];
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1051 for (unsigned int y = 0; y < accessor.GetInformation().GetHeight(); y++)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 {
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1053 for (unsigned int x = 0; x < accessor.GetInformation().GetWidth(); x++, pixel++)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 int32_t v = accessor.GetValue(x, y);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 if (v < static_cast<int32_t>(std::numeric_limits<T>::min()))
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 *pixel = std::numeric_limits<T>::min();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 else if (v > static_cast<int32_t>(std::numeric_limits<T>::max()))
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 *pixel = std::numeric_limits<T>::max();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 *pixel = static_cast<T>(v);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1065 w.WriteToMemory(result, accessor.GetInformation().GetWidth(), accessor.GetInformation().GetHeight(),
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1066 accessor.GetInformation().GetWidth() * sizeof(T), format, &image[0]);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 void ParsedDicomFile::SaveToMemoryBuffer(std::string& buffer)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071 {
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
1072 FromDcmtkBridge::SaveToMemoryBuffer(buffer, *pimpl_->file_->getDataset());
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 void ParsedDicomFile::SaveToFile(const std::string& path)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 // TODO Avoid using a temporary memory buffer, write directly on disk
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 std::string content;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 SaveToMemoryBuffer(content);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 Toolbox::WriteFile(content, path);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1085 ParsedDicomFile::ParsedDicomFile() : pimpl_(new PImpl)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1087 pimpl_->file_.reset(new DcmFileFormat);
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1088 pimpl_->encoding_ = Encoding_Ascii;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 Replace(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 Replace(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 Replace(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1095
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1096 ParsedDicomFile::ParsedDicomFile(const char* content, size_t size) : pimpl_(new PImpl)
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1097 {
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1098 Setup(content, size);
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1099 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1100
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1101 ParsedDicomFile::ParsedDicomFile(const std::string& content) : pimpl_(new PImpl)
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1102 {
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1103 if (content.size() == 0)
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1104 {
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1105 Setup(NULL, 0);
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1106 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1107 else
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1108 {
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1109 Setup(&content[0], content.size());
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1110 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
1111 }
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1112
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1113
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1114 ParsedDicomFile::ParsedDicomFile(ParsedDicomFile& other) :
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1115 pimpl_(new PImpl)
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1116 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1117 pimpl_->file_.reset(dynamic_cast<DcmFileFormat*>(other.pimpl_->file_->clone()));
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
1118 pimpl_->encoding_ = other.pimpl_->encoding_;
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1119
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
1120 // Create a new instance-level identifier
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
1121 Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1122 }
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1123
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1124
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1125 ParsedDicomFile::~ParsedDicomFile()
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1126 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1127 delete pimpl_;
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1128 }
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
1129
793
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1130
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1131 void* ParsedDicomFile::GetDcmtkObject()
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1132 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1133 return pimpl_->file_.get();
793
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1134 }
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1135
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1136
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1137 ParsedDicomFile* ParsedDicomFile::Clone()
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1138 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1139 return new ParsedDicomFile(*this);
793
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1140 }
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1141
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1142
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1143 void ParsedDicomFile::EmbedContent(const std::string& dataUriScheme)
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1144 {
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
1145 std::string mime, content;
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
1146 Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme);
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1147 Toolbox::ToLowerCase(mime);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1148
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1149 if (mime == "image/png")
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1150 {
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1151 EmbedImage(mime, content);
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1152 }
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1153 else if (mime == "application/pdf")
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1154 {
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1155 EmbedPdf(content);
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1156 }
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1157 else
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1158 {
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1159 LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file";
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1160 throw OrthancException(ErrorCode_NotImplemented);
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1161 }
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1162 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1163
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1164
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1165 void ParsedDicomFile::EmbedImage(const std::string& mime,
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1166 const std::string& content)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1167 {
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1168 if (mime == "image/png")
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1169 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1170 PngReader reader;
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1171 reader.ReadFromMemory(content);
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1172 EmbedImage(reader);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1173 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1174 else
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1175 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1176 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1177 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1178 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1179
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1180
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1181 void ParsedDicomFile::EmbedImage(const ImageAccessor& accessor)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1182 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1183 if (accessor.GetFormat() != PixelFormat_Grayscale8 &&
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1184 accessor.GetFormat() != PixelFormat_Grayscale16 &&
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1185 accessor.GetFormat() != PixelFormat_RGB24 &&
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1186 accessor.GetFormat() != PixelFormat_RGBA32)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1187 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1188 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1189 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1190
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1191 if (accessor.GetFormat() == PixelFormat_RGBA32)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1192 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1193 LOG(WARNING) << "Getting rid of the alpha channel when embedding a RGBA image inside DICOM";
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1194 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1195
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1196 // http://dicomiseasy.blogspot.be/2012/08/chapter-12-pixel-data.html
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1197
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1198 Remove(DICOM_TAG_PIXEL_DATA);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1199 Replace(DICOM_TAG_COLUMNS, boost::lexical_cast<std::string>(accessor.GetWidth()));
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1200 Replace(DICOM_TAG_ROWS, boost::lexical_cast<std::string>(accessor.GetHeight()));
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1201 Replace(DICOM_TAG_SAMPLES_PER_PIXEL, "1");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1202 Replace(DICOM_TAG_NUMBER_OF_FRAMES, "1");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1203 Replace(DICOM_TAG_PIXEL_REPRESENTATION, "0"); // Unsigned pixels
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1204 Replace(DICOM_TAG_PLANAR_CONFIGURATION, "0"); // Color channels are interleaved
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1205 Replace(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1206 Replace(DICOM_TAG_BITS_ALLOCATED, "8");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1207 Replace(DICOM_TAG_BITS_STORED, "8");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1208 Replace(DICOM_TAG_HIGH_BIT, "7");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1209
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1210 unsigned int bytesPerPixel = 1;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1211
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1212 switch (accessor.GetFormat())
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1213 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1214 case PixelFormat_RGB24:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1215 case PixelFormat_RGBA32:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1216 Replace(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "RGB");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1217 Replace(DICOM_TAG_SAMPLES_PER_PIXEL, "3");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1218 bytesPerPixel = 3;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1219 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1220
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1221 case PixelFormat_Grayscale8:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1222 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1223
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1224 case PixelFormat_Grayscale16:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1225 Replace(DICOM_TAG_BITS_ALLOCATED, "16");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1226 Replace(DICOM_TAG_BITS_STORED, "16");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1227 Replace(DICOM_TAG_HIGH_BIT, "15");
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1228 bytesPerPixel = 2;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1229 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1230
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1231 default:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1232 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1233 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1234
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1235 DcmTag key(DICOM_TAG_PIXEL_DATA.GetGroup(),
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1236 DICOM_TAG_PIXEL_DATA.GetElement());
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1237
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1238 std::auto_ptr<DcmPixelData> pixels(new DcmPixelData(key));
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1239
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1240 unsigned int pitch = accessor.GetWidth() * bytesPerPixel;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1241 Uint8* target = NULL;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1242 pixels->createUint8Array(accessor.GetHeight() * pitch, target);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1243
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1244 for (unsigned int y = 0; y < accessor.GetHeight(); y++)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1245 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1246 switch (accessor.GetFormat())
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1247 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1248 case PixelFormat_RGB24:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1249 case PixelFormat_Grayscale8:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1250 case PixelFormat_Grayscale16:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1251 case PixelFormat_SignedGrayscale16:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1252 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1253 memcpy(target, reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)), pitch);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1254 target += pitch;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1255 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1256 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1257
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1258 case PixelFormat_RGBA32:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1259 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1260 // The alpha channel is not supported by the DICOM standard
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1261 const Uint8* source = reinterpret_cast<const Uint8*>(accessor.GetConstRow(y));
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1262 for (unsigned int x = 0; x < accessor.GetWidth(); x++, target += 3, source += 4)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1263 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1264 target[0] = source[0];
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1265 target[1] = source[1];
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1266 target[2] = source[2];
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1267 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1268
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1269 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1270 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1271
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1272 default:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1273 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1274 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1275 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1276
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1277 if (!pimpl_->file_->getDataset()->insert(pixels.release(), false, false).good())
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1278 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1279 throw OrthancException(ErrorCode_InternalError);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1280 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1281 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1282
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1283
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1284 void ParsedDicomFile::ExtractImage(ImageBuffer& result,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1285 unsigned int frame)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1286 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1287 DcmDataset& dataset = *pimpl_->file_->getDataset();
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1288
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1289 if (!DicomImageDecoder::Decode(result, dataset, frame))
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1290 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1291 throw OrthancException(ErrorCode_BadFileFormat);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1292 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1293 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1294
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1295
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1296 void ParsedDicomFile::ExtractImage(ImageBuffer& result,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1297 unsigned int frame,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1298 ImageExtractionMode mode)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1299 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1300 DcmDataset& dataset = *pimpl_->file_->getDataset();
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1301
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1302 bool ok = false;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1303
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1304 switch (mode)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1305 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1306 case ImageExtractionMode_UInt8:
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
1307 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale8, false);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1308 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1309
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1310 case ImageExtractionMode_UInt16:
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
1311 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale16, false);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1312 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1313
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1314 case ImageExtractionMode_Int16:
1015
f009f7c75069 fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
1315 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_SignedGrayscale16, false);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1316 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1317
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1318 case ImageExtractionMode_Preview:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1319 ok = DicomImageDecoder::DecodePreview(result, dataset, frame);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1320 break;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1321
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1322 default:
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1323 throw OrthancException(ErrorCode_ParameterOutOfRange);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1324 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1325
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1326 if (!ok)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1327 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1328 throw OrthancException(ErrorCode_BadFileFormat);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1329 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1330 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1331
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1332
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1333 void ParsedDicomFile::ExtractPngImage(std::string& result,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1334 unsigned int frame,
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1335 ImageExtractionMode mode)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1336 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1337 ImageBuffer buffer;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1338 ExtractImage(buffer, frame, mode);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1339
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1340 ImageAccessor accessor(buffer.GetConstAccessor());
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1341 PngWriter writer;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1342 writer.WriteToMemory(result, accessor);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1343 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1344
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1345
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1346 Encoding ParsedDicomFile::GetEncoding() const
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1347 {
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1348 return pimpl_->encoding_;
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1349 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1350
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1351
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1352 void ParsedDicomFile::SetEncoding(Encoding encoding)
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1353 {
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1354 if (encoding == Encoding_Windows1251)
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1355 {
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1356 // This Cyrillic codepage is not officially supported by the
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1357 // DICOM standard. Do not set the SpecificCharacterSet tag.
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1358 return;
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1359 }
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1360
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
1361 pimpl_->encoding_ = encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
1362
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
1363 std::string s = GetDicomSpecificCharacterSet(encoding);
1091
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
1364 Replace(DICOM_TAG_SPECIFIC_CHARACTER_SET, s, DicomReplaceMode_InsertIfAbsent);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1365 }
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1366
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1367 void ParsedDicomFile::ToJson(Json::Value& target, bool simplify)
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1368 {
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1369 if (simplify)
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1370 {
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1371 Json::Value tmp;
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1372 FromDcmtkBridge::ToJson(tmp, *pimpl_->file_->getDataset());
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1373 SimplifyTags(target, tmp);
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1374 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1375 else
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1376 {
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1377 FromDcmtkBridge::ToJson(target, *pimpl_->file_->getDataset());
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1378 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1379 }
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1380
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1381
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1382 bool ParsedDicomFile::HasTag(const DicomTag& tag) const
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1383 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1384 DcmTag key(tag.GetGroup(), tag.GetElement());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1385 return pimpl_->file_->getDataset()->tagExists(key);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1386 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1387
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1388
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1389 void ParsedDicomFile::EmbedPdf(const std::string& pdf)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1390 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1391 if (pdf.size() < 5 || // (*)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1392 strncmp("%PDF-", pdf.c_str(), 5) != 0)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1393 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1394 LOG(ERROR) << "Not a PDF file";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1395 throw OrthancException(ErrorCode_BadFileFormat);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1396 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1397
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1398 Replace(DICOM_TAG_SOP_CLASS_UID, UID_EncapsulatedPDFStorage);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1399 Replace(FromDcmtkBridge::Convert(DCM_Modality), "OT");
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1400 Replace(FromDcmtkBridge::Convert(DCM_ConversionType), "WSD");
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1401 Replace(FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument), "application/pdf");
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
1402 //Replace(FromDcmtkBridge::Convert(DCM_SeriesNumber), "1");
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1403
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1404 std::auto_ptr<DcmPolymorphOBOW> element(new DcmPolymorphOBOW(DCM_EncapsulatedDocument));
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1405
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1406 size_t s = pdf.size();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1407 if (s & 1)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1408 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1409 // The size of the buffer must be even
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1410 s += 1;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1411 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1412
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1413 Uint8* bytes = NULL;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1414 OFCondition result = element->createUint8Array(s, bytes);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1415 if (!result.good() || bytes == NULL)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1416 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1417 throw OrthancException(ErrorCode_NotEnoughMemory);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1418 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1419
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1420 // Blank pad byte (no access violation, as "pdf.size() >= 5" because of (*) )
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1421 bytes[s - 1] = 0;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1422
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1423 memcpy(bytes, pdf.c_str(), pdf.size());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1424
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1425 DcmPolymorphOBOW* obj = element.release();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1426 result = pimpl_->file_->getDataset()->insert(obj);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1427
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1428 if (!result.good())
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1429 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1430 delete obj;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1431 throw OrthancException(ErrorCode_NotEnoughMemory);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1432 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1433 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1434
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1435
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1436 bool ParsedDicomFile::ExtractPdf(std::string& pdf)
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1437 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1438 std::string sop, mime;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1439
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1440 if (!GetTagValue(sop, DICOM_TAG_SOP_CLASS_UID) ||
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1441 !GetTagValue(mime, FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument)) ||
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1442 sop != UID_EncapsulatedPDFStorage ||
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1443 mime != "application/pdf")
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1444 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1445 return false;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1446 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1447
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1448 if (!GetTagValue(pdf, DICOM_TAG_ENCAPSULATED_DOCUMENT))
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1449 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1450 return false;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1451 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1452
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1453 // Strip the possible pad byte at the end of file, because the
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1454 // encapsulated documents must always have an even length. The PDF
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1455 // format expects files to end with %%EOF followed by CR/LF. If
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1456 // the last character of the file is not a CR or LF, we assume it
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1457 // is a pad byte and remove it.
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1458 if (pdf.size() > 0)
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1459 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1460 char last = *pdf.rbegin();
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1461
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1462 if (last != 10 && last != 13)
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1463 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1464 pdf.resize(pdf.size() - 1);
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1465 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1466 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1467
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1468 return true;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1469 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 }