00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 std::vector<std::vector<boost::shared_ptr<Param2FunctionInt> > >
00185 approx_implicit_;
00186
00187
00188
00189
00190
00191
00192 std::vector<double> approx_implicit_err_;
00193
00194
00195
00196
00197
00198
00199 std::vector<double> approx_implicit_gradsize_;
00200
00201
00202
00203
00204
00205
00206 std::vector<double> approx_implicit_gradvar_;
00207
00208
00209
00210 bool prev_implicit_[2];
00211
00212
00213 int sorting_obj_[2];
00214 Point sorting_dir_[2];
00215
00216 bool sorting_pardir_[2];
00217
00218
00219
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
00260
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
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
00294
00295
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
00356
00357
00358
00359 void createApproxImplicit(double tol, int recursion_limit = 10);
00360
00361
00362
00363 void setApproxImplicitFromPrev();
00364
00365
00366
00367
00368 void setGradValues(int i);
00369
00370
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 }
00383
00384
00385 #endif // _SFSFINTERSECTOR_H
00386