Skip to content

Commit dd25ad0

Browse files
committed
Vrml node for particle rendering
1 parent f9b64c5 commit dd25ad0

6 files changed

Lines changed: 219 additions & 17 deletions

File tree

src/OpenCOVER/plugins/general/Particles/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
if(NOT COVISE_USE_QT)
22
return()
33
endif()
4+
USING(VRML)
45

5-
#USING(CG OPENGL)
66

77
SET(HEADERS
88
ParticleViewer.h
99
Particles.h
10+
VrmlNodeParticles.h
1011
)
1112
SET(SOURCES
1213
ParticleViewer.cpp
1314
Particles.cpp
15+
VrmlNodeParticles.cpp
1416
)
1517
cover_add_plugin(Particles)
1618

src/OpenCOVER/plugins/general/Particles/ParticleViewer.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <osg/Geode>
5151
#include <cover/VRSceneGraph.h>
5252

53-
ParticleViewer *plugin = NULL;
53+
ParticleViewer *ParticleViewer::plugin = NULL;
5454

5555
FileHandler fileHandler[] = {
5656
{ NULL,
@@ -358,7 +358,7 @@ void ParticleViewer::tabletEvent(coTUIElement *tUIItem)
358358
}
359359
for (std::list<Particles *>::iterator it = particles.begin(); it != particles.end(); it++)
360360
{
361-
(*it)->updateRadii(currentRValue);
361+
(*it)->updateRadii(currentRValue); // this also sets the radius to the editField value if currentRValue is 0 == NONE
362362
}
363363
}
364364
}
@@ -566,6 +566,19 @@ ParticleViewer::~ParticleViewer()
566566
coVRFileManager::instance()->unregisterFileHandler(&fileHandler[3]);
567567
} // DESTRUCTOR
568568

569+
void ParticleViewer::updateColors()
570+
{
571+
int currentValue = valChoice->getSelectedEntry();
572+
int currentRValue = radChoice->getSelectedEntry();
573+
int aCurrentValue = aValChoice->getSelectedEntry();
574+
int aCurrentRValue = aRadChoice->getSelectedEntry();
575+
for (std::list<Particles *>::iterator it = particles.begin(); it != particles.end(); it++)
576+
{
577+
(*it)->updateColors(currentValue, aCurrentValue);
578+
(*it)->updateRadii(currentRValue);
579+
}
580+
}
581+
569582
// Called before each frame
570583
void ParticleViewer::preFrame()
571584
{

src/OpenCOVER/plugins/general/Particles/ParticleViewer.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ class ParticleViewer : public coVRPlugin, public coTUIListener
5151
typedef float FlColor[5];
5252
int currentMap;
5353
int aCurrentMap;
54+
static ParticleViewer *plugin;
5455

5556
public:
5657
// Constructor
5758
ParticleViewer();
5859

5960
// Destructor
6061
~ParticleViewer();
62+
static ParticleViewer * instance()
63+
{
64+
return plugin;
65+
};
6166
bool init();
6267

6368
void setTimestep(int t);
@@ -67,6 +72,57 @@ class ParticleViewer : public coVRPlugin, public coTUIListener
6772
float getAMinVal();
6873
float getAMaxVal();
6974
float getARadius();
75+
void setParticlesColorMap(const std::string &name)
76+
{
77+
mapChoice->setSelectedText(name);
78+
currentMap = mapNames.indexOf(QString(name.c_str()));
79+
};
80+
void setArrowsColorMap(const std::string &name)
81+
{
82+
aMapChoice->setSelectedText(name);
83+
aCurrentMap = mapNames.indexOf(QString(name.c_str()));
84+
};
85+
void setParticlesValue(const std::string &name)
86+
{
87+
valChoice->setSelectedText(name);
88+
};
89+
void setArrowsValue(const std::string &name)
90+
{
91+
aValChoice->setSelectedText(name);
92+
};
93+
void setParticlesMin(float min)
94+
{
95+
mapMin->setValue(min);
96+
};
97+
void setParticlesMax(float max)
98+
{
99+
mapMax->setValue(max);
100+
};
101+
void setParticlesRadius(float radius)
102+
{
103+
radiusEdit->setValue(radius);
104+
};
105+
void setArrowsMin(float min)
106+
{
107+
aMapMin->setValue(min);
108+
};
109+
void setArrowsMax(float max)
110+
{
111+
aMapMax->setValue(max);
112+
};
113+
void setArrowsRadius(float radius)
114+
{
115+
aRadiusEdit->setValue(radius);
116+
};
117+
void setArrowsRadiusValue(const std::string &name)
118+
{
119+
aRadChoice->setSelectedText(name);
120+
};
121+
void setParticlesRadiusValue(const std::string &name)
122+
{
123+
radChoice->setSelectedText(name);
124+
};
125+
void updateColors();
70126

71127
void preFrame(); // Update function , called each frame
72128

src/OpenCOVER/plugins/general/Particles/Particles.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ TimeStepData::~TimeStepData()
188188
delete[] Ivalues;
189189
}
190190

191-
extern ParticleViewer *plugin;
192191

193192
int Particles::read64(uint64_t &val)
194193
{
@@ -801,7 +800,7 @@ int Particles::readBinaryTimestep(int timestep)
801800
//sphere->setColorBinding(colorbinding);
802801
float *radii = values[1];
803802
sphere->setCoords(numParticles, xc, yc, zc, radii);
804-
float f = plugin->getRadius();
803+
float f = ParticleViewer::instance()->getRadius();
805804
float *rn = new float[numParticles];
806805
for (int n = 0; n < numParticles; n++)
807806
{
@@ -926,7 +925,7 @@ int Particles::readFile(char *fn, int timestep)
926925
}
927926
else
928927
{
929-
//float radius = plugin->getRadius();
928+
//float radius = ParticleViewer::instance()->getRadius();
930929
while (!feof(fp))
931930
{
932931
if (n > numParticles)
@@ -1144,7 +1143,7 @@ int Particles::readIMWFFile(char *fn, int timestep)
11441143

11451144
int n = 0;
11461145

1147-
//float radius = plugin->getRadius();
1146+
//float radius = ParticleViewer::instance()->getRadius();
11481147
if (version == 0)
11491148
{
11501149
while (!feof(fp))
@@ -1346,7 +1345,7 @@ int Particles::readIndentFile(char *fn, int timestep)
13461345
float *xc = new float[numParticles];
13471346
float *yc = new float[numParticles];
13481347
float *zc = new float[numParticles];
1349-
//float radius = plugin->getRadius();
1348+
//float radius = ParticleViewer::instance()->getRadius();
13501349
//
13511350
int i = 0;
13521351
int n = 0;
@@ -1421,7 +1420,7 @@ int Particles::readIndentFile(char *fn, int timestep)
14211420

14221421
void Particles::updateRadii(unsigned int valueNumber)
14231422
{
1424-
float f = plugin->getRadius();
1423+
float f = ParticleViewer::instance()->getRadius();
14251424
for (int i = 0; i < numTimesteps; i++)
14261425
{
14271426
if (timesteps[i]->sphere)
@@ -1461,14 +1460,14 @@ void Particles::updateColors(unsigned int valueNumber, unsigned int aValueNumber
14611460
float *rc = new float[numParticles];
14621461
float *gc = new float[numParticles];
14631462
float *bc = new float[numParticles];
1464-
float minVal = plugin->getMinVal();
1465-
float maxVal = plugin->getMaxVal();
1463+
float minVal = ParticleViewer::instance()->getMinVal();
1464+
float maxVal = ParticleViewer::instance()->getMaxVal();
14661465
if (variableTypes[valueNumber + numHiddenVars] == T_FLOAT)
14671466
{
14681467
float *temp = timesteps[i]->values[variableIndex[valueNumber]];
14691468
for (int n = 0; n < numParticles; n++)
14701469
{
1471-
osg::Vec4 c = plugin->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
1470+
osg::Vec4 c = ParticleViewer::instance()->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
14721471
rc[n] = c[0];
14731472
gc[n] = c[1];
14741473
bc[n] = c[2];
@@ -1479,7 +1478,7 @@ void Particles::updateColors(unsigned int valueNumber, unsigned int aValueNumber
14791478
int64_t *temp = timesteps[i]->Ivalues[variableIndex[valueNumber]];
14801479
for (int n = 0; n < numParticles; n++)
14811480
{
1482-
osg::Vec4 c = plugin->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
1481+
osg::Vec4 c = ParticleViewer::instance()->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
14831482
rc[n] = c[0];
14841483
gc[n] = c[1];
14851484
bc[n] = c[2];
@@ -1506,14 +1505,14 @@ void Particles::updateColors(unsigned int valueNumber, unsigned int aValueNumber
15061505
{
15071506
int numParticles = timesteps[i]->numParticles;
15081507
colArr = new osg::Vec4Array(numParticles * 2);
1509-
float minVal = plugin->getAMinVal();
1510-
float maxVal = plugin->getAMaxVal();
1508+
float minVal = ParticleViewer::instance()->getAMinVal();
1509+
float maxVal = ParticleViewer::instance()->getAMaxVal();
15111510
if (variableTypes[aValueNumber + numHiddenVars - 1] == T_FLOAT)
15121511
{
15131512
float *temp = timesteps[i]->values[variableIndex[aValueNumber - 1]];
15141513
for (int n = 0; n < numParticles; n++)
15151514
{
1516-
osg::Vec4 c = plugin->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
1515+
osg::Vec4 c = ParticleViewer::instance()->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
15171516
colArr->at(n * 2).r() = c[0];
15181517
colArr->at(n * 2).g() = c[1];
15191518
colArr->at(n * 2).b() = c[2];
@@ -1529,7 +1528,7 @@ void Particles::updateColors(unsigned int valueNumber, unsigned int aValueNumber
15291528
int64_t *temp = timesteps[i]->Ivalues[variableIndex[aValueNumber - 1]];
15301529
for (int n = 0; n < numParticles; n++)
15311530
{
1532-
osg::Vec4 c = plugin->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
1531+
osg::Vec4 c = ParticleViewer::instance()->getColor((temp[n] - minVal) / (maxVal - minVal), getMode());
15331532
colArr->at(n * 2).r() = c[0];
15341533
colArr->at(n * 2).g() = c[1];
15351534
colArr->at(n * 2).b() = c[2];
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* This file is part of COVISE.
2+
3+
You can use it under the terms of the GNU Lesser General Public License
4+
version 2.1 or later, see lgpl-2.1.txt.
5+
6+
* License: LGPL 2+ */
7+
8+
//
9+
// Vrml 97 library
10+
// Copyright (C) 2001 Uwe Woessner
11+
//
12+
// %W% %G%
13+
// VrmlNodeParticles.cpp
14+
15+
#include "VrmlNodeParticles.h"
16+
17+
#include "ParticleViewer.h"
18+
19+
static VrmlNode *creator(VrmlScene *scene)
20+
{
21+
return new VrmlNodeParticles(scene);
22+
}
23+
24+
VrmlNodeParticles::VrmlNodeParticles(VrmlScene *scene)
25+
: VrmlNodeChild(scene, typeName())
26+
{
27+
}
28+
29+
VrmlNodeParticles::VrmlNodeParticles(const VrmlNodeParticles &n)
30+
: VrmlNodeChild(n)
31+
{
32+
}
33+
34+
35+
void VrmlNodeParticles::initFields(VrmlNodeParticles *node, VrmlNodeType *t)
36+
{
37+
VrmlNodeChild::initFields(node, t); // Parent class
38+
initFieldsHelper(node, t,
39+
field("particlesColorMap", node->d_ParticlesColorMap, [node](auto f)
40+
{ ParticleViewer::instance()->setParticlesColorMap(node->d_ParticlesColorMap.get()); }),
41+
field("particlesValue", node->d_ParticlesValue, [node](auto f)
42+
{ ParticleViewer::instance()->setParticlesValue(node->d_ParticlesValue.get()); }),
43+
field("particlesMin", node->d_ParticlesMin, [node](auto f)
44+
{ ParticleViewer::instance()->setParticlesMin(node->d_ParticlesMin.get()); }),
45+
field("particlesMax", node->d_ParticlesMax, [node](auto f)
46+
{ ParticleViewer::instance()->setParticlesMax(node->d_ParticlesMax.get()); }),
47+
field("particlesRadius", node->d_ParticlesRadius, [node](auto f)
48+
{ ParticleViewer::instance()->setParticlesRadius(node->d_ParticlesRadius.get()); }),
49+
field("particlesRadiusValue", node->d_ParticlesRadiusValue, [node](auto f)
50+
{ ParticleViewer::instance()->setParticlesRadiusValue(node->d_ParticlesRadiusValue.get()); }),
51+
field("arrowsColorMap", node->d_ArrowsColorMap, [node](auto f)
52+
{ ParticleViewer::instance()->setArrowsColorMap(node->d_ArrowsColorMap.get()); }),
53+
field("arrowsValue", node->d_ArrowsValue, [node](auto f)
54+
{ ParticleViewer::instance()->setArrowsValue(node->d_ArrowsValue.get()); }),
55+
field("arrowsMin", node->d_ArrowsMin, [node](auto f)
56+
{ ParticleViewer::instance()->setArrowsMin(node->d_ArrowsMin.get()); }),
57+
field("arrowsMax", node->d_ArrowsMax, [node](auto f)
58+
{ ParticleViewer::instance()->setArrowsMax(node->d_ArrowsMax.get()); }),
59+
field("arrowsRadius", node->d_ArrowsRadius, [node](auto f)
60+
{ ParticleViewer::instance()->setArrowsRadius(node->d_ArrowsRadius.get()); }),
61+
field("arrowsRadiusValue", node->d_ArrowsRadiusValue, [node](auto f)
62+
{ ParticleViewer::instance()->setArrowsRadiusValue(node->d_ArrowsRadiusValue.get()); }));
63+
if (t)
64+
{
65+
t->addEventIn("update", VrmlField::SFTIME);
66+
}
67+
}
68+
const char *VrmlNodeParticles::typeName()
69+
{
70+
return "Particles";
71+
}
72+
73+
inline void VrmlNodeParticles::eventIn(double timeStamp, const char *eventName, const VrmlField *fieldValue)
74+
{
75+
if (strcmp(eventName, "update") == 0)
76+
{
77+
ParticleViewer::instance()->updateColors();
78+
}
79+
// Check parent class for eventIn
80+
else
81+
{
82+
VrmlNode::eventIn(timeStamp, eventName, fieldValue);
83+
}
84+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* This file is part of COVISE.
2+
3+
You can use it under the terms of the GNU Lesser General Public License
4+
version 2.1 or later, see lgpl-2.1.txt.
5+
6+
* License: LGPL 2+ */
7+
8+
#ifndef _VRML_NODE_PARTICLES_H
9+
#define _VRML_NODE_PARTICLES_H
10+
11+
#include <util/coTypes.h>
12+
13+
#include <vrml97/vrml/VrmlNode.h>
14+
#include <vrml97/vrml/VrmlSFFloat.h>
15+
#include <vrml97/vrml/VrmlSFVec3f.h>
16+
#include <vrml97/vrml/VrmlSFString.h>
17+
#include <vrml97/vrml/VrmlNodeChild.h>
18+
19+
using namespace vrml;
20+
21+
class VrmlNodeParticles : public VrmlNodeChild
22+
{
23+
public:
24+
VrmlNodeParticles(VrmlScene *scene = 0);
25+
VrmlNodeParticles(const VrmlNodeParticles &n);
26+
27+
static void initFields(VrmlNodeParticles *node, vrml::VrmlNodeType *t);
28+
static const char *typeName();
29+
30+
void eventIn(double timeStamp,
31+
const char *eventName,
32+
const VrmlField *fieldValue);
33+
34+
private:
35+
VrmlSFString d_ParticlesColorMap = "";
36+
VrmlSFString d_ParticlesValue = "";
37+
VrmlSFFloat d_ParticlesMin = 0.0;
38+
VrmlSFFloat d_ParticlesMax = 1.0;
39+
VrmlSFFloat d_ParticlesRadius = 1.0;
40+
VrmlSFString d_ParticlesRadiusValue = "";
41+
VrmlSFString d_ArrowsColorMap = "";
42+
VrmlSFString d_ArrowsValue = "";
43+
VrmlSFFloat d_ArrowsMin = 0.0;
44+
VrmlSFFloat d_ArrowsMax = 1.0;
45+
VrmlSFFloat d_ArrowsRadius = 1.0;
46+
VrmlSFString d_ArrowsRadiusValue = "";
47+
};
48+
#endif

0 commit comments

Comments
 (0)