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
137 emit rendering();137 emit rendering();
138}138}
139 139
140void MetavoxelSystem::updateHermiteDisplay() {140void MetavoxelSystem::refreshVoxelData() {
141 if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {141 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
142 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {142 if (node->getType() == NodeType::MetavoxelServer) {
143 if (node->getType() == NodeType::MetavoxelServer) {143 QMutexLocker locker(&node->getMutex());
144 QMutexLocker locker(&node->getMutex());144 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
145 MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());145 if (client) {
146 if (client) {146 QMetaObject::invokeMethod(client, "refreshVoxelData");
147 QMetaObject::invokeMethod(client, "refreshVoxelData");
148 }
149 }147 }
150 }148 }
151 }149 }
@@ -642,8 +640,47 @@ void PointBuffer::render(bool cursor) { · 490 unmodified lines
642 _buffer.release();640 _buffer.release();
643}641}
644 642
645VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points) :643VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points, const QVector<glm::vec3>& hermite) :
646 PointBuffer(points) {644 PointBuffer(points),
645 _hermite(hermite),
646 _hermiteCount(hermite.size()) {
647}
648
649static 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 }
647}684}
648 685
649void VoxelPointBuffer::render(bool cursor) {686void VoxelPointBuffer::render(bool cursor) {
@@ -656,6 +693,8 @@ void VoxelPointBuffer::render(bool cursor) { · 6 unmodified lines
656 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);693 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
657 694
658 DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();695 DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();
696
697 renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer);
659}698}
660 699
661const int HeightfieldBuffer::HEIGHT_BORDER = 1;700const int HeightfieldBuffer::HEIGHT_BORDER = 1;
@@ -1136,40 +1175,7 @@ void VoxelBuffer::render(bool cursor) { · 474 unmodified lines
1136 _vertexBuffer.release();1175 _vertexBuffer.release();
1137 _indexBuffer.release();1176 _indexBuffer.release();
1138 1177
1139 if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {1178 renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer);
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 }
1173}1179}
1174 1180
1175BufferDataAttribute::BufferDataAttribute(const QString& name) :1181BufferDataAttribute::BufferDataAttribute(const QString& name) :
@@ -1638,11 +1644,14 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 462 unmodified lines
1638 if (!info.isLeaf) {1644 if (!info.isLeaf) {
1639 return DEFAULT_ORDER;1645 return DEFAULT_ORDER;
1640 }1646 }
1647 const int EDGES_PER_CUBE = 12;
1648
1641 BufferData* buffer = NULL;1649 BufferData* buffer = NULL;
1642 VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>();1650 VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>();
1643 VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>();1651 VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>();
1644 VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>();1652 VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>();
1645 if (color && hermite && material) {1653
1654 if (color && hermite && (material || !Menu::getInstance()->isOptionChecked(MenuOption::LowerDetailAsPoints))) {
1646 QVector<VoxelPoint> vertices;1655 QVector<VoxelPoint> vertices;
1647 QVector<int> indices;1656 QVector<int> indices;
1648 QVector<glm::vec3> hermiteSegments;1657 QVector<glm::vec3> hermiteSegments;
@@ -1677,7 +1686,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 28 unmodified lines
1677 QVector<AxisIndex> planeIndices(expanded * expanded);1686 QVector<AxisIndex> planeIndices(expanded * expanded);
1678 QVector<AxisIndex> lastPlaneIndices(expanded * expanded);1687 QVector<AxisIndex> lastPlaneIndices(expanded * expanded);
1679 1688
1680 const int EDGES_PER_CUBE = 12;
1681 EdgeCrossing crossings[EDGES_PER_CUBE];1689 EdgeCrossing crossings[EDGES_PER_CUBE];
1682 1690
1683 float highest = size - 1.0f;1691 float highest = size - 1.0f;
@@ -2182,6 +2190,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 498 unmodified lines
2182 2190
2183 } else if (color && hermite) {2191 } else if (color && hermite) {
2184 BufferPointVector points;2192 BufferPointVector points;
2193 QVector<glm::vec3> hermiteSegments;
2185 2194
2186 const QVector<QRgb>& colorContents = color->getContents();2195 const QVector<QRgb>& colorContents = color->getContents();
2187 const QVector<QRgb>& hermiteContents = hermite->getContents();2196 const QVector<QRgb>& hermiteContents = hermite->getContents();
@@ -2201,6 +2210,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 13 unmodified lines
2201 const QRgb* hermiteData = hermiteContents.constData();2210 const QRgb* hermiteData = hermiteContents.constData();
2202 int hermiteStride = hermite->getSize() * VoxelHermiteData::EDGE_COUNT;2211 int hermiteStride = hermite->getSize() * VoxelHermiteData::EDGE_COUNT;
2203 int hermiteArea = hermiteStride * hermite->getSize();2212 int hermiteArea = hermiteStride * hermite->getSize();
2213 bool displayHermite = Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData);
2214
2215 EdgeCrossing crossings[EDGES_PER_CUBE];
2204 2216
2205 for (int z = 0; z < limit; z++) {2217 for (int z = 0; z < limit; z++) {
2206 const QRgb* colorY = colorZ;2218 const QRgb* colorY = colorZ;
@@ -2218,80 +2230,90 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 11 unmodified lines
2218 }2230 }
2219 const QRgb* hermiteBase = hermiteData + z * hermiteArea + y * hermiteStride +2231 const QRgb* hermiteBase = hermiteData + z * hermiteArea + y * hermiteStride +
2220 x * VoxelHermiteData::EDGE_COUNT;2232 x * VoxelHermiteData::EDGE_COUNT;
2221 glm::vec3 normal;
2222 glm::vec3 position;
2223 int crossingCount = 0;2233 int crossingCount = 0;
2224 if (a0 != a1) {2234 if (a0 != a1) {
2225 QRgb hermite = hermiteBase[0];2235 QRgb hermite = hermiteBase[0];
2226 position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f);2236 EdgeCrossing& crossing = crossings[crossingCount++];
2227 normal += unpackNormal(hermite);2237 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f);
2228 crossingCount++;2238 crossing.normal = unpackNormal(hermite);
2229 }2239 }
2230 if (a0 != a2) {2240 if (a0 != a2) {
2231 QRgb hermite = hermiteBase[1];2241 QRgb hermite = hermiteBase[1];
2232 position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);2242 EdgeCrossing& crossing = crossings[crossingCount++];
2233 normal += unpackNormal(hermite);2243 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2234 crossingCount++;2244 crossing.normal = unpackNormal(hermite);
2235 }2245 }
2236 if (a0 != a4) {2246 if (a0 != a4) {
2237 QRgb hermite = hermiteBase[2];2247 QRgb hermite = hermiteBase[2];
2238 position += glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);2248 EdgeCrossing& crossing = crossings[crossingCount++];
2239 normal += unpackNormal(hermite);2249 crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2240 crossingCount++;2250 crossing.normal = unpackNormal(hermite);
2241 }2251 }
2242 if (a1 != a3) {2252 if (a1 != a3) {
2243 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 1];2253 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 1];
2244 position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);2254 EdgeCrossing& crossing = crossings[crossingCount++];
2245 normal += unpackNormal(hermite);2255 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2246 crossingCount++;2256 crossing.normal = unpackNormal(hermite);
2247 }2257 }
2248 if (a1 != a5) {2258 if (a1 != a5) {
2249 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 2];2259 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 2];
2250 position += glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);2260 EdgeCrossing& crossing = crossings[crossingCount++];
2251 normal += unpackNormal(hermite);2261 crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2252 crossingCount++;2262 crossing.normal = unpackNormal(hermite);
2253 }2263 }
2254 if (a2 != a3) {2264 if (a2 != a3) {
2255 QRgb hermite = hermiteBase[hermiteStride];2265 QRgb hermite = hermiteBase[hermiteStride];
2256 position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f);2266 EdgeCrossing& crossing = crossings[crossingCount++];
2257 normal += unpackNormal(hermite);2267 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f);
2258 crossingCount++;2268 crossing.normal = unpackNormal(hermite);
2259 }2269 }
2260 if (a2 != a6) {2270 if (a2 != a6) {
2261 QRgb hermite = hermiteBase[hermiteStride + 2];2271 QRgb hermite = hermiteBase[hermiteStride + 2];
2262 position += glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);2272 EdgeCrossing& crossing = crossings[crossingCount++];
2263 normal += unpackNormal(hermite);2273 crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2264 crossingCount++;2274 crossing.normal = unpackNormal(hermite);
2265 }2275 }
2266 if (a3 != a7) {2276 if (a3 != a7) {
2267 QRgb hermite = hermiteBase[hermiteStride + VoxelHermiteData::EDGE_COUNT + 2];2277 QRgb hermite = hermiteBase[hermiteStride + VoxelHermiteData::EDGE_COUNT + 2];
2268 position += glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);2278 EdgeCrossing& crossing = crossings[crossingCount++];
2269 normal += unpackNormal(hermite); 2279 crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2270 crossingCount++;2280 crossing.normal = unpackNormal(hermite);
2271 }2281 }
2272 if (a4 != a5) {2282 if (a4 != a5) {
2273 QRgb hermite = hermiteBase[hermiteArea];2283 QRgb hermite = hermiteBase[hermiteArea];
2274 position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f);2284 EdgeCrossing& crossing = crossings[crossingCount++];
2275 normal += unpackNormal(hermite);2285 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f);
2276 crossingCount++;2286 crossing.normal = unpackNormal(hermite);
2277 }2287 }
2278 if (a4 != a6) {2288 if (a4 != a6) {
2279 QRgb hermite = hermiteBase[hermiteArea + 1];2289 QRgb hermite = hermiteBase[hermiteArea + 1];
2280 position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);2290 EdgeCrossing& crossing = crossings[crossingCount++];
2281 normal += unpackNormal(hermite);2291 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2282 crossingCount++;2292 crossing.normal = unpackNormal(hermite);
2283 }2293 }
2284 if (a5 != a7) {2294 if (a5 != a7) {
2285 QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1];2295 QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1];
2286 position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);2296 EdgeCrossing& crossing = crossings[crossingCount++];
2287 normal += unpackNormal(hermite);2297 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2288 crossingCount++;2298 crossing.normal = unpackNormal(hermite);
2289 }2299 }
2290 if (a6 != a7) {2300 if (a6 != a7) {
2291 QRgb hermite = hermiteBase[hermiteArea + hermiteStride];2301 QRgb hermite = hermiteBase[hermiteArea + hermiteStride];
2292 position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f);2302 EdgeCrossing& crossing = crossings[crossingCount++];
2293 normal += unpackNormal(hermite);2303 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f);
2294 crossingCount++;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 }
2295 }2317 }
2296 normal = safeNormalize(normal);2318 normal = safeNormalize(normal);
2297 BufferPoint point = { minimum + (glm::vec4(x, y, z, 1.0f) +2319 BufferPoint point = { minimum + (glm::vec4(x, y, z, 1.0f) +
@@ -2309,7 +2331,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 11 unmodified lines
2309 }2331 }
2310 colorZ += area;2332 colorZ += area;
2311 }2333 }
2312 buffer = new VoxelPointBuffer(points);2334 buffer = new VoxelPointBuffer(points, hermiteSegments);
2313 }2335 }
2314 BufferDataPointer pointer(buffer);2336 BufferDataPointer pointer(buffer);
2315 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));2337 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));