]> Creatis software - clitk.git/blob - vv/vvGlyphSource.cxx
removed headers
[clitk.git] / vv / vvGlyphSource.cxx
1 #include "vvGlyphSource.h"
2
3 #include "vtkCellArray.h"
4 #include "vtkCellData.h"
5 #include "vtkMath.h"
6 #include "vtkInformation.h"
7 #include "vtkInformationVector.h"
8 #include "vtkObjectFactory.h"
9 #include "vtkPolyData.h"
10 #include "vtkUnsignedCharArray.h"
11
12 vtkCxxRevisionMacro(vvGlyphSource, "DummyRevision");
13 vtkStandardNewMacro(vvGlyphSource);
14
15
16 //----------------------------------------------------------------------------
17 int vvGlyphSource::RequestData(
18     vtkInformation *vtkNotUsed(request),
19     vtkInformationVector **vtkNotUsed(inputVector),
20     vtkInformationVector *outputVector)
21 {
22     // get the info object
23     vtkInformation *outInfo = outputVector->GetInformationObject(0);
24
25     // get the ouptut
26     vtkPolyData *output = vtkPolyData::SafeDownCast(
27                               outInfo->Get(vtkDataObject::DATA_OBJECT()));
28
29     //Allocate storage
30     vtkPoints *pts = vtkPoints::New();
31     pts->Allocate(6,6);
32     vtkCellArray *verts = vtkCellArray::New();
33     verts->Allocate(verts->EstimateSize(1,1),1);
34     vtkCellArray *lines = vtkCellArray::New();
35     lines->Allocate(lines->EstimateSize(4,2),2);
36     vtkCellArray *polys = vtkCellArray::New();
37     polys->Allocate(polys->EstimateSize(1,4),4);
38     vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
39     colors->SetNumberOfComponents(3);
40     colors->Allocate(2,2);
41
42     this->ConvertColor();
43
44     //Special options
45     if ( this->Dash )
46     {
47         int filled = this->Filled;
48         this->Filled = 0;
49         this->CreateDash(pts,lines,polys,colors,this->Scale2);
50         this->Filled = filled;
51     }
52     if ( this->Cross )
53     {
54         int filled = this->Filled;
55         this->Filled = 0;
56         this->CreateCross(pts,lines,polys,colors,this->Scale2);
57         this->Filled = filled;
58     }
59
60     //Call the right function
61     switch (this->GlyphType)
62     {
63     case VTK_NO_GLYPH:
64         break;
65     case VTK_VERTEX_GLYPH:
66         this->CreateVertex(pts,verts,colors);
67         break;
68     case VTK_DASH_GLYPH:
69         this->CreateDash(pts,lines,polys,colors,this->Scale);
70         break;
71     case VTK_CROSS_GLYPH:
72         this->CreateCross(pts,lines,polys,colors,this->Scale);
73         break;
74     case VTK_THICKCROSS_GLYPH:
75         this->CreateThickCross(pts,lines,polys,colors);
76         break;
77     case VTK_TRIANGLE_GLYPH:
78         this->CreateTriangle(pts,lines,polys,colors);
79         break;
80     case VTK_SQUARE_GLYPH:
81         this->CreateSquare(pts,lines,polys,colors);
82         break;
83     case VTK_CIRCLE_GLYPH:
84         this->CreateCircle(pts,lines,polys,colors);
85         break;
86     case VTK_DIAMOND_GLYPH:
87         this->CreateDiamond(pts,lines,polys,colors);
88         break;
89     case VTK_ARROW_GLYPH:
90         this->CreateArrow(pts,lines,polys,colors);
91         break;
92     case VTK_THICKARROW_GLYPH:
93         this->CreateThickArrow(pts,lines,polys,colors);
94         break;
95     case VTK_HOOKEDARROW_GLYPH:
96         this->CreateHookedArrow(pts,lines,polys,colors);
97         break;
98     case VTK_EDGEARROW_GLYPH:
99         this->CreateEdgeArrow(pts,lines,polys,colors);
100         break;
101     case VTK_SPECIFICARROW_GLYPH:
102         this->CreateSpecificArrow(pts,lines,polys,colors);
103         break;
104     }
105
106     this->TransformGlyph(pts);
107
108     //Clean up
109     output->SetPoints(pts);
110     pts->Delete();
111
112     output->SetVerts(verts);
113     verts->Delete();
114
115     output->SetLines(lines);
116     lines->Delete();
117
118     output->SetPolys(polys);
119     polys->Delete();
120
121     output->GetCellData()->SetScalars(colors);
122     colors->Delete();
123
124     return 1;
125 }
126
127 void vvGlyphSource::CreateSpecificArrow(vtkPoints *pts, vtkCellArray *lines,
128                                         vtkCellArray *polys, vtkUnsignedCharArray *colors)
129 {
130     //stem
131     vtkIdType ptIds[3];
132     ptIds[0] = pts->InsertNextPoint( 0.0, 0.0, 0.0);
133     ptIds[1] = pts->InsertNextPoint(  1.0, 0.0, 0.0);
134     lines->InsertNextCell(2,ptIds);
135     colors->InsertNextValue(0);
136     colors->InsertNextValue(0);
137     colors->InsertNextValue(1);
138
139     //arrow head
140     ptIds[0] = pts->InsertNextPoint( 0.7, -0.1, 0.0);
141     ptIds[1] = pts->InsertNextPoint( 1.0,  0.0, 0.0);
142     ptIds[2] = pts->InsertNextPoint( 0.7,  0.1, 0.0);
143     lines->InsertNextCell(3,ptIds);
144     colors->InsertNextValue(0);
145     colors->InsertNextValue(1);
146     colors->InsertNextValue(0);
147 }
148
149 void vvGlyphSource::PrintSelf(ostream& os, vtkIndent indent)
150 {
151     this->Superclass::PrintSelf(os, indent);
152 }