Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Applications/VpView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ if(VISGUI_ENABLE_VIDTK)
else()
list(APPEND vpViewSources
vpVdfIO.cxx
vpVdfEventIO.cxx
vpVdfTrackIO.cxx
)
endif()
Expand Down
28 changes: 27 additions & 1 deletion Applications/VpView/vpEventIO.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*ckwg +5
* Copyright 2013 by Kitware, Inc. All Rights Reserved. Please refer to
* Copyright 2019 by Kitware, Inc. All Rights Reserved. Please refer to
* KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
* Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
*/
Expand Down Expand Up @@ -31,3 +31,29 @@ bool vpEventIO::ImportEvents(vtkIdType, float, float)
{
return false;
}

//-----------------------------------------------------------------------------
int vpEventIO::GetEventType(const char* typeName)
{
const auto index = this->GetEventTypeIndex(typeName);
return this->EventTypes->GetType(index).GetId();
}

//-----------------------------------------------------------------------------
int vpEventIO::GetEventTypeIndex(const char* typeName)
{
const auto index = this->EventTypes->GetTypeIndex(typeName);

if (index >= 0)
{
return index;
}

vgEventType type;
type.SetName(typeName);
type.SetId(this->EventTypes->GetNextAvailableId());

const auto newIndex = this->EventTypes->GetNumberOfTypes();
this->EventTypes->AddType(type);
return newIndex;
}
5 changes: 4 additions & 1 deletion Applications/VpView/vpEventIO.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*ckwg +5
* Copyright 2018 by Kitware, Inc. All Rights Reserved. Please refer to
* Copyright 2019 by Kitware, Inc. All Rights Reserved. Please refer to
* KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
* Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
*/
Expand Down Expand Up @@ -27,6 +27,9 @@ class vpEventIO

virtual bool WriteEvents(const char* filename) const = 0;

int GetEventType(const char* typeName);
int GetEventTypeIndex(const char* typeName);

protected:
friend class vpFileEventReader;

Expand Down
19 changes: 19 additions & 0 deletions Applications/VpView/vpTrackIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <vtkMatrix4x4.h>

#include <QSettings>

#include <algorithm>

#include <assert.h>
Expand Down Expand Up @@ -160,3 +162,20 @@ int vpTrackIO::GetTrackTypeIndex(const char* typeName)
this->TrackTypes->AddType(type);
return newIndex;
}

//-----------------------------------------------------------------------------
QPointF vpTrackIO::EstimateTrackPoint(const QRectF& box)
{
constexpr static auto half = static_cast<qreal>(0.5);

static const bool bottom =
QSettings{}.value("TrackPointsAtBottom", false).toBool();

auto const x = half * (box.left() + box.right());
if (bottom)
{
return {x, box.bottom()};
}

return {x, half * (box.top() + box.bottom())};
}
5 changes: 4 additions & 1 deletion Applications/VpView/vpTrackIO.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*ckwg +5
* Copyright 2018 by Kitware, Inc. All Rights Reserved. Please refer to
* Copyright 2019 by Kitware, Inc. All Rights Reserved. Please refer to
* KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
* Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
*/
Expand All @@ -12,6 +12,7 @@
#include <vtkSmartPointer.h>

#include <QPointF>
#include <QRectF>

class vpFrameMap;

Expand Down Expand Up @@ -89,6 +90,8 @@ class vpTrackIO
protected:
virtual unsigned int GetImageHeight() const = 0;

QPointF EstimateTrackPoint(const QRectF& box);

protected:
friend class vpFileTrackReader;

Expand Down
190 changes: 190 additions & 0 deletions Applications/VpView/vpVdfEventIO.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*ckwg +5
* Copyright 2019 by Kitware, Inc. All Rights Reserved. Please refer to
* KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
* Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
*/

#include "vpVdfEventIO.h"

#include "vpFileUtil.h"

#include <vtkVgEvent.h>
#include <vtkVgEventModel.h>
#include <vtkVgTrackModel.h>

#include <vdfDataSource.h>
#include <vdfEventReader.h>
#include <vdfSourceService.h>

#include <vgCheckArg.h>

#include <qtEnumerate.h>
#include <qtStlUtil.h>

#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QUrl>

QTE_IMPLEMENT_D_FUNC(vpVdfEventIO)

//-----------------------------------------------------------------------------
class vpVdfEventIOPrivate
{
public:
QHash<long long, vtkIdType>& EventSourceIdToModelIdMap;
const QHash<long long, vtkIdType>& TrackSourceIdToModelIdMap;

QUrl EventsUri;
};

//-----------------------------------------------------------------------------
vpVdfEventIO::vpVdfEventIO(
QHash<long long, vtkIdType>& eventSourceIdToModelIdMap,
const QHash<long long, vtkIdType>& trackSourceIdToModelIdMap,
vtkVgEventModel* eventModel, vtkVgEventTypeRegistry* eventTypes)
: vpEventIO{eventModel, eventTypes},
d_ptr{new vpVdfEventIOPrivate{eventSourceIdToModelIdMap,
trackSourceIdToModelIdMap, {}}}
{
}

//-----------------------------------------------------------------------------
vpVdfEventIO::~vpVdfEventIO()
{
}

//-----------------------------------------------------------------------------
void vpVdfEventIO::SetEventsUri(const QUrl& uri)
{
QTE_D();
d->EventsUri = uri;
}

//-----------------------------------------------------------------------------
bool vpVdfEventIO::ReadEvents()
{
QTE_D();

vdfEventReader reader;
auto const& desiredSources = reader.desiredSources();

auto* const trackModel = this->EventModel->GetTrackModel();
CHECK_ARG(trackModel, false);

if (d->EventsUri.isLocalFile())
{
// TODO resolve relative globs
// const auto& globPath = d->EventsUri.toLocalFile();
// const auto& files = vpGlobFiles(QDir::current(), pattern);

QFileInfo fi{d->EventsUri.toLocalFile()};
const auto& dir = fi.absoluteDir();
const auto& pattern = fi.fileName();

const auto& files = vpGlobFiles(dir, pattern);
if (files.isEmpty())
{
return false;
}

// Read through each event file
for (const auto& filePath : files)
{
// Construct the event source and event reader
const auto& eventUri = QUrl::fromLocalFile(filePath);
QScopedPointer<vdfDataSource> source{
vdfSourceService::createArchiveSource(eventUri, desiredSources)};

if (source && reader.setSource(source.data()))
{
// Read events
if (!reader.exec() && reader.failed())
{
// Event reading failed; die
return false;
}
}
}
}
else
{
// Construct the event source and event reader
QScopedPointer<vdfDataSource> source{
vdfSourceService::createArchiveSource(d->EventsUri, desiredSources)};

if (source)
{
reader.setSource(source.data());

// Read events
if (!reader.exec() && reader.failed())
{
// Event reading failed; die
return false;
}
}
}

if (!reader.hasData())
{
// No data was obtained; die
return false;
}

const auto& inEvents = reader.events();
for (const auto& in : inEvents)
{
auto event = vtkSmartPointer<vtkVgEvent>::New();

// Get (desired) event model identifier
const auto vtkId = static_cast<vtkIdType>(in.Id);

// Set (actual) track model identifier
if (this->EventModel->GetEvent(vtkId))
{
const auto fallbackId = this->EventModel->GetNextAvailableId();
qInfo() << "Event id" << vtkId
<< "is not unique: changing id of imported event to"
<< fallbackId;
event->SetId(fallbackId);
d->EventSourceIdToModelIdMap.insert(in.Id, fallbackId);
}
else
{
event->SetId(vtkId);
}

// Set event start/stop
event->SetStartFrame(in.Start);
event->SetEndFrame(in.Stop);

// Set event classifiers
for (const auto& c : in.Classification)
{
event->AddClassifier(this->GetEventType(c.first.c_str()), c.second);
}

// Set event tracks
for (const auto& ti : in.TrackIntervals)
{
const auto tsn = ti.Track.SerialNumber;
const auto trackId =
d->TrackSourceIdToModelIdMap.value(tsn, static_cast<vtkIdType>(tsn));
auto* const track = trackModel->GetTrack(trackId);
if (track)
{
event->AddTrack(track, ti.Start, ti.Stop);
}
else
{
qWarning() << "Track" << ti.Track << "for event" << vtkId
<< "was not found!";
}
}

this->EventModel->AddEvent(event);
}

return true;
}
46 changes: 46 additions & 0 deletions Applications/VpView/vpVdfEventIO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*ckwg +5
* Copyright 2019 by Kitware, Inc. All Rights Reserved. Please refer to
* KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
* Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
*/

#ifndef __vpVdfEventIO_h
#define __vpVdfEventIO_h

#include "vpEventIO.h"

#include <qtGlobal.h>

#include <QScopedPointer>

template <typename Key, typename Value> class QHash;

class QUrl;

class vpVdfEventIOPrivate;

class vpVdfEventIO : public vpEventIO
{
public:
vpVdfEventIO(
QHash<long long, vtkIdType>& eventSourceIdToModelIdMap,
const QHash<long long, vtkIdType>& trackSourceIdToModelIdMap,
vtkVgEventModel* eventModel, vtkVgEventTypeRegistry* eventTypes);

virtual ~vpVdfEventIO();

void SetEventsUri(const QUrl&);

virtual bool ReadEvents() override;
virtual bool WriteEvents(const char*) const override
{ return false; }

protected:
QTE_DECLARE_PRIVATE_RPTR(vpVdfEventIO);

private:
QTE_DECLARE_PRIVATE(vpVdfEventIO);
QTE_DISABLE_COPY(vpVdfEventIO);
};

#endif
Loading