Commit 8d33adaf authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents 36fc86cd 74c9ca16
......@@ -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",
"e c #FF8C00",
"f c #FF8B00",
"g c #FF8800",
"h c #FF8801",
"i c #FF8900",
"j c #FE8800",
"k c #FE8701",
"l c #FE8702",
"m c #FD8702",
"n c #FD8701",
"o c #FE8801",
"p c #FC8603",
"q c #FD8603",
"r c #FD8602",
"s c #FC8602",
"t c #FD8502",
"u c #FC8504",
"v c #FB8504",
"w c #FC8404",
"x c #FC8503",
"y c #FB8404",
"z c #FA8305",
"A c #FB8405",
"B c #C16503",
"C c #8D4A02",
"D c #FB8305",
"E c #703B02",
"F c #FA8405",
"G c #DF7505",
"H c #1E0F00",
"I c #FA8306",
"J c #FB8306",
"K c #FB8406",
"L c #F98307",
"M c #F98206",
"N c #F98207",
"O c #371D01",
"P c #482601",
"Q c #6E3A03",
"R c #F98306",
"S c #FA8206",
"T c #110900",
"U c #A65704",
"V c #542C02",
"W c #FA8307",
"X c #FA8207",
"Y c #F88207",
"Z c #F98108",
"` c #F88108",
" . c #A65605",
".. c #492602",
"+. c #A35505",
"@. c #502902",
"#. c #F88107",
"$. c #703A03",
"%. c #8B4803",
"&. c #F98107",
"*. c #DC7306",
"=. c #402101",
"-. c #050300",
";. c #1A0D00",
">. c #A25405",
",. c #8F4A04",
"'. c #0D0700",
"). c #130A00",
"!. c #9F5205",
"~. c #F78009",
"{. c #F78109",
"]. c #F27D07",
"^. c #261401",
"/. c #D26C07",
"(. c #C66607",
"_. c #311901",
":. c #F88109",
"<. c #D76F06",
"[. c #201101",
"}. c #F88009",
"|. c #F88008",
"1. c #391D02",
"2. c #C06407",
"3. c #3B1E02",
"4. c #914B05",
"5. c #EF7B08",
"6. c #BD6206",
"7. c #0C0600",
"8. c #0A0500",
"9. c #D16B07",
"0. c #BD6106",
"a. c #F67F0B",
"b. c #F67F0A",
"c. c #8B4805",
"d. c #643304",
"e. c #E47509",
"f. c #130900",
"g. c #974E06",
"h. c #633304",
"i. c #F77F0A",
"j. c #F27C09",
"k. c #0F0700",
"l. c #EF7B09",
"m. c #E77709",
"n. c #D46C09",
"o. c #C86608",
"p. c #994F06",
"q. c #180C00",
"r. c #F67E0A",
"s. c #4A2603",
"t. c #3D1F02",
"u. c #C36307",
"v. c #F67E0B",
"w. c #F77F0B",
"x. c #F57D0B",
"y. c #E6760A",
"z. c #1D0F01",
"A. c #DD720A",
"B. c #F57E0B",
"C. c #0B0500",
"D. c #EC790A",
"E. c #F57E0C",
"F. c #582D03",
"G. c #A45408",
"H. c #F67E0C",
"I. c #C36408",
"J. c #341B02",
"K. c #A15307",
"L. c #060300",
"M. c #321A02",
"N. c #4B2703",
"O. c #F27C0A",
"P. c #A05207",
"Q. c #291501",
"R. c #844405",
"S. c #F47D0D",
"T. c #723A06",
"U. c #CC680A",
"V. c #1B0E01",
"W. c #E2740C",
"X. c #F47C0D",
"Y. c #8D4706",
"Z. c #6A3605",
"`. c #F47C0C",
" + c #1A0D01",
".+ c #C7660A",
"++ c #381C02",
"@+ c #A45308",
"#+ c #070300",
"$+ c #E9760B",
"%+ c #F57D0D",
"&+ c #DE710A",
"*+ c #F47D0C",
"=+ c #241202",
"-+ c #EB780D",
";+ c #F37C0E",
">+ c #F37B0E",
",+ c #432203",
"'+ c #AE580A",
")+ c #DC700C",
"!+ c #130901",
"~+ c #EB780C",
"{+ c #562B04",
"]+ c #9F5009",
"^+ c #100800",