Changeset 13041 for OpenSceneGraph/trunk/include/osg/TransferFunction
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/TransferFunction (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/TransferFunction
r12139 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 24 24 25 25 /** TransferFunction is a class that provide a 1D,2D or 3D colour look up table 26 * that can be used on the GPU as a 1D, 2D or 3D texture. 27 * Typically uses include mapping heights to colours when contouring terrain, 26 * that can be used on the GPU as a 1D, 2D or 3D texture. 27 * Typically uses include mapping heights to colours when contouring terrain, 28 28 * or mapping intensities to colours when volume rendering. 29 29 */ … … 31 31 { 32 32 public : 33 33 34 34 TransferFunction(); 35 35 … … 44 44 /** Get the const image that is used for passing the transfer function data to the GPU.*/ 45 45 const osg::Image* getImage() const { return _image.get(); } 46 46 47 47 protected: 48 48 49 49 virtual ~TransferFunction(); 50 50 … … 56 56 { 57 57 public: 58 58 59 59 TransferFunction1D(); 60 60 61 61 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ 62 62 TransferFunction1D(const TransferFunction1D& tf, const CopyOp& copyop=CopyOp::SHALLOW_COPY); 63 63 64 64 META_Object(osg, TransferFunction1D) 65 65 66 66 /** Get the minimum transfer function value.*/ 67 67 float getMinimum() const { return _colorMap.empty() ? 0.0f : _colorMap.begin()->first; } 68 68 69 69 /** Get the maximum transfer function value.*/ 70 70 float getMaximum() const { return _colorMap.empty() ? 0.0f : _colorMap.rbegin()->first; } … … 76 76 /** Clear the whole range to just represent a single color.*/ 77 77 void clear(const osg::Vec4& color = osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 78 78 79 79 /** Get pixel value from the image. */ 80 80 osg::Vec4 getPixelValue(unsigned int i) const 81 81 { 82 82 if (_image.valid() && i<static_cast<unsigned int>(_image->s())) 83 { 83 { 84 84 return *reinterpret_cast<osg::Vec4*>(_image->data(i)); 85 85 } … … 97 97 * tracks the color map. Pass in false as the updateImage parameter if you are setting up many values 98 98 * at once to avoid recomputation of the image data, then once all setColor calls are made explictly call 99 * updateImage() to bring the osg::Image back into sync with the color map. */ 99 * updateImage() to bring the osg::Image back into sync with the color map. */ 100 100 void setColor(float v, const osg::Vec4& color, bool updateImage=true); 101 101 102 102 /** Get the color for a specified transfer function value, interpolating the value if no exact match is found.*/ 103 103 osg::Vec4 getColor(float v) const; 104 104 105 105 typedef std::map<float, osg::Vec4> ColorMap; 106 106 107 107 /** Get the color map that stores the mapping between the the transfer function value and the colour it maps to.*/ 108 108 ColorMap& getColorMap() { return _colorMap; } 109 109 110 110 /** Get the const color map that stores the mapping between the the transfer function value and the colour it maps to.*/ 111 111 const ColorMap& getColorMap() const { return _colorMap; } … … 113 113 /** Assign a color map and automatically update the image to make sure they are in sync.*/ 114 114 void assign(const ColorMap& vcm); 115 115 116 116 /** Manually update the associate osg::Image to represent the colors assigned in the color map.*/ 117 117 void updateImage(); 118 118 119 119 protected: 120 120 121 121 ColorMap _colorMap; 122 122 123 123 void assignToImage(float lower_v, const osg::Vec4& lower_c, float upper_v, const osg::Vec4& upper_c); 124 124 };
