From c9659a95ee0928855d9e949cb97342622ea67c30 Mon Sep 17 00:00:00 2001 From: Stefano Date: Fri, 8 Jan 2021 09:46:08 +0100 Subject: [PATCH] Removed unused files. --- include/icub-visualizer/Visualizer.h | 53 ------ src/Visualizer.cpp | 252 --------------------------- 2 files changed, 305 deletions(-) delete mode 100644 include/icub-visualizer/Visualizer.h delete mode 100644 src/Visualizer.cpp diff --git a/include/icub-visualizer/Visualizer.h b/include/icub-visualizer/Visualizer.h deleted file mode 100644 index 8dc2419..0000000 --- a/include/icub-visualizer/Visualizer.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2020 Fondazione Istituto Italiano di Tecnologia - * - * Licensed under either the GNU Lesser General Public License v3.0 : - * https://www.gnu.org/licenses/lgpl-3.0.html - * or the GNU Lesser General Public License v2.1 : - * https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html - * at your option. - */ -#ifndef ICUB_VISUALIZER_H -#define ICUB_VISUALIZER_H - -#include -#include -#include -#include -#include - -class Visualizer { - -public: - - Visualizer(); - - ~Visualizer(); - - bool setModel(const iDynTree::Model& model); - - bool visualizeState(const DynamicalPlanner::State& stateToVisualize); - - bool visualizeStates(const std::vector& states, double endTime = -1.0); - - bool visualizeStates(const std::vector& states, - const std::vector& cameraPosition, - const std::vector& cameraTarget, - double endTime = -1.0); - - bool visualizeStatesAndSaveAnimation(const std::vector& states, const std::string& workingFolder, - const std::string& fileName, const std::string& fileExtension = "gif", double endTime = -1.0); - - bool setCameraPosition(const iDynTree::Position& cameraPosition); - - bool setCameraTarget(const iDynTree::Position& cameraTarget); - - bool setLightDirection(const iDynTree::Direction& lightDirection); - -private: - - class VisualizerImplementation; - std::unique_ptr m_pimpl; -}; - -#endif // ICUB_VISUALIZER_H diff --git a/src/Visualizer.cpp b/src/Visualizer.cpp deleted file mode 100644 index 96f9d91..0000000 --- a/src/Visualizer.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (C) 2020 Fondazione Istituto Italiano di Tecnologia - * - * Licensed under either the GNU Lesser General Public License v3.0 : - * https://www.gnu.org/licenses/lgpl-3.0.html - * or the GNU Lesser General Public License v2.1 : - * https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html - * at your option. - */ - -#include -#include -#include -#include -#include -#include -#include - - -using namespace DynamicalPlanner; - -class Visualizer::VisualizerImplementation { -public: - - iDynTree::Visualizer viz; - iDynTree::Position defaultCameraPosition, defaultCameraTarget; - - VisualizerImplementation() {} - ~VisualizerImplementation(){} -}; - -Visualizer::Visualizer() - : m_pimpl(std::make_unique()) -{ - iDynTree::VisualizerOptions options; - options.winWidth = 1920; - options.winHeight = 1080; -// options.backgroundColor = iDynTree::ColorViz(0.0, 0.0, 0.0, 0.0); - m_pimpl->viz.init(options); - setCameraPosition(iDynTree::Position(1.0, 0.0, 0.5)); - setCameraTarget(iDynTree::Position(0.4, 0.0, 0.5)); - double sqrt2 = std::sqrt(2.0); - setLightDirection(iDynTree::Direction(-0.5/sqrt2, 0, -0.5/sqrt2)); - m_pimpl->viz.vectors().setVectorsAspect(0.01, 0.0, 0.01); -} - -Visualizer::~Visualizer() -{ - m_pimpl->viz.close(); -} - -bool Visualizer::setModel(const iDynTree::Model &model) -{ - if (m_pimpl->viz.getNrOfVisualizedModels()) { - std::cerr << "[ERROR][Visualizer::setModel] Model already set." << std::endl; - return false; - } - bool modelLoaded = m_pimpl->viz.addModel(model, "DynamicalPlannerVisualizer"); - - if (!modelLoaded) { - std::cerr << "[ERROR][Visualizer::setModel] Failed to set model for visualization." << std::endl; - return false; - } - - return modelLoaded; -} - -bool Visualizer::visualizeState(const State &stateToVisualize) -{ - if (!(m_pimpl->viz.getNrOfVisualizedModels())) { - std::cerr << "[ERROR][Visualizer::visualizeState] First you have to load a model." << std::endl; - return false; - } - - m_pimpl->viz.modelViz(0).setPositions(stateToVisualize.worldToBaseTransform, stateToVisualize.jointsConfiguration); - - iDynTree::IVectorsVisualization& forcesViz = m_pimpl->viz.vectors(); - - size_t vectorIndex = 0; - iDynTree::Position posBuf; - - for (const ContactPointState& point : stateToVisualize.leftContactPointsState) { - iDynTree::toEigen(posBuf) = iDynTree::toEigen(point.pointPosition); - if (vectorIndex < forcesViz.getNrOfVectors()) { - forcesViz.updateVector(vectorIndex, posBuf, point.pointForce); - } else { - forcesViz.addVector(posBuf, point.pointForce); - } - vectorIndex++; - } - - for (const ContactPointState& point : stateToVisualize.rightContactPointsState) { - iDynTree::toEigen(posBuf) = iDynTree::toEigen(point.pointPosition); - if (vectorIndex < forcesViz.getNrOfVectors()) { - forcesViz.updateVector(vectorIndex, posBuf, point.pointForce); - } else { - forcesViz.addVector(posBuf, point.pointForce); - } - vectorIndex++; - } - - m_pimpl->viz.draw(); - - return true; -} - -bool Visualizer::visualizeStates(const std::vector &states, double endTime) -{ - if (!(m_pimpl->viz.getNrOfVisualizedModels())) { - std::cerr << "[ERROR][Visualizer::visualizeState] First you have to load a model." << std::endl; - return false; - } - - for (size_t i = 0; i < states.size(); ++i) { - if ((endTime > 0) && (states[i].time > endTime)) { - break; - } - std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); - visualizeState(states[i]); - std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); - if ((i + 1) < states.size()) { - std::chrono::milliseconds durationMs(static_cast(std::round((states[i + 1].time - states[i].time)*1000))); - std::chrono::milliseconds elapsed = std::chrono::duration_cast(end - begin); - - if (elapsed < durationMs) { - std::this_thread::sleep_for (durationMs - elapsed); - } - } - } - - return true; -} - -bool Visualizer::visualizeStates(const std::vector &states, const std::vector &cameraPosition, const std::vector &cameraTarget, double endTime) -{ - if (!(m_pimpl->viz.getNrOfVisualizedModels())) { - std::cerr << "[ERROR][Visualizer::visualizeState] First you have to load a model." << std::endl; - return false; - } - - if (cameraPosition.size() != states.size()) { - std::cerr << "[ERROR][Visualizer::visualizeState] The cameraPosition vector should have the same dimension of the states vector." << std::endl; - return false; - } - - if (cameraTarget.size() != states.size()) { - std::cerr << "[ERROR][Visualizer::visualizeState] The cameraTarget vector should have the same dimension of the states vector." << std::endl; - return false; - } - - for (size_t i = 0; i < states.size(); ++i) { - if ((endTime > 0) && (states[i].time > endTime)) { - break; - } - std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); - m_pimpl->viz.camera().setPosition(cameraPosition[i]); - m_pimpl->viz.camera().setTarget(cameraTarget[i]); - visualizeState(states[i]); - std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); - if ((i + 1) < states.size()) { - std::chrono::milliseconds durationMs(static_cast(std::round((states[i + 1].time - states[i].time)*1000))); - std::chrono::milliseconds elapsed = std::chrono::duration_cast(end - begin); - - if (elapsed < durationMs) { - std::this_thread::sleep_for (durationMs - elapsed); - } - } - } - - m_pimpl->viz.camera().setPosition(m_pimpl->defaultCameraPosition); - - m_pimpl->viz.camera().setTarget(m_pimpl->defaultCameraTarget); - - return true; -} - -bool Visualizer::visualizeStatesAndSaveAnimation(const std::vector &states, const std::string &workingFolder, const std::string &fileName, const std::string &fileExtension, double endTime) -{ - if (!(m_pimpl->viz.getNrOfVisualizedModels())) { - std::cerr << "[ERROR][Visualizer::visualizeState] First you have to load a model." << std::endl; - return false; - } - - unsigned int digits = static_cast(std::floor(std::log(states.size()) + 1)); - - size_t i = 0; - - while (i < states.size() && (!(endTime < 0) || (states[i].time <= endTime))) { - - std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); - visualizeState(states[i]); - m_pimpl->viz.drawToFile(workingFolder + "/" + fileName + "_img_" + std::string(digits - std::to_string(i).size(), '0') + std::to_string(i) + ".png"); - std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); - if ((i + 1) < states.size()) { - std::chrono::milliseconds durationMs(static_cast(std::round((states[i + 1].time - states[i].time)*1000))); - std::chrono::milliseconds elapsed = std::chrono::duration_cast(end - begin); - - if (elapsed < durationMs) { - std::this_thread::sleep_for (durationMs - elapsed); - } - } - - ++i; - } - - if (i == 0) { - return true; - } - - std::string fps = std::to_string(static_cast(std::round(i/states[i-1].time))); - - auto frameArgs = " -framerate " + fps; - auto inputArgs = " -i " + workingFolder + "/" + fileName + "_img_%0" + std::to_string(digits) + "d" + ".png"; - auto overwriteArgs = " -y"; - auto outputArgs = " " + workingFolder + "/" + fileName + "." + fileExtension; - auto pixFormatArgs = ""; - - // http://superuser.com/questions/533695/how-can-i-convert-a-series-of-png-images-to-a-video-for-youtube#answers-header - if (fileExtension == "mp4") { - pixFormatArgs = " -pix_fmt yuv420p"; - } - - auto args = "ffmpeg" + frameArgs + inputArgs + overwriteArgs + pixFormatArgs + outputArgs; - - std::cout << "[INFO][Visualizer::visualizeState] Generating video with the following arguments:\n" << args << std::endl; - - int useless_int = system(args.c_str()); - - return true; -} - -bool Visualizer::setCameraPosition(const iDynTree::Position &cameraPosition) -{ - m_pimpl->viz.camera().setPosition(cameraPosition); - m_pimpl->defaultCameraPosition = cameraPosition; - return true; -} - -bool Visualizer::setCameraTarget(const iDynTree::Position &cameraTarget) -{ - m_pimpl->viz.camera().setTarget(cameraTarget); - m_pimpl->defaultCameraTarget = cameraTarget; - return true; -} - -bool Visualizer::setLightDirection(const iDynTree::Direction &lightDirection) -{ - m_pimpl->viz.enviroment().lightViz("sun").setDirection(lightDirection); - - return true; - -}