53 return !(*
this == other);
78 m_Value += other.m_Value;
84 m_Value -= other.m_Value;
102 Voxel voxNew = *
this;
109 Voxel voxNew = *
this;
116 Voxel voxNew = *
this;
123 Voxel voxNew = *
this;
134 : m_Width(1), m_Height(1), m_Depth(1), m_Size(0), m_Voxels(1)
144 return m_Voxels[x + y*m_Width + z*m_Width*m_Height];
154 return &(m_Voxels.front());
186 fopen_s(&fp, filename.toStdString().c_str(),
"rb");
189 std::cerr <<
"+ Error loading file: " << filename.toStdString() << std::endl;
195 progressBar->setRange(0, m_Size + 10);
196 progressBar->setValue(0);
201 unsigned short uWidth, uHeight, uDepth;
202 fread(&uWidth,
sizeof(
unsigned short), 1, fp);
203 fread(&uHeight,
sizeof(
unsigned short), 1, fp);
204 fread(&uDepth,
sizeof(
unsigned short), 1, fp);
206 m_Width = int(uWidth);
207 m_Height = int(uHeight);
208 m_Depth = int(uDepth);
212 m_Width <= 0 || m_Width > 1000 ||
213 m_Height <= 0 || m_Height > 1000 ||
214 m_Depth <= 0 || m_Depth > 1000)
216 std::cerr <<
"+ Error loading file: " << filename.toStdString() << std::endl;
217 std::cerr <<
"Unvalid dimensions - probably loaded .dat flow file instead of .gri file?" << std::endl;
222 int slice = m_Width * m_Height;
223 m_Size = slice * m_Depth;
224 m_Voxels.resize(m_Size);
230 std::vector<unsigned short> vecData;
231 vecData.resize(m_Size);
232 fread((
void*)&(vecData.front()),
sizeof(
unsigned short), m_Size, fp);
235 progressBar->setValue(10);
240 for (
int i = 0; i < m_Size; i++)
245 const float value = std::fmin(1.0f,
float(vecData[i]) / 4095.0f);
246 m_Voxels[i] =
Voxel(value);
247 progressBar->setValue(10 + i);
250 progressBar->setValue(0);
252 std::cout <<
"Loaded VOLUME with dimensions " << m_Width <<
" x " << m_Height <<
" x " << m_Depth << std::endl;
258 auto tex =
new QOpenGLTexture(QOpenGLTexture::Target3D);
259 if (!tex->create()) {
260 std::cout <<
"Unable to create texture object" << std::endl;
264 std::vector<float> rawData;
265 for (
const auto& vox : m_Voxels) {
266 rawData.push_back(vox.getValue());
269 tex->setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::ClampToBorder);
270 tex->setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::ClampToBorder);
271 tex->setWrapMode(QOpenGLTexture::DirectionR, QOpenGLTexture::ClampToBorder);
273 tex->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
274 tex->setMagnificationFilter(QOpenGLTexture::Nearest);
276 tex->setFormat(QOpenGLTexture::R32F);
277 tex->setSize(m_Width, m_Height, m_Depth);
279 tex->allocateStorage(QOpenGLTexture::Red, QOpenGLTexture::Float32);
280 if (tex->isStorageAllocated()) {
281 tex->setData(0, QOpenGLTexture::Red, QOpenGLTexture::Float32, rawData.data());
const bool operator>=(const Voxel &other) const
const Voxel & operator*=(const float &value)
const Voxel & voxel(const int i) const
const Voxel operator+(const Voxel &other) const
const bool operator<(const Voxel &other) const
const Voxel operator*(const float &value) const
const bool operator<=(const Voxel &other) const
void setValue(const float value)
QOpenGLTexture * generate3DTex()
generate3DTex transforms the loaded volume data set into a 3D texture which can be sampled in the gls...
const Voxel & operator+=(const Voxel &other)
const Voxel operator/(const float &value) const
const Voxel & operator-=(const Voxel &other)
const Voxel * voxels() const
const bool operator!=(const Voxel &other) const
const Voxel operator-(const Voxel &other) const
Helper class for Voxels with basic operators.
const float getValue() const
bool loadFromFile(QString filename, QProgressBar *progressBar)
const bool operator==(const Voxel &other) const
const bool operator>(const Voxel &other) const
const Voxel & operator/=(const float &value)