NVIDIA Index example code nvidia_logo_transpbg.gif Up
multi_view_volume.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/icolormap.h>
15#include <nv/index/ifont.h>
16#include <nv/index/iindex.h>
17#include <nv/index/ilabel.h>
18#include <nv/index/ilight.h>
19#include <nv/index/imaterial.h>
20#include <nv/index/iscene.h>
21#include <nv/index/isession.h>
22#include <nv/index/isparse_volume_rendering_properties.h>
23#include <nv/index/iviewport.h>
24
25#include <nv/index/app/index_connect.h>
26#include <nv/index/app/string_dict.h>
27
28#include "utility/app_rendering_context.h"
29#include "utility/canvas_utility.h"
30
31#include <sstream>
32#include <iostream>
33
34//----------------------------------------------------------------------
36 public nv::index::app::Index_connect
37{
38public:
40 :
41 Index_connect()
42 {
43 // INFO_LOG << "DEBUG: Multi_view_volume() ctor";
44 }
45
47 {
48 // Note: Index_connect::~Index_connect() will be called after here.
49 // INFO_LOG << "DEBUG: ~Multi_view_volume() dtor";
50 }
51
52 // launch application
53 mi::Sint32 launch();
54
55protected:
56 virtual bool evaluate_options(nv::index::app::String_dict& sdict) CPP11_OVERRIDE;
57 // override
59 mi::neuraylib::INetwork_configuration* network_configuration,
60 nv::index::app::String_dict& options) CPP11_OVERRIDE
61 {
62 check_success(network_configuration != 0);
63
64 check_success(options.is_defined("unittest"));
65 const bool is_unittest = nv::index::app::get_bool(options.get("unittest"));
66 if (is_unittest)
67 {
68 info_cout("NETWORK: disabled networking mode.", options);
69 network_configuration->set_mode(mi::neuraylib::INetwork_configuration::MODE_OFF);
70 return true;
71 }
72
73 return initialize_networking_as_default_udp(network_configuration, options);
74 }
75
76private:
77 // Setup camera to see this example scene
78 // \param[in] camera_tag camera tag
79 // \param[in] dice_transaction dice transaction
80 void setup_camera(
81 const mi::neuraylib::Tag& camera_tag,
82 mi::neuraylib::IDice_transaction* dice_transaction) const;
83 // Localize scene elements
84 void localize_scene_element();
85 // Filter enable viewport index list
86 // \return newly created filtered viewport list
87 nv::index::IViewport_list* filter_enabled_viewport_index_list();
88 // Render one frame
89 // \param[in] frame_idx current frame index
90 // \return true when success
91 bool render_one_frame(mi::Sint32 frame_idx);
92 // Create multiple viewports
93 //
94 // The view structure of this example
95 //
96 // +-----------------+-----------------+(512,512)
97 // | viewport 0 | viewport 1 |
98 // | global scope | camera change |
99 // (0,256)+-----------------+-----------------+(512,256)
100 // | viewport 2 | viewport 3 |
101 // | | |
102 // +-----------------+-----------------+
103 // (0,0) (256,0) (512,0)
104 //
105 //
106 // \param[in,out] arc application rendering context. multiple views will be updated.
107 void create_views();
108
109 // Create a synthetic volume.
110 //
111 // \note The new volume is not added to the hierachical scene description.
112 //
113 // \param[in] scene scene root object to update the scene
114 // \param[in] volume_size volume size to be created
115 // \param[in] dice_transaction dice db transaction
116 // \return tag of the newly created volume
117 mi::neuraylib::Tag create_synthetic_sparse_volume(
118 nv::index::IScene* scene,
119 const mi::math::Vector<mi::Uint32, 3>& volume_size,
120 mi::neuraylib::IDice_transaction* dice_transaction) const;
121
122 // Add a label
123 //
124 // \param[in] scene_edit the editable IndeX scene
125 // \param[in] group_node parent group node
126 // \param[in] label_point label's corner position in the object space
127 // \param[in] label_str label contents string
128 // \param[in] label_height label height in the object space
129 // \param[in] label_width label width in the object space
130 // \param[in] fg_col label foreground color
131 // \param[in] bg_col label background color
132 // \param[in] opt_map command line option map
133 // \param[in] dice_transaction db transaction
134 // \return created label tag
135 mi::neuraylib::Tag create_append_label_to_group(
136 nv::index::IScene* scene_edit,
137 nv::index::ITransformed_scene_group* group_node,
138 const mi::math::Vector<mi::Float32, 3>& label_point,
139 const std::string& label_str,
140 const mi::Float32 label_height,
141 const mi::Float32 label_width,
142 const mi::math::Color_struct& fg_col,
143 const mi::math::Color_struct& bg_col,
144 mi::neuraylib::IDice_transaction* dice_transaction) const;
145 // Set up the scene
146 // Create a scene that contains a synthetically generated volume.
147 // \param[in] volume_size volume size to be created
148 // \param[in] dice_transaction DiCE db transaction
149 void setup_scene(
150 const mi::math::Vector<mi::Uint32, 3>& volume_size,
151 mi::neuraylib::IDice_transaction* dice_transaction);
152 // Set up as the main host
153 // \return true when success
154 bool setup_main_host();
155
156 // This session tag
157 mi::neuraylib::Tag m_session_tag;
158 // NVIDIA IndeX cluster configuration
159 mi::base::Handle<nv::index::ICluster_configuration> m_cluster_configuration;
160 // Application layer image file canvas (a render target)
161 mi::base::Handle<nv::index::app::canvas_infrastructure::IIndex_image_file_canvas> m_image_file_canvas;
162 // Create_icons options
163 std::string m_outfname;
164 bool m_is_unittest;
165 std::string m_verify_image_path_base;
166 std::string m_font_fpath;
167 std::string m_iconfile;
168 std::vector<bool> m_enable_view_idx_vec;
169 // camera tag
170 mi::neuraylib::Tag m_camera_tag;
171 // volume scene element tag
172 mi::neuraylib::Tag m_volume_tag;
173 // colormap 1 tag
174 mi::neuraylib::Tag m_colormap_1_tag;
175 // colormap 40 tag
176 mi::neuraylib::Tag m_colormap_40_tag;
177 // static group node tag for volume
178 mi::neuraylib::Tag m_static_group_node_tag;
179 // label group node tag
180 mi::neuraylib::Tag m_label_group_node_tag;
181 // label tag vector
182 std::vector<mi::neuraylib::Tag> m_label_tag_vec;
183 mi::base::Handle<nv::index::IViewport_list> m_viewport_list;
184};
185
186//----------------------------------------------------------------------
188{
189 // Set up
190 {
191 // const std::string enable_vidx_str = sdict.get("enable_vidx_vec");
192 // const std::vector<bool> enable_vidx_vec = get_bool_vec_from_string(enable_vidx_str);
193 check_success(setup_main_host());
194
195 // Create multiple views in the arc.
196 create_views();
197
198 mi::Sint32 frame_idx = 0;
199 // Render multiple views for a single render call. Before localize.
200 {
201 // Render a frame and save the rendered image to a file.
202 const bool is_success = render_one_frame(frame_idx);
203 check_success(is_success);
204 ++frame_idx;
205 }
206
207 // localize scene elements
208 localize_scene_element();
209
210 // Render multiple views for a single render call.
211 {
212 // Render a frame and save the rendered image to a file.
213 const bool is_success = render_one_frame(frame_idx);
214 check_success(is_success);
215 ++frame_idx;
216 }
217 }
218 return 0;
219}
220
221//----------------------------------------------------------------------
222bool Multi_view_volume::evaluate_options(nv::index::app::String_dict& sdict)
223{
224 const std::string com_name = sdict.get("command:", "<unknown_command>");
225 m_is_unittest = nv::index::app::get_bool(sdict.get("unittest", "false"));
226 if (m_is_unittest)
227 {
228 sdict.insert("dice::verbose", "2");
229 }
230 m_outfname = sdict.get("outfname");
231 m_verify_image_path_base = sdict.get("verify_image_path_base");
232 m_enable_view_idx_vec = get_bool_vec_from_string(sdict.get("enable_vidx_vec"));
233 m_font_fpath = sdict.get("font_fpath");
234 m_iconfile = sdict.get("iconfile");
235
236 info_cout("running " + com_name, sdict);
237 info_cout("outfname = [" + m_outfname +
238 "], verify_image_path_base = [" + m_verify_image_path_base +
239 "], dice::verbose = " + sdict.get("dice::verbose"), sdict);
240
241 // print help and exit if -h
242 if (sdict.is_defined("h"))
243 {
244 std::cout
245 << "info: Usage: " << com_name << " [option]\n"
246 << "Option: [-h]\n"
247 << " print out this message\n"
248 << " [-dice::verbose severity_level]\n"
249 << " verbose severity level (3 is info). (default: " + sdict.get("dice::verbose")
250 << ")\n"
251
252 << " [-font_fpath FONT_FILE_PATH]\n"
253 << " font file path. (default: " << m_font_fpath << ")\n"
254
255 << " [-outfname string]\n"
256 << " output ppm file base name. When empty, no output.\n"
257 << " A frame number and extension (.ppm) will be added.\n"
258 << " (default: [" << m_outfname << "])\n"
259
260 << " [-verify_image_path_base image path basename]\n"
261 << " when image_fname path basename exist, verify the rendering images.\n"
262 << " (default: [" << m_verify_image_path_base << "])\n"
263
264 << " [-unittest bool]\n"
265 << " when true, unit test mode. "
266 << "(default: [" << m_is_unittest << "])\n"
267
268 << " [-enable_vidx_vec enabled_vector]\n"
269 << " Specify which viewport is enabled by a bool vector.\n"
270 << " (default: [" << sdict.get("enable_vidx_vec") << "])"
271
272 << std::endl;
273 exit(1);
274 }
275 return true;
276}
277
278//----------------------------------------------------------------------
279void Multi_view_volume::setup_camera(
280 const mi::neuraylib::Tag& camera_tag,
281 mi::neuraylib::IDice_transaction* dice_transaction) const
282{
283 check_success(camera_tag.is_valid());
284
285 mi::base::Handle<nv::index::IPerspective_camera> cam(
286 dice_transaction->edit<nv::index::IPerspective_camera>(camera_tag));
287 check_success(cam.is_valid_interface());
288
289 // Set the camera parameters to see the whole scene
290 const mi::math::Vector<mi::Float32, 3> from(300.0f, 300.0f, 1000.0f);
291 mi::math::Vector<mi::Float32, 3> dir ( 0.0f, 0.0f, -1.0f);
292 const mi::math::Vector<mi::Float32, 3> up ( 0.0f, 1.0f, 0.0f);
293 dir.normalize();
294
295 cam->set(from, dir, up);
296 cam->set_aperture(0.033f);
297 cam->set_aspect(1.0f);
298 cam->set_focal(0.03f);
299 cam->set_clip_min(2.0f);
300 cam->set_clip_max(1000.0f);
301}
302
303//----------------------------------------------------------------------
304void Multi_view_volume::localize_scene_element()
305{
306 check_success(m_viewport_list.is_valid_interface());
307
308 // Process local views first.
309
310 // Set up viewport 1: enable the label 1 and change the camera
311 {
312 const mi::Size view_idx = 1;
313 check_success(m_viewport_list->size() > view_idx);
314
315 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
316 check_success(viewport != 0);
317
318 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
319 check_success(cur_scope);
320 check_success(std::string(cur_scope->get_id()) == "1");
321
322 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
323 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
324 check_success(dice_transaction.is_valid_interface());
325
326 // localize and edit scene elements
327 {
328 //----- localize
329 // localize the scene group containing the volume
330 mi::Sint32 ret_localize = 1;
331 ret_localize = dice_transaction->localize(m_static_group_node_tag,
332 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
333 check_success(ret_localize == 0);
334
335 // localize labels
336 for (mi::Size i = 0; i < m_label_tag_vec.size(); ++i)
337 {
338 ret_localize = dice_transaction->localize(m_label_tag_vec[i],
339 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
340 check_success(ret_localize == 0);
341 }
342
343 // localize colormap
344 ret_localize = dice_transaction->localize(m_colormap_1_tag,
345 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
346 check_success(ret_localize == 0);
347 ret_localize = dice_transaction->localize(m_colormap_40_tag,
348 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
349 check_success(ret_localize == 0);
350
351 // localize camera
352 ret_localize = dice_transaction->localize(m_camera_tag,
353 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
354 check_success(ret_localize == 0);
355
356
357 //----- edit
358 // edit disable the scene group containing the volume
359 {
360 // edit the scene group in order to disable it
361 mi::base::Handle<nv::index::IStatic_scene_group> static_group_node(
362 dice_transaction->edit<nv::index::IStatic_scene_group>(
363 m_static_group_node_tag));
364 check_success(static_group_node.is_valid_interface());
365
366 static_group_node->set_enabled(false);
367 }
368
369 // edit labels
370 for (mi::Size i = 0; i < m_label_tag_vec.size(); ++i)
371 {
372 mi::base::Handle<nv::index::ILabel_3D> label(
373 dice_transaction->edit<nv::index::ILabel_3D>(m_label_tag_vec[i]));
374 check_success(label.is_valid_interface());
375 if (i == view_idx)
376 {
377 label->set_enabled(true);
378 label->set_text("View 1: right");
379 }
380 else
381 {
382 label->set_enabled(false);
383 }
384 }
385
386 // edit camera
387 {
388 mi::base::Handle<nv::index::ICamera> cam(
389 dice_transaction->edit<nv::index::ICamera>(m_camera_tag));
390 check_success(cam.is_valid_interface());
391
392 const mi::math::Vector<mi::Float32, 3> from( 0.0f, 300.0f, 1000.0f);
393 mi::math::Vector<mi::Float32, 3> dir ( 0.5f, 0.0f, -1.0f);
394 const mi::math::Vector<mi::Float32, 3> up ( 0.0f, 1.0f, 0.0f);
395 dir.normalize();
396
397 cam->set(from, dir, up);
398 }
399
400 // edit colormap
401 {
402 mi::base::Handle<nv::index::IColormap> colormap_1(
403 dice_transaction->edit<nv::index::IColormap>(m_colormap_1_tag));
404 colormap_1->set_enabled(true);
405 mi::base::Handle<nv::index::IColormap> colormap_40(
406 dice_transaction->edit<nv::index::IColormap>(m_colormap_40_tag));
407 colormap_40->set_enabled(false);
408 }
409 }
410 dice_transaction->commit();
411 }
412
413 // Set up viewport 2: enable the label 2 and change the camera and colormap
414 {
415 const mi::Size view_idx = 2;
416 check_success(m_viewport_list->size() > view_idx);
417
418 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
419 check_success(viewport != 0);
420
421 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
422 check_success(cur_scope);
423 check_success(std::string(cur_scope->get_id()) == "2");
424
425 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
426 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
427 check_success(dice_transaction.is_valid_interface());
428
429 mi::base::Handle<const nv::index::ISession> session(
430 dice_transaction->access<nv::index::ISession>(m_session_tag));
431 check_success(session.is_valid_interface());
432
433 // localize scene elements
434 {
435 //----- Localize
436 // localize the scene root element
437 mi::Sint32 ret_localize = 1;
438 ret_localize = dice_transaction->localize(session->get_scene(),
439 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
440 check_success(ret_localize == 0);
441
442 // localize labels
443 for (mi::Size i = 0; i < m_label_tag_vec.size(); ++i)
444 {
445 ret_localize = dice_transaction->localize(m_label_tag_vec[i],
446 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
447 check_success(ret_localize == 0);
448 }
449
450 // localize colormap
451 ret_localize = dice_transaction->localize(m_colormap_1_tag,
452 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
453 check_success(ret_localize == 0);
454 ret_localize = dice_transaction->localize(m_colormap_40_tag,
455 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
456 check_success(ret_localize == 0);
457
458 // localize camera, volume scene element
459 ret_localize = dice_transaction->localize(m_camera_tag,
460 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
461 check_success(ret_localize == 0);
462
463 // localize volume
464 ret_localize = dice_transaction->localize(m_volume_tag,
465 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
466 check_success(ret_localize == 0);
467
468 //----- Edit
469 // change the region of interest of the scene
470 {
471 mi::base::Handle<nv::index::IScene> scene(
472 dice_transaction->edit<nv::index::IScene>(session->get_scene()));
473 check_success(scene.is_valid_interface());
474
475 // modify the region of interest
476 mi::math::Bbox<mi::Float32, 3> roi(scene->get_clipped_bounding_box());
477 roi.max.x = 700.f; // larger than before
478 roi.min.y = 200.f; // smaller so that the label is visible
479 scene->set_clipped_bounding_box(roi);
480 }
481
482 // edit labels
483 for (mi::Size i = 0; i < m_label_tag_vec.size(); ++i)
484 {
485 mi::base::Handle<nv::index::ILabel_3D> label(
486 dice_transaction->edit<nv::index::ILabel_3D>(m_label_tag_vec[i]));
487 check_success(label.is_valid_interface());
488 if (i == view_idx)
489 {
490 label->set_enabled(true);
491 label->set_text("View 2: left");
492 }
493 else
494 {
495 label->set_enabled(false);
496 }
497 }
498
499 // edit camera and volume scene element
500 {
501 mi::base::Handle<nv::index::ICamera> cam(
502 dice_transaction->edit<nv::index::ICamera>(m_camera_tag));
503 check_success(cam.is_valid_interface());
504
505 const mi::math::Vector<mi::Float32, 3> from(600.0f, 300.0f, 1000.0f);
506 mi::math::Vector<mi::Float32, 3> dir ( -0.5f, 0.0f, -1.0f);
507 const mi::math::Vector<mi::Float32, 3> up ( 0.0f, 1.0f, 0.0f);
508 dir.normalize();
509
510 cam->set(from, dir, up);
511 }
512
513 // edit colormap
514 {
515 mi::base::Handle<nv::index::IColormap> colormap_1(
516 dice_transaction->edit<nv::index::IColormap>(m_colormap_1_tag));
517 colormap_1->set_enabled(false);
518 mi::base::Handle<nv::index::IColormap> colormap_40(
519 dice_transaction->edit<nv::index::IColormap>(m_colormap_40_tag));
520 colormap_40->set_enabled(true);
521 }
522 }
523 dice_transaction->commit();
524 }
525
526 // Set up viewport 3: enable the label 3 and change the camera
527 {
528 const mi::Size view_idx = 3;
529 check_success(m_viewport_list->size() > view_idx);
530
531 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
532 check_success(viewport != 0);
533
534 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
535 check_success(cur_scope);
536 check_success(std::string(cur_scope->get_id()) == "3");
537
538 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
539 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
540 check_success(dice_transaction.is_valid_interface());
541
542 // localize scene elements
543 {
544 //----- Localize
545 mi::Sint32 ret_localize = 1;
546 // localize labels
547 for (mi::Size i = 0; i < m_label_tag_vec.size(); ++i)
548 {
549 ret_localize = dice_transaction->localize(m_label_tag_vec[i],
550 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
551 check_success(ret_localize == 0);
552 }
553
554 // localize colormap
555 ret_localize = dice_transaction->localize(m_colormap_1_tag,
556 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
557 check_success(ret_localize == 0);
558 ret_localize = dice_transaction->localize(m_colormap_40_tag,
559 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
560 check_success(ret_localize == 0);
561
562 // localize camera
563 ret_localize = dice_transaction->localize(m_camera_tag,
564 mi::neuraylib::IDice_transaction::LOCAL_SCOPE);
565 check_success(ret_localize == 0);
566
567 //----- Edit
568 // edit labels
569 for (mi::Size i = 0; i < m_label_tag_vec.size(); ++i)
570 {
571 mi::base::Handle<nv::index::ILabel_3D> label(
572 dice_transaction->edit<nv::index::ILabel_3D>(m_label_tag_vec[i]));
573 check_success(label.is_valid_interface());
574 if (i == view_idx)
575 {
576 label->set_enabled(true);
577 label->set_text("View 3: Zoom");
578 }
579 else
580 {
581 label->set_enabled(false);
582 }
583 }
584
585 // edit camera
586 {
587 mi::base::Handle<nv::index::ICamera> cam(
588 dice_transaction->edit<nv::index::ICamera>(m_camera_tag));
589 check_success(cam.is_valid_interface());
590
591 const mi::math::Vector<mi::Float32, 3> from(300.0f, 300.0f, 700.0f);
592 mi::math::Vector<mi::Float32, 3> dir ( 0.0f, 0.0f, -1.0f);
593 const mi::math::Vector<mi::Float32, 3> up ( 0.0f, 1.0f, 0.0f);
594 dir.normalize();
595
596 cam->set(from, dir, up);
597 }
598
599 // edit colormap
600 {
601 mi::base::Handle<nv::index::IColormap> colormap_1(
602 dice_transaction->edit<nv::index::IColormap>(m_colormap_1_tag));
603 colormap_1->set_enabled(true);
604 mi::base::Handle<nv::index::IColormap> colormap_40(
605 dice_transaction->edit<nv::index::IColormap>(m_colormap_40_tag));
606 colormap_40->set_enabled(false);
607 }
608
609 }
610 dice_transaction->commit();
611 }
612
613 // Set up viewport 0 with the global scope: disable labels
614 {
615 const mi::Size view_idx = 0;
616 check_success(m_viewport_list->size() > view_idx);
617
618 mi::base::Handle<nv::index::IViewport> viewport(m_viewport_list->get(view_idx));
619 check_success(viewport != 0);
620
621 mi::base::Handle<mi::neuraylib::IScope> cur_scope(viewport->get_scope());
622 check_success(cur_scope);
623 check_success(std::string(cur_scope->get_id()) == "0");
624
625 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
626 cur_scope->create_transaction<mi::neuraylib::IDice_transaction>());
627 check_success(dice_transaction.is_valid_interface());
628
629 // edit scene elements
630 {
631 // edit labels
632 for (mi::Size i = 0; i < m_label_tag_vec.size(); ++i)
633 {
634 mi::base::Handle<nv::index::ILabel_3D> label(
635 dice_transaction->edit<nv::index::ILabel_3D>(m_label_tag_vec[i]));
636 check_success(label.is_valid_interface());
637
638 if (i == view_idx)
639 {
640 // label->set_text("View 0");
641 }
642 else
643 {
644 label->set_enabled(false);
645 }
646 }
647 }
648 // edit colormap
649 {
650 mi::base::Handle<nv::index::IColormap> colormap_1(
651 dice_transaction->edit<nv::index::IColormap>(m_colormap_1_tag));
652 colormap_1->set_enabled(true);
653 mi::base::Handle<nv::index::IColormap> colormap_40(
654 dice_transaction->edit<nv::index::IColormap>(m_colormap_40_tag));
655 colormap_40->set_enabled(false);
656 }
657
658 dice_transaction->commit();
659 }
660}
661
662//----------------------------------------------------------------------
663nv::index::IViewport_list* Multi_view_volume::filter_enabled_viewport_index_list()
664{
665 mi::base::Handle<nv::index::IViewport_list> new_viewport_list;
666 {
667 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
668 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
669 assert(dice_transaction.is_valid_interface());
670 {
671 assert(m_session_tag.is_valid());
672 mi::base::Handle<const nv::index::ISession> session(
673 dice_transaction->access<nv::index::ISession>(m_session_tag));
674 assert(session.is_valid_interface());
675
676 // create viewport from a session
677 new_viewport_list = session->create_viewport_list();
678 }
679 dice_transaction->commit();
680 }
681
682 check_success(new_viewport_list.is_valid_interface());
683 const mi::Size nb_views = m_viewport_list->size();
684
685 std::stringstream sstr;
686 mi::Size nb_enabled = 0;
687 for (mi::Size i = 0; i < nb_views; ++i)
688 {
689 if (m_enable_view_idx_vec[i])
690 {
691 sstr << i << " ";
692 mi::base::Handle<nv::index::IViewport> vp (m_viewport_list->get(i));
693 new_viewport_list->append(vp.get());
694 ++nb_enabled;
695 }
696 }
697 // copy advisory state
698 new_viewport_list->set_advisory_enabled(m_viewport_list->get_advisory_enabled());
699
700 if (nb_enabled == nb_views)
701 {
702 INFO_LOG << "All views are enabled.";
703 }
704 else
705 {
706 INFO_LOG << "Filtered views. Enabled: " << sstr.str();
707 }
708
709 new_viewport_list->retain();
710 return new_viewport_list.get();
711}
712
713//----------------------------------------------------------------------
714bool Multi_view_volume::render_one_frame(mi::Sint32 frame_idx)
715{
716 bool success = true;
717
718 // Render a frame and save the rendered image to a file.
719 // Only save the file at the end of the iteration.
720 std::string fname = "";
721 if (!(m_outfname.empty()))
722 {
723 fname = get_output_file_name(m_outfname, frame_idx);
724 }
725 check_success(m_index_rendering.is_valid_interface());
726
727 // set up canvas. output_fname.empty() is valid (no output file)
728 m_image_file_canvas->set_rgba_file_name(fname.c_str());
729
730 // set advisory to see the multiview rendering details
731 m_viewport_list->set_advisory_enabled(true);
732
733 mi::base::Handle<nv::index::IViewport_list> cur_viewport_list(
734 filter_enabled_viewport_index_list());
735 check_success(cur_viewport_list.is_valid_interface());
736
737 mi::base::Handle<nv::index::IFrame_results_list> frame_results_list(
738 m_index_rendering->render(
739 m_session_tag,
740 m_image_file_canvas.get(),
741 cur_viewport_list.get()));
742 check_success(frame_results_list.is_valid_interface());
743
744 if (frame_results_list->size() == 0)
745 {
746 ERROR_LOG << "IIndex_rendering rendering call has no results.";
747 success = false;
748 }
749 else
750 {
751 for (mi::Size i = 0; i < frame_results_list->size(); ++i)
752 {
753 mi::base::Handle<nv::index::IFrame_results>
754 frame_results(frame_results_list->get(i));
755 check_success(frame_results.is_valid_interface());
756
757 const mi::base::Handle<nv::index::IError_set> err_set(frame_results->get_error_set());
758 check_success(err_set.is_valid_interface());
759 if (err_set->any_errors())
760 {
761 std::ostringstream os;
762
763 const mi::base::Handle<nv::index::IError_set> err_set(frame_results->get_error_set());
764 const mi::Uint32 nb_err = err_set->get_nb_errors();
765 for (mi::Uint32 e = 0; e < nb_err; ++e)
766 {
767 if (e != 0) os << '\n';
768 const mi::base::Handle<nv::index::IError> err(err_set->get_error(e));
769 os << err->get_error_string();
770 }
771
772 ERROR_LOG << "IIndex_rendering rendering call failed with the following error(s): " << '\n'
773 << os.str();
774 success = false;
775 }
776 else
777 {
778 // print some performance values
779 const mi::base::Handle<nv::index::IPerformance_values> performance_values(
780 frame_results->get_performance_values());
781
782 const mi::Float32 rendering_time = performance_values->get_time("time_total_rendering") / 1000.f;
783 const mi::Float32 compositing_time = performance_values->get_time("time_total_compositing") / 1000.f;
784
785
786 INFO_LOG << "--------------------------------------------";
787 INFO_LOG << " Frame: " << frame_idx << ", Viewport: " << i;
788 INFO_LOG << "--------------------------------------------";
789 INFO_LOG << "Rendering time : " << rendering_time << " [sec]";
790 INFO_LOG << "Compositing time : " << compositing_time << " [sec]";
791 }
792 }
793 }
794
795 // verify the generated frame
796 if (!(m_verify_image_path_base.empty()))
797 {
798 const std::string ref_img_fpath = get_output_file_name(m_verify_image_path_base, frame_idx);
799 if (!(verify_canvas_result(get_application_layer_interface(),
800 m_image_file_canvas.get(), ref_img_fpath, get_options())))
801 {
802 success = false;
803 }
804 }
805
806 return success;
807}
808
809//----------------------------------------------------------------------
810void Multi_view_volume::create_views()
811{
812 // Check session and multiple views in the arc
813 check_success(m_session_tag.is_valid());
814 check_success(m_viewport_list.is_valid_interface());
815 check_success(m_viewport_list->size() == 0);
816
817 // Multiple view itself lives in the global scope.
818 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(create_transaction());
819 check_success(dice_transaction.is_valid_interface());
820 {
821 mi::base::Handle<const nv::index::ISession> session(
822 dice_transaction->access<nv::index::ISession>(m_session_tag));
823 check_success(session.is_valid_interface());
824
825 // 0. create a single viewport in the global scope.
826 {
827 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
828 check_success(viewport.is_valid_interface());
829
830 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 0, 256);
831 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
832
833 viewport->set_position(viewport_pos);
834 viewport->set_size(viewport_size);
835 viewport->set_scope(m_global_scope.get()); // ref count up
836
837 m_viewport_list->append(viewport.get());
838 }
839
840 // 1. viewport
841 {
842 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
843 check_success(viewport.is_valid_interface());
844
845 mi::neuraylib::IScope* parent = 0; // this means global scope in this context
846 mi::Uint8 privacy_level = 1;
847 bool is_temp = false;
848 mi::base::Handle<mi::neuraylib::IScope> local_scope(m_database->create_scope(parent, privacy_level, is_temp));
849 check_success(local_scope.is_valid_interface());
850
851 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 256, 256);
852 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
853
854 viewport->set_position(viewport_pos);
855 viewport->set_size(viewport_size);
856 viewport->set_scope(local_scope.get()); // ref count up
857
858 m_viewport_list->append(viewport.get());
859 }
860
861 // 2. viewport
862 {
863 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
864 check_success(viewport.is_valid_interface());
865
866 mi::neuraylib::IScope* parent = 0; // this means global scope in this context
867 mi::Uint8 privacy_level = 1;
868 bool is_temp = false;
869 mi::base::Handle<mi::neuraylib::IScope> local_scope(m_database->create_scope(parent, privacy_level, is_temp));
870 check_success(local_scope.is_valid_interface());
871
872 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 0, 0);
873 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
874
875 viewport->set_position(viewport_pos);
876 viewport->set_size(viewport_size);
877 viewport->set_scope(local_scope.get()); // ref count up
878
879 m_viewport_list->append(viewport.get());
880 }
881
882 // 3. viewport
883 {
884 mi::base::Handle<nv::index::IViewport> viewport(session->create_viewport());
885 check_success(viewport.is_valid_interface());
886
887 mi::neuraylib::IScope* parent = 0; // this means global scope in this context
888 mi::Uint8 privacy_level = 1;
889 bool is_temp = false;
890 mi::base::Handle<mi::neuraylib::IScope> local_scope(m_database->create_scope(parent, privacy_level, is_temp));
891 check_success(local_scope.is_valid_interface());
892
893 const mi::math::Vector<mi::Sint32, 2> viewport_pos( 256, 0);
894 const mi::math::Vector<mi::Sint32, 2> viewport_size(256, 256);
895
896 viewport->set_position(viewport_pos);
897 viewport->set_size(viewport_size);
898 viewport->set_scope(local_scope.get()); // ref count up
899
900 m_viewport_list->append(viewport.get());
901 }
902 }
903 dice_transaction->commit();
904}
905
906//----------------------------------------------------------------------
907mi::neuraylib::Tag Multi_view_volume::create_synthetic_sparse_volume(
908 nv::index::IScene* scene,
909 const mi::math::Vector<mi::Uint32, 3>& volume_size,
910 mi::neuraylib::IDice_transaction* dice_transaction) const
911{
912 mi::math::Bbox<mi::Float32, 3> ijk_bbox;
913 ijk_bbox.min.x = 0.0f;
914 ijk_bbox.min.y = 0.0f;
915 ijk_bbox.min.z = 0.0f;
916 ijk_bbox.max.x = static_cast<mi::Float32>(volume_size.x);
917 ijk_bbox.max.y = static_cast<mi::Float32>(volume_size.y);
918 ijk_bbox.max.z = static_cast<mi::Float32>(volume_size.z);
919
920 // sparse volume creation parameter
921 nv::index::app::String_dict sparse_volume_opt;
922 sparse_volume_opt.insert("args::type", "sparse_volume");
923 sparse_volume_opt.insert("args::importer", "synthetic");
924 std::stringstream sstr;
925 sstr << "0 0 0 " << volume_size.x << " " << volume_size.y << " " << volume_size.z;
926 sparse_volume_opt.insert("args::bbox", sstr.str());
927 sparse_volume_opt.insert("args::voxel_format", "uint8");
928 sparse_volume_opt.insert("args::synthetic_type", "sphere_0");
929 nv::index::IDistributed_data_import_callback* importer_callback =
930 get_importer_from_application_layer(
931 get_application_layer_interface(),
932 "nv::index::plugin::base_importer.Sparse_volume_generator_synthetic",
933 sparse_volume_opt);
934
935 // Create the sparse volume scene element
936 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(1.0f); // Identity matrix
937 const mi::math::Vector<mi::Float32, 3> scale(1.0f, 1.0f, 1.0f);
938 const mi::Float32 rotate_k = 0.0f;
939 const mi::math::Vector<mi::Float32, 3> translate(0.0f, 0.0f, 0.0f);
940 const bool is_rendering_enabled = true;
941
942 mi::base::Handle<nv::index::ISparse_volume_scene_element> sparse_volume(
943 scene->create_sparse_volume(ijk_bbox, transform_mat, importer_callback, dice_transaction));
944 check_success(sparse_volume.is_valid_interface());
945 sparse_volume->set_enabled(is_rendering_enabled);
946
947 DEBUG_LOG << "setup_imported_volume: "
948 << "size: " << volume_size.x << " " << volume_size.y << " " << volume_size.z << " "
949 << ", scale: " << scale.x << " " << scale.y << " " << scale.z << " "
950 << ", rotate_k: " << rotate_k
951 << ", translate: " << translate.x << " " << translate.y << " " << translate.z << " "
952 << ", is_rendering_enabled: " << is_rendering_enabled
953 ;
954
955 const mi::neuraylib::Tag sparse_volume_tag =
956 dice_transaction->store_for_reference_counting(sparse_volume.get());
957 check_success(sparse_volume_tag.is_valid());
958
959 INFO_LOG << "Creating a synthetic volume: size = [" << volume_size.x
960 << " " << volume_size.y << " " << volume_size.z << "], tag = " << sparse_volume_tag.id;
961 INFO_LOG << "This will take a while...";
962
963 return sparse_volume_tag;
964}
965
966//----------------------------------------------------------------------
967mi::neuraylib::Tag Multi_view_volume::create_append_label_to_group(
968 nv::index::IScene* scene_edit,
969 nv::index::ITransformed_scene_group* group_node,
970 const mi::math::Vector<mi::Float32, 3>& label_point,
971 const std::string& label_str,
972 const mi::Float32 label_height,
973 const mi::Float32 label_width,
974 const mi::math::Color_struct& fg_col,
975 const mi::math::Color_struct& bg_col,
976 mi::neuraylib::IDice_transaction* dice_transaction) const
977{
978 check_success(scene_edit != 0);
979 check_success(group_node != 0);
980
981 // Add font to the scene description
982 mi::base::Handle<nv::index::IFont> font(scene_edit->create_attribute<nv::index::IFont>());
983 check_success(font.is_valid_interface());
984
985 if (font->set_file_name(m_font_fpath.c_str()))
986 {
987 INFO_LOG << "set the font path [" << m_font_fpath << "]";
988 }
989 else
990 {
991 ERROR_LOG << "Can not find the font path [" << m_font_fpath << "], "
992 << "the rendering result may not correct.";
993 }
994 font->set_font_resolution(64.0f);
995 const mi::neuraylib::Tag font_tag = dice_transaction->store_for_reference_counting(font.get());
996 INFO_LOG << "Created a font: tag: " << font_tag;
997 check_success(font_tag.is_valid());
998 group_node->append(font_tag, dice_transaction);
999
1000 // Add a label
1001 mi::neuraylib::Tag label_tag;
1002 {
1003 mi::base::Handle<nv::index::ILabel_layout> label_layout(
1004 scene_edit->create_attribute<nv::index::ILabel_layout>());
1005 check_success(label_layout.is_valid_interface());
1006 const mi::Float32 padding = 20.0f;
1007 label_layout->set_padding(padding);
1008 label_layout->set_color(fg_col, bg_col);
1009 const mi::neuraylib::Tag label_layout_tag =
1010 dice_transaction->store_for_reference_counting(label_layout.get());
1011 INFO_LOG << "Created a label_layout: tag: " << label_layout_tag;
1012 check_success(label_layout_tag.is_valid());
1013 group_node->append(label_layout_tag, dice_transaction);
1014
1015 mi::base::Handle<nv::index::ILabel_3D> label(scene_edit->create_shape<nv::index::ILabel_3D>());
1016 check_success(label.is_valid_interface());
1017 label->set_text(label_str.c_str());
1018
1019 const mi::math::Vector<mi::Float32, 3> right(1.0f, 0.0f, 0.0f);
1020 const mi::math::Vector<mi::Float32, 3> up (0.0f, 1.0f, 0.0f);
1021 label->set_geometry(label_point, right, up, label_height, label_width);
1022 label_tag = dice_transaction->store_for_reference_counting(label.get());
1023 INFO_LOG << "Created a label: tag: " << label_tag;
1024 check_success(label_tag.is_valid());
1025 group_node->append(label_tag, dice_transaction);
1026 }
1027 return label_tag;
1028}
1029
1030//----------------------------------------------------------------------
1031void Multi_view_volume::setup_scene(
1032 const mi::math::Vector<mi::Uint32, 3>& volume_size,
1033 mi::neuraylib::IDice_transaction* dice_transaction)
1034{
1035 check_success(dice_transaction != 0);
1036
1037 // Create a scene that contains a synthetically generated volume.
1038
1039 // Access the session instance from the database.
1040 mi::base::Handle<const nv::index::ISession> session(
1041 dice_transaction->access<const nv::index::ISession>(m_session_tag));
1042 check_success(session.is_valid_interface());
1043
1044 // Access (edit mode) the scene instance from the database.
1045 mi::base::Handle<nv::index::IScene> scene_edit(
1046 dice_transaction->edit<nv::index::IScene>(session->get_scene()));
1047 check_success(scene_edit.is_valid_interface());
1048
1049 // Create static group node for large data
1050 mi::base::Handle<nv::index::IStatic_scene_group> static_group_node(
1051 scene_edit->create_scene_group<nv::index::IStatic_scene_group>());
1052 check_success(static_group_node.is_valid_interface());
1053
1054 // Added a light and a material to the static group node
1055 {
1056 // Add a light
1057 mi::base::Handle<nv::index::IDirectional_headlight> headlight(
1058 scene_edit->create_attribute<nv::index::IDirectional_headlight>());
1059 check_success(headlight.is_valid_interface());
1060 const mi::math::Color color_intensity(1.0f, 1.0f, 1.0f, 1.0f);
1061 headlight->set_intensity(color_intensity);
1062 headlight->set_direction(mi::math::Vector<mi::Float32, 3>(1.0f, -1.0f, -1.0f));
1063
1064 const mi::neuraylib::Tag headlight_tag = dice_transaction->store_for_reference_counting(headlight.get());
1065 check_success(headlight_tag.is_valid());
1066 static_group_node->append(headlight_tag, dice_transaction);
1067 INFO_LOG << "Created a headlight: tag = " << headlight_tag.id;
1068
1069 // Add a sparse_volume_render_properties to the scene.
1070 mi::base::Handle<nv::index::ISparse_volume_rendering_properties> sparse_render_prop(
1071 scene_edit->create_attribute<nv::index::ISparse_volume_rendering_properties>());
1072 sparse_render_prop->set_filter_mode(nv::index::SPARSE_VOLUME_FILTER_NEAREST);
1073 sparse_render_prop->set_sampling_distance( 1.0);
1074 sparse_render_prop->set_reference_sampling_distance( 1.0);
1075 sparse_render_prop->set_voxel_offsets( mi::math::Vector<mi::Float32, 3>(0.0f, 0.0f, 0.0f));
1076 sparse_render_prop->set_preintegrated_volume_rendering(false);
1077 sparse_render_prop->set_lod_rendering_enabled( false);
1078 sparse_render_prop->set_lod_pixel_threshold( 2.0);
1079 sparse_render_prop->set_debug_visualization_option( 0);
1080 const mi::neuraylib::Tag sparse_render_prop_tag
1081 = dice_transaction->store_for_reference_counting(sparse_render_prop.get());
1082 check_success(sparse_render_prop_tag.is_valid());
1083 static_group_node->append(sparse_render_prop_tag, dice_transaction);
1084 INFO_LOG << "Created a sparse_render_prop_tag: tag = " << sparse_render_prop_tag;
1085
1086 // Create two colormaps. To see the colormap 1 in the first
1087 // frame, the order is 40 -> 1. Because we render, localize & edit, render.
1088 {
1089 const mi::Sint32 colormap_entry_id = 40; // same as demo application's colormap file 40
1090 const mi::neuraylib::Tag colormap_40_tag =
1091 create_colormap(colormap_entry_id, scene_edit.get(), dice_transaction);
1092 check_success(colormap_40_tag.is_valid());
1093 check_success(((!m_colormap_40_tag.is_valid())));
1094 m_colormap_40_tag = colormap_40_tag; // record tag
1095 static_group_node->append(colormap_40_tag, dice_transaction);
1096 INFO_LOG << "Created colormap_40: " << colormap_40_tag;
1097 }
1098 {
1099 const mi::Sint32 colormap_entry_id = 1; // same as demo application's colormap file 1, orange
1100 const mi::neuraylib::Tag colormap_1_tag =
1101 create_colormap(colormap_entry_id, scene_edit.get(), dice_transaction);
1102 check_success(colormap_1_tag.is_valid());
1103 m_colormap_1_tag = colormap_1_tag; // record tag
1104 static_group_node->append(colormap_1_tag, dice_transaction);
1105 INFO_LOG << "Created colormap_1: " << colormap_1_tag;
1106 }
1107 }
1108
1109 // Add a synthetic volume to the scene.
1110 {
1111 check_success(!m_volume_tag.is_valid())
1112 m_volume_tag =
1113 create_synthetic_sparse_volume(
1114 scene_edit.get(),
1115 volume_size,
1116 dice_transaction);
1117 check_success(m_volume_tag.is_valid());
1118
1119 INFO_LOG << "Creating a synthetic volume: size = [" << volume_size.x
1120 << " " << volume_size.y << " " << volume_size.z << "], tag = "
1121 << m_volume_tag.id;
1122 INFO_LOG << "This would take a while...";
1123
1124 // Append the volume to the scene group
1125 static_group_node->append(m_volume_tag, dice_transaction);
1126
1127
1128 mi::neuraylib::Tag static_group_node_tag =
1129 dice_transaction->store_for_reference_counting(static_group_node.get());
1130 check_success(static_group_node_tag.is_valid());
1131 check_success(!m_static_group_node_tag.is_valid());
1132 m_static_group_node_tag = static_group_node_tag;
1133
1134 scene_edit->append(static_group_node_tag, dice_transaction);
1135
1136 std::stringstream sstr;
1137 sstr << "Created an synthetic volume: size = "
1138 << volume_size << ", tag = " << m_volume_tag.id;
1139 INFO_LOG << sstr.str();
1140 }
1141
1142 // Create and add labels
1143 {
1144 // Add a scene group where the shapes should be added
1145 mi::base::Handle<nv::index::ITransformed_scene_group> label_group_node(
1146 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
1147 check_success(label_group_node.is_valid_interface());
1148
1149 // Add a material
1150 {
1151 // Add a fully ambient material for the planes, so that lighting doesn't matter
1152 mi::math::Color ambient_color (1.0f, 1.0f, 1.0f, 1.0f);
1153 mi::math::Color diffuse_color (0.0f, 0.0f, 0.0f, 1.0f);
1154 mi::math::Color specular_color(0.0f, 0.0f, 0.0f, 1.0f);
1155 mi::Float32 shiness = 100.0f;
1156 mi::base::Handle<nv::index::IPhong_gl> phong_1(
1157 scene_edit->create_attribute<nv::index::IPhong_gl>());
1158 check_success(phong_1.is_valid_interface());
1159 phong_1->set_ambient(ambient_color);
1160 phong_1->set_diffuse(diffuse_color);
1161 phong_1->set_specular(specular_color);
1162 phong_1->set_shininess(shiness);
1163
1164 mi::neuraylib::Tag phong_1_tag = dice_transaction->store_for_reference_counting(phong_1.get());
1165 INFO_LOG << "Created phong for labels: tag: " << phong_1_tag;
1166 check_success(phong_1_tag.is_valid());
1167 label_group_node->append(phong_1_tag, dice_transaction);
1168 }
1169
1170 mi::math::Color_struct fg_col; fg_col.r = 0.25f; fg_col.g = 0.95f; fg_col.b = 0.25f; fg_col.a = 1.0f;
1171 mi::math::Color_struct bg_col; bg_col.r = 0.4f; bg_col.g = 0.5f; bg_col.b = 0.4f; bg_col.a = 0.5f;
1172
1173 m_label_tag_vec.clear();
1174 mi::math::Vector<mi::Float32, 3> label_pos (10.0f, -250.0f, 10.0f);
1175 std::string str = "View 0";
1176 const mi::Float32 width = -1.0f; // automated width
1177 mi::neuraylib::Tag created_label =
1178 create_append_label_to_group(scene_edit.get(), label_group_node.get(), label_pos, str,
1179 100.0f, width, fg_col, bg_col, dice_transaction);
1180 check_success(created_label);
1181 m_label_tag_vec.push_back(created_label);
1182
1183 label_pos.y += 150.0f;
1184 str = "View 1";
1185 created_label =
1186 create_append_label_to_group(scene_edit.get(), label_group_node.get(), label_pos, str,
1187 100.0f, width, fg_col, bg_col, dice_transaction);
1188 check_success(created_label.is_valid());
1189 m_label_tag_vec.push_back(created_label);
1190
1191 label_pos.y += 150.0f;
1192 str = "View 2";
1193 created_label =
1194 create_append_label_to_group(scene_edit.get(), label_group_node.get(), label_pos, str,
1195 100.0f, width, fg_col, bg_col, dice_transaction);
1196 check_success(created_label.is_valid());
1197 m_label_tag_vec.push_back(created_label);
1198
1199 label_pos.y += 150.0f;
1200 str = "View 3";
1201 created_label =
1202 create_append_label_to_group(scene_edit.get(), label_group_node.get(), label_pos, str,
1203 100.0f, width, fg_col, bg_col, dice_transaction);
1204 check_success(created_label.is_valid());
1205 m_label_tag_vec.push_back(created_label);
1206
1207 // Finally append everything to the root of the hierachical scene description
1208 const mi::neuraylib::Tag label_group_node_tag =
1209 dice_transaction->store_for_reference_counting(label_group_node.get());
1210 check_success(label_group_node_tag.is_valid());
1211 INFO_LOG << "Created a label_group: " << label_group_node_tag;
1212
1213 check_success(label_group_node_tag.is_valid());
1214 scene_edit->append(label_group_node_tag, dice_transaction);
1215 m_label_group_node_tag = label_group_node_tag;
1216 }
1217
1218 // Define a region of interest for the entire scene in the
1219 // scene's global coordinate system.
1220 const mi::math::Bbox<mi::Float32, 3> region_of_interest(
1221 0.0f, 0.0f, 0.0f,
1222 static_cast<mi::Float32>(volume_size.x),
1223 static_cast<mi::Float32>(volume_size.y),
1224 static_cast<mi::Float32>(volume_size.z));
1225
1226 // Set the region of interest
1227 check_success(region_of_interest.is_volume());
1228 scene_edit->set_clipped_bounding_box(region_of_interest);
1229
1230 // Set the scene global transformation matrix.
1231 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
1232 1.0f, 0.0f, 0.0f, 0.0f,
1233 0.0f, 1.0f, 0.0f, 0.0f,
1234 0.0f, 0.0f, 1.0f, 0.0f,
1235 0.0f, 0.0f, 0.0f, 1.0f
1236 );
1237
1238 scene_edit->set_transform_matrix(transform_mat);
1239
1240 // Create a camera
1241 mi::base::Handle< nv::index::IPerspective_camera > cam(
1242 scene_edit->create_camera<nv::index::IPerspective_camera>());
1243 check_success(cam.is_valid_interface());
1244 m_camera_tag = dice_transaction->store(cam.get());
1245 check_success(m_camera_tag.is_valid());
1246
1247 // set up the camera
1248 setup_camera(m_camera_tag, dice_transaction);
1249
1250 // ... and add the camera to the scene.
1251 scene_edit->set_camera(m_camera_tag);
1252}
1253
1254//----------------------------------------------------------------------
1255bool Multi_view_volume::setup_main_host()
1256{
1257 // Access the IndeX rendering query interface for querying performance values and pick results
1258 m_cluster_configuration =
1259 get_index_interface()->get_api_component<nv::index::ICluster_configuration>();
1260 check_success(m_cluster_configuration.is_valid_interface());
1261
1262 // create image canvas in application_layer
1263 m_image_file_canvas = create_image_file_canvas(get_application_layer_interface());
1264 check_success(m_image_file_canvas.is_valid_interface());
1265
1266 // Verifying that local host has joined
1267 // This may fail when there is a license problem.
1268 check_success(is_local_host_joined(m_cluster_configuration.get()));
1269
1270 // DiCE database access
1271 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
1272 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
1273 check_success(dice_transaction.is_valid_interface());
1274 {
1275 //----------------------------------------------------------------------
1276 // Setup session information
1277 m_session_tag =
1278 m_index_session->create_session(dice_transaction.get());
1279 check_success(m_session_tag.is_valid());
1280 mi::base::Handle<const nv::index::ISession> session(
1281 dice_transaction->access<nv::index::ISession>(
1282 m_session_tag));
1283 check_success(session.is_valid_interface());
1284
1285 // Setup the main multiple views, but it is empty at here.
1286 m_viewport_list = session->create_viewport_list();
1287 check_success(m_viewport_list.is_valid_interface());
1288
1289 // Enable monitoring of performance values.
1290 mi::base::Handle<nv::index::IConfig_settings> config_settings(
1291 dice_transaction->edit<nv::index::IConfig_settings>(session->get_config()));
1292 check_success(config_settings.is_valid_interface());
1293 config_settings->set_monitor_performance_values(true);
1294 config_settings->set_automatic_span_control(true);
1295 config_settings->set_max_spans_per_machine(8);
1296
1297
1298 //----------------------------------------------------------------------
1299 // Scene setup in the global scope
1300 mi::math::Vector<mi::Uint32, 3> volume_size(600, 600, 32);
1301 setup_scene(volume_size, dice_transaction.get());
1302 }
1303 dice_transaction->commit();
1304
1305 // set canvas size
1306 const mi::math::Vector<mi::Uint32, 2> buffer_resolution(512, 512);
1307 m_image_file_canvas->set_resolution(buffer_resolution);
1308
1309 INFO_LOG << "Initialization complete.";
1310
1311 return true;
1312}
1313
1314//----------------------------------------------------------------------
1315// This example shows how to use multi-view functionality with a volume
1316int main(int argc, const char* argv[])
1317{
1318 nv::index::app::String_dict sdict;
1319 sdict.insert("dice::verbose", "4"); // log level
1320 sdict.insert("font_fpath", "/usr/share/fonts/dejavu/DejaVuSans.ttf"); // font path
1321 sdict.insert("outfname", "frame_multi_view_volume"); // output file base name
1322 sdict.insert("verify_image_path_base", ""); // for unit test
1323 sdict.insert("unittest", "0"); // unit test mode
1324 sdict.insert("enable_vidx_vec", "1 1 1 1"); // enabled view indices vector
1325
1326 // Load IndeX library via Index_connect
1327 sdict.insert("dice::network::mode", "OFF");
1328
1329 // index setting
1330 sdict.insert("index::config::set_monitor_performance_values", "true");
1331 sdict.insert("index::service", "rendering_and_compositing");
1332 sdict.insert("index::cuda_debug_checks", "false");
1333
1334 // application_layer component loading
1335 sdict.insert("index::app::components::application_layer::component_name_list",
1336 "canvas_infrastructure image io");
1337 sdict.insert("index::app::plugins::base_importer::enabled", "true");
1338
1339 // Initialize application
1340 Multi_view_volume multi_view_volume;
1341 multi_view_volume.initialize(argc, argv, sdict);
1342 check_success(multi_view_volume.is_initialized());
1343
1344 // launch the application. creating the scene and rendering.
1345 const mi::Sint32 exit_code = multi_view_volume.launch();
1346 INFO_LOG << "Shutting down ...";
1347
1348 return exit_code;
1349}
virtual bool evaluate_options(nv::index::app::String_dict &sdict) CPP11_OVERRIDE
virtual bool initialize_networking(mi::neuraylib::INetwork_configuration *network_configuration, nv::index::app::String_dict &options) CPP11_OVERRIDE
int main(int argc, const char *argv[])
#define check_success(expr)