aimsdata 6.0.0
Neuroimaging data handling
aimsGraphR_d.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34/*
35 * Region Of Interest
36 */
37#ifndef AIMS_IO_AIMSGRAPHR_D_H
38#define AIMS_IO_AIMSGRAPHR_D_H
39
40#include <aims/io/aimsGraphR.h>
41#include <aims/io/reader.h>
43#include <aims/io/finder.h>
45#include <cartobase/smart/rcptr.h>
46
47namespace aims
48{
49
50 namespace internal
51 {
52
54 {
56
57 private:
58 static void
59 loadGlobalObjects( std::map<std::string, aims::AimsGraphReader::Wrapper*>
60 & objects,
61 const std::map<std::string,
62 std::map<std::string, std::string> > & globals,
63 const std::string & basepath,
64 std::map<std::string,
65 std::map<std::string, GraphElementCode> > & objmap,
66 AimsGraphReader & agr );
67
68 std::string filename;
69 std::set<std::string> readfilter;
70 std::set<std::string> excludefilter;
72 };
73
74 }
75
76 // Implementation
77
78 template<typename T> AimsGraphReader::Wrapper *
79 AimsGraphReader::ObjectWrapper<T>::extract( int index )
80 {
81 typename T::const_iterator io;
82 io = data->find( index );
83 T *obj = new T;
84 if( io != data->end() )
85 (*obj)[0] = io->second;
86 DataManip::adjustVoxelSize( *obj, *data );
87 return( new ObjectWrapper<T>( obj ) );
88 }
89
90
91 template<typename T> std::string
96
97
98 template<typename T> std::string
103
104
105 template<class T> bool
106 AimsGraphReader::read( Process & p, const std::string & fname, Finder & f )
107 {
108 T *obj = new T;
109 Reader<T> r( fname );
110 try
111 {
112 r.read( *obj );
113 }
114 catch( std::exception & e )
115 {
116 std::cerr << e.what() << std::endl;
117 delete obj;
118 return false;
119 }
120
121 AimsGraphReader & ap = (AimsGraphReader &) p;
122 internal::AimsGraphReader_Private & ps = *ap._priv;
123 ElementInfo & info = ps.postproc.info;
124
125 // ensure postprocessor has this type registered
126 const std::map<std::string, std::map<std::string, ProcFunc> > & pcs
127 = ps.postproc.processTypes();
128 std::map<std::string, std::map<std::string, ProcFunc> >::const_iterator
129 ipcs = pcs.find( f.objectType() );
130 if( ipcs == pcs.end()
131 || ipcs->second.find( f.dataType() ) == ipcs->second.end() )
132 ps.postproc.registerProcessType
133 ( f.objectType(), f.dataType(),
134 &AimsGraphReader::defaultInsertFunction<T> );
135
136 // also register my own type because Volume/CartoVolume may be mixed
139 {
140 ipcs = pcs.find( carto::DataTypeCode<T>::objectType() );
141 if( ipcs == pcs.end()
142 || ipcs->second.find( carto::DataTypeCode<T>::dataType() )
143 == ipcs->second.end() )
144 ps.postproc.registerProcessType(
147 &AimsGraphReader::defaultInsertFunction<T> );
148 }
149
151 return( true );
152 }
153
154
155 template<class T> bool
156 AimsGraphReader::defaultInsertFunction( Process & p, const std::string &,
157 Finder & )
158 {
159 PostProcessor & pp = (PostProcessor &) p;
160 const ElementInfo & info = pp.elementInfo();
161 T * obj = ((const ObjectWrapper<T> *) info.object)->data;
162 if( obj )
163 info.element->setProperty( info.attribute, carto::rc_ptr<T>( obj ) );
164 return( true );
165 }
166
167
168}
169
170
171#endif
Reader / postprocessor for graph reading.
Definition aimsGraphR.h:59
static bool read(Process &, const std::string &, Finder &)
Aims object reading function - called by the Process mechanism.
AimsGraphReader(const std::string &filename)
Generic finder / checker for all data objects and file formats This will replace the old AimsFinder.
Definition finder.h:118
std::string dataType() const
Definition finder.h:143
std::string objectType() const
Definition finder.h:141
Link mechanism between the Finder and a process operating on arbitrary data types.
Definition process.h:200
const std::map< std::string, std::map< std::string, ProcFunc > > & processTypes() const
Query registered process types.
Definition process.h:235
void registerProcessType(const std::string &objType, const std::string &dataType, ProcFunc procFunc)
Registers the process to call on a given (object type, data type) couple (just fills the map)
Process()
Attempts to read the header of filename and, if successful, calls the operator() of the process \proc...
Generic reader for every format of Aims object.
Definition reader.h:70
virtual bool read(T &obj, int border=0, const std::string *format=0, int frame=-1)
Finds the correct format and reads the object. if format is specified, this format is tried first,...
Definition reader_d.h:142
std::string objectType()
std::string dataType()
void adjustVoxelSize(T &, const T &)
utility function to copy voxel sizes from an object to another (if applicable)
The class for EcatSino data write operation.
virtual std::string objectType() const
virtual std::string dataType() const