connects to points through corners
#include <polygon.h>
Public Types | |
typedef std::vector < mesh3d::corner * > | corner_collection |
Public Member Functions | |
polygon () | |
~polygon () | |
void | copy_polygon_normal_to_corners (std::tr1::shared_ptr< attribute_map< mesh3d::corner *, mesh3d::vec3 > > corner_normals, std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > polygon_normals) |
void | compute_normal (std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > polygon_normals, std::tr1::shared_ptr< attribute_map< mesh3d::point *, mesh3d::vec3 > > point_locations) |
void | compute_centroid (std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > polygon_centroids, std::tr1::shared_ptr< attribute_map< mesh3d::point *, mesh3d::vec3 > > point_locations) |
void | compute_corner_normals (std::tr1::shared_ptr< attribute_map< mesh3d::corner *, mesh3d::vec3 > > corner_normals, std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > polygon_normals, std::tr1::shared_ptr< attribute_map< mesh3d::point *, mesh3d::vec3 > > point_locations, float cos_max_smoothing_angle) |
mesh3d::corner * | corner (mesh3d::point *pnt) |
mesh3d::corner * | make_corner (mesh3d::point *pnt) |
corner_collection & | corners () |
corner_collection const & | corners () const |
void | reverse () |
Definition at line 43 of file polygon.h.
typedef std::vector<mesh3d::corner*> mesh3d::polygon::corner_collection |
mesh3d::polygon::~polygon | ( | ) |
Definition at line 37 of file polygon.cpp.
00038 { 00039 for( 00040 corner_collection::iterator i = m_corners.begin(); 00041 i != m_corners.end(); 00042 ++i 00043 ) 00044 { 00045 mesh3d::corner *cor = *i; 00046 delete cor; 00047 *i = 0; 00048 } 00049 m_corners.clear(); 00050 }
void mesh3d::polygon::copy_polygon_normal_to_corners | ( | std::tr1::shared_ptr< attribute_map< mesh3d::corner *, mesh3d::vec3 > > | corner_normals, | |
std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > | polygon_normals | |||
) |
Definition at line 145 of file polygon.cpp.
00149 { 00150 if(m_corners.size() > 2) 00151 { 00152 mesh3d::vec3 pol_normal = polygon_normals->value(this); 00153 for( 00154 corner_collection::iterator i = m_corners.begin(); 00155 i != m_corners.end(); 00156 ++i 00157 ) 00158 { 00159 mesh3d::corner *cor = *i; 00160 corner_normals->set_value(cor, pol_normal); 00161 } 00162 } 00163 }
void mesh3d::polygon::compute_normal | ( | std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > | polygon_normals, | |
std::tr1::shared_ptr< attribute_map< mesh3d::point *, mesh3d::vec3 > > | point_locations | |||
) |
Definition at line 52 of file polygon.cpp.
00056 { 00057 if(m_corners.size() > 2) 00058 { 00059 corner_collection::iterator i = m_corners.begin(); 00060 mesh3d::corner *c0 = *i; ++i; /* first point in polygon */ 00061 mesh3d::corner *c1 = *i; /* second point in polygon */ 00062 mesh3d::corner *c2 = m_corners.back(); /* last point in polygon */ 00063 mesh3d::point *p0 = c0->point(); 00064 mesh3d::point *p1 = c1->point(); 00065 mesh3d::point *p2 = c2->point(); 00066 00067 /* Make sure all points are unique from others */ 00068 if( 00069 (p0 != p1) && 00070 (p0 != p2) && 00071 (p1 != p2) 00072 ) 00073 { 00074 vec3 pos0 = point_locations->value(p0); 00075 vec3 pos1 = point_locations->value(p1); 00076 vec3 pos2 = point_locations->value(p2); 00077 vec3 normal = cross((pos2 - pos0), (pos1 - pos0)); 00078 normal = normalize(normal); 00079 polygon_normals->set_value(this, normal); 00080 } 00081 else 00082 { 00083 throw std::exception("polygons with duplicate points\n"); 00084 } 00085 00086 } 00087 }
void mesh3d::polygon::compute_centroid | ( | std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > | polygon_centroids, | |
std::tr1::shared_ptr< attribute_map< mesh3d::point *, mesh3d::vec3 > > | point_locations | |||
) |
Definition at line 89 of file polygon.cpp.
00093 { 00094 mesh3d::vec3 centroid = mesh3d::vec3(0.0f, 0.0f, 0.0f); 00095 int count = 0; 00096 for( 00097 corner_collection::iterator i = m_corners.begin(); 00098 i != m_corners.end(); 00099 ++i 00100 ) 00101 { 00102 mesh3d::corner *cor = *i; 00103 mesh3d::point *pnt = cor->point(); 00104 mesh3d::vec3 pos0 = point_locations->value(pnt); 00105 centroid += pos0; 00106 ++count; 00107 } 00108 if(count > 0) 00109 { 00110 centroid /= (float)(count); 00111 polygon_centroids->set_value(this, centroid); 00112 } 00113 else 00114 { 00115 polygon_centroids->set_value(this, centroid); 00116 } 00117 }
void mesh3d::polygon::compute_corner_normals | ( | std::tr1::shared_ptr< attribute_map< mesh3d::corner *, mesh3d::vec3 > > | corner_normals, | |
std::tr1::shared_ptr< attribute_map< mesh3d::polygon *, mesh3d::vec3 > > | polygon_normals, | |||
std::tr1::shared_ptr< attribute_map< mesh3d::point *, mesh3d::vec3 > > | point_locations, | |||
float | cos_max_smoothing_angle | |||
) |
Definition at line 119 of file polygon.cpp.
00125 { 00126 if(m_corners.size() > 2) 00127 { 00128 for( 00129 corner_collection::iterator i = m_corners.begin(); 00130 i != m_corners.end(); 00131 ++i 00132 ) 00133 { 00134 mesh3d::corner *cor = *i; 00135 cor->compute_normal( 00136 corner_normals, 00137 polygon_normals, 00138 point_locations, 00139 cos_max_smoothing_angle 00140 ); 00141 } 00142 } 00143 }
mesh3d::corner * mesh3d::polygon::corner | ( | mesh3d::point * | pnt | ) |
Definition at line 165 of file polygon.cpp.
00166 { 00167 for( 00168 corner_collection::iterator i = m_corners.begin(); 00169 i != m_corners.end(); 00170 ++i 00171 ) 00172 { 00173 mesh3d::corner *cor = *i; 00174 if(pnt == cor->point()) 00175 { 00176 return cor; 00177 } 00178 } 00179 return 0; 00180 }
mesh3d::corner * mesh3d::polygon::make_corner | ( | mesh3d::point * | pnt | ) |
Definition at line 182 of file polygon.cpp.
00183 { 00184 mesh3d::corner *cor = new mesh3d::corner(pnt, this); 00185 pnt->add_corner(cor); 00186 m_corners.push_back(cor); 00187 return cor; 00188 }
corner_collection& mesh3d::polygon::corners | ( | ) | [inline] |
corner_collection const& mesh3d::polygon::corners | ( | ) | const [inline] |
void mesh3d::polygon::reverse | ( | ) | [inline] |
Definition at line 77 of file polygon.h.
00077 { std::reverse(m_corners.begin(), m_corners.end()); }