Commit 8d33adaf by Sebastian Eichelbaum

[MERGE]

parents 36fc86cd 74c9ca16
......@@ -25,7 +25,7 @@
#ifndef WGECOLORMAPS_GLSL
#define WGECOLORMAPS_GLSL
#version 120
#version 130
uniform int useColorMap;
......@@ -438,7 +438,7 @@ void colorMap( inout vec3 col, in float value, int cmap )
* \param colormap the colormap index to use
*/
void colormap( inout vec4 color, in vec4 value, float minV, float scaleV, float thresholdV, float alpha, int colormap,
bool active )
bool cmactive )
{
// below threshold?
bool clip = ( value.r + value.g + value.b ) / 3.0 < ( ( minV + thresholdV ) / scaleV );
......@@ -478,7 +478,7 @@ void colormap( inout vec4 color, in vec4 value, float minV, float scaleV, float
}
// finally mix colors according to alpha
color = mix( color, col, float( active ) * alpha );
color = mix( color, col, float( cmactive ) * alpha );
}
#endif // WGECOLORMAPS_GLSL
......
......@@ -25,7 +25,7 @@
#ifndef WGECOLORMAPSIMPROVED_GLSL
#define WGECOLORMAPSIMPROVED_GLSL
#version 120
#version 130
#include "WGEUtils.glsl"
......@@ -463,7 +463,7 @@ vec4 colormap( in vec4 value, float minV, float scaleV,
bool clipZeroEnabled,
float thresholdVLower, float thresholdVUpper, bool thresholdEnabled,
vec2 window, bool windowEnabled,
float alpha, int colormap, bool active )
float alpha, int colormap, bool cmactive )
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Scale the input data to original space, and apply windowing
......@@ -550,7 +550,7 @@ vec4 colormap( in vec4 value, float minV, float scaleV,
alpha * // did the user specified an alpha?
clip * // value clip?
clipTh * // clip due to threshold?
float( active ) ); // is it active?
float( cmactive ) ); // is it active?
}
#endif // WGECOLORMAPS_GLSL
......
......@@ -25,7 +25,7 @@
#ifndef WGECOLORMAPPING_FRAGMENT_GLSL
#define WGECOLORMAPPING_FRAGMENT_GLSL
#version 120
#version 130
#include "WGEColorMapsImproved.glsl"
......@@ -55,7 +55,7 @@ void colormap( inout vec4 color, in sampler3D sampler, in vec3 coord, in vec3 si
bool clipZeroEnabled,
float thresholdVLower, float thresholdVUpper, bool thresholdEnabled,
bool windowEnabled, vec2 window,
float alpha, int cmap, bool active )
float alpha, int cmap, bool cmactive )
{
// This implements a manual trilinear interpolation. Include WGETextureutils.glsl to use this
// vec3 vSize = vec3( 1.0 / float( size.x ),
......@@ -75,14 +75,14 @@ void colormap( inout vec4 color, in sampler3D sampler, in vec3 coord, in vec3 si
// vec3 c101 = getNeighbourVoxel( vSize, coord, vec3( 1.0, 0.0, 1.0 ) );
// vec3 c111 = getNeighbourVoxel( vSize, coord, vec3( 1.0, 1.0, 1.0 ) );
//
// vec4 v00 = mix( colormap( texture3D( sampler, c000 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c100 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
// vec4 v10 = mix( colormap( texture3D( sampler, c010 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c110 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
// vec4 v01 = mix( colormap( texture3D( sampler, c001 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c101 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
// vec4 v11 = mix( colormap( texture3D( sampler, c011 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c111 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
// vec4 v00 = mix( colormap( texture3D( sampler, c000 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ),
// colormap( texture3D( sampler, c100 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ), coordDiff.x );
// vec4 v10 = mix( colormap( texture3D( sampler, c010 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ),
// colormap( texture3D( sampler, c110 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ), coordDiff.x );
// vec4 v01 = mix( colormap( texture3D( sampler, c001 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ),
// colormap( texture3D( sampler, c101 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ), coordDiff.x );
// vec4 v11 = mix( colormap( texture3D( sampler, c011 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ),
// colormap( texture3D( sampler, c111 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, cmactive ), coordDiff.x );
//
// vec4 src = mix( mix( v00, v10, coordDiff.y ),
// mix( v01, v11, coordDiff.y ), coordDiff.z );
......@@ -94,7 +94,7 @@ void colormap( inout vec4 color, in sampler3D sampler, in vec3 coord, in vec3 si
vec4 src = colormap( value, minV, scaleV, clipZeroEnabled,
thresholdVLower, thresholdVUpper, thresholdEnabled,
window, windowEnabled,
alpha, cmap, active );
alpha, cmap, cmactive );
// compositing:
// associated colors needed
......
......@@ -25,7 +25,7 @@
#ifndef WGECOLORMAPPING_UNIFORMS_GLSL
#define WGECOLORMAPPING_UNIFORMS_GLSL
#version 120
#version 130
// All the uniforms needed. These uniforms get set by the WGEColormapping class for your Node.
......
......@@ -25,7 +25,7 @@
#ifndef WGECOLORMAPPING_VARYINGS_GLSL
#define WGECOLORMAPPING_VARYINGS_GLSL
#version 120
#version 130
/**
* The texture coordinate in local texture space.
......
......@@ -25,7 +25,7 @@
#ifndef WGECOLORMAPPING_VERTEX_GLSL
#define WGECOLORMAPPING_VERTEX_GLSL
#version 120
#version 130
#include "WGEColormapping-uniforms.glsl"
#include "WGEColormapping-varyings.glsl"
......
......@@ -22,7 +22,7 @@
//
//---------------------------------------------------------------------------
#version 120
#version 130
#include "WGEShadingTools.glsl"
......
......@@ -22,7 +22,7 @@
//
//---------------------------------------------------------------------------
#version 120
#version 130
/**
* The normal.
......
......@@ -22,7 +22,7 @@
//
//---------------------------------------------------------------------------
#version 120
#version 130
#include "WGEShadingTools.glsl"
......
......@@ -22,7 +22,7 @@
//
//---------------------------------------------------------------------------
#version 120
#version 130
#include "WGETransformationTools.glsl"
......
......@@ -25,7 +25,7 @@
#ifndef WGEPOSTPROCESSING_GLSL
#define WGEPOSTPROCESSING_GLSL
#version 120
#version 130
// This defines some stuff needed to enable your shader to allow the result to be post-processed.
// You'll need to do the following:
......
......@@ -25,7 +25,7 @@
#ifndef WGEPOSTPROCESSOR_VERTEX_GLSL
#define WGEPOSTPROCESSOR_VERTEX_GLSL
#version 120
#version 130
#include "WGEPostprocessorUtils-vertex.glsl"
......
......@@ -25,7 +25,7 @@
#ifndef WGEPOSTPROCESSORCOMBINER_FRAGMENT_GLSL
#define WGEPOSTPROCESSORCOMBINER_FRAGMENT_GLSL
#version 120
#version 130
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Input-Texture Uniforms
......
......@@ -25,7 +25,7 @@
#ifndef WGEPOSTPROCESSORCOMBINER_VERTEX_GLSL
#define WGEPOSTPROCESSORCOMBINER_VERTEX_GLSL
#version 120
#version 130
/**
* Does transfer the quad to image space.
......
......@@ -25,7 +25,7 @@
#ifndef WGEPOSTPROCESSORUTILS_VERTEX_GLSL
#define WGEPOSTPROCESSORUTILS_VERTEX_GLSL
#version 120
#version 130
/**
* Does transfer the quad to image space.
......
......@@ -25,7 +25,7 @@
#ifndef WGESHADINGTOOLS_GLSL
#define WGESHADINGTOOLS_GLSL
#version 120
#version 130
/**
* A struct containing the needed light and material parameters commonly used in most shaders.
......
......@@ -25,7 +25,7 @@
#ifndef WGETENSORTOOLS_GLSL
#define WGETENSORTOOLS_GLSL
#version 120
#version 130
// (c) 2007 by Mario Hlawitschka
......
......@@ -25,7 +25,7 @@
#ifndef WGETEXTURETOOLS_GLSL
#define WGETEXTURETOOLS_GLSL
#version 120
#version 130
#include "WGEUtils.glsl"
......
......@@ -25,7 +25,7 @@
#ifndef WGETRANSFORMATIONTOOLS_GLSL
#define WGETRANSFORMATIONTOOLS_GLSL
#version 120
#version 130
/**
* Projects a given point to screen-space, where (0,0) is the lower left corner and (1,1) the upper right. The Depth
......
......@@ -25,7 +25,7 @@
#ifndef WGEUTILS_GLSL
#define WGEUTILS_GLSL
#version 120
#version 130
/**
*
......
......@@ -22,7 +22,7 @@
//
//---------------------------------------------------------------------------
#version 120
#version 130
#include "WGEColormapping-fragment.glsl"
......
......@@ -22,7 +22,7 @@
//
//---------------------------------------------------------------------------
#version 120
#version 130
#include "WGEColormapping-vertex.glsl"
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <osg/Image>
#include <osg/Texture3D>
#include <osgDB/ReadFile>
#include "core/common/WStringUtils.h"
#include "core/kernel/WKernel.h"
#include "WMAtlasCreator.h"
#include "WMAtlasCreator.xpm"
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMAtlasCreator )
WMAtlasCreator::WMAtlasCreator():
WModule()
{
}
WMAtlasCreator::~WMAtlasCreator()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMAtlasCreator::factory() const
{
// See "src/modules/template/" for an extensively documented example.
return boost::shared_ptr< WModule >( new WMAtlasCreator() );
}
const char** WMAtlasCreator::getXPMIcon() const
{
return WMAtlasCreator_xpm; // Please put a real icon here.
}
const std::string WMAtlasCreator::getName() const
{
return "Atlas Creator";
}
const std::string WMAtlasCreator::getDescription() const
{
// Specify your module description here. Be detailed. This text is read by the user.
// See "src/modules/template/" for an extensively documented example.
return "No documentation yet.";
}
void WMAtlasCreator::connectors()
{
m_output = boost::shared_ptr< WModuleOutputData < WDataSetScalar > >(
new WModuleOutputData< WDataSetScalar >( shared_from_this(), "out", "The created image." ) );
addConnector( m_output );
WModule::connectors();
}
void WMAtlasCreator::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
// Put the code for your properties here. See "src/modules/template/" for an extensively documented example.
//m_propMetaFile = m_properties->addProperty( "Tree file", "", WPathHelper::getAppPath() );
m_propDirectory = m_properties->addProperty( "Directoy", "", boost::filesystem::path( "/SCR/ratte/png8/Amyg034.png" ) );
m_propReadTrigger = m_properties->addProperty( "Do read", "Press!", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
WModule::properties();
}
void WMAtlasCreator::moduleMain()
{
m_moduleState.setResetable( true, true );
m_moduleState.add( m_propCondition );
m_moduleState.add( m_active->getUpdateCondition() );
ready();
debugLog() << m_volume.size();
while( !m_shutdownFlag() )
{
m_moduleState.wait();
if( m_shutdownFlag() )
{
break;
}
if( m_propReadTrigger->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
{
boost::filesystem::path fileName = m_propDirectory->get();
m_propReadTrigger->set( WPVBaseTypes::PV_TRIGGER_READY, true );
loadPngs( fileName );
updateOutDataset();
}
}
}
bool WMAtlasCreator::loadPngs( boost::filesystem::path sliceFile )
{
using namespace boost::filesystem; //NOLINT
if( !exists( sliceFile ) )
{
return false;
}
osg::Image* osgImage;
osgImage = osgDB::readImageFile( sliceFile.string().c_str() );
debugLog() << osgImage->r() << " : " << osgImage->s() << " : " << osgImage->t();
m_xDim = osgImage->s();
m_yDim = 60;
m_zDim = osgImage->t();
path dirPath( sliceFile );
dirPath.remove_filename().string();
m_volume.resize( m_xDim * m_yDim * m_zDim, 0 );
directory_iterator end_itr; // default construction yields past-the-end
for( directory_iterator itr( dirPath ); itr != end_itr; ++itr )
{
//debugLog() << itr->path().string().c_str();
path p( itr->path() );
if( p.extension() == ".png" )
{
addPngToVolume( p );
}
}
for( size_t i = 0; i < m_regions.size(); ++i )
{
debugLog() << i << ": " << m_regions[i];
}
return true;
}
void WMAtlasCreator::addPngToVolume( boost::filesystem::path image )
{
using namespace boost::filesystem; //NOLINT
std::string fn = image.filename().string();
fn.erase( fn.size() - 4, 4 );
std::string number = fn.substr( fn.size() - 3 );
fn.erase( fn.size() - 3, 3 );
size_t pos = string_utils::fromString<size_t>( number );
if( pos > 119 )
{
return;
}
uint8_t id = 0;
bool found = false;
for( size_t i = 0; i < m_regions.size(); ++i )
{
if( m_regions[i] == fn )
{
id = static_cast<uint8_t>( i );
found = true;
}
}
if( !found )
{
m_regions.push_back( fn );
id = static_cast<uint8_t>( m_regions.size() - 1 );
}
osg::Image* osgImage;
osgImage = osgDB::readImageFile( image.string().c_str() );
unsigned char* data = osgImage->data();
pos /= 2;
++id;
for( int i = 0; i < m_zDim; ++i )
{
for( int k = 0; k < m_xDim; ++k )
{
if( data[k * 3 + ( i * m_xDim * 3 )] != 0 )
{
m_volume[ pos * m_xDim + ( i * m_xDim * m_yDim ) + k ] = id;
}
}
}
}
void WMAtlasCreator::updateOutDataset()
{
boost::shared_ptr< WValueSet< unsigned char > > vs =
boost::shared_ptr< WValueSet< unsigned char > >( new WValueSet< unsigned char >(
0, 1, boost::shared_ptr< std::vector< uint8_t > >( new std::vector< uint8_t >( m_volume ) ), W_DT_UINT8 ) );
WMatrix< double > mat( 4, 4 );
mat.makeIdentity();
mat( 0, 0 ) = 0.1;
mat( 2, 2 ) = 0.1;
boost::shared_ptr<WGridRegular3D> grid = boost::shared_ptr<WGridRegular3D>( new WGridRegular3D( m_xDim, m_yDim, m_zDim,
WGridTransformOrtho( mat ) ) );
boost::shared_ptr< WDataSetScalar >outData = boost::shared_ptr< WDataSetScalar >( new WDataSetScalar( vs, grid ) );
m_output->updateData( outData );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMATLASCREATOR_H
#define WMATLASCREATOR_H
#include <string>
#include <vector>
#include <osg/Geode>
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
#include "core/dataHandler/WDataSetScalar.h"
#include "core/dataHandler/WValueSet.h"
/**
* Someone should add some documentation here.
* Probably the best person would be the module's
* creator, i.e. "schurade".
*
* This is only an empty template for a new module. For
* an example module containing many interesting concepts
* and extensive documentation have a look at "src/modules/template"
*
* \ingroup modules
*/
class WMAtlasCreator: public WModule
{
public:
/**
*
*/
WMAtlasCreator();
/**
*
*/
virtual ~WMAtlasCreator();
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual const std::string getName() const;
/**
* Gives back a description of this module.
* \return description to module.
*/
virtual const std::string getDescription() const;
/**
* Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
* should never be initialized or modified in some other way. A simple new instance is required.
*
* \return the prototype used to create every module in OpenWalnut.
*/
virtual boost::shared_ptr< WModule > factory() const;
/**
* Get the icon for this module in XPM format.
* \return The icon.
*/
virtual const char** getXPMIcon() const;
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void moduleMain();
/**
* Initialize the connectors this module is using.
*/
virtual void connectors();
/**
* Initialize the properties for this module.
*/
virtual void properties();
private:
/**
* loads and parses the meta file
* \param path to the meta file
* \return true if a meta file was successfully loaded, false otherwise
*/
bool loadPngs( boost::filesystem::path path );
/**
* inserts a slice, given as a png image into the volume
* \param image path to the image file
*/
void addPngToVolume( boost::filesystem::path image );
/**
* updates the output connector
*/
void updateOutDataset();
WPropTrigger m_propReadTrigger; //!< This property triggers the actual reading,
WPropFilename m_propDirectory; //!< The png files will be loaded form this directory
/**
* A condition used to notify about changes in several properties.
*/
boost::shared_ptr< WCondition > m_propCondition;
std::vector< std::string > m_regions; //!< store the region names extracted fromt he file name
std::vector< uint8_t >m_volume; //!< volume data created from 2d images
/**
* An output connector for the output scalar dsataset.
*/
boost::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output;
int m_xDim; //!< x Dimension of the volume
int m_yDim; //!< y Dimension of the volume
int m_zDim; //!< z Dimension of the volume
};
#endif // WMATLASCREATOR_H
/* XPM */
static const char * WMAtlasCreator_xpm[] = {
"32 32 245 2",
" c None",
". c #FFE300",
"+ c #FFE400",
"@ c #FFE100",
"# c #FFE200",
"$ c #FFE000",
"% c #FFDF00",
"& c #FFD600",
"* c #FFD700",
"= c #FFD500",
"- c #FFD400",
"; c #FFCC00",
"> c #FFCB00",
", c #FFCA00",
"' c #FFC900",
") c #FFC100",
"! c #FFC000",
"~ c #FFBF00",
"{ c #FFBE00",
"] c #FFB500",
"^ c #FFB600",
"/ c #FFB200",
"( c #FFB100",
"_ c #FFAE00",
": c #FFAD00",
"< c #FFAA00",
"[ c #FFAB00",
"} c #FFA600",
"| c #FFA700",
"1 c #FFA300",
"2 c #FFA400",
"3 c #FFA000",
"4 c #FFA100",
"5 c #FF9D00",
"6 c #000000",
"7 c #FF9C00",
"8 c #FF9A00",
"9 c #FF9900",
"0 c #FF9600",
"a c #FF9500",
"b c #FF9200",
"c c #FF9300",
"d c #FF8F00",