VTK-m  2.0
Canvas.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_rendering_Canvas_h
12 #define vtk_m_rendering_Canvas_h
13 
14 #include <vtkm/rendering/vtkm_rendering_export.h>
15 
16 #include <vtkm/Matrix.h>
17 #include <vtkm/Types.h>
18 #include <vtkm/cont/ColorTable.h>
19 #include <vtkm/cont/DataSet.h>
21 #include <vtkm/rendering/Camera.h>
22 #include <vtkm/rendering/Color.h>
24 
25 #define VTKM_DEFAULT_CANVAS_DEPTH 1.001f
26 
27 namespace vtkm
28 {
29 namespace rendering
30 {
31 
32 class WorldAnnotator;
33 
34 class VTKM_RENDERING_EXPORT Canvas
35 {
36 public:
40 
41  Canvas(vtkm::Id width = 1024, vtkm::Id height = 1024);
42  virtual ~Canvas();
43 
44  virtual vtkm::rendering::Canvas* NewCopy() const;
45 
46  virtual void Clear();
47 
48  virtual void BlendBackground();
49 
50  VTKM_CONT
51  vtkm::Id GetWidth() const;
52 
53  VTKM_CONT
54  vtkm::Id GetHeight() const;
55 
56  VTKM_CONT
57  const ColorBufferType& GetColorBuffer() const;
58 
59  VTKM_CONT
60  ColorBufferType& GetColorBuffer();
61 
62  VTKM_CONT
63  const DepthBufferType& GetDepthBuffer() const;
64 
65  VTKM_CONT
66  DepthBufferType& GetDepthBuffer();
67 
78  VTKM_CONT vtkm::cont::DataSet GetDataSet(const std::string& colorFieldName = "color",
79  const std::string& depthFieldName = "depth") const;
80  VTKM_CONT vtkm::cont::DataSet GetDataSet(const char* colorFieldName,
81  const char* depthFieldName = "depth") const;
83 
84  VTKM_CONT
85  void ResizeBuffers(vtkm::Id width, vtkm::Id height);
86 
87  VTKM_CONT
88  const vtkm::rendering::Color& GetBackgroundColor() const;
89 
90  VTKM_CONT
91  void SetBackgroundColor(const vtkm::rendering::Color& color);
92 
93  VTKM_CONT
94  const vtkm::rendering::Color& GetForegroundColor() const;
95 
96  VTKM_CONT
97  void SetForegroundColor(const vtkm::rendering::Color& color);
98 
99  VTKM_CONT
100  vtkm::Id2 GetScreenPoint(vtkm::Float32 x,
101  vtkm::Float32 y,
102  vtkm::Float32 z,
103  const vtkm::Matrix<vtkm::Float32, 4, 4>& transfor) const;
104 
105  // If a subclass uses a system that renderers to different buffers, then
106  // these should be overridden to copy the data to the buffers.
107  virtual void RefreshColorBuffer() const {}
108  virtual void RefreshDepthBuffer() const {}
109 
110  virtual void SetViewToWorldSpace(const vtkm::rendering::Camera& camera, bool clip);
111  virtual void SetViewToScreenSpace(const vtkm::rendering::Camera& camera, bool clip);
112  virtual void SetViewportClipping(const vtkm::rendering::Camera&, bool) {}
113 
114  virtual void SaveAs(const std::string& fileName) const;
115 
123  virtual vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const;
124 
125  VTKM_CONT
126  virtual void AddColorSwatch(const vtkm::Vec2f_64& point0,
127  const vtkm::Vec2f_64& point1,
128  const vtkm::Vec2f_64& point2,
129  const vtkm::Vec2f_64& point3,
130  const vtkm::rendering::Color& color) const;
131 
132  VTKM_CONT
133  void AddColorSwatch(const vtkm::Float64 x0,
134  const vtkm::Float64 y0,
135  const vtkm::Float64 x1,
136  const vtkm::Float64 y1,
137  const vtkm::Float64 x2,
138  const vtkm::Float64 y2,
139  const vtkm::Float64 x3,
140  const vtkm::Float64 y3,
141  const vtkm::rendering::Color& color) const;
142 
143  VTKM_CONT
144  virtual void AddLine(const vtkm::Vec2f_64& point0,
145  const vtkm::Vec2f_64& point1,
146  vtkm::Float32 linewidth,
147  const vtkm::rendering::Color& color) const;
148 
149  VTKM_CONT
150  void AddLine(vtkm::Float64 x0,
151  vtkm::Float64 y0,
152  vtkm::Float64 x1,
153  vtkm::Float64 y1,
154  vtkm::Float32 linewidth,
155  const vtkm::rendering::Color& color) const;
156 
157  VTKM_CONT
158  virtual void AddColorBar(const vtkm::Bounds& bounds,
159  const vtkm::cont::ColorTable& colorTable,
160  bool horizontal) const;
161 
162  VTKM_CONT
163  void AddColorBar(vtkm::Float32 x,
164  vtkm::Float32 y,
165  vtkm::Float32 width,
166  vtkm::Float32 height,
167  const vtkm::cont::ColorTable& colorTable,
168  bool horizontal) const;
169 
170  virtual void AddText(const vtkm::Vec2f_32& position,
171  vtkm::Float32 scale,
172  vtkm::Float32 angle,
173  vtkm::Float32 windowAspect,
174  const vtkm::Vec2f_32& anchor,
175  const vtkm::rendering::Color& color,
176  const std::string& text) const;
177 
178  VTKM_CONT
179  void AddText(vtkm::Float32 x,
180  vtkm::Float32 y,
181  vtkm::Float32 scale,
182  vtkm::Float32 angle,
183  vtkm::Float32 windowAspect,
184  vtkm::Float32 anchorX,
185  vtkm::Float32 anchorY,
186  const vtkm::rendering::Color& color,
187  const std::string& text) const;
188 
189  VTKM_CONT
190  void AddText(const vtkm::Matrix<vtkm::Float32, 4, 4>& transform,
191  vtkm::Float32 scale,
192  const vtkm::Vec2f_32& anchor,
193  const vtkm::rendering::Color& color,
194  const std::string& text,
195  const vtkm::Float32& depth = 0) const;
196 
197  VTKM_CONT
198  void BeginTextRenderingBatch() const;
199 
200  VTKM_CONT
201  void EndTextRenderingBatch() const;
202 
203  friend class AxisAnnotation2D;
204  friend class ColorBarAnnotation;
205  friend class ColorLegendAnnotation;
206  friend class TextAnnotationScreen;
207  friend class TextRenderer;
208  friend class WorldAnnotator;
209 
210 private:
211  bool LoadFont() const;
212 
213  bool EnsureFontLoaded() const;
214 
215  const vtkm::Matrix<vtkm::Float32, 4, 4>& GetModelView() const;
216 
217  const vtkm::Matrix<vtkm::Float32, 4, 4>& GetProjection() const;
218 
219  struct CanvasInternals;
220  std::shared_ptr<CanvasInternals> Internals;
221 };
222 }
223 } //namespace vtkm::rendering
224 
225 #endif //vtk_m_rendering_Canvas_h
vtkm::rendering::ColorLegendAnnotation
Definition: ColorLegendAnnotation.h:26
vtkm::cont::ArrayHandle< vtkm::Vec4f_32 >
vtkm::rendering::Canvas::RefreshColorBuffer
virtual void RefreshColorBuffer() const
Definition: Canvas.h:107
vtkm::rendering::TextRenderer
Definition: TextRenderer.h:27
vtkm::rendering::Color
It's a color!
Definition: Color.h:28
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::ColorTable
Color Table for coloring arbitrary fields.
Definition: cont/ColorTable.h:89
Types.h
Matrix.h
vtkm::cont::DataSet
Definition: DataSet.h:34
ColorTable.h
vtkm::rendering::Canvas::RefreshDepthBuffer
virtual void RefreshDepthBuffer() const
Definition: Canvas.h:108
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::rendering::Canvas
Definition: Canvas.h:34
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
Texture2D.h
vtkm::rendering::AxisAnnotation2D
Definition: AxisAnnotation2D.h:29
vtkm::Bounds
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
vtkm::rendering::WorldAnnotator
Definition: WorldAnnotator.h:27
vtkm::Vec< vtkm::Id, 2 >
vtkm::Matrix< vtkm::Float32, 4, 4 >
BitmapFont.h
vtkm::Float32
float Float32
Definition: Types.h:154
Camera.h
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::rendering::TextAnnotationScreen
Definition: TextAnnotationScreen.h:20
Color.h
vtkm::rendering::Camera
Definition: Camera.h:28
vtkm::rendering::Canvas::SetViewportClipping
virtual void SetViewportClipping(const vtkm::rendering::Camera &, bool)
Definition: Canvas.h:112
vtkm::rendering::Canvas::Internals
std::shared_ptr< CanvasInternals > Internals
Definition: Canvas.h:219
vtkm::rendering::Texture2D< 1 >
vtkm::rendering::ColorBarAnnotation
Definition: ColorBarAnnotation.h:26
DataSet.h