Skip to main content

smpl_core/common/
animation.rs

1use super::{
2    expression::Expression,
3    metadata::smpl_metadata,
4    pose::PoseG,
5    types::{AngleType, SmplType, UpAxis},
6};
7use crate::{codec::codec::SmplCodec, common::types::FaceType};
8use burn::prelude::Backend;
9use core::time::Duration;
10use gloss_utils::nshare::{RefNdarray1, ToNalgebra};
11use log::warn;
12use nalgebra as na;
13use nd::concatenate;
14use ndarray as nd;
15use ndarray_npy::NpzReader;
16use num_derive::FromPrimitive;
17use serde_json::Value;
18use smpl_utils::{
19    io::FileLoader,
20    numerical::{euler2angleaxis, map},
21};
22use std::io::{Read, Seek};
23/// Animation Wrap mode
24#[derive(PartialEq, PartialOrd, Clone, Default, FromPrimitive)]
25pub enum AnimWrap {
26    Clamp,
27    #[default]
28    Loop,
29    Reverse,
30}
31/// Animation config
32#[derive(Clone)]
33pub struct AnimationConfig {
34    pub fps: f32,
35    pub wrap_behaviour: AnimWrap,
36    pub angle_type: AngleType,
37    pub up_axis: UpAxis,
38    pub smpl_type: SmplType,
39    pub face_type: FaceType,
40}
41impl Default for AnimationConfig {
42    fn default() -> Self {
43        Self {
44            fps: 60.0,
45            wrap_behaviour: AnimWrap::Clamp,
46            angle_type: AngleType::AxisAngle,
47            up_axis: UpAxis::Y,
48            smpl_type: SmplType::SmplX,
49            face_type: FaceType::SmplX,
50        }
51    }
52}
53/// The runner for animations
54#[derive(Clone)]
55#[allow(clippy::struct_excessive_bools)]
56pub struct AnimationRunner {
57    pub anim_current_time: Duration,
58    pub anim_reversed: bool,
59    pub nr_repetitions: u32,
60    pub paused: bool,
61    pub temporary_pause: bool,
62}
63impl Default for AnimationRunner {
64    fn default() -> Self {
65        Self {
66            anim_current_time: Duration::ZERO,
67            anim_reversed: false,
68            nr_repetitions: 0,
69            paused: false,
70            temporary_pause: false,
71        }
72    }
73}
74/// Animation struct for all data regarding a certain animation
75#[derive(Clone)]
76pub struct Animation {
77    pub per_frame_joint_poses: nd::Array3<f32>,
78    pub per_frame_root_trans: nd::Array2<f32>,
79    pub per_frame_expression_coeffs: Option<nd::Array2<f32>>,
80    pub start_offset: usize,
81    pub runner: AnimationRunner,
82    pub config: AnimationConfig,
83}
84impl Animation {
85    /// # Panics
86    /// Will panic if the translation and rotation do not cover the same number
87    /// of timesteps
88    #[allow(clippy::cast_possible_truncation)]
89    pub fn new_from_matrices(
90        per_frame_joint_poses: nd::Array3<f32>,
91        per_frame_global_trans: nd::Array2<f32>,
92        per_frame_expression_coeffs: Option<nd::Array2<f32>>,
93        config: AnimationConfig,
94    ) -> Self {
95        assert!(
96            per_frame_joint_poses.dim().0 == per_frame_global_trans.dim().0,
97            "The translation and rotation should cover the same number of timesteps"
98        );
99        let mut per_frame_joint_poses = per_frame_joint_poses;
100        let per_frame_global_trans = per_frame_global_trans;
101        if config.smpl_type == SmplType::SmplPP && config.angle_type == AngleType::Euler {
102            warn!("Angle type Euler is not allowed with SMPL++");
103        }
104        if config.smpl_type != SmplType::SmplPP && config.angle_type == AngleType::Euler {
105            let animation_frames = per_frame_joint_poses.dim().0;
106            let num_active_joints = per_frame_joint_poses.dim().1;
107            let mut new_per_frame_joint_poses: nd::Array3<f32> = nd::Array3::<f32>::zeros((animation_frames, num_active_joints, 3));
108            for (idx_timestep, poses_for_timestep) in per_frame_joint_poses.axis_iter(nd::Axis(0)).enumerate() {
109                for (idx_joint, joint_pose) in poses_for_timestep.axis_iter(nd::Axis(0)).enumerate() {
110                    let angle_axis = euler2angleaxis(joint_pose[0], joint_pose[1], joint_pose[2]);
111                    new_per_frame_joint_poses[(idx_timestep, idx_joint, 0)] = angle_axis.x;
112                    new_per_frame_joint_poses[(idx_timestep, idx_joint, 1)] = angle_axis.y;
113                    new_per_frame_joint_poses[(idx_timestep, idx_joint, 2)] = angle_axis.z;
114                }
115            }
116            per_frame_joint_poses = new_per_frame_joint_poses;
117        }
118        Self {
119            per_frame_joint_poses,
120            per_frame_root_trans: per_frame_global_trans,
121            per_frame_expression_coeffs,
122            start_offset: 0,
123            runner: AnimationRunner::default(),
124            config,
125        }
126    }
127    #[allow(clippy::cast_possible_truncation)]
128    fn new_from_npz_reader<R: Read + Seek>(npz: &mut NpzReader<R>, config: AnimationConfig) -> Self {
129        let per_frame_joint_poses: nd::Array2<f64> = npz.by_name("poses.npy").unwrap();
130        let animation_frames = per_frame_joint_poses.nrows();
131        let num_joints_3 = per_frame_joint_poses.ncols();
132        let per_frame_joint_poses = per_frame_joint_poses.mapv(|x| x as f32);
133        let per_frame_joint_poses = per_frame_joint_poses.into_shape((animation_frames, num_joints_3 / 3, 3)).unwrap();
134        let per_frame_global_trans: nd::Array2<f64> = npz.by_name("trans.npy").unwrap();
135        let per_frame_global_trans = per_frame_global_trans.mapv(|x| x as f32);
136        let per_frame_expression_coeffs: Option<nd::Array2<f64>> = npz.by_name("expressionParameters.npy").ok();
137        let per_frame_expression_coeffs = per_frame_expression_coeffs.map(|x| x.mapv(|x| x as f32));
138        Self::new_from_matrices(per_frame_joint_poses, per_frame_global_trans, per_frame_expression_coeffs, config)
139    }
140    /// # Panics
141    /// Will panic if the path cannot be opened
142    /// Will panic if the translation and rotation do not cover the same number
143    /// of timesteps
144    #[cfg(not(target_arch = "wasm32"))]
145    #[allow(clippy::cast_possible_truncation)]
146    pub fn new_from_npz(anim_npz_path: &str, config: AnimationConfig) -> Self {
147        let mut npz =
148            NpzReader::new(std::fs::File::open(anim_npz_path).unwrap_or_else(|_| panic!("Could not find/open file: {anim_npz_path}"))).unwrap();
149        Self::new_from_npz_reader(&mut npz, config)
150    }
151    /// # Panics
152    /// Will panic if the path cannot be opened
153    /// Will panic if the translation and rotation do not cover the same number
154    /// of timesteps
155    #[allow(clippy::cast_possible_truncation)]
156    pub async fn new_from_npz_async(anim_npz_path: &str, config: AnimationConfig) -> Self {
157        let reader = FileLoader::open(anim_npz_path).await;
158        let mut npz = NpzReader::new(reader).unwrap();
159        Self::new_from_npz_reader(&mut npz, config)
160    }
161    /// # Panics
162    /// Will panic if the path cannot be opened
163    /// Will panic if the translation and rotation do not cover the same number
164    /// of timesteps
165    #[allow(clippy::cast_possible_truncation)]
166    #[allow(clippy::identity_op)]
167    pub fn new_from_json(path: &str, _anim_fps: f32, config: AnimationConfig) -> Self {
168        let file = std::fs::File::open(path).unwrap();
169        let reader = std::io::BufReader::new(file);
170        let v: Value = serde_json::from_reader(reader).unwrap();
171        let poses = &v["poses"];
172        let animation_frames = poses.as_array().unwrap().len();
173        let num_active_joints = poses[0].as_array().unwrap().len() / 3;
174        let per_frame_global_trans: nd::Array2<f32> = nd::Array2::<f32>::zeros((animation_frames, 3));
175        let poses_json_vec: Vec<f32> = poses.as_array().unwrap().iter().map(|x| x.as_f64().unwrap() as f32).collect();
176        let per_frame_joint_poses = nd::Array3::from_shape_vec((animation_frames, num_active_joints, 3), poses_json_vec).unwrap();
177        Self::new_from_matrices(per_frame_joint_poses, per_frame_global_trans, None, config)
178    }
179    /// Create an ``Animation`` component from a ``SmplCodec``
180    /// # Panics
181    /// Will panic if the individual body part poses in the codec don't have the
182    /// correct shape to be concatenated together into a full pose for the whole
183    /// body
184    #[allow(clippy::cast_sign_loss)]
185    pub fn new_from_smpl_codec(codec: &SmplCodec, wrap_behaviour: AnimWrap) -> Option<Self> {
186        let nr_frames = codec.frame_count as usize;
187        let metadata = smpl_metadata(&codec.smpl_type());
188        let body_translation = codec
189            .body_translation
190            .as_ref()
191            .unwrap_or(&ndarray::Array2::<f32>::zeros((nr_frames, 3)))
192            .clone();
193        let fps = codec.frame_rate?;
194        if codec.smpl_type() == SmplType::SmplPP {
195            let body_pose = codec
196                .body_pose
197                .as_ref()
198                .unwrap_or(&ndarray::Array3::<f32>::zeros((nr_frames, metadata.pose_dim, 1)))
199                .clone();
200            let config = AnimationConfig {
201                smpl_type: SmplType::SmplPP,
202                wrap_behaviour,
203                fps,
204                ..Default::default()
205            };
206            Some(Self::new_from_matrices(body_pose, body_translation, None, config))
207        } else {
208            let body_pose = codec
209                .body_pose
210                .as_ref()
211                .unwrap_or(&ndarray::Array3::<f32>::zeros((nr_frames, 1 + metadata.num_body_joints, 3)))
212                .clone();
213            let head_pose = codec
214                .head_pose
215                .as_ref()
216                .unwrap_or(&ndarray::Array3::<f32>::zeros((nr_frames, metadata.num_face_joints, 3)))
217                .clone();
218            let left_hand_pose = codec
219                .left_hand_pose
220                .as_ref()
221                .unwrap_or(&ndarray::Array3::<f32>::zeros((nr_frames, metadata.num_hand_joints, 3)))
222                .clone();
223            let right_hand_pose = codec
224                .right_hand_pose
225                .as_ref()
226                .unwrap_or(&ndarray::Array3::<f32>::zeros((nr_frames, metadata.num_hand_joints, 3)))
227                .clone();
228            let per_frame_joint_poses = concatenate(
229                nd::Axis(1),
230                &[body_pose.view(), head_pose.view(), left_hand_pose.view(), right_hand_pose.view()],
231            )
232            .unwrap();
233            let per_frame_expression_coeffs = codec.expression_parameters.clone();
234            let config = AnimationConfig {
235                smpl_type: codec.smpl_type(),
236                wrap_behaviour,
237                fps,
238                ..Default::default()
239            };
240            Some(Self::new_from_matrices(
241                per_frame_joint_poses,
242                body_translation,
243                per_frame_expression_coeffs,
244                config,
245            ))
246        }
247    }
248    /// Create an ``Animation`` component from a ``.smpl`` file
249    #[cfg(not(target_arch = "wasm32"))]
250    #[allow(clippy::cast_possible_truncation)]
251    pub fn new_from_smpl_file(path: &str, wrap_behaviour: AnimWrap) -> Option<Self> {
252        let codec = SmplCodec::from_file(path);
253        Self::new_from_smpl_codec(&codec, wrap_behaviour)
254    }
255    /// Create an ``Animation`` component from a ``.smpl`` buffer
256    #[allow(clippy::cast_possible_truncation)]
257    pub fn new_from_smpl_buf(buf: &[u8], wrap_behaviour: AnimWrap) -> Option<Self> {
258        let codec = SmplCodec::from_buf(buf);
259        Self::new_from_smpl_codec(&codec, wrap_behaviour)
260    }
261    pub fn num_active_joints(&self) -> usize {
262        self.per_frame_joint_poses.dim().1
263    }
264    pub fn num_animation_frames(&self) -> usize {
265        self.per_frame_joint_poses.dim().0
266    }
267    /// Advances the animation by the amount of time elapsed since last time we
268    /// got the current pose
269    pub fn advance(&mut self, dt_raw: Duration, first_time: bool) {
270        let duration = self.duration();
271        let runner = &mut self.runner;
272        let config = &self.config;
273        let mut dt = dt_raw;
274        if first_time {
275            dt = Duration::ZERO;
276        }
277        let will_overflow = runner.anim_current_time + dt > duration;
278        let will_underflow = runner.anim_current_time < dt && runner.anim_reversed;
279        if will_overflow || will_underflow {
280            if will_overflow {
281                match config.wrap_behaviour {
282                    AnimWrap::Clamp => {
283                        dt = Duration::ZERO;
284                        runner.anim_current_time = duration;
285                    }
286                    AnimWrap::Loop => {
287                        dt = Duration::from_secs_f64(dt.as_secs_f64() % duration.as_secs_f64());
288                        runner.anim_current_time = Duration::ZERO;
289                        runner.nr_repetitions += 1;
290                    }
291                    AnimWrap::Reverse => {
292                        dt = Duration::from_secs_f64(dt.as_secs_f64() % duration.as_secs_f64());
293                        runner.anim_current_time = duration;
294                        runner.anim_reversed = !runner.anim_reversed;
295                        runner.nr_repetitions += 1;
296                    }
297                }
298            } else {
299                match config.wrap_behaviour {
300                    AnimWrap::Clamp => {
301                        dt = Duration::ZERO;
302                        runner.anim_current_time = Duration::ZERO;
303                    }
304                    AnimWrap::Loop => {
305                        dt = Duration::from_secs_f64(dt.as_secs_f64() % duration.as_secs_f64());
306                        runner.anim_current_time = duration;
307                        runner.nr_repetitions += 1;
308                    }
309                    AnimWrap::Reverse => {
310                        dt = Duration::from_secs_f64(dt.as_secs_f64() % duration.as_secs_f64());
311                        runner.anim_reversed = !runner.anim_reversed;
312                        runner.nr_repetitions += 1;
313                    }
314                }
315            }
316        }
317        if runner.anim_reversed {
318            runner.anim_current_time = runner.anim_current_time.saturating_sub(dt);
319        } else {
320            runner.anim_current_time = runner.anim_current_time.saturating_add(dt);
321        }
322    }
323    pub fn has_expression(&self) -> bool {
324        self.per_frame_expression_coeffs.is_some()
325    }
326    #[allow(clippy::cast_precision_loss)]
327    #[allow(clippy::cast_possible_truncation)]
328    #[allow(clippy::cast_sign_loss)]
329    pub fn get_smooth_time_indices(&self) -> (usize, usize, f32) {
330        let frame_time = map(
331            self.runner.anim_current_time.as_secs_f32(),
332            0.0,
333            self.duration().as_secs_f32(),
334            0.0,
335            (self.num_animation_frames() - 1) as f32,
336        );
337        let frame_ceil = frame_time.ceil();
338        let frame_ceil = frame_ceil.clamp(0.0, (self.num_animation_frames() - 1) as f32);
339        let frame_floor = frame_time.floor();
340        let frame_floor = frame_floor.clamp(0.0, (self.num_animation_frames() - 1) as f32);
341        let w_ceil = frame_ceil - frame_time;
342        let w_ceil = 1.0 - w_ceil;
343        (frame_floor as usize, frame_ceil as usize, w_ceil)
344    }
345    /// Get the pose and translation at the current time, interpolates if
346    /// necessary. Using Slerp interpolation is more accurate but also slower. Most of the time when vieweing an animation, it's enough to use `use_slerp=false`
347    #[allow(clippy::cast_precision_loss)]
348    #[allow(clippy::cast_possible_truncation)]
349    #[allow(clippy::cast_sign_loss)]
350    pub fn get_current_pose<B: Backend>(&mut self, use_slerp: bool) -> PoseG<B> {
351        let (frame_floor, frame_ceil, w_ceil) = self.get_smooth_time_indices();
352        let anim_frame_ceil = self.get_pose_at_idx(frame_ceil);
353        let anim_frame_floor = self.get_pose_at_idx(frame_floor);
354        anim_frame_floor.interpolate(&anim_frame_ceil, w_ceil, use_slerp)
355    }
356    /// Get pose at a certain frame ID
357    #[allow(clippy::cast_precision_loss)]
358    #[allow(clippy::cast_possible_truncation)]
359    #[allow(clippy::cast_sign_loss)]
360    pub fn get_pose_at_idx<B: Backend>(&self, idx: usize) -> PoseG<B> {
361        let joint_poses = self.per_frame_joint_poses.index_axis(nd::Axis(0), idx).to_owned();
362        let global_trans = self.per_frame_root_trans.index_axis(nd::Axis(0), idx).to_owned();
363        PoseG::<B>::new_from_ndarray(joint_poses, global_trans, self.config.up_axis, self.config.smpl_type)
364    }
365    /// Get expression at current time
366    pub fn get_current_expression(&mut self) -> Option<Expression> {
367        let (frame_floor, frame_ceil, w_ceil) = self.get_smooth_time_indices();
368        let expression_ceil = self.get_expression_at_idx(frame_ceil);
369        let expresion_floor = self.get_expression_at_idx(frame_floor);
370        expresion_floor.map(|expresion_floor| expresion_floor.interpolate(&expression_ceil.unwrap(), w_ceil))
371    }
372    /// Get expression at a given frame ID
373    #[allow(clippy::cast_precision_loss)]
374    #[allow(clippy::cast_possible_truncation)]
375    #[allow(clippy::cast_sign_loss)]
376    pub fn get_expression_at_idx(&self, idx: usize) -> Option<Expression> {
377        if let Some(ref per_frame_expression_coeffs) = self.per_frame_expression_coeffs {
378            let expr_coeffs = per_frame_expression_coeffs.index_axis(nd::Axis(0), idx).to_owned();
379            Some(Expression::new_from_ndarray(expr_coeffs, self.config.face_type))
380        } else {
381            None
382        }
383    }
384    #[must_use]
385    pub fn slice_time_range(&self, start_sec: f32, end_sec: f32) -> Animation {
386        let mut cur_anim = self.clone();
387        cur_anim.set_cur_time_as_sec(start_sec);
388        let (start_idx, _, _) = cur_anim.get_smooth_time_indices();
389        cur_anim.set_cur_time_as_sec(end_sec);
390        let (_, end_idx, _) = cur_anim.get_smooth_time_indices();
391        let nr_frames = end_idx - start_idx + 1;
392        let nr_joints = cur_anim.per_frame_joint_poses.shape()[1];
393        let mut new_per_frame_joint_poses = nd::Array3::<f32>::zeros((nr_frames, nr_joints, 3));
394        let mut new_per_frame_root_trans = nd::Array2::<f32>::zeros((nr_frames, 3));
395        for (idx_insert_to, idx_extract_from) in (start_idx..=end_idx).enumerate() {
396            let joint_poses = cur_anim.per_frame_joint_poses.index_axis(nd::Axis(0), idx_extract_from);
397            let trans = cur_anim.per_frame_root_trans.index_axis(nd::Axis(0), idx_extract_from);
398            new_per_frame_joint_poses.index_axis_mut(nd::Axis(0), idx_insert_to).assign(&joint_poses);
399            new_per_frame_root_trans.index_axis_mut(nd::Axis(0), idx_insert_to).assign(&trans);
400        }
401        let _new_per_frame_expression_coeffs = if let Some(ref per_frame_expression_coeffs) = cur_anim.per_frame_expression_coeffs {
402            let nr_expr_coeffs = per_frame_expression_coeffs.shape()[1];
403            let mut new_per_frame_expression_coeffs = nd::Array2::<f32>::zeros((nr_frames, nr_expr_coeffs));
404            for (idx_insert_to, idx_extract_from) in (start_idx..=end_idx).enumerate() {
405                let expr = per_frame_expression_coeffs.index_axis(nd::Axis(0), idx_extract_from);
406                new_per_frame_expression_coeffs.index_axis_mut(nd::Axis(0), idx_insert_to).assign(&expr);
407            }
408            Some(new_per_frame_expression_coeffs)
409        } else {
410            None
411        };
412        let new_per_frame_expression_coeffs = if let Some(ref per_frame_expression_coeffs) = cur_anim.per_frame_expression_coeffs {
413            let nr_expr_coeffs = per_frame_expression_coeffs.shape()[1];
414            let mut new_per_frame_expression_coeffs = nd::Array2::<f32>::zeros((nr_frames, nr_expr_coeffs));
415            for (idx_insert_to, idx_extract_from) in (start_idx..=end_idx).enumerate() {
416                let expr = per_frame_expression_coeffs.index_axis(nd::Axis(0), idx_extract_from);
417                new_per_frame_expression_coeffs.index_axis_mut(nd::Axis(0), idx_insert_to).assign(&expr);
418            }
419            Some(new_per_frame_expression_coeffs)
420        } else {
421            None
422        };
423        Animation::new_from_matrices(
424            new_per_frame_joint_poses,
425            new_per_frame_root_trans,
426            new_per_frame_expression_coeffs,
427            cur_anim.config.clone(),
428        )
429    }
430    /// Rotates multiple of 90 until the axis of the body is aligned with some
431    /// arbitrary vector
432    pub fn align_y_axis_quadrant(&mut self, current_axis: &nd::Array1<f32>, desired_axis: &nd::Array1<f32>) {
433        let mut cur_axis_xz = na::Vector2::new(current_axis[0], -current_axis[2]).normalize();
434        let desired_axis_xz = na::Vector2::new(desired_axis[0], -desired_axis[2]).normalize();
435        let mut best_dot = f32::MIN;
436        let mut best_angle: f32 = 0.0;
437        let mut cur_angle = 0.0;
438        let rot_90 = na::Rotation2::new(std::f32::consts::FRAC_PI_2);
439        for _iters in 0..4 {
440            cur_axis_xz = rot_90 * cur_axis_xz;
441            cur_angle += 90.0;
442            let dot = cur_axis_xz.dot(&desired_axis_xz);
443            if dot > best_dot {
444                best_dot = dot;
445                best_angle = cur_angle;
446            }
447        }
448        let alignment_rot = na::Rotation3::from_euler_angles(0.0, best_angle.to_radians(), 0.0);
449        ndarray::Zip::from(self.per_frame_joint_poses.outer_iter_mut())
450            .and(self.per_frame_root_trans.outer_iter_mut())
451            .for_each(|mut poses_for_timestep, mut trans_for_timestep| {
452                let pelvis_axis_angle = poses_for_timestep.row(0).into_nalgebra();
453                let pelvis_axis_angle = pelvis_axis_angle.fixed_rows::<3>(0);
454                let pelvis_rot = na::Rotation3::from_scaled_axis(pelvis_axis_angle);
455                let new_pelvis_rot = alignment_rot * pelvis_rot;
456                poses_for_timestep.row_mut(0).assign(&new_pelvis_rot.scaled_axis().ref_ndarray1());
457                let trans_for_timestep_na = trans_for_timestep.to_owned().into_nalgebra();
458                let new_trans_for_timestep_na = alignment_rot * trans_for_timestep_na;
459                trans_for_timestep.assign(&new_trans_for_timestep_na.ref_ndarray1());
460            });
461    }
462    pub fn get_cur_time(&self) -> Duration {
463        self.runner.anim_current_time
464    }
465    pub fn set_cur_time_as_sec(&mut self, time_sec: f32) {
466        self.runner.anim_current_time = Duration::from_secs_f32(time_sec);
467    }
468    pub fn pause(&mut self) {
469        self.runner.paused = true;
470    }
471    pub fn play(&mut self) {
472        self.runner.paused = false;
473    }
474    /// Duration of the animation
475    #[allow(clippy::cast_precision_loss)]
476    pub fn duration(&self) -> Duration {
477        Duration::from_secs_f32(self.num_animation_frames() as f32 / self.config.fps)
478    }
479    pub fn is_finished(&self) -> bool {
480        self.config.wrap_behaviour == AnimWrap::Clamp && self.runner.anim_current_time >= self.duration()
481    }
482    pub fn nr_repetitions(&self) -> u32 {
483        self.runner.nr_repetitions
484    }
485    /// Shift each frame of the animation by the given translation vector.
486    ///
487    /// # Errors
488    ///
489    /// Will return `Err` for array size mismatch.
490    pub fn translate(&mut self, translation: &nd::Array1<f32>) -> Result<(), String> {
491        if translation.len() != self.per_frame_root_trans.ncols() {
492            return Err("Translation vector should be length-3 array".to_owned());
493        }
494        for mut row in self.per_frame_root_trans.rows_mut() {
495            row += translation;
496        }
497        Ok(())
498    }
499}