]> Creatis software - clitk.git/blob - vv/vvLandmarksGlyph.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvLandmarksGlyph.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 "vvLandmarksGlyph.h"
19
20 #include "vtkCellArray.h"
21 #include "vtkInformation.h"
22 #include "vtkInformationVector.h"
23 #include "vtkObjectFactory.h"
24 #include "vtkPointData.h"
25 #include "vtkPoints.h"
26 #include "vtkPolyData.h"
27 #include "vtkUnsignedCharArray.h"
28 #include <cassert>
29
30 vtkStandardNewMacro(vvLandmarksGlyph);
31
32 #define vtkfont_width 9
33 //#define vtkfont_width 14
34 #define vtkfont_row_width 864
35 #define vtkfont_height 15
36 //#define vtkfont_height 20
37 static unsigned char vtkfont_bits[] = {
38   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
39   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
41   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
42   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
43   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
44   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
45   0x00,0x00,0xe0,0x00,0x10,0x90,0x00,0x00,0x40,0x88,0x03,0x1c,0x10,0x08,0x00,
46   0x00,0x00,0x00,0x00,0x00,0x20,0x1c,0x10,0xf8,0xf8,0x03,0xe2,0x0f,0x8f,0x3f,
47   0x3e,0x7c,0x00,0x00,0x00,0x02,0x80,0x00,0x1f,0x3e,0x10,0xfc,0xf0,0xf1,0xe3,
48   0xcf,0x1f,0x1f,0x41,0x7c,0xe0,0x09,0x12,0x20,0x48,0x10,0x1f,0x3f,0x7c,0xfc,
49   0xf0,0xf1,0x27,0x48,0x90,0x20,0x41,0x82,0xfc,0xe1,0x11,0xc0,0x03,0x02,0x00,
50   0x0e,0x00,0x04,0x00,0x00,0x04,0x00,0x0e,0x00,0x01,0x00,0x00,0x08,0xc0,0x00,
51   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
52   0x80,0x83,0xe0,0x80,0x11,0xe0,0x00,0x10,0x90,0x90,0x80,0xa0,0x44,0x04,0x0c,
53   0x08,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x22,0x18,0x04,0x01,0x02,0x23,
54   0x80,0x00,0x20,0x41,0x82,0x00,0x00,0x00,0x01,0x00,0x81,0x20,0x41,0x28,0x08,
55   0x09,0x22,0x44,0x80,0x80,0x20,0x41,0x10,0x80,0x08,0x11,0x20,0x48,0x90,0x20,
56   0x41,0x82,0x04,0x09,0x82,0x20,0x48,0x90,0x20,0x41,0x82,0x00,0x21,0x20,0x00,
57   0x02,0x05,0x00,0x0c,0x00,0x04,0x00,0x00,0x04,0x00,0x11,0x00,0x01,0x10,0x80,
58   0x08,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
59   0x00,0x00,0x00,0x40,0x80,0x00,0x41,0x12,0xe0,0x00,0x10,0x90,0x90,0xe0,0xa3,
60   0x44,0x04,0x02,0x08,0x10,0x00,0x40,0x00,0x00,0x00,0x00,0x10,0x41,0x14,0x04,
61   0x01,0x81,0x22,0x40,0x00,0x20,0x41,0x82,0x00,0x00,0x80,0x00,0x00,0x82,0x20,
62   0x41,0x44,0x08,0x09,0x20,0x44,0x80,0x80,0x00,0x41,0x10,0x80,0x88,0x10,0x60,
63   0xcc,0x90,0x20,0x41,0x82,0x04,0x09,0x80,0x20,0x48,0x90,0x20,0x22,0x44,0x80,
64   0x20,0x20,0x00,0x82,0x08,0x00,0x10,0x00,0x04,0x00,0x00,0x04,0x00,0x11,0x00,
65   0x01,0x00,0x00,0x08,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
66   0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x41,0x0c,0xe0,0x00,0x10,0x00,
67   0xf8,0x91,0x40,0x42,0x04,0x00,0x04,0x20,0x88,0x40,0x00,0x00,0x00,0x00,0x08,
68   0x41,0x10,0x00,0x81,0x40,0xa2,0x47,0x00,0x10,0x41,0x82,0x20,0x40,0x40,0x00,
69   0x00,0x04,0x20,0x79,0x82,0x08,0x09,0x20,0x44,0x80,0x80,0x00,0x41,0x10,0x80,
70   0x48,0x10,0xa0,0x4a,0x91,0x20,0x41,0x82,0x04,0x09,0x80,0x20,0x88,0x88,0x20,
71   0x14,0x28,0x40,0x20,0x40,0x00,0x42,0x10,0x00,0x00,0x7c,0xf4,0xf0,0xe1,0xc5,
72   0x07,0x01,0x2f,0x3d,0x18,0xe0,0x08,0x82,0xe0,0x46,0x0f,0x1f,0x3d,0xbc,0xe4,
73   0xf0,0xf1,0x23,0x44,0x90,0x20,0x41,0x42,0xfc,0x81,0x80,0x80,0x00,0x00,0xe0,
74   0x00,0x10,0x00,0x90,0x90,0x00,0x81,0x03,0x00,0x04,0x20,0x50,0x40,0x00,0x00,
75   0x00,0x00,0x04,0x41,0x10,0x80,0xc0,0x21,0x62,0x48,0x0f,0x08,0x3e,0xc2,0x70,
76   0xe0,0x20,0xe0,0x0f,0x08,0x10,0x45,0x82,0xf8,0x08,0x20,0xc4,0x83,0x87,0x00,
77   0x7f,0x10,0x80,0x38,0x10,0xa0,0x4a,0x92,0x20,0x3f,0x82,0xfc,0xf0,0x81,0x20,
78   0x88,0x88,0x24,0x08,0x10,0x20,0x20,0x80,0x00,0x02,0x00,0x00,0x00,0x80,0x0c,
79   0x09,0x12,0x26,0x08,0x81,0x10,0x43,0x10,0x80,0x88,0x81,0x20,0xc9,0x90,0x20,
80   0x43,0xc2,0x18,0x09,0x42,0x20,0x44,0x90,0x20,0x22,0x42,0x80,0x60,0x80,0x00,
81   0x03,0x00,0xe0,0x00,0x10,0x00,0x90,0xe0,0x03,0x41,0x04,0x00,0x04,0x20,0xfc,
82   0xf9,0x03,0xe0,0x0f,0x00,0x04,0x41,0x10,0x40,0x00,0x12,0x02,0xc8,0x10,0x04,
83   0x41,0xbc,0x20,0x40,0x20,0x00,0x00,0x08,0x08,0x65,0x82,0x08,0x09,0x20,0x44,
84   0x80,0x80,0x38,0x41,0x10,0x80,0x28,0x10,0x20,0x49,0x94,0x20,0x01,0x82,0x24,
85   0x00,0x82,0x20,0x88,0x88,0x24,0x08,0x10,0x10,0x20,0x80,0x00,0x02,0x00,0x00,
86   0x00,0x80,0x04,0x09,0x10,0x24,0xc8,0x87,0x10,0x41,0x10,0x80,0x68,0x80,0x20,
87   0x49,0x90,0x20,0x41,0x82,0x08,0x09,0x40,0x20,0x84,0x88,0x24,0x14,0x42,0x40,
88   0x60,0x80,0x00,0x03,0x00,0xe0,0x00,0x10,0x00,0xf8,0x81,0x84,0x44,0x14,0x00,
89   0x04,0x20,0x50,0x40,0x00,0x00,0x00,0x00,0x02,0x41,0x10,0x30,0x00,0xf2,0x07,
90   0x48,0x10,0x02,0x41,0x80,0x00,0x00,0x40,0x00,0x00,0x04,0x04,0x59,0xfe,0x08,
91   0x09,0x20,0x44,0x80,0x80,0x20,0x41,0x10,0x80,0x48,0x10,0x20,0x49,0x98,0x20,
92   0x01,0x82,0x44,0x00,0x82,0x20,0x08,0x85,0x24,0x14,0x10,0x08,0x20,0x00,0x01,
93   0x02,0x00,0x00,0x00,0xfc,0x04,0x09,0x10,0xe4,0x0f,0x81,0x10,0x41,0x10,0x80,
94   0x18,0x80,0x20,0x49,0x90,0x20,0x41,0x82,0x08,0xf0,0x41,0x20,0x84,0x88,0x24,
95   0x08,0x42,0x20,0x80,0x80,0x80,0x00,0x00,0xe0,0x00,0x10,0x00,0x90,0x80,0x44,
96   0x4a,0x08,0x00,0x08,0x10,0x88,0x40,0x00,0x00,0x00,0x00,0x01,0x41,0x10,0x08,
97   0x00,0x02,0x02,0x48,0x10,0x02,0x41,0x80,0x00,0x00,0x80,0xe0,0x0f,0x02,0x04,
98   0x01,0x82,0x08,0x09,0x20,0x44,0x80,0x80,0x20,0x41,0x10,0x80,0x88,0x10,0x20,
99   0x48,0x90,0x20,0x01,0x92,0x84,0x00,0x82,0x20,0x08,0x85,0x24,0x22,0x10,0x04,
100   0x20,0x00,0x02,0x02,0x00,0x00,0x00,0x82,0x04,0x09,0x10,0x24,0x00,0x01,0x0f,
101   0x41,0x10,0x80,0x68,0x80,0x20,0x49,0x90,0x20,0x41,0x82,0x08,0x00,0x42,0x20,
102   0x04,0x85,0x24,0x14,0x42,0x10,0x40,0x80,0x00,0x01,0x00,0xe0,0x00,0x00,0x00,
103   0x90,0xe0,0x43,0x4a,0x0c,0x00,0x08,0x10,0x00,0x40,0xc0,0x01,0x00,0x02,0x01,
104   0x22,0x10,0x04,0x08,0x02,0x22,0x48,0x10,0x01,0x41,0x40,0x20,0xe0,0x00,0x01,
105   0x00,0x01,0x00,0x01,0x82,0x08,0x09,0x22,0x44,0x80,0x80,0x20,0x41,0x10,0x84,
106   0x08,0x11,0x20,0x48,0x90,0x20,0x01,0xa2,0x04,0x09,0x82,0x20,0x08,0x85,0x2a,
107   0x41,0x10,0x04,0x20,0x00,0x02,0x02,0x00,0x00,0x00,0xc2,0x0c,0x09,0x12,0x26,
108   0x00,0x81,0x00,0x41,0x10,0x80,0x88,0x81,0x20,0x49,0x90,0x20,0x43,0xc2,0x08,
109   0x08,0x42,0x24,0x04,0x85,0x2a,0x22,0x62,0x08,0x40,0x80,0x00,0x01,0x00,0xe0,
110   0x00,0x10,0x00,0x00,0x80,0x20,0x84,0x13,0x00,0x10,0x08,0x00,0x00,0xc0,0x00,
111   0x00,0x87,0x00,0x1c,0x7c,0xfc,0xf1,0x01,0xc2,0x87,0x0f,0x01,0x3e,0x3c,0x70,
112   0x60,0x00,0x02,0x80,0x00,0x04,0x3e,0x82,0xfc,0xf0,0xf1,0xe3,0x8f,0x00,0x1f,
113   0x41,0x7c,0x78,0x08,0xf2,0x27,0x48,0x10,0x1f,0x01,0x7c,0x04,0xf1,0x81,0xc0,
114   0x07,0x02,0x11,0x41,0x10,0xfc,0xe1,0x01,0xc4,0x03,0x00,0x00,0x00,0xbc,0xf4,
115   0xf0,0xe1,0xc5,0x07,0x01,0x1f,0x41,0x7c,0x84,0x08,0xe2,0x23,0x48,0x10,0x1f,
116   0x3d,0xbc,0x08,0xf0,0x81,0xc3,0x0b,0x02,0x11,0x41,0x5c,0xfc,0x81,0x83,0xe0,
117   0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
118   0x00,0x20,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
119   0x00,0x00,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
120   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,
121   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x3f,
122   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x20,0x00,0x00,0x84,0x00,0x00,0x00,
123   0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
124   0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
125   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
126   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
127   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
128   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
129   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x20,0x00,0x00,0x84,
130   0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
131   0x00,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
132   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
133   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
134   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
135   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
136   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,
137   0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,
138   0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,
139   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
140   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
141   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
142   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
143   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
144   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
145   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0
146 };
147
148 // Construct object with no string set and backing enabled.
149 vvLandmarksGlyph::vvLandmarksGlyph()
150 {
151   this->Text = NULL;
152   this->Backing = 1;
153   this->ForegroundColor[0] = 1.0;
154   this->ForegroundColor[1] = 1.0;
155   this->ForegroundColor[2] = 1.0;
156   this->ForegroundColor[3] = 1.0;
157   this->BackgroundColor[0] = 0.0;
158   this->BackgroundColor[1] = 0.0;
159   this->BackgroundColor[2] = 0.0;
160   this->BackgroundColor[3] = 1.0;
161
162   this->SetNumberOfInputPorts(0);
163 }
164
165 vvLandmarksGlyph::~vvLandmarksGlyph()
166 {
167   if (this->Text) {
168     delete [] this->Text;
169   }
170 }
171
172 int vvLandmarksGlyph::RequestData(
173   vtkInformation *vtkNotUsed(request),
174   vtkInformationVector **vtkNotUsed(inputVector),
175   vtkInformationVector *outputVector)
176 {
177   // get the info object
178   vtkInformation *outInfo = outputVector->GetInformationObject(0);
179
180   // get the ouptut
181   vtkPolyData *output = vtkPolyData::SafeDownCast(
182                           outInfo->Get(vtkDataObject::DATA_OBJECT()));
183
184   vtkPoints *newPoints;
185   vtkCellArray *newPolys;
186   vtkCellArray *newLines;
187   vtkUnsignedCharArray *newScalars;
188
189   newPoints = vtkPoints::New();
190   newPolys = vtkCellArray::New();
191   newScalars = vtkUnsignedCharArray::New();
192   newScalars->SetNumberOfComponents(4);
193   newLines = vtkCellArray::New();
194   newLines->Allocate(newLines->EstimateSize(3,2));
195
196   AddTextGlyph(newPoints,newScalars,newPolys,0);
197   AddTextGlyph(newPoints,newScalars,newPolys,1);
198   AddTextGlyph(newPoints,newScalars,newPolys,2);
199
200   AddCrossGlyph(newPoints, newLines);
201
202   output->SetPoints(newPoints);
203   newPoints->Delete();
204
205   output->SetLines(newLines);
206   newLines->Delete();
207
208   output->GetPointData()->SetScalars(newScalars);
209   newScalars->Delete();
210
211   output->SetPolys(newPolys);
212   newPolys->Delete();
213
214   return 1;
215 }
216
217 void vvLandmarksGlyph::AddTextGlyph(vtkPoints* newPoints,vtkUnsignedCharArray* newScalars, vtkCellArray *newPolys, int orientation)
218 {
219   int row, col;
220   int pos = 0;
221   int pixelPos;
222   vtkIdType pts[5];
223   vtkIdType numPolys = 0;
224   double x[3];
225   int acol;
226   int drawingWhite = 0;
227   int drawingBlack = 0;
228   unsigned char white[4];
229   unsigned char black[4];
230   std::cout << "AddTextGlyph(output," << orientation << ")" << std::endl;
231
232   if (this->Text == NULL) {
233     vtkErrorMacro (<< "Text is not set!");
234     return;
235   }
236
237   // convert colors to unsigned char
238   for (int i = 0; i < 4; i++) {
239     white[i] = (unsigned char) (this->ForegroundColor[i] * 255.0);
240     black[i] = (unsigned char) (this->BackgroundColor[i] * 255.0);
241   }
242
243   std::cout << "Create Text" << std::endl;
244   // Create Text
245   while (this->Text[pos]) {
246     if (this->Text[pos] != 32) {
247       for (col = 0; col < vtkfont_width; col++) {
248         acol = (this->Text[pos] - 32)*vtkfont_width + col - 1;
249         for (row = 0; row < vtkfont_height; row++) {
250           pixelPos = acol + row*vtkfont_row_width;
251           if (vtkfont_bits[pixelPos/8] & (0x01 << pixelPos%8)) {
252             if (drawingBlack) {
253               x[0] = pos*vtkfont_width + col + 1;
254               x[1] = vtkfont_height - row;
255               x[2] = 0;
256               ChangeOrientation(x,orientation);
257               newPoints->InsertNextPoint(x);
258               newScalars->InsertNextValue(black[0]);
259               newScalars->InsertNextValue(black[1]);
260               newScalars->InsertNextValue(black[2]);
261               newScalars->InsertNextValue(black[3]);
262
263               x[0] = pos*vtkfont_width + col;
264               x[1] = vtkfont_height - row;
265               x[2] = 0;
266               ChangeOrientation(x,orientation);
267               newPoints->InsertNextPoint(x);
268               newScalars->InsertNextValue(black[0]);
269               newScalars->InsertNextValue(black[1]);
270               newScalars->InsertNextValue(black[2]);
271               newScalars->InsertNextValue(black[3]);
272
273               pts[0] = numPolys*4;
274               pts[1] = numPolys*4 + 1;
275               pts[2] = numPolys*4 + 2;
276               pts[3] = numPolys*4 + 3;
277               newPolys->InsertNextCell(4,pts);
278               numPolys++;
279               drawingBlack = 0;
280             }
281             if (!drawingWhite) {
282               x[0] = pos*vtkfont_width + col;
283               x[1] = vtkfont_height - row;
284               x[2] = 0;
285               ChangeOrientation(x,orientation);
286               newPoints->InsertNextPoint(x);
287               newScalars->InsertNextValue(white[0]);
288               newScalars->InsertNextValue(white[1]);
289               newScalars->InsertNextValue(white[2]);
290               newScalars->InsertNextValue(white[3]);
291
292               x[0] = pos*vtkfont_width + col + 1;
293               x[1] = vtkfont_height - row;
294               x[2] = 0;
295               ChangeOrientation(x,orientation);
296               newPoints->InsertNextPoint(x);
297               newScalars->InsertNextValue(white[0]);
298               newScalars->InsertNextValue(white[1]);
299               newScalars->InsertNextValue(white[2]);
300               newScalars->InsertNextValue(white[3]);
301               drawingWhite = 1;
302             }
303           }
304           // if the pixel is not set the close up the rectangle
305           else {
306             if (drawingWhite) {
307               x[0] = pos*vtkfont_width + col + 1;
308               x[1] = vtkfont_height - row;
309               x[2] = 0;
310               ChangeOrientation(x,orientation);
311               newPoints->InsertNextPoint(x);
312               newScalars->InsertNextValue(white[0]);
313               newScalars->InsertNextValue(white[1]);
314               newScalars->InsertNextValue(white[2]);
315               newScalars->InsertNextValue(white[3]);
316
317               x[0] = pos*vtkfont_width + col;
318               x[1] = vtkfont_height - row;
319               x[2] = 0;
320               ChangeOrientation(x,orientation);
321               newPoints->InsertNextPoint(x);
322               newScalars->InsertNextValue(white[0]);
323               newScalars->InsertNextValue(white[1]);
324               newScalars->InsertNextValue(white[2]);
325               newScalars->InsertNextValue(white[3]);
326
327               pts[0] = numPolys*4;
328               pts[1] = numPolys*4 + 1;
329               pts[2] = numPolys*4 + 2;
330               pts[3] = numPolys*4 + 3;
331               newPolys->InsertNextCell(4,pts);
332               numPolys++;
333               drawingWhite = 0;
334             }
335             if (!drawingBlack && this->Backing) {
336               x[0] = pos*vtkfont_width + col;
337               x[1] = vtkfont_height - row;
338               x[2] = 0;
339               ChangeOrientation(x,orientation);
340               newPoints->InsertNextPoint(x);
341               newScalars->InsertNextValue(black[0]);
342               newScalars->InsertNextValue(black[1]);
343               newScalars->InsertNextValue(black[2]);
344               newScalars->InsertNextValue(black[3]);
345
346               x[0] = pos*vtkfont_width + col + 1;
347               x[1] = vtkfont_height - row;
348               x[2] = 0;
349               ChangeOrientation(x,orientation);
350               newPoints->InsertNextPoint(x);
351               newScalars->InsertNextValue(black[0]);
352               newScalars->InsertNextValue(black[1]);
353               newScalars->InsertNextValue(black[2]);
354               newScalars->InsertNextValue(black[3]);
355               drawingBlack = 1;
356             }
357           }
358         }
359         // if we finished up a row but are still drawing close it up
360         if (drawingWhite) {
361           x[0] = pos*vtkfont_width + col + 1;
362           x[1] = 0;
363           x[2] = 0;
364           ChangeOrientation(x,orientation);
365           newPoints->InsertNextPoint(x);
366           newScalars->InsertNextValue(white[0]);
367           newScalars->InsertNextValue(white[1]);
368           newScalars->InsertNextValue(white[2]);
369           newScalars->InsertNextValue(white[3]);
370
371           x[0] = pos*vtkfont_width + col;
372           x[1] = 0;
373           x[2] = 0;
374           ChangeOrientation(x,orientation);
375           newPoints->InsertNextPoint(x);
376           newScalars->InsertNextValue(white[0]);
377           newScalars->InsertNextValue(white[1]);
378           newScalars->InsertNextValue(white[2]);
379           newScalars->InsertNextValue(white[3]);
380
381           pts[0] = numPolys*4;
382           pts[1] = numPolys*4 + 1;
383           pts[2] = numPolys*4 + 2;
384           pts[3] = numPolys*4 + 3;
385           newPolys->InsertNextCell(4,pts);
386           numPolys++;
387           drawingWhite = 0;
388         }
389         if (drawingBlack) {
390           x[0] = pos*vtkfont_width + col + 1;
391           x[1] = 0;
392           x[2] = 0;
393           ChangeOrientation(x,orientation);
394           newPoints->InsertNextPoint(x);
395           newScalars->InsertNextValue(black[0]);
396           newScalars->InsertNextValue(black[1]);
397           newScalars->InsertNextValue(black[2]);
398           newScalars->InsertNextValue(black[3]);
399
400           x[0] = pos*vtkfont_width + col;
401           x[1] = 0;
402           x[2] = 0;
403           ChangeOrientation(x,orientation);
404           newPoints->InsertNextPoint(x);
405           newScalars->InsertNextValue(black[0]);
406           newScalars->InsertNextValue(black[1]);
407           newScalars->InsertNextValue(black[2]);
408           newScalars->InsertNextValue(black[3]);
409
410           pts[0] = numPolys*4;
411           pts[1] = numPolys*4 + 1;
412           pts[2] = numPolys*4 + 2;
413           pts[3] = numPolys*4 + 3;
414           newPolys->InsertNextCell(4,pts);
415           numPolys++;
416           drawingBlack = 0;
417         }
418       }
419     } else {
420       // draw a black square for a space
421       if (this->Backing) {
422         x[0] = pos*vtkfont_width;
423         x[1] = vtkfont_height;
424         x[2] = 0;
425         ChangeOrientation(x,orientation);
426         newPoints->InsertNextPoint(x);
427         newScalars->InsertNextValue(black[0]);
428         newScalars->InsertNextValue(black[1]);
429         newScalars->InsertNextValue(black[2]);
430         newScalars->InsertNextValue(black[3]);
431
432         x[0] = pos*vtkfont_width + vtkfont_width;
433         x[1] = vtkfont_height;
434         x[2] = 0;
435         ChangeOrientation(x,orientation);
436         newPoints->InsertNextPoint(x);
437         newScalars->InsertNextValue(black[0]);
438         newScalars->InsertNextValue(black[1]);
439         newScalars->InsertNextValue(black[2]);
440         newScalars->InsertNextValue(black[3]);
441
442         x[0] = pos*vtkfont_width + vtkfont_width;
443         x[1] = 0;
444         x[2] = 0;
445         ChangeOrientation(x,orientation);
446         newPoints->InsertNextPoint(x);
447         newScalars->InsertNextValue(black[0]);
448         newScalars->InsertNextValue(black[1]);
449         newScalars->InsertNextValue(black[2]);
450         newScalars->InsertNextValue(black[3]);
451
452         x[0] = pos*vtkfont_width;
453         x[1] = 0;
454         x[2] = 0;
455         ChangeOrientation(x,orientation);
456         newPoints->InsertNextPoint(x);
457         newScalars->InsertNextValue(black[0]);
458         newScalars->InsertNextValue(black[1]);
459         newScalars->InsertNextValue(black[2]);
460         newScalars->InsertNextValue(black[3]);
461
462         pts[0] = numPolys*4;
463         pts[1] = numPolys*4 + 1;
464         pts[2] = numPolys*4 + 2;
465         pts[3] = numPolys*4 + 3;
466         newPolys->InsertNextCell(4,pts);
467         numPolys++;
468       }
469     }
470     pos++;
471   }
472 }
473
474 void vvLandmarksGlyph::AddCrossGlyph(vtkPoints* newPts,vtkCellArray* newLines)
475 {
476   vtkIdType ptIds[2];
477   double x[3];
478   std::cout << "AddCross" << std::endl;
479   x[0] = -10;
480   x[1] = 0;
481   x[2] = 0;
482   ptIds[0] = newPts->InsertNextPoint(x);
483
484   x[0] = 10;
485   x[1] = 0;
486   x[2] = 0;
487   ptIds[1] = newPts->InsertNextPoint(x);
488   newLines->InsertNextCell(2,ptIds);
489
490   x[0] = 0;
491   x[1] = -10;
492   x[2] = 0;
493   ptIds[0] = newPts->InsertNextPoint(x);
494
495   x[0] = 0;
496   x[1] = 10;
497   x[2] = 0;
498   ptIds[1] = newPts->InsertNextPoint(x);
499   newLines->InsertNextCell(2,ptIds);
500
501   x[0] = 0;
502   x[1] = 0;
503   x[2] = -10;
504   ptIds[0] = newPts->InsertNextPoint(x);
505
506   x[0] = 0;
507   x[1] = 0;
508   x[2] = 10;
509   ptIds[1] = newPts->InsertNextPoint(x);
510   newLines->InsertNextCell(2,ptIds);
511 }
512
513
514 void vvLandmarksGlyph::ChangeOrientation(double v[3],int orientation)
515 {
516   double x=0,y=0,z=0;
517   switch (orientation) {
518   case 0:
519     x = v[1];
520     y = v[2];
521     z = v[0];
522     break;
523   case 1:
524     x = v[2];
525     y = v[0];
526     z = v[1];
527     break;
528   case 2:
529     x = v[0];
530     y = v[1];
531     z = v[2];
532     break;
533   default:
534     assert(false); //This definitely shouldn't happen
535   }
536   v[0] = x;
537   v[1] = y;
538   v[2] = z;
539 }
540
541 void vvLandmarksGlyph::PrintSelf(ostream& os, vtkIndent indent)
542 {
543   this->Superclass::PrintSelf(os,indent);
544
545   os << indent << "Text: " << (this->Text ? this->Text : "(none)") << "\n";
546   os << indent << "Background Drawn: " << (this->Backing ? "On\n" : "Off\n");
547   os << indent << "ForegroundColor: (" << this->ForegroundColor[0] << ", "
548      << this->ForegroundColor[1] << ", " << this->ForegroundColor[2]  << ")\n";
549   os << indent << "BackgroundColor: (" << this->BackgroundColor[0] << ", "
550      << this->BackgroundColor[1] << ", " << this->BackgroundColor[2] << ")\n";
551 }