This example introduces the MDL Discovery Api that helps to overview the MDL includes.
#include <chrono>
#include <ctime>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include "example_shared.h"
using namespace std;
{
switch (kind)
{
case IMdl_info::DK_PACKAGE: return "DK_PACKAGE";
case IMdl_info::DK_MODULE: return "DK_MODULE";
case IMdl_info::DK_XLIFF: return "DK_XLIFF";
case IMdl_info::DK_LIGHTPROFILE: return "DK_LIGHTPROFILE";
case IMdl_info::DK_TEXTURE: return "DK_TEXTURE";
case IMdl_info::DK_MEASURED_BSDF: return "DK_MEASURED_BSDF";
case IMdl_info::DK_DIRECTORY: return "DK_DIRECTORY";
default: return "UNKNOWN";
}
}
{
if (strcmp(s.c_str(), "DK_PACKAGE") == 0)
return IMdl_info::DK_PACKAGE;
else if (strcmp(s.c_str(), "DK_MODULE") == 0)
return IMdl_info::DK_MODULE;
else if (strcmp(s.c_str(), "DK_XLIFF") == 0)
return IMdl_info::DK_XLIFF;
else if (strcmp(s.c_str(), "DK_LIGHTPROFILE") == 0)
return IMdl_info::DK_LIGHTPROFILE;
else if (strcmp(s.c_str(), "DK_TEXTURE") == 0)
return IMdl_info::DK_TEXTURE;
else if (strcmp(s.c_str(), "DK_MEASURED_BSDF") == 0)
return IMdl_info::DK_MEASURED_BSDF;
if (strcmp(s.c_str(), "DK_DIRECTORY") == 0)
return IMdl_info::DK_DIRECTORY;
else if (strcmp(s.c_str(), "DK_ALL") == 0)
return IMdl_info::DK_ALL;
else {
cerr << "\nWarning: Unexpected kind type " << s.c_str();
cerr << ". Filtering will be disabled.\n";
return IMdl_info::DK_ALL;
}
}
void log_default_attributes(
const char* shift,
const char* search_path,
const char* resolved_path,
bool in_archive)
{
cout << "\n" << shift << "search path index: " << search_path_index;
cout << "\n" << shift << "search path: " << search_path;
cout << "\n" << shift << "resolved path: " << resolved_path;
cout << "\n" << shift << "found in archive: " << in_archive;
cout << "\n";
}
{
string shift(" ");
for (int s = 0; s < level; s++)
shift.append(" ");
cerr << "\nError: Unexpected empty kind!\n";
}
else {
cout <<
"\n" << shift.c_str() <<
"simple name: " <<
info->get_simple_name();
cout <<
"\n" << shift.c_str() <<
"qualified name: " <<
info->get_qualified_name();
cout << "\n" << shift.c_str() << "kind: " << DK_to_string(k);
if (
info->get_kind() == IMdl_info:
:DK_XLIFF) {
log_default_attributes(
shift.c_str(),
xliff_info->get_search_path_index(),
xliff_info->get_search_path(),
xliff_info->get_resolved_path(),
xliff_info->in_archive());
return;
}
if (
info->get_kind() == IMdl_info:
:DK_TEXTURE) {
log_default_attributes(
shift.c_str(),
texture_info->get_search_path_index(),
texture_info->get_search_path(),
texture_info->get_resolved_path(),
texture_info->in_archive());
cout << "\n" << shift.c_str() << "number of shadows: "
<< texture_info->get_shadows_count();
for (
mi::Size s = 0; s < texture_info->get_shadows_count(); s++)
{
cout << "\n" << shift.c_str() << "* in search path: " << sh->get_search_path();
}
cout << "\n";
return;
}
if (
info->get_kind() == IMdl_info:
:DK_LIGHTPROFILE) {
log_default_attributes(
shift.c_str(),
lightprofile_info->get_search_path_index(),
lightprofile_info->get_search_path(),
lightprofile_info->get_resolved_path(),
lightprofile_info->in_archive());
cout << "\n" << shift.c_str() << "number of shadows: "
<< lightprofile_info->get_shadows_count();
for (
mi::Size s = 0; s < lightprofile_info->get_shadows_count(); s++)
{
cout << "\n" << shift.c_str() << "* in search path: " << sh->get_search_path();
}
cout << "\n";
return;
}
if (
info->get_kind() == IMdl_info:
:DK_MEASURED_BSDF) {
log_default_attributes(
shift.c_str(),
bsdf_info->get_search_path_index(),
bsdf_info->get_search_path(),
bsdf_info->get_resolved_path(),
bsdf_info->in_archive());
cout << "\n" << shift.c_str() << "number of shadows: "
<< bsdf_info->get_shadows_count();
for (
mi::Size s = 0; s < bsdf_info->get_shadows_count(); s++)
{
cout << "\n" << shift.c_str() << "* in search path: " << sh->get_search_path();
}
cout << "\n";
return;
}
if (
info->get_kind() == IMdl_info:
:DK_MODULE)
{
log_default_attributes(
shift.c_str(),
module_info->get_search_path_index(),
module_info->get_search_path(),
module_info->get_resolved_path()->get_c_str(),
module_info->in_archive());
cout << "\n" << shift.c_str() << "number of shadows: "
<< module_info->get_shadows_count();
for (
mi::Size s = 0; s < module_info->get_shadows_count(); s++)
{
cout << "\n" << shift.c_str() << "* in search path: " << sh->get_search_path();
}
cout << "\n";
return;
}
if ((
info->get_kind() == IMdl_info:
:DK_PACKAGE)||
(
info->get_kind() == IMdl_info:
:DK_DIRECTORY))
{
const mi::Size spi_count = package_info->get_search_path_index_count();
if (spi_count > 0)
{
cout << "\n" << shift.c_str() << "discovered in " << spi_count << " search paths:";
for (
mi::Size i = 0; i < spi_count; ++i)
{
log_default_attributes(
shift.c_str(),
package_info->get_search_path_index(i),
package_info->get_search_path(i),
package_info->get_resolved_path(i)->get_c_str(),
package_info->in_archive(i));
}
}
const mi::Size child_count = package_info->get_child_count();
cout << "\n" << shift.c_str() << "number of children: " << child_count;
if (child_count > 0) cout << "\n";
for (
mi::Size i = 0; i < child_count; i++)
{
log_api_package(child.get(), level + 1);
}
if (child_count == 0) cout << "\n";
return;
}
}
cerr << "\n Unhandled IMdl_info::Kind found!\n";
}
static void usage(const char *name)
{
std::cout
<< "usage: " << name << " [options]\n"
<< "--help, -h print this text\n"
<< "--filter, -f <kind> discovery filter, can occur multiple times\n"
<< " Valid values are: DK_PACKAGE DK_MODULE DK_XLIFF DK_TEXTURE\n"
<< " DK_LIGHTPROFILE DK_MEASURED_BSDF DK_ALL(default)\n"
<< "--mdl_path, -m <path> mdl search path, can occur multiple times\n"
<< " if none is provided, the example search path is used\n";
exit(EXIT_FAILURE);
}
int MAIN_UTF8(int argc, char* argv[])
{
mi::examples::mdl::Configure_options options;
vector<string> kind_filter;
if (argc > 1) {
for (int i = 1; i < argc; ++i) {
const char *opt = argv[i];
if ((strcmp(opt, "--filter") == 0) || (strcmp(opt, "-f") == 0)) {
if (i < argc - 1)
kind_filter.push_back(argv[++i]);
else
usage(argv[0]);
}
else if ((strcmp(opt, "--help") == 0) || (strcmp(opt, "-h") == 0)) {
usage(argv[0]);
}
else if ((strcmp(opt, "--mdl_path") == 0) || (strcmp(opt, "-m") == 0)) {
if (i < argc - 1)
options.additional_mdl_paths.push_back(argv[++i]);
else
usage(argv[0]);
}
else {
std::cout << "Unknown option: \"" << opt << "\"" << std::endl;
usage(argv[0]);
}
}
if (options.additional_mdl_paths.size() > 0) {
options.add_example_search_path = false;
}
}
options.add_admin_space_search_paths = false;
options.add_user_space_search_paths = false;
if (kind_filter.size() > 0) {
discover_filter = IMdl_info::DK_PACKAGE;
for (auto& filter : kind_filter)
discover_filter |= string_to_DK(filter);
}
if (!neuray.is_valid_interface())
exit_failure("Failed to load the SDK.");
if (!mi::examples::mdl::configure(neuray.get(), options))
exit_failure("Failed to initialize the SDK.");
if (ret != 0)
exit_failure("Failed to initialize the SDK. Result code: %d", ret);
{
vector<string> mdl_files;
chrono::time_point<chrono::system_clock> start, end;
start = chrono::system_clock::now();
disc_result(discovery_api->discover(discover_filter));
end = chrono::system_clock::now();
chrono::duration<double> elapsed_seconds = end - start;
if (disc_result != nullptr)
{
disc_result->get_graph());
cout << "\nsearch path";
mi::Size num = disc_result->get_search_paths_count();
if (num > 1)
cout << "s: \n";
else
cout << ": \n";
cout << disc_result->get_search_path(i) << "\n";
cout << "\n -------------------- MDL graph --------------------\n";
log_api_package(root.get(), 0);
cout << "\n ------------------ \\ MDL graph --------------------\n";
stringstream m;
m << "\nTraversed search path(s) ";
for (size_t p = 0; p < options.additional_mdl_paths.size(); ++p)
m << options.additional_mdl_paths[p] << " ";
m << "in " << elapsed_seconds.count() << " seconds \n\n";
cerr << m.str();
}
else
cerr << "Failed to create collapsing graph out of search path "
<< options.additional_mdl_paths[0] << "\n";
discovery_api = 0;
}
if (neuray->shutdown() != 0)
exit_failure("Failed to shutdown the SDK.");
neuray = nullptr;
if (!mi::examples::mdl::unload())
exit_failure("Failed to unload the SDK.");
exit_success();
}
COMMANDLINE_TO_UTF8
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Interface for the discovery API.
Definition: imdl_discovery_api.h:224
Abstract interface for a discovery graph node.
Definition: imdl_discovery_api.h:23
Kind
The kinds of the graph nodes.
Definition: imdl_discovery_api.h:27
Interface for lightprofile files.
Definition: imdl_discovery_api.h:138
Interface for measured bsdf files.
Definition: imdl_discovery_api.h:145
Interface for a graph node representing an MDL module.
Definition: imdl_discovery_api.h:55
Interface for a graph node representing an MDL package.
Definition: imdl_discovery_api.h:151
Interface for texture files.
Definition: imdl_discovery_api.h:131
Interface for xliff files.
Definition: imdl_discovery_api.h:81
std::basic_ostream<C, T> & info(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:580
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46
Namespace for the MDL SDK API.
Definition: example_derivatives.dox:6