VTK-m  2.1
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 
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 
36 {
37 public:
41 
43  Canvas(vtkm::Id width = 1024, vtkm::Id height = 1024);
44  virtual ~Canvas();
45 
47  virtual vtkm::rendering::Canvas* NewCopy() const;
48 
50  virtual void Clear();
51 
59  virtual void BlendBackground();
60 
62  VTKM_CONT
63  vtkm::Id GetWidth() const;
64 
66  VTKM_CONT
67  vtkm::Id GetHeight() const;
68 
70  VTKM_CONT
71  const ColorBufferType& GetColorBuffer() const;
72 
74  VTKM_CONT
75  ColorBufferType& GetColorBuffer();
76 
78  VTKM_CONT
79  const DepthBufferType& GetDepthBuffer() const;
80 
82  VTKM_CONT
83  DepthBufferType& GetDepthBuffer();
84 
94  VTKM_CONT vtkm::cont::DataSet GetDataSet(const std::string& colorFieldName = "color",
95  const std::string& depthFieldName = "depth") const;
97  VTKM_CONT vtkm::cont::DataSet GetDataSet(const char* colorFieldName,
98  const char* depthFieldName = "depth") const;
99 
101  VTKM_CONT
102  void ResizeBuffers(vtkm::Id width, vtkm::Id height);
103 
105  VTKM_CONT
106  const vtkm::rendering::Color& GetBackgroundColor() const;
107 
109  VTKM_CONT
110  void SetBackgroundColor(const vtkm::rendering::Color& color);
111 
113  VTKM_CONT
114  const vtkm::rendering::Color& GetForegroundColor() const;
115 
117  VTKM_CONT
118  void SetForegroundColor(const vtkm::rendering::Color& color);
119 
120  VTKM_CONT
121  vtkm::Id2 GetScreenPoint(vtkm::Float32 x,
122  vtkm::Float32 y,
123  vtkm::Float32 z,
124  const vtkm::Matrix<vtkm::Float32, 4, 4>& transfor) const;
125 
126  // If a subclass uses a system that renderers to different buffers, then
127  // these should be overridden to copy the data to the buffers.
128  virtual void RefreshColorBuffer() const {}
129  virtual void RefreshDepthBuffer() const {}
130 
131  virtual void SetViewToWorldSpace(const vtkm::rendering::Camera& camera, bool clip);
132  virtual void SetViewToScreenSpace(const vtkm::rendering::Camera& camera, bool clip);
133  virtual void SetViewportClipping(const vtkm::rendering::Camera&, bool) {}
134 
139  virtual void SaveAs(const std::string& fileName) const;
140 
148  virtual vtkm::rendering::WorldAnnotator* CreateWorldAnnotator() const;
149 
150  VTKM_CONT
151  virtual void AddColorSwatch(const vtkm::Vec2f_64& point0,
152  const vtkm::Vec2f_64& point1,
153  const vtkm::Vec2f_64& point2,
154  const vtkm::Vec2f_64& point3,
155  const vtkm::rendering::Color& color) const;
156 
157  VTKM_CONT
158  void AddColorSwatch(const vtkm::Float64 x0,
159  const vtkm::Float64 y0,
160  const vtkm::Float64 x1,
161  const vtkm::Float64 y1,
162  const vtkm::Float64 x2,
163  const vtkm::Float64 y2,
164  const vtkm::Float64 x3,
165  const vtkm::Float64 y3,
166  const vtkm::rendering::Color& color) const;
167 
168  VTKM_CONT
169  virtual void AddLine(const vtkm::Vec2f_64& point0,
170  const vtkm::Vec2f_64& point1,
171  vtkm::Float32 linewidth,
172  const vtkm::rendering::Color& color) const;
173 
174  VTKM_CONT
175  void AddLine(vtkm::Float64 x0,
176  vtkm::Float64 y0,
177  vtkm::Float64 x1,
178  vtkm::Float64 y1,
179  vtkm::Float32 linewidth,
180  const vtkm::rendering::Color& color) const;
181 
182  VTKM_CONT
183  virtual void AddColorBar(const vtkm::Bounds& bounds,
184  const vtkm::cont::ColorTable& colorTable,
185  bool horizontal) const;
186 
187  VTKM_CONT
188  void AddColorBar(vtkm::Float32 x,
189  vtkm::Float32 y,
190  vtkm::Float32 width,
191  vtkm::Float32 height,
192  const vtkm::cont::ColorTable& colorTable,
193  bool horizontal) const;
194 
195  virtual void AddText(const vtkm::Vec2f_32& position,
196  vtkm::Float32 scale,
197  vtkm::Float32 angle,
198  vtkm::Float32 windowAspect,
199  const vtkm::Vec2f_32& anchor,
200  const vtkm::rendering::Color& color,
201  const std::string& text) const;
202 
203  VTKM_CONT
204  void AddText(vtkm::Float32 x,
205  vtkm::Float32 y,
206  vtkm::Float32 scale,
207  vtkm::Float32 angle,
208  vtkm::Float32 windowAspect,
209  vtkm::Float32 anchorX,
210  vtkm::Float32 anchorY,
211  const vtkm::rendering::Color& color,
212  const std::string& text) const;
213 
214  VTKM_CONT
215  void AddText(const vtkm::Matrix<vtkm::Float32, 4, 4>& transform,
216  vtkm::Float32 scale,
217  const vtkm::Vec2f_32& anchor,
218  const vtkm::rendering::Color& color,
219  const std::string& text,
220  const vtkm::Float32& depth = 0) const;
221 
222  VTKM_CONT
223  void BeginTextRenderingBatch() const;
224 
225  VTKM_CONT
226  void EndTextRenderingBatch() const;
227 
228  friend class AxisAnnotation2D;
229  friend class ColorBarAnnotation;
230  friend class ColorLegendAnnotation;
231  friend class TextAnnotationScreen;
232  friend class TextRenderer;
233  friend class WorldAnnotator;
234 
235 private:
236  bool LoadFont() const;
237 
238  bool EnsureFontLoaded() const;
239 
240  const vtkm::Matrix<vtkm::Float32, 4, 4>& GetModelView() const;
241 
242  const vtkm::Matrix<vtkm::Float32, 4, 4>& GetProjection() const;
243 
244  struct CanvasInternals;
245  std::shared_ptr<CanvasInternals> Internals;
246 };
247 }
248 } //namespace vtkm::rendering
249 
250 #endif //vtk_m_rendering_Canvas_h
vtkm::rendering::ColorLegendAnnotation
Definition: ColorLegendAnnotation.h:26
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm::rendering::Canvas::RefreshColorBuffer
virtual void RefreshColorBuffer() const
Definition: Canvas.h:128
vtkm::rendering::TextRenderer
Definition: TextRenderer.h:27
vtkm::rendering::Color
Representation of a color.
Definition: Color.h:29
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
VTKM_RENDERING_EXPORT
#define VTKM_RENDERING_EXPORT
Definition: vtkm_rendering_export.h:44
Types.h
Matrix.h
vtkm::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
ColorTable.h
vtkm::rendering::Canvas::RefreshDepthBuffer
virtual void RefreshDepthBuffer() const
Definition: Canvas.h:129
vtkm_rendering_export.h
vtkm::rendering::Canvas
Represents the image space that is the target of rendering.
Definition: Canvas.h:35
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
Texture2D.h
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
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
Base type to use for 32-bit floating-point numbers.
Definition: Types.h:157
Camera.h
vtkm::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:161
vtkm::rendering::TextAnnotationScreen
Definition: TextAnnotationScreen.h:20
Color.h
vtkm::rendering::Camera
Specifies the viewport for a rendering.
Definition: Camera.h:37
vtkm::rendering::Canvas::SetViewportClipping
virtual void SetViewportClipping(const vtkm::rendering::Camera &, bool)
Definition: Canvas.h:133
vtkm::rendering::Canvas::Internals
std::shared_ptr< CanvasInternals > Internals
Definition: Canvas.h:244
vtkm::rendering::Texture2D< 1 >
vtkm::rendering::ColorBarAnnotation
Definition: ColorBarAnnotation.h:26
DataSet.h