v2.0.0
Loading...
Searching...
No Matches
sliceobject.cpp
Go to the documentation of this file.
1//=============================================================================================================
12
13//=============================================================================================================
14// INCLUDES
15//=============================================================================================================
16
17#include "sliceobject.h"
18
19//=============================================================================================================
20// USED NAMESPACES
21//=============================================================================================================
22
23using namespace DISP3DLIB;
24
25//=============================================================================================================
26// DEFINE MEMBER METHODS
27//=============================================================================================================
28
30 : m_corner00(Eigen::Vector3d::Zero())
31 , m_corner10(Eigen::Vector3d::UnitX())
32 , m_corner01(Eigen::Vector3d::UnitY())
33 , m_corner11(Eigen::Vector3d::UnitX() + Eigen::Vector3d::UnitY())
34{
35}
36
37//=============================================================================================================
38
39void SliceObject::setSlice(const QImage& image,
41 int sliceIndex,
42 const Eigen::Matrix4d& voxelToWorld)
43{
44 m_image = image;
45 m_orientation = orientation;
46 m_sliceIndex = sliceIndex;
47 m_voxelToWorld = voxelToWorld;
48
49 // Image dimensions define the number of voxels along each in-plane axis.
50 const int w = m_image.width();
51 const int h = m_image.height();
52
53 // Build the four corner positions in voxel coordinates, then transform to world.
54 // u runs along image columns, v along image rows.
55 Eigen::Vector4d c00, c10, c01, c11;
56
57 switch (m_orientation) {
59 // u → X, v → Y, slice along Z
60 c00 << 0, 0, sliceIndex, 1;
61 c10 << w, 0, sliceIndex, 1;
62 c01 << 0, h, sliceIndex, 1;
63 c11 << w, h, sliceIndex, 1;
64 break;
66 // u → X, v → Z, slice along Y
67 c00 << 0, sliceIndex, 0, 1;
68 c10 << w, sliceIndex, 0, 1;
69 c01 << 0, sliceIndex, h, 1;
70 c11 << w, sliceIndex, h, 1;
71 break;
73 // u → Y, v → Z, slice along X
74 c00 << sliceIndex, 0, 0, 1;
75 c10 << sliceIndex, w, 0, 1;
76 c01 << sliceIndex, 0, h, 1;
77 c11 << sliceIndex, w, h, 1;
78 break;
79 }
80
81 // Transform voxel → world (RAS)
82 Eigen::Vector4d w00 = m_voxelToWorld * c00;
83 Eigen::Vector4d w10 = m_voxelToWorld * c10;
84 Eigen::Vector4d w01 = m_voxelToWorld * c01;
85 Eigen::Vector4d w11 = m_voxelToWorld * c11;
86
87 m_corner00 = w00.head<3>();
88 m_corner10 = w10.head<3>();
89 m_corner01 = w01.head<3>();
90 m_corner11 = w11.head<3>();
91}
92
93//=============================================================================================================
94
97 int sliceIndex,
98 const Eigen::Matrix4d& imageToWorld)
99{
100 m_image = image;
101 m_orientation = orientation;
102 m_sliceIndex = sliceIndex;
103
104 const int w = m_image.width();
105 const int h = m_image.height();
106
107 const Eigen::Vector4d c00(0.0, 0.0, 0.0, 1.0);
108 const Eigen::Vector4d c10(static_cast<double>(w), 0.0, 0.0, 1.0);
109 const Eigen::Vector4d c01(0.0, static_cast<double>(h), 0.0, 1.0);
110 const Eigen::Vector4d c11(static_cast<double>(w), static_cast<double>(h), 0.0, 1.0);
111
112 m_corner00 = (imageToWorld * c00).head<3>();
113 m_corner10 = (imageToWorld * c10).head<3>();
114 m_corner01 = (imageToWorld * c01).head<3>();
115 m_corner11 = (imageToWorld * c11).head<3>();
116}
117
118//=============================================================================================================
119
121{
122 return m_orientation;
123}
124
125//=============================================================================================================
126
128{
129 return m_sliceIndex;
130}
131
132//=============================================================================================================
133
134const QImage& SliceObject::image() const
135{
136 return m_image;
137}
138
139//=============================================================================================================
140
142{
143 // Build a 4×4 matrix that maps the unit quad [0,1]² to the world-space quad.
144 // Column 0: edge along u (corner10 – corner00)
145 // Column 1: edge along v (corner01 – corner00)
146 // Column 3: translation (corner00)
147 Eigen::Vector3d u = m_corner10 - m_corner00;
148 Eigen::Vector3d v = m_corner01 - m_corner00;
149 Eigen::Vector3d n = u.cross(v).normalized();
150
151 QMatrix4x4 mat;
152 mat.setToIdentity();
153 mat(0, 0) = static_cast<float>(u.x());
154 mat(1, 0) = static_cast<float>(u.y());
155 mat(2, 0) = static_cast<float>(u.z());
156
157 mat(0, 1) = static_cast<float>(v.x());
158 mat(1, 1) = static_cast<float>(v.y());
159 mat(2, 1) = static_cast<float>(v.z());
160
161 mat(0, 2) = static_cast<float>(n.x());
162 mat(1, 2) = static_cast<float>(n.y());
163 mat(2, 2) = static_cast<float>(n.z());
164
165 mat(0, 3) = static_cast<float>(m_corner00.x());
166 mat(1, 3) = static_cast<float>(m_corner00.y());
167 mat(2, 3) = static_cast<float>(m_corner00.z());
168
169 return mat;
170}
171
172//=============================================================================================================
173
174void SliceObject::setWindowLevel(float center, float width)
175{
176 m_windowCenter = center;
177 m_windowWidth = width;
178}
179
180//=============================================================================================================
181
183{
184 return m_windowCenter;
185}
186
187//=============================================================================================================
188
190{
191 return m_windowWidth;
192}
193
194//=============================================================================================================
195
197{
198 m_opacity = opacity;
199}
200
201//=============================================================================================================
202
204{
205 return m_opacity;
206}
207
208//=============================================================================================================
209
210void SliceObject::generateQuadVertices(QVector<float>& vertices) const
211{
212 // 4 vertices: pos(3) + uv(2) = 5 floats each → 20 floats total
213 vertices.resize(20);
214 float* p = vertices.data();
215
216 // Vertex 0: corner00, uv(0,0)
217 *p++ = static_cast<float>(m_corner00.x());
218 *p++ = static_cast<float>(m_corner00.y());
219 *p++ = static_cast<float>(m_corner00.z());
220 *p++ = 0.0f; *p++ = 0.0f;
221
222 // Vertex 1: corner10, uv(1,0)
223 *p++ = static_cast<float>(m_corner10.x());
224 *p++ = static_cast<float>(m_corner10.y());
225 *p++ = static_cast<float>(m_corner10.z());
226 *p++ = 1.0f; *p++ = 0.0f;
227
228 // Vertex 2: corner01, uv(0,1)
229 *p++ = static_cast<float>(m_corner01.x());
230 *p++ = static_cast<float>(m_corner01.y());
231 *p++ = static_cast<float>(m_corner01.z());
232 *p++ = 0.0f; *p++ = 1.0f;
233
234 // Vertex 3: corner11, uv(1,1)
235 *p++ = static_cast<float>(m_corner11.x());
236 *p++ = static_cast<float>(m_corner11.y());
237 *p++ = static_cast<float>(m_corner11.z());
238 *p++ = 1.0f; *p++ = 1.0f;
239}
240
241//=============================================================================================================
242
243void SliceObject::generateQuadIndices(QVector<unsigned int>& indices)
244{
245 // Two triangles: (0,1,2) and (2,1,3)
246 indices = { 0, 1, 2, 2, 1, 3 };
247}
Single MRI volume slice rendered as a textured quad with adjustable axis, position,...
3-D brain visualisation using the Qt RHI rendering backend.
SliceOrientation
Orientation for an orthogonal MRI slice.
Definition sliceobject.h:60
float windowCenter() const
const QImage & image() const
void setWindowLevel(float center, float width)
static void generateQuadIndices(QVector< unsigned int > &indices)
float windowWidth() const
QMatrix4x4 sliceToWorld() const
void setSlice(const QImage &image, SliceOrientation orientation, int sliceIndex, const Eigen::Matrix4d &voxelToWorld)
void setSliceToWorld(const QImage &image, SliceOrientation orientation, int sliceIndex, const Eigen::Matrix4d &imageToWorld)
void generateQuadVertices(QVector< float > &vertices) const
SliceOrientation orientation() const
void setOpacity(float opacity)