1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkLinesPainter.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkLinesPainter.h"
16
17 #include "vtkCellArray.h"
18 #include "vtkCellData.h"
19 #include "vtkObjectFactory.h"
20 #include "vtkPainterDeviceAdapter.h"
21 #include "vtkPoints.h"
22 #include "vtkPointData.h"
23 #include "vtkPolyData.h"
24 #include "vtkProperty.h"
25 #include "vtkRenderer.h"
26 #include "vtkRenderWindow.h"
27 #include "vtkUnsignedCharArray.h"
28
29 vtkStandardNewMacro(vtkLinesPainter);
30 //-----------------------------------------------------------------------------
vtkLinesPainter()31 vtkLinesPainter::vtkLinesPainter()
32 {
33 this->SetSupportedPrimitive(vtkPainter::LINES | vtkPainter::POLYS);
34 this->RenderPolys = 0;
35 }
36
37 //-----------------------------------------------------------------------------
~vtkLinesPainter()38 vtkLinesPainter::~vtkLinesPainter()
39 {
40 }
41
42 //-----------------------------------------------------------------------------
43 #define vtkDrawPrimsMacro(prim,glVertFuncs,glInitFuncs) \
44 { \
45 vtkIdType nPts; unsigned short count = 0; \
46 glInitFuncs \
47 while (ptIds < endPtIds) \
48 { \
49 nPts = *ptIds; \
50 ++ptIds; \
51 device->BeginPrimitive(prim);\
52 while (nPts > 0) \
53 { \
54 glVertFuncs \
55 ++ptIds; \
56 --nPts; \
57 } \
58 device->EndPrimitive();\
59 if (++count == 10000) \
60 { \
61 cellNum += 10000; \
62 count = 0; \
63 this->UpdateProgress(static_cast<double>(cellNum-cellNumStart)/totalCells); \
64 if (ren->GetRenderWindow()->CheckAbortStatus()) \
65 { \
66 break; \
67 } \
68 } \
69 } \
70 cellNum += count; \
71 }
72 //-----------------------------------------------------------------------------
RenderInternal(vtkRenderer * renderer,vtkActor * actor,unsigned long typeflags,bool forceCompileOnly)73 void vtkLinesPainter::RenderInternal(vtkRenderer* renderer, vtkActor* actor,
74 unsigned long typeflags,
75 bool forceCompileOnly)
76 {
77 if (typeflags == vtkPainter::POLYS)
78 {
79 this->RenderPolys = 1;
80 }
81 else
82 {
83 this->RenderPolys = 0;
84 }
85 this->Superclass::RenderInternal(renderer, actor, typeflags,forceCompileOnly);
86 }
87
88 //-----------------------------------------------------------------------------
RenderPrimitive(unsigned long idx,vtkDataArray * n,vtkUnsignedCharArray * c,vtkDataArray * t,vtkRenderer * ren)89 int vtkLinesPainter::RenderPrimitive(unsigned long idx, vtkDataArray* n,
90 vtkUnsignedCharArray* c, vtkDataArray* t, vtkRenderer* ren)
91 {
92 vtkPolyData* pd = this->GetInputAsPolyData();
93 vtkPoints* p = pd->GetPoints();
94 vtkCellArray* ca = (this->RenderPolys)? pd->GetPolys() : pd->GetLines();
95 vtkIdType cellNum = pd->GetVerts()->GetNumberOfCells();
96 vtkIdType cellNumStart = cellNum;
97 vtkIdType totalCells = ca->GetNumberOfCells();
98
99 vtkPainterDeviceAdapter* device = ren->GetRenderWindow()->
100 GetPainterDeviceAdapter();
101 void *points = p->GetVoidPointer(0);
102 void *normals = 0;
103 void *tcoords = 0;
104 unsigned char *colors = 0;
105 if (ca->GetNumberOfCells() == 0)
106 {
107 return 1;
108 }
109 if (n)
110 {
111 normals = n->GetVoidPointer(0);
112 }
113 if (t)
114 {
115 tcoords = t->GetVoidPointer(0);
116 }
117 if (c)
118 {
119 colors = c->GetPointer(0);
120 }
121 vtkIdType *ptIds = ca->GetPointer();
122 vtkIdType *endPtIds = ptIds + ca->GetNumberOfConnectivityEntries();
123 int ptype = p->GetDataType();
124 int ntype = (n)? n->GetDataType() : 0;
125 int ttype = (t)? t->GetDataType() : 0;
126 int tcomps = (t)? t->GetNumberOfComponents() : 0;
127 int primitive = (this->RenderPolys)? VTK_TETRA : VTK_POLY_LINE;
128
129 // since this painter does not deal with field colors specially,
130 // we just ignore the flag.
131 idx &= (~VTK_PDM_FIELD_COLORS);
132
133 // Also ignore edge flags.
134 idx &= (~VTK_PDM_EDGEFLAGS);
135
136 // draw all the elements, use fast path if available
137 switch (idx)
138 {
139 case 0:
140 vtkDrawPrimsMacro(primitive,
141 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
142 ptype, points, 3**ptIds);,;);
143 break;
144
145 case VTK_PDM_NORMALS:
146 vtkDrawPrimsMacro(primitive,
147 device->SendAttribute(vtkPointData::NORMALS, 3,
148 ntype, normals, 3**ptIds);
149 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
150 ptype, points, 3**ptIds);,;);
151 break;
152
153 case VTK_PDM_COLORS:
154 vtkDrawPrimsMacro(primitive,
155 device->SendAttribute(vtkPointData::SCALARS, 4,
156 VTK_UNSIGNED_CHAR, colors + 4**ptIds);
157 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
158 ptype, points, 3**ptIds);,;);
159 break;
160
161 case VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
162 vtkDrawPrimsMacro(primitive,
163 device->SendAttribute(vtkPointData::SCALARS, 3,
164 VTK_UNSIGNED_CHAR, colors + 4**ptIds);
165 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
166 ptype, points, 3**ptIds);,;);
167 break;
168
169 case VTK_PDM_NORMALS | VTK_PDM_COLORS:
170 vtkDrawPrimsMacro(primitive,
171 device->SendAttribute(vtkPointData::NORMALS, 3,
172 ntype, normals, 3**ptIds);
173 device->SendAttribute(vtkPointData::SCALARS, 4,
174 VTK_UNSIGNED_CHAR, colors + 4**ptIds);
175 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
176 ptype, points, 3**ptIds);,;);
177 break;
178
179 case VTK_PDM_NORMALS | VTK_PDM_COLORS | VTK_PDM_OPAQUE_COLORS:
180 vtkDrawPrimsMacro(primitive,
181 device->SendAttribute(vtkPointData::NORMALS, 3,
182 ntype, normals, 3**ptIds);
183 device->SendAttribute(vtkPointData::SCALARS, 4,
184 VTK_UNSIGNED_CHAR, colors + 4**ptIds);
185 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
186 ptype, points, 3**ptIds);,;);
187 break;
188
189 case VTK_PDM_TCOORDS:
190 vtkDrawPrimsMacro(primitive,
191 device->SendAttribute(vtkPointData::TCOORDS, tcomps,
192 ttype, tcoords, tcomps**ptIds);
193 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
194 ptype, points, 3**ptIds);,;);
195 break;
196
197 case VTK_PDM_NORMALS | VTK_PDM_TCOORDS:
198 vtkDrawPrimsMacro(primitive,
199 device->SendAttribute(vtkPointData::NORMALS, 3,
200 ntype, normals, 3**ptIds);
201 device->SendAttribute(vtkPointData::TCOORDS, tcomps,
202 ttype, tcoords, tcomps**ptIds);
203 device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
204 ptype, points, 3**ptIds);,;);
205 break;
206
207 default:
208 return 0; // let the delegate painter handle this call.
209 }
210 return 1;
211 }
212
213 //-----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)214 void vtkLinesPainter::PrintSelf(ostream& os, vtkIndent indent)
215 {
216 this->Superclass::PrintSelf(os, indent);
217 }
218