Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
SmoothFace.hpp
Go to the documentation of this file.
00001 #ifndef SMOOTH_FACE_EVAL_HPP
00002 #define SMOOTH_FACE_EVAL_HPP
00003 
00004 #include "moab/Interface.hpp"
00005 #include "moab/Range.hpp"
00006 #include "moab/CartVect.hpp"
00007 #include "MBTagConventions.hpp"
00008 #include "moab/Types.hpp"
00009 
00010 #include <cmath>
00011 #include <vector>
00012 #include <map>
00013 
00014 #define determ3( p1, q1, p2, q2, p3, q3 ) \
00015     ( ( q3 ) * ( ( p2 ) - ( p1 ) ) + ( q2 ) * ( ( p1 ) - ( p3 ) ) + ( q1 ) * ( ( p3 ) - ( p2 ) ) )
00016 #define blend( x ) ( -2.0 * ( x ) * ( x ) * ( x ) + 3.0 * ( x ) * ( x ) )
00017 
00018 // work only with CAMAL > = 500
00019 // #if CAMAL_VERSION < 500
00020 // #else
00021 
00022 #include "moab/GeomTopoTool.hpp"
00023 
00024 namespace moab
00025 {
00026 class SmoothCurve;  // it is derived from SmoothBase, maybe just need
00027 
00028 //! Implement CAMAL geometry callbacks using smooth iMesh
00029 class SmoothFace  // public CMLSurfEval, public SmoothBase
00030 {
00031   public:
00032     SmoothFace( Interface* mb, EntityHandle surface_set,
00033                 GeomTopoTool* gTool );  // entity or entity set
00034 
00035     virtual ~SmoothFace();
00036 
00037     virtual double area();
00038 
00039     virtual void bounding_box( double box_min[3], double box_max[3] );
00040 
00041     virtual void move_to_surface( double& x, double& y, double& z );
00042     /*
00043      virtual void move_to_surface(double& x, double& y, double& z,
00044      double& u_guess, double& v_guess);*/
00045 
00046     virtual bool normal_at( double x, double y, double z, double& nx, double& ny, double& nz );
00047 
00048     // initialize normals// they will be stored as tags on nodes
00049     int init_gradient();
00050 
00051     // some functions for edge evaluations
00052     ErrorCode evaluate_smooth_edge( EntityHandle eh, double& t, CartVect& outv );
00053 
00054     ErrorCode eval_bezier_patch( EntityHandle tri, CartVect& areacoord, CartVect& pt );
00055 
00056     void project_to_facet_plane( EntityHandle tri, CartVect& pt, CartVect& point_on_plane, double& dist_to_plane );
00057 
00058     void facet_area_coordinate( EntityHandle facet, CartVect& pt_on_plane, CartVect& areacoord );
00059 
00060     ErrorCode project_to_facets_main( CartVect& this_point,
00061                                       bool trim,
00062                                       bool& outside,
00063                                       CartVect* closest_point_ptr = NULL,  // interested only in normal
00064                                       CartVect* normal_ptr        = NULL );       // interested only in closest point
00065 
00066     ErrorCode project_to_facets( std::vector< EntityHandle >& facet_list,
00067                                  EntityHandle& lastFacet,
00068                                  int interpOrder,
00069                                  double compareTol,
00070                                  CartVect& this_point,
00071                                  bool trim,
00072                                  bool& outside,
00073                                  CartVect* closest_point_ptr,
00074                                  CartVect* normal_ptr );
00075 
00076     ErrorCode project_to_facet( EntityHandle facet,
00077                                 CartVect& pt,
00078                                 CartVect& areacoord,
00079                                 CartVect& close_point,
00080                                 bool& outside_facet,
00081                                 double compare_tol );
00082 
00083     bool is_at_vertex( EntityHandle facet,         // (IN) facet we are evaluating
00084                        CartVect& pt,               // (IN) the point
00085                        CartVect& ac,               // (IN) the ac of the point on the facet plane
00086                        double compare_tol,         // (IN) return TRUE of closer than this
00087                        CartVect& eval_pt,          // (OUT) location at vertex if TRUE
00088                        CartVect* eval_norm_ptr );  // (OUT) normal at vertex if TRUE
00089 
00090     ErrorCode project_to_patch( EntityHandle facet,   // (IN) the facet where the patch is defined
00091                                 CartVect& ac,         // (IN) area coordinate initial guess (from linear facet)
00092                                 CartVect& pt,         // (IN) point we are projecting to patch
00093                                 CartVect& eval_pt,    // (OUT) The projected point
00094                                 CartVect* eval_norm,  // (OUT) normal at evaluated point
00095                                 bool& outside,        // (OUT) the closest point on patch to pt is on an edge
00096                                 double compare_tol,   // (IN) comparison tolerance
00097                                 int edge_id );        // (IN) only used if this is to be projected to one
00098     //      of the edges.  Otherwise, should be -1
00099 
00100     ErrorCode eval_bezier_patch_normal( EntityHandle facet, CartVect& areacoord, CartVect& normal );
00101 
00102     // this will be called now from driver...
00103     ErrorCode compute_tangents_for_each_edge();  // they will be used for control points
00104 
00105     ErrorCode get_normals_for_vertices( const EntityHandle* conn2,
00106                                         CartVect N[2] );  // here we need the gradient tag
00107 
00108     // make this one public, will be called during initialization !!!
00109     ErrorCode init_edge_control_points( CartVect& P0,
00110                                         CartVect& P3,
00111                                         CartVect& N0,
00112                                         CartVect& N3,
00113                                         CartVect& T0,
00114                                         CartVect& T3,
00115                                         CartVect* Pi );
00116 
00117     // moved from private, because will be called from PaveDriver
00118     ErrorCode compute_control_points_on_edges( double min_dot, Tag edgeCtrlTag, Tag markTag );
00119 
00120     ErrorCode compute_internal_control_points_on_facets( double min_dot, Tag facetCtrlTag, Tag facetEdgeCtrlTag );
00121 
00122     // move from private too
00123     void DumpModelControlPoints();
00124 
00125     int eval_counter()
00126     {
00127         return _evaluationsCounter;
00128     }
00129 
00130     // new method for ray intersection correction
00131     ErrorCode ray_intersection_correct( EntityHandle facet,  // (IN) the facet where the patch is defined
00132                                         CartVect& pt,        // (IN) shoot from
00133                                         CartVect& ray,       // (IN) ray direction
00134                                         CartVect& eval_pt,   // (INOUT) The intersection point
00135                                         double& distance,    // (IN OUT) the new distance
00136                                         bool& outside );     // (OUT) the closest point on patch to pt is on an edge
00137 
00138     void append_smooth_tags( std::vector< Tag >& smoothTags );
00139     //      of the edges.  Otherwise, should be -1)
00140   private:
00141     //===========================================================================
00142     // Function Name: move_ac_inside
00143     //
00144     // Member Type:  PRIVATE
00145     // Description:  find the closest area coordinate to the boundary of the
00146     //              patch if any of its components are < 0
00147     //              Return if the ac was modified.
00148     //===========================================================================
00149     bool move_ac_inside( CartVect& ac, double tol );
00150 
00151     //===========================================================================
00152     // Function Name: ac_at_edge
00153     //
00154     // Member Type:  PRIVATE
00155     // Description:  determine the area coordinate of the facet at the edge
00156     //===========================================================================
00157     void ac_at_edge( CartVect& fac,  // facet area coordinate
00158                      CartVect& eac,  // edge area coordinate
00159                      int edge_id );  // id of edge
00160 
00161     // some local functions that do not need to be public
00162     ErrorCode init_bezier_edge( EntityHandle edge, double min_dot );
00163     //
00164 
00165     ErrorCode find_edges_orientations( EntityHandle edges[3],
00166                                        const EntityHandle* conn3,
00167                                        int orient[3] );  // maybe we will set it?
00168 
00169     ErrorCode init_facet_control_points( CartVect N[6],     // vertex normals (per edge)
00170                                          CartVect P[3][5],  // edge control points
00171                                          CartVect G[6] );   // return internal control points
00172 
00173     // those are the bounding box limits;
00174     // they are adjusted for the control points too in each triangle
00175     void adjust_bounding_box( CartVect& vect );
00176     CartVect _minim;
00177     CartVect _maxim;
00178 
00179     Range _triangles;
00180     Range _edges;
00181     Range _nodes;
00182 
00183     // std::vector<double> _fractions;// they are increasing from 0. to 1., do we need these?
00184     // std::vector<double> _loopLengths;
00185 
00186     // number of loops is decided by the size of _loopEnds.size()
00187     // this ref face will be gone, we will replace it with a new call
00188     // RefFace * _smooth_face;
00189     // int myDimension;
00190     // double meshSize;
00191 
00192     // this tag is on edges
00193     // rval = _mb->tag_create("MARKER", 1, MB_TAG_BIT, _markTag, &value);
00194     Tag _markTag;  // this is a tag used to mark edges when we look for loops
00195 
00196     // this tag is on nodes
00197     // ErrorCode rval = _mb->tag_create("GRADIENT", 3 * sizeof(double),
00198     // MB_TAG_DENSE, _gradientTag, &defNormal);
00199     Tag _gradientTag;  // this will be used for normal at nodes
00200 
00201     // this tag is on edges
00202     // ErrorCode rval = _mb->tag_create("TANGENTS", 6 * sizeof(double),
00203     // MB_TAG_DENSE, _tangentsTag, &defTangents);
00204     Tag _tangentsTag;  // each edge will have exactly 2 tangents, because there is only
00205     // one feature edge, and it is periodic
00206     // the feature edge is exactly on the boundary
00207 
00208     // this tag is on edges
00209     // ErrorCode rval = _mb->tag_create("CONTROLEDGE", 9 * sizeof(double),
00210     // MB_TAG_DENSE, _edgeCtrlTag, &defControls);
00211     Tag _edgeCtrlTag;
00212 
00213     // this tag is on facets (triangles), 6 control points on each facet
00214     // there are also some 15 points used in evaluation; how to store them?
00215     // ErrorCode rval = _mb->tag_create("CONTROLFACE", 18 * sizeof(double),
00216     // MB_TAG_DENSE, _facetCtrlTag, &defControls);
00217     Tag _facetCtrlTag;
00218 
00219     // these are the 12 points stored for each edge, again
00220     // it is cheaper this way compared to retrieve the edges every time, determine their
00221     // orientation, order in triangle, and retrieve the control points from the edge the control
00222     // points are stored as 12 points, in order : edge 0, 1, and 2, in that order
00223     // ErrorCode rval = _mb->tag_create("CONTROLEDGEFACE", 36 * sizeof(double),
00224     // MB_TAG_DENSE, _facetEdgeCtrlTag, &defControls);
00225     Tag _facetEdgeCtrlTag;  //
00226     // plane of the facet stores as a normal a, b, c and d, distance, for
00227     // ax+by+cz+d=0
00228     // ErrorCode rval = _mb->tag_create("PLANE", 4 * sizeof(double),
00229     // MB_TAG_DENSE, _planeTag, &defPlane);
00230     Tag _planeTag;
00231 
00232     Interface* _mb;
00233     EntityHandle _set;
00234     GeomTopoTool* _my_geomTopoTool;
00235     EntityHandle _obb_root;
00236     // counter for calls
00237     long _evaluationsCounter;
00238 };
00239 // #endif
00240 }  // namespace moab
00241 #endif /* SMOOTH_FACE_EVAL_HPP*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines