diff --git a/src/TrackedObjectBBox.cpp b/src/TrackedObjectBBox.cpp index 88e5a0a6..451cde04 100644 --- a/src/TrackedObjectBBox.cpp +++ b/src/TrackedObjectBBox.cpp @@ -38,18 +38,21 @@ using google::protobuf::util::TimeUtil; -// Default Constructor that sets the bounding-box displacement as 0 and the scales as 1 for the first frame -TrackedObjectBBox::TrackedObjectBBox() : delta_x(0.0), delta_y(0.0), scale_x(1.0), scale_y(1.0), rotation(0.0), - stroke_width(2) , background_alpha(1.0), stroke_alpha(0.0), background_corner(0), - stroke(0,0,255,0), background(0,0,255,0) -{ - this->TimeScale = 1.0; - return; -} +using namespace openshot; -TrackedObjectBBox::TrackedObjectBBox(int Red, int Green, int Blue, int Alfa) : delta_x(0.0), delta_y(0.0), scale_x(1.0), scale_y(1.0), rotation(0.0), - stroke_width(2) , background_alpha(1.0), stroke_alpha(0.0), background_corner(0), - stroke(Red,Green,Blue,Alfa), background(0,0,255,0) +// Default Constructor, delegating +TrackedObjectBBox::TrackedObjectBBox() + : TrackedObjectBBox::TrackedObjectBBox(0, 0, 255, 0) {} + +// Constructor that takes RGBA values for stroke, and sets the bounding-box +// displacement as 0 and the scales as 1 for the first frame +TrackedObjectBBox::TrackedObjectBBox(int Red, int Green, int Blue, int Alfa) + : delta_x(0.0), delta_y(0.0), + scale_x(1.0), scale_y(1.0), rotation(0.0), + background_alpha(1.0), background_corner(0), + stroke_width(2) , stroke_alpha(0.0), + stroke(Red, Green, Blue, Alfa), + background(0, 0, 255, 0) { this->TimeScale = 1.0; return; @@ -69,7 +72,7 @@ void TrackedObjectBBox::AddBox(int64_t _frame_num, float _cx, float _cy, float _ double time = this->FrameNToTime(_frame_num, 1.0); // Create an iterator that points to the BoxVec pair indexed by the time of given frame auto BBoxIterator = BoxVec.find(time); - + if (BBoxIterator != BoxVec.end()) { // There is a bounding-box indexed by the time of given frame, update-it @@ -142,7 +145,7 @@ BBox TrackedObjectBBox::GetBox(int64_t frame_number) double time = this->FrameNToTime(frame_number, this->TimeScale); // Return a iterator pointing to the BoxVec pair indexed by time or to the pair indexed - // by the closest upper time value. + // by the closest upper time value. auto currentBBoxIterator = BoxVec.lower_bound(time); // Check if there is a pair indexed by time, returns an empty bbox if there isn't. @@ -165,7 +168,7 @@ BBox TrackedObjectBBox::GetBox(int64_t frame_number) currentBBox.width *= this->scale_x.GetValue(frame_number); currentBBox.height *= this->scale_y.GetValue(frame_number); currentBBox.angle += this->rotation.GetValue(frame_number); - + return currentBBox; } @@ -184,7 +187,7 @@ BBox TrackedObjectBBox::GetBox(int64_t frame_number) interpolatedBBox.width *= this->scale_x.GetValue(frame_number); interpolatedBBox.height *= this->scale_y.GetValue(frame_number); interpolatedBBox.angle += this->rotation.GetValue(frame_number); - + return interpolatedBBox; } @@ -290,7 +293,7 @@ bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath) this->AddBox(frame_number, cx, cy, width, height, angle); } } - + // Show the time stamp from the last update in tracker data file if (bboxMessage.has_last_updated()) { @@ -334,7 +337,7 @@ Json::Value TrackedObjectBBox::JsonValue() const root["delta_x"] = delta_x.JsonValue(); root["delta_y"] = delta_y.JsonValue(); root["scale_x"] = scale_x.JsonValue(); - root["scale_y"] = scale_y.JsonValue(); + root["scale_y"] = scale_y.JsonValue(); root["rotation"] = rotation.JsonValue(); root["visible"] = visible.JsonValue(); root["draw_box"] = draw_box.JsonValue(); @@ -369,7 +372,7 @@ void TrackedObjectBBox::SetJson(const std::string value) // Load Json::Value into this object void TrackedObjectBBox::SetJsonValue(const Json::Value root) -{ +{ // Set the Id by the given JSON object if (!root["box_id"].isNull() && root["box_id"].asString() != "") @@ -377,7 +380,7 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root) // Set the BaseFps by the given JSON object if (!root["BaseFPS"].isNull() && root["BaseFPS"].isObject()) - { + { if (!root["BaseFPS"]["num"].isNull()) BaseFps.num = (int)root["BaseFPS"]["num"].asInt(); if (!root["BaseFPS"]["den"].isNull()) @@ -397,7 +400,7 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root) Clip* parentClip = (Clip *) ParentClip(); ChildClipId(root["child_clip_id"].asString()); } - + // Set the Keyframes by the given JSON object if (!root["delta_x"].isNull()) delta_x.SetJsonValue(root["delta_x"]); @@ -459,7 +462,7 @@ Json::Value TrackedObjectBBox::PropertiesJSON(int64_t requested_frame) const root["draw_box"] = add_property_json("Draw Box", draw_box.GetValue(requested_frame), "int", "", &draw_box, -1, 1.0, false, requested_frame); root["draw_box"]["choices"].append(add_property_choice_json("Off", 0, draw_box.GetValue(requested_frame))); root["draw_box"]["choices"].append(add_property_choice_json("On", 1, draw_box.GetValue(requested_frame))); - + root["stroke"] = add_property_json("Border", 0.0, "color", "", NULL, 0, 255, false, requested_frame); root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame); root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame); @@ -469,7 +472,7 @@ Json::Value TrackedObjectBBox::PropertiesJSON(int64_t requested_frame) const root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame); root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "int", "", &background_corner, 0.0, 60.0, false, requested_frame); - + root["background"] = add_property_json("Background", 0.0, "color", "", NULL, 0, 255, false, requested_frame); root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame); root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame); @@ -540,13 +543,13 @@ std::map TrackedObjectBBox::GetBoxValues(int64_t frame_numbe boxValues["dy"] = this->delta_y.GetValue(frame_number); boxValues["r"] = this->rotation.GetValue(frame_number); - + return boxValues; } // Return a map that contains the properties of this object's parent clip std::map TrackedObjectBBox::GetParentClipProperties(int64_t frame_number) const { - + // Get the parent clip of this object as a Clip pointer Clip* parentClip = (Clip *) ParentClip(); @@ -575,4 +578,4 @@ std::map TrackedObjectBBox::GetParentClipProperties(int64_t parentClipProperties["rotation"] = parentClip_rotation; return parentClipProperties; -} \ No newline at end of file +} diff --git a/src/TrackedObjectBase.cpp b/src/TrackedObjectBase.cpp index e3d6ed24..0a33683f 100644 --- a/src/TrackedObjectBase.cpp +++ b/src/TrackedObjectBase.cpp @@ -36,22 +36,15 @@ namespace openshot { - // Blank constructor - TrackedObjectBase::TrackedObjectBase() : visible(1.0), draw_box(1) - { - // Initializes the id as "" - id = ""; - childClipId = ""; - } + // Default constructor, delegating + TrackedObjectBase::TrackedObjectBase() : TrackedObjectBase("") {} - // Default constructor - TrackedObjectBase::TrackedObjectBase(std::string _id) : visible(1.0) - { - Id(_id); - childClipId = ""; - } + // Constructor + TrackedObjectBase::TrackedObjectBase(std::string _id) + : visible(1.0), draw_box(1), id(_id), childClipId("") {} - Json::Value TrackedObjectBase::add_property_choice_json(std::string name, int value, int selected_value) const + Json::Value TrackedObjectBase::add_property_choice_json( + std::string name, int value, int selected_value) const { // Create choice Json::Value new_choice = Json::Value(Json::objectValue);