Structural deformable models
Node.cpp
Go to the documentation of this file.
1 #include "Sensor.h"
2 #include "Node.h"
3 #include "glutils.h"
4 
5 using namespace std;
6 
8  : Point(0,0), sensor(getZeroSensor()),
9  mass(phys->mass), index(-1), state(ST_NONE)
10 {
11 }
12 
14 Node::Node(float _x, float _y, const ParticleParam *phys)
15  : Point(_x, _y), sensor(getZeroSensor()), mass(phys->mass),
16  index(-1), state(ST_NONE)
17 {
18 }
19 
21 Node& Node::operator=(const Node &rhs) {
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 }
36 
38 ostream& operator<<(ostream &os, const Node &n) {
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 }
49 
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 }
61 
63  if(sensor) {
64  Point sf = sensor->getWeightedGradient((int)x,(int)y);
65  f += sf;
66  }
67 }
68 
69 void Node::draw() const {
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 }
static ParticleParam global
Definition: PartParam.h:72
void attachSensor(sensor_cptr _sensor)
Definition: Node.cpp:50
Implements a Node used by Model and Edge.
Definition: Node.h:13
std::vector< int > edges
Definition: Node.h:60
float y
Definition: Point.h:224
Point f
Definition: Node.h:52
STL namespace.
float mass
Mass.
Definition: Node.h:48
Definition: Sensor.h:21
Point ef
extern force
Definition: Node.h:54
void draw() const
Definition: Node.cpp:69
Point2D & operator=(const Point2D &rhs)
Definition: Point.h:27
sensor_ptr getZeroSensor()
Definition: Sensor.cpp:234
Point2D Point
Definition: Point.h:251
Node(const ParticleParam *phys=&ParticleParam::global)
Default constructor.
Definition: Node.cpp:7
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
void addSensorForce()
Definition: Node.cpp:62
Point v
Velocity and Force.
Definition: Node.h:52
bool hasState(dword nstate=0xffffffff) const
Definition: Node.h:41
Node & operator=(const Node &rhs)
Assignment operator.
Definition: Node.cpp:21
friend std::ostream & operator<<(std::ostream &os, const Node &n)
output operator
Definition: Node.cpp:38
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
std::shared_ptr< const Sensor > sensor_cptr
Definition: types_fwd.h:17
Definition: Point.h:16
float x
Definition: Point.h:224
float oangle
Definition: Node.h:57