Public Types | Public Member Functions | Protected Attributes

mitk::ImageDataItem Class Reference
[Data Classes]

Internal class for managing references on sub-images. More...

#include <mitkImageDataItem.h>

Collaboration diagram for mitk::ImageDataItem:
Collaboration graph
[legend]

List of all members.

Public Types

typedef ImageDataItem Self
typedef itk::LightObject Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
 ImageDataItem (const ImageDataItem &aParent, unsigned int dimension, void *data=NULL, bool manageMemory=false, vcl_size_t offset=0)
 ~ImageDataItem ()
 ImageDataItem (const mitk::PixelType &type, unsigned int dimension, unsigned int *dimensions, void *data, bool manageMemory)
void * GetData () const
bool IsComplete () const
void SetComplete (bool complete)
int GetOffset () const
PixelType GetPixelType () const
ImageDataItem::ConstPointer GetParent () const
mitkIpPicDescriptor * GetPicDescriptor () const
vtkImageData * GetVtkImageData () const
bool GetManageMemory () const
virtual void ConstructVtkImageData () const
unsigned long GetSize () const
virtual void Modified () const

Protected Attributes

unsigned char * m_Data
PixelType m_PixelType
bool m_ManageMemory
mitkIpPicDescriptor * m_PicDescriptor
vtkImageData * m_VtkImageData
int m_Offset
bool m_IsComplete
unsigned long m_Size

Detailed Description

Internal class for managing references on sub-images.

ImageDataItem is a container for image data which is used internal in mitk::Image to handle the communication between the different data types for images used in MITK (ipPicDescriptor, mitk::Image, vtkImageData). Common for these image data types is the actual image data, but they differ in representation of pixel type etc. The class is also used to convert ipPic images to vtkImageData.

The class is mainly used to extract sub-images inside of mitk::Image, like single slices etc. It should not be used outside of this.

Parameters:
manageMemoryDetermines if image data is removed while destruction of ImageDataItem or not.

Definition at line 43 of file mitkImageDataItem.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::ImageDataItem::ConstPointer

Definition at line 46 of file mitkImageDataItem.h.

typedef itk::SmartPointer<Self> mitk::ImageDataItem::Pointer

Definition at line 46 of file mitkImageDataItem.h.

Definition at line 46 of file mitkImageDataItem.h.

typedef itk::LightObject mitk::ImageDataItem::Superclass

Definition at line 46 of file mitkImageDataItem.h.


Constructor & Destructor Documentation

mitk::ImageDataItem::ImageDataItem ( const ImageDataItem aParent,
unsigned int  dimension,
void *  data = NULL,
bool  manageMemory = false,
vcl_size_t  offset = 0 
)

Definition at line 38 of file mitkImageDataItem.cpp.

References mitk::PixelType::GetBpe(), GetData(), GetPicDescriptor(), GetPixelType(), mitk::PixelType::GetType(), m_Data, m_PicDescriptor, m_PixelType, and m_Size.

                                                                                                                                   :
  m_Data(NULL), m_ManageMemory(false), m_PicDescriptor(NULL), m_VtkImageData(NULL), m_Offset(offset), m_IsComplete(false), m_Size(0),
  m_Parent(&aParent)
{
  m_PixelType = aParent.GetPixelType();
  m_PicDescriptor=mitkIpPicNew();
  m_PicDescriptor->bpe=m_PixelType.GetBpe();
  m_PicDescriptor->type=m_PixelType.GetType();
  m_PicDescriptor->dim=dimension;
  memcpy(m_PicDescriptor->n, aParent.GetPicDescriptor()->n, sizeof(mitkIpUInt4_t)*_mitkIpPicNDIM);
  m_PicDescriptor->data=m_Data=static_cast<unsigned char*>(aParent.GetData())+offset;
  mitkIpFuncCopyTags(m_PicDescriptor, aParent.GetPicDescriptor());

  m_Size = _mitkIpPicSize(m_PicDescriptor);
  if(data != NULL)
  {
    memcpy(m_Data, data, m_Size);
    if(manageMemory)
    {
      delete [] (unsigned char*) data;
    }
  }

  m_ReferenceCountLock.Lock();
  m_ReferenceCount = 0;
  m_ReferenceCountLock.Unlock();
}
mitk::ImageDataItem::~ImageDataItem (  )

Definition at line 66 of file mitkImageDataItem.cpp.

{
  if(m_VtkImageData!=NULL)
    m_VtkImageData->Delete();
  if(m_PicDescriptor!=NULL)
  {
    m_PicDescriptor->data=NULL;
    mitkIpPicFree(m_PicDescriptor);
  }
  if(m_Parent.IsNull())
  {
    if(m_ManageMemory)
      delete [] m_Data;
  }
}
mitk::ImageDataItem::ImageDataItem ( const mitk::PixelType type,
unsigned int  dimension,
unsigned int *  dimensions,
void *  data,
bool  manageMemory 
)

Definition at line 82 of file mitkImageDataItem.cpp.

References mitk::PixelType::GetBpe(), mitk::PixelType::GetType(), m_Data, m_ManageMemory, m_PicDescriptor, m_PixelType, and m_Size.

                                                                                                                                           :
  m_Data((unsigned char*)data), m_ManageMemory(manageMemory), m_PicDescriptor(NULL), m_VtkImageData(NULL), m_Offset(0), m_IsComplete(false), m_Size(0),
  m_Parent(NULL)
{
  //const std::type_info & typeId=*type.GetTypeId();
  m_PixelType = type;
  m_PicDescriptor=mitkIpPicNew();
  m_PicDescriptor->bpe=m_PixelType.GetBpe();
  m_PicDescriptor->type=m_PixelType.GetType();
  m_PicDescriptor->dim=dimension;
  memcpy(m_PicDescriptor->n, dimensions, sizeof(mitkIpUInt4_t)*(dimension<=_mitkIpPicNDIM?dimension:_mitkIpPicNDIM));
  unsigned char i;
  for(i=dimension; i < _mitkIpPicNDIM; ++i)
    m_PicDescriptor->n[i] = 1;
  m_Size = _mitkIpPicSize(m_PicDescriptor);
  if(m_Data == NULL)
  {
    m_Data = mitk::MemoryUtilities::AllocateElements<unsigned char>( m_Size );
    m_ManageMemory = true;
  }
  m_PicDescriptor->data=m_Data;

  m_ReferenceCountLock.Lock();
  m_ReferenceCount = 0;
  m_ReferenceCountLock.Unlock();
}

Member Function Documentation

void mitk::ImageDataItem::ConstructVtkImageData (  ) const [virtual]

Definition at line 109 of file mitkImageDataItem.cpp.

{
  vtkImageData *inData = vtkImageData::New();
  vtkDataArray *scalars = NULL;

  unsigned long size = 0;
  if ( m_PicDescriptor->dim == 1 )
  {
    inData->SetDimensions( m_PicDescriptor->n[0] -1, 1, 1);
    size = m_PicDescriptor->n[0];
    inData->SetOrigin( ((float) m_PicDescriptor->n[0]) / 2.0f, 0, 0 );
  }
  else
  if ( m_PicDescriptor->dim == 2 )
  {
    inData->SetDimensions( m_PicDescriptor->n[0] , m_PicDescriptor->n[1] , 1 );
    size = m_PicDescriptor->n[0] * m_PicDescriptor->n[1];
    inData->SetOrigin( ((float) m_PicDescriptor->n[0]) / 2.0f, ((float) m_PicDescriptor->n[1]) / 2.0f, 0 );
  }
  else
  if ( m_PicDescriptor->dim >= 3 )
  {
    inData->SetDimensions( m_PicDescriptor->n[0], m_PicDescriptor->n[1], m_PicDescriptor->n[2] );
    size = m_PicDescriptor->n[0] * m_PicDescriptor->n[1] * m_PicDescriptor->n[2];
    // Test
    //inData->SetOrigin( (float) m_PicDescriptor->n[0] / 2.0f, (float) m_PicDescriptor->n[1] / 2.0f, (float) m_PicDescriptor->n[2] / 2.0f );
    inData->SetOrigin( 0, 0, 0 );
  }
  else
  {
    inData->Delete () ;
    return;
  }

  inData->SetNumberOfScalarComponents(m_PixelType.GetNumberOfComponents());

  if ( ( m_PixelType.GetType() == mitkIpPicInt || m_PixelType.GetType() == mitkIpPicUInt ) && m_PixelType.GetBitsPerComponent() == 1 )
  {
    inData->SetScalarType( VTK_BIT );
    scalars = vtkBitArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicInt && m_PixelType.GetBitsPerComponent() == 8 )
  {
    inData->SetScalarType( VTK_CHAR );
    scalars = vtkCharArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicUInt && m_PixelType.GetBitsPerComponent() == 8 )
  {
    inData->SetScalarType( VTK_UNSIGNED_CHAR );
    scalars = vtkUnsignedCharArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicInt && m_PixelType.GetBitsPerComponent() == 16 )
  {
    inData->SetScalarType( VTK_SHORT );
    scalars = vtkShortArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicUInt && m_PixelType.GetBitsPerComponent() == 16 )
  {
    inData->SetScalarType( VTK_UNSIGNED_SHORT );
    scalars = vtkUnsignedShortArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicInt && m_PixelType.GetBitsPerComponent() == 32 )
  {
    inData->SetScalarType( VTK_INT );
    scalars = vtkIntArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicUInt && m_PixelType.GetBitsPerComponent() == 32 )
  {
    inData->SetScalarType( VTK_UNSIGNED_INT );
    scalars = vtkUnsignedIntArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicInt && m_PixelType.GetBitsPerComponent() == 64 )
  {
    inData->SetScalarType( VTK_LONG );
    scalars = vtkLongArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicUInt && m_PixelType.GetBitsPerComponent() == 64 )
  {
    inData->SetScalarType( VTK_UNSIGNED_LONG );
    scalars = vtkUnsignedLongArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicFloat && m_PixelType.GetBitsPerComponent() == 32 )
  {
    inData->SetScalarType( VTK_FLOAT );
    scalars = vtkFloatArray::New();
  }
  else if ( m_PixelType.GetType() == mitkIpPicFloat && m_PixelType.GetBitsPerComponent() == 64 )
  {
    inData->SetScalarType( VTK_DOUBLE );
    scalars = vtkDoubleArray::New();
  }
  else
  {
    inData->Delete();
    return;
  }

  m_VtkImageData = inData;

  // allocate the new scalars
  scalars->SetNumberOfComponents(m_VtkImageData->GetNumberOfScalarComponents());

  scalars->SetVoidArray(m_PicDescriptor->data, _mitkIpPicElements(m_PicDescriptor)*m_VtkImageData->GetNumberOfScalarComponents(), 1);

  m_VtkImageData->GetPointData()->SetScalars(scalars);
  scalars->Delete();

}
virtual const char* mitk::ImageDataItem::GetClassName (  ) const [virtual]
void* mitk::ImageDataItem::GetData (  ) const [inline]

Definition at line 54 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

    {
      return m_Data;
    }
bool mitk::ImageDataItem::GetManageMemory (  ) const [inline]

Definition at line 97 of file mitkImageDataItem.h.

    {
      return m_ManageMemory;
    }
int mitk::ImageDataItem::GetOffset (  ) const [inline]

Definition at line 68 of file mitkImageDataItem.h.

    {
      return m_Offset;
    }
ImageDataItem::ConstPointer mitk::ImageDataItem::GetParent (  ) const [inline]

Definition at line 78 of file mitkImageDataItem.h.

    {
      return m_Parent;
    }
mitkIpPicDescriptor* mitk::ImageDataItem::GetPicDescriptor (  ) const [inline]

Definition at line 83 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

    {
      return m_PicDescriptor;
    }
PixelType mitk::ImageDataItem::GetPixelType (  ) const [inline]

Definition at line 73 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

    {
      return m_PixelType;    
    }
unsigned long mitk::ImageDataItem::GetSize (  ) const [inline]

Definition at line 104 of file mitkImageDataItem.h.

    {
      return m_Size;
    }
vtkImageData* mitk::ImageDataItem::GetVtkImageData (  ) const [inline]

Definition at line 89 of file mitkImageDataItem.h.

bool mitk::ImageDataItem::IsComplete (  ) const [inline]

Definition at line 59 of file mitkImageDataItem.h.

    {
      return m_IsComplete;
    }
void mitk::ImageDataItem::Modified (  ) const [virtual]

Definition at line 218 of file mitkImageDataItem.cpp.

{
  if(m_VtkImageData)
    m_VtkImageData->Modified();
}
void mitk::ImageDataItem::SetComplete ( bool  complete ) [inline]

Definition at line 63 of file mitkImageDataItem.h.

Referenced by mitk::Image::GetChannelData(), and mitk::Image::GetVolumeData().

    {
      m_IsComplete = complete;
    }

Member Data Documentation

unsigned char* mitk::ImageDataItem::m_Data [protected]

Definition at line 112 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

Definition at line 122 of file mitkImageDataItem.h.

Definition at line 116 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

Definition at line 120 of file mitkImageDataItem.h.

mitkIpPicDescriptor* mitk::ImageDataItem::m_PicDescriptor [protected]

Definition at line 118 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

Definition at line 114 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

unsigned long mitk::ImageDataItem::m_Size [protected]

Definition at line 124 of file mitkImageDataItem.h.

Referenced by ImageDataItem().

vtkImageData* mitk::ImageDataItem::m_VtkImageData [mutable, protected]

Definition at line 119 of file mitkImageDataItem.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines