Decimater.hh 11.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef OPENMESH_PYTHON_DECIMATER_HH
#define OPENMESH_PYTHON_DECIMATER_HH

#include "Python/Bindings.hh"
#include "OpenMesh/Tools/Decimater/ModBaseT.hh"
#include "OpenMesh/Tools/Decimater/ModAspectRatioT.hh"
#include "OpenMesh/Tools/Decimater/ModEdgeLengthT.hh"
#include "OpenMesh/Tools/Decimater/ModHausdorffT.hh"
#include "OpenMesh/Tools/Decimater/ModIndependentSetsT.hh"
#include "OpenMesh/Tools/Decimater/ModNormalDeviationT.hh"
#include "OpenMesh/Tools/Decimater/ModNormalFlippingT.hh"
#include "OpenMesh/Tools/Decimater/ModProgMeshT.hh"
#include "OpenMesh/Tools/Decimater/ModQuadricT.hh"
#include "OpenMesh/Tools/Decimater/ModRoundnessT.hh"
#include "OpenMesh/Tools/Decimater/DecimaterT.hh"

#include <cstdio>

namespace OpenMesh {
namespace Python {

Alexander Dielen's avatar
Alexander Dielen committed
22 23
#define INIT_MESH_REF init<Mesh&>()[with_custodian_and_ward<1,2>()]

24 25 26 27 28 29 30 31 32 33 34 35 36
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(decimate_overloads, decimate, 0, 1)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(decimate_to_faces_overloads, decimate_to_faces, 0, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_max_err_overloads, set_max_err, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_min_roundness_overloads, set_min_roundness, 1, 2)


template <class Handle>
void expose_module_handle(const char *_name) {
	class_<Handle, boost::noncopyable>(_name)
		.def("is_valid", &Handle::is_valid)
		;
}

37 38 39 40 41 42 43 44 45 46
template <class Module>
list infolist(Module& _self) {
	const typename Module::InfoList& infos = _self.infolist();
	list res;
	for (size_t i = 0; i < infos.size(); ++i) {
		res.append(infos[i]);
	}
	return res;
}

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
template <class Mesh>
void expose_decimater(const char *_name) {

	typedef Decimater::ModBaseT<Mesh> ModBase;
	typedef Decimater::ModAspectRatioT<Mesh> ModAspectRatio;
	typedef Decimater::ModEdgeLengthT<Mesh> ModEdgeLength;
	typedef Decimater::ModHausdorffT<Mesh> ModHausdorff;
	typedef Decimater::ModIndependentSetsT<Mesh> ModIndependentSets;
	typedef Decimater::ModNormalDeviationT<Mesh> ModNormalDeviation;
	typedef Decimater::ModNormalFlippingT<Mesh> ModNormalFlipping;
	typedef Decimater::ModProgMeshT<Mesh> ModProgMesh;
	typedef Decimater::ModQuadricT<Mesh> ModQuadric;
	typedef Decimater::ModRoundnessT<Mesh> ModRoundness;

	typedef Decimater::ModHandleT<ModAspectRatio> ModAspectRatioHandle;
	typedef Decimater::ModHandleT<ModEdgeLength> ModEdgeLengthHandle;
	typedef Decimater::ModHandleT<ModHausdorff> ModHausdorffHandle;
	typedef Decimater::ModHandleT<ModIndependentSets> ModIndependentSetsHandle;
	typedef Decimater::ModHandleT<ModNormalDeviation> ModNormalDeviationHandle;
	typedef Decimater::ModHandleT<ModNormalFlipping> ModNormalFlippingHandle;
	typedef Decimater::ModHandleT<ModProgMesh> ModProgMeshHandle;
	typedef Decimater::ModHandleT<ModQuadric> ModQuadricHandle;
	typedef Decimater::ModHandleT<ModRoundness> ModRoundnessHandle;

	typedef Decimater::BaseDecimaterT<Mesh> BaseDecimater;
	typedef Decimater::DecimaterT<Mesh> Decimater;

74 75 76
	typedef typename ModProgMesh::Info Info;
	typedef std::vector<Info> InfoList;

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
	bool (BaseDecimater::*add1)(ModAspectRatioHandle&) = &Decimater::add;
	bool (BaseDecimater::*add2)(ModEdgeLengthHandle&) = &Decimater::add;
	bool (BaseDecimater::*add3)(ModHausdorffHandle&) = &Decimater::add;
	bool (BaseDecimater::*add4)(ModIndependentSetsHandle&) = &Decimater::add;
	bool (BaseDecimater::*add5)(ModNormalDeviationHandle&) = &Decimater::add;
	bool (BaseDecimater::*add6)(ModNormalFlippingHandle&) = &Decimater::add;
	bool (BaseDecimater::*add7)(ModProgMeshHandle&) = &Decimater::add;
	bool (BaseDecimater::*add8)(ModQuadricHandle&) = &Decimater::add;
	bool (BaseDecimater::*add9)(ModRoundnessHandle&) = &Decimater::add;

	bool (BaseDecimater::*remove1)(ModAspectRatioHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove2)(ModEdgeLengthHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove3)(ModHausdorffHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove4)(ModIndependentSetsHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove5)(ModNormalDeviationHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove6)(ModNormalFlippingHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove7)(ModProgMeshHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove8)(ModQuadricHandle&) = &Decimater::remove;
	bool (BaseDecimater::*remove9)(ModRoundnessHandle&) = &Decimater::remove;

	ModAspectRatio& (BaseDecimater::*module1)(ModAspectRatioHandle&) = &Decimater::module;
	ModEdgeLength& (BaseDecimater::*module2)(ModEdgeLengthHandle&) = &Decimater::module;
	ModHausdorff& (BaseDecimater::*module3)(ModHausdorffHandle&) = &Decimater::module;
	ModIndependentSets& (BaseDecimater::*module4)(ModIndependentSetsHandle&) = &Decimater::module;
	ModNormalDeviation& (BaseDecimater::*module5)(ModNormalDeviationHandle&) = &Decimater::module;
	ModNormalFlipping& (BaseDecimater::*module6)(ModNormalFlippingHandle&) = &Decimater::module;
	ModProgMesh& (BaseDecimater::*module7)(ModProgMeshHandle&) = &Decimater::module;
	ModQuadric& (BaseDecimater::*module8)(ModQuadricHandle&) = &Decimater::module;
	ModRoundness& (BaseDecimater::*module9)(ModRoundnessHandle&) = &Decimater::module;

	// Decimater
	// ----------------------------------------

	char buffer[64];
	snprintf(buffer, sizeof buffer, "%s%s", _name, "Decimater");

Alexander Dielen's avatar
Alexander Dielen committed
113
	class_<Decimater, boost::noncopyable>(buffer, INIT_MESH_REF)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
		.def("decimate", &Decimater::decimate, decimate_overloads())
		.def("decimate_to", &Decimater::decimate_to)
		.def("decimate_to_faces", &Decimater::decimate_to_faces, decimate_to_faces_overloads())

		.def("initialize", &Decimater::initialize)
		.def("is_initialized", &Decimater::is_initialized)

		.def("add", add1)
		.def("add", add2)
		.def("add", add3)
		.def("add", add4)
		.def("add", add5)
		.def("add", add6)
		.def("add", add7)
		.def("add", add8)
		.def("add", add9)

		.def("remove", remove1)
		.def("remove", remove2)
		.def("remove", remove3)
		.def("remove", remove4)
		.def("remove", remove5)
		.def("remove", remove6)
		.def("remove", remove7)
		.def("remove", remove8)
		.def("remove", remove9)

		.def("module", module1, return_value_policy<reference_existing_object>())
		.def("module", module2, return_value_policy<reference_existing_object>())
		.def("module", module3, return_value_policy<reference_existing_object>())
		.def("module", module4, return_value_policy<reference_existing_object>())
		.def("module", module5, return_value_policy<reference_existing_object>())
		.def("module", module6, return_value_policy<reference_existing_object>())
		.def("module", module7, return_value_policy<reference_existing_object>())
		.def("module", module8, return_value_policy<reference_existing_object>())
		.def("module", module9, return_value_policy<reference_existing_object>())
		;

	// ModBase
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModBase");

	class_<ModBase, boost::noncopyable>(buffer, no_init)
		.def("name", &ModBase::name, OPENMESH_PYTHON_DEFAULT_POLICY)
		.def("is_binary", &ModBase::is_binary)
		.def("set_binary", &ModBase::set_binary)
		.def("initialize", &ModBase::initialize) // TODO VIRTUAL
		.def("collapse_priority", &ModBase::collapse_priority) // TODO VIRTUAL
		.def("preprocess_collapse", &ModBase::preprocess_collapse) // TODO VIRTUAL
		.def("postprocess_collapse", &ModBase::postprocess_collapse) // TODO VIRTUAL
		.def("set_error_tolerance_factor", &ModBase::set_error_tolerance_factor) // TODO VIRTUAL
		;

	// ModAspectRatio
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModAspectRatio");

Alexander Dielen's avatar
Alexander Dielen committed
173
	class_<ModAspectRatio, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
174 175 176 177 178 179 180 181 182 183 184 185
		.def("aspect_ratio", &ModAspectRatio::aspect_ratio)
		.def("set_aspect_ratio", &ModAspectRatio::set_aspect_ratio)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModAspectRatioHandle");
	expose_module_handle<ModAspectRatioHandle>(buffer);

	// ModEdgeLength
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModEdgeLength");

Alexander Dielen's avatar
Alexander Dielen committed
186
	class_<ModEdgeLength, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
187 188 189 190 191 192 193 194 195 196 197 198
		.def("edge_length", &ModEdgeLength::edge_length)
		.def("set_edge_length", &ModEdgeLength::set_edge_length)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModEdgeLengthHandle");
	expose_module_handle<ModEdgeLengthHandle>(buffer);

	// ModHausdorff
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModHausdorff");

Alexander Dielen's avatar
Alexander Dielen committed
199
	class_<ModHausdorff, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
200 201 202 203 204 205 206 207 208 209 210 211
		.def("tolerance", &ModHausdorff::tolerance)
		.def("set_tolerance", &ModHausdorff::set_tolerance)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModHausdorffHandle");
	expose_module_handle<ModHausdorffHandle>(buffer);

	// ModIndependentSets
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModIndependentSets");

Alexander Dielen's avatar
Alexander Dielen committed
212
	class_<ModIndependentSets, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF);
213 214 215 216 217 218 219 220 221

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModIndependentSetsHandle");
	expose_module_handle<ModIndependentSetsHandle>(buffer);

	// ModNormalDeviation
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalDeviation");

Alexander Dielen's avatar
Alexander Dielen committed
222
	class_<ModNormalDeviation, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
223 224 225 226 227 228 229 230 231 232 233 234
		.def("normal_deviation", &ModNormalDeviation::normal_deviation)
		.def("set_normal_deviation", &ModNormalDeviation::set_normal_deviation)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalDeviationHandle");
	expose_module_handle<ModNormalDeviationHandle>(buffer);

	// ModNormalFlipping
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalFlipping");

Alexander Dielen's avatar
Alexander Dielen committed
235
	class_<ModNormalFlipping, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
236 237 238 239 240 241 242 243 244 245
		.def("max_normal_deviation", &ModNormalFlipping::max_normal_deviation)
		.def("set_max_normal_deviation", &ModNormalFlipping::set_max_normal_deviation)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalFlippingHandle");
	expose_module_handle<ModNormalFlippingHandle>(buffer);

	// ModProgMesh
	// ----------------------------------------

246 247 248 249 250 251 252 253 254
	class_<Info>("Info", no_init)
		.def_readwrite("v0", &Info::v0)
		.def_readwrite("v1", &Info::v1)
		.def_readwrite("vl", &Info::vl)
		.def_readwrite("vr", &Info::vr)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModProgMesh");

Alexander Dielen's avatar
Alexander Dielen committed
255
	class_<ModProgMesh, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
256 257 258 259 260 261 262
		.def("pmi", &infolist<ModProgMesh>)
		.def("infolist", &infolist<ModProgMesh>)
		.def("write", &ModProgMesh::write)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModProgMeshHandle");
	expose_module_handle<ModProgMeshHandle>(buffer);
263 264 265 266 267 268

	// ModQuadric
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModQuadric");

Alexander Dielen's avatar
Alexander Dielen committed
269
	class_<ModQuadric, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
270 271 272 273 274 275 276 277 278 279 280 281 282
		.def("set_max_err", &ModQuadric::set_max_err, set_max_err_overloads())
		.def("unset_max_err", &ModQuadric::unset_max_err)
		.def("max_err", &ModQuadric::max_err)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModQuadricHandle");
	expose_module_handle<ModQuadricHandle>(buffer);

	// ModRoundness
	// ----------------------------------------

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModRoundness");

Alexander Dielen's avatar
Alexander Dielen committed
283
	class_<ModRoundness, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
284 285 286 287 288 289 290 291 292 293 294 295 296 297
		.def("set_min_angle", &ModRoundness::set_min_angle)
		.def("set_min_roundness", &ModRoundness::set_min_roundness, set_min_roundness_overloads())
		.def("unset_min_roundness", &ModRoundness::unset_min_roundness)
		.def("roundness", &ModRoundness::roundness)
		;

	snprintf(buffer, sizeof buffer, "%s%s", _name, "ModRoundnessHandle");
	expose_module_handle<ModRoundnessHandle>(buffer);
}

} // namespace OpenMesh
} // namespace Python

#endif