The original text is transferred from http://blog.csdn.net/timzc/article/details/6053198
Vtkpoints:setpoint (vtkidtype ID, double x[3]) and insertpoint (Vtkidtype ID, double x[3]) can set the Vtkidtype (similar to ID values) and three-dimensional coordinates of a point. The difference between two functions is that Insertpoint has to complete the range check and memory allocation of the point first, and the index is slower. Note: The essence of these two functions is to invoke settuple (const vtkidtype i, const float *tuple) and inserttuple (const vtkidtype i, const float *tuple) the value in the first position of the array. Applies to all arrays such as bit/char/data/double/float. such as voidfloatarray::settuple (const vtkidtype i, const float *tuple); Parameter 1 position, parameter 2 actual data: Pcoords->settuple (i, pts[i]);
Vtkcellarray the cell unit, call the Insertnextcell function to incrementally add new cells, such as function Vtkcellarray::insertnextcell (Vtkidtype npts, Vtkidtype * PTS) The first parameter value is the number of midpoint in the cell, and the second parameter points to the coordinate data of those points. (Note: Vtkidtype *pts, stored in the points of the included points in the order of information, the number of course should be consistent with the previous npts. Here, 2 points can be connected to a line, three points can get a face. That is to say: Theinformation about the point, line and surface in VTK is stored in the Cellarray, the application is also directly to the Cellarray pointer processing, data writes and reads in Vtkcellarray class completes.
The next task is to define a vtkpolydata, which includes the vertices, lines, polygons, triangular bands, the geometric structure, namely three-dimensional entities . Here through the function setpoints set point information, Setpolys set cell array to define the polygon, cell array set unit arrangement (cell array) definition line, Setstrips set cell arrangement (cell Array) defines a triangle with strip,setverts to set vertices, and so forth.
#include "stdafx.h"
#include "VtkCellArray.h"
#include "VtkDoubleArray.h"
#include "VtkFloatArray.h"
#include "VtkIntArray.h"
#include "VtkPointData.h"
#include "VtkPoints.h"
#include "VtkPolyData.h"
#include "VtkPolyDataMapper.h"
#include "VtkRenderWindow.h"
#include "VtkRenderWindowInteractor.h"
#include "VtkRenderer.h"
int _tmain (int argc, _tchar* argv[])
{
int i;
Create a floating-point array to store the "dot"
Vtkfloatarray *pcoords = Vtkfloatarray::new ();
Set dimension, point->3
Pcoords->setnumberofcomponents (3);
Set the number of arrays
Pcoords->setnumberoftuples (4);
Specify each array, the specific point coordinates
Float Pts[4][3] = {0.0, 0.0, 0.0}, {0.0, 1.0, 0.0},
{1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}};
for (i=0; i<4; i++)
{
Set the points in an array
Pcoords->settuple (i, pts[i]);
}
Vtkpoints *points = Vtkpoints::new ();
Get four Points
Points->setdata (pcoords);
Create a grid array
Vtkcellarray *strips = Vtkcellarray::new ();
The set unit consists of several points
/* Strips->insertnextcell (4);
Strips->insertcellpoint (0);
Strips->insertcellpoint (1);
Strips->insertcellpoint (2);
Strips->insertcellpoint (3);
Strips->insertnextcell (3);
Strips->insertcellpoint (0);
Strips->insertcellpoint (1);
Strips->insertcellpoint (2);
Strips->insertcellpoint (3);
Creating an array of integers
Vtkintarray *temperature = Vtkintarray::new ();
Temperature->setname ("Temperature");
Temperature->insertnextvalue (60);
Temperature->insertnextvalue (70);
Temperature->insertnextvalue (80);
Temperature->insertnextvalue (90);
///Create a double array
Vtkdoublearray *vorticity = Vtkdoublearray::new ();
Vorticity->setname ("vorticity");
Vorticity->insertnextvalue (2.7);
Vorticity->insertnextvalue (4.1);
Vorticity->insertnextvalue (5.3);
Vorticity->insertnextvalue (3.4);
To create a dataset
Vtkpolydata *polydata = Vtkpolydata::new ();
Specify dots and grids
Polydata->setpoints (points);
Polydata->setstrips (strips);
Specify scalar
Polydata->getpointdata ()->setscalars (temperature);
Polydata->getpointdata ()->addarray (vorticity);
Vtkpolydatamapper *mapper = Vtkpolydatamapper::new ();
Mapper->setinput (Polydata);
Mapper->setscalarrange (0, 40);
Create an actor.
Vtkactor* actor = vtkactor::new ();
Actor->setmapper (mapper);
Create the rendering objects.
vtkrenderer* ren = vtkrenderer::new ();
Ren->addactor (actor);
vtkrenderwindow* Renwin = Vtkrenderwindow::new ();
Renwin->addrenderer (ren);
vtkrenderwindowinteractor* Iren = Vtkrenderwindowinteractor::new ();
Iren->setrenderwindow (Renwin);
Iren->initialize ();
Iren->start ();
return 0;
}