comparison Samples/Sdl/Loader.cpp @ 759:774681b2c77c

simplification
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 22 May 2019 17:25:44 +0200
parents f7c236894c1a
children 1181e1ad98ec
comparison
equal deleted inserted replaced
758:8c97c381f242 759:774681b2c77c
80 80
81 virtual ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const = 0; 81 virtual ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const = 0;
82 }; 82 };
83 83
84 84
85 class InvalidExtractedSlice : public IVolumeSlicer::ExtractedSlice
86 {
87 public:
88 virtual bool IsValid()
89 {
90 return false;
91 }
92
93 virtual uint64_t GetRevision()
94 {
95 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
96 }
97
98 virtual ISceneLayer* CreateSceneLayer()
99 {
100 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
101 }
102 };
103
85 104
86 class DicomVolumeImageOrthogonalSlice : public IVolumeSlicer::ExtractedSlice 105 class DicomVolumeImageOrthogonalSlice : public IVolumeSlicer::ExtractedSlice
87 { 106 {
88 private: 107 private:
89 CoordinateSystem3D cuttingPlane_; 108 const ImageBuffer3D& image_;
90 bool isInitialized_; 109 const VolumeImageGeometry& geometry_;
91 bool valid_; 110 bool valid_;
92 VolumeProjection projection_; 111 VolumeProjection projection_;
93 unsigned int sliceIndex_; 112 unsigned int sliceIndex_;
94 uint64_t revision_;
95
96 void Initialize()
97 {
98 if (!isInitialized_)
99 {
100 valid_ = DetectSlice(projection_, sliceIndex_, revision_, cuttingPlane_);
101 isInitialized_ = true;
102 }
103 }
104 113
105 protected: 114 protected:
106 virtual const ImageBuffer3D& GetImage() const = 0; 115 virtual uint64_t GetRevisionInternal(VolumeProjection projection,
107 116 unsigned int sliceIndex) const = 0;
108 virtual const VolumeImageGeometry& GetGeometry() const = 0;
109
110 // WARNING - This cannot be invoked from the constructor, hence lazy "Initialize()"
111 virtual bool DetectSlice(VolumeProjection& projection,
112 unsigned int& sliceIndex,
113 uint64_t& revision,
114 const CoordinateSystem3D& cuttingPlane) const = 0;
115 117
116 virtual const DicomInstanceParameters& GetDicomParameters(VolumeProjection projection, 118 virtual const DicomInstanceParameters& GetDicomParameters(VolumeProjection projection,
117 unsigned int sliceIndex) const = 0; 119 unsigned int sliceIndex) const = 0;
118 120
119 public: 121 public:
120 DicomVolumeImageOrthogonalSlice(const CoordinateSystem3D& cuttingPlane) : 122 DicomVolumeImageOrthogonalSlice(const ImageBuffer3D& image,
121 cuttingPlane_(cuttingPlane), 123 const VolumeImageGeometry& geometry,
122 isInitialized_(false) 124 const CoordinateSystem3D& cuttingPlane) :
123 { 125 image_(image),
126 geometry_(geometry)
127 {
128 valid_ = geometry_.DetectSlice(projection_, sliceIndex_, cuttingPlane);
124 } 129 }
125 130
126 virtual bool IsValid() 131 virtual bool IsValid()
127 { 132 {
128 Initialize();
129
130 return valid_; 133 return valid_;
131 } 134 }
132 135
133 virtual uint64_t GetRevision() 136 virtual uint64_t GetRevision()
134 { 137 {
135 Initialize();
136
137 if (!valid_) 138 if (!valid_)
138 { 139 {
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 140 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
140 } 141 }
141 else 142 else
142 { 143 {
143 return revision_; 144 return GetRevisionInternal(projection_, sliceIndex_);
144 } 145 }
145 } 146 }
146 147
147 virtual ISceneLayer* CreateSceneLayer() 148 virtual ISceneLayer* CreateSceneLayer()
148 { 149 {
149 Initialize();
150
151 if (!valid_) 150 if (!valid_)
152 { 151 {
153 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 152 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
154 } 153 }
155 else 154 else
156 { 155 {
157 std::auto_ptr<TextureBaseSceneLayer> texture; 156 std::auto_ptr<TextureBaseSceneLayer> texture;
158 157
159 { 158 {
160 ImageBuffer3D::SliceReader reader(GetImage(), projection_, sliceIndex_); 159 const DicomInstanceParameters& parameters = GetDicomParameters(projection_, sliceIndex_);
161 texture.reset(GetDicomParameters(projection_, sliceIndex_).CreateTexture(reader.GetAccessor())); 160 ImageBuffer3D::SliceReader reader(image_, projection_, sliceIndex_);
162 } 161 texture.reset(parameters.CreateTexture(reader.GetAccessor()));
163 162 }
164 const CoordinateSystem3D& system = GetGeometry().GetProjectionGeometry(projection_); 163
164 const CoordinateSystem3D& system = geometry_.GetProjectionGeometry(projection_);
165 165
166 double x0, y0, x1, y1; 166 double x0, y0, x1, y1;
167 system.ProjectPoint(x0, y0, system.GetOrigin()); 167 system.ProjectPoint(x0, y0, system.GetOrigin());
168 system.ProjectPoint(x1, y1, system.GetOrigin() + system.GetAxisX()); 168 system.ProjectPoint(x1, y1, system.GetOrigin() + system.GetAxisX());
169 texture->SetOrigin(x0, y0); 169 texture->SetOrigin(x0, y0);
175 { 175 {
176 texture->SetAngle(atan2(dy, dx)); 176 texture->SetAngle(atan2(dy, dx));
177 } 177 }
178 178
179 Vector tmp; 179 Vector tmp;
180 GetGeometry().GetVoxelDimensions(projection_); 180 geometry_.GetVoxelDimensions(projection_);
181 texture->SetPixelSpacing(tmp[0], tmp[1]); 181 texture->SetPixelSpacing(tmp[0], tmp[1]);
182 182
183 // texture->SetLinearInterpolation(linearInterpolation_); // TODO 183 // texture->SetLinearInterpolation(linearInterpolation_); // TODO
184 184
185 return texture.release(); 185 return texture.release();
197 { 197 {
198 private: 198 private:
199 const DicomSeriesVolumeImage& that_; 199 const DicomSeriesVolumeImage& that_;
200 200
201 protected: 201 protected:
202 virtual const ImageBuffer3D& GetImage() const 202 virtual uint64_t GetRevisionInternal(VolumeProjection projection,
203 { 203 unsigned int sliceIndex) const
204 return that_.GetImage(); 204 {
205 } 205 if (projection == VolumeProjection_Axial)
206 206 {
207 virtual const VolumeImageGeometry& GetGeometry() const 207 return that_.GetSliceRevision(sliceIndex);
208 {
209 return that_.GetGeometry();
210 }
211
212 virtual bool DetectSlice(VolumeProjection& projection,
213 unsigned int& sliceIndex,
214 uint64_t& revision,
215 const CoordinateSystem3D& cuttingPlane) const
216 {
217 if (!that_.HasGeometry() ||
218 !that_.GetGeometry().DetectSlice(projection, sliceIndex, cuttingPlane))
219 {
220 return false;
221 } 208 }
222 else 209 else
223 { 210 {
224 if (projection == VolumeProjection_Axial) 211 // For coronal and sagittal projections, we take the global
225 { 212 // revision of the volume
226 revision = that_.GetSliceRevision(sliceIndex); 213 return that_.GetRevision();
227 }
228 else
229 {
230 // For coronal and sagittal projections, we take the global
231 // revision of the volume
232 revision = that_.GetRevision();
233 }
234
235 return true;
236 } 214 }
237 } 215 }
238 216
239 virtual const DicomInstanceParameters& GetDicomParameters(VolumeProjection projection, 217 virtual const DicomInstanceParameters& GetDicomParameters(VolumeProjection projection,
240 unsigned int sliceIndex) const 218 unsigned int sliceIndex) const
243 } 221 }
244 222
245 public: 223 public:
246 Slice(const DicomSeriesVolumeImage& that, 224 Slice(const DicomSeriesVolumeImage& that,
247 const CoordinateSystem3D& plane) : 225 const CoordinateSystem3D& plane) :
248 DicomVolumeImageOrthogonalSlice(plane), 226 DicomVolumeImageOrthogonalSlice(that.GetImage(), that.GetGeometry(), plane),
249 that_(that) 227 that_(that)
250 { 228 {
251 } 229 }
252 }; 230 };
253 231
495 } 473 }
496 } 474 }
497 475
498 virtual IVolumeSlicer::ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const 476 virtual IVolumeSlicer::ExtractedSlice* ExtractSlice(const CoordinateSystem3D& cuttingPlane) const
499 { 477 {
500 return new Slice(*this, cuttingPlane); 478 if (HasGeometry())
479 {
480 return new Slice(*this, cuttingPlane);
481 }
482 else
483 {
484 return new InvalidExtractedSlice;
485 }
501 } 486 }
502 }; 487 };
503 488
504 489
505 490