basic ParticleTree and ParticleTreeElement classes

This commit is contained in:
ZappoMan 2013-12-04 12:32:46 -08:00
parent 2b27c91550
commit c24e32ce06
5 changed files with 166 additions and 2 deletions

View file

@ -250,7 +250,6 @@ public slots:
protected:
void deleteOctalCodeFromTreeRecursion(OctreeElement* node, void* extraData);
void readCodeColorBufferToTreeRecursion(OctreeElement* node, void* extraData);
int encodeTreeBitstreamRecursion(OctreeElement* node,
OctreePacketData* packetData, OctreeElementBag& bag,

View file

@ -1 +1,19 @@
// ParticleTree.cpp
//
// ParticleTree.cpp
// hifi
//
// Created by Brad Hefta-Gaub on 12/4/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include "ParticleTree.h"
ParticleTree::ParticleTree(bool shouldReaverage) : Octree(shouldReaverage) {
_rootNode = createNewElement();
}
ParticleTreeElement* ParticleTree::createNewElement(unsigned char * octalCode) const {
ParticleTreeElement* newElement = new ParticleTreeElement(octalCode);
return newElement;
}

View file

@ -0,0 +1,36 @@
//
// ParticleTree.h
// hifi
//
// Created by Brad Hefta-Gaub on 12/4/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef __hifi__ParticleTree__
#define __hifi__ParticleTree__
#include <set>
#include <SimpleMovingAverage.h>
#include <OctreeElementBag.h>
#include <Octree.h>
#include <CoverageMap.h>
#include <JurisdictionMap.h>
#include <ViewFrustum.h>
#include "ParticleTreeElement.h"
#include "VoxelPacketData.h"
#include "VoxelSceneStats.h"
#include "VoxelEditPacketSender.h"
class ReadCodeColorBufferToTreeArgs;
class ParticleTree : public Octree {
Q_OBJECT
public:
ParticleTree(bool shouldReaverage = false);
virtual ParticleTreeElement* createNewElement(unsigned char * octalCode = NULL) const;
ParticleTreeElement* getRoot() { return (ParticleTreeElement*)_rootNode; }
private:
};
#endif /* defined(__hifi__ParticleTree__) */

View file

@ -0,0 +1,64 @@
//
// ParticleTreeElement.cpp
// hifi
//
// Created by Brad Hefta-Gaub on 12/4/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#include <QtCore/QDebug>
#include <NodeList.h>
#include <PerfStat.h>
#include "ParticleTree.h"
#include "ParticleTreeElement.h"
ParticleTreeElement::ParticleTreeElement(unsigned char* octalCode) : OctreeElement() {
init(octalCode);
};
ParticleTreeElement::~ParticleTreeElement() {
_voxelMemoryUsage -= sizeof(ParticleTreeElement);
}
// This will be called primarily on addChildAt(), which means we're adding a child of our
// own type to our own tree. This means we should initialize that child with any tree and type
// specific settings that our children must have. One example is out VoxelSystem, which
// we know must match ours.
OctreeElement* ParticleTreeElement::createNewElement(unsigned char* octalCode) const {
ParticleTreeElement* newChild = new ParticleTreeElement(octalCode);
return newChild;
}
void ParticleTreeElement::init(unsigned char* octalCode) {
OctreeElement::init(octalCode);
_voxelMemoryUsage += sizeof(ParticleTreeElement);
}
bool ParticleTreeElement::appendElementData(OctreePacketData* packetData) const {
// will write to the encoded stream all of the contents of this element
return true;
}
int ParticleTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args) {
// will read from the encoded stream all of the contents of this element
return 0;
}
// will average a "common reduced LOD view" from the the child elements...
void ParticleTreeElement::calculateAverageFromChildren() {
// nothing to do here yet...
}
// will detect if children are leaves AND collapsable into the parent node
// and in that case will collapse children and make this node
// a leaf, returns TRUE if all the leaves are collapsed into a
// single node
bool ParticleTreeElement::collapseChildren() {
// nothing to do here yet...
return false;
}

View file

@ -0,0 +1,47 @@
//
// ParticleTreeElement.h
// hifi
//
// Created by Brad Hefta-Gaub on 12/4/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
//
#ifndef __hifi__ParticleTreeElement__
#define __hifi__ParticleTreeElement__
#include <QReadWriteLock>
#include <OctreeElement.h>
#include <SharedUtil.h>
class ParticleTree;
class ParticleTreeElement;
class ParticleTreeElement : public OctreeElement {
friend class ParticleTree; // to allow createElement to new us...
ParticleTreeElement(unsigned char* octalCode = NULL);
virtual OctreeElement* createNewElement(unsigned char* octalCode = NULL) const;
public:
virtual ~ParticleTreeElement();
virtual void init(unsigned char * octalCode);
virtual bool hasContent() const;
virtual void splitChildren() {}
virtual bool requiresSplit() const { return false; }
virtual bool appendElementData(OctreePacketData* packetData) const;
virtual int readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args);
virtual void calculateAverageFromChildren();
virtual bool collapseChildren();
virtual bool isRendered() const;
// type safe versions of OctreeElement methods
ParticleTreeElement* getChildAtIndex(int index) { return (ParticleTreeElement*)OctreeElement::getChildAtIndex(index); }
ParticleTreeElement* addChildAtIndex(int index) { return (ParticleTreeElement*)OctreeElement::addChildAtIndex(index); }
protected:
};
#endif /* defined(__hifi__ParticleTreeElement__) */