-
Notifications
You must be signed in to change notification settings - Fork 10
/
GLModelWidget.h
158 lines (120 loc) · 4.99 KB
/
GLModelWidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef __GL_MODEL_WIDGET_H__
#define __GL_MODEL_WIDGET_H__
#include <vector>
#include <QGLWidget>
#include <QSettings>
#include "Tools.h"
#include "Global.h"
#include "GLCamera.h"
#include "UndoManager.h"
#include "VoxelGridGroup.h"
#include <ImathBox.h>
#include <ImathVec.h>
#include <ImathColor.h>
class GLModelWidget : public QGLWidget
{
Q_OBJECT
public:
enum CubeFaceMask { FACE_POSY = 0x01, FACE_NEGY = 0x02,
FACE_POSX = 0x04, FACE_NEGX = 0x08,
FACE_POSZ = 0x10, FACE_NEGZ = 0x20,
FACE_NONE = 0x00, FACE_ALL = 0x3f };
public:
GLModelWidget(QWidget* parent, QSettings* appSettings, UndoManager *undoManager, VoxelGridGroupPtr sprite);
~GLModelWidget();
QSize minimumSizeHint() const;
QSize sizeHint() const;
VoxelGridGroupPtr getSprite() const { return m_gvg; }
void saveSettings();
public:
void frame(bool fullExtents);
void handleArrows(QKeyEvent *event);
void resizeAndClearVoxelGrid(const Imath::V3i& size);
void resizeAndShiftVoxelGrid(const Imath::V3i& size, const Imath::V3i& shift);
void reresVoxelGrid(const float scale);
void shiftVoxels(const SproxelAxis axis, const bool up, const bool wrap);
void mirrorVoxels(const SproxelAxis axis);
void rotateVoxels(const SproxelAxis axis, const int dir);
void setVoxelColor(const Imath::V3i& index, const Imath::Color4f color, int ind);
// Accessors
const Imath::V3i& activeVoxel() const { return m_activeVoxel; }
const Imath::Color4f& activeColor() const { return m_activeColor; }
int activeIndex() const { return m_activeIndex; }
bool drawGrid() const { return m_drawGrid; }
bool drawVoxelGrid() const { return m_drawVoxelGrid; }
bool drawBoundingBox() const { return m_drawBoundingBox; }
bool drawSpriteBounds() const { return m_drawSpriteBounds; }
bool shiftWrap() const { return m_shiftWrap; }
SproxelAxis currentAxis() const { return m_currAxis; }
signals:
void colorSampled(const Imath::Color4f& color, int index);
void sliceChanged(int min_ofs, int max_ofs, int range);
public slots:
void setSprite(VoxelGridGroupPtr sprite);
void setActiveTool(const SproxelTool tool);
void setDrawGrid(const bool value) { m_drawGrid = value; updateGL(); }
void setDrawVoxelGrid(const bool value) { m_drawVoxelGrid = value; updateGL(); }
void setDrawBoundingBox(const bool value) { m_drawBoundingBox = value; updateGL(); }
void setDrawSpriteBounds(const bool value) { m_drawSpriteBounds = value; updateGL(); }
void setShiftWrap(const bool value) { m_shiftWrap = value; }
void setCurrentAxis(const SproxelAxis val);
void setAxisX() { setCurrentAxis(X_AXIS); }
void setAxisY() { setCurrentAxis(Y_AXIS); }
void setAxisZ() { setCurrentAxis(Z_AXIS); }
void setActiveColor(const Imath::Color4f& c, int i) { m_activeColor = c; m_activeIndex=i; }
void setLightColor(const Imath::Color4f& c) { m_lightColor = c; update(); }
void onSpriteChanged(VoxelGridGroupPtr spr) { if (spr==m_gvg) update(); }
void onPaletteChanged(ColorPalettePtr pal) { if (m_gvg && m_gvg->hasPalette(pal)) update(); }
void frameFull() { frame(true); }
void frameData() { frame(false); }
void setMinSlice(int);
void setMaxSlice(int);
protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
private:
GLCamera m_cam;
double m_cameraSnapStep;
Imath::V2d m_cameraSnapDelta;
VoxelGridGroupPtr m_gvg;
std::vector<Imath::V3i> m_previews;
UndoManager *p_undoManager;
Imath::V3i m_activeVoxel;
Imath::Color4f m_activeColor;
int m_activeIndex;
Imath::Color4f m_lightColor;
QPoint m_lastMouse;
bool m_drawGrid;
bool m_drawVoxelGrid;
bool m_drawBoundingBox;
bool m_drawSpriteBounds;
bool m_shiftWrap;
SproxelAxis m_currAxis;
ToolState* m_activeTool;
Imath::V3i m_minBoundOffset, m_maxBoundOffset;
Imath::Box3i editBounds();
double* glMatrix(const Imath::M44d& m);
void objWritePoly(FILE* fp, bool asTriangles,
const int& v0, const int& v1, const int& v2, const int& v3);
Imath::Box3d dataBounds();
void centerGrid();
CubeFaceMask computeVoxelFaceMask(const Imath::V3i& index, const Imath::Box3i &bounds);
void glDrawAxes();
void glDrawGrid(const int size,
const int gridCellSize,
const Imath::Color4f& gridColor,
const Imath::Color4f& bgColor);
void glDrawCubeWire();
void glDrawCubePoly(const CubeFaceMask mask, bool smooth);
void glDrawVoxelGrid();
void glDrawActiveVoxel();
void glDrawPreviewVoxels();
void glDrawVoxelCenter(const size_t sx, const size_t sy, const size_t sz);
void glDrawBounds(const Imath::Box3i &bounds, QColor color);
QSettings* p_appSettings;
};
#endif