comparison Framework/Volumes/DicomVolumeImageMPRSlicer.cpp @ 1161:19b1c8caade4 broker

fix sagittal geometry
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 Nov 2019 17:30:05 +0100
parents 640feb146fa8
children 0ca50d275b9a
comparison
equal deleted inserted replaced
1160:59906485896f 1161:19b1c8caade4
43 const CoordinateSystem3D& cuttingPlane) : 43 const CoordinateSystem3D& cuttingPlane) :
44 volume_(volume), 44 volume_(volume),
45 revision_(volume_.GetRevision()) 45 revision_(volume_.GetRevision())
46 { 46 {
47 valid_ = (volume_.HasDicomParameters() && 47 valid_ = (volume_.HasDicomParameters() &&
48 volume_.GetGeometry().DetectSlice(projection_, sliceIndex_, 48 volume_.GetGeometry().DetectSlice(projection_, sliceIndex_, cuttingPlane));
49 cuttingPlane));
50 } 49 }
51 50
52 51
53 VolumeProjection DicomVolumeImageMPRSlicer::Slice::GetProjection() const 52 VolumeProjection DicomVolumeImageMPRSlicer::Slice::GetProjection() const
54 { 53 {
80 { 79 {
81 const DicomInstanceParameters& parameters = volume_.GetDicomParameters(); 80 const DicomInstanceParameters& parameters = volume_.GetDicomParameters();
82 ImageBuffer3D::SliceReader reader(volume_.GetPixelData(), projection_, sliceIndex_); 81 ImageBuffer3D::SliceReader reader(volume_.GetPixelData(), projection_, sliceIndex_);
83 texture.reset(dynamic_cast<TextureBaseSceneLayer*> 82 texture.reset(dynamic_cast<TextureBaseSceneLayer*>
84 (configurator->CreateTextureFromDicom(reader.GetAccessor(), parameters))); 83 (configurator->CreateTextureFromDicom(reader.GetAccessor(), parameters)));
85
86 // <DEBUG-BLOCK>
87 #if 0
88 Orthanc::JpegWriter writer;
89 writer.SetQuality(60);
90 static int index = 0;
91 std::string filePath = "C:\\temp\\sliceReader_P";
92 filePath += boost::lexical_cast<std::string>(projection_);
93 filePath += "_I";
94 filePath += boost::lexical_cast<std::string>(index);
95 filePath += ".jpg";
96 index++;
97 writer.WriteToFile(filePath, reader.GetAccessor());
98 #endif
99 // <END-OF-DEBUG-BLOCK>
100 } 84 }
101 85
102 const CoordinateSystem3D& system = volume_.GetGeometry().GetProjectionGeometry(projection_); 86 const CoordinateSystem3D& system = volume_.GetGeometry().GetProjectionGeometry(projection_);
103 87
104 double x0, y0, x1, y1; 88 double x0, y0, x1, y1;
105 cuttingPlane.ProjectPoint(x0, y0, system.GetOrigin()); 89 cuttingPlane.ProjectPoint(x0, y0, system.GetOrigin());
106 cuttingPlane.ProjectPoint(x1, y1, system.GetOrigin() + system.GetAxisX()); 90 cuttingPlane.ProjectPoint(x1, y1, system.GetOrigin() + system.GetAxisX());
107 91
108 // <DEBUG-BLOCK>
109 #if 0
110 { 92 {
111 LOG(ERROR) << "+----------------------------------------------------+"; 93 double xz, yz;
112 LOG(ERROR) << "| DicomVolumeImageMPRSlicer::Slice::CreateSceneLayer |"; 94 cuttingPlane.ProjectPoint(xz, yz, LinearAlgebra::CreateVector(0, 0, 0));
113 LOG(ERROR) << "+----------------------------------------------------+"; 95 texture->SetOrigin(x0 - xz, y0 - yz);
114 std::string projectionString;
115 switch (projection_)
116 {
117 case VolumeProjection_Coronal:
118 projectionString = "CORONAL";
119 break;
120 case VolumeProjection_Axial:
121 projectionString = "CORONAL";
122 break;
123 case VolumeProjection_Sagittal:
124 projectionString = "SAGITTAL";
125 break;
126 default:
127 ORTHANC_ASSERT(false);
128 }
129 if(volume_.GetGeometry().GetDepth() == 200)
130 LOG(ERROR) << "| CT IMAGE 512x512 with projection " << projectionString;
131 else
132 LOG(ERROR) << "| RTDOSE IMAGE NNNxNNN with projection " << projectionString;
133 LOG(ERROR) << "+----------------------------------------------------+";
134 LOG(ERROR) << "| cuttingPlane = " << cuttingPlane;
135 LOG(ERROR) << "| point to project = " << system.GetOrigin();
136 LOG(ERROR) << "| result = x0: " << x0 << " y0: " << y0;
137 LOG(ERROR) << "+----------------------- END ------------------------+";
138 } 96 }
139 #endif
140 // <END-OF-DEBUG-BLOCK>
141
142 #if 1 // BGO 2019-08-13
143 // The sagittal coordinate system has a Y vector going down. The displayed
144 // image (scene coords) has a Y vector pointing upwards (towards the patient
145 // coord Z index)
146 // we need to flip the Y local coordinates to get the scene-coord offset.
147 // TODO: this is quite ugly. Isn't there a better way?
148 if(projection_ == VolumeProjection_Sagittal)
149 texture->SetOrigin(x0, -y0);
150 else
151 texture->SetOrigin(x0, y0);
152 #else
153 texture->SetOrigin(x0, y0);
154 #endif
155 97
156 double dx = x1 - x0; 98 double dx = x1 - x0;
157 double dy = y1 - y0; 99 double dy = y1 - y0;
158 if (!LinearAlgebra::IsCloseToZero(dx) || 100 if (!LinearAlgebra::IsCloseToZero(dx) ||
159 !LinearAlgebra::IsCloseToZero(dy)) 101 !LinearAlgebra::IsCloseToZero(dy))
161 texture->SetAngle(atan2(dy, dx)); 103 texture->SetAngle(atan2(dy, dx));
162 } 104 }
163 105
164 Vector tmp = volume_.GetGeometry().GetVoxelDimensions(projection_); 106 Vector tmp = volume_.GetGeometry().GetVoxelDimensions(projection_);
165 texture->SetPixelSpacing(tmp[0], tmp[1]); 107 texture->SetPixelSpacing(tmp[0], tmp[1]);
166
167 // <DEBUG-BLOCK>
168 {
169 //using std::endl;
170 //std::stringstream ss;
171 //ss << "DicomVolumeImageMPRSlicer::Slice::CreateSceneLayer | cuttingPlane = " << cuttingPlane << " | projection_ = " << projection_ << endl;
172 //ss << "volume_.GetGeometry().GetProjectionGeometry(projection_) = " << system << endl;
173 //ss << "cuttingPlane.ProjectPoint(x0, y0, system.GetOrigin()); --> | x0 = " << x0 << " | y0 = " << y0 << "| x1 = " << x1 << " | y1 = " << y1 << endl;
174 //ss << "volume_.GetGeometry() = " << volume_.GetGeometry() << endl;
175 //ss << "volume_.GetGeometry() = " << volume_.GetGeometry() << endl;
176 //LOG(ERROR) << ss.str();
177 }
178 // <END-OF-DEBUG-BLOCK>
179 108
180 return texture.release(); 109 return texture.release();
181 } 110 }
182 111
183 112