1 | /*========================================================================= |
---|
2 | |
---|
3 | Program: Visualization Toolkit |
---|
4 | Module: vtkRpAxisActor.cpp |
---|
5 | Thanks: Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory |
---|
6 | |
---|
7 | Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen |
---|
8 | All rights reserved. |
---|
9 | See Copyright.txt or http://www.kitware.com/Copyright.htm for details. |
---|
10 | |
---|
11 | This software is distributed WITHOUT ANY WARRANTY; without even |
---|
12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
13 | PURPOSE. See the above copyright notice for more information. |
---|
14 | =========================================================================*/ |
---|
15 | #include "vtkRpAxisActor.h" |
---|
16 | #include "vtkCamera.h" |
---|
17 | #include "vtkCellArray.h" |
---|
18 | #include "vtkCoordinate.h" |
---|
19 | #include "vtkFollower.h" |
---|
20 | #include "vtkObjectFactory.h" |
---|
21 | #include "vtkPolyData.h" |
---|
22 | #include "vtkPolyDataMapper.h" |
---|
23 | #include "vtkProperty.h" |
---|
24 | #include "vtkStringArray.h" |
---|
25 | #include "vtkVectorText.h" |
---|
26 | #include "vtkViewport.h" |
---|
27 | |
---|
28 | // **************************************************************** |
---|
29 | // Modifications: |
---|
30 | // Kathleen Bonnell, Wed Mar 6 13:48:48 PST 2002 |
---|
31 | // Replace 'New' method with macro to match VTK 4.0 API. |
---|
32 | // **************************************************************** |
---|
33 | |
---|
34 | vtkStandardNewMacro(vtkRpAxisActor); |
---|
35 | vtkCxxSetObjectMacro(vtkRpAxisActor, Camera, vtkCamera); |
---|
36 | |
---|
37 | // **************************************************************** |
---|
38 | // Instantiate this object. |
---|
39 | // |
---|
40 | // Modifications: |
---|
41 | // Kathleen Bonnell, Wed Oct 31 07:57:49 PST 2001 |
---|
42 | // Initialize new members mustAdjustValue and valueScaleFactor. |
---|
43 | // |
---|
44 | // Kathleen Bonnell, Wed Nov 7 16:19:16 PST 2001 |
---|
45 | // No longer allocate large amounts of memory for labels, instead |
---|
46 | // allocate dynamically. Initialize new members: |
---|
47 | // LastLabelStart; LastAxisPosition; LastTickLocation; LastTickVisibility; |
---|
48 | // LastDrawGridlines; LastMinorTicksVisible; LastRange; MinorTickPts; |
---|
49 | // MajorTickPts; GridlinePts. |
---|
50 | // |
---|
51 | // Kathleen Bonnell, Thu May 16 10:13:56 PDT 2002 |
---|
52 | // Initialize new member AxisHasZeroLength. |
---|
53 | // |
---|
54 | // Kathleen Bonnell, Thu Aug 1 13:44:02 PDT 2002 |
---|
55 | // Initialize new member ForceLabelReset. |
---|
56 | // |
---|
57 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
58 | // Removed mustAdjustValue, valueScaleFator, ForceLabelReset. |
---|
59 | // |
---|
60 | // Kathleen Bonnell, Thu Apr 29 17:02:10 PDT 2004 |
---|
61 | // Initialize MinorStart, MajorStart, DeltaMinor, DeltaMajor. |
---|
62 | // |
---|
63 | // **************************************************************** |
---|
64 | |
---|
65 | vtkRpAxisActor::vtkRpAxisActor() |
---|
66 | { |
---|
67 | this->Point1Coordinate = vtkCoordinate::New(); |
---|
68 | this->Point1Coordinate->SetCoordinateSystemToWorld(); |
---|
69 | this->Point1Coordinate->SetValue(0.0, 0.0, 0.0); |
---|
70 | |
---|
71 | this->Point2Coordinate = vtkCoordinate::New(); |
---|
72 | this->Point2Coordinate->SetCoordinateSystemToWorld(); |
---|
73 | this->Point2Coordinate->SetValue(0.75, 0.0, 0.0); |
---|
74 | |
---|
75 | this->Camera = NULL; |
---|
76 | this->Title = NULL; |
---|
77 | this->MinorTicksVisible = 1; |
---|
78 | this->MajorTickSize = 1.0; |
---|
79 | this->MinorTickSize = 0.5; |
---|
80 | this->TickLocation = VTK_TICKS_INSIDE; |
---|
81 | this->Range[0] = 0.0; |
---|
82 | this->Range[1] = 1.0; |
---|
83 | |
---|
84 | this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = -1; |
---|
85 | this->Bounds[1] = this->Bounds[3] = this->Bounds[5] = 1; |
---|
86 | |
---|
87 | this->LabelFormat = new char[8]; |
---|
88 | sprintf(this->LabelFormat, "%s", "%-#6.3g"); |
---|
89 | |
---|
90 | this->TitleVector = vtkVectorText::New(); |
---|
91 | this->TitleMapper = vtkPolyDataMapper::New(); |
---|
92 | #ifdef USE_VTK6 |
---|
93 | this->TitleMapper->SetInputData(this->TitleVector->GetOutput()); |
---|
94 | #else |
---|
95 | this->TitleMapper->SetInput(this->TitleVector->GetOutput()); |
---|
96 | #endif |
---|
97 | this->TitleActor = vtkFollower::New(); |
---|
98 | this->TitleActor->SetMapper(this->TitleMapper); |
---|
99 | |
---|
100 | // to avoid deleting/rebuilding create once up front |
---|
101 | this->NumberOfLabelsBuilt = 0; |
---|
102 | this->LabelVectors = NULL; |
---|
103 | this->LabelMappers = NULL; |
---|
104 | this->LabelActors = NULL; |
---|
105 | |
---|
106 | this->Axis = vtkPolyData::New(); |
---|
107 | this->AxisMapper = vtkPolyDataMapper::New(); |
---|
108 | #ifdef USE_VTK6 |
---|
109 | this->AxisMapper->SetInputData(this->Axis); |
---|
110 | #else |
---|
111 | this->AxisMapper->SetInput(this->Axis); |
---|
112 | #endif |
---|
113 | this->AxisActor = vtkActor::New(); |
---|
114 | this->AxisActor->SetMapper(this->AxisMapper); |
---|
115 | |
---|
116 | this->AxisVisibility = 1; |
---|
117 | this->TickVisibility = 1; |
---|
118 | this->LabelVisibility = 1; |
---|
119 | this->TitleVisibility = 1; |
---|
120 | |
---|
121 | this->DrawGridlines = 0; |
---|
122 | this->GridlineXLength = 1.; |
---|
123 | this->GridlineYLength = 1.; |
---|
124 | this->GridlineZLength = 1.; |
---|
125 | |
---|
126 | this->AxisType = VTK_AXIS_TYPE_X; |
---|
127 | // |
---|
128 | // AxisPosition denotes which of the four possibilities in relation |
---|
129 | // to the bounding box. An x-Type axis with min min, means the x-axis |
---|
130 | // at minimum y and minimum z values of the bbox. |
---|
131 | // |
---|
132 | this->AxisPosition = VTK_AXIS_POS_MINMIN; |
---|
133 | |
---|
134 | this->LastLabelStart = 100000; |
---|
135 | |
---|
136 | this->LastAxisPosition = -1; |
---|
137 | this->LastTickLocation = -1; |
---|
138 | this->LastTickVisibility = -1; |
---|
139 | this->LastDrawGridlines = -1; |
---|
140 | this->LastMinorTicksVisible = -1; |
---|
141 | this->LastRange[0] = -1.0; |
---|
142 | this->LastRange[1] = -1.0; |
---|
143 | |
---|
144 | this->MinorTickPts = vtkPoints::New(); |
---|
145 | this->MajorTickPts = vtkPoints::New(); |
---|
146 | this->GridlinePts = vtkPoints::New(); |
---|
147 | |
---|
148 | this->AxisHasZeroLength = false; |
---|
149 | |
---|
150 | this->MinorStart = 0.; |
---|
151 | this->MajorStart = 0.; |
---|
152 | this->DeltaMinor = 1.; |
---|
153 | this->DeltaMajor = 1.; |
---|
154 | this->MinorRangeStart = 0.; |
---|
155 | this->MajorRangeStart = 0.; |
---|
156 | this->DeltaRangeMinor = 1.; |
---|
157 | this->DeltaRangeMajor = 1.; |
---|
158 | } |
---|
159 | |
---|
160 | // **************************************************************** |
---|
161 | // Modifications: |
---|
162 | // Kathleen Bonnell, Wed Mar 6 13:48:48 PST 2002 |
---|
163 | // Added call to set camera to null. |
---|
164 | // **************************************************************** |
---|
165 | |
---|
166 | vtkRpAxisActor::~vtkRpAxisActor() |
---|
167 | { |
---|
168 | this->SetCamera(NULL); |
---|
169 | |
---|
170 | if (this->Point1Coordinate) |
---|
171 | { |
---|
172 | this->Point1Coordinate->Delete(); |
---|
173 | this->Point1Coordinate = NULL; |
---|
174 | } |
---|
175 | |
---|
176 | if (this->Point2Coordinate) |
---|
177 | { |
---|
178 | this->Point2Coordinate->Delete(); |
---|
179 | this->Point2Coordinate = NULL; |
---|
180 | } |
---|
181 | |
---|
182 | if (this->LabelFormat) |
---|
183 | { |
---|
184 | delete [] this->LabelFormat; |
---|
185 | this->LabelFormat = NULL; |
---|
186 | } |
---|
187 | |
---|
188 | if (this->TitleVector) |
---|
189 | { |
---|
190 | this->TitleVector->Delete(); |
---|
191 | this->TitleVector = NULL; |
---|
192 | } |
---|
193 | if (this->TitleMapper) |
---|
194 | { |
---|
195 | this->TitleMapper->Delete(); |
---|
196 | this->TitleMapper = NULL; |
---|
197 | } |
---|
198 | if (this->TitleActor) |
---|
199 | { |
---|
200 | this->TitleActor->Delete(); |
---|
201 | this->TitleActor = NULL; |
---|
202 | } |
---|
203 | |
---|
204 | if (this->Title) |
---|
205 | { |
---|
206 | delete [] this->Title; |
---|
207 | this->Title = NULL; |
---|
208 | } |
---|
209 | |
---|
210 | if (this->LabelMappers != NULL) |
---|
211 | { |
---|
212 | for (int i=0; i < this->NumberOfLabelsBuilt; i++) |
---|
213 | { |
---|
214 | this->LabelVectors[i]->Delete(); |
---|
215 | this->LabelMappers[i]->Delete(); |
---|
216 | this->LabelActors[i]->Delete(); |
---|
217 | } |
---|
218 | this->NumberOfLabelsBuilt = 0; |
---|
219 | delete [] this->LabelVectors; |
---|
220 | delete [] this->LabelMappers; |
---|
221 | delete [] this->LabelActors; |
---|
222 | this->LabelVectors = NULL; |
---|
223 | this->LabelMappers = NULL; |
---|
224 | this->LabelActors = NULL; |
---|
225 | } |
---|
226 | |
---|
227 | if (this->Axis) |
---|
228 | { |
---|
229 | this->Axis->Delete(); |
---|
230 | this->Axis = NULL; |
---|
231 | } |
---|
232 | if (this->AxisMapper) |
---|
233 | { |
---|
234 | this->AxisMapper->Delete(); |
---|
235 | this->AxisMapper = NULL; |
---|
236 | } |
---|
237 | if (this->AxisActor) |
---|
238 | { |
---|
239 | this->AxisActor->Delete(); |
---|
240 | this->AxisActor = NULL; |
---|
241 | } |
---|
242 | |
---|
243 | if (this->MinorTickPts) |
---|
244 | { |
---|
245 | this->MinorTickPts ->Delete(); |
---|
246 | this->MinorTickPts = NULL; |
---|
247 | } |
---|
248 | if (this->MajorTickPts) |
---|
249 | { |
---|
250 | this->MajorTickPts->Delete(); |
---|
251 | this->MajorTickPts = NULL; |
---|
252 | } |
---|
253 | if (this->GridlinePts) |
---|
254 | { |
---|
255 | this->GridlinePts->Delete(); |
---|
256 | this->GridlinePts = NULL; |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | // Release any graphics resources that are being consumed by this actor. |
---|
261 | // The parameter window could be used to determine which graphic |
---|
262 | // resources to release. |
---|
263 | void vtkRpAxisActor::ReleaseGraphicsResources(vtkWindow *win) |
---|
264 | { |
---|
265 | this->TitleActor->ReleaseGraphicsResources(win); |
---|
266 | for (int i=0; i < this->NumberOfLabelsBuilt; i++) |
---|
267 | { |
---|
268 | this->LabelActors[i]->ReleaseGraphicsResources(win); |
---|
269 | } |
---|
270 | this->AxisActor->ReleaseGraphicsResources(win); |
---|
271 | } |
---|
272 | |
---|
273 | // **************************************************************** |
---|
274 | // |
---|
275 | // Modifications: |
---|
276 | // Kathleen Bonnell, Wed Oct 31 07:57:49 PST 2001 |
---|
277 | // Copy over mustAdjustValue and valueScaleFactor. |
---|
278 | // |
---|
279 | // Kathleen Bonnell, Wed Mar 6 13:48:48 PST 2002 |
---|
280 | // Call superclass's method in new VTK 4.0 way. |
---|
281 | // |
---|
282 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
283 | // Removed mustAdjustValue, valueScaleFator. |
---|
284 | // |
---|
285 | // **************************************************************** |
---|
286 | |
---|
287 | void vtkRpAxisActor::ShallowCopy(vtkProp *prop) |
---|
288 | { |
---|
289 | vtkRpAxisActor *a = vtkRpAxisActor::SafeDownCast(prop); |
---|
290 | if (a != NULL) |
---|
291 | { |
---|
292 | this->SetPoint1(a->GetPoint1()); |
---|
293 | this->SetPoint2(a->GetPoint2()); |
---|
294 | this->SetCamera(a->GetCamera()); |
---|
295 | this->SetRange(a->GetRange()); |
---|
296 | this->SetLabelFormat(a->GetLabelFormat()); |
---|
297 | this->SetTitle(a->GetTitle()); |
---|
298 | this->SetAxisVisibility(a->GetAxisVisibility()); |
---|
299 | this->SetTickVisibility(a->GetTickVisibility()); |
---|
300 | this->SetLabelVisibility(a->GetLabelVisibility()); |
---|
301 | this->SetTitleVisibility(a->GetTitleVisibility()); |
---|
302 | } |
---|
303 | |
---|
304 | // Now do superclass |
---|
305 | this->Superclass::ShallowCopy(prop); |
---|
306 | } |
---|
307 | |
---|
308 | // **************************************************************** |
---|
309 | // Build the axis, ticks, title, and labels and render. |
---|
310 | // |
---|
311 | // Modifications: |
---|
312 | // Kathleen Bonnell, Thu May 16 10:13:56 PDT 2002 |
---|
313 | // Don't render a zero-length axis. |
---|
314 | // |
---|
315 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
316 | // Added bool argument to BuildAxis. |
---|
317 | // |
---|
318 | // **************************************************************** |
---|
319 | |
---|
320 | int vtkRpAxisActor::RenderOpaqueGeometry(vtkViewport *viewport) |
---|
321 | { |
---|
322 | int i, renderedSomething=0; |
---|
323 | |
---|
324 | this->BuildAxis(viewport, false); |
---|
325 | |
---|
326 | // Everything is built, just have to render |
---|
327 | |
---|
328 | if (!this->AxisHasZeroLength) |
---|
329 | { |
---|
330 | if (this->Title != NULL && this->Title[0] != 0 && this->TitleVisibility) |
---|
331 | { |
---|
332 | renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport); |
---|
333 | } |
---|
334 | |
---|
335 | if (this->AxisVisibility || this->TickVisibility) |
---|
336 | { |
---|
337 | renderedSomething += this->AxisActor->RenderOpaqueGeometry(viewport); |
---|
338 | } |
---|
339 | |
---|
340 | if (this->LabelVisibility) |
---|
341 | { |
---|
342 | for (i=0; i<this->NumberOfLabelsBuilt; i++) |
---|
343 | { |
---|
344 | renderedSomething += |
---|
345 | this->LabelActors[i]->RenderOpaqueGeometry(viewport); |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | return renderedSomething; |
---|
351 | } |
---|
352 | |
---|
353 | // ************************************************************************** |
---|
354 | // Perform some initialization, determine which Axis type we are |
---|
355 | // and call the appropriate build method. |
---|
356 | // |
---|
357 | // Modifications: |
---|
358 | // Kathleen Bonnell, Wed Nov 7 17:45:20 PST 2001 |
---|
359 | // Added logic to only rebuild sub-parts if necessary. |
---|
360 | // |
---|
361 | // Kathleen Bonnell, Fri Nov 30 17:02:41 PST 2001 |
---|
362 | // Moved setting values for LastRange to end of method, so they |
---|
363 | // can be used in comparisons elsewhere. |
---|
364 | // |
---|
365 | // Kathleen Bonnell, Mon Dec 3 16:49:01 PST 2001 |
---|
366 | // Compare vtkTimeStamps correctly. |
---|
367 | // |
---|
368 | // Kathleen Bonnell, Thu May 16 10:13:56 PDT 2002 |
---|
369 | // Test for zero length axis. |
---|
370 | // |
---|
371 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
372 | // Added bool argument that will allow all axis components to be built |
---|
373 | // if set to true. Removed call to AdjustTicksComputeRange (handled by |
---|
374 | // vtkCubeAxesActor. Remvoed call to Build?TypeAxis, added calls |
---|
375 | // to BuildLabels, SetAxisPointsAndLines and BuildTitle, (which used to |
---|
376 | // be handled in Build?TypeAxis). . |
---|
377 | // |
---|
378 | // ************************************************************************** |
---|
379 | |
---|
380 | void vtkRpAxisActor::BuildAxis(vtkViewport *viewport, bool force) |
---|
381 | { |
---|
382 | // We'll do our computation in world coordinates. First determine the |
---|
383 | // location of the endpoints. |
---|
384 | double *x, p1[3], p2[3]; |
---|
385 | x = this->Point1Coordinate->GetValue(); |
---|
386 | p1[0] = x[0]; p1[1] = x[1]; p1[2] = x[2]; |
---|
387 | x = this->Point2Coordinate->GetValue(); |
---|
388 | p2[0] = x[0]; p2[1] = x[1]; p2[2] = x[2]; |
---|
389 | |
---|
390 | // |
---|
391 | // Test for axis of zero length. |
---|
392 | // |
---|
393 | if (p1[0] == p2[0] && p1[1] == p2[1] && p1[2] == p2[2]) |
---|
394 | { |
---|
395 | vtkDebugMacro(<<"Axis has zero length, not building."); |
---|
396 | this->AxisHasZeroLength = true; |
---|
397 | return; |
---|
398 | } |
---|
399 | this->AxisHasZeroLength = false; |
---|
400 | |
---|
401 | if (!force && this->GetMTime() < this->BuildTime.GetMTime() && |
---|
402 | viewport->GetMTime() < this->BuildTime.GetMTime()) |
---|
403 | { |
---|
404 | return; //already built |
---|
405 | } |
---|
406 | |
---|
407 | vtkDebugMacro(<<"Rebuilding axis"); |
---|
408 | |
---|
409 | if (force || this->GetProperty()->GetMTime() > this->BuildTime.GetMTime()) |
---|
410 | { |
---|
411 | this->AxisActor->SetProperty(this->GetProperty()); |
---|
412 | this->TitleActor->SetProperty(this->GetProperty()); |
---|
413 | } |
---|
414 | |
---|
415 | // |
---|
416 | // Generate the axis and tick marks. |
---|
417 | // |
---|
418 | bool ticksRebuilt; |
---|
419 | if (this->AxisType == VTK_AXIS_TYPE_X) |
---|
420 | { |
---|
421 | ticksRebuilt = this->BuildTickPointsForXType(p1, p2, force); |
---|
422 | } |
---|
423 | else if (this->AxisType == VTK_AXIS_TYPE_Y) |
---|
424 | { |
---|
425 | ticksRebuilt = this->BuildTickPointsForYType(p1, p2, force); |
---|
426 | } |
---|
427 | else |
---|
428 | { |
---|
429 | ticksRebuilt = this->BuildTickPointsForZType(p1, p2, force); |
---|
430 | } |
---|
431 | |
---|
432 | bool tickVisChanged = this->TickVisibilityChanged(); |
---|
433 | |
---|
434 | if (force || ticksRebuilt || tickVisChanged) |
---|
435 | { |
---|
436 | this->SetAxisPointsAndLines(); |
---|
437 | } |
---|
438 | |
---|
439 | this->BuildLabels(viewport, force); |
---|
440 | |
---|
441 | if (this->Title != NULL && this->Title[0] != 0) |
---|
442 | { |
---|
443 | this->BuildTitle(force); |
---|
444 | } |
---|
445 | |
---|
446 | this->LastAxisPosition = this->AxisPosition; |
---|
447 | this->LastTickLocation = this->TickLocation; |
---|
448 | |
---|
449 | this->LastRange[0] = this->Range[0]; |
---|
450 | this->LastRange[1] = this->Range[1]; |
---|
451 | this->BuildTime.Modified(); |
---|
452 | } |
---|
453 | |
---|
454 | // **************************************************************** |
---|
455 | // |
---|
456 | // Set label values and properties. |
---|
457 | // |
---|
458 | // Modifications: |
---|
459 | // Kathleen Bonnell, Wed Oct 31 07:57:49 PST 2001 |
---|
460 | // Use valueScaleFactor to scale value if necessary. |
---|
461 | // |
---|
462 | // Kathleen Bonnell, Wed Nov 7 17:45:20 PST 2001 |
---|
463 | // Added code for early termination. Added call to SetNumberOfLabels |
---|
464 | // for dynamic memory allocation. Number of labels limited to 200. |
---|
465 | // |
---|
466 | // Kathleen Bonnell, Fri Nov 30 17:02:41 PST 2001 |
---|
467 | // Added test for modified range to determine if labels really need to |
---|
468 | // be built. |
---|
469 | // |
---|
470 | // Kathleen Bonnell, Thu May 16 10:13:56 PDT 2002 |
---|
471 | // Use defined constant to limit number of labels. |
---|
472 | // |
---|
473 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
474 | // Remvoed determination of label text, added call to |
---|
475 | // SetLabelPositions. |
---|
476 | // |
---|
477 | // **************************************************************** |
---|
478 | |
---|
479 | void |
---|
480 | vtkRpAxisActor::BuildLabels(vtkViewport *viewport, bool force) |
---|
481 | { |
---|
482 | if (!force && !this->LabelVisibility) |
---|
483 | { |
---|
484 | return; |
---|
485 | } |
---|
486 | |
---|
487 | for (int i = 0; i < this->NumberOfLabelsBuilt; i++) |
---|
488 | { |
---|
489 | this->LabelActors[i]->SetCamera(this->Camera); |
---|
490 | this->LabelActors[i]->SetProperty(this->GetProperty()); |
---|
491 | } |
---|
492 | |
---|
493 | if (force || this->BuildTime.GetMTime() < this->BoundsTime.GetMTime() || |
---|
494 | this->AxisPosition != this->LastAxisPosition || |
---|
495 | this->LastRange[0] != this->Range[0] || |
---|
496 | this->LastRange[1] != this->Range[1]) |
---|
497 | { |
---|
498 | this->SetLabelPositions(viewport, force); |
---|
499 | } |
---|
500 | } |
---|
501 | |
---|
502 | int vtkRpAxisActorMultiplierTable1[4] = { -1, -1, 1, 1}; |
---|
503 | int vtkRpAxisActorMultiplierTable2[4] = { -1, 1, 1, -1}; |
---|
504 | |
---|
505 | // ******************************************************************* |
---|
506 | // Determine and set scale factor and position for labels. |
---|
507 | // |
---|
508 | // Modifications: |
---|
509 | // Kathleen Bonnell, Fri Nov 30 17:02:41 PST 2001 |
---|
510 | // Reset labels scale to 1. before testing length, in order to |
---|
511 | // ensure proper scaling. Use Bounds[1] and Bounds[0] for bWidth |
---|
512 | // instead of Bounds[5] and Bounds[4]. |
---|
513 | // |
---|
514 | // Kathleen Bonnell, Tue Dec 4 09:55:03 PST 2001 |
---|
515 | // Ensure that scale does not go below MinScale. |
---|
516 | // |
---|
517 | // Kathleen Bonnell, Tue Apr 9 14:41:08 PDT 2002 |
---|
518 | // Removed MinScale as it allowed axes with very small ranges |
---|
519 | // to have labels scaled too large for the dataset. |
---|
520 | // |
---|
521 | // Kathleen Bonnell, Fri Jul 18 09:09:31 PDT 2003 |
---|
522 | // Renamed to SetLabelPosition. Removed calculation of label |
---|
523 | // scale factor, added check for no labels to early return test. |
---|
524 | // |
---|
525 | // Eric Brugger, Tue Jul 29 14:42:44 PDT 2003 |
---|
526 | // Corrected the test that causes the routine to exit early when |
---|
527 | // no work needs to be done. |
---|
528 | // |
---|
529 | // David Gobbi, Fri Apr 8 16:50:00 MST 2011 |
---|
530 | // Use mapper bounds, not actor bounds. |
---|
531 | // |
---|
532 | // ******************************************************************* |
---|
533 | |
---|
534 | void vtkRpAxisActor::SetLabelPositions(vtkViewport *viewport, bool force) |
---|
535 | { |
---|
536 | if (!force && (!this->LabelVisibility || this->NumberOfLabelsBuilt == 0)) |
---|
537 | { |
---|
538 | return; |
---|
539 | } |
---|
540 | |
---|
541 | double bounds[6], center[3], tick[3], pos[3], scale[3]; |
---|
542 | int i = 0; |
---|
543 | int xmult = 0; |
---|
544 | int ymult = 0; |
---|
545 | |
---|
546 | switch (this->AxisType) |
---|
547 | { |
---|
548 | case VTK_AXIS_TYPE_X : |
---|
549 | xmult = 0; |
---|
550 | ymult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
551 | break; |
---|
552 | case VTK_AXIS_TYPE_Y : |
---|
553 | xmult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
554 | ymult = 0; |
---|
555 | break; |
---|
556 | case VTK_AXIS_TYPE_Z : |
---|
557 | xmult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
558 | ymult = vtkRpAxisActorMultiplierTable2[this->AxisPosition]; |
---|
559 | break; |
---|
560 | } |
---|
561 | |
---|
562 | int ptIdx; |
---|
563 | // |
---|
564 | // xadjust & yadjust are used for positioning the label correctly |
---|
565 | // depending upon the 'orientation' of the axis as determined |
---|
566 | // by its position in view space (via transformed bounds). |
---|
567 | // |
---|
568 | double displayBounds[6] = { 0., 0., 0., 0., 0., 0.}; |
---|
569 | this->TransformBounds(viewport, displayBounds); |
---|
570 | double xadjust = (displayBounds[0] > displayBounds[1] ? -1 : 1); |
---|
571 | double yadjust = (displayBounds[2] > displayBounds[3] ? -1 : 1); |
---|
572 | |
---|
573 | for (i=0; i < this->NumberOfLabelsBuilt && |
---|
574 | i < this->MajorTickPts->GetNumberOfPoints(); i++) |
---|
575 | { |
---|
576 | ptIdx = 4*i + 1; |
---|
577 | this->MajorTickPts->GetPoint(ptIdx, tick); |
---|
578 | |
---|
579 | this->LabelActors[i]->GetMapper()->GetBounds(bounds); |
---|
580 | this->LabelActors[i]->GetScale(scale); |
---|
581 | |
---|
582 | double halfWidth = (bounds[1] - bounds[0]) * 0.5 * scale[0]; |
---|
583 | double halfHeight = (bounds[3] - bounds[2]) * 0.5 * scale[1]; |
---|
584 | |
---|
585 | center[0] = tick[0] + xmult * (halfWidth + this->MinorTickSize); |
---|
586 | center[1] = tick[1] + ymult * (halfHeight + this->MinorTickSize); |
---|
587 | pos[0] = (center[0] - xadjust *halfWidth); |
---|
588 | pos[1] = (center[1] - yadjust *halfHeight); |
---|
589 | pos[2] = tick[2]; |
---|
590 | this->LabelActors[i]->SetPosition(pos[0], pos[1], pos[2]); |
---|
591 | } |
---|
592 | } |
---|
593 | |
---|
594 | // ********************************************************************** |
---|
595 | // Determines scale and position for the Title. Currently, |
---|
596 | // title can only be centered with respect to its axis. |
---|
597 | // |
---|
598 | // Modifications: |
---|
599 | // Kathleen Bonnell, Wed Nov 7 17:45:20 PST 2001 |
---|
600 | // Added logic for early-termination. |
---|
601 | // |
---|
602 | // Kathleen Bonnell, Mon Dec 3 16:49:01 PST 2001 |
---|
603 | // Test for modified bounds before early termination, use |
---|
604 | // MinScale, modified target so title size is a bit more reasonable. |
---|
605 | // |
---|
606 | // Kathleen Bonnell, Tue Apr 9 14:41:08 PDT 2002 |
---|
607 | // Removed MinScale as it allowed axes with very small ranges |
---|
608 | // to have labels scaled too large for the dataset. |
---|
609 | // |
---|
610 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
611 | // Added bool argument that allow the build to be forced, even if |
---|
612 | // the title won't be visible. |
---|
613 | // |
---|
614 | // Kathleen Bonnell, Tue Aug 31 16:17:43 PDT 2004 |
---|
615 | // Added TitleTime test so that the title can be rebuilt when its |
---|
616 | // text has changed. |
---|
617 | // |
---|
618 | // Hank Childs, Sun May 13 11:06:12 PDT 2007 |
---|
619 | // Fix bug with positioning of titles (the titles were being placed |
---|
620 | // far away from the bounding box in some cases). |
---|
621 | // |
---|
622 | // David Gobbi, Fri Apr 8 16:50:00 MST 2011 |
---|
623 | // Use mapper bounds, not actor bounds. |
---|
624 | // |
---|
625 | // ********************************************************************** |
---|
626 | |
---|
627 | void vtkRpAxisActor::BuildTitle(bool force) |
---|
628 | { |
---|
629 | if (!force && !this->TitleVisibility) |
---|
630 | { |
---|
631 | return; |
---|
632 | } |
---|
633 | double labBounds[6], titleBounds[6], center[3], pos[3], scale[3]; |
---|
634 | double labHeight, maxHeight = 0, labWidth, maxWidth = 0; |
---|
635 | double halfTitleWidth, halfTitleHeight; |
---|
636 | |
---|
637 | double *p1 = this->Point1Coordinate->GetValue(); |
---|
638 | double *p2 = this->Point2Coordinate->GetValue(); |
---|
639 | int xmult = 0; |
---|
640 | int ymult = 0; |
---|
641 | |
---|
642 | if (!force && this->LabelBuildTime.GetMTime() < this->BuildTime.GetMTime() && |
---|
643 | this->BoundsTime.GetMTime() < this->BuildTime.GetMTime() && |
---|
644 | this->AxisPosition == this->LastAxisPosition && |
---|
645 | this->TitleTextTime.GetMTime() < this->BuildTime.GetMTime()) |
---|
646 | { |
---|
647 | return; |
---|
648 | } |
---|
649 | |
---|
650 | switch (this->AxisType) |
---|
651 | { |
---|
652 | case VTK_AXIS_TYPE_X : |
---|
653 | xmult = 0; |
---|
654 | ymult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
655 | break; |
---|
656 | case VTK_AXIS_TYPE_Y : |
---|
657 | xmult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
658 | ymult = 0; |
---|
659 | break; |
---|
660 | case VTK_AXIS_TYPE_Z : |
---|
661 | xmult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
662 | ymult = vtkRpAxisActorMultiplierTable2[this->AxisPosition]; |
---|
663 | break; |
---|
664 | } |
---|
665 | // |
---|
666 | // Title should be in relation to labels (if any) |
---|
667 | // so find out information about them. |
---|
668 | // |
---|
669 | for (int i = 0; i < this->NumberOfLabelsBuilt; i++) |
---|
670 | { |
---|
671 | this->LabelActors[i]->GetMapper()->GetBounds(labBounds); |
---|
672 | this->LabelActors[i]->GetScale(scale); |
---|
673 | labWidth = (labBounds[1] - labBounds[0])*scale[0]; |
---|
674 | maxWidth = (labWidth > maxWidth ? labWidth : maxWidth); |
---|
675 | labHeight = (labBounds[3] - labBounds[2])*scale[1]; |
---|
676 | maxHeight = (labHeight > maxHeight ? labHeight : maxHeight); |
---|
677 | } |
---|
678 | this->TitleVector->SetText(this->Title); |
---|
679 | this->TitleActor->SetCamera(this->Camera); |
---|
680 | this->TitleActor->SetPosition(p2[0], p2[1], p2[2]); |
---|
681 | this->TitleActor->GetMapper()->GetBounds(titleBounds); |
---|
682 | this->TitleActor->GetScale(scale); |
---|
683 | halfTitleWidth = (titleBounds[1] - titleBounds[0]) * 0.5 * scale[0]; |
---|
684 | halfTitleHeight = (titleBounds[3] - titleBounds[2]) * 0.5 * scale[1]; |
---|
685 | |
---|
686 | center[0] = p1[0] + (p2[0] - p1[0]) / 2.0; |
---|
687 | center[1] = p1[1] + (p2[1] - p1[1]) / 2.0; |
---|
688 | center[2] = p1[2] + (p2[2] - p1[2]) / 2.0; |
---|
689 | |
---|
690 | center[0] += xmult * (halfTitleWidth + maxWidth); |
---|
691 | center[1] += ymult * (halfTitleHeight + 2*maxHeight); |
---|
692 | |
---|
693 | pos[0] = center[0] - xmult*halfTitleWidth; |
---|
694 | pos[1] = center[1] - ymult*halfTitleHeight; |
---|
695 | pos[2] = center[2]; |
---|
696 | this->TitleActor->SetPosition(pos[0], pos[1], pos[2]); |
---|
697 | } |
---|
698 | |
---|
699 | // |
---|
700 | // Transform the bounding box to display coordinates. Used |
---|
701 | // in determining orientation of the axis. |
---|
702 | // |
---|
703 | void vtkRpAxisActor::TransformBounds(vtkViewport *viewport, double bnds[6]) |
---|
704 | { |
---|
705 | double minPt[3], maxPt[3], transMinPt[3], transMaxPt[3]; |
---|
706 | minPt[0] = this->Bounds[0]; |
---|
707 | minPt[1] = this->Bounds[2]; |
---|
708 | minPt[2] = this->Bounds[4]; |
---|
709 | maxPt[0] = this->Bounds[1]; |
---|
710 | maxPt[1] = this->Bounds[3]; |
---|
711 | maxPt[2] = this->Bounds[5]; |
---|
712 | |
---|
713 | viewport->SetWorldPoint(minPt[0], minPt[1], minPt[2], 1.0); |
---|
714 | viewport->WorldToDisplay(); |
---|
715 | viewport->GetDisplayPoint(transMinPt); |
---|
716 | viewport->SetWorldPoint(maxPt[0], maxPt[1], maxPt[2], 1.0); |
---|
717 | viewport->WorldToDisplay(); |
---|
718 | viewport->GetDisplayPoint(transMaxPt); |
---|
719 | |
---|
720 | bnds[0] = transMinPt[0]; |
---|
721 | bnds[2] = transMinPt[1]; |
---|
722 | bnds[4] = transMinPt[2]; |
---|
723 | bnds[1] = transMaxPt[0]; |
---|
724 | bnds[3] = transMaxPt[1]; |
---|
725 | bnds[5] = transMaxPt[2]; |
---|
726 | } |
---|
727 | |
---|
728 | inline double ffix(double value) |
---|
729 | { |
---|
730 | int ivalue = static_cast<int>(value); |
---|
731 | return static_cast<double>(ivalue); |
---|
732 | } |
---|
733 | |
---|
734 | inline double fsign(double value, double sign) |
---|
735 | { |
---|
736 | value = fabs(value); |
---|
737 | if (sign < 0.) |
---|
738 | { |
---|
739 | value *= -1.; |
---|
740 | } |
---|
741 | return value; |
---|
742 | } |
---|
743 | |
---|
744 | // **************************************************************** |
---|
745 | // Modifications: |
---|
746 | // Kathleen Bonnell, Wed Mar 6 13:48:48 PST 2002 |
---|
747 | // Call superclass's method in new VTK 4.0 way. |
---|
748 | // **************************************************************** |
---|
749 | |
---|
750 | void vtkRpAxisActor::PrintSelf(ostream& os, vtkIndent indent) |
---|
751 | { |
---|
752 | this->Superclass::PrintSelf(os,indent); |
---|
753 | |
---|
754 | os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n"; |
---|
755 | os << indent << "Number Of Labels Built: " |
---|
756 | << this->NumberOfLabelsBuilt << "\n"; |
---|
757 | os << indent << "Range: (" << this->Range[0] |
---|
758 | << ", " << this->Range[1] << ")\n"; |
---|
759 | |
---|
760 | os << indent << "Label Format: " << this->LabelFormat << "\n"; |
---|
761 | |
---|
762 | os << indent << "Axis Visibility: " |
---|
763 | << (this->AxisVisibility ? "On\n" : "Off\n"); |
---|
764 | |
---|
765 | os << indent << "Tick Visibility: " |
---|
766 | << (this->TickVisibility ? "On\n" : "Off\n"); |
---|
767 | |
---|
768 | os << indent << "Label Visibility: " |
---|
769 | << (this->LabelVisibility ? "On\n" : "Off\n"); |
---|
770 | |
---|
771 | os << indent << "Title Visibility: " |
---|
772 | << (this->TitleVisibility ? "On\n" : "Off\n"); |
---|
773 | |
---|
774 | os << indent << "Point1 Coordinate: " << this->Point1Coordinate << "\n"; |
---|
775 | this->Point1Coordinate->PrintSelf(os, indent.GetNextIndent()); |
---|
776 | |
---|
777 | os << indent << "Point2 Coordinate: " << this->Point2Coordinate << "\n"; |
---|
778 | this->Point2Coordinate->PrintSelf(os, indent.GetNextIndent()); |
---|
779 | |
---|
780 | os << indent << "AxisType: "; |
---|
781 | switch (this->AxisType) |
---|
782 | { |
---|
783 | case VTK_AXIS_TYPE_X: |
---|
784 | os << "X Axis" << endl; |
---|
785 | break; |
---|
786 | case VTK_AXIS_TYPE_Y: |
---|
787 | os << "Y Axis" << endl; |
---|
788 | break; |
---|
789 | case VTK_AXIS_TYPE_Z: |
---|
790 | os << "Z Axis" << endl; |
---|
791 | break; |
---|
792 | default: |
---|
793 | // shouldn't get here |
---|
794 | ; |
---|
795 | } |
---|
796 | |
---|
797 | os << indent << "DeltaMajor: " << this->DeltaMajor << endl; |
---|
798 | os << indent << "DeltaMinor: " << this->DeltaMinor << endl; |
---|
799 | os << indent << "DeltaRangeMajor: " << this->DeltaRangeMajor << endl; |
---|
800 | os << indent << "DeltaRangeMinor: " << this->DeltaRangeMinor << endl; |
---|
801 | os << indent << "MajorRangeStart: " << this->MajorRangeStart << endl; |
---|
802 | os << indent << "MinorRangeStart: " << this->MinorRangeStart << endl; |
---|
803 | |
---|
804 | os << indent << "MinorTicksVisible: " << this->MinorTicksVisible << endl; |
---|
805 | |
---|
806 | os << indent << "Camera: "; |
---|
807 | if (this->Camera) |
---|
808 | { |
---|
809 | this->Camera->PrintSelf(os, indent); |
---|
810 | } |
---|
811 | else |
---|
812 | { |
---|
813 | os << "(none)" << endl; |
---|
814 | } |
---|
815 | |
---|
816 | os << indent << "MajorTickSize: " << this->MajorTickSize << endl; |
---|
817 | os << indent << "MinorTickSize: " << this->MinorTickSize << endl; |
---|
818 | |
---|
819 | os << indent << "DrawGridlines: " << this->DrawGridlines << endl; |
---|
820 | |
---|
821 | os << indent << "MajorStart: " << this->MajorStart << endl; |
---|
822 | os << indent << "MinorStart: " << this->MinorStart << endl; |
---|
823 | |
---|
824 | os << indent << "AxisPosition: " << this->AxisPosition << endl; |
---|
825 | |
---|
826 | os << indent << "GridlineXLength: " << this->GridlineXLength << endl; |
---|
827 | os << indent << "GridlineYLength: " << this->GridlineYLength << endl; |
---|
828 | os << indent << "GridlineZLength: " << this->GridlineZLength << endl; |
---|
829 | |
---|
830 | os << indent << "TickLocation: " << this->TickLocation << endl; |
---|
831 | } |
---|
832 | |
---|
833 | // ************************************************************************** |
---|
834 | // Sets text string for label vectors. Allocates memory if necessary. |
---|
835 | // |
---|
836 | // Programmer: Kathleen Bonnell |
---|
837 | // Creation: July 18, 2003 |
---|
838 | // ************************************************************************** |
---|
839 | void vtkRpAxisActor::SetLabels(vtkStringArray *labels) |
---|
840 | { |
---|
841 | // |
---|
842 | // If the number of labels has changed, re-allocate the correct |
---|
843 | // amount of memory. |
---|
844 | // |
---|
845 | int i, numLabels = labels->GetNumberOfValues(); |
---|
846 | if (this->NumberOfLabelsBuilt != numLabels) |
---|
847 | { |
---|
848 | if (this->LabelMappers != NULL) |
---|
849 | { |
---|
850 | for (i = 0; i < this->NumberOfLabelsBuilt; i++) |
---|
851 | { |
---|
852 | this->LabelVectors[i]->Delete(); |
---|
853 | this->LabelMappers[i]->Delete(); |
---|
854 | this->LabelActors[i]->Delete(); |
---|
855 | } |
---|
856 | delete [] this->LabelVectors; |
---|
857 | delete [] this->LabelMappers; |
---|
858 | delete [] this->LabelActors; |
---|
859 | } |
---|
860 | |
---|
861 | this->LabelVectors = new vtkVectorText * [numLabels]; |
---|
862 | this->LabelMappers = new vtkPolyDataMapper * [numLabels]; |
---|
863 | this->LabelActors = new vtkFollower * [numLabels]; |
---|
864 | |
---|
865 | for (i = 0; i < numLabels; i++) |
---|
866 | { |
---|
867 | this->LabelVectors[i] = vtkVectorText::New(); |
---|
868 | this->LabelMappers[i] = vtkPolyDataMapper::New(); |
---|
869 | #ifdef USE_VTK6 |
---|
870 | this->LabelMappers[i]->SetInputData(this->LabelVectors[i]->GetOutput()); |
---|
871 | #else |
---|
872 | this->LabelMappers[i]->SetInput(this->LabelVectors[i]->GetOutput()); |
---|
873 | #endif |
---|
874 | this->LabelActors[i] = vtkFollower::New(); |
---|
875 | this->LabelActors[i]->SetMapper(this->LabelMappers[i]); |
---|
876 | } |
---|
877 | } |
---|
878 | |
---|
879 | // |
---|
880 | // Set the label vector text. |
---|
881 | // |
---|
882 | for (i = 0; i < numLabels; i++) |
---|
883 | { |
---|
884 | this->LabelVectors[i]->SetText(labels->GetValue(i).c_str()); |
---|
885 | } |
---|
886 | this->NumberOfLabelsBuilt = numLabels; |
---|
887 | this->LabelBuildTime.Modified(); |
---|
888 | } |
---|
889 | |
---|
890 | // ************************************************************************** |
---|
891 | // Creates points for ticks (minor, major, gridlines) in correct position |
---|
892 | // for X-type axsis. |
---|
893 | // |
---|
894 | // Programmer: Kathleen Bonnell |
---|
895 | // Creation: November 7, 2001 |
---|
896 | // |
---|
897 | // Modifications: |
---|
898 | // Kathleen Bonnell, Mon Dec 3 16:49:01 PST 2001 |
---|
899 | // Compare vtkTimeStamps correctly. |
---|
900 | // |
---|
901 | // Kathleen Bonnell, Thu May 16 10:13:56 PDT 2002 |
---|
902 | // Use defined constant VTK_MAX_TICKS to prevent infinite loops. |
---|
903 | // |
---|
904 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
905 | // Allow a forced build, despite previous build time. |
---|
906 | // |
---|
907 | // ************************************************************************** |
---|
908 | bool vtkRpAxisActor::BuildTickPointsForXType(double p1[3], double p2[3], |
---|
909 | bool force) |
---|
910 | { |
---|
911 | if (!force && (this->AxisPosition == this->LastAxisPosition) && |
---|
912 | (this->TickLocation == this->LastTickLocation ) && |
---|
913 | (this->BoundsTime.GetMTime() < this->BuildTime.GetMTime())) |
---|
914 | { |
---|
915 | return false; |
---|
916 | } |
---|
917 | |
---|
918 | double xPoint1[3], xPoint2[3], yPoint[3], zPoint[3], x; |
---|
919 | int numTicks; |
---|
920 | |
---|
921 | this->MinorTickPts->Reset(); |
---|
922 | this->MajorTickPts->Reset(); |
---|
923 | this->GridlinePts->Reset(); |
---|
924 | |
---|
925 | // |
---|
926 | // Ymult & Zmult control adjustments to tick position based |
---|
927 | // upon "where" this axis is located in relation to the underlying |
---|
928 | // assumed bounding box. |
---|
929 | // |
---|
930 | int yMult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
931 | int zMult = vtkRpAxisActorMultiplierTable2[this->AxisPosition]; |
---|
932 | |
---|
933 | // |
---|
934 | // Build Minor Ticks |
---|
935 | // |
---|
936 | if (this->TickLocation == VTK_TICKS_OUTSIDE) |
---|
937 | { |
---|
938 | xPoint1[1] = xPoint2[1] = zPoint[1] = p1[1]; |
---|
939 | xPoint1[2] = xPoint2[2] = yPoint[2] = p1[2]; |
---|
940 | yPoint[1] = p1[1] + yMult * this->MinorTickSize; |
---|
941 | zPoint[2] = p1[2] + zMult * this->MinorTickSize; |
---|
942 | } |
---|
943 | else if (this->TickLocation == VTK_TICKS_INSIDE) |
---|
944 | { |
---|
945 | yPoint[1] = xPoint2[1] = zPoint[1] = p1[1]; |
---|
946 | xPoint1[2] = yPoint[2] = zPoint[2] = p1[2]; |
---|
947 | xPoint1[1] = p1[1] - yMult * this->MinorTickSize; |
---|
948 | xPoint2[2] = p1[2] - zMult * this->MinorTickSize; |
---|
949 | } |
---|
950 | else // both sides |
---|
951 | { |
---|
952 | xPoint2[1] = zPoint[1] = p1[1]; |
---|
953 | xPoint1[2] = yPoint[2] = p1[2]; |
---|
954 | yPoint[1] = p1[1] + yMult * this->MinorTickSize; |
---|
955 | zPoint[2] = p1[2] + zMult * this->MinorTickSize; |
---|
956 | xPoint1[1] = p1[1] - yMult * this->MinorTickSize; |
---|
957 | xPoint2[2] = p1[2] - zMult * this->MinorTickSize; |
---|
958 | } |
---|
959 | x = this->MinorStart; |
---|
960 | numTicks = 0; |
---|
961 | while (x <= p2[0] && numTicks < VTK_MAX_TICKS) |
---|
962 | { |
---|
963 | xPoint1[0] = xPoint2[0] = yPoint[0] = zPoint[0] = x; |
---|
964 | // xy-portion |
---|
965 | this->MinorTickPts->InsertNextPoint(xPoint1); |
---|
966 | this->MinorTickPts->InsertNextPoint(yPoint); |
---|
967 | // xz-portion |
---|
968 | this->MinorTickPts->InsertNextPoint(xPoint2); |
---|
969 | this->MinorTickPts->InsertNextPoint(zPoint); |
---|
970 | x+= this->DeltaMinor; |
---|
971 | numTicks++; |
---|
972 | } |
---|
973 | |
---|
974 | // |
---|
975 | // Gridline points |
---|
976 | // |
---|
977 | yPoint[1] = xPoint2[1] = zPoint[1] = p1[1]; |
---|
978 | xPoint1[1] = p1[1] - yMult * this->GridlineYLength; |
---|
979 | xPoint1[2] = yPoint[2] = zPoint[2] = p1[2]; |
---|
980 | xPoint2[2] = p1[2] - zMult * this->GridlineZLength; |
---|
981 | |
---|
982 | x = this->MajorStart; |
---|
983 | numTicks = 0; |
---|
984 | while (x <= p2[0] && numTicks < VTK_MAX_TICKS) |
---|
985 | { |
---|
986 | xPoint1[0] = xPoint2[0] = yPoint[0] = zPoint[0] = x; |
---|
987 | // xy-portion |
---|
988 | this->GridlinePts->InsertNextPoint(xPoint1); |
---|
989 | this->GridlinePts->InsertNextPoint(yPoint); |
---|
990 | // xz-portion |
---|
991 | this->GridlinePts->InsertNextPoint(xPoint2); |
---|
992 | this->GridlinePts->InsertNextPoint(zPoint); |
---|
993 | x += this->DeltaMajor; |
---|
994 | numTicks++; |
---|
995 | } |
---|
996 | |
---|
997 | // |
---|
998 | // Major ticks |
---|
999 | // |
---|
1000 | if (this->TickLocation == VTK_TICKS_OUTSIDE) |
---|
1001 | { |
---|
1002 | xPoint1[1] = xPoint2[1] = zPoint[1] = p1[1]; |
---|
1003 | xPoint1[2] = xPoint2[2] = yPoint[2] = p1[2]; |
---|
1004 | yPoint[1] = p1[1] + yMult * this->MajorTickSize; |
---|
1005 | zPoint[2] = p1[2] + zMult * this->MajorTickSize; |
---|
1006 | } |
---|
1007 | else if (this->TickLocation == VTK_TICKS_INSIDE) |
---|
1008 | { |
---|
1009 | yPoint[1] = xPoint2[1] = zPoint[1] = p1[1]; |
---|
1010 | xPoint1[2] = yPoint[2] = zPoint[2] = p1[2]; |
---|
1011 | xPoint1[1] = p1[1] - yMult * this->MajorTickSize; |
---|
1012 | xPoint2[2] = p1[2] - zMult * this->MajorTickSize; |
---|
1013 | } |
---|
1014 | else // both sides |
---|
1015 | { |
---|
1016 | xPoint2[1] = zPoint[1] = p1[1]; |
---|
1017 | xPoint1[2] = yPoint[2] = p1[2]; |
---|
1018 | yPoint[1] = p1[1] + yMult * this->MajorTickSize; |
---|
1019 | zPoint[2] = p1[2] + zMult * this->MajorTickSize; |
---|
1020 | xPoint1[1] = p1[1] - yMult * this->MajorTickSize; |
---|
1021 | xPoint2[2] = p1[2] - zMult * this->MajorTickSize; |
---|
1022 | } |
---|
1023 | x = this->MajorStart; |
---|
1024 | numTicks = 0; |
---|
1025 | while (x <= p2[0] && numTicks < VTK_MAX_TICKS) |
---|
1026 | { |
---|
1027 | xPoint1[0] = xPoint2[0] = yPoint[0] = zPoint[0] = x; |
---|
1028 | // xy-portion |
---|
1029 | this->MajorTickPts->InsertNextPoint(xPoint1); |
---|
1030 | this->MajorTickPts->InsertNextPoint(yPoint); |
---|
1031 | // xz-portion |
---|
1032 | this->MajorTickPts->InsertNextPoint(xPoint2); |
---|
1033 | this->MajorTickPts->InsertNextPoint(zPoint); |
---|
1034 | x += this->DeltaMajor; |
---|
1035 | numTicks++; |
---|
1036 | } |
---|
1037 | |
---|
1038 | return true; |
---|
1039 | } |
---|
1040 | |
---|
1041 | // ************************************************************************** |
---|
1042 | // Creates points for ticks (minor, major, gridlines) in correct position |
---|
1043 | // for Y-type axis. |
---|
1044 | // |
---|
1045 | // Programmer: Kathleen Bonnell |
---|
1046 | // Creation: November 7, 2001 |
---|
1047 | // |
---|
1048 | // Modifications: |
---|
1049 | // Kathleen Bonnell, Mon Dec 3 16:49:01 PST 2001 |
---|
1050 | // Compare vtkTimeStamps correctly. |
---|
1051 | // |
---|
1052 | // Kathleen Bonnell, Thu May 16 10:13:56 PDT 2002 |
---|
1053 | // Use defined constant VTK_MAX_TICKS to prevent infinite loops. |
---|
1054 | // |
---|
1055 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
1056 | // Allow a forced build, despite previous build time. |
---|
1057 | // |
---|
1058 | // ************************************************************************** |
---|
1059 | bool vtkRpAxisActor::BuildTickPointsForYType(double p1[3], double p2[3], |
---|
1060 | bool force) |
---|
1061 | { |
---|
1062 | if (!force && (this->AxisPosition == this->LastAxisPosition) && |
---|
1063 | (this->TickLocation == this->LastTickLocation) && |
---|
1064 | (this->BoundsTime.GetMTime() < this->BuildTime.GetMTime())) |
---|
1065 | { |
---|
1066 | return false; |
---|
1067 | } |
---|
1068 | |
---|
1069 | double yPoint1[3], yPoint2[3], xPoint[3], zPoint[3], y; |
---|
1070 | int numTicks; |
---|
1071 | |
---|
1072 | this->MinorTickPts->Reset(); |
---|
1073 | this->MajorTickPts->Reset(); |
---|
1074 | this->GridlinePts->Reset(); |
---|
1075 | // |
---|
1076 | // xMult & zMult control adjustments to tick position based |
---|
1077 | // upon "where" this axis is located in relation to the underlying |
---|
1078 | // assumed bounding box. |
---|
1079 | // |
---|
1080 | |
---|
1081 | int xMult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
1082 | int zMult = vtkRpAxisActorMultiplierTable2[this->AxisPosition]; |
---|
1083 | |
---|
1084 | // |
---|
1085 | // The ordering of the tick endpoints is important because |
---|
1086 | // label position is defined by them. |
---|
1087 | // |
---|
1088 | |
---|
1089 | // |
---|
1090 | // minor ticks |
---|
1091 | // |
---|
1092 | if (this->TickLocation == VTK_TICKS_INSIDE) |
---|
1093 | { |
---|
1094 | yPoint1[2] = xPoint[2] = zPoint[2] = p1[2]; |
---|
1095 | yPoint2[0] = xPoint[0] = zPoint[0] = p1[0]; |
---|
1096 | yPoint1[0] = p1[0] - xMult * this->MinorTickSize; |
---|
1097 | yPoint2[2] = p1[2] - zMult * this->MinorTickSize; |
---|
1098 | } |
---|
1099 | else if (this->TickLocation == VTK_TICKS_OUTSIDE) |
---|
1100 | { |
---|
1101 | yPoint1[0] = yPoint2[0] = zPoint[0] = p1[0]; |
---|
1102 | yPoint1[2] = yPoint2[2] = xPoint[2] = p1[2]; |
---|
1103 | xPoint[0] = p1[0] + xMult * this->MinorTickSize; |
---|
1104 | zPoint[2] = p1[2] + zMult * this->MinorTickSize; |
---|
1105 | } |
---|
1106 | else // both sides |
---|
1107 | { |
---|
1108 | yPoint1[2] = xPoint[2] = p1[2]; |
---|
1109 | yPoint2[0] = zPoint[0] = p1[0]; |
---|
1110 | yPoint1[0] = p1[0] - xMult * this->MinorTickSize; |
---|
1111 | yPoint2[2] = p1[2] + zMult * this->MinorTickSize; |
---|
1112 | xPoint[0] = p1[0] + xMult * this->MinorTickSize; |
---|
1113 | zPoint[2] = p1[2] - zMult * this->MinorTickSize; |
---|
1114 | } |
---|
1115 | y = this->MinorStart; |
---|
1116 | numTicks = 0; |
---|
1117 | while (y < p2[1] && numTicks < VTK_MAX_TICKS) |
---|
1118 | { |
---|
1119 | yPoint1[1] = xPoint[1] = yPoint2[1] = zPoint[1] = y; |
---|
1120 | // yx portion |
---|
1121 | this->MinorTickPts->InsertNextPoint(yPoint1); |
---|
1122 | this->MinorTickPts->InsertNextPoint(xPoint); |
---|
1123 | // yz portion |
---|
1124 | this->MinorTickPts->InsertNextPoint(yPoint2); |
---|
1125 | this->MinorTickPts->InsertNextPoint(zPoint); |
---|
1126 | y += this->DeltaMinor; |
---|
1127 | numTicks++; |
---|
1128 | } |
---|
1129 | |
---|
1130 | // |
---|
1131 | // gridlines |
---|
1132 | // |
---|
1133 | yPoint1[0] = p1[0] - xMult * this->GridlineXLength; |
---|
1134 | yPoint2[2] = p1[2] - zMult * this->GridlineZLength; |
---|
1135 | yPoint2[0] = xPoint[0] = zPoint[0] = p1[0]; |
---|
1136 | yPoint1[2] = xPoint[2] = zPoint[2] = p1[2]; |
---|
1137 | |
---|
1138 | y = this->MajorStart; |
---|
1139 | numTicks = 0; |
---|
1140 | while (y <= p2[1] && numTicks < VTK_MAX_TICKS) |
---|
1141 | { |
---|
1142 | yPoint1[1] = xPoint[1] = yPoint2[1] = zPoint[1] = y; |
---|
1143 | // yx portion |
---|
1144 | this->GridlinePts->InsertNextPoint(yPoint1); |
---|
1145 | this->GridlinePts->InsertNextPoint(xPoint); |
---|
1146 | // yz portion |
---|
1147 | this->GridlinePts->InsertNextPoint(yPoint2); |
---|
1148 | this->GridlinePts->InsertNextPoint(zPoint); |
---|
1149 | y += this->DeltaMajor; |
---|
1150 | numTicks++; |
---|
1151 | } |
---|
1152 | |
---|
1153 | // |
---|
1154 | // major ticks |
---|
1155 | // |
---|
1156 | if (this->TickLocation == VTK_TICKS_INSIDE) |
---|
1157 | { |
---|
1158 | yPoint1[2] = xPoint[2] = zPoint[2] = p1[2]; |
---|
1159 | yPoint2[0] = xPoint[0] = zPoint[0] = p1[0]; |
---|
1160 | yPoint1[0] = p1[0] - xMult * this->MajorTickSize; |
---|
1161 | yPoint2[2] = p1[2] - zMult * this->MajorTickSize; |
---|
1162 | } |
---|
1163 | else if (this->TickLocation == VTK_TICKS_OUTSIDE) |
---|
1164 | { |
---|
1165 | yPoint1[0] = yPoint2[0] = zPoint[0] = p1[0]; |
---|
1166 | yPoint1[2] = yPoint2[2] = xPoint[2] = p1[2]; |
---|
1167 | xPoint[0] = p1[0] + xMult * this->MajorTickSize; |
---|
1168 | zPoint[2] = p1[2] + zMult * this->MajorTickSize; |
---|
1169 | } |
---|
1170 | else // both sides |
---|
1171 | { |
---|
1172 | yPoint1[2] = xPoint[2] = p1[2]; |
---|
1173 | yPoint2[0] = zPoint[0] = p1[0]; |
---|
1174 | yPoint1[0] = p1[0] - xMult * this->MajorTickSize; |
---|
1175 | yPoint2[2] = p1[2] + zMult * this->MajorTickSize; |
---|
1176 | xPoint[0] = p1[0] + xMult * this->MajorTickSize; |
---|
1177 | zPoint[2] = p1[2] - zMult * this->MajorTickSize; |
---|
1178 | } |
---|
1179 | y = this->MajorStart; |
---|
1180 | numTicks = 0; |
---|
1181 | while (y <= p2[1] && numTicks < VTK_MAX_TICKS) |
---|
1182 | { |
---|
1183 | yPoint1[1] = xPoint[1] = yPoint2[1] = zPoint[1] = y; |
---|
1184 | // yx portion |
---|
1185 | this->MajorTickPts->InsertNextPoint(yPoint1); |
---|
1186 | this->MajorTickPts->InsertNextPoint(xPoint); |
---|
1187 | // yz portion |
---|
1188 | this->MajorTickPts->InsertNextPoint(yPoint2); |
---|
1189 | this->MajorTickPts->InsertNextPoint(zPoint); |
---|
1190 | y += this->DeltaMajor; |
---|
1191 | numTicks++; |
---|
1192 | } |
---|
1193 | return true; |
---|
1194 | } |
---|
1195 | |
---|
1196 | // ************************************************************************** |
---|
1197 | // Creates points for ticks (minor, major, gridlines) in correct position |
---|
1198 | // for Z-type axis. |
---|
1199 | // |
---|
1200 | // Programmer: Kathleen Bonnell |
---|
1201 | // Creation: November 7, 2001 |
---|
1202 | // |
---|
1203 | // Modifications: |
---|
1204 | // Kathleen Bonnell, Mon Dec 3 16:49:01 PST 2001 |
---|
1205 | // Compare vtkTimeStamps correctly. |
---|
1206 | // |
---|
1207 | // Kathleen Bonnell, Thu May 16 10:13:56 PDT 2002 |
---|
1208 | // Use defined constant VTK_MAX_TICKS to prevent infinite loops. |
---|
1209 | // |
---|
1210 | // Kathleen Bonnell, Fri Jul 25 14:37:32 PDT 2003 |
---|
1211 | // Allow a forced build, despite previous build time. |
---|
1212 | // |
---|
1213 | // ************************************************************************** |
---|
1214 | |
---|
1215 | bool vtkRpAxisActor::BuildTickPointsForZType(double p1[3], double p2[3], |
---|
1216 | bool force) |
---|
1217 | { |
---|
1218 | if (!force && (this->AxisPosition == this->LastAxisPosition) && |
---|
1219 | (this->TickLocation == this->LastTickLocation) && |
---|
1220 | (this->BoundsTime.GetMTime() < this->BuildTime.GetMTime())) |
---|
1221 | { |
---|
1222 | return false; |
---|
1223 | } |
---|
1224 | |
---|
1225 | this->MinorTickPts->Reset(); |
---|
1226 | this->MajorTickPts->Reset(); |
---|
1227 | this->GridlinePts->Reset(); |
---|
1228 | |
---|
1229 | // |
---|
1230 | // xMult & yMult control adjustments to tick position based |
---|
1231 | // upon "where" this axis is located in relation to the underlying |
---|
1232 | // assumed bounding box. |
---|
1233 | // |
---|
1234 | int xMult = vtkRpAxisActorMultiplierTable1[this->AxisPosition]; |
---|
1235 | int yMult = vtkRpAxisActorMultiplierTable2[this->AxisPosition]; |
---|
1236 | |
---|
1237 | double zPoint1[3], zPoint2[3], xPoint[3], yPoint[3], z; |
---|
1238 | int numTicks; |
---|
1239 | |
---|
1240 | // |
---|
1241 | // The ordering of the tick endpoints is important because |
---|
1242 | // label position is defined by them. |
---|
1243 | // |
---|
1244 | |
---|
1245 | // |
---|
1246 | // minor ticks |
---|
1247 | // |
---|
1248 | if (this->TickLocation == VTK_TICKS_INSIDE) |
---|
1249 | { |
---|
1250 | zPoint1[0] = p1[0] - xMult * this->MinorTickSize; |
---|
1251 | zPoint2[1] = p1[1] - yMult * this->MinorTickSize; |
---|
1252 | zPoint2[0] = xPoint[0] = yPoint[0] = p1[0]; |
---|
1253 | zPoint1[1] = xPoint[1] = yPoint[1] = p1[1]; |
---|
1254 | } |
---|
1255 | else if (this->TickLocation == VTK_TICKS_OUTSIDE) |
---|
1256 | { |
---|
1257 | xPoint[0] = p1[0] + xMult * this->MinorTickSize; |
---|
1258 | yPoint[1] = p1[1] +yMult * this->MinorTickSize; |
---|
1259 | zPoint1[0] = zPoint2[0] = yPoint[0] = p1[0]; |
---|
1260 | zPoint1[1] = zPoint2[1] = xPoint[1] = p1[1]; |
---|
1261 | } |
---|
1262 | else // both sides |
---|
1263 | { |
---|
1264 | zPoint1[0] = p1[0] - xMult * this->MinorTickSize; |
---|
1265 | xPoint[0] = p1[0] + xMult * this->MinorTickSize; |
---|
1266 | zPoint2[1] = p1[1] - yMult * this->MinorTickSize; |
---|
1267 | yPoint[1] = p1[1] + yMult * this->MinorTickSize; |
---|
1268 | zPoint1[1] = xPoint[1] = p1[1]; |
---|
1269 | zPoint2[0] = yPoint[0] = p1[0]; |
---|
1270 | } |
---|
1271 | z = this->MinorStart; |
---|
1272 | numTicks = 0; |
---|
1273 | while (z < p2[2] && numTicks < VTK_MAX_TICKS) |
---|
1274 | { |
---|
1275 | zPoint1[2] = zPoint2[2] = xPoint[2] = yPoint[2] = z; |
---|
1276 | // zx-portion |
---|
1277 | this->MinorTickPts->InsertNextPoint(zPoint1); |
---|
1278 | this->MinorTickPts->InsertNextPoint(xPoint); |
---|
1279 | // zy-portion |
---|
1280 | this->MinorTickPts->InsertNextPoint(zPoint2); |
---|
1281 | this->MinorTickPts->InsertNextPoint(yPoint); |
---|
1282 | z += this->DeltaMinor; |
---|
1283 | numTicks++; |
---|
1284 | } |
---|
1285 | |
---|
1286 | // |
---|
1287 | // gridlines |
---|
1288 | // |
---|
1289 | zPoint1[0] = p1[0] - xMult * this->GridlineXLength; |
---|
1290 | zPoint2[1] = p1[1] - yMult * this->GridlineYLength; |
---|
1291 | zPoint1[1] = xPoint[1] = yPoint[1] = p1[1]; |
---|
1292 | zPoint2[0] = xPoint[0] = yPoint[0] = p1[0]; |
---|
1293 | |
---|
1294 | z = this->MajorStart; |
---|
1295 | numTicks = 0; |
---|
1296 | while (z <= p2[2] && numTicks < VTK_MAX_TICKS) |
---|
1297 | { |
---|
1298 | zPoint1[2] = zPoint2[2] = xPoint[2] = yPoint[2] = z; |
---|
1299 | // zx-portion |
---|
1300 | this->GridlinePts->InsertNextPoint(zPoint1); |
---|
1301 | this->GridlinePts->InsertNextPoint(xPoint); |
---|
1302 | // zy-portion |
---|
1303 | this->GridlinePts->InsertNextPoint(zPoint2); |
---|
1304 | this->GridlinePts->InsertNextPoint(yPoint); |
---|
1305 | z += this->DeltaMajor; |
---|
1306 | numTicks++; |
---|
1307 | } |
---|
1308 | |
---|
1309 | // |
---|
1310 | // major ticks |
---|
1311 | // |
---|
1312 | |
---|
1313 | if (this->TickLocation == VTK_TICKS_INSIDE) |
---|
1314 | { |
---|
1315 | zPoint1[0] = p1[0] - xMult * this->MajorTickSize; |
---|
1316 | zPoint2[1] = p1[1] - yMult * this->MajorTickSize; |
---|
1317 | zPoint2[0] = xPoint[0] = yPoint[0] = p1[0]; |
---|
1318 | zPoint1[1] = xPoint[1] = yPoint[1] = p1[1]; |
---|
1319 | } |
---|
1320 | else if (this->TickLocation == VTK_TICKS_OUTSIDE) |
---|
1321 | { |
---|
1322 | xPoint[0] = p1[0] + xMult * this->MajorTickSize; |
---|
1323 | yPoint[2] = p1[1] + yMult * this->MajorTickSize; |
---|
1324 | zPoint1[0] = zPoint2[0] = yPoint[0] = p1[0]; |
---|
1325 | zPoint1[1] = zPoint2[1] = xPoint[1] = p1[1]; |
---|
1326 | } |
---|
1327 | else // both sides |
---|
1328 | { |
---|
1329 | zPoint1[0] = p1[0] - xMult * this->MajorTickSize; |
---|
1330 | xPoint[0] = p1[0] + xMult * this->MajorTickSize; |
---|
1331 | zPoint2[1] = p1[1] - yMult * this->MajorTickSize; |
---|
1332 | yPoint[1] = p1[1] + yMult * this->MajorTickSize; |
---|
1333 | zPoint1[1] = xPoint[1] = p1[1]; |
---|
1334 | zPoint2[0] = yPoint[0] = p1[0]; |
---|
1335 | } |
---|
1336 | z = this->MajorStart; |
---|
1337 | numTicks = 0; |
---|
1338 | while (z <= p2[2] && numTicks < VTK_MAX_TICKS) |
---|
1339 | { |
---|
1340 | zPoint1[2] = zPoint2[2] = xPoint[2] = yPoint[2] = z; |
---|
1341 | // zx-portion |
---|
1342 | this->MajorTickPts->InsertNextPoint(zPoint1); |
---|
1343 | this->MajorTickPts->InsertNextPoint(xPoint); |
---|
1344 | // zy-portion |
---|
1345 | this->MajorTickPts->InsertNextPoint(zPoint2); |
---|
1346 | this->MajorTickPts->InsertNextPoint(yPoint); |
---|
1347 | z += this->DeltaMajor; |
---|
1348 | numTicks++; |
---|
1349 | } |
---|
1350 | return true; |
---|
1351 | } |
---|
1352 | |
---|
1353 | // ************************************************************************** |
---|
1354 | // Creates Poly data (lines) from tickmarks (minor/major), gridlines, and axis. |
---|
1355 | // |
---|
1356 | // Programmer: Kathleen Bonnell |
---|
1357 | // Creation: November 7, 2001 |
---|
1358 | // |
---|
1359 | // Modifications: |
---|
1360 | // Kathleen Bonnell, Thu Nov 15 13:20:44 PST 2001 |
---|
1361 | // Make ptIds of type vtkIdType to match VTK 4.0 API. |
---|
1362 | // |
---|
1363 | // Kathleen Bonnell, Thu Jul 18 13:24:03 PDT 2002 |
---|
1364 | // Allow gridlines to be drawn when enabled, even if ticks are disabled. |
---|
1365 | // |
---|
1366 | // Kathleen Bonnell, Fri Jul 25 15:10:24 PDT 2003 |
---|
1367 | // Removed arguments. |
---|
1368 | // |
---|
1369 | // ************************************************************************** |
---|
1370 | void vtkRpAxisActor::SetAxisPointsAndLines() |
---|
1371 | { |
---|
1372 | vtkPoints *pts = vtkPoints::New(); |
---|
1373 | vtkCellArray *lines = vtkCellArray::New(); |
---|
1374 | this->Axis->SetPoints(pts); |
---|
1375 | this->Axis->SetLines(lines); |
---|
1376 | pts->Delete(); |
---|
1377 | lines->Delete(); |
---|
1378 | int i, numPts, numLines; |
---|
1379 | vtkIdType ptIds[2]; |
---|
1380 | |
---|
1381 | if (this->TickVisibility) |
---|
1382 | { |
---|
1383 | if (this->MinorTicksVisible) |
---|
1384 | { |
---|
1385 | numPts = this->MinorTickPts->GetNumberOfPoints(); |
---|
1386 | for (i = 0; i < numPts; i++) |
---|
1387 | { |
---|
1388 | pts->InsertNextPoint(this->MinorTickPts->GetPoint(i)); |
---|
1389 | } |
---|
1390 | } |
---|
1391 | |
---|
1392 | if (this->DrawGridlines) |
---|
1393 | { |
---|
1394 | numPts = this->GridlinePts->GetNumberOfPoints(); |
---|
1395 | for (i = 0; i < numPts; i++) |
---|
1396 | { |
---|
1397 | pts->InsertNextPoint(this->GridlinePts->GetPoint(i)); |
---|
1398 | } |
---|
1399 | } |
---|
1400 | else // major tick points |
---|
1401 | { |
---|
1402 | numPts = this->MajorTickPts->GetNumberOfPoints(); |
---|
1403 | for (i = 0; i < numPts; i++) |
---|
1404 | { |
---|
1405 | pts->InsertNextPoint(this->MajorTickPts->GetPoint(i)); |
---|
1406 | } |
---|
1407 | } |
---|
1408 | } |
---|
1409 | else if (this->DrawGridlines) // grids are enabled but ticks are off |
---|
1410 | { |
---|
1411 | numPts = this->GridlinePts->GetNumberOfPoints(); |
---|
1412 | for (i = 0; i < numPts; i++) |
---|
1413 | { |
---|
1414 | pts->InsertNextPoint(this->GridlinePts->GetPoint(i)); |
---|
1415 | } |
---|
1416 | } |
---|
1417 | |
---|
1418 | // create lines |
---|
1419 | numLines = pts->GetNumberOfPoints() / 2; |
---|
1420 | for (i=0; i < numLines; i++) |
---|
1421 | { |
---|
1422 | ptIds[0] = 2*i; |
---|
1423 | ptIds[1] = 2*i + 1; |
---|
1424 | lines->InsertNextCell(2, ptIds); |
---|
1425 | } |
---|
1426 | |
---|
1427 | if (this->AxisVisibility) |
---|
1428 | { |
---|
1429 | //first axis point |
---|
1430 | ptIds[0] = pts->InsertNextPoint(this->Point1Coordinate->GetValue()); |
---|
1431 | //last axis point |
---|
1432 | ptIds[1] = pts->InsertNextPoint(this->Point2Coordinate->GetValue()); |
---|
1433 | lines->InsertNextCell(2, ptIds); |
---|
1434 | } |
---|
1435 | } |
---|
1436 | |
---|
1437 | // ********************************************************************* |
---|
1438 | // Returns true if any tick vis attribute has changed since last check. |
---|
1439 | // |
---|
1440 | // Programmer: Kathleen Bonnell |
---|
1441 | // Creation: November 7, 2001 |
---|
1442 | // ********************************************************************* |
---|
1443 | bool vtkRpAxisActor::TickVisibilityChanged() |
---|
1444 | { |
---|
1445 | bool retVal = (this->TickVisibility != this->LastTickVisibility) || |
---|
1446 | (this->DrawGridlines != this->LastDrawGridlines) || |
---|
1447 | (this->MinorTicksVisible != this->LastMinorTicksVisible); |
---|
1448 | |
---|
1449 | this->LastTickVisibility = this->TickVisibility; |
---|
1450 | this->LastDrawGridlines = this->DrawGridlines; |
---|
1451 | this->LastMinorTicksVisible = this->MinorTicksVisible; |
---|
1452 | |
---|
1453 | return retVal; |
---|
1454 | } |
---|
1455 | |
---|
1456 | // ********************************************************************* |
---|
1457 | // Set the bounds for this actor to use. Sets timestamp BoundsModified. |
---|
1458 | // |
---|
1459 | // Programmer: Kathleen Bonnell |
---|
1460 | // Creation: November 7, 2001 |
---|
1461 | // ********************************************************************* |
---|
1462 | void |
---|
1463 | vtkRpAxisActor::SetBounds(double b[6]) |
---|
1464 | { |
---|
1465 | if ((this->Bounds[0] != b[0]) || |
---|
1466 | (this->Bounds[1] != b[1]) || |
---|
1467 | (this->Bounds[2] != b[2]) || |
---|
1468 | (this->Bounds[3] != b[3]) || |
---|
1469 | (this->Bounds[4] != b[4]) || |
---|
1470 | (this->Bounds[5] != b[5]) ) |
---|
1471 | { |
---|
1472 | for (int i = 0; i < 6; i++) |
---|
1473 | { |
---|
1474 | this->Bounds[i] = b[i]; |
---|
1475 | } |
---|
1476 | this->BoundsTime.Modified(); |
---|
1477 | } |
---|
1478 | } |
---|
1479 | |
---|
1480 | // ********************************************************************* |
---|
1481 | // Retrieves the bounds of this actor. |
---|
1482 | // Set the bounds for this actor to use. Sets timestamp BoundsModified. |
---|
1483 | // |
---|
1484 | // Programmer: Will Schroeder |
---|
1485 | // Creation: December 8, 2010 |
---|
1486 | // ********************************************************************* |
---|
1487 | void vtkRpAxisActor:: |
---|
1488 | SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) |
---|
1489 | { |
---|
1490 | if ((this->Bounds[0] != xmin) || |
---|
1491 | (this->Bounds[1] != xmax) || |
---|
1492 | (this->Bounds[2] != ymin) || |
---|
1493 | (this->Bounds[3] != ymax) || |
---|
1494 | (this->Bounds[4] != zmin) || |
---|
1495 | (this->Bounds[5] != zmax) ) |
---|
1496 | { |
---|
1497 | this->Bounds[0] = xmin; |
---|
1498 | this->Bounds[1] = xmax; |
---|
1499 | this->Bounds[2] = ymin; |
---|
1500 | this->Bounds[3] = ymax; |
---|
1501 | this->Bounds[4] = zmin; |
---|
1502 | this->Bounds[5] = zmax; |
---|
1503 | |
---|
1504 | this->BoundsTime.Modified(); |
---|
1505 | } |
---|
1506 | } |
---|
1507 | |
---|
1508 | // ********************************************************************* |
---|
1509 | // Retrieves the bounds of this actor. |
---|
1510 | // |
---|
1511 | // Programmer: Kathleen Bonnell |
---|
1512 | // Creation: November 7, 2001 |
---|
1513 | // ********************************************************************* |
---|
1514 | double* vtkRpAxisActor::GetBounds() |
---|
1515 | { |
---|
1516 | return this->Bounds; |
---|
1517 | } |
---|
1518 | |
---|
1519 | // ********************************************************************* |
---|
1520 | // Retrieves the bounds of this actor. |
---|
1521 | // |
---|
1522 | // Programmer: Kathleen Bonnell |
---|
1523 | // Creation: November 7, 2001 |
---|
1524 | // ********************************************************************* |
---|
1525 | |
---|
1526 | void vtkRpAxisActor::GetBounds(double b[6]) |
---|
1527 | { |
---|
1528 | for (int i = 0; i < 6; i++) |
---|
1529 | { |
---|
1530 | b[i] = this->Bounds[i]; |
---|
1531 | } |
---|
1532 | } |
---|
1533 | |
---|
1534 | // ********************************************************************* |
---|
1535 | // Method: vtkRpAxisActor::ComputeMaxLabelLength |
---|
1536 | // |
---|
1537 | // Purpose: Determines the maximum length that a label will occupy |
---|
1538 | // if placed at point 'center' and with a scale of 1. |
---|
1539 | // |
---|
1540 | // Arguments: |
---|
1541 | // center The position to use for the label actor |
---|
1542 | // |
---|
1543 | // Returns: |
---|
1544 | // the maximum length of all the labels, 0 if there are no labels. |
---|
1545 | // |
---|
1546 | // Programmer: Kathleen Bonnell |
---|
1547 | // Creation: July 18, 2003 |
---|
1548 | // |
---|
1549 | // Modifications: |
---|
1550 | // Kathleen Bonnell, Tue Dec 16 11:06:21 PST 2003 |
---|
1551 | // Reset the actor's position and scale. |
---|
1552 | // |
---|
1553 | // Modifications: |
---|
1554 | // David Gobbi, Fri Apr 8 16:50:00 MST 2011 |
---|
1555 | // Use mapper bounds, not actor bounds, so centering is not necessary. |
---|
1556 | // |
---|
1557 | // ********************************************************************* |
---|
1558 | |
---|
1559 | double vtkRpAxisActor::ComputeMaxLabelLength(const double vtkNotUsed(center)[3]) |
---|
1560 | { |
---|
1561 | double length, maxLength = 0.; |
---|
1562 | double bounds[6]; |
---|
1563 | double xsize, ysize; |
---|
1564 | for (int i = 0; i < this->NumberOfLabelsBuilt; i++) |
---|
1565 | { |
---|
1566 | this->LabelActors[i]->SetCamera(this->Camera); |
---|
1567 | this->LabelActors[i]->SetProperty(this->GetProperty()); |
---|
1568 | this->LabelActors[i]->GetMapper()->GetBounds(bounds); |
---|
1569 | xsize = bounds[1] - bounds[0]; |
---|
1570 | ysize = bounds[3] - bounds[2]; |
---|
1571 | length = sqrt(xsize*xsize + ysize*ysize); |
---|
1572 | maxLength = (length > maxLength ? length : maxLength); |
---|
1573 | } |
---|
1574 | return maxLength; |
---|
1575 | } |
---|
1576 | |
---|
1577 | // ********************************************************************* |
---|
1578 | // Method: vtkRpAxisActor::ComputeTitleLength |
---|
1579 | // |
---|
1580 | // Purpose: Determines the length that the title will occupy |
---|
1581 | // if placed at point 'center' and with a scale of 1. |
---|
1582 | // |
---|
1583 | // Arguments: |
---|
1584 | // center The position to use for the title actor |
---|
1585 | // |
---|
1586 | // Returns: |
---|
1587 | // the length of all the title, |
---|
1588 | // |
---|
1589 | // Programmer: Kathleen Bonnell |
---|
1590 | // Creation: July 25, 2003 |
---|
1591 | // |
---|
1592 | // Modifications: |
---|
1593 | // Kathleen Bonnell, Tue Dec 16 11:06:21 PST 2003 |
---|
1594 | // Reset the actor's position and scale. |
---|
1595 | // |
---|
1596 | // Modifications: |
---|
1597 | // David Gobbi, Fri Apr 8 16:50:00 MST 2011 |
---|
1598 | // Use mapper bounds, not actor bounds, so centering is not necessary. |
---|
1599 | // |
---|
1600 | // ********************************************************************* |
---|
1601 | |
---|
1602 | double vtkRpAxisActor::ComputeTitleLength(const double vtkNotUsed(center)[3]) |
---|
1603 | { |
---|
1604 | double bounds[6]; |
---|
1605 | double xsize, ysize; |
---|
1606 | double length; |
---|
1607 | |
---|
1608 | this->TitleVector->SetText(this->Title); |
---|
1609 | this->TitleActor->SetCamera(this->Camera); |
---|
1610 | this->TitleActor->SetProperty(this->GetProperty()); |
---|
1611 | this->TitleActor->GetMapper()->GetBounds(bounds); |
---|
1612 | xsize = bounds[1] - bounds[0]; |
---|
1613 | ysize = bounds[3] - bounds[2]; |
---|
1614 | length = sqrt(xsize*xsize + ysize*ysize); |
---|
1615 | return length; |
---|
1616 | } |
---|
1617 | |
---|
1618 | // ********************************************************************* |
---|
1619 | // Method: vtkRpAxisActor::SetLabelScale |
---|
1620 | // |
---|
1621 | // Purpose: Sets the scaling factor for label actors. |
---|
1622 | // |
---|
1623 | // Arguments: |
---|
1624 | // s The scale factor to use. |
---|
1625 | // |
---|
1626 | // Programmer: Kathleen Bonnell |
---|
1627 | // Creation: July 18, 2003 |
---|
1628 | // |
---|
1629 | // ********************************************************************* |
---|
1630 | |
---|
1631 | void vtkRpAxisActor::SetLabelScale(const double s) |
---|
1632 | { |
---|
1633 | for (int i=0; i < this->NumberOfLabelsBuilt; i++) |
---|
1634 | { |
---|
1635 | this->LabelActors[i]->SetScale(s); |
---|
1636 | } |
---|
1637 | } |
---|
1638 | |
---|
1639 | // ********************************************************************* |
---|
1640 | // Method: vtkRpAxisActor::SetTitleScale |
---|
1641 | // |
---|
1642 | // Purpose: Sets the scaling factor for the title actor. |
---|
1643 | // |
---|
1644 | // Arguments: |
---|
1645 | // s The scale factor to use. |
---|
1646 | // |
---|
1647 | // Programmer: Kathleen Bonnell |
---|
1648 | // Creation: July 18, 2003 |
---|
1649 | // |
---|
1650 | // ********************************************************************* |
---|
1651 | |
---|
1652 | void vtkRpAxisActor::SetTitleScale(const double s) |
---|
1653 | { |
---|
1654 | this->TitleActor->SetScale(s); |
---|
1655 | } |
---|
1656 | |
---|
1657 | // ********************************************************************* |
---|
1658 | // Method: vtkRpAxisActor::SetTitle |
---|
1659 | // |
---|
1660 | // Purpose: Sets the text for the title. |
---|
1661 | // |
---|
1662 | // Notes: Not using vtkSetStringMacro so that the modification time of |
---|
1663 | // the text can be kept (so the title will be updated as |
---|
1664 | // appropriate when the text changes.) |
---|
1665 | // |
---|
1666 | // Arguments: |
---|
1667 | // t The text to use. |
---|
1668 | // |
---|
1669 | // Programmer: Kathleen Bonnell |
---|
1670 | // Creation: August 31, 2004 |
---|
1671 | // |
---|
1672 | // ********************************************************************* |
---|
1673 | |
---|
1674 | void vtkRpAxisActor::SetTitle(const char *t) |
---|
1675 | { |
---|
1676 | if (this->Title == NULL && t == NULL) |
---|
1677 | { |
---|
1678 | return; |
---|
1679 | } |
---|
1680 | if (this->Title && (!strcmp(this->Title, t))) |
---|
1681 | { |
---|
1682 | return; |
---|
1683 | } |
---|
1684 | if (this->Title) |
---|
1685 | { |
---|
1686 | delete [] this->Title; |
---|
1687 | } |
---|
1688 | if (t) |
---|
1689 | { |
---|
1690 | this->Title = new char[strlen(t)+1]; |
---|
1691 | strcpy(this->Title, t); |
---|
1692 | } |
---|
1693 | else |
---|
1694 | { |
---|
1695 | this->Title = NULL; |
---|
1696 | } |
---|
1697 | this->TitleTextTime.Modified(); |
---|
1698 | this->Modified(); |
---|
1699 | } |
---|
1700 | |
---|
1701 | //--------------------------------------------------------------------------- |
---|
1702 | // endpoint-related methods |
---|
1703 | vtkCoordinate* vtkRpAxisActor::GetPoint1Coordinate() |
---|
1704 | { |
---|
1705 | vtkDebugMacro(<< this->GetClassName() << " (" << this |
---|
1706 | << "): returning Point1 Coordinate address " |
---|
1707 | << this->Point1Coordinate ); |
---|
1708 | return this->Point1Coordinate; |
---|
1709 | } |
---|
1710 | |
---|
1711 | vtkCoordinate* vtkRpAxisActor::GetPoint2Coordinate() |
---|
1712 | { |
---|
1713 | vtkDebugMacro(<< this->GetClassName() << " (" << this |
---|
1714 | << "): returning Point2 Coordinate address " |
---|
1715 | << this->Point2Coordinate ); |
---|
1716 | return this->Point2Coordinate; |
---|
1717 | } |
---|
1718 | |
---|
1719 | void vtkRpAxisActor::SetPoint1(double x, double y, double z) |
---|
1720 | { |
---|
1721 | this->Point1Coordinate->SetValue(x, y, z); |
---|
1722 | } |
---|
1723 | |
---|
1724 | void vtkRpAxisActor::SetPoint2(double x, double y, double z) |
---|
1725 | { |
---|
1726 | this->Point2Coordinate->SetValue(x, y, z); |
---|
1727 | } |
---|
1728 | |
---|
1729 | double* vtkRpAxisActor::GetPoint1() |
---|
1730 | { |
---|
1731 | return this->Point1Coordinate->GetValue(); |
---|
1732 | } |
---|
1733 | |
---|
1734 | double* vtkRpAxisActor::GetPoint2() |
---|
1735 | { |
---|
1736 | return this->Point2Coordinate->GetValue(); |
---|
1737 | } |
---|