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

Implements a Node used by Model and Edge. More...

#include <Node.h>

Inheritance diagram for Node:
Inheritance graph
[legend]
Collaboration diagram for Node:
Collaboration graph
[legend]

Public Types

enum  NodeState { ST_NONE =0, ST_HIGHLIGHT =1, ST_SELECT =2 }
 

Public Member Functions

 Node (const ParticleParam *phys=&ParticleParam::global)
 Default constructor. More...
 
 Node (const Node &rhs)
 Assignment constructor. More...
 
 Node (float _x, float _y, const ParticleParam *phys=&ParticleParam::global)
 Constructor. More...
 
virtual ~Node ()
 Destructor. More...
 
Nodeoperator= (const Node &rhs)
 Assignment operator. More...
 
NodesetPos (const Point &p)
 
int getIndex () const
 
void attachSensor (sensor_cptr _sensor)
 
void addSensorForce ()
 
void enableState (dword nstate)
 
void disableState (dword nstate=0xffffffff)
 
void toggleState (dword nstate)
 
bool hasState (dword nstate=0xffffffff) const
 
void draw () const
 
- Public Member Functions inherited from Point2D
 Point2D ()
 
 Point2D (const Point2D &rhs)
 
 Point2D (float _x, float _y)
 
 Point2D (const float *val)
 
virtual ~Point2D ()
 
Point2Doperator= (const Point2D &rhs)
 
Point2Doperator= (float rhs)
 
Point2Doperator= (const float *rhs)
 
Point2Doperator+= (const Point2D &rhs)
 
Point2Doperator-= (const Point2D &rhs)
 
Point2Doperator*= (const Point2D &rhs)
 
Point2Doperator*= (const float f)
 
Point2Doperator/= (const Point2D &rhs)
 
Point2Doperator/= (const float f)
 
float operator* (const Point2D &rhs) const
 
const Point2Dconst_times (const Point2D &rhs) const
 
Point2Dtimes (const Point2D &rhs)
 
float dot (const Point2D &rhs) const
 
float crossZ (const Point2D &rhs) const
 
float sinAngle (const Point2D &rhs) const
 
float angle (const Point2D &rhs=Point2D(1, 0)) const
 
float sinAngleX () const
 
float angleX () const
 
Point2D operator* (float rhs) const
 
Point2D operator+ (const Point2D &rhs) const
 
Point2D operator- (const Point2D &rhs) const
 
Point2D operator/ (const Point2D &rhs) const
 
Point2D operator/ (float rhs) const
 
float sum () const
 returns 1-norm More...
 
float norm2 () const
 returns squared 2-norm More...
 
float norm () const
 returns 2-norm aka length or absolute More...
 
float normalize ()
 normalizes the vector; returns old norm More...
 
bool clamp (float x0, float y0, float x1, float y1)
 
void glVertex () const
 Issue a glVertex2f call. More...
 
const Point2D flipOrtho () const
 
const Point2D copyNormalized () const
 
const Point2D rotate (float angle) const
 

Public Attributes

sensor_cptr sensor
 
std::string sensorID
 
float mass
 Mass. More...
 
- Public Attributes inherited from Point2D
float x
 
float y
 

Protected Attributes

Point v
 Velocity and Force. More...
 
Point f
 
Point ef
 extern force More...
 
int index
 Index in the list (Model.nodes) More...
 
float oangle
 
float cangle
 
float nedges
 
std::vector< int > edges
 
dword state
 

Friends

class Model
 
std::ostream & operator<< (std::ostream &os, const Node &n)
 output operator More...
 

Detailed Description

Implements a Node used by Model and Edge.

Definition at line 13 of file Node.h.

Member Enumeration Documentation

Enumerator
ST_NONE 
ST_HIGHLIGHT 
ST_SELECT 

Definition at line 16 of file Node.h.

Constructor & Destructor Documentation

Node::Node ( const ParticleParam phys = &ParticleParam::global)

Default constructor.

Definition at line 7 of file Node.cpp.

Referenced by Node().

8  : Point(0,0), sensor(getZeroSensor()),
9  mass(phys->mass), index(-1), state(ST_NONE)
10 {
11 }
float mass
Mass.
Definition: Node.h:48
sensor_ptr getZeroSensor()
Definition: Sensor.cpp:234
Point2D Point
Definition: Point.h:251
int index
Index in the list (Model.nodes)
Definition: Node.h:56
sensor_cptr sensor
Definition: Node.h:43
float mass
Definition: PartParam.h:66
dword state
Definition: Node.h:61
Node::Node ( const Node rhs)
inline

Assignment constructor.

Definition at line 21 of file Node.h.

References ParticleParam::global, Node(), operator=(), and Model::phys.

21 { operator=(rhs); }
Node & operator=(const Node &rhs)
Assignment operator.
Definition: Node.cpp:21
Node::Node ( float  _x,
float  _y,
const ParticleParam phys = &ParticleParam::global 
)

Constructor.

Definition at line 14 of file Node.cpp.

15  : Point(_x, _y), sensor(getZeroSensor()), mass(phys->mass),
16  index(-1), state(ST_NONE)
17 {
18 }
float mass
Mass.
Definition: Node.h:48
sensor_ptr getZeroSensor()
Definition: Sensor.cpp:234
Point2D Point
Definition: Point.h:251
int index
Index in the list (Model.nodes)
Definition: Node.h:56
sensor_cptr sensor
Definition: Node.h:43
float mass
Definition: PartParam.h:66
dword state
Definition: Node.h:61
virtual Node::~Node ( )
inlinevirtual

Destructor.

Definition at line 25 of file Node.h.

References operator=().

25 {};

Member Function Documentation

void Node::addSensorForce ( )

Definition at line 62 of file Node.cpp.

References f, sensor, Point2D::x, and Point2D::y.

Referenced by getIndex().

62  {
63  if(sensor) {
64  Point sf = sensor->getWeightedGradient((int)x,(int)y);
65  f += sf;
66  }
67 }
float y
Definition: Point.h:224
Point f
Definition: Node.h:52
sensor_cptr sensor
Definition: Node.h:43
Definition: Point.h:16
float x
Definition: Point.h:224
void Node::attachSensor ( sensor_cptr  _sensor)

Definition at line 50 of file Node.cpp.

References PPSensor::PP_DO, PPSensor::PP_DONT, sensor, sensorID, and Sensor::UPD_MINMAX.

Referenced by getIndex(), Model::readNode(), and Brain::triggerTest().

50  {
51  sensor = _sensor;
52  sensorID = sensor->getID();
53  if(!sensor->isUpdate(Sensor::UPD_MINMAX)) {
54  std::const_pointer_cast<Sensor>(sensor)->enableUpdate(Sensor::UPD_MINMAX);
55  std::const_pointer_cast<Sensor>(sensor)->setModified(Sensor::UPD_MINMAX);
56  }
57  std::shared_ptr<const PPSensor> pps = std::dynamic_pointer_cast<const PPSensor, const Sensor>(_sensor);
58  if(pps && pps->getPPState()==PPSensor::PP_DONT)
59  std::const_pointer_cast<PPSensor>(pps)->togglePP(PPSensor::PP_DO);
60 }
Definition: Sensor.h:21
sensor_cptr sensor
Definition: Node.h:43
std::string sensorID
Definition: Node.h:44
void Node::disableState ( dword  nstate = 0xffffffff)
inline

Definition at line 39 of file Node.h.

References state.

Referenced by Model::setHLNode(), and Brain::triggerTest().

39 { state &= ~nstate; }
dword state
Definition: Node.h:61
void Node::draw ( ) const

Definition at line 69 of file Node.cpp.

References hasState(), sensorID, sglBitmapStringOutlined(), ST_HIGHLIGHT, ST_SELECT, state, Point2D::x, and Point2D::y.

Referenced by hasState().

69  {
70  if(state) {
71  const int HLSIZE = 5;
72  if(hasState(ST_HIGHLIGHT)) {
73  glBegin(GL_QUADS); {
74  glColor4f(1,1,0,0.5);
75  glVertex2f(x-HLSIZE, y-HLSIZE);
76  glVertex2f(x-HLSIZE, y+HLSIZE);
77  glVertex2f(x+HLSIZE, y+HLSIZE);
78  glVertex2f(x+HLSIZE, y-HLSIZE);
79  } glEnd();
80  sglBitmapStringOutlined(sensorID.c_str(), (int)x, (int)y);
81  }
82  if(hasState(ST_SELECT)) {
83  glBegin(GL_LINE_STRIP); {
84  glColor4f(1,0,1,1);
85  glVertex2f(x-HLSIZE, y-HLSIZE);
86  glVertex2f(x-HLSIZE, y+HLSIZE);
87  glVertex2f(x+HLSIZE, y+HLSIZE);
88  glVertex2f(x+HLSIZE, y-HLSIZE);
89  glVertex2f(x-HLSIZE, y-HLSIZE);
90  } glEnd();
91  }
92  }
93 }
float y
Definition: Point.h:224
bool hasState(dword nstate=0xffffffff) const
Definition: Node.h:41
dword state
Definition: Node.h:61
std::string sensorID
Definition: Node.h:44
int sglBitmapStringOutlined(const char *msg, int x, int y, void *font=(void *) GLUT_BITMAP_8_BY_13)
Definition: glutils.h:22
float x
Definition: Point.h:224
void Node::enableState ( dword  nstate)
inline

Definition at line 38 of file Node.h.

References state.

Referenced by Model::setHLNode(), and Brain::triggerTest().

38 { state |= nstate; }
dword state
Definition: Node.h:61
int Node::getIndex ( ) const
inline
Returns
the index in Model.nodes array

Definition at line 33 of file Node.h.

References addSensorForce(), attachSensor(), index, and operator<<.

Referenced by Brain::doCommand().

33 { return index; }
int index
Index in the list (Model.nodes)
Definition: Node.h:56
bool Node::hasState ( dword  nstate = 0xffffffff) const
inline

Definition at line 41 of file Node.h.

References draw(), and state.

Referenced by draw().

41 { return state & nstate; }
dword state
Definition: Node.h:61
Node & Node::operator= ( const Node rhs)

Assignment operator.

Definition at line 21 of file Node.cpp.

References edges, ef, f, index, mass, oangle, Point2D::operator=(), sensor, sensorID, state, and v.

Referenced by Node(), and ~Node().

21  {
22  if(&rhs == this) return *this;
23  Point::operator=(rhs);
24  mass = rhs.mass;
25  f = rhs.f;
26  v = rhs.v;
27  index = rhs.index;
28  sensor = rhs.sensor;
29  edges = rhs.edges;
30  oangle = rhs.oangle;
31  sensorID = rhs.sensorID;
32  ef = 0.f;
33  state = rhs.state;
34  return *this;
35 }
std::vector< int > edges
Definition: Node.h:60
Point f
Definition: Node.h:52
float mass
Mass.
Definition: Node.h:48
Point ef
extern force
Definition: Node.h:54
Point2D & operator=(const Point2D &rhs)
Definition: Point.h:27
int index
Index in the list (Model.nodes)
Definition: Node.h:56
sensor_cptr sensor
Definition: Node.h:43
Point v
Velocity and Force.
Definition: Node.h:52
dword state
Definition: Node.h:61
std::string sensorID
Definition: Node.h:44
float oangle
Definition: Node.h:57
Node& Node::setPos ( const Point p)
inline

Definition at line 28 of file Node.h.

References Point2D::operator=().

Referenced by Brain::triggerTest().

28  {
30  return *this;
31  }
Point2D & operator=(const Point2D &rhs)
Definition: Point.h:27
void Node::toggleState ( dword  nstate)
inline

Definition at line 40 of file Node.h.

References state.

40 { state ^= nstate; }
dword state
Definition: Node.h:61

Friends And Related Function Documentation

friend class Model
friend

Definition at line 14 of file Node.h.

std::ostream& operator<< ( std::ostream &  os,
const Node n 
)
friend

output operator

Definition at line 38 of file Node.cpp.

Referenced by getIndex(), and operator<<().

38  {
39  os << "v ";
40  operator<<(os, Point(n));
41  if(n.sensor) {
42  os << " s " << n.sensor->getID();
43  }
45  os << " m " << n.mass;
46  os << endl;
47  return os;
48 }
static ParticleParam global
Definition: PartParam.h:72
float mass
Mass.
Definition: Node.h:48
Point2D Point
Definition: Point.h:251
sensor_cptr sensor
Definition: Node.h:43
float mass
Definition: PartParam.h:66
friend std::ostream & operator<<(std::ostream &os, const Node &n)
output operator
Definition: Node.cpp:38

Member Data Documentation

float Node::cangle
protected

Definition at line 58 of file Node.h.

std::vector<int> Node::edges
protected

Definition at line 60 of file Node.h.

Referenced by Model::getNodeAngle(), and operator=().

Point Node::ef
protected

extern force

Definition at line 54 of file Node.h.

Referenced by operator=().

Point Node::f
protected

Definition at line 52 of file Node.h.

Referenced by addSensorForce(), Model::addTorque(), and operator=().

int Node::index
protected

Index in the list (Model.nodes)

Definition at line 56 of file Node.h.

Referenced by Model::addNode(), getIndex(), and operator=().

float Node::mass

Mass.

Definition at line 48 of file Node.h.

Referenced by operator<<(), operator=(), and Model::readNode().

float Node::nedges
protected

Definition at line 59 of file Node.h.

float Node::oangle
protected

Definition at line 57 of file Node.h.

Referenced by operator=().

sensor_cptr Node::sensor

Definition at line 43 of file Node.h.

Referenced by addSensorForce(), attachSensor(), Edge::getSensorValue(), operator<<(), and operator=().

std::string Node::sensorID

Definition at line 44 of file Node.h.

Referenced by attachSensor(), draw(), and operator=().

dword Node::state
protected

Definition at line 61 of file Node.h.

Referenced by disableState(), draw(), enableState(), hasState(), operator=(), and toggleState().

Point Node::v
protected

Velocity and Force.

Definition at line 52 of file Node.h.

Referenced by operator=().


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