From 9224bca88b1150fe32f1573f453078342ba12abd Mon Sep 17 00:00:00 2001 From: atlante45 Date: Thu, 22 Aug 2013 13:52:24 -0700 Subject: [PATCH 01/11] Fixed glBuffers not deleted in VoxelSystem --- interface/src/VoxelSystem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index b0cbcf02c3..9c31040ca5 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -115,6 +115,10 @@ void VoxelSystem::clearFreeBufferIndexes() { } VoxelSystem::~VoxelSystem() { + glDeleteBuffers(1, &_vboVerticesID); + glDeleteBuffers(1, &_vboNormalsID); + glDeleteBuffers(1, &_vboColorsID); + glDeleteBuffers(1, &_vboIndicesID); delete[] _readVerticesArray; delete[] _writeVerticesArray; delete[] _readColorsArray; From 99321b3e096f66505d518976ab86c37a469d7778 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Thu, 22 Aug 2013 15:43:58 -0700 Subject: [PATCH 02/11] Fixed VBOs not being deleted in VoxelSystem destructor --- interface/src/VoxelSystem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index b0cbcf02c3..9c31040ca5 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -115,6 +115,10 @@ void VoxelSystem::clearFreeBufferIndexes() { } VoxelSystem::~VoxelSystem() { + glDeleteBuffers(1, &_vboVerticesID); + glDeleteBuffers(1, &_vboNormalsID); + glDeleteBuffers(1, &_vboColorsID); + glDeleteBuffers(1, &_vboIndicesID); delete[] _readVerticesArray; delete[] _writeVerticesArray; delete[] _readColorsArray; From 1dc8d8dd0c8d699c0e7370d7cbcf17f0366762c0 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Thu, 29 Aug 2013 17:59:36 -0700 Subject: [PATCH 03/11] Added LOD to preview + Shared voxelSystem for reduced memory consumption --- interface/src/Application.cpp | 70 +++++++-------- interface/src/Application.h | 9 +- interface/src/ImportDialog.cpp | 124 ++++++++++++++++++++++++--- interface/src/ImportDialog.h | 7 +- interface/src/VoxelImporter.cpp | 72 +++++++++------- interface/src/VoxelImporter.h | 14 ++- interface/src/VoxelSystem.cpp | 14 ++- interface/src/VoxelSystem.h | 6 +- libraries/voxels/src/ViewFrustum.cpp | 1 + libraries/voxels/src/VoxelTree.cpp | 14 ++- 10 files changed, 227 insertions(+), 104 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 494a1e6976..8402236d78 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -82,7 +82,7 @@ const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2; // Startup optimistically with small jitter buffer that // will start playback on the second received audio packet. -static const float CLIPBOARD_TREE_SCALE = 1.0f; +static const float SHARED_VOXEL_SYSTEM_TREE_SCALE = 1.0f; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { fprintf(stdout, "%s", message.toLocal8Bit().constData()); @@ -97,7 +97,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _frameCount(0), _fps(120.0f), _justStarted(true), - _clipboard(CLIPBOARD_TREE_SCALE), _voxelImporter(_window), _wantToKillLocalVoxels(false), _audioScope(256, 200, true), @@ -1207,15 +1206,6 @@ void Application::exportVoxels() { void Application::importVoxels() { if (_voxelImporter.exec()) { 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 { qDebug("[DEBUG] Import failed.\n"); } @@ -1230,13 +1220,17 @@ void Application::cutVoxels() { } 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); if (selectedNode) { - // clear the clipboard first... - _clipboard.killLocalVoxels(); - - // then copy onto it - _voxels.copySubTreeIntoNewTree(selectedNode, &_clipboard, true); + _voxels.copySubTreeIntoNewTree(selectedNode, &_sharedVoxelSystem, true); } } @@ -1257,12 +1251,13 @@ void Application::pasteVoxels() { args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); } - if (_voxelImporter.getImportWaiting()) { - _voxelImporter.getVoxelSystem()->recurseTreeWithOperation(sendVoxelsOperation, &args); - _voxelImporter.reset(); - } else { - _clipboard.recurseTreeWithOperation(sendVoxelsOperation, &args); + _sharedVoxelSystem.getTree()->recurseTreeWithOperation(sendVoxelsOperation, &args); + + if (_sharedVoxelSystem.getTree() != &_clipboard) { + _sharedVoxelSystem.killLocalVoxels(); + _sharedVoxelSystem.changeTree(&_clipboard); } + _voxelEditSender.flushQueue(); if (calculatedOctCode) { @@ -1304,10 +1299,21 @@ void Application::initDisplay() { void Application::init() { _voxels.init(); - _clipboard.init(); - _clipboardViewFrustum.setKeyholeRadius(1000.0f); - _clipboardViewFrustum.calculate(); - _clipboard.setViewFrustum(&_clipboardViewFrustum); + _sharedVoxelSystemViewFrustum.setPosition(glm::vec3(TREE_SCALE / 2.0f, + TREE_SCALE / 2.0f, + 3.0f * TREE_SCALE / 2.0f)); + _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(); @@ -1318,6 +1324,7 @@ void Application::init() { _headMouseX = _mouseX = _glWidget->width() / 2; _headMouseY = _mouseY = _glWidget->height() / 2; + QCursor::setPos(_headMouseX, _headMouseY); _myAvatar.init(); _myAvatar.setPosition(START_LOCATION); @@ -1325,7 +1332,6 @@ void Application::init() { _myCamera.setModeShiftRate(1.0f); _myAvatar.setDisplayingLookatVectors(false); - QCursor::setPos(_headMouseX, _headMouseY); OculusManager::connect(); if (OculusManager::isConnected()) { @@ -2225,15 +2231,11 @@ void Application::displaySide(Camera& whichCamera) { glTranslatef(_mouseVoxel.x * TREE_SCALE, _mouseVoxel.y * TREE_SCALE, _mouseVoxel.z * TREE_SCALE); - glScalef(_mouseVoxel.s * TREE_SCALE, - _mouseVoxel.s * TREE_SCALE, - _mouseVoxel.s * TREE_SCALE); + glScalef(_mouseVoxel.s, + _mouseVoxel.s, + _mouseVoxel.s); - if (_voxelImporter.getImportWaiting()) { - _voxelImporter.getVoxelSystem()->render(true); - } else { - _clipboard.render(true); - } + _sharedVoxelSystem.render(true); glPopMatrix(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 7ad64ca707..dfb6079e81 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -112,6 +112,8 @@ public: Camera* getCamera() { return &_myCamera; } ViewFrustum* getViewFrustum() { return &_viewFrustum; } VoxelSystem* getVoxels() { return &_voxels; } + VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; } + VoxelTree* getClipboard() { return &_clipboard; } Environment* getEnvironment() { return &_environment; } SerialInterface* getSerialHeadSensor() { return &_serialHeadSensor; } Webcam* getWebcam() { return &_webcam; } @@ -238,10 +240,11 @@ private: Stars _stars; - VoxelSystem _voxels; - VoxelSystem _clipboard; // if I copy/paste - ViewFrustum _clipboardViewFrustum; + VoxelSystem _voxels; + VoxelTree _clipboard; // if I copy/paste VoxelImporter _voxelImporter; + VoxelSystem _sharedVoxelSystem; + ViewFrustum _sharedVoxelSystemViewFrustum; QByteArray _voxelsFilename; bool _wantToKillLocalVoxels; diff --git a/interface/src/ImportDialog.cpp b/interface/src/ImportDialog.cpp index 9c6653cc8a..bb2365cec1 100644 --- a/interface/src/ImportDialog.cpp +++ b/interface/src/ImportDialog.cpp @@ -34,9 +34,9 @@ const float FIELD_OF_VIEW = 60.0f; class GLWidget : public QGLWidget { public: - GLWidget(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL); + GLWidget(QWidget* parent = NULL); void setDraw(bool draw) {_draw = draw;} - void setTargetCenter(glm::vec3 targetCenter) {_targetCenter = targetCenter;} + void setTargetCenter(glm::vec3 targetCenter) { _targetCenter = targetCenter; } protected: virtual void initializeGL(); @@ -61,9 +61,8 @@ private: int _mouseY; }; -GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) +GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent, Application::getInstance()->getGLWidget()), - _voxelSystem(voxelSystem), _draw(false), _a(0.0f), _h(VERTICAL_ANGLE), @@ -71,6 +70,7 @@ GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) _pressed(false), _mouseX(0), _mouseY(0) { + _voxelSystem = Application::getInstance()->getSharedVoxelSystem(); } void GLWidget::initializeGL() { @@ -110,7 +110,7 @@ void GLWidget::paintGL() { UP_VECT.x, UP_VECT.y, UP_VECT.z); - if (_draw && _voxelSystem) { + if (_draw) { glBegin(GL_LINES); glColor3d(1, 1 ,1); glVertex3d(0, 0, 0); @@ -134,11 +134,109 @@ void GLWidget::paintGL() { glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 0 ); glEnd(); + glScalef(1.0f / TREE_SCALE, 1.0f / TREE_SCALE, 1.0f / TREE_SCALE); + _voxelSystem->render(false); + + + ViewFrustum& viewFrustum = *Application::getInstance()->getSharedVoxelSystem()->getViewFrustum(); + glm::vec3 position = viewFrustum.getOffsetPosition(); + glm::vec3 direction = viewFrustum.getOffsetDirection(); + glm::vec3 up = viewFrustum.getOffsetUp(); + glm::vec3 right = viewFrustum.getOffsetRight(); + + // Calculate the origin direction vectors + glm::vec3 lookingAt = position + (direction * 0.2f); + glm::vec3 lookingAtUp = position + (up * 0.2f); + glm::vec3 lookingAtRight = position + (right * 0.2f); + + glBegin(GL_LINES); + // Looking At = white + glColor3d(1.0f, 1.0f, 1.0f); + glVertex3d(position.x, position.y, position.z); + glVertex3d(lookingAt.x, lookingAt.y, lookingAt.z); + + // Looking At Up = purple + glColor3d(1.0f, 0.0f, 1.0f); + glVertex3d(position.x, position.y, position.z); + glVertex3d(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z); + + // Looking At Right = cyan + glColor3d(0.0f, 1.0f, 1.0f); + glVertex3d(position.x, position.y, position.z); + glVertex3d(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z); + + + // Drawing the bounds of the frustum + // viewFrustum.getNear plane - bottom edge + glColor3d(1.0f, 0.0f, 0.0f); + glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); + glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); + + // viewFrustum.getNear plane - top edge + glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); + glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); + + // viewFrustum.getNear plane - right edge + glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); + glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); + + // viewFrustum.getNear plane - left edge + glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); + glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); + + + // viewFrustum.getFar plane - bottom edge + glColor3d(0.0f, 1.0f, 0.0f); // GREEN!!! + glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); + glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); + + // viewFrustum.getFar plane - top edge + glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); + glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); + + // viewFrustum.getFar plane - right edge + glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); + glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); + + // viewFrustum.getFar plane - left edge + glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); + glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); + + // RIGHT PLANE IS CYAN + // right plane - bottom edge - viewFrustum.getNear to distant + glColor3d(0.0f, 1.0f, 1.0f); + glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); + glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); + + // right plane - top edge - viewFrustum.getNear to distant + glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); + glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); + + // LEFT PLANE IS BLUE + // left plane - bottom edge - viewFrustum.getNear to distant + glColor3d(0.0f, 0.0f, 1.0f); + glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); + glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); + + // left plane - top edge - viewFrustum.getNear to distant + glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); + glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); + glEnd(); + + // Draw the keyhole + float keyholeRadius = viewFrustum.getKeyholeRadius(); + if (keyholeRadius > 0.0f) { + glPushMatrix(); + glColor3d(1.0f, 1.0f, 0.0f); + glTranslatef(position.x, position.y, position.z); // where we actually want it! + glutWireSphere(keyholeRadius, 20, 20); + glPopMatrix(); + } + } } - void GLWidget::mousePressEvent(QMouseEvent* event) { _pressed = true; _mouseX = event->globalX(); @@ -158,14 +256,13 @@ void GLWidget::mouseReleaseEvent(QMouseEvent* event) { _pressed = false; } -ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) +ImportDialog::ImportDialog(QWidget *parent) : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES), _importButton (IMPORT_BUTTON_NAME, this), _clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this), _previewBox (PREVIEW_CHECKBOX_STRING, this), _previewBar (this), - _glPreview (new GLWidget(this, voxelSystem)) { - + _glPreview (new GLWidget(this)) { setOption(QFileDialog::DontUseNativeDialog, true); setFileMode(QFileDialog::ExistingFile); setViewMode(QFileDialog::Detail); @@ -188,15 +285,18 @@ ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); 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() { 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() { _importButton.setDisabled(true); _clipboardImportBox.setDisabled(true); diff --git a/interface/src/ImportDialog.h b/interface/src/ImportDialog.h index f3c1934760..35102dfe4c 100644 --- a/interface/src/ImportDialog.h +++ b/interface/src/ImportDialog.h @@ -23,15 +23,16 @@ class GLWidget; class ImportDialog : public QFileDialog { Q_OBJECT public: - ImportDialog(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL); + ImportDialog(QWidget* parent = NULL); ~ImportDialog(); + void init(); + void reset(); + bool getWantPreview() const { return _previewBox.isChecked(); } QString getCurrentFile() const { return _currentFile; } bool getImportIntoClipboard() const { return _clipboardImportBox.isChecked(); } - void reset(); - signals: void previewToggled(bool); void accepted(); diff --git a/interface/src/VoxelImporter.cpp b/interface/src/VoxelImporter.cpp index ef4eeafc4b..b3ca39bbb0 100644 --- a/interface/src/VoxelImporter.cpp +++ b/interface/src/VoxelImporter.cpp @@ -7,29 +7,24 @@ // #include +#include #include #include -static const int IMPORT_SYSTEM_SCALE = 1.0f; -static const int MAX_VOXELS_PER_IMPORT = 2000000; - class ImportTask : public QObject, public QRunnable { public: - ImportTask(VoxelSystem* voxelSystem, const QString &filename); + ImportTask(const QString &filename); void run(); private: - VoxelSystem* _voxelSystem; - QString _filename; + QString _filename; }; VoxelImporter::VoxelImporter(QWidget* parent) : QObject(parent), - _voxelSystem(IMPORT_SYSTEM_SCALE, MAX_VOXELS_PER_IMPORT), - _initialized(false), - _importWaiting(false), - _importDialog(parent, &_voxelSystem), + _voxelTree(true), + _importDialog(parent), _currentTask(NULL), _nextTask(NULL) { @@ -38,6 +33,10 @@ VoxelImporter::VoxelImporter(QWidget* parent) connect(&_importDialog, SIGNAL(accepted()), SLOT(import())); } +void VoxelImporter::init() { + _importDialog.init(); +} + VoxelImporter::~VoxelImporter() { if (_nextTask) { delete _nextTask; @@ -46,16 +45,15 @@ VoxelImporter::~VoxelImporter() { if (_currentTask) { disconnect(_currentTask, 0, 0, 0); - _voxelSystem.cancelImport(); + _voxelTree.cancelImport(); _currentTask = NULL; } } void VoxelImporter::reset() { - _voxelSystem.killLocalVoxels(); + _voxelTree.eraseAllVoxels(); _importDialog.reset(); _filename = ""; - _importWaiting = false; if (_nextTask) { delete _nextTask; @@ -63,17 +61,11 @@ void VoxelImporter::reset() { } if (_currentTask) { - _voxelSystem.cancelImport(); + _voxelTree.cancelImport(); } } int VoxelImporter::exec() { - if (!_initialized) { - _voxelSystem.init(); - _importViewFrustum.calculate(); - _voxelSystem.setViewFrustum(&_importViewFrustum); - _initialized = true; - } reset(); int ret = _importDialog.exec(); @@ -82,7 +74,15 @@ int VoxelImporter::exec() { reset(); } else { _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; @@ -102,11 +102,11 @@ int VoxelImporter::preImport() { delete _nextTask; } - _nextTask = new ImportTask(&_voxelSystem, _filename); + _nextTask = new ImportTask(_filename); connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask())); if (_currentTask != NULL) { - _voxelSystem.cancelImport(); + _voxelTree.cancelImport(); } else { launchTask(); } @@ -138,12 +138,12 @@ int VoxelImporter::import() { delete _nextTask; } - _nextTask = new ImportTask(&_voxelSystem, _filename); + _nextTask = new ImportTask(_filename); connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask())); connect(_nextTask, SIGNAL(destroyed()), &_importDialog, SLOT(accept())); if (_currentTask != NULL) { - _voxelSystem.cancelImport(); + _voxelTree.cancelImport(); } else { launchTask(); } @@ -153,28 +153,36 @@ int VoxelImporter::import() { void VoxelImporter::launchTask() { if (_nextTask != NULL) { - _voxelSystem.killLocalVoxels(); _currentTask = _nextTask; _nextTask = NULL; + + if (Application::getInstance()->getSharedVoxelSystem()->getTree() != &_voxelTree) { + Application::getInstance()->getSharedVoxelSystem()->changeTree(&_voxelTree); + } + QThreadPool::globalInstance()->start(_currentTask); } else { _currentTask = NULL; } } -ImportTask::ImportTask(VoxelSystem* voxelSystem, const QString &filename) - : _voxelSystem(voxelSystem), - _filename(filename) { +ImportTask::ImportTask(const QString &filename) + : _filename(filename) { } void ImportTask::run() { + VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem(); + voxelSystem->killLocalVoxels(); + if (_filename.endsWith(".png", Qt::CaseInsensitive)) { - _voxelSystem->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data()); + voxelSystem->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data()); } else if (_filename.endsWith(".svo", Qt::CaseInsensitive)) { - _voxelSystem->readFromSVOFile(_filename.toLocal8Bit().data()); + voxelSystem->readFromSVOFile(_filename.toLocal8Bit().data()); } else if (_filename.endsWith(".schematic", Qt::CaseInsensitive)) { - _voxelSystem->readFromSchematicFile(_filename.toLocal8Bit().data()); + voxelSystem->readFromSchematicFile(_filename.toLocal8Bit().data()); } else { qDebug("[ERROR] Invalid file extension.\n"); } + + voxelSystem->getTree()->reaverageVoxelColors(voxelSystem->getTree()->rootNode); } diff --git a/interface/src/VoxelImporter.h b/interface/src/VoxelImporter.h index 9b25adcee0..a84955f2c9 100644 --- a/interface/src/VoxelImporter.h +++ b/interface/src/VoxelImporter.h @@ -22,11 +22,11 @@ class VoxelImporter : public QObject { public: VoxelImporter(QWidget* parent = NULL); ~VoxelImporter(); + + void init(); void reset(); - bool getImportWaiting() const { return _importWaiting; } - VoxelSystem* getVoxelSystem() { return &_voxelSystem; } - bool getImportIntoClipboard() const { return _importDialog.getImportIntoClipboard(); } + VoxelTree* getVoxelTree() { return &_voxelTree; } public slots: int exec(); @@ -37,14 +37,10 @@ private slots: void launchTask(); private: - VoxelSystem _voxelSystem; - ViewFrustum _importViewFrustum; - bool _initialized; - bool _importWaiting; - + VoxelTree _voxelTree; ImportDialog _importDialog; - QString _filename; + QString _filename; ImportTask* _currentTask; ImportTask* _nextTask; diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 9c31040ca5..50cfd819cc 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -420,7 +420,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { bool shouldRender = false; // assume we don't need to render it // if it's colored, we might need to render it! shouldRender = node->calculateShouldRender(_viewFrustum); - + node->setShouldRender(shouldRender); // let children figure out their renderness if (!node->isLeaf()) { @@ -631,6 +631,18 @@ void VoxelSystem::init() { _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() { updateVBOSegment(0, _voxelsInReadArrays); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 7b6c001e8a..53a083ada9 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -43,6 +43,8 @@ public: void simulate(float deltaTime) { }; void render(bool texture); + void changeTree(VoxelTree* newTree); + VoxelTree* getTree() const {return _tree;} ViewFrustum* getViewFrustum() const {return _viewFrustum;} void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;} unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}; @@ -93,6 +95,7 @@ public: virtual void nodeDeleted(VoxelNode* node); virtual void nodeAdded(Node* node); virtual void nodeKilled(Node* node); + void setupNewVoxelsForDrawing(); signals: void importSize(float x, float y, float z); @@ -120,8 +123,7 @@ protected: VoxelTree* _tree; glm::vec3 computeVoxelVertex(const glm::vec3& startVertex, float voxelScale, int index) const; - - void setupNewVoxelsForDrawing(); + virtual void updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& startVertex, float voxelScale, const nodeColor& color); diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index f12608f5dd..a35dc49ec0 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -423,6 +423,7 @@ void ViewFrustum::printDebugDetails() const { qDebug("_right=%f,%f,%f\n", _right.x, _right.y, _right.z ); qDebug("_fieldOfView=%f\n", _fieldOfView); qDebug("_aspectRatio=%f\n", _aspectRatio); + qDebug("_keyHoleRadius=%f\n", _keyholeRadius); qDebug("_nearClip=%f\n", _nearClip); qDebug("_farClip=%f\n", _farClip); qDebug("_eyeOffsetPosition=%f,%f,%f\n", _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z ); diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index b17200448b..8ecb95d4d6 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1581,7 +1581,6 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp bool VoxelTree::readFromSVOFile(const char* fileName) { std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate); if(file.is_open()) { - emit importSize(1.0f, 1.0f, 1.0f); emit importProgress(0); @@ -1607,9 +1606,7 @@ bool VoxelTree::readFromSVOFile(const char* fileName) { } bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) { - emit importSize(1.0f, 1.0f, 1.0f); emit importProgress(0); - int minAlpha = INT_MAX; QImage pngImage = QImage(filename); @@ -1624,6 +1621,8 @@ bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) { while (maxSize > scale) {scale *= 2;} float size = 1.0f / scale; + emit importSize(size * pngImage.width(), 1.0f, size * pngImage.height()); + QRgb pixel; int minNeighborhoodAlpha; @@ -1692,14 +1691,13 @@ bool VoxelTree::readFromSchematicFile(const char *fileName) { while (max > scale) {scale *= 2;} float size = 1.0f / scale; - int create = 1; - int red = 128, green = 128, blue = 128; - int count = 0; - emit importSize(size * schematics.getWidth(), size * schematics.getHeight(), 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 z = 0; z < schematics.getLength(); ++z) { From fc991bf1aca1fbadc0537d220405bebb5b7896eb Mon Sep 17 00:00:00 2001 From: atlante45 Date: Thu, 29 Aug 2013 18:11:16 -0700 Subject: [PATCH 04/11] Some code reformating --- interface/src/Application.cpp | 1 - interface/src/VoxelSystem.h | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8402236d78..27d11a61b6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -82,7 +82,6 @@ const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2; // Startup optimistically with small jitter buffer that // will start playback on the second received audio packet. -static const float SHARED_VOXEL_SYSTEM_TREE_SCALE = 1.0f; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { fprintf(stdout, "%s", message.toLocal8Bit().constData()); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 53a083ada9..ed635dae3f 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -95,7 +95,6 @@ public: virtual void nodeDeleted(VoxelNode* node); virtual void nodeAdded(Node* node); virtual void nodeKilled(Node* node); - void setupNewVoxelsForDrawing(); signals: void importSize(float x, float y, float z); @@ -121,6 +120,8 @@ protected: float _treeScale; int _maxVoxels; VoxelTree* _tree; + + void setupNewVoxelsForDrawing(); glm::vec3 computeVoxelVertex(const glm::vec3& startVertex, float voxelScale, int index) const; From f21a2798ffb2da0c3566e3d3fc784e895464e2e8 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Fri, 30 Aug 2013 10:37:55 -0700 Subject: [PATCH 05/11] Fixed _sharedVoxelSystemTree deleted twice --- interface/src/Application.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 27d11a61b6..3f0d418fd3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -235,6 +235,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : Application::~Application() { NodeList::getInstance()->removeHook(&_voxels); NodeList::getInstance()->removeHook(this); + + _sharedVoxelSystem.changeTree(new VoxelTree); } void Application::initializeGL() { From 229821e211cbcb6b878a826a8bb74ceb4fd9cc0d Mon Sep 17 00:00:00 2001 From: atlante45 Date: Fri, 30 Aug 2013 15:28:10 -0700 Subject: [PATCH 06/11] Removed frustum display in preview mode --- interface/src/ImportDialog.cpp | 98 ---------------------------------- 1 file changed, 98 deletions(-) diff --git a/interface/src/ImportDialog.cpp b/interface/src/ImportDialog.cpp index bb2365cec1..beda8977cd 100644 --- a/interface/src/ImportDialog.cpp +++ b/interface/src/ImportDialog.cpp @@ -135,105 +135,7 @@ void GLWidget::paintGL() { glEnd(); glScalef(1.0f / TREE_SCALE, 1.0f / TREE_SCALE, 1.0f / TREE_SCALE); - _voxelSystem->render(false); - - - ViewFrustum& viewFrustum = *Application::getInstance()->getSharedVoxelSystem()->getViewFrustum(); - glm::vec3 position = viewFrustum.getOffsetPosition(); - glm::vec3 direction = viewFrustum.getOffsetDirection(); - glm::vec3 up = viewFrustum.getOffsetUp(); - glm::vec3 right = viewFrustum.getOffsetRight(); - - // Calculate the origin direction vectors - glm::vec3 lookingAt = position + (direction * 0.2f); - glm::vec3 lookingAtUp = position + (up * 0.2f); - glm::vec3 lookingAtRight = position + (right * 0.2f); - - glBegin(GL_LINES); - // Looking At = white - glColor3d(1.0f, 1.0f, 1.0f); - glVertex3d(position.x, position.y, position.z); - glVertex3d(lookingAt.x, lookingAt.y, lookingAt.z); - - // Looking At Up = purple - glColor3d(1.0f, 0.0f, 1.0f); - glVertex3d(position.x, position.y, position.z); - glVertex3d(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z); - - // Looking At Right = cyan - glColor3d(0.0f, 1.0f, 1.0f); - glVertex3d(position.x, position.y, position.z); - glVertex3d(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z); - - - // Drawing the bounds of the frustum - // viewFrustum.getNear plane - bottom edge - glColor3d(1.0f, 0.0f, 0.0f); - glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - - // viewFrustum.getNear plane - top edge - glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - - // viewFrustum.getNear plane - right edge - glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - - // viewFrustum.getNear plane - left edge - glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - - - // viewFrustum.getFar plane - bottom edge - glColor3d(0.0f, 1.0f, 0.0f); // GREEN!!! - glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - - // viewFrustum.getFar plane - top edge - glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // viewFrustum.getFar plane - right edge - glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // viewFrustum.getFar plane - left edge - glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - - // RIGHT PLANE IS CYAN - // right plane - bottom edge - viewFrustum.getNear to distant - glColor3d(0.0f, 1.0f, 1.0f); - glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - - // right plane - top edge - viewFrustum.getNear to distant - glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // LEFT PLANE IS BLUE - // left plane - bottom edge - viewFrustum.getNear to distant - glColor3d(0.0f, 0.0f, 1.0f); - glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - - // left plane - top edge - viewFrustum.getNear to distant - glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - glEnd(); - - // Draw the keyhole - float keyholeRadius = viewFrustum.getKeyholeRadius(); - if (keyholeRadius > 0.0f) { - glPushMatrix(); - glColor3d(1.0f, 1.0f, 0.0f); - glTranslatef(position.x, position.y, position.z); // where we actually want it! - glutWireSphere(keyholeRadius, 20, 20); - glPopMatrix(); - } - } } From 0068b838b2821d90047695c7707dc859aaf9ab10 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Fri, 30 Aug 2013 15:56:28 -0700 Subject: [PATCH 07/11] Fixed importer crashing on non ARGB32 png. --- libraries/voxels/src/VoxelTree.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index b17200448b..c673755e82 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1614,8 +1614,10 @@ bool VoxelTree::readFromSquareARGB32Pixels(const char* filename) { QImage pngImage = QImage(filename); - for (int x = 0; x < pngImage.width() * pngImage.height(); ++x) { - minAlpha = std::min(qAlpha(pngImage.color(x)) , minAlpha); + for (int i = 0; i < pngImage.width(); ++i) { + 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()); From 66425763b82682257cb700b700df1ebb808a3e3e Mon Sep 17 00:00:00 2001 From: atlante45 Date: Fri, 30 Aug 2013 16:01:18 -0700 Subject: [PATCH 08/11] Revert "Fixed glBuffers not deleted in VoxelSystem" This reverts commit 9224bca88b1150fe32f1573f453078342ba12abd. --- interface/src/VoxelSystem.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 9c31040ca5..b0cbcf02c3 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -115,10 +115,6 @@ void VoxelSystem::clearFreeBufferIndexes() { } VoxelSystem::~VoxelSystem() { - glDeleteBuffers(1, &_vboVerticesID); - glDeleteBuffers(1, &_vboNormalsID); - glDeleteBuffers(1, &_vboColorsID); - glDeleteBuffers(1, &_vboIndicesID); delete[] _readVerticesArray; delete[] _writeVerticesArray; delete[] _readColorsArray; From 26691118de431585757f1e295c093f40d2131df4 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 3 Sep 2013 10:30:46 -0700 Subject: [PATCH 09/11] Some code reformatting. --- interface/src/ImportDialog.cpp | 2 +- interface/src/VoxelSystem.h | 10 ++--- libraries/voxels/src/ViewFrustum.h | 66 +++++++++++++++--------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/interface/src/ImportDialog.cpp b/interface/src/ImportDialog.cpp index beda8977cd..eea090dfbd 100644 --- a/interface/src/ImportDialog.cpp +++ b/interface/src/ImportDialog.cpp @@ -195,7 +195,7 @@ ImportDialog::~ImportDialog() { void ImportDialog::init() { VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem(); - connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float))); + connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float,float,float))); connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int))); } diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index ed635dae3f..48204295ef 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -44,11 +44,11 @@ public: void render(bool texture); void changeTree(VoxelTree* newTree); - VoxelTree* getTree() const {return _tree;} - ViewFrustum* getViewFrustum() const {return _viewFrustum;} - void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;} - unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}; - unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;}; + VoxelTree* getTree() const { return _tree; } + ViewFrustum* getViewFrustum() const { return _viewFrustum; } + 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 writeToSVOFile(const char* filename, VoxelNode* node) const; diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 188b85c0de..aea81f7b7a 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -24,50 +24,50 @@ const float DEFAULT_KEYHOLE_RADIUS = 3.0f; class ViewFrustum { public: // setters for camera attributes - void setPosition (const glm::vec3& p) { _position = p; }; - void setOrientation (const glm::quat& orientationAsQuaternion); + void setPosition(const glm::vec3& p) { _position = p; } + void setOrientation(const glm::quat& orientationAsQuaternion); // getters for camera attributes - const glm::vec3& getPosition() const { return _position; }; - const glm::quat& getOrientation() const { return _orientation; }; - const glm::vec3& getDirection() const { return _direction; }; - const glm::vec3& getUp() const { return _up; }; - const glm::vec3& getRight() const { return _right; }; + const glm::vec3& getPosition() const { return _position; } + const glm::quat& getOrientation() const { return _orientation; } + const glm::vec3& getDirection() const { return _direction; } + const glm::vec3& getUp() const { return _up; } + const glm::vec3& getRight() const { return _right; } // setters for lens attributes - void setFieldOfView ( float f ) { _fieldOfView = f; }; - void setAspectRatio ( float a ) { _aspectRatio = a; }; - void setNearClip ( float n ) { _nearClip = n; }; - void setFarClip ( float f ) { _farClip = f; }; - void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; }; - void setEyeOffsetOrientation (const glm::quat& o) { _eyeOffsetOrientation = o; }; + void setFieldOfView(float f) { _fieldOfView = f; } + void setAspectRatio(float a) { _aspectRatio = a; } + void setNearClip(float n) { _nearClip = n; } + void setFarClip(float f) { _farClip = f; } + void setEyeOffsetPosition(const glm::vec3& p) { _eyeOffsetPosition = p; } + void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; } // getters for lens attributes - float getFieldOfView() const { return _fieldOfView; }; - float getAspectRatio() const { return _aspectRatio; }; - float getNearClip() const { return _nearClip; }; - float getFarClip() const { return _farClip; }; - const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }; - const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation;}; + float getFieldOfView() const { return _fieldOfView; } + float getAspectRatio() const { return _aspectRatio; } + float getNearClip() const { return _nearClip; } + float getFarClip() const { return _farClip; } + const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; } + const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; } - const glm::vec3& getOffsetPosition() const { return _offsetPosition; }; - const glm::vec3& getOffsetDirection() const { return _offsetDirection;}; - const glm::vec3& getOffsetUp() const { return _offsetUp; }; - const glm::vec3& getOffsetRight() const { return _offsetRight; }; + const glm::vec3& getOffsetPosition() const { return _offsetPosition; } + const glm::vec3& getOffsetDirection() const { return _offsetDirection; } + const glm::vec3& getOffsetUp() const { return _offsetUp; } + const glm::vec3& getOffsetRight() const { return _offsetRight; } - const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; - const glm::vec3& getFarTopRight() const { return _farTopRight; }; - const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; }; - const glm::vec3& getFarBottomRight() const { return _farBottomRight; }; + const glm::vec3& getFarTopLeft() const { return _farTopLeft; } + const glm::vec3& getFarTopRight() const { return _farTopRight; } + const glm::vec3& getFarBottomLeft() const { return _farBottomLeft; } + const glm::vec3& getFarBottomRight() const { return _farBottomRight; } - const glm::vec3& getNearTopLeft() const { return _nearTopLeft; }; - const glm::vec3& getNearTopRight() const { return _nearTopRight; }; - const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; }; - const glm::vec3& getNearBottomRight() const { return _nearBottomRight;}; + const glm::vec3& getNearTopLeft() const { return _nearTopLeft; } + const glm::vec3& getNearTopRight() const { return _nearTopRight; } + const glm::vec3& getNearBottomLeft() const { return _nearBottomLeft; } + const glm::vec3& getNearBottomRight() const { return _nearBottomRight; } // get/set for keyhole attribute - void setKeyholeRadius(float keyholdRadius) { _keyholeRadius = keyholdRadius; }; - float getKeyholeRadius() const { return _keyholeRadius; }; + void setKeyholeRadius(float keyholdRadius) { _keyholeRadius = keyholdRadius; } + float getKeyholeRadius() const { return _keyholeRadius; } void calculate(); From 15a3a8d252e95499f8efe57b5d81c98fc90e818a Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 3 Sep 2013 10:32:38 -0700 Subject: [PATCH 10/11] Some more code reformatting. --- interface/src/VoxelSystem.h | 6 +++--- libraries/voxels/src/ViewFrustum.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 48204295ef..189d19f866 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -34,13 +34,13 @@ public: VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM); ~VoxelSystem(); - void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }; - int getDataSourceID() const { return _dataSourceID; }; + void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; } + int getDataSourceID() const { return _dataSourceID; } int parseData(unsigned char* sourceBuffer, int numBytes); virtual void init(); - void simulate(float deltaTime) { }; + void simulate(float deltaTime) { } void render(bool texture); void changeTree(VoxelTree* newTree); diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index aea81f7b7a..22830cb48d 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -81,7 +81,7 @@ public: // some frustum comparisons 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; From 843d5656bd63cb651945139fe1a758398ec5e7d0 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 3 Sep 2013 10:45:33 -0700 Subject: [PATCH 11/11] Fix for compile warnings on Linux: check return values on read/write. --- interface/src/SerialInterface.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index d9c1bd928f..4082bc87ef 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -125,9 +125,15 @@ void SerialInterface::initializePort(char* portname) { tcflush(_serialDescriptor, TCIOFLUSH); // 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]; - read(_serialDescriptor, result, 4); + if (read(_serialDescriptor, result, 4) != 4) { + qDebug("Failed.\n"); + return; + } tty_set_file_descriptor(_serialDescriptor); mpu_init(0);