1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //  This software is distributed WITHOUT ANY WARRANTY; without even
6 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 //  PURPOSE.  See the above copyright notice for more information.
8 //
9 //  Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 //  Copyright 2015 UT-Battelle, LLC.
11 //  Copyright 2015 Los Alamos National Security.
12 //
13 //  Under the terms of Contract DE-NA0003525 with NTESS,
14 //  the U.S. Government retains certain rights in this software.
15 //
16 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 //  Laboratory (LANL), the U.S. Government retains certain rights in
18 //  this software.
19 //============================================================================
20 #ifndef vtk_m_rendering_View_h
21 #define vtk_m_rendering_View_h
22 
23 #include <vtkm/rendering/vtkm_rendering_export.h>
24 
25 #include <vtkm/rendering/Camera.h>
26 #include <vtkm/rendering/Canvas.h>
27 #include <vtkm/rendering/Color.h>
28 #include <vtkm/rendering/Mapper.h>
29 #include <vtkm/rendering/Scene.h>
30 #include <vtkm/rendering/TextAnnotation.h>
31 
32 #include <memory>
33 
34 namespace vtkm
35 {
36 namespace rendering
37 {
38 
39 class VTKM_RENDERING_EXPORT View
40 {
41 public:
42   View(const vtkm::rendering::Scene& scene,
43        const vtkm::rendering::Mapper& mapper,
44        const vtkm::rendering::Canvas& canvas,
45        const vtkm::rendering::Color& backgroundColor = vtkm::rendering::Color(0, 0, 0, 1),
46        const vtkm::rendering::Color& foregroundColor = vtkm::rendering::Color(1, 1, 1, 1));
47 
48   View(const vtkm::rendering::Scene& scene,
49        const vtkm::rendering::Mapper& mapper,
50        const vtkm::rendering::Canvas& canvas,
51        const vtkm::rendering::Camera& camera,
52        const vtkm::rendering::Color& backgroundColor = vtkm::rendering::Color(0, 0, 0, 1),
53        const vtkm::rendering::Color& foregroundColor = vtkm::rendering::Color(1, 1, 1, 1));
54 
55   virtual ~View();
56 
57   VTKM_CONT
GetScene()58   const vtkm::rendering::Scene& GetScene() const { return this->Scene; }
59   VTKM_CONT
GetScene()60   vtkm::rendering::Scene& GetScene() { return this->Scene; }
61   VTKM_CONT
SetScene(const vtkm::rendering::Scene & scene)62   void SetScene(const vtkm::rendering::Scene& scene) { this->Scene = scene; }
63 
64   VTKM_CONT
GetMapper()65   const vtkm::rendering::Mapper& GetMapper() const { return *this->MapperPointer; }
66   VTKM_CONT
GetMapper()67   vtkm::rendering::Mapper& GetMapper() { return *this->MapperPointer; }
68 
69   VTKM_CONT
GetCanvas()70   const vtkm::rendering::Canvas& GetCanvas() const { return *this->CanvasPointer; }
71   VTKM_CONT
GetCanvas()72   vtkm::rendering::Canvas& GetCanvas() { return *this->CanvasPointer; }
73 
74   VTKM_CONT
GetWorldAnnotator()75   const vtkm::rendering::WorldAnnotator& GetWorldAnnotator() const
76   {
77     return *this->WorldAnnotatorPointer;
78   }
79 
80   VTKM_CONT
GetCamera()81   const vtkm::rendering::Camera& GetCamera() const { return this->Camera; }
82   VTKM_CONT
GetCamera()83   vtkm::rendering::Camera& GetCamera() { return this->Camera; }
84   VTKM_CONT
SetCamera(const vtkm::rendering::Camera & camera)85   void SetCamera(const vtkm::rendering::Camera& camera) { this->Camera = camera; }
86 
87   VTKM_CONT
GetBackgroundColor()88   const vtkm::rendering::Color& GetBackgroundColor() const
89   {
90     return this->CanvasPointer->GetBackgroundColor();
91   }
92 
93   VTKM_CONT
SetBackgroundColor(const vtkm::rendering::Color & color)94   void SetBackgroundColor(const vtkm::rendering::Color& color)
95   {
96     this->CanvasPointer->SetBackgroundColor(color);
97   }
98 
99   VTKM_CONT
SetForegroundColor(const vtkm::rendering::Color & color)100   void SetForegroundColor(const vtkm::rendering::Color& color)
101   {
102     this->CanvasPointer->SetForegroundColor(color);
103   }
104 
105   virtual void Initialize();
106 
107   virtual void Paint() = 0;
108   virtual void RenderScreenAnnotations() = 0;
109   virtual void RenderWorldAnnotations() = 0;
110 
111   void SaveAs(const std::string& fileName) const;
112 
113   VTKM_CONT
SetAxisColor(vtkm::rendering::Color c)114   void SetAxisColor(vtkm::rendering::Color c) { this->AxisColor = c; }
115 
116   VTKM_CONT
ClearAnnotations()117   void ClearAnnotations() { Annotations.clear(); }
118 
119   VTKM_CONT
AddAnnotation(vtkm::rendering::TextAnnotation * ann)120   void AddAnnotation(vtkm::rendering::TextAnnotation* ann) { Annotations.push_back(ann); }
121 
122 protected:
123   void SetupForWorldSpace(bool viewportClip = true);
124 
125   void SetupForScreenSpace(bool viewportClip = false);
126 
127   void RenderAnnotations();
128 
129   vtkm::rendering::Color AxisColor = vtkm::rendering::Color::white;
130 
131 private:
132   vtkm::rendering::Scene Scene;
133   std::shared_ptr<vtkm::rendering::Mapper> MapperPointer;
134   std::shared_ptr<vtkm::rendering::Canvas> CanvasPointer;
135   std::shared_ptr<vtkm::rendering::WorldAnnotator> WorldAnnotatorPointer;
136   std::vector<vtkm::rendering::TextAnnotation*> Annotations;
137   vtkm::rendering::Camera Camera;
138 };
139 }
140 } //namespace vtkm::rendering
141 
142 #endif //vtk_m_rendering_View_h
143