SfSfIntersector.h

00001 //===========================================================================
00002 // GoTools - SINTEF Geometry Tools
00003 //
00004 // GoTools module: Intersections, version 1.0
00005 //
00006 // Copyright (C) 2000-2007 SINTEF ICT, Applied Mathematics, Norway.
00007 //
00008 // This program is free software; you can redistribute it and/or          
00009 // modify it under the terms of the GNU General Public License            
00010 // as published by the Free Software Foundation version 2 of the License. 
00011 //
00012 // This program is distributed in the hope that it will be useful,        
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00015 // GNU General Public License for more details.                           
00016 //
00017 // You should have received a copy of the GNU General Public License      
00018 // along with this program; if not, write to the Free Software            
00019 // Foundation, Inc.,                                                      
00020 // 59 Temple Place - Suite 330,                                           
00021 // Boston, MA  02111-1307, USA.                                           
00022 //
00023 // Contact information: E-mail: tor.dokken@sintef.no                      
00024 // SINTEF ICT, Department of Applied Mathematics,                         
00025 // P.O. Box 124 Blindern,                                                 
00026 // 0314 Oslo, Norway.                                                     
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //===========================================================================
00033 #ifndef _SFSFINTERSECTOR_H
00034 #define _SFSFINTERSECTOR_H
00035 
00036 
00037 #include "Intersector2Obj.h"
00038 #include "IntersectionPoint.h"
00039 #include "IntersectionPool.h"
00040 
00041 
00042 namespace Go {
00045 
00046 
00047 
00048 class Param2FunctionInt;
00049 
00050 
00052 
00053 class SfSfIntersector : public Intersector2Obj {
00054 public:
00055 
00056     friend class SfSelfIntersector;
00057 
00059     SfSfIntersector() {}
00060 
00069     SfSfIntersector(boost::shared_ptr<ParamGeomInt> obj1, 
00070                     boost::shared_ptr<ParamGeomInt> obj2,
00071                     boost::shared_ptr<GeoTol> epsge, 
00072                     Intersector* prev = 0);
00073 
00082    SfSfIntersector(boost::shared_ptr<ParamGeomInt> obj1, 
00083                     boost::shared_ptr<ParamGeomInt> obj2,
00084                     double epsge, 
00085                     Intersector* prev = 0);
00087     virtual ~SfSfIntersector();
00088 
00091     virtual int numParams() const
00092     { return 4; }
00093 
00094     void postIterate3(int nmb_orig, int dir)
00095         {
00096             postIterate(nmb_orig, dir, false);
00097         }
00098 
00099     friend class IntersectionPool;
00100 
00101 protected:
00102 
00103     virtual boost::shared_ptr<Intersector> 
00104       lowerOrderIntersector(boost::shared_ptr<ParamGeomInt> obj1,
00105                             boost::shared_ptr<ParamGeomInt> obj2, 
00106                             Intersector* prev = 0,
00107                             int eliminated_parameter = -1,
00108                             double eliminated_value = 0);
00109 
00110     virtual int performRotatedBoxTest(double eps1, double eps2);
00111 
00112     virtual bool foundIntersectionNearBoundary();
00113 
00114     virtual int performInterceptionByImplicitization();
00115 
00116     virtual int interceptionBySeparationSurface();
00117 
00118     virtual int simpleCase2(Point& axis1, Point& axis2);
00119 
00120     virtual int simpleCaseByImplicitization();
00121 
00122     virtual bool complexityReduced();
00123 
00124     virtual void handleComplexity();
00125 
00126     virtual int checkCoincidence();
00127     
00128     virtual void microCase();
00129     
00130     virtual bool degTriangleSimple();
00131 
00132     virtual int updateIntersections();
00133 
00134     virtual int repairIntersections();
00135 
00136     void repairSingularityBox();
00137 
00138     void repairFalseBranchPoints();
00139 
00140     void removeIsolatedPoints();
00141 
00142     void repairMissingLinks();
00143 
00144     bool connectIfPossible(boost::shared_ptr<IntersectionPoint> pt1,
00145                            boost::shared_ptr<IntersectionPoint> pt2);
00146 
00148     void fixCrossingLinks();
00149 
00150     bool checkCloseEndpoint(boost::shared_ptr<IntersectionPoint> pnt, 
00151                             boost::shared_ptr<IntersectionLink> link);
00152 
00153     void iterateOnIntersectionPoints();
00154 
00155     void getSingularityBox(boost::shared_ptr<IntersectionPoint> sing,
00156                            double frompar[], double topar[]);
00157 
00158     boost::shared_ptr<SfSfIntersector>
00159     getSubIntersector(double frompar[], double topar[]);
00160 
00161     virtual int linearCase();
00162 
00163     virtual int doSubdivide();
00164 
00165     void getApproxImplicit(std::vector<std::vector<boost::
00166                            shared_ptr<Param2FunctionInt> > >& approx_implicit,
00167                            std::vector<double>& approx_implicit_err,
00168                            std::vector<double>& approx_implicit_gradsize,
00169                            std::vector<double>& approx_implicit_gradvar);
00170     
00171 private:
00172 
00173     // Implicitization related data members
00174 
00175     // This object contains the result of plugging in the two surfaces
00176     // into the two approximate implicitizations. The convention is
00177     // that
00178     //
00179     // approx_implicit_[implicit][surface] ,
00180     //
00181     // where implicit = 0 or 1, and surface = 0 or 1, means the result
00182     // of plugging surface 'surface' into implicit function
00183     // 'implicit'.
00184     std::vector<std::vector<boost::shared_ptr<Param2FunctionInt> > >
00185     approx_implicit_;
00186 
00187     // The "error" of the implicitizations. Equals the smallest
00188     // singular values of the implicitization "D-matrix", and bounds
00189     // the algebraic distance between the exact object and the
00190     // implicit approximation. The index (0 or 1) refers to the
00191     // implicit surface.
00192     std::vector<double> approx_implicit_err_;
00193 
00194     // The size of the gradient of the implicit surface over the
00195     // inserted surface. The measure of the size is taken to be the
00196     // l2-norm of the control points of approx_implicit_[0][1] and
00197     // approx_implicit_[1][0]. The index (0 or 1) refers to the
00198     // inserted parametric surface.
00199     std::vector<double> approx_implicit_gradsize_;
00200 
00201     // The variation of the gradient of the implicit surface over the
00202     // inserted surface. The measure of the variation is taken to be
00203     // max length divided by min length of the control vectors of
00204     // approx_implicit_[0][1] and approx_implicit_[1][0]. The index (0
00205     // or 1) refers to the inserted parametric surface.
00206     std::vector<double> approx_implicit_gradvar_;
00207 
00208     // Indicates if the results is fetched from this or the previous
00209     // level of the recursion
00210     bool prev_implicit_[2];
00211 
00212     // VSK, 0806. Information about monotone trend in simple case
00213     int sorting_obj_[2];  // -1 if not set, otherwise 0 or 1
00214     Point sorting_dir_[2];  // Direction along which to sort intersection
00215                          // points in the parameter domain of object sorting_obj_
00216     bool sorting_pardir_[2];  // Indicates whether the parameter directions in
00217                               // the intersection points are consistent
00218 
00219     // Service funtionality for subdivision
00220     int sortParameterDirections(int perm[], int deg_edge[]);
00221 
00222     SubdivisionClassification 
00223     getSubdivisionParameter(int dir, int deg_edge, double& par);
00224 
00225     bool getSubdivParDegEdge(ParamSurfaceInt *surf, int dir, int pdir, 
00226                              int deg_edge, double treshhold, double& par);
00227 
00228     void setDegTriangle(std::vector<boost::shared_ptr<ParamGeomInt> >&
00229                         sub_objects,
00230                         int deg_edge, int pdir, double par);
00231 
00232     int checkSubdivParam(int dir, double par, double ta, double tb,
00233                          std::vector<boost::shared_ptr<IntersectionPoint> >&
00234                          int_pts);
00235 
00236     int checkIsoCurve(int pdir, bool first, double par,
00237                       std::vector<boost::shared_ptr<IntersectionPoint> >&
00238                       int_pts);
00239 
00240     bool getSubdivAtSing(int dir, double ta, double tb, double& par);
00241     
00242     int splitIntResults(std::vector<boost::shared_ptr<IntersectionPoint> >&
00243                          int_pts, int pardir, double par, double start, 
00244                          double end, bool large_move);
00245 
00246     void doIterate(int pardir, double parval, double param[], double& dist,
00247                    double seed[]);
00248 
00249     void doIterate(int pardir, double param[], double limit1[], double w1,
00250                    double limit2[], double w2, double& dist, double *seed = 0);
00251 
00252     virtual void postIterate(int nmb_orig, int dir, bool keep_endpt=true);
00253 
00254     void postIterate2(int nmb_orig, int dir, double par,
00255                       bool along = true, bool only_isolated = true);
00256 
00257     virtual void removeDegenerateConnections();
00258 
00259     // Service functionality for connecting intersection points at the 
00260     // boundaries in a simple case situation
00261     bool isConnected(std::vector<boost::shared_ptr<IntersectionPoint> >&
00262                      bd_ints);
00263 
00264     bool isConnected(std::vector<std::
00265                      pair<boost::shared_ptr<IntersectionPoint>,
00266                      IntPtClassification> >& bd_ints, 
00267                      int nmb_nottouch);
00268 
00269     bool connectDirected(std::vector<std::
00270                          pair<boost::shared_ptr<IntersectionPoint>,
00271                          IntPtClassification> >& bd_ints, 
00272                          int nmb_nottouch);
00273 
00274     bool canConnect(boost::shared_ptr<IntersectionPoint> pt1,
00275                     boost::shared_ptr<IntersectionPoint> pt2);
00276 
00277     bool findMiddlePoint(boost::shared_ptr<IntersectionPoint> pt1,
00278                          boost::shared_ptr<IntersectionPoint> pt2,
00279                          double param[], double& dist);
00280 
00281     // Service funtionality for handling tiny, degenerate triangles
00282     void getPointsAtDegEdges(std::vector<boost::
00283                              shared_ptr<IntersectionPoint> >& result);
00284 
00285     void getPointsOppositeDegEdges(std::vector<std::pair<boost::
00286                                    shared_ptr<IntersectionPoint>, int> >&
00287                                    result);
00288 
00289     void getLinksAtDegEdges(std::vector<boost::shared_ptr<IntersectionPoint> >& deg_pnts, 
00290                             int idx, boost::shared_ptr<IntersectionPoint> curr,
00291                             std::vector<boost::shared_ptr<IntersectionLink> >& links);
00292 
00293     // Service funtionality and structure for handling of sub problems
00294     // that are recognize as complex and not recommended for further
00295     // subdivision
00296 
00297     struct IntersectionGroup {
00298         std::vector<boost::shared_ptr<IntersectionPoint> > points;
00299         std::vector<IntPtClassification> type;
00300         IntPtClassification main_type;
00301         bool tangential;
00302         bool iso[4];
00303         
00304         IntersectionGroup(std::vector<boost::
00305                           shared_ptr<IntersectionPoint> >& pts)
00306         {
00307             points = pts;
00308             type.resize(pts.size());
00309             for (size_t ki=0; ki<type.size(); ki++)
00310                 type[ki] = DIR_UNDEF;
00311             main_type = DIR_UNDEF;
00312             tangential = false;
00313             for (int dir=0; dir<4; dir++)
00314                 iso[dir] = false;
00315         }
00316 
00317         void classifyPoints(ParamSurface *srf1, ParamSurface *srf2);
00318         void classifyCurve();
00319         boost::shared_ptr<IntersectionPoint> 
00320         closestToPoint(IntersectionPoint* pnt);
00321         boost::shared_ptr<IntersectionPoint> getBranchPoint();
00322         boost::shared_ptr<IntersectionPoint> 
00323         getMainPoint(IntPtClassification &type_curr, 
00324                      IntPtClassification type_other);
00325         bool isIso()
00326         {
00327             for (int ki=0; ki<4; ki++)
00328                 if (iso[ki])
00329                     return true;
00330             return false;
00331         }
00332     };
00333     
00334     void makeIntersectionGroups(std::vector<boost::
00335                                 shared_ptr<IntersectionPoint> >& pts,
00336                                 std::vector<boost::
00337                                 shared_ptr<IntersectionGroup> >& groups);
00338 
00339     void classifyGroups(std::vector<boost::
00340                         shared_ptr<IntersectionGroup> >& groups);
00341 
00342     void tryConnectGroups(boost::shared_ptr<IntersectionGroup> group1,
00343                           boost::shared_ptr<IntersectionGroup> group2);
00344 
00345     void mergeGroups(std::vector<boost::shared_ptr<IntersectionGroup> >& group,
00346                      IntersectionPoint *sing);
00347 
00348     void connectToSing(boost::shared_ptr<IntersectionGroup> group,
00349                        IntersectionPoint *sing);
00350 
00351     void selfintComplex(IntersectionPoint *sing);
00352  
00353     void selfintComplex2();
00354  
00355     // Perform an approximate implicitization on both surfaces, then
00356     // plug both surfaces into the resulting algebraic
00357     // expressions. This results in (up to) four combinations of
00358     // plugged in objects, as well as the two implicitization errors.
00359     void createApproxImplicit(double tol, int recursion_limit = 10);
00360 
00361     // If object has a prev intersector (i.e. a parent), we initialize
00362     // appr_impl_tol_ based on that.
00363     void setApproxImplicitFromPrev();
00364 
00365     // Set the values of approx_implicit_gradsize_[i] and
00366     // approx_implicit_gradvar_[i], where 'i' is the index (0 or 1) of
00367     // the inserted parametric surface.
00368     void setGradValues(int i);
00369 
00370     // DEBUG
00371     void writeDebugConnect(std::vector<std::
00372                            pair<boost::shared_ptr<IntersectionPoint>,
00373                            IntPtClassification> >& bd_ints);
00374 
00375     void writeDebugLinear(std::vector<boost::
00376                           shared_ptr<IntersectionPoint> >&  bd_ints);
00377 
00378 };
00379 
00380 
00382 } // namespace Go
00383 
00384 
00385 #endif  // _SFSFINTERSECTOR_H
00386 

Generated on Fri Nov 23 12:24:33 2007 for GoTools Intersections Library by  doxygen 1.5.1