This repository has been archived by the owner on Dec 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VisualPickVisitor.cpp
138 lines (117 loc) · 4.1 KB
/
VisualPickVisitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "VisualPickVisitor.h"
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#include <sofa/gl/gl.h>
#include <sofa/simulation/Node.h>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/core/visual/Shader.h>
namespace sofa::simplegui
{
VisualPickVisitor::VisualPickVisitor(core::visual::VisualParams* params)
: VisualVisitor(params)
{
pickedId = 0;
}
simulation::Visitor::Result VisualPickVisitor::processNodeTopDown(simulation::Node* node)
{
// cerr <<"VisualPickVisitor::processNodeTopDown" << endl;
hasShader = (node->getShader()!=NULL);
for_each(this, node, node->visualModel, &VisualPickVisitor::fwdVisualModel);
this->VisualVisitor::processNodeTopDown(node);
return RESULT_CONTINUE;
}
void VisualPickVisitor::processNodeBottomUp(simulation::Node* node)
{
// cerr <<"VisualPickVisitor::processNodeBottomUp" << endl;
for_each(this, node, node->visualModel, &VisualPickVisitor::bwdVisualModel);
}
void VisualPickVisitor::processObject(simulation::Node* /*node*/, core::objectmodel::BaseObject* o)
{
#ifdef DEBUG_DRAW
std::cerr << ">" << o->getClassName() << "::draw() of " << o->getName() << std::endl;
#endif
// cout<<"VisualPickVisitor::processObject push name of "<< o->getName() << " = " << pickedId << endl;
names.push_back(o->getName());
glPushName(pickedId++);
o->draw(vparams);
glPopName();
// cout<<"VisualPickVisitor::processObject end " << endl;
#ifdef DEBUG_DRAW
std::cerr << "<" << o->getClassName() << "::draw() of " << o->getName() << std::endl;
#endif
}
void VisualPickVisitor::fwdVisualModel(simulation::Node* /*node*/, core::visual::VisualModel* vm)
{
#ifdef DEBUG_DRAW
std::cerr << ">" << vm->getClassName() << "::fwdDraw() of " << vm->getName() << std::endl;
#endif
vm->fwdDraw(vparams);
#ifdef DEBUG_DRAW
std::cerr << "<" << vm->getClassName() << "::fwdDraw() of " << vm->getName() << std::endl;
#endif
}
void VisualPickVisitor::bwdVisualModel(simulation::Node* /*node*/,core::visual::VisualModel* vm)
{
#ifdef DEBUG_DRAW
std::cerr << ">" << vm->getClassName() << "::bwdDraw() of " << vm->getName() << std::endl;
#endif
vm->bwdDraw(vparams);
#ifdef DEBUG_DRAW
std::cerr << "<" << vm->getClassName() << "::bwdDraw() of " << vm->getName() << std::endl;
#endif
}
void VisualPickVisitor::processVisualModel(simulation::Node* node, core::visual::VisualModel* vm)
{
//cerr<<"VisualPickVisitor::processVisualModel "<<vm->getName()<<endl;
sofa::core::visual::Shader* shader = NULL;
if (hasShader)
shader = dynamic_cast<sofa::core::visual::Shader*>(node->getShader(subsetsToManage));
switch(vparams->pass())
{
case core::visual::VisualParams::Std:
{
if (shader && shader->isActive())
shader->start();
#ifdef DEBUG_DRAW
std::cerr << ">" << vm->getClassName() << "::drawVisual() of " << vm->getName() << std::endl;
#endif
names.push_back(vm->getName());
glPushName(pickedId++);
vm->drawVisual(vparams);
glPopName();
#ifdef DEBUG_DRAW
std::cerr << "<" << vm->getClassName() << "::drawVisual() of " << vm->getName() << std::endl;
#endif
if (shader && shader->isActive())
shader->stop();
break;
}
case core::visual::VisualParams::Transparent:
{
if (shader && shader->isActive())
shader->start();
#ifdef DEBUG_DRAW
std::cerr << ">" << vm->getClassName() << "::drawTransparent() of " << vm->getName() << std::endl;
#endif
vm->drawTransparent(vparams);
#ifdef DEBUG_DRAW
std::cerr << "<" << vm->getClassName() << "::drawTransparent() of " << vm->getName() << std::endl;
#endif
if (shader && shader->isActive())
shader->stop();
break;
}
case core::visual::VisualParams::Shadow:
#ifdef DEBUG_DRAW
std::cerr << ">" << vm->getClassName() << "::drawShadow() of " << vm->getName() << std::endl;
#endif
vm->drawShadow(vparams);
#ifdef DEBUG_DRAW
std::cerr << "<" << vm->getClassName() << "::drawShadow() of " << vm->getName() << std::endl;
#endif
break;
}
}
}