|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/hook.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstream.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfilepath.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheet.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshcell.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Hook::Hook()
|
|
Toshihiro Shimizu |
890ddd |
: m_id(0), m_trackerObjectId(-1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool Hook::isEmpty() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_frames.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool Hook::isKeyframe(const TFrameId &fid) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_frames.count(fid) > 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Hook::Frames::const_iterator Hook::find(TFrameId fid) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_frames.empty())
|
|
Toshihiro Shimizu |
890ddd |
return m_frames.end();
|
|
Toshihiro Shimizu |
890ddd |
Frames::const_iterator it;
|
|
Toshihiro Shimizu |
890ddd |
it = m_frames.lower_bound(fid);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_frames.end()) {
|
|
Toshihiro Shimizu |
890ddd |
// dopo l'ultimo
|
|
Toshihiro Shimizu |
890ddd |
assert(it != m_frames.begin());
|
|
Toshihiro Shimizu |
890ddd |
--it;
|
|
Toshihiro Shimizu |
890ddd |
} else if (it->first == fid || it == m_frames.begin()) {
|
|
Toshihiro Shimizu |
890ddd |
// giusto o prima del primo
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
--it;
|
|
Toshihiro Shimizu |
890ddd |
return it;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD Hook::getPos(const TFrameId &fid) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//return TPointD(0,0);
|
|
Toshihiro Shimizu |
890ddd |
Frames::const_iterator it = find(fid);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_frames.end())
|
|
Toshihiro Shimizu |
890ddd |
return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second.m_pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD Hook::getAPos(const TFrameId &fid) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Frames::const_iterator it = find(fid);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_frames.end())
|
|
Toshihiro Shimizu |
890ddd |
return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
else if (it->first == fid)
|
|
Toshihiro Shimizu |
890ddd |
return it->second.m_aPos;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second.m_bPos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD Hook::getBPos(const TFrameId &fid) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Frames::const_iterator it = find(fid);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_frames.end())
|
|
Toshihiro Shimizu |
890ddd |
return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second.m_bPos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Hook::setAPos(const TFrameId &fid, TPointD pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Frames::iterator it = m_frames.lower_bound(fid);
|
|
Toshihiro Shimizu |
890ddd |
Frame f;
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_frames.end() && it->first == fid) {
|
|
Toshihiro Shimizu |
890ddd |
f = it->second;
|
|
Toshihiro Shimizu |
890ddd |
if (f.m_aPos == f.m_bPos)
|
|
Toshihiro Shimizu |
890ddd |
f.m_aPos = f.m_bPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
else if (tdistance2(pos, f.m_bPos) <= 1)
|
|
Toshihiro Shimizu |
890ddd |
f.m_aPos = f.m_bPos;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
f.m_aPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
f.m_aPos = f.m_bPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_frames[fid] = f;
|
|
Toshihiro Shimizu |
890ddd |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Hook::setBPos(const TFrameId &fid, TPointD pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Frames::iterator it = m_frames.lower_bound(fid);
|
|
Toshihiro Shimizu |
890ddd |
Frame f;
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_frames.end() && it->first == fid) {
|
|
Toshihiro Shimizu |
890ddd |
f = it->second;
|
|
Toshihiro Shimizu |
890ddd |
if (tdistance2(pos, f.m_aPos) <= 1)
|
|
Toshihiro Shimizu |
890ddd |
f.m_bPos = f.m_aPos;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
f.m_bPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
f.m_aPos = getAPos(fid);
|
|
Toshihiro Shimizu |
890ddd |
f.m_bPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_frames[fid] = f;
|
|
Toshihiro Shimizu |
890ddd |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
TRectD Hook::getTrackerRegion(const TFrameId &fid)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRectD rect;
|
|
Toshihiro Shimizu |
890ddd |
rect.x0 = getPos(fid).x - (getTrackerRegionWidth() * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
rect.y0 = getPos(fid).y - (getTrackerRegionHeight() * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
rect.x1 = getPos(fid).x + (getTrackerRegionWidth() * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
rect.y1 = getPos(fid).y + (getTrackerRegionHeight() * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Hook::update()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD delta;
|
|
Toshihiro Shimizu |
890ddd |
for (Frames::iterator it = m_frames.begin();
|
|
Toshihiro Shimizu |
890ddd |
it != m_frames.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
it->second.m_pos = it->second.m_aPos + delta;
|
|
Toshihiro Shimizu |
890ddd |
delta -= it->second.m_bPos - it->second.m_aPos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_delta = delta;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Hook::renumber(const std::map<tframeid, tframeid=""> &renumberTable)</tframeid,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Frames oldFrames = m_frames;
|
|
Toshihiro Shimizu |
890ddd |
m_frames.clear();
|
|
Toshihiro Shimizu |
890ddd |
for (Frames::iterator it = oldFrames.begin(); it != oldFrames.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
std::map<tframeid, tframeid="">::const_iterator j = renumberTable.find(it->first);</tframeid,>
|
|
Toshihiro Shimizu |
890ddd |
assert(j != renumberTable.end());
|
|
Toshihiro Shimizu |
890ddd |
if (j == renumberTable.end())
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
m_frames[j->second] = it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Hook::eraseFrame(const TFrameId &fid)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_frames.erase(fid);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Hook::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Frames::iterator j;
|
|
Toshihiro Shimizu |
890ddd |
for (j = m_frames.begin(); j != m_frames.end(); ++j) {
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("frame");
|
|
Toshihiro Shimizu |
890ddd |
os << j->first.getNumber();
|
|
Toshihiro Shimizu |
890ddd |
os << j->second.m_aPos.x << j->second.m_aPos.y;
|
|
Toshihiro Shimizu |
890ddd |
os << j->second.m_bPos.x << j->second.m_bPos.y;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (m_trackerObjectId >= 0) {
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("tracker");
|
|
Toshihiro Shimizu |
890ddd |
os << m_trackerObjectId << m_width << m_height;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Hook::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_frames.clear();
|
|
Shinya Kitaoka |
3bfa54 |
std::string tagName;
|
|
Toshihiro Shimizu |
890ddd |
while (is.matchTag(tagName)) {
|
|
Toshihiro Shimizu |
890ddd |
if (tagName == "frame") {
|
|
Toshihiro Shimizu |
890ddd |
Frame f;
|
|
Toshihiro Shimizu |
890ddd |
int frameNumber = 0;
|
|
Toshihiro Shimizu |
890ddd |
is >> frameNumber;
|
|
Toshihiro Shimizu |
890ddd |
is >> f.m_aPos.x >> f.m_aPos.y;
|
|
Toshihiro Shimizu |
890ddd |
is >> f.m_bPos.x >> f.m_bPos.y;
|
|
Toshihiro Shimizu |
890ddd |
m_frames[TFrameId(frameNumber)] = f;
|
|
Toshihiro Shimizu |
890ddd |
m_trackerObjectId = -1;
|
|
Toshihiro Shimizu |
890ddd |
} else if (tagName == "tracker") {
|
|
Toshihiro Shimizu |
890ddd |
is >> m_trackerObjectId;
|
|
Toshihiro Shimizu |
890ddd |
is >> m_width;
|
|
Toshihiro Shimizu |
890ddd |
is >> m_height;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
throw TException("expected ");
|
|
Toshihiro Shimizu |
890ddd |
is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
HookSet::HookSet()
|
|
Toshihiro Shimizu |
890ddd |
: m_trackerObjectsSet(new TrackerObjectsSet)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
HookSet::~HookSet()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
clearPointerContainer(m_hooks);
|
|
Toshihiro Shimizu |
890ddd |
delete m_trackerObjectsSet;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
HookSet::HookSet(const HookSet &other)
|
|
Toshihiro Shimizu |
890ddd |
: m_hooks(other.m_hooks), m_trackerObjectsSet(new TrackerObjectsSet)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int h, hCount = m_hooks.size();
|
|
Toshihiro Shimizu |
890ddd |
for (h = 0; h != hCount; ++h)
|
|
Toshihiro Shimizu |
890ddd |
if (m_hooks[h])
|
|
Toshihiro Shimizu |
890ddd |
m_hooks[h] = new Hook(*m_hooks[h]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
HookSet &HookSet::operator=(const HookSet &other)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
clearPointerContainer(m_hooks);
|
|
Toshihiro Shimizu |
890ddd |
m_hooks = other.m_hooks;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int h, hCount = m_hooks.size();
|
|
Toshihiro Shimizu |
890ddd |
for (h = 0; h != hCount; ++h)
|
|
Toshihiro Shimizu |
890ddd |
if (m_hooks[h])
|
|
Toshihiro Shimizu |
890ddd |
m_hooks[h] = new Hook(*m_hooks[h]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return *this;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int HookSet::getHookCount() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_hooks.size();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Hook *HookSet::getHook(int index) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return 0 <= index && index < getHookCount() ? m_hooks[index] : 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Hook *HookSet::touchHook(int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(0 <= index && index < maxHooksCount);
|
|
Toshihiro Shimizu |
890ddd |
if (index < 0 || index >= maxHooksCount)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (index >= (int)m_hooks.size())
|
|
Toshihiro Shimizu |
890ddd |
m_hooks.push_back(0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_hooks[index] == 0) {
|
|
Toshihiro Shimizu |
890ddd |
Hook *hook = new Hook();
|
|
Toshihiro Shimizu |
890ddd |
m_hooks[index] = hook;
|
|
Toshihiro Shimizu |
890ddd |
hook->m_id = index;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return m_hooks[index];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Hook *HookSet::addHook()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int h, hCount = m_hooks.size();
|
|
Toshihiro Shimizu |
890ddd |
for (h = 0; h != hCount; ++h) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_hooks[h] == 0) {
|
|
Toshihiro Shimizu |
890ddd |
Hook *hook = new Hook();
|
|
Toshihiro Shimizu |
890ddd |
m_hooks[h] = hook;
|
|
Toshihiro Shimizu |
890ddd |
hook->m_id = h;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return hook;
|
|
Toshihiro Shimizu |
890ddd |
} else if (m_hooks[h]->isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return m_hooks[h];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_hooks.size() >= maxHooksCount)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Hook *hook = new Hook();
|
|
Toshihiro Shimizu |
890ddd |
hook->m_id = m_hooks.size();
|
|
Toshihiro Shimizu |
890ddd |
m_hooks.push_back(hook);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return hook;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void HookSet::clearHook(Hook *hook)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)m_hooks.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
if (m_hooks[i] == hook)
|
|
Toshihiro Shimizu |
890ddd |
m_hooks[i] = 0;
|
|
Toshihiro Shimizu |
890ddd |
delete hook;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void HookSet::clearHooks()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)m_hooks.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
delete m_hooks[i];
|
|
Toshihiro Shimizu |
890ddd |
m_hooks.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TrackerObjectsSet *HookSet::getTrackerObjectsSet() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// Ripulisco l'insieme dei tracker objects
|
|
Toshihiro Shimizu |
890ddd |
m_trackerObjectsSet->clearAll();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// costruisco il tracker object in base agli Hook
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < getHookCount(); ++i) {
|
|
Toshihiro Shimizu |
890ddd |
Hook *hook = getHook(i);
|
|
Toshihiro Shimizu |
890ddd |
if (!hook || hook->isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int trackerObjectId = hook->getTrackerObjectId();
|
|
Toshihiro Shimizu |
890ddd |
if (trackerObjectId >= 0) // se l'Hook ha anche una regione
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TrackerObject *trackerObject = m_trackerObjectsSet->getObject(trackerObjectId);
|
|
Toshihiro Shimizu |
890ddd |
if (trackerObject == NULL) {
|
|
Toshihiro Shimizu |
890ddd |
trackerObject = new TrackerObject(trackerObjectId);
|
|
Toshihiro Shimizu |
890ddd |
m_trackerObjectsSet->addObject(trackerObject);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
trackerObject = m_trackerObjectsSet->getObject(trackerObjectId);
|
|
Toshihiro Shimizu |
890ddd |
assert(trackerObject != NULL);
|
|
Toshihiro Shimizu |
890ddd |
trackerObject->addHook(hook);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return m_trackerObjectsSet;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void HookSet::renumber(const std::map<tframeid, tframeid=""> &renumberTable)</tframeid,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < getHookCount(); i++)
|
|
Toshihiro Shimizu |
890ddd |
if (getHook(i))
|
|
Toshihiro Shimizu |
890ddd |
getHook(i)->renumber(renumberTable);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void HookSet::eraseFrame(const TFrameId &fid)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < getHookCount(); i++)
|
|
Toshihiro Shimizu |
890ddd |
if (getHook(i))
|
|
Toshihiro Shimizu |
890ddd |
getHook(i)->eraseFrame(fid);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void HookSet::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < getHookCount(); ++i) {
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("hook");
|
|
Toshihiro Shimizu |
890ddd |
Hook *hook = getHook(i);
|
|
Toshihiro Shimizu |
890ddd |
// Pay attention: it is necessary that empty hook will be however saved
|
|
Toshihiro Shimizu |
890ddd |
// in the xml file.
|
|
Toshihiro Shimizu |
890ddd |
if (hook)
|
|
Toshihiro Shimizu |
890ddd |
hook->saveData(os);
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void HookSet::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::string tagName;
|
|
Toshihiro Shimizu |
890ddd |
while (is.matchTag(tagName)) {
|
|
Toshihiro Shimizu |
890ddd |
if (tagName == "hook") {
|
|
Toshihiro Shimizu |
890ddd |
Hook *hook = new Hook();
|
|
Toshihiro Shimizu |
890ddd |
hook->m_id = m_hooks.size();
|
|
Toshihiro Shimizu |
890ddd |
hook->loadData(is);
|
|
Toshihiro Shimizu |
890ddd |
is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
m_hooks.push_back(hook);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TRACKER
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Hook *TrackerObject::getHook(int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(index >= 0 && index < getHooksCount());
|
|
Toshihiro Shimizu |
890ddd |
return m_hooks.at(index);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void TrackerObject::addHook(Hook *hook)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_hooks.push_back(hook);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TrackerObject::removeHook(int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(index >= 0 && index < (int)m_hooks.size());
|
|
Toshihiro Shimizu |
890ddd |
m_hooks.erase(m_hooks.begin() + index);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TrackerObject *TrackerObjectsSet::getObject(int objectId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(objectId >= 0);
|
|
Toshihiro Shimizu |
890ddd |
std::map<int, *="" trackerobject="">::iterator it = m_trackerObjects.find(objectId);</int,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_trackerObjects.end())
|
|
Toshihiro Shimizu |
890ddd |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return NULL;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TrackerObject *TrackerObjectsSet::getObjectFromIndex(int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(index >= 0 && index < (int)m_trackerObjects.size());
|
|
Toshihiro Shimizu |
890ddd |
return m_trackerObjects[index];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// return objectIndex, return -1 if objectId doesn't exist
|
|
Toshihiro Shimizu |
890ddd |
int TrackerObjectsSet::getIndexFromId(int objectId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int index = -1;
|
|
Toshihiro Shimizu |
890ddd |
int i = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < (int)m_trackerObjects.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
int id = m_trackerObjects[i]->getId();
|
|
Toshihiro Shimizu |
890ddd |
if (id == objectId) {
|
|
Toshihiro Shimizu |
890ddd |
index = i;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return index;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TrackerObjectsSet::getIdFromIndex(int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(index >= 0 && index < (int)m_trackerObjects.size());
|
|
Toshihiro Shimizu |
890ddd |
return m_trackerObjects[index]->getId();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// add new object, return new object Id
|
|
Toshihiro Shimizu |
890ddd |
int TrackerObjectsSet::addObject()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// assegno l'id
|
|
Toshihiro Shimizu |
890ddd |
int id;
|
|
Toshihiro Shimizu |
890ddd |
if (m_trackerObjects.size() > 0) {
|
|
Toshihiro Shimizu |
890ddd |
std::map<int, *="" trackerobject="">::iterator it = m_trackerObjects.end();</int,>
|
|
Toshihiro Shimizu |
890ddd |
--it;
|
|
Toshihiro Shimizu |
890ddd |
id = it->first + 1;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
id = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TrackerObject *trackerObject = new TrackerObject(id);
|
|
Toshihiro Shimizu |
890ddd |
m_trackerObjects[id] = trackerObject;
|
|
Toshihiro Shimizu |
890ddd |
return id;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TrackerObjectsSet::addObject(TrackerObject *trackerObject)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(trackerObject);
|
|
Toshihiro Shimizu |
890ddd |
int id = trackerObject->getId();
|
|
Toshihiro Shimizu |
890ddd |
assert(id >= 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_trackerObjects[id] = trackerObject;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TrackerObjectsSet::removeObject(int objectId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(objectId >= 0);
|
|
Toshihiro Shimizu |
890ddd |
std::map<int, *="" trackerobject="">::iterator tt = m_trackerObjects.find(objectId);</int,>
|
|
Toshihiro Shimizu |
890ddd |
if (tt != m_trackerObjects.end()) {
|
|
Toshihiro Shimizu |
890ddd |
delete tt->second;
|
|
Toshihiro Shimizu |
890ddd |
m_trackerObjects.erase(tt);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TrackerObjectsSet::clearAll()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<int, *="" trackerobject="">::iterator tt, tEnd(m_trackerObjects.end());</int,>
|
|
Toshihiro Shimizu |
890ddd |
for (tt = m_trackerObjects.begin(); tt != tEnd; ++tt)
|
|
Toshihiro Shimizu |
890ddd |
delete tt->second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_trackerObjects.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string getHookName(int code)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(0 <= code && code < 10);
|
|
Toshihiro Shimizu |
890ddd |
if (code == 0)
|
|
Toshihiro Shimizu |
890ddd |
return "B";
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return "H" + toString(code);
|
|
Toshihiro Shimizu |
890ddd |
}
|