]> Creatis software - clitk.git/blob - vv/vvGlyphSource.cxx
Reformatted using new coding style
[clitk.git] / vv / vvGlyphSource.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #include "vvGlyphSource.h"
19
20 #include "vtkCellArray.h"
21 #include "vtkCellData.h"
22 #include "vtkMath.h"
23 #include "vtkInformation.h"
24 #include "vtkInformationVector.h"
25 #include "vtkObjectFactory.h"
26 #include "vtkPolyData.h"
27 #include "vtkUnsignedCharArray.h"
28
29 vtkCxxRevisionMacro(vvGlyphSource, "DummyRevision");
30 vtkStandardNewMacro(vvGlyphSource);
31
32
33 //----------------------------------------------------------------------------
34 int vvGlyphSource::RequestData(
35   vtkInformation *vtkNotUsed(request),
36   vtkInformationVector **vtkNotUsed(inputVector),
37   vtkInformationVector *outputVector)
38 {
39   // get the info object
40   vtkInformation *outInfo = outputVector->GetInformationObject(0);
41
42   // get the ouptut
43   vtkPolyData *output = vtkPolyData::SafeDownCast(
44                           outInfo->Get(vtkDataObject::DATA_OBJECT()));
45
46   //Allocate storage
47   vtkPoints *pts = vtkPoints::New();
48   pts->Allocate(6,6);
49   vtkCellArray *verts = vtkCellArray::New();
50   verts->Allocate(verts->EstimateSize(1,1),1);
51   vtkCellArray *lines = vtkCellArray::New();
52   lines->Allocate(lines->EstimateSize(4,2),2);
53   vtkCellArray *polys = vtkCellArray::New();
54   polys->Allocate(polys->EstimateSize(1,4),4);
55   vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
56   colors->SetNumberOfComponents(3);
57   colors->Allocate(2,2);
58
59   this->ConvertColor();
60
61   //Special options
62   if ( this->Dash ) {
63     int filled = this->Filled;
64     this->Filled = 0;
65     this->CreateDash(pts,lines,polys,colors,this->Scale2);
66     this->Filled = filled;
67   }
68   if ( this->Cross ) {
69     int filled = this->Filled;
70     this->Filled = 0;
71     this->CreateCross(pts,lines,polys,colors,this->Scale2);
72     this->Filled = filled;
73   }
74
75   //Call the right function
76   switch (this->GlyphType) {
77   case VTK_NO_GLYPH:
78     break;
79   case VTK_VERTEX_GLYPH:
80     this->CreateVertex(pts,verts,colors);
81     break;
82   case VTK_DASH_GLYPH:
83     this->CreateDash(pts,lines,polys,colors,this->Scale);
84     break;
85   case VTK_CROSS_GLYPH:
86     this->CreateCross(pts,lines,polys,colors,this->Scale);
87     break;
88   case VTK_THICKCROSS_GLYPH:
89     this->CreateThickCross(pts,lines,polys,colors);
90     break;
91   case VTK_TRIANGLE_GLYPH:
92     this->CreateTriangle(pts,lines,polys,colors);
93     break;
94   case VTK_SQUARE_GLYPH:
95     this->CreateSquare(pts,lines,polys,colors);
96     break;
97   case VTK_CIRCLE_GLYPH:
98     this->CreateCircle(pts,lines,polys,colors);
99     break;
100   case VTK_DIAMOND_GLYPH:
101     this->CreateDiamond(pts,lines,polys,colors);
102     break;
103   case VTK_ARROW_GLYPH:
104     this->CreateArrow(pts,lines,polys,colors);
105     break;
106   case VTK_THICKARROW_GLYPH:
107     this->CreateThickArrow(pts,lines,polys,colors);
108     break;
109   case VTK_HOOKEDARROW_GLYPH:
110     this->CreateHookedArrow(pts,lines,polys,colors);
111     break;
112   case VTK_EDGEARROW_GLYPH:
113     this->CreateEdgeArrow(pts,lines,polys,colors);
114     break;
115   case VTK_SPECIFICARROW_GLYPH:
116     this->CreateSpecificArrow(pts,lines,polys,colors);
117     break;
118   }
119
120   this->TransformGlyph(pts);
121
122   //Clean up
123   output->SetPoints(pts);
124   pts->Delete();
125
126   output->SetVerts(verts);
127   verts->Delete();
128
129   output->SetLines(lines);
130   lines->Delete();
131
132   output->SetPolys(polys);
133   polys->Delete();
134
135   output->GetCellData()->SetScalars(colors);
136   colors->Delete();
137
138   return 1;
139 }
140
141 void vvGlyphSource::CreateSpecificArrow(vtkPoints *pts, vtkCellArray *lines,
142                                         vtkCellArray *polys, vtkUnsignedCharArray *colors)
143 {
144   //stem
145   vtkIdType ptIds[3];
146   ptIds[0] = pts->InsertNextPoint( 0.0, 0.0, 0.0);
147   ptIds[1] = pts->InsertNextPoint(  1.0, 0.0, 0.0);
148   lines->InsertNextCell(2,ptIds);
149   colors->InsertNextValue(0);
150   colors->InsertNextValue(0);
151   colors->InsertNextValue(1);
152
153   //arrow head
154   ptIds[0] = pts->InsertNextPoint( 0.7, -0.1, 0.0);
155   ptIds[1] = pts->InsertNextPoint( 1.0,  0.0, 0.0);
156   ptIds[2] = pts->InsertNextPoint( 0.7,  0.1, 0.0);
157   lines->InsertNextCell(3,ptIds);
158   colors->InsertNextValue(0);
159   colors->InsertNextValue(1);
160   colors->InsertNextValue(0);
161 }
162
163 void vvGlyphSource::PrintSelf(ostream& os, vtkIndent indent)
164 {
165   this->Superclass::PrintSelf(os, indent);
166 }