00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef _WIN32
00022 #pragma warning(disable:4786)
00023 #endif
00024
00025 #include <cstdio>
00026 #include <cassert>
00027 #include "halfedge.h"
00028 #include "face.h"
00029 #include "vertex.h"
00030
00031 using namespace std;
00032 using namespace Geometry;
00033 using namespace HE;
00034
00035 HalfEdge* HalfEdge::prev()
00036 {
00037 HalfEdge* he = _next;
00038 while (he->next() != this)
00039 he = he->next();
00040
00041 return he;
00042 }
00043
00044 const HalfEdge* HalfEdge::prev() const
00045 {
00046 HalfEdge* he = _next;
00047 while (he->next() != this)
00048 he = he->next();
00049
00050 return he;
00051 }
00052
00053
00054 ostream& HE::operator<< (ostream& out, const HalfEdge& he)
00055 {
00056 char s[128];
00057 if (he.twin())
00058 {
00059 if (he.src())
00060 sprintf(s, "%d", he.src()->index());
00061 else
00062 strcpy(s, "NULL");
00063 }
00064 else
00065 strcpy(s, "unreachable through twin");
00066
00067 char d[128];
00068 if (he.dst())
00069 sprintf(d, "%d", he.dst()->index());
00070 else
00071 strcpy(d, "NULL");
00072
00073 return out << "[(src " << s
00074 << "), (dst " << d
00075 << "), (face " << (int) he.face()
00076 << "), (twin " << (int) he.twin()
00077 << "), (next " << (int) he.next() << ")]";
00078 }
00079
00080 Vector3Df HalfEdge::normal() const
00081 {
00082 return (src()->normal()+dst()->normal())/2;
00083 }
00084
00085
00086 Vector3Df HalfEdge::tangent() const
00087 {
00088 return dst()->position() - src()->position();
00089 }
00090
00091 Vector3Df HalfEdge::midpoint() const
00092 {
00093
00094 return (src()->position() + dst()->position()) / 2;
00095 }
00096
00097 bool HalfEdge::isBoundary() const
00098 {
00099 return face()->hole() || twin()->face()->hole();
00100 }
00101