59 #ifndef OPENMESH_DECIMATER_MODROUNDNESST_HH 60 #define OPENMESH_DECIMATER_MODROUNDNESST_HH 68 #if defined(OM_CC_MSVC) 69 # define OM_ENABLE_WARNINGS 4244 70 # pragma warning(disable : OM_ENABLE_WARNINGS ) 90 template <
class MeshT>
99 typedef typename MeshT::Point Point;
131 double priority = 0.0;
132 typename Mesh::FaceHandle fhC, fhB;
137 C =
vector_cast<
Vec3f>(Base::mesh().point( Base::mesh().to_vertex_handle(*voh_it)));
138 fhC = Base::mesh().face_handle( *voh_it );
140 for (++voh_it; voh_it.is_valid(); ++voh_it)
144 C =
vector_cast<
Vec3f>(Base::mesh().point(Base::mesh().to_vertex_handle(*voh_it)));
145 fhC = Base::mesh().face_handle( *voh_it );
147 if ( fhB == _ci.
fl || fhB == _ci.
fr )
151 r = roundness( vector_cast<Vec3f>(_ci.
p1), B, C );
154 priority = std::max( priority, (1.0-r) );
160 C =
vector_cast<
Vec3f>(Base::mesh().point( Base::mesh().to_vertex_handle(*voh_it)));
161 fhC = Base::mesh().face_handle( *voh_it );
163 for (++voh_it; voh_it.is_valid() && (priority==Base::LEGAL_COLLAPSE); ++voh_it)
167 C =
vector_cast<
Vec3f>(Base::mesh().point(Base::mesh().to_vertex_handle(*voh_it)));
168 fhC = Base::mesh().face_handle( *voh_it );
170 if ( fhB == _ci.
fl || fhB == _ci.
fr )
173 priority = ( (r=roundness( vector_cast<Vec3f>(_ci.
p1), B, C )) < min_r_)
174 ? Base::ILLEGAL_COLLAPSE : Base::LEGAL_COLLAPSE;
178 return (
float) priority;
184 if (_factor >= 0.0 && _factor <= 1.0) {
188 value_type min_roundness = min_r_ * _factor / this->error_tolerance_factor_;
190 this->error_tolerance_factor_ = _factor;
198 void set_min_angle(
float _angle,
bool )
200 assert( _angle > 0 && _angle < 60 );
202 _angle = float(M_PI * _angle /180.0);
206 A =
Vec3f( 0.0f, 0.0f, 0.0f);
207 B =
Vec3f( 2.0f * cos(_angle), 0.0f, 0.0f);
208 C =
Vec3f( cos(_angle), sin(_angle), 0.0f);
210 double r1 = roundness(A,B,C);
212 _angle = float(0.5 * ( M_PI - _angle ));
214 A =
Vec3f( 0.0f, 0.0f, 0.0f);
215 B =
Vec3f( 2.0f*cos(_angle), 0.0f, 0.0f);
216 C =
Vec3f( cos(_angle), sin(_angle), 0.0f);
218 double r2 = roundness(A,B,C);
232 assert( 0.0 <= _min_roundness && _min_roundness <= 1.0 );
233 min_r_ = _min_roundness;
234 Base::set_binary(_binary);
241 Base::set_binary(
false);
287 const value_type epsilon = value_type(1e-15);
289 static const value_type sqrt43 = value_type(sqrt(4.0/3.0));
295 value_type aa = (B-C).sqrnorm();
296 value_type bb = vecAC.
sqrnorm();
297 value_type cc = vecAB.
sqrnorm();
298 value_type AA =
cross(vecAC,vecAB).sqrnorm();
303 double nom = AA * std::min( std::min(aa,bb),cc );
304 double denom = aa * bb * cc;
305 double nR = sqrt43 * sqrt(nom/denom);
320 #if defined(OM_CC_MSVC) && defined(OM_ENABLE_WARNINGS) 321 # pragma warning(default : OM_ENABLE_WARNINGS) 322 # undef OM_ENABLE_WARNINGS 325 #endif // OPENMESH_DECIMATER_MODROUNDNESST_HH defined void unset_min_roundness()
Unset minimum value constraint and enable non-binary mode.
Mesh::FaceHandle fl
Left face.
~ModRoundnessT()
Destructor.
Mesh::FaceHandle fr
Right face.
bool is_binary(void) const
Returns true if criteria returns a binary value.
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
Mesh::Point p1
Positions of remaining vertex.
void set_error_tolerance_factor(double _factor)
set the percentage of minimum roundness
Use Roundness of triangles to control decimation.
Mesh::VertexHandle v0
Vertex to be removed.
float collapse_priority(const CollapseInfo &_ci)
void set_min_roundness(value_type _min_roundness, bool _binary=true)
VectorT< float, 3 > Vec3f
decltype(std::declval< S >()*std::declval< S >()) sqrnorm() const
compute squared euclidean norm
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
ModRoundnessT(MeshT &_dec)
Constructor.