Go to the documentation of this file.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 #include "surfaceLocation.H"
00027 #include <triSurface/triSurface.H>
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 Foam::vector Foam::surfaceLocation::normal(const triSurface& s) const
00041 {
00042 const vectorField& n = s.faceNormals();
00043
00044 if (elementType_ == triPointRef::NONE)
00045 {
00046 return n[index()];
00047 }
00048 else if (elementType_ == triPointRef::EDGE)
00049 {
00050 const labelList& eFaces = s.edgeFaces()[index()];
00051
00052 if (eFaces.size() == 1)
00053 {
00054 return n[eFaces[0]];
00055 }
00056 else
00057 {
00058 vector edgeNormal(vector::zero);
00059
00060 forAll(eFaces, i)
00061 {
00062 edgeNormal += n[eFaces[i]];
00063 }
00064 return edgeNormal/(mag(edgeNormal) + VSMALL);
00065 }
00066 }
00067 else
00068 {
00069 return s.pointNormals()[index()];
00070 }
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 void Foam::surfaceLocation::write(Ostream& os, const triSurface& s) const
00083 {
00084 if (elementType_ == triPointRef::NONE)
00085 {
00086 os << "trianglecoords:" << s[index()].tri(s.points());
00087 }
00088 else if (elementType() == triPointRef::EDGE)
00089 {
00090 const edge& e = s.edges()[index()];
00091
00092 os << "edgecoords:" << e.line(s.localPoints());
00093 }
00094 else
00095 {
00096 os << "pointcoord:" << s.localPoints()[index()];
00097 }
00098 }
00099
00100
00101 Foam::Istream& Foam::operator>>(Istream& is, surfaceLocation& sl)
00102 {
00103 label elType;
00104 is >> static_cast<pointIndexHit&>(sl)
00105 >> elType >> sl.triangle_;
00106 sl.elementType_ = triPointRef::proxType(elType);
00107 return is;
00108 }
00109
00110
00111 Foam::Ostream& Foam::operator<<(Ostream& os, const surfaceLocation& sl)
00112 {
00113 return os
00114 << static_cast<const pointIndexHit&>(sl)
00115 << token::SPACE << label(sl.elementType_)
00116 << token::SPACE << sl.triangle_;
00117 }
00118
00119
00120 Foam::Ostream& Foam::operator<<
00121 (
00122 Ostream& os,
00123 const InfoProxy<surfaceLocation>& ip
00124 )
00125 {
00126 const surfaceLocation& sl = ip.t_;
00127
00128 if (sl.elementType() == triPointRef::NONE)
00129 {
00130 os << "coord:" << sl.rawPoint()
00131 << " inside triangle:" << sl.index()
00132 << " excludeTriangle:" << sl.triangle();
00133 }
00134 else if (sl.elementType() == triPointRef::EDGE)
00135 {
00136 os << "coord:" << sl.rawPoint()
00137 << " on edge:" << sl.index()
00138 << " excludeTriangle:" << sl.triangle();
00139 }
00140 else
00141 {
00142 os << "coord:" << sl.rawPoint()
00143 << " on point:" << sl.index()
00144 << " excludeTriangle:" << sl.triangle();
00145 }
00146
00147 if (sl.hit())
00148 {
00149 os << " (hit)";
00150 }
00151 else
00152 {
00153 os << " (miss)";
00154 }
00155
00156 return os;
00157 }
00158
00159
00160