]> Creatis software - clitk.git/blob - vv/vvGlyphSource.cxx
remove antique RCS headers
[clitk.git] / vv / vvGlyphSource.cxx
1 /*=========================================================================
2
3  Program:   vv
4  Language:  C++
5  Author :   Pierre Seroul (pierre.seroul@gmail.com)
6
7 Copyright (C) 2008
8 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
9 CREATIS-LRMN http://www.creatis.insa-lyon.fr
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, version 3 of the License.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 =========================================================================*/
24 #include "vvGlyphSource.h"
25
26 #include "vtkCellArray.h"
27 #include "vtkCellData.h"
28 #include "vtkMath.h"
29 #include "vtkInformation.h"
30 #include "vtkInformationVector.h"
31 #include "vtkObjectFactory.h"
32 #include "vtkPolyData.h"
33 #include "vtkUnsignedCharArray.h"
34
35 vtkCxxRevisionMacro(vvGlyphSource, "$Revision: 1.2 $");
36 vtkStandardNewMacro(vvGlyphSource);
37
38
39 //----------------------------------------------------------------------------
40 int vvGlyphSource::RequestData(
41     vtkInformation *vtkNotUsed(request),
42     vtkInformationVector **vtkNotUsed(inputVector),
43     vtkInformationVector *outputVector)
44 {
45     // get the info object
46     vtkInformation *outInfo = outputVector->GetInformationObject(0);
47
48     // get the ouptut
49     vtkPolyData *output = vtkPolyData::SafeDownCast(
50                               outInfo->Get(vtkDataObject::DATA_OBJECT()));
51
52     //Allocate storage
53     vtkPoints *pts = vtkPoints::New();
54     pts->Allocate(6,6);
55     vtkCellArray *verts = vtkCellArray::New();
56     verts->Allocate(verts->EstimateSize(1,1),1);
57     vtkCellArray *lines = vtkCellArray::New();
58     lines->Allocate(lines->EstimateSize(4,2),2);
59     vtkCellArray *polys = vtkCellArray::New();
60     polys->Allocate(polys->EstimateSize(1,4),4);
61     vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
62     colors->SetNumberOfComponents(3);
63     colors->Allocate(2,2);
64
65     this->ConvertColor();
66
67     //Special options
68     if ( this->Dash )
69     {
70         int filled = this->Filled;
71         this->Filled = 0;
72         this->CreateDash(pts,lines,polys,colors,this->Scale2);
73         this->Filled = filled;
74     }
75     if ( this->Cross )
76     {
77         int filled = this->Filled;
78         this->Filled = 0;
79         this->CreateCross(pts,lines,polys,colors,this->Scale2);
80         this->Filled = filled;
81     }
82
83     //Call the right function
84     switch (this->GlyphType)
85     {
86     case VTK_NO_GLYPH:
87         break;
88     case VTK_VERTEX_GLYPH:
89         this->CreateVertex(pts,verts,colors);
90         break;
91     case VTK_DASH_GLYPH:
92         this->CreateDash(pts,lines,polys,colors,this->Scale);
93         break;
94     case VTK_CROSS_GLYPH:
95         this->CreateCross(pts,lines,polys,colors,this->Scale);
96         break;
97     case VTK_THICKCROSS_GLYPH:
98         this->CreateThickCross(pts,lines,polys,colors);
99         break;
100     case VTK_TRIANGLE_GLYPH:
101         this->CreateTriangle(pts,lines,polys,colors);
102         break;
103     case VTK_SQUARE_GLYPH:
104         this->CreateSquare(pts,lines,polys,colors);
105         break;
106     case VTK_CIRCLE_GLYPH:
107         this->CreateCircle(pts,lines,polys,colors);
108         break;
109     case VTK_DIAMOND_GLYPH:
110         this->CreateDiamond(pts,lines,polys,colors);
111         break;
112     case VTK_ARROW_GLYPH:
113         this->CreateArrow(pts,lines,polys,colors);
114         break;
115     case VTK_THICKARROW_GLYPH:
116         this->CreateThickArrow(pts,lines,polys,colors);
117         break;
118     case VTK_HOOKEDARROW_GLYPH:
119         this->CreateHookedArrow(pts,lines,polys,colors);
120         break;
121     case VTK_EDGEARROW_GLYPH:
122         this->CreateEdgeArrow(pts,lines,polys,colors);
123         break;
124     case VTK_SPECIFICARROW_GLYPH:
125         this->CreateSpecificArrow(pts,lines,polys,colors);
126         break;
127     }
128
129     this->TransformGlyph(pts);
130
131     //Clean up
132     output->SetPoints(pts);
133     pts->Delete();
134
135     output->SetVerts(verts);
136     verts->Delete();
137
138     output->SetLines(lines);
139     lines->Delete();
140
141     output->SetPolys(polys);
142     polys->Delete();
143
144     output->GetCellData()->SetScalars(colors);
145     colors->Delete();
146
147     return 1;
148 }
149
150 void vvGlyphSource::CreateSpecificArrow(vtkPoints *pts, vtkCellArray *lines,
151                                         vtkCellArray *polys, vtkUnsignedCharArray *colors)
152 {
153     //stem
154     vtkIdType ptIds[3];
155     ptIds[0] = pts->InsertNextPoint( 0.0, 0.0, 0.0);
156     ptIds[1] = pts->InsertNextPoint(  1.0, 0.0, 0.0);
157     lines->InsertNextCell(2,ptIds);
158     colors->InsertNextValue(0);
159     colors->InsertNextValue(0);
160     colors->InsertNextValue(1);
161
162     //arrow head
163     ptIds[0] = pts->InsertNextPoint( 0.7, -0.1, 0.0);
164     ptIds[1] = pts->InsertNextPoint( 1.0,  0.0, 0.0);
165     ptIds[2] = pts->InsertNextPoint( 0.7,  0.1, 0.0);
166     lines->InsertNextCell(3,ptIds);
167     colors->InsertNextValue(0);
168     colors->InsertNextValue(1);
169     colors->InsertNextValue(0);
170 }
171
172 void vvGlyphSource::PrintSelf(ostream& os, vtkIndent indent)
173 {
174     this->Superclass::PrintSelf(os, indent);
175 }