This example imports a scene file, renders the scene, and serves the image via an HTTP server
#include <iostream>
#include "example_shared.h"
#include "example_render_target_simple.h"
{
public:
{
connection->
enqueue( m_buffer.get());
return true;
}
private:
};
{
public:
{
iresponse->set_header( "Content-Type", "image/jpeg");
}
};
{
check_success( rc->add_mdl_path( mdl_path) == 0);
check_success( rc->add_mdl_path( ".") == 0);
}
{
check_success( database.is_valid_interface());
database->get_global_scope());
scope->create_transaction());
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);
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->create_render_context( transaction.get(), "iray"));
check_success( render_context.is_valid_interface());
scheduler_mode->set_c_str( "batch");
render_context->set_option( "scheduler_mode", scheduler_mode.get());
scene = 0;
new Render_target( image_api.get(), "Color", 512, 384));
check_success( render_context->render( transaction.get(), render_target.get(), 0) >= 0);
image_api->create_buffer_from_canvas( canvas.get(), "jpg", "Rgb"));
transaction->commit();
return buffer;
}
void run_http_server(
{
http_factory->create_server());
http_server->install( request_handler.get());
http_server->install( response_handler.get());
std::string address = "0.0.0.0:";
address += port;
http_server->start( address.c_str());
sleep_seconds( 30);
http_server->shutdown();
}
int main( int argc, char* argv[])
{
if( argc != 4) {
std::cerr << "Usage: example_http_server <scene_file> <mdl_path> <port>" << std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* scene_file = argv[1];
const char* mdl_path = argv[2];
const char* port = argv[3];
check_success( neuray.is_valid_interface());
configuration( neuray.get(), mdl_path);
check_start_success( result);
run_http_server( neuray.get(), buffer.
get(), port);
buffer = 0;
check_success( neuray->
shutdown() == 0);
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
A simple string class.
Definition: istring.h:22
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
The connection class represents a connection from a client to the server.
Definition: http.h:277
virtual IResponse * get_response()=0
Returns the response associated with the connection.
virtual bool enqueue(neuraylib::IBuffer *buffer)=0
Enqueues a buffer to be sent on the connection.
The factory can be used to instantiate the built-in HTTP classes.
Definition: http.h:922
This interface holds all the parameters of a response.
Definition: http.h:197
Abstract interface for a simple buffer with binary data.
Definition: ibuffer.h:25
This interface is used to interact with the distributed database.
Definition: idatabase.h:289
This interface provides various utilities related to canvases and buffers.
Definition: iimage_api.h:72
This interface is used to import files.
Definition: iimport_api.h:100
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
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
#define MI_BASE_DLL_FILE_EXT
The operating system specific default filename extension for shared libraries (DLLs)
Definition: config.h:340
static const Dup_interface DUP_INTERFACE
Symbolic constant to trigger a special constructor in the Handle class.
Definition: handle.h:37
Interface * get() const
Access to the interface. Returns 0 for an invalid interface.
Definition: handle.h:294
signed int Sint32
32-bit signed integer.
Definition: types.h:46
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: neuraylib.h:179