15 #ifndef __CONTACT_SEARCH_KD_TREE__
16 #define __CONTACT_SEARCH_KD_TREE__
46 typedef multi_index_container<
47 boost::shared_ptr<ContactCommonData>,
67 &*v_n.data().begin(), &*v_s1.data().begin(),
68 &*v_s2.data().begin());
74 double s1_mag = sqrt(t_s1(
i) * t_s1(
i));
75 double n_mag = sqrt(t_n(
i) * t_n(
i));
81 for (
int ii = 0; ii != 3; ++ii) {
82 m_rot(0, ii) = t_s1(ii);
83 m_rot(1, ii) = t_s2(ii);
84 m_rot(2, ii) = t_n(ii);
99 &*n_vec.data().begin(), s1, s2);
102 double n_mag = sqrt(t_n(
i) * t_n(
i));
115 boost::shared_ptr<ContactCommonData_multiIndex>
116 contact_commondata_multi_index,
117 Range &range_slave_master_prisms) {
129 Paths path_slave(1), path_master(1), solution;
135 double roundfact = 1e6;
138 Range tris_in_polygon;
141 v_slave_tri_cent.resize(3,
false);
144 v_coords_slave_new.resize(9,
false);
147 m_rot.resize(3, 3,
false);
150 n_vec.resize(3,
false);
153 v_coords_slave.resize(9,
false);
157 for (Range::iterator tri_it_slave = range_surf_slave.begin();
158 tri_it_slave != range_surf_slave.end(); ++tri_it_slave) {
172 for (
int ii = 0; ii != 3; ++ii) {
173 prism_nodes[ii + 3] = conn_slave[ii];
177 &*v_coords_slave.data().begin());
179 auto t_coords_slave = get_tensor_vec(v_coords_slave);
185 &m_rot(0, 0), &m_rot(0, 1), &m_rot(0, 2), &m_rot(1, 0), &m_rot(1, 1),
186 &m_rot(1, 2), &m_rot(2, 0), &m_rot(2, 1), &m_rot(2, 2)};
189 auto t_slave_normal = get_tensor_vec(n_vec);
194 auto t_coords_slave_new = get_tensor_vec(v_coords_slave_new);
196 auto t_slave_tri_cent = get_tensor_vec(v_slave_tri_cent);
197 t_slave_tri_cent(
i) = 0;
200 for (
int ii = 0; ii != 3; ++ii) {
201 t_coords_slave_new(
i) = t_m_rot(
i,
j) * t_coords_slave(
j);
202 t_slave_tri_cent(
i) += t_coords_slave(
i) / 3;
204 z_shift = v_coords_slave_new[2];
206 t_coords_slave_new(2) = 0;
207 ++t_coords_slave_new;
212 v_coords_slave_new = roundfact * v_coords_slave_new;
215 path_slave[0].clear();
216 path_slave[0] << IntPoint(v_coords_slave_new[0], v_coords_slave_new[1])
217 << IntPoint(v_coords_slave_new[3], v_coords_slave_new[4])
218 << IntPoint(v_coords_slave_new[6], v_coords_slave_new[7]);
225 Range range_closest_master_tris;
226 range_closest_master_tris.clear();
227 double closest_point[3];
230 &*v_slave_tri_cent.data().begin(),
231 closest_point, closest_master_tri);
233 range_closest_master_tris.insert(closest_master_tri);
237 bool flag_first_master =
240 bool flag_end_of_search =
false;
241 bool flag_temp =
true;
242 while (flag_end_of_search ==
false) {
244 Range range_master_tris_on_surf_new;
245 if (flag_first_master ==
true) {
246 range_master_tris_on_surf_new = range_closest_master_tris;
247 flag_first_master =
false;
254 Range range_adj_entities;
261 range_conn, 2,
false, range_adj_entities, moab::Interface::UNION);
264 Range range_master_tris_on_surf =
265 intersect(range_surf_master, range_adj_entities);
269 range_master_tris_on_surf_new =
270 subtract(range_master_tris_on_surf, range_closest_master_tris);
275 v_coords_master.resize(9,
false);
278 n_vec_master.resize(3,
false);
282 v_coords_master_new.resize(9,
false);
288 int num_intersections = 0;
289 for (Range::iterator tri_it_master =
290 range_master_tris_on_surf_new.begin();
291 tri_it_master != range_master_tris_on_surf_new.end();
294 int num_nodes_master = 0;
299 &*v_coords_master.data().begin());
301 auto t_coords_master = get_tensor_vec(v_coords_master);
305 auto t_master_normal = get_tensor_vec(n_vec_master);
308 if (fabs(t_slave_normal(
i) * t_master_normal(
i)) < 0.035)
311 auto t_coords_master_new = get_tensor_vec(v_coords_master_new);
315 for (
int ii = 0; ii != 3; ++ii) {
316 t_coords_master_new(
i) = t_m_rot(
i,
j) * t_coords_master(
j);
317 t_coords_master_new(2) = 0;
318 ++t_coords_master_new;
322 v_coords_master_new = roundfact * v_coords_master_new;
323 path_master[0].clear();
325 << IntPoint(v_coords_master_new[0], v_coords_master_new[1])
326 << IntPoint(v_coords_master_new[3], v_coords_master_new[4])
327 << IntPoint(v_coords_master_new[6], v_coords_master_new[7]);
332 c.AddPaths(path_slave,
ptClip,
true);
335 if (solution.size() != 1 && flag_temp) {
337 CHKERR Tools::getTriNormal(&v_coords_slave(0), ray_dir);
338 double norm = cblas_dnrm2(3, ray_dir, 1);
339 cblas_dscal(3, 1. / norm, ray_dir, 1);
340 const double tol = 1e-6;
341 std::vector<double> distance;
342 std::vector<EntityHandle> triangles_out;
344 &*v_slave_tri_cent.data().begin(),
345 triangles_out, distance);
347 if (!triangles_out.empty()) {
348 range_closest_master_tris.clear();
349 range_closest_master_tris.insert(triangles_out.front());
350 flag_first_master =
true;
351 num_intersections = -1;
356 if (solution.size() == 1) {
357 range_closest_master_tris.insert(
359 num_intersections += 1;
361 int n_vertices_polygon = solution[0].size();
365 for (
int ii = 0; ii != 3; ++ii) {
366 prism_nodes[ii] = conn_master[ii];
371 slave_master_1prism);
373 range_slave_master_prisms.insert(slave_master_1prism);
379 v_coord_polygon.resize(3 * n_vertices_polygon);
385 v_coord_polygon_new.resize(3 * n_vertices_polygon);
387 auto t_coord_polygon_new = get_tensor_vec(v_coord_polygon_new);
388 auto t_coord_polygon = get_tensor_vec(v_coord_polygon);
390 std::vector<EntityHandle> conn_polygon(n_vertices_polygon);
391 for (
int ii = 0; ii != n_vertices_polygon; ++ii) {
392 t_coord_polygon(0) = solution[0][ii].X / roundfact;
393 t_coord_polygon(1) = solution[0][ii].Y / roundfact;
394 t_coord_polygon(2) += z_shift;
396 t_coord_polygon_new(
i) = t_m_rot(
j,
i) * t_coord_polygon(
j);
398 coord[0] = t_coord_polygon_new(0);
399 coord[1] = t_coord_polygon_new(1);
400 coord[2] = t_coord_polygon_new(2);
403 ++t_coord_polygon_new;
409 MBPOLYGON, &conn_polygon[0], n_vertices_polygon, polygon);
413 tris_in_polygon.clear();
414 if (n_vertices_polygon == 3) {
417 new_tri_conn[0] = conn_polygon[0];
418 new_tri_conn[1] = conn_polygon[1];
419 new_tri_conn[2] = conn_polygon[2];
424 tris_in_polygon.insert(new_tri);
427 new_tri_conn[0] = conn_polygon[0];
428 for (
int ii = 0; ii != n_vertices_polygon - 2; ++ii) {
429 new_tri_conn[1] = conn_polygon[ii + 1];
430 new_tri_conn[2] = conn_polygon[ii + 2];
436 tris_in_polygon.insert(new_tri);
442 contact_commondata_multi_index->insert(
444 slave_master_1prism, tris_in_polygon)));
448 if (num_intersections == 0)
449 flag_end_of_search =
true;