aimsdata 6.0.0
Neuroimaging data handling
aimsGraphW_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#ifndef AIMS_IO_AIMSGRAPHW_D_H
35#define AIMS_IO_AIMSGRAPHW_D_H
36
37#include <aims/io/aimsGraphW.h>
39#include <aims/io/writer.h>
41#include <aims/io/finder.h>
42#include <graph/graph/graph.h>
43#include <cartobase/smart/rcptr.h>
44#include <cartobase/stream/fileutil.h>
46#include <list>
47#include <vector>
48
49namespace aims
50{
51
73
74
76 : colors( new std::map<std::string,std::vector<int> > )
77 {
78 }
79
80
82 {
83 std::map<std::string,AimsGraphWriter::Wrapper *>::iterator i, e
84 = globalobjects.end();
85 for ( i=globalobjects.begin(); i!=e; ++i )
86 {
87 // i->second->destroy(); ? no, object can be kept in graph
88 delete i->second;
89 }
90 }
91
92
93 template<typename T> bool
94 AimsGraphWriter::ObjectWrapper<T>::write( const AimsGraphWriter & wp ) const
95 {
96 return wp.write( *data );
97 }
98
99
100 template<typename T> int
101 AimsGraphWriter::ObjectWrapper<T>::freeindex() const
102 {
103 typename T::const_iterator i = data->begin(), e = data->end();
104 int n = 1;
105 if( i != e && i->first == 0 )
106 n = 0;
107 for ( ; i!=e && i->first==n; ++i, ++n ) {}
108 return n;
109 }
110
111
112 template<typename T> std::string
114 {
115 return ::carto::DataTypeCode<T>().objectType();
116 }
117
118
119 template<typename T> std::string
124
125
126 template <typename T>
127 bool AimsGraphWriter::isEmpty( const T & obj )
128 {
129 return obj.empty();
130 }
131
132
133 template <>
135 {
136 return !obj.any();
137 }
138
139
140 template <>
142 {
143 return !obj.any();
144 }
145
146
147 template<class T>
148 bool AimsGraphWriter::write( const T & obj ) const
149 {
150 // write in file or in global object
151 if ( d->mode == Local )
152 {
153 if ( d->saveall || ( d->modified && !isEmpty( obj ) ) )
154 {
155 std::string dir = carto::FileUtil::dirname( d->elemfname );
156 if( carto::FileUtil::fileStat( dir ).find( '+' )
157 == std::string::npos )
158 {
159 carto::Directory cd( dir );
160 cd.makedirs();
161 }
162 Writer<T> w( d->elemfname );
163 return w.write( obj );
164 }
165 return true;
166 }
167 else
168 {
169 Wrapper *& glob = d->globalobjects[ d->elemcode.global_filename ];
170 if ( !glob )
171 {
172 //cout << "create " << d->elemcode.global_filename << endl;
173 carto::rc_ptr<T> gobject;
174 if ( !d->elemcode.global_attribute.empty()
175 && info.graph->getProperty( d->elemcode.global_attribute,
176 gobject ) )
177 glob = new ObjectWrapper<T>( gobject.get() );
178 else
179 {
180 glob = new ObjectWrapper<T>( new T );
181 T* data = ((ObjectWrapper<T> *) glob)->data;
182 DataManip::adjustVoxelSize( *data, obj );
183 DataManip::setHeaderInfo( *data, *info.graph );
184 }
185 }
186 if( !d->delayindex && d->mode == Global )
187 {
188 /*cout << "insert index " << d->elemindex << " in "
189 << d->elemcode.global_filename << endl;*/
190 DataManip::insertElement( *((ObjectWrapper<T> *) glob)->data,
191 d->elemindex, obj );
192 }
193 }
194
195 return true;
196 }
197
198
199 template<class T>
200 bool AimsGraphWriter::defaultTakeObject( Process & p, const std::string &,
201 Finder & f )
202 {
203 AimsGraphWriter & wp = (AimsGraphWriter &) p;
204 ElementInfo & info = wp.info;
206
207 try
208 {
209 if ( !info.element->getProperty( info.attribute, obj ) )
210 {
211 carto::Object o = info.element->getProperty( info.attribute );
212 return false;
213 }
214 info.object = new ObjectWrapper<T>( obj.get() );
215 return true;
216 }
217 catch( std::exception & e )
218 {
219 std::cerr << e.what() << std::endl;
220 return false;
221 }
222 }
223
224}
225
226#endif
static bool defaultTakeObject(Process &, const std::string &, Finder &)
static bool isEmpty(const T &obj)
friend struct ObjectWrapper
Definition aimsGraphW.h:106
AimsGraphWriter(const std::string &filename)
Generic finder / checker for all data objects and file formats This will replace the old AimsFinder.
Definition finder.h:118
Process()
Attempts to read the header of filename and, if successful, calls the operator() of the process \proc...
std::string dataType()
static std::string dirname(const std::string &)
static std::string fileStat(const std::string &)
bool any() const
T * get() const
void insertElement(T &dest, int index, const T &src)
insert a sub-element in a container data (time bucket/mesh/texture, or volume of labels....
void adjustVoxelSize(T &, const T &)
utility function to copy voxel sizes from an object to another (if applicable)
void setHeaderInfo(T &obj, const carto::GenericObject &srcheader)
The class for EcatSino data write operation.
STL namespace.
virtual std::string objectType() const
virtual std::string dataType() const
AimsGraphWriter::SavingMode mode
AimsGraphWriter::SavingMode newmode
std::map< std::string, AimsGraphWriter::Wrapper * > globalobjects
AimsGraphWriter::SavingMode oldmode
std::map< std::string, bool > globalmodified
carto::rc_ptr< std::map< std::string, std::vector< int > > > colors
AimsGraphWriter::SavingMode prevmode
Describe how Aims objects are stored in graph objects.
Definition graphmanip.h:67