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