[vtkusers] SetScalarType refactor

Berk Geveci berk.geveci at kitware.com
Thu Apr 4 10:04:05 EDT 2013


I am not very familiar with reslice filters but a quick look at your code
tells me that it may be wrong to replace reslice->SetInput() with
reslice->SetInformationInput(). Those are not same inputs. Did you try
SetInputData() instead? By the way, did you look at the migration guide?

http://www.vtk.org/Wiki/VTK/VTK_6_Migration_Guide

Best,
-berk


On Wed, Apr 3, 2013 at 4:15 PM, Boxer, Aaron <Aaron.Boxer at uhn.ca> wrote:

>  Thanks, Bill. ****
>
> ** **
>
> The situation is a bit complicated, because the old code was actually C#
> code, using the ActiViz wrapper.****
>
> ** **
>
> Also, unlike the usual examples, I am not reading data in from disk, but
> passing it  from memory.****
>
> ** **
>
> I’ve done some modifications since my first post; below  is what I have
> come up with so far.****
>
> ** **
>
> This code crashes on rendering with memory access violation.****
>
> ** **
>
> One change I made is that I had to remove the UpdateInformation call on
> the vtkImageData object, because it****
>
> no longer exists.  ****
>
> ** **
>
> Aaron****
>
> ** **
>
> ** **
>
> ** **
>
>        ////////////////////////////////////****
>
>     //create VTK volume****
>
>     _vtkVolume = vtkImageData::New();****
>
> ** **
>
>     _vtkVolume->SetDimensions(dim[0],dim[1],dim[2]);****
>
>     _vtkVolume->SetOrigin(origin[0],origin[1],origin[2]);****
>
>     _vtkVolume->SetSpacing(spacing[0],spacing[1],spacing[2]);****
>
> ** **
>
>               vtkSmartPointer<vtkShortArray> dataArray =
> vtkShortArray::New();****
>
>               dataArray->SetArray((short *)data, size, 1);****
>
>         _vtkVolume->GetPointData()->SetScalars(dataArray);****
>
>    ****
>
> ** **
>
>     // This call is necessary to ensure vtkImageData data's info is
> correct (e->g-> updates WholeExtent values)****
>
>    // _vtkVolume->UpdateInformation();****
>
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////
> ****
>
>       ****
>
> ** **
>
>     //////////////////////////////////////////////****
>
>     // create vtk image reslice object****
>
>      reslice = vtkImageSlabReslice::New();****
>
>                      ****
>
>        //VtkHelper->RegisterVtkErrorEvents(_reslicer);****
>
> ** **
>
>    // reslice->SetInput(_vtkVolume);****
>
>     reslice->SetInformationInput(_vtkVolume);****
>
> ** **
>
>        // Must instruct reslicer to output 2D images****
>
>        reslice->SetOutputDimensionality(2);****
>
> ** **
>
>        // Use the volume's padding value for all pixels that are outside
> the volume****
>
>        reslice->SetBackgroundLevel(paddingValue);****
>
> ** **
>
>        // This ensures VTK obeys the real spacing, results in all VTK
> slices being isotropic->****
>
>        //     Effective spacing is the minimum of these three->****
>
>        reslice->SetOutputSpacing(spacing[0],spacing[1],spacing[2]);****
>
> ** **
>
> ** **
>
> ** **
>
> *From:* Bill Lorensen [mailto:bill.lorensen at gmail.com]
> *Sent:* Wednesday, April 03, 2013 3:56 PM
> *To:* Boxer, Aaron
> *Cc:* vtkusers at vtk.org
> *Subject:* Re: [vtkusers] SetScalarType refactor****
>
> ** **
>
> Aaron,
>
> What did you code look like ijn VTK5.x?****
>
> This is how you would typically do things in VTK6:
> vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
>  image->SetDimensions(10, 10, 10);
>
> #if VTK_MAJOR_VERSION <= 5
>   image->SetNumberOfScalarComponents(1);
>   image->SetScalarTypeToUnsignedChar();
>   image->AllocateScalars();
> #else
>   image->AllocateScalars(VTK_UNSIGNED_CHAR,1);
> #endif****
>
> ** **
>
> ** **
>
> On Wed, Apr 3, 2013 at 3:08 PM, Boxer, Aaron <Aaron.Boxer at uhn.ca> wrote:**
> **
>
> Hello,****
>
> I am porting some code to the master branch.****
>
>  ****
>
> I am passing an existing data set into vtk for rendering.****
>
>  ****
>
> Since my data set could be either unsigned short or simply short, ****
>
> the code used to call SetScalarType on the vtkImageData object.****
>
>  ****
>
> I see that this has been removed.****
>
>  ****
>
> My question:  will the following code work, or do I need to worry about***
> *
>
> data types:****
>
>  ****
>
>    _vtkVolume = vtkImageData::New();****
>
>  ****
>
>     _vtkVolume->SetDimensions(volume->ArrayDimensions->Width,
> volume->ArrayDimensions->Height, volume->ArrayDimensions->Depth);****
>
>     _vtkVolume->SetOrigin(volume->Origin->X, volume->Origin->Y,
> volume->Origin->Z);****
>
>     _vtkVolume->SetSpacing(volume->VoxelSpacing->X,
> volume->VoxelSpacing->Y, volume->VoxelSpacing->Z);****
>
>  ****
>
>     if (!volume->IsSigned())****
>
>     {****
>
>             vtkSmartPointer<vtkUnsignedShortArray> dataArray =
> vtkUnsignedShortArray::New();****
>
>             dataArray->SetArray(volume->PinnedAddress,
> volume->VolumeDataUInt16->Length, 1);****
>
>              _vtkVolume->GetPointData()->SetScalars(dataArray);****
>
>     }****
>
>     else****
>
>     {****
>
>             vtkSmartPointer<vtkShortArray> dataArray =
> vtkShortArray::New();****
>
>             dataArray->SetArray(volume->PinnedAddress,
> volume->VolumeDataInt16->Length, 1);****
>
>            _vtkVolume->GetPointData()->SetScalars(dataArray);****
>
>     }****
>
>  ****
>
>     // This call is necessary to ensure vtkImageData data's info is
> correct (e->g-> updates WholeExtent values)****
>
>     _vtkVolume->UpdateInformation();****
>
>  ****
>
>  ****
>
>  ****
>
>  ****
>
> Thanks!****
>
>  ****
>
> Aaron****
>
>  ****
>
>
> This e-mail may contain confidential and/or privileged information for the
> sole use of the intended recipient.
> Any review or distribution by anyone other than the person for whom it was
> originally intended is strictly prohibited.
> If you have received this e-mail in error, please contact the sender and
> delete all copies.
> Opinions, conclusions or other information contained in this e-mail may
> not be that of the organization.****
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers****
>
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com****
>
> This e-mail may contain confidential and/or privileged information for the
> sole use of the intended recipient.
> Any review or distribution by anyone other than the person for whom it was
> originally intended is strictly prohibited.
> If you have received this e-mail in error, please contact the sender and
> delete all copies.
> Opinions, conclusions or other information contained in this e-mail may
> not be that of the organization.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130404/666c61ba/attachment.htm>


More information about the vtkusers mailing list