2015-10-23 32 views
0

我嘗試寫入選定的掩碼,但它不起作用。將數據寫入選定的掩碼

class IdMaskV1 : public Iop 
{ 
public: 

    IdMaskV1(Node* node) : Iop(node), 
     aaIndexFile(0) 
    { 
     mChannelSet = Mask_RGBA; 
    } 

    ~IdMaskV1() {} 

    //int maximum_inputs() const { return 1; } 
    //int minimum_inputs() const { return 1; } 

    virtual void knobs(Knob_Callback); 
    void _validate(bool); 
    void in_channels(int input_number, ChannelSet& channels) const; 
    void _request(int x, int y, int r, int t, ChannelMask channels, int count); 
    void engine(int y, int x, int r, ChannelMask channels, Row& outRow); 


    const char* Class() const { return CLASS; } 
    const char* node_help() const { return HELP; } 

private: 
    static const Iop::Description description; 
    static const char* const CLASS; 
    static const char* const HELP; 
    ChannelSet mChannelSet; 
}; 


static Iop* IdMaskV1Create(Node* node) 
{ 
    return new IdMaskV1(node); 
} 

const Iop::Description IdMaskV1::description(CLASS, "Examples/IdMaskV1", IdMaskV1Create); 
const char* const IdMaskV1::CLASS = "IdMaskV1"; 
const char* const IdMaskV1::HELP = "Example Plugin"; 

void IdMaskV1::_validate(bool for_real) 
{ 
    copy_info(); 
    set_out_channels(mChannelSet); 
    info_.turn_on(mChannelSet); 
} 

void IdMaskV1::in_channels(int input_number, ChannelSet& channels) const 
{ 
    /* 
    // Must turn on the other color channels if any color channels are requested: 
    foreach(z, channels) { 
     if (colourIndex(z) <= 3) { // it is red, green, or blue 
      if (!(mChannelSet & z)) { // save some time if we already turned this on 
       mChannelSet.addBrothers(z, 3); // add all three to the "done" set 
      } 
     } 
    }*/ 
    //channels += mChannelSet; // add the colors to the channels we need 
} 

void IdMaskV1::_request(int x, int y, int r, int t, ChannelMask channels, int count) 
{ 
    input(0)->request(x, y, r, t, ChannelMask(channels), count); 
} 


void IdMaskV1::engine(int y, int x, int r, ChannelMask channels, Row& outRow) 
{ 

    ChannelMask mask(channels); 

    if (aborted()) { 
     std::cerr << "Aborted!"; 
     return; 
    } 

    Row inputRow(x, r); 
    inputRow.get(input0(), y, x, r, mask); 

    foreach(channel, mask) { 
     Channel ch = brother(channel, colourIndex(channel)); 
     mChannelSet += ch; 
    } 

    for (int curX = x; curX < r; curX++) { 

     foreach(channel, mChannelSet) { 
      float value = 0; 

         // some process. In RGB i write 0.f, to A i write mask; 

      outRow.writable(channel)[curX] = value; 
     } 
    } 
} 


void IdMaskV1::knobs(Knob_Callback f) 
{ 
    ... 
    ChannelMask_knob(f, &mChannelSet, 1, "channels"); 
} 

對於我創建'other.test'的過程。在旋鈕中,我選擇了頻道rgba(或自定義:'測試')和自定義掩碼:'other.test'

我等待'other.test'的結果,但結果發現在rgba | rgba.alpha | A:\

更新

新的嘗試:

#include "DDImage/Iop.h" 
#include "DDImage/Row.h" 
#include "DDImage/Knobs.h" 
#include "DDImage/Tile.h" 

using namespace DD::Image; 
using namespace std; 

class IdMaskV1 : public Iop 
{ 
public: 

    IdMaskV1(Node* node) : Iop(node) 
    { 

    } 

    ~IdMaskV1() {} 

    virtual void knobs(Knob_Callback); 
    void _validate(bool); 
    void _request(int x, int y, int r, int t, ChannelMask channels, int count); 
    void engine(int y, int x, int r, ChannelMask channels, Row& outRow); 

    const char* Class() const { return CLASS; } 
    const char* node_help() const { return HELP; } 

private: 
    static const Iop::Description description; 
    static const char* const CLASS; 
    static const char* const HELP; 
    Channel mMaskChan; 
}; 


static Iop* IdMaskV1Create(Node* node) 
{ 
    return new IdMaskV1(node); 
} 

const Iop::Description IdMaskV1::description(CLASS, "Examples/IdMaskV1", IdMaskV1Create); 
const char* const IdMaskV1::CLASS = "IdMaskV1"; 
const char* const IdMaskV1::HELP = "Example Plugin"; 

void IdMaskV1::_validate(bool for_real) 
{ 
    copy_info(); 
    set_out_channels(mMaskChan); 
    info_.turn_on(mMaskChan); 
} 

void IdMaskV1::_request(int x, int y, int r, int t, ChannelMask channels, int count) 
{ 
    input(0)->request(x, y, r, t, channels, count); 
} 


void IdMaskV1::engine(int y, int x, int r, ChannelMask channels, Row& outRow) 
{ 
    if (aborted()) { 
     std::cerr << "Aborted!"; 
     return; 
    } 
    ChannelSet unchanged(channels); 

    if (unchanged & mMaskChan) { 
     unchanged -= mMaskChan; 

     static float value = 0.1678f; 

     float* out = outRow.writable(mMaskChan) + x; 
     const float* END = outRow[mMaskChan] + r; 
     while (out < END) 
      *out++ = value; 
    } 

    if (unchanged) 
     input0().get(y, x, r, unchanged, outRow); 
} 

void IdMaskV1::knobs(Knob_Callback f) 
{ 
    Channel_knob(f, &mMaskChan, 1, "channels"); 
} 

開不工作:\

屏幕從核彈: enter image description here

+0

在這種情況下,'mask'是一個位掩碼,指示您的'engine()'調用將被填充的通道,而不是掩碼圖像。我推薦閱讀更多關於Nuke的2D架構和可能的NukeWrapper插件類:https://www.thefoundry.co.uk/products/nuke/developers/90/ndkdevguide/2d/index.html – nrusch

+0

你已經選擇了'other.test'頻道作爲觀看者alpha通道,但您仍在查看RGB通道。如果您在查看器中點擊「A」,您應該看到測試頻道。 – nrusch

+0

@nrusch alpha是空的 –

回答

1

通常情況下,你可以使用一個ChannelSet_knob(或其中一個如果它的變化),如果你想執行相同的在用戶指定的所有通道上進行操作。但是,確定旋鈕ChannelSet中的給定通道是否實際上是在旋鈕上的遮罩下拉菜單中指定的通道會很棘手,因爲可以禁用其他通道中的某些通道。因此,如果您想要將特定數據寫入一個特定頻道,使用Channel_knob會更簡單,並且僅在內部呈現並在單個頻道上運行。

在這種情況下,一個engine()實現可能是這樣的:

void IdMaskV1::engine(int y, int x, int r, ChannelMask channels, Row& outRow) 
{ 
    ChannelSet unchanged(channels); 

    // mMaskChan is a `Channel`, and is the private knob storage for a `Channel_knob` 
    if (unchanged & mMaskChan) { 
     unchanged -= mMaskChan; 

     static float value = 0.1678f; // Whatever value or data you want 

     float* OUT = outRow.writable(mMaskChan) + x; 
     const float* END = outRow[mMaskChan] + r; 
     while (OUT < END) 
      *OUT++ = value; 
    } 

    if (unchanged) 
     input0().get(y, x, r, unchanged, outRow); 
} 

您還需要修改_validate方法來調用set_out_channelsinfo_.turn_onmMaskChan而不是mChannelSet

希望這會有所幫助。

+0

thx測試這個答覆,我添加了我的測試結果 –