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