Commit 02d5f816 authored by Joseph Mirabel's avatar Joseph Mirabel

Add plugin to view hpp::fcl::BVHModel

parent 14e72d8e
......@@ -22,6 +22,8 @@ INCLUDE(${GEPETTO_VIEWER_CORBA_CMAKE_PLUGIN})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_OPTIONAL_DEPENDENCY(hpp-fcl)
SET(BUILD_REMOTEIMU_PLUGIN ${REMOTEIMU_FOUND}
CACHE BOOL "Build remoteimuplugin")
SET(BUILD_HPP_CORBASERVER_PLUGIN OFF
......@@ -30,6 +32,8 @@ SET(BUILD_HPP_WIDGETS_PLUGIN ${HPP_CORBASERVER_FOUND}
CACHE BOOL "Build hppwidgetsplugin")
SET(BUILD_HPP_MANIPULATION_WIDGETS_PLUGIN ${HPP_MANIPULATION_CORBA_FOUND}
CACHE BOOL "Build hppmanipulationwidgetsplugin")
SET(BUILD_HPP_FCL_PLUGIN ${HPP_FCL_FOUND}
CACHE BOOL "Build hppfclplugin")
IF (HPP_CORBASERVER_FOUND)
IF (REMOTEIMU_FOUND AND BUILD_REMOTEIMU_PLUGIN)
......@@ -48,3 +52,7 @@ IF (HPP_CORBASERVER_FOUND)
ADD_SUBDIRECTORY(hppmanipulationwidgetsplugin)
ENDIF (HPP_MANIPULATION_CORBA_FOUND AND BUILD_HPP_MANIPULATION_WIDGETS_PLUGIN)
ENDIF (HPP_CORBASERVER_FOUND)
IF (HPP_FCL_FOUND)
ADD_SUBDIRECTORY(hppfcl)
ENDIF()
# Copyright (c) 2018 CNRS
# Authors: Joseph Mirabel
#
#
# This file is part of gepetto-viewer-corba
# gepetto-viewer-corba is free software: you can redistribute it
# and/or modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, either version
# 3 of the License, or (at your option) any later version.
#
# gepetto-viewer-corba is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Lesser Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with
# gepetto-viewer-corba If not, see
# <http://www.gnu.org/licenses/>.
IF(USE_QT4)
SET(QT4 "QT4")
ELSE()
SET(QT4 "")
ENDIF()
GEPETTO_GUI_PLUGIN(hppfclplugin
${QT4}
HEADERS_NO_MOC
node.hh
HEADERS
plugin.hh
FORMS
RESOURCES
SOURCES
plugin.cc
node.cc
LINK_DEPENDENCIES
PKG_CONFIG_DEPENDENCIES
hpp-fcl
)
// Copyright (c) 2019 CNRS
// Authors: Joseph Mirabel
//
//
// This file is part of hpp-gui
// hpp-gui is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-gui is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-gui If not, see
// <http://www.gnu.org/licenses/>.
#include <node.hh>
#include <hpp/fcl/mesh_loader/assimp.h>
namespace hpp {
namespace gui {
BVHDisplay::BVHDisplay (const std::string& filename, const std::string& name)
: graphics::Node (name)
, filename_ (filename)
{
setWireFrameMode (graphics::WIREFRAME);
}
void BVHDisplay::setColor (const osgVector4&)
{
// TODO
}
void BVHDisplay::setLevel (const std::size_t level)
{
if (level >= levels_.size())
throw std::invalid_argument ("level out of range");
this->asQueue()->replaceChild (
levels_[level_].geode,
levels_[level ].geode);
level_ = level;
}
void BVHDisplay::init (hpp::fcl::SplitMethodType splitMethod)
{
using namespace hpp::fcl;
BVHPtr_t bvh (new BVH_t);
bvh->bv_splitter.reset (new BVSplitter<BoundingVolume>(splitMethod));
loadPolyhedronFromResource (filename_, Vec3f(1,1,1), bvh);
recursiveBuildTree (*bvh, 0, 0);
level_ = 0;
this->asQueue()->addChild(levels_[0].geode);
using graphics::UIntProperty;
addProperty (UIntProperty::create ("Level",
UIntProperty::getterFromMemberFunction (this, &BVHDisplay::getLevel),
UIntProperty::setterFromMemberFunction (this, &BVHDisplay::setLevel))
);
}
void BVHDisplay::recursiveBuildTree (const BVH_t& bvh, int ibv,
std::size_t level)
{
if (levels_.size() <= level)
levels_.resize (level+1);
BVLevel& bvlevel = levels_[level];
const BoundingVolume& bv = bvh.getBV(ibv).bv;
::osg::BoxRefPtr box = new ::osg::Box ();
box->setCenter (osg::Vec3 ((float)bv.To [0],(float)bv.To [1],(float)bv.To [2]));
box->setHalfLengths (osg::Vec3 ((float)bv.extent[0],(float)bv.extent[1],(float)bv.extent[2]));
Eigen::Quaterniond q (bv.axes);
box->setRotation (::osg::Quat (q.x(),q.y(),q.z(),q.w()));
::osg::ShapeDrawableRefPtr drawable = new ::osg::ShapeDrawable(box);
bvlevel.boxes.push_back (box);
if (!bvlevel.geode) bvlevel.geode = new ::osg::Geode;
bvlevel.geode->addDrawable(drawable);
if (bvh.getBV(ibv).isLeaf()) return;
recursiveBuildTree (bvh, bvh.getBV(ibv). leftChild(), level + 1);
recursiveBuildTree (bvh, bvh.getBV(ibv).rightChild(), level + 1);
}
} // namespace gui
} // namespace hpp
// Copyright (c) 2019 CNRS
// Authors: Joseph Mirabel
//
//
// This file is part of hpp-gui
// hpp-gui is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-gui is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-gui If not, see
// <http://www.gnu.org/licenses/>.
#ifndef HPP_GUI_HPP_FCL_PLUGIN_NODE_HH
#define HPP_GUI_HPP_FCL_PLUGIN_NODE_HH
#include <gepetto/viewer/node.h>
#include <hpp/fcl/BVH/BVH_model.h>
namespace hpp {
namespace gui {
DEF_CLASS_SMART_PTR(BVHDisplay)
class BVHDisplay : public graphics::Node
{
public:
BVHDisplay (const std::string& filename, const std::string& name);
void setLevel (const std::size_t level);
const std::size_t& getLevel () const
{
return level_;
}
void setColor (const osgVector4& color);
void init (hpp::fcl::SplitMethodType splitMethod);
private:
typedef hpp::fcl::OBB BoundingVolume;
typedef hpp::fcl::BVHModel<BoundingVolume> BVH_t;
typedef boost::shared_ptr < BVH_t > BVHPtr_t;
void recursiveBuildTree (const BVH_t& bvh, int ibv, std::size_t level);
struct BVLevel {
//std::vector< ::osg::ShapeDrawableRefPtr > bvs;
std::vector< ::osg::BoxRefPtr > boxes;
::osg::GeodeRefPtr geode;
};
const std::string filename_;
std::vector <BVLevel> levels_;
std::size_t level_;
};
} // namespace gui
} // namespace hpp
#endif // HPP_GUI_HPP_FCL_PLUGIN_NODE_HH
// Copyright (c) 2019 CNRS
// Authors: Joseph Mirabel
//
//
// This file is part of hpp-gui
// hpp-gui is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-gui is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-gui If not, see
// <http://www.gnu.org/licenses/>.
#include <plugin.hh>
#include <QToolBar>
#include <QAction>
#include <QFileDialog>
#include <QInputDialog>
#include <gepetto/gui/mainwindow.hh>
#include <gepetto/gui/windows-manager.hh>
#include <node.hh>
namespace hpp {
namespace gui {
using gepetto::gui::MainWindow;
void HppFclPlugin::init()
{
// TODO add a way to add an action to body tree items.
QToolBar* toolBar = MainWindow::instance()->addToolBar("hpp-fcl tools");
toolBar->setObjectName ("hppfclplugin.toolbar");
QAction* openD = new QAction (QIcon::fromTheme("document-open"), "Load a BVH model", toolBar);
toolBar->addAction (openD);
connect (openD, SIGNAL(triggered()), SLOT (openDialog()));
}
void HppFclPlugin::openDialog() const
{
QString filename = QFileDialog::getOpenFileName (NULL, "Select a mesh file");
QString name = QInputDialog::getText(NULL, "Node name", "Node name", QLineEdit::Normal, "bvhmodel");
std::string _name (name.toStdString());
int splitMethod = QInputDialog::getInt(NULL, "Split method type",
"Split method type", 0, 0, 3, 1);
BVHDisplayPtr_t node (new BVHDisplay (filename.toStdString(), _name));
switch (splitMethod) {
default:
case 0:
node->init (hpp::fcl::SPLIT_METHOD_MEAN);
break;
case 1:
node->init (hpp::fcl::SPLIT_METHOD_MEDIAN);
break;
case 2:
node->init (hpp::fcl::SPLIT_METHOD_BV_CENTER);
break;
}
MainWindow* main = MainWindow::instance ();
main->osg()->insertNode (_name, node);
main->osg()->addToGroup (_name, "hpp-gui");
}
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
Q_EXPORT_PLUGIN2 (hppfclplugin, HppFclPlugin)
#endif
} // namespace gui
} // namespace hpp
// Copyright (c) 2019 CNRS
// Authors: Joseph Mirabel
//
//
// This file is part of hpp-gui
// hpp-gui is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-gui is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-gui If not, see
// <http://www.gnu.org/licenses/>.
#include <QObject>
#include <gepetto/gui/plugin-interface.hh>
namespace hpp {
namespace gui {
class HppFclPlugin : public QObject, public gepetto::gui::PluginInterface
{
Q_OBJECT
Q_INTERFACES (gepetto::gui::PluginInterface)
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
Q_PLUGIN_METADATA (IID "hpp-gui.hppwidgetsplugin")
#endif
public:
QString name () const { return QString("HppFclPlugin"); }
protected:
void init();
protected slots:
void openDialog () const;
};
} // namespace gui
} // namespace hpp
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment