1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Authors: |
---|
6 | * Wei Qiao <qiaow@purdue.edu> |
---|
7 | * Insoo Woo <iwoo@purdue.edu> |
---|
8 | * George A. Howlett <gah@purdue.edu> |
---|
9 | * Leif Delgass <ldelgass@purdue.edu> |
---|
10 | */ |
---|
11 | |
---|
12 | #include <assert.h> |
---|
13 | |
---|
14 | #include <vrmath/Color4f.h> |
---|
15 | |
---|
16 | #include "nanovis.h" // For NMESH |
---|
17 | #include "FlowParticles.h" |
---|
18 | #include "Flow.h" |
---|
19 | #include "Trace.h" |
---|
20 | |
---|
21 | using namespace nv; |
---|
22 | using namespace vrmath; |
---|
23 | |
---|
24 | FlowParticles::FlowParticles(const char *name) : |
---|
25 | _name(name), |
---|
26 | _renderer(new ParticleRenderer(NMESH, NMESH)), |
---|
27 | _volume(NULL) |
---|
28 | { |
---|
29 | _sv.position.value = 0.0; |
---|
30 | _sv.position.flags = RELPOS; |
---|
31 | _sv.position.axis = AXIS_Z; |
---|
32 | _sv.color.r = _sv.color.g = _sv.color.b = _sv.color.a = 1.0f; |
---|
33 | _sv.isHidden = false; |
---|
34 | _sv.particleSize = 1.2; |
---|
35 | } |
---|
36 | |
---|
37 | FlowParticles::~FlowParticles() |
---|
38 | { |
---|
39 | TRACE("Deleting renderer"); |
---|
40 | if (_renderer != NULL) { |
---|
41 | delete _renderer; |
---|
42 | } |
---|
43 | TRACE("Freeing switches"); |
---|
44 | FreeSwitches(_switches, &_sv, 0); |
---|
45 | } |
---|
46 | |
---|
47 | float |
---|
48 | FlowParticles::getRelativePosition(FlowPosition *position) |
---|
49 | { |
---|
50 | if (position->flags == RELPOS) { |
---|
51 | return (float)position->value; |
---|
52 | } |
---|
53 | switch (position->axis) { |
---|
54 | case AXIS_X: |
---|
55 | return (float)((position->value - _volume->xAxis.min()) / |
---|
56 | (_volume->xAxis.max() - _volume->xAxis.min())); |
---|
57 | case AXIS_Y: |
---|
58 | return (float)((position->value - _volume->yAxis.min()) / |
---|
59 | (_volume->yAxis.max() - _volume->yAxis.min())); |
---|
60 | case AXIS_Z: |
---|
61 | return (float)((position->value - _volume->zAxis.min()) / |
---|
62 | (_volume->zAxis.max() - _volume->zAxis.min())); |
---|
63 | } |
---|
64 | return 0.0f; |
---|
65 | } |
---|
66 | |
---|
67 | void |
---|
68 | FlowParticles::render() |
---|
69 | { |
---|
70 | TRACE("Particles '%s' axis: %d pos: %g rel pos: %g", |
---|
71 | _name.c_str(), _sv.position.axis, _sv.position.value, |
---|
72 | getRelativePosition(&_sv.position)); |
---|
73 | |
---|
74 | _renderer->setSlicePosition(getRelativePosition(&_sv.position)); |
---|
75 | _renderer->setSliceAxis(_sv.position.axis); |
---|
76 | assert(_renderer->active()); |
---|
77 | _renderer->render(); |
---|
78 | } |
---|
79 | |
---|
80 | bool |
---|
81 | FlowParticles::configure() |
---|
82 | { |
---|
83 | bool needReset = false; |
---|
84 | |
---|
85 | _renderer->setColor(Color4f(_sv.color.r, |
---|
86 | _sv.color.g, |
---|
87 | _sv.color.b, |
---|
88 | _sv.color.a)); |
---|
89 | _renderer->particleSize(_sv.particleSize); |
---|
90 | if (_renderer->getSliceAxis() != _sv.position.axis) { |
---|
91 | needReset = true; |
---|
92 | _renderer->setSliceAxis(_sv.position.axis); |
---|
93 | } |
---|
94 | float pos = getRelativePosition(&_sv.position); |
---|
95 | if (_renderer->getSlicePosition() != pos) { |
---|
96 | needReset = true; |
---|
97 | _renderer->setSlicePosition(pos); |
---|
98 | } |
---|
99 | _renderer->active(!_sv.isHidden); |
---|
100 | |
---|
101 | return needReset; |
---|
102 | } |
---|