diff --git a/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.cpp b/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.cpp index 075f05b3cdaa90dc13635972e7d95a9f20fea4dc..58b14a230c17340f897e7625fe4b7c638cc37415 100644 --- a/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.cpp +++ b/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.cpp @@ -49,6 +49,12 @@ namespace armarx::viz::coin ARMARX_INFO << "Loading robot from " << fullFilename; result = VirtualRobot::RobotIO::loadRobot(fullFilename, loadMode); result->setThreadsafe(false); + // HACK: Disable visualization updates to time + for (auto& node : result->getRobotNodes()) + { + node->setUpdateVisualization(false); + node->setUpdateCollisionModel(false); + } } catch (std::exception const& ex) { @@ -56,6 +62,7 @@ namespace armarx::viz::coin << "\nReason: " << ex.what(); } + return result; } @@ -99,6 +106,8 @@ namespace armarx::viz::coin bool VisualizationRobot::update(ElementType const& element) { + IceUtil::Time time_start = IceUtil::Time::now(); + bool robotChanged = loaded.project != element.project || loaded.filename != element.filename; if (robotChanged) { @@ -113,12 +122,15 @@ namespace armarx::viz::coin << "\nFilename: " << element.filename; return true; } + IceUtil::Time time_load = IceUtil::Time::now(); + bool drawStyleChanged = loadedDrawStyle != element.drawStyle; if (robotChanged || drawStyleChanged) { recreateVisualizationNodes(element.drawStyle); loadedDrawStyle = element.drawStyle; } + IceUtil::Time time_style = IceUtil::Time::now(); // Set pose, configuration and so on @@ -132,8 +144,9 @@ namespace armarx::viz::coin // robot.setGlobalPose(pose, false); robot.setJointValues(element.jointValues); + IceUtil::Time time_set = IceUtil::Time::now(); - if (loadedDrawStyle & ModelDrawStyle_OVERRIDE_COLOR) + if (loadedDrawStyle & ModelDrawStyle::OVERRIDE_COLOR) { int numChildren = node->getNumChildren(); for (int i = 0; i < numChildren; i++) @@ -157,6 +170,13 @@ namespace armarx::viz::coin m->setOverride(true); } } + IceUtil::Time time_color = IceUtil::Time::now(); + + ARMARX_INFO << "Total: " << (time_color - time_start).toMilliSecondsDouble() + << "\nLoad: " << (time_load - time_start).toMilliSecondsDouble() + << "\nStyle: " << (time_style - time_load).toMilliSecondsDouble() + << "\nSet: " << (time_set - time_style).toMilliSecondsDouble() + << "\nColor: " << (time_color - time_set).toMilliSecondsDouble(); return true; } @@ -164,7 +184,7 @@ namespace armarx::viz::coin void VisualizationRobot::recreateVisualizationNodes(int drawStyle) { VirtualRobot::SceneObject::VisualizationType visuType = VirtualRobot::SceneObject::Full; - if (drawStyle & ModelDrawStyle_COLLISION) + if (drawStyle & ModelDrawStyle::COLLISION) { visuType = VirtualRobot::SceneObject::Collision; } diff --git a/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.h b/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.h index 15c81347abea9dc26e14de426feda46b8eaa8c07..0f4a49211a9d04cfe929ec46871db45026eec751 100644 --- a/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.h +++ b/source/RobotAPI/components/ArViz/Coin/VisualizationRobot.h @@ -24,7 +24,7 @@ namespace armarx::viz::coin void recreateVisualizationNodes(int drawStyle); LoadedRobot loaded; - int loadedDrawStyle = ModelDrawStyle_ORIGINAL; + int loadedDrawStyle = ModelDrawStyle::ORIGINAL; }; void clearRobotCache(); diff --git a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp index 92135134dcc176c7a0a672633156c6809ba68b5f..6ae7956ce17b8eafc9825944a1694b0c36cfe627 100644 --- a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp +++ b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp @@ -125,6 +125,7 @@ namespace armarx::viz std::set<std::string> updatedIDs; + IceUtil::Time time_start = IceUtil::Time::now(); // Add or update the elements in the update CoinLayer& layer = layerIt->second; for (auto& updatedElementPtr : update.elements) @@ -145,9 +146,10 @@ namespace armarx::viz } if (visualizer == nullptr) { - ARMARX_WARNING << "No visualizer for element type found: " + ARMARX_WARNING << deactivateSpam(1) + << "No visualizer for element type found: " << boost::core::demangle(elementType.name()); - return; + continue; } auto oldElementIter = layer.elements.find(updatedElement.id); @@ -157,6 +159,12 @@ namespace armarx::viz coin::ElementVisualization& oldElement = *oldElementIter->second; bool updated = visualizer->update(updatedElement, &oldElement); + if (update.name == "Example") + { + IceUtil::Time dur_elem = IceUtil::Time::now() - time_start; + ARMARX_INFO << "Elem " << updatedElement.id + << ": " << dur_elem.toMilliSecondsDouble(); + } if (updated) { continue; @@ -182,6 +190,11 @@ namespace armarx::viz << "You need to register a visualizer for each type in ArViz/Coin/Visualizer.cpp"; } } + IceUtil::Time duration = IceUtil::Time::now() - time_start; + if (duration > IceUtil::Time::milliSeconds(2)) + { + ARMARX_INFO << "Layer " << update.name << ": " << duration.toMilliSecondsDouble(); + } // Remove the elements which were not contained in the update for (auto iter = layer.elements.begin(); iter != layer.elements.end();) @@ -240,25 +253,34 @@ namespace armarx::viz // We never block the GUI thread with Ice calls: Only get result when call is completed if (pullUpdateResult->isCompleted()) { - TimedBlock block("apply-updates"); + IceUtil::Time time_start = IceUtil::Time::now(); auto layerIDsBefore = getLayerIDs(); LayerUpdates pulledUpdates = storage->end_pullUpdatesSince(pullUpdateResult); + IceUtil::Time time_afterPull = IceUtil::Time::now(); + pullUpdateResult = nullptr; for (LayerUpdate const& update : pulledUpdates.updates) { apply(update); } updateCounter = pulledUpdates.updateCounter; + IceUtil::Time time_afterApply = IceUtil::Time::now(); auto layerIDsAfter = getLayerIDs(); if (layerIDsAfter != layerIDsBefore) { emitLayersChanged(layerIDsAfter); } - - ARMARX_INFO << "Updates: " << pulledUpdates.updates.size(); + IceUtil::Time time_afterLayersChanged = IceUtil::Time::now(); + + // Most of the time is spent in apply + // ARMARX_INFO << "Updates: " << pulledUpdates.updates.size() + // << "\nTotal: " << (time_afterLayersChanged - time_start).toMilliSecondsDouble() + // << "\nPull: " << (time_afterPull - time_start).toMilliSecondsDouble() + // << "\nApply: " << (time_afterApply - time_afterPull).toMilliSecondsDouble() + // << "\nLayers: " << (time_afterLayersChanged - time_afterApply).toMilliSecondsDouble(); } else { @@ -311,6 +333,7 @@ namespace armarx::viz std::vector<CoinLayerID> CoinVisualizer::getLayerIDs() { std::vector<CoinLayerID> result; + result.reserve(layers.size()); for (auto& entry : layers) { result.push_back(entry.first); diff --git a/source/RobotAPI/components/ArVizExample/ArVizExample.cpp b/source/RobotAPI/components/ArVizExample/ArVizExample.cpp index 94e5ccc5894a32bb8f761b22cb95675530f370ac..9e4d49e3991e22369e6b7b7206ef5a14b9cf9042 100644 --- a/source/RobotAPI/components/ArVizExample/ArVizExample.cpp +++ b/source/RobotAPI/components/ArVizExample/ArVizExample.cpp @@ -382,31 +382,30 @@ namespace armarx::viz return *this; } - // Encapsulate this Robot& useCollisionModel() { - data_->drawStyle |= ModelDrawStyle_COLLISION; + data_->drawStyle |= ModelDrawStyle::COLLISION; return *this; } Robot& useFullModel() { - data_->drawStyle &= ~ModelDrawStyle_COLLISION; + data_->drawStyle &= ~ModelDrawStyle::COLLISION; return *this; } Robot& overrideColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255) { - data_->drawStyle |= ModelDrawStyle_OVERRIDE_COLOR; + data_->drawStyle |= ModelDrawStyle::OVERRIDE_COLOR; return color(r, g, b, a); } Robot& useOriginalColor() { - data_->drawStyle &= ~ModelDrawStyle_OVERRIDE_COLOR; + data_->drawStyle &= ~ModelDrawStyle::OVERRIDE_COLOR; return *this; } @@ -770,5 +769,3 @@ armarx::PropertyDefinitionsPtr ArVizExample::createPropertyDefinitions() return armarx::PropertyDefinitionsPtr(new ArVizExamplePropertyDefinitions( getConfigIdentifier())); } - - diff --git a/source/RobotAPI/interface/ArViz/Elements.ice b/source/RobotAPI/interface/ArViz/Elements.ice index 6745ceb88d957e191cbd3ec0b802bb2f5cbb7be9..e9dc918a49386e04dbc644e33db5dd2767d846ac 100644 --- a/source/RobotAPI/interface/ArViz/Elements.ice +++ b/source/RobotAPI/interface/ArViz/Elements.ice @@ -128,18 +128,18 @@ module viz FaceSeq faces; }; - enum ModelDrawStyleFlags + module ModelDrawStyle { - ModelDrawStyle_ORIGINAL = 0, - ModelDrawStyle_COLLISION = 1, - ModelDrawStyle_OVERRIDE_COLOR = 2, + const int ORIGINAL = 0; + const int COLLISION = 1; + const int OVERRIDE_COLOR = 2; }; class ElementRobot extends Element { string project; string filename; - int drawStyle = ModelDrawStyle_ORIGINAL; + int drawStyle = ModelDrawStyle::ORIGINAL; StringFloatDictionary jointValues; };