[vtk-developers] vtkVoxelModeller converted from BIT to INT

David Doria daviddoria+vtk at gmail.com
Mon Mar 15 13:20:41 EDT 2010


On Mon, Mar 15, 2010 at 11:17 AM, Will Schroeder <will.schroeder at kitware.com
> wrote:

> Hi David-
>
> I think we have to approach this in a series of steps, we may not be able
> to correctly solve the VTK_BIT problem immediately, but do something quick
> with an eye to fixing it longer term.
>
> One option: since the writer doesn't work now let's do something quickly,
> documenting the fact (e.g. bug tracker, etc.) that long term we need to
> improve the support for VTK_BIT. (I would use VTK_UNSIGNED_CHAR myself which
> is half the size of VTK_SHORT assuming it works.)
>
> Another option (and I am shooting from the hip here) is to do the minimal
> work in the reader/writer to get VTK_BIT "sort of" working meaning you may
> have to perform temporary conversions to and from VTK_BIT to another type,
> etc. which may cause temporary increases in memory.
>
> I'm sure there are other opinions in the community about this...
>
> Will
>

I tested vtkVoxelModeller using VTK_UNSIGNED_CHAR and it worked fine. I
added the file to the bug report:
http://public.kitware.com/Bug/view.php?id=10414

I dug through the writer code for a while.

In vtkXMLWriter.cxx I changed:

vtkXMLWriter::OffsetType vtkXMLWriter::GetWordTypeSize(int dataType)
{
  OffsetType size = 1;
  switch (dataType)
    {
    vtkTemplateMacro(
      size = vtkXMLWriterGetWordTypeSize(static_cast<VTK_TT*>(0))
      );
  case VTK_STRING:
    return sizeof(vtkStdString::value_type);
  //case VTK_BIT: //doesn't work for some reason
  case 1: // VTK_BIT == 1
    return sizeof(bool);
  default:
      { vtkWarningMacro("Unsupported data type: " << dataType); } break;
    }
  return size;
}

in vtkXMLDataElement.cxx I changed:

int vtkXMLDataElement::GetWordTypeAttribute(const char* name, int& value)
{
  // These string values must match vtkXMLWriter::GetWordTypeName().
  const char* v = this->GetAttribute(name);
  if(!v)
    {
    vtkErrorMacro("Missing word type attribute \"" << name << "\".");
    return 0;
    }
  else if(strcmp(v, "Bit") == 0)
    {
    value = VTK_BIT;
    return 1;
    }

It seems to write the file without a problem now. However, when I try to
read it, in vtkXMLDataReader.cxx

template <class iterT>
int vtkXMLDataReaderReadArrayValues(vtkXMLDataElement* da,
  vtkXMLDataParser* xmlparser, vtkIdType arrayIndex,
  iterT* iter, vtkIdType startIndex, vtkIdType numValues)
{
  if (!iter)
    {
    return 0;
    }
  vtkAbstractArray* array = iter->GetArray();

'array' is null so then the code crashes. Maybe this could be a starting
point for the next brave person?

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100315/ef85917d/attachment.html>


More information about the vtk-developers mailing list