/** ImageDimension constants */
itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
-
- // void Update() { GenerateOutputInformation(); GenerateData(); }
protected:
CropLikeImageFilter();
bool m_LikeFilenameIsGiven;
PointType m_Origin;
const itk::ImageBase<ImageDimension> * m_LikeImage;
- //typename ImageType::Pointer m_LikeImage;
std::vector<bool> m_CropAlongThisDimension;
PointType m_StartPoint; // start point in physical world
template <class ImageType>
void
clitk::CropLikeImageFilter<ImageType>::
-GenerateOutputInformation() {
- DD("GenerateOutputInformation");
+GenerateOutputInformation() {
// Get input pointers
ImageConstPointer input = dynamic_cast<const ImageType*>(itk::ProcessObject::GetInput(0));
for(unsigned int i=0; i<ImageType::ImageDimension; i++) {
if (likeSpacing[i] != input->GetSpacing()[i]) {
clitkExceptionMacro("Images must have the same spacing, but input's spacing(" << i
- <<") is " << input->GetSpacing()[i] << " while like's spacing(" << i
- << ") is " << likeSpacing[i] << ".");
+ <<") is " << input->GetSpacing()[i] << " while the spacing(" << i
+ << ") of 'like' is " << likeSpacing[i] << ".");
}
}
// Define output region
output->SetBufferedRegion(m_OutputRegion);
output->SetSpacing(likeSpacing);
output->SetOrigin(likeOrigin);
+ output->Allocate(); // Needed ?
// get startpoint source/dest
// for each dim
for(int i=0; i<ImageType::ImageDimension; i++)
s[i] = m_StopSourceIndex[i]-m_StartSourceIndex[i];
m_Region.SetSize(s);
+
}
//--------------------------------------------------------------------
// Get output pointer, fill with Background
ImagePointer output = this->GetOutput(0);
- output->Allocate();
+
output->FillBuffer(GetBackgroundValue());
// Paste image inside
typedef itk::PasteImageFilter<ImageType,ImageType> PasteFilterType;
typename PasteFilterType::Pointer pasteFilter = PasteFilterType::New();
+ //pasteFilter->ReleaseDataFlagOn(); // change nothing ?
+ // pasteFilter->InPlaceOn(); // makt it seg fault
pasteFilter->SetSourceImage(input);
pasteFilter->SetDestinationImage(output);
pasteFilter->SetDestinationIndex(m_StartDestIndex);
pasteFilter->Update();
// Get (graft) output (SetNthOutput does not fit here because of Origin).
- // this->GraftOutput(cropFilter->GetOutput());
this->GraftOutput(pasteFilter->GetOutput());
}
//--------------------------------------------------------------------