aimsdata 6.0.0
Neuroimaging data handling
fscurvformatreader_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_SOMA_FSCURVFORMATREADER_D_H
35#define AIMS_IO_SOMA_FSCURVFORMATREADER_D_H
36
37//-------------------------------------------------------------------
39#include <aims/mesh/texture.h>
41#include <soma-io/datasourceinfo/datasourceinfoloader.h>
43//--- debug ------------------------------------------------------------------
44#include <cartobase/config/verbose.h>
45#define localMsg( message ) cartoCondMsg( 4, message, "FSCURVFORMATREADER" )
46// localMsg must be undef at end of file
47//----------------------------------------------------------------------------
48
49
50// from http://www.grahamwideman.com/gw/brain/fs/surfacefileformats.htm
51
52namespace soma
53{
54
55 template <typename T>
57 FsCurvFormatReader<T>::createAndRead( rc_ptr<DataSourceInfo> dsi,
58 const AllocatorContext & context,
59 Object options )
60 {
61 carto::rc_ptr<soma::DataSource> ds = dsi->list().dataSource();
62 localMsg( "createAndRead " + ds->url() );
64 try
65 {
66 read( *mesh, dsi, context, options );
67 }
68 catch( ... )
69 {
70 delete mesh;
71 throw;
72 }
73 mesh->header().copyProperties( dsi->header() );
74 return mesh;
75 }
76
77
78 template <typename T>
80 rc_ptr<DataSourceInfo> dsi,
81 const AllocatorContext & /* context */,
82 Object options )
83 {
84 // std::cout << "FsCurvFormatReader::read " << dsi->list().dataSource()->url() << std::endl;
85 carto::rc_ptr<DataSource> ds = dsi->list().dataSource();
86
87 if( !ds->isOpen() )
88 {
89 std::cout << "WARNING: reopening freesurfer curv file at beginning\n";
90 ds->open( DataSource::Read ); // FIXME recover offset
91 }
92 if( !ds->isOpen() )
93 throw file_not_found_error( ds->url() );
94
95 carto::Object hdr = dsi->header();
96
97 int asciii = 0;
98 int bswapi = 0;
99 hdr->getProperty( "ascii", asciii );
100 bool ascii = bool( asciii );
101 hdr->getProperty( "byte_swapping", bswapi );
102 bool bswap = bool( bswapi );
103 int nv = 0, np = 0, ps;
104 hdr->getProperty( "vertex_number", nv );
105
106 if( !readTexture( ds, obj, nv, ascii, bswap ) )
107 throw carto::invalid_format_error( ds->url() );
108
109
111 rc_ptr<DataSource> mds( 0 );
112 try
113 {
114 mds = dsi->list().dataSource( "minf" );
115 if( mds.get() )
116 DataSourceInfoLoader::readMinf( *mds, hdr, options );
117 }
118 catch( ... )
119 {
120 }
121
122 obj.header().copyProperties( hdr );
123 if( dsi->header().get() )
124 obj.header().copyProperties( dsi->header() );
125
126 // std::cout << "read FSCURV OK\n";
127 }
128
129
130 template <typename T>
133 {
134 return new FsCurvFormatReader;
135 }
136
137
138 template <typename T>
140 TimeTexture<T> & obj,
141 int nv, bool ascii,
142 bool bswap ) const
143 {
144 // std::cout << "readVTexture: " << nv << ", " << ascii << ", " << bswap << std::endl;
145
147 std::unique_ptr<ItemReader<T> > itemr;
148 itemr.reset( dir.reader( !ascii, bswap ) );
149
150 std::vector<T> & tex = obj[0].data();
151 tex.resize( nv );
152
153 long n = itemr->read( *ds, &tex[0], nv );
154 if( n != nv )
155 return false;
156
157 return true;
158 }
159
160
161}
162
163#undef localMsg
164
165#endif
const aims::PythonHeader & header() const
Get the header.
Definition texture.h:143
virtual void copyProperties(Object source)
static Object value()
static carto::Object readMinf(DataSource &ds, carto::Object base=carto::none(), carto::Object options=carto::none())
virtual ItemReader< T > * reader(bool binary=true, bool bswap=false) const
Freesurfer texture (curvature) format.
virtual void read(TimeTexture< T > &obj, carto::rc_ptr< DataSourceInfo > dsi, const AllocatorContext &context, carto::Object options)
virtual TimeTexture< T > * createAndRead(carto::rc_ptr< DataSourceInfo > dsi, const AllocatorContext &context, carto::Object options)
bool readTexture(carto::rc_ptr< DataSource > ds, TimeTexture< T > &obj, int nv, bool ascii, bool bswap) const
virtual FormatReader< TimeTexture< T > > * clone() const
#define localMsg(message)
Definition reader_d.h:48