History

Provide the option to display lower detail metavoxel data as points.

Andrzej Kapolka committed 12 years ago

Commit b5b82ed1 parent 049a00b5 files · +122 −91Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 5 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+108−86
@@ -137,15 +137,13 @@ void MetavoxelSystem::render() { · 136 unmodified lines
137137 emit rendering();
138138 }
139139
140−void MetavoxelSystem::updateHermiteDisplay() {
141− if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
142− foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
143− if (node->getType() == NodeType::MetavoxelServer) {
144− QMutexLocker locker(&node->getMutex());
145− MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
146− if (client) {
147− QMetaObject::invokeMethod(client, "refreshVoxelData");
148− }
140+void MetavoxelSystem::refreshVoxelData() {
141+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
142+ if (node->getType() == NodeType::MetavoxelServer) {
143+ QMutexLocker locker(&node->getMutex());
144+ MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
145+ if (client) {
146+ QMetaObject::invokeMethod(client, "refreshVoxelData");
149147 }
150148 }
151149 }
@@ -642,8 +640,47 @@ void PointBuffer::render(bool cursor) { · 490 unmodified lines
642640 _buffer.release();
643641 }
644642
645−VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points) :
646− PointBuffer(points) {
643+VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points, const QVector<glm::vec3>& hermite) :
644+ PointBuffer(points),
645+ _hermite(hermite),
646+ _hermiteCount(hermite.size()) {
647+}
648+
649+static void renderHermiteData(QVector<glm::vec3>& hermite, int hermiteCount, QOpenGLBuffer& hermiteBuffer) {
650+ if (hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
651+ if (!hermiteBuffer.isCreated()) {
652+ hermiteBuffer.create();
653+ hermiteBuffer.bind();
654+ hermiteBuffer.allocate(hermite.constData(), hermite.size() * sizeof(glm::vec3));
655+ hermite.clear();
656+
657+ } else {
658+ hermiteBuffer.bind();
659+ }
660+
661+ glDisableClientState(GL_COLOR_ARRAY);
662+ glDisableClientState(GL_NORMAL_ARRAY);
663+
664+ glVertexPointer(3, GL_FLOAT, 0, 0);
665+
666+ Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind();
667+
668+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
669+ glNormal3f(0.0f, 1.0f, 0.0f);
670+
671+ glLineWidth(2.0f);
672+
673+ glDrawArrays(GL_LINES, 0, hermiteCount);
674+
675+ glLineWidth(1.0f);
676+
677+ DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();
678+
679+ glEnableClientState(GL_COLOR_ARRAY);
680+ glEnableClientState(GL_NORMAL_ARRAY);
681+
682+ hermiteBuffer.release();
683+ }
647684 }
648685
649686 void VoxelPointBuffer::render(bool cursor) {
@@ -656,6 +693,8 @@ void VoxelPointBuffer::render(bool cursor) { · 6 unmodified lines
656693 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
657694
658695 DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();
696+
697+ renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer);
659698 }
660699
661700 const int HeightfieldBuffer::HEIGHT_BORDER = 1;
@@ -1136,40 +1175,7 @@ void VoxelBuffer::render(bool cursor) { · 474 unmodified lines
11361175 _vertexBuffer.release();
11371176 _indexBuffer.release();
11381177
1139− if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
1140− if (!_hermiteBuffer.isCreated()) {
1141− _hermiteBuffer.create();
1142− _hermiteBuffer.bind();
1143− _hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3));
1144− _hermite.clear();
1145−
1146− } else {
1147− _hermiteBuffer.bind();
1148− }
1149−
1150− glDisableClientState(GL_COLOR_ARRAY);
1151− glDisableClientState(GL_NORMAL_ARRAY);
1152−
1153− glVertexPointer(3, GL_FLOAT, 0, 0);
1154−
1155− Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind();
1156−
1157− glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
1158− glNormal3f(0.0f, 1.0f, 0.0f);
1159−
1160− glLineWidth(2.0f);
1161−
1162− glDrawArrays(GL_LINES, 0, _hermiteCount);
1163−
1164− glLineWidth(1.0f);
1165−
1166− DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();
1167−
1168− glEnableClientState(GL_COLOR_ARRAY);
1169− glEnableClientState(GL_NORMAL_ARRAY);
1170−
1171− _hermiteBuffer.release();
1172− }
1178+ renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer);
11731179 }
11741180
11751181 BufferDataAttribute::BufferDataAttribute(const QString& name) :
@@ -1638,11 +1644,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 462 unmodified lines
16381644 if (!info.isLeaf) {
16391645 return DEFAULT_ORDER;
16401646 }
1647+ const int EDGES_PER_CUBE = 12;
1648+
16411649 BufferData* buffer = NULL;
16421650 VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>();
16431651 VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>();
16441652 VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>();
1645− if (color && hermite && material) {
1653+
1654+ if (color && hermite && (material || !Menu::getInstance()->isOptionChecked(MenuOption::LowerDetailAsPoints))) {
16461655 QVector<VoxelPoint> vertices;
16471656 QVector<int> indices;
16481657 QVector<glm::vec3> hermiteSegments;
@@ -1677,7 +1686,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 28 unmodified lines
16771686 QVector<AxisIndex> planeIndices(expanded * expanded);
16781687 QVector<AxisIndex> lastPlaneIndices(expanded * expanded);
16791688
1680− const int EDGES_PER_CUBE = 12;
16811689 EdgeCrossing crossings[EDGES_PER_CUBE];
16821690
16831691 float highest = size - 1.0f;
@@ -2182,6 +2190,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 498 unmodified lines
21822190
21832191 } else if (color && hermite) {
21842192 BufferPointVector points;
2193+ QVector<glm::vec3> hermiteSegments;
21852194
21862195 const QVector<QRgb>& colorContents = color->getContents();
21872196 const QVector<QRgb>& hermiteContents = hermite->getContents();
@@ -2201,6 +2210,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 13 unmodified lines
22012210 const QRgb* hermiteData = hermiteContents.constData();
22022211 int hermiteStride = hermite->getSize() * VoxelHermiteData::EDGE_COUNT;
22032212 int hermiteArea = hermiteStride * hermite->getSize();
2213+ bool displayHermite = Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData);
2214+
2215+ EdgeCrossing crossings[EDGES_PER_CUBE];
22042216
22052217 for (int z = 0; z < limit; z++) {
22062218 const QRgb* colorY = colorZ;
@@ -2218,80 +2230,90 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 11 unmodified lines
22182230 }
22192231 const QRgb* hermiteBase = hermiteData + z * hermiteArea + y * hermiteStride +
22202232 x * VoxelHermiteData::EDGE_COUNT;
2221− glm::vec3 normal;
2222− glm::vec3 position;
22232233 int crossingCount = 0;
22242234 if (a0 != a1) {
22252235 QRgb hermite = hermiteBase[0];
2226− position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f);
2227− normal += unpackNormal(hermite);
2228− crossingCount++;
2236+ EdgeCrossing& crossing = crossings[crossingCount++];
2237+ crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f);
2238+ crossing.normal = unpackNormal(hermite);
22292239 }
22302240 if (a0 != a2) {
22312241 QRgb hermite = hermiteBase[1];
2232− position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2233− normal += unpackNormal(hermite);
2234− crossingCount++;
2242+ EdgeCrossing& crossing = crossings[crossingCount++];
2243+ crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2244+ crossing.normal = unpackNormal(hermite);
22352245 }
22362246 if (a0 != a4) {
22372247 QRgb hermite = hermiteBase[2];
2238− position += glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2239− normal += unpackNormal(hermite);
2240− crossingCount++;
2248+ EdgeCrossing& crossing = crossings[crossingCount++];
2249+ crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2250+ crossing.normal = unpackNormal(hermite);
22412251 }
22422252 if (a1 != a3) {
22432253 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 1];
2244− position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2245− normal += unpackNormal(hermite);
2246− crossingCount++;
2254+ EdgeCrossing& crossing = crossings[crossingCount++];
2255+ crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2256+ crossing.normal = unpackNormal(hermite);
22472257 }
22482258 if (a1 != a5) {
22492259 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 2];
2250− position += glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2251− normal += unpackNormal(hermite);
2252− crossingCount++;
2260+ EdgeCrossing& crossing = crossings[crossingCount++];
2261+ crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2262+ crossing.normal = unpackNormal(hermite);
22532263 }
22542264 if (a2 != a3) {
22552265 QRgb hermite = hermiteBase[hermiteStride];
2256− position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f);
2257− normal += unpackNormal(hermite);
2258− crossingCount++;
2266+ EdgeCrossing& crossing = crossings[crossingCount++];
2267+ crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f);
2268+ crossing.normal = unpackNormal(hermite);
22592269 }
22602270 if (a2 != a6) {
22612271 QRgb hermite = hermiteBase[hermiteStride + 2];
2262− position += glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2263− normal += unpackNormal(hermite);
2264− crossingCount++;
2272+ EdgeCrossing& crossing = crossings[crossingCount++];
2273+ crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2274+ crossing.normal = unpackNormal(hermite);
22652275 }
22662276 if (a3 != a7) {
22672277 QRgb hermite = hermiteBase[hermiteStride + VoxelHermiteData::EDGE_COUNT + 2];
2268− position += glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2269− normal += unpackNormal(hermite);
2270− crossingCount++;
2278+ EdgeCrossing& crossing = crossings[crossingCount++];
2279+ crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2280+ crossing.normal = unpackNormal(hermite);
22712281 }
22722282 if (a4 != a5) {
22732283 QRgb hermite = hermiteBase[hermiteArea];
2274− position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f);
2275− normal += unpackNormal(hermite);
2276− crossingCount++;
2284+ EdgeCrossing& crossing = crossings[crossingCount++];
2285+ crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f);
2286+ crossing.normal = unpackNormal(hermite);
22772287 }
22782288 if (a4 != a6) {
22792289 QRgb hermite = hermiteBase[hermiteArea + 1];
2280− position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2281− normal += unpackNormal(hermite);
2282− crossingCount++;
2290+ EdgeCrossing& crossing = crossings[crossingCount++];
2291+ crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2292+ crossing.normal = unpackNormal(hermite);
22832293 }
22842294 if (a5 != a7) {
22852295 QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1];
2286− position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2287− normal += unpackNormal(hermite);
2288− crossingCount++;
2296+ EdgeCrossing& crossing = crossings[crossingCount++];
2297+ crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2298+ crossing.normal = unpackNormal(hermite);
22892299 }
22902300 if (a6 != a7) {
22912301 QRgb hermite = hermiteBase[hermiteArea + hermiteStride];
2292− position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f);
2293− normal += unpackNormal(hermite);
2294− crossingCount++;
2302+ EdgeCrossing& crossing = crossings[crossingCount++];
2303+ crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f);
2304+ crossing.normal = unpackNormal(hermite);
2305+ }
2306+ glm::vec3 normal;
2307+ glm::vec3 position;
2308+ for (int i = 0; i < crossingCount; i++) {
2309+ const EdgeCrossing& crossing = crossings[i];
2310+ position += crossing.point;
2311+ normal += crossing.normal;
2312+ if (displayHermite) {
2313+ glm::vec3 base = glm::vec3(minimum) + (glm::vec3(x, y, z) + crossing.point) * step;
2314+ hermiteSegments.append(base);
2315+ hermiteSegments.append(base + crossing.normal * step);
2316+ }
22952317 }
22962318 normal = safeNormalize(normal);
22972319 BufferPoint point = { minimum + (glm::vec4(x, y, z, 1.0f) +
@@ -2309,7 +2331,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 11 unmodified lines
23092331 }
23102332 colorZ += area;
23112333 }
2312− buffer = new VoxelPointBuffer(points);
2334+ buffer = new VoxelPointBuffer(points, hermiteSegments);
23132335 }
23142336 BufferDataPointer pointer(buffer);
23152337 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));