Return a bounding-box from BoxVec with it's properties adjusted by the Keyframes
| 123 | |
| 124 | // Return a bounding-box from BoxVec with it's properties adjusted by the Keyframes |
| 125 | BBox TrackedObjectBBox::GetBox(int64_t frame_number) |
| 126 | { |
| 127 | // Get the time position of the given frame. |
| 128 | double time = this->FrameNToTime(frame_number, this->TimeScale); |
| 129 | |
| 130 | // Return a iterator pointing to the BoxVec pair indexed by time or to the pair indexed |
| 131 | // by the closest upper time value. |
| 132 | auto currentBBoxIterator = BoxVec.lower_bound(time); |
| 133 | |
| 134 | // Check if there is a pair indexed by time, returns an empty bbox if there isn't. |
| 135 | if (currentBBoxIterator == BoxVec.end()) |
| 136 | { |
| 137 | // Create and return an empty bounding-box object |
| 138 | BBox emptyBBox; |
| 139 | return emptyBBox; |
| 140 | } |
| 141 | |
| 142 | // Check if the iterator matches a BBox indexed by time or points to the first element of BoxVec |
| 143 | if ((currentBBoxIterator->first == time) || (currentBBoxIterator == BoxVec.begin())) |
| 144 | { |
| 145 | // Get the BBox indexed by time |
| 146 | BBox currentBBox = currentBBoxIterator->second; |
| 147 | |
| 148 | // Adjust the BBox properties by the Keyframes values |
| 149 | currentBBox.cx += this->delta_x.GetValue(frame_number); |
| 150 | currentBBox.cy += this->delta_y.GetValue(frame_number); |
| 151 | currentBBox.width *= this->scale_x.GetValue(frame_number); |
| 152 | currentBBox.height *= this->scale_y.GetValue(frame_number); |
| 153 | currentBBox.angle += this->rotation.GetValue(frame_number); |
| 154 | |
| 155 | return currentBBox; |
| 156 | } |
| 157 | |
| 158 | // BBox indexed by the closest upper time |
| 159 | BBox currentBBox = currentBBoxIterator->second; |
| 160 | // BBox indexed by the closet lower time |
| 161 | BBox previousBBox = prev(currentBBoxIterator, 1)->second; |
| 162 | |
| 163 | // Interpolate a BBox in the middle of previousBBox and currentBBox |
| 164 | BBox interpolatedBBox = InterpolateBoxes(prev(currentBBoxIterator, 1)->first, currentBBoxIterator->first, |
| 165 | previousBBox, currentBBox, time); |
| 166 | |
| 167 | // Adjust the BBox properties by the Keyframes values |
| 168 | interpolatedBBox.cx += this->delta_x.GetValue(frame_number); |
| 169 | interpolatedBBox.cy += this->delta_y.GetValue(frame_number); |
| 170 | interpolatedBBox.width *= this->scale_x.GetValue(frame_number); |
| 171 | interpolatedBBox.height *= this->scale_y.GetValue(frame_number); |
| 172 | interpolatedBBox.angle += this->rotation.GetValue(frame_number); |
| 173 | |
| 174 | return interpolatedBBox; |
| 175 | } |
| 176 | |
| 177 | // Interpolate the bouding-boxes properties |
| 178 | BBox TrackedObjectBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target) |
no test coverage detected