corner.cpp
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 #include "mesh3d/corner.h"
00021 #include "mesh3d/attribute_map.h"
00022 #include "mesh3d/point.h"
00023 #include "mesh3d/vec3.h"
00024 #include <cassert>
00025
00033 namespace mesh3d {
00034
00035
00036
00037
00038
00039
00040 void corner::compute_normal(
00041 std::tr1::shared_ptr<attribute_map<mesh3d::corner*, vec3> > corner_normals,
00042 std::tr1::shared_ptr<attribute_map<mesh3d::polygon*, vec3> > polygon_normals,
00043 std::tr1::shared_ptr<attribute_map<mesh3d::point*, vec3> > point_locations,
00044 float cos_max_smoothing_angle
00045 )
00046 {
00047 mesh3d::polygon *pol = polygon();
00048 mesh3d::point *pnt = point ();
00049
00050 vec3 corner_normal;
00051
00052 if(polygon_normals->has(pol) == false)
00053 {
00054 corner_normal = vec3(0, 0, 0);
00055 }
00056 else
00057 {
00058 vec3 polygon_normal = polygon_normals->value(pol);
00059 corner_normal = polygon_normal;
00060
00061 size_t point_corners = 0;
00062 size_t participants = 0;
00063 for(
00064 point::corner_collection::iterator i = pnt->corners().begin();
00065 i != pnt->corners().end();
00066 ++i
00067 )
00068 {
00069 ++point_corners;
00070 mesh3d::corner *point_corner = *i;
00071 mesh3d::polygon *neighbor_pol = point_corner->polygon();
00072 if(
00073 (pol != neighbor_pol ) &&
00074 (polygon_normals->has(neighbor_pol) ) &&
00075 (neighbor_pol->corners().size() > 2)
00076 )
00077 {
00078 vec3 neighbor_normal = polygon_normals->value(neighbor_pol);
00079 float cos_angle = dot(
00080 polygon_normal,
00081 neighbor_normal
00082 );
00083 if(cos_angle < cos_max_smoothing_angle)
00084 {
00085 corner_normal += neighbor_normal;
00086 ++participants;
00087 }
00088 }
00089 }
00090
00091 corner_normal = normalize(corner_normal);
00092 }
00093 corner_normals->set_value(this, corner_normal);
00094 }
00095
00096 }
00097