1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
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 | |
---|
24 | #include "NvFlowVisRenderer.h" |
---|
25 | #include "NvVectorField.h" |
---|
26 | #include "Trace.h" |
---|
27 | |
---|
28 | #define NV_32 |
---|
29 | |
---|
30 | NvFlowVisRenderer::NvFlowVisRenderer(int w, int h) : |
---|
31 | _activated(true) |
---|
32 | { |
---|
33 | _psys_width = w; |
---|
34 | _psys_height = h; |
---|
35 | } |
---|
36 | |
---|
37 | NvFlowVisRenderer::~NvFlowVisRenderer() |
---|
38 | { |
---|
39 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
40 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
41 | delete (*iter).second; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | void |
---|
46 | NvFlowVisRenderer::initialize() |
---|
47 | { |
---|
48 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
49 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
50 | (*iter).second->initialize(); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | void |
---|
55 | NvFlowVisRenderer::reset() |
---|
56 | { |
---|
57 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
58 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
59 | (*iter).second->reset(); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | void |
---|
64 | NvFlowVisRenderer::initialize(const std::string& vfName) |
---|
65 | { |
---|
66 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
67 | if (iter != _vectorFieldMap.end()) { |
---|
68 | if ((*iter).second) { |
---|
69 | (*iter).second->initialize(); |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | void |
---|
75 | NvFlowVisRenderer::advect() |
---|
76 | { |
---|
77 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
78 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
79 | if ((*iter).second && (*iter).second->active()) |
---|
80 | (*iter).second->advect(); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void |
---|
85 | NvFlowVisRenderer::render() |
---|
86 | { |
---|
87 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
88 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
89 | if ((*iter).second && (*iter).second->active()) |
---|
90 | (*iter).second->render(); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | void |
---|
95 | NvFlowVisRenderer::addVectorField(const std::string& vfName, Volume* volPtr, |
---|
96 | const Vector3& ori, |
---|
97 | float scaleX, float scaleY, float scaleZ, float max) |
---|
98 | { |
---|
99 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
100 | if (iter != _vectorFieldMap.end()) { |
---|
101 | if ((*iter).second) { |
---|
102 | ((*iter).second)->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max); |
---|
103 | } else { |
---|
104 | NvVectorField *vf = new NvVectorField(); |
---|
105 | _vectorFieldMap[vfName] = vf; |
---|
106 | vf->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max); |
---|
107 | } |
---|
108 | } else { |
---|
109 | NvVectorField *vf = new NvVectorField(); |
---|
110 | _vectorFieldMap[vfName] = vf; |
---|
111 | vf->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max); |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | NvFlowVisRenderer::activateVectorField(const std::string& vfName) |
---|
117 | { |
---|
118 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
119 | if (iter != _vectorFieldMap.end()) { |
---|
120 | if ((*iter).second) |
---|
121 | (*iter).second->active(true); |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | void |
---|
126 | NvFlowVisRenderer::deactivateVectorField(const std::string& vfName) |
---|
127 | { |
---|
128 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
129 | if (iter != _vectorFieldMap.end()) { |
---|
130 | if ((*iter).second) |
---|
131 | (*iter).second->active(false); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | void |
---|
136 | NvFlowVisRenderer::activatePlane(const std::string& vfName, const std::string& name) |
---|
137 | { |
---|
138 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
139 | if (iter != _vectorFieldMap.end()) { |
---|
140 | if ((*iter).second) |
---|
141 | (*iter).second->activatePlane(name); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | void |
---|
146 | NvFlowVisRenderer::deactivatePlane(const std::string& vfName, const std::string& name) |
---|
147 | { |
---|
148 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
149 | if (iter != _vectorFieldMap.end()) { |
---|
150 | if ((*iter).second) |
---|
151 | (*iter).second->deactivatePlane(name); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | void |
---|
156 | NvFlowVisRenderer::setPlaneAxis(const std::string& vfName, const std::string& planeName, int axis) |
---|
157 | { |
---|
158 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
159 | if (iter != _vectorFieldMap.end()) { |
---|
160 | if ((*iter).second) |
---|
161 | (*iter).second->setPlaneAxis(planeName, axis); |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | void |
---|
166 | NvFlowVisRenderer::setPlanePos(const std::string& vfName, const std::string& name, float pos) |
---|
167 | { |
---|
168 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
169 | if (iter != _vectorFieldMap.end()) { |
---|
170 | if ((*iter).second) |
---|
171 | (*iter).second->setPlanePos(name, pos); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | void |
---|
176 | NvFlowVisRenderer::setParticleColor(const std::string& vfName, const std::string& name, const Vector4& color) |
---|
177 | { |
---|
178 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
179 | if (iter != _vectorFieldMap.end()) { |
---|
180 | if ((*iter).second) |
---|
181 | (*iter).second->setParticleColor(name, color); |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | void |
---|
186 | NvFlowVisRenderer::removeVectorField(const std::string& vfName) |
---|
187 | { |
---|
188 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
189 | if (iter != _vectorFieldMap.end()) { |
---|
190 | delete (*iter).second; |
---|
191 | _vectorFieldMap.erase(iter); |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | void |
---|
196 | NvFlowVisRenderer::addPlane(const std::string& vfName, const std::string& name) |
---|
197 | { |
---|
198 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
199 | if (iter != _vectorFieldMap.end()) { |
---|
200 | if ((*iter).second) |
---|
201 | (*iter).second->addPlane(name); |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | void |
---|
206 | NvFlowVisRenderer::removePlane(const std::string& vfName, const std::string& name) |
---|
207 | { |
---|
208 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
209 | if (iter != _vectorFieldMap.end()) { |
---|
210 | if ((*iter).second) |
---|
211 | (*iter).second->removePlane(name); |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | void |
---|
216 | NvFlowVisRenderer::activateDeviceShape(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) |
---|
221 | (*iter).second->activateDeviceShape(name); |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | void |
---|
226 | NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName, const std::string& name) |
---|
227 | { |
---|
228 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
229 | if (iter != _vectorFieldMap.end()) { |
---|
230 | if ((*iter).second) |
---|
231 | (*iter).second->deactivateDeviceShape(name); |
---|
232 | } |
---|
233 | } |
---|
234 | |
---|
235 | void |
---|
236 | NvFlowVisRenderer::activateDeviceShape(const std::string& vfName) |
---|
237 | { |
---|
238 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
239 | if (iter != _vectorFieldMap.end()) { |
---|
240 | if ((*iter).second) |
---|
241 | (*iter).second->activateDeviceShape(); |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | void |
---|
246 | NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName) |
---|
247 | { |
---|
248 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
249 | if (iter != _vectorFieldMap.end()) { |
---|
250 | if ((*iter).second) |
---|
251 | (*iter).second->deactivateDeviceShape(); |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | void |
---|
256 | NvFlowVisRenderer::addDeviceShape(const std::string& vfName, const std::string& name, const NvDeviceShape& shape) |
---|
257 | { |
---|
258 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
259 | if (iter != _vectorFieldMap.end()) { |
---|
260 | if ((*iter).second) |
---|
261 | (*iter).second->addDeviceShape(name, shape); |
---|
262 | } |
---|
263 | } |
---|
264 | |
---|
265 | void |
---|
266 | NvFlowVisRenderer::removeDeviceShape(const std::string& vfName, const std::string& name) |
---|
267 | { |
---|
268 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
269 | if (iter != _vectorFieldMap.end()) { |
---|
270 | if ((*iter).second) |
---|
271 | (*iter).second->removeDeviceShape(name); |
---|
272 | } |
---|
273 | } |
---|