Cannot return copy (updated)

N

none

In the below code the call:

DisplayImage(job.GetImage());

just shows a black image even though it looks fine when its created.



int main() {

typedef MyImg MyImgType;
typedef Job<MyImgType> JobType;

MyImageApp<MyImgType> app;
JobType job;
app.Run(job);

// This only shows a black image!
DisplayImage(job.GetImage());
return 0;

}




// ============== MyImageApp ======================

template<typename F>
class MyImageApp {
public:


void Run(JobType & job) {

// The 'processor' instance will die when this function returns.
Processor<F> processor;
processor.Process();

// Not possble to copy the image from the processor into the job!?
job.SetImage(processor.GetProcessedImage());
}

};



// ============== Processor =======================

template <typename FI>
class Processor {
public:
typedef FI FixedImageType;
typedef itk::ResampleImageFilter< FixedImageType, FixedImageType > ResampleFilterType;

WarpProcessor ();
virtual ~WarpProcessor ();
void Process();

// Returning a copy not a reference!
typename FixedImageType::pointer GetProcessedImage(){return this->imageW;}

private:
typename FixedImageType::pointer imageW;

};

template <typename FI>
void
Processor<FI>::process() {
// Computing stuff

// ...

// Copying the result into the imageW instance
CopyImageToImage<typename FixedImageType::pointer, FixedImageType>(
resampler->GetOutput(),
imageW);

// image looks fine when viewed here!
DisplayImage(imageW)

}




// ================== Job =======================

template<typename F>
class Job {
public:
typedef F FixedImageType;

// Return copy!
typename FixedImageType::pointer GetImage() {return this->imageR;}
void SetImage(typename FixedImageType::pointer image) {this->imageR = image;}

private:
typename FixedImageType::pointer imageR;

};




Any ideas on why the image looks fine when calling:

DisplayImage(imageW)

in Processor::process() and pitch black when calling:

DisplayImage(job.GetImage());

in main?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top