annotate OrthancServer/ParsedDicomFile.cpp @ 2313:d19e716b79fa issue-46-anonymization

switch to anonymization according to DICOM 2017c
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2017 22:07:07 +0200
parents b7fba68747f6
children 96b3ec054b69
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
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
4 * Department, University Hospital of Liege, Belgium
2244
a3a65de1840f shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2209
diff changeset
5 * Copyright (C) 2017 Osimis, Belgium
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * modify file(s) with this exception, you may extend this exception to
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * 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
20 * you do not wish to do so, delete this exception statement from your
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 This file is based on portions of the following project:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 Program: GDCM (Grassroots DICOM). A DICOM library
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 Module: http://gdcm.sourceforge.net/Copyright.html
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 Copyright (c) 2006-2011 Mathieu Malaterre
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 Copyright (c) 1993-2005 CREATIS
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 All rights reserved.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 Redistribution and use in source and binary forms, with or without
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 modification, are permitted provided that the following conditions are met:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 * Redistributions of source code must retain the above copyright notice,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 this list of conditions and the following disclaimer.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 * Redistributions in binary form must reproduce the above copyright notice,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 this list of conditions and the following disclaimer in the documentation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 and/or other materials provided with the distribution.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 endorse or promote products derived from this software without specific
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 prior written permission.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 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
71 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
76 #include "PrecompiledHeadersServer.h"
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 817
diff changeset
77
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 #ifndef NOMINMAX
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 #define NOMINMAX
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 #endif
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 #include "ParsedDicomFile.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
84 #include "OrthancInitialization.h"
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
85 #include "ServerToolbox.h"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 #include "FromDcmtkBridge.h"
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 #include "ToDcmtkBridge.h"
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
88 #include "Internals/DicomFrameIndex.h"
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
89 #include "../Core/Images/JpegReader.h"
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
90 #include "../Core/Images/PngReader.h"
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
91 #include "../Core/Logging.h"
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
92 #include "../Core/OrthancException.h"
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
93 #include "../Core/Toolbox.h"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 #include <list>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 #include <limits>
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 <boost/lexical_cast.hpp>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 #include <dcmtk/dcmdata/dcchrstr.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 #include <dcmtk/dcmdata/dcdicent.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 #include <dcmtk/dcmdata/dcdict.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 #include <dcmtk/dcmdata/dcfilefo.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 #include <dcmtk/dcmdata/dcuid.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 #include <dcmtk/dcmdata/dcmetinf.h>
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
106 #include <dcmtk/dcmdata/dcdeftag.h>
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 #include <dcmtk/dcmdata/dcvrae.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 #include <dcmtk/dcmdata/dcvras.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 #include <dcmtk/dcmdata/dcvrcs.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 #include <dcmtk/dcmdata/dcvrda.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 #include <dcmtk/dcmdata/dcvrds.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 #include <dcmtk/dcmdata/dcvrdt.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 #include <dcmtk/dcmdata/dcvrfd.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 #include <dcmtk/dcmdata/dcvrfl.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 #include <dcmtk/dcmdata/dcvris.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 #include <dcmtk/dcmdata/dcvrlo.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 #include <dcmtk/dcmdata/dcvrlt.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 #include <dcmtk/dcmdata/dcvrpn.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 #include <dcmtk/dcmdata/dcvrsh.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 #include <dcmtk/dcmdata/dcvrsl.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 #include <dcmtk/dcmdata/dcvrss.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 #include <dcmtk/dcmdata/dcvrst.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 #include <dcmtk/dcmdata/dcvrtm.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 #include <dcmtk/dcmdata/dcvrui.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 #include <dcmtk/dcmdata/dcvrul.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 #include <dcmtk/dcmdata/dcvrus.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 #include <dcmtk/dcmdata/dcvrut.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 #include <dcmtk/dcmdata/dcpixel.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 #include <dcmtk/dcmdata/dcpixseq.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 #include <dcmtk/dcmdata/dcpxitem.h>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 #include <boost/math/special_functions/round.hpp>
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 #include <dcmtk/dcmdata/dcostrmb.h>
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
136 #include <boost/algorithm/string/predicate.hpp>
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
1945
76ff6eecf07f fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1941
diff changeset
139 #if DCMTK_VERSION_NUMBER <= 360
76ff6eecf07f fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1941
diff changeset
140 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax
76ff6eecf07f fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1941
diff changeset
141 #endif
76ff6eecf07f fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1941
diff changeset
142
76ff6eecf07f fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1941
diff changeset
143
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 static const char* CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 namespace Orthanc
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
150 struct ParsedDicomFile::PImpl
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
151 {
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
152 std::auto_ptr<DcmFileFormat> file_;
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
153 std::auto_ptr<DicomFrameIndex> frameIndex_;
794
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
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
156
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 static void SendPathValueForDictionary(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 DcmItem& dicom)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 Json::Value v = Json::arrayValue;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 for (unsigned long i = 0; i < dicom.card(); i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 DcmElement* element = dicom.getElement(i);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 if (element)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 char buf[16];
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 sprintf(buf, "%04x-%04x", element->getTag().getGTag(), element->getTag().getETag());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 v.append(buf);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 output.AnswerJson(v);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 static inline uint16_t GetCharValue(char c)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 if (c >= '0' && c <= '9')
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 return c - '0';
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 else if (c >= 'a' && c <= 'f')
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 return c - 'a' + 10;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 else if (c >= 'A' && c <= 'F')
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 return c - 'A' + 10;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return 0;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 static inline uint16_t GetTagValue(const char* c)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 return ((GetCharValue(c[0]) << 12) +
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 (GetCharValue(c[1]) << 8) +
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 (GetCharValue(c[2]) << 4) +
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 GetCharValue(c[3]));
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 static void ParseTagAndGroup(DcmTagKey& key,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 const std::string& tag)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 DicomTag t = FromDcmtkBridge::ParseTag(tag);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 key = DcmTagKey(t.GetGroup(), t.GetElement());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 static void SendSequence(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 DcmSequenceOfItems& sequence)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 // This element is a sequence
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 Json::Value v = Json::arrayValue;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 for (unsigned long i = 0; i < sequence.card(); i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 v.append(boost::lexical_cast<std::string>(i));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 output.AnswerJson(v);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 static unsigned int GetPixelDataBlockCount(DcmPixelData& pixelData,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 E_TransferSyntax transferSyntax)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 DcmPixelSequence* pixelSequence = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 if (pixelData.getEncapsulatedRepresentation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 return pixelSequence->card();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 return 1;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
235 namespace
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
237 class DicomFieldStream : public IHttpStreamAnswer
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
238 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
239 private:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
240 DcmElement& element_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
241 uint32_t length_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
242 uint32_t offset_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
243 std::string chunk_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
244 size_t chunkSize_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
245
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
246 public:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
247 DicomFieldStream(DcmElement& element,
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
248 E_TransferSyntax transferSyntax) :
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
249 element_(element),
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
250 length_(element.getLength(transferSyntax)),
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
251 offset_(0),
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
252 chunkSize_(0)
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
253 {
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1520
diff changeset
254 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
255 chunk_.resize(CHUNK_SIZE);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
256 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
1523
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
258 virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/,
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
259 bool /*deflateAllowed*/)
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
260 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
261 // No support for compression
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
262 return HttpCompression_None;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
263 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
265 virtual bool HasContentFilename(std::string& filename)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
267 return false;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
1519
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 virtual std::string GetContentType()
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
272 return "";
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
275 virtual uint64_t GetContentLength()
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
277 return length_;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
279
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
280 virtual bool ReadNextChunk()
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
1520
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
282 assert(offset_ <= length_);
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
283
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
284 if (offset_ == length_)
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
285 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
286 return false;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
287 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
288 else
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
289 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
290 if (length_ - offset_ < chunk_.size())
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
291 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
292 chunkSize_ = length_ - offset_;
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 else
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
295 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
296 chunkSize_ = chunk_.size();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
297 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
298
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
299 OFCondition cond = element_.getPartialValue(&chunk_[0], offset_, chunkSize_);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
300
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
301 offset_ += chunkSize_;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
302
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
303 if (!cond.good())
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
304 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
305 LOG(ERROR) << "Error while sending a DICOM field: " << cond.text();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
306 throw OrthancException(ErrorCode_InternalError);
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
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
309 return true;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
310 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 }
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
312
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
313 virtual const char *GetChunkContent()
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
314 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
315 return chunk_.c_str();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
316 }
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 virtual size_t GetChunkSize()
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 return chunkSize_;
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 };
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 static bool AnswerPixelData(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 DcmItem& dicom,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 E_TransferSyntax transferSyntax,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 const std::string* blockUri)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 DcmTag k(DICOM_TAG_PIXEL_DATA.GetGroup(),
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 DICOM_TAG_PIXEL_DATA.GetElement());
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 DcmElement *element = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 if (!dicom.findAndGetElement(k, element).good() ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 element == NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 return false;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 try
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 DcmPixelData& pixelData = dynamic_cast<DcmPixelData&>(*element);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 if (blockUri == NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 {
1913
41e402cd7b3a do not generate RC files for non-Windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
346 // The user asks how many blocks are present in this pixel data
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 unsigned int blocks = GetPixelDataBlockCount(pixelData, transferSyntax);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 Json::Value result(Json::arrayValue);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 for (unsigned int i = 0; i < blocks; i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 result.append(boost::lexical_cast<std::string>(i));
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 output.AnswerJson(result);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 return true;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 unsigned int block = boost::lexical_cast<unsigned int>(*blockUri);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 if (block < GetPixelDataBlockCount(pixelData, transferSyntax))
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 DcmPixelSequence* pixelSequence = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 if (pixelData.getEncapsulatedRepresentation
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 // This is the case for JPEG transfer syntaxes
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 if (block < pixelSequence->card())
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 DcmPixelItem* pixelItem = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 if (pixelSequence->getItem(pixelItem, block).good() && pixelItem)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 if (pixelItem->getLength() == 0)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 output.AnswerBuffer(NULL, 0, CONTENT_TYPE_OCTET_STREAM);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 return true;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 Uint8* buffer = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 if (pixelItem->getUint8Array(buffer).good() && buffer)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 output.AnswerBuffer(buffer, pixelItem->getLength(), CONTENT_TYPE_OCTET_STREAM);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 return true;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 // This is the case for raw, uncompressed image buffers
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 assert(*blockUri == "0");
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
393 DicomFieldStream stream(*element, transferSyntax);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
394 output.AnswerStream(stream);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 catch (boost::bad_lexical_cast&)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 // The URI entered by the user is not a number
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 catch (std::bad_cast&)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 // This should never happen
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 return false;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
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 static void SendPathValueForLeaf(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 const std::string& tag,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 DcmItem& dicom,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 E_TransferSyntax transferSyntax)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 DcmTagKey k;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 ParseTagAndGroup(k, tag);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 DcmSequenceOfItems* sequence = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 if (dicom.findAndGetSequence(k, sequence).good() &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 sequence != NULL &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 sequence->getVR() == EVR_SQ)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 SendSequence(output, *sequence);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 DcmElement* element = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 if (dicom.findAndGetElement(k, element).good() &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 element != NULL &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 //element->getVR() != EVR_UNKNOWN && // This would forbid private tags
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 element->getVR() != EVR_SQ)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
435 DicomFieldStream stream(*element, transferSyntax);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
436 output.AnswerStream(stream);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 void ParsedDicomFile::SendPathValue(RestApiOutput& output,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 const UriComponents& uri)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
443 DcmItem* dicom = pimpl_->file_->getDataset();
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
444 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer();
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 // Special case: Accessing the pixel data
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 if (uri.size() == 1 ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 uri.size() == 2)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 DcmTagKey tag;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 ParseTagAndGroup(tag, uri[0]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 if (tag.getGroup() == DICOM_TAG_PIXEL_DATA.GetGroup() &&
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 tag.getElement() == DICOM_TAG_PIXEL_DATA.GetElement())
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 AnswerPixelData(output, *dicom, transferSyntax, uri.size() == 1 ? NULL : &uri[1]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 // Go down in the tag hierarchy according to the URI
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 for (size_t pos = 0; pos < uri.size() / 2; pos++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 size_t index;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 try
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 index = boost::lexical_cast<size_t>(uri[2 * pos + 1]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 catch (boost::bad_lexical_cast&)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 }
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 k;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 DcmItem *child = NULL;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 ParseTagAndGroup(k, uri[2 * pos]);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 if (!dicom->findAndGetSequenceItem(k, child, index).good() ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 child == NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 return;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 dicom = child;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 // We have reached the end of the URI
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 if (uri.size() % 2 == 0)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 SendPathValueForDictionary(output, *dicom);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 SendPathValueForLeaf(output, uri.back(), *dicom, transferSyntax);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 }
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 void ParsedDicomFile::Remove(const DicomTag& tag)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 {
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
500 InvalidateCache();
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
501
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 DcmTagKey key(tag.GetGroup(), tag.GetElement());
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
503 DcmElement* element = pimpl_->file_->getDataset()->remove(key);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 if (element != NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 delete element;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 }
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
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
511 void ParsedDicomFile::Clear(const DicomTag& tag,
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
512 bool onlyIfExists)
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
513 {
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
514 InvalidateCache();
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
515
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
516 DcmItem* dicom = pimpl_->file_->getDataset();
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
517 DcmTagKey key(tag.GetGroup(), tag.GetElement());
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
518
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
519 if (onlyIfExists &&
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
520 !dicom->tagExists(key))
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
521 {
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
522 // The tag is non-existing, do not clear it
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
523 }
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
524 else
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
525 {
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
526 if (!dicom->insertEmptyElement(key, OFTrue /* replace old value */).good())
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
527 {
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
528 throw OrthancException(ErrorCode_InternalError);
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
529 }
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
530 }
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
531 }
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
532
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
534 void ParsedDicomFile::RemovePrivateTagsInternal(const std::set<DicomTag>* toKeep)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
536 InvalidateCache();
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
537
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
538 DcmDataset& dataset = *pimpl_->file_->getDataset();
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
539
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
540 // Loop over the dataset to detect its private tags
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 typedef std::list<DcmElement*> Tags;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 Tags privateTags;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 for (unsigned long i = 0; i < dataset.card(); i++)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 DcmElement* element = dataset.getElement(i);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 DcmTag tag(element->getTag());
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
548
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
549 // Is this a private tag?
1694
06d579e82bb8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
550 if (tag.isPrivate())
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
552 bool remove = true;
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
553
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
554 // 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
555 if (toKeep != NULL)
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
556 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
557 DicomTag tmp = FromDcmtkBridge::Convert(tag);
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
558 if (toKeep->find(tmp) != toKeep->end())
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
559 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
560 remove = false; // Keep it
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
561 }
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
562 }
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
563
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
564 if (remove)
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
565 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
566 privateTags.push_back(element);
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
567 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
571 // Loop over the detected private tags to remove them
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 for (Tags::iterator it = privateTags.begin();
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 it != privateTags.end(); ++it)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 DcmElement* tmp = dataset.remove(*it);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 if (tmp != NULL)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 delete tmp;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
584 static void InsertInternal(DcmDataset& dicom,
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
585 DcmElement* element)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 {
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
587 OFCondition cond = dicom.insert(element, false, false);
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
588 if (!cond.good())
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 // This field already exists
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
591 delete element;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 throw OrthancException(ErrorCode_InternalError);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
597 void ParsedDicomFile::Insert(const DicomTag& tag,
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
598 const Json::Value& value,
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
599 bool decodeDataUriScheme)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 {
1980
ebce5f456b8e new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1979
diff changeset
601 if (pimpl_->file_->getDataset()->tagExists(ToDcmtkBridge::Convert(tag)))
ebce5f456b8e new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1979
diff changeset
602 {
ebce5f456b8e new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1979
diff changeset
603 throw OrthancException(ErrorCode_AlreadyExistingTag);
ebce5f456b8e new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1979
diff changeset
604 }
ebce5f456b8e new error code: ErrorCode_AlreadyExistingTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1979
diff changeset
605
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
606 if (decodeDataUriScheme &&
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
607 value.type() == Json::stringValue &&
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
608 (tag == DICOM_TAG_ENCAPSULATED_DOCUMENT ||
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
609 tag == DICOM_TAG_PIXEL_DATA))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
610 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
611 if (EmbedContentInternal(value.asString()))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
612 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
613 return;
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
614 }
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
615 }
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
616
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
617 InvalidateCache();
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
618 std::auto_ptr<DcmElement> element(FromDcmtkBridge::FromJson(tag, value, decodeDataUriScheme, GetEncoding()));
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
619 InsertInternal(*pimpl_->file_->getDataset(), element.release());
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
620 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
621
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
623 static bool CanReplaceProceed(DcmDataset& dicom,
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
624 const DcmTagKey& tag,
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
625 DicomReplaceMode mode)
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
626 {
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
627 if (dicom.findAndDeleteElement(tag).good())
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 {
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
629 // This tag was existing, it has been deleted
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
630 return true;
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
631 }
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
632 else
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
633 {
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
634 // This tag was absent, act wrt. the specified "mode"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 switch (mode)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 case DicomReplaceMode_InsertIfAbsent:
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
638 return true;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 case DicomReplaceMode_ThrowIfAbsent:
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 throw OrthancException(ErrorCode_InexistentItem);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 case DicomReplaceMode_IgnoreIfAbsent:
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
644 return false;
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
645
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
646 default:
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
647 throw OrthancException(ErrorCode_ParameterOutOfRange);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 }
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
650 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
651
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
652
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
653 void ParsedDicomFile::UpdateStorageUid(const DicomTag& tag,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
654 const std::string& utf8Value,
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
655 bool decodeDataUriScheme)
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
656 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
657 if (tag != DICOM_TAG_SOP_CLASS_UID &&
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
658 tag != DICOM_TAG_SOP_INSTANCE_UID)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 {
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
660 return;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
663 std::string binary;
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
664 const std::string* decoded = &utf8Value;
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
665
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
666 if (decodeDataUriScheme &&
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
667 boost::starts_with(utf8Value, "data:application/octet-stream;base64,"))
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
668 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
669 std::string mime;
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
670 if (!Toolbox::DecodeDataUriScheme(mime, binary, utf8Value))
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
671 {
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
672 throw OrthancException(ErrorCode_BadFileFormat);
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
673 }
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
674
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
675 decoded = &binary;
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
676 }
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
677 else
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
678 {
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
679 Encoding encoding = GetEncoding();
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
680 if (GetEncoding() != Encoding_Utf8)
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
681 {
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
682 binary = Toolbox::ConvertFromUtf8(utf8Value, encoding);
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
683 decoded = &binary;
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
684 }
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
685 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 /**
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 * dcmodify will automatically correct 'Media Storage SOP Class
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 * UID' and 'Media Storage SOP Instance UID' in the metaheader, if
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 * you make changes to the related tags in the dataset ('SOP Class
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 * UID' and 'SOP Instance UID') via insert or modify mode
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 * options. You can disable this behaviour by using the -nmu
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 * option.
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 **/
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 if (tag == DICOM_TAG_SOP_CLASS_UID)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
698 ReplacePlainString(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, *decoded);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 if (tag == DICOM_TAG_SOP_INSTANCE_UID)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
703 ReplacePlainString(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, *decoded);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
704 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
705 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
706
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
707
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
708 void ParsedDicomFile::Replace(const DicomTag& tag,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
709 const std::string& utf8Value,
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
710 bool decodeDataUriScheme,
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
711 DicomReplaceMode mode)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
712 {
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
713 InvalidateCache();
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
714
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
715 DcmDataset& dicom = *pimpl_->file_->getDataset();
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
716 if (CanReplaceProceed(dicom, ToDcmtkBridge::Convert(tag), mode))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
717 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
718 // Either the tag was previously existing (and now removed), or
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
719 // the replace mode was set to "InsertIfAbsent"
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
720
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
721 if (decodeDataUriScheme &&
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
722 (tag == DICOM_TAG_ENCAPSULATED_DOCUMENT ||
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
723 tag == DICOM_TAG_PIXEL_DATA))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
724 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
725 if (EmbedContentInternal(utf8Value))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
726 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
727 return;
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
728 }
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
729 }
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
730
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
731 std::auto_ptr<DcmElement> element(FromDcmtkBridge::CreateElementForTag(tag));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
732 FromDcmtkBridge::FillElementWithString(*element, tag, utf8Value, decodeDataUriScheme, GetEncoding());
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
733
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
734 InsertInternal(dicom, element.release());
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
735 UpdateStorageUid(tag, utf8Value, false);
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
736 }
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
737 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
738
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
739
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
740 void ParsedDicomFile::Replace(const DicomTag& tag,
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
741 const Json::Value& value,
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
742 bool decodeDataUriScheme,
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
743 DicomReplaceMode mode)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
744 {
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
745 InvalidateCache();
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
746
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
747 DcmDataset& dicom = *pimpl_->file_->getDataset();
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
748 if (CanReplaceProceed(dicom, ToDcmtkBridge::Convert(tag), mode))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
749 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
750 // Either the tag was previously existing (and now removed), or
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
751 // the replace mode was set to "InsertIfAbsent"
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
752
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
753 if (decodeDataUriScheme &&
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
754 value.type() == Json::stringValue &&
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
755 (tag == DICOM_TAG_ENCAPSULATED_DOCUMENT ||
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
756 tag == DICOM_TAG_PIXEL_DATA))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
757 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
758 if (EmbedContentInternal(value.asString()))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
759 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
760 return;
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
761 }
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
762 }
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
763
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
764 InsertInternal(dicom, FromDcmtkBridge::FromJson(tag, value, decodeDataUriScheme, GetEncoding()));
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
765
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
766 if (tag == DICOM_TAG_SOP_CLASS_UID ||
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
767 tag == DICOM_TAG_SOP_INSTANCE_UID)
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
768 {
1979
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
769 if (value.type() != Json::stringValue)
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
770 {
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
771 throw OrthancException(ErrorCode_BadParameterType);
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
772 }
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
773
9e0f408db796 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1956
diff changeset
774 UpdateStorageUid(tag, value.asString(), decodeDataUriScheme);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
775 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 void ParsedDicomFile::Answer(RestApiOutput& output)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 std::string serialized;
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
783 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset()))
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 output.AnswerBuffer(serialized, CONTENT_TYPE_OCTET_STREAM);
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
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 bool ParsedDicomFile::GetTagValue(std::string& value,
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 const DicomTag& tag)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 DcmTagKey k(tag.GetGroup(), tag.GetElement());
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
795 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
796
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
797 if (tag.IsPrivate() ||
1655
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1641
diff changeset
798 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
799 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
800 tag == DICOM_TAG_ENCAPSULATED_DOCUMENT)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 {
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
802 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
803 long unsigned int count = 0;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
805 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
806 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
807 if (count > 0)
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
808 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
809 assert(data != NULL);
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
810 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
811 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
812 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
813 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
814 value.clear();
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
815 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
817 return true;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
818 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
819 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
820 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
821 return false;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
822 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 else
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 {
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
826 DcmElement* element = NULL;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
827 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
828 element == NULL)
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
829 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
830 return false;
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
831 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
832
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
833 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
834 (*element, DicomToJsonFlags_Default,
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
835 ORTHANC_MAXIMUM_TAG_LENGTH, GetEncoding()));
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
836
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
837 if (v.get() == NULL ||
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
838 v->IsNull())
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
839 {
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
840 value = "";
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
841 }
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
842 else
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
843 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
844 // TODO v->IsBinary()
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
845 value = v->GetContent();
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
846 }
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
847
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
848 return true;
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 DicomInstanceHasher ParsedDicomFile::GetHasher()
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 std::string patientId, studyUid, seriesUid, instanceUid;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 if (!GetTagValue(patientId, DICOM_TAG_PATIENT_ID) ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 !GetTagValue(studyUid, DICOM_TAG_STUDY_INSTANCE_UID) ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 !GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID) ||
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 !GetTagValue(instanceUid, DICOM_TAG_SOP_INSTANCE_UID))
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 throw OrthancException(ErrorCode_BadFileFormat);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid);
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 void ParsedDicomFile::SaveToMemoryBuffer(std::string& buffer)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 {
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
871 FromDcmtkBridge::SaveToMemoryBuffer(buffer, *pimpl_->file_->getDataset());
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 void ParsedDicomFile::SaveToFile(const std::string& path)
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 {
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 // TODO Avoid using a temporary memory buffer, write directly on disk
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 std::string content;
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 SaveToMemoryBuffer(content);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2131
diff changeset
880 SystemToolbox::WriteFile(content, path);
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1800
diff changeset
884 ParsedDicomFile::ParsedDicomFile(bool createIdentifiers) : pimpl_(new PImpl)
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
886 pimpl_->file_.reset(new DcmFileFormat);
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1800
diff changeset
887
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1800
diff changeset
888 if (createIdentifiers)
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1800
diff changeset
889 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
890 ReplacePlainString(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
891 ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
892 ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
893 ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1800
diff changeset
894 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 }
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
897
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
898 void ParsedDicomFile::CreateFromDicomMap(const DicomMap& source,
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
899 Encoding defaultEncoding)
1786
164d78911382 primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
900 {
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
901 pimpl_->file_.reset(new DcmFileFormat);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
902
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
903 const DicomValue* tmp = source.TestAndGetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
904 if (tmp != NULL)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
905 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
906 Encoding encoding;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
907 if (tmp->IsNull() ||
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
908 tmp->IsBinary() ||
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
909 !GetDicomEncoding(encoding, tmp->GetContent().c_str()))
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
910 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
911 throw OrthancException(ErrorCode_ParameterOutOfRange);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
912 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
913 else
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
914 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
915 SetEncoding(encoding);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
916 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
917 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
918 else
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
919 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
920 SetEncoding(defaultEncoding);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
921 }
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1786
diff changeset
922
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
923 for (DicomMap::Map::const_iterator
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
924 it = source.map_.begin(); it != source.map_.end(); ++it)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
925 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
926 if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET &&
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
927 !it->second->IsNull())
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
928 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
929 ReplacePlainString(it->first, it->second->GetContent());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
930 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
931 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
932 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
933
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1786
diff changeset
934
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
935 ParsedDicomFile::ParsedDicomFile(const DicomMap& map,
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
936 Encoding defaultEncoding) :
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
937 pimpl_(new PImpl)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
938 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
939 CreateFromDicomMap(map, defaultEncoding);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
940 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
941
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
942
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
943 ParsedDicomFile::ParsedDicomFile(const DicomMap& map) :
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
944 pimpl_(new PImpl)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
945 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
946 CreateFromDicomMap(map, Configuration::GetDefaultEncoding());
1786
164d78911382 primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
947 }
164d78911382 primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
948
164d78911382 primitives to handle dicom worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
949
1800
30e97a1f4093 callback for handling worklists with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
950 ParsedDicomFile::ParsedDicomFile(const void* content,
30e97a1f4093 callback for handling worklists with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
951 size_t size) : pimpl_(new PImpl)
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
952 {
1935
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
953 pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(content, size));
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
954 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
955
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
956 ParsedDicomFile::ParsedDicomFile(const std::string& content) : pimpl_(new PImpl)
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
957 {
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
958 if (content.size() == 0)
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
959 {
1935
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
960 pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(NULL, 0));
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
961 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
962 else
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
963 {
1935
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
964 pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(&content[0], content.size()));
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
965 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
966 }
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
967
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
968
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
969 ParsedDicomFile::ParsedDicomFile(ParsedDicomFile& other) :
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
970 pimpl_(new PImpl)
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
971 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
972 pimpl_->file_.reset(dynamic_cast<DcmFileFormat*>(other.pimpl_->file_->clone()));
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
973
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
974 // Create a new instance-level identifier
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
975 ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
976 }
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
977
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
978
1788
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
979 ParsedDicomFile::ParsedDicomFile(DcmDataset& dicom) : pimpl_(new PImpl)
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
980 {
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
981 pimpl_->file_.reset(new DcmFileFormat(&dicom));
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
982 }
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
983
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
984
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
985 ParsedDicomFile::ParsedDicomFile(DcmFileFormat& dicom) : pimpl_(new PImpl)
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
986 {
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
987 pimpl_->file_.reset(new DcmFileFormat(dicom));
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
988 }
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
989
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
990
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
991 ParsedDicomFile::~ParsedDicomFile()
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
992 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
993 delete pimpl_;
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
994 }
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
995
793
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
996
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
997 DcmFileFormat& ParsedDicomFile::GetDcmtkObject() const
793
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
998 {
1788
6a2d507ef064 getting rid of opaque data structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
999 return *pimpl_->file_.get();
793
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1000 }
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1001
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1002
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1003 ParsedDicomFile* ParsedDicomFile::Clone()
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1004 {
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 793
diff changeset
1005 return new ParsedDicomFile(*this);
793
145604a97914 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
1006 }
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1007
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1008
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1009 bool ParsedDicomFile::EmbedContentInternal(const std::string& dataUriScheme)
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1010 {
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
1011 std::string mime, content;
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
1012 if (!Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme))
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
1013 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1014 return false;
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
1015 }
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1980
diff changeset
1016
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1017 Toolbox::ToLowerCase(mime);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1018
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1019 if (mime == "image/png" ||
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1020 mime == "image/jpeg")
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1021 {
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1022 EmbedImage(mime, content);
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1023 }
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1024 else if (mime == "application/pdf")
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1025 {
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1026 EmbedPdf(content);
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1027 }
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1028 else
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1029 {
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1030 LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file: " << mime;
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1031 throw OrthancException(ErrorCode_NotImplemented);
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
1032 }
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1033
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1034 return true;
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1035 }
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1036
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1037
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1038 void ParsedDicomFile::EmbedContent(const std::string& dataUriScheme)
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1039 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1040 if (!EmbedContentInternal(dataUriScheme))
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1041 {
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1042 throw OrthancException(ErrorCode_BadFileFormat);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1043 }
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1044 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1045
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1046
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1047 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
1048 const std::string& content)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1049 {
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1050 if (mime == "image/png")
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1051 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1052 PngReader reader;
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1053 reader.ReadFromMemory(content);
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1054 EmbedImage(reader);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1055 }
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1056 else if (mime == "image/jpeg")
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1057 {
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1058 JpegReader reader;
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1059 reader.ReadFromMemory(content);
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1060 EmbedImage(reader);
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
1061 }
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1062 else
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1063 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1064 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1065 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1066 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1067
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1068
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1069 void ParsedDicomFile::EmbedImage(const ImageAccessor& accessor)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1070 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1071 if (accessor.GetFormat() != PixelFormat_Grayscale8 &&
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1072 accessor.GetFormat() != PixelFormat_Grayscale16 &&
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1073 accessor.GetFormat() != PixelFormat_SignedGrayscale16 &&
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1074 accessor.GetFormat() != PixelFormat_RGB24 &&
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1075 accessor.GetFormat() != PixelFormat_RGBA32)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1076 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1077 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1078 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1079
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1080 InvalidateCache();
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1081
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1082 if (accessor.GetFormat() == PixelFormat_RGBA32)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1083 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1084 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
1085 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1086
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1087 // 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
1088
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1089 Remove(DICOM_TAG_PIXEL_DATA);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1090 ReplacePlainString(DICOM_TAG_COLUMNS, boost::lexical_cast<std::string>(accessor.GetWidth()));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1091 ReplacePlainString(DICOM_TAG_ROWS, boost::lexical_cast<std::string>(accessor.GetHeight()));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1092 ReplacePlainString(DICOM_TAG_SAMPLES_PER_PIXEL, "1");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1093 ReplacePlainString(DICOM_TAG_NUMBER_OF_FRAMES, "1");
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1094
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1095 if (accessor.GetFormat() == PixelFormat_SignedGrayscale16)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1096 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1097 ReplacePlainString(DICOM_TAG_PIXEL_REPRESENTATION, "1");
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1098 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1099 else
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1100 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1101 ReplacePlainString(DICOM_TAG_PIXEL_REPRESENTATION, "0"); // Unsigned pixels
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1102 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1103
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1104 ReplacePlainString(DICOM_TAG_PLANAR_CONFIGURATION, "0"); // Color channels are interleaved
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1105 ReplacePlainString(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2");
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1106
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1107 unsigned int bytesPerPixel = 0;
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1108
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1109 switch (accessor.GetFormat())
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1110 {
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1111 case PixelFormat_Grayscale8:
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1112 ReplacePlainString(DICOM_TAG_BITS_ALLOCATED, "8");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1113 ReplacePlainString(DICOM_TAG_BITS_STORED, "8");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1114 ReplacePlainString(DICOM_TAG_HIGH_BIT, "7");
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1115 bytesPerPixel = 1;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1116 break;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1117
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1118 case PixelFormat_RGB24:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1119 case PixelFormat_RGBA32:
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1120 ReplacePlainString(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "RGB");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1121 ReplacePlainString(DICOM_TAG_SAMPLES_PER_PIXEL, "3");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1122 ReplacePlainString(DICOM_TAG_BITS_ALLOCATED, "8");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1123 ReplacePlainString(DICOM_TAG_BITS_STORED, "8");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1124 ReplacePlainString(DICOM_TAG_HIGH_BIT, "7");
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1125 bytesPerPixel = 3;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1126 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1127
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1128 case PixelFormat_Grayscale16:
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1129 case PixelFormat_SignedGrayscale16:
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1130 ReplacePlainString(DICOM_TAG_BITS_ALLOCATED, "16");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1131 ReplacePlainString(DICOM_TAG_BITS_STORED, "16");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1132 ReplacePlainString(DICOM_TAG_HIGH_BIT, "15");
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1133 bytesPerPixel = 2;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1134 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1135
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1136 default:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1137 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1138 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1139
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1140 assert(bytesPerPixel != 0);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
1141
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1142 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
1143 DICOM_TAG_PIXEL_DATA.GetElement());
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1144
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1145 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
1146
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1147 unsigned int pitch = accessor.GetWidth() * bytesPerPixel;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1148 Uint8* target = NULL;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1149 pixels->createUint8Array(accessor.GetHeight() * pitch, target);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1150
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1151 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
1152 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1153 switch (accessor.GetFormat())
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1154 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1155 case PixelFormat_RGB24:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1156 case PixelFormat_Grayscale8:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1157 case PixelFormat_Grayscale16:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1158 case PixelFormat_SignedGrayscale16:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1159 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1160 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
1161 target += pitch;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1162 break;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1163 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1164
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1165 case PixelFormat_RGBA32:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1166 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1167 // 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
1168 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
1169 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
1170 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1171 target[0] = source[0];
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1172 target[1] = source[1];
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1173 target[2] = source[2];
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1174 }
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 break;
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 default:
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1180 throw OrthancException(ErrorCode_NotImplemented);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1181 }
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
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1184 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
1185 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
1186 throw OrthancException(ErrorCode_InternalError);
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 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1189
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1190
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1191 Encoding ParsedDicomFile::GetEncoding() const
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1192 {
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
1193 return FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset(),
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
1194 Configuration::GetDefaultEncoding());
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1195 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1196
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1197
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1198 void ParsedDicomFile::SetEncoding(Encoding encoding)
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1199 {
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1200 if (encoding == Encoding_Windows1251)
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1201 {
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1202 // 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
1203 // 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
1204 return;
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1205 }
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1206
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
1207 std::string s = GetDicomSpecificCharacterSet(encoding);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1208 ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, s);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1209 }
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1018
diff changeset
1210
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1211 void ParsedDicomFile::DatasetToJson(Json::Value& target,
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1212 DicomToJsonFormat format,
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1213 DicomToJsonFlags flags,
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1214 unsigned int maxStringLength)
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1215 {
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2125
diff changeset
1216 FromDcmtkBridge::ExtractDicomAsJson(target, *pimpl_->file_->getDataset(),
2131
bb199bccdc45 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
1217 format, flags, maxStringLength, Configuration::GetDefaultEncoding());
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1218 }
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1219
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1220
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1221 void ParsedDicomFile::DatasetToJson(Json::Value& target)
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1222 {
2131
bb199bccdc45 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
1223 Configuration::ExtractDicomAsJson(target, *pimpl_->file_->getDataset());
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1224 }
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1225
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
1226
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1827
diff changeset
1227 void ParsedDicomFile::HeaderToJson(Json::Value& target,
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1827
diff changeset
1228 DicomToJsonFormat format)
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1827
diff changeset
1229 {
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2125
diff changeset
1230 FromDcmtkBridge::ExtractHeaderAsJson(target, *pimpl_->file_->getMetaInfo(), format, DicomToJsonFlags_None, 0);
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1827
diff changeset
1231 }
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1827
diff changeset
1232
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1827
diff changeset
1233
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1234 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
1235 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1236 DcmTag key(tag.GetGroup(), tag.GetElement());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1237 return pimpl_->file_->getDataset()->tagExists(key);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1238 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1239
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1240
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1241 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
1242 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1243 if (pdf.size() < 5 || // (*)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1244 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
1245 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1246 LOG(ERROR) << "Not a PDF file";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1247 throw OrthancException(ErrorCode_BadFileFormat);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1248 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1249
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1250 InvalidateCache();
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1251
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1252 ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, UID_EncapsulatedPDFStorage);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1253 ReplacePlainString(FromDcmtkBridge::Convert(DCM_Modality), "OT");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1254 ReplacePlainString(FromDcmtkBridge::Convert(DCM_ConversionType), "WSD");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1255 ReplacePlainString(FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument), "application/pdf");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1256 //ReplacePlainString(FromDcmtkBridge::Convert(DCM_SeriesNumber), "1");
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1257
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1258 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
1259
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1260 size_t s = pdf.size();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1261 if (s & 1)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1262 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1263 // 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
1264 s += 1;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1265 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1266
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1267 Uint8* bytes = NULL;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1268 OFCondition result = element->createUint8Array(s, bytes);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1269 if (!result.good() || bytes == NULL)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1270 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1271 throw OrthancException(ErrorCode_NotEnoughMemory);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1272 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1273
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1274 // 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
1275 bytes[s - 1] = 0;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1276
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1277 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
1278
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1279 DcmPolymorphOBOW* obj = element.release();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1280 result = pimpl_->file_->getDataset()->insert(obj);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1281
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1282 if (!result.good())
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1283 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1284 delete obj;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1285 throw OrthancException(ErrorCode_NotEnoughMemory);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1286 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1287 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
1288
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1289
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1290 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
1291 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1292 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
1293
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1294 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
1295 !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
1296 sop != UID_EncapsulatedPDFStorage ||
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1297 mime != "application/pdf")
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1298 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1299 return false;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1300 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1301
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1302 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
1303 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1304 return false;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1305 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1306
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1307 // 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
1308 // 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
1309 // 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
1310 // 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
1311 // 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
1312 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
1313 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1314 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
1315
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1316 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
1317 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1318 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
1319 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1320 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1321
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1322 return true;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1323 }
1662
09be34b2f30e ParsedDicomFile::Convert()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
1324
09be34b2f30e ParsedDicomFile::Convert()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
1325
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1326 ParsedDicomFile* ParsedDicomFile::CreateFromJson(const Json::Value& json,
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1327 DicomFromJsonFlags flags)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1328 {
2028
d108412411e5 fix msvc warnings
sjodogne
parents: 2016
diff changeset
1329 const bool generateIdentifiers = (flags & DicomFromJsonFlags_GenerateIdentifiers) ? true : false;
d108412411e5 fix msvc warnings
sjodogne
parents: 2016
diff changeset
1330 const bool decodeDataUriScheme = (flags & DicomFromJsonFlags_DecodeDataUriScheme) ? true : false;
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1331
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1332 std::auto_ptr<ParsedDicomFile> result(new ParsedDicomFile(generateIdentifiers));
1934
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
1333 result->SetEncoding(FromDcmtkBridge::ExtractEncoding(json, Configuration::GetDefaultEncoding()));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1334
1934
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
1335 const Json::Value::Members tags = json.getMemberNames();
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
1336
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1337 for (size_t i = 0; i < tags.size(); i++)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1338 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1339 DicomTag tag = FromDcmtkBridge::ParseTag(tags[i]);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1340 const Json::Value& value = json[tags[i]];
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1341
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1342 if (tag == DICOM_TAG_PIXEL_DATA ||
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1343 tag == DICOM_TAG_ENCAPSULATED_DOCUMENT)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1344 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1345 if (value.type() != Json::stringValue)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1346 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1347 throw OrthancException(ErrorCode_BadRequest);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1348 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1349 else
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1350 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1351 result->EmbedContent(value.asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1352 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1353 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1354 else if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1355 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1356 result->Replace(tag, value, decodeDataUriScheme, DicomReplaceMode_InsertIfAbsent);
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1357 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1358 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1359
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1360 return result.release();
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
1361 }
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1362
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1363
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1364 void ParsedDicomFile::GetRawFrame(std::string& target,
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1365 std::string& mime,
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1366 unsigned int frameId)
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1367 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1368 if (pimpl_->frameIndex_.get() == NULL)
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1369 {
1956
fc16ee04e71b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
1370 pimpl_->frameIndex_.reset(new DicomFrameIndex(*pimpl_->file_));
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1371 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1372
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1373 pimpl_->frameIndex_->GetRawFrame(target, frameId);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1374
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1375 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer();
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1376 switch (transferSyntax)
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1377 {
1946
40b7a0176305 fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1945
diff changeset
1378 case EXS_JPEGProcess1:
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1379 mime = "image/jpeg";
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1380 break;
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1381
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1382 case EXS_JPEG2000LosslessOnly:
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1383 case EXS_JPEG2000:
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1384 mime = "image/jp2";
2016
0ae26237569a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
1385 break;
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1386
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1387 default:
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1388 mime = "application/octet-stream";
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1389 break;
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1390 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1391 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1392
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1393
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1394 void ParsedDicomFile::InvalidateCache()
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1395 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1396 pimpl_->frameIndex_.reset(NULL);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1397 }
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1946
diff changeset
1398
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1946
diff changeset
1399
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1946
diff changeset
1400 unsigned int ParsedDicomFile::GetFramesCount() const
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1946
diff changeset
1401 {
1956
fc16ee04e71b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
1402 return DicomFrameIndex::GetFramesCount(*pimpl_->file_);
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1946
diff changeset
1403 }
2207
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1404
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1405
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1406 void ParsedDicomFile::ChangeEncoding(Encoding target)
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1407 {
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1408 Encoding source = GetEncoding();
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1409
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1410 if (source != target) // Avoid unnecessary conversion
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1411 {
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1412 ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, GetDicomSpecificCharacterSet(target));
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1413 FromDcmtkBridge::ChangeStringEncoding(*pimpl_->file_->getDataset(), source, target);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1414 }
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1415 }
2209
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1416
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1417
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1418 void ParsedDicomFile::ExtractDicomSummary(DicomMap& target) const
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1419 {
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1420 Configuration::ExtractDicomSummary(target, *pimpl_->file_->getDataset());
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1421 }
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1422
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1423
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1424 void ParsedDicomFile::ExtractDicomAsJson(Json::Value& target) const
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1425 {
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1426 Configuration::ExtractDicomAsJson(target, *pimpl_->file_->getDataset());
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1427 }
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1428
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1429
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1430 bool ParsedDicomFile::LookupTransferSyntax(std::string& result)
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1431 {
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1432 return FromDcmtkBridge::LookupTransferSyntax(result, *pimpl_->file_);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
1433 }
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1434
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1435
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1436 bool ParsedDicomFile::LookupPhotometricInterpretation(PhotometricInterpretation& result) const
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1437 {
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1438 DcmTagKey k(DICOM_TAG_PHOTOMETRIC_INTERPRETATION.GetGroup(),
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1439 DICOM_TAG_PHOTOMETRIC_INTERPRETATION.GetElement());
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1440
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1441 DcmDataset& dataset = *pimpl_->file_->getDataset();
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1442
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1443 const char *c = NULL;
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1444 if (dataset.findAndGetString(k, c).good() &&
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1445 c != NULL)
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1446 {
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1447 result = StringToPhotometricInterpretation(c);
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1448 return true;
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1449 }
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1450 else
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1451 {
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1452 return false;
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1453 }
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
1454 }
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 }