source: trunk/packages/vizservers/nanovis/FlowParticles.cpp @ 3935

Last change on this file since 3935 was 3631, checked in by ldelgass, 11 years ago

Refactor names in particle renderer to match other classes

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
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
21using namespace nv;
22using namespace vrmath;
23
24FlowParticles::FlowParticles(const char *name) :
25    _name(name),
26    _renderer(new ParticleRenderer(NMESH, NMESH))
27{
28    _sv.position.value = 0.0f;
29    _sv.position.flags = RELPOS;
30    _sv.position.axis = AXIS_Z;
31    _sv.color.r = _sv.color.g = _sv.color.b = _sv.color.a = 1.0f;
32    _sv.isHidden = false;
33    _sv.particleSize = 1.2;
34}
35
36FlowParticles::~FlowParticles()
37{
38    TRACE("Deleting renderer");
39    if (_renderer != NULL) {
40        delete _renderer;
41    }
42    TRACE("Freeing switches");
43    Rappture::FreeSwitches(_switches, &_sv, 0);
44}
45
46float
47FlowParticles::getRelativePosition(FlowPosition *position)
48{
49    if (position->flags == RELPOS) {
50        return position->value;
51    }
52    switch (position->axis) {
53    case AXIS_X: 
54        return (position->value - _volume->xAxis.min()) /
55            (_volume->xAxis.max() - _volume->xAxis.min());
56    case AXIS_Y: 
57        return (position->value - _volume->yAxis.min()) /
58            (_volume->yAxis.max() - _volume->yAxis.min());
59    case AXIS_Z: 
60        return (position->value - _volume->zAxis.min()) /
61            (_volume->zAxis.max() - _volume->zAxis.min());
62    }
63    return 0.0;
64}
65
66void
67FlowParticles::render()
68{
69    TRACE("Particles '%s' axis: %d pos: %g rel pos: %g",
70          _name.c_str(), _sv.position.axis, _sv.position.value,
71          getRelativePosition(&_sv.position));
72
73    _renderer->setSlicePosition(getRelativePosition(&_sv.position));
74    _renderer->setSliceAxis(_sv.position.axis);
75    assert(_renderer->active());
76    _renderer->render();
77}
78
79bool
80FlowParticles::configure()
81{
82    bool needReset = false;
83
84    _renderer->setColor(Color4f(_sv.color.r,
85                                _sv.color.g,
86                                _sv.color.b,
87                                _sv.color.a));
88    _renderer->particleSize(_sv.particleSize);
89    if (_renderer->getSliceAxis() != _sv.position.axis) {
90        needReset = true;
91        _renderer->setSliceAxis(_sv.position.axis);
92    }
93    float pos = getRelativePosition(&_sv.position);
94    if (_renderer->getSlicePosition() != pos) {
95        needReset = true;
96        _renderer->setSlicePosition(pos);
97    }
98    _renderer->active(!_sv.isHidden);
99
100    return needReset;
101}
Note: See TracBrowser for help on using the repository browser.