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