Skip to content
Closed
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
5 changes: 5 additions & 0 deletions docs/tutorials/otio-serialized-schema-only-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ parameters:

parameters:
- *available_range*
- *bounds*
- *metadata*
- *name*

Expand Down Expand Up @@ -149,6 +150,7 @@ parameters:

parameters:
- *available_range*
- *bounds*
- *metadata*
- *name*
- *target_url*
Expand All @@ -174,6 +176,7 @@ parameters:

parameters:
- *available_range*
- *bounds*
- *generator_kind*
- *metadata*
- *name*
Expand All @@ -183,6 +186,7 @@ parameters:

parameters:
- *available_range*
- *bounds*
- *frame_step*
- *frame_zero_padding*
- *metadata*
Expand Down Expand Up @@ -214,6 +218,7 @@ parameters:

parameters:
- *available_range*
- *bounds*
- *metadata*
- *name*

Expand Down
5 changes: 5 additions & 0 deletions docs/tutorials/otio-serialized-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ None

parameters:
- *available_range*:
- *bounds*:
- *metadata*:
- *name*:

Expand Down Expand Up @@ -300,6 +301,7 @@ None

parameters:
- *available_range*:
- *bounds*:
- *metadata*:
- *name*:
- *target_url*:
Expand Down Expand Up @@ -349,6 +351,7 @@ None

parameters:
- *available_range*:
- *bounds*:
- *generator_kind*:
- *metadata*:
- *name*:
Expand Down Expand Up @@ -426,6 +429,7 @@ Negative ``start_frame`` is also handled. The above example with a ``start_frame

parameters:
- *available_range*:
- *bounds*:
- *frame_step*: Step between frame numbers in file names.
- *frame_zero_padding*: Number of digits to pad zeros out to in frame numbers.
- *metadata*:
Expand Down Expand Up @@ -481,6 +485,7 @@ None

parameters:
- *available_range*:
- *bounds*:
- *metadata*:
- *name*:

Expand Down
2 changes: 2 additions & 0 deletions src/opentime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set(OPENTIME_HEADER_FILES
box.h
errorStatus.h
point.h
rationalTime.h
stringPrintf.h
timeRange.h
Expand Down
76 changes: 76 additions & 0 deletions src/opentime/box.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#pragma once

#include "opentime/version.h"
#include "opentime/point.h"

namespace opentime {
namespace OPENTIME_VERSION {

class Box {
public:
Box() = default;

Box(double width, double height, Point const& center)
: _width(width), _height(height), _center(center) {}

double width() const {
return _width;
}

double height() const {
return _height;
}

Point const& center() const {
return _center;
}

double get_aspect_ratio() const {
return is_equal( _height, 0.0 ) ? 1.0 : _width / _height;
}

bool contains(Point const& p) const {
static constexpr auto epsilon = std::numeric_limits<double>::epsilon();

const double min_x = _center.x() - _width * 0.5 - epsilon;
const double max_x = _center.x() + _width * 0.5 + epsilon;

if (p.x() < min_x || p.x() > max_x) return false;

const double min_y = _center.y() - _height * 0.5 - epsilon;
const double max_y = _center.y() + _height * 0.5 + epsilon;

return p.y() >= min_y && p.y() <= max_y;
}

Box get_union(Box const& b) const {
const double min_x = std::min(_center.x() - _width * 0.5,
b._center.x() - b._width * 0.5);
const double max_x = std::max(_center.x() + _width * 0.5,
b._center.x() + b._width * 0.5);
const double min_y = std::min(_center.y() - _height * 0.5,
b._center.y() - b._height * 0.5);
const double max_y = std::max(_center.y() + _height * 0.5,
b._center.y() + b._height * 0.5);

return Box(max_x - min_x, max_y - min_y,
Point((max_x + min_x) * 0.5, (max_y + min_y) * 0.5));
}

friend bool operator== (Box lhs, Box rhs) {
return is_equal( lhs._width, rhs._width ) &&
is_equal( lhs._height, rhs._height ) &&
lhs._center == rhs._center;
}

friend bool operator!= (Box lhs, Box rhs) {
return !(lhs == rhs);
}

private:
double _width{ 0.0 };
double _height{ 0.0 };
Point _center;
};

} }
44 changes: 44 additions & 0 deletions src/opentime/point.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include "opentime/version.h"

#include <limits>
#include <cmath>

namespace opentime {
namespace OPENTIME_VERSION {

template <class T>
inline bool is_equal(T a, T b) {
return std::fabs(a - b) < std::numeric_limits<T>::epsilon();
}

class Point {
public:
Point() = default;

Point(double x, double y)
: _x(x), _y(y) {}

double x() const {
return _x;
}

double y() const {
return _y;
}

friend bool operator== (Point lhs, Point rhs) {
return is_equal(lhs._x, rhs._x) && is_equal(lhs._y, rhs._y);
}

friend bool operator!= (Point lhs, Point rhs) {
return !(lhs == rhs);
}

private:
double _x{ 0.0 };
double _y{ 0.0 };
};

} }
22 changes: 19 additions & 3 deletions src/opentimelineio/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "opentimelineio/missingReference.h"

namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {

Clip::Clip(std::string const& name,
MediaReference* media_reference,
optional<TimeRange> const& source_range,
Expand Down Expand Up @@ -40,14 +40,30 @@ TimeRange Clip::available_range(ErrorStatus* error_status) const {
"No media reference set on clip", this);
return TimeRange();
}

if (!_media_reference.value->available_range()) {
*error_status = ErrorStatus(ErrorStatus::CANNOT_COMPUTE_AVAILABLE_RANGE,
"No available_range set on media reference on clip", this);
return TimeRange();
}

return *_media_reference.value->available_range();
}

Box Clip::bounds(ErrorStatus* error_status) const {
if (!_media_reference) {
*error_status = ErrorStatus(ErrorStatus::CANNOT_COMPUTE_BOUNDS,
"No media reference set on clip", this);
return Box();
}

if (!_media_reference.value->bounds()) {
*error_status = ErrorStatus(ErrorStatus::CANNOT_COMPUTE_BOUNDS,
"No bounds set on media reference on clip", this);
return Box();
}

return *_media_reference.value->bounds();
}

} }
5 changes: 3 additions & 2 deletions src/opentimelineio/clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "opentimelineio/mediaReference.h"

namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {

class Clip : public Item {
public:
struct Schema {
Expand All @@ -23,8 +23,9 @@ class Clip : public Item {
void set_media_reference(MediaReference* media_reference);

MediaReference* media_reference() const;

virtual TimeRange available_range(ErrorStatus* error_status) const;
virtual Box bounds(ErrorStatus* error_status) const;

protected:
virtual ~Clip();
Expand Down
7 changes: 6 additions & 1 deletion src/opentimelineio/composable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "opentimelineio/composition.h"

namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {

Composable::Composable(std::string const& name,
AnyDictionary const& metadata)
: Parent(name, metadata),
Expand Down Expand Up @@ -50,4 +50,9 @@ RationalTime Composable::duration(ErrorStatus* error_status) const {
return RationalTime();
}

Box Composable::bounds(ErrorStatus* error_status) const {
*error_status = ErrorStatus::NOT_IMPLEMENTED;
return Box();
}

} }
5 changes: 3 additions & 2 deletions src/opentimelineio/composable.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "opentimelineio/serializableObjectWithMetadata.h"

namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {

class Composition;

class Composable : public SerializableObjectWithMetadata {
Expand All @@ -25,8 +25,9 @@ class Composable : public SerializableObjectWithMetadata {
Composition* parent() const {
return _parent;
}

virtual RationalTime duration(ErrorStatus* error_status) const;
virtual Box bounds(ErrorStatus* error_status) const;

protected:
bool _set_parent(Composition*);
Expand Down
13 changes: 13 additions & 0 deletions src/opentimelineio/composition.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "opentimelineio/composition.h"
#include "opentimelineio/vectorIndexing.h"
#include "opentimelineio/clip.h"

#include <assert.h>
#include <set>
Expand Down Expand Up @@ -335,4 +336,16 @@ bool Composition::has_child(Composable* child) const {
return _child_set.find(child) != _child_set.end();
}

bool Composition::has_clips() const {
for (auto child: children()) {
if (dynamic_cast<Clip*>(child.value)) {
return true;
}
else if (auto child_comp = dynamic_cast<Composition*>(child.value)) {
return child_comp->has_clips();
}
}
return false;
}

} }
2 changes: 2 additions & 0 deletions src/opentimelineio/composition.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Composition : public Item {
optional<TimeRange> trim_child_range(TimeRange child_range) const;

bool has_child(Composable* child) const;

bool has_clips() const;

virtual std::map<Composable*, TimeRange> range_of_all_children(ErrorStatus* error_status) const;

Expand Down
Loading