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 #include "rtc/rtcGeometry3D.h"
00022 #include "rtc/rtcMesh3D.h"
00023 #include "rtc/rtcVertex3D.h"
00024 #include "rtc/rtcFace3D.h"
00025
00026 #define FACE_FLAG_BOUNDARY 0x01
00027 #define FACE_FLAG_HIDDEN 0x02
00028 #define FACE_FLAG_EMPTY2 0x04
00029 #define FACE_FLAG_EMPTY3 0x08
00030 #define FACE_FLAG_EMPTY4 0x10
00031 #define FACE_FLAG_EMPTY5 0x20
00032 #define FACE_FLAG_EMPTY6 0x40
00033 #define FACE_FLAG_EMPTY7 0x80
00034
00035
00036
00037 namespace rtc {
00038
00039 Face3D::Face3D(Mesh3D* _mesh, int v0, int v1, int v2)
00040 :mesh(_mesh),v(v0,v1,v2),flags(0)
00041 {
00042 }
00043
00044 Face3D::~Face3D()
00045 {
00046 }
00047
00048 Face3D::Face3D(const Face3D& other)
00049 {
00050 mesh = other.mesh;
00051 v = other.v;
00052 n = other.n;
00053 flags = other.flags;
00054 }
00055
00056
00057 void Face3D::update()
00058 {
00059 Vec3f t1 = mesh->vertices[v(1)]->p-mesh->vertices[v(0)]->p;
00060 Vec3f t2 = mesh->vertices[v(2)]->p-mesh->vertices[v(0)]->p;
00061 n = t1.cross(t2);
00062 n.normalize();
00063 }
00064
00065 bool Face3D::getFlag(int flag) const
00066 {
00067 return ((flags&flag)!=0);
00068 }
00069
00070 void Face3D::setFlag(int flag, bool value)
00071 {
00072 if(value)
00073 flags|=flag;
00074 else
00075 flags&=flag;
00076 }
00077
00078 bool Face3D::boundary() const
00079 {
00080 return getFlag(FACE_FLAG_BOUNDARY);
00081 }
00082
00083 void Face3D::setBoundary(bool boundary)
00084 {
00085 setFlag(FACE_FLAG_BOUNDARY,boundary);
00086 }
00087
00088 bool Face3D::hidden() const
00089 {
00090 return getFlag(FACE_FLAG_HIDDEN);
00091 }
00092
00093 void Face3D::setHidden(bool hidden)
00094 {
00095 setFlag(FACE_FLAG_HIDDEN,hidden);
00096 }
00097
00098 bool Face3D::write(OutputHandler &oh) const
00099 {
00100 rtc_write(oh,v);
00101 rtc_write(oh,n);
00102 rtc_write(oh,"flags",flags);
00103 return true;
00104 }
00105
00106 void Face3D::write( FILE *fp ) const
00107 {
00108 fwrite(&v,sizeof(v),1,fp);
00109 fwrite(&n,sizeof(n),1,fp);
00110 fwrite(&flags,sizeof(flags),1,fp);
00111 }
00112
00113 bool Face3D::read(InputHandler &ih)
00114 {
00115 rtc_read(ih,v);
00116 rtc_read(ih,n);
00117 rtc_read(ih,"flags",flags);
00118 return true;
00119 }
00120
00121 void Face3D::read( FILE *fp )
00122 {
00123 size_t res = 0;
00124 res+=fread(&v,sizeof(v),1,fp);
00125 res+=fread(&n,sizeof(n),1,fp);
00126 res+=fread(&flags,sizeof(flags),1,fp);
00127 }
00128
00129
00130 }
00131