Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef PLASTICDEFORMER_H
Toshihiro Shimizu 890ddd
#define PLASTICDEFORMER_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
#include "tmeshimage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzExt includes
Toshihiro Shimizu 890ddd
#include "ext/plastichandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STL includes
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// tcg includes
Toshihiro Shimizu 890ddd
#include "tcg/tcg_list.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TNZEXT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    Plastic Deformation  declaration
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The PlasticDeformer class implements an interactive mesh deformer.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
\warning Objects of this class expect that the mesh and rigidities supplied on construction
Toshihiro Shimizu 890ddd
  remain \b constant throughout the deformer's lifetime. Deforming a changed mesh is not supported
Toshihiro Shimizu 890ddd
  and will typically result in a crash. Deforming a mesh whose vertex rigidities have been
Toshihiro Shimizu 890ddd
  \a deleted will result in a crash. Altering the rigidities results in undefined deformations
Toshihiro Shimizu 890ddd
  until the deformer is recompiled against them.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class DVAPI PlasticDeformer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	class Imp;
Toshihiro Shimizu 890ddd
	Imp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	PlasticDeformer();
Toshihiro Shimizu 890ddd
	~PlasticDeformer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend void swap(PlasticDeformer &a, PlasticDeformer &b) { std::swap(a.m_imp, b.m_imp); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    Returns whether the last compilation procedure succeeded, or it either failed
Toshihiro Shimizu 890ddd
    or was never invoked after the last initialize() call.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	bool compiled() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    Initializes a deformation on the specified mesh object.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void initialize(const TTextureMeshP &mesh);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  \brief Compiles the deformer against a group of deformation handles, and returns
Toshihiro Shimizu 890ddd
    whether the procedure was successful.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \note Accepts hints about the mesh face containing each handle; the hinted face
Toshihiro Shimizu 890ddd
    is checked before scanning the whole mesh. In case hints are supplied, they will be
Toshihiro Shimizu 890ddd
    returned with the correct face indices containing each handle.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \warning Requires a previous initialize() call. The compilation may legitimately
Toshihiro Shimizu 890ddd
    fail to process handle configurations that \a cannot result in suitable
Toshihiro Shimizu 890ddd
    deformations (eg, if more than 3 handles lie in the same mesh face).
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	bool compile(const std::vector<plastichandle> &handles, int *faceHints = 0);</plastichandle>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    Applies the deformation specified with input handles deformed positions, returning
Toshihiro Shimizu 890ddd
    the deformed mesh vertices positions.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \note In case the compilation step failed or was never invoked, this function
Toshihiro Shimizu 890ddd
    will silently return the original, undeformed mesh vertices.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \warning Requires previous compile() invocation.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void deform(const TPointD *dstHandlePos, double *dstVerticesCoords) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    Releases data from the initialize() step that is unnecessary during deform().
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \warning Initialization data is still necessary to invoke compile(), which will
Toshihiro Shimizu 890ddd
    therefore need to be preceded by a new call to initialize().
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void releaseInitializedData();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// Not copyable
Toshihiro Shimizu 890ddd
	PlasticDeformer(const PlasticDeformer &);
Toshihiro Shimizu 890ddd
	PlasticDeformer &operator=(const PlasticDeformer &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // PLASTICDEFORMER_H