Difference between revisions of "VTK/VTK 6 Migration/Changes to Scalars Manipulation Functions"

From KitwarePublic
< VTK
Jump to navigationJump to search
(Created page with "= Changes to Scalars Manipulation Functions in vtkImageData = VTK 6 introduces a number of backwards-incompatible changes. The reasons behind these changes are described in more...")
 
 
Line 1: Line 1:
 
= Changes to Scalars Manipulation Functions in vtkImageData =
 
= Changes to Scalars Manipulation Functions in vtkImageData =
  
VTK 6 introduces a number of backwards-incompatible changes. The reasons behind these changes are described in more detail [here].  Among these are changes to several vtkImageData methods that were used to facilitate meta-data management and memory allocation using pipeline meta-data. Since vtkImageData no longer has direct access to the pipeline information (see this wiki document), these methods were changed to behave differently or to accept additional arguments for dealing with meta-data. These methods are as follows.
+
VTK 6 introduces a number of backwards-incompatible changes. The reasons behind these changes are described in more detail [[VTK/VTK 6 Migration/Overview | here]].  Among these are changes to several vtkImageData methods that were used to facilitate meta-data management and memory allocation using pipeline meta-data. Since vtkImageData no longer has direct access to the pipeline information (see this wiki document), these methods were changed to behave differently or to accept additional arguments for dealing with meta-data. These methods are as follows.
 
* GetScalarTypeMin()
 
* GetScalarTypeMin()
 
*GetScalarTypeMax()
 
*GetScalarTypeMax()

Latest revision as of 14:24, 6 April 2012

Changes to Scalars Manipulation Functions in vtkImageData

VTK 6 introduces a number of backwards-incompatible changes. The reasons behind these changes are described in more detail here. Among these are changes to several vtkImageData methods that were used to facilitate meta-data management and memory allocation using pipeline meta-data. Since vtkImageData no longer has direct access to the pipeline information (see this wiki document), these methods were changed to behave differently or to accept additional arguments for dealing with meta-data. These methods are as follows.

  • GetScalarTypeMin()
  • GetScalarTypeMax()
  • GetScalarType()
  • SetScalarType(int scalar_type)
  • GetNumberOfScalarComponents()
  • SetNumberOfScalarComponents(int n)
  • AllocateScalars()

Note that these methods were all designed to work with pipeline meta-data (aka PipelineInformation). For example, SetScalarType() was implemented as follows:

void vtkImageData::SetScalarType(int type)
{
  this->GetProducerPort();
  if(vtkInformation* info = this->GetPipelineInformation())
    {
    vtkDataObject::SetPointDataActiveScalarInfo(info, type, -1);
    }
  else
    {
    vtkErrorMacro("SetScalarType called with no "
                  "executive producing this image data object.");
    }
}

Since data objects can no longer be used to manipulate meta-data directly, these methods were changed. Specific changes are as follows.

GetNumberOfScalarComponents(), GetScalarType(), GetScalarTypeMin() and GetScalarTypeMax()

These methods were changed to return the number of scalar components, the scalar type or the min/max value for that scalar type of the actual vtkImageData. Therefore, they will no longer return the correct value if called before the scalars are allocated (in RequestInformation for example). If you need to access the scalar type before RequestData, you can still do it by passing the pipeline information to GetScalarType().

Example 1

Replace

int vtkMyAlg::RequestInformation(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
   vtkImageData* output = this->GetOutput();
   output->GetScalarType();
   output->GetNumberOfScalarComponents();

with

int vtkMyAlg::RequestInformation(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
    vtkInformation* outInfo = outInfoVec->GetInformationObject(0);
    vtkImageData::GetScalarType(outInfo);
    vtkImageData::GetNumberOfScalarComponents(outInfo);

Example 2

int vtkMyAlg::RequestData(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
vtkImageData* output = vtkImageData::GetData(outInfoVec);
// Allocate output scalars here
output->GetScalarType();
output->GetNumberOfScalarComponents();

This code does not need to be changed.

SetScalarType() and SetNumberOfScalarComponents()

SetScalarType() and SetNumberOfScalarComponets() were previously used to populate pipeline information with scalar meta-data. In VTK 6, SetPointDataActiveScalarInfo() can be used to perform the same task.

Example 1

Replace

int vtkMyAlg::RequestInformation(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
   vtkImageData* output = this->GetOutput();
   output->SetScalarType(VTK_UNSIGNED_CHAR);
   output->SetNumberOfScalarComponents(3);
   return 1;
}

with

int vtkMyAlg::RequestInformation(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
   vtkInformation* outInfo = outInfoVec->GetInformationObject(0);
   vtkDataObject::SetPointDataActiveScalarInfo(
       outInfo, VTK_UNSIGNED_CHAR, 3);
   return 1;
}

AllocateScalars()

Before VTK 6, AllocateScalars() was used in conjunction with SetScalarType() and SetNumberOfScalarComponents(). The latter two stored meta-data in the pipeline information and AllocateScalars() allocated data by using this meta-data. Since AllocateScalars() can no longer access the pipeline information, it needs to be told what scalar type and how many components to allocate.

Example 1

Replace

// set the extent of the image data first
imageData->SetScalarTypeToFloat();
imageData->SetNumberOfScalarComponents(3);
imageData->AllocateScalars();

with

// set the extent of the image data first
imageData->AllocateScalars(VTK_FLOAT, 3);

Example 2

Replace

int vtkMyAlg::RequestInformation(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
   vtkImageData* output = this->GetOutput();
   output->SetScalarType(VTK_UNSIGNED_CHAR);
   output->SetNumberOfScalarComponents(3);
   return 1;
}

int vtkMyAlg::RequestData(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
   vtkImageData* output = this->GetOutput();
   output->AllocateScalars();

with

int vtkMyAlg::RequestInformation(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
   vtkInformation* outInfo = outInfoVec->GetInformationObject(0);
   vtkDataObject::SetPointDataActiveScalarInfo(
       outInfo, VTK_UNSIGNED_CHAR, 3);
   return 1;
}

int vtkMyAlg::RequestData(vtkInformation*, vtkInformationVector**, 
       vtkInformationVector* outInfoVec)
{
   vtkInformation* outInfo = outInfoVec->GetInformationObject(0);
   vtkImageData* output = vtkImageData::GetData(outInfoVec);
   output->AllocateScalars(outInfo);