aimsdata  5.0.5
Neuroimaging data handling
aims::Finder Class Reference

Generic finder / checker for all data objects and file formats This will replace the old AimsFinder. More...

#include <aims/io/finder.h>

Public Types

enum  State { Unchecked, Ok, Error }
 

Public Member Functions

 Finder ()
 
 ~Finder ()
 
bool check (const std::string &filename)
 Determines object associated to file name and returns true if success. More...
 
std::string objectType () const
 
void setObjectType (const std::string &obj)
 
std::string dataType () const
 
void setDataType (const std::string &dat)
 
std::vector< std::string > possibleDataTypes () const
 
void setPossibleDataTypes (const std::vector< std::string > &dt)
 
std::string format () const
 
void setFormat (const std::string &fmt)
 
const Headerheader () const
 
void setHeader (Header *hdr)
 
carto::Object headerObject () const
 
void setHeader (carto::Object hdr)
 
State state () const
 
std::string errorMessage () const
 
void launchException ()
 creates and throws an exception corresponding to the error state More...
 

Static Public Member Functions

static void registerFormat (const std::string &fmtid, FinderFormat *format, const std::vector< std::string > &extensions, const std::string &before="")
 
static FinderFormatfinderFormat (const std::string &format)
 Finds the FinderFormat associated with the given string ID. More...
 
static void unregisterFormat (const std::string &format)
 
static void postProcessHeader (carto::Object hdr)
 
static std::set< std::string > extensions (const std::string &format)
 show the set of official extensions for a given format More...
 

Detailed Description

Generic finder / checker for all data objects and file formats This will replace the old AimsFinder.

Warning: Finder will be replaced by carto::DataSourceInfo in cartobase library. Avoid using it in new code.

The Finder provides a plug-in system for new formats and data types. Formats are hidden in the plugins and should never be accessed directly.

Usage: check() the file and then process according to the object type ("Volume", "Mesh", "Texture", "Bucket", ...) and its data type (if any) ("S16" : short, "U8": unsigned byte, "FLOAT", "DOUBLE", ...)
Use the generic Reader once the data type is known, the right format will be selected automatically.

Avoiding manually switching on objects and data types is now possible using the new Process interface and presumably, template functions.

See the AimsFileInfo command for an example of how to use it.

Here is an example of using the Finder class:

#include <aims/io/finder.h>
#include <aims/io/reader.h>
#include <aims/data/data.h>
string fname = "toto.ima";
if( ! f.check( fname ) )
cerr << "could not load " << fname << endl;
else
{
if( f.objectType() == "Volume" )
{
if( f.dataType() == "S16" )
{
Reader<AimsData<short> > vr( fname );
if( vr.read( vol )
cout << "volume read\n";
else
cerr << "Error loading " << fname << endl;
}
else
{
cerr << fname << " is not a volume of short\n";
}
}
else if( f.objectType() == "Mesh" )
{
// ...
}
else
cerr << fname << " is not a volume or a mesh\n";
}
See also
Reader Process

Definition at line 117 of file finder.h.

Member Enumeration Documentation

◆ State

Enumerator
Unchecked 
Ok 
Error 

Definition at line 120 of file finder.h.

Constructor & Destructor Documentation

◆ Finder()

aims::Finder::Finder ( )

◆ ~Finder()

aims::Finder::~Finder ( )

Member Function Documentation

◆ check()

bool aims::Finder::check ( const std::string &  filename)

Determines object associated to file name and returns true if success.

If successful, appropriate infos are stored into the Finder, including the full format header

◆ dataType()

std::string aims::Finder::dataType ( ) const
inline

Definition at line 143 of file finder.h.

Referenced by aims::AimsGraphReader::read().

◆ errorMessage()

std::string aims::Finder::errorMessage ( ) const
inline

Definition at line 160 of file finder.h.

◆ extensions()

static std::set<std::string> aims::Finder::extensions ( const std::string &  format)
static

show the set of official extensions for a given format

◆ finderFormat()

static FinderFormat* aims::Finder::finderFormat ( const std::string &  format)
static

Finds the FinderFormat associated with the given string ID.

◆ format()

std::string aims::Finder::format ( ) const
inline

Definition at line 153 of file finder.h.

◆ header()

const Header* aims::Finder::header ( ) const

◆ headerObject()

carto::Object aims::Finder::headerObject ( ) const
inline

Definition at line 157 of file finder.h.

◆ launchException()

void aims::Finder::launchException ( )

creates and throws an exception corresponding to the error state

◆ objectType()

std::string aims::Finder::objectType ( ) const
inline

Definition at line 141 of file finder.h.

Referenced by aims::AimsGraphReader::read().

◆ possibleDataTypes()

std::vector<std::string> aims::Finder::possibleDataTypes ( ) const
inline

Some formats (like VIDA and ECAT) can be read as different data types for the same file (for ex. if using shorts resampled for each slice). By asking all the possible data types you can choose the one you prefer for your application. Possible types may be sorted by preference.

Definition at line 149 of file finder.h.

◆ postProcessHeader()

static void aims::Finder::postProcessHeader ( carto::Object  hdr)
static

◆ registerFormat()

static void aims::Finder::registerFormat ( const std::string &  fmtid,
FinderFormat format,
const std::vector< std::string > &  extensions,
const std::string &  before = "" 
)
static

◆ setDataType()

void aims::Finder::setDataType ( const std::string &  dat)
inline

Definition at line 144 of file finder.h.

◆ setFormat()

void aims::Finder::setFormat ( const std::string &  fmt)
inline

Definition at line 154 of file finder.h.

◆ setHeader() [1/2]

void aims::Finder::setHeader ( Header hdr)

◆ setHeader() [2/2]

void aims::Finder::setHeader ( carto::Object  hdr)

◆ setObjectType()

void aims::Finder::setObjectType ( const std::string &  obj)
inline

Definition at line 142 of file finder.h.

◆ setPossibleDataTypes()

void aims::Finder::setPossibleDataTypes ( const std::vector< std::string > &  dt)
inline

Definition at line 151 of file finder.h.

◆ state()

State aims::Finder::state ( ) const
inline

Definition at line 159 of file finder.h.

◆ unregisterFormat()

static void aims::Finder::unregisterFormat ( const std::string &  format)
static

The documentation for this class was generated from the following file: