SoSlection Pick Filter Manipulator

本文介绍了一个使用选择回调和选择过滤回调来实现在多个操控器中选择特定对象的示例。通过自定义选择逻辑,当用户点击带有操控器的对象时,可以选择到实际的对象而非操控器本身。

/*------------------------------------------------------------- * This example demonstrates the use of the pick filter * callback to pick through manipulators. * * The scene graph has several objects. Clicking the left * mouse on an object selects it and adds a manipulator to * it. Clicking again deselects it and removes the manipulator. * In this case, the pick filter is needed to deselect the * object rather than select the manipulator. *------------------------------------------------------------*/ #include <Inventor/SoDB.h> #include <Inventor/SoInput.h> #include <Inventor/SoPath.h> #include <Inventor/SoPickedPoint.h> #include <Inventor/Win/SoWin.h> #include <Inventor/Win/viewers/SoWinExaminerViewer.h> #include <Inventor/manips/SoHandleBoxManip.h> #include <Inventor/nodes/SoBaseColor.h> #include <Inventor/nodes/SoFont.h> #include <Inventor/nodes/SoNode.h> #include <Inventor/nodes/SoSelection.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoText3.h> #include <Inventor/nodes/SoTransform.h> // Returns path to xform left of the input path tail. // Inserts the xform if none found. In this example, // assume that the xform is always the node preceeding // the selected shape. SoPath * findXform(SoPath *p) { SoPath *returnPath; // Copy the input path up to tail's parent. returnPath = p->copy(0, p->getLength() - 1); // Get the parent of the selected shape SoGroup *g = (SoGroup *) p->getNodeFromTail(1); int tailNodeIndex = p->getIndexFromTail(0); // Check if there is already a transform node if (tailNodeIndex > 0) { SoNode *n = g->getChild(tailNodeIndex - 1); if (n->isOfType(SoTransform::getClassTypeId())) { // Append to returnPath and return it. returnPath->append(n); return returnPath; } } // Otherwise, add a transform node. SoTransform *xf = new SoTransform; g->insertChild(xf, tailNodeIndex); // right before the tail // Append to returnPath and return it. returnPath->append(xf); return returnPath; } // Returns the manip affecting this path. In this example, // the manip is always preceeding the selected shape. SoPath * findManip(SoPath *p) { SoPath *returnPath; // Copy the input path up to tail's parent. returnPath = p->copy(0, p->getLength() - 1); // Get the index of the last node in the path. int tailNodeIndex = p->getIndexFromTail(0); // Append the left sibling of the tail to the returnPath returnPath->append(tailNodeIndex - 1); return returnPath; } // Add a manipulator to the transform affecting this path // The first parameter, userData, is not used. void selCB(void *, SoPath *path) { if (path->getLength() < 2) return; // Find the transform affecting this object SoPath *xfPath = findXform(path); xfPath->ref(); // Replace the transform with a manipulator SoHandleBoxManip *manip = new SoHandleBoxManip; manip->ref(); manip->replaceNode(xfPath); // Unref the xfPath xfPath->unref(); } // Remove the manipulator affecting this path. // The first parameter, userData, is not used. void deselCB(void *, SoPath *path) { if (path->getLength() < 2) return; // Find the manipulator affecting this object SoPath *manipPath = findManip(path); manipPath->ref(); // Replace the manipulator with a transform SoTransformManip *manip = (SoTransformManip *) manipPath->getTail(); manip->replaceManip(manipPath, new SoTransform); manip->unref(); // Unref the manipPath manipPath->unref(); } ////////////////////////////////////////////////////////////// // CODE FOR The Inventor Mentor STARTS HERE (part 1) SoPath * pickFilterCB(void *, const SoPickedPoint *pick) { SoPath *filteredPath = NULL; // See if the picked object is a manipulator. // If so, change the path so it points to the object the manip // is attached to. SoPath *p = pick->getPath(); SoNode *n = p->getTail(); if (n->isOfType(SoTransformManip::getClassTypeId())) { // Manip picked! We know the manip is attached // to its next sibling. Set up and return that path. int manipIndex = p->getIndex(p->getLength() - 1); filteredPath = p->copy(0, p->getLength() - 1); filteredPath->append(manipIndex + 1); // get next sibling } else filteredPath = p; return filteredPath; } // CODE FOR The Inventor Mentor ENDS HERE /////////////////////////////////////////////////////////////// // Create a sample scene graph SoNode * myText(char *str, int i, const SbColor &color) { SoSeparator *sep = new SoSeparator; SoBaseColor *col = new SoBaseColor; SoTransform *xf = new SoTransform; SoText3 *text = new SoText3; col->rgb = color; xf->translation.setValue(6.0f*i, 0.0f, 0.0f); text->string = str; text->parts = (SoText3::FRONT | SoText3::SIDES); text->justification = SoText3::CENTER; sep->addChild(col); sep->addChild(xf); sep->addChild(text); return sep; } SoNode * buildScene() { SoSeparator *scene = new SoSeparator; SoFont *font = new SoFont; font->size = 10; scene->addChild(font); scene->addChild(myText("O", 0, SbColor(0.0f, 0.0f, 1.0f))); scene->addChild(myText("p", 1, SbColor(0.0f, 1.0f, 0.0f))); scene->addChild(myText("e", 2, SbColor(0.0f, 1.0f, 1.0f))); scene->addChild(myText("n", 3, SbColor(1.0f, 0.0f, 0.0f))); // Open Inventor is two words! scene->addChild(myText("I", 5, SbColor(1.0f, 0.0f, 1.0f))); scene->addChild(myText("n", 6, SbColor(1.0f, 1.0f, 0.0f))); scene->addChild(myText("v", 7, SbColor(1.0f, 1.0f, 1.0f))); scene->addChild(myText("e", 8, SbColor(0.0f, 0.0f, 1.0f))); scene->addChild(myText("n", 9, SbColor(0.0f, 1.0f, 0.0f))); scene->addChild(myText("t", 10, SbColor(0.0f, 1.0f, 1.0f))); scene->addChild(myText("o", 11, SbColor(1.0f, 0.0f, 0.0f))); scene->addChild(myText("r", 12, SbColor(1.0f, 0.0f, 1.0f))); return scene; } int main(int, char **argv) { // Initialization HWND mainWindow = SoWin::init(argv[0]); // Create a scene graph. Use the toggle selection policy. SoSelection *sel = new SoSelection; sel->ref(); sel->policy.setValue(SoSelection::TOGGLE); sel->addChild(buildScene()); // Create a viewer SoWinExaminerViewer *viewer = new SoWinExaminerViewer(mainWindow); viewer->setSceneGraph(sel); viewer->setTitle("Select Through Manips"); viewer->show(); // Selection callbacks sel->addSelectionCallback(selCB); sel->addDeselectionCallback(deselCB); //sel->setPickFilterCallback(pickFilterCB); SoWin::show(mainWindow); SoWin::mainLoop(); return 0; }

### Manipulator 的定义与应用 在编程和机器人学领域,`manipulator` 是指一种用于控制或操作对象的工具或设备。具体来说,在机器人技术中,它通常指的是机械臂或其他能够执行物理任务的装置[^1]。 #### 1. Robotics Context 在机器人学背景下,`manipulator` 主要是指 **机械手** 或 **机械臂**,这是一种由多个关节组成的可移动结构,可以抓取、移动物体并完成复杂的动作。这种类型的 manipulator 常见于工业自动化场景以及服务型机器人中。例如,Underactuated Robotics 中提到的内容涉及如何设计具有欠驱动特性的操纵器来实现特定功能。 以下是典型的机械臂控制系统架构: ```python class RobotManipulator: def __init__(self, joints): self.joints = joints def move_to(self, target_position): # 计算逆运动学解 joint_angles = inverse_kinematics(target_position) # 设置各关节角度 for i, angle in enumerate(joint_angles): self.set_joint_angle(i, angle) def set_joint_angle(self, index, angle): # 更新指定关节的角度 pass ``` #### 2. Programming Context 在更广泛的编程语境下,`manipulator` 可能被用来描述任何负责数据处理或转换的对象。比如 C++ 流中的标准库函数 `std::setw`, `std::setprecision` 等都可以视为流控制器 (stream manipulators),它们调整输入/输出格式的行为方式[^3]。 对于增强现实界面的设计而言,Frank Regal 等人的研究展示了如何通过 AR 技术构建命令与监控大型多代理团队的人机交互方案[^2]。这表明即使是在虚拟环境中,“操控者”的角色依然重要——无论是实际硬件还是软件模拟版本都需要精确规划路径及行为逻辑才能有效运作。 综上所述,无论是在实体世界里作为机器手臂存在还是抽象意义上代表某种形式的数据处理器件,manipulator 都扮演着不可或缺的角色。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值