1 #include <tclap/CmdLine.h> 6 #include <itkImageRegionIterator.h> 10 int main(
int argc,
char **argv)
12 typedef itk::Image <double,3> DoubleImageType;
13 typedef itk::VectorImage <double,3> VectorImageType;
15 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
17 TCLAP::ValueArg<std::string> inArg(
"i",
"inputlist",
"Input list of chunks of data",
true,
"",
"input list",cmd);
18 TCLAP::ValueArg<std::string> outArg(
"o",
"outputfile",
"output image",
true,
"",
"output image",cmd);
20 TCLAP::ValueArg<std::string> geomArg(
"g",
"geometryimage",
"geometry image",
true,
"",
"geometry image",cmd);
21 TCLAP::SwitchArg vecArg(
"V",
"isvec",
"Input images are vector images",cmd,
false);
27 catch (TCLAP::ArgException& e)
29 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
33 DoubleImageType::Pointer geomImage = anima::readImage <DoubleImageType> (geomArg.getValue());
35 DoubleImageType::SpacingType spacing = geomImage->GetSpacing();
36 DoubleImageType::PointType origin = geomImage->GetOrigin();
37 DoubleImageType::DirectionType direction = geomImage->GetDirection();
38 DoubleImageType::RegionType region = geomImage->GetLargestPossibleRegion();
40 std::vector <std::string> fileNames;
41 std::vector <DoubleImageType::IndexType> indexes;
43 ifstream fileList(inArg.getValue());
46 while (!fileList.eof())
48 fileList.getline(tmpStr,2048);
49 while ((strncmp(tmpStr,
"<BLOCK>",7) != 0)&&(!fileList.eof()))
51 fileList.getline(tmpStr,2048);
57 fileList.getline(tmpStr,2048);
59 DoubleImageType::IndexType tmpInd;
60 while (strncmp(tmpStr,
"</BLOCK>",8) != 0)
62 if (strncmp(tmpStr,
"BLOCK_FILE=",11) == 0)
64 sscanf(tmpStr,
"BLOCK_FILE=%s",fileName);
66 else if (strncmp(tmpStr,
"STARTING_INDEX=",15) == 0)
68 sscanf(tmpStr,
"STARTING_INDEX=%ld %ld %ld",&tmpInd[0],&tmpInd[1],&tmpInd[2]);
71 fileList.getline(tmpStr,2048);
74 fileNames.push_back(fileName);
75 indexes.push_back(tmpInd);
80 bool isVect = vecArg.isSet();
83 DoubleImageType::Pointer mainData = DoubleImageType::New();
84 mainData->Initialize();
85 mainData->SetOrigin(origin);
86 mainData->SetSpacing(spacing);
87 mainData->SetDirection(direction);
88 mainData->SetRegions(region);
92 for (
unsigned int i = 0;i < fileNames.size();++i)
94 DoubleImageType::Pointer tmpImage = anima::readImage <DoubleImageType> (fileNames[i]);
96 DoubleImageType::RegionType origRegion = tmpImage->GetLargestPossibleRegion();
97 DoubleImageType::RegionType destRegion = origRegion;
98 for (
unsigned int j = 0;j < DoubleImageType::GetImageDimension();++j)
99 destRegion.SetIndex(j,indexes[i][j]);
101 itk::ImageRegionIterator <DoubleImageType> origItr(tmpImage,origRegion);
102 itk::ImageRegionIterator <DoubleImageType> destItr(mainData,destRegion);
104 while (!origItr.IsAtEnd())
106 destItr.Set(origItr.Get());
113 anima::writeImage <DoubleImageType> (outArg.getValue(),mainData);
117 VectorImageType::Pointer mainData = VectorImageType::New();
118 mainData->Initialize();
120 mainData->SetOrigin(origin);
121 mainData->SetSpacing(spacing);
122 mainData->SetDirection(direction);
123 mainData->SetRegions(region);
127 for (
unsigned int i = 0;i < fileNames.size();++i)
129 std::cout << fileNames[i] <<
"..." << std::flush;
130 VectorImageType::Pointer tmpImage = anima::readImage <VectorImageType> (fileNames[i]);
134 mainData->SetNumberOfComponentsPerPixel(tmpImage->GetNumberOfComponentsPerPixel());
135 mainData->Allocate();
137 itk::VariableLengthVector <double> tmpVecFill(tmpImage->GetNumberOfComponentsPerPixel());
138 for (
unsigned int j = 0;j < tmpImage->GetNumberOfComponentsPerPixel();++j)
141 itk::ImageRegionIterator <VectorImageType> tmpDestItr(mainData,mainData->GetLargestPossibleRegion());
142 while (!tmpDestItr.IsAtEnd())
144 tmpDestItr.Set(tmpVecFill);
149 VectorImageType::RegionType origRegion = tmpImage->GetLargestPossibleRegion();
150 VectorImageType::RegionType destRegion = origRegion;
151 for (
unsigned int j = 0;j < VectorImageType::GetImageDimension();++j)
152 destRegion.SetIndex(j,indexes[i][j]);
154 itk::ImageRegionIterator <VectorImageType> origItr(tmpImage,origRegion);
155 itk::ImageRegionIterator <VectorImageType> destItr(mainData,destRegion);
157 while (!origItr.IsAtEnd())
159 itk::VariableLengthVector <double> tmpVec = origItr.Get();
166 std::cout <<
" Done..." <<std::endl;
169 anima::writeImage <VectorImageType> (outArg.getValue(),mainData);
int main(int argc, char **argv)