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

Last change on this file since 1380 was 1380, checked in by gah, 13 years ago
File size: 7.7 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->isActivated()) (*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->isActivated()) (*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->activate();
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->deactivate();
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        {
202                delete (*iter).second;
203                _vectorFieldMap.erase(iter);
204        }
205}
206
207void
208NvFlowVisRenderer::addPlane(const std::string& vfName, const std::string& name)
209{
210        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
211        if (iter != _vectorFieldMap.end())
212        {
213                if ((*iter).second) (*iter).second->addPlane(name);
214        }
215}
216
217void
218NvFlowVisRenderer::removePlane(const std::string& vfName, const std::string& name)
219{
220        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
221        if (iter != _vectorFieldMap.end())
222        {
223                if ((*iter).second) (*iter).second->removePlane(name);
224        }
225}
226
227void
228NvFlowVisRenderer::activateDeviceShape(const std::string& vfName, const std::string& name)
229{
230        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
231        if (iter != _vectorFieldMap.end())
232        {
233                if ((*iter).second) (*iter).second->activateDeviceShape(name);
234        }
235}
236
237void
238NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName, const std::string& name)
239{
240        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
241        if (iter != _vectorFieldMap.end())
242        {
243                if ((*iter).second) (*iter).second->deactivateDeviceShape(name);
244        }
245}
246
247void
248NvFlowVisRenderer::activateDeviceShape(const std::string& vfName)
249{
250        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
251        if (iter != _vectorFieldMap.end())
252        {
253                if ((*iter).second) (*iter).second->activateDeviceShape();
254        }
255}
256
257void
258NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName)
259{
260        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
261        if (iter != _vectorFieldMap.end())
262        {
263                if ((*iter).second) (*iter).second->deactivateDeviceShape();
264        }
265}
266
267void
268NvFlowVisRenderer::addDeviceShape(const std::string& vfName, const std::string& name, const NvDeviceShape& shape)
269{
270        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
271        if (iter != _vectorFieldMap.end())
272        {
273                if ((*iter).second) (*iter).second->addDeviceShape(name, shape);
274        }
275}
276
277void
278NvFlowVisRenderer::removeDeviceShape(const std::string& vfName, const std::string& name)
279{
280        std::map<std::string, NvVectorField*>::iterator iter = _vectorFieldMap.find(vfName);
281        if (iter != _vectorFieldMap.end())
282        {
283                if ((*iter).second) (*iter).second->removeDeviceShape(name);
284        }
285}
Note: See TracBrowser for help on using the repository browser.