static SoXipDataImage *
createXipImageSingle(SoItkDataImage * xipItkImage, SbXipImage::DataType typeFlag,
		     int bitsPerComp, SbXipImage::ComponentLayoutType compLayout)
{
    typedef typename itk::Image<Type, nDims> ImageType;
    ImageType * itkImage = reinterpret_cast<ImageType *>(xipItkImage->getPointer());

    typename ImageType::RegionType region = itkImage->GetBufferedRegion();

    SbXipImageDimensions dimensions(1, 1, 1);

    for (unsigned int i = 0; i < nDims; ++ i)
    {
	dimensions[i] = region.GetSize()[i];
    }

    SbXipImage* image =
	new SbXipImage(dimensions, typeFlag, bitsPerComp,
		       itkImage->GetBufferPointer(), nComps,
		       SbXipImage::INTERLEAVED, compLayout,
		       xipItkImage->getModelMatrix());

    if (!image) return 0;

    SoXipDataImage * xipImage = new SoXipDataImage;
    xipImage->ref();
    xipImage->addRef(xipItkImage);
    xipImage->set(image);

    return xipImage;
}
Ejemplo n.º 2
0
void
NrrdPlugin::readSlice(int idx[3], int sz[3],
		       int nbytes, uchar *slice)
{
  typedef itk::Image<T, 3> ImageType;

  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(m_fileName[0].toAscii().data());
  typedef itk::NrrdImageIO NrrdIOType;
  NrrdIOType::Pointer nrrdIO = NrrdIOType::New();
  reader->SetImageIO(nrrdIO);

  typedef itk::RegionOfInterestImageFilter<ImageType,ImageType> RegionExtractor;

  ImageType::RegionType region;
  ImageType::SizeType size;
  ImageType::IndexType index;
  index[2] = idx[2];
  index[1] = idx[1];
  index[0] = idx[0];
  size[2] = sz[2];
  size[1] = sz[1];
  size[0] = sz[0];
  region.SetIndex(index);
  region.SetSize(size);
  
  // Extract the relevant sub-region.
  RegionExtractor::Pointer extractor = RegionExtractor::New();
  extractor->SetInput(reader->GetOutput());
  extractor->SetRegionOfInterest(region);
  extractor->Update();
  ImageType *dimg = extractor->GetOutput();
  char *tdata = (char*)(dimg->GetBufferPointer());
  memcpy(slice, tdata, nbytes);
}