GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/node-rod.cpp Lines: 1 54 1.9 %
Date: 2020-05-14 11:23:33 Branches: 2 114 1.8 %

Line Branch Exec Source
1
//
2
//  node-rod.cpp
3
//  gepetto-viewer
4
//
5
//  Created by Pierre Fernbach in may 2015.
6
//  Copyright (c) 2015 LAAS-CNRS. All rights reserved.
7
//
8
#include <gepetto/viewer/node-rod.h>
9
10
#include <sstream>
11
12
namespace gepetto {
13
namespace viewer {
14
15
  // ---- protected constructor ---- //
16
17
  NodeRod::NodeRod (const std::string& name, osgVector4 color, float radius, float totalLength,size_t maxCapsule):Node(name), list_of_capsule_()
18
    {
19
        radius_ = radius;
20
        totalLength_ = totalLength;
21
        color_ = osgVector4(color);
22
        maxCapsule_=maxCapsule;
23
24
        osgVector3 zero;
25
        // Z -> -X
26
        osgQuat y_90(M_PI/2,osgVector3(0,1,0));
27
        for (size_t i = 0; i< maxCapsule ; i++){
28
            std::stringstream nameCap;
29
            nameCap << name << "_cap"<<i;
30
            LeafNodeCapsulePtr_t cap = LeafNodeCapsule::create(nameCap.str(),radius,(totalLength/((float)maxCapsule)),color);
31
            cap->setStaticTransform (zero, y_90);
32
            list_of_capsule_.push_back(cap);
33
            this->asQueue()->addChild(cap->asGroup());
34
        }
35
    }
36
37
38
  NodeRod::NodeRod (const NodeRod& other):
39
      Node (other)
40
  {
41
      size_t i;
42
      radius_ = other.radius();
43
      totalLength_ = other.totalLength();
44
      color_ = other.color();
45
      maxCapsule_=other.maxCapsule();
46
47
      for(i = 0 ; i < (size_t) other.maxCapsule() ; i++){
48
          LeafNodeCapsulePtr_t cap = LeafNodeCapsule::createCopy(other.getCapsule(i));
49
          list_of_capsule_.push_back(cap);
50
        }
51
  }
52
53
    void NodeRod::initWeakPtr(NodeRodWeakPtr other_weak_ptr)
54
    {
55
        weak_ptr_ = other_weak_ptr;
56
    }
57
58
59
60
61
    //------- public :------- //
62
63
64
    NodeRodPtr_t NodeRod::create(const std::string& name,osgVector4 color, float radius, float totalLength,short maxCapsule)
65
    {
66
        NodeRodPtr_t shared_ptr(new NodeRod(name,color,radius,totalLength,maxCapsule));
67
68
        // Add reference to itself
69
        shared_ptr->initWeakPtr(shared_ptr);
70
71
        return shared_ptr;
72
    }
73
74
    NodeRodPtr_t NodeRod::createCopy(NodeRodPtr_t other)
75
    {
76
        NodeRodPtr_t shared_ptr(new NodeRod(*other));
77
78
        // Add reference to itself
79
        shared_ptr->initWeakPtr(shared_ptr);
80
81
        return shared_ptr;
82
    }
83
84
85
    NodeRodPtr_t NodeRod::self(void) const
86
    {
87
        return weak_ptr_.lock();
88
    }
89
90
91
92
93
    std::string NodeRod::getCapsuleName(size_t i)
94
    {
95
        return list_of_capsule_.at(i)->getID();
96
    }
97
98
    LeafNodeCapsulePtr_t NodeRod::getCapsule(size_t i) const{
99
      return list_of_capsule_.at(i);
100
    }
101
102
    /**
103
      Applyconfiguration to all the capsules of the rod,
104
      params is a sequence of maxCapsule parameter, size 8 (length + pos + quat), or size 7 (pos + quat)
105
      quat : (w,x,y,z)
106
      */
107
    void NodeRod::applyConfiguration(std::vector<std::vector<value_type> > params){
108
      if(params.size() != (size_t) maxCapsule_)
109
        std::cout<<"Error in rod Applyconfiguration : the size of the sequence must be the same as the number of capsules"<<std::endl;
110
111
      for(size_t i = 0; i < params.size(); i++) {
112
          if(params.at(i).size() == 8){
113
            list_of_capsule_.at(i)->setHeight(params.at(i)[0]);
114
            ::osg::Quat quat = ::osg::Quat(params.at(i)[5],params.at(i)[6],params.at(i)[7],params.at(i)[4]);
115
            ::osg::Vec3f pos = ::osg::Vec3f(params.at(i)[1],params.at(i)[2],params.at(i)[3]);
116
            list_of_capsule_.at(i)->applyConfiguration(pos,quat);
117
          }
118
          else if (params.at(i).size() == 7){
119
              ::osg::Quat quat = ::osg::Quat(params.at(i)[4],params.at(i)[5],params.at(i)[6],params.at(i)[3]);
120
              ::osg::Vec3f pos = ::osg::Vec3f(params.at(i)[0],params.at(i)[1],params.at(i)[2]);
121
              list_of_capsule_.at(i)->applyConfiguration(pos,quat);
122
123
            }else
124
            std::cout<<"Parameter must have 7 or 8 elements"<<std::endl;
125
      }
126
127
    }
128
129
130
} /* namespace viewer */
131

3
} // namespace gepetto
132