//=========================================================================== // GoTools Core - SINTEF Geometry Tools Core library, version 2.0.1 // // Copyright (C) 2000-2007, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00015 #ifndef _CURVEBOUNDEDDOMAIN_H 00016 #define _CURVEBOUNDEDDOMAIN_H 00017 00018 #include "GoTools/geometry/Domain.h" 00019 #include "GoTools/geometry/RectDomain.h" 00020 #include "GoTools/geometry/CurveLoop.h" 00021 #include "GoTools/geometry/SplineSurface.h" 00022 #include "GoTools/geometry/CurveOnSurface.h" 00023 #include "GoTools/utils/config.h" 00024 00025 // using std::vector; 00026 // using std::pair; 00027 // using boost::shared_ptr; 00028 00029 namespace Go 00030 { 00031 00034 class GO_API CurveBoundedDomain : public Domain 00035 { 00036 public: 00038 CurveBoundedDomain() 00039 {} 00040 00044 00045 00052 CurveBoundedDomain(std::vector<boost::shared_ptr<CurveLoop> > loops); 00053 00058 CurveBoundedDomain(boost::shared_ptr<CurveLoop> ccw_loop); 00059 00061 virtual ~CurveBoundedDomain(); 00062 00063 // virtual DomainType domainType() const; 00064 00074 virtual bool isInDomain(const Array<double, 2>& point, 00075 double tolerance) const; 00076 00084 virtual bool isOnBoundary(const Array<double, 2>& point, 00085 double tolerance) const; 00086 00089 bool isOnCorner(const Array<double, 2>& point, 00090 double tolerance) const; 00091 00100 virtual void closestInDomain(const Array<double, 2>& point, 00101 Array<double, 2>& clo_pt, 00102 double tolerance) const; 00103 00113 virtual void closestOnBoundary(const Array<double, 2>& point, 00114 Array<double, 2>& clo_bd_pt, 00115 double tolerance) const; 00116 00119 void getInternalPoint(double& upar, double& vpar) const; 00120 00128 RectDomain containingDomain() const; 00129 00145 void clipWithDomain(int pardir, double parval, 00146 double tolerance, boost::shared_ptr<ParamSurface> srf, 00147 std::vector<boost::shared_ptr<CurveOnSurface> >& trim_pieces) const; 00148 00149 // Determine which intervals of a 2D spline curve lies inside the bounded 00150 // domain. The start and end parameter values for the inside intervals are 00151 // found in the vector 'params_start_end_interval'. Even entries in this 00152 // vector marks the start of an inside interval, odd entries marks the end. 00153 00154 00167 void 00168 findPcurveInsideSegments(const SplineCurve& curve, 00169 double tolerance, 00170 std::vector<double>& params_start_end_interval) const; 00171 00192 void 00193 findPcurveInsideSegments(const SplineCurve& curve, 00194 double tolerance, 00195 std::vector<double>& params_start_end_interval, 00196 std::vector<double>& boundary_params, 00197 std::vector<int>& boundary_loops, 00198 std::vector<int>& boundary_curves) const; 00199 00200 // Fetch all intervals in one parameter direction 00201 // going through a specific point lying inside the 00202 // bounded domain. 00203 // 00204 // Return value: -1 : Outside of outer loop 00205 // 0 : Inside domain 00206 // j>0 : Inside hole number j, i.e. inside loop number j 00207 int positionPointInDomain(int pardir, double parval1, 00208 double parval2, 00209 double tolerance) const; 00210 00211 private: 00212 typedef struct intersection_point { 00213 double par1, par2; // par1 is intersection parameter on external curve, par2 is boundary curve 00214 int loop_idx, curve_idx; // Position of boundary curve 00215 int pretop[4]; 00216 00217 intersection_point(double p1, double p2, int l_idx, int c_idx, int *top) 00218 { 00219 par1 = p1; par2 = p2; 00220 loop_idx = l_idx; curve_idx = c_idx; 00221 pretop[0] = top[0]; 00222 pretop[1] = top[1]; 00223 pretop[2] = top[2]; 00224 pretop[3] = top[3]; 00225 } 00226 00227 } intersection_point; 00228 00229 // Comparisement function to use in std::sort 00230 static bool par1_compare(const intersection_point& el1, 00231 const intersection_point& el2) 00232 { 00233 if (el1.par1 < el2.par1) 00234 return true; 00235 else 00236 return false; 00237 } 00238 00239 00240 // We store a set of curve loops 00241 std::vector<boost::shared_ptr<CurveLoop> > loops_; 00242 00243 // Fetch all intervals in one parameter direction 00244 // going through a specific point lying inside the 00245 // bounded domain. 00246 void getInsideIntervals(int pardir, double parval1, double parval2, 00247 double tolerance, 00248 std::vector<std::pair<double, double> >& insideInts) const; 00249 00250 00251 // We return a pointer to a parameter curve defining boundary. If loops_ 00252 // consists of CoCurveOnSurface's, the parameter domain curve is returned. 00253 // Otherwise we make sure that dimension really is 2. 00254 boost::shared_ptr<ParamCurve> getParameterCurve(int loop_nmb, int curve_nmb) const; 00255 00256 // Determine which intervals of a 2D spline curve lies inside the 00257 // bounded domain. The start and end parameter values for the 00258 // inside intervals are found in the intersection_points in the 00259 // 'intpt' vector. Those intersection_points with even indexes 00260 // marks the start of such an interval, each following 00261 // (odd-indexed) intersection_point mark the end of that interval. 00262 void findPcurveInsideSegments(const SplineCurve& curve, 00263 double tolerance, 00264 std::vector<intersection_point>& intpt) const; 00265 00266 }; 00267 00268 00269 } // namespace Go 00270 00271 #endif // _CURVEBOUNDEDDOMAIN_H 00272