moab
GeomUtil.hpp
Go to the documentation of this file.
00001 /*
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  * 
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
00007  * retains certain rights in this software.
00008  * 
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  * 
00014  */
00015 
00021 #ifndef MB_GEOM_UTIL_HPP
00022 #define MB_GEOM_UTIL_HPP
00023 
00024 #include "moab/CartVect.hpp"
00025 #include <cmath>
00026 
00027 namespace moab {
00028 
00032 namespace GeomUtil {
00033 
00058 bool segment_box_intersect( CartVect box_min,
00059                             CartVect box_max,
00060                             const CartVect& seg_pt,
00061                             const CartVect& seg_unit_dir,
00062                             double& seg_start, double& seg_end );
00063 
00076 bool ray_tri_intersect( const CartVect vertices[3],
00077                         const CartVect& ray_point,
00078                         const CartVect& ray_unit_direction,
00079                         double tolerance,
00080                         double& t_out,
00081                         const double* ray_length = 0 );
00082 
00083 
00106 enum intersection_type {NONE, INTERIOR, NODE0, NODE1, NODE2, EDGE0, EDGE1, EDGE2};
00107 bool plucker_ray_tri_intersect( const CartVect vertices[3],
00108                                 const CartVect& ray_point,
00109                                 const CartVect& ray_unit_direction,
00110                                 double tolerance, /* unused */
00111                                 double& dist_out,
00112                                 const double* nonneg_ray_length = 0,
00113                                 const double* neg_ray_length = 0,
00114                                 const int* orientation = 0,
00115                                 intersection_type* int_type = 0);
00116 
00134 bool ray_box_intersect( const CartVect& box_min,
00135                         const CartVect& box_max,
00136                         const CartVect& ray_pt,
00137                         const CartVect& ray_dir,
00138                         double& t_enter, double& t_exit );
00139 
00163 bool box_plane_overlap( const CartVect& plane_normal, 
00164                         double            plane_coeff,
00165                         CartVect        box_min_corner, 
00166                         CartVect        box_max_corner );
00167 
00189 bool box_tri_overlap( const CartVect  triangle_corners[3],
00190                       const CartVect& box_min_corner,
00191                       const CartVect& box_max_corner,
00192                       double            tolerance );
00193 
00203 bool box_tri_overlap( const CartVect  triangle_corners[3],
00204                       const CartVect& box_center,
00205                       const CartVect& box_half_dims );
00206 
00207 bool box_point_overlap( const CartVect& box_min_corner,
00208                         const CartVect& box_max_corner,
00209                         const CartVect& point,
00210                         double tolerance );
00211 
00223 bool box_elem_overlap( const CartVect *elem_corners,
00224                        EntityType elem_type,
00225                        const CartVect& box_center,
00226                        const CartVect& box_half_dims ); 
00227 
00239 bool box_linear_elem_overlap( const CartVect *elem_corners,
00240                               EntityType elem_type,
00241                               const CartVect& box_center,
00242                               const CartVect& box_half_dims ); 
00243 
00256 bool box_linear_elem_overlap( const CartVect *elem_corners,
00257                               EntityType elem_type,
00258                               const CartVect& box_half_dims ); 
00259 
00260 void closest_location_on_box( const CartVect& box_min_corner,
00261                               const CartVect& box_max_corner,
00262                               const CartVect& point,
00263                               CartVect& closest );
00264 
00272 void closest_location_on_tri( const CartVect& location,
00273                               const CartVect* vertices,
00274                               CartVect& closest_out );
00275 
00284 void closest_location_on_polygon( const CartVect& location,
00285                                   const CartVect* vertices,
00286                                   int num_vertices,
00287                                   CartVect& closest_out );
00288 
00301 void closest_location_on_tri( const CartVect& location,
00302                               const CartVect* vertices,
00303                               double tolerance,
00304                               CartVect& closest_out,
00305                               int& closest_topo );
00306 
00307 // Finds whether or not a box defined by the center and the half
00308 // width intersects a trilinear hex defined by its eight vertices.
00309 bool box_hex_overlap( const CartVect hexv[8],
00310                       const CartVect& box_center,
00311                       const CartVect& box_dims);
00312 
00313 // Finds whether or not a box defined by the center and the half
00314 // width intersects a linear tetrahedron defined by its four vertices.
00315 bool box_tet_overlap( const CartVect tet_corners[4],
00316                       const CartVect& box_center,
00317                       const CartVect& box_dims);
00318 
00319 // tests if 2 boxes overlap within a tolerance
00320 // assume that data is valid, box_min1 << box_max1, and box_min2<< box_max2
00321 // they are overlapping if they are overlapping in all directions
00322 // for example in x direction:
00323 //   box_max2[0] + tolerance < box_min1[0] -- false
00324 bool boxes_overlap( const CartVect & box_min1, const CartVect & box_max1,
00325     const CartVect & box_min2, const CartVect & box_max2, double tolerance);
00326 
00327 // see if boxes formed by 2 lists of "CartVect"s overlap
00328 bool bounding_boxes_overlap (const CartVect * list1, int num1, const CartVect * list2, int num2,
00329       double tolerance);
00330 //
00331 // point_in_trilinear_hex
00332 // Tests if a point in xyz space is within a hex element defined with
00333 // its eight vertex points forming a trilinear basis function.  Computes
00334 // the natural coordinates with respect to the hex of the xyz point 
00335 // and checks if each are between +/-1.  If anyone is outside the range
00336 // the function returns false, otherwise it returns true.
00337 //
00338 bool point_in_trilinear_hex(const CartVect *hex, 
00339                             const CartVect& xyz,
00340                             double etol);
00341 
00342 bool nat_coords_trilinear_hex( const CartVect* corner_coords,
00343                                const CartVect& x,
00344                                CartVect& xi,
00345                                double tol );
00346 } // namespace GeomUtil
00347 
00348 } // namespace moab
00349 
00350 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines