Viskores  1.0
ANARIScene.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_interop_anari_ANARIScene_h
20 #define viskores_interop_anari_ANARIScene_h
21 
23 // std
24 #include <string>
25 #include <type_traits>
26 
27 namespace viskores
28 {
29 namespace interop
30 {
31 namespace anari
32 {
33 
52 struct VISKORES_ANARI_EXPORT ANARIScene
53 {
56  ANARIScene(anari_cpp::Device device);
57 
60  ~ANARIScene();
61 
62  ANARIScene(const ANARIScene&) = delete;
63  ANARIScene(ANARIScene&&) = delete;
64  ANARIScene& operator=(const ANARIScene&) = delete;
65  ANARIScene& operator=(ANARIScene&&) = delete;
66 
71  template <typename ANARIMapperType>
72  ANARIMapperType& AddMapper(const ANARIMapperType& mapper, bool visible = true);
73 
80  template <typename ANARIMapperType>
81  void ReplaceMapper(const ANARIMapperType& newMapper, viskores::IdComponent id, bool visible);
82 
85  viskores::IdComponent GetNumberOfMappers() const;
86 
89  bool HasMapperWithName(const char* name) const;
90 
93  viskores::IdComponent GetMapperIndexByName(const char* name);
94 
97  ANARIMapper& GetMapper(viskores::IdComponent id);
98 
101  ANARIMapper& GetMapper(const char* name);
102 
105  bool GetMapperVisible(viskores::IdComponent id) const;
106  void SetMapperVisible(viskores::IdComponent id, bool shown);
107 
110  void RemoveMapper(viskores::IdComponent id);
111 
114  void RemoveMapper(const char* name);
115 
117  void RemoveAllMappers();
118 
122  anari_cpp::Device GetDevice() const;
123 
127  anari_cpp::World GetANARIWorld();
128 
129 private:
130  void UpdateWorld();
131 
132  anari_cpp::Device Device{ nullptr };
133  anari_cpp::World World{ nullptr };
134 
135  struct SceneMapper
136  {
137  std::unique_ptr<ANARIMapper> Mapper;
138  bool Show{ true };
139  };
140 
141  std::vector<SceneMapper> Mappers;
142 };
143 
144 // Inlined definitions ////////////////////////////////////////////////////////
145 
146 template <typename ANARIMapperType>
147 inline ANARIMapperType& ANARIScene::AddMapper(const ANARIMapperType& mapper, bool visible)
148 {
149  static_assert(std::is_base_of<ANARIMapper, ANARIMapperType>::value,
150  "Only ANARIMapper types can be added to ANARIScene");
151 
152  auto* name = mapper.GetName();
153  if (HasMapperWithName(name))
154  {
155  auto idx = GetMapperIndexByName(name);
156  ReplaceMapper(mapper, idx, visible);
157  return (ANARIMapperType&)GetMapper(idx);
158  }
159  else
160  {
161  this->Mappers.push_back({ std::make_unique<ANARIMapperType>(mapper), visible });
162  UpdateWorld();
163  return (ANARIMapperType&)GetMapper(GetNumberOfMappers() - 1);
164  }
165 }
166 
167 template <typename ANARIMapperType>
168 inline void ANARIScene::ReplaceMapper(const ANARIMapperType& newMapper,
170  bool visible)
171 {
172  static_assert(std::is_base_of<ANARIMapper, ANARIMapperType>::value,
173  "Only ANARIMapper types can be added to ANARIScene");
174  const bool wasVisible = GetMapperVisible(id);
175  Mappers[id] = { std::make_unique<ANARIMapperType>(newMapper), visible };
176  if (wasVisible || visible)
177  UpdateWorld();
178 }
179 
180 } // namespace anari
181 } // namespace interop
182 } // namespace viskores
183 
184 #endif
anari
Definition: ViskoresANARITypes.h:38
ANARIMapper.h
viskores::interop::anari::ANARIScene::SceneMapper
Definition: ANARIScene.h:135
viskores::interop::anari::ANARIScene
Object which manages a collection of mappers representing a single scene.
Definition: ANARIScene.h:52
viskores::interop::anari::ANARIScene::AddMapper
ANARIMapperType & AddMapper(const ANARIMapperType &mapper, bool visible=true)
Add a mapper to the scene.
Definition: ANARIScene.h:147
viskores::interop::anari::ANARIScene::SceneMapper::Mapper
std::unique_ptr< ANARIMapper > Mapper
Definition: ANARIScene.h:137
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::interop::anari::ANARIScene::HasMapperWithName
bool HasMapperWithName(const char *name) const
Ask whether a mapper has the passed in name or not.
viskores::interop::anari::ANARIScene::GetNumberOfMappers
viskores::IdComponent GetNumberOfMappers() const
Get number of mappers in this scene.
viskores::interop::anari::ANARIScene::GetMapperVisible
bool GetMapperVisible(viskores::IdComponent id) const
Get the associated mapper by name.
viskores::interop::anari::ANARIScene::ReplaceMapper
void ReplaceMapper(const ANARIMapperType &newMapper, viskores::IdComponent id, bool visible)
Add a mapper to the scene.
Definition: ANARIScene.h:168
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::interop::anari::ANARIScene::Mappers
std::vector< SceneMapper > Mappers
Definition: ANARIScene.h:141
viskores::interop::anari::ANARIScene::GetMapper
ANARIMapper & GetMapper(viskores::IdComponent id)
Get the associated mapper by index.
viskores::interop::anari::ANARIMapper
This is the base class used for all ANARI mappers.
Definition: ANARIMapper.h:45
viskores::interop::anari::ANARIScene::GetMapperIndexByName
viskores::IdComponent GetMapperIndexByName(const char *name)
Get the index to the mapper with the given name.
viskores::interop::anari::ANARIScene::UpdateWorld
void UpdateWorld()