Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -158,13 +158,13 @@ int RenderVisitor::visit(MetavoxelInfo& info) { · 157 unmodified lines | |||
| 158 | return DEFAULT_ORDER; | 158 | return DEFAULT_ORDER; |
| 159 | } | 159 | } |
| 160 | static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue< | 160 | static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue< |
| 161 | SharedObjectPointer>().data())->getImplementation()->render(info); | 161 | SharedObjectPointer>().data())->getImplementation()->render(*_data, info, _lod); |
| 162 | return STOP_RECURSION; | 162 | return STOP_RECURSION; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | void MetavoxelSystem::render() { | 165 | void MetavoxelSystem::render() { |
| 166 | RenderVisitor renderVisitor(getLOD()); | 166 | RenderVisitor renderVisitor(getLOD()); |
| 167 | guide(renderVisitor); | 167 | guideToAugmented(renderVisitor); |
| 168 | 168 | ||
| 169 | int viewport[4]; | 169 | int viewport[4]; |
| 170 | glGetIntegerv(GL_VIEWPORT, viewport); | 170 | glGetIntegerv(GL_VIEWPORT, viewport); |
| @@ -227,6 +227,18 @@ MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) { · 56 unmodified lines | |||
| 227 | return new MetavoxelSystemClient(node, _updater); | 227 | return new MetavoxelSystemClient(node, _updater); |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor) { | ||
| 231 | foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { | ||
| 232 | if (node->getType() == NodeType::MetavoxelServer) { | ||
| 233 | QMutexLocker locker(&node->getMutex()); | ||
| 234 | MetavoxelSystemClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData()); | ||
| 235 | if (client) { | ||
| 236 | client->getAugmentedData().guide(visitor); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 230 | MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) : | 242 | MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) : |
| 231 | MetavoxelClient(node, updater), | 243 | MetavoxelClient(node, updater), |
| 232 | _pointCount(0) { | 244 | _pointCount(0) { |
| @@ -259,6 +271,16 @@ void MetavoxelSystemClient::setPoints(const BufferPointVector& points) { · 26 unmodified lines | |||
| 259 | 271 | ||
| 260 | } | 272 | } |
| 261 | 273 | ||
| 274 | void MetavoxelSystemClient::setAugmentedData(const MetavoxelData& data) { | ||
| 275 | QWriteLocker locker(&_augmentedDataLock); | ||
| 276 | _augmentedData = data; | ||
| 277 | } | ||
| 278 | |||
| 279 | MetavoxelData MetavoxelSystemClient::getAugmentedData() { | ||
| 280 | QReadLocker locker(&_augmentedDataLock); | ||
| 281 | return _augmentedData; | ||
| 282 | } | ||
| 283 | |||
| 262 | int MetavoxelSystemClient::parseData(const QByteArray& packet) { | 284 | int MetavoxelSystemClient::parseData(const QByteArray& packet) { |
| 263 | // process through sequencer | 285 | // process through sequencer |
| 264 | QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet)); | 286 | QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet)); |
| @@ -426,6 +448,67 @@ void PointBufferBuilder::run() { · 161 unmodified lines | |||
| 426 | qDebug() << "collect" << (QDateTime::currentMSecsSinceEpoch() - now); | 448 | qDebug() << "collect" << (QDateTime::currentMSecsSinceEpoch() - now); |
| 427 | } | 449 | } |
| 428 | 450 | ||
| 451 | class AugmentVisitor : public MetavoxelVisitor { | ||
| 452 | public: | ||
| 453 | |||
| 454 | AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData); | ||
| 455 | |||
| 456 | virtual int visit(MetavoxelInfo& info); | ||
| 457 | |||
| 458 | private: | ||
| 459 | |||
| 460 | const MetavoxelData& _previousData; | ||
| 461 | }; | ||
| 462 | |||
| 463 | AugmentVisitor::AugmentVisitor(const MetavoxelLOD& lod, const MetavoxelData& previousData) : | ||
| 464 | MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getRendererAttribute(), | ||
| 465 | QVector<AttributePointer>(), lod), | ||
| 466 | _previousData(previousData) { | ||
| 467 | } | ||
| 468 | |||
| 469 | int AugmentVisitor::visit(MetavoxelInfo& info) { | ||
| 470 | if (!info.isLeaf) { | ||
| 471 | return DEFAULT_ORDER; | ||
| 472 | } | ||
| 473 | static_cast<MetavoxelRenderer*>(info.inputValues.at(0).getInlineValue< | ||
| 474 | SharedObjectPointer>().data())->getImplementation()->augment(*_data, _previousData, info, _lod); | ||
| 475 | return STOP_RECURSION; | ||
| 476 | } | ||
| 477 | |||
| 478 | class Augmenter : public QRunnable { | ||
| 479 | public: | ||
| 480 | |||
| 481 | Augmenter(const SharedNodePointer& node, const MetavoxelData& data, | ||
| 482 | const MetavoxelData& previousData, const MetavoxelLOD& lod); | ||
| 483 | |||
| 484 | virtual void run(); | ||
| 485 | |||
| 486 | private: | ||
| 487 | |||
| 488 | QWeakPointer<Node> _node; | ||
| 489 | MetavoxelData _data; | ||
| 490 | MetavoxelData _previousData; | ||
| 491 | MetavoxelLOD _lod; | ||
| 492 | }; | ||
| 493 | |||
| 494 | Augmenter::Augmenter(const SharedNodePointer& node, const MetavoxelData& data, | ||
| 495 | const MetavoxelData& previousData, const MetavoxelLOD& lod) : | ||
| 496 | _node(node), | ||
| 497 | _data(data), | ||
| 498 | _previousData(previousData), | ||
| 499 | _lod(lod) { | ||
| 500 | } | ||
| 501 | |||
| 502 | void Augmenter::run() { | ||
| 503 | SharedNodePointer node = _node; | ||
| 504 | if (!node) { | ||
| 505 | return; | ||
| 506 | } | ||
| 507 | AugmentVisitor visitor(_lod, _previousData); | ||
| 508 | _data.guide(visitor); | ||
| 509 | QMetaObject::invokeMethod(node.data(), "setAugmentedData", Q_ARG(const MetavoxelData&, _data)); | ||
| 510 | } | ||
| 511 | |||
| 429 | void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { | 512 | void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { |
| 430 | MetavoxelClient::dataChanged(oldData); | 513 | MetavoxelClient::dataChanged(oldData); |
| 431 | 514 | ||
| @@ -442,6 +525,8 @@ void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { · 10 unmodified lines | |||
| 442 | _data.guide(builder); | 525 | _data.guide(builder); |
| 443 | } */ | 526 | } */ |
| 444 | QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD)); | 527 | QThreadPool::globalInstance()->start(new PointBufferBuilder(_node, _data, _remoteDataLOD)); |
| 528 | |||
| 529 | QThreadPool::globalInstance()->start(new Augmenter(_node, _data, getAugmentedData(), _remoteDataLOD)); | ||
| 445 | } | 530 | } |
| 446 | 531 | ||
| 447 | void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { | 532 | void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { |
| @@ -505,7 +590,56 @@ AttributeValue PointBufferAttribute::inherit(const AttributeValue& parentValue) · 57 unmodified lines | |||
| 505 | PointMetavoxelRendererImplementation::PointMetavoxelRendererImplementation() { | 590 | PointMetavoxelRendererImplementation::PointMetavoxelRendererImplementation() { |
| 506 | } | 591 | } |
| 507 | 592 | ||
| 508 | void PointMetavoxelRendererImplementation::render(MetavoxelInfo& info) { | 593 | class PointAugmentVisitor : public MetavoxelVisitor { |
| 594 | public: | ||
| 595 | |||
| 596 | PointAugmentVisitor(const MetavoxelLOD& lod); | ||
| 597 | |||
| 598 | virtual int visit(MetavoxelInfo& info); | ||
| 599 | }; | ||
| 600 | |||
| 601 | PointAugmentVisitor::PointAugmentVisitor(const MetavoxelLOD& lod) : | ||
| 602 | MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() << | ||
| 603 | AttributeRegistry::getInstance()->getNormalAttribute(), QVector<AttributePointer>() << | ||
| 604 | Application::getInstance()->getMetavoxels()->getPointBufferAttribute(), lod) { | ||
| 605 | } | ||
| 606 | |||
| 607 | int PointAugmentVisitor::visit(MetavoxelInfo& info) { | ||
| 608 | if (!info.isLeaf) { | ||
| 609 | return DEFAULT_ORDER; | ||
| 610 | } | ||
| 611 | return STOP_RECURSION; | ||
| 612 | } | ||
| 613 | |||
| 614 | void PointMetavoxelRendererImplementation::augment(MetavoxelData& data, const MetavoxelData& previous, | ||
| 615 | MetavoxelInfo& info, const MetavoxelLOD& lod) { | ||
| 616 | PointAugmentVisitor visitor(lod); | ||
| 617 | data.guideToDifferent(previous, visitor, &info); | ||
| 618 | } | ||
| 619 | |||
| 620 | class PointRenderVisitor : public MetavoxelVisitor { | ||
| 621 | public: | ||
| 622 | |||
| 623 | PointRenderVisitor(const MetavoxelLOD& lod); | ||
| 624 | |||
| 625 | virtual int visit(MetavoxelInfo& info); | ||
| 626 | }; | ||
| 627 | |||
| 628 | PointRenderVisitor::PointRenderVisitor(const MetavoxelLOD& lod) : | ||
| 629 | MetavoxelVisitor(QVector<AttributePointer>() << Application::getInstance()->getMetavoxels()->getPointBufferAttribute(), | ||
| 630 | QVector<AttributePointer>(), lod) { | ||
| 631 | } | ||
| 632 | |||
| 633 | int PointRenderVisitor::visit(MetavoxelInfo& info) { | ||
| 634 | if (!info.isLeaf) { | ||
| 635 | return DEFAULT_ORDER; | ||
| 636 | } | ||
| 637 | return STOP_RECURSION; | ||
| 638 | } | ||
| 639 | |||
| 640 | void PointMetavoxelRendererImplementation::render(MetavoxelData& data, MetavoxelInfo& info, const MetavoxelLOD& lod) { | ||
| 641 | PointRenderVisitor visitor(lod); | ||
| 642 | data.guide(visitor, &info); | ||
| 509 | } | 643 | } |
| 510 | 644 | ||
| 511 | static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { | 645 | static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { |