GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/transform-writer.cc Lines: 1 31 3.2 %
Date: 2020-05-14 11:23:33 Branches: 2 6 33.3 %

Line Branch Exec Source
1
// Copyright (c) 2015, Joseph Mirabel
2
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3
//
4
// This file is part of gepetto-viewer.
5
// gepetto-viewer is free software: you can redistribute it
6
// and/or modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation, either version
8
// 3 of the License, or (at your option) any later version.
9
//
10
// gepetto-viewer is distributed in the hope that it will be
11
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
// General Lesser Public License for more details.  You should have
14
// received a copy of the GNU Lesser General Public License along with
15
// gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16
17
#include <gepetto/viewer/transform-writer.h>
18
#include <gepetto/viewer/node.h>
19
20
namespace gepetto {
21
namespace viewer {
22
  namespace {
23
    const char indent[] = "  ";
24
  }
25
26
  void TransformWriter::newFrame ()
27
  {
28
    writeNewFrame ();
29
    frameCount_++;
30
  }
31
32
  void BasicTransformWriter::writeNewFrame ()
33
  {
34
    file_ << "FRAME=" << frameCount_ << "\n";
35
  }
36
37
  void BasicTransformWriter::writeTransform (const char* objName,
38
      const osgVector3& vec, const osgQuat& quat)
39
  {
40
    file_ << objName << "=" <<
41
      vec[0] << ", " <<
42
      vec[1] << ", " <<
43
      vec[2] << ", " <<
44
      quat.w() << ", " <<
45
      quat.x() << ", " <<
46
      quat.y() << ", " <<
47
      quat.z() << "\n";
48
  }
49
50
  void YamlTransformWriter::writeNewFrame ()
51
  {
52
    file_ << "frame_" << frameCount_ << ":\n";
53
  }
54
55
  void YamlTransformWriter::writeTransform (const char* objName,
56
      const osgVector3& vec, const osgQuat& quat)
57
  {
58
    file_ << indent << objName << ": ["
59
      << vec[0] << ", " << vec[1] << ", " << vec[2] << ", " <<
60
      quat.w() << ", " << quat.x() << ", " << quat.y() << ", " <<
61
      quat.z() << "]\n";
62
  }
63
64
  void TransformWriterVisitor::apply (Node& node)
65
  {
66
    const Configuration& cfg = node.getGlobalTransform ();
67
    writer_->writeTransform (node.getID ().c_str(), cfg.position, cfg.quat);
68
    traverse (node);
69
  }
70
71
  void TransformWriterVisitor::captureFrame (Node& node)
72
  {
73
    writer_->openFile ();
74
    writer_->newFrame ();
75
    apply (node);
76
    writer_->closeFile ();
77
  }
78
79
} // namespace viewer
80

3
} // namespace gepetto