MOAB: Mesh Oriented datABase  (version 5.3.0)
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, bool trim, bool& outside,
00061                                       CartVect* closest_point_ptr = NULL,  // interested only in normal
00062                                       CartVect* normal_ptr        = NULL );       // interested only in closest point
00063 
00064     ErrorCode project_to_facets( std::vector< EntityHandle >& facet_list, EntityHandle& lastFacet, int interpOrder,
00065                                  double compareTol, CartVect& this_point, bool trim, bool& outside,
00066                                  CartVect* closest_point_ptr, CartVect* normal_ptr );
00067 
00068     ErrorCode project_to_facet( EntityHandle facet, CartVect& pt, CartVect& areacoord, CartVect& close_point,
00069                                 bool& outside_facet, double compare_tol );
00070 
00071     bool is_at_vertex( EntityHandle facet,         // (IN) facet we are evaluating
00072                        CartVect& pt,               // (IN) the point
00073                        CartVect& ac,               // (IN) the ac of the point on the facet plane
00074                        double compare_tol,         // (IN) return TRUE of closer than this
00075                        CartVect& eval_pt,          // (OUT) location at vertex if TRUE
00076                        CartVect* eval_norm_ptr );  // (OUT) normal at vertex if TRUE
00077 
00078     ErrorCode project_to_patch( EntityHandle facet,   // (IN) the facet where the patch is defined
00079                                 CartVect& ac,         // (IN) area coordinate initial guess (from linear facet)
00080                                 CartVect& pt,         // (IN) point we are projecting to patch
00081                                 CartVect& eval_pt,    // (OUT) The projected point
00082                                 CartVect* eval_norm,  // (OUT) normal at evaluated point
00083                                 bool& outside,        // (OUT) the closest point on patch to pt is on an edge
00084                                 double compare_tol,   // (IN) comparison tolerance
00085                                 int edge_id );        // (IN) only used if this is to be projected to one
00086     //      of the edges.  Otherwise, should be -1
00087 
00088     ErrorCode eval_bezier_patch_normal( EntityHandle facet, CartVect& areacoord, CartVect& normal );
00089 
00090     // this will be called now from driver...
00091     ErrorCode compute_tangents_for_each_edge();  // they will be used for control points
00092 
00093     ErrorCode get_normals_for_vertices( const EntityHandle* conn2,
00094                                         CartVect N[2] );  // here we need the gradient tag
00095 
00096     // make this one public, will be called during initialization !!!
00097     ErrorCode init_edge_control_points( CartVect& P0, CartVect& P3, CartVect& N0, CartVect& N3, CartVect& T0,
00098                                         CartVect& T3, CartVect* Pi );
00099 
00100     // moved from private, because will be called from PaveDriver
00101     ErrorCode compute_control_points_on_edges( double min_dot, Tag edgeCtrlTag, Tag markTag );
00102 
00103     ErrorCode compute_internal_control_points_on_facets( double min_dot, Tag facetCtrlTag, Tag facetEdgeCtrlTag );
00104 
00105     // move from private too
00106     void DumpModelControlPoints();
00107 
00108     int eval_counter()
00109     {
00110         return _evaluationsCounter;
00111     }
00112 
00113     // new method for ray intersection correction
00114     ErrorCode ray_intersection_correct( EntityHandle facet,  // (IN) the facet where the patch is defined
00115                                         CartVect& pt,        // (IN) shoot from
00116                                         CartVect& ray,       // (IN) ray direction
00117                                         CartVect& eval_pt,   // (INOUT) The intersection point
00118                                         double& distance,    // (IN OUT) the new distance
00119                                         bool& outside );     // (OUT) the closest point on patch to pt is on an edge
00120 
00121     void append_smooth_tags( std::vector< Tag >& smoothTags );
00122     //      of the edges.  Otherwise, should be -1)
00123   private:
00124     //===========================================================================
00125     // Function Name: move_ac_inside
00126     //
00127     // Member Type:  PRIVATE
00128     // Description:  find the closest area coordinate to the boundary of the
00129     //              patch if any of its components are < 0
00130     //              Return if the ac was modified.
00131     //===========================================================================
00132     bool move_ac_inside( CartVect& ac, double tol );
00133 
00134     //===========================================================================
00135     // Function Name: ac_at_edge
00136     //
00137     // Member Type:  PRIVATE
00138     // Description:  determine the area coordinate of the facet at the edge
00139     //===========================================================================
00140     void ac_at_edge( CartVect& fac,  // facet area coordinate
00141                      CartVect& eac,  // edge area coordinate
00142                      int edge_id );  // id of edge
00143 
00144     // some local functions that do not need to be public
00145     ErrorCode init_bezier_edge( EntityHandle edge, double min_dot );
00146     //
00147 
00148     ErrorCode find_edges_orientations( EntityHandle edges[3], const EntityHandle* conn3,
00149                                        int orient[3] );  // maybe we will set it?
00150 
00151     ErrorCode init_facet_control_points( CartVect N[6],     // vertex normals (per edge)
00152                                          CartVect P[3][5],  // edge control points
00153                                          CartVect G[6] );   // return internal control points
00154 
00155     // those are the bounding box limits;
00156     // they are adjusted for the control points too in each triangle
00157     void adjust_bounding_box( CartVect& vect );
00158     CartVect _minim;
00159     CartVect _maxim;
00160 
00161     Range _triangles;
00162     Range _edges;
00163     Range _nodes;
00164 
00165     // std::vector<double> _fractions;// they are increasing from 0. to 1., do we need these?
00166     // std::vector<double> _loopLengths;
00167 
00168     // number of loops is decided by the size of _loopEnds.size()
00169     // this ref face will be gone, we will replace it with a new call
00170     // RefFace * _smooth_face;
00171     // int myDimension;
00172     // double meshSize;
00173 
00174     // this tag is on edges
00175     // rval = _mb->tag_create("MARKER", 1, MB_TAG_BIT, _markTag, &value);
00176     Tag _markTag;  // this is a tag used to mark edges when we look for loops
00177 
00178     // this tag is on nodes
00179     // ErrorCode rval = _mb->tag_create("GRADIENT", 3 * sizeof(double),
00180     // MB_TAG_DENSE, _gradientTag, &defNormal);
00181     Tag _gradientTag;  // this will be used for normal at nodes
00182 
00183     // this tag is on edges
00184     // ErrorCode rval = _mb->tag_create("TANGENTS", 6 * sizeof(double),
00185     // MB_TAG_DENSE, _tangentsTag, &defTangents);
00186     Tag _tangentsTag;  // each edge will have exactly 2 tangents, because there is only
00187     // one feature edge, and it is periodic
00188     // the feature edge is exactly on the boundary
00189 
00190     // this tag is on edges
00191     // ErrorCode rval = _mb->tag_create("CONTROLEDGE", 9 * sizeof(double),
00192     // MB_TAG_DENSE, _edgeCtrlTag, &defControls);
00193     Tag _edgeCtrlTag;
00194 
00195     // this tag is on facets (triangles), 6 control points on each facet
00196     // there are also some 15 points used in evaluation; how to store them?
00197     // ErrorCode rval = _mb->tag_create("CONTROLFACE", 18 * sizeof(double),
00198     // MB_TAG_DENSE, _facetCtrlTag, &defControls);
00199     Tag _facetCtrlTag;
00200 
00201     // these are the 12 points stored for each edge, again
00202     // it is cheaper this way compared to retrieve the edges every time, determine their
00203     // orientation, order in triangle, and retrieve the control points from the edge the control
00204     // points are stored as 12 points, in order : edge 0, 1, and 2, in that order
00205     // ErrorCode rval = _mb->tag_create("CONTROLEDGEFACE", 36 * sizeof(double),
00206     // MB_TAG_DENSE, _facetEdgeCtrlTag, &defControls);
00207     Tag _facetEdgeCtrlTag;  //
00208     // plane of the facet stores as a normal a, b, c and d, distance, for
00209     // ax+by+cz+d=0
00210     // ErrorCode rval = _mb->tag_create("PLANE", 4 * sizeof(double),
00211     // MB_TAG_DENSE, _planeTag, &defPlane);
00212     Tag _planeTag;
00213 
00214     Interface* _mb;
00215     EntityHandle _set;
00216     GeomTopoTool* _my_geomTopoTool;
00217     EntityHandle _obb_root;
00218     // counter for calls
00219     long _evaluationsCounter;
00220 };
00221 // #endif
00222 }  // namespace moab
00223 #endif /* SMOOTH_FACE_EVAL_HPP*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines