VTK-m  2.2
ANARIScene.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_interop_anari_ANARIScene_h
12 #define vtk_m_interop_anari_ANARIScene_h
13 
15 // std
16 #include <string>
17 #include <type_traits>
18 
19 namespace vtkm
20 {
21 namespace interop
22 {
23 namespace anari
24 {
25 
44 struct VTKM_ANARI_EXPORT ANARIScene
45 {
48  ANARIScene(anari_cpp::Device device);
49 
52  ~ANARIScene();
53 
54  ANARIScene(const ANARIScene&) = delete;
55  ANARIScene(ANARIScene&&) = delete;
56  ANARIScene& operator=(const ANARIScene&) = delete;
57  ANARIScene& operator=(ANARIScene&&) = delete;
58 
63  template <typename ANARIMapperType>
64  ANARIMapperType& AddMapper(const ANARIMapperType& mapper, bool visible = true);
65 
72  template <typename ANARIMapperType>
73  void ReplaceMapper(const ANARIMapperType& newMapper, vtkm::IdComponent id, bool visible);
74 
77  vtkm::IdComponent GetNumberOfMappers() const;
78 
81  bool HasMapperWithName(const char* name) const;
82 
85  vtkm::IdComponent GetMapperIndexByName(const char* name);
86 
89  ANARIMapper& GetMapper(vtkm::IdComponent id);
90 
93  ANARIMapper& GetMapper(const char* name);
94 
97  bool GetMapperVisible(vtkm::IdComponent id) const;
98  void SetMapperVisible(vtkm::IdComponent id, bool shown);
99 
102  void RemoveMapper(vtkm::IdComponent id);
103 
106  void RemoveMapper(const char* name);
107 
109  void RemoveAllMappers();
110 
114  anari_cpp::Device GetDevice() const;
115 
119  anari_cpp::World GetANARIWorld();
120 
121 private:
122  void UpdateWorld();
123 
124  anari_cpp::Device Device{ nullptr };
125  anari_cpp::World World{ nullptr };
126 
127  struct SceneMapper
128  {
129  std::unique_ptr<ANARIMapper> Mapper;
130  bool Show{ true };
131  };
132 
133  std::vector<SceneMapper> Mappers;
134 };
135 
136 // Inlined definitions ////////////////////////////////////////////////////////
137 
138 template <typename ANARIMapperType>
139 inline ANARIMapperType& ANARIScene::AddMapper(const ANARIMapperType& mapper, bool visible)
140 {
141  static_assert(std::is_base_of<ANARIMapper, ANARIMapperType>::value,
142  "Only ANARIMapper types can be added to ANARIScene");
143 
144  auto* name = mapper.GetName();
145  if (HasMapperWithName(name))
146  {
147  auto idx = GetMapperIndexByName(name);
148  ReplaceMapper(mapper, idx, visible);
149  return (ANARIMapperType&)GetMapper(idx);
150  }
151  else
152  {
153  this->Mappers.push_back({ std::make_unique<ANARIMapperType>(mapper), visible });
154  UpdateWorld();
155  return (ANARIMapperType&)GetMapper(GetNumberOfMappers() - 1);
156  }
157 }
158 
159 template <typename ANARIMapperType>
160 inline void ANARIScene::ReplaceMapper(const ANARIMapperType& newMapper,
162  bool visible)
163 {
164  static_assert(std::is_base_of<ANARIMapper, ANARIMapperType>::value,
165  "Only ANARIMapper types can be added to ANARIScene");
166  const bool wasVisible = GetMapperVisible(id);
167  Mappers[id] = { std::make_unique<ANARIMapperType>(newMapper), visible };
168  if (wasVisible || visible)
169  UpdateWorld();
170 }
171 
172 } // namespace anari
173 } // namespace interop
174 } // namespace vtkm
175 
176 #endif
anari
Definition: VtkmANARITypes.h:30
ANARIMapper.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::interop::anari::ANARIScene::AddMapper
ANARIMapperType & AddMapper(const ANARIMapperType &mapper, bool visible=true)
Add a mapper to the scene.
Definition: ANARIScene.h:139
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::interop::anari::ANARIScene::ReplaceMapper
void ReplaceMapper(const ANARIMapperType &newMapper, vtkm::IdComponent id, bool visible)
Add a mapper to the scene.
Definition: ANARIScene.h:160
vtkm::interop::anari::ANARIMapper
This is the base class used for all ANARI mappers.
Definition: ANARIMapper.h:37
vtkm::interop::anari::ANARIScene::SceneMapper::Mapper
std::unique_ptr< ANARIMapper > Mapper
Definition: ANARIScene.h:129
vtkm::interop::anari::ANARIScene::GetMapperVisible
bool GetMapperVisible(vtkm::IdComponent id) const
Get the associated mapper by name.
vtkm::interop::anari::ANARIScene
Object which manages a collection of mappers representing a single scene.
Definition: ANARIScene.h:44
vtkm::interop::anari::ANARIScene::HasMapperWithName
bool HasMapperWithName(const char *name) const
Ask whether a mapper has the passed in name or not.
vtkm::interop::anari::ANARIScene::GetMapper
ANARIMapper & GetMapper(vtkm::IdComponent id)
Get the associated mapper by index.
vtkm::interop::anari::ANARIScene::UpdateWorld
void UpdateWorld()
vtkm::interop::anari::ANARIScene::GetNumberOfMappers
vtkm::IdComponent GetNumberOfMappers() const
Get number of mappers in this scene.
vtkm::interop::anari::ANARIScene::SceneMapper
Definition: ANARIScene.h:127
vtkm::interop::anari::ANARIScene::Mappers
std::vector< SceneMapper > Mappers
Definition: ANARIScene.h:133
vtkm::interop::anari::ANARIScene::GetMapperIndexByName
vtkm::IdComponent GetMapperIndexByName(const char *name)
Get the index to the mapper with the given name.