Structural deformable models
Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
Edge Class Reference

Implements an Edge with spring functionality. More...

#include <Edge.h>

Collaboration diagram for Edge:
Collaboration graph
[legend]

Public Member Functions

 Edge (const Edge &rhs)
 
 Edge (int _from, int _to, std::vector< Node > &_nodes, const ParticleParam *phys=&ParticleParam::global, int _index=-1)
 
 Edge (int _from, int _to, std::vector< Node > &_nodes, float restlength, float spring_k=1, int _index=-1)
 
virtual ~Edge ()
 
void setNodesList (std::vector< Node > &nodes)
 
Edgeoperator= (const Edge &rhs)
 
const Point dir () const
 
const Point idir () const
 
float length2 () const
 
float length () const
 
float lengthRatio () const
 
float adaptRestLength ()
 
float adaptRestLength (float ratio)
 
float getAngle () const
 
float adaptAngle ()
 
NodefromNode ()
 
NodetoNode ()
 
const NodefromNode () const
 
const NodetoNode () const
 
dword getSensorValue (float &sum, dword &nsamples) const
 

Public Attributes

int from
 
int to
 
float xangle
 
float cxangle
 
std::vector< Node > * nodes
 
float restlength
 
float springconstant
 spring constant More...
 
float dampingconstant
 damping constant More...
 
int edgesensor
 0-none, >0-use from sensor n times, <0 use to sensor More...
 

Protected Attributes

int index
 index in the model (Model.edges) More...
 

Friends

class Model
 
std::ostream & operator<< (std::ostream &os, const Edge &p)
 

Detailed Description

Implements an Edge with spring functionality.

Definition at line 14 of file Edge.h.

Constructor & Destructor Documentation

Edge::Edge ( const Edge rhs)
inline

Definition at line 25 of file Edge.h.

References operator=().

26  {
27  operator=(rhs);
28  }
Edge & operator=(const Edge &rhs)
Definition: Edge.h:60
Edge::Edge ( int  _from,
int  _to,
std::vector< Node > &  _nodes,
const ParticleParam phys = &ParticleParam::global,
int  _index = -1 
)
inline

Definition at line 29 of file Edge.h.

References adaptRestLength(), ParticleParam::damping, dampingconstant, edgesensor, from, index, nodes, Model::phys, ParticleParam::springconst, springconstant, and to.

32  {
33  from = _from;
34  to = _to;
35  nodes = &_nodes;
38  dampingconstant = phys->damping;
39  edgesensor = 0;
40  index = _index;
41  }
int index
index in the model (Model.edges)
Definition: Edge.h:141
float adaptRestLength()
Definition: Edge.h:95
float dampingconstant
damping constant
Definition: Edge.h:136
int edgesensor
0-none, >0-use from sensor n times, <0 use to sensor
Definition: Edge.h:137
float springconstant
spring constant
Definition: Edge.h:134
int from
Definition: Edge.h:128
float damping
Definition: PartParam.h:65
int to
Definition: Edge.h:128
std::vector< Node > * nodes
Definition: Edge.h:131
float springconst
Definition: PartParam.h:64
Edge::Edge ( int  _from,
int  _to,
std::vector< Node > &  _nodes,
float  restlength,
float  spring_k = 1,
int  _index = -1 
)
inline

Definition at line 42 of file Edge.h.

References edgesensor, from, index, nodes, restlength, springconstant, and to.

44  {
45  from = _from;
46  to = _to;
47  nodes = &_nodes;
48  this->restlength = restlength;
49  this->springconstant = spring_k;
50  edgesensor = 0;
51  this->index = _index;
52  }
int index
index in the model (Model.edges)
Definition: Edge.h:141
int edgesensor
0-none, >0-use from sensor n times, <0 use to sensor
Definition: Edge.h:137
float springconstant
spring constant
Definition: Edge.h:134
int from
Definition: Edge.h:128
int to
Definition: Edge.h:128
float restlength
Definition: Edge.h:132
std::vector< Node > * nodes
Definition: Edge.h:131
virtual Edge::~Edge ( )
inlinevirtual

Definition at line 54 of file Edge.h.

54 {}

Member Function Documentation

float Edge::adaptAngle ( )
inline

Definition at line 105 of file Edge.h.

References getAngle(), and xangle.

105  {
106  return xangle = getAngle();
107  }
float xangle
Definition: Edge.h:129
float getAngle() const
Definition: Edge.h:102
float Edge::adaptRestLength ( )
inline

Definition at line 95 of file Edge.h.

References length(), and restlength.

Referenced by Edge(), and Brain::triggerTest().

95  {
96  return restlength = length();
97  }
float length() const
Definition: Edge.h:87
float restlength
Definition: Edge.h:132
float Edge::adaptRestLength ( float  ratio)
inline

Definition at line 99 of file Edge.h.

References length(), and restlength.

99  {
100  return restlength -= (restlength-length())*ratio;
101  }
float length() const
Definition: Edge.h:87
float restlength
Definition: Edge.h:132
const Point Edge::dir ( ) const
inline

Definition at line 73 of file Edge.h.

References from, fromNode(), to, and toNode().

Referenced by getAngle(), and length2().

73  {
74  if(from==-1 || to==-1) return Point();
75  return toNode()-fromNode();
76  }
Point2D Point
Definition: Point.h:251
Node & fromNode()
Definition: Edge.h:121
int from
Definition: Edge.h:128
int to
Definition: Edge.h:128
Node & toNode()
Definition: Edge.h:122
Node& Edge::fromNode ( )
inline

Definition at line 121 of file Edge.h.

References from, and nodes.

Referenced by Model::addTorque(), dir(), getSensorValue(), and idir().

121 { return (*nodes)[from]; }
int from
Definition: Edge.h:128
std::vector< Node > * nodes
Definition: Edge.h:131
const Node& Edge::fromNode ( ) const
inline

Definition at line 123 of file Edge.h.

References from, and nodes.

123 { return (*nodes)[from]; }
int from
Definition: Edge.h:128
std::vector< Node > * nodes
Definition: Edge.h:131
float Edge::getAngle ( ) const
inline

Definition at line 102 of file Edge.h.

References Point2D::angleX(), and dir().

Referenced by adaptAngle().

102  {
103  return dir().angleX();
104  }
float angleX() const
Definition: Point.h:123
const Point dir() const
Definition: Edge.h:73
dword Edge::getSensorValue ( float &  sum,
dword nsamples 
) const
inline

Definition at line 144 of file Edge.h.

References edgesensor, from, fromNode(), Node::sensor, to, and toNode().

Referenced by toNode().

145 {
146  if(!edgesensor) return 0;
147  const Node& from = fromNode();
148  const Node& to = toNode();
149  sensor_cptr sensor = (edgesensor > 0) ? from.sensor : to.sensor;
150  if(!sensor) return 0;
151  dword ntimes = edgesensor > 0 ? dword(edgesensor) : dword(-edgesensor);
152  Point x(from);
153  Point xinc(to); xinc -= from; xinc /= float(ntimes+1);
154  x += xinc;
155  for(dword i=0; i<ntimes; i++, x+=xinc) {
156  sum += sensor->getWeightedValue((int)x.x, (int)x.y);
157  }
158  nsamples += ntimes;
159  return ntimes;
160 }
Implements a Node used by Model and Edge.
Definition: Node.h:13
int edgesensor
0-none, >0-use from sensor n times, <0 use to sensor
Definition: Edge.h:137
sensor_cptr sensor
Definition: Node.h:43
Node & fromNode()
Definition: Edge.h:121
DMatrix< T > sum(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:59
int from
Definition: Edge.h:128
int to
Definition: Edge.h:128
unsigned long dword
Definition: simpletypes.h:6
std::shared_ptr< const Sensor > sensor_cptr
Definition: types_fwd.h:17
Definition: Point.h:16
Node & toNode()
Definition: Edge.h:122
const Point Edge::idir ( ) const
inline

Definition at line 77 of file Edge.h.

References from, fromNode(), to, and toNode().

77  {
78  if(from==-1 || to==-1) return Point();
79  return fromNode()-toNode();
80  }
Point2D Point
Definition: Point.h:251
Node & fromNode()
Definition: Edge.h:121
int from
Definition: Edge.h:128
int to
Definition: Edge.h:128
Node & toNode()
Definition: Edge.h:122
float Edge::length ( ) const
inline

Definition at line 87 of file Edge.h.

References length2(), and dmutil::sqrt().

Referenced by adaptRestLength(), and lengthRatio().

87  {
88  return (float)sqrt(length2());
89  }
float length2() const
Definition: Edge.h:82
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Edge::length2 ( ) const
inline

Definition at line 82 of file Edge.h.

References dir(), from, Point2D::norm2(), and to.

Referenced by length().

82  {
83  if(from==-1 || to==-1) return 0;
84  return dir().norm2();
85  }
const Point dir() const
Definition: Edge.h:73
int from
Definition: Edge.h:128
int to
Definition: Edge.h:128
float norm2() const
returns squared 2-norm
Definition: Point.h:165
float Edge::lengthRatio ( ) const
inline

Definition at line 91 of file Edge.h.

References length(), and restlength.

Referenced by MStructure::buildMasterModel().

91  {
92  return length()/restlength;
93  }
float length() const
Definition: Edge.h:87
float restlength
Definition: Edge.h:132
Edge& Edge::operator= ( const Edge rhs)
inline

Definition at line 60 of file Edge.h.

References dampingconstant, edgesensor, from, index, nodes, restlength, springconstant, and to.

Referenced by Edge().

60  {
61  if(&rhs == this) return *this;
62  from = rhs.from;
63  to = rhs.to;
64  nodes = rhs.nodes;
65  restlength = rhs.restlength;
68  edgesensor = rhs.edgesensor;
69  index = rhs.index;
70  return *this;
71  }
int index
index in the model (Model.edges)
Definition: Edge.h:141
float dampingconstant
damping constant
Definition: Edge.h:136
int edgesensor
0-none, >0-use from sensor n times, <0 use to sensor
Definition: Edge.h:137
float springconstant
spring constant
Definition: Edge.h:134
int from
Definition: Edge.h:128
int to
Definition: Edge.h:128
float restlength
Definition: Edge.h:132
std::vector< Node > * nodes
Definition: Edge.h:131
void Edge::setNodesList ( std::vector< Node > &  nodes)
inline

Definition at line 56 of file Edge.h.

References nodes.

56  {
57  this->nodes = &nodes;
58  }
std::vector< Node > * nodes
Definition: Edge.h:131
Node& Edge::toNode ( )
inline

Definition at line 122 of file Edge.h.

References nodes, and to.

Referenced by Model::addTorque(), dir(), getSensorValue(), and idir().

122 { return (*nodes)[to]; }
int to
Definition: Edge.h:128
std::vector< Node > * nodes
Definition: Edge.h:131
const Node& Edge::toNode ( ) const
inline

Definition at line 124 of file Edge.h.

References getSensorValue(), nodes, dmutil::sum(), and to.

124 { return (*nodes)[to]; }
int to
Definition: Edge.h:128
std::vector< Node > * nodes
Definition: Edge.h:131

Friends And Related Function Documentation

friend class Model
friend

Definition at line 15 of file Edge.h.

std::ostream& operator<< ( std::ostream &  os,
const Edge p 
)
friend

Definition at line 108 of file Edge.h.

108  {
109  os << "e " << p.from+1 << " " << p.to+1;
111  os << " sc " << p.springconstant;
113  os << " dc " << p.dampingconstant;
114  if(p.length() != p.restlength) os << " rl " << p.restlength;
115  if(p.edgesensor>0) os << " es f " << p.edgesensor;
116  if(p.edgesensor<0) os << " es t " << -p.edgesensor;
117  os << std::endl;
118  return os;
119  }
static ParticleParam global
Definition: PartParam.h:72
float dampingconstant
damping constant
Definition: Edge.h:136
int edgesensor
0-none, >0-use from sensor n times, <0 use to sensor
Definition: Edge.h:137
float springconstant
spring constant
Definition: Edge.h:134
int from
Definition: Edge.h:128
float length() const
Definition: Edge.h:87
float damping
Definition: PartParam.h:65
int to
Definition: Edge.h:128
float restlength
Definition: Edge.h:132
float springconst
Definition: PartParam.h:64

Member Data Documentation

float Edge::cxangle

Definition at line 130 of file Edge.h.

float Edge::dampingconstant

damping constant

Definition at line 136 of file Edge.h.

Referenced by Edge(), operator=(), and Model::readEdge().

int Edge::edgesensor

0-none, >0-use from sensor n times, <0 use to sensor

Definition at line 137 of file Edge.h.

Referenced by Edge(), getSensorValue(), operator=(), and Model::readEdge().

int Edge::from

Definition at line 128 of file Edge.h.

Referenced by dir(), Edge(), fromNode(), getSensorValue(), idir(), length2(), operator=(), and Brain::triggerTest().

int Edge::index
protected

index in the model (Model.edges)

Definition at line 141 of file Edge.h.

Referenced by Edge(), and operator=().

std::vector<Node>* Edge::nodes

Definition at line 131 of file Edge.h.

Referenced by Edge(), fromNode(), operator=(), setNodesList(), and toNode().

float Edge::restlength
float Edge::springconstant

spring constant

Definition at line 134 of file Edge.h.

Referenced by MStructure::buildMasterModel(), Edge(), operator=(), Model::readEdge(), and Brain::triggerTest().

int Edge::to

Definition at line 128 of file Edge.h.

Referenced by dir(), Edge(), getSensorValue(), idir(), length2(), operator=(), toNode(), and Brain::triggerTest().

float Edge::xangle

Definition at line 129 of file Edge.h.

Referenced by adaptAngle().


The documentation for this class was generated from the following file: