rtcFace3D.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007
00003  * Robert Bosch LLC
00004  * Research and Technology Center North America
00005  * Palo Alto, California
00006  *
00007  * All rights reserved.
00008  *
00009  *------------------------------------------------------------------------------
00010  * project ....: Autonomous Technologies
00011  * file .......: Face3D.cpp
00012  * authors ....: Benjamin Pitzer
00013  * organization: Robert Bosch LLC
00014  * creation ...: 03/28/2008
00015  * modified ...: $Date:2008-03-03 10:26:02 -0800 (Mon, 03 Mar 2008) $
00016  * changed by .: $Author:benjaminpitzer $
00017  * revision ...: $Revision:141 $
00018  */
00019 
00020 //== INCLUDES ==================================================================
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 // NAMESPACE
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 // calculate edge vector and normal vector
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 } // NAMESPACE rtc
00131 //==============================================================================


rtc
Author(s): Benjamin Pitzer
autogenerated on Mon Oct 6 2014 10:07:34