More work on stream testing, fixed bug with differently-ordered edits.

This commit is contained in:
Andrzej Kapolka 2014-06-20 14:08:39 -07:00
parent 24f535e02d
commit ce778f47b1
2 changed files with 21 additions and 8 deletions

View file

@ -1153,8 +1153,23 @@ int MetavoxelVisitor::encodeOrder(const glm::vec3& direction) {
indexDistances.at(6).index, indexDistances.at(7).index); indexDistances.at(6).index, indexDistances.at(7).index);
} }
const int ORDER_ELEMENT_BITS = 3;
const int ORDER_ELEMENT_MASK = (1 << ORDER_ELEMENT_BITS) - 1;
int MetavoxelVisitor::encodeRandomOrder() { int MetavoxelVisitor::encodeRandomOrder() {
return DEFAULT_ORDER; // see http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_.22inside-out.22_algorithm
int order;
int randomValues = rand();
for (int i = 0, iShift = 0; i < MetavoxelNode::CHILD_COUNT; i++, iShift += ORDER_ELEMENT_BITS) {
int j = (randomValues >> iShift) % (i + 1);
int jShift = j * ORDER_ELEMENT_BITS;
if (j != i) {
int jValue = (order >> jShift) & ORDER_ELEMENT_MASK;
order = (order & ~(ORDER_ELEMENT_MASK << iShift)) | (jValue << iShift);
}
order = (order & ~(ORDER_ELEMENT_MASK << jShift)) | (i << jShift);
}
return order;
} }
const int MetavoxelVisitor::DEFAULT_ORDER = encodeOrder(0, 1, 2, 3, 4, 5, 6, 7); const int MetavoxelVisitor::DEFAULT_ORDER = encodeOrder(0, 1, 2, 3, 4, 5, 6, 7);
@ -1350,8 +1365,6 @@ bool DefaultMetavoxelGuide::guide(MetavoxelVisitation& visitation) {
QVector<OwnedAttributeValue>(visitation.outputNodes.size()) } }; QVector<OwnedAttributeValue>(visitation.outputNodes.size()) } };
for (int i = 0; i < MetavoxelNode::CHILD_COUNT; i++) { for (int i = 0; i < MetavoxelNode::CHILD_COUNT; i++) {
// the encoded order tells us the child indices for each iteration // the encoded order tells us the child indices for each iteration
const int ORDER_ELEMENT_BITS = 3;
const int ORDER_ELEMENT_MASK = (1 << ORDER_ELEMENT_BITS) - 1;
int index = encodedOrder & ORDER_ELEMENT_MASK; int index = encodedOrder & ORDER_ELEMENT_MASK;
encodedOrder >>= ORDER_ELEMENT_BITS; encodedOrder >>= ORDER_ELEMENT_BITS;
for (int j = 0; j < visitation.inputNodes.size(); j++) { for (int j = 0; j < visitation.inputNodes.size(); j++) {
@ -1392,7 +1405,7 @@ bool DefaultMetavoxelGuide::guide(MetavoxelVisitation& visitation) {
} }
} }
MetavoxelNode* node = visitation.outputNodes.at(j); MetavoxelNode* node = visitation.outputNodes.at(j);
MetavoxelNode* child = node->getChild(i); MetavoxelNode* child = node->getChild(index);
if (child) { if (child) {
child->decrementReferenceCount(value.getAttribute()); child->decrementReferenceCount(value.getAttribute());
} else { } else {

View file

@ -598,17 +598,17 @@ public:
private: private:
bool _finished; int _mutationsRemaining;
}; };
MutateVisitor::MutateVisitor() : MutateVisitor::MutateVisitor() :
MetavoxelVisitor(QVector<AttributePointer>(), MetavoxelVisitor(QVector<AttributePointer>(),
QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute()), QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute()),
_finished(false) { _mutationsRemaining(randIntInRange(2, 4)) {
} }
int MutateVisitor::visit(MetavoxelInfo& info) { int MutateVisitor::visit(MetavoxelInfo& info) {
if (_finished) { if (_mutationsRemaining <= 0) {
return STOP_RECURSION; return STOP_RECURSION;
} }
if (info.size > MAXIMUM_LEAF_SIZE || (info.size > MINIMUM_LEAF_SIZE && randomBoolean())) { if (info.size > MAXIMUM_LEAF_SIZE || (info.size > MINIMUM_LEAF_SIZE && randomBoolean())) {
@ -616,7 +616,7 @@ int MutateVisitor::visit(MetavoxelInfo& info) {
} }
info.outputValues[0] = OwnedAttributeValue(_outputs.at(0), encodeInline<QRgb>(qRgb(randIntInRange(0, 255), info.outputValues[0] = OwnedAttributeValue(_outputs.at(0), encodeInline<QRgb>(qRgb(randIntInRange(0, 255),
randIntInRange(0, 255), randIntInRange(0, 255)))); randIntInRange(0, 255), randIntInRange(0, 255))));
_finished = true; _mutationsRemaining--;
return STOP_RECURSION; return STOP_RECURSION;
} }