Commit 94c6b55a authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents adea6056 df2053c3
......@@ -60,3 +60,18 @@ std::string WStatusReport::stringBar( char symbol, unsigned int finalNumOfSymbol
unsigned int numSymbols = progress() * finalNumOfSymbols;
return std::string( numSymbols, symbol );
}
unsigned int WStatusReport::getTotalSteps() const
{
return m_totalSteps;
}
unsigned int WStatusReport::getFinishedSteps() const
{
return m_finishedSteps;
}
double WStatusReport::progress() const
{
return static_cast< double >( m_finishedSteps ) / m_totalSteps;
}
......@@ -28,7 +28,8 @@
#include <string>
/**
* A counter for reporting the progress of some work.
* A counter for reporting the progress of some work. The work is represented
* as steps, and hence the progress of the ratio of finished_steps / overall_steps.
*/
class WStatusReport
{
......@@ -44,26 +45,17 @@ public:
* Returns the total number of steps which are considered as 100 percent
* work.
*/
unsigned int getTotalSteps() const
{
return m_totalSteps;
}
unsigned int getTotalSteps() const;
/**
* Returns the number of steps done so far
*/
unsigned int getFinishedSteps() const
{
return m_finishedSteps;
}
unsigned int getFinishedSteps() const;
/**
* Returns the progress in percentage done so far: e.g. 0.7 == 70%
*/
double progress() const
{
return static_cast< double >( m_finishedSteps ) / m_totalSteps;
}
double progress() const;
/**
* Increments the finished work by one step.
......@@ -86,8 +78,9 @@ public:
protected:
private:
unsigned int m_totalSteps;
unsigned int m_finishedSteps;
unsigned int m_totalSteps; //!< indication of the overall work
unsigned int m_finishedSteps; //!< indicates the work done so far
};
#endif // WSTATUSREPORT_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-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 <stdexcept>
#include <string>
#include "WDHNoSuchFile.h"
WDHNoSuchFile::WDHNoSuchFile( const std::string &fname )
: WDHException( "file: '" + fname + "' not found" )
{
}
WDHNoSuchFile::~WDHNoSuchFile() throw()
{
// clean up
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-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 WDHNOSUCHFILE_H
#define WDHNOSUCHFILE_H
#include <stdexcept>
#include <string>
#include "WDHException.h"
/**
* File not found exception.
*/
class WDHNoSuchFile : public WDHException
{
public:
/**
* Default constructor.
* \param msg the exception message.
*/
explicit WDHNoSuchFile( const std::string &fname = "unknown file not found" );
/**
* Destructor
*/
virtual ~WDHNoSuchFile() throw();
protected:
private:
};
#endif // WDHNOSUCHFILE_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-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 "WReader.h"
#include "WIOTools.hpp"
#include "../exceptions/WDHNoSuchFile.h"
WReader::WReader( std::string fname )
{
setFileName( fname ); // not in constructor list since fileExcsits check
}
void WReader::setFileName( std::string fname ) throw( WDHNoSuchFile )
{
m_fname = fname;
if( !wiotools::fileExists( m_fname ) )
{
throw WDHNoSuchFile( m_fname );
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-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 WREADER_H
#define WREADER_H
#include <string>
#include "../exceptions/WDHNoSuchFile.h"
/**
* Read some data from a given file. This base class is just for file
* management (file exists, etc.) Subclasses may use those mechanisms and
* specify their file format which is not the purpose of this base class.
*/
class WReader
{
public:
/**
* Creates a read object for file reading.
*
* \param fname path to file which should be loaded
*/
explicit WReader( std::string fname );
/**
* Reset the file name and checks if it exists.
*
* \throws WDHNoSuchFile
*/
void setFileName( std::string fname ) throw( WDHNoSuchFile );
protected:
std::string m_fname; //!< Absolute path of the file to read from
private:
};
#endif // WREADER_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-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 <fstream>
#include <stdexcept>
#include <string>
#include <vector>
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include "WIOTools.hpp"
#include "WReader.h"
#include "WReaderLookUpTableVTK.h"
#include "../exceptions/WDHException.h"
#include "../exceptions/WDHIOFailure.h"
#include "../../common/WStringUtils.hpp"
WReaderLookUpTableVTK::WReaderLookUpTableVTK( std::string fname )
: WReader( fname )
{
}
void WReaderLookUpTableVTK::readTable( boost::shared_ptr< std::vector< double > > table ) const
{
assert( table->size() == 0 && "error, since the vector will be filled IN HERE" );
// code mainly taken from WLoaderFibers.cpp, and adjusted since I don't
// know how to code this DRY. Any suggestions?
std::ifstream ifs;
ifs.open( m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
assert( ifs && !ifs.bad() );
std::vector< std::string > header;
std::string line;
try
{
for( int i = 0; i < 4; ++i ) // strip first four lines
{
std::getline( ifs, line );
if( !ifs.good() )
{
throw WDHException( "Unexpected end of file: " + m_fname );
}
header.push_back( line );
}
}
catch( const std::ios_base::failure &e )
{
throw WDHIOFailure( "Reading first 4 lines of '" + m_fname + "': " + e.what() );
}
assert( header[0] == "# vtk DataFile Version 3.0" );
assert( header[1] == "DXtLookUpTable from OpenWalnut" );
assert( header[2] == "BINARY" );
assert( header[3] == "FIELD DXtLookUpTable 1" );
try
{
std::getline( ifs, line ); // something like this: "DISTANCES 15879430 1 float" expected
}
catch( const std::ios_base::failure &e )
{
throw WDHIOFailure( "Error reading DISTANCES field '" + m_fname + "': " + e.what() );
}
namespace su = string_utils;
size_t numDistances = 0;
std::vector< std::string > tokens = su::tokenize( line );
if( tokens.size() != 4 || su::toLower( tokens.at( 3 ) ) != "float" )
{
throw WDHException( "Invalid DISTANCES declaration: " + line );
}
try
{
numDistances = boost::lexical_cast< size_t >( tokens.at( 1 ) );
}
catch( const boost::bad_lexical_cast &e )
{
throw WDHException( "Invalid number of distances: " + tokens.at( 1 ) );
}
float *data = new float[ numDistances ];
try
{
ifs.read( reinterpret_cast< char* >( data ), sizeof( float ) * numDistances );
}
catch( const std::ios_base::failure &e )
{
throw WDHIOFailure( "Error reading distances in VTK DISTANCES field '" + m_fname + "': " + e.what() );
}
// all 4 bytes of each float are in wrong order we need to reorder them
wiotools::switchByteOrderOfArray( data, numDistances );
for( size_t i = 0; i < numDistances; ++i )
{
table->push_back( static_cast< double >( data[ i ] ) );
}
delete[] data;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-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 WREADERLOOKUPTABLEVTK_H
#define WREADERLOOKUPTABLEVTK_H
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "WReader.h"
/**
* Can read a look up table from a file in VTK format.
*/
class WReaderLookUpTableVTK : public WReader
{
public:
/**
* Creates a reader object for look up tables. On parameter documention
* take a look into the WReader base class.
*/
explicit WReaderLookUpTableVTK( std::string fname );
/**
* Perform reading from the file.
*/
void readTable( boost::shared_ptr< std::vector< double > > table ) const;
protected:
private:
};
#endif // WREADERLOOKUPTABLEVTK_H
......@@ -28,11 +28,9 @@
#include <string>
/**
* Writes some data to a file. This class is only for convenience access to
* rudimentary file management things such as: file exists, if the given
* file should be overwritten, etc. Subclasses may use those mechanisms in
* their own public memberfunctions where the signature is different every
* time. e.g. writeFibs( WDataSetFibers ds );
* Write some data to the given file. This base class is just for file
* management (file exists, etc.) Subclasses may use those mechanisms and
* specify their file format which is not the purpose of this base class.
*/
class WWriter
{
......@@ -47,7 +45,8 @@ public:
WWriter( std::string fname, bool overwrite = false );
/**
* Reset the destination (file) where the writing should take place.
* Reset file name and checks if the file already exists in case of
* non overwriting is specified.
*/
void setFileName( std::string fname );
......
......@@ -38,7 +38,7 @@ WWriterLookUpTableVTK::WWriterLookUpTableVTK( std::string fname, bool overwrite
{
}
void WWriterLookUpTableVTK::writeTable( const std::vector< double > &table ) const
void WWriterLookUpTableVTK::writeTable( const std::vector< double > &table, size_t dim ) const
{
using std::fstream;
fstream out( m_fname.c_str(), fstream::out | fstream::in | fstream::trunc );
......@@ -51,14 +51,15 @@ void WWriterLookUpTableVTK::writeTable( const std::vector< double > &table ) con
out << "BINARY" << std::endl;
out << "FIELD DXtLookUpTable 1" << std::endl;
unsigned int numDistances = table.size();
unsigned int numDistances = table.size() + 1;
out << "DISTANCES " << numDistances << " 1 float" << std::endl;
float *data = new float[numDistances];
for( size_t i = 0; i < numDistances; ++i )
for( size_t i = 0; i < table.size() ; ++i )
{
data[i] = static_cast< float >( table[i] );
}
data[ numDistances - 1 ] = static_cast< float >( dim );
wiotools::switchByteOrderOfArray< float >( data, numDistances );
out.write( reinterpret_cast< char* >( data ), sizeof( float ) * numDistances );
......
......@@ -50,7 +50,7 @@ public:
* \param table The data in that table will be saved
* \param dim the dimensionality of the table
*/
void writeTable( const std::vector< double > &table ) const;
void writeTable( const std::vector< double > &table, size_t dim ) const;
protected:
private:
......
......@@ -135,14 +135,10 @@ void WGEGraphicsWindow::keyEvent( KeyEvents eventType, int key )
switch( eventType )
{
case KEYPRESS:
m_GraphicsWindow->getEventQueue()->keyPress(
static_cast<osgGA::GUIEventAdapter::KeySymbol>( key )
);
m_GraphicsWindow->getEventQueue()->keyPress( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
break;
case KEYRELEASE:
m_GraphicsWindow->getEventQueue()->keyRelease(
static_cast<osgGA::GUIEventAdapter::KeySymbol>( key )
);
m_GraphicsWindow->getEventQueue()->keyRelease( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
break;
}
}
......@@ -152,19 +148,13 @@ void WGEGraphicsWindow::mouseEvent( MouseEvents eventType, int x, int y, int but
switch( eventType )
{
case MOUSEPRESS:
m_GraphicsWindow->getEventQueue()->mouseButtonPress(
x, y, button
);
m_GraphicsWindow->getEventQueue()->mouseButtonPress( x, y, button );
break;
case MOUSERELEASE:
m_GraphicsWindow->getEventQueue()->mouseButtonRelease(
x, y, button
);
m_GraphicsWindow->getEventQueue()->mouseButtonRelease( x, y, button );
break;
case MOUSEDOUBLECLICK:
m_GraphicsWindow->getEventQueue()->mouseDoubleButtonPress(
x, y, button
);
m_GraphicsWindow->getEventQueue()->mouseDoubleButtonPress( x, y, button );
break;
case MOUSEMOVE:
m_GraphicsWindow->getEventQueue()->mouseMotion( x, y );
......
......@@ -36,6 +36,7 @@
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/View>
#include <osgDB/ReadFile>
......@@ -85,6 +86,8 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i
osg::ref_ptr<osgText::Text> updateText = new osgText::Text;
m_View->addEventHandler( new WPickHandler( updateText.get() ) );
keyEvent( WGEViewer::KEYPRESS, ' ' );
}
catch( ... )
{
......
......@@ -197,22 +197,31 @@ void WQtDatasetBrowser::selectTreeItem()
void WQtDatasetBrowser::changeTreeItem()
{
if ( m_treeWidget->selectedItems().size() == 0 || m_treeWidget->selectedItems().at( 0 )->type() != 1 )
if ( m_treeWidget->selectedItems().size() == 1 && m_treeWidget->selectedItems().at( 0 )->type() == 1 )
{
return;
}
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
if ( m_treeWidget->selectedItems().at( 0 )->checkState( 0 ) )
{
module->getProperties()->setValue<bool>( "active", true );
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
if ( m_treeWidget->selectedItems().at( 0 )->checkState( 0 ) )
{
module->getProperties()->setValue<bool>( "active", true );
}
else
{
module->getProperties()->setValue<bool>( "active", false );
}
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
}
else
else if ( m_treeWidget->selectedItems().size() == 1 && m_treeWidget->selectedItems().at( 0 )->type() == 3 )
{
module->getProperties()->setValue<bool>( "active", false );
boost::shared_ptr< WModule >module =( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
if ( m_treeWidget->selectedItems().at( 0 )->checkState( 0 ) )
{
module->getProperties()->setValue<bool>( "active", true );
}
else
{
module->getProperties()->setValue<bool>( "active", false );
}