Merge branch 'master' of https://github.com/worklist/hifi into shifty

This commit is contained in:
Andrzej Kapolka 2013-09-03 11:00:29 -07:00
commit 7c3bb4ecc4
12 changed files with 188 additions and 149 deletions

View file

@ -82,7 +82,6 @@ const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;
// Startup optimistically with small jitter buffer that // Startup optimistically with small jitter buffer that
// will start playback on the second received audio packet. // will start playback on the second received audio packet.
static const float CLIPBOARD_TREE_SCALE = 1.0f;
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
fprintf(stdout, "%s", message.toLocal8Bit().constData()); fprintf(stdout, "%s", message.toLocal8Bit().constData());
@ -97,7 +96,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_frameCount(0), _frameCount(0),
_fps(120.0f), _fps(120.0f),
_justStarted(true), _justStarted(true),
_clipboard(CLIPBOARD_TREE_SCALE),
_voxelImporter(_window), _voxelImporter(_window),
_wantToKillLocalVoxels(false), _wantToKillLocalVoxels(false),
_audioScope(256, 200, true), _audioScope(256, 200, true),
@ -237,6 +235,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
Application::~Application() { Application::~Application() {
NodeList::getInstance()->removeHook(&_voxels); NodeList::getInstance()->removeHook(&_voxels);
NodeList::getInstance()->removeHook(this); NodeList::getInstance()->removeHook(this);
_sharedVoxelSystem.changeTree(new VoxelTree);
} }
void Application::initializeGL() { void Application::initializeGL() {
@ -1207,15 +1207,6 @@ void Application::exportVoxels() {
void Application::importVoxels() { void Application::importVoxels() {
if (_voxelImporter.exec()) { if (_voxelImporter.exec()) {
qDebug("[DEBUG] Import succedded.\n"); qDebug("[DEBUG] Import succedded.\n");
if (_voxelImporter.getImportIntoClipboard()) {
_clipboard.killLocalVoxels();
_voxelImporter.getVoxelSystem()->copySubTreeIntoNewTree(
_voxelImporter.getVoxelSystem()->getVoxelAt(0, 0, 0, 1),
&_clipboard,
true);
_voxelImporter.reset();
}
} else { } else {
qDebug("[DEBUG] Import failed.\n"); qDebug("[DEBUG] Import failed.\n");
} }
@ -1230,13 +1221,17 @@ void Application::cutVoxels() {
} }
void Application::copyVoxels() { void Application::copyVoxels() {
// switch to and clear the clipboard first...
_sharedVoxelSystem.killLocalVoxels();
if (_sharedVoxelSystem.getTree() != &_clipboard) {
_clipboard.eraseAllVoxels();
_sharedVoxelSystem.changeTree(&_clipboard);
}
// then copy onto it if there is something to copy
VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
if (selectedNode) { if (selectedNode) {
// clear the clipboard first... _voxels.copySubTreeIntoNewTree(selectedNode, &_sharedVoxelSystem, true);
_clipboard.killLocalVoxels();
// then copy onto it
_voxels.copySubTreeIntoNewTree(selectedNode, &_clipboard, true);
} }
} }
@ -1257,12 +1252,13 @@ void Application::pasteVoxels() {
args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
} }
if (_voxelImporter.getImportWaiting()) { _sharedVoxelSystem.getTree()->recurseTreeWithOperation(sendVoxelsOperation, &args);
_voxelImporter.getVoxelSystem()->recurseTreeWithOperation(sendVoxelsOperation, &args);
_voxelImporter.reset(); if (_sharedVoxelSystem.getTree() != &_clipboard) {
} else { _sharedVoxelSystem.killLocalVoxels();
_clipboard.recurseTreeWithOperation(sendVoxelsOperation, &args); _sharedVoxelSystem.changeTree(&_clipboard);
} }
_voxelEditSender.flushQueue(); _voxelEditSender.flushQueue();
if (calculatedOctCode) { if (calculatedOctCode) {
@ -1304,10 +1300,21 @@ void Application::initDisplay() {
void Application::init() { void Application::init() {
_voxels.init(); _voxels.init();
_clipboard.init(); _sharedVoxelSystemViewFrustum.setPosition(glm::vec3(TREE_SCALE / 2.0f,
_clipboardViewFrustum.setKeyholeRadius(1000.0f); TREE_SCALE / 2.0f,
_clipboardViewFrustum.calculate(); 3.0f * TREE_SCALE / 2.0f));
_clipboard.setViewFrustum(&_clipboardViewFrustum); _sharedVoxelSystemViewFrustum.setNearClip(TREE_SCALE / 2.0f);
_sharedVoxelSystemViewFrustum.setFarClip(3.0f * TREE_SCALE / 2.0f);
_sharedVoxelSystemViewFrustum.setFieldOfView(90);
_sharedVoxelSystemViewFrustum.setOrientation(glm::quat());
_sharedVoxelSystemViewFrustum.calculate();
_sharedVoxelSystem.setViewFrustum(&_sharedVoxelSystemViewFrustum);
_sharedVoxelSystem.init();
VoxelTree* tmpTree = _sharedVoxelSystem.getTree();
_sharedVoxelSystem.changeTree(&_clipboard);
delete tmpTree;
_voxelImporter.init();
_environment.init(); _environment.init();
@ -1318,6 +1325,7 @@ void Application::init() {
_headMouseX = _mouseX = _glWidget->width() / 2; _headMouseX = _mouseX = _glWidget->width() / 2;
_headMouseY = _mouseY = _glWidget->height() / 2; _headMouseY = _mouseY = _glWidget->height() / 2;
QCursor::setPos(_headMouseX, _headMouseY);
_myAvatar.init(); _myAvatar.init();
_myAvatar.setPosition(START_LOCATION); _myAvatar.setPosition(START_LOCATION);
@ -1325,7 +1333,6 @@ void Application::init() {
_myCamera.setModeShiftRate(1.0f); _myCamera.setModeShiftRate(1.0f);
_myAvatar.setDisplayingLookatVectors(false); _myAvatar.setDisplayingLookatVectors(false);
QCursor::setPos(_headMouseX, _headMouseY);
OculusManager::connect(); OculusManager::connect();
if (OculusManager::isConnected()) { if (OculusManager::isConnected()) {
@ -2225,15 +2232,11 @@ void Application::displaySide(Camera& whichCamera) {
glTranslatef(_mouseVoxel.x * TREE_SCALE, glTranslatef(_mouseVoxel.x * TREE_SCALE,
_mouseVoxel.y * TREE_SCALE, _mouseVoxel.y * TREE_SCALE,
_mouseVoxel.z * TREE_SCALE); _mouseVoxel.z * TREE_SCALE);
glScalef(_mouseVoxel.s * TREE_SCALE, glScalef(_mouseVoxel.s,
_mouseVoxel.s * TREE_SCALE, _mouseVoxel.s,
_mouseVoxel.s * TREE_SCALE); _mouseVoxel.s);
if (_voxelImporter.getImportWaiting()) { _sharedVoxelSystem.render(true);
_voxelImporter.getVoxelSystem()->render(true);
} else {
_clipboard.render(true);
}
glPopMatrix(); glPopMatrix();
} }

View file

@ -112,6 +112,8 @@ public:
Camera* getCamera() { return &_myCamera; } Camera* getCamera() { return &_myCamera; }
ViewFrustum* getViewFrustum() { return &_viewFrustum; } ViewFrustum* getViewFrustum() { return &_viewFrustum; }
VoxelSystem* getVoxels() { return &_voxels; } VoxelSystem* getVoxels() { return &_voxels; }
VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; }
VoxelTree* getClipboard() { return &_clipboard; }
Environment* getEnvironment() { return &_environment; } Environment* getEnvironment() { return &_environment; }
SerialInterface* getSerialHeadSensor() { return &_serialHeadSensor; } SerialInterface* getSerialHeadSensor() { return &_serialHeadSensor; }
Webcam* getWebcam() { return &_webcam; } Webcam* getWebcam() { return &_webcam; }
@ -238,10 +240,11 @@ private:
Stars _stars; Stars _stars;
VoxelSystem _voxels; VoxelSystem _voxels;
VoxelSystem _clipboard; // if I copy/paste VoxelTree _clipboard; // if I copy/paste
ViewFrustum _clipboardViewFrustum;
VoxelImporter _voxelImporter; VoxelImporter _voxelImporter;
VoxelSystem _sharedVoxelSystem;
ViewFrustum _sharedVoxelSystemViewFrustum;
QByteArray _voxelsFilename; QByteArray _voxelsFilename;
bool _wantToKillLocalVoxels; bool _wantToKillLocalVoxels;

View file

@ -34,9 +34,9 @@ const float FIELD_OF_VIEW = 60.0f;
class GLWidget : public QGLWidget { class GLWidget : public QGLWidget {
public: public:
GLWidget(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL); GLWidget(QWidget* parent = NULL);
void setDraw(bool draw) {_draw = draw;} void setDraw(bool draw) {_draw = draw;}
void setTargetCenter(glm::vec3 targetCenter) {_targetCenter = targetCenter;} void setTargetCenter(glm::vec3 targetCenter) { _targetCenter = targetCenter; }
protected: protected:
virtual void initializeGL(); virtual void initializeGL();
@ -61,9 +61,8 @@ private:
int _mouseY; int _mouseY;
}; };
GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) GLWidget::GLWidget(QWidget *parent)
: QGLWidget(parent, Application::getInstance()->getGLWidget()), : QGLWidget(parent, Application::getInstance()->getGLWidget()),
_voxelSystem(voxelSystem),
_draw(false), _draw(false),
_a(0.0f), _a(0.0f),
_h(VERTICAL_ANGLE), _h(VERTICAL_ANGLE),
@ -71,6 +70,7 @@ GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem)
_pressed(false), _pressed(false),
_mouseX(0), _mouseX(0),
_mouseY(0) { _mouseY(0) {
_voxelSystem = Application::getInstance()->getSharedVoxelSystem();
} }
void GLWidget::initializeGL() { void GLWidget::initializeGL() {
@ -110,7 +110,7 @@ void GLWidget::paintGL() {
UP_VECT.x, UP_VECT.y, UP_VECT.z); UP_VECT.x, UP_VECT.y, UP_VECT.z);
if (_draw && _voxelSystem) { if (_draw) {
glBegin(GL_LINES); glBegin(GL_LINES);
glColor3d(1, 1 ,1); glColor3d(1, 1 ,1);
glVertex3d(0, 0, 0); glVertex3d(0, 0, 0);
@ -134,11 +134,11 @@ void GLWidget::paintGL() {
glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 0 ); glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 0 );
glEnd(); glEnd();
glScalef(1.0f / TREE_SCALE, 1.0f / TREE_SCALE, 1.0f / TREE_SCALE);
_voxelSystem->render(false); _voxelSystem->render(false);
} }
} }
void GLWidget::mousePressEvent(QMouseEvent* event) { void GLWidget::mousePressEvent(QMouseEvent* event) {
_pressed = true; _pressed = true;
_mouseX = event->globalX(); _mouseX = event->globalX();
@ -158,14 +158,13 @@ void GLWidget::mouseReleaseEvent(QMouseEvent* event) {
_pressed = false; _pressed = false;
} }
ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) ImportDialog::ImportDialog(QWidget *parent)
: QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES), : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES),
_importButton (IMPORT_BUTTON_NAME, this), _importButton (IMPORT_BUTTON_NAME, this),
_clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this), _clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this),
_previewBox (PREVIEW_CHECKBOX_STRING, this), _previewBox (PREVIEW_CHECKBOX_STRING, this),
_previewBar (this), _previewBar (this),
_glPreview (new GLWidget(this, voxelSystem)) { _glPreview (new GLWidget(this)) {
setOption(QFileDialog::DontUseNativeDialog, true); setOption(QFileDialog::DontUseNativeDialog, true);
setFileMode(QFileDialog::ExistingFile); setFileMode(QFileDialog::ExistingFile);
setViewMode(QFileDialog::Detail); setViewMode(QFileDialog::Detail);
@ -188,15 +187,18 @@ ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem)
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
connect(&_glTimer, SIGNAL(timeout()), SLOT(timer())); connect(&_glTimer, SIGNAL(timeout()), SLOT(timer()));
connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
} }
ImportDialog::~ImportDialog() { ImportDialog::~ImportDialog() {
delete _glPreview; delete _glPreview;
} }
void ImportDialog::init() {
VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem();
connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float,float,float)));
connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
}
void ImportDialog::import() { void ImportDialog::import() {
_importButton.setDisabled(true); _importButton.setDisabled(true);
_clipboardImportBox.setDisabled(true); _clipboardImportBox.setDisabled(true);

View file

@ -23,15 +23,16 @@ class GLWidget;
class ImportDialog : public QFileDialog { class ImportDialog : public QFileDialog {
Q_OBJECT Q_OBJECT
public: public:
ImportDialog(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL); ImportDialog(QWidget* parent = NULL);
~ImportDialog(); ~ImportDialog();
void init();
void reset();
bool getWantPreview() const { return _previewBox.isChecked(); } bool getWantPreview() const { return _previewBox.isChecked(); }
QString getCurrentFile() const { return _currentFile; } QString getCurrentFile() const { return _currentFile; }
bool getImportIntoClipboard() const { return _clipboardImportBox.isChecked(); } bool getImportIntoClipboard() const { return _clipboardImportBox.isChecked(); }
void reset();
signals: signals:
void previewToggled(bool); void previewToggled(bool);
void accepted(); void accepted();

View file

@ -125,9 +125,15 @@ void SerialInterface::initializePort(char* portname) {
tcflush(_serialDescriptor, TCIOFLUSH); tcflush(_serialDescriptor, TCIOFLUSH);
// this disables streaming so there's no garbage data on reads // this disables streaming so there's no garbage data on reads
write(_serialDescriptor, "SD\n", 3); if (write(_serialDescriptor, "SD\n", 3) != 3) {
qDebug("Failed.\n");
return;
}
char result[4]; char result[4];
read(_serialDescriptor, result, 4); if (read(_serialDescriptor, result, 4) != 4) {
qDebug("Failed.\n");
return;
}
tty_set_file_descriptor(_serialDescriptor); tty_set_file_descriptor(_serialDescriptor);
mpu_init(0); mpu_init(0);

View file

@ -7,29 +7,24 @@
// //
#include <VoxelImporter.h> #include <VoxelImporter.h>
#include <Application.h>
#include <QFileInfo> #include <QFileInfo>
#include <QThreadPool> #include <QThreadPool>
static const int IMPORT_SYSTEM_SCALE = 1.0f;
static const int MAX_VOXELS_PER_IMPORT = 2000000;
class ImportTask : public QObject, public QRunnable { class ImportTask : public QObject, public QRunnable {
public: public:
ImportTask(VoxelSystem* voxelSystem, const QString &filename); ImportTask(const QString &filename);
void run(); void run();
private: private:
VoxelSystem* _voxelSystem; QString _filename;
QString _filename;
}; };
VoxelImporter::VoxelImporter(QWidget* parent) VoxelImporter::VoxelImporter(QWidget* parent)
: QObject(parent), : QObject(parent),
_voxelSystem(IMPORT_SYSTEM_SCALE, MAX_VOXELS_PER_IMPORT), _voxelTree(true),
_initialized(false), _importDialog(parent),
_importWaiting(false),
_importDialog(parent, &_voxelSystem),
_currentTask(NULL), _currentTask(NULL),
_nextTask(NULL) { _nextTask(NULL) {
@ -38,6 +33,10 @@ VoxelImporter::VoxelImporter(QWidget* parent)
connect(&_importDialog, SIGNAL(accepted()), SLOT(import())); connect(&_importDialog, SIGNAL(accepted()), SLOT(import()));
} }
void VoxelImporter::init() {
_importDialog.init();
}
VoxelImporter::~VoxelImporter() { VoxelImporter::~VoxelImporter() {
if (_nextTask) { if (_nextTask) {
delete _nextTask; delete _nextTask;
@ -46,16 +45,15 @@ VoxelImporter::~VoxelImporter() {
if (_currentTask) { if (_currentTask) {
disconnect(_currentTask, 0, 0, 0); disconnect(_currentTask, 0, 0, 0);
_voxelSystem.cancelImport(); _voxelTree.cancelImport();
_currentTask = NULL; _currentTask = NULL;
} }
} }
void VoxelImporter::reset() { void VoxelImporter::reset() {
_voxelSystem.killLocalVoxels(); _voxelTree.eraseAllVoxels();
_importDialog.reset(); _importDialog.reset();
_filename = ""; _filename = "";
_importWaiting = false;
if (_nextTask) { if (_nextTask) {
delete _nextTask; delete _nextTask;
@ -63,17 +61,11 @@ void VoxelImporter::reset() {
} }
if (_currentTask) { if (_currentTask) {
_voxelSystem.cancelImport(); _voxelTree.cancelImport();
} }
} }
int VoxelImporter::exec() { int VoxelImporter::exec() {
if (!_initialized) {
_voxelSystem.init();
_importViewFrustum.calculate();
_voxelSystem.setViewFrustum(&_importViewFrustum);
_initialized = true;
}
reset(); reset();
int ret = _importDialog.exec(); int ret = _importDialog.exec();
@ -82,7 +74,15 @@ int VoxelImporter::exec() {
reset(); reset();
} else { } else {
_importDialog.reset(); _importDialog.reset();
_importWaiting = true;
if (_importDialog.getImportIntoClipboard()) {
VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem();
voxelSystem->copySubTreeIntoNewTree(voxelSystem->getTree()->rootNode,
Application::getInstance()->getClipboard(),
true);
voxelSystem->changeTree(Application::getInstance()->getClipboard());
}
} }
return ret; return ret;
@ -102,11 +102,11 @@ int VoxelImporter::preImport() {
delete _nextTask; delete _nextTask;
} }
_nextTask = new ImportTask(&_voxelSystem, _filename); _nextTask = new ImportTask(_filename);
connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask())); connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask()));
if (_currentTask != NULL) { if (_currentTask != NULL) {
_voxelSystem.cancelImport(); _voxelTree.cancelImport();
} else { } else {
launchTask(); launchTask();
} }
@ -138,12 +138,12 @@ int VoxelImporter::import() {
delete _nextTask; delete _nextTask;
} }
_nextTask = new ImportTask(&_voxelSystem, _filename); _nextTask = new ImportTask(_filename);
connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask())); connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask()));
connect(_nextTask, SIGNAL(destroyed()), &_importDialog, SLOT(accept())); connect(_nextTask, SIGNAL(destroyed()), &_importDialog, SLOT(accept()));
if (_currentTask != NULL) { if (_currentTask != NULL) {
_voxelSystem.cancelImport(); _voxelTree.cancelImport();
} else { } else {
launchTask(); launchTask();
} }
@ -153,28 +153,36 @@ int VoxelImporter::import() {
void VoxelImporter::launchTask() { void VoxelImporter::launchTask() {
if (_nextTask != NULL) { if (_nextTask != NULL) {
_voxelSystem.killLocalVoxels();
_currentTask = _nextTask; _currentTask = _nextTask;
_nextTask = NULL; _nextTask = NULL;
if (Application::getInstance()->getSharedVoxelSystem()->getTree() != &_voxelTree) {
Application::getInstance()->getSharedVoxelSystem()->changeTree(&_voxelTree);
}
QThreadPool::globalInstance()->start(_currentTask); QThreadPool::globalInstance()->start(_currentTask);
} else { } else {
_currentTask = NULL; _currentTask = NULL;
} }
} }
ImportTask::ImportTask(VoxelSystem* voxelSystem, const QString &filename) ImportTask::ImportTask(const QString &filename)
: _voxelSystem(voxelSystem), : _filename(filename) {
_filename(filename) {
} }
void ImportTask::run() { void ImportTask::run() {
VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem();
voxelSystem->killLocalVoxels();
if (_filename.endsWith(".png", Qt::CaseInsensitive)) { if (_filename.endsWith(".png", Qt::CaseInsensitive)) {
_voxelSystem->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data()); voxelSystem->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data());
} else if (_filename.endsWith(".svo", Qt::CaseInsensitive)) { } else if (_filename.endsWith(".svo", Qt::CaseInsensitive)) {
_voxelSystem->readFromSVOFile(_filename.toLocal8Bit().data()); voxelSystem->readFromSVOFile(_filename.toLocal8Bit().data());
} else if (_filename.endsWith(".schematic", Qt::CaseInsensitive)) { } else if (_filename.endsWith(".schematic", Qt::CaseInsensitive)) {
_voxelSystem->readFromSchematicFile(_filename.toLocal8Bit().data()); voxelSystem->readFromSchematicFile(_filename.toLocal8Bit().data());
} else { } else {
qDebug("[ERROR] Invalid file extension.\n"); qDebug("[ERROR] Invalid file extension.\n");
} }
voxelSystem->getTree()->reaverageVoxelColors(voxelSystem->getTree()->rootNode);
} }

View file

@ -22,11 +22,11 @@ class VoxelImporter : public QObject {
public: public:
VoxelImporter(QWidget* parent = NULL); VoxelImporter(QWidget* parent = NULL);
~VoxelImporter(); ~VoxelImporter();
void init();
void reset(); void reset();
bool getImportWaiting() const { return _importWaiting; } VoxelTree* getVoxelTree() { return &_voxelTree; }
VoxelSystem* getVoxelSystem() { return &_voxelSystem; }
bool getImportIntoClipboard() const { return _importDialog.getImportIntoClipboard(); }
public slots: public slots:
int exec(); int exec();
@ -37,14 +37,10 @@ private slots:
void launchTask(); void launchTask();
private: private:
VoxelSystem _voxelSystem; VoxelTree _voxelTree;
ViewFrustum _importViewFrustum;
bool _initialized;
bool _importWaiting;
ImportDialog _importDialog; ImportDialog _importDialog;
QString _filename; QString _filename;
ImportTask* _currentTask; ImportTask* _currentTask;
ImportTask* _nextTask; ImportTask* _nextTask;

View file

@ -115,6 +115,10 @@ void VoxelSystem::clearFreeBufferIndexes() {
} }
VoxelSystem::~VoxelSystem() { VoxelSystem::~VoxelSystem() {
glDeleteBuffers(1, &_vboVerticesID);
glDeleteBuffers(1, &_vboNormalsID);
glDeleteBuffers(1, &_vboColorsID);
glDeleteBuffers(1, &_vboIndicesID);
delete[] _readVerticesArray; delete[] _readVerticesArray;
delete[] _writeVerticesArray; delete[] _writeVerticesArray;
delete[] _readColorsArray; delete[] _readColorsArray;
@ -416,7 +420,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
bool shouldRender = false; // assume we don't need to render it bool shouldRender = false; // assume we don't need to render it
// if it's colored, we might need to render it! // if it's colored, we might need to render it!
shouldRender = node->calculateShouldRender(_viewFrustum); shouldRender = node->calculateShouldRender(_viewFrustum);
node->setShouldRender(shouldRender); node->setShouldRender(shouldRender);
// let children figure out their renderness // let children figure out their renderness
if (!node->isLeaf()) { if (!node->isLeaf()) {
@ -627,6 +631,18 @@ void VoxelSystem::init() {
_perlinModulateProgram->release(); _perlinModulateProgram->release();
} }
void VoxelSystem::changeTree(VoxelTree* newTree) {
disconnect(_tree, 0, this, 0);
_tree = newTree;
_tree->setDirtyBit();
connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float)));
connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
setupNewVoxelsForDrawing();
}
void VoxelSystem::updateFullVBOs() { void VoxelSystem::updateFullVBOs() {
updateVBOSegment(0, _voxelsInReadArrays); updateVBOSegment(0, _voxelsInReadArrays);

View file

@ -34,19 +34,21 @@ public:
VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM); VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM);
~VoxelSystem(); ~VoxelSystem();
void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }; void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }
int getDataSourceID() const { return _dataSourceID; }; int getDataSourceID() const { return _dataSourceID; }
int parseData(unsigned char* sourceBuffer, int numBytes); int parseData(unsigned char* sourceBuffer, int numBytes);
virtual void init(); virtual void init();
void simulate(float deltaTime) { }; void simulate(float deltaTime) { }
void render(bool texture); void render(bool texture);
ViewFrustum* getViewFrustum() const {return _viewFrustum;} void changeTree(VoxelTree* newTree);
void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;} VoxelTree* getTree() const { return _tree; }
unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}; ViewFrustum* getViewFrustum() const { return _viewFrustum; }
unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;}; void setViewFrustum(ViewFrustum* viewFrustum) { _viewFrustum = viewFrustum; }
unsigned long getVoxelsUpdated() const { return _voxelsUpdated; }
unsigned long getVoxelsRendered() const { return _voxelsInReadArrays; }
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
void writeToSVOFile(const char* filename, VoxelNode* node) const; void writeToSVOFile(const char* filename, VoxelNode* node) const;
@ -118,10 +120,11 @@ protected:
float _treeScale; float _treeScale;
int _maxVoxels; int _maxVoxels;
VoxelTree* _tree; VoxelTree* _tree;
void setupNewVoxelsForDrawing();
glm::vec3 computeVoxelVertex(const glm::vec3& startVertex, float voxelScale, int index) const; glm::vec3 computeVoxelVertex(const glm::vec3& startVertex, float voxelScale, int index) const;
void setupNewVoxelsForDrawing();
virtual void updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& startVertex, virtual void updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& startVertex,
float voxelScale, const nodeColor& color); float voxelScale, const nodeColor& color);

View file

@ -423,6 +423,7 @@ void ViewFrustum::printDebugDetails() const {
qDebug("_right=%f,%f,%f\n", _right.x, _right.y, _right.z ); qDebug("_right=%f,%f,%f\n", _right.x, _right.y, _right.z );
qDebug("_fieldOfView=%f\n", _fieldOfView); qDebug("_fieldOfView=%f\n", _fieldOfView);
qDebug("_aspectRatio=%f\n", _aspectRatio); qDebug("_aspectRatio=%f\n", _aspectRatio);
qDebug("_keyHoleRadius=%f\n", _keyholeRadius);
qDebug("_nearClip=%f\n", _nearClip); qDebug("_nearClip=%f\n", _nearClip);
qDebug("_farClip=%f\n", _farClip); qDebug("_farClip=%f\n", _farClip);
qDebug("_eyeOffsetPosition=%f,%f,%f\n", _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z ); qDebug("_eyeOffsetPosition=%f,%f,%f\n", _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z );

View file

@ -24,50 +24,50 @@ const float DEFAULT_KEYHOLE_RADIUS = 3.0f;
class ViewFrustum { class ViewFrustum {
public: public:
// setters for camera attributes // setters for camera attributes
void setPosition (const glm::vec3& p) { _position = p; }; void setPosition(const glm::vec3& p) { _position = p; }
void setOrientation (const glm::quat& orientationAsQuaternion); void setOrientation(const glm::quat& orientationAsQuaternion);
// getters for camera attributes // getters for camera attributes
const glm::vec3& getPosition() const { return _position; }; const glm::vec3& getPosition() const { return _position; }
const glm::quat& getOrientation() const { return _orientation; }; const glm::quat& getOrientation() const { return _orientation; }
const glm::vec3& getDirection() const { return _direction; }; const glm::vec3& getDirection() const { return _direction; }
const glm::vec3& getUp() const { return _up; }; const glm::vec3& getUp() const { return _up; }
const glm::vec3& getRight() const { return _right; }; const glm::vec3& getRight() const { return _right; }
// setters for lens attributes // setters for lens attributes
void setFieldOfView ( float f ) { _fieldOfView = f; }; void setFieldOfView(float f) { _fieldOfView = f; }
void setAspectRatio ( float a ) { _aspectRatio = a; }; void setAspectRatio(float a) { _aspectRatio = a; }
void setNearClip ( float n ) { _nearClip = n; }; void setNearClip(float n) { _nearClip = n; }
void setFarClip ( float f ) { _farClip = f; }; void setFarClip(float f) { _farClip = f; }
void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; }; void setEyeOffsetPosition(const glm::vec3& p) { _eyeOffsetPosition = p; }
void setEyeOffsetOrientation (const glm::quat& o) { _eyeOffsetOrientation = o; }; void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; }
// getters for lens attributes // getters for lens attributes
float getFieldOfView() const { return _fieldOfView; }; float getFieldOfView() const { return _fieldOfView; }
float getAspectRatio() const { return _aspectRatio; }; float getAspectRatio() const { return _aspectRatio; }
float getNearClip() const { return _nearClip; }; float getNearClip() const { return _nearClip; }
float getFarClip() const { return _farClip; }; float getFarClip() const { return _farClip; }
const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }; const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }
const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation;}; const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; }
const glm::vec3& getOffsetPosition() const { return _offsetPosition; }; const glm::vec3& getOffsetPosition() const { return _offsetPosition; }
const glm::vec3& getOffsetDirection() const { return _offsetDirection;}; const glm::vec3& getOffsetDirection() const { return _offsetDirection; }
const glm::vec3& getOffsetUp() const { return _offsetUp; }; const glm::vec3& getOffsetUp() const { return _offsetUp; }
const glm::vec3& getOffsetRight() const { return _offsetRight; }; const glm::vec3& getOffsetRight() const { return _offsetRight; }
const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; const glm::vec3& getFarTopLeft() const { return _farTopLeft; }
const glm::vec3& getFarTopRight() const { return _farTopRight; }; const glm::vec3& getFarTopRight() const { return _farTopRight; }
const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; }; const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; }
const glm::vec3& getFarBottomRight() const { return _farBottomRight; }; const glm::vec3& getFarBottomRight() const { return _farBottomRight; }
const glm::vec3& getNearTopLeft() const { return _nearTopLeft; }; const glm::vec3& getNearTopLeft() const { return _nearTopLeft; }
const glm::vec3& getNearTopRight() const { return _nearTopRight; }; const glm::vec3& getNearTopRight() const { return _nearTopRight; }
const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }; const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }
const glm::vec3& getNearBottomRight() const { return _nearBottomRight;}; const glm::vec3& getNearBottomRight() const { return _nearBottomRight; }
// get/set for keyhole attribute // get/set for keyhole attribute
void setKeyholeRadius(float keyholdRadius) { _keyholeRadius = keyholdRadius; }; void setKeyholeRadius(float keyholdRadius) { _keyholeRadius = keyholdRadius; }
float getKeyholeRadius() const { return _keyholeRadius; }; float getKeyholeRadius() const { return _keyholeRadius; }
void calculate(); void calculate();
@ -81,7 +81,7 @@ public:
// some frustum comparisons // some frustum comparisons
bool matches(const ViewFrustum& compareTo, bool debug = false) const; bool matches(const ViewFrustum& compareTo, bool debug = false) const;
bool matches(const ViewFrustum* compareTo, bool debug = false) const { return matches(*compareTo, debug); }; bool matches(const ViewFrustum* compareTo, bool debug = false) const { return matches(*compareTo, debug); }
void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const; void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const;

View file

@ -1581,7 +1581,6 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
bool VoxelTree::readFromSVOFile(const char* fileName) { bool VoxelTree::readFromSVOFile(const char* fileName) {
std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate); std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);
if(file.is_open()) { if(file.is_open()) {
emit importSize(1.0f, 1.0f, 1.0f); emit importSize(1.0f, 1.0f, 1.0f);
emit importProgress(0); emit importProgress(0);
@ -1607,15 +1606,15 @@ bool VoxelTree::readFromSVOFile(const char* fileName) {
} }
bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) { bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) {
emit importSize(1.0f, 1.0f, 1.0f);
emit importProgress(0); emit importProgress(0);
int minAlpha = INT_MAX; int minAlpha = INT_MAX;
QImage pngImage = QImage(filename); QImage pngImage = QImage(filename);
for (int x = 0; x < pngImage.width() * pngImage.height(); ++x) { for (int i = 0; i < pngImage.width(); ++i) {
minAlpha = std::min(qAlpha(pngImage.color(x)) , minAlpha); for (int j = 0; j < pngImage.height(); ++j) {
minAlpha = std::min(qAlpha(pngImage.pixel(i, j)) , minAlpha);
}
} }
int maxSize = std::max(pngImage.width(), pngImage.height()); int maxSize = std::max(pngImage.width(), pngImage.height());
@ -1624,6 +1623,8 @@ bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) {
while (maxSize > scale) {scale *= 2;} while (maxSize > scale) {scale *= 2;}
float size = 1.0f / scale; float size = 1.0f / scale;
emit importSize(size * pngImage.width(), 1.0f, size * pngImage.height());
QRgb pixel; QRgb pixel;
int minNeighborhoodAlpha; int minNeighborhoodAlpha;
@ -1692,14 +1693,13 @@ bool VoxelTree::readFromSchematicFile(const char *fileName) {
while (max > scale) {scale *= 2;} while (max > scale) {scale *= 2;}
float size = 1.0f / scale; float size = 1.0f / scale;
int create = 1;
int red = 128, green = 128, blue = 128;
int count = 0;
emit importSize(size * schematics.getWidth(), emit importSize(size * schematics.getWidth(),
size * schematics.getHeight(), size * schematics.getHeight(),
size * schematics.getLength()); size * schematics.getLength());
emit importProgress(0);
int create = 1;
int red = 128, green = 128, blue = 128;
int count = 0;
for (int y = 0; y < schematics.getHeight(); ++y) { for (int y = 0; y < schematics.getHeight(); ++y) {
for (int z = 0; z < schematics.getLength(); ++z) { for (int z = 0; z < schematics.getLength(); ++z) {