Cumulia Illustrator Rendering Engine v1.1.0
A Rendering engine for industrial CAD/CAE model and optimized for greatest performance
 
Loading...
Searching...
No Matches
passthrough.h
1//##################################################################################################
2//
3// Copyright (c) 2024 Beijing Qiongqi Tech Co.,Ltd. All rights reserved.
4
5// This source code is confidential and proprietary to Beijing Qiongqi Tech Co.,Ltd(The Holder).
6// Any unauthorized use, copying, modification, or distribution of the code is strictly prohibited.
7// Any user shall obtain authorizaition from the Holder before modifying the source code. And the user shall not
8// sublicense, sell, distribute, or transfer the source code, whether in original or modified form, to any third party
9// without the prior written consent of the Holder.
10
11// This copyright notice and permission grant shall be included in all copies or substantial portions of the source code.
12
13// Author Cumulia Illustrator
14// Date 2024-10-31
15// Version V1.1.0
16//##################################################################################################
17
18#pragma once
19
20#include "selector.h"
21
22namespace cil
23{
24 template <typename T>
26 {
27 protected:
28 std::shared_ptr<EntityBuilder<T>> m_builder;
29 std::shared_ptr<EntityProducer> m_producer;
30
31 private:
32 std::shared_ptr<std::vector<std::shared_ptr<Node>>> m_builtNodes;
33
34 public:
39
41 {
42 }
43
44 virtual void update(SelectorUpdateMode mode)
45 {
46 switch (mode)
47 {
50 {
51 this->m_builtNodes = nullptr;
52 break;
53 }
54 default: break;
55 }
56 }
57
58 virtual void setEntities(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
59 {
60 this->m_builder->setEntities(entities);
62 }
63
64 std::vector<std::shared_ptr<T>> select(int x, int y, int depth = 0)
65 {
66 this->buildNodes();
67 this->m_producer->toPixel(x, y);
68
69 int count = 0;
70 auto nodes = _nodes();
71 *nodes = *this->m_builtNodes;
72 std::vector<std::shared_ptr<T>> result;
73
74 std::function<void()> render;
75 render = [&]() -> void {
76 this->m_producer->updatePassBatch();
77 auto image = this->m_producer->produce(nodes);
78 auto entityIndex = ((unsigned int*)image->data())[0];
79 if (entityIndex != 0XFFFFFFFF)
80 {
81 result.push_back((*this->m_builder->entities())[entityIndex]);
82
83 auto& node = (*this->m_builtNodes)[entityIndex];
84 auto it = std::find(nodes->begin(), nodes->end(), node);
85 if (it != nodes->end())
86 {
87 nodes->erase(it);
88
89 count++;
90 if (!depth || count < depth)
91 render();
92 }
93 }
94 };
95 render();
96
97 return result;
98 }
99
100 std::vector<std::shared_ptr<T>> multiSelect(int x1, int y1, int x2, int y2, int depth = 0)
101 {
102 this->buildNodes();
103 this->m_producer->toBox(x1, y1, x2, y2);
104
105 int count = 0;
106 auto nodes = _nodes();
107 *nodes = *this->m_builtNodes;
108 std::vector<std::shared_ptr<T>> result;
109
110 std::function<void()> render;
111 render = [&]() -> void {
112 this->m_producer->updatePassBatch();
113 auto image = this->m_producer->produce(nodes);
114 auto imageData = (unsigned int*)image->data();
115
116 std::set<unsigned int> entityIndices;
117 auto length = image->width() * image->height();
118 for (int i = 0; i < length; ++i)
119 {
120 entityIndices.insert(imageData[i]);
121 }
122 entityIndices.erase(0XFFFFFFFF);
123
124 if (entityIndices.size() != 0)
125 {
126 auto entities = *this->m_builder->entities();
127 for (auto entityIndex : entityIndices)
128 {
129 result.push_back(entities[entityIndex]);
130
131 auto& node = (*this->m_builtNodes)[entityIndex];
132 auto it = std::find(nodes->begin(), nodes->end(), node);
133 if (it != nodes->end())
134 {
135 nodes->erase(it);
136 }
137 }
138
139 count++;
140 if (!depth || count < depth)
141 render();
142 }
143 };
144 render();
145
146 return result;
147 }
148
149 private:
150 void buildNodes()
151 {
152 if (!this->m_builtNodes)
153 {
154 this->m_builtNodes = this->m_builder->build();
155 this->m_producer->updatePass();
156 }
157 }
158 };
159
160 template <typename T>
162 {
163 public:
164 PassThroughFaceSelector(const std::shared_ptr<SelectorEngine>& engine, const std::shared_ptr<SelectorOptions<T>>& options)
166 {
167 this->m_builder = std::make_shared<FaceBuilder<T>>(options->entities, options->entity2node);
168 this->m_producer = std::make_shared<FaceProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
169 }
170
172 {
173 }
174 };
175
176 template <typename T>
178 {
179 public:
180 PassThroughVertexSelector(const std::shared_ptr<SelectorEngine>& engine, const std::shared_ptr<SelectorOptions<T>>& options)
182 {
183 this->m_builder = std::make_shared<VertexBuilder<T>>(options->entities, options->entity2node);
184 this->m_producer = std::make_shared<VertexProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
185 }
186
188 {
189 }
190 };
191
192 template <typename T>
194 {
195 public:
196 PassThroughEdgeSelector(const std::shared_ptr<SelectorEngine>& engine, const std::shared_ptr<SelectorOptions<T>>& options)
198 {
199 this->m_builder = std::make_shared<EdgeBuilder<T>>(options->entities, options->entity2node);
200 this->m_producer = std::make_shared<EdgeProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
201 }
202
204 {
205 }
206 };
207
208 template <typename T>
209 std::shared_ptr<PassThroughFaceSelector<T>> _passThroughFaceSelector(const std::shared_ptr<SelectorEngine>& engine, const std::shared_ptr<SelectorOptions<T>>& options)
210 {
211 return std::make_shared<PassThroughFaceSelector<T>>(engine, options);
212 }
213
214 template <typename T>
215 std::shared_ptr<PassThroughVertexSelector<T>> _passThroughVertexSelector(const std::shared_ptr<SelectorEngine>& engine, const std::shared_ptr<SelectorOptions<T>>& options)
216 {
217 return std::make_shared<PassThroughVertexSelector<T>>(engine, options);
218 }
219
220 template <typename T>
221 std::shared_ptr<PassThroughEdgeSelector<T>> _passThroughEdgeSelector(const std::shared_ptr<SelectorEngine>& engine, const std::shared_ptr<SelectorOptions<T>>& options)
222 {
223 return std::make_shared<PassThroughEdgeSelector<T>>(engine, options);
224 }
225}
Definition selector.h:73
Definition passthrough.h:194
PassThroughEdgeSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options)
Definition passthrough.h:196
virtual ~PassThroughEdgeSelector()
Definition passthrough.h:203
Definition passthrough.h:26
virtual ~PassThroughEntitySelector()
Definition passthrough.h:40
std::vector< std::shared_ptr< T > > multiSelect(int x1, int y1, int x2, int y2, int depth=0)
Definition passthrough.h:100
std::shared_ptr< EntityProducer > m_producer
Definition passthrough.h:29
PassThroughEntitySelector()
Definition passthrough.h:35
std::shared_ptr< EntityBuilder< T > > m_builder
Definition passthrough.h:28
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition passthrough.h:58
std::vector< std::shared_ptr< T > > select(int x, int y, int depth=0)
Definition passthrough.h:64
virtual void update(SelectorUpdateMode mode)
Definition passthrough.h:44
Definition passthrough.h:162
virtual ~PassThroughFaceSelector()
Definition passthrough.h:171
PassThroughFaceSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options)
Definition passthrough.h:164
Definition passthrough.h:178
virtual ~PassThroughVertexSelector()
Definition passthrough.h:187
PassThroughVertexSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options)
Definition passthrough.h:180
Definition selector.h:53
Definition decal.h:23
SelectorUpdateMode
Definition selector.h:35
std::shared_ptr< PassThroughEdgeSelector< T > > _passThroughEdgeSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options)
Definition passthrough.h:221
std::shared_ptr< PassThroughVertexSelector< T > > _passThroughVertexSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options)
Definition passthrough.h:215
std::shared_ptr< std::vector< std::shared_ptr< Node > > > _nodes(const std::vector< std::shared_ptr< Node > > &nodes={})
std::shared_ptr< PassThroughFaceSelector< T > > _passThroughFaceSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options)
Definition passthrough.h:209