tahoma2d/toonz/sources/tnzext/plasticdeformerstorage.cpp

656 lines
22 KiB
C++
Raw Normal View History

2016-04-14 19:51:50 +12:00
#include <memory>
2016-03-19 06:57:51 +13:00
// TnzExt includes
#include "ext/plasticskeleton.h"
#include "ext/plasticskeletondeformation.h"
// STD includes
#include <limits>
#include <map>
#include <algorithm>
// Boost includes
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
// Qt includes
#include <QMutex>
#include <QMutexLocker>
#include "ext/plasticdeformerstorage.h"
//***********************************************************************************************
// Storage multi-index map definition
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
typedef PlasticDeformerDataGroup DataGroup;
//----------------------------------------------------------------------------------
typedef std::pair<const SkD *, int> DeformedSkeleton;
//----------------------------------------------------------------------------------
struct Key {
2016-06-15 18:43:10 +12:00
const TMeshImage *m_mi;
DeformedSkeleton m_ds;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::shared_ptr<DataGroup> m_dataGroup;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Key(const TMeshImage *mi, const SkD *sd, int skelId)
: m_mi(mi), m_ds(sd, skelId), m_dataGroup() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool operator<(const Key &other) const {
return (m_mi < other.m_mi) ||
((!(other.m_mi < m_mi)) && (m_ds < other.m_ds));
}
2016-03-19 06:57:51 +13:00
};
//----------------------------------------------------------------------------------
using namespace boost::multi_index;
2016-06-15 18:43:10 +12:00
typedef boost::multi_index_container<
Key, indexed_by<
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ordered_unique<identity<Key>>,
ordered_non_unique<tag<TMeshImage>,
member<Key, const TMeshImage *, &Key::m_mi>>,
ordered_non_unique<tag<DeformedSkeleton>,
member<Key, DeformedSkeleton, &Key::m_ds>>
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
>>
DeformersSet;
2016-03-19 06:57:51 +13:00
typedef DeformersSet::nth_index<0>::type DeformersByKey;
typedef DeformersSet::index<TMeshImage>::type DeformersByMeshImage;
typedef DeformersSet::index<DeformedSkeleton>::type DeformersByDeformedSkeleton;
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//***********************************************************************************************
// Initialization stage functions
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void initializeSO(PlasticDeformerData &data, const TTextureMeshP &mesh) {
data.m_so.reset(new double[mesh->facesCount()]);
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void initializeDeformerData(PlasticDeformerData &data,
const TTextureMeshP &mesh) {
initializeSO(data, mesh); // Allocates SO data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Also, allocate suitable input-output arrays for the deformation
data.m_output.reset(new double[2 * mesh->verticesCount()]);
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void initializeDeformersData(DataGroup *group, const TMeshImage *meshImage) {
group->m_datas.reset(new PlasticDeformerData[meshImage->meshes().size()]);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Push a PlasticDeformer for each mesh in the image
const std::vector<TTextureMeshP> &meshes = meshImage->meshes();
int fTotal = 0; // Also count total # of faces
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m, mCount = meshes.size();
for (m = 0; m != mCount; ++m) {
fTotal += meshes[m]->facesCount();
initializeDeformerData(group->m_datas[m], meshes[m]);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Initialize the vector of sorted faces
std::vector<std::pair<int, int>> &sortedFaces = group->m_sortedFaces;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
sortedFaces.reserve(fTotal);
for (m = 0; m != mCount; ++m) {
const TTextureMesh &mesh = *meshes[m];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int f, fCount = mesh.facesCount();
for (f = 0; f != fCount; ++f) sortedFaces.push_back(std::make_pair(f, m));
}
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//***********************************************************************************************
// Handle processing functions
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void transformHandles(std::vector<PlasticHandle> &handles, const TAffine &aff) {
// Transforms handles through deformAff AND applies mi's dpi scale inverse
std::vector<PlasticHandle>::size_type h, hCount = handles.size();
for (h = 0; h != hCount; ++h) handles[h].m_pos = aff * handles[h].m_pos;
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void transformHandles(std::vector<TPointD> &handles, const TAffine &aff) {
// Transforms handles through deformAff AND applies mi's dpi scale inverse
std::vector<PlasticHandle>::size_type h, hCount = handles.size();
for (h = 0; h != hCount; ++h) handles[h] = aff * handles[h];
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
void processHandles(DataGroup *group, double frame, const TMeshImage *meshImage,
2016-06-15 18:43:10 +12:00
const SkD *sd, int skelId,
const TAffine &deformationAffine) {
assert(sd);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const PlasticSkeletonP &skeleton = sd->skeleton(skelId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!skeleton || skeleton->verticesCount() == 0) {
group->m_handles.clear();
group->m_dstHandles.clear();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
group->m_compiled |= PlasticDeformerStorage::HANDLES;
group->m_upToDate |= PlasticDeformerStorage::HANDLES;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int mCount = meshImage->meshes().size();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!(group->m_upToDate & PlasticDeformerStorage::HANDLES)) {
// Compile handles if necessary
if (!(group->m_compiled & PlasticDeformerStorage::HANDLES)) {
// Build and transform handles
group->m_handles = skeleton->verticesToHandles();
::transformHandles(group->m_handles, deformationAffine);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Prepare a vector for handles' face hints
for (int m = 0; m != mCount; ++m)
group->m_datas[m].m_faceHints.resize(group->m_handles.size(), -1);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
group->m_compiled |= PlasticDeformerStorage::HANDLES;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Then, build destination handles
PlasticSkeleton
deformedSkeleton; // NOTE: Could this be moved to the group as well?
sd->storeDeformedSkeleton(skelId, frame, deformedSkeleton);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Copy deformed skeleton data into input deformation parameters
group->m_dstHandles = std::vector<TPointD>(
deformedSkeleton.vertices().begin(), deformedSkeleton.vertices().end());
::transformHandles(group->m_dstHandles, deformationAffine);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
group->m_upToDate |= PlasticDeformerStorage::HANDLES;
}
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//***********************************************************************************************
// Stacking Order processing functions
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool updateHandlesSO(DataGroup *group, const SkD *sd, int skelId,
double frame) {
assert(sd);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const PlasticSkeletonP &skeleton = sd->skeleton(skelId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!skeleton || skeleton->verticesCount() == 0) {
group->m_soMin = group->m_soMax = 0.0;
return false;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Copy SO values to data's handles
// Return whether values changed with respect to previous ones
bool changed = false;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(group->m_handles.size() == skeleton->verticesCount());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int h, hCount = group->m_handles.size();
{
tcg::list<PlasticSkeletonVertex>::iterator vt =
skeleton->vertices().begin();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
for (h = 0; h != hCount; ++h, ++vt) {
const SkVD *vd = sd->vertexDeformation(vt->name());
if (!vd) continue;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double so = vd->m_params[SkVD::SO]->getValue(frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PlasticHandle &handle = group->m_handles[h];
if (handle.m_so != so) {
group->m_handles[h].m_so = so;
changed = true;
}
}
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (changed) {
// Rebuild SO minmax
group->m_soMax = -(group->m_soMin = (std::numeric_limits<double>::max)());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
for (h = 0; h != hCount; ++h) {
const double &so = group->m_handles[h].m_so;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
group->m_soMin = std::min(group->m_soMin, so);
group->m_soMax = std::max(group->m_soMax, so);
}
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return changed;
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void interpolateSO(DataGroup *group, const TMeshImage *meshImage) {
int m, mCount = meshImage->meshes().size();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (group->m_handles.size() == 0) {
// No handles case, fill in with 0s
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
for (m = 0; m != mCount; ++m) {
const TTextureMesh &mesh = *meshImage->meshes()[m];
PlasticDeformerData &data = group->m_datas[m];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::fill(data.m_so.get(), data.m_so.get() + mesh.facesCount(), 0.0);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Apply handles' SO values to each mesh
for (m = 0; m != mCount; ++m) {
const TTextureMesh &mesh = *meshImage->meshes()[m];
PlasticDeformerData &data = group->m_datas[m];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Interpolate so values
std::unique_ptr<double[]> verticesSO(new double[mesh.verticesCount()]);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
::buildSO(verticesSO.get(), mesh, group->m_handles,
&data.m_faceHints.front());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Make the mean of each face's vertex values and store that
int f, fCount = mesh.facesCount();
for (f = 0; f != fCount; ++f) {
int v0, v1, v2;
mesh.faceVertices(f, v0, v1, v2);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
data.m_so[f] = (verticesSO[v0] + verticesSO[v1] + verticesSO[v2]) / 3.0;
}
}
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
struct FaceLess {
2016-06-15 18:43:10 +12:00
const PlasticDeformerDataGroup *m_group;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
FaceLess(const PlasticDeformerDataGroup *group) : m_group(group) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
return (m_group->m_datas[a.second].m_so[a.first] <
m_group->m_datas[b.second].m_so[b.first]);
}
2016-03-19 06:57:51 +13:00
};
// Must be invoked after updateSO
2016-06-15 18:43:10 +12:00
void updateSortedFaces(PlasticDeformerDataGroup *group) {
FaceLess comp(group);
std::sort(group->m_sortedFaces.begin(), group->m_sortedFaces.end(), comp);
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
void processSO(DataGroup *group, double frame, const TMeshImage *meshImage,
2016-06-15 18:43:10 +12:00
const SkD *sd, int skelId, const TAffine &deformationAffine) {
// SO re-interpolate values along the mesh if either:
// 1. Recompilation was requested (ie some vertex may have been
// added/removed)
// 2. OR the value of one of the handle has changed
bool interpolate = !(group->m_compiled & PlasticDeformerStorage::SO);
if (!(group->m_upToDate &
PlasticDeformerStorage::SO)) // implied by (interpolate == true)
{
interpolate = updateHandlesSO(group, sd, skelId, frame) ||
interpolate; // Order is IMPORTANT
if (interpolate) {
interpolateSO(group, meshImage);
updateSortedFaces(group);
}
group->m_compiled |= PlasticDeformerStorage::SO;
group->m_upToDate |= PlasticDeformerStorage::SO;
}
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//***********************************************************************************************
// Mesh Deform processing functions
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
void processMesh(DataGroup *group, double frame, const TMeshImage *meshImage,
2016-06-15 18:43:10 +12:00
const SkD *sd, int skelId, const TAffine &deformationAffine) {
if (!(group->m_upToDate & PlasticDeformerStorage::MESH)) {
int m, mCount = meshImage->meshes().size();
if (!(group->m_compiled & PlasticDeformerStorage::MESH)) {
for (m = 0; m != mCount; ++m) {
const TTextureMeshP &mesh = meshImage->meshes()[m];
PlasticDeformerData &data = group->m_datas[m];
data.m_deformer.initialize(mesh);
data.m_deformer.compile(
group->m_handles,
data.m_faceHints.empty() ? 0 : &data.m_faceHints.front());
data.m_deformer.releaseInitializedData();
}
group->m_compiled |= PlasticDeformerStorage::MESH;
}
const TPointD *dstHandlePos =
group->m_dstHandles.empty() ? 0 : &group->m_dstHandles.front();
for (m = 0; m != mCount; ++m) {
PlasticDeformerData &data = group->m_datas[m];
data.m_deformer.deform(dstHandlePos, data.m_output.get());
}
group->m_upToDate |= PlasticDeformerStorage::MESH;
}
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//***********************************************************************************************
// PlasticDeformerData implementation
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
PlasticDeformerData::PlasticDeformerData() {}
2016-03-19 06:57:51 +13:00
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
PlasticDeformerData::~PlasticDeformerData() {}
2016-03-19 06:57:51 +13:00
//***********************************************************************************************
// PlasticDeformerDataGroup implementation
//***********************************************************************************************
PlasticDeformerDataGroup::PlasticDeformerDataGroup()
2016-06-15 18:43:10 +12:00
: m_datas()
, m_compiled(PlasticDeformerStorage::NONE)
, m_upToDate(PlasticDeformerStorage::NONE)
, m_outputFrame((std::numeric_limits<double>::max)())
, m_soMin()
, m_soMax() {}
2016-03-19 06:57:51 +13:00
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
PlasticDeformerDataGroup::~PlasticDeformerDataGroup() {}
2016-03-19 06:57:51 +13:00
//***********************************************************************************************
// PlasticDeformerStorage::Imp definition
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
class PlasticDeformerStorage::Imp {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
QMutex m_mutex; //!< Access mutex - needed for thread-safety
DeformersSet m_deformers; //!< Set of deformers, ordered by mesh image,
//!deformation, and affine.
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Imp() : m_mutex(QMutex::Recursive) {}
2016-03-19 06:57:51 +13:00
};
//***********************************************************************************************
// PlasticDeformerStorage implementation
//***********************************************************************************************
2016-06-15 18:43:10 +12:00
PlasticDeformerStorage::PlasticDeformerStorage() : m_imp(new Imp) {}
2016-03-19 06:57:51 +13:00
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
PlasticDeformerStorage::~PlasticDeformerStorage() {}
2016-03-19 06:57:51 +13:00
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
PlasticDeformerStorage *PlasticDeformerStorage::instance() {
static PlasticDeformerStorage theInstance;
return &theInstance;
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
PlasticDeformerDataGroup *PlasticDeformerStorage::deformerData(
2016-06-15 18:43:10 +12:00
const TMeshImage *meshImage, const PlasticSkeletonDeformation *deformation,
int skelId) {
QMutexLocker locker(&m_imp->m_mutex);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Search for the corresponding deformation in the storage
Key key(meshImage, deformation, skelId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByKey::iterator dt = m_imp->m_deformers.find(key);
if (dt == m_imp->m_deformers.end()) {
// No deformer was found. Allocate it.
key.m_dataGroup = std::make_shared<PlasticDeformerDataGroup>();
initializeDeformersData(key.m_dataGroup.get(), meshImage);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
dt = m_imp->m_deformers.insert(key).first;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return dt->m_dataGroup.get();
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
const PlasticDeformerDataGroup *PlasticDeformerStorage::process(
2016-06-15 18:43:10 +12:00
double frame, const TMeshImage *meshImage,
const PlasticSkeletonDeformation *deformation, int skelId,
const TAffine &skeletonAffine, DataType dataType) {
QMutexLocker locker(&m_imp->m_mutex);
PlasticDeformerDataGroup *group =
deformerData(meshImage, deformation, skelId);
// On-the-fly checks for data invalidation
if (group->m_skeletonAffine != skeletonAffine) {
group->m_upToDate = NONE;
group->m_compiled = NONE;
group->m_skeletonAffine = skeletonAffine;
}
if (group->m_outputFrame != frame) {
group->m_upToDate = NONE;
group->m_outputFrame = frame;
}
bool doMesh = (dataType & MESH);
bool doSO = (dataType & SO) || doMesh;
bool doHandles = (bool)dataType;
// Process data
if (doHandles)
processHandles(group, frame, meshImage, deformation, skelId,
skeletonAffine);
if (doSO)
processSO(group, frame, meshImage, deformation, skelId, skeletonAffine);
if (doMesh)
processMesh(group, frame, meshImage, deformation, skelId, skeletonAffine);
return group;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//----------------------------------------------------------------------------------
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const PlasticDeformerDataGroup *PlasticDeformerStorage::processOnce(
double frame, const TMeshImage *meshImage,
const PlasticSkeletonDeformation *deformation, int skelId,
const TAffine &skeletonAffine, DataType dataType) {
PlasticDeformerDataGroup *group = new PlasticDeformerDataGroup;
initializeDeformersData(group, meshImage);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool doMesh = (dataType & MESH);
bool doSO = (dataType & SO) || doMesh;
bool doHandles = (bool)dataType;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Process data
if (doHandles)
processHandles(group, frame, meshImage, deformation, skelId,
skeletonAffine);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (doSO)
processSO(group, frame, meshImage, deformation, skelId, skeletonAffine);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (doMesh)
processMesh(group, frame, meshImage, deformation, skelId, skeletonAffine);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return group;
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerStorage::invalidateMeshImage(const TMeshImage *meshImage,
int recompiledData) {
QMutexLocker locker(&m_imp->m_mutex);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByMeshImage &deformers = m_imp->m_deformers.get<TMeshImage>();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByMeshImage::iterator dBegin(deformers.lower_bound(meshImage));
if (dBegin == deformers.end()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByMeshImage::iterator dt, dEnd(deformers.upper_bound(meshImage));
for (dt = dBegin; dt != dEnd; ++dt) {
dt->m_dataGroup->m_outputFrame =
(std::numeric_limits<double>::max)(); // Schedule for redeformation
if (recompiledData)
dt->m_dataGroup->m_compiled &=
~recompiledData; // Schedule for recompilation, too
}
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
void PlasticDeformerStorage::invalidateSkeleton(
2016-06-15 18:43:10 +12:00
const PlasticSkeletonDeformation *deformation, int skelId,
int recompiledData) {
QMutexLocker locker(&m_imp->m_mutex);
DeformedSkeleton ds(deformation, skelId);
DeformersByDeformedSkeleton &deformers =
m_imp->m_deformers.get<DeformedSkeleton>();
DeformersByDeformedSkeleton::iterator dBegin(deformers.lower_bound(ds));
if (dBegin == deformers.end()) return;
DeformersByDeformedSkeleton::iterator dt, dEnd(deformers.upper_bound(ds));
for (dt = dBegin; dt != dEnd; ++dt) {
dt->m_dataGroup->m_outputFrame =
(std::numeric_limits<double>::max)(); // Schedule for redeformation
if (recompiledData)
dt->m_dataGroup->m_compiled &=
~recompiledData; // Schedule for recompilation, too
}
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
void PlasticDeformerStorage::invalidateDeformation(
2016-06-15 18:43:10 +12:00
const PlasticSkeletonDeformation *deformation, int recompiledData) {
QMutexLocker locker(&m_imp->m_mutex);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByDeformedSkeleton &deformers =
m_imp->m_deformers.get<DeformedSkeleton>();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformedSkeleton dsBegin(deformation, -(std::numeric_limits<int>::max)()),
dsEnd(deformation, (std::numeric_limits<int>::max)());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByDeformedSkeleton::iterator dBegin(deformers.lower_bound(dsBegin));
DeformersByDeformedSkeleton::iterator dEnd(deformers.upper_bound(dsEnd));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (dBegin == dEnd) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
for (DeformersByDeformedSkeleton::iterator dt = dBegin; dt != dEnd; ++dt) {
dt->m_dataGroup->m_outputFrame =
(std::numeric_limits<double>::max)(); // Schedule for redeformation
if (recompiledData)
dt->m_dataGroup->m_compiled &=
~recompiledData; // Schedule for recompilation, too
}
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerStorage::releaseMeshData(const TMeshImage *meshImage) {
QMutexLocker locker(&m_imp->m_mutex);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByMeshImage &deformers = m_imp->m_deformers.get<TMeshImage>();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByMeshImage::iterator dBegin(deformers.lower_bound(meshImage));
if (dBegin == deformers.end()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
deformers.erase(dBegin, deformers.upper_bound(meshImage));
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerStorage::releaseSkeletonData(const SkD *deformation,
int skelId) {
QMutexLocker locker(&m_imp->m_mutex);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformedSkeleton ds(deformation, skelId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByDeformedSkeleton &deformers =
m_imp->m_deformers.get<DeformedSkeleton>();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByDeformedSkeleton::iterator dBegin(deformers.lower_bound(ds));
if (dBegin == deformers.end()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
deformers.erase(dBegin, deformers.upper_bound(ds));
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerStorage::releaseDeformationData(const SkD *deformation) {
QMutexLocker locker(&m_imp->m_mutex);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByDeformedSkeleton &deformers =
m_imp->m_deformers.get<DeformedSkeleton>();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformedSkeleton dsBegin(deformation, -(std::numeric_limits<int>::max)()),
dsEnd(deformation, (std::numeric_limits<int>::max)());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DeformersByDeformedSkeleton::iterator dBegin(deformers.lower_bound(dsBegin));
DeformersByDeformedSkeleton::iterator dEnd(deformers.upper_bound(dsEnd));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (dBegin == dEnd) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
deformers.erase(dBegin, dEnd);
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void PlasticDeformerStorage::clear() {
QMutexLocker locker(&m_imp->m_mutex);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_imp->m_deformers.clear();
2016-03-19 06:57:51 +13:00
}