Skip to content

Commit

Permalink
fixed bug that caused segfault when calling a signal that receives a …
Browse files Browse the repository at this point in the history
…boost shared pointer of an image
  • Loading branch information
Erik Tuerke committed Jul 4, 2012
1 parent 67f3a36 commit ca5f507
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
24 changes: 13 additions & 11 deletions lib/core/data/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ namespace data
bool Image::forceTypedImage_ = false;
bool Image::forceProposedDataType_ = false;

// util::Signal<void( const util::SharredPointer<Image> &, const types::ImageDataType &)> Image::signal_conversion_begin;
// util::Signal<void( const util::SharredPointer<Image> &, const types::ImageDataType &)> Image::signal_conversion_end;
// util::Signal<void( const util::SharredPointer<Image> &, const ImageBase::ImageContentType &)> Image::signal_content_changed;
util::Signal<void( const Image &, const types::ImageDataType &)> Image::signal_conversion_begin;
util::Signal<void( const Image &, const types::ImageDataType &)> Image::signal_conversion_end;
util::Signal<void( const Image &, const ImageBase::ImageContentType &)> Image::signal_content_changed;

types::ImageDataType Image::proposedScalar_ = types::SCALAR_PROPOSED;
types::ImageDataType Image::proposedColor_ = types::COLOR_PROPOSED;
Expand Down Expand Up @@ -70,7 +70,7 @@ Image::Image ( const isis::data::Image& image )
break;
}
}
is_valid = synchronizeFrom( image, VOXELS );
is_valid = synchronizeVoxelContentFrom( image );

if( !is_valid ) {
LOG( Runtime, error ) << "Creating of isis::glance::Image from "
Expand All @@ -84,8 +84,8 @@ Image::Image ( const isis::data::Image &image, bool force_typed_image )
type_( major_type )
{
forceTypedImage_ = force_typed_image;
is_valid = synchronizeFrom( image, VOXELS );

is_valid = synchronizeVoxelContentFrom( image );
if( !is_valid ) {
LOG( Runtime, error ) << "Creating of isis::glance::Image from "
<< file_path << " failed!";
Expand All @@ -97,8 +97,8 @@ Image::Image ( const isis::data::Image &image, const types::ImageDataType &type
type_( type )
{
forceTypedImage_ = true;
is_valid = synchronizeFrom( image, VOXELS );

is_valid = synchronizeVoxelContentFrom( image );
if( !is_valid ) {
LOG( data::Runtime, error ) << "Creating of isis::glance::Image from "
<< file_path << " failed!";
Expand Down Expand Up @@ -127,15 +127,17 @@ void Image::setProposedDataType ( const ImageDataProperties::ImageTypeGroup& typ

void Image::convertVolumesByType ( const types::ImageDataType &type )
{
// signal_conversion_begin.call(this, type);
signal_conversion_begin.call(*this, type);
LOG( Runtime, info ) << "Converting image " << file_path << " to type "
<< isis::util::getTypeMap(false).at(type);
VolumesType buffer;
const size_t volume_size[] = { image_size[0], image_size[1], image_size[2] };
BOOST_FOREACH( VolumesType::reference volume, volumes_ ) {
buffer.push_back( VolumeType( volume->convertByID( type ), volume_size ) );
}
assert( buffer.size() == volumes_.size() );
volumes_ = buffer;
// signal_conversion_end.call(this, type);
signal_conversion_end.call(*this, type);
}


Expand All @@ -161,7 +163,7 @@ bool Image::synchronizeFrom ( const isis::data::Image &image, const ImageBase::I

//send signal if synchronization was successful
if( ok ) {
// signal_content_changed.call(this, content );
signal_content_changed.call(*this, content );
}
return ok;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/core/data/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ class Image : public ImageBase
static void setProposedDataType( const Image::ImageTypeGroup &type_group, const types::ImageDataType &data_type );

// //signals
// static util::Signal<void( const util::SharredPointer<Image> &, const types::ImageDataType &)> signal_conversion_begin;
// static util::Signal<void( const util::SharredPointer<Image> &, const types::ImageDataType &)> signal_conversion_end;
// static util::Signal<void( const util::SharredPointer<Image> &, const ImageContentType &)> signal_content_changed;
static util::Signal<void( const Image &, const types::ImageDataType &)> signal_conversion_begin;
static util::Signal<void( const Image &, const types::ImageDataType &)> signal_conversion_end;
static util::Signal<void( const Image &, const ImageContentType &)> signal_content_changed;

protected:
bool synchronizeVoxelContentFrom( isis::data::Image image );
Expand Down
6 changes: 4 additions & 2 deletions lib/core/data/io_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ ImageVector IOFactory::_load ( const isis::util::slist &paths, const isis::util:
} else {
signal_start_loading_path.call(path);
//we have to do this consecutively cause IOFactory uses Singletons and so is not thread-safe
const std::list<isis::data::Image> images = isis::data::IOFactory::load( path, suffix_override, dialect );
std::list<isis::data::Image> images = isis::data::IOFactory::load( path, suffix_override, dialect );

if( images.size() == 0 ) {
signal_failed_loading_from_path.call( path );
//we do not need error messages here because isis will send them
} else {
signal_loaded_n_images_from_path.call( images.size(), path );
boost::shared_ptr<_internal::LoadingThread> threadPtr;
BOOST_FOREACH( std::list<isis::data::Image>::const_reference image, images ) {
BOOST_FOREACH( std::list<isis::data::Image>::reference image, images ) {
//setting the file_path so we can use that later
image.setPropertyAs<std::string>("file_path", path );
threadPtr.reset( new _internal::LoadingThread( image ) );
threadPtr->setDebugIdentification( path );
threadPtr->start();
Expand Down
6 changes: 6 additions & 0 deletions lib/core/data/io_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class IOFactory
*/
static ImageVector load( const isis::util::slist &paths, const isis::util::istring &suffix_override = "", const isis::util::istring &dialect = "" );

static void setForceTypedImage( const bool &force ) { isis::glance::data::Image::setForceTypedImage(force); }
static void setUseProposedDataType( const bool &use_proposed ) { isis::glance::data::Image::setUseProposedDataType( use_proposed ); }
static void setProposedDataType( const Image::ImageTypeGroup &type_group, const types::ImageDataType &data_type ) {
isis::glance::data::Image::setProposedDataType( type_group, data_type );
}

//signals
///This signal is called when starting to load a path
static util::Signal<void ( const std::string & )> signal_start_loading_path;
Expand Down
21 changes: 12 additions & 9 deletions tests/data/ioFactoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// {

// BOOST_AUTO_TEST_CASE( io_factory_test )#
void printPath( const std::string &path) {
std::cout << "PATH: " << path << std::endl;
void printPath( const isis::glance::util::SharredPointer<isis::glance::data::Image> &, const isis::glance::data::Image::ImageContentType &) {
std::cout << "PATH: " /*<< path*/ << std::endl;
}
int main()
{
// ENABLE_LOG( isis::glance::data::Debug, isis::util::DefaultMsgPrint, isis::verbose_info );
ENABLE_LOG( isis::glance::util::Debug, isis::util::DefaultMsgPrint, isis::verbose_info );
ENABLE_LOG( isis::glance::data::Runtime, isis::util::DefaultMsgPrint, isis::verbose_info );

isis::util::slist paths;
// paths.push_back("/SCR/DATA/viewerImages/my_mni.v");
Expand All @@ -29,24 +30,26 @@ int main()
// paths.push_back("/SCR/DATA/viewerImages/out.nii");
// paths.push_back("/SCR/DATA/viewerImages/x.v");
// paths.push_back("/SCR/DATA/viewerImages/zz.v");
// paths.push_back("/SCR/DATA/viewerImages/my_mni.v");
paths.push_back("/SCR/DATA/viewerImages/my_mni.v");
// paths.push_back("/SCR/DATA/viewerImages/t1.v");
// paths.push_back("/SCR/DATA/viewerImages/BK1T_091112_FLASH_mag.nii");
// paths.push_back("/SCR/DATA/viewerImages/BK1T_091126_FLASH_mag.nii");
// paths.push_back("/SCR/DATA/viewerImages/BK1T_091203_FLASH_mag.nii");
// paths.push_back("/SCR/DATA/viewerImages/out.nii");
// paths.push_back("/SCR/DATA/viewerImages/x.v");
// paths.push_back("/SCR/DATA/viewerImages/zz.v");
paths.push_back( "/SCR/DATA/ana9_contrast1_s16bit.nii" );
paths.push_back( "/SCR/DATA/ana9_contrast1_u16bit.nii" );
// paths.push_back( "/SCR/DATA/ana9_contrast1_s16bit.nii" );
// paths.push_back( "/SCR/DATA/ana9_contrast1_u16bit.nii" );

boost::timer timer;
timer.restart();

isis::glance::data::IOFactory::signal_start_loading_path.get().connect( &printPath );
isis::glance::data::Image::setUseProposedDataType(true);

std::cout << isis::glance::data::IOFactory::load( paths ).size() << std::endl;
// isis::glance::data::Image::signal_content_changed.get().connect( &printPath );
isis::glance::data::IOFactory::setUseProposedDataType(true);
isis::glance::data::IOFactory::setProposedDataType( isis::glance::data::ImageDataProperties::SCALAR, isis::glance::data::types::FLOAT );
isis::glance::data::ImageVector images = isis::glance::data::IOFactory::load( paths );

images.front()->synchronize(isis::glance::data::ImageBase::ALL);

std::cout << timer.elapsed() << " seconds" << std::endl;
return 0;
Expand Down

0 comments on commit ca5f507

Please sign in to comment.