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
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00046
00047
00048
00049
00050
00051
00052 #ifndef OPENMESH_TOOLS_MODROUNDNESST_HH
00053 #define OPENMESH_TOOLS_MODROUNDNESST_HH
00054
00055
00056
00057
00058 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
00059 #include <math.h>
00060
00061 #if defined(OM_CC_MSVC)
00062 # define OM_ENABLE_WARNINGS 4244
00063 # pragma warning(disable : OM_ENABLE_WARNINGS )
00064 #endif
00065
00066
00067
00068 namespace OpenMesh {
00069 namespace Decimater {
00070
00071
00072
00073
00074
00077 template <class DecimaterType>
00078 class ModRoundnessT : public ModBaseT<DecimaterType>
00079 {
00080 public:
00081 DECIMATING_MODULE( ModRoundnessT, DecimaterType, Roundness );
00082
00083 public:
00084
00085
00086 typedef typename Mesh::Point Point;
00087 typedef typename vector_traits<Point>::value_type value_type;
00088
00089 public:
00090
00092 ModRoundnessT( DecimaterType &_dec ) :
00093 Base(_dec, false),
00094 min_r_(-1.0)
00095 { }
00096
00098 ~ModRoundnessT() { }
00099
00100 public:
00101
00112 float collapse_priority(const CollapseInfo& _ci)
00113 {
00114
00115
00116 typename Mesh::ConstVertexOHalfedgeIter voh_it(Base::mesh(), _ci.v0);
00117 double r;
00118 double priority = 0.0;
00119 typename Mesh::FaceHandle fhC, fhB;
00120 Vec3f B,C;
00121
00122 if ( min_r_ < 0.0 )
00123 {
00124 C = vector_cast<Vec3f>(Base::mesh().point( Base::mesh().to_vertex_handle(voh_it)));
00125 fhC = Base::mesh().face_handle( voh_it.handle() );
00126
00127 for (++voh_it; voh_it; ++voh_it)
00128 {
00129 B = C;
00130 fhB = fhC;
00131 C = vector_cast<Vec3f>(Base::mesh().point(Base::mesh().to_vertex_handle(voh_it)));
00132 fhC = Base::mesh().face_handle( voh_it.handle() );
00133
00134 if ( fhB == _ci.fl || fhB == _ci.fr )
00135 continue;
00136
00137
00138 r = roundness( vector_cast<Vec3f>(_ci.p1), B, C );
00139
00140
00141 priority = std::max( priority, (1.0-r) );
00142
00143 }
00144 }
00145 else
00146 {
00147 C = vector_cast<Vec3f>(Base::mesh().point( Base::mesh().to_vertex_handle(voh_it)));
00148 fhC = Base::mesh().face_handle( voh_it.handle() );
00149
00150 for (++voh_it; voh_it && (priority==Base::LEGAL_COLLAPSE); ++voh_it)
00151 {
00152 B = C;
00153 fhB = fhC;
00154 C = vector_cast<Vec3f>(Base::mesh().point(Base::mesh().to_vertex_handle(voh_it)));
00155 fhC = Base::mesh().face_handle( voh_it.handle() );
00156
00157 if ( fhB == _ci.fl || fhB == _ci.fr )
00158 continue;
00159
00160 priority = ( (r=roundness( vector_cast<Vec3f>(_ci.p1), B, C )) < min_r_)
00161 ? Base::ILLEGAL_COLLAPSE
00162 : Base::LEGAL_COLLAPSE;
00163 }
00164 }
00165
00166 return (float) priority;
00167 }
00168
00169
00170
00171 public:
00172
00173 void set_min_angle( float _angle, bool )
00174 {
00175 assert( _angle > 0 && _angle < 60 );
00176
00177 _angle = float(M_PI * _angle /180.0);
00178
00179 Vec3f A,B,C;
00180
00181 A = Vec3f( 0, 0, 0);
00182 B = Vec3f( 2*cos(_angle), 0, 0);
00183 C = Vec3f( cos(_angle), sin(_angle), 0);
00184
00185 double r1 = roundness(A,B,C);
00186
00187 _angle = float(0.5 * ( M_PI - _angle ));
00188
00189 A = Vec3f( 0, 0, 0);
00190 B = Vec3f( 2*cos(_angle), 0, 0);
00191 C = Vec3f( cos(_angle), sin(_angle), 0);
00192
00193 double r2 = roundness(A,B,C);
00194
00195 set_min_roundness( value_type(std::min(r1,r2)), true );
00196 }
00197
00205 void set_min_roundness( value_type _min_roundness, bool _binary=true )
00206 {
00207 assert( 0.0 <= _min_roundness && _min_roundness <= 1.0 );
00208 min_r_ = _min_roundness;
00209 Base::set_binary(_binary);
00210 }
00211
00213 void unset_min_roundness()
00214 {
00215 min_r_ = -1.0;
00216 Base::set_binary(false);
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 double roundness( const Vec3f& A, const Vec3f& B, const Vec3f &C )
00261 {
00262 const value_type epsilon = value_type(1e-15);
00263
00264 static const value_type sqrt43 = value_type(sqrt(4.0/3.0));
00265
00266 Vec3f vecAC = C-A;
00267 Vec3f vecAB = B-A;
00268
00269
00270 value_type aa = (B-C).sqrnorm();
00271 value_type bb = vecAC.sqrnorm();
00272 value_type cc = vecAB.sqrnorm();
00273 value_type AA = cross(vecAC,vecAB).sqrnorm();
00274
00275 if ( AA < epsilon )
00276 return 0.0;
00277
00278 double nom = AA * std::min( std::min(aa,bb),cc );
00279 double denom = aa * bb * cc;
00280 double nR = sqrt43 * sqrt(nom/denom);
00281
00282 return nR;
00283 }
00284
00285 private:
00286
00287 value_type min_r_;
00288 };
00289
00290
00291
00292 }
00293 }
00294
00295 #if defined(OM_CC_MSVC) && defined(OM_ENABLE_WARNINGS)
00296 # pragma warning(default : OM_ENABLE_WARNINGS)
00297 # undef OM_ENABLE_WARNINGS
00298 #endif
00299
00300 #endif // OPENMESH_TOOLS_PROGMESHT_HH defined
00301
00302