Viskores  1.0
Canvas.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 
19 #ifndef viskores_rendering_Canvas_h
20 #define viskores_rendering_Canvas_h
21 
23 
24 #include <viskores/Matrix.h>
25 #include <viskores/Types.h>
27 #include <viskores/cont/DataSet.h>
32 
33 #define VISKORES_DEFAULT_CANVAS_DEPTH 1.001f
34 
35 namespace viskores
36 {
37 namespace rendering
38 {
39 
40 class WorldAnnotator;
41 
43 class VISKORES_RENDERING_EXPORT Canvas
44 {
45 public:
49 
51  Canvas(viskores::Id width = 1024, viskores::Id height = 1024);
52  virtual ~Canvas();
53 
55  virtual viskores::rendering::Canvas* NewCopy() const;
56 
58  virtual void Clear();
59 
67  virtual void BlendBackground();
68 
71  viskores::Id GetWidth() const;
72 
75  viskores::Id GetHeight() const;
76 
79  const ColorBufferType& GetColorBuffer() const;
80 
83  ColorBufferType& GetColorBuffer();
84 
87  const DepthBufferType& GetDepthBuffer() const;
88 
91  DepthBufferType& GetDepthBuffer();
92 
103  const std::string& colorFieldName = "color",
104  const std::string& depthFieldName = "depth") const;
106  VISKORES_CONT viskores::cont::DataSet GetDataSet(const char* colorFieldName,
107  const char* depthFieldName = "depth") const;
108 
111  void ResizeBuffers(viskores::Id width, viskores::Id height);
112 
115  const viskores::rendering::Color& GetBackgroundColor() const;
116 
119  void SetBackgroundColor(const viskores::rendering::Color& color);
120 
123  const viskores::rendering::Color& GetForegroundColor() const;
124 
127  void SetForegroundColor(const viskores::rendering::Color& color);
128 
130  viskores::Id2 GetScreenPoint(viskores::Float32 x,
133  const viskores::Matrix<viskores::Float32, 4, 4>& transfor) const;
134 
135  // If a subclass uses a system that renderers to different buffers, then
136  // these should be overridden to copy the data to the buffers.
137  virtual void RefreshColorBuffer() const {}
138  virtual void RefreshDepthBuffer() const {}
139 
140  virtual void SetViewToWorldSpace(const viskores::rendering::Camera& camera, bool clip);
141  virtual void SetViewToScreenSpace(const viskores::rendering::Camera& camera, bool clip);
142  virtual void SetViewportClipping(const viskores::rendering::Camera&, bool) {}
143 
148  virtual void SaveAs(const std::string& fileName) const;
149 
157  virtual viskores::rendering::WorldAnnotator* CreateWorldAnnotator() const;
158 
160  virtual void AddColorSwatch(const viskores::Vec2f_64& point0,
161  const viskores::Vec2f_64& point1,
162  const viskores::Vec2f_64& point2,
163  const viskores::Vec2f_64& point3,
164  const viskores::rendering::Color& color) const;
165 
167  void AddColorSwatch(const viskores::Float64 x0,
168  const viskores::Float64 y0,
169  const viskores::Float64 x1,
170  const viskores::Float64 y1,
171  const viskores::Float64 x2,
172  const viskores::Float64 y2,
173  const viskores::Float64 x3,
174  const viskores::Float64 y3,
175  const viskores::rendering::Color& color) const;
176 
178  virtual void AddLine(const viskores::Vec2f_64& point0,
179  const viskores::Vec2f_64& point1,
180  viskores::Float32 linewidth,
181  const viskores::rendering::Color& color) const;
182 
184  void AddLine(viskores::Float64 x0,
188  viskores::Float32 linewidth,
189  const viskores::rendering::Color& color) const;
190 
192  virtual void AddColorBar(const viskores::Bounds& bounds,
193  const viskores::cont::ColorTable& colorTable,
194  bool horizontal) const;
195 
197  void AddColorBar(viskores::Float32 x,
199  viskores::Float32 width,
200  viskores::Float32 height,
201  const viskores::cont::ColorTable& colorTable,
202  bool horizontal) const;
203 
204  virtual void AddText(const viskores::Vec2f_32& position,
205  viskores::Float32 scale,
206  viskores::Float32 angle,
207  viskores::Float32 windowAspect,
208  const viskores::Vec2f_32& anchor,
209  const viskores::rendering::Color& color,
210  const std::string& text) const;
211 
213  void AddText(viskores::Float32 x,
215  viskores::Float32 scale,
216  viskores::Float32 angle,
217  viskores::Float32 windowAspect,
218  viskores::Float32 anchorX,
219  viskores::Float32 anchorY,
220  const viskores::rendering::Color& color,
221  const std::string& text) const;
222 
224  void AddText(const viskores::Matrix<viskores::Float32, 4, 4>& transform,
225  viskores::Float32 scale,
226  const viskores::Vec2f_32& anchor,
227  const viskores::rendering::Color& color,
228  const std::string& text,
229  const viskores::Float32& depth = 0) const;
230 
232  void BeginTextRenderingBatch() const;
233 
235  void EndTextRenderingBatch() const;
236 
237  friend class AxisAnnotation2D;
238  friend class ColorBarAnnotation;
239  friend class ColorLegendAnnotation;
240  friend class TextAnnotationScreen;
241  friend class TextRenderer;
242  friend class WorldAnnotator;
243 
244 private:
245  bool LoadFont() const;
246 
247  bool EnsureFontLoaded() const;
248 
249  const viskores::Matrix<viskores::Float32, 4, 4>& GetModelView() const;
250 
251  const viskores::Matrix<viskores::Float32, 4, 4>& GetProjection() const;
252 
253  struct CanvasInternals;
254  std::shared_ptr<CanvasInternals> Internals;
255 };
256 }
257 } //namespace viskores::rendering
258 
259 #endif //viskores_rendering_Canvas_h
viskores::rendering::TextRenderer
Definition: TextRenderer.h:35
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
viskores::rendering::Canvas::SetViewportClipping
virtual void SetViewportClipping(const viskores::rendering::Camera &, bool)
Definition: Canvas.h:142
Types.h
viskores::Bounds
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:37
viskores::rendering::Canvas::RefreshDepthBuffer
virtual void RefreshDepthBuffer() const
Definition: Canvas.h:138
viskores::rendering::ColorLegendAnnotation
Definition: ColorLegendAnnotation.h:34
Matrix.h
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::rendering::Canvas::Internals
std::shared_ptr< CanvasInternals > Internals
Definition: Canvas.h:253
ColorTable.h
viskores::rendering::TextAnnotationScreen
Definition: TextAnnotationScreen.h:28
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::ColorTable
Color Table for coloring arbitrary fields.
Definition: cont/ColorTable.h:97
viskores::Float32
float Float32
Base type to use for 32-bit floating-point numbers.
Definition: Types.h:165
viskores::Matrix< viskores::Float32, 4, 4 >
Texture2D.h
viskores::rendering::Texture2D< 1 >
viskores::rendering::Canvas::RefreshColorBuffer
virtual void RefreshColorBuffer() const
Definition: Canvas.h:137
viskores::rendering::Camera
Specifies the viewport for a rendering.
Definition: Camera.h:45
BitmapFont.h
Camera.h
Color.h
viskores_rendering_export.h
viskores::rendering::WorldAnnotator
Definition: WorldAnnotator.h:35
viskores::rendering::ColorBarAnnotation
Definition: ColorBarAnnotation.h:34
viskores::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:169
viskores::Vec< viskores::Id, 2 >
DataSet.h
viskores::rendering::Canvas
Represents the image space that is the target of rendering.
Definition: Canvas.h:43
viskores::rendering::Color
Representation of a color.
Definition: Color.h:37
viskores::rendering::AxisAnnotation2D
Definition: AxisAnnotation2D.h:37