mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
Basic voxel visitation with multiple attributes.
This commit is contained in:
parent
eab9986316
commit
79a2e409a8
3 changed files with 66 additions and 8 deletions
|
@ -10,6 +10,17 @@
|
|||
|
||||
#include "MetavoxelSystem.h"
|
||||
|
||||
class DebugVisitor : public MetavoxelVisitor {
|
||||
public:
|
||||
|
||||
virtual bool visit(const QVector<AttributeValue>& attributeValues);
|
||||
};
|
||||
|
||||
bool DebugVisitor::visit(const QVector<AttributeValue>& attributeValues) {
|
||||
qDebug() << decodeInline<float>(attributeValues.at(0).getValue()) << "\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
void MetavoxelSystem::init() {
|
||||
MetavoxelPath p1;
|
||||
p1 += 0;
|
||||
|
@ -28,5 +39,8 @@ void MetavoxelSystem::init() {
|
|||
AttributeValue value = _data.getAttributeValue(p2, blerp);
|
||||
|
||||
qDebug("fliggedy bloo %g\n", decodeInline<float>(value.getValue()));
|
||||
|
||||
DebugVisitor visitor;
|
||||
_data.visitVoxels(QVector<AttributePointer>() << blerp, visitor);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,51 @@ MetavoxelData::~MetavoxelData() {
|
|||
}
|
||||
}
|
||||
|
||||
void MetavoxelData::visitVoxels(const QVector<Attribute*>& attributes, VoxelVisitor* visitor) {
|
||||
// map attributes to layers, indices
|
||||
class Visitation {
|
||||
public:
|
||||
MetavoxelVisitor& visitor;
|
||||
QVector<MetavoxelNode*> nodes;
|
||||
QVector<AttributeValue> attributeValues;
|
||||
|
||||
void apply();
|
||||
};
|
||||
|
||||
void Visitation::apply() {
|
||||
Visitation nextVisitation = { visitor, QVector<MetavoxelNode*>(nodes.size()), attributeValues };
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
MetavoxelNode* node = nodes.at(i);
|
||||
if (node) {
|
||||
nextVisitation.attributeValues[i] = node->getAttributeValue(attributeValues[i].getAttribute());
|
||||
}
|
||||
}
|
||||
|
||||
if (!visitor.visit(nextVisitation.attributeValues)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MetavoxelNode::CHILD_COUNT; i++) {
|
||||
bool anyChildrenPresent = false;
|
||||
for (int j = 0; j < nodes.size(); j++) {
|
||||
MetavoxelNode* node = nodes.at(j);
|
||||
if ((nextVisitation.nodes[j] = node ? node->getChild(i) : NULL)) {
|
||||
anyChildrenPresent = true;
|
||||
}
|
||||
}
|
||||
if (anyChildrenPresent) {
|
||||
nextVisitation.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MetavoxelData::visitVoxels(const QVector<AttributePointer>& attributes, MetavoxelVisitor& visitor) {
|
||||
// start with the root values/defaults
|
||||
Visitation firstVisitation = { visitor, QVector<MetavoxelNode*>(attributes.size()),
|
||||
QVector<AttributeValue>(attributes.size()) };
|
||||
for (int i = 0; i < attributes.size(); i++) {
|
||||
firstVisitation.nodes[i] = _roots.value(attributes[i]);
|
||||
firstVisitation.attributeValues[i] = attributes[i];
|
||||
}
|
||||
firstVisitation.apply();
|
||||
}
|
||||
|
||||
void MetavoxelData::setAttributeValue(const MetavoxelPath& path, const AttributeValue& attributeValue) {
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
#include <QBitArray>
|
||||
#include <QHash>
|
||||
#include <QScopedPointer>
|
||||
#include <QVector>
|
||||
|
||||
#include "AttributeRegistry.h"
|
||||
|
||||
class MetavoxelNode;
|
||||
class MetavoxelPath;
|
||||
class VoxelVisitor;
|
||||
class MetavoxelVisitor;
|
||||
|
||||
/// The base metavoxel representation shared between server and client.
|
||||
class MetavoxelData {
|
||||
|
@ -27,7 +28,7 @@ public:
|
|||
|
||||
/// Applies the specified function to the contained voxels.
|
||||
/// \param attributes the list of attributes desired
|
||||
void visitVoxels(const QVector<Attribute*>& attributes, VoxelVisitor* visitor);
|
||||
void visitVoxels(const QVector<AttributePointer>& attributes, MetavoxelVisitor& visitor);
|
||||
|
||||
/// Sets the attribute value corresponding to the specified path.
|
||||
void setAttributeValue(const MetavoxelPath& path, const AttributeValue& attributeValue);
|
||||
|
@ -93,13 +94,14 @@ private:
|
|||
QBitArray _array;
|
||||
};
|
||||
|
||||
/// Interface for visitors to voxels.
|
||||
class VoxelVisitor {
|
||||
/// Interface for visitors to metavoxels.
|
||||
class MetavoxelVisitor {
|
||||
public:
|
||||
|
||||
/// Visits a voxel.
|
||||
/// Visits a metavoxel.
|
||||
/// \param attributeValues the values of the desired attributes
|
||||
virtual void visit(const QVector<void*>& attributeValues) = 0;
|
||||
/// \param if true, continue descending; if false, stop
|
||||
virtual bool visit(const QVector<AttributeValue>& attributeValues) = 0;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__MetavoxelData__) */
|
||||
|
|
Loading…
Reference in a new issue