[OpenWalnut-Dev] Write file reader for WDataSetScalar

Frank Zisko frank.zisko at gmx.net
Thu May 10 17:58:24 CEST 2012



Hey guys,

I've a problem in writing a file reader.  
(ROOT/src/modules/data/io/WReaderMy.cpp  .h)
It is a anatomic file. Including a header, voxels (intensity values)  
and postheader.

I try to use a WDataSetScalar. Constructor want: WDataSetScalar  
aDataSet = new (WValueSetBase,WGrid). But something is wrong in my  
code. I write all values in WValueSet and create a WGrid. The 3D  
viewer shows a black dataset, the histogram viewer give me errors (see  
below). The tmp variable in the loop has right values. But I don't  
know why it doesn't works.

Has anybody an idea what can i do?


HEADER

[...]
protected:

     boost::shared_ptr< std::ifstream > m_ifs;
[...]


SOURCE

#include ...
[...]
boost::shared_ptr< WDataSet > WReaderMy::read()
{
     m_ifs = boost::shared_ptr< std::ifstream >( new std::ifstream() );
     m_ifs->open( m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
[...]
     wlog::info( "WReaderMy" ) << "Read array ...";
     // My Data Array.
     int voxelCount = dimX * dimY * dimZ;
     int tensorDim = 1; // Scalar values.
     int order = 0; // ?
     boost::shared_ptr< std::vector< int > > myData =   
boost::shared_ptr< std::vector< int > >( new std::vector< int >(  
voxelCount ) );

     int tmp = 0;
     for (int i = 0; i < voxelCount; i++)
     {
         //m_ifs->read( reinterpret_cast<char*>(&myData->at(i) ),  1);
         m_ifs->read( reinterpret_cast<char*>(&tmp),  1); // Read 1 byte.
         (*myData)[i] = tmp;
     }
     wlog::info( "WReaderMy" ) << "Read array ... Done.";

     boost::shared_ptr< WValueSetBase > myValueSet; // For creatiung  
DataSetScalar ( WValueSetBase, WGrid).
     myValueSet = boost::shared_ptr< WValueSetBase >( new WValueSet<  
int >( order, tensorDim, myData) );


[...]
     boost::shared_ptr< WGrid > myGrid;
     myGrid = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D(  
dimX, dimY, dimZ, WGridTransformOrtho( getStandardTransform() ) ) );
     boost::shared_ptr< WDataSet > myDataSet;
     wlog::debug( "WReaderMy" ) << "Load as WDataSetScalar";
     myDataSet = boost::shared_ptr< WDataSet >( new WDataSetScalar(  
myValueSet, myGrid ) );
     myDataSet->setFilename( m_fname );
     m_ifs->close();
     return myDataSet;
}


Histogram output in bash:

[...]
*INFO    [ModuleContainer (KernelRootContainer)] Connecting Data  
Module:out with HistogramView:Input dataset #0
*INFO    [HistogramView] Recalculating histogram.
Exception thrown! Callstack's backtrace:
trace: WException::WException(std::exception  
const&)	->	lib/libopenwalnut.so.1(_ZN10WExceptionC1ERKSt9exception+0x135)  
[0x7ff3457e6715]
trace:  
WThreadedRunner::threadMainSave()	->	lib/libopenwalnut.so.1(_ZN15WThreadedRunner14threadMainSaveEv+0xba)  
[0x7ff34581b00a]
trace: boost::detail::thread_data<boost::function<void ()>  
 >::run()	->	lib/libopenwalnut.so.1(_ZN5boost6detail11thread_dataINS_8functionIFvvEEEE3runEv+0x1e)  
[0x7ff34581d98e]
trace:  
thread_proxy()	->	/usr/lib/libboost_thread.so.1.46.1(thread_proxy+0x69)  
[0x7ff341f19ba9]
trace: ()	->	/usr/lib/nvidia-current-updates/libGL.so.1(+0xa7354)  
[0x7ff33f197354]

*ERROR   [KernelRootContainer] Error in module "HistogramView".  
Forwarding to nesting container.
*INFO    [ModuleContainer (KernelRootContainer)] Disconnecting Data  
Module:out from HistogramView:Input dataset #0
*ERROR   [Module (HistogramView)] WException. Notifying. Message:  
vector::_M_range_check




More information about the OpenWalnut-Dev mailing list