]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/marDicomBase.cpp
6d0bb372da6c95acabef4af8243043f7677457c5
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / marDicomBase.cpp
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 #include "marDicomBase.h"
28
29 #include <vtkVolume16Reader.h> 
30 #include <vtkExtractVOI.h>
31 #include <vtkImageChangeInformation.h>
32 #include "vtkMetaImageWriter.h"
33
34
35
36 marFilesBase::marFilesBase( marParameters* p  ) :  marObject( p ) {
37         _volume=NULL;
38 }
39 // -------------------------------------------------------------------------
40 marFilesBase::~marFilesBase(){
41         freeVolume( );
42 }
43 // -------------------------------------------------------------------------
44 kVolume* marFilesBase::getVolume( ){
45         return( _volume );
46 }
47 // -------------------------------------------------------------------------
48 void marFilesBase::SetVolume( kVolume* volume  ){
49         _volume=volume;
50 }
51 // -------------------------------------------------------------------------
52 bool marFilesBase::volumeLoaded( ){
53         return( _volume != NULL );
54 }
55 // -------------------------------------------------------------------------
56 void marFilesBase::freeVolume( ){
57         if( _volume ) delete _volume;
58         _volume = NULL;
59 }
60
61
62 // -------------------------------------------------------------------------
63
64 std::vector < std::string*>  *marFilesBase::GetListImages()
65 {
66         return &_lstString;
67 }
68
69 // -------------------------------------------------------------------------
70 void marFilesBase::CleanListImages()
71 {
72         int i,size;
73         size=this->_lstString.size();
74         for(i=0;i<size;i++)
75         {
76                 delete _lstString[i];
77         }
78         _lstString.clear();
79 }
80
81
82 // -------------------------------------------------------------------------
83 void marFilesBase::ResetLstFileNotReaded()
84 {
85         _lstFileNotReaded.clear();
86 }
87
88
89 // -------------------------------------------------------------------------
90 std::string marFilesBase::GetMsgLstFile()
91 {
92         int i,sizeLst;
93 //EEDx44
94         std::string msgLstFile="";
95         sizeLst=_lstFileNotReaded.size();
96         for (i=0;i<sizeLst;i++)
97         {
98                 msgLstFile = msgLstFile + *(_lstFileNotReaded[i]) ;
99                 msgLstFile = msgLstFile + "\n";
100         }
101
102         return msgLstFile;
103 }
104
105
106
107
108
109
110 // -------------------------------------------------------------------------
111 // -------------------------------------------------------------------------
112 // -------------------------------------------------------------------------
113 marRAWFiles::marRAWFiles(marParameters* p)
114 :  marFilesBase(p)
115 {
116         _littreEndianBigEndian=0;
117 }
118 // -------------------------------------------------------------------------
119 marRAWFiles::~marRAWFiles()
120 {
121 }
122 // -------------------------------------------------------------------------
123 //EED 9 oct 2006
124 bool marRAWFiles::loadImage(int i) // virtual
125 {
126
127         int dim[3];
128
129         vtkImageData *vol = getVolume( )->castVtk();
130         void *p_vol=(void*)getVolume( )->castVtk()->GetScalarPointer(0,0,i);
131         vol->GetDimensions(dim);
132
133         int dataSize = sizeof(unsigned short)*dim[0]*dim[1];
134         bool ok=true;
135
136 /*
137         std::string *ss = _lstString[i];
138         FILE *ff=fopen( (char*)(ss->c_str())  , "r+" );
139         fread( (char*)p_vol , dataSize,1, ff);
140         fclose(ff);
141 */
142
143         std::string *ss = _lstString[i];
144         vtkVolume16Reader *reader = vtkVolume16Reader::New ();
145         reader->SetDataDimensions ( dim[0] , dim[1] );
146         if (_littreEndianBigEndian == 0) {
147             reader->SetDataByteOrderToLittleEndian ( );
148         } else {
149                 reader->SetDataByteOrderToBigEndian();
150         }
151         reader->SetFilePrefix ( (char*)(ss->c_str())  );
152         reader->SetFilePattern("%s");
153     reader->SetImageRange ( 0, 0 );
154     reader->SetDataSpacing ( 1, 1, 1 );
155     reader->Update ();
156         void *pp_vol=(void*)reader->GetOutput()->GetScalarPointer(0,0,0);
157         memcpy(p_vol,pp_vol,dataSize);
158         reader->Delete();
159
160
161 /*
162
163         std::string *ss = _lstString[i];
164         vtkGsmisReader *reader = vtkGsmisReader::New();
165         reader->SetFileName( (char*)(ss->c_str())  );
166         vtkImageData *ima=reader->GetOutput();
167         ima->Update();
168         void *pp_vol=(void*)ima->GetScalarPointer(0,0,0);
169         memcpy(p_vol,pp_vol,dataSize);
170 //      reader->Delete();
171 */
172
173
174
175 /*
176         int             ii;
177         char    tmp;
178         char    *pp = (char*)p_vol;
179         unsigned short   *valueA;
180         dataSize        = dim[0]*dim[1];
181         for (ii=0;ii<dataSize;ii++)
182         {
183                 tmp             = *pp;
184                 *pp             = *(pp+1);
185                 *(pp+1) = tmp;
186
187                 valueA=(unsigned short*)pp;
188                 *valueA=*valueA-32000;
189                 if (*valueA>=32000)
190                 {
191                         *valueA=0;
192                 } 
193
194                 pp              = pp+2;
195         }
196 */
197
198         if (ok==false) {
199                 _lstFileNotReaded.push_back( (char*)(ss->c_str()) );
200         }
201
202         return ok;
203 }
204 // -------------------------------------------------------------------------
205 //EED 9 oct 2006
206 void marRAWFiles::loadActualSerie(wxGauge* gauge )
207 {
208
209         // Read File List
210         FILE *ff;
211         ff = fopen( _lstString[0] -> c_str() , "r"); 
212         std::string directory(*(_lstString[1]) );
213         char tmp[255];
214
215         fscanf(ff,"%s",tmp);
216         fscanf(ff,"%s",tmp);
217         //int type =    atoi(tmp);  // 0 // JPRx
218
219         fscanf(ff,"%s",tmp);
220         fscanf(ff,"%s",tmp);
221         int wx  =       atoi(tmp);
222         fscanf(ff,"%s",tmp);
223         fscanf(ff,"%s",tmp);
224         int wy  =       atoi(tmp);
225
226         fscanf(ff,"%s",tmp);
227         fscanf(ff,"%s",tmp);
228         double spx      =       atof(tmp);
229         fscanf(ff,"%s",tmp);
230         fscanf(ff,"%s",tmp);
231         double spy      =       atof(tmp);
232         fscanf(ff,"%s",tmp);
233         fscanf(ff,"%s",tmp);
234         double spz      =       atof(tmp);
235
236         fscanf(ff,"%s",tmp);
237         fscanf(ff,"%s",tmp);
238         int LB  =       atoi(tmp);
239
240         this->SetLittreEndianBigEndian(LB);
241
242
243         int wz=0;
244         this->CleanListImages();
245         while ( !feof(ff) )
246         {
247                 fscanf(ff,"%s",tmp);
248                 std::string *tmpStr =  new std::string(tmp);
249                 (*tmpStr) = "/"+(*tmpStr);
250                 (*tmpStr) = (directory)+(*tmpStr);
251                 _lstString.push_back( tmpStr);
252                 wz++;
253         }
254
255         fclose(ff);
256
257
258         // Create Free Memory block image
259         freeVolume();
260
261         if (wz==0)
262         {
263                 wz=1;
264         }
265
266         kVolume *vol =new kVolume( kVolume::USHORT, wx, wy, wz,spx, spy, spz, malloc(sizeof(unsigned short)*wx*wy*wz ) );
267         SetVolume( vol );
268
269
270         // Define Spacing
271         getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spx );
272         getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spy );
273         getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spz );
274
275         // Define Intercept Slope
276         getParameters( )->setDoubleParam( marParameters::e_RescaleIntercept , 0 );
277         getParameters( )->setDoubleParam( marParameters::e_RescaleSlope     , 1 );
278 }
279 // -------------------------------------------------------------------------
280 void marRAWFiles::SetLittreEndianBigEndian(int value)
281 {
282         _littreEndianBigEndian = value;
283 }
284 // -------------------------------------------------------------------------
285 int     marRAWFiles::GetLittreEndianBigEndian()
286 {
287         return _littreEndianBigEndian;
288 }
289 // -------------------------------------------------------------------------
290 void marRAWFiles::reset( )
291 {
292 }
293 // -------------------------------------------------------------------------
294 void marRAWFiles::copyFrom( const marObject& from )
295 {
296 }
297 // -------------------------------------------------------------------------
298 bool marRAWFiles::save( std::ofstream& os )
299 {
300         return true;
301 }
302 // -------------------------------------------------------------------------
303 bool marRAWFiles::load( std::ifstream& is )
304 {
305         return true;
306 }
307
308
309 //-------------------------------------------------------------------------
310 // -------------------------------------------------------------------------
311 // -------------------------------------------------------------------------
312 marRAW2AsciiFiles::marRAW2AsciiFiles(marParameters* p)
313 :  marRAWFiles(p)
314 {
315 }
316 // -------------------------------------------------------------------------
317 marRAW2AsciiFiles::~marRAW2AsciiFiles()
318 {
319 }
320 // -------------------------------------------------------------------------
321 bool marRAW2AsciiFiles::loadImage(int i) // virtual
322 {
323         return true;
324 }
325
326
327 // -------------------------------------------------------------------------
328 //EED 9 oct 2006
329 void marRAW2AsciiFiles::loadActualSerie(wxGauge* gauge )
330 {
331
332         // Read File List
333         FILE *ff;
334         ff = fopen( _lstString[0] -> c_str() , "r"); 
335         char tmp[255];
336
337         // type
338         fscanf(ff,"%s",tmp);
339         fscanf(ff,"%s",tmp);
340         //int type =    atoi(tmp);  // 300  // JPRx
341
342         //size x,y,z
343         fscanf(ff,"%s",tmp);
344         fscanf(ff,"%s",tmp);
345         int wx  =       atoi(tmp);
346         fscanf(ff,"%s",tmp);
347         fscanf(ff,"%s",tmp);
348         int wy  =       atoi(tmp);
349         fscanf(ff,"%s",tmp);
350         fscanf(ff,"%s",tmp);
351         int wz  =       atoi(tmp);
352
353         // spacing x,y,z
354         fscanf(ff,"%s",tmp);
355         fscanf(ff,"%s",tmp);
356         double spx      =       atof(tmp);
357         fscanf(ff,"%s",tmp);
358         fscanf(ff,"%s",tmp);
359         double spy      =       atof(tmp);
360         fscanf(ff,"%s",tmp);
361         fscanf(ff,"%s",tmp);
362         double spz      =       atof(tmp);
363
364         // Intercept Slope
365         fscanf(ff,"%s",tmp);
366         fscanf(ff,"%s",tmp);
367         double intercept        =       atof(tmp);
368         fscanf(ff,"%s",tmp);
369         fscanf(ff,"%s",tmp);
370         double slope            =       atof(tmp);
371
372
373         fscanf(ff,"%s",tmp);
374         std::string file(tmp);
375         std::string namefile( *_lstString[1] );  // directory
376         namefile=namefile+"/";                   // +  
377         namefile=namefile+file;                  // file
378
379         fclose(ff);
380
381
382         this->CleanListImages();
383
384         // Create Free Memory block image
385         freeVolume();
386
387         if (wz==0)
388         {
389                 wz=1;
390         }
391
392         kVolume *vol =new kVolume( kVolume::USHORT, wx, wy, wz,spx, spy, spz, malloc(sizeof(unsigned short)*wx*wy*wz ) );
393         SetVolume( vol );
394
395
396         // Define Spacing
397         getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spx );
398         getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spy );
399         getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spz );
400
401         // Define Intercept Slope
402         getParameters( )->setDoubleParam( marParameters::e_RescaleIntercept , 0 );
403         getParameters( )->setDoubleParam( marParameters::e_RescaleSlope     , 1 );
404
405
406         void    *p_vol  = (void*)getVolume( )->castVtk()->GetScalarPointer(0,0,0);
407         short   *pp             = (short*)p_vol;
408
409         FILE *fff=fopen( (char*)namefile.c_str() , "r+" );
410         long int ii, dataSize   = wx*wy*wz;
411         float value;
412         for (ii=0;ii<dataSize;ii++)
413         {
414                 fscanf(fff,"%f ",&value);
415                 // Intercept Slope
416                 *pp     = (short)        ( value*slope + intercept );
417                 if (*pp<0)
418                 {
419                         *pp=0;
420                 } 
421                 pp++;
422         }
423         fclose(fff);
424
425
426 // Y- Flip
427 //      FlipY( getVolume( )->castVtk() );
428         
429 }
430
431
432 // -------------------------------------------------------------------------
433 // -------------------------------------------------------------------------
434 // -------------------------------------------------------------------------
435 marRAW2Files::marRAW2Files(marParameters* p)
436 :  marRAWFiles(p)
437 {
438 }
439 // -------------------------------------------------------------------------
440 marRAW2Files::~marRAW2Files()
441 {
442 }
443 // -------------------------------------------------------------------------
444 bool marRAW2Files::loadImage(int i) // virtual
445 {
446         return true;
447 }
448
449
450 // -------------------------------------------------------------------------
451 //EED 9 oct 2006
452 void marRAW2Files::loadActualSerie(wxGauge* gauge )
453 {
454
455         // Read File List
456         FILE *ff;
457         ff = fopen( _lstString[0] -> c_str() , "r"); 
458         char tmp[255];
459
460         // type
461         fscanf(ff,"%s",tmp);
462         fscanf(ff,"%s",tmp);
463         //int type =    atoi(tmp);  // 200  // JPRx
464
465         //size x,y,z
466         fscanf(ff,"%s",tmp);
467         fscanf(ff,"%s",tmp);
468         int wx  =       atoi(tmp);
469         fscanf(ff,"%s",tmp);
470         fscanf(ff,"%s",tmp);
471         int wy  =       atoi(tmp);
472 //      fscanf(ff,"%s",tmp);
473 //      fscanf(ff,"%s",tmp);
474 //      int wz  =       atoi(tmp);
475
476         fscanf(ff,"%s",tmp);
477         fscanf(ff,"%s",tmp);
478         int wz1 =       atoi(tmp);
479         fscanf(ff,"%s",tmp);
480         fscanf(ff,"%s",tmp);
481         int wz2 =       atoi(tmp);
482
483         int wz = wz2-wz1;
484         
485         // spacing x,y,z
486         fscanf(ff,"%s",tmp);
487         fscanf(ff,"%s",tmp);
488         double spx      =       atof(tmp);
489         fscanf(ff,"%s",tmp);
490         fscanf(ff,"%s",tmp);
491         double spy      =       atof(tmp);
492         fscanf(ff,"%s",tmp);
493         fscanf(ff,"%s",tmp);
494         double spz      =       atof(tmp);
495
496         // Intercept Slope
497         fscanf(ff,"%s",tmp);
498         fscanf(ff,"%s",tmp);
499         double intercept        =       atof(tmp);
500         fscanf(ff,"%s",tmp);
501         fscanf(ff,"%s",tmp);
502         double slope            =       atof(tmp);
503
504         // L/B
505         fscanf(ff,"%s",tmp);
506         fscanf(ff,"%s",tmp);
507         int littleBig   =       atoi(tmp);
508
509         // bits
510         fscanf(ff,"%s",tmp);
511         fscanf(ff,"%s",tmp);
512         int bits        =       atoi(tmp);
513
514         if ((bits!=8) && (bits!=16)){
515                 bits=16;
516         }
517         
518         fscanf(ff,"%s",tmp);
519         std::string file(tmp);
520         std::string namefile( *_lstString[1] );  // directory
521         namefile=namefile+"/";                   // +  
522         namefile=namefile+file;                  // file
523
524         fclose(ff);
525
526
527         this->CleanListImages();
528
529         // Create Free Memory block image
530         freeVolume();
531
532         if (wz==0)
533         {
534                 wz=1;
535         }
536
537
538         kVolume *vol =new kVolume( kVolume::USHORT, wx, wy, wz,spx, spy, spz, malloc(sizeof(unsigned short)*wx*wy*wz ) );
539         SetVolume( vol );
540
541
542         // Define Spacing
543         getParameters( )->setDoubleParam( marParameters::e_voxel_x_dimension, spx );
544         getParameters( )->setDoubleParam( marParameters::e_voxel_y_dimension, spy );
545         getParameters( )->setDoubleParam( marParameters::e_voxel_z_dimension, spz );
546
547         // Define Intercept Slope
548         getParameters( )->setDoubleParam( marParameters::e_RescaleIntercept , 0 );
549         getParameters( )->setDoubleParam( marParameters::e_RescaleSlope     , 1 );
550
551         void *p_vol=(void*)getVolume( )->castVtk()->GetScalarPointer(0,0,0);
552         FILE *fff=fopen( (char*)namefile.c_str() , "r+" );
553     if (bits==16)
554     {
555                 fseek( fff , wx*wy*wz1*2 , SEEK_CUR );
556         fread( (char*)p_vol , wx*wy*wz*2,1, fff);
557             fclose(fff);
558
559
560         // littleBigEndien
561                 if (littleBig==1){
562                         long int                ii;
563                         char                    tmpB;
564                         char                    *pp = (char*)p_vol;
565                         unsigned short   *valueA;
566                         long int dataSize       = wx*wy*wz;
567                         for (ii=0;ii<dataSize;ii++)
568                         {
569                                 tmpB            = *pp;
570                                 *pp                     = *(pp+1);
571                                 *(pp+1)         = tmpB;
572                                 
573                                 valueA= ((unsigned short*)pp);
574                                 if (*valueA>=32000)
575                                 {
576                                         *valueA=0;
577                                 } 
578                                 pp              = pp+2;
579
580                         }
581                 }
582
583                 unsigned short                  *pp = (unsigned short*)p_vol;
584                 int tmpInt;
585                 int ii, dataSize        = wx*wy*wz;
586                 for (ii=0;ii<dataSize;ii++)
587                 {
588                         tmpInt = (int) (*pp);
589                         tmpInt  = (int)  ( tmpInt*slope+intercept );
590                         if (tmpInt<0)
591                         {
592                                 tmpInt=0;
593                         } 
594                         if (tmpInt>65535) 
595                         {
596                                 tmpInt=65535;
597                         }
598                         (*pp) = (unsigned short)tmpInt;
599                         pp              = pp+1;
600                 }
601
602     } else {
603         unsigned short *pShort=(unsigned short*)p_vol;
604         int i8bitImage,size8bitImage = wx*wy*wz;
605         unsigned char *pChar=(unsigned char*)malloc( size8bitImage );
606                 fseek( fff , wx*wy*wz1 , SEEK_CUR );
607         fread( (unsigned char*)pChar , size8bitImage,1, fff);
608             fclose(fff);
609                 double tmpDouble;
610         for ( i8bitImage=0 ; i8bitImage < size8bitImage ; i8bitImage++ )
611         {
612                         
613                         tmpDouble=(float)pChar[ i8bitImage ];
614                         tmpDouble=tmpDouble*slope+intercept;
615                         if (tmpDouble<0)
616                         {
617                                 tmpDouble=0;
618                         } 
619                 pShort[ i8bitImage ] = (unsigned short)tmpDouble;
620         }
621         free (pChar);
622     }
623
624 // Y- Flip
625         FlipY( getVolume( )->castVtk() );
626         
627 }
628
629
630
631
632 // -------------------------------------------------------------------------
633 void marRAW2Files::FlipY(vtkImageData *imagedata)
634 {
635         vtkImageData *vtkimagedata = imagedata;
636         vtkimagedata->Update();
637         int dim[3];
638         vtkimagedata->GetDimensions(dim);
639         unsigned short tmp;
640         unsigned short *pp=(unsigned short*)vtkimagedata->GetScalarPointer(0,0,0);
641         int xx,yy,zz;
642         int sizeX  = dim[0];
643         int sizeY  = dim[1];
644         int sizeY2 = sizeY/2;
645         int sizeZ  = dim[2];
646         long int deltaZ;
647         long int deltaA;
648         long int deltaB;
649
650         for ( zz=0 ; zz<sizeZ ; zz++ )
651         {
652                 deltaZ=zz*sizeX*sizeY;
653                 for ( xx=0 ; xx<sizeX ; xx++ )
654                 {
655                 for ( yy=0 ; yy<sizeY2 ; yy++ )
656                         {
657                                 deltaA          = xx + yy*sizeX + deltaZ;
658                                 deltaB          = xx + (sizeY-yy-1)*sizeX + deltaZ;
659                                 tmp                     = pp[deltaA ];
660                                 pp[deltaA]      = pp[deltaB ];
661                                 pp[deltaB]      = tmp;
662                                 }
663                         }
664                 }
665    vtkimagedata->Update();
666
667 }
668 // -------------------------------------------------------------------------
669
670 // EED 23 Janvier 2007
671 void marRAW2Files::saveVolume( std::string directory, std::string name, vtkImageData *imagedata,int voi[6], double slope, double intercept) // virtual
672 {
673
674         std::string filename             = directory+"/"+name;
675
676                 // Crop
677         vtkExtractVOI *crop = vtkExtractVOI::New();
678         crop->SetInput( imagedata );
679         crop->SetVOI( voi );
680         crop->Update();
681
682         int dim[3];
683         int ext[6];
684         double spc[3];
685         crop->GetOutput()->GetDimensions(dim);
686         crop->GetOutput()->GetSpacing(spc);
687         crop->GetOutput()->GetExtent(ext);
688
689
690         vtkImageChangeInformation* change = vtkImageChangeInformation::New();
691         change->SetInput( crop->GetOutput() );
692
693
694 //      change->SetExtentTranslation( -ext[0], -ext[2], -ext[4] );
695    
696
697         change->SetOutputSpacing ( spc[0] , spc[1] , spc[2] );
698         change->Update();    //important
699
700 //   change->SetExtentTranslation( ext[0], ext[2], ext[4] );
701 //      change->Update();
702
703
704         // write mdh file
705    std::string nameMW            = filename+".mhd";
706
707         vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
708         writer->SetInput( change->GetOutput() );
709         writer->SetFileName( nameMW.c_str() );
710         writer->SetFileDimensionality( 3 );
711         writer->Write( );
712
713                 // write maracas file
714         std::string nameM=filename+".maracas";
715
716
717         FILE *ff;
718         ff=fopen(nameM.c_str(),"w");
719                 fprintf(ff,"MaracasType 200\n" );
720                 fprintf(ff,"sizeX %d\n",dim[0] );
721                 fprintf(ff,"sizeY %d\n",dim[1] );
722                 fprintf(ff,"sizeZ1 %d\n",0 );
723                 fprintf(ff,"sizeZ2 %d\n",dim[2] );
724                 fprintf(ff,"spcX %f\n",spc[0]  );
725                 fprintf(ff,"spcY %f\n",spc[1]  );
726                 fprintf(ff,"spcZ %f\n",spc[2]  );
727                 fprintf(ff,"intercept %f\n",intercept );
728                 fprintf(ff,"slope %f\n",slope );
729                 fprintf(ff,"LB %d\n",0 );
730                 fprintf(ff,"bits %d\n",16 );
731                 fprintf(ff,"%s.raw\n", name.c_str() );
732         fclose(ff);
733
734         writer  -> Delete();
735         change  -> Delete();
736         crop    -> Delete();
737 }
738