From c4f199d1b503bccd1af3877c2d7700aa8391d5e5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 2 Jul 2014 16:26:18 +0000 Subject: [PATCH] Added osgVolume::VolumeSettings object git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14347 16af8721-9629-0410-8352-f15c8da7e697 --- include/osgVolume/VolumeSettings | 81 +++++++++++++++++++ src/osgPlugins/dds/ReaderWriterDDS.cpp | 19 +++-- src/osgVolume/CMakeLists.txt | 2 + src/osgVolume/VolumeSettings.cpp | 37 +++++++++ .../serializers/osgVolume/VolumeSettings.cpp | 29 +++++++ 5 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 include/osgVolume/VolumeSettings create mode 100644 src/osgVolume/VolumeSettings.cpp create mode 100644 src/osgWrappers/serializers/osgVolume/VolumeSettings.cpp diff --git a/include/osgVolume/VolumeSettings b/include/osgVolume/VolumeSettings new file mode 100644 index 000000000..cafc19cc7 --- /dev/null +++ b/include/osgVolume/VolumeSettings @@ -0,0 +1,81 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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 OSGVOLUMESETTINGS +#define OSGVOLUMESETTINGS 1 + +#include +#include + +namespace osgVolume { + +class OSGVOLUME_EXPORT VolumeSettings : public osg::Object +{ + public: + + VolumeSettings(); + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + VolumeSettings(const VolumeSettings&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgVolume, VolumeSettings); + + enum Technique + { + FixedFunction, + RayTraced, + MultiPass + }; + + void setTechnique(Technique technique) { _technique = technique; } + Technique getTechnique() const { return _technique; } + + enum ShadingModel + { + Standard, + Light, + Isosurface, + MaximumIntensityProjection + }; + + void setShadingModel(ShadingModel sm) { _shadingModel = sm; } + ShadingModel getShadingModel() const { return _shadingModel; } + + void setSampleRatio(float sr) { _sampleRatio = sr; } + float getSampleRatio() const { return _sampleRatio; } + + void setSampleRatioWhenMoving(float sr) { _sampleRatioWhenMoving = sr; } + float getSampleRatioWhenMoving() const { return _sampleRatioWhenMoving; } + + void setCutoff(float co) { _cutoff = co; } + float getCutoff() const { return _cutoff; } + + void setTransparency(float t) { _transparency = t; } + float getTransparency() const { return _transparency; } + + protected: + + virtual ~VolumeSettings() {} + + Technique _technique; + ShadingModel _shadingModel; + float _sampleRatio; + float _sampleRatioWhenMoving; + float _cutoff; + float _transparency; + +}; + +} + +#endif diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index 475f210d6..eb2f9217b 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -264,7 +264,7 @@ struct DXT1TexelsBlock */ #define FOURCC_DX10 (MAKEFOURCC('D','X','1','0')) -typedef enum OSG_DXGI_FORMAT { +typedef enum OSG_DXGI_FORMAT { OSG_DXGI_FORMAT_UNKNOWN = 0, OSG_DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, OSG_DXGI_FORMAT_R32G32B32A32_FLOAT = 2, @@ -384,7 +384,7 @@ typedef enum OSG_DXGI_FORMAT { OSG_DXGI_FORMAT_FORCE_UINT = 0xffffffffUL } OSG_DXGI_FORMAT; -typedef enum OSG_D3D10_RESOURCE_DIMENSION { +typedef enum OSG_D3D10_RESOURCE_DIMENSION { OSG_D3D10_RESOURCE_DIMENSION_UNKNOWN = 0, OSG_D3D10_RESOURCE_DIMENSION_BUFFER = 1, OSG_D3D10_RESOURCE_DIMENSION_TEXTURE1D = 2, @@ -407,7 +407,7 @@ static unsigned int ComputeImageSizeInBytes( int width, int height, int depth, if( width < 1 ) width = 1; if( height < 1 ) height = 1; if( depth < 1 ) depth = 1; - + return osg::Image::computeImageSizeInBytes(width, height, depth, pixelFormat, pixelType, packing, slice_packing, image_packing); } @@ -982,6 +982,8 @@ osg::Image* ReadDDSFile(std::istream& _istream, bool flipDDSRead) } } + OSG_NOTICE<<"ReadDDS, dataType = 0x"<setOrigin(osg::Image::BOTTOM_LEFT); if (!isDXTC || ((s>4 && s%4==0 && t>4 && t%4==0) || s<4)) // Flip may crash (access violation) or fail for non %4 dimensions (except for s<4). Tested with revision trunk 2013-02-22. { + OSG_NOTICE<<"Flipping dds on load"<flipVertical(); } else @@ -1061,7 +1064,9 @@ bool WriteDDSFile(const osg::Image *img, std::ostream& fout, bool autoFlipDDSWri unsigned int pixelSize = osg::Image::computePixelSizeInBits(pixelFormat, dataType); unsigned int imageSize = img->getTotalSizeInBytes(); - // Check that theorical image size (computation taking into account DXTC blocks) is not bigger than actual image size. + OSG_NOTICE<<"WriteDDS, dataType = 0x"< source; if (autoFlipDDSWrite && img->getOrigin() == osg::Image::BOTTOM_LEFT) { + OSG_NOTICE<<"Flipping dds image on write"< copy( new osg::Image(*img,osg::CopyOp::DEEP_COPY_ALL) ); const int s(copy->s()); const int t(copy->t()); @@ -1283,7 +1290,7 @@ bool WriteDDSFile(const osg::Image *img, std::ostream& fout, bool autoFlipDDSWri OSG_WARN << "WriteDDSFile warning: Vertical flip was skipped. Image dimensions have to be multiple of 4." << std::endl; } source = copy; - } + } else { source = img; @@ -1361,7 +1368,7 @@ public: if (options) { std::istringstream iss(options->getOptionString()); - std::string opt; + std::string opt; while (iss >> opt) { if (opt == "dds_flip") dds_flip = true; diff --git a/src/osgVolume/CMakeLists.txt b/src/osgVolume/CMakeLists.txt index 6f530a2d9..9cf1faf78 100644 --- a/src/osgVolume/CMakeLists.txt +++ b/src/osgVolume/CMakeLists.txt @@ -18,6 +18,7 @@ SET(TARGET_H ${HEADER_PATH}/Version ${HEADER_PATH}/Volume ${HEADER_PATH}/VolumeScene + ${HEADER_PATH}/VolumeSettings ${HEADER_PATH}/VolumeTechnique ${HEADER_PATH}/VolumeTile ) @@ -33,6 +34,7 @@ SET(TARGET_SRC Version.cpp Volume.cpp VolumeScene.cpp + VolumeSettings.cpp VolumeTechnique.cpp VolumeTile.cpp ${OPENSCENEGRAPH_VERSIONINFO_RC} diff --git a/src/osgVolume/VolumeSettings.cpp b/src/osgVolume/VolumeSettings.cpp new file mode 100644 index 000000000..696def6b6 --- /dev/null +++ b/src/osgVolume/VolumeSettings.cpp @@ -0,0 +1,37 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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 + +using namespace osgVolume; + +VolumeSettings::VolumeSettings(): + _technique(MultiPass), + _shadingModel(Standard), + _sampleRatio(1.0f), + _sampleRatioWhenMoving(1.0f), + _cutoff(0.0f), + _transparency(1.0f) +{ +} + +VolumeSettings::VolumeSettings(const VolumeSettings& vs,const osg::CopyOp& copyop): + osg::Object(vs, copyop), + _technique(vs._technique), + _shadingModel(vs._shadingModel), + _sampleRatio(vs._sampleRatio), + _sampleRatioWhenMoving(vs._sampleRatioWhenMoving), + _cutoff(vs._cutoff), + _transparency(vs._transparency) +{ +} diff --git a/src/osgWrappers/serializers/osgVolume/VolumeSettings.cpp b/src/osgWrappers/serializers/osgVolume/VolumeSettings.cpp new file mode 100644 index 000000000..86535ccac --- /dev/null +++ b/src/osgWrappers/serializers/osgVolume/VolumeSettings.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +REGISTER_OBJECT_WRAPPER( osgVolume_VolumeSettings, + new osgVolume::VolumeSettings, + osgVolume::VolumeSettings, + "osg::Object osgVolume::VolumeSettings" ) +{ + BEGIN_ENUM_SERIALIZER( Technique, MultiPass ); + ADD_ENUM_VALUE( FixedFunction ); + ADD_ENUM_VALUE( RayTraced ); + ADD_ENUM_VALUE( MultiPass ); + END_ENUM_SERIALIZER(); + + BEGIN_ENUM_SERIALIZER( ShadingModel, Standard ); + ADD_ENUM_VALUE( Standard ); + ADD_ENUM_VALUE( Light ); + ADD_ENUM_VALUE( Isosurface ); + ADD_ENUM_VALUE( MaximumIntensityProjection ); + END_ENUM_SERIALIZER(); + + ADD_FLOAT_SERIALIZER( SampleRatio, 1.0f ); + ADD_FLOAT_SERIALIZER( SampleRatioWhenMoving, 1.0f ); + ADD_FLOAT_SERIALIZER( Cutoff, 0.0f ); + ADD_FLOAT_SERIALIZER( Transparency, 1.0f ); +}