1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkCoordinate.h,v $
6 Date: $Date: 2002/06/07 22:11:04 $
7 Version: $Revision: 1.29 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkCoordinate - perform coordinate transformation, and represent position, in a variety of vtk coordinate systems
19 // .SECTION Description
20 // vtkCoordinate represents position in a variety of coordinate systems, and
21 // converts position to other coordinate systems. It also supports relative
22 // positioning, so you can create a cascade of vtkCoordinate objects (no loops
23 // please!) that refer to each other. The typical usage of this object is
24 // to set the coordinate system in which to represent a position (e.g.,
25 // SetCoordinateSystemToNormalizedDisplay()), set the value of the coordinate
26 // (e.g., SetValue()), and then invoke the appropriate method to convert to
27 // another coordinate system (e.g., GetComputedWorldValue()).
29 // The coordinate systems in vtk are as follows:
31 // DISPLAY - x-y pixel values in window
32 // NORMALIZED DISPLAY - x-y (0,1) normalized values
33 // VIEWPORT - x-y pixel values in viewport
34 // NORMALIZED VIEWPORT - x-y (0,1) normalized value in viewport
35 // VIEW - x-y-z (-1,1) values in camera coordinates. (z is depth)
36 // WORLD - x-y-z global coordinate values
37 // USERDEFINED - x-y-z in User defined space
40 // If you cascade vtkCoordinate objects, you refer to another vtkCoordinate
41 // object which in turn can refer to others, and so on. This allows you to
42 // create composite groups of things like vtkActor2D that are positioned
43 // relative to one another. Note that in cascaded sequences, each
44 // vtkCoordinate object may be specified in different coordinate systems!
47 // vtkProp2D vtkActor2D vtkScalarBarActor
49 #ifndef __vtkCoordinate_h
50 #define __vtkCoordinate_h
52 #include "vtkObject.h"
56 #define VTK_NORMALIZED_DISPLAY 1
57 #define VTK_VIEWPORT 2
58 #define VTK_NORMALIZED_VIEWPORT 3
61 #define VTK_USERDEFINED 6
63 class VTK_COMMON_EXPORT vtkCoordinate : public vtkObject
66 vtkTypeRevisionMacro(vtkCoordinate,vtkObject);
67 void PrintSelf(ostream& os, vtkIndent indent);
70 // Creates an instance of this class with the following defaults:
71 // value of (0,0,0) in world coordinates.
72 static vtkCoordinate* New();
75 // Set/get the coordinate system which this coordinate
76 // is defined in. The options are Display, Normalized Display,
77 // Viewport, Normalized Viewport, View, and World.
78 vtkSetMacro(CoordinateSystem, int);
79 vtkGetMacro(CoordinateSystem, int);
80 void SetCoordinateSystemToDisplay() {this->SetCoordinateSystem(VTK_DISPLAY);}
81 void SetCoordinateSystemToNormalizedDisplay()
82 {this->SetCoordinateSystem(VTK_NORMALIZED_DISPLAY);}
83 void SetCoordinateSystemToViewport()
84 {this->SetCoordinateSystem(VTK_VIEWPORT);}
85 void SetCoordinateSystemToNormalizedViewport()
86 {this->SetCoordinateSystem(VTK_NORMALIZED_VIEWPORT);}
87 void SetCoordinateSystemToView() {this->SetCoordinateSystem(VTK_VIEW);}
88 void SetCoordinateSystemToWorld() {this->SetCoordinateSystem(VTK_WORLD);}
90 const char *GetCoordinateSystemAsString ();
93 // Set/get the value of this coordinate. This can be thought of as
94 // the position of this coordinate in its coordinate system.
95 vtkSetVector3Macro(Value,float);
96 vtkGetVector3Macro(Value,float);
97 void SetValue(float a, float b) { this->SetValue(a,b,0.0);}
100 // If this coordinate is relative to another coordinate,
101 // then specify that coordinate as the ReferenceCoordinate.
102 // If this is NULL the coordinate is assumed to be absolute.
103 virtual void SetReferenceCoordinate(vtkCoordinate*);
104 vtkGetObjectMacro(ReferenceCoordinate,vtkCoordinate);
107 // If you want this coordinate to be relative to a specific
108 // vtkViewport (vtkRenderer, vtkImager) then you can specify
110 void SetViewport(vtkViewport *viewport);
111 vtkGetObjectMacro(Viewport,vtkViewport);
114 // Return the computed value in a specified coordinate system.
115 float *GetComputedWorldValue(vtkViewport *);
116 int *GetComputedViewportValue(vtkViewport *);
117 int *GetComputedDisplayValue(vtkViewport *);
118 int *GetComputedLocalDisplayValue(vtkViewport *);
120 float *GetComputedFloatViewportValue(vtkViewport *);
121 float *GetComputedFloatDisplayValue(vtkViewport *);
124 // GetComputedValue() will return either World, Viewport or
125 // Display based on what has been set as the coordinate system.
126 // This is good for objects like vtkLineSource, where the
127 // user might want to use them as World or Viewport coordinates
128 float *GetComputedValue(vtkViewport *);
131 // GetComputedUserDefinedValue() is to be used only when
132 // the coordinate system is VTK_USERDEFINED. The user
133 // must subclass vtkCoordinate and override this function,
134 // when set as the TransformCoordinate in 2D-Mappers, the user
135 // can customize display of 2D polygons
136 virtual float *GetComputedUserDefinedValue(vtkViewport *)
137 { return this->Value; }
144 int CoordinateSystem;
145 vtkCoordinate *ReferenceCoordinate;
146 vtkViewport *Viewport;
147 float ComputedWorldValue[3];
148 int ComputedDisplayValue[2];
149 int ComputedViewportValue[2];
152 float ComputedFloatDisplayValue[2];
153 float ComputedFloatViewportValue[2];
154 float ComputedUserDefinedValue[3];
157 vtkCoordinate(const vtkCoordinate&); // Not implemented.
158 void operator=(const vtkCoordinate&); // Not implemented.