$search
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 .......: Vertex3D.cpp 00012 * authors ....: Benjamin Pitzer 00013 * organization: Robert Bosch LLC 00014 * creation ...: 02/29/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/rtcFace3D.h" 00022 #include "rtc/rtcMesh3D.h" 00023 #include "rtc/rtcVertex3D.h" 00024 00025 //============================================================================== 00026 // NAMESPACE 00027 namespace rtc { 00028 00029 Vertex3D::Vertex3D(Mesh3D* _mesh) 00030 : IOObject(), mesh(_mesh),p(0,0,0),n(0,0,0),c(0,0,0),flags(0) 00031 { 00032 } 00033 00034 Vertex3D::Vertex3D(Mesh3D* _mesh, const Point3Df& _p) 00035 : IOObject(), mesh(_mesh),p(_p),n(0,0,0),c(0,0,0),flags(0) 00036 { 00037 } 00038 00039 Vertex3D::~Vertex3D() 00040 { 00041 } 00042 00043 Vertex3D::Vertex3D(const Vertex3D& other) 00044 : IOObject() 00045 { 00046 mesh = other.mesh; 00047 p = other.p; 00048 n = other.n; 00049 c = other.c; 00050 flags = other.flags; 00051 faces = other.faces; 00052 t = other.t; 00053 } 00054 00055 // calculate normal vector 00056 void Vertex3D::update() 00057 { 00058 if(faces.empty()) { 00059 n = Vec3f(1,0,0); 00060 } 00061 else { 00062 n.set(0.0f); 00063 for(unsigned int i=0;i<faces.size();++i) { 00064 n+=mesh->faces[faces[i]]->n; 00065 } 00066 } 00067 n.normalize(); 00068 } 00069 00070 // Mutators 00071 void Vertex3D::set(Vec3f _p) 00072 { 00073 set(_p.x[0],_p.x[1],_p.x[2]); 00074 } 00075 00076 void Vertex3D::set(float x, float y, float z) 00077 { 00078 p[0] = x; p[1] = y; p[2] = z; 00079 } 00080 00081 bool Vertex3D::getFlag(int flag) const 00082 { 00083 return (flags&flag); 00084 } 00085 00086 void Vertex3D::setFlag(int flag, bool value) 00087 { 00088 if(value) 00089 flags|=flag; 00090 else 00091 flags&=flag; 00092 } 00093 00094 bool Vertex3D::boundary() const 00095 { 00096 return getFlag(VERTEX_FLAG_BOUNDARY); 00097 } 00098 00099 void Vertex3D::setBoundary(bool boundary) 00100 { 00101 setFlag(VERTEX_FLAG_BOUNDARY,boundary); 00102 } 00103 00104 bool Vertex3D::hidden() const 00105 { 00106 return getFlag(VERTEX_FLAG_HIDDEN); 00107 } 00108 00109 void Vertex3D::setHidden(bool hidden) 00110 { 00111 setFlag(VERTEX_FLAG_HIDDEN,hidden); 00112 } 00113 00114 bool Vertex3D::hasTexCoord() const 00115 { 00116 return getFlag(VERTEX_FLAG_HAS_TEX_COORD); 00117 } 00118 00119 bool Vertex3D::write(OutputHandler &oh) const 00120 { 00121 rtc_write(oh,p); 00122 rtc_write(oh,n); 00123 rtc_write(oh,c); 00124 rtc_write(oh,"flags",flags); 00125 if(hasTexCoord()) rtc_write(oh,t); 00126 return true; 00127 } 00128 00129 void Vertex3D::write( FILE *fp ) const 00130 { 00131 fwrite(&p,sizeof(p),1,fp); 00132 fwrite(&n,sizeof(n),1,fp); 00133 fwrite(&c,sizeof(c),1,fp); 00134 fwrite(&flags,sizeof(flags),1,fp); 00135 if (hasTexCoord()) fwrite(&t,sizeof(t),1,fp); 00136 } 00137 00138 bool Vertex3D::read(InputHandler &ih) 00139 { 00140 rtc_read(ih,p); 00141 rtc_read(ih,n); 00142 rtc_read(ih,c); 00143 rtc_read(ih,"flags",flags); 00144 if(hasTexCoord()) rtc_read(ih,t); 00145 return true; 00146 } 00147 00148 void Vertex3D::read( FILE *fp ) 00149 { 00150 size_t res = 0; 00151 res+=fread(&p,sizeof(p),1,fp); 00152 res+=fread(&n,sizeof(n),1,fp); 00153 res+=fread(&c,sizeof(c),1,fp); 00154 res+=fread(&flags,sizeof(flags),1,fp); 00155 if (hasTexCoord()) res+=fread(&t,sizeof(t),1,fp); 00156 } 00157 00158 //============================================================================== 00159 } // NAMESPACE rtc 00160 //==============================================================================