00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
00043 #define OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
00044
00045
00046
00047
00048 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
00049
00050
00051
00052 namespace OpenMesh {
00053 namespace Decimater {
00054
00055
00056
00057
00066 template <typename DecimaterT>
00067 class ModNormalFlippingT : public ModBaseT< DecimaterT >
00068 {
00069 public:
00070
00071 DECIMATING_MODULE( ModNormalFlippingT, DecimaterT, NormalFlipping );
00072
00073 typedef typename Mesh::Scalar Scalar;
00074
00075
00076 ModNormalFlippingT( DecimaterT &_dec)
00077 : Base(_dec, true), mesh_(Self::mesh())
00078 {
00079 set_max_normal_deviation( 90.0f );
00080 }
00081
00082
00083
00098 float collapse_priority(const CollapseInfo& _ci)
00099 {
00100
00101 mesh_.set_point(_ci.v0, _ci.p1);
00102
00103
00104 typename Mesh::ConstVertexFaceIter vf_it(mesh_, _ci.v0);
00105 typename Mesh::FaceHandle fh;
00106 typename Mesh::Scalar c(1.0);
00107
00108 for (; vf_it; ++vf_it)
00109 {
00110 fh = vf_it.handle();
00111 if (fh != _ci.fl && fh != _ci.fr)
00112 {
00113 typename Mesh::Normal n1 = mesh_.normal(fh);
00114 typename Mesh::Normal n2 = mesh_.calc_face_normal(fh);
00115
00116 c = dot(n1, n2);
00117
00118 if (c < min_cos_)
00119 break;
00120 }
00121 }
00122
00123
00124 mesh_.set_point(_ci.v0, _ci.p0);
00125
00126 return float( (c < min_cos_) ?
00127 Self::ILLEGAL_COLLAPSE :
00128 Self::LEGAL_COLLAPSE );
00129 }
00130
00131
00132
00134 Scalar max_normal_deviation() const { return max_deviation_ / M_PI * 180.0; }
00135
00136
00142 void set_max_normal_deviation(Scalar _f) {
00143 max_deviation_ = (Scalar)(_f / 180.0 * M_PI);
00144 min_cos_ = cos(max_deviation_);
00145 }
00146
00147
00148
00149
00150 void set_binary(bool _b)
00151 {
00152 if (!_b)
00153 {
00154 std::cerr << "ModNormalFlippingT can only be used binary\n";
00155 exit(1);
00156 }
00157 }
00158
00159
00160 private:
00161
00162 Mesh& mesh_;
00163 Scalar max_deviation_, min_cos_;
00164 };
00165
00166
00167
00168 }
00169 }
00170
00171 #endif // OPENACG_MODNORMALFLIPPING_HH defined
00172
00173