55 std::shared_ptr<std::vector<std::shared_ptr<T>>>
entities;
56 std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>
entity2node;
85 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities) = 0;
97 std::shared_ptr<std::vector<std::shared_ptr<Node>>> m_builtNodes;
98 std::shared_ptr<Image2D> m_bufferImage;
114 this->m_bufferImage =
nullptr;
119 this->m_builtNodes =
nullptr;
120 this->m_bufferImage =
nullptr;
127 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
129 this->m_builder->setEntities(entities);
136 if (this->m_buffered)
138 this->produceBufferImage();
139 auto consumer = std::make_shared<PixelConsumer>(this->m_producer->windowSize());
140 auto pixelIndex = consumer->select(x, y);
141 unsigned int entityIndex = ((
unsigned int*)this->m_bufferImage->data())[pixelIndex];
142 return entityIndex != 0XFFFFFFFF ? (*this->m_builder->entities())[entityIndex] :
nullptr;
146 this->m_producer->toPixel(x, y);
147 auto image = this->m_producer->produce(this->m_builtNodes);
148 unsigned int entityIndex = ((
unsigned int*)image->data())[0];
149 return entityIndex != 0XFFFFFFFF ? (*this->m_builder->entities())[entityIndex] :
nullptr;
153 std::vector<std::shared_ptr<T>>
multiSelect(
int x1,
int y1,
int x2,
int y2)
156 if (this->m_buffered)
158 this->produceBufferImage();
159 auto consumer = std::make_shared<BoxConsumer>(this->m_producer->windowSize());
160 std::vector<int> pixelIndices = consumer->select(x1, y1, x2, y2);
162 std::set<unsigned int> entityIndices;
163 auto imageData = (
unsigned int*)this->m_bufferImage->data();
164 for (
auto pixelIndex : pixelIndices)
166 entityIndices.insert(imageData[pixelIndex]);
168 entityIndices.erase(0XFFFFFFFF);
170 std::vector<std::shared_ptr<T>> result;
171 auto& entities = *this->m_builder->entities();
172 for (
auto entityIndex : entityIndices)
174 result.push_back(entities[entityIndex]);
181 this->m_producer->toBox(x1, y1, x2, y2);
182 auto image = this->m_producer->produce(this->m_builtNodes);
184 std::set<unsigned int> entityIndices;
185 auto imageData = (
unsigned int*)image->data();
186 auto length = image->width() * image->height();
187 for (
int i = 0; i < length; ++i)
189 entityIndices.insert(imageData[i]);
191 entityIndices.erase(0XFFFFFFFF);
193 std::vector<std::shared_ptr<T>> result;
194 auto& entities = *this->m_builder->entities();
195 for (
auto entityIndex : entityIndices)
197 result.push_back(entities[entityIndex]);
207 if (!this->m_builtNodes)
209 this->m_builtNodes = this->m_builder->build();
210 this->m_producer->updatePass();
214 void produceBufferImage()
216 if (!this->m_bufferImage) {
217 this->m_producer->toWindow();
218 this->m_bufferImage = this->m_producer->produce(this->m_builtNodes);
223 template <
typename T>
230 this->m_builder = std::make_shared<FaceBuilder<T>>(options->entities, options->entity2node);
231 this->m_producer = std::make_shared<FaceProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
232 this->m_buffered = buffered;
240 template <
typename T>
247 this->m_builder = std::make_shared<VertexBuilder<T>>(options->entities, options->entity2node);
248 this->m_producer = std::make_shared<VertexProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
249 this->m_buffered = buffered;
257 template <
typename T>
264 this->m_builder = std::make_shared<EdgeBuilder<T>>(options->entities, options->entity2node);
265 this->m_producer = std::make_shared<EdgeProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
266 this->m_buffered = buffered;
274 template <
typename T>
283 std::shared_ptr<std::vector<std::shared_ptr<Node>>> m_builtNodes;
284 std::vector<std::shared_ptr<Image2D>> m_bufferImages;
301 this->m_bufferImages.clear();
306 this->m_builtNodes =
nullptr;
307 this->m_bufferImages.clear();
314 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
316 this->m_builder->setEntities(entities);
320 std::shared_ptr<Vector3f>
select(
int x,
int y)
323 if (this->m_buffered)
325 this->produceBufferImages();
326 auto consumer = std::make_shared<PixelConsumer>(this->m_producer->windowSize());
327 auto pixelIndex = consumer->select(x, y);
328 unsigned int value = ((
unsigned int*)this->m_bufferImages[0]->data())[pixelIndex];
329 if (value != 0XFFFFFFFF)
331 auto x = ((
float*)this->m_bufferImages[0]->data())[pixelIndex];
332 auto y = ((
float*)this->m_bufferImages[1]->data())[pixelIndex];
333 auto z = ((
float*)this->m_bufferImages[2]->data())[pixelIndex];
335 return _vec3(x, y, z);
344 this->m_producer->toPixel(x, y);
345 auto images = this->m_producer->produce(this->m_builtNodes);
346 unsigned int value = ((
unsigned int*)images[0]->data())[0];
347 if (value != 0XFFFFFFFF)
349 auto x = ((
float*)images[0]->data())[0];
350 auto y = ((
float*)images[1]->data())[0];
351 auto z = ((
float*)images[2]->data())[0];
353 return _vec3(x, y, z);
365 if (!this->m_builtNodes)
367 this->m_builtNodes = this->m_builder->build();
368 this->m_producer->updatePass();
372 void produceBufferImages()
374 if (this->m_bufferImages.size() == 0) {
375 this->m_producer->toWindow();
376 this->m_bufferImages = this->m_producer->produce(this->m_builtNodes);
381 template <
typename T>
388 this->m_builder = std::make_shared<PositionBuilder<T>>(options->entities, options->entity2node);
389 this->m_producer = std::make_shared<PositionProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
390 this->m_buffered = buffered;
398 template <
typename T>
405 this->m_builder = std::make_shared<NormalBuilder<T>>(options->entities, options->entity2node);
406 this->m_producer = std::make_shared<NormalProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
407 this->m_buffered = buffered;
415 template <
typename T>
424 std::shared_ptr<std::vector<std::shared_ptr<Node>>> m_builtNodes;
425 std::shared_ptr<Image2D> m_bufferImage;
431 this->m_builder = std::make_shared<PrimitiveBuilder<T>>(options->entities, options->entity2node);
432 this->m_producer = std::make_shared<PrimitiveProducer>(engine->renderer, engine->camera, engine->backgroundSize, engine->windowSize);
433 this->m_buffered = buffered;
445 this->m_bufferImage =
nullptr;
450 this->m_builtNodes =
nullptr;
451 this->m_bufferImage =
nullptr;
458 virtual void setEntities(
const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
460 this->m_builder->setEntities(entities);
467 if (this->m_buffered)
469 this->produceBufferImage();
470 auto consumer = std::make_shared<PixelConsumer>(this->m_producer->windowSize());
471 auto pixelIndex = consumer->select(x, y);
472 unsigned int primitiveIndex = ((
unsigned int*)this->m_bufferImage->data())[pixelIndex];
474 return primitiveIndex;
478 this->m_producer->toPixel(x, y);
479 auto image = this->m_producer->produce(this->m_builtNodes);
480 unsigned int primitiveIndex = ((
unsigned int*)image->data())[0];
482 return primitiveIndex;
486 std::vector<unsigned int>
multiSelect(
int x1,
int y1,
int x2,
int y2)
489 if (this->m_buffered)
491 this->produceBufferImage();
492 auto consumer = std::make_shared<BoxConsumer>(this->m_producer->windowSize());
493 std::vector<int> pixelIndices = consumer->select(x1, y1, x2, y2);
495 std::set<unsigned int> primitiveIndices;
496 auto imageData = (
unsigned int*)this->m_bufferImage->data();
497 for (
auto pixelIndex : pixelIndices)
499 primitiveIndices.insert(imageData[pixelIndex]);
501 primitiveIndices.erase(0XFFFFFFFF);
503 return std::vector<unsigned int>(primitiveIndices.begin(), primitiveIndices.end());
507 this->m_producer->toBox(x1, y1, x2, y2);
508 auto image = this->m_producer->produce(this->m_builtNodes);
509 auto imageData = (
unsigned int*)image->data();
511 std::set<unsigned int> primitiveIndices;
512 auto length = image->width() * image->height();
513 for (
int i = 0; i < length; ++i)
515 primitiveIndices.insert(imageData[i]);
517 primitiveIndices.erase(0XFFFFFFFF);
519 return std::vector<unsigned int>(primitiveIndices.begin(), primitiveIndices.end());
526 if (!this->m_builtNodes)
528 this->m_builtNodes = this->m_builder->build();
529 this->m_producer->updatePass();
533 void produceBufferImage()
535 if (!this->m_bufferImage) {
536 this->m_producer->toWindow();
537 this->m_bufferImage = this->m_producer->produce(this->m_builtNodes);
542 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);
544 template <
typename T>
545 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)
547 auto options = std::make_shared<SelectorOptions<T>>();
548 options->entities = entities;
549 options->entity2node = entity2node;
554 template <
typename T>
555 std::shared_ptr<FaceSelector<T>>
_faceSelector(
const std::shared_ptr<SelectorEngine>& engine,
const std::shared_ptr<
SelectorOptions<T>>& options,
bool buffered =
true)
557 return std::make_shared<FaceSelector<T>>(engine, options, buffered);
560 template <
typename T>
563 return std::make_shared<VertexSelector<T>>(engine, options, buffered);
566 template <
typename T>
567 std::shared_ptr<EdgeSelector<T>>
_edgeSelector(
const std::shared_ptr<SelectorEngine>& engine,
const std::shared_ptr<
SelectorOptions<T>>& options,
bool buffered =
true)
569 return std::make_shared<EdgeSelector<T>>(engine, options, buffered);
572 template <
typename T>
575 return std::make_shared<PositionSelector<T>>(engine, options, buffered);
578 template <
typename T>
581 return std::make_shared<NormalSelector<T>>(engine, options, buffered);
584 template <
typename T>
587 return std::make_shared<PrimitiveSelector<T>>(engine, options, buffered);
Definition selector.h:276
virtual void update(SelectorUpdateMode mode)
Definition selector.h:296
AttributeSelector()
Definition selector.h:287
std::shared_ptr< AttributeBuilder< T > > m_builder
Definition selector.h:278
std::shared_ptr< AttributeProducer > m_producer
Definition selector.h:279
virtual ~AttributeSelector()
Definition selector.h:292
bool m_buffered
Definition selector.h:280
std::shared_ptr< Vector3f > select(int x, int y)
Definition selector.h:320
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition selector.h:314
BaseSelector()
Definition selector.h:75
virtual ~BaseSelector()
Definition selector.h:80
virtual void update(SelectorUpdateMode mode)=0
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)=0
Definition selector.h:259
virtual ~EdgeSelector()
Definition selector.h:269
EdgeSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:261
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition selector.h:127
std::shared_ptr< EntityBuilder< T > > m_builder
Definition selector.h:92
EntitySelector()
Definition selector.h:101
std::vector< std::shared_ptr< T > > multiSelect(int x1, int y1, int x2, int y2)
Definition selector.h:153
std::shared_ptr< EntityProducer > m_producer
Definition selector.h:93
virtual ~EntitySelector()
Definition selector.h:105
bool m_buffered
Definition selector.h:94
std::shared_ptr< T > select(int x, int y)
Definition selector.h:133
virtual void update(SelectorUpdateMode mode)
Definition selector.h:109
Definition selector.h:225
FaceSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:227
virtual ~FaceSelector()
Definition selector.h:235
Definition selector.h:400
NormalSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:402
virtual ~NormalSelector()
Definition selector.h:410
Definition selector.h:383
virtual ~PositionSelector()
Definition selector.h:393
PositionSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:385
Definition selector.h:417
unsigned int select(int x, int y)
Definition selector.h:464
bool m_buffered
Definition selector.h:421
std::vector< unsigned int > multiSelect(int x1, int y1, int x2, int y2)
Definition selector.h:486
virtual void update(SelectorUpdateMode mode)
Definition selector.h:440
PrimitiveSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=false)
Definition selector.h:428
std::shared_ptr< PrimitiveBuilder< T > > m_builder
Definition selector.h:419
std::shared_ptr< PrimitiveProducer > m_producer
Definition selector.h:420
virtual ~PrimitiveSelector()
Definition selector.h:436
virtual void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition selector.h:458
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:66
Selector()
Definition selector.h:62
Definition selector.h:242
VertexSelector(const std::shared_ptr< SelectorEngine > &engine, const std::shared_ptr< SelectorOptions< T > > &options, bool buffered=true)
Definition selector.h:244
virtual ~VertexSelector()
Definition selector.h:252
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:561
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:579
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:555
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:585
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:567
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:573
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:545