The way of VTK learning--painting my Little apple

Source: Internet
Author: User

The dataset consists primarily of the point set data that describes the geometry of the dataset and the cells that make up the dataset, so the main task of building the dataset is to identify the point set and the building Unit, the sample program builds an Apple entity, and then it paints Apple, and the sample program executes the following steps:
1, first determine the outer contour of the Apple control points, the formation of point set.
2, build a line unit.
3, build the polygon data, connect the points set together to draw a line.
4, using the pressing filter to rotate the contour line, forming an apple surface entity.
5. Drawing Apples

The code for the sample program is as follows:

#include "stdafx.h" #include <vtkPoints.h> #include <vtkSmartPointer.h> #include <vtkcellarray.h># Include <vtkPolyData.h> #include <vtkPolyDataMapper.h> #include <vtkrotationalextrusionfilter.h># Include <vtkActor.h> #include <vtkProperty.h> #include <vtkRenderer.h> #include <    vtkrenderwindow.h> #include <vtkrenderwindowinteractor.h>int _tmain (int argc, _tchar* argv[]) {//define the point coordinates of the Apple contour line    Vtksmartpointer<vtkpoints>ppoints=vtkpoints::new ();    Ppoints->insertpoint (0,0.0,0.0,1.5);    Ppoints->insertpoint (1,1.0,0.0,1);    Ppoints->insertpoint (2,2.0,0.0,1.5);    Ppoints->insertpoint (3,3.0,0.0,2.5);    Ppoints->insertpoint (4,3.5,0.0,3.0);    Ppoints->insertpoint (5,4.0,0.0,5.0);    Ppoints->insertpoint (6,3.5,0.0,6.0);    Ppoints->insertpoint (7,2.0,0.0,7.0);    Ppoints->insertpoint (8,1.0,0.0,6.0);    Ppoints->insertpoint (9,0.0,0.0,5.0); Building line units, drawing contour lines vtksmartpointer<vtkcellarray>plinecell=Vtkcellarray::new ();    Construct a unit consisting of 10 points plinecell->insertnextcell (10);    Index number of the constituent cell point set plinecell->insertcellpoint (0);    Plinecell->insertcellpoint (1);    Plinecell->insertcellpoint (2);    Plinecell->insertcellpoint (3);    Plinecell->insertcellpoint (4);    Plinecell->insertcellpoint (5);    Plinecell->insertcellpoint (6);    Plinecell->insertcellpoint (7);    Plinecell->insertcellpoint (8);    Plinecell->insertcellpoint (9);    Defines a polygon dataset vtksmartpointer<vtkpolydata>ppolydata=vtkpolydata::new ();    Sets the geometry data ppolydata->setpoints (ppoints) that make up the polygon;    Set the cell type, line unit ppolydata->setlines (Plinecell); Suppress contour lines to form Apple solid Vtksmartpointer<vtkrotationalextrusionfilter>pextrufilter=vtkrotationalextrusionfilter::    New ();    Pextrufilter->setinput (Ppolydata);    Setting the smoothness parameter of the apple surface, the surface of Apple is composed of pextrufilter->setresolution (10).   Map data to the graphics system for plotting vtksmartpointer<vtkpolydatamapper>pmap=vtkpolydatamapper::new (); Pmap->setinpUT (Pextrufilter->getoutput ());   Vtksmartpointer<vtkactor>pactor=vtkactor::new ();   Pactor->setmapper (PMAP);    Pactor->getproperty ()->setcolor (0.0,1.0,0.0);   Draw Vtksmartpointer<vtkrenderer>pren=vtkrenderer::new ();   Pren->addactor (Pactor);   Create a drawing form vtksmartpointer<vtkrenderwindow>prenwin=vtkrenderwindow::new ();   Prenwin->addrenderer (PRen);   Create the vtksmartpointer<vtkrenderwindowinteractor>piren=vtkrenderwindowinteractor::new ();    Piren->setrenderwindow (Prenwin);   Set Background color pren->setbackground (1,1,1);   Set window size prenwin->setsize (300,300);   Prenwin->render ();   Pren->resetcamera ();   Start Drawing piren->initialize ();   Piren->start (); return 0;}


Several angles of the results










The way of VTK learning--painting my Little apple

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.