@@ -582,7 +582,7 @@ bool vtkPlusMetaImageSequenceIO::CanWriteFile( const std::string& filename )
582582// ----------------------------------------------------------------------------
583583/* * Writes the spacing and dimensions of the image.
584584* Assumes SetFileName has been called with a valid file name. */
585- PlusStatus vtkPlusMetaImageSequenceIO::OpenImageHeader ()
585+ PlusStatus vtkPlusMetaImageSequenceIO::WriteInitialImageHeader ()
586586{
587587 if ( this ->TrackedFrameList ->GetNumberOfTrackedFrames () == 0 )
588588 {
@@ -592,7 +592,7 @@ PlusStatus vtkPlusMetaImageSequenceIO::OpenImageHeader()
592592
593593 // First, is this 2D or 3D?
594594 bool isData3D = ( this ->TrackedFrameList ->GetTrackedFrame ( 0 )->GetFrameSize ()[2 ] > 1 );
595- bool isDataTimeSeries = this ->TrackedFrameList -> GetNumberOfTrackedFrames () > 1 ;
595+ bool isDataTimeSeries = this ->IsDataTimeSeries ; // don't compute it from the number of frames because we may still have only one frame but acquire more frames later
596596
597597 // Override fields
598598 this ->NumberOfDimensions = isData3D ? 3 : 2 ;
@@ -604,12 +604,7 @@ PlusStatus vtkPlusMetaImageSequenceIO::OpenImageHeader()
604604 {
605605 this ->NumberOfDimensions ++;
606606 }
607-
608- {
609- std::stringstream ss;
610- ss << this ->NumberOfDimensions ;
611- SetCustomString ( " NDims" , ss.str () );
612- }
607+ SetCustomString (" NDims" , this ->NumberOfDimensions );
613608
614609 SetCustomString ( " BinaryData" , " True" );
615610 SetCustomString ( " BinaryDataByteOrderMSB" , " False" );
@@ -629,7 +624,7 @@ PlusStatus vtkPlusMetaImageSequenceIO::OpenImageHeader()
629624 else
630625 {
631626 SetCustomString ( " CompressedData" , " False" );
632- SetCustomString ( SEQMETA_FIELD_COMPRESSED_DATA_SIZE, NULL );
627+ SetCustomString ( SEQMETA_FIELD_COMPRESSED_DATA_SIZE, ( const char *)( NULL ) );
633628 }
634629
635630 unsigned int frameSize[3 ] = {0 , 0 , 0 };
@@ -669,7 +664,7 @@ PlusStatus vtkPlusMetaImageSequenceIO::OpenImageHeader()
669664 }
670665
671666 // Update NDims and Dims fields in header
672- this ->GenerateFrameSizeCustomStrings ( this ->TrackedFrameList ->GetNumberOfTrackedFrames (), isData3D );
667+ this ->UpdateDimensionsCustomStrings ( this ->TrackedFrameList ->GetNumberOfTrackedFrames (), isData3D );
673668
674669 // PixelType
675670 if ( this ->TrackedFrameList ->IsContainingValidImageData () )
@@ -692,9 +687,7 @@ PlusStatus vtkPlusMetaImageSequenceIO::OpenImageHeader()
692687 {
693688 this ->NumberOfScalarComponents = this ->TrackedFrameList ->GetNumberOfScalarComponents ();
694689 }
695- std::ostringstream ss;
696- ss << this ->NumberOfScalarComponents ;
697- SetCustomString ( " ElementNumberOfChannels" , ss.str ().c_str () );
690+ SetCustomString (" ElementNumberOfChannels" , this ->NumberOfScalarComponents );
698691 }
699692
700693 SetCustomString ( SEQMETA_FIELD_US_IMG_ORIENT, PlusVideoFrame::GetStringFromUsImageOrientation ( US_IMG_ORIENT_MF ) );
@@ -861,10 +854,10 @@ PlusStatus vtkPlusMetaImageSequenceIO::AppendImagesToHeader()
861854 }
862855
863856 // Write frame fields (Seq_Frame0000_... = ...)
864- for ( unsigned int frameNumber = CurrentFrameOffset; frameNumber < this ->TrackedFrameList ->GetNumberOfTrackedFrames () + CurrentFrameOffset; frameNumber++ )
857+ for ( unsigned int frameNumber = this -> CurrentFrameOffset ; frameNumber < this ->TrackedFrameList ->GetNumberOfTrackedFrames () + this -> CurrentFrameOffset ; frameNumber++ )
865858 {
866859 LOG_DEBUG ( " Writing frame " << frameNumber );
867- unsigned int adjustedFrameNumber = frameNumber - CurrentFrameOffset;
860+ unsigned int adjustedFrameNumber = frameNumber - this -> CurrentFrameOffset ;
868861 PlusTrackedFrame* trackedFrame = this ->TrackedFrameList ->GetTrackedFrame ( adjustedFrameNumber );
869862
870863 std::ostringstream frameIndexStr;
@@ -1262,16 +1255,15 @@ PlusStatus vtkPlusMetaImageSequenceIO::UpdateFieldInImageHeader( const char* fie
12621255 newLineStr << name << " = " << GetCustomString ( name.c_str () );
12631256
12641257 // need to add padding whitespace characters to fully replace the old line
1265- int paddingCharactersNeeded = SEQMETA_FIELD_PADDED_LINE_LENGTH - newLineStr.str ().size ();
1266- for ( int i = 0 ; i < paddingCharactersNeeded; i++ )
1258+ int paddingCharactersNeeded = line. length () - newLineStr.str ().size ();
1259+ if (paddingCharactersNeeded < 0 )
12671260 {
1268- newLineStr << " " ;
1261+ LOG_ERROR (" Cannot update line in image header (the new string '" << newLineStr.str () << " ' is longer than the current string '" << line << " ')" );
1262+ return PLUS_FAIL;
12691263 }
1270-
1271- if ( newLineStr.str ().length () != line.length () )
1264+ for ( int i = 0 ; i < paddingCharactersNeeded; i++ )
12721265 {
1273- LOG_ERROR ( " Cannot update line in image header (the new string '" << newLineStr.str () << " ' is longer than the current string '" << line << " ')" );
1274- return PLUS_FAIL;
1266+ newLineStr << " " ;
12751267 }
12761268
12771269 // rewind to file pointer the first character of the line
@@ -1387,7 +1379,7 @@ PlusStatus vtkPlusMetaImageSequenceIO::SetFileName( const std::string& aFilename
13871379}
13881380
13891381// ----------------------------------------------------------------------------
1390- PlusStatus vtkPlusMetaImageSequenceIO::GenerateFrameSizeCustomStrings ( int numberOfFrames, bool isData3D )
1382+ PlusStatus vtkPlusMetaImageSequenceIO::UpdateDimensionsCustomStrings ( int numberOfFrames, bool isData3D )
13911383{
13921384 if ( this ->EnableImageDataWrite && this ->TrackedFrameList ->IsContainingValidImageData () )
13931385 {
0 commit comments