From c24e32ce06259c88bf40e23ac8b2cc5c45ffdd2e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 4 Dec 2013 12:32:46 -0800 Subject: [PATCH] basic ParticleTree and ParticleTreeElement classes --- libraries/octree/src/Octree.h | 1 - libraries/particles/src/ParticleTree.cpp | 20 +++++- libraries/particles/src/ParticleTree.h | 36 +++++++++++ .../particles/src/ParticleTreeElement.cpp | 64 +++++++++++++++++++ libraries/particles/src/ParticleTreeElement.h | 47 ++++++++++++++ 5 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 libraries/particles/src/ParticleTree.h create mode 100644 libraries/particles/src/ParticleTreeElement.cpp create mode 100644 libraries/particles/src/ParticleTreeElement.h diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index 1cdd789a3c..36588efb9e 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -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, diff --git a/libraries/particles/src/ParticleTree.cpp b/libraries/particles/src/ParticleTree.cpp index a8215ba4cf..99580e974b 100644 --- a/libraries/particles/src/ParticleTree.cpp +++ b/libraries/particles/src/ParticleTree.cpp @@ -1 +1,19 @@ -// ParticleTree.cpp \ No newline at end of file +// +// 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; +} + diff --git a/libraries/particles/src/ParticleTree.h b/libraries/particles/src/ParticleTree.h new file mode 100644 index 0000000000..821e1b0b49 --- /dev/null +++ b/libraries/particles/src/ParticleTree.h @@ -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 +#include +#include +#include +#include +#include +#include + +#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__) */ diff --git a/libraries/particles/src/ParticleTreeElement.cpp b/libraries/particles/src/ParticleTreeElement.cpp new file mode 100644 index 0000000000..81bc491ade --- /dev/null +++ b/libraries/particles/src/ParticleTreeElement.cpp @@ -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 +#include +#include + +#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; +} + diff --git a/libraries/particles/src/ParticleTreeElement.h b/libraries/particles/src/ParticleTreeElement.h new file mode 100644 index 0000000000..8a35d6e622 --- /dev/null +++ b/libraries/particles/src/ParticleTreeElement.h @@ -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 +#include +#include + +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__) */ \ No newline at end of file