source: trunk/packages/vizservers/nanovis/NvFlowVisRenderer.cpp @ 1431

Last change on this file since 1431 was 1431, checked in by gah, 15 years ago

fixup new flow visualization command structure

File size: 7.9 KB
Line 
1
2/*
3 * ----------------------------------------------------------------------
4 * NvFlowVisRenderer.cpp: particle system class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2006  Purdue Research Foundation
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16
17#include <stdio.h>
18#include <assert.h>
19#include <malloc.h>
20#include <string.h>
21
22#include <R2/R2FilePath.h>
23#include "NvFlowVisRenderer.h"
24#include "NvVectorField.h"
25#include <Trace.h>
26
27
28#define NV_32
29
30NvFlowVisRenderer::NvFlowVisRenderer(int w, int h, CGcontext context) :
31    _activated(true)
32{
33    _psys_width = w;
34    _psys_height = h;
35
36    /*
37      licRenderer[0] = new NvLIC(NMESH, NPIX, NPIX, 0,
38      Vector3(0, 0, 0), g_context);
39      licRenderer[1] = new NvLIC(NMESH, NPIX, NPIX, 1,
40      Vector3(0, 0, 0), g_context);
41      licRenderer[2] = new NvLIC(NMESH, NPIX, NPIX, 2,
42      Vector3(0, 0, 0), g_context);
43    */
44}
45
46NvFlowVisRenderer::~NvFlowVisRenderer()
47{
48    std::map<std::string, NvVectorField*>::iterator iter;
49    for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter)
50        {
51            delete (*iter).second;
52        }
53
54    /*
55      for (int i = 0; i < 3; ++i)
56      {
57      delete licRenderer[i];
58      }
59    */
60}
61
62void
63NvFlowVisRenderer::initialize()
64{
65    std::map<std::string, NvVectorField*>::iterator iter;
66    for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter)
67        {
68            (*iter).second->initialize();
69        }
70}
71
72void
73NvFlowVisRenderer::reset()
74{
75    std::map<std::string, NvVectorField*>::iterator iter;
76    for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter)
77        {
78            (*iter).second->reset();
79        }
80}
81
82void
83NvFlowVisRenderer::initialize(const std::string& vfName)
84{
85    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
86    if (iter != _vectorFieldMap.end())
87        {
88            if ((*iter).second)
89                {
90                    (*iter).second->initialize();
91                }
92        }
93}
94
95void
96NvFlowVisRenderer::advect()
97{
98    std::map<std::string, NvVectorField*>::iterator iter;
99    for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter)
100        {
101            if((*iter).second && (*iter).second->active()) (*iter).second->advect();
102        }
103}
104
105void
106NvFlowVisRenderer::render()
107{
108    std::map<std::string, NvVectorField*>::iterator iter;
109    for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter)
110        {
111            if((*iter).second && (*iter).second->active()) (*iter).second->render();
112        }
113}
114
115void
116NvFlowVisRenderer::addVectorField(const std::string& vfName, Volume* volPtr, const Vector3& ori, float scaleX, float scaleY, float scaleZ, float max)
117{
118    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
119    if (iter != _vectorFieldMap.end()) {
120        if ((*iter).second) {
121            ((*iter).second)->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max);
122        } else {
123            NvVectorField* vf = new NvVectorField();
124            _vectorFieldMap[vfName] = vf;
125            vf->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max);
126        }
127    } else {
128        NvVectorField* vf = new NvVectorField();
129        _vectorFieldMap[vfName] = vf;
130        vf->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max);
131    }
132}
133
134void
135NvFlowVisRenderer::activateVectorField(const std::string& vfName)
136{
137    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
138    if (iter != _vectorFieldMap.end())
139        if ((*iter).second) (*iter).second->active(true);
140}
141
142void
143NvFlowVisRenderer::deactivateVectorField(const std::string& vfName)
144{
145    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
146    if (iter != _vectorFieldMap.end())
147        if ((*iter).second) (*iter).second->active(false);
148}
149
150void
151NvFlowVisRenderer::activatePlane(const std::string& vfName, const std::string& name)
152{
153    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
154    if (iter != _vectorFieldMap.end())
155        {
156            if ((*iter).second) (*iter).second->activatePlane(name);
157        }
158}
159
160void
161NvFlowVisRenderer::deactivatePlane(const std::string& vfName, const std::string& name)
162{
163    std::map<std::string, NvVectorField*>::iterator iter;
164
165    iter = _vectorFieldMap.find(vfName);
166    if (iter != _vectorFieldMap.end())
167        {
168            if ((*iter).second) (*iter).second->deactivatePlane(name);
169        }
170}
171
172void
173NvFlowVisRenderer::setPlaneAxis(const std::string& vfName, const std::string& planeName, int axis)
174{
175    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
176    if (iter != _vectorFieldMap.end())
177        if((*iter).second) (*iter).second->setPlaneAxis(planeName, axis);
178}
179
180void
181NvFlowVisRenderer::setPlanePos(const std::string& vfName, const std::string& name, float pos)
182{
183    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
184    if (iter != _vectorFieldMap.end())
185        if((*iter).second) (*iter).second->setPlanePos(name, pos);
186}
187
188void
189NvFlowVisRenderer::setParticleColor(const std::string& vfName, const std::string& name, const Vector4& color)
190{
191    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
192    if (iter != _vectorFieldMap.end())
193        if((*iter).second) (*iter).second->setParticleColor(name, color);
194}
195
196void
197NvFlowVisRenderer::removeVectorField(const std::string& vfName)
198{
199    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
200    if (iter != _vectorFieldMap.end()) {
201        delete (*iter).second;
202        _vectorFieldMap.erase(iter);
203    }
204}
205
206void
207NvFlowVisRenderer::addPlane(const std::string& vfName, const std::string& name)
208{
209    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
210    if (iter != _vectorFieldMap.end()) {
211        if ((*iter).second) (*iter).second->addPlane(name);
212    }
213}
214
215void
216NvFlowVisRenderer::removePlane(const std::string& vfName, const std::string& name)
217{
218    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
219    if (iter != _vectorFieldMap.end()) {
220        if ((*iter).second) (*iter).second->removePlane(name);
221    }
222}
223
224void
225NvFlowVisRenderer::activateDeviceShape(const std::string& vfName, const std::string& name)
226{
227    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
228    if (iter != _vectorFieldMap.end()) {
229        if ((*iter).second) (*iter).second->activateDeviceShape(name);
230    }
231}
232
233void
234NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName, const std::string& name)
235{
236    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
237    if (iter != _vectorFieldMap.end()) {
238        if ((*iter).second) (*iter).second->deactivateDeviceShape(name);
239    }
240}
241
242void
243NvFlowVisRenderer::activateDeviceShape(const std::string& vfName)
244{
245    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
246    if (iter != _vectorFieldMap.end()) {
247        if ((*iter).second) (*iter).second->activateDeviceShape();
248    }
249}
250
251void
252NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName)
253{
254    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
255    if (iter != _vectorFieldMap.end()) {
256        if ((*iter).second) (*iter).second->deactivateDeviceShape();
257    }
258}
259
260void
261NvFlowVisRenderer::addDeviceShape(const std::string& vfName, const std::string& name, const NvDeviceShape& shape)
262{
263    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
264    if (iter != _vectorFieldMap.end()) {
265        if ((*iter).second) (*iter).second->addDeviceShape(name, shape);
266    }
267}
268
269void
270NvFlowVisRenderer::removeDeviceShape(const std::string& vfName, const std::string& name)
271{
272    std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
273    if (iter != _vectorFieldMap.end()) {
274        if ((*iter).second) (*iter).second->removeDeviceShape(name);
275    }
276}
Note: See TracBrowser for help on using the repository browser.