34 #ifndef CARTODATA_IO_VOLUMEFORMATREADER_D_H 35 #define CARTODATA_IO_VOLUMEFORMATREADER_D_H 61 #define localMsg( message ) cartoCondMsg( 4, message, "VOLUMEFORMATREADER" ) 90 template <
typename T>
void 98 std::string url = FileUtil::uriFilename( uri );
100 if( urioptions.
get() ) {
103 options->copyProperties( urioptions );
108 return FormatReader<Volume<T> >::setupAndRead( obj, dsi, context,
112 typename std::set<std::string>::iterator p;
113 typename std::set<std::string>::iterator plast = prop.end();
114 for( p = prop.begin(); p != prop.end(); ++p )
116 if( options->hasProperty( *p ) )
119 bool convert =
false;
120 options->getProperty(
"convert_to_aims", convert );
140 template <
typename T> Volume<T>*
145 localMsg(
"Creating and reading object ( " + dsi->
url() +
" )" );
149 std::string url = FileUtil::uriFilename( uri );
154 options = options->clone();
155 if( urioptions.
get() ) {
156 options->copyProperties( urioptions );
161 return FormatReader<Volume<T> >::createAndRead( dsi, context, options );
164 typename std::set<std::string>::iterator p;
165 typename std::set<std::string>::iterator plast = prop.end();
166 Volume<T> *volume = 0;
167 for( p = prop.begin(); p != plast; ++p )
169 if( options->hasProperty( *p ) )
171 localMsg(
"using VolumeUtilIO<T>::read ( " + dsi->
url() +
" )" );
179 localMsg(
"using classical Volume reading ( " + dsi->
url() +
" )" );
181 dsi, context, options );
185 bool convert =
false;
186 options->getProperty(
"convert_to_aims", convert );
210 template <
typename T>
216 localMsg(
"Reading object ( " + dsi->
url() +
" )" );
219 std::string otype = dsi->
header()->getProperty(
"object_type" )->getString();
220 std::string dtype = dsi->
header()->getProperty(
"data_type" )->getString();
221 std::string ttype = DataTypeCode<T>::dataType();
222 if( otype !=
"Volume" )
223 throw datatype_format_error(
"unsupported data type - " + otype +
" != Volume", dsi->
url() );
226 if( dsi->
header()->hasProperty(
"possible_data_types" ) )
230 i<dsi->
header()->getProperty(
"possible_data_types" )->size();
233 if( dsi->
header()->getProperty(
"possible_data_types" )
234 ->getArrayItem( i )->getString()
238 if( i == dsi->
header()->getProperty(
"possible_data_types" )->size() )
239 throw datatype_format_error( dsi->
url() );
241 throw datatype_format_error(
"unsupported data type - " + dtype +
" != " + ttype, dsi->
url() );
245 localMsg(
"checking for memory mapping..." );
249 localMsg(
" -> Memory Mapping : nothing to read." );
254 localMsg(
"checking if object is a view..." );
261 localMsg(
" -> Unallocated Volume : nothing to read." );
264 localMsg( std::string(
" -> object ") + ( parent1 ?
"is" :
"isn't" )
270 localMsg( std::string(
" -> parent exists and ")
276 localMsg( std::string(
" -> grandparent exists and ")
283 std::vector<int> viewsize = obj.
getSize();
291 localMsg(
"reading multiresolution level..." );
293 if( options->hasProperty(
"resolution_level" ) ) {
294 options->getProperty(
"resolution_level", level );
300 level += dsi->
header()->getProperty(
"resolutions_dimension" )
310 localMsg(
"reading full volume size..." );
311 std::vector<int> imagesize( 4, 0 );
316 = dsi->
header()->getProperty(
"resolutions_dimension" )->getArrayItem(
318 int i, ndim = dim->size();
319 imagesize.resize(
std::max(
size_t( 4 ), dim->size() ), 1 );
320 for( i=0; i<ndim; ++i )
321 imagesize[ i ] = (
int) rint( dim->getArrayItem( i )->getScalar() );
322 localMsg(
" -> found \"resolutions_dimension\"." );
330 int i, ndim = dim->size();
331 imagesize.resize(
std::max(
size_t( 4 ), dim->size() ), 1 );
332 for( i=0; i<ndim; ++i )
333 imagesize[ i ] = (
int) rint( dim->getArrayItem( i )->getScalar() );
334 localMsg(
" -> found \"volume_dimension\"." );
340 imagesize = parent1->
getSize();
341 localMsg(
" -> found unallocated parent." );
342 }
else if( parent2 ) {
343 imagesize = parent2->
getSize();
344 localMsg(
" -> found grandparent." );
346 imagesize = viewsize;
347 localMsg(
" -> full volume is self." );
359 localMsg(
"reading allocated size..." );
360 std::vector<int> allocsize( 4, 0 );
362 allocsize = viewsize;
363 localMsg(
" -> allocated volume is self (full volume)." );
365 allocsize = viewsize;
366 localMsg(
" -> allocated volume is self (partial volume)." );
368 allocsize = parent1->
getSize();
369 localMsg(
" -> allocated volume is parent " 370 "(borders or partially loading in full volume)." );
372 localMsg(
" -> allocated volume size ( " 379 size_t i, ndim = allocsize.size();
380 std::vector<long> strides( ndim );
381 std::vector<int> stride_pos;
382 for( i=0; i<ndim; ++i )
384 stride_pos = std::vector<int>( ndim, 0 );
386 strides[i] = &obj( stride_pos ) - &obj( 0,0,0,0 );
390 localMsg(
"reading view position in reference to full volume..." );
391 std::vector<int> pos ( ndim, 0 );
394 }
else if( parent2 ) {
406 bool withborders =
false;
407 bool partialreading =
false;
408 for( i=0; i<ndim; ++i )
410 if( allocsize[i] > viewsize[i] )
412 if( imagesize[i] > viewsize[i] )
413 partialreading =
true;
416 + std::string( ( withborders ?
"yes" :
"no" ) ) );
418 + std::string( ( partialreading ?
"yes" :
"no" ) ) );
419 partialreading = partialreading;
425 localMsg(
"reading volume using strides..." );
427 _imr->read( ( T * ) &obj(0,0,0,0), *dsi, pos,
428 viewsize, strides, options );
432 localMsg(
"reading volume without strides..." );
435 std::vector<int> posline ( pos );
436 std::vector<int> sizeline ( ndim, 1 );
437 std::vector<int> volpos( ndim, 0 );
439 sizeline[ 0 ] = viewsize[ 0 ];
441 bool nextrow =
false, ended =
false;
443 bool was_open = _imr->isOpen( *dsi );
445 if( !was_open && !_imr->open( *dsi ) )
451 for( dim=1; dim<ndim; ++dim )
456 if( volpos[dim] == viewsize[dim] )
458 if( dim == ( ndim - 1 ) )
465 posline[dim] = pos[dim] + volpos[dim];
469 posline[1] = pos[1] + volpos[1];
470 _imr->read( ( T * ) &obj( volpos ), *dsi, posline,
471 sizeline, strides, options );
500 template <
typename T>
511 template <
typename T>
518 template <
typename T>
524 return _imr->formatID();
534 template <
typename T>
545 template <
typename T>
void 553 std::string url = FileUtil::uriFilename( uri );
555 if( urioptions.
get() ) {
558 options->copyProperties( urioptions );
562 if( !options.
get() ) {
570 typename std::set<std::string>::iterator p;
571 typename std::set<std::string>::iterator plast = prop.end();
572 for( p = prop.begin(); p != plast; ++p )
574 if( options->hasProperty( *p ) )
579 bool convert =
false;
580 options->getProperty(
"convert_to_aims", convert );
597 template <
typename T> VolumeRef<T>*
604 return new VolumeRef<T>( vrf.
createAndRead( dsi, context, options ) );
615 template <
typename T>
623 vrf.
read( *obj, dsi, context, options );
629 template <
typename T>
636 template <
typename T>
646 template <
typename T>
652 return _imr->formatID();
const Position & posInRefVolume() const
Get position in parent volume.
const carto::rc_ptr< DataSource > & dataSource(const std::string &s="default", int i=0) const
T max(const Volume< T > &vol)
Returns the maximum value of the volume.
bool canHandleStrides() const
MappingMode allocatorType() const
const DataSourceCapabilities & capabilities() const
Convenient handle for a Volume - this is normally the entry point for all volumes handling...
static Object reference(T &value)
std::vector< int > getSize() const
get the 4 dimensions in a vector
const AllocatorContext & allocatorContext() const
returns volume's AllocatorContext
rc_ptr< Volume< T > > refVolume() const
Get parent volume.
static carto::Volume< T > * read(carto::Volume< T > *obj, carto::rc_ptr< DataSourceInfo > dsi, carto::Object options)
Manages all the volumes necessary and returns the final Volume.
static std::set< std::string > listReadProperties()
list of properties triggering partial reading and/or borders
GenericObject * get() const
std::string toString(const T &object)
const carto::Object & header() const
const DataSourceList & list() const