NDEVR
API Documentation
ModelIterator.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: ModelIterator
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Model.h>
34#include <NDEVR/Geometry.h>
35#include <functional>
36namespace NDEVR
37{
48 class NDEVR_DESIGN_API ModelIterator
49 {
50 public:
60
65
70 explicit ModelIterator(const Model& model);
71
76 explicit ModelIterator(Buffer<Model> models);
77
82 void parseAll(const Model& model);
83
88 void parseAllChildren(const Model& parent);
89
94 void parseAllModels(const Buffer<Model>& models);
95
100 void addToStack(const Model& model);
101
105 void parseAll();
106
112
118
119 std::function<bool(const Model&, const Geometry&)> geo_filter;
120 std::function<bool(const Model&, const Material&)> material_filter;
121 std::function<bool(const Model&)> model_filter;
122
123 bool process_material = false;
124 bool process_geometry = true;
125 bool process_model = true;
126 bool post_process_model = false;
127 bool depth_first = true;
128 bool is_recursive = true;
129 bool use_unit = false;
130
131 protected:
137 virtual ParseResult process(Model& model);
138
145 virtual ParseResult process(Model& model, Material& mat);
146
153 virtual ParseResult process(Model& model, Geometry& geo);
154
161
166
170 virtual void _parseAllModels();
171
177
181 };
182
189 class NDEVR_DESIGN_API BasicModelIterator : public ModelIterator
190 {
191 public:
196
201 explicit BasicModelIterator(const Model& model);
202
207 explicit BasicModelIterator(const Buffer<Model>& models);
208
213 explicit BasicModelIterator(const std::function<ParseResult(Model&, Geometry&)>& geo_callback);
214
219 explicit BasicModelIterator(const std::function<ParseResult(Model&, Material&)>& material_callback);
220
225 explicit BasicModelIterator(const std::function<ParseResult(Model&)>& model_callback);
226
231 void setCallback(const std::function<ParseResult(Model&, Geometry&)>& geo_callback);
232
237 void setCallback(const std::function<ParseResult(Model&, Material&)>& material_callback);
238
243 void setCallback(const std::function<ParseResult(Model&)>& model_callback);
244
245 protected:
251 ParseResult process(Model& model) final override;
252
259 ParseResult process(Model& model, Material& mat) final override;
260
267 ParseResult process(Model& model, Geometry& geo) final override;
268
269 protected:
273 };
274}
275
276
277
278
BasicModelIterator(const Buffer< Model > &models)
Constructs an iterator initialized with multiple root models.
void setCallback(const std::function< ParseResult(Model &, Material &)> &material_callback)
Sets the callback invoked for each material during traversal.
void setCallback(const std::function< ParseResult(Model &, Geometry &)> &geo_callback)
Sets the callback invoked for each geometry during traversal.
BasicModelIterator(const std::function< ParseResult(Model &)> &model_callback)
Constructs an iterator with a model processing callback.
ParseResult process(Model &model) final override
Dispatches to m_model_callback if set; otherwise returns e_continue_parsing.
BasicModelIterator(const Model &model)
Constructs an iterator initialized with a single root model.
ParseResult process(Model &model, Geometry &geo) final override
Dispatches to m_geo_callback if set; otherwise returns e_continue_parsing.
std::function< ParseResult(Model &)> m_model_callback
Callback invoked for each model during traversal.
BasicModelIterator(const std::function< ParseResult(Model &, Geometry &)> &geo_callback)
Constructs an iterator with a geometry processing callback.
void setCallback(const std::function< ParseResult(Model &)> &model_callback)
Sets the callback invoked for each model during traversal.
BasicModelIterator(const std::function< ParseResult(Model &, Material &)> &material_callback)
Constructs an iterator with a material processing callback.
std::function< ParseResult(Model &, Geometry &)> m_geo_callback
Callback invoked for each geometry during traversal.
ParseResult process(Model &model, Material &mat) final override
Dispatches to m_material_callback if set; otherwise returns e_continue_parsing.
std::function< ParseResult(Model &, Material &)> m_material_callback
Callback invoked for each material during traversal.
BasicModelIterator()
Default constructor.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:153
bool use_unit
Whether to apply unit conversions during processing.
void parseAll(const Model &model)
Parses the given model and all of its descendants.
void parseAllChildren(const Model &parent)
Parses all children of the given parent model, but not the parent itself.
virtual ParseResult postProcess(Model &model)
Called after all children of a model have been processed, when post_process_model is true.
bool depth_first
Whether to traverse depth-first (true) or breadth-first (false).
virtual void _parseAllModels()
Internal method that drives the main parsing loop over all stacked models.
bool process_material
Whether to invoke process() for each Material on a model.
Buffer< std::pair< Model, uint04 > > m_model_parent_stack
Stack tracking parent models and their child indices for post-processing.
ParseResult parseNext()
Parses the next model on the stack, processing it and optionally its geometry and material.
std::function< bool(const Model &, const Material &)> material_filter
Optional filter predicate for material processing. Returns true to include.
ModelIterator(const Model &model)
Constructs an iterator initialized with a single root model.
std::function< bool(const Model &)> model_filter
Optional filter predicate for model processing. Returns true to include.
std::function< bool(const Model &, const Geometry &)> geo_filter
Optional filter predicate for geometry processing. Returns true to include.
uint04 m_forward_position
Current forward index position used in breadth-first traversal.
Model currentModel() const
Returns the model currently at the top of the traversal stack.
ModelIterator(Buffer< Model > models)
Constructs an iterator initialized with multiple root models.
bool post_process_model
Whether to invoke postProcess() after a model's children have been parsed.
Buffer< Model > m_model_stack
The stack of models pending traversal.
void removeFromPostProcessStack()
Removes the current model from the post-process stack.
void parseAll()
Parses all models currently on the internal stack and their descendants.
void addToStack(const Model &model)
Adds a model to the internal traversal stack without starting iteration.
ParseResult
The result returned by process functions to control iteration flow.
@ e_continue_parsing
Continue normal traversal to sibling and child nodes.
@ e_do_not_parse_children
Skip the children of the current node but continue with siblings.
@ e_finish_parsing
Stop all traversal immediately.
bool process_geometry
Whether to invoke process() for each Geometry on a model.
ModelIterator()
Default constructor.
virtual ParseResult process(Model &model, Geometry &geo)
Called for each geometry associated with a model.
virtual ParseResult process(Model &model)
Called for each model node during traversal.
void parseAllModels(const Buffer< Model > &models)
Parses all models in the given buffer and their descendants.
Model popNextModel()
Pops and returns the next model from the traversal stack.
bool is_recursive
Whether to recurse into child models.
bool process_model
Whether to invoke process() for the model itself.
virtual ParseResult process(Model &model, Material &mat)
Called for each material associated with a model.
A core class that represents a node on model hierarchy.
Definition Model.h:292
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...