~ubuntu-branches/ubuntu/saucy/caret/saucy-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#ifndef __GIFTI_DATA_ARRAY_FILE_H__
#define __GIFTI_DATA_ARRAY_FILE_H__

/*LICENSE_START*/
/*
 *  Copyright 1995-2002 Washington University School of Medicine
 *
 *  http://brainmap.wustl.edu
 *
 *  This file is part of CARET.
 *
 *  CARET is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  CARET is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CARET; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
/*LICENSE_END*/

#include "AbstractFile.h"
#include "FileException.h"
#include "GiftiDataArray.h"
#include "GiftiLabelTable.h"

class DeformationMapFile;
class QDataStream;
class QDomDocument;
class QDomElement;
class QFile;
class QTextStream;

/// This abstract class defines some variables and methods used for gifti data array files.
/// While this class may be instantiated, it is best subclassed.
class GiftiDataArrayFile : public AbstractFile {
   public:
      /// append array index values
      enum APPEND_ARRAY_INDEX {
         APPEND_ARRAY_NEW = -1,
         APPEND_ARRAY_DO_NOT_LOAD = -2
      };
      
      /// constructor
      GiftiDataArrayFile(const QString& descriptiveName,
                   const QString& defaultDataArrayIntentIn,
                   const GiftiDataArray::DATA_TYPE defaultDataTypeIn,
                   const QString& defaultExt,
                   const FILE_FORMAT defaultWriteTypeIn,
                   const FILE_IO supportsAsciiFormat,
                   const FILE_IO supportsBinaryFormat,
                   const FILE_IO supportsOtherFormat,
                   const FILE_IO supportsCSVfFormat,
                   const bool dataAreIndicesIntoLabelTableIn);
      
      /// constructor for generic gifti data array file
      GiftiDataArrayFile();
      
      // copy constructor
      GiftiDataArrayFile(const GiftiDataArrayFile& nndf);
      
      // destructor
      virtual ~GiftiDataArrayFile();

      // assignment operator
      GiftiDataArrayFile& operator=(const GiftiDataArrayFile& nndf);
      
      // add a data array
      virtual void addDataArray(GiftiDataArray* nda);
            
      // add rows to this file.
      void addRows(const int numberOfRowsToAdd);

      // append a data array file to this one
      virtual void append(const GiftiDataArrayFile& naf) throw (FileException);

      // append a data array file to this one but selectively load/overwrite arraysumns
      // arrayDestination is where naf's arrays should be (-1=new, -2=do not load)
      virtual void append(const GiftiDataArrayFile& naf, 
                          std::vector<int>& indexDestination,
                          const FILE_COMMENT_MODE fcm) throw (FileException);

      /// compare a file for unit testing (returns true if "within tolerance")
      virtual bool compareFileForUnitTesting(const AbstractFile* af,
                                             const float tolerance,
                                             QString& messageOut) const;
                                     
      // Clear the gifti array data file.
      virtual void clear();
      
      // returns true if the file is isEmpty (contains no data)
      virtual bool empty() const;
      
      /// get the number of data arrays
      int getNumberOfDataArrays() const { return dataArrays.size() ; }
      
      /// get a data array
      GiftiDataArray* getDataArray(const int arrayNumber) { return dataArrays[arrayNumber]; }
      
      /// get a data array (const method)
      const GiftiDataArray* getDataArray(const int arrayNumber) const { return dataArrays[arrayNumber]; }
      
      /// reset a data array
      virtual void resetDataArray(const int arrayIndex);
      
      /// remove a data array
      virtual void removeDataArray(const GiftiDataArray* arrayPointer);
      
      /// remove a data array
      virtual void removeDataArray(const int arrayIndex);
      
      // get all of the data array names
      void getAllArrayNames(std::vector<QString>& names) const;
      
      // get the specified data array's name
      QString getDataArrayName(const int arrayIndex) const;

      // get the index of the data array with the specified name 
      int getDataArrayWithNameIndex(const QString& n) const;
 
      // get the data array with the specified name 
      GiftiDataArray* getDataArrayWithName(const QString& n);
 
      // get the data array with the specified name 
      const GiftiDataArray* getDataArrayWithName(const QString& n) const;
 
      // get the index of the data array of the specified intent
      int getDataArrayWithIntentIndex(const QString& catName) const;
      
      // get the data array of the specified intent
      GiftiDataArray* getDataArrayWithIntent(const QString& catName);
      
      // get the data array of the specified intent (const method)
      const GiftiDataArray* getDataArrayWithIntent(const QString& catName) const;
      
      // get the comment for a data array
      QString getDataArrayComment(const int arrayIndex) const;
      
      // set the name of a data array
      void setDataArrayName(const int arrayIndex, const QString& name);
      
      // set the comment for a data array
      void setDataArrayComment(const int arrayIndex, const QString& comm);
      
      // append to the comment for a data array
      void appendToDataArrayComment(const int arrayIndex, const QString& comm);
      
      // prepend to the comment for a data array
      void prependToDataArrayComment(const int arrayIndex, const QString& comm);
      
      // check for data arrays with the same name (returns true if there are any)
      bool checkForDataArraysWithSameName(std::vector<QString>& multipleDataArrayNames) const;
      
      // get the metadata
      GiftiMetaData* getMetaData() { return &metaData; }
      
      // get the metadata (const method)
      const GiftiMetaData* getMetaData() const { return &metaData; }
      
      /// get the label table 
      GiftiLabelTable* getLabelTable() { return &labelTable; }
      
      /// get the label table 
      const GiftiLabelTable* getLabelTable() const { return &labelTable; }
            
      /// see if gifti data array data files are enabled
      static bool getGiftiXMLEnabled() { return giftiXMLFilesEnabled; }
      
      /// set gifti data array files enabled
      static void setGiftiXMLEnabled(const bool b) { giftiXMLFilesEnabled = b; }
      
      /// get the current version for GiftiDataArrayFiles
      static float getCurrentFileVersion() { return 1.0; }
      
      /// get the default data array intent
      QString getDefaultDataArrayIntent() const { return defaultDataArrayIntent; }
      
      /// get the default data array intent
      void setDefaultDataArrayIntent(const QString& newIntentName);
      
      /// set the number of nodes for sparse node index files (NIFTI_INTENT_NODE_INDEX)
      void setNumberOfNodesForSparseNodeIndexFiles(const int numNodes);
      
   protected:
      // append helper for files where data are label indices
      void appendLabelDataHelper(const GiftiDataArrayFile& naf,
                                 const std::vector<bool>& arrayWillBeAppended,
                                 std::vector<int>& oldIndicesToNewIndicesTable);
                                 
      // copy helper
      void copyHelperGiftiDataArrayFile(const GiftiDataArrayFile& nndf);
      
      /// read legacy file format data
      virtual void readLegacyFileData(QFile& file, 
                                      QTextStream& stream, 
                                      QDataStream& binStream) throw (FileException);

      /// write legacy file format data
      virtual void writeLegacyFileData(QTextStream& stream, 
                                       QDataStream& binStream) throw (FileException);
      
      // read the XML file 
      virtual void readFileDataXML(QFile& file) throw (FileException);
      
      // write the XML file
      virtual void writeFileDataXML(QTextStream& stream) throw (FileException);
      
      /// Read the contents of the file (header has already been read)
      virtual void readFileData(QFile& file,
                                QTextStream& stream,
                                QDataStream& binStream,
                                QDomElement& rootElement) throw (FileException);

      /// Write the file's data (header has already been written)
      virtual void writeFileData(QTextStream& stream,
                                 QDataStream& binStream,
                                 QDomDocument& xmlDoc,
                                 QDomElement& rootElement) throw (FileException);
      
      // process NIFTI_INTENT_NODE_INDEX arrays
      void procesNiftiIntentNodeIndexArrays() throw (FileException);

      // validate the data arrays (optional for subclasses)
      virtual void validateDataArrays() throw (FileException);

      /// the data arrays
      std::vector<GiftiDataArray*> dataArrays;
      
      /// the label table
      GiftiLabelTable labelTable;
      
      /// the file's metadata
      GiftiMetaData metaData;
      
      /// the default data type
      GiftiDataArray::DATA_TYPE defaultDataType;
      
      /// default data array intent for this file
      QString defaultDataArrayIntent;
      
      /// data arrays contain indices into label table
      bool dataAreIndicesIntoLabelTable;
      
      /// gifti XML files enabled
      static bool giftiXMLFilesEnabled;
      
      /// number of nodes in sparse node index files (NIFTI_INTENT_NODE_INDEX array)
      int numberOfNodesForSparseNodeIndexFile;
      
      /*!!!! be sure to update copyHelperGiftiDataArrayFile if new member added !!!!*/
   
   // 
   // friends
   //
};

#endif // __GIFTI_DATA_ARRAY_FILE_H__

#ifdef __GIFTI_DATA_ARRAY_FILE_MAIN__
   bool GiftiDataArrayFile::giftiXMLFilesEnabled = true;
#endif // __GIFTI_DATA_ARRAY_FILE_MAIN__