29#include <Inventor/SbRotation.h>
30#include <Inventor/SbVec3f.h>
31#include <Inventor/nodes/SoCone.h>
32#include <Inventor/nodes/SoMaterial.h>
33#include <Inventor/nodes/SoSeparator.h>
41 objectName(operation.objectName),
42 objectCollection(operation.objectCollection),
43 objectPosition(operation.objectPosition),
44 objectRotation(operation.objectRotation)
53 const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
54 const std::shared_ptr<scene3D::Scene>& scene,
55 const std::string& objectName,
56 const std::string& objectCollection,
57 const SbVec3f& objectPosition,
58 const SbRotation& objectRotation,
59 const std::string& objectId) :
60 Operation(memoryXController, scene, objectId),
61 objectName(objectName),
62 objectCollection(objectCollection),
63 objectPosition(objectPosition),
64 objectRotation(objectRotation)
69 const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
70 const std::shared_ptr<scene3D::Scene>& scene,
71 const std::string& objectName,
72 const std::string& objectCollection,
73 const SbVec3f& objectPosition,
74 const SbRotation& objectRotation) :
76 objectName(objectName),
77 objectCollection(objectCollection),
78 objectPosition(objectPosition),
79 objectRotation(objectRotation)
85 const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
86 const std::shared_ptr<scene3D::Scene>& scene,
87 const std::string& objectName,
88 const std::string& objectCollection) :
90 objectName(objectName),
91 objectCollection(objectCollection),
92 objectPosition(0, 0, 0),
93 objectRotation(SbVec3f(1, 0, 0), 0)
99controller::AddOperation::createRandomId()
101 static const char chars[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
102 const int length = 20;
104 std::shared_ptr<scene3D::Scene> scene = getScene();
105 char random[length + 1];
109 for (
int i = 0; i < length; ++i)
111 random[i] = chars[rand() % (
sizeof(chars) - 1)];
115 }
while (scene->getObjectManager()->getObjectById(random));
117 std::string
id = random;
124 std::shared_ptr<controller::Operation> inverseOperation(
132 return inverseOperation;
144 memoryXController->getPriorKnowlegdeController()->getObjectClassPtr(objectName,
149 std::string newObjectId =
150 memoryXController->getWorkingMemoryController()->addObjectInstance(objectName, objectClass);
155 newObjectId, objectRotation, objectPosition);
161 std::shared_ptr<scene3D::Scene> scene =
getScene();
165 priorKnowledgeController->getObjectClassPtr(objectName, objectCollection);
166 SoNode* geometryNode = priorKnowledgeController->getCoinVisualisation(objectClass,
false);
167 SoNode* collisionNode = priorKnowledgeController->getCoinVisualisation(objectClass,
true);
171 ARMARX_WARNING_S <<
"object \"" << objectName <<
"\" has no collison model";
172 collisionNode =
new SoSeparator;
173 SoMaterial* material =
new SoMaterial;
174 material->ambientColor.setValue(1.0f, 0.0f, 0.0f);
175 material->diffuseColor.setValue(1.0f, 0.0f, 0.0f);
176 SoCone* cone =
new SoCone;
177 cone->bottomRadius.setValue(0.03);
178 cone->height.setValue(0.3);
179 ((SoSeparator*)collisionNode)->addChild(material);
180 ((SoSeparator*)collisionNode)->addChild(cone);
185 ARMARX_WARNING_S <<
"object \"" << objectName <<
"\" has no visualisation model";
186 geometryNode =
new SoSeparator;
187 SoMaterial* material =
new SoMaterial;
188 material->ambientColor.setValue(1.0f, 0.0f, 0.0f);
189 material->diffuseColor.setValue(1.0f, 0.0f, 0.0f);
190 SoCone* cone =
new SoCone;
191 cone->bottomRadius.setValue(0.03);
192 cone->height.setValue(0.3);
193 ((SoSeparator*)geometryNode)->addChild(material);
194 ((SoSeparator*)geometryNode)->addChild(cone);
197 SoSeparator* geometry =
new SoSeparator();
198 geometry->addChild(geometryNode);
199 SoSeparator* collision =
new SoSeparator();
200 collision->addChild(collisionNode);
204 object->setRotation(objectRotation);
205 object->setTranslation(objectPosition);
206 scene->getObjectManager()->addObject(
object);
A Operation to create a new object in the scene and the WorkingMemory.
const OperationPtr createInverseOperation() const override
Returns a new operation which removes the object, which will be added in this operation.
void executeOnScene() override
Adds the object to the local Scene.
AddOperation(const AddOperation &operation)
Creates a new operation, which is a copy of the given operation, but has a new random ID.
void executeOnWorkingMemory() override
Adds the object to the WorkingMemory.
std::string getObjectId() const
Returns the ID of the object, this Operation is working on.
const std::shared_ptr< memoryxcontroller::MemoryXController > getMemoryXController() const
Returns the the MemoryXController to execute the Operation at.
const std::shared_ptr< scene3D::Scene > getScene() const
Returns the the Scene to execute the Operation at.
Operation(const std::shared_ptr< memoryxcontroller::MemoryXController > &memoryXController, const std::shared_ptr< scene3D::Scene > &scene, const std::string &objectId)
A constructor.
void setObjectId(const std::string &objectId)
Sets the ID, this operation is working on.
A Operation to remove a object in the scene and the WorkingMemory.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< Operation > OperationPtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
std::shared_ptr< PriorKnowledgeController > PriorKnowledgeControllerPtr
std::shared_ptr< MemoryXController > MemoryXControllerPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr