VTK  9.1.0
World.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Types.h"
4#include "Geometry.h"
5
6#include <VisRTX.h>
7
8#include <set>
9
10namespace RTW
11{
12 class World : public Object
13 {
14 friend class Renderer;
15
16 public:
19 {
20 VisRTX::Context* rtx = VisRTX_GetContext();
21 this->model = rtx->CreateModel();
22 }
23
25 {
26 for (Geometry* geometry : this->geometries)
27 if (geometry)
28 geometry->Release();
29 this->model->Release();
30 }
31
32 void Commit() override
33 {
34 }
35
36 void SetObject(const std::string& id, Object *object) override
37 {
38 Object::SetObject(id, object);
39 if(object && object->GetDataType() == RTW_DATA)
40 {
41 Data *data = reinterpret_cast<Data *>(object);
42 if(data->GetElementDataType() == RTW_INSTANCE)
43 {
44 int numElements = data->GetNumElements();
45 Instance **elemData = reinterpret_cast<Instance **>(data->GetData());
46 while(numElements-- > 0)
47 {
48 Object *elem = *elemData;
49 assert(elem->GetDataType() == RTW_INSTANCE);
50 Group *group = reinterpret_cast<Instance *>(elem)->group;
51 std::set<GeometricModel *> &geoModels = group->geometricModels;
52 for(auto &m : geoModels)
53 AddGeometry(m->geometry);
54 elemData++;
55 }
56 }
57 }
58 else if(object && object->GetDataType() == RTW_INSTANCE)
59 {
60 Group *group = reinterpret_cast<Instance *>(object)->group;
61 std::set<GeometricModel *> &geoModels = group->geometricModels;
62 for(auto &m : geoModels)
63 AddGeometry(m->geometry);
64 }
65 }
66
67 void RemoveParam(const std::string& id) override
68 {
69 Object *obj = GetObject({id});
70 if(obj && obj->GetDataType() == RTW_INSTANCE)
71 {
72 Group *group = reinterpret_cast<Instance *>(obj)->group;
73 std::set<GeometricModel *> geoModels = group->geometricModels;
74 for(auto &m : geoModels)
75 RemoveGeometry(m->geometry);
76 }
78 }
79
80 void AddGeometry(Geometry* geometry)
81 {
82 if (!geometry)
83 return;
84
85 // Check if already added
86 auto it = this->geometries.find(geometry);
87 if (it != this->geometries.end())
88 return;
89
90
91 // Add and increase ref count
92 this->model->AddGeometry(geometry->geometry);
93 this->geometries.insert(geometry);
94 geometry->AddRef();
95 }
96
97 void RemoveGeometry(Geometry* geometry)
98 {
99 if (!geometry)
100 return;
101
102 // Check if already added
103 auto it = this->geometries.find(geometry);
104 if (it != this->geometries.end())
105 {
106 this->model->RemoveGeometry(geometry->geometry);
107 this->geometries.erase(geometry);
108 geometry->Release();
109 }
110 }
111
112
113
114 private:
115 //The OSPRay 'world' object roughly corresponds to a VisRTX 'model' object.
116 VisRTX::Model* model = nullptr;
117 std::set<Geometry*> geometries;
118 };
119}
@ RTW_WORLD
Definition: Types.h:150
@ RTW_INSTANCE
Definition: Types.h:142
@ RTW_DATA
Definition: Types.h:134
Definition: Data.h:10
RTWDataType GetDataType() const
Definition: Object.h:306
void Release()
Definition: Object.h:43
virtual void SetObject(const std::string &id, Object *object)
Definition: Object.h:78
void AddRef()
Definition: Object.h:38
T * GetObject(const std::vector< std::string > &ids, T *defaultValue=nullptr, bool *found=nullptr) const
Definition: Object.h:98
virtual void RemoveParam(const std::string &id)
Definition: Object.h:230
World()
Definition: World.h:17
void AddGeometry(Geometry *geometry)
Definition: World.h:80
~World()
Definition: World.h:24
void RemoveParam(const std::string &id) override
Definition: World.h:67
void Commit() override
Definition: World.h:32
void RemoveGeometry(Geometry *geometry)
Definition: World.h:97
void SetObject(const std::string &id, Object *object) override
Definition: World.h:36
Definition: Backend.h:6
@ data
Definition: vtkX3D.h:321
@ string
Definition: vtkX3D.h:496