NVIDIA Index example code nvidia_logo_transpbg.gif Up
multi_view_shape.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright 2023 NVIDIA Corporation. All rights reserved.
3 *****************************************************************************/
6
7#include <mi/dice.h>
8
9// Include code shared by all examples.
10#include "utility/example_shared.h"
11
12#include <nv/index/icamera.h>
13#include <nv/index/iconfig_settings.h>
14#include <nv/index/ifont.h>
15#include <nv/index/ilabel.h>
16
17#include <nv/index/icamera.h>
18#include <nv/index/icircle.h>
19#include <nv/index/icone.h>
20#include <nv/index/iconfig_settings.h>
21#include <nv/index/icylinder.h>
22#include <nv/index/idepth_offset.h>
23#include <nv/index/idistributed_data_access.h>
24#include <nv/index/iellipse.h>
25#include <nv/index/iellipsoid.h>
26#include <nv/index/iicon.h>
27#include <nv/index/iindex.h>
28#include <nv/index/iindex_debug_configuration.h>
29#include <nv/index/ilabel.h>
30#include <nv/index/ilight.h>
31#include <nv/index/iline_set.h>
32#include <nv/index/imaterial.h>
33#include <nv/index/ipath.h>
34#include <nv/index/iplane.h>
35#include <nv/index/ipoint_set.h>
36#include <nv/index/ipolygon.h>
37#include <nv/index/iscene.h>
38#include <nv/index/isession.h>
39#include <nv/index/isphere.h>
40#include <nv/index/itexture.h>
41#include <nv/index/itexture_filter_mode.h>
42#include <nv/index/iviewport.h>
43
44#include <nv/index/app/idata_analysis_and_processing.h>
45#include <nv/index/app/iimage_importer.h>
46#include <nv/index/app/index_connect.h>
47#include <nv/index/app/string_dict.h>
48
49#include "utility/app_rendering_context.h"
50#include "utility/canvas_utility.h"
51
52#include <sstream>
53#include <iostream>
54
55//----------------------------------------------------------------------
57 public nv::index::app::Index_connect
58{
59public:
61 :
62 Index_connect()
63 {
64 // INFO_LOG << "DEBUG: Multi_view_shape() ctor";
65 }
66
68 {
69 // Note: Index_connect::~Index_connect() will be called after here.
70 // INFO_LOG << "DEBUG: ~Multi_view_shape() dtor";
71 }
72
73 // launch application
74 mi::Sint32 launch();
75
76protected:
77 virtual bool evaluate_options(nv::index::app::String_dict& sdict) CPP11_OVERRIDE;
78 // override
80 mi::neuraylib::INetwork_configuration* network_configuration,
81 nv::index::app::String_dict& options) CPP11_OVERRIDE
82 {
83 check_success(network_configuration != 0);
84
85 check_success(options.is_defined("unittest"));
86 const bool is_unittest = nv::index::app::get_bool(options.get("unittest"));
87 if (is_unittest)
88 {
89 info_cout("NETWORK: disabled networking mode.", options);
90 network_configuration->set_mode(mi::neuraylib::INetwork_configuration::MODE_OFF);
91 return true;
92 }
93
94 return initialize_networking_as_default_udp(network_configuration, options);
95 }
96
97private:
98 // Setup camera to see this example scene
99 //
100 // \param[in] camera_tag camera tag
101 // \param[in] dice_transaction dice transaction
102 void setup_camera(
103 const mi::neuraylib::Tag& camera_tag,
104 mi::neuraylib::IDice_transaction* dice_transaction) const;
105 // localize scene elements
106 void localize_scene_element() const;
107 // Filter enable viewport index list
108 // \return newly created filtered viewport list
109 nv::index::IViewport_list* filter_enabled_viewport_index_list();
110 // Render one frame
111 // \param[in] frame_idx current frame index
112 // \return true when success
113 bool render_one_frame(mi::Sint32 frame_idx);
114 // create multiple views
115 //
116 // The view structure of this example
117 //
118 // +-----------------+-----------------+(511,511)
119 // (0,256)| 0. global scope | 1. view 1 |
120 // +-----------------+-----------------+(511,255)
121 // (0,255)| 2. view 2 | 3. view 3 |
122 // +-----------------+-----------------+
123 // (0,0) (255,0) (511,0)
124 //
125 //
126 // \param[in,out] arc application rendering context. multiple views will be updated.
127 void create_views() const;
128
129 // create lights and materials and put them into the tag map
130 //
131 // \param[in] scene_edit scene root for edit
132 // \param[in] dice_transaction dice db transaction
133 // \param[out] light_mat_tag_map {M: light and material name -> tag}
134 void create_light_material_instance(
135 nv::index::IScene* scene_edit,
136 mi::neuraylib::IDice_transaction* dice_transaction,
137 std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map) const;
138 mi::neuraylib::Tag get_valid_light_mat_tag_by_name(
139 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
140 const std::string& light_mat_name) const;
141 void add_scene_defaut_light(
142 nv::index::IScene* scene_edit,
143 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
144 mi::neuraylib::IDice_transaction* dice_transaction);
145 void add_scene_group_simple_geometry(
146 nv::index::IScene* scene_edit,
147 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
148 mi::neuraylib::IDice_transaction* dice_transaction);
149 void add_scene_group_planes(
150 nv::index::IScene* scene_edit,
151 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
152 mi::neuraylib::IDice_transaction* dice_transaction);
153 void add_scene_group_raster(
154 nv::index::IScene* scene_edit,
155 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
156 mi::neuraylib::IDice_transaction* dice_transaction);
157 void add_scene_group_paths(
158 nv::index::IScene* scene_edit,
159 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
160 mi::neuraylib::IDice_transaction* dice_transaction);
161 void add_scene_group_labels(
162 nv::index::IScene* scene_edit,
163 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
164 mi::neuraylib::IDice_transaction* dice_transaction);
165 void add_scene_group_icons(
166 nv::index::IScene* scene_edit,
167 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
168 mi::neuraylib::IDice_transaction* dice_transaction);
169 // set up the scene
170 // Create a scene that contains a triangle mesh.
171 // \param[in] dice_transaction db transaction
172 void setup_scene(mi::neuraylib::IDice_transaction* dice_transaction);
173 // set up as the main host
174 // \return true when success
175 bool setup_main_host();
176
177 // This session tag
178 mi::neuraylib::Tag m_session_tag;
179 // NVIDIA IndeX cluster configuration
180 mi::base::Handle<nv::index::ICluster_configuration> m_cluster_configuration;
181 // Application layer image file canvas (a render target)
182 mi::base::Handle<nv::index::app::canvas_infrastructure::IIndex_image_file_canvas> m_image_file_canvas;
183 // Create_icons options
184 std::string m_outfname;
185 bool m_is_unittest;
186 std::string m_verify_image_path_base;
187 std::string m_font_fpath;
188 std::string m_iconfile;
189 std::vector<bool> m_enable_view_idx_vec;
190 // camera tag
191 mi::neuraylib::Tag m_camera_tag;
192 // simple geometry group node tag
193 mi::neuraylib::Tag m_simple_geo_group_node_tag;
194 // plane tag
195 mi::neuraylib::Tag m_plane_tag;
196 // raster object circle tag
197 mi::neuraylib::Tag m_raster_circle1_tag;
198 // raster object ellipses tag
199 mi::neuraylib::Tag m_raster_ellipses1_tag;
200 // IPath3D path tag
201 mi::neuraylib::Tag m_path3d_1_tag;
202 // ILabel2D tag
203 mi::neuraylib::Tag m_label2d_tag;
204 // Polygon group tag
205 mi::neuraylib::Tag m_polygon_group_tag;
206 mi::base::Handle<nv::index::IViewport_list> m_viewport_list;
207};
208
209//----------------------------------------------------------------------
211{
212 // setup
213 {
214 check_success(setup_main_host());
215
216 // Create multiple views in the arc.
217 create_views();
218
219 mi::Sint32 frame_idx = 0;
220 // Render multiple views for a single render call. Before localize.
221 {
222 // Render a frame and save the rendered image to a file.
223 const bool is_success = render_one_frame(frame_idx);
224 check_success(is_success);
225 ++frame_idx;
226 }
227
228 // localize scene elements
229 localize_scene_element();
230
231 // Render multiple views for a single render call.
232 {
233 // Render a frame and save the rendered image to a file.
234 const bool is_success = render_one_frame(frame_idx);
235 check_success(is_success);
236 ++frame_idx;
237 }
238 }
239 // index_connect shutdown
240 return 0;
241}
242
243//----------------------------------------------------------------------
244bool Multi_view_shape::evaluate_options(nv::index::app::String_dict& sdict)
245{
246 const std::string com_name = sdict.get("command:", "<unknown_command>");
247 m_is_unittest = nv::index::app::get_bool(sdict.get("unittest", "false"));
248 if (m_is_unittest)
249 {
250 sdict.insert("dice::verbose", "2");
251 }
252
253 m_outfname = sdict.get("outfname");
254 m_verify_image_path_base = sdict.get("verify_image_path_base");
255 m_enable_view_idx_vec = get_bool_vec_from_string(sdict.get("enable_vidx_vec"));
256 m_font_fpath = sdict.get("font_fpath");
257 m_iconfile = sdict.get("iconfile");
258
259 info_cout("running " + com_name, sdict);
260 info_cout("outfname = [" + m_outfname +
261 "], verify_image_path_base = [" + m_verify_image_path_base +
262 "], dice::verbose = " + sdict.get("dice::verbose"), sdict);
263
264 // print help and exit if -h
265 if (sdict.is_defined("h"))
266 {
267 std::cout
268 << "info: Usage: " << com_name << " [option]\n"
269 << "Option: [-h]\n"
270 << " print out this message\n"
271
272 << " [-dice::verbose severity_level]\n"
273 << " verbose severity level (3 is info). (default: " + sdict.get("dice::verbose")
274 << ")\n"
275
276 << " [-font_fpath FONT_FILE_PATH]\n"
277 << " font file path. (default: " << sdict.get("font_fpath") << ")\n"
278
279 << " [-icon_file ICON_FILE_PATH]\n"
280 << " Specify an icon file. (default: [" << sdict.get("iconfile") << "])\n"
281
282 << " [-outfname string]\n"
283 << " output ppm file base name. When empty, no output.\n"
284 << " A frame number and extension (.ppm) will be added.\n"
285 << " (default: [" << sdict.get("outfname") << "])\n"
286
287 << " [-verify_image_path_base image path basename]\n"
288 << " when image_fname path basename exist, verify the rendering images.\n"
289 << " (default: [" << sdict.get("verify_image_path_base") << "])\n"
290
291 << " [-unittest bool]\n"
292 << " when true, unit test mode. "
293 << "(default: [" << sdict.get("unittest") << "])\n"
294
295 << " [-enable_vidx_vec enabled_vector]\n"
296 << " Specify which viewport is enabled by a bool vector.\n"
297 << " (default: [" << sdict.get("enable_vidx_vec") << "])"
298
299 << std::endl;
300 exit(1);
301 }
302
303 return true;
304}
305
306//----------------------------------------------------------------------
307void Multi_view_shape::setup_camera(
308 const mi::neuraylib::Tag& camera_tag,
309 mi::neuraylib::IDice_transaction* dice_transaction) const
310{
311 check_success(camera_tag.is_valid());
312
313 mi::base::Handle<nv::index::IPerspective_camera> cam(
314 dice_transaction->edit<nv::index::IPerspective_camera>(camera_tag));
315 check_success(cam.is_valid_interface());
316
317 const mi::math::Vector<mi::Float32, 3> from(500.0f, 1500.0f, 250.0f);
318 mi::math::Vector<mi::Float32, 3> dir ( 0.0f, -0.9f, 0.2f);
319 const mi::math::Vector<mi::Float32, 3> up ( 0.0f, -0.2f, -1.0f);
320 dir.normalize();
321
322 cam->set(from, dir, up);
323 cam->set_aperture(0.033f);
324 cam->set_aspect(1.0f);
325 cam->set_focal(0.03f);
326 cam->set_clip_min(2.0f);
327 cam->set_clip_max(1000.0f);
328}
329
330//----------------------------------------------------------------------
331void Multi_view_shape::localize_scene_element() const
332{
333 // Process local views first.
334
335 // Set up view 1:
336 {
337 const mi::Size view_idx = 1;
338 check_success(m_viewport_list->size() > view_idx);
339
340 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
341 check_success(viewport != 0);
342
343 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
344 check_success(cur_scope);
345 check_success(std::string(cur_scope->get_id()) == "1");
346
347 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
348 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
349 check_success(dice_transaction.is_valid_interface());
350
351 // localize scene elements for viewport 1
352 {
353 mi::Sint32 ret_localize = 1;
354 ret_localize = dice_transaction->localize(m_simple_geo_group_node_tag,
355 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
356 check_success(ret_localize == 0);
357 ret_localize = dice_transaction->localize(m_plane_tag,
358 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
359 check_success(ret_localize == 0);
360 ret_localize = dice_transaction->localize(m_raster_circle1_tag,
361 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
362 check_success(ret_localize == 0);
363 ret_localize = dice_transaction->localize(m_label2d_tag,
364 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
365 check_success(ret_localize == 0);
366
367 // change the transformation in viewport 1
368 mi::base::Handle<nv::index::ITransformed_scene_group> simple_geometry_group_node(
369 dice_transaction->edit<nv::index::ITransformed_scene_group>(m_simple_geo_group_node_tag));
370 check_success(simple_geometry_group_node.is_valid_interface());
371 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
372 1.0f, 0.0f, 0.0f, 0.0f,
373 0.0f, 1.0f, 0.0f, 0.0f,
374 0.0f, 0.0f, 1.0f, 0.0f,
375 200.0f - 100.0f, 200.0f, 600.0f, 1.0f // move x -100
376 );
377 simple_geometry_group_node->set_transform(transform_mat);
378
379 mi::base::Handle<nv::index::IPlane> plane(
380 dice_transaction->edit<nv::index::IPlane>(m_plane_tag));
381 plane->set_extent(mi::math::Vector<mi::Float32,2>(600.0f - 100.0f, 800.0f - 200.0f)); // make it smaller
382
383 mi::base::Handle<nv::index::ICircle> circle(
384 dice_transaction->edit<nv::index::ICircle>(m_raster_circle1_tag));
385 check_success(circle.is_valid_interface());
386 circle->set_enabled(false);
387
388 mi::base::Handle<nv::index::ILabel_2D> label_2d(
389 dice_transaction->edit<nv::index::ILabel_2D>(m_label2d_tag));
390 check_success(label_2d.is_valid_interface());
391 label_2d->set_text("View 1: transform + disable some");
392
393 }
394 dice_transaction->commit();
395 }
396
397 // Set up viewport 2:
398 {
399 const mi::Size view_idx = 2;
400 check_success(m_viewport_list->size() > view_idx);
401
402 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
403 check_success(viewport != 0);
404
405 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
406 check_success(cur_scope);
407 check_success(std::string(cur_scope->get_id()) == "2");
408
409 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
410 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
411 check_success(dice_transaction.is_valid_interface());
412
413 // localize scene elements
414 {
415 mi::Sint32 ret_localize = 1;
416 ret_localize = dice_transaction->localize(m_raster_ellipses1_tag,
417 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
418 check_success(ret_localize == 0);
419 ret_localize = dice_transaction->localize(m_path3d_1_tag,
420 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
421 check_success(ret_localize == 0);
422 ret_localize = dice_transaction->localize(m_label2d_tag,
423 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
424 check_success(ret_localize == 0);
425 ret_localize = dice_transaction->localize(m_polygon_group_tag,
426 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
427 check_success(ret_localize == 0);
428
429 mi::base::Handle<nv::index::IEllipse> ellipse(
430 dice_transaction->edit<nv::index::IEllipse>(m_raster_ellipses1_tag));
431 check_success(ellipse.is_valid_interface());
432 ellipse->set_enabled(false);
433
434 mi::base::Handle<nv::index::IPath_3D> path1(
435 dice_transaction->edit<nv::index::IPath_3D>(m_path3d_1_tag));
436 path1->set_radius(20.0f); // from 10.0
437
438 mi::base::Handle<nv::index::ILabel_2D> label_2d(
439 dice_transaction->edit<nv::index::ILabel_2D>(m_label2d_tag));
440 check_success(label_2d.is_valid_interface());
441 label_2d->set_text("View 2: changed ellipse/path/polygon");
442
443 mi::base::Handle<nv::index::ITransformed_scene_group> polygon_group_node(
444 dice_transaction->edit<nv::index::ITransformed_scene_group>(m_polygon_group_tag));
445 check_success(polygon_group_node.is_valid_interface());
446 polygon_group_node->set_enabled(false);
447 }
448 dice_transaction->commit();
449 }
450
451 // Set up viewport 3:
452 {
453 const mi::Size view_idx = 3;
454 check_success(m_viewport_list->size() > view_idx);
455
456 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
457 check_success(viewport != 0);
458
459 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
460 check_success(cur_scope);
461 check_success(std::string(cur_scope->get_id()) == "3");
462
463 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
464 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
465 check_success(dice_transaction.is_valid_interface());
466
467 // localize scene elements
468 {
469 // no changes in this viewport
470 }
471 dice_transaction->commit();
472 }
473
474 // Set up viewport 0 with the global scope:
475 {
476 const mi::Size view_idx = 0;
477 check_success(m_viewport_list->size() > view_idx);
478
479 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
480 check_success(viewport != 0);
481
482 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
483 check_success(cur_scope);
484 check_success(std::string(cur_scope->get_id()) == "0");
485
486 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
487 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
488 check_success(dice_transaction.is_valid_interface());
489
490 // localize scene elements
491 {
492 // no changes for this viewport
493 }
494 dice_transaction->commit();
495 }
496}
497
498//----------------------------------------------------------------------
499nv::index::IViewport_list* Multi_view_shape::filter_enabled_viewport_index_list()
500{
501 mi::base::Handle<nv::index::IViewport_list> new_viewport_list;
502 {
503 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(create_transaction());
504 assert(dice_transaction.is_valid_interface());
505 {
506 assert(m_session_tag.is_valid());
507 mi::base::Handle<const nv::index::ISession> session(
508 dice_transaction->access<nv::index::ISession>(m_session_tag));
509 assert(session.is_valid_interface());
510
511 // create viewport from a session
512 new_viewport_list = session->create_viewport_list();
513 }
514 dice_transaction->commit();
515 }
516
517 check_success(new_viewport_list.is_valid_interface());
518 const mi::Size nb_views = m_viewport_list->size();
519
520 std::stringstream sstr;
521 mi::Size nb_enabled = 0;
522 for (mi::Size i = 0; i < nb_views; ++i)
523 {
524 if (m_enable_view_idx_vec[i])
525 {
526 sstr << i << " ";
527 mi::base::Handle<nv::index::IViewport> vp (m_viewport_list->get(i));
528 new_viewport_list->append(vp.get());
529 ++nb_enabled;
530 }
531 }
532 // copy advisory state
533 new_viewport_list->set_advisory_enabled(m_viewport_list->get_advisory_enabled());
534
535 if (nb_enabled == nb_views)
536 {
537 INFO_LOG << "All views are enabled.";
538 }
539 else
540 {
541 INFO_LOG << "Filtered views. Enabled: " << sstr.str();
542 }
543
544 new_viewport_list->retain();
545 return new_viewport_list.get();
546}
547
548//----------------------------------------------------------------------
549bool Multi_view_shape::render_one_frame(mi::Sint32 frame_idx)
550{
551 bool success = true;
552
553 // Render a frame and save the rendered image to a file.
554 // Only save the file at the end of the iteration.
555 std::string fname = "";
556 if (!(m_outfname.empty()))
557 {
558 fname = get_output_file_name(m_outfname, frame_idx);
559 }
560 check_success(m_index_rendering.is_valid_interface());
561
562 // set up canvas. output_fname.empty() is valid (no output file)
563 m_image_file_canvas->set_rgba_file_name(fname.c_str());
564
565 // set advisory to see the multiview rendering details
566 m_viewport_list->set_advisory_enabled(true);
567
568 mi::base::Handle<nv::index::IViewport_list> cur_viewport_list(
569 filter_enabled_viewport_index_list());
570 check_success(cur_viewport_list.is_valid_interface());
571
572 mi::base::Handle<nv::index::IFrame_results_list> frame_results_list(
573 m_index_rendering->render(
574 m_session_tag,
575 m_image_file_canvas.get(),
576 cur_viewport_list.get()));
577 check_success(frame_results_list.is_valid_interface());
578
579 if (frame_results_list->size() == 0)
580 {
581 ERROR_LOG << "IIndex_rendering rendering call has no results.";
582 success = false;
583 }
584 else
585 {
586 for (mi::Size i = 0; i < frame_results_list->size(); ++i)
587 {
588 mi::base::Handle<nv::index::IFrame_results>
589 frame_results(frame_results_list->get(i));
590 check_success(frame_results.is_valid_interface());
591
592 const mi::base::Handle<nv::index::IError_set> err_set(frame_results->get_error_set());
593 check_success(err_set.is_valid_interface());
594 if (err_set->any_errors())
595 {
596 std::ostringstream os;
597
598 const mi::base::Handle<nv::index::IError_set> err_set(frame_results->get_error_set());
599 const mi::Uint32 nb_err = err_set->get_nb_errors();
600 for (mi::Uint32 e = 0; e < nb_err; ++e)
601 {
602 if (e != 0) os << '\n';
603 const mi::base::Handle<nv::index::IError> err(err_set->get_error(e));
604 os << err->get_error_string();
605 }
606
607 ERROR_LOG << "IIndex_rendering rendering call failed with the following error(s): " << '\n'
608 << os.str();
609 success = false;
610 }
611 }
612 }
613
614 // verify the generated frame
615 if (!(m_verify_image_path_base.empty()))
616 {
617 const std::string ref_img_fpath = get_output_file_name(m_verify_image_path_base, frame_idx);
618 if (!(verify_canvas_result(get_application_layer_interface(),
619 m_image_file_canvas.get(), ref_img_fpath, get_options())))
620 {
621 success = false;
622 }
623 }
624
625 return success;
626}
627
628//----------------------------------------------------------------------
629void Multi_view_shape::create_views() const
630{
631 // Check session and multiple views in the arc
632 check_success(m_session_tag.is_valid());
633 check_success(m_viewport_list.is_valid_interface());
634 check_success(m_viewport_list->size() == 0);
635
636 // Multiple view itself lives in the global scope.
637 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
638 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
639 check_success(dice_transaction.is_valid_interface());
640 {
641 mi::base::Handle<const nv::index::ISession> session(
642 dice_transaction->access<nv::index::ISession>(m_session_tag));
643 check_success(session.is_valid_interface());
644
645 // 0. create a single viewport in the global scope.
646 {
647 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
648 check_success(viewport.is_valid_interface());
649
650 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 0, 256);
651 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
652
653 viewport->set_position(viewport_pos);
654 viewport->set_size(viewport_size);
655 viewport->set_scope(m_global_scope.get()); // ref count up
656
657 m_viewport_list->append(viewport.get());
658 }
659
660 // 1. viewport
661 {
662 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
663 check_success(viewport.is_valid_interface());
664
665 mi::neuraylib::IScope* parent = 0; // this means global scope in this context
666 mi::Uint8 privacy_level = 1;
667 bool is_temp = false;
668 mi::base::Handle<mi::neuraylib::IScope> local_scope(m_database->create_scope(parent, privacy_level, is_temp));
669 check_success(local_scope.is_valid_interface());
670
671 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 256, 256);
672 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
673
674 viewport->set_position(viewport_pos);
675 viewport->set_size(viewport_size);
676 viewport->set_scope(local_scope.get()); // ref count up
677
678 m_viewport_list->append(viewport.get());
679 }
680
681 // 2. viewport
682 {
683 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
684 check_success(viewport.is_valid_interface());
685
686 mi::neuraylib::IScope* parent = 0; // this means global scope in this context
687 mi::Uint8 privacy_level = 1;
688 bool is_temp = false;
689 mi::base::Handle<mi::neuraylib::IScope> local_scope(m_database->create_scope(parent, privacy_level, is_temp));
690 check_success(local_scope.is_valid_interface());
691
692 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 0, 0);
693 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
694
695 viewport->set_position(viewport_pos);
696 viewport->set_size(viewport_size);
697 viewport->set_scope(local_scope.get()); // ref count up
698
699 m_viewport_list->append(viewport.get());
700 }
701
702 // 3. viewport
703 {
704 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
705 check_success(viewport.is_valid_interface());
706
707 mi::neuraylib::IScope* parent = 0; // this means global scope in this context
708 mi::Uint8 privacy_level = 1;
709 bool is_temp = false;
710 mi::base::Handle<mi::neuraylib::IScope> local_scope(m_database->create_scope(parent, privacy_level, is_temp));
711 check_success(local_scope.is_valid_interface());
712
713 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 256, 0);
714 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
715
716 viewport->set_position(viewport_pos);
717 viewport->set_size(viewport_size);
718 viewport->set_scope(local_scope.get()); // ref count up
719
720 m_viewport_list->append(viewport.get());
721 }
722 }
723 dice_transaction->commit();
724}
725
726//----------------------------------------------------------------------
727void Multi_view_shape::create_light_material_instance(
728 nv::index::IScene* scene_edit,
729 mi::neuraylib::IDice_transaction* dice_transaction,
730 std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map) const
731{
732 assert(scene_edit != 0);
733 assert(dice_transaction != 0);
734 assert(light_mat_tag_map.empty()); // should be empty
735
736 // create lights
737 {
738 mi::base::Handle<nv::index::IDirectional_headlight> default_light(
739 scene_edit->create_attribute<nv::index::IDirectional_headlight>());
740 check_success(default_light.is_valid_interface());
741
742 default_light->set_direction(mi::math::Vector<mi::Float32, 3>(1.0f, -1.0f, -1.0f));
743 const mi::math::Color color_intensity(1.0f, 1.0f, 1.0f, 1.0f);
744 default_light->set_intensity(color_intensity);
745
746 const mi::neuraylib::Tag default_light_tag = dice_transaction->store_for_reference_counting(default_light.get());
747 check_success(default_light_tag.is_valid());
748
749 light_mat_tag_map["default_light"] = default_light_tag;
750 }
751
752 {
753 mi::base::Handle<nv::index::IDirectional_headlight> headlight(
754 scene_edit->create_attribute<nv::index::IDirectional_headlight>());
755 check_success(headlight.is_valid_interface());
756
757 headlight->set_direction(mi::math::Vector<mi::Float32, 3>(1.0f, -1.0f, -1.0f));
758 const mi::math::Color color_intensity(1.0f, 1.0f, 1.0f, 1.0f);
759 headlight->set_intensity(color_intensity);
760
761 const mi::neuraylib::Tag headlight_tag = dice_transaction->store_for_reference_counting(headlight.get());
762 check_success(headlight_tag.is_valid());
763
764 light_mat_tag_map["headlight"] = headlight_tag;
765 }
766
767 {
768 mi::base::Handle<nv::index::IDirectional_light> dirlight(
769 scene_edit->create_attribute<nv::index::IDirectional_light>());
770 check_success(dirlight.is_valid_interface());
771
772 dirlight->set_direction(mi::math::Vector<mi::Float32, 3>(-1.0f, 0.0f, 0.0f));
773 const mi::math::Color color_intensity(1.0f, 1.0f, 1.0f, 1.0f);
774 dirlight->set_intensity(color_intensity);
775
776 const mi::neuraylib::Tag dirlight_tag = dice_transaction->store_for_reference_counting(dirlight.get());
777 check_success(dirlight_tag.is_valid());
778
779 light_mat_tag_map["dirlight"] = dirlight_tag;
780 }
781
782 // create materials
783 {
784 std::vector<std::string> matname_vec;
785 matname_vec.push_back("mat_red");
786 matname_vec.push_back("mat_green");
787 matname_vec.push_back("mat_blue");
788 matname_vec.push_back("mat_yellow");
789 matname_vec.push_back("mat_white");
790 matname_vec.push_back("mat_pink");
791 matname_vec.push_back("mat_exotic");
792
793 std::vector<mi::math::Color> ambient_vec;
794 ambient_vec.push_back(mi::math::Color(0.3f, 0.0f, 0.0f, 1.0f));
795 ambient_vec.push_back(mi::math::Color(0.0f, 0.3f, 0.0f, 1.0f));
796 ambient_vec.push_back(mi::math::Color(0.0f, 0.0f, 0.3f, 1.0f));
797 ambient_vec.push_back(mi::math::Color(0.6f, 0.6f, 0.0f, 1.0f));
798 ambient_vec.push_back(mi::math::Color(0.3f, 0.3f, 0.3f, 1.0f));
799 ambient_vec.push_back(mi::math::Color(1.0f, 0.0f, 1.0f, 1.0f));
800 ambient_vec.push_back(mi::math::Color(0.5f, 0.0f, 0.0f, 1.0f));
801
802 std::vector<mi::math::Color> diffuse_vec;
803 diffuse_vec.push_back(mi::math::Color(0.4f, 0.0f, 0.0f, 1.0f));
804 diffuse_vec.push_back(mi::math::Color(0.0f, 0.4f, 0.0f, 1.0f));
805 diffuse_vec.push_back(mi::math::Color(0.0f, 0.0f, 0.4f, 1.0f));
806 diffuse_vec.push_back(mi::math::Color(0.3f, 0.3f, 0.0f, 1.0f));
807 diffuse_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.4f, 1.0f));
808 diffuse_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.0f, 1.0f));
809 diffuse_vec.push_back(mi::math::Color(0.0f, 0.5f, 0.0f, 1.0f));
810
811 std::vector<mi::math::Color> specular_vec;
812 specular_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.4f, 1.0f));
813 specular_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.4f, 1.0f));
814 specular_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.4f, 1.0f));
815 specular_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.4f, 1.0f));
816 specular_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.4f, 1.0f));
817 specular_vec.push_back(mi::math::Color(0.4f, 0.4f, 0.4f, 1.0f));
818 specular_vec.push_back(mi::math::Color(0.0f, 0.0f, 1.0f, 1.0f));
819
820 std::vector<mi::Float32> shiness_vec;
821 shiness_vec.push_back(100.0f);
822 shiness_vec.push_back(100.0f);
823 shiness_vec.push_back(100.0f);
824 shiness_vec.push_back(100.0f);
825 shiness_vec.push_back(100.0f);
826 shiness_vec.push_back(100.0f);
827 shiness_vec.push_back(100.0f);
828
829 assert(matname_vec.size() == ambient_vec.size());
830 assert(matname_vec.size() == diffuse_vec.size());
831 assert(matname_vec.size() == specular_vec.size());
832 assert(matname_vec.size() == shiness_vec.size());
833
834 // Materials
835 for (mi::Size i = 0; i < matname_vec.size(); ++i)
836 {
837 mi::base::Handle<nv::index::IPhong_gl> phong_1(scene_edit->create_attribute<nv::index::IPhong_gl>());
838 check_success(phong_1.is_valid_interface());
839
840 phong_1->set_ambient(ambient_vec[i]);
841 phong_1->set_diffuse(diffuse_vec[i]);
842 phong_1->set_specular(specular_vec[i]);
843 phong_1->set_shininess(shiness_vec[i]);
844 const mi::neuraylib::Tag phong_1_tag
845 = dice_transaction->store_for_reference_counting(phong_1.get());
846 check_success(phong_1_tag.is_valid());
847
848 if (light_mat_tag_map.find(matname_vec[i]) != light_mat_tag_map.end())
849 {
850 ERROR_LOG << "Duplicated mat name: " << matname_vec[i];
851 assert(false);
852 }
853 light_mat_tag_map[matname_vec[i]] = phong_1_tag;
854 }
855 }
856}
857
858//----------------------------------------------------------------------
859mi::neuraylib::Tag Multi_view_shape::get_valid_light_mat_tag_by_name(
860 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
861 const std::string& light_mat_name) const
862{
863 if (light_mat_tag_map.find(light_mat_name) == light_mat_tag_map.end())
864 {
865 ERROR_LOG << "Cannot find light/mat name: " << light_mat_name;
866 assert(false);
867 }
868 const mi::neuraylib::Tag tag = light_mat_tag_map.find(light_mat_name)->second;
869 assert(tag.is_valid());
870
871 return tag;
872}
873
874//----------------------------------------------------------------------
875void Multi_view_shape::add_scene_defaut_light(
876 nv::index::IScene* scene_edit,
877 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
878 mi::neuraylib::IDice_transaction* dice_transaction)
879{
880 const mi::neuraylib::Tag default_light_tag = get_valid_light_mat_tag_by_name(light_mat_tag_map, "default_light");
881 scene_edit->append(default_light_tag, dice_transaction);
882}
883
884//----------------------------------------------------------------------
885void Multi_view_shape::add_scene_group_simple_geometry(
886 nv::index::IScene* scene_edit,
887 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
888 mi::neuraylib::IDice_transaction* dice_transaction)
889{
890 // Add a scene group where the shapes should be added
891 mi::base::Handle<nv::index::ITransformed_scene_group> simple_geometry_group_node(
892 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
893 check_success(simple_geometry_group_node.is_valid_interface());
894 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
895 1.0f, 0.0f, 0.0f, 0.0f,
896 0.0f, 1.0f, 0.0f, 0.0f,
897 0.0f, 0.0f, 1.0f, 0.0f,
898 200.0f, 200.0f, 600.0f, 1.0f
899 );
900 simple_geometry_group_node->set_transform(transform_mat);
901
902 // headlight
903 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "headlight"), dice_transaction);
904
905 // mat_red
906 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_red"), dice_transaction);
907
908 // group_spheres
909 std::vector<mi::neuraylib::Tag> sphere_tag_vec;
910 {
911 // app::scene::group_spheres::type = transformed_scene_group
912 mi::base::Handle<nv::index::ITransformed_scene_group> group_spheres(
913 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
914 check_success(group_spheres.is_valid_interface());
915
916 // Create spheres (3D)
917 //
918 std::vector<mi::math::Vector<mi::Float32, 3> > center_vec;
919 center_vec.push_back(mi::math::Vector<mi::Float32, 3>( 0.0f, 0.0f, 0.0f));
920 center_vec.push_back(mi::math::Vector<mi::Float32, 3>(-100.0f, -100.0f, 0.0f));
921 center_vec.push_back(mi::math::Vector<mi::Float32, 3>( -60.0f, -100.0f, 0.0f));
922 center_vec.push_back(mi::math::Vector<mi::Float32, 3>( -20.0f, -100.0f, 0.0f));
923 center_vec.push_back(mi::math::Vector<mi::Float32, 3>( 20.0f, -100.0f, 0.0f));
924 center_vec.push_back(mi::math::Vector<mi::Float32, 3>( 60.0f, -100.0f, 0.0f));
925 center_vec.push_back(mi::math::Vector<mi::Float32, 3>( 100.0f, 0.0f, 0.0f));
926
927 std::vector<mi::Float32> radius_vec;
928 radius_vec.push_back(50.0f);
929 radius_vec.push_back(10.0f);
930 radius_vec.push_back(12.0f);
931 radius_vec.push_back(14.0f);
932 radius_vec.push_back(16.0f);
933 radius_vec.push_back(18.0f);
934 radius_vec.push_back(25.0f);
935 assert(center_vec.size() == radius_vec.size());
936 assert(center_vec.size() == 7);
937
938 for (mi::Size i = 0; i < center_vec.size(); ++i)
939 {
940 mi::base::Handle<nv::index::ISphere> sphere(
941 scene_edit->create_shape<nv::index::ISphere>());
942 sphere->set_center(center_vec[i]);
943 sphere->set_radius(radius_vec[i]);
944
945 const mi::neuraylib::Tag sphere_tag
946 = dice_transaction->store_for_reference_counting(sphere.get());
947 check_success(sphere_tag.is_valid());
948 sphere_tag_vec.push_back(sphere_tag);
949 }
950
951 // app::scene::group_spheres::children = mat_green sphere1 mat_red sphere2 sphere3 sphere4 sphere5 sphere6
952 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_green"), dice_transaction);
953 simple_geometry_group_node->append(sphere_tag_vec[0], dice_transaction);
954 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_red"), dice_transaction);
955 simple_geometry_group_node->append(sphere_tag_vec[1], dice_transaction);
956 simple_geometry_group_node->append(sphere_tag_vec[2], dice_transaction);
957 simple_geometry_group_node->append(sphere_tag_vec[3], dice_transaction);
958 simple_geometry_group_node->append(sphere_tag_vec[4], dice_transaction);
959 simple_geometry_group_node->append(sphere_tag_vec[5], dice_transaction);
960 }
961
962 // mat_exotic
963 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_exotic"), dice_transaction);
964 // dirlight
965 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "dirlight"), dice_transaction);
966 // sphere_exotic
967 simple_geometry_group_node->append(sphere_tag_vec[6], dice_transaction);
968 // mat_blue
969 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_blue"), dice_transaction);
970 // headlight
971 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "headlight"), dice_transaction);
972 // mat_yellow
973 simple_geometry_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_yellow"), dice_transaction);
974 // ellipsoid
975 {
976 mi::base::Handle<nv::index::IEllipsoid> ellipsoid(
977 scene_edit->create_shape<nv::index::IEllipsoid>());
978 ellipsoid->set_center(mi::math::Vector<mi::Float32, 3>(200.0f, 0.0f, 0.0f));
979
980 mi::math::Vector<mi::Float32, 3> a(55.0f, 0.0f, 0.0f);
981 mi::math::Vector<mi::Float32, 3> b( 0.0f, 35.0f, 0.0f);
982 mi::Float32 c = 35.0f;
983 ellipsoid->set_semi_axes(a, b, c);
984
985 const mi::neuraylib::Tag ellipsoid_tag
986 = dice_transaction->store_for_reference_counting(ellipsoid.get());
987 check_success(ellipsoid_tag.is_valid());
988 simple_geometry_group_node->append(ellipsoid_tag, dice_transaction);
989 }
990
991 // group_cylinders
992 {
993 // Cylinders and cones (3D)
994 mi::base::Handle<nv::index::ITransformed_scene_group> group_cylinders(
995 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
996 check_success(group_cylinders.is_valid_interface());
997 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
998 1.0f, 0.0f, 0.0f, 0.0f,
999 0.0f, 1.0f, 0.0f, 0.0f,
1000 0.0f, 0.0f, 1.0f, 0.0f,
1001 100.0f, 200.0f, 150.0f, 1.0f
1002 );
1003 group_cylinders->set_transform(transform_mat);
1004
1005 // mat_green
1006 group_cylinders->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_green"), dice_transaction);
1007 mi::base::Handle<nv::index::ICylinder> capped_cylinder(
1008 scene_edit->create_shape<nv::index::ICylinder>());
1009 capped_cylinder->set_bottom(mi::math::Vector<mi::Float32, 3>(50.0f, 0.0f, 90.0f));
1010 capped_cylinder->set_top(mi::math::Vector<mi::Float32, 3>(220.0f, 0.0f, 40.0f));
1011 capped_cylinder->set_radius(15.0f);
1012 capped_cylinder->set_capped(true);
1013 const mi::neuraylib::Tag capped_cylinder_tag
1014 = dice_transaction->store_for_reference_counting(capped_cylinder.get());
1015 check_success(capped_cylinder_tag.is_valid());
1016 group_cylinders->append(capped_cylinder_tag, dice_transaction);
1017
1018 // mat_blue
1019 group_cylinders->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_blue"), dice_transaction);
1020 // uncapped_cylinder
1021 mi::base::Handle<nv::index::ICylinder> uncapped_cylinder(
1022 scene_edit->create_shape<nv::index::ICylinder>());
1023 uncapped_cylinder->set_bottom(mi::math::Vector<mi::Float32, 3>(0.0f, 75.0f, 0.0f));
1024 uncapped_cylinder->set_top(mi::math::Vector<mi::Float32, 3>(250.0f, 75.0f, 0.0f));
1025 uncapped_cylinder->set_radius(30.0f);
1026 uncapped_cylinder->set_capped(false);
1027 const mi::neuraylib::Tag uncapped_cylinder_tag
1028 = dice_transaction->store_for_reference_counting(uncapped_cylinder.get());
1029 check_success(uncapped_cylinder_tag.is_valid());
1030 group_cylinders->append(uncapped_cylinder_tag, dice_transaction);
1031
1032 // mat_red
1033 group_cylinders->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_red"), dice_transaction);
1034 // cone
1035 mi::base::Handle<nv::index::ICone> cone(
1036 scene_edit->create_shape<nv::index::ICone>());
1037 cone->set_center(mi::math::Vector<mi::Float32, 3>(250.0f, 75.0f, 0.0f));
1038 cone->set_tip(mi::math::Vector<mi::Float32, 3>(300.0f, 75.0f, 0.0f));
1039 cone->set_radius(30.0f);
1040 cone->set_capped(true);
1041
1042 const mi::neuraylib::Tag cone_tag
1043 = dice_transaction->store_for_reference_counting(cone.get());
1044 check_success(cone_tag.is_valid());
1045 group_cylinders->append(cone_tag, dice_transaction);
1046
1047 const mi::neuraylib::Tag group_cylinders_tag
1048 = dice_transaction->store_for_reference_counting(group_cylinders.get());
1049 check_success(group_cylinders_tag.is_valid());
1050 simple_geometry_group_node->append(group_cylinders_tag, dice_transaction);
1051 }
1052
1053 m_simple_geo_group_node_tag =
1054 dice_transaction->store_for_reference_counting(simple_geometry_group_node.get());
1055 check_success(m_simple_geo_group_node_tag.is_valid());
1056
1057 scene_edit->append(m_simple_geo_group_node_tag, dice_transaction);
1058}
1059
1060//----------------------------------------------------------------------
1061void Multi_view_shape::add_scene_group_planes(
1062 nv::index::IScene* scene_edit,
1063 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
1064 mi::neuraylib::IDice_transaction* dice_transaction)
1065{
1066 // Textured planes
1067 mi::base::Handle<nv::index::ITransformed_scene_group> group_plane(
1068 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1069 check_success(group_plane.is_valid_interface());
1070
1071 group_plane->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "headlight"), dice_transaction);
1072 group_plane->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_red"), dice_transaction);
1073 // tex_checkerboard
1074 mi::base::Handle<nv::index::ITexture_filter_mode> tex_filter(
1075 scene_edit->create_attribute<nv::index::ITexture_filter_mode_nearest_neighbor>());
1076 check_success(tex_filter.is_valid_interface());
1077 mi::neuraylib::Tag tex_filter_tag = dice_transaction->store_for_reference_counting(tex_filter.get());
1078 check_success(tex_filter_tag.is_valid());
1079 group_plane->append(tex_filter_tag, dice_transaction);
1080
1081 // Access an application layer component that provides some sample techniques such as the checkerboard for 2d surfaces:
1082 mi::base::Handle<nv::index::app::data_analysis_and_processing::IData_analysis_and_processing> processing(
1083 get_application_layer_interface()->get_api_component<nv::index::app::data_analysis_and_processing::IData_analysis_and_processing>());
1084 check_success(processing.is_valid_interface());
1085 // Create a checkerboard technique and add it to the scene. For more details on how to implement the checkerboard, please review the provided
1086 // source that was shipped with the application layer component 'nv::index::app::data_analysis_and_processing::IData_analysis_and_processing'.
1087 mi::base::Handle<nv::index::IDistributed_compute_technique> tex(
1088 processing->get_sample_tool_set()->create_checker_board_2d_technique(
1089 mi::math::Vector<mi::Float32, 2>(320.0f, 320.0f),
1090 nv::index::IDistributed_compute_destination_buffer_2d_texture::FORMAT_RGBA_FLOAT32,
1091 mi::math::Color(0.9f, 0.2f, 0.15f, 0.7f),
1092 mi::math::Color(0.2f, 0.2f, 0.8f, 1.0f)));
1093 check_success(tex.is_valid_interface());
1094
1095 const mi::neuraylib::Tag tex_tag = dice_transaction->store_for_reference_counting(tex.get());
1096 check_success(tex_tag.is_valid());
1097 group_plane->append(tex_tag, dice_transaction);
1098
1099 // plane_diagonal
1100 mi::base::Handle<nv::index::IPlane> plane(
1101 scene_edit->create_shape<nv::index::IPlane>());
1102 plane->set_point( mi::math::Vector<mi::Float32,3>(200.0f, -100.0f, 300.0f));
1103 plane->set_normal(mi::math::Vector<mi::Float32,3>(1.0f, 1.0f, 1.0f));
1104 plane->set_up( mi::math::Vector<mi::Float32,3>(-1.0f, 1.0f, 0.0f));
1105 plane->set_extent(mi::math::Vector<mi::Float32,2>(600.0f, 800.0f));
1106 check_success(!m_plane_tag.is_valid());
1107 m_plane_tag =
1108 dice_transaction->store_for_reference_counting(plane.get());
1109 check_success(m_plane_tag.is_valid());
1110 group_plane->append(m_plane_tag, dice_transaction);
1111
1112 const mi::neuraylib::Tag group_plane_tag
1113 = dice_transaction->store_for_reference_counting(group_plane.get());
1114 check_success(group_plane_tag.is_valid());
1115 scene_edit->append(group_plane_tag, dice_transaction);
1116}
1117
1118//----------------------------------------------------------------------
1119void Multi_view_shape::add_scene_group_raster(
1120 nv::index::IScene* scene_edit,
1121 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
1122 mi::neuraylib::IDice_transaction* dice_transaction)
1123{
1124 // Raster geometry (2D)
1125 mi::base::Handle<nv::index::ITransformed_scene_group> raster_group_node(
1126 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1127 check_success(raster_group_node.is_valid_interface());
1128 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1129 1.0f, 0.0f, 0.0f, 0.0f,
1130 0.0f, 1.0f, 0.0f, 0.0f,
1131 0.0f, 0.0f, 1.0f, 0.0f,
1132 100.0f, 100.0f, 100.0f, 1.0f
1133 );
1134 raster_group_node->set_transform(transform_mat);
1135
1136 // headlight
1137 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "headlight"), dice_transaction);
1138
1139 // group_lines_points
1140 {
1141 // Lines and points (2D)
1142 mi::base::Handle<nv::index::ITransformed_scene_group> group_lines_points_node(
1143 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1144 check_success(group_lines_points_node.is_valid_interface());
1145 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1146 1.0f, 0.0f, 0.0f, 0.0f,
1147 0.0f, 1.0f, 0.0f, 0.0f,
1148 0.0f, 0.0f, 1.0f, 0.0f,
1149 50.0f, 0.0f, 100.0f, 1.0f
1150 );
1151 group_lines_points_node->set_transform(transform_mat);
1152
1153 // mat_white
1154 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_white"), dice_transaction);
1155 // points
1156 {
1157 // Some shaded points with a headlight, with per-vertex color
1158 std::vector<mi::math::Vector<mi::Float32,3> > pos_vec;
1159 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(30.0f, 50.0f, 10.0f));
1160 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(34.0f, 51.0f, 40.0f));
1161 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(39.0f, 58.0f, 70.0f));
1162 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(50.0f, 62.0f, 100.0f));
1163 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(53.0f, 70.0f, 140.0f));
1164 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(55.0f, 50.0f, 190.0f));
1165 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(70.0f, 51.0f, 240.0f));
1166 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(90.0f, 58.0f, 370.0f));
1167 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(91.0f, 62.0f, 500.0f));
1168 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(93.0f, 70.0f, 640.0f));
1169
1170 std::vector<mi::math::Color> col_vec;
1171 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1172 col_vec.push_back(mi::math::Color(0.0f, 1.0f, 0.0f, 1.0f));
1173 col_vec.push_back(mi::math::Color(0.0f, 0.0f, 1.0f, 1.0f));
1174 col_vec.push_back(mi::math::Color(1.0f, 1.0f, 0.0f, 1.0f));
1175 col_vec.push_back(mi::math::Color(0.0f, 1.0f, 1.0f, 1.0f));
1176 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1177 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1178 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1179 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1180 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1181
1182 std::vector<mi::Float32> rad_vec;
1183 for (mi::Size i = 0; i < pos_vec.size(); ++i)
1184 {
1185 rad_vec.push_back(2.0f);
1186 }
1187
1188 assert(pos_vec.size() == col_vec.size());
1189 assert(pos_vec.size() == rad_vec.size());
1190
1191 mi::base::Handle<nv::index::IPoint_set> point_set(
1192 scene_edit->create_shape<nv::index::IPoint_set>());
1193 check_success(point_set.is_valid_interface());
1194 point_set->set_point_style(nv::index::IPoint_set::SHADED_CIRCLE);
1195 point_set->set_vertices(&pos_vec[0], pos_vec.size());
1196 point_set->set_colors( &col_vec[0], col_vec.size());
1197 point_set->set_radii( &rad_vec[0], rad_vec.size());
1198
1199 const mi::neuraylib::Tag point_set_tag
1200 = dice_transaction->store_for_reference_counting(point_set.get());
1201 check_success(point_set_tag.is_valid());
1202 raster_group_node->append(point_set_tag, dice_transaction);
1203 }
1204
1205 // mat_blue
1206 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_blue"), dice_transaction);
1207 // lines
1208 {
1209 std::vector<mi::math::Vector<mi::Float32,3> > pos_vec;
1210 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(30.0f, 50.0f, 10.0f));
1211 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(34.0f, 51.0f, 40.0f));
1212 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(34.0f, 51.0f, 40.0f));
1213 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(39.0f, 58.0f, 70.0f));
1214 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(39.0f, 58.0f, 70.0f));
1215 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(50.0f, 62.0f, 100.0f));
1216 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(50.0f, 62.0f, 100.0f));
1217 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(53.0f, 70.0f, 140.0f));
1218 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(53.0f, 70.0f, 140.0f));
1219 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(55.0f, 50.0f, 190.0f));
1220 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(55.0f, 50.0f, 190.0f));
1221 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(70.0f, 51.0f, 240.0f));
1222 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(70.0f, 51.0f, 240.0f));
1223 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(90.0f, 58.0f, 370.0f));
1224 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(90.0f, 58.0f, 370.0f));
1225 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(91.0f, 62.0f, 500.0f));
1226 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(91.0f, 62.0f, 500.0f));
1227 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(93.0f, 70.0f, 640.0f));
1228 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(40.0f, 60.0f, 15.0f));
1229 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(44.0f, 61.0f, 45.0f));
1230 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(44.0f, 61.0f, 45.0f));
1231 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(59.0f, 68.0f, 75.0f));
1232 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(59.0f, 68.0f, 75.0f));
1233 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(60.0f, 70.0f, 109.0f));
1234 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(60.0f, 70.0f, 109.0f));
1235 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(60.0f, 75.0f, 141.0f));
1236 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(60.0f, 75.0f, 141.0f));
1237 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(60.0f, 80.0f, 196.0f));
1238 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(60.0f, 80.0f, 196.0f));
1239 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(80.0f, 81.0f, 242.0f));
1240 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(80.0f, 81.0f, 242.0f));
1241 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(100.0f, 88.0f, 393.0f));
1242 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(100.0f, 88.0f, 393.0f));
1243 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(101.0f, 82.0f, 530.0f));
1244 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(101.0f, 82.0f, 530.0f));
1245 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(108.0f, 90.0f, 655.0f));
1246 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(108.0f, 90.0f, 655.0f));
1247 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(113.0f, 109.0f, 685.0f));
1248 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(113.0f, 109.0f, 685.0f));
1249 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(129.0f, 115.0f, 688.0f));
1250
1251 // Create line_set scene element and add it to the scene
1252 mi::base::Handle<nv::index::ILine_set> line_set(scene_edit->create_shape<nv::index::ILine_set>());
1253 check_success(line_set.is_valid_interface());
1254
1255 line_set->set_line_type(nv::index::ILine_set::LINE_TYPE_SEGMENTS);
1256 line_set->set_line_style(nv::index::ILine_set::LINE_STYLE_DASHED);
1257 line_set->set_lines(&pos_vec[0], pos_vec.size());
1258
1259 std::vector<mi::math::Color> col_vec;
1260 std::vector<mi::Float32> width_vec;
1261 for (mi::Size i = 0; i < pos_vec.size(); ++i)
1262 {
1263 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1264 width_vec.push_back(2.0f);
1265 }
1266 line_set->set_colors(&col_vec[0], col_vec.size()/2);
1267 line_set->set_widths(&width_vec[0], width_vec.size());
1268
1269 const mi::neuraylib::Tag line_set_tag
1270 = dice_transaction->store_for_reference_counting(line_set.get());
1271
1272 INFO_LOG << "line_set_tag: " << line_set_tag;
1273 check_success(line_set_tag.is_valid());
1274 raster_group_node->append(line_set_tag, dice_transaction);
1275 }
1276
1277 // dirlight
1278 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "dirlight"), dice_transaction);
1279 // mat_blue
1280 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_blue"), dice_transaction);
1281 // point_large
1282 {
1283 mi::math::Vector<mi::Float32,3> pos(120.0f, 120.0f, 120.0f);
1284 mi::Float32 rad = 20.0f;
1285
1286 mi::base::Handle<nv::index::IPoint_set> point_large(
1287 scene_edit->create_shape<nv::index::IPoint_set>());
1288 check_success(point_large.is_valid_interface());
1289 point_large->set_point_style(nv::index::IPoint_set::SHADED_CIRCLE);
1290 point_large->set_vertices(&pos, 1);
1291 point_large->set_radii( &rad, 1);
1292
1293 const mi::neuraylib::Tag point_large_tag
1294 = dice_transaction->store_for_reference_counting(point_large.get());
1295 check_success(point_large_tag.is_valid());
1296 raster_group_node->append(point_large_tag, dice_transaction);
1297 }
1298
1299 // mat_white
1300 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_white"), dice_transaction);
1301 // triangles
1302 {
1303 std::vector<mi::math::Vector<mi::Float32,3> > pos_vec;
1304 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(10.0f, 60.0f, 10.0f));
1305 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(30.0f, 50.0f, 10.0f));
1306 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(80.0f, 40.0f, 10.0f));
1307
1308 std::vector<mi::math::Color> col_vec;
1309 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1310 col_vec.push_back(mi::math::Color(0.0f, 1.0f, 0.0f, 1.0f));
1311 col_vec.push_back(mi::math::Color(0.0f, 0.0f, 1.0f, 1.0f));
1312
1313 std::vector<mi::Float32> rad_vec;
1314 for (mi::Size i = 0; i < pos_vec.size(); ++i)
1315 {
1316 rad_vec.push_back(10.0f);
1317 }
1318
1319 mi::base::Handle<nv::index::IPoint_set> point_set(
1320 scene_edit->create_shape<nv::index::IPoint_set>());
1321 check_success(point_set.is_valid_interface());
1322 point_set->set_point_style(nv::index::IPoint_set::FLAT_TRIANGLE);
1323 point_set->set_vertices(&pos_vec[0], pos_vec.size());
1324 point_set->set_colors( &col_vec[0], col_vec.size());
1325 point_set->set_radii( &rad_vec[0], rad_vec.size());
1326
1327 const mi::neuraylib::Tag point_set_tag
1328 = dice_transaction->store_for_reference_counting(point_set.get());
1329 check_success(point_set_tag.is_valid());
1330 raster_group_node->append(point_set_tag, dice_transaction);
1331 }
1332 }
1333
1334 // group_circles_ellipses
1335 {
1336 // Circles and ellipses (2D)
1337 mi::base::Handle<nv::index::ITransformed_scene_group> circle_ellipses_group_node(
1338 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1339 check_success(circle_ellipses_group_node.is_valid_interface());
1340 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1341 1.0f, 0.0f, 0.0f, 0.0f,
1342 0.0f, 1.0f, 0.0f, 0.0f,
1343 0.0f, 0.0f, 1.0f, 0.0f,
1344 300.0f, 500.0f, 100.0f, 1.0f
1345 );
1346 circle_ellipses_group_node->set_transform(transform_mat);
1347
1348 // headlight
1349 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "headlight"), dice_transaction);
1350 // mat_white
1351 raster_group_node->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_white"), dice_transaction);
1352 {
1353 // circle and ellipses
1354 std::vector<mi::neuraylib::Tag> circle_and_ellipses_tag_vec;
1355 {
1356 {
1357 std::vector<mi::math::Vector<mi::Float32,3> > pos_vec;
1358 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(300.0f, 50.0f, 90.0f));
1359 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(100.0f, 450.0f, 350.0f));
1360 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(440.0f, 450.0f, 56.0f));
1361 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(440.0f, 450.0f, 56.0f));
1362
1363 std::vector<mi::Float32> rad_vec;
1364 rad_vec.push_back(20.0f);
1365 rad_vec.push_back( 8.0f);
1366 rad_vec.push_back(10.0f);
1367 rad_vec.push_back( 5.0f);
1368
1369 std::vector<mi::math::Color> col_vec;
1370 col_vec.push_back(mi::math::Color(1.0f, 1.0f, 0.0f, 1.0f));
1371 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 1.0f, 1.0f));
1372 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.5f, 1.0f));
1373 col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1374
1375 std::vector<mi::Float32> width_vec;
1376 width_vec.push_back(0.75f);
1377 width_vec.push_back(2.75f);
1378 width_vec.push_back(5.75f);
1379 width_vec.push_back(1.0f);
1380
1381 std::vector<mi::math::Color> fill_col_vec;
1382 fill_col_vec.push_back(mi::math::Color(0.0f, 1.0f, 1.0f, 0.66f));
1383 fill_col_vec.push_back(mi::math::Color(0.0f, 1.0f, 0.0f, 0.75f));
1384 fill_col_vec.push_back(mi::math::Color(1.0f, 0.5f, 0.0f, 1.0f));
1385 fill_col_vec.push_back(mi::math::Color(1.0f, 1.0f, 0.0f, 1.0f));
1386
1387 assert(pos_vec.size() == rad_vec.size());
1388 assert(pos_vec.size() == col_vec.size());
1389 assert(pos_vec.size() == width_vec.size());
1390 assert(pos_vec.size() == fill_col_vec.size());
1391
1392 for (mi::Size i = 0; i < pos_vec.size(); ++i)
1393 {
1394 mi::base::Handle<nv::index::ICircle> circle(
1395 scene_edit->create_shape<nv::index::ICircle>());
1396 check_success(circle.is_valid_interface());
1397
1398 circle->set_geometry(pos_vec[i], rad_vec[i]);
1399 circle->set_outline_style(col_vec[i], width_vec[i]);
1400 circle->set_fill_style(fill_col_vec[i], nv::index::ICircle::FILL_SOLID);
1401
1402 const mi::neuraylib::Tag circle_tag
1403 = dice_transaction->store_for_reference_counting(circle.get());
1404 check_success(circle_tag.is_valid());
1405
1406 circle_and_ellipses_tag_vec.push_back(circle_tag);
1407 }
1408 }
1409
1410 {
1411 std::vector<mi::math::Vector<mi::Float32,3> > pos_vec;
1412 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(30.0f, 50.0f, -50.0f));
1413 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(50.0f, 100.0f, 50.0f));
1414 pos_vec.push_back(mi::math::Vector<mi::Float32,3>(150.0f, 100.0f, 200.0f));
1415
1416 std::vector<mi::Float32> rad_x_vec;
1417 rad_x_vec.push_back(15.0f);
1418 rad_x_vec.push_back(40.0f);
1419 rad_x_vec.push_back(40.0f);
1420
1421 std::vector<mi::Float32> rad_y_vec;
1422 rad_y_vec.push_back(20.0f);
1423 rad_y_vec.push_back(20.0f);
1424 rad_y_vec.push_back(10.0f);
1425
1426 std::vector<mi::Float32> rot_vec;
1427 rot_vec.push_back(0.2f);
1428 rot_vec.push_back(0.15f);
1429 rot_vec.push_back(0.785f);
1430
1431 std::vector<mi::math::Color> line_col_vec;
1432 line_col_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1433 line_col_vec.push_back(mi::math::Color(0.0f, 0.0f, 1.0f, 1.0f));
1434 line_col_vec.push_back(mi::math::Color(0.0f, 1.0f, 1.0f, 1.0f));
1435
1436 std::vector<mi::Float32> width_vec;
1437 width_vec.push_back(2.0);
1438 width_vec.push_back(3.0);
1439 width_vec.push_back(15.0);
1440
1441 std::vector<mi::math::Color> fill_col_vec;
1442 fill_col_vec.push_back(mi::math::Color(1.0f, 1.0f, 0.0f, 1.0f));
1443 fill_col_vec.push_back(mi::math::Color(1.0f, 1.0f, 1.0f, 0.5f));
1444 fill_col_vec.push_back(mi::math::Color(1.0f, 1.0f, 1.0f, 0.0f));
1445
1446 assert(pos_vec.size() == rad_x_vec.size());
1447 assert(pos_vec.size() == rad_y_vec.size());
1448 assert(pos_vec.size() == rot_vec.size());
1449 assert(pos_vec.size() == line_col_vec.size());
1450 assert(pos_vec.size() == width_vec.size());
1451 assert(pos_vec.size() == fill_col_vec.size());
1452
1453 for (mi::Size i = 0; i < pos_vec.size(); ++i)
1454 {
1455 mi::base::Handle<nv::index::IEllipse> ellipse(
1456 scene_edit->create_shape<nv::index::IEllipse>());
1457 check_success(ellipse.is_valid_interface());
1458
1459 ellipse->set_geometry(pos_vec[i], rad_x_vec[i], rad_y_vec[i], rot_vec[i]);
1460 ellipse->set_outline_style(line_col_vec[i], width_vec[i]);
1461 ellipse->set_fill_style(fill_col_vec[i], nv::index::IEllipse::FILL_SOLID);
1462
1463 const mi::neuraylib::Tag ellipse_tag
1464 = dice_transaction->store_for_reference_counting(ellipse.get());
1465 check_success(ellipse_tag.is_valid());
1466
1467 circle_and_ellipses_tag_vec.push_back(ellipse_tag);
1468 }
1469 }
1470
1471 }
1472
1473 // Depth offset is needed so that the circles 3a and 3b actually overlap
1474 mi::base::Handle<nv::index::IDepth_offset> depth_offset_attr(
1475 scene_edit->create_attribute<nv::index::IDepth_offset>());
1476 check_success(depth_offset_attr.is_valid_interface());
1477 depth_offset_attr->set_depth_offset(10.0f);
1478 const mi::neuraylib::Tag depth_offset_attr_tag
1479 = dice_transaction->store_for_reference_counting(depth_offset_attr.get());
1480 check_success(depth_offset_attr_tag.is_valid());
1481
1482 // circle1
1483 raster_group_node->append(circle_and_ellipses_tag_vec[0], dice_transaction);
1484 // circle2
1485 raster_group_node->append(circle_and_ellipses_tag_vec[1], dice_transaction);
1486 // circle3a
1487 raster_group_node->append(circle_and_ellipses_tag_vec[2], dice_transaction);
1488 // depth_offset_circle
1489 raster_group_node->append(depth_offset_attr_tag, dice_transaction);
1490 // circle3b
1491 raster_group_node->append(circle_and_ellipses_tag_vec[3], dice_transaction);
1492 // ellipse1
1493 raster_group_node->append(circle_and_ellipses_tag_vec[4], dice_transaction);
1494 // ellipse2
1495 raster_group_node->append(circle_and_ellipses_tag_vec[5], dice_transaction);
1496 // ellipse3
1497 raster_group_node->append(circle_and_ellipses_tag_vec[6], dice_transaction);
1498
1499 m_raster_circle1_tag = circle_and_ellipses_tag_vec[0];
1500 m_raster_ellipses1_tag = circle_and_ellipses_tag_vec[4];
1501 }
1502 }
1503
1504 // group_polygons
1505 {
1506 // Polygons (2D)
1507 mi::base::Handle<nv::index::ITransformed_scene_group> group_polygons(
1508 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1509 check_success(group_polygons.is_valid_interface());
1510 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1511 1.0f, 0.0f, 0.0f, 0.0f, // Half size
1512 0.0f, 1.0f, 0.0f, 0.0f,
1513 0.0f, 0.0f, 1.0f, 0.0f,
1514 0.0f, 0.0f, 0.0f, 1.0f
1515 );
1516 group_polygons->set_transform(transform_mat);
1517
1518 // headlight
1519 group_polygons->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "headlight"), dice_transaction);
1520 // mat_white
1521 group_polygons->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_white"), dice_transaction);
1522
1523 const mi::Size NB_POLY = 4;
1524 std::vector<mi::math::Vector<mi::Float32, 3> > center_vec;
1525 center_vec.push_back(mi::math::Vector<mi::Float32, 3>(90.0f, 50.0f, 150.0f));
1526 center_vec.push_back(mi::math::Vector<mi::Float32, 3>(129.0f, 300.0f, 50.0f));
1527 center_vec.push_back(mi::math::Vector<mi::Float32, 3>(200.0f, 150.0f, 200.0f));
1528 center_vec.push_back(mi::math::Vector<mi::Float32, 3>(530.0f, 50.0f, 340.0f));
1529
1530 std::vector<mi::math::Vector<mi::Float32, 2> > vtx_vec[NB_POLY];
1531 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, 20.0f));
1532 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, 60.0f));
1533 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, 60.0f));
1534 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, 20.0f));
1535 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(-60.0f, 20.0f));
1536 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(-60.0f, -20.0f));
1537 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, -20.0f));
1538 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, -60.0f));
1539 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, -60.0f));
1540 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, -20.0f));
1541 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(60.0f, -20.0f));
1542 vtx_vec[0].push_back(mi::math::Vector<mi::Float32, 2>(60.0f, 20.0f));
1543
1544 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(0.0f, 60.0f));
1545 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, 20.0f));
1546 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(-60.0f, 20.0f));
1547 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(-25.0f, 0.0f));
1548 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(-40.0f, -40.0f));
1549 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(0.0f, -20.0f));
1550 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(40.0f, -40.0f));
1551 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(25.0f, 0.0f));
1552 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(60.0f, 20.0f));
1553 vtx_vec[1].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, 20.0f));
1554
1555 vtx_vec[2].push_back(mi::math::Vector<mi::Float32, 2>(0.0f, 40.0f));
1556 vtx_vec[2].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, 0.0f));
1557 vtx_vec[2].push_back(mi::math::Vector<mi::Float32, 2>(0.0f, -40.0f));
1558 vtx_vec[2].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, 0.0f));
1559
1560 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(0.0f, 20.0f));
1561 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, 60.0f));
1562 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(-60.0f, 60.0f));
1563 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(-30.0f, 0.0f));
1564 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(-60.0f, -60.0f));
1565 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(-20.0f, -60.0f));
1566 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(0.0f, -20.0f));
1567 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, -60.0f));
1568 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(60.0f, -60.0f));
1569 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(30.0f, 0.0f));
1570 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(60.0f, 60.0f));
1571 vtx_vec[3].push_back(mi::math::Vector<mi::Float32, 2>(20.0f, 60.0f));
1572
1573 // Adjust for the canvas (Originally for 1024x1024, but this is 256x256)
1574 for (mi::Size i = 0; i < NB_POLY; ++i)
1575 {
1576 for (mi::Size j = 0; j < vtx_vec[i].size(); ++j)
1577 {
1578 vtx_vec[i][j] = 0.25f * vtx_vec[i][j];
1579 }
1580 }
1581
1582 std::vector<mi::math::Color> line_color_vec;
1583 line_color_vec.push_back(mi::math::Color(1.0f, 1.0f, 0.5f, 1.0f));
1584 line_color_vec.push_back(mi::math::Color(1.0f, 0.5f, 0.5f, 1.0f));
1585 line_color_vec.push_back(mi::math::Color(1.0f, 1.0f, 1.0f, 1.0f));
1586 line_color_vec.push_back(mi::math::Color(0.7f, 0.7f, 1.0f, 1.0f));
1587
1588 std::vector<mi::Float32> line_width_vec;
1589 line_width_vec.push_back(3.0f);
1590 line_width_vec.push_back(2.5f);
1591 line_width_vec.push_back(3.5f);
1592 line_width_vec.push_back(1.7f);
1593
1594 std::vector<mi::math::Color> fill_color_vec;
1595 fill_color_vec.push_back(mi::math::Color(0.0f, 1.0f, 0.0f, 1.0f));
1596 fill_color_vec.push_back(mi::math::Color(1.0f, 0.0f, 0.0f, 1.0f));
1597 fill_color_vec.push_back(mi::math::Color(0.0f, 0.0f, 1.0f, 1.0f));
1598 fill_color_vec.push_back(mi::math::Color(1.0f, 1.0f, 0.5f, 1.0f));
1599
1600 check_success(center_vec.size() == line_color_vec.size());
1601 check_success(center_vec.size() == line_width_vec.size());
1602 check_success(center_vec.size() == fill_color_vec.size());
1603
1604 for (mi::Size i = 0; i < center_vec.size(); ++i)
1605 {
1606 mi::base::Handle<nv::index::IPolygon> polygon(
1607 scene_edit->create_shape<nv::index::IPolygon>());
1608 check_success((polygon->set_geometry(&(vtx_vec[i][0]), vtx_vec[i].size(), center_vec[i])));
1609 polygon->set_fill_style(fill_color_vec[i], nv::index::IPolygon::FILL_SOLID);
1610
1611 const mi::neuraylib::Tag polygon_tag = dice_transaction->store_for_reference_counting(polygon.get());
1612 check_success(polygon_tag.is_valid());
1613 group_polygons->append(polygon_tag, dice_transaction);
1614 }
1615
1616 check_success(!m_polygon_group_tag.is_valid());
1617 m_polygon_group_tag = dice_transaction->store_for_reference_counting(group_polygons.get());
1618 check_success(m_polygon_group_tag.is_valid());
1619 raster_group_node->append(m_polygon_group_tag, dice_transaction);
1620 }
1621
1622 const mi::neuraylib::Tag raster_group_node_tag
1623 = dice_transaction->store_for_reference_counting(raster_group_node.get());
1624 check_success(raster_group_node_tag.is_valid());
1625 scene_edit->append(raster_group_node_tag, dice_transaction);
1626}
1627
1628//----------------------------------------------------------------------
1629void Multi_view_shape::add_scene_group_paths(
1630 nv::index::IScene* scene_edit,
1631 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
1632 mi::neuraylib::IDice_transaction* dice_transaction)
1633{
1634 // Paths (2D/3D)
1635 mi::base::Handle<nv::index::ITransformed_scene_group> group_paths(
1636 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1637 check_success(group_paths.is_valid_interface());
1638 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1639 1.0f, 0.0f, 0.0f, 0.0f,
1640 0.0f, 1.0f, 0.0f, 0.0f,
1641 0.0f, 0.0f, 1.0f, 0.0f,
1642 160.0f, 150.0f, 300.0f, 1.0f
1643 );
1644 group_paths->set_transform(transform_mat);
1645
1646 // headlight
1647 group_paths->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "headlight"), dice_transaction);
1648 // mat_blue
1649 group_paths->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_blue"), dice_transaction);
1650 // mat_green
1651 group_paths->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_green"), dice_transaction);
1652 // mat_red
1653 group_paths->append(get_valid_light_mat_tag_by_name(light_mat_tag_map, "mat_red"), dice_transaction);
1654
1655 mi::base::Handle<nv::index::IPath_style> path_style_linear(
1656 scene_edit->create_attribute<nv::index::IPath_style>());
1657 check_success(path_style_linear.is_valid_interface());
1658 path_style_linear->set_interpolation(nv::index::IPath_style::INTERPOLATION_LINEAR);
1659
1660 const mi::neuraylib::Tag path_style_linear_tag = dice_transaction->store_for_reference_counting(path_style_linear.get());
1661 check_success(path_style_linear_tag.is_valid());
1662 group_paths->append(path_style_linear_tag, dice_transaction);
1663
1664 // path1
1665 std::vector<mi::math::Vector<mi::Float32,3> > point_vec;
1666 point_vec.push_back(mi::math::Vector<mi::Float32,3>(130.0f, 250.0f, 10.0f));
1667 point_vec.push_back(mi::math::Vector<mi::Float32,3>(134.0f, 251.0f, 40.0f));
1668 point_vec.push_back(mi::math::Vector<mi::Float32,3>(139.0f, 258.0f, 70.0f));
1669 point_vec.push_back(mi::math::Vector<mi::Float32,3>(150.0f, 262.0f, 100.0f));
1670 point_vec.push_back(mi::math::Vector<mi::Float32,3>(153.0f, 270.0f, 140.0f));
1671 point_vec.push_back(mi::math::Vector<mi::Float32,3>(155.0f, 250.0f, 190.0f));
1672 point_vec.push_back(mi::math::Vector<mi::Float32,3>(170.0f, 251.0f, 240.0f));
1673 point_vec.push_back(mi::math::Vector<mi::Float32,3>(190.0f, 258.0f, 370.0f));
1674 point_vec.push_back(mi::math::Vector<mi::Float32,3>(191.0f, 262.0f, 500.0f));
1675 point_vec.push_back(mi::math::Vector<mi::Float32,3>(193.0f, 270.0f, 640.0f));
1676
1677 std::vector<mi::Uint32> mat_vec;
1678 mat_vec.push_back(2);
1679 mat_vec.push_back(1);
1680 mat_vec.push_back(0);
1681 mat_vec.push_back(2);
1682 mat_vec.push_back(2);
1683 mat_vec.push_back(1);
1684 mat_vec.push_back(1);
1685 mat_vec.push_back(0);
1686 mat_vec.push_back(2);
1687 mat_vec.push_back(1);
1688
1689 mi::base::Handle<nv::index::IPath_3D> path1(
1690 scene_edit->create_shape<nv::index::IPath_3D>());
1691 check_success(path1.is_valid_interface());
1692 path1->set_radius(10.0f);
1693 path1->set_points(&(point_vec[0]), point_vec.size());
1694 path1->set_color_map_indexes(&(mat_vec[0]), mat_vec.size());
1695
1696 check_success(!m_path3d_1_tag.is_valid());
1697 m_path3d_1_tag = dice_transaction->store_for_reference_counting(path1.get());
1698 check_success(m_path3d_1_tag.is_valid());
1699 group_paths->append(m_path3d_1_tag, dice_transaction);
1700
1701 const mi::neuraylib::Tag group_paths_tag = dice_transaction->store_for_reference_counting(group_paths.get());
1702 check_success(group_paths_tag.is_valid());
1703 scene_edit->append(group_paths_tag, dice_transaction);
1704}
1705
1706//----------------------------------------------------------------------
1707void Multi_view_shape::add_scene_group_labels(
1708 nv::index::IScene* scene_edit,
1709 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
1710 mi::neuraylib::IDice_transaction* dice_transaction)
1711{
1712 // Labels (2D/3D)
1713 mi::base::Handle<nv::index::ITransformed_scene_group> group_labels(
1714 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1715 check_success(group_labels.is_valid_interface());
1716 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1717 1.0f, 0.0f, 0.0f, 0.0f,
1718 0.0f, 1.0f, 0.0f, 0.0f,
1719 0.0f, 0.0f, 1.0f, 0.0f,
1720 0.0f, 0.0f, 0.0f, 1.0f
1721 );
1722 group_labels->set_transform(transform_mat);
1723
1724 // default_font
1725 mi::base::Handle<nv::index::IFont> font(scene_edit->create_attribute<nv::index::IFont>());
1726 check_success(font.is_valid_interface());
1727
1728 if (font->set_file_name(m_font_fpath.c_str()))
1729 {
1730 INFO_LOG << "set the font path [" << m_font_fpath << "]";
1731 }
1732 else
1733 {
1734 ERROR_LOG << "Can not find the font path [" << m_font_fpath << "], "
1735 << "the rendering result may not correct.";
1736 }
1737 font->set_font_resolution(64.0f);
1738 const mi::neuraylib::Tag font_tag = dice_transaction->store_for_reference_counting(font.get());
1739 check_success(font_tag.is_valid());
1740 group_labels->append(font_tag, dice_transaction);
1741
1742 // label_layout1
1743 mi::base::Handle<nv::index::ILabel_layout> label_layout(
1744 scene_edit->create_attribute<nv::index::ILabel_layout>());
1745 check_success(label_layout.is_valid_interface());
1746 label_layout->set_padding(10.0f);
1747 label_layout->set_color(mi::math::Color(1.0f, 1.0f, 1.0f, 1.0f), mi::math::Color(1.0f, 1.0f, 1.0f, 0.157f));
1748 const mi::neuraylib::Tag label_layout_tag =
1749 dice_transaction->store_for_reference_counting(label_layout.get());
1750 check_success(label_layout_tag.is_valid());
1751 group_labels->append(label_layout_tag, dice_transaction);
1752
1753 // label_2d
1754 mi::base::Handle<nv::index::ILabel_2D> label_2d(scene_edit->create_shape<nv::index::ILabel_2D>());
1755 check_success(label_2d.is_valid_interface());
1756 label_2d->set_text("Global scope view");
1757 const mi::math::Vector<mi::Float32, 3> label_2d_position(-40.0f, 000.0f, 570.0f);
1758 const mi::math::Vector<mi::Float32, 2> right_2d(1.0f, 0.0f);
1759 const mi::math::Vector<mi::Float32, 2> up_2d (0.0f, 1.0f);
1760 label_2d->set_geometry(label_2d_position, right_2d, up_2d, 30.0f, -1.0f);
1761 m_label2d_tag =
1762 dice_transaction->store_for_reference_counting(label_2d.get());
1763 check_success(m_label2d_tag.is_valid());
1764
1765 group_labels->append(m_label2d_tag, dice_transaction);
1766
1767 // label_layout2
1768 mi::base::Handle<nv::index::ILabel_layout> label_layout2(
1769 scene_edit->create_attribute<nv::index::ILabel_layout>());
1770 check_success(label_layout2.is_valid_interface());
1771 label_layout2->set_padding(0.0f);
1772 label_layout2->set_color(mi::math::Color(0.46f, 0.73f, 0.0f, 1.0f), mi::math::Color(0.0f, 0.0f, 0.0f, 0.0f));
1773 const mi::neuraylib::Tag label_layout2_tag =
1774 dice_transaction->store_for_reference_counting(label_layout2.get());
1775 check_success(label_layout2_tag.is_valid());
1776 group_labels->append(label_layout2_tag, dice_transaction);
1777
1778 // label_3d
1779 mi::base::Handle<nv::index::ILabel_3D> label_3d(scene_edit->create_shape<nv::index::ILabel_3D>());
1780 check_success(label_3d.is_valid_interface());
1781 label_3d->set_text("NVIDIA IndeX");
1782 const mi::math::Vector<mi::Float32, 3> label_3d_position(550.0f, 200.0f, 150.0f);
1783 const mi::math::Vector<mi::Float32, 3> right_3d(1.0f, 0.0f, 0.0f);
1784 const mi::math::Vector<mi::Float32, 3> up_3d (0.0f, 0.0f, -1.0f);
1785 label_3d->set_geometry(label_3d_position, right_3d, up_3d, 50.0f, 400.0f);
1786 const mi::neuraylib::Tag label_3d_tag = dice_transaction->store_for_reference_counting(label_3d.get());
1787 check_success(label_3d_tag.is_valid());
1788 group_labels->append(label_3d_tag, dice_transaction);
1789
1790 const mi::neuraylib::Tag group_labels_tag =
1791 dice_transaction->store_for_reference_counting(group_labels.get());
1792 check_success(group_labels_tag.is_valid());
1793 scene_edit->append(group_labels_tag, dice_transaction);
1794}
1795
1796//----------------------------------------------------------------------
1797void Multi_view_shape::add_scene_group_icons(
1798 nv::index::IScene* scene_edit,
1799 const std::map<std::string, mi::neuraylib::Tag>& light_mat_tag_map,
1800 mi::neuraylib::IDice_transaction* dice_transaction)
1801{
1802 // Icons (2D/3D)
1803 mi::base::Handle<nv::index::ITransformed_scene_group> group_icons(
1804 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1805 check_success(group_icons.is_valid_interface());
1806 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1807 1.0f, 0.0f, 0.0f, 0.0f,
1808 0.0f, 1.0f, 0.0f, 0.0f,
1809 0.0f, 0.0f, 1.0f, 0.0f,
1810 0.0f, 0.0f, 0.0f, 1.0f
1811 );
1812 group_icons->set_transform(transform_mat);
1813
1814 // texture_nvidia
1815 mi::base::Handle<nv::index::ITexture> tex(
1816 scene_edit->create_attribute<nv::index::ITexture>());
1817
1818 // Load the texture from a file
1819 mi::base::Handle<nv::index::app::image::IImage_importer> image_importer(
1820 get_application_layer_interface()->get_api_component<nv::index::app::image::IImage_importer>());
1821 check_success(image_importer.is_valid_interface());
1822 mi::base::Handle<mi::neuraylib::ICanvas> canvas(
1823 image_importer->create_canvas_from_file(m_iconfile.c_str()));
1824 check_success(canvas.is_valid_interface());
1825
1826 // Copy the pixel data
1827 check_success(tex->set_pixel_data(canvas.get(), nv::index::ITexture::RGBA_FLOAT32));
1828
1829 const mi::neuraylib::Tag tex_tag =
1830 dice_transaction->store_for_reference_counting(tex.get());
1831 check_success(tex_tag.is_valid());
1832 group_icons->append(tex_tag, dice_transaction);
1833
1834 // icon1
1835 {
1836 mi::base::Handle<nv::index::IIcon_3D> icon_3d(
1837 scene_edit->create_shape<nv::index::IIcon_3D>());
1838 check_success(icon_3d.is_valid_interface());
1839 const mi::math::Vector<mi::Float32, 3> position(-150.0f, 700.0f, 400.0f);
1840 const mi::math::Vector<mi::Float32, 3> right_vector(0.0f, -1.0f, 0.0f);
1841 const mi::math::Vector<mi::Float32, 3> up_vector (0.0f, 0.0f, -1.0f);
1842 icon_3d->set_geometry(position, right_vector, up_vector, 44.0f, 180.0f);
1843 const mi::neuraylib::Tag icon_3d_tag =
1844 dice_transaction->store_for_reference_counting(icon_3d.get());
1845 check_success(icon_3d_tag.is_valid());
1846 group_icons->append(icon_3d_tag, dice_transaction);
1847 }
1848
1849 // icon2
1850 {
1851 mi::base::Handle<nv::index::IIcon_2D> icon_2d(
1852 scene_edit->create_shape<nv::index::IIcon_2D>());
1853 check_success(icon_2d.is_valid_interface());
1854 const mi::math::Vector<mi::Float32, 3> position(520.0f, 0.0f, 80.0f);
1855 const mi::math::Vector<mi::Float32, 2> right_vector(1.0f, 0.0f);
1856 const mi::math::Vector<mi::Float32, 2> up_vector (0.0f, 1.0f);
1857 icon_2d->set_geometry(position, right_vector, up_vector, 44.0f, 180.0f);
1858 const mi::neuraylib::Tag icon_2d_tag =
1859 dice_transaction->store_for_reference_counting(icon_2d.get());
1860 check_success(icon_2d_tag.is_valid());
1861 group_icons->append(icon_2d_tag, dice_transaction);
1862 }
1863
1864 const mi::neuraylib::Tag group_icons_tag =
1865 dice_transaction->store_for_reference_counting(group_icons.get());
1866 check_success(group_icons_tag.is_valid());
1867 scene_edit->append(group_icons_tag, dice_transaction);
1868}
1869
1870//----------------------------------------------------------------------
1871void Multi_view_shape::setup_scene(mi::neuraylib::IDice_transaction* dice_transaction)
1872{
1873 check_success(dice_transaction != 0);
1874
1875 // Access the session instance from the database.
1876 mi::base::Handle<const nv::index::ISession> session(
1877 dice_transaction->access<const nv::index::ISession>(m_session_tag));
1878 check_success(session.is_valid_interface());
1879
1880 // Access (edit mode) the scene instance from the database.
1881 mi::base::Handle<nv::index::IScene> scene_edit(
1882 dice_transaction->edit<nv::index::IScene>(session->get_scene()));
1883 check_success(scene_edit.is_valid_interface());
1884
1885 std::map<std::string, mi::neuraylib::Tag> light_mat_tag_map;
1886 create_light_material_instance(scene_edit.get(), dice_transaction, light_mat_tag_map);
1887
1888 // Add a scene elements to the scene
1889 add_scene_defaut_light(scene_edit.get(), light_mat_tag_map, dice_transaction);
1890 add_scene_group_simple_geometry(scene_edit.get(), light_mat_tag_map, dice_transaction);
1891 add_scene_group_planes(scene_edit.get(), light_mat_tag_map, dice_transaction);
1892 add_scene_group_raster(scene_edit.get(), light_mat_tag_map, dice_transaction);
1893 add_scene_group_paths( scene_edit.get(), light_mat_tag_map, dice_transaction);
1894 add_scene_group_labels(scene_edit.get(), light_mat_tag_map, dice_transaction);
1895 add_scene_group_icons( scene_edit.get(), light_mat_tag_map, dice_transaction);
1896
1897 // Define a region of interest for the entire scene in the
1898 // scene's global coordinate system.
1899 const mi::math::Bbox<mi::Float32, 3> region_of_interest(
1900 -1000.0f, -1000.0f, -1000.0f,
1901 1300.0f, 1300.0f, 1300.0f
1902 );
1903 scene_edit->set_clipped_bounding_box(region_of_interest);
1904
1905 // Set the scene global transformation matrix.
1906 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1907 1.0f, 0.0f, 0.0f, 0.0f,
1908 0.0f, 1.0f, 0.0f, 0.0f,
1909 0.0f, 0.0f, 1.0f, 0.0f,
1910 0.0f, 0.0f, 0.0f, 1.0f
1911 );
1912
1913 scene_edit->set_transform_matrix(transform_mat);
1914
1915 // Create a camera
1916 mi::base::Handle< nv::index::IPerspective_camera > cam(
1917 scene_edit->create_camera<nv::index::IPerspective_camera>());
1918 check_success(cam.is_valid_interface());
1919 m_camera_tag = dice_transaction->store(cam.get());
1920 check_success(m_camera_tag.is_valid());
1921
1922 // set up the camera (default camera parameter)
1923 setup_camera(m_camera_tag, dice_transaction);
1924
1925 // ... and add the camera to the scene.
1926 scene_edit->set_camera(m_camera_tag);
1927}
1928
1929//----------------------------------------------------------------------
1930bool Multi_view_shape::setup_main_host()
1931{
1932 // Access the IndeX rendering query interface for querying performance values and pick results
1933 m_cluster_configuration =
1934 get_index_interface()->get_api_component<nv::index::ICluster_configuration>();
1935 check_success(m_cluster_configuration.is_valid_interface());
1936
1937 // create image canvas in application_layer
1938 m_image_file_canvas = create_image_file_canvas(get_application_layer_interface());
1939 check_success(m_image_file_canvas.is_valid_interface());
1940
1941 // Verifying that local host has joined
1942 // This may fail when there is a license problem.
1943 check_success(is_local_host_joined(m_cluster_configuration.get()));
1944
1945 // DiCE database access
1946 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
1947 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
1948 check_success(dice_transaction.is_valid_interface());
1949 {
1950 //----------------------------------------------------------------------
1951 // Setup session information
1952 m_session_tag =
1953 m_index_session->create_session(dice_transaction.get());
1954 check_success(m_session_tag.is_valid());
1955 mi::base::Handle<const nv::index::ISession> session(
1956 dice_transaction->access<nv::index::ISession>(
1957 m_session_tag));
1958 check_success(session.is_valid_interface());
1959
1960 // Setup the main multiple views, but it is empty at here.
1961 m_viewport_list = session->create_viewport_list();
1962 check_success(m_viewport_list.is_valid_interface());
1963
1964 //----------------------------------------------------------------------
1965 // Scene setup in the global scope
1966 setup_scene(dice_transaction.get());
1967 }
1968 dice_transaction->commit();
1969
1970 // set canvas size
1971 const mi::math::Vector<mi::Uint32, 2> buffer_resolution(512, 512);
1972 m_image_file_canvas->set_resolution(buffer_resolution);
1973
1974 INFO_LOG << "Initialization complete.";
1975
1976 return true;
1977}
1978
1979//----------------------------------------------------------------------
1980// This example shows how to use multiview functionality with non-massive shapes
1981int main(int argc, const char* argv[])
1982{
1983 nv::index::app::String_dict sdict;
1984 sdict.insert("dice::verbose", "4"); // log level
1985 sdict.insert("font_fpath", "/usr/share/fonts/dejavu/DejaVuSans.ttf"); // font path
1986 sdict.insert("iconfile", "../create_icons/nvidia_logo.ppm");
1987 sdict.insert("outfname", "frame_multi_view_shape"); // output file base name
1988 sdict.insert("verify_image_path_base", ""); // for unit test
1989 sdict.insert("unittest", "0"); // unit test mode
1990 sdict.insert("enable_vidx_vec", "1 1 1 1"); // enabled view indices vector
1991
1992 // Load IndeX library via Index_connect
1993 sdict.insert("dice::network::mode", "OFF");
1994
1995 // index setting
1996 sdict.insert("index::config::set_monitor_performance_values", "true");
1997 sdict.insert("index::service", "rendering_and_compositing");
1998 sdict.insert("index::cuda_debug_checks", "false");
1999
2000 // application_layer component loading
2001 sdict.insert("index::app::components::application_layer::component_name_list",
2002 "canvas_infrastructure image io data_analysis_and_processing" );
2003
2004 // Initialize application
2005 Multi_view_shape multi_view_shape;
2006 multi_view_shape.initialize(argc, argv, sdict);
2007 check_success(multi_view_shape.is_initialized());
2008
2009 // launch the application. creating the scene and rendering.
2010 const mi::Sint32 exit_code = multi_view_shape.launch();
2011 INFO_LOG << "Shutting down ...";
2012
2013 return exit_code;
2014}
virtual bool initialize_networking(mi::neuraylib::INetwork_configuration *network_configuration, nv::index::app::String_dict &options) CPP11_OVERRIDE
virtual bool evaluate_options(nv::index::app::String_dict &sdict) CPP11_OVERRIDE
virtual ~Multi_view_shape()
int main(int argc, const char *argv[])
#define check_success(expr)