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; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算法来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算法(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算法会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值