Changeset 4358 for trunk/packages/vizservers
- Timestamp:
- May 21, 2014, 12:44:28 AM (10 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/ColorMap.cpp
r4073 r4358 143 143 { 144 144 _needsBuild = true; 145 // Clamp value to [0,1]145 // Clamp value,midpoint,sharpness to [0,1] 146 146 if (cp.value < 0.0) 147 147 cp.value = 0.0; 148 148 if (cp.value > 1.0) 149 cp.value = 1.0; 149 cp.value = 1.0; 150 if (cp.midpoint < 0.0) 151 cp.midpoint = 0.0; 152 if (cp.midpoint > 1.0) 153 cp.midpoint = 1.0; 154 if (cp.sharpness < 0.0) 155 cp.sharpness = 0.0; 156 if (cp.sharpness > 1.0) 157 cp.sharpness = 1.0; 150 158 151 159 #ifdef DEBUG 152 TRACE("New control point: %g = %g %g %g", 153 cp.value, cp.color[0], cp.color[1], cp.color[2]); 160 TRACE("New control point: %g = %g %g %g, %g %g", 161 cp.value, cp.color[0], cp.color[1], cp.color[2], 162 cp.midpoint, cp.sharpness); 154 163 #endif 155 164 for (std::list<ControlPoint>::iterator itr = _controlPoints.begin(); 156 157 158 159 160 161 162 163 165 itr != _controlPoints.end(); ++itr) { 166 if (itr->value == cp.value) { 167 *itr = cp; 168 return; 169 } else if (itr->value > cp.value) { 170 _controlPoints.insert(itr, cp); 171 return; 172 } 164 173 } 165 174 // If we reach here, our control point goes at the end 166 175 _controlPoints.insert(_controlPoints.end(), cp); 167 _colorTF->AddRGBPoint(cp.value, cp.color[0], cp.color[1], cp.color[2]); 176 _colorTF->AddRGBPoint(cp.value, cp.color[0], cp.color[1], cp.color[2], 177 cp.midpoint, cp.sharpness); 168 178 } 169 179 … … 174 184 { 175 185 _needsBuild = true; 176 // Clamp value to [0,1]186 // Clamp value,midpoint,sharpness to [0,1] 177 187 if (cp.value < 0.0) 178 188 cp.value = 0.0; 179 189 if (cp.value > 1.0) 180 cp.value = 1.0; 190 cp.value = 1.0; 191 if (cp.midpoint < 0.0) 192 cp.midpoint = 0.0; 193 if (cp.midpoint > 1.0) 194 cp.midpoint = 1.0; 195 if (cp.sharpness < 0.0) 196 cp.sharpness = 0.0; 197 if (cp.sharpness > 1.0) 198 cp.sharpness = 1.0; 181 199 182 200 #ifdef DEBUG 183 TRACE("New opacity control point: %g = %g ",184 cp.value, cp.alpha);201 TRACE("New opacity control point: %g = %g, %g %g", 202 cp.value, cp.alpha, cp.midpoint, cp.sharpness); 185 203 #endif 186 204 for (std::list<OpacityControlPoint>::iterator itr = _opacityControlPoints.begin(); 187 188 189 190 191 192 193 194 205 itr != _opacityControlPoints.end(); ++itr) { 206 if (itr->value == cp.value) { 207 *itr = cp; 208 return; 209 } else if (itr->value > cp.value) { 210 _opacityControlPoints.insert(itr, cp); 211 return; 212 } 195 213 } 196 214 // If we reach here, our control point goes at the end 197 215 _opacityControlPoints.insert(_opacityControlPoints.end(), cp); 198 _opacityTF->AddPoint(cp.value, cp.alpha );216 _opacityTF->AddPoint(cp.value, cp.alpha, cp.midpoint, cp.sharpness); 199 217 } 200 218 … … 209 227 { 210 228 if (numEntries != _numTableEntries) { 211 212 213 214 215 229 _needsBuild = true; 230 _numTableEntries = numEntries; 231 if (_lookupTable != NULL) { 232 build(); 233 } 216 234 } 217 235 } … … 228 246 return _numTableEntries; 229 247 } 230 248 #if 0 231 249 /** 232 250 * \brief Build the lookup table from the control points in the transfer … … 236 254 { 237 255 if (!_needsBuild) 238 256 return; 239 257 240 258 TRACE("%s", _name.c_str()); 241 259 242 260 if (_lookupTable == NULL) { 243 261 _lookupTable = vtkSmartPointer<vtkLookupTable>::New(); 244 262 } 245 263 … … 252 270 // constant range up to first specified cp 253 271 if (itr->value > 0.0) { 254 255 256 272 ControlPoint cp = *itr; 273 cp.value = 0.0; 274 itr = _controlPoints.insert(itr, cp); 257 275 } 258 276 if (oitr->value > 0.0) { 259 260 261 277 OpacityControlPoint ocp = *oitr; 278 ocp.value = 0.0; 279 oitr = _opacityControlPoints.insert(oitr, ocp); 262 280 } 263 281 … … 268 286 269 287 for (int i = 0; i < _numTableEntries; i++) { 270 288 double value = _numTableEntries < 2 ? 0.0 : ((double)i)/(_numTableEntries-1); 271 289 double color[4]; 272 273 274 275 276 277 278 279 280 290 while (itr2 != _controlPoints.end() && value > itr2->value) { 291 itr = itr2; 292 itr2++; 293 } 294 while (oitr2 != _opacityControlPoints.end() && value > oitr2->value) { 295 oitr = oitr2; 296 oitr2++; 297 } 298 if (itr2 == _controlPoints.end()) { 281 299 #ifdef DEBUG 282 283 300 TRACE("val: %g Range: %g - 1 Color: %g %g %g", value, itr->value, 301 itr->color[0], itr->color[1], itr->color[2]); 284 302 #endif 285 303 memcpy(color, itr->color, sizeof(double)*3); 286 287 288 289 304 } else { 305 assert(itr->value < itr2->value); 306 assert(value >= itr->value && value <= itr2->value); 307 lerp(color, *itr, *itr2, value); 290 308 #ifdef DEBUG 291 292 309 TRACE("val: %g Range: %g - %g Color: %g %g %g", value, itr->value, itr2->value, 310 color[0], color[1], color[2]); 293 311 #endif 294 295 312 } 313 if (oitr2 == _opacityControlPoints.end()) { 296 314 #ifdef DEBUG 297 298 315 TRACE("val: %g Range: %g - 1 Alpha %g", value, oitr->value, 316 oitr->alpha); 299 317 #endif 300 318 color[3] = oitr->alpha; 301 302 303 304 319 } else { 320 assert(oitr->value < oitr2->value); 321 assert(value >= oitr->value && value <= oitr2->value); 322 lerp(&color[3], *oitr, *oitr2, value); 305 323 #ifdef DEBUG 306 307 324 TRACE("val: %g Range: %g - %g Alpha: %g", value, oitr->value, oitr2->value, 325 color[3]); 308 326 #endif 309 327 } 310 328 _lookupTable->SetTableValue(i, color); 311 329 } … … 313 331 TRACE("Leave"); 314 332 } 315 333 #else 334 /** 335 * \brief Build the lookup table from the control points in the transfer 336 * function 337 */ 338 void ColorMap::build() 339 { 340 if (!_needsBuild) 341 return; 342 343 TRACE("%s", _name.c_str()); 344 345 if (_lookupTable == NULL) { 346 _lookupTable = vtkSmartPointer<vtkLookupTable>::New(); 347 } 348 349 _lookupTable->SetNumberOfTableValues(_numTableEntries); 350 351 double colorTable[_numTableEntries*3]; 352 _colorTF->GetTable(0., 1., _numTableEntries, colorTable); 353 double opacityTable[_numTableEntries]; 354 _opacityTF->GetTable(0., 1., _numTableEntries, opacityTable, 1); 355 356 for (int i = 0; i < _numTableEntries; i++) { 357 //double value = _numTableEntries < 2 ? 0.0 : ((double)i)/(_numTableEntries-1); 358 double color[4]; 359 memcpy(color, colorTable+i*3, sizeof(double)*3); 360 color[3] = opacityTable[i]; 361 _lookupTable->SetTableValue(i, color); 362 } 363 _needsBuild = false; 364 TRACE("Leave"); 365 } 366 #endif 316 367 /** 317 368 * \brief Perform linear interpolation of two color control points … … 324 375 double factor = (value - cp1.value) / (cp2.value - cp1.value); 325 376 for (int i = 0; i < 3; i++) { 326 377 result[i] = cp1.color[i] * (1.0 - factor) + cp2.color[i] * factor; 327 378 } 328 379 } … … 384 435 cp[4].color[2] = 0.0; 385 436 for (int i = 0; i < 5; i++) { 386 437 _default->addControlPoint(cp[i]); 387 438 } 388 439 OpacityControlPoint ocp[2]; … … 462 513 cp[4].color[2] = 0.0; 463 514 for (int i = 0; i < 5; i++) { 464 515 _volumeDefault->addControlPoint(cp[i]); 465 516 } 466 517 OpacityControlPoint ocp[2]; -
trunk/packages/vizservers/vtkvis/ColorMap.h
r4073 r4358 34 34 struct ControlPoint { 35 35 ControlPoint() : 36 value(0) 36 value(0), 37 midpoint(0.5), 38 sharpness(0) 37 39 { 38 40 memset(color, 0, sizeof(double)*3); 39 41 } 40 42 ControlPoint(const ControlPoint& other) : 41 value(other.value) 43 value(other.value), 44 midpoint(other.midpoint), 45 sharpness(other.sharpness) 42 46 { 43 47 memcpy(color, other.color, sizeof(double)*3); … … 47 51 if (this != &other) { 48 52 value = other.value; 53 midpoint = other.midpoint; 54 sharpness = other.sharpness; 49 55 memcpy(color, other.color, sizeof(double)*3); 50 56 } … … 53 59 54 60 double value; ///< Normalized scalar data value [0,1] 61 double midpoint, sharpness; 55 62 double color[3]; ///< RGB color 56 63 }; … … 62 69 OpacityControlPoint() : 63 70 value(0), 71 midpoint(0.5), 72 sharpness(0), 64 73 alpha(1) 65 74 { … … 67 76 OpacityControlPoint(const OpacityControlPoint& other) : 68 77 value(other.value), 78 midpoint(other.midpoint), 79 sharpness(other.sharpness), 69 80 alpha(other.alpha) 70 81 { … … 74 85 if (this != &other) { 75 86 value = other.value; 87 midpoint = other.midpoint; 88 sharpness = other.sharpness; 76 89 alpha = other.alpha; 77 90 } … … 80 93 81 94 double value; ///< Normalized scalar data value [0,1] 95 double midpoint, sharpness; 82 96 double alpha; ///< Opacity 83 97 };
Note: See TracChangeset
for help on using the changeset viewer.