52 #ifndef OPENMESH_DECIMATER_MODNORMALDEVIATIONT_HH
53 #define OPENMESH_DECIMATER_MODNORMALDEVIATIONT_HH
59 #include <OpenMesh/Core/Utils/Property.hh>
60 #include <OpenMesh/Core/Geometry/NormalConeT.hh>
86 template <
class MeshT>
93 typedef typename Mesh::Scalar Scalar;
94 typedef typename Mesh::Point Point;
96 typedef typename Mesh::VertexHandle VertexHandle;
97 typedef typename Mesh::FaceHandle FaceHandle;
98 typedef typename Mesh::EdgeHandle EdgeHandle;
107 : Base(_mesh, true), mesh_(Base::
mesh())
110 mesh_.add_property(normal_cones_);
116 mesh_.add_property(normal_cones_);
122 return normal_deviation_ / M_PI * 180.0;
127 normal_deviation_ = _s / 180.0 * M_PI;
133 if (!normal_cones_.is_valid())
134 mesh_.add_property(normal_cones_);
136 typename Mesh::FaceIter f_it = mesh_.faces_begin(),
137 f_end = mesh_.faces_end();
139 for (; f_it != f_end; ++f_it)
140 mesh_.property(normal_cones_, *f_it) =
NormalCone(mesh_.normal(*f_it));
159 mesh_.set_point(_ci.
v0, _ci.
p1);
162 typename Mesh::Scalar max_angle(0.0);
163 typename Mesh::ConstVertexFaceIter vf_it(mesh_, _ci.
v0);
164 typename Mesh::FaceHandle fh, fhl, fhr;
166 if (_ci.
v0vl.is_valid()) fhl = mesh_.face_handle(_ci.
v0vl);
167 if (_ci.
vrv0.is_valid()) fhr = mesh_.face_handle(_ci.
vrv0);
169 for (; vf_it.is_valid(); ++vf_it) {
171 if (fh != _ci.
fl && fh != _ci.
fr) {
172 NormalCone nc = mesh_.property(normal_cones_, fh);
175 if (fh == fhl) nc.
merge(mesh_.property(normal_cones_, _ci.
fl));
176 if (fh == fhr) nc.
merge(mesh_.property(normal_cones_, _ci.
fr));
178 if (nc.
angle() > max_angle) {
179 max_angle = nc.
angle();
180 if (max_angle > 0.5 * normal_deviation_)
188 mesh_.set_point(_ci.
v0, _ci.
p0);
191 return (max_angle < 0.5 * normal_deviation_ ? max_angle :
float( Base::ILLEGAL_COLLAPSE ));
196 if (_factor >= 0.0 && _factor <= 1.0) {
200 Scalar
normal_deviation = (normal_deviation_ * 180.0/M_PI) * _factor / this->error_tolerance_factor_;
202 this->error_tolerance_factor_ = _factor;
209 typename Mesh::VertexFaceIter vf_it(mesh_, _ci.
v1);
210 for (; vf_it.is_valid(); ++vf_it)
211 mesh_.property(normal_cones_, *vf_it).
216 typename Mesh::FaceHandle fh;
218 if (_ci.
vlv1.is_valid()) {
219 fh = mesh_.face_handle(mesh_.opposite_halfedge_handle(_ci.
vlv1));
221 mesh_.property(normal_cones_, fh).
222 merge(mesh_.property(normal_cones_, _ci.
fl));
225 if (_ci.
v1vr.is_valid()) {
226 fh = mesh_.face_handle(mesh_.opposite_halfedge_handle(_ci.
v1vr));
228 mesh_.property(normal_cones_, fh).
229 merge(mesh_.property(normal_cones_, _ci.
fr));
238 Scalar normal_deviation_;
247 #endif // OPENMESH_DECIMATER_MODNORMALDEVIATIONT_HH defined
MeshT & mesh()
Access the mesh associated with the decimater.
Definition: ModBaseT.hh:275
Base class for all decimation modules.
/class NormalCone NormalCone.hh <ACG/Geometry/Types/NormalCone.hh>
Definition: NormalConeT.hh:78
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:73
Handle representing a face property.
Definition: Property.hh:518
void set_error_tolerance_factor(double _factor)
set the percentage of normal deviation
Definition: ModNormalDeviationT.hh:195
void merge(const NormalConeT &)
merge _cone; this instance will then enclose both former cones
Definition: NormalConeT.cc:120
Mesh::HalfedgeHandle vlv1
Outer remaining halfedge of diamond spanned by v0, v1, vl, and vr.
Definition: CollapseInfoT.hh:102
Base class for all decimation modules.
Definition: ModBaseT.hh:190
Mesh::VertexHandle v1
Remaining vertex.
Definition: CollapseInfoT.hh:91
Scalar angle() const
returns size of cone (radius in radians)
Definition: NormalConeT.hh:105
float collapse_priority(const CollapseInfo &_ci)
Control normals when Decimating.
Definition: ModNormalDeviationT.hh:157
Mesh::Point p0
Position of removed vertex.
Definition: CollapseInfoT.hh:92
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80
Mesh::HalfedgeHandle vrv0
Outer remaining halfedge of diamond spanned by v0, v1, vl, and vr.
Definition: CollapseInfoT.hh:102
void initialize()
Allocate and init normal cones.
Definition: ModNormalDeviationT.hh:132
Scalar normal_deviation() const
Get normal deviation ( 0 .. 360 )
Definition: ModNormalDeviationT.hh:121
Use Normal deviation to control decimation.
Definition: ModNormalDeviationT.hh:87
Mesh::HalfedgeHandle v1vr
Outer remaining halfedge of diamond spanned by v0, v1, vl, and vr.
Definition: CollapseInfoT.hh:102
~ModNormalDeviationT()
Destructor.
Definition: ModNormalDeviationT.hh:115
ModNormalDeviationT(MeshT &_mesh, float _max_dev=180.0)
Constructor.
Definition: ModNormalDeviationT.hh:106
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:90
void postprocess_collapse(const CollapseInfo &_ci)
After _from_vh has been collapsed into _to_vh, this method will be called.
Definition: ModNormalDeviationT.hh:207
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:93
void set_normal_deviation(Scalar _s)
Set normal deviation ( 0 .. 360 )
Definition: ModNormalDeviationT.hh:126
Mesh::FaceHandle fl
Left face.
Definition: CollapseInfoT.hh:94
Mesh::FaceHandle fr
Right face.
Definition: CollapseInfoT.hh:95
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:147
Mesh::HalfedgeHandle v0vl
Outer remaining halfedge of diamond spanned by v0, v1, vl, and vr.
Definition: CollapseInfoT.hh:102