Show
Ignore:
Timestamp:
11/05/08 16:59:48 (6 years ago)
Author:
robert
Message:

Added --no-rescale, --rescale (default) and --shift-min-to-zero command line options for controlling how the pixel data is managed.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp

    r9103 r9105  
    17971797    arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt3","Enable the usage of S3TC DXT3 compressed textures."); 
    17981798    arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt5","Enable the usage of S3TC DXT5 compressed textures."); 
    1799     arguments.getApplicationUsage()->addCommandLineOption("--modulate-alpha-by-luminance","For each pixel multiple the alpha value by the luminance."); 
    1800     arguments.getApplicationUsage()->addCommandLineOption("--replace-alpha-with-luminance","For each pixel mSet the alpha value to the luminance."); 
     1799    arguments.getApplicationUsage()->addCommandLineOption("--modulate-alpha-by-luminance","For each pixel multiply the alpha value by the luminance."); 
     1800    arguments.getApplicationUsage()->addCommandLineOption("--replace-alpha-with-luminance","For each pixel set the alpha value to the luminance."); 
     1801    arguments.getApplicationUsage()->addCommandLineOption("--replace-rgb-with-luminance","For each rgb pixel convert to the luminance."); 
    18011802    arguments.getApplicationUsage()->addCommandLineOption("--num-components <num>","Set the number of components to in he target image."); 
     1803    arguments.getApplicationUsage()->addCommandLineOption("--no-rescale","Disable the rescaling of the pixel data to 0.0 to 1.0 range"); 
     1804    arguments.getApplicationUsage()->addCommandLineOption("--rescale","Enable the rescale of the pixel data to 0.0 to 1.0 range (default)."); 
     1805    arguments.getApplicationUsage()->addCommandLineOption("--shift-min-to-zero","Shift the pixel data so min value is 0.0."); 
    18021806//    arguments.getApplicationUsage()->addCommandLineOption("--raw <sizeX> <sizeY> <sizeZ> <numberBytesPerComponent> <numberOfComponents> <endian> <filename>","read a raw image data"); 
    18031807 
     
    19171921    while(arguments.read("--replace-alpha-with-luminance")) { colourSpaceOperation = REPLACE_ALPHA_WITH_LUMINANACE; } 
    19181922    while(arguments.read("--replace-rgb-with-luminance")) { colourSpaceOperation = REPLACE_RGB_WITH_LUMINANCE; } 
     1923 
     1924 
     1925    enum RescaleOperation 
     1926    { 
     1927        NO_RESCALE, 
     1928        RESCALE_TO_ZERO_TO_ONE_RANGE, 
     1929        SHIFT_MIN_TO_ZERO 
     1930    }; 
     1931     
     1932    RescaleOperation rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; 
     1933    while(arguments.read("--no-rescale")) rescaleOperation = NO_RESCALE; 
     1934    while(arguments.read("--rescale")) rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; 
     1935    while(arguments.read("--shift-min-to-zero")) rescaleOperation = SHIFT_MIN_TO_ZERO; 
     1936 
    19191937         
    19201938    bool resizeToPowerOfTwo = false; 
     
    21572175        maxComponent = osg::maximum(maxComponent,maxValue[3]); 
    21582176 
    2159         float scale = 0.99f/(maxComponent-minComponent); 
    2160         float offset = -minComponent * scale; 
    2161  
    2162  
    2163         for(Images::iterator itr = images.begin(); 
    2164             itr != images.end(); 
    2165             ++itr) 
    2166         {         
    2167             osgVolume::offsetAndScaleImage(itr->get(),  
    2168                 osg::Vec4(offset, offset, offset, offset), 
    2169                 osg::Vec4(scale, scale, scale, scale)); 
    2170         } 
     2177 
     2178        switch(rescaleOperation) 
     2179        { 
     2180            case(NO_RESCALE): 
     2181                break; 
     2182 
     2183            case(RESCALE_TO_ZERO_TO_ONE_RANGE): 
     2184            { 
     2185                float scale = 0.99f/(maxComponent-minComponent); 
     2186                float offset = -minComponent * scale; 
     2187 
     2188                for(Images::iterator itr = images.begin(); 
     2189                    itr != images.end(); 
     2190                    ++itr) 
     2191                {         
     2192                    osgVolume::offsetAndScaleImage(itr->get(),  
     2193                        osg::Vec4(offset, offset, offset, offset), 
     2194                        osg::Vec4(scale, scale, scale, scale)); 
     2195                } 
     2196                break; 
     2197            } 
     2198            case(SHIFT_MIN_TO_ZERO): 
     2199            { 
     2200                float offset = -minComponent; 
     2201 
     2202                for(Images::iterator itr = images.begin(); 
     2203                    itr != images.end(); 
     2204                    ++itr) 
     2205                {         
     2206                    osgVolume::offsetAndScaleImage(itr->get(),  
     2207                        osg::Vec4(offset, offset, offset, offset), 
     2208                        osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 
     2209                } 
     2210                break; 
     2211            } 
     2212                break; 
     2213        }; 
     2214 
    21712215    } 
    21722216