/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include #include using namespace osg; /////////////////////////////////////////////////////////////////////// // // TransferFunction base class // TransferFunction::TransferFunction() { } TransferFunction::TransferFunction(const TransferFunction& tf, const CopyOp& copyop): Object(tf,copyop) { } TransferFunction::~TransferFunction() { } /////////////////////////////////////////////////////////////////////// // // TransferFunction1D class // TransferFunction1D::TransferFunction1D() { } TransferFunction1D::TransferFunction1D(const TransferFunction1D& tf, const CopyOp& copyop): TransferFunction(tf,copyop) { allocate(tf.getNumberImageCells()); assign(_colorMap); } void TransferFunction1D::allocate(unsigned int numX) { _image = new osg::Image; _image->allocateImage(numX,1,1,GL_RGBA, GL_FLOAT); if (!_colorMap.empty()) assign(_colorMap); } void TransferFunction1D::clear(const osg::Vec4& color) { ColorMap newColours; newColours[getMinimum()] = color; newColours[getMaximum()] = color; assign(newColours); } void TransferFunction1D::assignToImage(float lower_v, const osg::Vec4& lower_c, float upper_v, const osg::Vec4& upper_c) { float minimum = _colorMap.begin()->first; float maximum = _colorMap.rbegin()->first; float endPos = float(getNumberImageCells()-1); float multiplier = endPos/(maximum - minimum); osg::Vec4* imageData = reinterpret_cast(_image->data()); float lower_iPos = (lower_v - minimum)*multiplier; float upper_iPos = (upper_v - minimum)*multiplier; float start_iPos = ceilf(lower_iPos); if (start_iPos<0.0f) start_iPos=0.0f; if (start_iPos>endPos) return; float end_iPos = floorf(upper_iPos); if (end_iPos<0.0f) return; if (end_iPos>endPos) end_iPos=endPos; //osg::notify(osg::NOTICE)<<"TransferFunction1D::assignToImage[lower_v="<