Cannot return copy (updated)

Discussion in 'C++' started by none, May 11, 2010.

  1. none

    none Guest

    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?
     
    none, May 11, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ram
    Replies:
    2
    Views:
    7,227
    Paul Glavich [MVP ASP.NET]
    Jun 30, 2005
  2. Alex
    Replies:
    2
    Views:
    1,242
  3. Replies:
    26
    Views:
    2,128
    Roland Pibinger
    Sep 1, 2006
  4. Waldy
    Replies:
    4
    Views:
    499
    Waldy
    Aug 3, 2007
  5. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    420
    Dmitry Korolyov
    Sep 22, 2003
Loading...

Share This Page