55 std::shared_ptr<std::vector<std::shared_ptr<T>>>
entities;
56 std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>
entity2node;
72 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities) = 0;
84 std::shared_ptr<std::vector<std::shared_ptr<Node>>> m_builtNodes;
85 std::shared_ptr<Image2D> m_bufferImage;
101 this->m_bufferImage =
nullptr;
106 this->m_builtNodes =
nullptr;
107 this->m_bufferImage =
nullptr;
114 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
116 this->m_builder->setEntities(entities);
123 if (this->m_buffered)
125 this->produceBufferImage();
126 auto consumer = std::make_shared<PixelConsumer>(this->m_producer->windowSize());
127 auto pixelIndex = consumer->select(x, y);
128 unsigned int entityIndex = ((
unsigned int*)this->m_bufferImage->data())[pixelIndex];
129 return entityIndex != 0XFFFFFFFF ? (*this->m_builder->entities())[entityIndex] :
nullptr;
133 this->m_producer->toPixel(x, y);
134 auto image = this->m_producer->produce(this->m_builtNodes);
135 unsigned int entityIndex = ((
unsigned int*)image->data())[0];
136 return entityIndex != 0XFFFFFFFF ? (*this->m_builder->entities())[entityIndex] :
nullptr;
140 std::vector<std::shared_ptr<T>>
multiSelect(
int x1,
int y1,
int x2,
int y2)
143 if (this->m_buffered)
145 this->produceBufferImage();
146 auto consumer = std::make_shared<BoxConsumer>(this->m_producer->windowSize());
147 std::vector<int> pixelIndices = consumer->select(x1, y1, x2, y2);
149 std::set<unsigned int> entityIndices;
150 auto imageData = (
unsigned int*)this->m_bufferImage->data();
151 for (
auto pixelIndex : pixelIndices)
153 entityIndices.insert(imageData[pixelIndex]);
155 entityIndices.erase(0XFFFFFFFF);
157 std::vector<std::shared_ptr<T>> result;
158 auto& entities = *this->m_builder->entities();
159 for (
auto entityIndex : entityIndices)
161 result.push_back(entities[entityIndex]);
168 this->m_producer->toBox(x1, y1, x2, y2);
169 auto image = this->m_producer->produce(this->m_builtNodes);
171 std::set<unsigned int> entityIndices;
172 auto imageData = (
unsigned int*)image->data();
173 auto length = image->width() * image->height();
174 for (
int i = 0; i < length; ++i)
176 entityIndices.insert(imageData[i]);
178 entityIndices.erase(0XFFFFFFFF);
180 std::vector<std::shared_ptr<T>> result;
181 auto& entities = *this->m_builder->entities();
182 for (
auto entityIndex : entityIndices)
184 result.push_back(entities[entityIndex]);
194 if (!this->m_builtNodes)
196 this->m_builtNodes = this->m_builder->build();
197 this->m_producer->updatePass();
201 void produceBufferImage()
203 if (!this->m_bufferImage) {
204 this->m_producer->toWindow();
205 this->m_bufferImage = this->m_producer->produce(this->m_builtNodes);
210 template <
typename T>
217 this->m_builder = std::make_shared<FaceBuilder<T>>(options->entities, options->entity2node);
218 this->m_producer = std::make_shared<FaceProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
219 this->m_buffered = buffered;
227 template <
typename T>
234 this->m_builder = std::make_shared<VertexBuilder<T>>(options->entities, options->entity2node);
235 this->m_producer = std::make_shared<VertexProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
236 this->m_buffered = buffered;
244 template <
typename T>
251 this->m_builder = std::make_shared<EdgeBuilder<T>>(options->entities, options->entity2node);
252 this->m_producer = std::make_shared<EdgeProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
253 this->m_buffered = buffered;
261 template <
typename T>
270 std::shared_ptr<std::vector<std::shared_ptr<Node>>> m_builtNodes;
271 std::vector<std::shared_ptr<Image2D>> m_bufferImages;
288 this->m_bufferImages.clear();
293 this->m_builtNodes =
nullptr;
294 this->m_bufferImages.clear();
301 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
303 this->m_builder->setEntities(entities);
307 std::shared_ptr<Vector3f>
select(
int x,
int y)
310 if (this->m_buffered)
312 this->produceBufferImages();
313 auto consumer = std::make_shared<PixelConsumer>(this->m_producer->windowSize());
314 auto pixelIndex = consumer->select(x, y);
315 unsigned int value = ((
unsigned int*)this->m_bufferImages[0]->data())[pixelIndex];
316 if (value != 0XFFFFFFFF)
318 auto x = ((
float*)this->m_bufferImages[0]->data())[pixelIndex];
319 auto y = ((
float*)this->m_bufferImages[1]->data())[pixelIndex];
320 auto z = ((
float*)this->m_bufferImages[2]->data())[pixelIndex];
322 return _vec3(x, y, z);
331 this->m_producer->toPixel(x, y);
332 auto images = this->m_producer->produce(this->m_builtNodes);
333 unsigned int value = ((
unsigned int*)images[0]->data())[0];
334 if (value != 0XFFFFFFFF)
336 auto x = ((
float*)images[0]->data())[0];
337 auto y = ((
float*)images[1]->data())[0];
338 auto z = ((
float*)images[2]->data())[0];
340 return _vec3(x, y, z);
352 if (!this->m_builtNodes)
354 this->m_builtNodes = this->m_builder->build();
355 this->m_producer->updatePass();
359 void produceBufferImages()
361 if (this->m_bufferImages.size() == 0) {
362 this->m_producer->toWindow();
363 this->m_bufferImages = this->m_producer->produce(this->m_builtNodes);
368 template <
typename T>
375 this->m_builder = std::make_shared<PositionBuilder<T>>(options->entities, options->entity2node);
376 this->m_producer = std::make_shared<PositionProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
377 this->m_buffered = buffered;
385 template <
typename T>
392 this->m_builder = std::make_shared<NormalBuilder<T>>(options->entities, options->entity2node);
393 this->m_producer = std::make_shared<NormalProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
394 this->m_buffered = buffered;
402 template <
typename T>
411 std::shared_ptr<std::vector<std::shared_ptr<Node>>> m_builtNodes;
412 std::shared_ptr<Image2D> m_bufferImage;
418 this->m_builder = std::make_shared<PrimitiveBuilder<T>>(options->entities, options->entity2node);
419 this->m_producer = std::make_shared<PrimitiveProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
420 this->m_buffered = buffered;
432 this->m_bufferImage =
nullptr;
437 this->m_builtNodes =
nullptr;
438 this->m_bufferImage =
nullptr;
445 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
447 this->m_builder->setEntities(entities);
454 if (this->m_buffered)
456 this->produceBufferImage();
457 auto consumer = std::make_shared<PixelConsumer>(this->m_producer->windowSize());
458 auto pixelIndex = consumer->select(x, y);
459 unsigned int primitiveIndex = ((
unsigned int*)this->m_bufferImage->data())[pixelIndex];
461 return primitiveIndex;
465 this->m_producer->toPixel(x, y);
466 auto image = this->m_producer->produce(this->m_builtNodes);
467 unsigned int primitiveIndex = ((
unsigned int*)image->data())[0];
469 return primitiveIndex;
473 std::vector<unsigned int>
multiSelect(
int x1,
int y1,
int x2,
int y2)
476 if (this->m_buffered)
478 this->produceBufferImage();
479 auto consumer = std::make_shared<BoxConsumer>(this->m_producer->windowSize());
480 std::vector<int> pixelIndices = consumer->select(x1, y1, x2, y2);
482 std::set<unsigned int> primitiveIndices;
483 auto imageData = (
unsigned int*)this->m_bufferImage->data();
484 for (
auto pixelIndex : pixelIndices)
486 primitiveIndices.insert(imageData[pixelIndex]);
488 primitiveIndices.erase(0XFFFFFFFF);
490 return std::vector<unsigned int>(primitiveIndices.begin(), primitiveIndices.end());
494 this->m_producer->toBox(x1, y1, x2, y2);
495 auto image = this->m_producer->produce(this->m_builtNodes);
496 auto imageData = (
unsigned int*)image->data();
498 std::set<unsigned int> primitiveIndices;
499 auto length = image->width() * image->height();
500 for (
int i = 0; i < length; ++i)
502 primitiveIndices.insert(imageData[i]);
504 primitiveIndices.erase(0XFFFFFFFF);
506 return std::vector<unsigned int>(primitiveIndices.begin(), primitiveIndices.end());
513 if (!this->m_builtNodes)
515 this->m_builtNodes = this->m_builder->build();
516 this->m_producer->updatePass();
520 void produceBufferImage()
522 if (!this->m_bufferImage) {
523 this->m_producer->toWindow();
524 this->m_bufferImage = this->m_producer->produce(this->m_builtNodes);
529 std::shared_ptr<SelectorEngine>
_selectorEngine(
const std::shared_ptr<Renderer>& renderer,
const std::shared_ptr<Camera>& camera,
const std::shared_ptr<Vector2i>& backgroundSize,
const std::shared_ptr<Vector2i>& windowSize);
531 template <
typename T>
532 std::shared_ptr<SelectorOptions<T>>
_selectorOptions(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities,
const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
534 auto options = std::make_shared<SelectorOptions<T>>();
535 options->entities = entities;
536 options->entity2node = entity2node;
541 template <
typename T>
542 std::shared_ptr<FaceSelector<T>>
_faceSelector(
const std::shared_ptr<SelectorEngine>& engine,
const std::shared_ptr<
SelectorOptions<T>>& options,
bool buffered =
true)
544 return std::make_shared<FaceSelector<T>>(engine, options, buffered);
547 template <
typename T>
550 return std::make_shared<VertexSelector<T>>(engine, options, buffered);
553 template <
typename T>
554 std::shared_ptr<EdgeSelector<T>>
_edgeSelector(
const std::shared_ptr<SelectorEngine>& engine,
const std::shared_ptr<
SelectorOptions<T>>& options,
bool buffered =
true)
556 return std::make_shared<EdgeSelector<T>>(engine, options, buffered);
559 template <
typename T>
562 return std::make_shared<PositionSelector<T>>(engine, options, buffered);
565 template <
typename T>
568 return std::make_shared<NormalSelector<T>>(engine, options, buffered);
571 template <
typename T>
574 return std::make_shared<PrimitiveSelector<T>>(engine, options, buffered);
Definition selector.h:263
virtual void update(SelectorUpdateMode mode)
Definition selector.h:283
AttributeSelector()
Definition selector.h:274
std::shared_ptr< AttributeBuilder< T > > m_builder
Definition selector.h:265
std::shared_ptr< AttributeProducer > m_producer
Definition selector.h:266
virtual ~AttributeSelector()
Definition selector.h:279
bool m_buffered
Definition selector.h:267
std::shared_ptr< Vector3f > select(int x, int y)
Definition selector.h:307
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition selector.h:301
Definition selector.h:246
virtual ~EdgeSelector()
Definition selector.h:256
EdgeSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:248
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition selector.h:114
std::shared_ptr< EntityBuilder< T > > m_builder
Definition selector.h:79
EntitySelector()
Definition selector.h:88
std::vector< std::shared_ptr< T > > multiSelect(int x1, int y1, int x2, int y2)
Definition selector.h:140
std::shared_ptr< EntityProducer > m_producer
Definition selector.h:80
virtual ~EntitySelector()
Definition selector.h:92
bool m_buffered
Definition selector.h:81
std::shared_ptr< T > select(int x, int y)
Definition selector.h:120
virtual void update(SelectorUpdateMode mode)
Definition selector.h:96
Definition selector.h:212
FaceSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:214
virtual ~FaceSelector()
Definition selector.h:222
Definition selector.h:387
NormalSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:389
virtual ~NormalSelector()
Definition selector.h:397
Definition selector.h:370
virtual ~PositionSelector()
Definition selector.h:380
PositionSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:372
Definition selector.h:404
unsigned int select(int x, int y)
Definition selector.h:451
bool m_buffered
Definition selector.h:408
std::vector< unsigned int > multiSelect(int x1, int y1, int x2, int y2)
Definition selector.h:473
virtual void update(SelectorUpdateMode mode)
Definition selector.h:427
PrimitiveSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:415
std::shared_ptr< PrimitiveBuilder< T > > m_builder
Definition selector.h:406
std::shared_ptr< PrimitiveProducer > m_producer
Definition selector.h:407
virtual ~PrimitiveSelector()
Definition selector.h:423
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition selector.h:445
std::shared_ptr< Camera > camera
Definition selector.h:46
std::shared_ptr< Vector2i > backgroundSize
Definition selector.h:47
std::shared_ptr< Vector2i > windowSize
Definition selector.h:48
std::shared_ptr< Renderer > renderer
Definition selector.h:45
std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> entity2node
Definition selector.h:56
std::shared_ptr< std::vector< std::shared_ptr< T > > > entities
Definition selector.h:55
virtual ~Selector()
Definition selector.h:67
Selector()
Definition selector.h:63
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)=0
virtual void update(SelectorUpdateMode mode)=0
Definition selector.h:229
VertexSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:231
virtual ~VertexSelector()
Definition selector.h:239
SelectorUpdateMode
Definition selector.h:35
std::shared_ptr< Vector3f > _vec3()
std::shared_ptr< VertexSelector< T > > _vertexSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:548
std::shared_ptr< NormalSelector< T > > _normalSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:566
std::shared_ptr< FaceSelector< T > > _faceSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:542
std::shared_ptr< PrimitiveSelector< T > > _primitiveSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:572
std::shared_ptr< SelectorEngine > _selectorEngine(const std::shared_ptr< Renderer > &renderer, const std::shared_ptr< Camera > &camera, const std::shared_ptr< Vector2i > &backgroundSize, const std::shared_ptr< Vector2i > &windowSize)
std::shared_ptr< EdgeSelector< T > > _edgeSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:554
std::shared_ptr< PositionSelector< T > > _positionSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:560
std::shared_ptr< SelectorOptions< T > > _selectorOptions(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition selector.h:532