Moved osgVolume::ImageUtils to osg::ImageUtils, updated wrappers, and started moving osgvolume example across to create osgVolume subgraphs
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
#ifndef OSGVOLUME_IMAGEUTILS
|
||||
#define OSGVOLUME_IMAGEUTILS 1
|
||||
|
||||
#include <osgVolume/Export>
|
||||
|
||||
#include <osg/Image>
|
||||
|
||||
namespace osgVolume {
|
||||
|
||||
template <typename T, class O>
|
||||
void _readRow(unsigned int num, GLenum pixelFormat, const T* data,float scale, O& operation)
|
||||
{
|
||||
switch(pixelFormat)
|
||||
{
|
||||
case(GL_LUMINANCE): { for(unsigned int i=0;i<num;++i) { float l = float(*data++)*scale; operation.luminance(l); } } break;
|
||||
case(GL_ALPHA): { for(unsigned int i=0;i<num;++i) { float a = float(*data++)*scale; operation.alpha(a); } } break;
|
||||
case(GL_LUMINANCE_ALPHA): { for(unsigned int i=0;i<num;++i) { float l = float(*data++)*scale; float a = float(*data++)*scale; operation.luminance_alpha(l,a); } } break;
|
||||
case(GL_RGB): { for(unsigned int i=0;i<num;++i) { float r = float(*data++)*scale; float g = float(*data++)*scale; float b = float(*data++)*scale; operation.rgb(r,g,b); } } break;
|
||||
case(GL_RGBA): { for(unsigned int i=0;i<num;++i) { float r = float(*data++)*scale; float g = float(*data++)*scale; float b = float(*data++)*scale; float a = float(*data++)*scale; operation.rgba(r,g,b,a); } } break;
|
||||
case(GL_BGR): { for(unsigned int i=0;i<num;++i) { float b = float(*data++)*scale; float g = float(*data++)*scale; float r = float(*data++)*scale; operation.rgb(r,g,b); } } break;
|
||||
case(GL_BGRA): { for(unsigned int i=0;i<num;++i) { float b = float(*data++)*scale; float g = float(*data++)*scale; float r = float(*data++)*scale; float a = float(*data++)*scale; operation.rgba(r,g,b,a); } } break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class O>
|
||||
void readRow(unsigned int num, GLenum pixelFormat, GLenum dataType, const unsigned char* data, O& operation)
|
||||
{
|
||||
switch(dataType)
|
||||
{
|
||||
case(GL_BYTE): _readRow(num,pixelFormat, (const char*)data, 1.0f/128.0f, operation); break;
|
||||
case(GL_UNSIGNED_BYTE): _readRow(num,pixelFormat, (const unsigned char*)data, 1.0f/255.0f, operation); break;
|
||||
case(GL_SHORT): _readRow(num,pixelFormat, (const short*) data, 1.0f/32768.0f, operation); break;
|
||||
case(GL_UNSIGNED_SHORT): _readRow(num,pixelFormat, (const unsigned short*)data, 1.0f/65535.0f, operation); break;
|
||||
case(GL_INT): _readRow(num,pixelFormat, (const int*) data, 1.0f/2147483648.0f, operation); break;
|
||||
case(GL_UNSIGNED_INT): _readRow(num,pixelFormat, (const unsigned int*) data, 1.0f/4294967295.0f, operation); break;
|
||||
case(GL_FLOAT): _readRow(num,pixelFormat, (const float*) data, 1.0f, operation); break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class O>
|
||||
void readImage(const osg::Image* image, O& operation)
|
||||
{
|
||||
if (!image) return;
|
||||
|
||||
for(int r=0;r<image->r();++r)
|
||||
{
|
||||
for(int t=0;t<image->t();++t)
|
||||
{
|
||||
readRow(image->s(), image->getPixelFormat(), image->getDataType(), image->data(0,t,r), operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// example ModifyOperator
|
||||
// struct ModifyOperator
|
||||
// {
|
||||
// inline void luminance(float& l) const {}
|
||||
// inline void alpha(float& a) const {}
|
||||
// inline void luminance_alpha(float& l,float& a) const {}
|
||||
// inline void rgb(float& r,float& g,float& b) const {}
|
||||
// inline void rgba(float& r,float& g,float& b,float& a) const {}
|
||||
// };
|
||||
|
||||
|
||||
template <typename T, class M>
|
||||
void _modifyRow(unsigned int num, GLenum pixelFormat, T* data,float scale, const M& operation)
|
||||
{
|
||||
float inv_scale = 1.0f/scale;
|
||||
switch(pixelFormat)
|
||||
{
|
||||
case(GL_LUMINANCE): { for(unsigned int i=0;i<num;++i) { float l = float(*data)*scale; operation.luminance(l); *data++ = T(l*inv_scale); } } break;
|
||||
case(GL_ALPHA): { for(unsigned int i=0;i<num;++i) { float a = float(*data)*scale; operation.alpha(a); *data++ = T(a*inv_scale); } } break;
|
||||
case(GL_LUMINANCE_ALPHA): { for(unsigned int i=0;i<num;++i) { float l = float(*data)*scale; float a = float(*(data+1))*scale; operation.luminance_alpha(l,a); *data++ = T(l*inv_scale); *data++ = T(a*inv_scale); } } break;
|
||||
case(GL_RGB): { for(unsigned int i=0;i<num;++i) { float r = float(*data)*scale; float g = float(*(data+1))*scale; float b = float(*(data+2))*scale; operation.rgb(r,g,b); *data++ = T(r*inv_scale); *data++ = T(g*inv_scale); *data++ = T(b*inv_scale); } } break;
|
||||
case(GL_RGBA): { for(unsigned int i=0;i<num;++i) { float r = float(*data)*scale; float g = float(*(data+1))*scale; float b = float(*(data+2))*scale; float a = float(*(data+3))*scale; operation.rgba(r,g,b,a); *data++ = T(r*inv_scale); *data++ = T(g*inv_scale); *data++ = T(g*inv_scale); *data++ = T(a*inv_scale); } } break;
|
||||
case(GL_BGR): { for(unsigned int i=0;i<num;++i) { float b = float(*data)*scale; float g = float(*(data+1))*scale; float r = float(*(data+2))*scale; operation.rgb(r,g,b); *data++ = T(b*inv_scale); *data++ = T(g*inv_scale); *data++ = T(r*inv_scale); } } break;
|
||||
case(GL_BGRA): { for(unsigned int i=0;i<num;++i) { float b = float(*data)*scale; float g = float(*(data+1))*scale; float r = float(*(data+2))*scale; float a = float(*(data+3))*scale; operation.rgba(r,g,b,a); *data++ = T(g*inv_scale); *data++ = T(b*inv_scale); *data++ = T(r*inv_scale); *data++ = T(a*inv_scale); } } break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class M>
|
||||
void modifyRow(unsigned int num, GLenum pixelFormat, GLenum dataType, unsigned char* data, const M& operation)
|
||||
{
|
||||
switch(dataType)
|
||||
{
|
||||
case(GL_BYTE): _modifyRow(num,pixelFormat, (char*)data, 1.0f/128.0f, operation); break;
|
||||
case(GL_UNSIGNED_BYTE): _modifyRow(num,pixelFormat, (unsigned char*)data, 1.0f/255.0f, operation); break;
|
||||
case(GL_SHORT): _modifyRow(num,pixelFormat, (short*) data, 1.0f/32768.0f, operation); break;
|
||||
case(GL_UNSIGNED_SHORT): _modifyRow(num,pixelFormat, (unsigned short*)data, 1.0f/65535.0f, operation); break;
|
||||
case(GL_INT): _modifyRow(num,pixelFormat, (int*) data, 1.0f/2147483648.0f, operation); break;
|
||||
case(GL_UNSIGNED_INT): _modifyRow(num,pixelFormat, (unsigned int*) data, 1.0f/4294967295.0f, operation); break;
|
||||
case(GL_FLOAT): _modifyRow(num,pixelFormat, (float*) data, 1.0f, operation); break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class M>
|
||||
void modifyImage(osg::Image* image, const M& operation)
|
||||
{
|
||||
if (!image) return;
|
||||
|
||||
for(int r=0;r<image->r();++r)
|
||||
{
|
||||
for(int t=0;t<image->t();++t)
|
||||
{
|
||||
modifyRow(image->s(), image->getPixelFormat(), image->getDataType(), image->data(0,t,r), operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute the min max colour values in the image.*/
|
||||
extern OSGVOLUME_EXPORT bool computeMinMax(const osg::Image* image, osg::Vec4& min, osg::Vec4& max);
|
||||
|
||||
/** Compute the min max colour values in the image.*/
|
||||
extern OSGVOLUME_EXPORT bool offsetAndScaleImage(osg::Image* image, const osg::Vec4& offset, const osg::Vec4& scale);
|
||||
|
||||
/** Compute source image to destination image.*/
|
||||
extern OSGVOLUME_EXPORT bool copyImage(const osg::Image* srcImage, int src_s, int src_t, int src_r, int width, int height, int depth,
|
||||
osg::Image* destImage, int dest_s, int dest_t, int dest_r, bool doRescale = false);
|
||||
|
||||
/** Compute the min max colour values in the image.*/
|
||||
extern OSGVOLUME_EXPORT bool clearImageToColor(osg::Image* image, const osg::Vec4& colour);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -27,6 +27,8 @@ class OSGVOLUME_EXPORT Locator : public osg::Object
|
||||
|
||||
Locator() {}
|
||||
|
||||
Locator(const osg::Matrixd& transform) { setTransform(transform); }
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Locator(const Locator& locator,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(locator, copyop),
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include <osgVolume/Layer>
|
||||
#include <osgVolume/VolumeTechnique>
|
||||
|
||||
namespace osgVolume {
|
||||
@@ -109,14 +110,19 @@ class OSGVOLUME_EXPORT VolumeTile : public osg::Group
|
||||
const TileID& getTileID() const { return _tileID; }
|
||||
|
||||
|
||||
void setLocator(osg::RefMatrix* locator) { _locator = locator; }
|
||||
osg::RefMatrix* getLocator() { return _locator.get(); }
|
||||
const osg::RefMatrix* getLocator() const { return _locator.get(); }
|
||||
void setLocator(Locator* locator) { _locator = locator; }
|
||||
Locator* getLocator() { return _locator.get(); }
|
||||
const Locator* getLocator() const { return _locator.get(); }
|
||||
|
||||
|
||||
void setImage(unsigned int i, osg::Image* image);
|
||||
osg::Image* getImage(unsigned int i) { return i<_images.size() ? _images[i].get() : 0; }
|
||||
const osg::Image* getImage(unsigned int i) const { return i<_images.size() ? _images[i].get() : 0; }
|
||||
void setLayer(unsigned int i, Layer* layer);
|
||||
Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].get() : 0; }
|
||||
const Layer* getImage(unsigned int i) const { return i<_layers.size() ? _layers[i].get() : 0; }
|
||||
|
||||
void addLayer(Layer* layer) { if (layer) _layers.push_back(layer); }
|
||||
|
||||
unsigned int getNumLayers() { return _layers.size(); }
|
||||
|
||||
|
||||
/** Set the VolumeTechnique*/
|
||||
void setVolumeTechnique(VolumeTechnique* VolumeTechnique);
|
||||
@@ -152,10 +158,10 @@ class OSGVOLUME_EXPORT VolumeTile : public osg::Group
|
||||
|
||||
osg::ref_ptr<VolumeTechnique> _volumeTechnique;
|
||||
|
||||
osg::ref_ptr<osg::RefMatrix> _locator;
|
||||
osg::ref_ptr<Locator> _locator;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Image> > Images;
|
||||
Images _images;
|
||||
typedef std::vector< osg::ref_ptr<Layer> > Layers;
|
||||
Layers _layers;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user