[vtkusers] vtk class error

Jothy jothybasu at gmail.com
Fri Oct 8 06:20:20 EDT 2010


Excellent!

vtkSmartPointer<vtkImageData> imageData; is working.

Thank you

Jothy

On Fri, Oct 8, 2010 at 3:25 AM, David Doria <daviddoria at gmail.com> wrote:

> On Thu, Oct 7, 2010 at 4:42 PM, Jothy <jothybasu at gmail.com> wrote:
>
>> Hi Guys,
>>
>> I am trying to create a c++ class to read a dicom image set. But,my app is
>> crashing with out any errors during building.
>>
>> here is the header and source of that class, I am using Qt creator.
>>
>> Header:
>>
>> #ifndef MYDCMIMPORTER_H
>>
>> #define MYDCMIMPORTER_H
>>
>> #include<vtkImageData.h>
>>
>> #include<QString>
>>
>> class myDcmImporter
>>
>> {
>>
>> public:
>>
>>     myDcmImporter();
>>
>>     vtkImageData* imageData;
>>
>>     vtkImageData* readImage();
>>
>> };
>>
>> #endif // MYDCMIMPORTER_H
>>
>>
>> Source:
>> #include "mydcmimporter.h"
>>
>> #include<QFileDialog>
>>
>> #include<QString>
>>
>> #include<vtkDICOMImageReader.h>
>>
>> #include<vtkSmartPointer.h>
>>
>> #include<QDebug>
>>
>> myDcmImporter::myDcmImporter()
>>
>> {
>>
>> }
>>
>> vtkImageData* myDcmImporter::readImage()
>>
>> {
>>
>>     QString imageDirName=QFileDialog::getExistingDirectory();
>>
>>     vtkSmartPointer <vtkDICOMImageReader> reader=
>>
>>             vtkSmartPointer<vtkDICOMImageReader>::New();
>>
>>     reader->SetDirectoryName(imageDirName.toLatin1());
>>
>>     reader->Update();
>>
>>     this->imageData= reader->GetOutput();
>>
>> }
>>
>>
>> App crashes only while executing
>>
>> myDcmImporter dcmImporter;
>>
>>     dcmImporter.readImage();
>>
>> //    vtkImageData *img=dcmImporter.imageData;
>>
>>     int dims[3];
>>
>>     dcmImporter.imageData->GetDimensions(dims);
>>
>> //    dcmImporter.imageData->GetDimensions(dims);
>>
>>     qDebug()<<dims[0]<<"running...";
>>
>>
>> Since I am new to c++, could be a silly mistake somewhere.
>>
>> Thank you
>>
>> Jothy
>>
>>
> This function is supposed to return a vtkImageData*, but there is no
> 'return' statement!
>
> vtkImageData* myDcmImporter::readImage()
> {
>     QString imageDirName=QFileDialog::getExistingDirectory();
>     vtkSmartPointer <vtkDICOMImageReader> reader=
>             vtkSmartPointer<vtkDICOMImageReader>::New();
>     reader->SetDirectoryName(imageDirName.toLatin1());
>     reader->Update();
>     this->imageData= reader->GetOutput();
> }
>
> However, I don't think this is the problem because you call the function
> without asking for its return value anyway.
>
> What may be happening is that the reader smart pointer is going out of
> scope. I think you could fix this in two ways
>
> 1) Change the member
> vtkImageData* imageData;
> to
> vtkSmartPointer<vtkImageData> imageData;
>
> I'm not sure, but that might make the reader pointer hang around longer.
>
> 2) (this will definitely work)
> Create the imageData object in the constructor:
>
> myDcmImporter::myDcmImporter()
>
> {
>
>   this->imageData = vtkImageData::New();
>
> }
>
>
> Then instead of assigning the pointer:
>
>
>     this->imageData= reader->GetOutput();
>
>
> actually copy the output of the filter:
>
>     this->imageData->ShallowCopy(reader->GetOutput());
>
>
> Give those a shot and let us know if you have any luck.
>
>
> David
>



-- 
Research Scholar
Dept. of Medical Physics
Clatterbridge Centre for Oncology
UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101008/910850ed/attachment.htm>


More information about the vtkusers mailing list