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