OpenCV tutorials--creating Widgets

Source: Internet
Author: User

Explanation
  • Extend Widget3d class to create a new 3D widget.
  • Assign a VTK actor to the widget.
  • Set color of the widget.
  • Construct a triangle widget and display it in the window.
Code
#include <opencv2/viz/vizcore.hpp> #include <opencv2/viz/widget_accessor.hpp> #include <iostream> #include <vtkPoints.h> #include <vtkTriangle.h> #include <vtkCellArray.h> #include < vtkpolydata.h> #include <vtkPolyDataMapper.h> #include <vtkIdList.h> #include <vtkactor.h># Include <vtkprop.h>using namespace cv;using namespace std;/** * @class Wtriangle * @brief defining our own 3D Triang Le widget */class wtriangle:public viz::widget3d{public:wtriangle (const point3f &AMP;PT1, const point3f &amp ;p T2, const point3f &AMP;PT3, const viz::color & Color = Viz::color::white ());};/ * * @function wtriangle::wtriangle */wtriangle::wtriangle (const point3f &AMP;PT1, const point3f &AMP;PT2, const point3f & AMP;PT3, const Viz::color & Color) {//Create a triangle vtksmartpointer<vtkpoints> points = Vtksmartpoint    Er<vtkpoints>::new ();    Points->insertnextpoint (pt1.x, Pt1.y, pt1.z); Points->insertnexTpoint (pt2.x, Pt2.y, pt2.z);    Points->insertnextpoint (pt3.x, Pt3.y, pt3.z);    Vtksmartpointer<vtktriangle> triangle = vtksmartpointer<vtktriangle>::new ();    Triangle->getpointids ()->setid (0,0);    Triangle->getpointids ()->setid ();    Triangle->getpointids ()->setid (2,2);    Vtksmartpointer<vtkcellarray> cells = vtksmartpointer<vtkcellarray>::new ();    Cells->insertnextcell (triangle);    Create a Polydata object vtksmartpointer<vtkpolydata> polydata = Vtksmartpointer<vtkpolydata>::new ();    Add the geometry and topology to the Polydata polydata->setpoints (points);    Polydata->setpolys (cells); Create Mapper and actor vtksmartpointer<vtkpolydatamapper> mapper = Vtksmartpointer<vtkpolydatamapper>:    : New (); #if vtk_major_version <= 5 mapper->setinput (polydata); #else mapper->setinputdata (polydata); #endif Vtksmartpointer<vtkactor> actor = VTKSMARTPOINTER&LT;VTKACTOR&GT;::new ();    Actor->setmapper (mapper);    Store This actor in the widgets in order that visualizer can access it Viz::widgetaccessor::setprop (*this, actor); Set the color of the widget.    This have to is called after Widgetaccessor. SetColor (color);}    /** * @function main */int main () {//Create a window viz::viz3d mywindow ("Creating Widgets"); Create a triangle widget wtriangle tw (point3f (0.0,0.0,0.0), point3f (1.0,1.0,1.0), point3f (0.0,1.0,0.0), Viz::color:    : Red ());    Show widget in the visualizer window Mywindow.showwidget ("TRIANGLE", TW);    Start event Loop Mywindow.spin (); return 0;}

OpenCV tutorials--creating Widgets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.