Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
OpenGL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
C-Fu
OpenGL
Commits
f5ee8a97
Commit
f5ee8a97
authored
Jan 07, 2017
by
Anakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using QString now,
fileinfo works now
parent
8c2ca44f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
127 additions
and
99 deletions
+127
-99
QtMeshViewer/Header/FileInterface.h
QtMeshViewer/Header/FileInterface.h
+7
-6
QtMeshViewer/Header/GeometryEngine.h
QtMeshViewer/Header/GeometryEngine.h
+3
-2
QtMeshViewer/Header/MainWindow.h
QtMeshViewer/Header/MainWindow.h
+5
-1
QtMeshViewer/Header/MshFile.h
QtMeshViewer/Header/MshFile.h
+1
-1
QtMeshViewer/Header/OglViewerWidget.h
QtMeshViewer/Header/OglViewerWidget.h
+1
-1
QtMeshViewer/Header/tga.h
QtMeshViewer/Header/tga.h
+2
-2
QtMeshViewer/Source/GeometryEngine.cpp
QtMeshViewer/Source/GeometryEngine.cpp
+59
-61
QtMeshViewer/Source/MainWindow.cpp
QtMeshViewer/Source/MainWindow.cpp
+38
-8
QtMeshViewer/Source/MshFile.cpp
QtMeshViewer/Source/MshFile.cpp
+6
-14
QtMeshViewer/Source/OglViewerWidget.cpp
QtMeshViewer/Source/OglViewerWidget.cpp
+5
-3
No files found.
QtMeshViewer/Header/FileInterface.h
View file @
f5ee8a97
...
...
@@ -3,6 +3,7 @@
#include <QVector>
#include <QVector2D>
#include <QVector3D>
#include <QStringList>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QOpenGLFunctions>
...
...
@@ -41,16 +42,16 @@ class FileInterface : public QObject
Q_OBJECT
public:
explicit
FileInterface
(
const
char
*
path
,
QObject
*
parent
)
explicit
FileInterface
(
QString
path
,
QObject
*
parent
)
:
QObject
(
parent
)
,
m_models
(
new
QVector
<
Model
*>
)
,
m_textureNames
(
new
Q
Vector
<
std
::
string
>
)
,
m_textureNames
(
new
Q
StringList
)
{
//open file
m_file
.
open
(
path
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
m_file
.
open
(
path
.
toStdString
().
c_str
()
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
!
m_file
.
is_open
())
throw
std
::
invalid_argument
(
std
::
string
(
"ERROR: file not found: "
)
+=
path
);
throw
std
::
invalid_argument
(
std
::
string
(
"ERROR: file not found: "
)
+=
path
.
toStdString
()
);
MainWindow
*
tmp
=
dynamic_cast
<
MainWindow
*>
(
parent
->
parent
()
->
parent
());
if
(
tmp
!=
NULL
)
...
...
@@ -87,14 +88,14 @@ public:
protected:
QVector
<
Model
*>*
m_models
;
std
::
fstream
m_file
;
Q
Vector
<
std
::
string
>
*
m_textureNames
;
Q
StringList
*
m_textureNames
;
BoundingBox
m_sceneBbox
;
virtual
void
import
()
=
0
;
public:
virtual
QVector
<
Model
*>*
getModels
()
const
{
return
m_models
;
};
virtual
Q
Vector
<
std
::
string
>
*
getTextureNames
()
const
{
return
m_textureNames
;
};
virtual
Q
StringList
*
getTextureNames
()
const
{
return
m_textureNames
;
};
virtual
BoundingBox
getBoundingBox
()
const
{
return
m_sceneBbox
;
};
signals:
...
...
QtMeshViewer/Header/GeometryEngine.h
View file @
f5ee8a97
...
...
@@ -29,16 +29,17 @@ private:
QVector
<
DrawInformation
>
m_drawList
;
BoundingBox
m_boundings
;
void
loadTexture
(
const
char
*
filePath
,
const
char
*
fileName
);
void
loadTexture
(
QString
filePath
,
QString
fileName
);
void
clearData
();
public
slots
:
void
loadFile
(
const
char
*
filePath
);
void
loadFile
(
QString
filePath
);
void
drawGeometry
(
QOpenGLShaderProgram
*
program
);
signals:
void
requestResetView
();
void
sendMessage
(
QString
message
,
int
severity
);
void
requestUpdate
();
void
sendFileInfo
(
QString
name
,
QStringList
textures
,
int
vertices
,
int
triangle
);
};
QtMeshViewer/Header/MainWindow.h
View file @
f5ee8a97
#pragma once
#include <QtWidgets/QMainWindow>
#include <QByteArray>
#include <QStringList>
#include "ui_MainWindow.h"
class
MainWindow
:
public
QMainWindow
...
...
@@ -15,6 +17,7 @@ private:
Ui
::
MainWindowClass
*
ui
;
int
m_curSeverity
;
void
setupWidgets
();
QByteArray
m_fileInfo
;
private
slots
:
...
...
@@ -24,7 +27,8 @@ private slots:
public
slots
:
void
printMessage
(
QString
message
,
int
severity
);
void
setFileInfo
(
QString
name
,
QStringList
textures
,
int
vertices
,
int
triangle
);
signals:
void
loadFile
(
const
char
*
);
void
loadFile
(
QString
);
};
QtMeshViewer/Header/MshFile.h
View file @
f5ee8a97
...
...
@@ -20,7 +20,7 @@ enum ModelTyp {
class
MshFile
:
public
FileInterface
{
public:
explicit
MshFile
(
const
char
*
path
,
QObject
*
parent
=
Q_NULLPTR
);
explicit
MshFile
(
QString
path
,
QObject
*
parent
=
Q_NULLPTR
);
virtual
~
MshFile
();
private:
...
...
QtMeshViewer/Header/OglViewerWidget.h
View file @
f5ee8a97
...
...
@@ -22,7 +22,7 @@ public:
~
OglViewerWidget
();
signals:
void
loadFile
(
const
char
*
);
void
loadFile
(
QString
);
private:
struct
{
...
...
QtMeshViewer/Header/tga.h
View file @
f5ee8a97
...
...
@@ -5,14 +5,14 @@
#include <iostream>
QImage
loadTga
(
const
char
*
filePath
,
bool
&
success
)
QImage
loadTga
(
QString
filePath
,
bool
&
success
)
{
QImage
img
;
if
(
!
img
.
load
(
filePath
))
{
// open the file
std
::
fstream
fsPicture
(
filePath
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
std
::
fstream
fsPicture
(
filePath
.
toStdString
().
c_str
()
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
!
fsPicture
.
is_open
())
{
...
...
QtMeshViewer/Source/GeometryEngine.cpp
View file @
f5ee8a97
...
...
@@ -4,6 +4,7 @@
#include "..\Header\MainWindow.h"
#include "..\Header\tga.h"
#include <cmath>
#include <QRegExp>
/////////////////////////////////////////////////////////////////////////
...
...
@@ -25,7 +26,57 @@ GeometryEngine::~GeometryEngine()
/////////////////////////////////////////////////////////////////////////
// private functions
void
GeometryEngine
::
loadFile
(
const
char
*
filePath
)
void
GeometryEngine
::
loadTexture
(
QString
filePath
,
QString
fileName
)
{
bool
loadSuccess
(
false
);
QImage
img
;
if
(
fileName
.
isEmpty
())
{
loadSuccess
=
true
;
img
=
QImage
(
1
,
1
,
QImage
::
Format_RGB32
);
img
.
fill
(
Qt
::
red
);
}
else
img
=
loadTga
(
filePath
+
"/"
+
fileName
,
loadSuccess
);
if
(
!
loadSuccess
)
emit
sendMessage
(
"WARNING: texture not found or corrupted: "
+
QString
(
fileName
),
1
);
// Load image to OglTexture
QOpenGLTexture
*
new_texture
=
new
QOpenGLTexture
(
img
.
mirrored
());
// Set nearest filtering mode for texture minification
new_texture
->
setMinificationFilter
(
QOpenGLTexture
::
Nearest
);
// Set bilinear filtering mode for texture magnification
new_texture
->
setMagnificationFilter
(
QOpenGLTexture
::
Linear
);
// Wrap texture coordinates by repeating
// f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
new_texture
->
setWrapMode
(
QOpenGLTexture
::
Repeat
);
m_textures
.
push_back
(
new_texture
);
}
void
GeometryEngine
::
clearData
()
{
if
(
m_arrayBuf
.
isCreated
())
m_arrayBuf
.
destroy
();
if
(
m_indexBuf
.
isCreated
())
m_indexBuf
.
destroy
();
for
(
auto
it
:
m_textures
)
delete
it
;
m_textures
.
clear
();
m_drawList
.
clear
();
}
/////////////////////////////////////////////////////////////////////////
// public slots
void
GeometryEngine
::
loadFile
(
QString
filePath
)
{
// cleanup old stuff and recreate buffers
clearData
();
...
...
@@ -39,7 +90,7 @@ void GeometryEngine::loadFile(const char* filePath)
try
{
QVector
<
Model
*>*
models
;
Q
Vector
<
std
::
string
>
*
textureNames
;
Q
StringList
*
textureNames
;
QVector
<
VertexData
>
vertexData
;
QVector
<
GLuint
>
indexData
;
...
...
@@ -66,7 +117,7 @@ void GeometryEngine::loadFile(const char* filePath)
new_info
.
modelMatrix
.
rotate
(
modelIterator
->
quadRotation
);
// add offset to indices, no need to do it for the first one (maybe it's very big)
if
(
vertexOffset
!=
0
)
if
(
vertexOffset
!=
0
)
for
(
auto
&
it
:
segmentIterator
->
indices
)
it
+=
vertexOffset
;
...
...
@@ -89,21 +140,18 @@ void GeometryEngine::loadFile(const char* filePath)
m_indexBuf
.
bind
();
m_indexBuf
.
allocate
(
indexData
.
data
(),
indexData
.
size
()
*
sizeof
(
GLuint
));
// get textures path
std
::
string
path
=
filePath
;
while
(
path
.
back
()
!=
'/'
&&
path
.
back
()
!=
'\\'
)
path
.
pop_back
();
emit
sendMessage
(
"loading textures.."
,
0
);
// load the textures
for
(
auto
&
it
:
*
textureNames
)
loadTexture
(
path
.
c_str
(),
it
.
c_str
());
int
split
=
filePath
.
lastIndexOf
(
QRegExp
(
"/|
\\\\
"
));
for
(
auto
&
it
:
*
textureNames
)
loadTexture
(
filePath
.
left
(
split
),
it
);
loadTexture
(
""
,
""
);
emit
requestUpdate
();
emit
sendMessage
(
"done.."
,
0
);
emit
sendFileInfo
(
filePath
.
right
(
filePath
.
size
()
-
split
-
1
),
QStringList
(
*
textureNames
),
vertexData
.
size
(),
indexData
.
size
()
/
3
);
}
catch
(
std
::
invalid_argument
e
)
{
...
...
@@ -112,56 +160,6 @@ void GeometryEngine::loadFile(const char* filePath)
}
}
void
GeometryEngine
::
loadTexture
(
const
char
*
filePath
,
const
char
*
fileName
)
{
bool
loadSuccess
(
false
);
QImage
img
;
if
(
!
strcmp
(
fileName
,
""
))
{
loadSuccess
=
true
;
img
=
QImage
(
1
,
1
,
QImage
::
Format_RGB32
);
img
.
fill
(
Qt
::
red
);
}
else
img
=
loadTga
((
std
::
string
(
filePath
)
+
std
::
string
(
fileName
)).
c_str
(),
loadSuccess
);
if
(
!
loadSuccess
)
emit
sendMessage
(
"WARNING: texture not found or corrupted: "
+
QString
(
fileName
),
1
);
// Load image to OglTexture
QOpenGLTexture
*
new_texture
=
new
QOpenGLTexture
(
img
.
mirrored
());
// Set nearest filtering mode for texture minification
new_texture
->
setMinificationFilter
(
QOpenGLTexture
::
Nearest
);
// Set bilinear filtering mode for texture magnification
new_texture
->
setMagnificationFilter
(
QOpenGLTexture
::
Linear
);
// Wrap texture coordinates by repeating
// f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
new_texture
->
setWrapMode
(
QOpenGLTexture
::
Repeat
);
m_textures
.
push_back
(
new_texture
);
}
void
GeometryEngine
::
clearData
()
{
if
(
m_arrayBuf
.
isCreated
())
m_arrayBuf
.
destroy
();
if
(
m_indexBuf
.
isCreated
())
m_indexBuf
.
destroy
();
for
(
auto
it
:
m_textures
)
delete
it
;
m_textures
.
clear
();
m_drawList
.
clear
();
}
/////////////////////////////////////////////////////////////////////////
// public functions
void
GeometryEngine
::
drawGeometry
(
QOpenGLShaderProgram
*
program
)
{
if
(
!
m_arrayBuf
.
isCreated
()
||
!
m_indexBuf
.
isCreated
())
...
...
QtMeshViewer/Source/MainWindow.cpp
View file @
f5ee8a97
...
...
@@ -3,10 +3,11 @@
#include <QSurfaceFormat>
#include <QMessageBox>
#include <QFileDialog>
#include <QFile>
#include <QPalette>
#include <QAction>
#include <QSignalMapper>
#include <QFile>
#include <QSizePolicy>
#include "..\Header\FileInterface.h"
#define WINDOW_NAME "Mesh Viewer"
...
...
@@ -28,6 +29,8 @@ MainWindow::MainWindow(QWidget *parent)
setupWidgets
();
ui
->
statusBar
->
showMessage
(
"MeshViewer by Anakin"
,
0
);
m_fileInfo
+=
"Filename: -
\n
Materials: -
\n
Vertices: -
\n
Triangle: -
\n
<detail>No file is open"
;
}
MainWindow
::~
MainWindow
()
...
...
@@ -38,7 +41,8 @@ MainWindow::~MainWindow()
void
MainWindow
::
openFile
()
{
QString
fileName
=
QFileDialog
::
getOpenFileName
(
this
,
"Open File"
,
""
,
"Mesh (*.msh)"
);
emit
loadFile
(
fileName
.
toStdString
().
c_str
());
if
(
!
fileName
.
isEmpty
())
emit
loadFile
(
fileName
);
}
void
MainWindow
::
setupWidgets
()
...
...
@@ -91,14 +95,17 @@ void MainWindow::setupWidgets()
void
MainWindow
::
aboutFile
()
{
QMessageBox
*
dialog
=
new
QMessageBox
(
QMessageBox
::
Informati
on
,
QMessageBox
*
dialog
=
new
QMessageBox
(
QMessageBox
::
NoIc
on
,
WINDOW_NAME
,
"When i find some time, i'll add some information about
\n
the file in the detailed text"
,
QString
(
m_fileInfo
.
left
(
m_fileInfo
.
indexOf
(
"<detail>"
)))
,
QMessageBox
::
StandardButton
::
Close
,
this
,
Qt
::
Dialog
|
Qt
::
MSWindowsFixedSizeDialogHint
);
dialog
->
setDetailedText
(
"This is the cool detailed text
\n
"
);
dialog
->
setStyleSheet
(
"QLabel{min-width: 200px;}"
);
dialog
->
setDetailedText
(
QString
(
m_fileInfo
.
right
(
m_fileInfo
.
size
()
-
m_fileInfo
.
indexOf
(
"<detail>"
)
-
8
)));
dialog
->
exec
();
delete
dialog
;
}
void
MainWindow
::
aboutTool
()
...
...
@@ -111,13 +118,36 @@ void MainWindow::aboutTool()
QString
(
file
.
readAll
()),
QMessageBox
::
StandardButton
::
Close
,
this
,
Qt
::
Dialog
|
Qt
::
MSWindowsFixedSizeDialogHint
);
Qt
::
Dialog
|
Qt
::
MSWindowsFixedSizeDialogHint
);
//dialog->setDetailedText(QString(file.readAll()));
file
.
close
();
dialog
->
exec
();
delete
dialog
;
}
void
MainWindow
::
setFileInfo
(
QString
name
,
QStringList
textures
,
int
vertices
,
int
triangle
)
{
m_fileInfo
=
QByteArray
(
"Filename: "
);
m_fileInfo
+=
name
;
m_fileInfo
+=
"
\n
Materials: "
;
m_fileInfo
+=
QByteArray
::
number
(
textures
.
size
());
m_fileInfo
+=
"
\n
Vertices: "
;
m_fileInfo
+=
QByteArray
::
number
(
vertices
);
m_fileInfo
+=
"
\n
Triangle: "
;
m_fileInfo
+=
QByteArray
::
number
(
triangle
);
m_fileInfo
+=
"<detail>"
;
int
count
(
0
);
for
(
auto
&
it
:
textures
)
{
m_fileInfo
+=
"Material "
;
m_fileInfo
+=
QByteArray
::
number
(
count
++
);
m_fileInfo
+=
" - "
;
m_fileInfo
+=
it
;
m_fileInfo
+=
"
\n
"
;
}
}
void
MainWindow
::
printMessage
(
QString
message
,
int
severity
)
...
...
QtMeshViewer/Source/MshFile.cpp
View file @
f5ee8a97
...
...
@@ -8,7 +8,7 @@
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
MshFile
::
MshFile
(
const
char
*
path
,
QObject
*
parent
)
MshFile
::
MshFile
(
QString
path
,
QObject
*
parent
)
:
FileInterface
(
path
,
parent
)
{
import
();
...
...
@@ -497,21 +497,13 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
// search if it is already known
bool
tmp_found
(
false
);
for
(
unsigned
int
i
=
0
;
i
<
m_textureNames
->
size
();
i
++
)
{
if
(
!
strcmp
(
buffer
,
m_textureNames
->
at
(
i
).
c_str
()))
{
// if found, save the index and stop searching
new_segment
->
textureIndex
=
i
;
tmp_found
=
true
;
break
;
}
}
// if it was not found add the texturename to the list
if
(
!
tmp_found
)
int
index
=
m_textureNames
->
indexOf
(
QString
::
fromStdString
(
buffer
));
if
(
index
!=
-
1
)
new_segment
->
textureIndex
=
index
;
else
{
m_textureNames
->
push_back
(
std
::
s
tring
(
buffer
));
m_textureNames
->
push_back
(
QString
::
fromStdS
tring
(
buffer
));
new_segment
->
textureIndex
=
m_textureNames
->
size
()
-
1
;
}
...
...
QtMeshViewer/Source/OglViewerWidget.cpp
View file @
f5ee8a97
...
...
@@ -135,7 +135,7 @@ void OglViewerWidget::dragEnterEvent(QDragEnterEvent *e)
void
OglViewerWidget
::
dropEvent
(
QDropEvent
*
e
)
{
emit
loadFile
(
e
->
mimeData
()
->
urls
().
first
().
toLocalFile
()
.
toStdString
().
c_str
()
);
emit
loadFile
(
e
->
mimeData
()
->
urls
().
first
().
toLocalFile
());
}
void
OglViewerWidget
::
keyPressEvent
(
QKeyEvent
*
e
)
...
...
@@ -226,10 +226,12 @@ void OglViewerWidget::initShaders()
void
OglViewerWidget
::
setConnections
()
{
connect
(
m_dataEngine
,
&
GeometryEngine
::
requestResetView
,
this
,
&
OglViewerWidget
::
resetView
);
connect
(
parentWidget
(),
SIGNAL
(
loadFile
(
const
char
*
)),
m_dataEngine
,
SLOT
(
loadFile
(
const
char
*
)));
connect
(
this
,
SIGNAL
(
loadFile
(
const
char
*
)),
m_dataEngine
,
SLOT
(
loadFile
(
const
char
*
)));
connect
(
parentWidget
(),
SIGNAL
(
loadFile
(
QString
)),
m_dataEngine
,
SLOT
(
loadFile
(
QString
)));
connect
(
this
,
SIGNAL
(
loadFile
(
QString
)),
m_dataEngine
,
SLOT
(
loadFile
(
QString
)));
connect
(
m_dataEngine
,
SIGNAL
(
sendMessage
(
QString
,
int
)),
parentWidget
(),
SLOT
(
printMessage
(
QString
,
int
)));
connect
(
m_dataEngine
,
SIGNAL
(
requestUpdate
()),
this
,
SLOT
(
update
()));
connect
(
m_dataEngine
,
SIGNAL
(
sendFileInfo
(
QString
,
QStringList
,
int
,
int
)),
parentWidget
(),
SLOT
(
setFileInfo
(
QString
,
QStringList
,
int
,
int
)));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment