OSGImageFunctions.cpp File Reference

#include <stdlib.h>
#include <stdio.h>
#include <OSGConfig.h>
#include <OSGLog.h>
#include <OSGImage.h>
#include <OSGBaseFunctions.h>
#include "OSGImageFunctions.h"

Go to the source code of this file.

Namespaces

namespace  osg

Defines

#define MAXB   0x100

Functions

bool osg::createComposedImage (std::vector< ImagePtr > imageVec, ImagePtr image, SliceDataType sliceDataType)
bool osg::createNormalMapFromBump (ImagePtr image, ImagePtr dst, Vec3f normalMapScale)
bool osg::createNormalVolume (ImagePtr inImage, ImagePtr outImage, const std::string &outputFormat)
bool osg::create2DPreIntegrationLUT (ImagePtr dst, ImagePtr src, Real32 thickness)
bool osg::splitRGBA (ImagePtr rgba, ImagePtr rgb, ImagePtr alpha)
bool osg::mergeRGBA (ImagePtr rgb, ImagePtr alpha, ImagePtr rgba)
bool osg::blendImage (ImagePtr canvas, ImagePtr brush, Vec3f position, Color4f color, Real32 alphaScale, Real32 paintZ)
bool osg::createPhongTexture (ImagePtr image, UInt32 size, Real32 specular_exponent, Real32 ka, Real32 kd, Real32 ks)
bool createPhongVolume (ImagePtr image, Color3f diffuseColor, Color3f specularColor, UInt32 lutSize, UInt32 lutScalar, Real32 lutIncr)
bool osg::createNormalizationCubeMap (std::vector< ImagePtr > imageVec, UInt32 size)
void setNoiseFrequency (Int32 frequency)
Real32 lerp (Real32 t, Real32 a, Real32 b)
Real32 sCurve (Real32 t)
Real32 at2 (Real32 *q, Real32 rx, Real32 ry)
Real32 at3 (Real32 *q, Real32 rx, Real32 ry, Real32 rz)
void setup (Real32 *vec, UInt8 i, Real32 &t, Int32 &b0, Int32 &b1, Real32 &r0, Real32 &r1)
void normalize2 (Real32 v[2])
void normalize3 (Real32 v[3])
void init (void)
Real32 noise1 (Real32 vec[1])
Real32 noise2 (Real32 vec[2])
Real32 noise3 (Real32 vec[3])
Real32 noise (Real32 vec[], Int32 len)
bool osg::createNoise (ImagePtr image, Image::PixelFormat pixelformat, UInt16 numOctaves, UInt16 size, UInt8 dim, bool splitOctaves)

Variables

Int32 p [MAXB+MAXB+2]
Real32 g3 [MAXB+MAXB+2][3]
Real32 g2 [MAXB+MAXB+2][2]
Real32 g1 [MAXB+MAXB+2]
Int32 start = 1
Int32 B = 0x100
Int32 BM = 0xff


Define Documentation

#define MAXB   0x100

Definition at line 1192 of file OSGImageFunctions.cpp.


Function Documentation

bool createPhongVolume ( ImagePtr  image,
Color3f  diffuseColor,
Color3f  specularColor,
UInt32  lutSize,
UInt32  lutScalar,
Real32  lutIncr 
)

create phong Volume

Definition at line 918 of file OSGImageFunctions.cpp.

References osg::beginEditCP(), osg::endEditCP(), FDEBUG, osg::Inf, osg::Image::OSG_RGB_PF, osg::osgClamp(), osg::osgcos(), osg::osgdegree2rad(), osg::osgpow(), and osg::osgsin().

00924 {
00925   const osg::Int32 lutFSize = lutSize / lutScalar;
00926     osg::Real32 theta1, theta2, dPhi, incr = lutScalar * lutIncr;
00927     osg::Real32 Const = 0.2f, Shi = 40, NdotL;
00928     osg::Vec3f color;
00929   osg::Vec3f diffuse  (diffuseColor[0],diffuseColor[1],diffuseColor[2]);
00930   osg::Vec3f specular (specularColor[0],specularColor[1],specularColor[2]);
00931     osg::UInt8 *ds;
00932     osg::Real32 min = osg::Inf, max = -osg::Inf;
00933     
00934   osg::beginEditCP(image);
00935 
00936     image->set( osg::Image::OSG_RGB_PF, lutFSize, lutFSize, lutFSize );
00937 
00938   ds = image->getData();
00939 
00940     FDEBUG (("calc phong map START\n"));
00941 
00942     for (dPhi=0; dPhi<360; dPhi+=incr) {
00943       for (theta1=0; theta1<180; theta1+=incr) {
00944         for (theta2=0; theta2<180; theta2+=incr) {
00945             osg::Real32 t1 = osg::osgdegree2rad(theta1),
00946                         t2 = osg::osgdegree2rad(theta2),
00947                         dp = osg::osgdegree2rad(dPhi);
00948             NdotL = osg::osgsin(t1)*osg::osgsin(t2)*osg::osgcos(dp) +
00949                     osg::osgcos(t1)*osg::osgcos(t2);
00950             NdotL = (NdotL >= 0) ? NdotL : 0;
00951             color = diffuse * (NdotL + Const) +
00952                     specular * osg::osgpow(NdotL, Shi);
00953 
00954             for (int i=0; i<3; i++) {
00955                 if (min>color[i]) min=color[i];
00956                 if (max<color[i]) max=color[i];
00957                 
00958                 color[i] = osg::osgClamp(0.f, (color[i]), 1.f);
00959                 *ds++ = (osg::UInt8)(color[i]*255);
00960             }
00961         }
00962       }
00963     }
00964 
00965   osg::endEditCP(image);
00966 
00967     FDEBUG (( "calc phong map FINISH: clamped from [%f,%f] to [0,1]\n", 
00968             min, max));
00969 
00970   return true;
00971 }

void @523::setNoiseFrequency ( Int32  frequency  )  [static]

Definition at line 1203 of file OSGImageFunctions.cpp.

Referenced by osg::createNoise().

01204 {
01205     start = 1;
01206     B = frequency;
01207     BM = B-1;
01208 }

Real32 @523::lerp ( Real32  t,
Real32  a,
Real32  b 
) [static]

Definition at line 1210 of file OSGImageFunctions.cpp.

Referenced by noise1(), noise2(), and noise3().

01211 {
01212     return (1 - t) * a + t * b;
01213 }

Real32 @523::sCurve ( Real32  t  )  [static]

Definition at line 1215 of file OSGImageFunctions.cpp.

Referenced by noise1(), noise2(), and noise3().

01216 {
01217     return t * t * (3.0f - 2.0f * t);
01218 }

Real32 @523::at2 ( Real32 *  q,
Real32  rx,
Real32  ry 
) [static]

Definition at line 1220 of file OSGImageFunctions.cpp.

Referenced by noise2().

01221 {
01222     return rx * q[0] + ry * q[1];
01223 }

Real32 @523::at3 ( Real32 *  q,
Real32  rx,
Real32  ry,
Real32  rz 
) [static]

Definition at line 1225 of file OSGImageFunctions.cpp.

Referenced by noise3().

01226 {
01227     return rx * q[0] + ry * q[1] + rz * q[2];
01228 }

void @523::setup ( Real32 *  vec,
UInt8  i,
Real32 &  t,
Int32 &  b0,
Int32 &  b1,
Real32 &  r0,
Real32 &  r1 
) [static]

Definition at line 1230 of file OSGImageFunctions.cpp.

Referenced by noise1(), noise2(), noise3(), and osg::QFCItem::setup().

01234 {
01235     t  = vec[i] + 0x1000;
01236     b0 = ((Int32)t) & BM;
01237     b1 = (b0 + 1) & BM;
01238     r0 = t - (Int32)t;
01239     r1 = r0 - 1.0f;
01240 }

void @523::normalize2 ( Real32  v[2]  )  [static]

Definition at line 1242 of file OSGImageFunctions.cpp.

Referenced by init().

01243 {
01244     Real32 s = sqrt(v[0] * v[0] + v[1] * v[1]);
01245     v[0] = v[0] / s;
01246     v[1] = v[1] / s;
01247 }

void @523::normalize3 ( Real32  v[3]  )  [static]

Definition at line 1249 of file OSGImageFunctions.cpp.

Referenced by init().

01250 {
01251     Real32 s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
01252     v[0] = v[0] / s;
01253     v[1] = v[1] / s;
01254     v[2] = v[2] / s;
01255 }

void @523::init ( void   )  [static]

Definition at line 1257 of file OSGImageFunctions.cpp.

References normalize2(), and normalize3().

Referenced by drawShaderStrips< posTrait, secPosTrait, colTrait, texTrait, sizeTrait, normalTrait >::draw(), drawShaderQuads< posTrait, secPosTrait, colTrait, texTrait, sizeTrait, normalTrait >::draw(), drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >::draw(), drawObjects< posTrait, colTrait, sizeTrait, normalTrait, geoTrait >::draw(), drawPoints< posTrait, colTrait, texTrait, sizeTrait >::draw(), drawLines< posTrait, colTrait, texTrait, sizeTrait >::draw(), drawViewerQuads< posTrait, colTrait, texTrait, sizeTrait >::draw(), drawViewDirQuads< posTrait, colTrait, texTrait, sizeTrait >::draw(), drawShaderStrips< posTrait, secPosTrait, colTrait, texTrait, sizeTrait, normalTrait >::drawIndexed(), drawShaderQuads< posTrait, secPosTrait, colTrait, texTrait, sizeTrait, normalTrait >::drawIndexed(), drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >::drawIndexed(), drawObjects< posTrait, colTrait, sizeTrait, normalTrait, geoTrait >::drawIndexed(), drawPoints< posTrait, colTrait, texTrait, sizeTrait >::drawIndexed(), drawLines< posTrait, colTrait, texTrait, sizeTrait >::drawIndexed(), drawViewerQuads< posTrait, colTrait, texTrait, sizeTrait >::drawIndexed(), drawViewDirQuads< posTrait, colTrait, texTrait, sizeTrait >::drawIndexed(), osg::GeoPumpFactory::glextInitFunction(), osg::PThreadBase::init(), osg::QTWindow::init(), noise1(), noise2(), and noise3().

01258 {
01259     Int32 i, j, k;
01260 
01261     srand(30757);
01262     for (i = 0 ; i < B ; i++)
01263     {
01264         p[i] = i;
01265         g1[i] = (Real32)((rand() % (B + B)) - B) / B;
01266 
01267         for (j = 0 ; j < 2 ; j++)
01268             g2[i][j] = (Real32)((rand() % (B + B)) - B) / B;
01269         normalize2(g2[i]);
01270 
01271         for (j = 0 ; j < 3 ; j++)
01272             g3[i][j] = (Real32)((rand() % (B + B)) - B) / B;
01273         normalize3(g3[i]);
01274     }
01275 
01276     while (--i)
01277     {
01278         k = p[i];
01279         p[i] = p[j = rand() % B];
01280         p[j] = k;
01281     }
01282 
01283     for (i = 0 ; i < B + 2 ; i++)
01284     {
01285         p[B + i] = p[i];
01286         g1[B + i] = g1[i];
01287         for (j = 0 ; j < 2 ; j++)
01288             g2[B + i][j] = g2[i][j];
01289         for (j = 0 ; j < 3 ; j++)
01290             g3[B + i][j] = g3[i][j];
01291     }
01292 }

Real32 @523::noise1 ( Real32  vec[1]  )  [static]

Definition at line 1294 of file OSGImageFunctions.cpp.

References init(), lerp(), sCurve(), and setup().

Referenced by noise().

01295 {
01296     Int32 bx0, bx1;
01297     Real32 rx0, rx1, sx, t, u, v;
01298 
01299     if (start)
01300     {
01301         start = 0;
01302         init();
01303     }
01304 
01305     setup(vec, 0, t, bx0, bx1, rx0, rx1);
01306 
01307     sx = sCurve(rx0);
01308 
01309     u = rx0 * g1[ p[ bx0 ] ];
01310     v = rx1 * g1[ p[ bx1 ] ];
01311 
01312     return lerp(sx, u, v);
01313 }

Real32 @523::noise2 ( Real32  vec[2]  )  [static]

Definition at line 1315 of file OSGImageFunctions.cpp.

References at2(), init(), lerp(), sCurve(), and setup().

Referenced by noise().

01316 {
01317     Int32 bx0, bx1, by0, by1, b00, b10, b01, b11;
01318     Real32 rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
01319     Int32 i, j;
01320 
01321     if (start)
01322     {
01323         start = 0;
01324         init();
01325     }
01326 
01327     setup(vec, 0, t, bx0, bx1, rx0, rx1);
01328     setup(vec, 1, t, by0, by1, ry0, ry1);
01329 
01330     i = p[ bx0 ];
01331     j = p[ bx1 ];
01332 
01333     b00 = p[ i + by0 ];
01334     b10 = p[ j + by0 ];
01335     b01 = p[ i + by1 ];
01336     b11 = p[ j + by1 ];
01337 
01338     sx = sCurve(rx0);
01339     sy = sCurve(ry0);
01340 
01341     q = g2[ b00 ] ; u = at2(q, rx0,ry0);
01342     q = g2[ b10 ] ; v = at2(q, rx1,ry0);
01343     a = lerp(sx, u, v);
01344 
01345     q = g2[ b01 ] ; u = at2(q, rx0,ry1);
01346     q = g2[ b11 ] ; v = at2(q, rx1,ry1);
01347     b = lerp(sx, u, v);
01348 
01349     return lerp(sy, a, b);
01350 }

Real32 @523::noise3 ( Real32  vec[3]  )  [static]

Definition at line 1352 of file OSGImageFunctions.cpp.

References at3(), init(), lerp(), sCurve(), and setup().

Referenced by noise().

01353 {
01354     Int32 bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
01355     Real32 rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
01356     Int32 i, j;
01357 
01358     if (start)
01359     {
01360         start = 0;
01361         init();
01362     }
01363 
01364     setup(vec, 0, t, bx0, bx1, rx0, rx1);
01365     setup(vec, 1, t, by0, by1, ry0, ry1);
01366     setup(vec, 2, t, bz0, bz1, rz0, rz1);
01367 
01368     i = p[ bx0 ];
01369     j = p[ bx1 ];
01370 
01371     b00 = p[ i + by0 ];
01372     b10 = p[ j + by0 ];
01373     b01 = p[ i + by1 ];
01374     b11 = p[ j + by1 ];
01375 
01376     t  = sCurve(rx0);
01377     sy = sCurve(ry0);
01378     sz = sCurve(rz0);
01379 
01380     q = g3[ b00 + bz0 ] ; u = at3(q, rx0,ry0,rz0);
01381     q = g3[ b10 + bz0 ] ; v = at3(q, rx1,ry0,rz0);
01382     a = lerp(t, u, v);
01383 
01384     q = g3[ b01 + bz0 ] ; u = at3(q, rx0,ry1,rz0);
01385     q = g3[ b11 + bz0 ] ; v = at3(q, rx1,ry1,rz0);
01386     b = lerp(t, u, v);
01387 
01388     c = lerp(sy, a, b);
01389 
01390     q = g3[ b00 + bz1 ] ; u = at3(q, rx0,ry0,rz1);
01391     q = g3[ b10 + bz1 ] ; v = at3(q, rx1,ry0,rz1);
01392     a = lerp(t, u, v);
01393 
01394     q = g3[ b01 + bz1 ] ; u = at3(q, rx0,ry1,rz1);
01395     q = g3[ b11 + bz1 ] ; v = at3(q, rx1,ry1,rz1);
01396     b = lerp(t, u, v);
01397 
01398     d = lerp(sy, a, b);
01399 
01400     return lerp(sz, c, d);
01401 }

Real32 @523::noise ( Real32  vec[],
Int32  len 
) [static]

Definition at line 1403 of file OSGImageFunctions.cpp.

References noise1(), noise2(), and noise3().

Referenced by osg::createNoise().

01404 {
01405     // noise functions over 1, 2, and 3 dimensions 
01406     switch (len)
01407     {
01408       case 1: return noise1(vec);
01409       case 2: return noise2(vec);
01410       case 3: return noise3(vec);
01411       case 0:
01412       default: return 0.0f;
01413     }
01414 }


Variable Documentation

Int32 p[MAXB+MAXB+2] [static]

Definition at line 1194 of file OSGImageFunctions.cpp.

Referenced by osg::Slices::adjustVolume(), osg::Particles::adjustVolume(), osg::calcFaceNormalsGeo(), osg::Particles::calcIndex(), osg::ExtrusionSurface::calcOptimizedContour(), osg::ExtrusionSurface::calcSweepSurfacePositions(), osg::calcVertexNormals(), CDDSImage::check_dxt1_alpha_data(), osg::Plane::clip(), osg::Color3< ValueTypeT >::convertFromHSV(), osg::DisplayCalibration::createCMViewports(), osg::DistortionDisplayFilter::createFilter(), osg::createNormalVolume(), osg::ParticleBSPTree::doBuild(), drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >::draw(), drawObjects< posTrait, colTrait, sizeTrait, normalTrait, geoTrait >::draw(), drawViewerQuads< posTrait, colTrait, texTrait, sizeTrait >::draw(), osg::ImageForeground::draw(), osg::DisplayFilterForeground::draw(), drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >::drawIndexed(), drawObjects< posTrait, colTrait, sizeTrait, normalTrait, geoTrait >::drawIndexed(), drawViewerQuads< posTrait, colTrait, texTrait, sizeTrait >::drawIndexed(), osg::Geometry::drawPrimitives(), osg::extend(), osg::ChunkMaterial::find(), osg::Window::frameExit(), osg::Window::frameInit(), osg::SceneFileHandler::getFileType(), osg::ShaderParameterAccess::getParameter(), osg::ImageComposer::getScreenAlignedBBox(), osg::Geometry::handleGL(), osg::Slices::initEdgeVec(), osg::intersect(), osg::Plane::isInHalfSpace(), osg::Plane::isOutHalfSpace(), osg::RenderAction::isSmallFeature(), osg::TransformationMatrix< ValueTypeT >::jacobi(), osg::makeBoxGeo(), osg::makeConicalFrustumGeo(), osg::makeLatLongSphereGeo(), osg::makePlaneGeo(), osg::makeSphereGeo(), osg::makeTorusGeo(), osg::osghtond(), osg::osghtondd(), osg::osghtonf(), osg::osgntohd(), osg::osgntohdd(), osg::osgntohf(), osg::MergeGraphOp::processTransformations(), osg::TextPixmapGlyph::putPixmap(), osg::SceneFileHandler::readProgress(), osg::Image::scaleData(), osg::ClusterWindow::serverRender(), osg::ShaderParameterAccess::setMParameter(), osg::ShaderParameterAccess::setParameter(), osg::Image::swapDataEndian(), osg::CylinderVolume::transform(), osg::ClusterWindow::updateFilter(), osg::TileGeometryLoad::updateGeometry(), osg::SHLChunk::updateParameters(), osg::TileGeometryLoad::updateView(), osg::PNMImageFileType::write(), and osg::VRMLWriteAction::writePoints().

Real32 g3[MAXB+MAXB+2][3] [static]

Definition at line 1195 of file OSGImageFunctions.cpp.

Real32 g2[MAXB+MAXB+2][2] [static]

Definition at line 1196 of file OSGImageFunctions.cpp.

Real32 g1[MAXB+MAXB+2] [static]

Definition at line 1197 of file OSGImageFunctions.cpp.

Referenced by osg::GradientBackground::clear().

Int32 start = 1 [static]

Int32 B = 0x100 [static]

Definition at line 1199 of file OSGImageFunctions.cpp.

Referenced by osg::calcVertexTangents().

Int32 BM = 0xff [static]

Definition at line 1200 of file OSGImageFunctions.cpp.


Generated on Mon Mar 17 12:02:36 2008 for OpenSG by  doxygen 1.5.5