Starting work on "metavoxels."

This commit is contained in:
Andrzej Kapolka 2013-12-02 12:15:43 -08:00
parent 14129cd86d
commit 4033baa5ca
6 changed files with 198 additions and 0 deletions

View file

@ -84,6 +84,7 @@ include(${MACRO_DIR}/LinkHifiLibrary.cmake)
# link required hifi libraries
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(metavoxels ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR})

View file

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 2.8)
set(ROOT_DIR ../..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
# setup for find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules/")
set(TARGET_NAME metavoxels)
find_package(Qt5Widgets REQUIRED)
include(${MACRO_DIR}/SetupHifiLibrary.cmake)
setup_hifi_library(${TARGET_NAME})
qt5_use_modules(${TARGET_NAME} Widgets)
include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${ROOT_DIR})

View file

@ -0,0 +1,53 @@
//
// Bitstream.cpp
// metavoxels
//
// Created by Andrzej Kapolka on 12/2/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include <QDataStream>
#include "Bitstream.h"
Bitstream::Bitstream(QDataStream& underlying)
: _underlying(underlying), _byte(0), _position(0) {
}
int Bitstream::write(const void* data, int bits) {
return bits;
}
int Bitstream::read(void* data, int bits) {
return bits;
}
void Bitstream::flush() {
if (_position != 0) {
_underlying << _byte;
_byte = 0;
_position = 0;
}
}
Bitstream& Bitstream::operator<<(bool value) {
if (value) {
_byte |= (1 << _position);
}
const int LAST_BIT_POSITION = 7;
if (_position++ == LAST_BIT_POSITION) {
flush();
}
return *this;
}
Bitstream& Bitstream::operator>>(bool& value) {
if (_position == 0) {
_underlying >> _byte;
}
value = _byte & (1 << _position);
if (_position++ == 7) {
_position = 0;
}
return *this;
}

View file

@ -0,0 +1,36 @@
//
// Bitstream.h
// metavoxels
//
// Created by Andrzej Kapolka on 12/2/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef __interface__Bitstream__
#define __interface__Bitstream__
class QDataStream;
/// A stream for bit-aligned data.
class Bitstream {
public:
Bitstream(QDataStream& underlying);
Bitstream& write(const void* data, int bits);
Bitstream& read(void* data, int bits);
/// Flushes any unwritten bits to the underlying stream.
void flush();
Bitstream& operator<<(bool value);
Bitstream& operator>>(bool& value);
private:
QDataStream& _underlying;
char _byte;
int _position;
};
#endif /* defined(__interface__Bitstream__) */

View file

@ -0,0 +1,50 @@
//
// Metavoxels.cpp
// metavoxels
//
// Created by Andrzej Kapolka on 12/2/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include "Bitstream.h"
#include "Metavoxel.h"
bool Metavoxel::isLeaf() const {
for (int i = 0; i < CHILD_COUNT; i++) {
if (_children[i]) {
return false;
}
}
return true;
}
Bitstream& operator<<(Bitstream& stream, const Metavoxel& voxel) {
for (int i = 0; i < Metavoxel::CHILD_COUNT; i++) {
const Metavoxel* child = voxel.getChild(i);
if (child) {
stream << true << *child;
} else {
stream << false;
}
}
return stream;
}
Bitstream& operator>>(Bitstream& stream, Metavoxel& voxel) {
for (int i = 0; i < Metavoxel::CHILD_COUNT; i++) {
bool childExists;
stream >> childExists;
Metavoxel* child = voxel.getChild(i);
if (childExists) {
if (!child) {
voxel.setChild(i, new Metavoxel);
}
stream >> *child;
} else if (child) {
voxel.setChild(i, NULL);
}
}
return stream;
}

View file

@ -0,0 +1,38 @@
//
// Metavoxel.h
// metavoxels
//
// Created by Andrzej Kapolka on 12/2/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef __interface__Metavoxel__
#define __interface__Metavoxel__
#include <QScopedPointer>
class Bitstream;
/// A single node in a metavoxel tree.
class Metavoxel {
public:
static const int CHILD_COUNT = 8;
/// Sets the child at the specified index. Note that this object will assume ownership if non-null.
void setChild(int index, Metavoxel* child) { _children[index].reset(child); }
const Metavoxel* getChild(int index) const { return _children[index].data(); }
Metavoxel* getChild(int index) { return _children[index].data(); }
bool isLeaf() const;
private:
QScopedPointer<Metavoxel> _children[CHILD_COUNT];
};
Bitstream& operator<<(Bitstream& stream, const Metavoxel& voxel);
Bitstream& operator>>(Bitstream& stream, Metavoxel& voxel);
#endif /* defined(__interface__Metavoxel__) */