Skip to main content

Rocky Solver SDK 2025 R2

rocky_point_cloud

Last update: 16.07.2025
1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
2#pragma once
3
4#include <rocky20/model/point_cloud.h>
5
6// Forward declarations ===========================================================================
7class cuda_host;
8typedef cuda_host RockyModel;
9struct IRockyModel;
10
11namespace rocky20
12{
13class PointCloudCollection;
14}
15
16namespace device
17{
18struct PointCloud;
19}
20
21// ================================================================================================
22// RockyPointCloud
23// ================================================================================================
24struct RockyPointCloud
25{
26 inline ROCKY_FUNCTIONS int get_n_points() const
27 {
28 return this->point_cloud->n_points;
29 }
30
31 inline ROCKY_FUNCTIONS int get_n_properties() const
32 {
33 return this->point_cloud->scalars->get_n_scalar_arrays();
34 }
35
36 inline ROCKY_FUNCTIONS double3 get_point_position(int point_index) const
37 {
38 return this->point_cloud->get_point_position(point_index);
39 }
40
41 template <class DataType = double>
42 inline ROCKY_FUNCTIONS DataType get_point_property(int point_index, int property_index) const
43 {
44 return this->point_cloud->get_point_property<DataType>(point_index, property_index);
45 }
46
47 device::PointCloud *point_cloud;
48};
49
50// ================================================================================================
51// RockyPointCloudController
52// ================================================================================================
53struct RockyPointCloudController
54{
55 explicit RockyPointCloudController(IRockyModel& _model);
56 explicit RockyPointCloudController(const IRockyModel& _model);
57
58 ~RockyPointCloudController();
59
60 int find_point_cloud(const std::string& point_cloud_name)
61 {
62 return this->pc_data->get_point_cloud_index(point_cloud_name);
63 }
64
65 int find_property(int point_cloud_index, const std::string& property_name)
66 {
67 auto pc = this->pc_data->at(point_cloud_index);
68 return pc->find_property(property_name);
69 }
70
71 void set_property_dimension(int point_cloud_index, int property_index, double dimension)
72 {
73 auto pc = this->pc_data->at(point_cloud_index);
74 pc->set_property_dimension(property_index, dimension);
75 }
76
77 void set_geometry_as_static(int point_cloud_index)
78 {
79 auto pc = this->pc_data->at(point_cloud_index);
80 pc->set_geometry_transient(false);
81
82 // If set geometry as static and no property is transient, we have a static point cloud
83 if (!pc->is_any_property_transient())
84 {
85 pc->set_transient(false);
86 }
87 }
88
89 void set_property_as_static(int point_cloud_index, int property_index)
90 {
91 auto pc = this->pc_data->at(point_cloud_index);
92 pc->scalars_controller.set_transient_attribute(property_index, false);
93
94 // If geometry is static and point cloud has no transient property, it is static
95 if (!pc->is_geometry_transient() && !pc->is_any_property_transient())
96 {
97 pc->set_transient(false);
98 }
99 }
100
109 template <class DataType = double>
110 int add_property(
111 int point_cloud_index,
112 const std::string& name,
113 const std::string& unit,
114 rocky20::ScalarsInfo::CollectiveOperationType collective_type =
115 rocky20::ScalarsInfo::cotIntegrated,
116 bool write = true)
117 {
118 PointCloud* pc = this->pc_data->at(point_cloud_index);
119 auto& scalars = pc->scalars_controller;
120
121 auto scalar_index = scalars.add_scalars(
122 sizeof(DataType),
123 name,
124 unit,
125 -1,
126 rocky20::get_scalars_data_type<DataType>(),
127 collective_type,
128 write ? static_cast<uint32_t>(rocky20::ScalarsInfo::sWrite) : static_cast<uint32_t>(0),
129 0);
130
131 // By default, properties added using this method are transient.
132 scalars.set_transient_attribute(scalar_index, true);
133 if (pc->get_n_points() > scalars.get_scalars_array_size())
134 scalars.resize(pc->get_n_points());
135 return scalar_index;
136 }
137
147 int add_point_cloud(const std::string& point_cloud_name, const std::vector<double3>& points);
148
155 int add_point_cloud(const std::string& point_cloud_name);
156
165 void enable_search_cut_off_distance(int point_cloud_index) const;
166
171 void disable_search_cut_off_distance(int point_cloud_index) const;
172
177 void enable_point_cloud(int point_cloud_index);
178
183 void disable_point_cloud(int point_cloud_index);
184
193 void update_point_cloud_geometry(
194 int point_cloud_index, const std::vector<double3>& new_coordinates);
195
204 template <class DataType = double>
205 void update_point_cloud_property(
206 int point_cloud_index, int property_index, const std::vector<DataType>& property_values)
207 {
208 auto pc = this->pc_data->at(point_cloud_index);
209 auto& scalars = pc->scalars_controller;
210
211 // Block property changes if the target property is static
212 if (!pc->is_new_point_cloud() && !pc->is_property_transient(property_index))
213 {
214 auto& name = pc->scalars_controller.scalars_info[property_index].name;
215 ROCKY_RUNTIME_ERROR(
216 "Cannot update the static property \"" << name << "\" of the point cloud.")
217 }
218
219 // Must match in size of the number of points, either from the pc_data or from the point
220 // cloud controller pc_points if it has already changed. pc_data will only change at the
221 // destructor
222 int n_points = pc->get_n_points();
223 if (n_points == 0)
224 {
225 ROCKY_RUNTIME_ERROR("Cannot update property of a Point Cloud without any points.")
226 }
227
228 if (pc->must_build_kd_tree())
229 {
230 // get size from pc_points instead
231 n_points = this->pc_points[point_cloud_index].size();
232 }
233
234 if (n_points != property_values.size())
235 {
236 ROCKY_RUNTIME_ERROR(
237 "Size mismatch between number of point cloud coordinates and properties.")
238 }
239
240 const int n_vars = pc->get_n_properties();
241 if (property_index >= n_vars)
242 {
243 ROCKY_RUNTIME_ERROR("Point Cloud property index mismatch.")
244 }
245
246 // Register that the property was updated, and we need to non dimensionalize it later.
247 scalars.set_updated_property_attribute(property_index, true);
248 scalars.set_updated_by_geometry_attribute(property_index, false);
249
250 // Assign new values for property
251 auto data = scalars.get_scalars<DataType>(property_index);
252 std::copy_n(property_values.begin(), n_points, data);
253
254 pc->set_update_property(true);
255 this->any_change = true;
256 }
257
266 void update_point_cloud_topology(
267 int point_cloud_index, const std::vector<double3>& new_coordinates);
268
269 static void setup_scalars(
270 cuda_host& solver_model, rocky20::PointCloudCollection& pc_data_collection);
271
277 bool is_enabled(int point_cloud_index) const;
278
279private:
280 RockyModel* model;
281 rocky20::PointCloudCollection* pc_data;
282
283 // Temporary input arrays to build point cloud kd tree and properties
284 std::vector<std::vector<KDTreePoints>> pc_points;
285
286 bool any_change { false };
287};
Definition rocky_api.h:58

Connect with Ansys