]> Creatis software - clitk.git/blob - vv/vvGlyphSource.cxx
added the new headers
[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     {
64         int filled = this->Filled;
65         this->Filled = 0;
66         this->CreateDash(pts,lines,polys,colors,this->Scale2);
67         this->Filled = filled;
68     }
69     if ( this->Cross )
70     {
71         int filled = this->Filled;
72         this->Filled = 0;
73         this->CreateCross(pts,lines,polys,colors,this->Scale2);
74         this->Filled = filled;
75     }
76
77     //Call the right function
78     switch (this->GlyphType)
79     {
80     case VTK_NO_GLYPH:
81         break;
82     case VTK_VERTEX_GLYPH:
83         this->CreateVertex(pts,verts,colors);
84         break;
85     case VTK_DASH_GLYPH:
86         this->CreateDash(pts,lines,polys,colors,this->Scale);
87         break;
88     case VTK_CROSS_GLYPH:
89         this->CreateCross(pts,lines,polys,colors,this->Scale);
90         break;
91     case VTK_THICKCROSS_GLYPH:
92         this->CreateThickCross(pts,lines,polys,colors);
93         break;
94     case VTK_TRIANGLE_GLYPH:
95         this->CreateTriangle(pts,lines,polys,colors);
96         break;
97     case VTK_SQUARE_GLYPH:
98         this->CreateSquare(pts,lines,polys,colors);
99         break;
100     case VTK_CIRCLE_GLYPH:
101         this->CreateCircle(pts,lines,polys,colors);
102         break;
103     case VTK_DIAMOND_GLYPH:
104         this->CreateDiamond(pts,lines,polys,colors);
105         break;
106     case VTK_ARROW_GLYPH:
107         this->CreateArrow(pts,lines,polys,colors);
108         break;
109     case VTK_THICKARROW_GLYPH:
110         this->CreateThickArrow(pts,lines,polys,colors);
111         break;
112     case VTK_HOOKEDARROW_GLYPH:
113         this->CreateHookedArrow(pts,lines,polys,colors);
114         break;
115     case VTK_EDGEARROW_GLYPH:
116         this->CreateEdgeArrow(pts,lines,polys,colors);
117         break;
118     case VTK_SPECIFICARROW_GLYPH:
119         this->CreateSpecificArrow(pts,lines,polys,colors);
120         break;
121     }
122
123     this->TransformGlyph(pts);
124
125     //Clean up
126     output->SetPoints(pts);
127     pts->Delete();
128
129     output->SetVerts(verts);
130     verts->Delete();
131
132     output->SetLines(lines);
133     lines->Delete();
134
135     output->SetPolys(polys);
136     polys->Delete();
137
138     output->GetCellData()->SetScalars(colors);
139     colors->Delete();
140
141     return 1;
142 }
143
144 void vvGlyphSource::CreateSpecificArrow(vtkPoints *pts, vtkCellArray *lines,
145                                         vtkCellArray *polys, vtkUnsignedCharArray *colors)
146 {
147     //stem
148     vtkIdType ptIds[3];
149     ptIds[0] = pts->InsertNextPoint( 0.0, 0.0, 0.0);
150     ptIds[1] = pts->InsertNextPoint(  1.0, 0.0, 0.0);
151     lines->InsertNextCell(2,ptIds);
152     colors->InsertNextValue(0);
153     colors->InsertNextValue(0);
154     colors->InsertNextValue(1);
155
156     //arrow head
157     ptIds[0] = pts->InsertNextPoint( 0.7, -0.1, 0.0);
158     ptIds[1] = pts->InsertNextPoint( 1.0,  0.0, 0.0);
159     ptIds[2] = pts->InsertNextPoint( 0.7,  0.1, 0.0);
160     lines->InsertNextCell(3,ptIds);
161     colors->InsertNextValue(0);
162     colors->InsertNextValue(1);
163     colors->InsertNextValue(0);
164 }
165
166 void vvGlyphSource::PrintSelf(ostream& os, vtkIndent indent)
167 {
168     this->Superclass::PrintSelf(os, indent);
169 }