Appleseed: Move Frame::write() and Frame::archive() to separate classes

Created on 17 Oct 2011  路  10Comments  路  Source: appleseedhq/appleseed

For instance renderer::FrameWriter and renderer::FrameArchiver.

Refactoring Good First Issue

All 10 comments

I'll work on this one

Why would you need to do that? What would be the intent of this two classes? I'm just curious.

Andr茅: excellent!

Dorian: It's just a refactoring. The image writing code adds lots of clutter to the implementation of the renderer::Frame entity.

Ok thanks! :)

did anyone start to work on this? can i give it a shot?

Well it seems like Andr茅 is already on it. Andr茅, still working on this?

Yes, sorry I've been busy during the weekend but I'll do it!

Could you provide a shell class for this? I'm having trouble understanding some parts of the code and I can't find documentation about it. What does this do:

namespace
{
    const UniqueID g_class_uid = new_guid();
}

UniqueID Frame::get_class_uid()
{
    return g_class_uid;
}

If I get this correctly I would move this function:

bool Frame::archive(
    const char*         directory,
    char**              output_path) const
{
    assert(directory);

    // Construct the name of the image file.
    const string filename =
        "autosave." + get_time_stamp_string() + ".exr";

    // Construct the path to the image file.
    const string file_path = (filesystem::path(directory) / filename).string();

    // Return the path to the image file.
    if (output_path)
        *output_path = duplicate_string(file_path.c_str());

    Image transformed_image(*impl->m_image);
    transform_to_output_color_space(transformed_image);

    return
        write_image(
            file_path.c_str(),
            transformed_image,
            ImageAttributes::create_default_attributes());
}

into a FrameWriter class. I'm just not sure how to start writing the class, should it look something like this:

//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.

//includes

//using namespaces

namespace renderer
{

FrameArchiver::archive(...)
{
//code from Frame::archive
}

}   // namespace renderer

Thanks, I just need some kickstart to start programming.

Yes, that's basically it. You'll need to create two new pairs of files (framewriter.{h,cpp} and framearchiver.{h,cpp}), or maybe just one pair (framewriter.{h,cpp}) if you think this is sufficient, add them to the CMakeLists.txt file, and move the code over to these new files.

Now:

namespace
{
    const UniqueID g_class_uid = new_guid();
}

This creates a new unique ID local to this file. This ID will be used to uniquely identify the "Frame" entity class. The class ID corresponding to the "Frame" class can be accessed via the following static method:

UniqueID Frame::get_class_uid()
{
    return g_class_uid;
}

Your FrameWriter class is not an entity class, just a plain class so you don't need any of this.

This issue is available again.

Was this page helpful?
0 / 5 - 0 ratings