This example demonstrate how to render a scene using the Bridge.
#include <iostream>
#include "example_shared.h"
class Application_session_handler
{
public:
Application_session_handler( const std::string& security_token)
: m_security_token( security_token) { }
{
return security_token && m_security_token == security_token;
}
private:
std::string m_security_token;
};
void run_bridge_server(
const char* disk_cache_path,
const char* snapshot_path,
const char* bridge_server_address,
const char* application_path,
const char* security_token,
const char* ssl_cert_file,
const char* ssl_private_key_file,
const char* ssl_password)
{
if( ssl_cert_file && ssl_private_key_file && ssl_password)
http_server->start_ssl(
bridge_server_address, ssl_cert_file, ssl_private_key_file, ssl_password);
else
http_server->start( bridge_server_address);
check_success( iray_bridge_server.is_valid_interface());
iray_bridge_server->create_application( application_path, http_server.get()));
if( iray_bridge_application.is_valid_interface()) {
check_success( iray_bridge_application->set_disk_cache( disk_cache_path) == 0);
check_success( iray_bridge_application->set_snapshot_path( snapshot_path) == 0);
new Application_session_handler( security_token));
check_success( iray_bridge_application->set_session_handler(
application_session_handler.get()) == 0);
iray_bridge_application->open();
sleep_seconds( 60);
iray_bridge_application->close();
}
http_server->shutdown();
}
{
}
int main( int argc, char* argv[])
{
if( argc != 6 && argc != 9) {
std::cerr << "Usage: example_bridge_server <disk_cache_path> <snapshot_path> \\\n"
<< " <bridge_server_address> <application_path> <security_token> \\\n"
<< " [<ssl_cert_file> <ssl_private_key_file> <ssl_password>]"
<< std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* disk_cache_path = argv[1];
const char* snapshot_path = argv[2];
const char* bridge_server_address = argv[3];
const char* application_path = argv[4];
const char* security_token = argv[5];
const char* ssl_cert_file = argc >= 9 ? argv[6] : 0;
const char* ssl_private_key_file = argc >= 9 ? argv[7] : 0;
const char* ssl_password = argc >= 9 ? argv[8] : 0;
check_success( neuray.is_valid_interface());
configuration( neuray.get());
check_start_success( result);
run_bridge_server( neuray.get(), disk_cache_path, snapshot_path, bridge_server_address,
application_path, security_token, ssl_cert_file, ssl_private_key_file, ssl_password);
check_success( neuray->
shutdown() == 0);
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Mixin class template for deriving interface implementations.
Definition: interface_implement.h:41
API component that serves as entry point for the server-side Iray Bridge API.
Definition: iiray_bridge_server.h:221
Represents the server side of a Bridge session.
Definition: ibridge_server.h:523
virtual const char * get_security_token() const =0
Returns the security token specified by the client.
The factory can be used to instantiate the built-in HTTP classes.
Definition: http.h:922
This is an object representing the Iray library.
Definition: ineuray.h:44
virtual Sint32 shutdown(bool blocking=true)=0
Shuts down the library.
virtual base::IInterface * get_api_component(const base::Uuid &uuid) const =0
Returns an API component from the Iray SDK API.
virtual Sint32 start(bool blocking=true)=0
Starts the operation of the Iray library.
This interface is used to load plugins and to query information about loaded plugins.
Definition: iplugin_configuration.h:24
#define MI_BASE_DLL_FILE_EXT
The operating system specific default filename extension for shared libraries (DLLs)
Definition: config.h:340
signed int Sint32
32-bit signed integer.
Definition: types.h:46
#include <iostream>
#include <sstream>
#include <string>
#include "example_shared.h"
#include "example_render_target_simple.h"
{
char buffer[256];
if( size > 1048576.0)
snprintf( buffer, sizeof( buffer)-1, "%.1f MB", size/1048576.0);
else if( size > 1024)
snprintf( buffer, sizeof( buffer)-1, "%.1f kB", size/1024.0);
else
snprintf( buffer,
sizeof( buffer)-1,
"%d bytes",
static_cast<mi::Sint32>( size));
return buffer;
}
class Progress_callback
{
public:
void progress(
mi::Float64 value,
const char* area,
const char* message)
{
if( strcmp( area, "bridge_bytes_uploaded") == 0)
m_bridge_bytes_uploaded = value;
else if( strcmp( area, "bridge_pending_cache_status") == 0)
m_bridge_pending_cache_status = value;
else if( strcmp( area, "bridge_pending_data_serialization") == 0)
m_bridge_pending_data_serialization = value;
else if( strcmp( area, "bridge_pending_hash_calculations") == 0)
m_bridge_pending_hash_calculations = value;
else if( strcmp( area, "bridge_total_bytes_to_upload") == 0)
m_bridge_total_bytes_to_upload = value;
else if( strcmp( area, "bridge_updated_elements") == 0)
m_bridge_updated_elements = value;
else if( strcmp( area, "bridge_upload_state") == 0)
m_bridge_upload_state = value;
else if( strcmp( area, "bridge_uploaded_element_bytes") == 0)
m_uploaded_element_uploaded_bytes = value;
else if( strcmp( area, "bridge_uploaded_element") == 0) {
if( message) {
std::stringstream s;
s << "\"" << message << "\"";
m_uploaded_element_name = s.str();
} else
m_uploaded_element_name = "unnamed element";
m_uploaded_element_size = value;
} else
return;
if( m_bridge_upload_state == 0) {
fprintf( stderr, "Bridge detecting changes: %llu modified element(s) detected.\n",
static_cast<mi::Size>( m_bridge_updated_elements));
} else if( m_bridge_upload_state == 1) {
fprintf( stderr, "Bridge calculating hashes: %llu pending calculation(s), "
"%s uploaded.\n",
static_cast<mi::Size>( m_bridge_pending_hash_calculations),
bytes_to_string( m_bridge_bytes_uploaded).c_str());
} else if( m_bridge_upload_state == 2) {
fprintf( stderr, "Bridge querying cache status: %llu pending request(s), "
"%s uploaded.\n",
static_cast<mi::Size>( m_bridge_pending_cache_status),
bytes_to_string( m_bridge_bytes_uploaded).c_str());
} else if( m_bridge_upload_state == 3) {
if( m_bridge_pending_data_serialization > 0.0)
fprintf( stderr, "Bridge upload: %s/%s (%.0lf%%) total - data serialization for "
"%llu element(s) pending.\n",
bytes_to_string( m_bridge_bytes_uploaded).c_str(),
bytes_to_string( m_bridge_total_bytes_to_upload).c_str(),
(m_bridge_bytes_uploaded / m_bridge_total_bytes_to_upload * 100.0),
static_cast<mi::Size>( m_bridge_pending_data_serialization));
else
fprintf( stderr, "Bridge upload: %s/%s (%.0lf%%) total - %s/%s (%.0lf%%) for %s.\n",
bytes_to_string( m_bridge_bytes_uploaded).c_str(),
bytes_to_string( m_bridge_total_bytes_to_upload).c_str(),
(m_bridge_bytes_uploaded / m_bridge_total_bytes_to_upload * 100.0),
bytes_to_string( m_uploaded_element_uploaded_bytes).c_str(),
bytes_to_string( m_uploaded_element_size).c_str(),
(m_uploaded_element_uploaded_bytes / m_uploaded_element_size * 100.0),
m_uploaded_element_name.c_str());
} else if( m_bridge_upload_state == 4) {
fprintf( stderr, "Bridge waiting for server to finish processing the upload.\n");
} else if( m_bridge_upload_state == 5) {
fprintf( stderr, "Bridge upload completed.\n");
m_bridge_upload_state = -1;
}
}
private:
std::string m_uploaded_element_name;
};
class Iray_bridge_snapshot_callback
{
public:
{
if( error_code == 0)
fprintf( stderr, "Successfully created cb snapshot.\n");
else
fprintf( stderr, "Failed to create cb snapshot.\n");
m_condition.signal();
}
void progress(
mi::Float64 value,
const char* area,
const char* message)
{
fprintf( stderr, "Progress: %.4f %s %s\n", value, area, message);
}
void wait_for_ready_callback()
{
m_condition.wait();
}
private:
};
{
check_success( rc->add_mdl_path( mdl_path) == 0);
check_success( rc->add_mdl_path( ".") == 0);
}
{
check_success( database.is_valid_interface());
check_success( transaction.is_valid_interface());
check_success( import_api.is_valid_interface());
import_api->import_elements( transaction.get(), uri->get_c_str()));
check_success( import_result->get_error_number() == 0);
check_success( scene.is_valid_interface());
scene->set_rootgroup( import_result->get_rootgroup());
scene->set_options( import_result->get_options());
scene->set_camera_instance( import_result->get_camera_inst());
transaction->store( scene.get(), "the_scene");
scene = 0;
transaction->commit();
}
void rendering(
{
check_success( iray_bridge_client.is_valid_interface());
check_success( iray_bridge_client->set_application_url( bridge_server_url) == 0);
check_success( iray_bridge_client->set_security_token( security_token) == 0);
check_success( database.is_valid_interface());
check_success( transaction.is_valid_interface());
scene->create_render_context( transaction.get(), "iray_cloud"));
check_success( render_context.is_valid_interface());
scheduler_mode->set_c_str( "batch");
render_context->set_option( "scheduler_mode", scheduler_mode.get());
video_format->set_c_str( "jpg");
render_context->set_option( "video_format", video_format.get());
scene = 0;
new Render_target( image_api.get(), "Color", 512, 384));
new Progress_callback());
render_context->render( transaction.get(), render_target.get(), callback.get());
check_success( export_api.is_valid_interface());
export_api->export_canvas( "file:example_bridge_client.png", canvas.get());
transaction->commit();
}
{
iray_bridge_client->create_snapshot_context( transaction.get(), "the_scene"));
= snapshot_context->create_snapshot( transaction.get(), "snapshot.cb", callback.get());
if( result >= 0)
callback->wait_for_ready_callback();
transaction->commit();
}
int main( int argc, char* argv[])
{
if( argc != 5) {
std::cerr << "Usage: example_bridge_client <scene_file> <mdl_path> <bridge_url> \\\n"
" <security_token>" << std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* scene_file = argv[1];
const char* mdl_path = argv[2];
const char* bridge_server_url = argv[3];
const char* security_token = argv[4];
check_success( neuray.is_valid_interface());
configuration( neuray.get(), mdl_path);
check_start_success( result);
import_and_store_scene( neuray.get(), scene_file);
rendering( neuray.get(), bridge_server_url, security_token);
make_snapshot( neuray.get());
check_success( neuray->
shutdown() == 0);
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
A simple string class.
Definition: istring.h:22
Conditions allow threads to signal an event and to wait for such a signal, respectively.
Definition: condition.h:33
API component that serves as entry point for the client-side Iray Bridge API.
Definition: iiray_bridge_client.h:248
This interface is used to interact with the distributed database.
Definition: idatabase.h:293
This interface is used to export files.
Definition: iexport_api.h:38
This interface provides various utilities related to canvases and buffers.
Definition: iimage_api.h:49
This interface is used to import files.
Definition: iimport_api.h:100
This interface is used to query and change the rendering configuration.
Definition: irendering_configuration.h:109
The scene is the top-level element describing a subset of DB elements to be rendered.
Definition: iscene.h:44
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
double Float64
64-bit float.
Definition: types.h:52