/* -*-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(tf._colorMap); } void TransferFunction1D::allocate(unsigned int numX) { _image = new osg::Image; _image->allocateImage(numX,1,1,GL_RGBA, GL_FLOAT); updateImage(); } 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) { int endPos = getNumberImageCells()-1; float minimum = _colorMap.begin()->first; float maximum = _colorMap.rbegin()->first; float multiplier = float(endPos)/(maximum - minimum); osg::Vec4* imageData = reinterpret_cast(_image->data()); float lower_iPos = (lower_v - minimum)*multiplier; float upper_iPos = (upper_v - minimum)*multiplier; int start_iPos = static_cast(ceilf(lower_iPos)); if (start_iPos < 0) start_iPos = 0; if (start_iPos > endPos) return; int end_iPos = static_cast(floorf(upper_iPos)); if (end_iPos < 0) return; if (end_iPos > endPos) end_iPos = endPos; //OSG_NOTICE<<"TransferFunction1D::assignToImage[lower_v="<