Changeset 953 for trunk/vizservers/nanovis/ContourLineFilter.cpp
- Timestamp:
- Mar 12, 2008, 3:48:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/ContourLineFilter.cpp
r780 r953 13 13 14 14 ContourLineFilter::ContourLineFilter() 15 : _colorMap(0) 16 { 17 } 18 19 void ContourLineFilter::clear() 20 { 21 22 ContourLineFilter::ContourLineList::iterator iter; 23 for (iter = _lines.begin(); iter != _lines.end(); ++iter) 24 { 25 delete (*iter); 26 } 27 28 _lines.clear(); 29 } 30 31 R2Geometry* ContourLineFilter::create(float min, float max, int linecount, Vector3* vertices, int width, int height) 32 { 33 _lines.clear(); 34 35 float transtion = (max - min) / (linecount + 1); 36 37 float val; 38 int totalNumOfPoints = 0, numOfPoints; 39 for (int i = 1; i <= linecount; ++i) 40 { 41 val = min + i * transtion; 42 43 ContourLine* c = new ContourLine(val); 44 if(numOfPoints = c->createLine(width, height, vertices)) 45 { 46 totalNumOfPoints += numOfPoints; 47 _lines.push_back(c); 48 } 49 else 50 delete c; 51 } 52 53 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 54 Vector3* colorSet = 0; 55 if (_colorMap) 56 { 57 colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 58 } 59 60 ContourLineFilter::ContourLineList::iterator iter; 61 int index = 0, colorIndex = 0; 62 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) 63 { 64 std::list<Vector3>& lines = (*iter)->_points; 65 std::list<Vector3>::iterator iter2; 66 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) 67 { 68 if (_colorMap && (colorIndex < _colorMap->size())) 69 { 70 colorSet[index] = _colorMap->at(colorIndex); 71 } 72 else 73 { 74 //colorSet[index].set((*iter)->_value, (*iter)->_value, (*iter)->_value); 75 } 76 vertexSet[index] = (*iter2); 77 } 78 } 79 80 R2VertexBuffer* vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, totalNumOfPoints, 81 totalNumOfPoints * sizeof(Vector3), vertexSet, false); 82 R2VertexBuffer* colorBuffer = 0; 83 R2Geometry* geometry = 0; 84 if (_colorMap) 85 { 86 colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, totalNumOfPoints, 87 totalNumOfPoints * sizeof(Vector3), colorSet, false); 88 } 89 90 geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 91 92 clear(); 93 94 return geometry; 95 } 96 97 R2Geometry* ContourLineFilter::create(float min, float max, int linecount, Vector4* vertices, int width, int height) 98 { 99 _lines.clear(); 100 101 float transtion = (max - min) / (linecount + 1); 102 103 float val; 104 int totalNumOfPoints = 0, numOfPoints; 105 for (int i = 1; i <= linecount; ++i) 106 { 107 val = min + i * transtion; 108 109 ContourLine* c = new ContourLine(val); 110 if(numOfPoints = c->createLine(width, height, vertices)) 111 { 112 totalNumOfPoints += numOfPoints; 113 _lines.push_back(c); 114 } 115 else 116 delete c; 117 } 118 119 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 120 Vector3* colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 121 122 ContourLineFilter::ContourLineList::iterator iter; 123 int index = 0, colorIndex = 0; 124 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) 125 { 126 std::list<Vector3>& lines = (*iter)->_points; 127 std::list<Vector3>::iterator iter2; 128 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) 129 { 130 if (_colorMap && (colorIndex < _colorMap->size())) 131 { 132 colorSet[index] = _colorMap->at(colorIndex); 133 } 134 else 135 { 136 colorSet[index].set((*iter)->_value, (*iter)->_value, (*iter)->_value); 137 } 138 vertexSet[index] = (*iter2); 139 } 140 } 141 142 R2VertexBuffer* vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, totalNumOfPoints, 143 totalNumOfPoints * sizeof(Vector3), vertexSet, false); 144 R2VertexBuffer* colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, totalNumOfPoints, 145 totalNumOfPoints * sizeof(Vector3), colorSet, false); 146 R2Geometry* geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 147 148 clear(); 149 150 return geometry; 15 : _colorMap(0) 16 { 17 } 18 19 void 20 ContourLineFilter::clear() 21 { 22 23 ContourLineFilter::ContourLineList::iterator iter; 24 for (iter = _lines.begin(); iter != _lines.end(); ++iter) { 25 delete (*iter); 26 } 27 _lines.clear(); 28 } 29 30 R2Geometry* 31 ContourLineFilter::create(float min, float max, int linecount, 32 Vector3* vertices, int width, int height) 33 { 34 _lines.clear(); 35 36 float transtion = (max - min) / (linecount + 1); 37 38 float val; 39 int totalNumOfPoints = 0, numOfPoints; 40 for (int i = 1; i <= linecount; ++i) { 41 val = min + i * transtion; 42 43 ContourLine* c = new ContourLine(val); 44 numOfPoints = c->createLine(width, height, vertices); 45 if (numOfPoints != 0) { 46 totalNumOfPoints += numOfPoints; 47 _lines.push_back(c); 48 } else { 49 delete c; 50 } 51 } 52 53 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 54 Vector3* colorSet = 0; 55 if (_colorMap) { 56 colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 57 } 58 59 ContourLineFilter::ContourLineList::iterator iter; 60 unsigned int index = 0, colorIndex = 0; 61 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) { 62 std::list<Vector3>& lines = (*iter)->_points; 63 std::list<Vector3>::iterator iter2; 64 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) { 65 if (_colorMap && (colorIndex < _colorMap->size())) { 66 colorSet[index] = _colorMap->at(colorIndex); 67 } else { 68 //colorSet[index].set((*iter)->_value, (*iter)->_value, (*iter)->_value); 69 } 70 vertexSet[index] = (*iter2); 71 } 72 } 73 74 R2VertexBuffer* vertexBuffer; 75 vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, 76 totalNumOfPoints, 77 totalNumOfPoints * sizeof(Vector3), 78 vertexSet, false); 79 R2VertexBuffer* colorBuffer = 0; 80 R2Geometry* geometry = 0; 81 if (_colorMap) { 82 colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, 83 totalNumOfPoints, 84 totalNumOfPoints * sizeof(Vector3), 85 colorSet, false); 86 } 87 88 geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 89 clear(); 90 return geometry; 91 } 92 93 R2Geometry* 94 ContourLineFilter::create(float min, float max, int linecount, 95 Vector4* vertices, int width, int height) 96 { 97 _lines.clear(); 98 99 float transtion = (max - min) / (linecount + 1); 100 101 float val; 102 int totalNumOfPoints = 0, numOfPoints; 103 for (int i = 1; i <= linecount; ++i) { 104 val = min + i * transtion; 105 106 ContourLine* c = new ContourLine(val); 107 numOfPoints = c->createLine(width, height, vertices); 108 if (numOfPoints != 0) { 109 totalNumOfPoints += numOfPoints; 110 _lines.push_back(c); 111 } else { 112 delete c; 113 } 114 } 115 Vector3* vertexSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 116 Vector3* colorSet = (Vector3*) malloc(sizeof(Vector3) * totalNumOfPoints); 117 118 ContourLineFilter::ContourLineList::iterator iter; 119 unsigned int index = 0, colorIndex = 0; 120 for (iter = _lines.begin(); iter != _lines.end(); ++iter, ++colorIndex) { 121 std::list<Vector3>& lines = (*iter)->_points; 122 std::list<Vector3>::iterator iter2; 123 for (iter2 = lines.begin(); iter2 != lines.end(); ++iter2, ++index) { 124 if (_colorMap && (colorIndex < _colorMap->size())) { 125 colorSet[index] = _colorMap->at(colorIndex); 126 } else { 127 colorSet[index].set((*iter)->_value, (*iter)->_value, 128 (*iter)->_value); 129 } 130 vertexSet[index] = (*iter2); 131 } 132 } 133 R2VertexBuffer* vertexBuffer; 134 vertexBuffer = new R2VertexBuffer(R2VertexBuffer::POSITION3, 135 totalNumOfPoints, 136 totalNumOfPoints * sizeof(Vector3), 137 vertexSet, false); 138 R2VertexBuffer* colorBuffer; 139 colorBuffer = new R2VertexBuffer(R2VertexBuffer::COLOR4, totalNumOfPoints, 140 totalNumOfPoints * sizeof(Vector3), 141 colorSet, false); 142 R2Geometry* geometry; 143 geometry = new R2Geometry(R2Geometry::LINES, vertexBuffer, colorBuffer, 0); 144 clear(); 145 return geometry; 151 146 } 152 147 153 148 154 149 ContourLineFilter::ContourLine::ContourLine(float value) 155 : _value(value) 156 { 157 } 158 159 160 int ContourLineFilter::ContourLine::createLine(int width, int height, Vector3* vertices) 161 { 162 _points.clear(); 163 164 int hl = height - 1; 165 int wl = width - 1; 166 int index1, index2, index3, index4; 167 for (int i = 0; i < hl; ++i) 168 { 169 for (int j = 0; j < wl; ++j) 170 { 171 index1 = j + i * width; 172 index2 = j + 1 + i * width; 173 index3 = j + 1 + (i + 1) * width; 174 index4 = j + (i + 1) * width; 175 176 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) getContourPoint(index1, index2, vertices, width); 177 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) getContourPoint(index2, index3, vertices, width); 178 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) getContourPoint(index3, index1, vertices, width); 179 180 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) getContourPoint(index1, index3, vertices, width); 181 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) getContourPoint(index3, index4, vertices, width); 182 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) getContourPoint(index4, index1, vertices, width); 183 } 184 } 185 186 return _points.size(); 187 } 188 189 190 int ContourLineFilter::ContourLine::createLine(int width, int height, Vector4* vertices) 191 { 192 _points.clear(); 193 194 int hl = height - 1; 195 int wl = width - 1; 196 int index1, index2, index3, index4; 197 for (int i = 0; i < hl; ++i) 198 { 199 for (int j = 0; j < wl; ++j) 200 { 201 index1 = j + i * width; 202 index2 = j + 1 + i * width; 203 index3 = j + 1 + (i + 1) * width; 204 index4 = j + (i + 1) * width; 205 206 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) getContourPoint(index1, index2, vertices, width); 207 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) getContourPoint(index2, index3, vertices, width); 208 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) getContourPoint(index3, index1, vertices, width); 209 210 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) getContourPoint(index1, index3, vertices, width); 211 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) getContourPoint(index3, index4, vertices, width); 212 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) getContourPoint(index4, index1, vertices, width); 213 } 214 } 215 216 return _points.size(); 217 } 218 219 bool ContourLineFilter::ContourLine::isValueWithIn(float val1, float Val2) 220 { 221 return (_value >= val1 && _value <= Val2) || (_value >= Val2 && _value <= val1); 222 } 223 224 void ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, int vertexIndex2, Vector3* vertices, int width) 225 { 226 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 227 float t = 0.0; 228 if (diff != 0) 229 { 230 t = (_value - vertices[vertexIndex1].y) / diff; 231 } 232 233 Vector3 p; 234 p.x = vertices[vertexIndex1].x + t * (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 235 p.y = vertices[vertexIndex1].y + t * (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 236 p.z = vertices[vertexIndex1].z + t * (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 237 238 _points.push_back(p); 239 } 240 241 void ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, int vertexIndex2, Vector4* vertices, int width) 242 { 243 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 244 float t = 0.0; 245 if (diff != 0) 246 { 247 t = (_value - vertices[vertexIndex1].y) / diff; 248 } 249 250 Vector3 p; 251 p.x = vertices[vertexIndex1].x + t * (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 252 p.y = vertices[vertexIndex1].y + t * (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 253 p.z = vertices[vertexIndex1].z + t * (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 254 255 _points.push_back(p); 256 } 257 258 259 void ContourLineFilter::setColorMap(Vector3Array* colorMap) 260 { 261 if (colorMap == _colorMap) return; 262 263 if (colorMap && _colorMap) 264 { 265 if (colorMap->size() != _colorMap->size()) 266 { 267 _colorMap->resize(_colorMap->size()); 268 } 269 _colorMap->assign(colorMap->begin(), colorMap->end()); 270 } 271 else 272 { 273 delete _colorMap; 274 275 if (colorMap && colorMap->size()) 276 { 277 _colorMap = new Vector3Array(colorMap->size()); 278 _colorMap->assign(colorMap->begin(), colorMap->end()); 279 } 280 else 281 { 282 _colorMap = 0; 283 } 284 } 285 } 150 : _value(value) 151 { 152 } 153 154 155 int 156 ContourLineFilter::ContourLine::createLine(int width, int height, 157 Vector3* vertices) 158 { 159 _points.clear(); 160 161 int hl = height - 1; 162 int wl = width - 1; 163 int index1, index2, index3, index4; 164 for (int i = 0; i < hl; ++i) { 165 for (int j = 0; j < wl; ++j) { 166 index1 = j + i * width; 167 index2 = j + 1 + i * width; 168 index3 = j + 1 + (i + 1) * width; 169 index4 = j + (i + 1) * width; 170 171 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) 172 getContourPoint(index1, index2, vertices, width); 173 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) 174 getContourPoint(index2, index3, vertices, width); 175 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) 176 getContourPoint(index3, index1, vertices, width); 177 178 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) 179 getContourPoint(index1, index3, vertices, width); 180 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) 181 getContourPoint(index3, index4, vertices, width); 182 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) 183 getContourPoint(index4, index1, vertices, width); 184 } 185 } 186 return _points.size(); 187 } 188 189 190 int 191 ContourLineFilter::ContourLine::createLine(int width, int height, 192 Vector4* vertices) 193 { 194 _points.clear(); 195 196 int hl = height - 1; 197 int wl = width - 1; 198 int index1, index2, index3, index4; 199 for (int i = 0; i < hl; ++i) { 200 for (int j = 0; j < wl; ++j) { 201 index1 = j + i * width; 202 index2 = j + 1 + i * width; 203 index3 = j + 1 + (i + 1) * width; 204 index4 = j + (i + 1) * width; 205 206 if (isValueWithIn(vertices[index1].y, vertices[index2].y)) 207 getContourPoint(index1, index2, vertices, width); 208 if (isValueWithIn(vertices[index2].y, vertices[index3].y)) 209 getContourPoint(index2, index3, vertices, width); 210 if (isValueWithIn(vertices[index3].y, vertices[index1].y)) 211 getContourPoint(index3, index1, vertices, width); 212 213 if (isValueWithIn(vertices[index1].y, vertices[index3].y)) 214 getContourPoint(index1, index3, vertices, width); 215 if (isValueWithIn(vertices[index3].y, vertices[index4].y)) 216 getContourPoint(index3, index4, vertices, width); 217 if (isValueWithIn(vertices[index4].y, vertices[index1].y)) 218 getContourPoint(index4, index1, vertices, width); 219 } 220 } 221 222 return _points.size(); 223 } 224 225 bool 226 ContourLineFilter::ContourLine::isValueWithIn(float val1, float Val2) 227 { 228 return ((_value >= val1 && _value <= Val2) || 229 (_value >= Val2 && _value <= val1)); 230 } 231 232 void 233 ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, 234 int vertexIndex2, Vector3* vertices, int width) 235 { 236 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 237 float t = 0.0; 238 if (diff != 0) { 239 t = (_value - vertices[vertexIndex1].y) / diff; 240 } 241 242 Vector3 p; 243 p.x = vertices[vertexIndex1].x + t * 244 (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 245 p.y = vertices[vertexIndex1].y + t * 246 (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 247 p.z = vertices[vertexIndex1].z + t * 248 (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 249 _points.push_back(p); 250 } 251 252 void 253 ContourLineFilter::ContourLine::getContourPoint(int vertexIndex1, 254 int vertexIndex2, Vector4* vertices, int width) 255 { 256 float diff = vertices[vertexIndex2].y - vertices[vertexIndex1].y; 257 float t = 0.0; 258 if (diff != 0) { 259 t = (_value - vertices[vertexIndex1].y) / diff; 260 } 261 262 Vector3 p; 263 p.x = vertices[vertexIndex1].x + 264 t * (vertices[vertexIndex2].x - vertices[vertexIndex1].x); 265 p.y = vertices[vertexIndex1].y + 266 t * (vertices[vertexIndex2].y - vertices[vertexIndex1].y); 267 p.z = vertices[vertexIndex1].z + 268 t * (vertices[vertexIndex2].z - vertices[vertexIndex1].z); 269 _points.push_back(p); 270 } 271 272 273 void 274 ContourLineFilter::setColorMap(Vector3Array* colorMap) 275 { 276 if (colorMap == _colorMap) { 277 return; 278 } 279 if (colorMap && _colorMap) { 280 if (colorMap->size() != _colorMap->size()) { 281 _colorMap->resize(_colorMap->size()); 282 } 283 _colorMap->assign(colorMap->begin(), colorMap->end()); 284 } else { 285 delete _colorMap; 286 287 if (colorMap && colorMap->size()) { 288 _colorMap = new Vector3Array(colorMap->size()); 289 _colorMap->assign(colorMap->begin(), colorMap->end()); 290 } else { 291 _colorMap = 0; 292 } 293 } 294 }
Note: See TracChangeset
for help on using the changeset viewer.