annotate OrthancStone/Sources/Toolbox/SortedFrames.cpp @ 1616:32090b775777

remove annoying alert
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Oct 2020 17:40:08 +0100
parents b3c439d96d3e
children 78509230f0d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
16 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "SortedFrames.h"
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1490
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
25 #include "GeometryToolbox.h"
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
1490
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
27 #include <OrthancException.h>
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
28 #include <Toolbox.h>
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancStone
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 SortedFrames::Instance::Instance(const Orthanc::DicomMap& tags)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 tags_.Assign(tags);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 if (!tags.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 uint32_t tmp;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 if (tags.ParseUnsignedInteger32(tmp, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 numberOfFrames_ = tmp;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 numberOfFrames_ = 1;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
1490
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
51 std::string photometric;
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
52 if (tags.LookupStringValue(photometric, Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION, false))
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
53 {
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
54 Orthanc::Toolbox::StripSpaces(photometric);
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
55 monochrome1_ = (photometric == "MONOCHROME1");
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
56 }
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
57 else
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
58 {
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
59 monochrome1_ = false;
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
60 }
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
61
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 hasPosition_ = (
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 LinearAlgebra::ParseVector(position_, tags, Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT) &&
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 position_.size() == 3 &&
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 GeometryToolbox::ComputeNormal(normal_, tags));
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 const Vector& SortedFrames::Instance::GetNormal() const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 if (hasPosition_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 return normal_;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 const Vector& SortedFrames::Instance::GetPosition() const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if (hasPosition_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 return position_;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 SortedFrames::Frame::Frame(const Instance& instance,
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
96 unsigned int frameNumber) :
1485
60be4627ae52 fix for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1479
diff changeset
97 instance_(&instance),
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
98 frameNumber_(frameNumber)
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
100 if (frameNumber >= instance.GetNumberOfFrames())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
107 const SortedFrames::Instance& SortedFrames::GetInstance(size_t instanceIndex) const
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
109 if (instanceIndex >= instances_.size())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
115 assert(instances_[instanceIndex] != NULL);
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
116 return *instances_[instanceIndex];
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
121 const SortedFrames::Frame& SortedFrames::GetFrame(size_t frameIndex) const
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 if (!sorted_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 "Sort() has not been called");
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
128 if (frameIndex >= frames_.size())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
134 return frames_[frameIndex];
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
1479
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
139 void SortedFrames::Clear()
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 for (size_t i = 0; i < instances_.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 assert(instances_[i] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 delete instances_[i];
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
1479
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
146
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
147 studyInstanceUid_.clear();
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
148 seriesInstanceUid_.clear();
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
149 frames_.clear();
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
150
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
151 instancesIndex_.clear();
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
152 framesIndex_.clear();
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
153
1479
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
154 sorted_ = true;
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 void SortedFrames::AddInstance(const Orthanc::DicomMap& tags)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 std::unique_ptr<Instance> instance(new Instance(tags));
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
1599
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
162 std::string studyInstanceUid, seriesInstanceUid, sopInstanceUid;
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 if (!tags.LookupStringValue(studyInstanceUid, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) ||
1599
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
164 !tags.LookupStringValue(seriesInstanceUid, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) ||
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
165 !tags.LookupStringValue(sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 if (instances_.empty())
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 studyInstanceUid_ = studyInstanceUid;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 seriesInstanceUid_ = seriesInstanceUid;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 if (studyInstanceUid_ != studyInstanceUid ||
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 seriesInstanceUid_ != seriesInstanceUid)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 "Mixing instances from different series");
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
1599
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
185 if (instancesIndex_.find(sopInstanceUid) != instancesIndex_.end())
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
186 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
187 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
188 "Cannot register twice the same SOP Instance UID");
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
189 }
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
190
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
191 instancesIndex_[sopInstanceUid] = instances_.size();
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
192
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 instances_.push_back(instance.release());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 sorted_ = false;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 frames_.clear();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
1599
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
199 bool SortedFrames::LookupSopInstanceUid(size_t& instanceIndex,
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
200 const std::string& sopInstanceUid) const
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
201 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
202 InstancesIndex::const_iterator found = instancesIndex_.find(sopInstanceUid);
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
203
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
204 if (found == instancesIndex_.end())
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
205 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
206 return false;
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
207 }
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
208 else
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
209 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
210 instanceIndex = found->second;
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
211 return true;
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
212 }
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
213 }
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
214
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
215
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 void SortedFrames::AddFramesOfInstance(std::set<size_t>& remainingInstances,
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
217 size_t instanceIndex)
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
219 assert(instances_[instanceIndex] != NULL);
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
220 const Instance& instance = *instances_[instanceIndex];
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
224 framesIndex_[std::make_pair(instance.GetSopInstanceUid(), i)] = frames_.size();
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 frames_.push_back(Frame(instance, i));
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
228 assert(remainingInstances.find(instanceIndex) != remainingInstances.end());
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
229 remainingInstances.erase(instanceIndex);
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 namespace
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 template<typename T>
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 class SortableItem
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 private:
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 T value_;
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
240 size_t instanceIndex_;
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 std::string sopInstanceUid_;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 public:
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 SortableItem(const T& value,
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
245 size_t instanceIndex,
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 const std::string& sopInstanceUid) :
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 value_(value),
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
248 instanceIndex_(instanceIndex),
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 sopInstanceUid_(sopInstanceUid)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 size_t GetInstanceIndex() const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
255 return instanceIndex_;
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 bool operator< (const SortableItem& other) const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 return (value_ < other.value_ ||
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 (value_ == other.value_ &&
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 sopInstanceUid_ < other.sopInstanceUid_));
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 };
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 void SortedFrames::SortUsingIntegerTag(std::set<size_t>& remainingInstances,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 const Orthanc::DicomTag& tag)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 std::vector< SortableItem<int32_t> > items;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 items.reserve(remainingInstances.size());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 assert(instances_[*it] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 const Instance& instance = *instances_[*it];
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 int32_t value;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 std::string sopInstanceUid;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 if (instance.GetTags().ParseInteger32(value, tag) &&
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 instance.GetTags().LookupStringValue(
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 items.push_back(SortableItem<int32_t>(value, *it, sopInstanceUid));
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 std::sort(items.begin(), items.end());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 for (size_t i = 0; i < items.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 void SortedFrames::SortUsingSopInstanceUid(std::set<size_t>& remainingInstances)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 std::vector<SortableItem<int32_t> > items;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 items.reserve(remainingInstances.size());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 assert(instances_[*it] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 const Instance& instance = *instances_[*it];
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 std::string sopInstanceUid;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 if (instance.GetTags().LookupStringValue(
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 items.push_back(SortableItem<int32_t>(0 /* arbitrary value */, *it, sopInstanceUid));
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 std::sort(items.begin(), items.end());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 for (size_t i = 0; i < items.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 void SortedFrames::SortUsing3DLocation(std::set<size_t>& remainingInstances)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 /**
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 * Compute the mean of the normal vectors, using the recursive
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 * formula for arithmetic means for numerical stability.
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 * https://diego.assencio.com/?index=c34d06f4f4de2375658ed41f70177d59
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 **/
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 Vector meanNormal;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 LinearAlgebra::AssignVector(meanNormal, 0, 0, 0);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 unsigned int n = 0;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 assert(instances_[*it] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 const Instance& instance = *instances_[*it];
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 if (instance.HasPosition())
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 n += 1;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 meanNormal += (instance.GetNormal() - meanNormal) / static_cast<float>(n);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 std::vector<SortableItem<float> > items;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 items.reserve(n);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 assert(instances_[*it] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 const Instance& instance = *instances_[*it];
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 std::string sopInstanceUid;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 if (instance.HasPosition() &&
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 instance.GetTags().LookupStringValue(
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 double p = LinearAlgebra::DotProduct(meanNormal, instance.GetPosition());
1605
b3c439d96d3e warning fix
Benjamin Golinvaux <bgo@osimis.io>
parents: 1602
diff changeset
368 items.push_back(SortableItem<float>(static_cast<float>(p), *it, sopInstanceUid));
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 assert(items.size() <= n);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 std::sort(items.begin(), items.end());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 for (size_t i = 0; i < items.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 size_t SortedFrames::GetFramesCount() const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 if (sorted_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 return frames_.size();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 "Sort() has not been called");
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
397 bool SortedFrames::LookupFrame(size_t& frameIndex,
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
398 const std::string& sopInstanceUid,
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
399 unsigned int frameNumber) const
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
400 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
401 if (sorted_)
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
402 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
403 FramesIndex::const_iterator found = framesIndex_.find(
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
404 std::make_pair(sopInstanceUid, frameNumber));
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
405
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
406 if (found == framesIndex_.end())
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
407 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
408 return false;
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
409 }
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
410 else
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
411 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
412 frameIndex = found->second;
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
413 return true;
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
414 }
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
415 }
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
416 else
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
417 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
418 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
419 "Sort() has not been called");
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
420 }
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
421 }
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
422
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
423
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 void SortedFrames::Sort()
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 if (!sorted_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 size_t totalFrames = 0;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 std::set<size_t> remainingInstances;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 for (size_t i = 0; i < instances_.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 assert(instances_[i] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 totalFrames += instances_[i]->GetNumberOfFrames();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 remainingInstances.insert(i);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 frames_.clear();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 frames_.reserve(totalFrames);
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
441 framesIndex_.clear();
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_INSTANCE_NUMBER); // VR is "IS"
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_IMAGE_INDEX); // VR is "US"
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 SortUsing3DLocation(remainingInstances);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 SortUsingSopInstanceUid(remainingInstances);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 // The following could in theory happen if several instances
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 // have the same SOPInstanceUID, no ordering is available
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
451 it != remainingInstances.end(); ++it)
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 AddFramesOfInstance(remainingInstances, *it);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 if (frames_.size() != totalFrames ||
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 !remainingInstances.empty())
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 sorted_ = true;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }