Changeset 2802 for trunk/packages/vizservers
- Timestamp:
- Mar 6, 2012, 2:28:39 AM (13 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/ParticleSystem.h
r2800 r2802 8 8 #include <limits> 9 9 10 #include <GL/glew.h> 10 11 #include <Cg/cg.h> 11 12 #include <Cg/cgGL.h> -
trunk/packages/vizservers/nanovis/ParticleSystemFactory.cpp
r2798 r2802 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 3 #include <vrutil/vrFilePath.h> 4 2 5 #include "ParticleSystemFactory.h" 3 6 #include "ParticleSystem.h" 4 #include <vrutil/vrFilePath.h> 7 5 8 #include <stdio.h> 6 9 #include "Trace.h" … … 26 29 void ParticleSystemFactory::startElement(void *userData, const char *elementName, const char **attrs) 27 30 { 28 ParticleSystemFactory* This = reinterpret_cast<ParticleSystemFactory*>(userData); 29 30 if (!strcmp(elementName, "particle-sys-info")) 31 { 32 This->parseParticleSysInfo(attrs); 33 } 34 else if (!strcmp(elementName, "emitter")) 35 { 36 This->parseEmitterInfo(attrs); 37 } 31 ParticleSystemFactory* This = reinterpret_cast<ParticleSystemFactory*>(userData); 32 33 if (!strcmp(elementName, "particle-sys-info")) { 34 This->parseParticleSysInfo(attrs); 35 } else if (!strcmp(elementName, "emitter")) { 36 This->parseEmitterInfo(attrs); 37 } 38 38 } 39 39 … … 42 42 } 43 43 44 ParticleSystemFactory::ParticleSystemFactory() 45 :_newParticleSystem(0)44 ParticleSystemFactory::ParticleSystemFactory() : 45 _newParticleSystem(0) 46 46 { 47 47 } … … 53 53 ParticleSystem* ParticleSystemFactory::create(const std::string& fileName) 54 54 { 55 FILE* fp = fopen(fileName.c_str(), "rb"); 56 57 if (fp == 0) { 58 return 0; 59 } 60 XML_Parser parser = XML_ParserCreate(NULL); 61 62 XML_SetUserData(parser, this); 63 XML_SetElementHandler(parser, startElement, endElement); 64 65 size_t stat; 66 size_t cnt; 67 68 while(! feof(fp)) 69 { 70 void *buff = XML_GetBuffer(parser, BUFSIZE); 71 if (! buff) 72 { 73 break; 74 } 75 cnt = fread(buff, 1, BUFSIZE, fp); 76 stat = XML_ParseBuffer(parser, (int) cnt, 0); 77 if (!stat) 78 { 79 //TRACE("Parse error at line %d\n", XML_GetCurrentLineNumber(parser)); 80 break; 81 } 82 } 83 84 fclose(fp); 85 86 XML_ParserFree(parser); 87 88 return _newParticleSystem; 55 FILE* fp = fopen(fileName.c_str(), "rb"); 56 57 if (fp == 0) { 58 return 0; 59 } 60 XML_Parser parser = XML_ParserCreate(NULL); 61 62 XML_SetUserData(parser, this); 63 XML_SetElementHandler(parser, startElement, endElement); 64 65 size_t stat; 66 size_t cnt; 67 68 while(! feof(fp)) { 69 void *buff = XML_GetBuffer(parser, BUFSIZE); 70 if (! buff) { 71 break; 72 } 73 cnt = fread(buff, 1, BUFSIZE, fp); 74 stat = XML_ParseBuffer(parser, (int) cnt, 0); 75 if (!stat) { 76 //TRACE("Parse error at line %d\n", XML_GetCurrentLineNumber(parser)); 77 break; 78 } 79 } 80 81 fclose(fp); 82 83 XML_ParserFree(parser); 84 85 return _newParticleSystem; 89 86 } 90 87 91 88 void ParticleSystemFactory::parseParticleSysInfo(const char** attrs) 92 89 { 93 int width = 2, height = 2; // default 94 std::string fileName = "J-wire-vec.dx"; 95 float pointSize = -1.0f; 96 int numOfUsedParticles = -1; 97 bool sortEnabled = false; 98 bool glypEnabled = false; 99 bool bboxVisible = false; 100 bool advectionEnabled = false; 101 bool streamlineEnabled = false; 102 bool timeVaryingData = false; 103 int fieldWidth = 1; 104 int fieldHeight = 1; 105 int fieldDepth = 1; 106 // TBD.. 107 //float timeSeries_vel_mag_min; 108 //float timeSeries_vel_mag_max; 109 //float timeSeriesVelMagMax; 110 int startIndex = -1, endIndex = -1; 111 for (int i = 0; attrs[i]; i += 2) { 112 if (!strcmp(attrs[i], "rendertarget-width")) 113 { 114 width = atoi(attrs[i + 1]); 115 } 116 else if (!strcmp(attrs[i], "rendertarget-height")) 117 { 118 height = atoi(attrs[i + 1]); 119 } 120 else if (!strcmp(attrs[i], "particle-point-size")) 121 { 122 pointSize = (float) atof(attrs[i + 1]); 123 } 124 else if (!strcmp(attrs[i], "vector-field-x")) 125 { 126 fieldWidth = (float) atof(attrs[i + 1]); 127 } 128 else if (!strcmp(attrs[i], "vector-field-y")) 129 { 130 fieldHeight = (float) atof(attrs[i + 1]); 131 } 132 else if (!strcmp(attrs[i], "vector-field-z")) 133 { 134 fieldDepth = (float) atof(attrs[i + 1]); 135 } 136 else if (!strcmp(attrs[i], "sort-enabled")) 137 { 138 if (!strcmp(attrs[i + 1], "true")) 139 sortEnabled = true; 140 } 141 else if (!strcmp(attrs[i], "glyp-enabled")) 142 { 143 if (!strcmp(attrs[i + 1], "true")) 144 glypEnabled = true; 145 } 146 else if (!strcmp(attrs[i], "bbox-draw-enabled")) 147 { 148 if (!strcmp(attrs[i + 1], "true")) 149 bboxVisible = true; 150 } 151 else if (!strcmp(attrs[i], "advection-enabled")) 152 { 153 if (!strcmp(attrs[i + 1], "true")) 154 advectionEnabled = true; 155 } 156 else if (!strcmp(attrs[i], "stream-line-enabled")) 157 { 158 if (!strcmp(attrs[i + 1], "true")) 159 streamlineEnabled = true; 160 } 161 else if (!strcmp(attrs[i], "vector-field")) 162 { 163 fileName = attrs[i + 1]; 164 } 165 else if (!strcmp(attrs[i], "vector-field")) 166 { 167 if (!strcmp(attrs[i + 1], "true")) 168 timeVaryingData = true; 169 } 170 else if (!strcmp(attrs[i], "particle-user-num")) 171 { 172 numOfUsedParticles = atoi(attrs[i + 1]); 173 } 174 else if (!strcmp(attrs[i], "time-series-start-index")) 175 { 176 startIndex = atoi(attrs[i + 1]); 177 } 178 else if (!strcmp(attrs[i], "time-series-end-index")) 179 { 180 endIndex = atoi(attrs[i + 1]); 181 } 182 else if (!strcmp(attrs[i], "time-varying")) 183 { 184 if (!strcmp(attrs[i + 1], "true")) 185 timeVaryingData = true; 186 } 187 188 } 189 190 if (timeVaryingData) 191 { 192 char buff[256]; 193 sprintf(buff, fileName.c_str(), startIndex); 194 std::string path = vrFilePath::getInstance()->getPath(buff); 195 if (path.size()) 196 { 197 std::string dir; 198 int index = path.rfind('/'); 199 if (index == -1) { 200 index = path.rfind('\\'); 201 if (index == -1) 202 TRACE("file not found\n"); 203 } 204 205 dir = path.substr(0, index + 1); 206 path = dir + fileName; 207 208 _newParticleSystem = new ParticleSystem(width, height, path.c_str(), fieldWidth, fieldHeight, fieldDepth, timeVaryingData, startIndex, endIndex); 209 } 210 else 211 { 212 _newParticleSystem = new ParticleSystem(width, height, fileName.c_str(), fieldWidth, fieldHeight, fieldDepth, timeVaryingData, startIndex, endIndex); 213 } 214 } 215 else 216 { 217 std::string path = vrFilePath::getInstance()->getPath(fileName.c_str()); 218 _newParticleSystem = new ParticleSystem(width, height, path.c_str(), fieldWidth, fieldHeight, fieldDepth, timeVaryingData, startIndex, endIndex); 219 } 220 221 if (pointSize != -1.0f) _newParticleSystem->setDefaultPointSize(pointSize); 222 if (sortEnabled) _newParticleSystem->enable(ParticleSystem::PS_SORT); 223 if (glypEnabled) _newParticleSystem->enable(ParticleSystem::PS_GLYPE); 224 if (bboxVisible) _newParticleSystem->enable(ParticleSystem::PS_DRAW_BBOX); 225 if (advectionEnabled) _newParticleSystem->enable(ParticleSystem::PS_ADVECTION); 226 if (streamlineEnabled) _newParticleSystem->enable(ParticleSystem::PS_STREAMLINE); 227 if (numOfUsedParticles != -1) _newParticleSystem->setUserDefinedNumOfParticles(numOfUsedParticles); 90 int width = 2, height = 2; // default 91 std::string fileName = "J-wire-vec.dx"; 92 float pointSize = -1.0f; 93 int numOfUsedParticles = -1; 94 bool sortEnabled = false; 95 bool glypEnabled = false; 96 bool bboxVisible = false; 97 bool advectionEnabled = false; 98 bool streamlineEnabled = false; 99 bool timeVaryingData = false; 100 int fieldWidth = 1; 101 int fieldHeight = 1; 102 int fieldDepth = 1; 103 // TBD.. 104 //float timeSeries_vel_mag_min; 105 //float timeSeries_vel_mag_max; 106 //float timeSeriesVelMagMax; 107 int startIndex = -1, endIndex = -1; 108 for (int i = 0; attrs[i]; i += 2) { 109 if (!strcmp(attrs[i], "rendertarget-width")) { 110 width = atoi(attrs[i + 1]); 111 } else if (!strcmp(attrs[i], "rendertarget-height")) { 112 height = atoi(attrs[i + 1]); 113 } else if (!strcmp(attrs[i], "particle-point-size")) { 114 pointSize = (float) atof(attrs[i + 1]); 115 } else if (!strcmp(attrs[i], "vector-field-x")) { 116 fieldWidth = (float) atof(attrs[i + 1]); 117 } else if (!strcmp(attrs[i], "vector-field-y")) { 118 fieldHeight = (float) atof(attrs[i + 1]); 119 } else if (!strcmp(attrs[i], "vector-field-z")) { 120 fieldDepth = (float) atof(attrs[i + 1]); 121 } else if (!strcmp(attrs[i], "sort-enabled")) { 122 if (!strcmp(attrs[i + 1], "true")) 123 sortEnabled = true; 124 } else if (!strcmp(attrs[i], "glyp-enabled")) { 125 if (!strcmp(attrs[i + 1], "true")) 126 glypEnabled = true; 127 } else if (!strcmp(attrs[i], "bbox-draw-enabled")) { 128 if (!strcmp(attrs[i + 1], "true")) 129 bboxVisible = true; 130 } else if (!strcmp(attrs[i], "advection-enabled")) { 131 if (!strcmp(attrs[i + 1], "true")) 132 advectionEnabled = true; 133 } else if (!strcmp(attrs[i], "stream-line-enabled")) { 134 if (!strcmp(attrs[i + 1], "true")) 135 streamlineEnabled = true; 136 } else if (!strcmp(attrs[i], "vector-field")) { 137 fileName = attrs[i + 1]; 138 } else if (!strcmp(attrs[i], "vector-field")) { 139 if (!strcmp(attrs[i + 1], "true")) 140 timeVaryingData = true; 141 } else if (!strcmp(attrs[i], "particle-user-num")) { 142 numOfUsedParticles = atoi(attrs[i + 1]); 143 } else if (!strcmp(attrs[i], "time-series-start-index")) { 144 startIndex = atoi(attrs[i + 1]); 145 } else if (!strcmp(attrs[i], "time-series-end-index")) { 146 endIndex = atoi(attrs[i + 1]); 147 } else if (!strcmp(attrs[i], "time-varying")) { 148 if (!strcmp(attrs[i + 1], "true")) 149 timeVaryingData = true; 150 } 151 } 152 153 if (timeVaryingData) { 154 char buff[256]; 155 sprintf(buff, fileName.c_str(), startIndex); 156 std::string path = vrFilePath::getInstance()->getPath(buff); 157 if (path.size()) { 158 std::string dir; 159 int index = path.rfind('/'); 160 if (index == -1) { 161 index = path.rfind('\\'); 162 if (index == -1) 163 TRACE("file not found\n"); 164 } 165 166 dir = path.substr(0, index + 1); 167 path = dir + fileName; 168 169 _newParticleSystem = new ParticleSystem(width, height, path.c_str(), fieldWidth, fieldHeight, fieldDepth, timeVaryingData, startIndex, endIndex); 170 } else { 171 _newParticleSystem = new ParticleSystem(width, height, fileName.c_str(), fieldWidth, fieldHeight, fieldDepth, timeVaryingData, startIndex, endIndex); 172 } 173 } else { 174 std::string path = vrFilePath::getInstance()->getPath(fileName.c_str()); 175 _newParticleSystem = new ParticleSystem(width, height, path.c_str(), fieldWidth, fieldHeight, fieldDepth, timeVaryingData, startIndex, endIndex); 176 } 177 178 if (pointSize != -1.0f) _newParticleSystem->setDefaultPointSize(pointSize); 179 if (sortEnabled) _newParticleSystem->enable(ParticleSystem::PS_SORT); 180 if (glypEnabled) _newParticleSystem->enable(ParticleSystem::PS_GLYPE); 181 if (bboxVisible) _newParticleSystem->enable(ParticleSystem::PS_DRAW_BBOX); 182 if (advectionEnabled) _newParticleSystem->enable(ParticleSystem::PS_ADVECTION); 183 if (streamlineEnabled) _newParticleSystem->enable(ParticleSystem::PS_STREAMLINE); 184 if (numOfUsedParticles != -1) _newParticleSystem->setUserDefinedNumOfParticles(numOfUsedParticles); 228 185 } 229 186 230 187 void ParticleSystemFactory::parseEmitterInfo(const char** attrs) 231 188 { 232 ParticleEmitter* emitter = new ParticleEmitter; 233 for (int i = 0; attrs[i]; i += 2) { 234 if (!strcmp(attrs[i], "max-position-offset")) 235 { 236 float x = 0, y = 0, z = 0; 237 sscanf(attrs[i+1], "%f%f%f",&x, &y, &z); 238 emitter->setMaxPositionOffset(x, y, z); 239 } 240 else if (!strcmp(attrs[i], "position")) 241 { 242 float x = 0, y = 0, z = 0; 243 sscanf(attrs[i+1], "%f%f%f",&x, &y, &z); 244 emitter->setPosition(x, y, z); 245 } 246 else if (!strcmp(attrs[i], "min-max-life-time")) 247 { 248 float min = 0, max = 0; 249 sscanf(attrs[i+1], "%f%f",&min, &max); 250 emitter->setMinMaxLifeTime(min, max); 251 } 252 else if (!strcmp(attrs[i], "min-max-new-particles")) 253 { 254 int min = 0, max = 0; 255 sscanf(attrs[i+1], "%d%d",&min, &max); 256 emitter->setMinMaxNumOfNewParticles(min, max); 257 } 258 else if (!strcmp(attrs[i], "enabled")) 259 { 260 if (!strcmp(attrs[i + 1], "true")) 261 emitter->setEnabled(true); 262 else 263 emitter->setEnabled(false); 264 } 265 } 266 _newParticleSystem->addEmitter(emitter); 267 } 189 ParticleEmitter* emitter = new ParticleEmitter; 190 for (int i = 0; attrs[i]; i += 2) { 191 if (!strcmp(attrs[i], "max-position-offset")) { 192 float x = 0, y = 0, z = 0; 193 sscanf(attrs[i+1], "%f%f%f",&x, &y, &z); 194 emitter->setMaxPositionOffset(x, y, z); 195 } else if (!strcmp(attrs[i], "position")) { 196 float x = 0, y = 0, z = 0; 197 sscanf(attrs[i+1], "%f%f%f",&x, &y, &z); 198 emitter->setPosition(x, y, z); 199 } else if (!strcmp(attrs[i], "min-max-life-time")) { 200 float min = 0, max = 0; 201 sscanf(attrs[i+1], "%f%f",&min, &max); 202 emitter->setMinMaxLifeTime(min, max); 203 } else if (!strcmp(attrs[i], "min-max-new-particles")) { 204 int min = 0, max = 0; 205 sscanf(attrs[i+1], "%d%d",&min, &max); 206 emitter->setMinMaxNumOfNewParticles(min, max); 207 } else if (!strcmp(attrs[i], "enabled")) { 208 if (!strcmp(attrs[i + 1], "true")) 209 emitter->setEnabled(true); 210 else 211 emitter->setEnabled(false); 212 } 213 } 214 _newParticleSystem->addEmitter(emitter); 215 }
Note: See TracChangeset
for help on using the changeset viewer.