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 _INTERSECTIONLINK_H
00034 #define _INTERSECTIONLINK_H
00035
00036
00037 #include "IntersectionPoint.h"
00038 #include "LinkType.h"
00039 #include <boost/shared_ptr.hpp>
00040 #include <fstream>
00041 #include "LineCloud.h"
00042
00043
00044 namespace Go {
00047
00048
00049
00054
00055 class IntersectionLink {
00056 public:
00058 IntersectionLink(IntersectionPoint* p1,
00059 IntersectionPoint* p2)
00060 : p1_(p1), p2_(p2), delimits_partial_coincidence_(false)
00061 {
00062 ASSERT(p1_->getObj1() == p2->getObj1());
00063 ASSERT(p1_->getObj2() == p2->getObj2());
00064 for (int i = 0; i < 4; iso_[i++] = false);
00065 }
00066
00069 void getIntersectionPoints(IntersectionPoint*& p1,
00070 IntersectionPoint*& p2)
00071 {
00072 p1 = p1_;
00073 p2 = p2_;
00074 }
00075
00078 void getIntersectionPoints(const IntersectionPoint*& p1,
00079 const IntersectionPoint*& p2) const
00080 {
00081 p1 = p1_;
00082 p2 = p2_;
00083 }
00084
00087 IntersectionPoint* getOtherPoint(const IntersectionPoint* p1)
00088 {
00089 return (p1 == p1_) ? p2_ : ((p1 == p2_) ? p1_ : 0);
00090 }
00091
00093 bool isAttachedTo(const IntersectionPoint* ip)
00094 {
00095 return (ip == p1_) || (ip == p2_);
00096 }
00097
00100 void copyMetaInformation(const IntersectionLink& rhs)
00101 {
00102 delimits_partial_coincidence_ = rhs.delimits_partial_coincidence_;
00103 for (int i = 0; i < 4; iso_[i] = rhs.iso_[i++]);
00104 }
00105
00108 bool delimitsPAC() const
00109 {
00110 return delimits_partial_coincidence_;
00111 }
00112
00113 void setPAC(bool value)
00114 {
00115 delimits_partial_coincidence_ = value;
00116 }
00117
00118 void setIsoparametricIn(int dir, bool iso)
00119 {
00120 ASSERT(dir >= 0 && dir < (p1_->numParams1() + p1_->numParams2()));
00121 iso_[dir] = iso;
00122
00123
00124 if (iso_[0] && iso_[1]) {
00125
00126
00127
00128 }
00129 if (iso_[2] && iso_[3]) {
00130
00131
00132 }
00133 }
00134
00135 bool isIsoparametricIn(int dir) const
00136 {
00137 ASSERT(dir >= 0 && dir < numParams());
00138 return iso_[dir];
00139 }
00140
00141 bool isIsoparametric() const
00142 {
00143 int num_param = numParams();
00144 for (int i = 0; i < num_param; ++i) {
00145 if (iso_[i]) {
00146 return true;
00147 }
00148 }
00149 return false;
00150 }
00151
00152 int numParams() const
00153 {
00154 return p1_->numParams1() + p1_->numParams2();
00155 }
00156
00158 int crosses(const boost::shared_ptr<IntersectionLink>& link) const
00159
00160
00161
00162
00163 {
00164
00165
00166
00167
00168 int close = 0;
00169 const IntersectionPoint *p1, *p2, *q1, *q2;
00170 getIntersectionPoints(p1, p2);
00171 link->getIntersectionPoints(q1, q2);
00172
00173 double aeps = p1->getTolerance()->getEpsge();
00174 double tol = 100.0*aeps;
00175
00176
00177 if (p1->numParams1() != 2 || p1->numParams2() != 2) {
00178 MESSAGE("IntersectionLink::crosses() is only implemented "
00179 "for two surfaces.");
00180 return 0;
00181 }
00182
00183
00184
00185 if (p1 == q1 || p1 == q2 || p2 == q1 || p2 == q2)
00186 return 0;
00187
00188
00189 if (p1->getPoint().dist(p2->getPoint()) < aeps ||
00190 q1->getPoint().dist(q2->getPoint()) < aeps)
00191 return 0;
00192
00193
00194 for (int i = 0; i < 4; i += 2)
00195 {
00196
00197 Point a = (i<2) ? p1->getPar1Point() : p1->getPar2Point();
00198 Point b = (i<2) ? p2->getPar1Point() : p2->getPar2Point();
00199 Point c = (i<2) ? q1->getPar1Point() : q1->getPar2Point();
00200 Point d = (i<2) ? q2->getPar1Point() : q2->getPar2Point();
00201 Point n1(-(b[1]-a[1]), b[0]-a[0]);
00202 Point n2(-(d[1]-c[1]), d[0]-c[0]);
00203 n1.normalize();
00204 n2.normalize();
00205 double s1 = (a - c)*n1;
00206 double s2 = (a - d)*n1;
00207 double s3 = (c - a)*n2;
00208 double s4 = (c - b)*n2;
00209 if (s1*s2 < 0.0 && s3*s4 < 0.0)
00210 {
00211 return 2;
00212 }
00213 else if (fabs(s1) < tol || fabs(s2) < tol || fabs(s3) < tol ||
00214 fabs(s4) < tol)
00215 close++;
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 }
00241
00242 return (close == 2) ? 1 : 0;
00243 }
00244
00247 const LinkType& linkType() const
00248 { return link_type_; }
00249
00252 LinkType& linkType()
00253 { return link_type_; }
00254
00256 void writeInfo() const
00257 {
00258
00259 p1_->writeParams(std::cout);
00260 std::cout << " -- ";
00261 p2_->writeParams(std::cout);
00262 std::cout << std::endl << "\t";
00263
00264
00265
00266 Point linkdir = p2_->getPoint() - p1_->getPoint();
00267 double len = linkdir.length();
00268 bool has_nonzero_link = (len != 0.0);
00269 if (has_nonzero_link) {
00270 linkdir.normalize();
00271 bool has_tangent;
00272 has_tangent
00273 = (p1_->getSingularityType() == ORDINARY_POINT
00274 || p1_->getSingularityType() == TANGENTIAL_POINT);
00275 if (has_tangent) {
00276 Point tangent = p1_->getTangent();
00277 tangent.normalize();
00278 double cos = tangent * linkdir;
00279 std::cout << "cos1 = ";
00280 std::cout.width(std::cout.precision()+4);
00281 std::cout << cos << " ";
00282 }
00283 else {
00284 std::cout << "cos1 = no tangent ";
00285 }
00286
00287 has_tangent
00288 = (p2_->getSingularityType() == ORDINARY_POINT
00289 || p2_->getSingularityType() == TANGENTIAL_POINT);
00290 if (has_tangent) {
00291 Point tangent = p2_->getTangent();
00292 tangent.normalize();
00293 double cos = -tangent * linkdir;
00294 std::cout << "cos2 = ";
00295 std::cout.width(std::cout.precision()+4);
00296 std::cout << cos << " ";
00297 }
00298 else {
00299 std::cout << "cos2 = no tangent ";
00300 }
00301 }
00302 else {
00303 std::cout << "link length = 0.0 ";
00304 }
00305
00306
00307 std::cout << "type = ";
00308 std::cout.width(2);
00309 std::cout << link_type_;
00310
00311 return;
00312 }
00313
00314 void dumpToStream(std::ostream& os)
00315 {
00316 double data[12];
00317 Point tmp = p1_->getPoint1();
00318 std::copy(tmp.begin(), tmp.end(), data);
00319 tmp = p2_->getPoint1();
00320 std::copy(tmp.begin(), tmp.end(), data+3);
00321 tmp = p1_->getPoint2();
00322 std::copy(tmp.begin(), tmp.end(), data+6);
00323 tmp = p2_->getPoint2();
00324 std::copy(tmp.begin(), tmp.end(), data+9);
00325 LineCloud lc(data,2);
00326 lc.writeStandardHeader(os);
00327 lc.write(os);
00328 }
00329
00330 private:
00331
00332
00333
00334
00335
00336 IntersectionPoint* const p1_;
00337 IntersectionPoint* const p2_;
00338
00339 bool delimits_partial_coincidence_;
00340 bool iso_[4];
00341
00342
00343 LinkType link_type_;
00344
00345 };
00346
00347
00349 };
00350
00351
00352 #endif // _INTERSECTIONLINK_H
00353
00354