c3dio 0.8.0

A library for reading and writing C3D motion capture files.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
//! Contains force platform information in the form of the `ForcePlatforms` struct.
//! Includes the C3d struct implementation and high-level functions for reading and writing C3D files.
use crate::parameters::{Parameter, ParameterData, Parameters};
use crate::processor::Processor;
use crate::{C3dParseError, C3dWriteError};
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use std::ops::{Index, IndexMut};

#[derive(Debug, Clone, Default, PartialEq)]
pub struct ForcePlatforms {
    pub force_platforms: Vec<ForcePlatform>,
    pub zero: [u16; 2],
}

impl Deref for ForcePlatforms {
    type Target = Vec<ForcePlatform>;

    fn deref(&self) -> &Self::Target {
        &self.force_platforms
    }
}

impl DerefMut for ForcePlatforms {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.force_platforms
    }
}

impl ToString for ForcePlatforms {
    fn to_string(&self) -> String {
        let mut s = String::new();
        s.push_str("Force Platforms:\n");
        s.push_str("Zero:\n");
        s.push_str(&format!("  {:?}\n", self.zero));
        s.push_str("Force Platforms:\n");
        for (i, force_platform) in self.force_platforms.iter().enumerate() {
            s.push_str(&format!("  {}: {:?}\n", i, force_platform));
        }
        s
    }
}

#[derive(Debug, Clone, Default)]
pub struct ForcePlatform {
    pub plate_type: ForcePlatformType,
    pub corners: ForcePlatformCorners,
    pub origin: ForcePlatformOrigin,
    pub channels: [u8; 8],
    pub cal_matrix: Option<[[f32; 6]; 6]>,
}

impl PartialEq for ForcePlatform {
    fn eq(&self, other: &Self) -> bool {
        self.plate_type == other.plate_type
            && self.corners == other.corners
            && self.origin == other.origin
            && self.channels == other.channels
            && self.cal_matrix == other.cal_matrix
    }
}

impl ToString for ForcePlatform {
    fn to_string(&self) -> String {
        let mut s = String::new();
        s.push_str("Plate Type:\n");
        s.push_str(&format!("  {:?}\n", self.plate_type));
        s.push_str("Corners:\n");
        for (i, corners) in self.corners.iter().enumerate() {
            s.push_str(&format!("  {}: {:?}\n", i, corners));
        }
        s.push_str("Origin:\n");
        s.push_str(&format!("  {:?}\n", self.origin));
        s.push_str("Channels:\n");
        s.push_str(&format!("  {:?}\n", self.channels));
        s.push_str("Cal Matrix:\n");
        s.push_str(&format!("  {:?}\n", self.cal_matrix));
        s
    }
}

impl ForcePlatforms {
    pub(crate) fn from_parameters(parameters: &mut Parameters) -> Result<Self, C3dParseError> {
        let used_parameter = parameters.remove("FORCE_PLATFORM", "USED");
        let used: Option<u16> = match used_parameter {
            None => None,
            Some(parameter) => Some(parameter.as_ref().try_into()?),
        };
        let mut is_none_or_zero = used.is_none();
        if !is_none_or_zero {
            let used = used.unwrap();
            is_none_or_zero = used == 0;
        }
        if is_none_or_zero {
            return Ok(ForcePlatforms::default());
        } else {
            let used = used.unwrap();
            let plate_type = ForcePlatformType::from_parameters(parameters, used)?;
            let corners = ForcePlatformCorners::from_parameters(parameters, used)?;
            let origin = ForcePlatformOrigin::from_parameters(parameters, used)?;
            let zero = parameters
                .remove_or_err("FORCE_PLATFORM", "ZERO")?
                .as_ref()
                .try_into()?;
            let contains_type_3 = plate_type.iter().any(|x| *x == ForcePlatformType::Type3);
            let channels = get_channels(parameters, used, contains_type_3)?;
            let cal_matrices = get_cal_matrix_vector(parameters, &plate_type)?;

            let mut force_platforms = Vec::new();
            for i in 0..used as usize {
                let mut force_platform = ForcePlatform::default();
                force_platform.plate_type = plate_type[i].clone();
                force_platform.corners = corners[i].clone();
                force_platform.origin = origin[i].clone();
                force_platform.channels = channels[i];
                force_platform.cal_matrix = cal_matrices[i].clone();
                force_platforms.push(force_platform);
            }
            let force_platform_parameters = ForcePlatforms {
                zero,
                force_platforms,
            };
            Ok(force_platform_parameters)
        }
    }

    pub fn len(&self) -> usize {
        self.force_platforms.len()
    }

    pub(crate) fn write(
        &self,
        processor: &Processor,
        group_names_to_ids: &HashMap<String, usize>,
    ) -> Result<Vec<u8>, C3dWriteError> {
        let mut bytes = Vec::new();
        // "FORCE_PLATFORM", "USED"
        bytes.extend(Parameter::integer(self.force_platforms.len() as i16).write(
            processor,
            "USED".to_string(),
            group_names_to_ids["FORCE_PLATFORM"],
            false,
        )?);
        // "FORCE_PLATFORM", "CORNERS"
        if self.force_platforms.len() > 0 {
            let mut corners = Parameter::floats(
                self.force_platforms
                    .iter()
                    .map(|x| {
                        let mut out: Vec<f32> = Vec::new();
                        for corner in x.corners.clone().to_vec() {
                            out.extend(corner.to_vec());
                        }
                        out
                    })
                    .flatten()
                    .collect::<Vec<f32>>(),
            )?;
            corners.dimensions = vec![3, 4, self.force_platforms.len() as u8];
            bytes.extend(corners.write(
                processor,
                "CORNERS".to_string(),
                group_names_to_ids["FORCE_PLATFORM"],
                false,
            )?);
        }
        // "FORCE_PLATFORM", "ORIGIN"
        if self.force_platforms.len() > 0 {
            let mut origin = Parameter::floats(
                self.force_platforms
                    .iter()
                    .map(|x| x.origin.clone().to_vec())
                    .flatten()
                    .collect::<Vec<f32>>(),
            )?;
            origin.dimensions = vec![3, self.force_platforms.len() as u8];
            bytes.extend(origin.write(
                processor,
                "ORIGIN".to_string(),
                group_names_to_ids["FORCE_PLATFORM"],
                false,
            )?);
        }
        // "FORCE_PLATFORM", "CHANNEL"
        if self.force_platforms.len() > 0 {
            let mut channels = Parameter::integers(
                self.force_platforms
                    .iter()
                    .map(|x| {
                        x.channels
                            .clone()
                            .to_vec()
                            .iter()
                            .map(|y| y.clone() as i16)
                            .collect::<Vec<i16>>()
                    })
                    .flatten()
                    .collect::<Vec<i16>>(),
            )?;
            channels.dimensions = vec![8, self.force_platforms.len() as u8];
            bytes.extend(channels.write(
                processor,
                "CHANNEL".to_string(),
                group_names_to_ids["FORCE_PLATFORM"],
                false,
            )?);
        }
        // "FORCE_PLATFORM", "CAL_MATRIX"
        if self.force_platforms.len() > 0 {
            if self.force_platforms.iter().any(|x| x.cal_matrix.is_some()) {
                let mut cal_matrices = Parameter::floats(
                    self.force_platforms
                        .iter()
                        .map(|force_platform| {
                            if force_platform.cal_matrix.is_some() {
                                force_platform
                                    .cal_matrix
                                    .unwrap()
                                    .to_vec()
                                    .iter()
                                    .map(|x| {
                                        x.to_vec()
                                            .iter()
                                            .map(|y| y.clone() as f32)
                                            .collect::<Vec<f32>>()
                                    })
                                    .flatten()
                                    .collect::<Vec<f32>>()
                            } else {
                                let mut temp: Vec<f32> = Vec::new();
                                for _ in 0..36 {
                                    temp.push(0.0);
                                }
                                temp
                            }
                        })
                        .flatten()
                        .collect::<Vec<f32>>(),
                )?;
                cal_matrices.dimensions = vec![6, 6, self.force_platforms.len() as u8];
                bytes.extend(cal_matrices.write(
                    processor,
                    "CAL_MATRIX".to_string(),
                    group_names_to_ids["FORCE_PLATFORM"],
                    false,
                )?);
            }
        }
        // "FORCE_PLATFORM", "ZERO"
        bytes.extend(
            Parameter::integers(self.zero.to_vec().iter().map(|x| *x as i16).collect())?.write(
                processor,
                "ZERO".to_string(),
                group_names_to_ids["FORCE_PLATFORM"],
                false,
            )?,
        );
        // "FORCE_PLATFORM", "TYPE"
        if self.force_platforms.len() > 0 {
            bytes.extend(
                Parameter::integers(
                    self.force_platforms
                        .iter()
                        .map(|x| match x.plate_type {
                            ForcePlatformType::Type1 => 1,
                            ForcePlatformType::Type2 => 2,
                            ForcePlatformType::Type3 => 3,
                            ForcePlatformType::Type4 => 4,
                        })
                        .collect::<Vec<i16>>(),
                )?
                .write(
                    processor,
                    "TYPE".to_string(),
                    group_names_to_ids["FORCE_PLATFORM"],
                    false,
                )?,
            );
        }
        Ok(bytes)
    }

    pub(crate) fn force_from_analog(
        &self,
        analog: [f32; 8],
        force_platform: usize,
    ) -> Option<[f32; 3]> {
        if force_platform < self.force_platforms.len() {
            Some(
                self.force_platforms[force_platform]
                    .plate_type
                    .force_from_analog(analog),
            )
        } else {
            None
        }
    }

    pub(crate) fn center_of_pressure_from_analog(
        &self,
        analog: [f32; 8],
        force_platform: usize,
    ) -> Option<[f32; 2]> {
        if force_platform < self.force_platforms.len() {
            Some(
                self.force_platforms[force_platform]
                    .plate_type
                    .center_of_pressure_from_analog(
                        analog,
                        self.force_platforms[force_platform].origin.clone(),
                        self.force_platforms[force_platform].corners.clone(),
                    ),
            )
        } else {
            None
        }
    }

    pub fn origin(&self, force_platform: usize) -> Option<&ForcePlatformOrigin> {
        if force_platform < self.force_platforms.len() {
            Some(&self.force_platforms[force_platform].origin)
        } else {
            None
        }
    }
}

#[derive(Debug, Clone, PartialEq, Default)]
pub enum ForcePlatformType {
    Type1,
    #[default]
    Type2,
    Type3,
    Type4,
}

impl ForcePlatformType {
    fn from_parameters(
        parameters: &mut Parameters,
        used: u16,
    ) -> Result<Vec<ForcePlatformType>, C3dParseError> {
        let force_platform_type: Vec<i16> = parameters
            .remove_or_err("FORCE_PLATFORM", "TYPE")?
            .as_ref()
            .try_into()?;
        let force_platform_type = force_platform_type
            .iter()
            .map(|x| match x {
                1 => Ok(ForcePlatformType::Type1),
                2 => Ok(ForcePlatformType::Type2),
                3 => Ok(ForcePlatformType::Type3),
                4 => Ok(ForcePlatformType::Type4),
                _ => Err(C3dParseError::InvalidParameterFormat(x.to_string())),
            })
            .collect::<Result<Vec<ForcePlatformType>, C3dParseError>>()?;
        if force_platform_type.len() != used as usize {
            return Err(C3dParseError::InvalidParameterFormat(
                "FORCE_PLATFORM:TYPE".to_string(),
            ));
        }
        Ok(force_platform_type)
    }

    fn force_from_analog(&self, analog: [f32; 8]) -> [f32; 3] {
        match self {
            ForcePlatformType::Type3 => {
                return [
                    analog[0] + analog[1],
                    analog[2] + analog[3],
                    analog[4] + analog[5] + analog[6] + analog[7],
                ];
            }
            _ => {
                return [analog[0], analog[1], analog[2]];
            }
        }
    }

    fn center_of_pressure_from_analog(
        &self,
        analog: [f32; 8],
        origin: ForcePlatformOrigin,
        corners: ForcePlatformCorners,
    ) -> [f32; 2] {
        match self {
            ForcePlatformType::Type1 => [analog[3], analog[4]],
            ForcePlatformType::Type3 => {
                [(analog[0] + analog[1]) / 2., (analog[2] + analog[3]) / 2.]
            }
            _ => {
                let origin = origin.origin;
                let height = corners[0][2] - origin[2];
                let x = (-height * analog[0] - analog[4]) / analog[2];
                let y = (-height * analog[1] - analog[3]) / analog[2];
                let x = -x;
                let y = -y;
                [x, y]
            }
        }
    }
}

#[derive(Debug, Clone, PartialEq, Default)]
pub struct ForcePlatformCorners {
    corners: [[f32; 3]; 4],
}

impl Deref for ForcePlatformCorners {
    type Target = [[f32; 3]; 4];

    fn deref(&self) -> &Self::Target {
        &self.corners
    }
}

impl DerefMut for ForcePlatformCorners {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.corners
    }
}

impl Index<usize> for ForcePlatformCorners {
    type Output = [f32; 3];

    fn index(&self, index: usize) -> &Self::Output {
        &self.corners[index]
    }
}

impl IndexMut<usize> for ForcePlatformCorners {
    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
        &mut self.corners[index]
    }
}

impl ForcePlatformCorners {
    pub fn new() -> Self {
        ForcePlatformCorners::default()
    }

    pub(crate) fn from_parameters(
        parameters: &mut Parameters,
        used: u16,
    ) -> Result<Vec<Self>, C3dParseError> {
        let mut corners = Vec::new();
        let parameter = parameters.remove_or_err("FORCE_PLATFORM", "CORNERS")?;
        match &parameter.data {
            ParameterData::Float(data) => {
                let dimensions: Vec<usize> =
                    parameter.dimensions.iter().map(|&x| x as usize).collect();
                if (dimensions.len() == 3 || dimensions.len() == 2)
                    && dimensions[1] == 4
                    && dimensions[0] == 3
                {
                    let num_plates = match dimensions.len() {
                        3 => dimensions[2],
                        2 => 1,
                        _ => Err(C3dParseError::InvalidData(
                            parameter.clone(),
                            "FORCE_PLATFORM_CORNERS".to_string(),
                        ))?,
                    };
                    for i in 0..num_plates {
                        let mut corner = [[0.0; 3]; 4];
                        for j in 0..4 {
                            let x = data[i * (dimensions[1] * dimensions[0]) + j * dimensions[0]];
                            let y =
                                data[i * (dimensions[1] * dimensions[0]) + j * dimensions[0] + 1];
                            let z =
                                data[i * (dimensions[1] * dimensions[0]) + j * dimensions[0] + 2];
                            corner[j] = [x, y, z];
                        }
                        corners.push(corner);
                    }
                } else {
                    return Err(C3dParseError::InvalidData(
                        parameter.clone(),
                        "FORCE_PLATFORM_CORNERS".to_string(),
                    ));
                }
            }
            _ => {
                return Err(C3dParseError::InvalidData(
                    parameter.clone(),
                    "FORCE_PLATFORM_CORNERS".to_string(),
                ));
            }
        }
        if corners.len() != used as usize {
            return Err(C3dParseError::InvalidData(
                parameter.clone(),
                "FORCE_PLATFORM_CORNERS".to_string(),
            ));
        }
        Ok(corners
            .iter()
            .map(|x| ForcePlatformCorners { corners: *x })
            .collect())
    }
}

#[derive(Debug, Clone, PartialEq, Default)]
pub struct ForcePlatformOrigin {
    origin: [f32; 3],
}

impl Deref for ForcePlatformOrigin {
    type Target = [f32; 3];

    fn deref(&self) -> &Self::Target {
        &self.origin
    }
}

impl DerefMut for ForcePlatformOrigin {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.origin
    }
}

impl ForcePlatformOrigin {
    pub fn new() -> Self {
        ForcePlatformOrigin::default()
    }

    pub(crate) fn from_parameters(
        parameters: &mut Parameters,
        used: u16,
    ) -> Result<Vec<Self>, C3dParseError> {
        let mut origin = Vec::new();
        let parameter = parameters.remove_or_err("FORCE_PLATFORM", "ORIGIN")?;
        match &parameter.data {
            ParameterData::Float(data) => {
                let dimensions: Vec<usize> =
                    parameter.dimensions.iter().map(|&x| x as usize).collect();
                if (dimensions.len() == 2 || dimensions.len() == 1) && dimensions[0] == 3 {
                    let num_plates = match dimensions.len() {
                        2 => dimensions[1],
                        1 => 1,
                        _ => unreachable!(),
                    };
                    for i in 0..num_plates {
                        let mut origin_point = [0.0; 3];
                        for j in 0..dimensions[0] {
                            origin_point[j] = data[i * dimensions[0] + j];
                        }
                        origin.push(origin_point);
                    }
                } else {
                    return Err(C3dParseError::InvalidData(
                        parameter.clone(),
                        "FORCE_PLATFORM_ORIGIN".to_string(),
                    ));
                }
            }
            _ => {
                return Err(C3dParseError::InvalidData(
                    parameter.clone(),
                    "FORCE_PLATFORM_ORIGIN".to_string(),
                ));
            }
        }
        if origin.len() != used as usize {
            return Err(C3dParseError::InvalidData(
                parameter.clone(),
                "FORCE_PLATFORM_ORIGIN".to_string(),
            ));
        }
        Ok(origin
            .iter()
            .map(|x| ForcePlatformOrigin {
                origin: [x[0], x[1], x[2]],
            })
            .collect())
    }
}

fn get_channels(
    parameters: &mut Parameters,
    used: u16,
    contains_type_3: bool,
) -> Result<Vec<[u8; 8]>, C3dParseError> {
    let channel_parameter = parameters.remove_or_err("FORCE_PLATFORM", "CHANNEL");
    let parameter = channel_parameter.unwrap();
    match &parameter.data {
        ParameterData::Integer(data) => {
            let dimensions: Vec<usize> = parameter.dimensions.iter().map(|&x| x as usize).collect();
            if dimensions.len() == 2 || dimensions.len() == 1 {
                if (dimensions.len() == 1 && used != 1)
                    || (dimensions.len() == 2 && dimensions[1] != used as usize)
                {
                    return Err(C3dParseError::InvalidData(
                        parameter.clone(),
                        "FORCE_PLATFORM_CHANNEL".to_string(),
                    ));
                }
                if dimensions[0] == 8 {
                    let mut array = Vec::new();
                    for i in 0..used as usize {
                        let mut channels = [0; 8];
                        for j in 0..8 {
                            channels[j] = data[i * 8 + j] as u8;
                        }
                        array.push(channels);
                    }
                    Ok(array)
                } else if dimensions[0] == 6 && !contains_type_3 {
                    let mut array = Vec::new();
                    for i in 0..used as usize {
                        let mut channels = [0; 8];
                        for j in 0..6 {
                            channels[j] = data[i * 6 + j] as u8;
                        }
                        array.push(channels);
                    }
                    Ok(array)
                } else {
                    Err(C3dParseError::InvalidData(
                        parameter.clone(),
                        "FORCE_PLATFORM_CHANNEL".to_string(),
                    ))
                }
            } else {
                Err(C3dParseError::InvalidData(
                    parameter.clone(),
                    "FORCE_PLATFORM_CHANNEL".to_string(),
                ))
            }
        }
        _ => Err(C3dParseError::InvalidData(
            parameter.clone(),
            "FORCE_PLATFORM_CHANNEL".to_string(),
        )),
    }
}

fn get_cal_matrix_vector(
    parameters: &mut Parameters,
    plate_type: &Vec<ForcePlatformType>,
) -> Result<Vec<Option<[[f32; 6]; 6]>>, C3dParseError> {
    let parameter = parameters.remove("FORCE_PLATFORM", "CAL_MATRIX");
    if parameter.is_none() {
        return Ok(vec![None; plate_type.len()]);
    }
    let num_type_4 = plate_type
        .iter()
        .filter(|x| **x == ForcePlatformType::Type4)
        .count();
    let parameter = parameter.unwrap();
    let cal_matrices = match &parameter.data {
        ParameterData::Float(data) => {
            let dimensions: Vec<usize> = parameter.dimensions.iter().map(|&x| x as usize).collect();
            if dimensions.len() == 3 || (dimensions.len() == 2 && data.len() == 36) {
                let mut array = Vec::new();
                if data.len() < 36 * num_type_4 {
                    return Err(C3dParseError::InvalidData(
                        parameter.clone(),
                        "FORCE_PLATFORM_CAL_MATRIX".to_string(),
                    ));
                }
                for platform in 0..data.len() / 36 {
                    let mut matrix = [[0.0; 6]; 6];
                    for i in 0..6 {
                        for j in 0..6 {
                            matrix[i][j] = data[platform * 36 + i * 6 + j];
                        }
                    }
                    array.push(matrix);
                }
                Some(array)
            } else {
                return Err(C3dParseError::InvalidData(
                    parameter.clone(),
                    "FORCE_PLATFORM_CAL_MATRIX".to_string(),
                ));
            }
        }
        _ => {
            return Err(C3dParseError::InvalidData(
                parameter.clone(),
                "FORCE_PLATFORM_CAL_MATRIX".to_string(),
            ))
        }
    };
    let cal_matrices = cal_matrices.unwrap();
    let mut cal_matrix_vec: Vec<Option<[[f32; 6]; 6]>> = vec![None; plate_type.len()];
    let mut count = 0;
    for i in 0..plate_type.len() {
        if plate_type[i] == ForcePlatformType::Type4 {
            cal_matrix_vec.push(Some(cal_matrices[count]));
            count += 1;
        }
    }
    Ok(cal_matrix_vec)
}