API Documentation
Loading...
Searching...
No Matches
ModelTiler.h
Go to the documentation of this file.
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: ModelTiler
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Model.h>
34#if NDEVR_MODEL_TILE_CONTAINER
35#include <NDEVR/Geometry.h>
36#include <NDEVR/AngleDefinitions.h>
37#include <NDEVR/MatrixFunctions.h>
38namespace NDEVR
39{
40 /**--------------------------------------------------------------------------------------------------
41 \brief Logic for tiling a model along a line or across a surface at a set interval.
42 **/
43 class ModelTiler
44 {
45 public:
46 enum TileMode
47 {
48 e_vertex_random
49 , e_vertex_even
50 };
51 struct TileOptions
52 {
53 Model parent;
54 Model model_to_tile;
55 Buffer<Model> old_model_pool;//models to be re-used (must be a copy of "model_to_tile"
56 Buffer<Model> new_models_added;//models created during the process
57 Matrix<fltp08> source_transform = Matrix<fltp08>(1.0);
58 Matrix<fltp08> model_to_tile_transform = Matrix<fltp08>(1.0);
59 LineSegment<3, fltp08> placement_segment;
60 bool use_heading = true;
61 bool use_inclination = true;
62 };
63 static Model RootChild(TileOptions& options)
64 {
65 Model root_child;
66 if (options.old_model_pool.size() > 0)
67 {
68 root_child = options.old_model_pool.last();
69 options.old_model_pool.removeLast();
70 }
71 else
72 {
73 root_child = options.parent.createChild();
74 root_child.copyFrom(options.model_to_tile, options.model_to_tile.getScene().uuid() != options.parent.getScene().uuid());
75 options.new_models_added.add(root_child);
76 }
77 return root_child;
78 }
79 static Model IndexChild(uint04 index, const Model& root_child, TileOptions& options)
80 {
81 Model child;
82 if (index == 0)
83 {
84 child = root_child;
85 }
86 else if (options.old_model_pool.size() > 0)
87 {
88 child = options.old_model_pool.last();
89 options.old_model_pool.removeLast();
90 }
91 else
92 {
93 child = options.parent.createChild();
94 child.copyFrom(root_child, false);
95 options.new_models_added.add(child);
96 }
97 return child;
98 }
99 static void TileAlongGeo(const Geometry& linework, TileOptions& options)
100 {
101 if (linework.getGeometryType() == GeometryType::e_linework)
102 {
103 //bool is_closed = linework.getGeometryProperty<bool>(Geometry::e_has_closed_primitive);
104 Buffer<Polyline<3, fltp08>> polylines = linework.polylines<3, fltp08>(PrimitiveProperty::Outline, VertexProperty::Position);
105 //Extrude Shape
106 for (uint04 i = 0; i < polylines.size(); i++)
107 {
108 polylines[i].simplify();
109 TileModelAlongLine(polylines[i], options);
110 }
111 }
112 /*
113
114
115 for (uint04 i = 0; i < broken_poly.vertexCount(); i++)
116 {
117 Model child = IndexChild(i, root_child, options);
118 Matrix<fltp08> mat = Matrix<fltp08>::OffsetMatrix(broken_poly.vertex(i));
119 uint04 segment_index = getMin(broken_poly.segmentCount() - 1, i);
120 if(options.use_heading)
121 mat = mat.rotate(AngleDefinitions::Heading<sint04>(broken_poly.segment(segment_index).ray()), Vector<3, fltp08>(0, 0, 1));
122 if(options.use_inclination)
123 mat = mat.rotate(-AngleDefinitions::Inclination<sint04>(broken_poly.segment(segment_index).ray()), Vector<3, fltp08>(0, 1, 0));
124 mat = parent_transform * mat * dest_transform;
125 child.setTransform(mat);
126 }
127 */
128 else if (linework.getGeometryType() == GeometryType::e_points)
129 {
130 Buffer<Vertex<3, fltp08>> vertices = linework.vertices<Vertex<3, fltp08>>(VertexProperty::Position);
131 Model root_child = RootChild(options);
132 const Matrix<fltp08> dest_transform = options.model_to_tile_transform * options.model_to_tile.getCompleteTransform();
133 const Matrix<fltp08> parent_transform = options.parent.getCompleteTransform().invert();
134 for (uint04 i = 0; i < vertices.size(); i++)
135 {
136 if (IsInvalid(vertices[i]))
137 continue;
138 Model child = IndexChild(i, root_child, options);
139 Matrix<fltp08> mat = Matrix<fltp08>::OffsetMatrix(options.source_transform * vertices[i]);
140 mat = parent_transform * mat * dest_transform;
141 child.setTransform(mat);
142 }
143 }
144 }
145 static void TileModelAlongLine(const Polyline<3, fltp08>& extrude_path, TileOptions& options)
146 {
147 fltp08 distance = options.placement_segment.ray()[X];
148 Polyline<3, fltp08> broken_poly = options.source_transform * extrude_path;
149 broken_poly = broken_poly.breakIntoSegmentsByDistance(distance);
150 if (broken_poly.segmentCount() == 0)
151 return;
152 Model root_child = RootChild(options);
153 //Vertex<3, fltp08> model_offset = model_to_tile.getTransform() * seg.vertex(A);
154 //Angle heading_angle = AngleDefinitions::Heading<sint04>(seg.ray());
155 //Angle inclination_angle = AngleDefinitions::Inclination(seg.ray());
156 const Matrix<fltp08> dest_transform = options.model_to_tile_transform * options.model_to_tile.getCompleteTransform();
157 const Matrix<fltp08> parent_transform = options.parent.getCompleteTransform().invert();
158 for (uint04 i = 0; i < broken_poly.vertexCount(); i++)
159 {
160 Model child = IndexChild(i, root_child, options);
161 Matrix<fltp08> mat = Matrix<fltp08>::OffsetMatrix(broken_poly.vertex(i));
162 uint04 segment_index = getMin(broken_poly.segmentCount() - 1, i);
163 if(options.use_heading)
164 mat = mat.rotate(AngleDefinitions::Heading<sint04>(broken_poly.segment(segment_index).ray()), Vector<3, fltp08>(0, 0, 1));
165 if(options.use_inclination)
166 mat = mat.rotate(-AngleDefinitions::Inclination<sint04>(broken_poly.segment(segment_index).ray()), Vector<3, fltp08>(0, 1, 0));
167 mat = parent_transform * mat * dest_transform;
168 child.setTransform(mat);
169 }
170 }
171
172 };
173}
174#endif
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_type distance(const t_vertex &vertex, const LineSegment< t_dims, t_type, t_vertex > &line)
Definition Distance.hpp:171
@ X
Definition BaseValues.hpp:167
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
Definition BaseFunctions.hpp:56