42 #include <sys/types.h>
47 #include "vtkExtractVOI.h"
48 #include "vtkImageData.h"
50 #include "vtkSmartPointer.h"
52 #include "vtkPNGWriter.h"
53 #include "vtkTIFFWriter.h"
61 m_FileType(GoFigure::
PNG), m_LSMReaders(0), m_Plaque (0), m_Row(0), m_Column (0),
62 m_XTile(0), m_YTile(0), m_ZTile (0), m_XOverlap(0), m_YOverlap(0), m_ZOverlap(0),
63 m_NumberOfChannels(0), m_NumberOfTimePoints(0), m_Dim(0)
160 std::string headerfilename = iMegaPath;
162 headerfilename +=
".meg";
164 std::ofstream file( headerfilename.c_str() );
165 file <<
"MegaCapture" << std::endl;
166 file <<
"<ImageSessionData>" << std::endl;
167 file <<
"Version 3.0" << std::endl;
168 file <<
"ExperimentTitle " << std::endl;
169 file <<
"ExperimentDescription ";
175 file <<
"TimeInterval " <<
m_LSMReaders[0]->GetTimeInterval() << std::endl;
176 file <<
"Objective " <<
m_LSMReaders[0]->GetObjective() << std::endl;
177 file <<
"VoxelSizeX " << spacing[0] * 1000000 << std::endl;
178 file <<
"VoxelSizeY " << spacing[1] * 1000000 << std::endl;
179 file <<
"VoxelSizeZ " << spacing[2] * 1000000 << std::endl;
180 file <<
"DimensionX " << dim[0] << std::endl;
181 file <<
"DimensionY " << dim[1] << std::endl;
182 file <<
"DimensionPL " <<
m_Plaque << std::endl;
183 file <<
"DimensionCO " <<
m_Column << std::endl;
184 file <<
"DimensionRO " <<
m_Row << std::endl;
185 file <<
"DimensionZT " <<
m_ZTile << std::endl;
186 file <<
"DimensionYT " <<
m_YTile << std::endl;
187 file <<
"DimensionXT " <<
m_XTile << std::endl;
189 file <<
"DimensionZS " << dim[2] << std::endl;
192 unsigned int i, j, k;
195 int r =
m_LSMReaders[0]->GetChannelColorComponent(i, 0);
196 int g =
m_LSMReaders[0]->GetChannelColorComponent(i, 1);
197 int b =
m_LSMReaders[0]->GetChannelColorComponent(i, 2);
198 std::ostringstream channelColor;
199 channelColor <<
"ChannelColor" << std::setw(2) << std::setfill(
'0') << i;
200 file << channelColor.str() <<
" " << r * 256 * 256 + g * 256 + b << std::endl;
205 file <<
"ChannelDepth 8" << std::endl;
206 file <<
"FileType PNG" << std::endl;
207 file <<
"</ImageSessionData>" << std::endl;
209 if ( m_NumberOfChannels > 1 )
223 char timeStr[100] =
"";
228 strftime( timeStr, 100,
"%Y-%m-%d %H:%M:%S", localtime(&buf.st_mtime) );
243 image3d->GetExtent(extent);
245 for ( k = 0; k < static_cast< unsigned int >( dim[2] ); k++ )
247 std::stringstream filename;
249 filename <<
"-CO" << setfill(
'0') << setw(2) <<
m_Column;
250 filename <<
"-RO" << setfill(
'0') << setw(2) <<
m_Row;
251 filename <<
"-ZT" << setfill(
'0') << setw(2) <<
m_ZTile;
252 filename <<
"-YT" << setfill(
'0') << setw(2) <<
m_YTile;
253 filename <<
"-XT" << setfill(
'0') << setw(2) <<
m_XTile;
254 filename <<
"-TM" << setfill(
'0') << setw(4) << i;
255 filename <<
"-ch" << setfill(
'0') << setw(2) << j;
256 filename <<
"-zs" << setfill(
'0') << setw(4) << k;
273 file <<
"<Image>" << std::endl;
274 file <<
"Filename " << filename.str() << std::endl;
275 file <<
"DateTime " << timeStr << std::endl;
276 file <<
"StageX 1000" << std::endl;
277 file <<
"StageY -1000" << std::endl;
278 file <<
"Pinhole 44.216" << std::endl;
279 file <<
"</Image>" << std::endl;
281 vtkSmartPointer< vtkExtractVOI > extract =
282 vtkSmartPointer< vtkExtractVOI >::New();
283 extract->SetSampleRate(1, 1, 1);
284 extract->SetInput(image3d);
285 extract->SetVOI(extent[0], extent[1], extent[2], extent[3], k, k);
288 vtkImageData *image2d = extract->GetOutput();
290 std::string final_filename = iMegaPath;
291 final_filename += filename.str();
298 vtkWriteImage< vtkPNGWriter >(image2d, final_filename);
303 vtkWriteImage< vtkTIFFWriter >(image2d, final_filename);
unsigned int m_NumberOfChannels
std::vector< vtkLSMReader * > m_LSMReaders
std::vector< vtkLSMReader * > GetLSMReaders()
void SetFileName(const std::string &iFileName)
Set input lsm file. (Extract m_BaseName)
Convert 1 LSM (5D file) into megacapture files.
void SetMegaPath(std::string iMegaPath)
Set the path of the MegaCapture file to create.
int GetNumberOfPoints()
Returns the number of signals to be sent for the progress bar.
void run()
Start multithread process (call when parameters are set up properly)
ConversionLsmToMegaThread()
Constructor.
void SetOutputFileType(const GoFigure::FileType &iFileType)
Set the output file type.
unsigned int m_NumberOfTimePoints
virtual ~ConversionLsmToMegaThread()
Destructor.
void ExportWithReimplemented(std::string iMegaPath)
Start the conversion to MegaCapture.
static vtkLSMReader * New()
void InitialisationProgressSent()
void SetOutputFileType(const GoFigure::FileType &iFileType)
Set the output format: PNG (default) or TIFF.
void ConversionTerminatedSent()
void SetBaseName(std::string iBaseName)
Set the base name of the LSM file to convert.
void SetLsmPath(std::string iLsmPath)
Set the path to the LSM file to convert and initialise LSM reader.
GoFigure::FileType m_FileType