I have a problem with an Access Violation Exception. I am using itk and read a File with it's file reader.
ThreeDImageFloatType* MyClass::loadImage(std::string filename){
const char* cfilename = filename.c_str();
fileReader = ImageFileReaderType::New();
fileReader->SetFileName(cfilename);
try{
fileReader->Update();
}catch( ... ) {
std::cerr << "failed to read file " << filename << std::endl;
}
CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput(fileReader->GetOutput());
castFilter->Update();
//ThreeDImageFloatType *t3dim = castFilter->GetOutput();
t3dim = castFilter->GetOutput();
return t3dim;
}
This is a function the class also contains 2 global variables:
ImageFileReaderType::Pointer fileReader;
ThreeDImageFloatType *t3dim;
Now if you call the the function in the class from for example my main method and try to access the return value, something like t3dim->GetLargestPossibleRegion().GetSize();
. I get an access violation error. It is important to notice if i don't outsource the code, and have it within the main method, it works like a charm. What could be the problem? How do i fix that?
[edit] I tried replacing the string filename with a const char* filename. The main method looks like this.
MyClass imIO;
const char* filename = "path to file";
ThreeDImageFloatType *t3dim = imIO.loadImage(filename);
t3dim->GetLargestPossibleRegion().GetSize();
Again if i put the code from the function completly in the main method it works.
[/edit]
[offtopic] maybe a moderator can tag it as itk, since it is an itk specific question? [/offtopic]