Skip to content

Commit

Permalink
refactored create_filter to remove char arrays and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahf committed Sep 26, 2018
1 parent f12d7ec commit ea3554e
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions cryptomatte/cryptomatte.h
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ struct CryptomatteData {
const String aov_rank_name = t_output.aov_name_tok + rank_num;

if (AiNodeLookUpByName(filter_rank_name.c_str()) == nullptr)
AtNode* filter = create_filter(orig_filter, filter_rank_name.c_str(), i);
AtNode* filter = create_filter(orig_filter, filter_rank_name, i);

TokenizedOutput new_t_output = t_output;
new_t_output.aov_name_tok = aov_rank_name;
Expand All @@ -1223,6 +1223,20 @@ struct CryptomatteData {
AiArraySetStr(crypto_aovs, i, aov_rank_name.c_str());
}
}

AtNode* create_filter(const AtNode* orig_filter, const String filter_name, int aovindex) const {
const AtNodeEntry* filter_nentry = AiNodeGetNodeEntry(orig_filter);
const auto width = AiNodeEntryLookUpParameter(filter_nentry, "width")
? AiNodeGetFlt(orig_filter, "width")
: 2.0f;
const String filter_type = AiNodeEntryGetName(filter_nentry);
const String filter_param = filter_type.substr(0, filter_type.find("_filter"));

AtNode* filter = AiNode("cryptomatte_filter", filter_name.c_str(), nullptr);
AiNodeSetStr(filter, "filter", filter_param.c_str());
AiNodeSetInt(filter, "rank", aovindex * 2);
AiNodeSetFlt(filter, "width", width);
return filter;
}

AtNode* get_or_create_noop_filter() const {
Expand Down Expand Up @@ -1505,29 +1519,6 @@ struct CryptomatteData {
float(clock() - metadata_start_time) / CLOCKS_PER_SEC);
}


AtNode* create_filter(const AtNode* orig_filter, const char* filter_rank_name,
int aovindex) const {
float aFilter_width = 2.0;
const AtNodeEntry* orig_filter_nentry = AiNodeGetNodeEntry(orig_filter);
const char* orig_filter_type_name = AiNodeEntryGetName(orig_filter_nentry);
if (AiNodeEntryLookUpParameter(orig_filter_nentry, "width"))
aFilter_width = AiNodeGetFlt(orig_filter, "width");

char aFilter_filter[MAX_STRING_LENGTH];
safe_copy_to_buffer(aFilter_filter, orig_filter_type_name);
char* filter_strip_point = strstr(aFilter_filter, "_filter");
if (filter_strip_point)
filter_strip_point[0] = '\0';

AtNode* filter = AiNode("cryptomatte_filter");
AiNodeSetStr(filter, "filter", aFilter_filter);
AiNodeSetInt(filter, "rank", aovindex * 2);
AiNodeSetFlt(filter, "width", aFilter_width);
AiNodeSetStr(filter, "name", filter_rank_name);
return filter;
}

///////////////////////////////////////////////
// Cleanup
///////////////////////////////////////////////
Expand Down

0 comments on commit ea3554e

Please sign in to comment.