SimulatedObjectAsObject.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package armarx::simulation::scene_generation
17  * @author Patrick Hegemann ( patrick dot hegemann at kit dot edu )
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
23 
25 
28 #include <ArmarXCore/interface/core/PackagePath.h>
29 
30 #include <VirtualRobot/XML/ObjectIO.h>
31 
33 {
34  SimulatedObjectAsObject::SimulatedObjectAsObject(const std::string& instanceName, const ObjectSource& objectSource) :
35  SimulatedObject(instanceName, objectSource)
36  {
37  // TODO(patrick.hegemann): refactor this dirty fix of stupid behavior
38  const armarx::data::PackagePath& pp = objectSource.path.serialize();
39  std::filesystem::path relPath(pp.path);
40  ARMARX_CHECK(!relPath.empty()) << "Relative path to object should not be empty";
41  if (!relPath.empty() && relPath.begin()->string() == pp.package)
42  {
43  relPath = relPath.lexically_relative(*relPath.begin());
44  }
45  armarx::PackagePath newPackagePath(pp.package, relPath);
46 
47  localCopy_ = VirtualRobot::ObjectIO::loadManipulationObject(newPackagePath.toSystemPath());
48  localCopy_->setName(instanceName);
49  }
50 
51  void SimulatedObjectAsObject::addToSimulator(armarx::SimulatorInterfacePrx& simulator)
52  {
53  PosePtr pose(new Pose(localCopy_->getGlobalPose()));
54  simulator->addObjectFromFile(getObjectSource().path.serialize(), getInstanceName(), pose, false);
55  }
56 
57  void SimulatedObjectAsObject::updatePoseFromSimulator(armarx::SimulatorInterfacePrx& simulator)
58  {
59  const PoseBasePtr& poseBase = simulator->getObjectPose(getInstanceName());
60  Pose p(poseBase->position, poseBase->orientation);
61  localCopy_->setGlobalPose(p.toEigen());
62  }
63 
64  void SimulatedObjectAsObject::updatePoseToSimulator(armarx::SimulatorInterfacePrx& simulator)
65  {
66  PosePtr pose(new Pose(localCopy_->getGlobalPose()));
67  simulator->setObjectPose(getInstanceName(), pose);
68  }
69 
70  bool SimulatedObjectAsObject::checkCollision(const VirtualRobot::CollisionCheckerPtr& col,
71  const VirtualRobot::SceneObjectSetPtr& objectSet)
72  {
73  return col->checkCollision(localCopy_->getCollisionModel(), objectSet);
74  }
75 
76  std::unique_ptr<Pose> SimulatedObjectAsObject::getLocalPose()
77  {
78  return std::make_unique<Pose>(localCopy_->getGlobalPose());
79  }
80 
82  {
83  localCopy_->setGlobalPose(pose->toEigen());
84  }
85 } // namespace armarx::simulation::scene_generation
armarx::simulation::scene_generation::SimulatedObjectAsObject::setLocalPose
void setLocalPose(const armarx::PosePtr &pose) override
Definition: SimulatedObjectAsObject.cpp:81
armarx::simulation::scene_generation::ObjectSource
Definition: SimulatedObject.h:44
armarx::simulation::scene_generation::SimulatedObject::getObjectSource
const ObjectSource & getObjectSource()
Definition: SimulatedObject.h:88
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::simulation::scene_generation
Definition: ClutteredSceneGenerator.cpp:48
armarx::simulation::scene_generation::SimulatedObjectAsObject::getLocalPose
std::unique_ptr< Pose > getLocalPose() override
Definition: SimulatedObjectAsObject.cpp:76
armarx::simulation::scene_generation::SimulatedObjectAsObject::updatePoseFromSimulator
void updatePoseFromSimulator(armarx::SimulatorInterfacePrx &simulator) override
Definition: SimulatedObjectAsObject.cpp:57
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::PackagePath::serialize
data::PackagePath serialize() const
Definition: PackagePath.cpp:76
IceInternal::Handle< Pose >
armarx::simulation::scene_generation::ObjectSource::path
armarx::PackagePath path
Definition: SimulatedObject.h:46
armarx::simulation::scene_generation::SimulatedObject::getInstanceName
const std::string & getInstanceName()
Definition: SimulatedObject.h:78
armarx::PackagePath::toSystemPath
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
Definition: PackagePath.cpp:54
armarx::Pose::toEigen
virtual Eigen::Matrix4f toEigen() const
Definition: Pose.cpp:334
armarx::simulation::scene_generation::SimulatedObjectAsObject::updatePoseToSimulator
void updatePoseToSimulator(armarx::SimulatorInterfacePrx &simulator) override
Definition: SimulatedObjectAsObject.cpp:64
SimulatedObject.h
SimulatedObjectAsObject.h
ExpressionException.h
armarx::Pose
The Pose class.
Definition: Pose.h:242
armarx::simulation::scene_generation::SimulatedObjectAsObject::SimulatedObjectAsObject
SimulatedObjectAsObject(const std::string &instanceName, const ObjectSource &source)
Definition: SimulatedObjectAsObject.cpp:34
armarx::simulation::scene_generation::SimulatedObjectAsObject::addToSimulator
void addToSimulator(armarx::SimulatorInterfacePrx &simulator) override
Definition: SimulatedObjectAsObject.cpp:51
armarx::PackagePath
Definition: PackagePath.h:55
armarx::simulation::scene_generation::SimulatedObject
Definition: SimulatedObject.h:57
armarx::simulation::scene_generation::SimulatedObjectAsObject::checkCollision
bool checkCollision(const VirtualRobot::CollisionCheckerPtr &col, const VirtualRobot::SceneObjectSetPtr &objectSet) override
Definition: SimulatedObjectAsObject.cpp:70
PackagePath.h