11 #include <vtkPoints.h>
12 #include <vtkTriangle.h>
13 #include <vtkCellArray.h>
14 #include <vtkPolyData.h>
15 #include <vtkPolyDataMapper.h>
16 #include <vtkIdList.h>
30 <<
"--------------------------------------------------------------------------" << endl
31 <<
"This program shows how to create a custom widget. You can create your own "
32 <<
"widgets by extending Widget2D/Widget3D, and with the help of WidgetAccessor." << endl
34 <<
"./creating_widgets" << endl
55 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
56 points->InsertNextPoint(pt1.
x, pt1.
y, pt1.
z);
57 points->InsertNextPoint(pt2.
x, pt2.
y, pt2.
z);
58 points->InsertNextPoint(pt3.
x, pt3.
y, pt3.
z);
60 vtkSmartPointer<vtkTriangle>
triangle = vtkSmartPointer<vtkTriangle>::New();
61 triangle->GetPointIds()->SetId(0,0);
62 triangle->GetPointIds()->SetId(1,1);
63 triangle->GetPointIds()->SetId(2,2);
65 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
66 cells->InsertNextCell(triangle);
69 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
72 polyData->SetPoints(points);
73 polyData->SetPolys(cells);
76 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
77 #if VTK_MAJOR_VERSION <= 5
78 mapper->SetInput(polyData);
80 mapper->SetInputData(polyData);
83 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
84 actor->SetMapper(mapper);
107 myWindow.showWidget(
"TRIANGLE", tw);
Template class for 3D points specified by its coordinates x, y and z.
Definition: types.hpp:218
_Tp y
Definition: types.hpp:243
Point3_< float > Point3f
Definition: types.hpp:247
_Tp x
Definition: types.hpp:243
This class a represents BGR color.
Definition: types.hpp:63
The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :
Definition: viz3d.hpp:67
_Tp z
Definition: types.hpp:243
Definition: gr_skig.hpp:63
int main(int argc, const char *argv[])
Definition: facerec_demo.cpp:67
Here is the result of the program.