The way of VTK learning--painting my Little apple

Source: Internet
Author: User

The data set consists mainly of the point set data describing the geometry of the data set and the units that make up the data set, so the main task of building the dataset is to determine the point set and the building unit, and this demo sample program builds an Apple entity and then draws the apple. The procedure for demonstrating the sample program runs such as the following:
1, first determine the outer contour of the Apple control point. Form a point set.


2, build a line unit.


3, build polygon data. Link these point sets together to draw a line.
4, adopt the pressing filter to rotate the contour line, forming the apple surface entity.
5. Drawing Apples

The code for the Demo 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); Build line units. Draw 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);    Set the smoothness of the apple surface, the surface of the 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 drawing window 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.