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 | |
---|
30 | NvFlowVisRenderer::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 | |
---|
46 | NvFlowVisRenderer::~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 | |
---|
62 | void |
---|
63 | NvFlowVisRenderer::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 | |
---|
72 | void |
---|
73 | NvFlowVisRenderer::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 | |
---|
82 | void |
---|
83 | NvFlowVisRenderer::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 | |
---|
95 | void |
---|
96 | NvFlowVisRenderer::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 | |
---|
105 | void |
---|
106 | NvFlowVisRenderer::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 | |
---|
115 | void |
---|
116 | NvFlowVisRenderer::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 | |
---|
134 | void |
---|
135 | NvFlowVisRenderer::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 | |
---|
142 | void |
---|
143 | NvFlowVisRenderer::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 | |
---|
150 | void |
---|
151 | NvFlowVisRenderer::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 | |
---|
160 | void |
---|
161 | NvFlowVisRenderer::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 | |
---|
172 | void |
---|
173 | NvFlowVisRenderer::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 | |
---|
180 | void |
---|
181 | NvFlowVisRenderer::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 | |
---|
188 | void |
---|
189 | NvFlowVisRenderer::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 | |
---|
196 | void |
---|
197 | NvFlowVisRenderer::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 | |
---|
206 | void |
---|
207 | NvFlowVisRenderer::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 | |
---|
215 | void |
---|
216 | NvFlowVisRenderer::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 | |
---|
224 | void |
---|
225 | NvFlowVisRenderer::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 | |
---|
233 | void |
---|
234 | NvFlowVisRenderer::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 | |
---|
242 | void |
---|
243 | NvFlowVisRenderer::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 | |
---|
251 | void |
---|
252 | NvFlowVisRenderer::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 | |
---|
260 | void |
---|
261 | NvFlowVisRenderer::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 | |
---|
269 | void |
---|
270 | NvFlowVisRenderer::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 | } |
---|