IntersectionPool.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 _INTERSECTIONPOOL_H
00034 #define _INTERSECTIONPOOL_H
00035 
00036 
00037 #include "ParamObjectInt.h"
00038 #include "IntersectionPoint.h"
00039 #include "IntersectionCurve.h"
00040 #include "Point.h"
00041 #include <boost/shared_ptr.hpp>
00042 #include <vector>
00043 #include <set>
00044 #include <ostream>
00045 
00046 
00047 namespace Go {
00050 
00051 
00052 
00053 class IntersectionPool;
00054 struct BoundaryIntersectionData;
00055 
00056 
00059 
00060 class IntersectionPool {
00061 public:
00062 
00071     IntersectionPool(boost::shared_ptr<ParamObjectInt> obj1, 
00072                      boost::shared_ptr<ParamObjectInt> obj2,
00073                      boost::shared_ptr<IntersectionPool> parent
00074                      = boost::shared_ptr<IntersectionPool>(),
00075                      int missing_dir = -1,
00076                      double missing_value = 0);
00077 
00079     virtual ~IntersectionPool() {}
00080 
00093     void addParamPoints(int nmb_int_pts, 
00094                         double* pointpar1, 
00095                         double* pointpar2,
00096                         boost::shared_ptr<GeoTol> epsge);
00097 
00115     template<class ip_iterator>
00116     void addCurves(int nmb_int_cvs, 
00117                    ip_iterator* start_iterators, 
00118                    ip_iterator* end_iterators);
00119 
00126     template<class ip_iterator>
00127     void addCurve(ip_iterator start, ip_iterator end);
00128 
00134     void getBoundaryIntersections(std::vector<boost::
00135                                   shared_ptr<IntersectionPoint> >& bd_ints);
00136 
00137     // @@@ VSK, Change name when implementing.
00138     // This function is not currently in use.
00139     bool  checkIfBothPointsLieOnOneEndpointAndNotOfTheSameCurve();
00140 
00141 
00147     void getSortedIntersections(std::vector<boost::
00148                                 shared_ptr<IntersectionPoint> >& int_pts);
00149 
00157     std::vector<double> getSortedInnerInts(int pardir);
00158 
00171     void getSortedBdInts(const Point& vec,
00172                          std::vector<boost::
00173                          shared_ptr<IntersectionPoint> >& result,
00174                          int obj_nmb = -1);
00175 
00184     // @@@jbt - NB: Find out about the return value...
00185     bool checkSortingDir(Point& vec, int sorting_obj);
00186 
00187     // This function is not yet implemented
00188     void getSortedInts(/* AROUND_BOUNDARIES ,*/
00189                        std::vector<boost::
00190                        shared_ptr<IntersectionPoint> >& result)
00191     { }
00192 
00193     // This function is not yet implemented
00194     void getAllIntersections(std::vector<boost::
00195                              shared_ptr<IntersectionPoint> >& result)
00196     { }
00197 
00201     void getBranchPoints(std::vector<boost::
00202                          shared_ptr<IntersectionPoint> > & pts);
00203 
00210     void getMidParameter(double *mid);
00211 
00212     // @@@ VSK. Let addIntersection point return the new intersection
00213     // point. It is sometimes useful.
00214 
00228     boost::shared_ptr<IntersectionPoint>
00229     addIntersectionPoint(boost::shared_ptr<ParamObjectInt> obj_int1_, 
00230                          boost::shared_ptr<ParamObjectInt> obj_int2_,
00231                          boost::shared_ptr<GeoTol> epsge,
00232                          double *par1, double *par2);
00233 
00241     void includeReducedInts(boost::shared_ptr<IntersectionPool>
00242                             lower_order_pool);
00243 
00271     void selfIntersectParamReorganise(boost::
00272                                       shared_ptr<IntersectionPool> sub_pool);
00273 
00274     // This function is to be used only in self intersection context, when
00275     // boundary intersections are computed.
00276     void mirrorIntersectionPoints(size_t first);
00277 
00278 
00286     bool hasPointsInInner(int pardir);
00287 
00292     bool hasIntersectionPoints() const
00293     { return (int_points_.size() > 0); }
00294     
00298     int numIntersectionPoints() const
00299     { return int_points_.size(); }
00300 
00307     int numSingularIntersectionPoints();
00308 
00315     bool isInDomain(IntersectionPoint *pnt) const;
00316 
00327     bool closestInDomain(double param[],
00328                          boost::shared_ptr<IntersectionPoint>& pnt) const;
00329 
00340     bool closestInDomain(const double param[],
00341                          boost::shared_ptr<IntersectionPoint>& pnt) const;
00342 
00349     bool existIntersectionPoint(int dir, double par);
00350 
00373     int inInfluenceArea(int pardir, double par, bool first_outside = true);
00374 
00399     int inInfluenceArea(int pardir, 
00400                         double par, 
00401                         std::vector<boost::
00402                         shared_ptr<IntersectionPoint> >& int_pts, 
00403                         bool first_outside = true);
00404 
00409     void getIntersectionPoints(std::vector<boost::
00410                                shared_ptr<IntersectionPoint> >& int_pts) const;
00411     
00416     void getIntersectionCurves(std::vector<boost::
00417                                shared_ptr<IntersectionCurve> >&
00418                                int_curves) const;
00419     
00424     std::vector<boost::shared_ptr<IntersectionPoint> >&
00425     getIntersectionPoints();
00426 
00431     const std::vector<boost::shared_ptr<IntersectionPoint> >&
00432     getIntersectionPoints() const;
00433 
00438     const std::vector<boost::shared_ptr<IntersectionCurve> >&
00439     getIntersectionCurves() const;
00440 
00448     void getIntersectionPoints(int dir, double par,
00449                                std::vector<boost::
00450                                shared_ptr<IntersectionPoint> >& result) const;
00451 
00460     bool hasIntersectionPoints(int dir, double par) const;
00461 
00471     bool checkIntersectionPoints(std::vector<IntPtInfo>& int_pt_info) const;
00472 
00475     bool checkIntersectionLinks() const;
00476 
00481     void removeDoublePoints();
00482 
00483     // Remove ordinary intersection points with only one neighbour when these
00484     // points lie reasonably close, their tangents point roughly in the same
00485     // direction, and the neighbour has significantly better accuracy.
00486     void removeLooseEnds();
00487 
00488     // Check ordinary intersection points to check if the links they belong to
00489     // are consistent
00490     void removeFalseCorners();
00491 
00495     void removeDefectLinks();
00496 
00497     void getAllLinks(std::set<boost::shared_ptr<IntersectionLink> >& links);
00498 
00507     void getResult(std::vector<boost::
00508                    shared_ptr<IntersectionPoint> >& int_points, 
00509                    std::vector<boost::
00510                    shared_ptr<IntersectionCurve> >& int_curves) ;
00511 
00514     int lackingParameter() const;
00515 
00518     double lackingParameterValue() const;
00519 
00527     bool atSameBoundary(boost::shared_ptr<IntersectionPoint> pt1,
00528                         boost::shared_ptr<IntersectionPoint> pt2);
00529 
00538     bool atDifferentBoundary(boost::shared_ptr<IntersectionPoint> pt1,
00539                              boost::shared_ptr<IntersectionPoint> pt2);
00540 
00550     bool isBoundaryIntersection(boost::shared_ptr<IntersectionPoint> pt1,
00551                                 boost::shared_ptr<IntersectionPoint> pt2);
00552 
00554     bool isBoundaryPoint(boost::shared_ptr<IntersectionPoint> pt1)
00555         {
00556             return isBoundaryPoint(pt1.get());
00557         }
00558 
00559     bool isBoundaryPoint(IntersectionPoint* pt1);
00560 
00561     // @@@ VSK. Yet some new functions. I just make a dummy implementation
00562 
00578     bool fetchLoops(std::vector<std::vector<boost::
00579                     shared_ptr<IntersectionPoint> > >& loop_ints);
00580 
00586     bool isPAC(std::vector<boost::shared_ptr<IntersectionPoint> >& int_loop);
00587 
00592     void setCoincidence(std::vector<boost::
00593                         shared_ptr<IntersectionPoint> >& int_loop);
00594 
00595     // Check if there is a connection between the given points through
00596     // the points in the intersection pool. For the time being
00597 
00610     bool isConnectedInside(boost::shared_ptr<IntersectionPoint> pt1,
00611                            boost::shared_ptr<IntersectionPoint> pt2);
00612 
00617     void makeIntersectionCurves();
00618 
00625     void getOrigPoints(std::vector<boost::
00626                        shared_ptr<IntersectionPoint> >& int_pts) const;
00627 
00630     void writeDebug(int singular = 0);
00631 
00638     void splitIntersectionLinks(int fixed_dir, double fixed_val);
00639 
00644     int numParams() const
00645     { return obj1_->numParams() + obj2_->numParams(); }
00646 
00652     double startParam(int dir) const;
00653 
00659     double endParam(int dir) const;
00660 
00665     void includeCoveredNeighbourPoints();
00666 
00687     void insertInInfluenceInterval(boost::
00688                                    shared_ptr<IntersectionPoint> pt_in_pool,
00689                                    double *parvals, int pardir);
00690 
00699     void synchronizePool();
00700 
00709     void cleanUpPool(int first_idx = 0, double epsge=1.0e-15);
00710 
00714 
00722     void removeIntPoint(boost::shared_ptr<IntersectionPoint> int_point);
00723     
00731     void removeIntPoint2(boost::shared_ptr<IntersectionPoint> int_point);
00732     
00740     void removeIntPoints(double* frompar, double* topar, bool only_inner = false);
00741     
00757     void intersectAlongCommonBoundary(double frac,
00758                                       std::vector<BoundaryIntersectionData>&
00759                                       isects);
00760 
00765     void removeBoundaryIntersections(bool single_pt=true);
00766 
00773     bool
00774     verifyIntersectionLink(const boost::shared_ptr<IntersectionLink>& link,
00775                            int recursion_limit = 10)
00776         const;
00777 
00780     bool 
00781         checkIntersectionChain(IntersectionPoint *pnt,
00782                                IntersectionPoint *first, 
00783                                IntersectionPoint *prev = 0);
00784 
00789     bool validate() const;
00790 
00791     // Remove unnecessary or harmful intersection points (called
00792     // before making IntersectionCurves.
00793     void weedOutClutterPoints() ; 
00794 
00797     void writeIntersectionPoints() const;
00798 
00801     void writeIntersectionLinks() const;
00802 
00803     friend class SfSfIntersector;
00804 
00805 private:
00806     // Data members
00807 
00808     // The intersecting objects
00809     boost::shared_ptr<ParamObjectInt> obj1_;
00810     boost::shared_ptr<ParamObjectInt> obj2_;
00811 
00812     // Intersection points (both isolated and on curves)
00813     std::vector<boost::shared_ptr<IntersectionPoint> > int_points_;
00814 
00815     // Intersection curves
00816     std::vector<boost::shared_ptr<IntersectionCurve> > int_curves_;
00817 
00818     int missing_param_index_;
00819     double missing_param_value_;
00820 
00821     boost::shared_ptr<IntersectionPool> prev_pool_;
00822 //     static const double REL_PAR_RES_; // a tolerance - @move this
00823 //                                    // somewhere else??
00824 
00825     // Functions
00826 
00827     void add_point_and_propagate_upwards(boost::
00828                                          shared_ptr<IntersectionPoint> point);
00829 
00830     void iterateToSplitPoint(boost::shared_ptr<IntersectionLink> link,
00831                              int fixed_dir, double fixed_value,
00832                              double par[], double& dist);
00833 
00834     void fetch_relevant_points(const std::vector<boost::
00835                                shared_ptr<IntersectionPoint> >& ipoints,
00836                                int missing_dir,
00837                                double missing_value);
00838 
00839     void constructor_implementation(boost::shared_ptr<ParamObjectInt> obj1, 
00840                                     boost::shared_ptr<ParamObjectInt> obj2,
00841                                     boost::shared_ptr<IntersectionPool> parent,
00842                                     int missing_dir,
00843                                     double missing_value);
00844 
00845     void associate_parent_points(std::vector<boost::
00846                                  shared_ptr<IntersectionPoint> >& children,
00847                                  int lacking_ix,
00848                                  double lacking_val);
00849 
00850     void transfer_links_to_parent_points(std::vector<boost::
00851                                          shared_ptr<IntersectionPoint> >&
00852                                          children,
00853                                          int lacking_ix);
00854 
00855     void get_param_limits(int pardir,
00856                           double& min_param, double& max_param) const;
00857 
00858     void
00859     set_correct_differentiating_domain(boost::
00860                                        shared_ptr<IntersectionPoint> ip) const;
00861 
00862     void separate_isoparametric_curves(std::vector<std::vector<int> >&
00863                                        curve_indices) const;
00864 
00865     void separate_at_problematic_points(std::vector<std::vector<int> >&
00866                                         curve_indices) const;
00867 
00868     int endof_noniso_curve(const std::vector<int>& cur_cv,
00869                            int start_ix) const;
00870 
00871     int endof_isoparametric_curve(const std::vector<int>& cur_cv,
00872                                   int start_ix) const;
00873 
00874     // Remove curves which are judged unnecessary or just 'clutter'.
00875     void weedOutClutterCurves(std::vector<std::vector<int> >& curves) const;
00876 
00877     void locateEdgepoints(Array<std::vector<boost::
00878                           shared_ptr<IntersectionPoint> >, 4>& obj1_edges,
00879                           Array<std::vector<boost::
00880                           shared_ptr<IntersectionPoint> >, 4>& obj2_edges);
00881 
00882     void determine_free_dir_parameter(double* par, 
00883                                       boost::shared_ptr<IntersectionLink> link,
00884                                       int free_dir,
00885                                       int fixed_dir,
00886                                       double fx_val);
00887 };
00888 
00889 
00890 //===========================================================================
00891 //                  IMPLEMENTATION OF INLINE METHODS
00892 //===========================================================================
00893 
00894 
00895 //===========================================================================
00896 inline void 
00897 IntersectionPool::
00898 getIntersectionPoints(std::vector<boost::
00899                       shared_ptr<IntersectionPoint> >& int_pts) const
00900 //===========================================================================
00901 {
00902     int_pts = int_points_;
00903 }
00904 
00905 
00906 //===========================================================================
00907 inline void 
00908 IntersectionPool::
00909 getIntersectionCurves(std::vector<boost::
00910                       shared_ptr<IntersectionCurve> >& int_curves) const
00911 //===========================================================================
00912 {
00913     int_curves = int_curves_;
00914 }
00915 
00916 
00917 //===========================================================================
00918 inline std::vector<boost::shared_ptr<IntersectionPoint> >&
00919 IntersectionPool::getIntersectionPoints()
00920 //===========================================================================
00921 {
00922     return int_points_;
00923 }
00924 
00925 
00926 //===========================================================================
00927 inline const std::vector<boost::shared_ptr<IntersectionPoint> >& 
00928 IntersectionPool::getIntersectionPoints() const
00929 //===========================================================================
00930 {
00931     return int_points_;
00932 }
00933 
00934 
00935 //===========================================================================
00936 inline const std::vector<boost::shared_ptr<IntersectionCurve> >&
00937 IntersectionPool::getIntersectionCurves() const 
00938 //===========================================================================
00939 {
00940     return int_curves_;
00941 }
00942 
00943 
00944 //===========================================================================
00945 template<class ip_iterator>
00946 inline void IntersectionPool::addCurves(int nmb_int_cvs, 
00947                                         ip_iterator* start_iterators, 
00948                                         ip_iterator* end_iterators)
00949 //===========================================================================
00950 {
00951     for (int i = 0; i < nmb_int_cvs; ++i) {
00952         addCurve(start_iterators[i], end_iterators[i]);
00953     }
00954 }
00955 
00956 
00957 //===========================================================================
00958 template<class ip_iterator>
00959 inline void IntersectionPool::addCurve(ip_iterator start, ip_iterator end)
00960 //===========================================================================
00961 {
00962     boost::shared_ptr<IntersectionCurve>
00963         temp(new IntersectionCurve(start, end));
00964     int_curves_.push_back(temp);
00965 }
00966 
00967 
00968 //===========================================================================
00969 inline int IntersectionPool::lackingParameter() const
00970 //===========================================================================
00971 {
00972     return missing_param_index_;
00973 }
00974 
00975 
00976 //===========================================================================
00977 inline double IntersectionPool::lackingParameterValue() const
00978 //===========================================================================
00979 {
00980     return missing_param_value_;
00981 }
00982 
00983 
00986 
00987 //===========================================================================
00988 struct BoundaryIntersectionData {
00989 //===========================================================================
00990 
00992     int dir[2];
00993 
00997     double par[2];
00998 
01000     std::vector<boost::shared_ptr<IntersectionPoint> > pts;
01001 
01002 };
01003 
01004 
01006 } // namespace Go
01007 
01008 
01009 #endif  // _INTERSECTIONPOOL_H
01010 

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