52 #ifndef OPENMESH_DECIMATER_MODROUNDNESST_HH
53 #define OPENMESH_DECIMATER_MODROUNDNESST_HH
61 #if defined(OM_CC_MSVC)
62 # define OM_ENABLE_WARNINGS 4244
63 # pragma warning(disable : OM_ENABLE_WARNINGS )
83 template <
class MeshT>
92 typedef typename MeshT::Point Point;
124 double priority = 0.0;
125 typename Mesh::FaceHandle fhC, fhB;
130 C =
vector_cast<Vec3f>(Base::mesh().point( Base::mesh().to_vertex_handle(*voh_it)));
131 fhC = Base::mesh().face_handle( *voh_it );
133 for (++voh_it; voh_it.is_valid(); ++voh_it)
137 C =
vector_cast<Vec3f>(Base::mesh().point(Base::mesh().to_vertex_handle(*voh_it)));
138 fhC = Base::mesh().face_handle( *voh_it );
140 if ( fhB == _ci.
fl || fhB == _ci.
fr )
144 r = roundness( vector_cast<Vec3f>(_ci.
p1), B, C );
147 priority = std::max( priority, (1.0-r) );
153 C =
vector_cast<Vec3f>(Base::mesh().point( Base::mesh().to_vertex_handle(*voh_it)));
154 fhC = Base::mesh().face_handle( *voh_it );
156 for (++voh_it; voh_it.is_valid() && (priority==Base::LEGAL_COLLAPSE); ++voh_it)
160 C =
vector_cast<Vec3f>(Base::mesh().point(Base::mesh().to_vertex_handle(*voh_it)));
161 fhC = Base::mesh().face_handle( *voh_it );
163 if ( fhB == _ci.
fl || fhB == _ci.
fr )
166 priority = ( (r=roundness( vector_cast<Vec3f>(_ci.
p1), B, C )) < min_r_)
167 ? Base::ILLEGAL_COLLAPSE : Base::LEGAL_COLLAPSE;
171 return (
float) priority;
177 if (_factor >= 0.0 && _factor <= 1.0) {
181 value_type min_roundness = min_r_ * _factor / this->error_tolerance_factor_;
183 this->error_tolerance_factor_ = _factor;
191 void set_min_angle(
float _angle,
bool )
193 assert( _angle > 0 && _angle < 60 );
195 _angle = float(M_PI * _angle /180.0);
199 A = Vec3f( 0.0f, 0.0f, 0.0f);
200 B = Vec3f( 2.0f * cos(_angle), 0.0f, 0.0f);
201 C = Vec3f( cos(_angle), sin(_angle), 0.0f);
203 double r1 = roundness(A,B,C);
205 _angle = float(0.5 * ( M_PI - _angle ));
207 A = Vec3f( 0.0f, 0.0f, 0.0f);
208 B = Vec3f( 2.0f*cos(_angle), 0.0f, 0.0f);
209 C = Vec3f( cos(_angle), sin(_angle), 0.0f);
211 double r2 = roundness(A,B,C);
225 assert( 0.0 <= _min_roundness && _min_roundness <= 1.0 );
226 min_r_ = _min_roundness;
227 Base::set_binary(_binary);
234 Base::set_binary(
false);
278 double roundness(
const Vec3f& A,
const Vec3f& B,
const Vec3f &C )
280 const value_type epsilon = value_type(1e-15);
282 static const value_type sqrt43 = value_type(sqrt(4.0/3.0));
288 value_type aa = (B-C).sqrnorm();
289 value_type bb = vecAC.sqrnorm();
290 value_type cc = vecAB.sqrnorm();
291 value_type AA =
cross(vecAC,vecAB).sqrnorm();
296 double nom = AA * std::min( std::min(aa,bb),cc );
297 double denom = aa * bb * cc;
298 double nR = sqrt43 * sqrt(nom/denom);
313 #if defined(OM_CC_MSVC) && defined(OM_ENABLE_WARNINGS)
314 # pragma warning(default : OM_ENABLE_WARNINGS)
315 # undef OM_ENABLE_WARNINGS
318 #endif // OPENMESH_DECIMATER_MODROUNDNESST_HH defined
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:169
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:147
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:73
Base class for all decimation modules.
Definition: ModBaseT.hh:190
vector_caster< dst_t, src_t >::return_type vector_cast(const src_t &_src)
Cast vector type to another vector type by copying the vector elements.
Definition: vector_cast.hh:170
ModRoundnessT(MeshT &_dec)
Constructor.
Definition: ModRoundnessT.hh:98
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:90
~ModRoundnessT()
Destructor.
Definition: ModRoundnessT.hh:104
Mesh::FaceHandle fr
Right face.
Definition: CollapseInfoT.hh:95
float collapse_priority(const CollapseInfo &_ci)
Compute collapse priority due to roundness of triangle.
Definition: ModRoundnessT.hh:118
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:189
Use Roundness of triangles to control decimation.
Definition: ModRoundnessT.hh:84
bool is_binary(void) const
Returns true if criteria returns a binary value.
Definition: ModBaseT.hh:218
Helper class providing information about a vector type.
Definition: vector_traits.hh:86
Base class for all decimation modules.
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:93
Mesh::FaceHandle fl
Left face.
Definition: CollapseInfoT.hh:94
void set_min_roundness(value_type _min_roundness, bool _binary=true)
Set a minimum roundness value.
Definition: ModRoundnessT.hh:223
void unset_min_roundness()
Unset minimum value constraint and enable non-binary mode.
Definition: ModRoundnessT.hh:231
void set_error_tolerance_factor(double _factor)
set the percentage of minimum roundness
Definition: ModRoundnessT.hh:175