~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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
/*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 <QGlobalStatic>

#include <fstream>
#include <iostream>
#include <sstream>

#include <QFile>
#include <QGlobalStatic>
#include <QTime>

#include "BrainVoyagerFile.h"
#include "ByteSwapping.h"
#include "DebugControl.h"
#include "FileUtilities.h"
#include "SpecFile.h"

/**
 * Constructor.
 */
BrainVoyagerFile::BrainVoyagerFile()
   : AbstractFile("Brain Voyager File", 
                  SpecFile::getBrainVoyagerFileExtension(),
                  false, 
                  AbstractFile::FILE_FORMAT_BINARY, 
                  FILE_IO_NONE, 
                  FILE_IO_READ_ONLY, 
                  FILE_IO_NONE,
                  FILE_IO_NONE)
{ 
   verticesX = NULL;
   verticesY = NULL;
   verticesZ = NULL;
   vertexRedComponent   = NULL;
   vertexGreenComponent = NULL;
   vertexBlueComponent  = NULL;
   vertexAlphaComponent = NULL;
   vertexColorTableIndices = NULL;
   triangles = NULL;
   
   clear();
}

/**
 * Destructor.
 */
BrainVoyagerFile::~BrainVoyagerFile()
{
   clear();
}

/**
 * clear the files contents.
 */
void
BrainVoyagerFile::clear()
{
   clearAbstractFile();
   version = -1.0;
   numberOfVertices  = 0;
   numberOfTriangles = 0;
   
   if (verticesX != NULL) {
      delete[] verticesX;
      verticesX = NULL;
   }
   if (verticesY != NULL) {
      delete[] verticesY;
      verticesY = NULL;
   }
   if (verticesZ != NULL) {
      delete[] verticesZ;
      verticesZ = NULL;
   }
   
   if (vertexRedComponent != NULL) {
      delete[] vertexRedComponent;
      vertexRedComponent = NULL;
   }
   if (vertexGreenComponent != NULL) {
      delete[] vertexGreenComponent;
      vertexGreenComponent = NULL;
   }
   if (vertexBlueComponent != NULL) {
      delete[] vertexBlueComponent;
      vertexBlueComponent = NULL;
   }
   if (vertexAlphaComponent != NULL) {
      delete[] vertexAlphaComponent;
      vertexAlphaComponent = NULL;
   }
   if (vertexColorTableIndices != NULL) {
      delete[] vertexColorTableIndices;
      vertexColorTableIndices = NULL;
   }
   if (triangles != NULL) {
      delete[] triangles;
      triangles = NULL;
   }
   
   colorTable.clear();
}

/**
 * get coordinates of a vertex.
 */
void 
BrainVoyagerFile::getVertexCoordinates(const int vertexNumber, float xyz[3]) const
{
   if (vertexNumber < numberOfVertices) {
      xyz[0] = verticesX[vertexNumber];
      xyz[1] = verticesY[vertexNumber];
      xyz[2] = verticesZ[vertexNumber];
   }
}
      
/**
 * get vertices of a tile.
 */
void 
BrainVoyagerFile::getTriangle(const int triangleNumber, int verts[3]) const
{
   if (triangleNumber < numberOfTriangles) {
      verts[0] = triangles[triangleNumber * 3];
      verts[1] = triangles[triangleNumber * 3 + 1];
      verts[2] = triangles[triangleNumber * 3 + 2];
   }
}      

/**
 * get the vertex color.
 */
void 
BrainVoyagerFile::getVertexColor(const int vertexNumber, unsigned char rgb[3]) const
{
   if (vertexNumber < numberOfVertices) {
      rgb[0] = static_cast<unsigned char>(vertexRedComponent[vertexNumber]);
      rgb[1] = static_cast<unsigned char>(vertexGreenComponent[vertexNumber]);
      rgb[2] = static_cast<unsigned char>(vertexBlueComponent[vertexNumber]);
   }
}

/**
 * Write the file's data (not used).
 */
void
BrainVoyagerFile::readFileData(QFile& /*file*/, QTextStream& /*stream*/, QDataStream&,
                               QDomElement& /* rootElement */) throw (FileException)
{
   throw FileException(filename, 
          "Program Error: BrainVoyagerFile::readFileData should never be called");
}

/**
 * Read the file's data (not used).
 */
void
BrainVoyagerFile::writeFileData(QTextStream& /*stream*/, QDataStream&,
                                 QDomDocument& /* xmlDoc */,
                                QDomElement& /* rootElement */) throw (FileException)
{
   throw FileException(filename, 
          "Program Error: BrainVoyagerFile::writeFileData should never be called");
}

/**
 * Read the file (overrides AbstractFile method).
 */
void
BrainVoyagerFile::readFile(const QString& filenameIn)  throw (FileException)
{
   const QString filename2(filenameIn);
   clear();
   filename = filename2;

   //
   // MSB systems will need to byte swap
   //
   //int wordSize;
   //bool bigEndian;
   //qSysInfo(&wordSize, &bigEndian);
   const bool needToByteSwap = (QSysInfo::ByteOrder == QSysInfo::BigEndian);

   QTime timer;
   timer.start();
   
   std::ifstream file(filename.toAscii().constData(), std::ios::in | std::ios::binary);
   if (file.bad() || file.fail()) {
      throw FileException(filename, "Failure trying to open: ");
   }
   else {
      try {
         
         int intDummy;
         float floatDummy;
         
         file.read((char*)&version, sizeof(version));;
         file.read((char*)&intDummy, sizeof(intDummy));
         file.read((char*)&numberOfVertices, sizeof(numberOfVertices));
         file.read((char*)&numberOfTriangles, sizeof(numberOfTriangles));
         
         if (DebugControl::getDebugOn()) {
            float fv = version;
            ByteSwapping::swapBytes(&fv, 1);
            std::cout << "version: " << version 
                      << " version byte swapped: " << fv << std::endl;
         }
         
         file.read((char*)&floatDummy, sizeof(floatDummy));   // mesh center x
         file.read((char*)&floatDummy, sizeof(floatDummy));   // mesh center y
         file.read((char*)&floatDummy, sizeof(floatDummy));   // mesh center z
         
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&version, 1);
            ByteSwapping::swapBytes(&numberOfVertices, 1);
            ByteSwapping::swapBytes(&numberOfTriangles, 1);
         }
         
         if (numberOfVertices > 0) {
            //
            // Read vertices
            //
            verticesX = new float[numberOfVertices];
            verticesY = new float[numberOfVertices];
            verticesZ = new float[numberOfVertices];
            
            file.read((char*)verticesX, (numberOfVertices * 4));
            file.read((char*)verticesY, (numberOfVertices * 4));
            file.read((char*)verticesZ, (numberOfVertices * 4));
            
            if (needToByteSwap) {
               ByteSwapping::swapBytes(verticesX, numberOfVertices);
               ByteSwapping::swapBytes(verticesY, numberOfVertices);
               ByteSwapping::swapBytes(verticesZ, numberOfVertices);
            }
            
            //
            // Skip normals
            //
            file.seekg(numberOfVertices * 4 * 3, std::ios::cur);
         }
         
         float redConvexCurvature, greenConvexCurvature, blueConvexCurvature;
         file.read((char*)&redConvexCurvature, sizeof(redConvexCurvature));
         file.read((char*)&greenConvexCurvature, sizeof(greenConvexCurvature));
         file.read((char*)&blueConvexCurvature, sizeof(blueConvexCurvature));
         file.read((char*)&floatDummy, sizeof(floatDummy));  // alpha convex curvature
         
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&redConvexCurvature, 1);
            ByteSwapping::swapBytes(&greenConvexCurvature, 1);
            ByteSwapping::swapBytes(&blueConvexCurvature, 1);
         }
         
         const unsigned char redConvex = 
            static_cast<unsigned char>(redConvexCurvature * 255.0);
         const unsigned char greenConvex = 
            static_cast<unsigned char>(greenConvexCurvature * 255.0);
         const unsigned char blueConvex = 
            static_cast<unsigned char>(blueConvexCurvature * 255.0);

         float redConcaveCurvature, greenConcaveCurvature, blueConcaveCurvature;
         file.read((char*)&redConcaveCurvature, sizeof(redConcaveCurvature));
         file.read((char*)&greenConcaveCurvature, sizeof(greenConcaveCurvature));
         file.read((char*)&blueConcaveCurvature, sizeof(blueConcaveCurvature));
         file.read((char*)&floatDummy, sizeof(floatDummy));  // alpha concave curvature
         
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&redConcaveCurvature, 1);
            ByteSwapping::swapBytes(&greenConcaveCurvature, 1);
            ByteSwapping::swapBytes(&blueConcaveCurvature, 1);
         }
         
         const unsigned char redConcave = 
            static_cast<unsigned char>(redConcaveCurvature * 255.0);
         const unsigned char greenConcave = 
            static_cast<unsigned char>(greenConcaveCurvature * 255.0);
         const unsigned char blueConcave = 
            static_cast<unsigned char>(blueConcaveCurvature * 255.0);
         
         //
         // Color indicies - Create color table
         //
         if (numberOfVertices > 0) {
            vertexColorTableIndices = new int[numberOfVertices];
            
            unsigned char dummyUnsignedChar;
            for (int i = 0; i < numberOfVertices; i++) {
               unsigned char index;
               file.read((char*)&index, sizeof(index));
               file.read((char*)&dummyUnsignedChar, sizeof(dummyUnsignedChar));
               file.read((char*)&dummyUnsignedChar, sizeof(dummyUnsignedChar));
               file.read((char*)&dummyUnsignedChar, sizeof(dummyUnsignedChar));
               
               //
               // See if color index already in color table
               //
               int colorTableIndex = -1;
               for (unsigned int j = 0; j < colorTable.size(); j++) {
                  if (colorTable[j].brainVoyagerIndex == index) {
                     colorTableIndex = static_cast<int>(j);
                  }
               }
               
               //
               // Create new color table element ?
               //
               if (colorTableIndex < 0) {
                  colorTable.push_back(BrainVoyagerColorTableElement(index));
                  colorTableIndex = static_cast<int>(colorTable.size()) - 1;
               }
               
               //
               // set vertice's color table index
               //
               vertexColorTableIndices[i] = colorTableIndex;
            }
               
            //
            // Set the convex and concave colors that are colors 0 & 1
            //
            if (colorTable.size() > 1) {
               colorTable[0].name.append("_convex");
               colorTable[0].rgb[0] = redConvex;
               colorTable[0].rgb[1] = greenConvex;
               colorTable[0].rgb[2] = blueConvex;
               colorTable[1].name.append("_concave");
               colorTable[1].rgb[0] = redConcave;
               colorTable[1].rgb[1] = greenConcave;
               colorTable[1].rgb[2] = blueConcave;
            }
         }
         
         
         
/*
         //
         // Color components
         //
         if (numberOfVertices > 0) {
            vertexRedComponent   = new unsigned char[numberOfVertices];
            vertexGreenComponent = new unsigned char[numberOfVertices];
            vertexBlueComponent  = new unsigned char[numberOfVertices];
            vertexAlphaComponent = new unsigned char[numberOfVertices];
            
            for (int i = 0; i < numberOfVertices; i++) {
               stream >> vertexRedComponent[i];
               stream >> vertexGreenComponent[i];
               stream >> vertexBlueComponent[i];
               stream >> vertexAlphaComponent[i];
               
               if (vertexRedComponent[i] == 0) {
                  vertexRedComponent[i]   = redConvex;
                  vertexGreenComponent[i] = greenConvex;
                  vertexBlueComponent[i]  = blueConvex;
               }
               else if (vertexRedComponent[i] == 1) {
                  vertexRedComponent[i]   = redConcave;
                  vertexGreenComponent[i] = greenConcave;
                  vertexBlueComponent[i]  = blueConcave;
               }
               
               //if (vertexRedComponent[i] != 0) {
                  std::cout << "node " << i 
                            << " (" << static_cast<int>(vertexRedComponent[i])
                            << " ," << static_cast<int>(vertexGreenComponent[i])
                            << " ," << static_cast<int>(vertexBlueComponent[i])
                            << " ," << static_cast<int>(vertexAlphaComponent[i])
                            << ")" << std::endl;
               //}
            }
         }
*/
         
         //
         // Vertex Neighbors
         //
         for (int i = 0; i < numberOfVertices; i++) {
            int numNeighbors;
            file.read((char*)&numNeighbors, sizeof(numNeighbors));
            if (needToByteSwap) {
               ByteSwapping::swapBytes(&numNeighbors, 1);
            }
            if (i == 147644) {
               std::cout << "Node " << i << " has "
                         << numNeighbors << " neighbors." << std::endl;
            }
            for (int j = 0; j < numNeighbors; j++) {
               file.read((char*)&intDummy, sizeof(intDummy));
            }
         }
         
         //
         // Triangles
         //
         triangles = new int[numberOfTriangles * 3];
         file.read((char*)triangles, numberOfTriangles * 3 * 4);
         if (needToByteSwap) {
            ByteSwapping::swapBytes(triangles, numberOfTriangles * 3);
         }
         
         //
         // Number of string elements
         //
         int numberOfStripElements;
         file.read((char*)&numberOfStripElements, sizeof(numberOfStripElements));
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&numberOfStripElements, 1);
         }

         //if (DebugControl::getDebugOn()) {
            std::cout << "Version: " << version << std::endl;
            std::cout << "Number of vertices: " << numberOfVertices << std::endl;
            std::cout << "Number of triangles: " << numberOfTriangles << std::endl;
            std::cout << "Number of strip elements: " << numberOfStripElements
                      << std::endl;
            std::cout << "Color table size: " << colorTable.size() << std::endl;
         //}
         
         clearModified();
      }
      catch (FileException& e) {
         file.close();
         clearModified();
         throw e;
      }
   
      file.close();
   }
   
   if (DebugControl::getDebugOn()) {
      std::cout << "Time to read " << FileUtilities::basename(filename).toAscii().constData() 
                << " was "
                << (static_cast<float>(timer.elapsed()) / 1000.0)
                << " seconds." << std::endl;
   }
}

/**
 * Read the file.
 */
/*
void
BrainVoyagerFile::readFile(const QString& filenameIn)  throw (FileException)
{
   const QString filename2(filenameIn);
   clear();
   filename = filename2);

   //
   // We always need to byte swap on both MSB & LSB systems.  It is
   // something to do with the way QDataStream works.
   //
   const bool needToByteSwap = true;
   
   QTime timer;
   timer.start();
   
   QFile file(filename);
   if (file.open(IO_ReadOnly)) {

      try {
         QDataStream stream(&file);
         
         if (DebugControl::getDebugOn()) {
            switch(stream.byteOrder()) {
               case QDataStream::BigEndian:
                  std::cout << "Brain Voyager File stream is big endian" << std::endl;
                  break;
               case QDataStream::LittleEndian:
                  std::cout << "Brain Voyager File stream is little endian" << std::endl;
                  break;
            }
         }
         
         int intDummy;
         float floatDummy;
         
         stream >> version;
         stream >> intDummy;
         stream >> numberOfVertices;
         stream >> numberOfTriangles;
         
         if (DebugControl::getDebugOn()) {
            float fv = version;
            ByteSwapping::swapBytes(&fv, 1);
            std::cout << "version: " << version 
                      << " version byte swapped: " << fv << std::endl;
         }
         
         stream >> floatDummy;   // mesh center x
         stream >> floatDummy;   // mesh center y
         stream >> floatDummy;   // mesh center z
         
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&version, 1);
            ByteSwapping::swapBytes(&numberOfVertices, 1);
            ByteSwapping::swapBytes(&numberOfTriangles, 1);
         }
         
         if (numberOfVertices > 0) {
            //
            // Read vertices
            //
            verticesX = new float[numberOfVertices];
            verticesY = new float[numberOfVertices];
            verticesZ = new float[numberOfVertices];
            
            stream.readRawBytes((char*)verticesX, (numberOfVertices * 4));
            stream.readRawBytes((char*)verticesY, (numberOfVertices * 4));
            stream.readRawBytes((char*)verticesZ, (numberOfVertices * 4));
            
            if (needToByteSwap) {
               ByteSwapping::swapBytes(verticesX, numberOfVertices);
               ByteSwapping::swapBytes(verticesY, numberOfVertices);
               ByteSwapping::swapBytes(verticesZ, numberOfVertices);
            }
            
            //
            // Skip normals
            //
            QIODevice::Offset pos = file.at();
            pos += numberOfVertices * 4 * 3;
            file.at(pos);
         }
         
         float redConvexCurvature, greenConvexCurvature, blueConvexCurvature;
         stream >> redConvexCurvature;
         stream >> greenConvexCurvature;
         stream >> blueConvexCurvature;
         stream >> floatDummy;  // alpha convex curvature
         
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&redConvexCurvature, 1);
            ByteSwapping::swapBytes(&greenConvexCurvature, 1);
            ByteSwapping::swapBytes(&blueConvexCurvature, 1);
         }
         
         const unsigned char redConvex = 
            static_cast<unsigned char>(redConvexCurvature * 255.0);
         const unsigned char greenConvex = 
            static_cast<unsigned char>(greenConvexCurvature * 255.0);
         const unsigned char blueConvex = 
            static_cast<unsigned char>(blueConvexCurvature * 255.0);

         float redConcaveCurvature, greenConcaveCurvature, blueConcaveCurvature;
         stream >> redConcaveCurvature;
         stream >> greenConcaveCurvature;
         stream >> blueConcaveCurvature;
         stream >> floatDummy;  // alpha concave curvature
         
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&redConcaveCurvature, 1);
            ByteSwapping::swapBytes(&greenConcaveCurvature, 1);
            ByteSwapping::swapBytes(&blueConcaveCurvature, 1);
         }
         
         const unsigned char redConcave = 
            static_cast<unsigned char>(redConcaveCurvature * 255.0);
         const unsigned char greenConcave = 
            static_cast<unsigned char>(greenConcaveCurvature * 255.0);
         const unsigned char blueConcave = 
            static_cast<unsigned char>(blueConcaveCurvature * 255.0);
         
         //
         // Color indicies - Create color table
         //
         if (numberOfVertices > 0) {
            vertexColorTableIndices = new int[numberOfVertices];
            
            unsigned char dummyUnsignedChar;
            for (int i = 0; i < numberOfVertices; i++) {
               unsigned char index;
               stream >> index;
               stream >> dummyUnsignedChar;
               stream >> dummyUnsignedChar;
               stream >> dummyUnsignedChar;
               
               //
               // See if color index already in color table
               //
               int colorTableIndex = -1;
               for (unsigned int j = 0; j < colorTable.size(); j++) {
                  if (colorTable[j].brainVoyagerIndex == index) {
                     colorTableIndex = static_cast<int>(j);
                  }
               }
               
               //
               // Create new color table element ?
               //
               if (colorTableIndex < 0) {
                  colorTable.push_back(BrainVoyagerColorTableElement(index));
                  colorTableIndex = static_cast<int>(colorTable.size());
               }
               
               //
               // set vertice's color table index
               //
               vertexColorTableIndices[i] = colorTableIndex;
            }
               
            //
            // Set the convex and concave colors that are colors 0 & 1
            //
            if (colorTable.size() > 1) {
               colorTable[0].name.append("_convex");
               colorTable[0].rgb[0] = redConvex;
               colorTable[0].rgb[1] = greenConvex;
               colorTable[0].rgb[2] = blueConvex;
               colorTable[1].name.append("_concave");
               colorTable[1].rgb[0] = redConcave;
               colorTable[1].rgb[1] = greenConcave;
               colorTable[1].rgb[2] = blueConcave;
            }
         }
         
         //
         // Vertex Neighbors
         //
         for (int i = 0; i < numberOfVertices; i++) {
            int numNeighbors;
            stream >> numNeighbors;
            if (needToByteSwap) {
               ByteSwapping::swapBytes(&numNeighbors, 1);
            }
            if (i == 147644) {
               std::cout << "Node " << i << " has "
                         << numNeighbors << " neighbors." << std::endl;
            }
            for (int j = 0; j < numNeighbors; j++) {
               stream >> intDummy;
            }
         }
         
         //
         // Triangles
         //
         triangles = new int[numberOfTriangles * 3];
         stream.readRawBytes((char*)triangles, numberOfTriangles * 3 * 4);
         if (needToByteSwap) {
            ByteSwapping::swapBytes(triangles, numberOfTriangles * 3);
         }
         
         //
         // Number of string elements
         //
         int numberOfStripElements;
         stream >> numberOfStripElements;
         if (needToByteSwap) {
            ByteSwapping::swapBytes(&numberOfStripElements, 1);
         }

         //if (DebugControl::getDebugOn()) {
            std::cout << "Version: " << version << std::endl;
            std::cout << "Number of vertices: " << numberOfVertices << std::endl;
            std::cout << "Number of triangles: " << numberOfTriangles << std::endl;
            std::cout << "Number of strip elements: " << numberOfStripElements
                      << std::endl;
         //}
         
         clearModified();
      }
      catch (FileException& e) {
         file.close();
         clearModified();
         throw e;
      }
   
      file.close();
   }
   else {
      throw FileException(filename, "Failure trying to open: ");
   }
   
   if (DebugControl::getDebugOn()) {
      std::cout << "Time to read " << FileUtilities::basename(filename) 
                << " was "
                << (static_cast<float>(timer.elapsed()) / 1000.0)
                << " seconds." << std::endl;
   }
}
*/

/**
 * Write the file.
 */
void
BrainVoyagerFile::writeFile(const QString& filenameIn)  throw (FileException)
{
   throw FileException(filenameIn, "Writing brain voyager file not supported.");
}

//---------------------------------------------------------------------------------

/**
 * Constructor.
 */
BrainVoyagerColorTableElement::BrainVoyagerColorTableElement(const int brainVoyagerIndexIn)
{
   initialize();
   brainVoyagerIndex = brainVoyagerIndexIn;
   
   std::ostringstream str;
   str << "Color_"
       << brainVoyagerIndex;
   name = str.str().c_str();
   
   switch(brainVoyagerIndex) {
      case 24:
         name.append("_white_med_wall_and_cuts");
         rgb[0] = 255;
         rgb[1] = 255;
         rgb[2] = 255;
         break;
      case 32:
         name.append("_bright_blue");
         rgb[0] = 24;
         rgb[1] = 93;
         rgb[2] = 255;
         break;
      case 33:
         name.append("_dark_blue");
         rgb[0] = 16;
         rgb[1] = 80;
         rgb[2] = 222;
         break;
      case 34:
         name.append("_bright_green");
         rgb[0] = 16;
         rgb[1] = 255;
         rgb[2] = 98;
         break;
      case 35:
         name.append("_dark_green");
         rgb[0] = 24;
         rgb[1] = 218;
         rgb[2] = 82;
         break;
      case 240:
         name.append("_light_gray_cuts");
         rgb[0] = 200;
         rgb[1] = 200;
         rgb[2] = 200;
         break;
   }
   
}

/**
 * Constructor.
 */
BrainVoyagerColorTableElement::BrainVoyagerColorTableElement()
{
   initialize();
}

/**
 * Destructor.
 */
BrainVoyagerColorTableElement::~BrainVoyagerColorTableElement()
{
}

/**
 *
 */
void
BrainVoyagerColorTableElement::getRgb(unsigned char rgbOut[3]) const
{
   rgbOut[0] = rgb[0];
   rgbOut[1] = rgb[1];
   rgbOut[2] = rgb[2];
}

/**
 * Initialize the elements.
 */ 
void
BrainVoyagerColorTableElement::initialize()
{
   brainVoyagerIndex = -1;
   rgb[0] = 255;
   rgb[1] = 0;
   rgb[2] = 0;
}