NVIDIA Index example code nvidia_logo_transpbg.gif Up
create_polygons.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/iindex.h>
13#include <nv/index/isession.h>
14#include <nv/index/iscene.h>
15#include <nv/index/icamera.h>
16#include <nv/index/ipolygon.h>
17
18#include <nv/index/app/index_connect.h>
19#include <nv/index/app/string_dict.h>
20
21#include "utility/canvas_utility.h"
22
23#include <iostream>
24#include <sstream>
25
26//----------------------------------------------------------------------
28 public nv::index::app::Index_connect
29{
30public:
32 :
33 Index_connect()
34 {
35 // INFO_LOG << "DEBUG: Create_polygons() ctor";
36 }
37
39 {
40 // Note: Index_connect::~Index_connect() will be called after here.
41 // INFO_LOG << "DEBUG: ~Create_polygons() dtor";
42 }
43
44 // launch application
45 mi::Sint32 launch();
46
47protected:
48 virtual bool evaluate_options(nv::index::app::String_dict& sdict) CPP11_OVERRIDE;
49 // override
51 mi::neuraylib::INetwork_configuration* network_configuration,
52 nv::index::app::String_dict& options) CPP11_OVERRIDE
53 {
54 check_success(network_configuration != 0);
55
56 check_success(options.is_defined("unittest"));
57 const bool is_unittest = nv::index::app::get_bool(options.get("unittest"));
58 if (is_unittest)
59 {
60 info_cout("NETWORK: disabled networking mode.", options);
61 network_configuration->set_mode(mi::neuraylib::INetwork_configuration::MODE_OFF);
62 return true;
63 }
64
65 return initialize_networking_as_default_udp(network_configuration, options);
66 }
67
68private:
69 // Create polygons in the scene.
70 bool create_polygons(
71 nv::index::IScene* scene_edit,
72 mi::neuraylib::IDice_transaction* dice_transaction) const;
73
74 // setup camera to see this example scene
75 //
76 // \param[in] cam a camera
77 void setup_camera(nv::index::IPerspective_camera* cam) const;
78
79 // render a frame
80 // \param[in] output_fname output rendering image filename
81 // \return performance values
82 nv::index::IFrame_results* render_frame(const std::string& output_fname) const;
83
84 // This session tag
85 mi::neuraylib::Tag m_session_tag;
86 // NVIDIA IndeX cluster configuration
87 mi::base::Handle<nv::index::ICluster_configuration> m_cluster_configuration;
88 // Application layer image file canvas (a render target)
89 mi::base::Handle<nv::index::app::canvas_infrastructure::IIndex_image_file_canvas> m_image_file_canvas;
90 // Create_icons options
91 std::string m_outfname;
92 bool m_is_unittest;
93 std::string m_verify_image_fname;
94};
95
96//----------------------------------------------------------------------
98{
99 mi::Sint32 exit_code = 0;
100
101 // Get DiCE database components
102 {
103 m_cluster_configuration =
104 get_index_interface()->get_api_component<nv::index::ICluster_configuration>();
105 check_success(m_cluster_configuration.is_valid_interface());
106
107 // create image canvas in application_layer
108 m_image_file_canvas = create_image_file_canvas(get_application_layer_interface());
109 check_success(m_image_file_canvas.is_valid_interface());
110
111 // Verifying that local host has joined
112 // This may fail when there is a license problem.
113 check_success(is_local_host_joined(m_cluster_configuration.get()));
114
115 {
116 // DiCE database access
117 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
118 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
119 check_success(dice_transaction.is_valid_interface());
120 {
121 // Setup session information
122 m_session_tag =
123 m_index_session->create_session(dice_transaction.get());
124 check_success(m_session_tag.is_valid());
125 mi::base::Handle< nv::index::ISession const > session(
126 dice_transaction->access< nv::index::ISession const >(
127 m_session_tag));
128 check_success(session.is_valid_interface());
129
130 mi::base::Handle< nv::index::IScene > scene_edit(
131 dice_transaction->edit< nv::index::IScene >(session->get_scene()));
132 check_success(scene_edit.is_valid_interface());
133
134 //----------------------------------------------------------------------
135 // Scene setup: add polygon shape, scene parameters, camera.
136 //----------------------------------------------------------------------
137 // Add polygon shapes to the scene
138 check_success(create_polygons(scene_edit.get(), dice_transaction.get()));
139
140 // Create and edit a camera. Data distribution is based on
141 // the camera. (Because only visible massive data are
142 // considered)
143 mi::base::Handle< nv::index::IPerspective_camera > cam(
144 scene_edit->create_camera<nv::index::IPerspective_camera>());
145 check_success(cam.is_valid_interface());
146 setup_camera(cam.get());
147 const mi::neuraylib::Tag camera_tag = dice_transaction->store(cam.get());
148 check_success(camera_tag.is_valid());
149
150 const mi::math::Vector<mi::Uint32, 2> buffer_resolution(1025, 1024);
151 m_image_file_canvas->set_resolution(buffer_resolution);
152
153 // Set up the scene
154 mi::math::Bbox_struct< mi::Float32, 3 > const xyz_roi_st = {
155 { 0.0f, 0.0f, 0.0f, },
156 { 500.0f, 500.0f, 500.0f, },
157 };
158
159 // set the region of interest
160 const mi::math::Bbox< mi::Float32, 3 > xyz_roi(xyz_roi_st);
161 check_success(xyz_roi.is_volume());
162 scene_edit->set_clipped_bounding_box(xyz_roi_st);
163
164 // Set the scene global transformation matrix.
165 // only change the coordinate system
166 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
167 1.0f, 0.0f, 0.0f, 0.0f,
168 0.0f, 1.0f, 0.0f, 0.0f,
169 0.0f, 0.0f, -1.0f, 0.0f,
170 0.0f, 0.0f, 0.0f, 1.0f
171 );
172 scene_edit->set_transform_matrix(transform_mat);
173
174 // Set the current camera to the scene.
175 check_success(camera_tag.is_valid());
176 scene_edit->set_camera(camera_tag);
177 }
178 dice_transaction->commit();
179 }
180
181 // Rendering
182 {
183 const std::string fname = get_output_file_name(m_outfname, 0);
184 mi::base::Handle<nv::index::IFrame_results> frame_results(render_frame(fname));
185 const mi::base::Handle<nv::index::IError_set> err_set(frame_results->get_error_set());
186 if (err_set->any_errors())
187 {
188 std::ostringstream os;
189 const mi::Uint32 nb_err = err_set->get_nb_errors();
190 for (mi::Uint32 e = 0; e < nb_err; ++e)
191 {
192 if (e != 0) os << '\n';
193 const mi::base::Handle<nv::index::IError> err(err_set->get_error(e));
194 os << err->get_error_string();
195 }
196
197 ERROR_LOG << "IIndex_rendering rendering call failed with the following error(s): " << '\n'
198 << os.str();
199 exit_code = 1;
200 }
201
202
203 // verify the generated frame
204 if (!(verify_canvas_result(get_application_layer_interface(),
205 m_image_file_canvas.get(), m_verify_image_fname, get_options())))
206 {
207 exit_code = 1;
208 }
209 }
210 }
211
212 return exit_code;
213}
214
215//----------------------------------------------------------------------
216bool Create_polygons::evaluate_options(nv::index::app::String_dict& sdict)
217{
218 const std::string com_name = sdict.get("command:", "<unknown_command>");
219 m_is_unittest = nv::index::app::get_bool(sdict.get("unittest", "false"));
220
221 if (m_is_unittest)
222 {
223 if (nv::index::app::get_bool(sdict.get("is_call_from_test", "false")))
224 {
225 sdict.insert("is_dump_comparison_image_when_failed", "0");
226 }
227 sdict.insert("outfname", ""); // turn off file output in the unit test mode
228 sdict.insert("dice::verbose", "2");
229 }
230
231
232 // Set own options
233 m_outfname = sdict.get("outfname", "");
234 m_verify_image_fname = sdict.get("verify_image_fname", "");
235
236 info_cout(std::string("running ") + com_name, sdict);
237 info_cout("outfname = [" + m_outfname +
238 "], verify_image_fname = [" + m_verify_image_fname +
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 << " printout 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 << " [-outfname string]\n"
253 << " output ppm file base name. When empty, no output.\n"
254 << " A frame number and extension (.ppm) will be added.\n"
255 << " (default: [" << sdict.get("outfname") << "])\n"
256 << " [-verify_image_fname [image_fname]]\n"
257 << " when image_fname exist, verify the rendering image. (default: ["
258 << m_verify_image_fname << "])\n"
259
260 << " [-unittest bool]\n"
261 << " when true, unit test mode (create smaller volume). "
262 << "(default: " << m_is_unittest << ")\n"
263
264 << " [-is_dump_comparison_image_when_failed bool]\n"
265 << " when true, dump the comparison images and generate the diff image for debug.\n"
266 << " You can also force to dump and set the filename.\n"
267 << " (default: " << sdict.get("is_dump_comparison_image_when_failed") << ")"
268 << std::endl;
269 exit(1);
270 }
271
272 return true;
273}
274
275//----------------------------------------------------------------------
276bool Create_polygons::create_polygons(
277 nv::index::IScene* scene_edit,
278 mi::neuraylib::IDice_transaction* dice_transaction) const
279{
280 check_success(scene_edit != 0);
281 check_success(dice_transaction != 0);
282
283 mi::base::Handle<nv::index::ITransformed_scene_group> group_node(
284 scene_edit->create_scene_group<nv::index::ITransformed_scene_group>());
285 check_success(group_node.is_valid_interface());
286
287 // create a pentagone
288 {
289 mi::base::Handle<nv::index::IPolygon> poly(scene_edit->create_shape<nv::index::IPolygon>());
290 check_success(poly.is_valid_interface());
291 mi::math::Vector_struct< mi::Float32, 3> pos;
292 pos.x = 40.f;
293 pos.y = 70.f;
294 pos.z = 30.f;
295
296 mi::Uint32 num_vertices = 5;
297 mi::math::Vector_struct< mi::Float32, 2> vertices[5];
298
299 const mi::Float32 delta_phi = (2.0f*static_cast<mi::Float32>(M_PI))/static_cast<mi::Float32>(num_vertices);
300 const mi::Float32 radius = 120.f;
301
302 for (mi::Uint32 i=0; i<num_vertices; i++)
303 {
304 mi::math::sincos(delta_phi*i, vertices[i].x, vertices[i].y);
305 vertices[i].x *= radius;
306 vertices[i].y *= radius;
307 }
308
309 // create polygon geometry
310 if (poly->set_geometry(vertices, num_vertices, pos))
311 {
312 INFO_LOG << "Pentagone created";
313
314 mi::math::Color_struct fill_color = {0.5f, 1.0f, 0.f, 1.f};
315
316 poly->set_fill_style(fill_color, nv::index::IPolygon::FILL_SOLID);
317
318 const mi::neuraylib::Tag poly_tag = dice_transaction->store_for_reference_counting(poly.get());
319 check_success(poly_tag.is_valid());
320 group_node->append(poly_tag, dice_transaction);
321 }
322 else
323 {
324 INFO_LOG << "Pentagone not created, bad shaped";
325 }
326 }
327
328 // create a star
329 {
330 mi::base::Handle<nv::index::IPolygon> poly(scene_edit->create_shape<nv::index::IPolygon>());
331 check_success(poly.is_valid_interface());
332 mi::math::Vector_struct< mi::Float32, 3> pos;
333 pos.x = 250.f;
334 pos.y = 70.f;
335 pos.z = 30.f;
336
337 mi::Uint32 num_vertices = 5;
338 mi::math::Vector_struct< mi::Float32, 2> vertices[10];
339
340 const mi::Float32 delta_phi = (2.0f * static_cast<mi::Float32>(M_PI)) / static_cast<mi::Float32 >(num_vertices);
341 const mi::Float32 radius = 120.f;
342 const mi::Float32 inner_radius = 80.f;
343
344 for (mi::Uint32 i=0; i<num_vertices; i++)
345 {
346 mi::math::sincos(delta_phi*i, vertices[2*i].x, vertices[2*i].y);
347 vertices[2*i].x *= radius;
348 vertices[2*i].y *= radius;
349
350 mi::math::sincos(delta_phi*(i+0.5f), vertices[2*i + 1].x, vertices[2*i + 1].y);
351 vertices[2*i + 1].x *= inner_radius;
352 vertices[2*i + 1].y *= inner_radius;
353 }
354
355 // create polygon geometry
356 if (poly->set_geometry(vertices, 2*num_vertices, pos))
357 {
358 INFO_LOG << "Star created";
359
360 mi::math::Color_struct fill_color = {0.39f, 0.58f, 0.93f, 1.f};
361
362 poly->set_fill_style(fill_color, nv::index::IPolygon::FILL_SOLID);
363
364 const mi::neuraylib::Tag poly_tag = dice_transaction->store_for_reference_counting(poly.get());
365 check_success(poly_tag.is_valid());
366 group_node->append(poly_tag, dice_transaction);
367 }
368 else
369 {
370 INFO_LOG << "Star not created, bad shaped";
371 }
372 }
373
374 // create a 8 spikes star
375 {
376 mi::base::Handle<nv::index::IPolygon> poly(scene_edit->create_shape<nv::index::IPolygon>());
377 check_success(poly.is_valid_interface());
378 mi::math::Vector_struct< mi::Float32, 3> pos;
379 pos.x = 460.f;
380 pos.y = 70.f;
381 pos.z = 30.f;
382
383 mi::Uint32 num_vertices = 8;
384 mi::math::Vector_struct< mi::Float32, 2> vertices[16];
385
386 const mi::Float32 delta_phi = (2.0f* static_cast<mi::Float32>(M_PI)) / static_cast<mi::Float32>(num_vertices);
387 const mi::Float32 radius = 120.f;
388 const mi::Float32 inner_radius = 60.f;
389
390 for (mi::Uint32 i=0; i<num_vertices; i++)
391 {
392 mi::math::sincos(delta_phi*i, vertices[2*i].x, vertices[2*i].y);
393 vertices[2*i].x *= radius;
394 vertices[2*i].y *= radius;
395
396 mi::math::sincos(delta_phi*(i+0.5f), vertices[2*i + 1].x, vertices[2*i + 1].y);
397 vertices[2*i + 1].x *= inner_radius;
398 vertices[2*i + 1].y *= inner_radius;
399 }
400
401 // create polygon geometry
402 if (poly->set_geometry(vertices, 2*num_vertices, pos))
403 {
404 INFO_LOG << "Star created";
405
406 mi::math::Color_struct fill_color = {0.39f, 0.58f, 0.93f, 1.f};
407
408 poly->set_fill_style(fill_color, nv::index::IPolygon::FILL_SOLID);
409
410 const mi::neuraylib::Tag poly_tag = dice_transaction->store_for_reference_counting(poly.get());
411 check_success(poly_tag.is_valid());
412 group_node->append(poly_tag, dice_transaction);
413 }
414 else
415 {
416 INFO_LOG << "Star not created, bad shaped";
417 }
418 }
419
420 // create a free shape: Cross
421 {
422 mi::base::Handle<nv::index::IPolygon> poly(scene_edit->create_shape<nv::index::IPolygon>());
423 check_success(poly.is_valid_interface());
424 mi::math::Vector_struct< mi::Float32, 3> pos;
425 pos.x = 40.f;
426 pos.y = 280.f;
427 pos.z = 30.f;
428
429 mi::Uint32 num_vertices = 12;
430 mi::math::Vector_struct< mi::Float32, 2> vertices[12];
431
432 vertices[0].x = -60.f;
433 vertices[0].y = 120.f;
434 vertices[1].x = -60.f;
435 vertices[1].y = 60.f;
436 vertices[2].x = -120.f;
437 vertices[2].y = 60.f;
438 vertices[3].x = -120.f;
439 vertices[3].y = -30.f;
440 vertices[4].x = -60.f;
441 vertices[4].y = -30.f;
442 vertices[5].x = -60.f;
443 vertices[5].y = -120.f;
444 vertices[6].x = 60.f;
445 vertices[6].y = -120.f;
446 vertices[7].x = 60.f;
447 vertices[7].y = -30.f;
448 vertices[8].x = 120.f;
449 vertices[8].y = -30.f;
450 vertices[9].x = 120.f;
451 vertices[9].y = 60.f;
452 vertices[10].x = 60.f;
453 vertices[10].y = 60.f;
454 vertices[11].x = 60.f;
455 vertices[11].y = 120.f;
456
457 // create polygon geometry
458 if (poly->set_geometry(vertices, num_vertices, pos))
459 {
460 INFO_LOG << "Cross created";
461
462 mi::math::Color_struct fill_color = {0.8f, 0.8f, 0.8f, 1.f};
463
464 poly->set_fill_style(fill_color, nv::index::IPolygon::FILL_SOLID);
465
466 const mi::neuraylib::Tag poly_tag = dice_transaction->store_for_reference_counting(poly.get());
467 check_success(poly_tag.is_valid());
468 group_node->append(poly_tag, dice_transaction);
469 }
470 else
471 {
472 INFO_LOG << "Cross not created, bad shaped";
473 }
474 }
475
476 // create a free shape: N
477 {
478 mi::base::Handle<nv::index::IPolygon> poly(scene_edit->create_shape<nv::index::IPolygon>());
479 check_success(poly.is_valid_interface());
480 mi::math::Vector_struct< mi::Float32, 3> pos;
481 pos.x = 250.f;
482 pos.y = 280.f;
483 pos.z = 30.f;
484
485 mi::Uint32 num_vertices = 10;
486 mi::math::Vector_struct< mi::Float32, 2> vertices[10];
487
488 vertices[0].x = -100.f;
489 vertices[0].y = -100.f;
490 vertices[1].x = -20.f;
491 vertices[1].y = -100.f;
492 vertices[2].x = -20.f;
493 vertices[2].y = -20.f;
494 vertices[3].x = 20.f;
495 vertices[3].y = -100.f;
496 vertices[4].x = 100.f;
497 vertices[4].y = -100.f;
498 vertices[5].x = 100.f;
499 vertices[5].y = 100.f;
500 vertices[6].x = 20.f;
501 vertices[6].y = 100.f;
502 vertices[7].x = 20.f;
503 vertices[7].y = 20.f;
504 vertices[8].x = -20.f;
505 vertices[8].y = 100.f;
506 vertices[9].x = -100.f;
507 vertices[9].y = 100.f;
508
509 // create polygon geometry
510 if (poly->set_geometry(vertices, num_vertices, pos))
511 {
512 INFO_LOG << "N created";
513
514 mi::math::Color_struct fill_color = {0.0f, 1.0f, 0.f, 1.f};
515
516 poly->set_fill_style(fill_color, nv::index::IPolygon::FILL_SOLID);
517
518 const mi::neuraylib::Tag poly_tag = dice_transaction->store_for_reference_counting(poly.get());
519 check_success(poly_tag.is_valid());
520 group_node->append(poly_tag, dice_transaction);
521 }
522 else
523 {
524 INFO_LOG << "N not created, bad shaped";
525 }
526 }
527
528 // create a free shape: Flash
529 {
530 mi::base::Handle<nv::index::IPolygon> poly(scene_edit->create_shape<nv::index::IPolygon>());
531 check_success(poly.is_valid_interface());
532 mi::math::Vector_struct< mi::Float32, 3> pos;
533 pos.x = 460.f;
534 pos.y = 280.f;
535 pos.z = 30.f;
536
537 mi::Uint32 num_vertices = 6;
538 mi::math::Vector_struct< mi::Float32, 2> vertices[6];
539
540 vertices[0].x = 0.f;
541 vertices[0].y = 0.f;
542 vertices[1].x = 0.f;
543 vertices[1].y = 40.f;
544 vertices[2].x = -80.f;
545 vertices[2].y = -40.f;
546 vertices[3].x = -20.f;
547 vertices[3].y = 0.f;
548 vertices[4].x = 0.f;
549 vertices[4].y = -40.f;
550 vertices[5].x = 80.f;
551 vertices[5].y = 60.f;
552
553 // create polygon geometry
554 if (poly->set_geometry(vertices, num_vertices, pos))
555 {
556 INFO_LOG << "Flash created";
557
558 mi::math::Color_struct fill_color = {0.0f, 1.0f, 0.f, 1.f};
559
560 poly->set_fill_style(fill_color, nv::index::IPolygon::FILL_SOLID);
561
562 const mi::neuraylib::Tag poly_tag = dice_transaction->store_for_reference_counting(poly.get());
563 check_success(poly_tag.is_valid());
564 group_node->append(poly_tag, dice_transaction);
565 }
566 else
567 {
568 INFO_LOG << "Flash not created, bad shaped";
569 }
570 }
571
572 // create a free shape: irregular shape
573 {
574 mi::base::Handle<nv::index::IPolygon> poly(scene_edit->create_shape<nv::index::IPolygon>());
575 check_success(poly.is_valid_interface());
576 mi::math::Vector_struct< mi::Float32, 3> pos;
577 pos.x = 240.f;
578 pos.y = 430.f;
579 pos.z = 30.f;
580
581 mi::Uint32 num_vertices = 26;
582 mi::math::Vector_struct< mi::Float32, 2> vertices[26];
583
584 vertices[0].x = 0.f;
585 vertices[0].y = -40.f;
586 vertices[1].x = 120.f;
587 vertices[1].y = -60.f;
588 vertices[2].x = 120.f;
589 vertices[2].y = -20.f;
590 vertices[3].x = 100.f;
591 vertices[3].y = -20.f;
592 vertices[4].x = 120.f;
593 vertices[4].y = 40.f;
594 vertices[5].x = 80.f;
595 vertices[5].y = 40.f;
596 vertices[6].x = 60.f;
597 vertices[6].y = -20.f;
598 vertices[7].x = 40.f;
599 vertices[7].y = -20.f;
600 vertices[8].x = 50.f;
601 vertices[8].y = 140.f;
602 vertices[9].x = 20.f;
603 vertices[9].y = 160.f;
604 vertices[10].x = -10.f;
605 vertices[10].y = 140.f;
606 vertices[11].x = 0.f;
607 vertices[11].y = 40.f;
608 vertices[12].x = -40.f;
609 vertices[12].y = 50.f;
610 vertices[13].x = -60.f;
611 vertices[13].y = 20.f;
612 vertices[14].x = -60.f;
613 vertices[14].y = -20.f;
614 vertices[15].x = -80.f;
615 vertices[15].y = -20.f;
616 vertices[16].x = -80.f;
617 vertices[16].y = 40.f;
618 vertices[17].x = -100.f;
619 vertices[17].y = 50.f;
620 vertices[18].x = -100.f;
621 vertices[18].y = -20.f;
622 vertices[19].x = -120.f;
623 vertices[19].y = -20.f;
624 vertices[20].x = -140.f;
625 vertices[20].y = -20.f;
626 vertices[21].x = -120.f;
627 vertices[21].y = 80.f;
628 vertices[22].x = -180.f;
629 vertices[22].y = 80.f;
630 vertices[23].x = -160.f;
631 vertices[23].y = -20.f;
632 vertices[24].x = -180.f;
633 vertices[24].y = -20.f;
634 vertices[25].x = -180.f;
635 vertices[25].y = -40.f;
636
637
638 // create polygon geometry
639 if (poly->set_geometry(vertices, num_vertices, pos))
640 {
641 INFO_LOG << "Irregular shape created";
642
643 mi::math::Color_struct fill_color = {1.0f, 0.25f, 0.f, 1.f};
644
645 poly->set_fill_style(fill_color, nv::index::IPolygon::FILL_SOLID);
646
647 const mi::neuraylib::Tag poly_tag = dice_transaction->store_for_reference_counting(poly.get());
648 check_success(poly_tag.is_valid());
649 group_node->append(poly_tag, dice_transaction);
650 }
651 else
652 {
653 INFO_LOG << "Irregular shape not created, bad shaped";
654 }
655 }
656
657 mi::neuraylib::Tag group_node_tag = dice_transaction->store_for_reference_counting(group_node.get());
658 check_success(group_node_tag.is_valid());
659 scene_edit->append(group_node_tag, dice_transaction);
660
661 return true;
662}
663
664//----------------------------------------------------------------------
665void Create_polygons::setup_camera(nv::index::IPerspective_camera* cam) const
666{
667 check_success(cam != 0);
668
669 // Set the camera parameters to see the whole scene
670 mi::math::Vector< mi::Float32, 3 > const from( 254.0f, 254.0f, 550.0f);
671 mi::math::Vector< mi::Float32, 3 > const to ( 255.0f, 255.0f, -255.0f);
672 mi::math::Vector< mi::Float32, 3 > const up ( 0.0f, 1.0f, 0.0f);
673 mi::math::Vector<mi::Float32, 3> viewdir = to - from;
674 viewdir.normalize();
675
676 cam->set(from, viewdir, up);
677 cam->set_aperture(0.033f);
678 cam->set_aspect(1.0f);
679 cam->set_focal(0.03f);
680 cam->set_clip_min(10.0f);
681 cam->set_clip_max(5000.0f);
682}
683
684//----------------------------------------------------------------------
685nv::index::IFrame_results* Create_polygons::render_frame(
686 const std::string& output_fname) const
687{
688 check_success(m_index_rendering.is_valid_interface());
689
690 // set output filename, empty string is valid
691 m_image_file_canvas->set_rgba_file_name(output_fname.c_str());
692
693 check_success(m_session_tag.is_valid());
694
695 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
696 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
697 check_success(dice_transaction.is_valid_interface());
698
699 m_index_session->update(m_session_tag, dice_transaction.get());
700
701 mi::base::Handle<nv::index::IFrame_results> frame_results(
702 m_index_rendering->render(
703 m_session_tag,
704 m_image_file_canvas.get(),
705 dice_transaction.get()));
706 check_success(frame_results.is_valid_interface());
707
708 dice_transaction->commit();
709
710 frame_results->retain();
711 return frame_results.get();
712}
713
714//----------------------------------------------------------------------
715// This example shows how to create polygons in the scene.
716int main(int argc, const char* argv[])
717{
718 nv::index::app::String_dict sdict;
719 sdict.insert("dice::verbose", "3"); // log level
720 sdict.insert("outfname", "frame_create_polygons"); // output file base name
721 sdict.insert("verify_image_fname", ""); // for unit test
722 sdict.insert("unittest", "0"); // default mode
723 sdict.insert("is_dump_comparison_image_when_failed", "1"); // default: dump images when failed.
724 sdict.insert("is_call_from_test", "0"); // default: not call from make check.
725
726 // Load IndeX library via Index_connect
727 sdict.insert("dice::network::mode", "OFF");
728
729 // index setting
730 sdict.insert("index::config::set_monitor_performance_values", "true");
731 sdict.insert("index::service", "rendering_and_compositing");
732 sdict.insert("index::cuda_debug_checks", "false");
733
734 // application_layer component loading
735 sdict.insert("index::app::components::application_layer::component_name_list",
736 "canvas_infrastructure image io");
737
738 // Initialize application
739 Create_polygons create_polygons;
740 create_polygons.initialize(argc, argv, sdict);
741 check_success(create_polygons.is_initialized());
742
743 // launch the application. creating the scene and rendering.
744 const mi::Sint32 exit_code = create_polygons.launch();
745 INFO_LOG << "Shutting down ...";
746
747 return exit_code;
748}
mi::Sint32 launch()
virtual ~Create_polygons()
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
int main(int argc, const char *argv[])
#define check_success(expr)