10#include "utility/example_shared.h"
14#include <nv/index/iindex.h>
15#include <nv/index/icamera.h>
16#include <nv/index/iconfig_settings.h>
17#include <nv/index/iintersection_highlighting.h>
18#include <nv/index/iintersection_highlight_pick_result.h>
19#include <nv/index/ilight.h>
20#include <nv/index/imaterial.h>
21#include <nv/index/iplane.h>
22#include <nv/index/iplane_pick_result.h>
23#include <nv/index/itriangle_mesh_scene_element.h>
24#include <nv/index/itriangle_mesh_query_results.h>
25#include <nv/index/iscene.h>
26#include <nv/index/iscene_group.h>
27#include <nv/index/isession.h>
28#include <nv/index/icolormap.h>
29#include <nv/index/itexture.h>
30#include <nv/index/ishading_model.h>
31#include <nv/index/itexture_filter_mode.h>
33#include <nv/index/app/idata_analysis_and_processing.h>
34#include <nv/index/app/index_connect.h>
35#include <nv/index/app/string_dict.h>
37#include "utility/app_rendering_context.h"
38#include "utility/canvas_utility.h"
42 public nv::index::app::Index_connect
62 virtual bool evaluate_options(nv::index::app::String_dict& sdict) CPP11_OVERRIDE;
65 mi::neuraylib::INetwork_configuration* network_configuration,
66 nv::index::app::String_dict& options) CPP11_OVERRIDE
71 const bool is_unittest = nv::index::app::get_bool(options.get(
"unittest"));
74 info_cout(
"NETWORK: disabled networking mode.", options);
75 network_configuration->set_mode(mi::neuraylib::INetwork_configuration:
:MODE_OFF);
79 return initialize_networking_as_default_udp(network_configuration, options);
93 const std::string& mesh_file_0,
94 const mi::math::Bbox<mi::Float32, 3>& mesh_bbox_0,
95 const std::string& mesh_file_1,
96 const mi::math::Bbox<mi::Float32, 3>& mesh_bbox_1,
97 nv::index::IScene* scene_edit,
98 mi::neuraylib::IDice_transaction* dice_transaction);
101 void setup_camera(nv::index::IPerspective_camera* cam)
const;
103 const mi::math::Vector<mi::Float32, 3>& from,
104 const mi::math::Vector<mi::Float32, 3>& up,
105 const mi::math::Bbox< mi::Float32, 3 >& bbox,
106 const mi::neuraylib::Tag& camera_tag,
107 const mi::neuraylib::Tag& scene_tag,
108 mi::neuraylib::IDice_transaction* dice_transaction)
const;
112 void setup_extreme_transformed_camera(nv::index::IPerspective_camera* cam)
const;
116 mi::math::Matrix<mi::Float32, 4, 4> get_extreme_transformed_matrix()
const;
120 nv::index::IFrame_results* render_frame(
const std::string& output_fname)
const;
123 mi::neuraylib::Tag m_session_tag;
125 mi::base::Handle<nv::index::ICluster_configuration> m_cluster_configuration;
127 mi::base::Handle<nv::index::app::canvas_infrastructure::IIndex_image_file_canvas> m_image_file_canvas;
129 std::string m_outfname;
131 std::string m_verify_image_fname;
132 std::string m_mesh_file_0;
133 std::string m_mesh_file_1;
134 mi::math::Bbox<mi::Float32, 3> m_roi_0;
135 mi::math::Bbox<mi::Float32, 3> m_roi_1;
136 bool m_supersampling;
137 bool m_is_large_translate;
138 mi::Float32 m_mesh_mat_opacity;
139 bool m_mesh_set_pickable;
145 mi::Sint32 exit_code = 0;
149 m_cluster_configuration =
150 get_index_interface()->get_api_component<nv::index::ICluster_configuration>();
154 m_image_file_canvas = create_image_file_canvas(get_application_layer_interface());
157 mi::base::Handle<nv::index::IIndex_scene_query> iindex_query(
158 get_index_interface()->get_api_component<nv::index::IIndex_scene_query>());
162 check_success(is_local_host_joined(m_cluster_configuration.get()));
166 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
167 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
171 m_session_tag = m_index_session->create_session(dice_transaction.get());
173 mi::base::Handle<const nv::index::ISession> session(
174 dice_transaction->access<
const nv::index::ISession>(m_session_tag));
177 mi::base::Handle< nv::index::IScene > scene_edit(
178 dice_transaction->edit<nv::index::IScene>(session->get_scene()));
184 mi::base::Handle<nv::index::IConfig_settings> config_settings(
185 dice_transaction->edit<nv::index::IConfig_settings>(session->get_config()));
188 config_settings->set_rendering_samples(8);
196 check_success(create_scene(m_mesh_file_0, m_roi_0, m_mesh_file_1, m_roi_1,
197 scene_edit.get(), dice_transaction.get()));
202 mi::base::Handle< nv::index::IPerspective_camera > cam(
203 scene_edit->create_camera<nv::index::IPerspective_camera>());
206 mi::math::Vector<mi::Uint32, 2> buffer_resolution(1024, 1024);
207 if (m_is_large_translate)
209 INFO_LOG <<
"large translate test mode.";
210 setup_extreme_transformed_camera(cam.get());
211 buffer_resolution = mi::math::Vector<mi::Uint32, 2>(1602, 934);
215 setup_camera(cam.get());
217 const mi::neuraylib::Tag camera_tag = dice_transaction->store(cam.get());
220 m_image_file_canvas->set_resolution(buffer_resolution);
223 const mi::math::Bbox< mi::Float32, 3 > xyz_roi_st = m_roi_0;
226 mi::base::Handle< nv::index::IScene > scene(
227 dice_transaction->edit< nv::index::IScene >(session->get_scene()));
231 const mi::math::Bbox< mi::Float32, 3 > xyz_roi(xyz_roi_st);
233 scene->set_clipped_bounding_box(xyz_roi_st);
236 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(1.f);
237 mi::math::Matrix<mi::Float32, 4, 4> scale_mat(1.0f);
238 scale_mat.zz = -0.2f;
239 transform_mat.rotate(0.0f,
static_cast<mi::Float32
>(M_PI), 0.0f);
240 transform_mat *= scale_mat;
242 if(m_is_large_translate)
244 transform_mat = get_extreme_transformed_matrix();
247 scene->set_transform_matrix(transform_mat);
251 scene->set_camera(camera_tag);
254 const mi::math::Vector<mi::Float32, 3> from(0.0f, 0.0f, 1.0f);
255 const mi::math::Vector<mi::Float32, 3> up (0.0f, 1.0f, 0.0f);
256 view_all_bbox(from, up, xyz_roi_st, camera_tag, session->get_scene(), dice_transaction.get());
258 dice_transaction->commit();
264 const mi::Sint32 frame_idx = 0;
265 const std::string fname = get_output_file_name(m_outfname, frame_idx);
267 mi::base::Handle<nv::index::IFrame_results> frame_results(render_frame(fname));
268 const mi::base::Handle<nv::index::IError_set> err_set(frame_results->get_error_set());
269 if (err_set->any_errors())
271 std::ostringstream os;
272 const mi::Uint32 nb_err = err_set->get_nb_errors();
273 for (mi::Uint32 e = 0; e < nb_err; ++e)
275 if (e != 0) os <<
'\n';
276 const mi::base::Handle<nv::index::IError> err(err_set->get_error(e));
277 os << err->get_error_string();
280 ERROR_LOG <<
"IIndex_rendering rendering call failed with the following error(s): " <<
'\n'
286 if (!(verify_canvas_result(get_application_layer_interface(),
287 m_image_file_canvas.get(), m_verify_image_fname, get_options())))
295 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
296 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
300 mi::math::Vector<mi::Uint32, 2> pick_location(769, 648);
301 mi::base::Handle<nv::index::IScene_pick_results> scene_pick_results(
302 iindex_query->pick(pick_location, m_image_file_canvas.get(), m_session_tag, dice_transaction.get()));
304 const mi::Uint32 nb_results = scene_pick_results->get_nb_results();
307 INFO_LOG <<
"Number of pick results: " << nb_results;
308 for(mi::Uint32 i=0; i<nb_results; ++i)
310 const mi::base::Handle<nv::index::IScene_pick_result> result(scene_pick_results->get_result(i));
311 const mi::math::Vector_struct<mi::Float32, 3>& intersection = result->get_intersection();
312 INFO_LOG <<
"Intersection no. " << i <<
"\n"
313 <<
"\t\t Element (tag) " << result->get_scene_element().id <<
"\n"
314 <<
"\t\t Sub index: " << result->get_scene_element_sub_index() <<
"\n"
315 <<
"\t\t Distance: " << result->get_distance() <<
"\n"
316 <<
"\t\t Position (local space): " << intersection <<
"\n"
317 <<
"\t\t Color (evaluated): " << result->get_color();
319 mi::Sint64 triangle_index = -1;
320 if(result->get_intersection_info_class() == nv::index::ITriangle_mesh_pick_result::IID() )
322 mi::base::Handle<const nv::index::ITriangle_mesh_pick_result> tri_mesh_pick_result(
323 result->get_interface<
const nv::index::ITriangle_mesh_pick_result>());
324 if(tri_mesh_pick_result.get())
326 triangle_index =
static_cast<mi::Sint64
>(tri_mesh_pick_result->get_triangle_index());
327 INFO_LOG <<
"Triangle mesh specific pick results:" <<
"\n"
328 <<
"\t\t Triangle id: " << tri_mesh_pick_result->get_triangle_index() <<
"\n"
329 <<
"\t\t Local triangle id: " << tri_mesh_pick_result->get_local_triangle_index() <<
"\n"
330 <<
"\t\t Normal: " << tri_mesh_pick_result->get_normal() <<
"\n"
331 <<
"\t\t Color: " << tri_mesh_pick_result->get_color_value() <<
"\n"
332 <<
"\t\t Colormap color: " << tri_mesh_pick_result->get_colormap_value() <<
"\n"
333 <<
"\t\t Barycentric coordinate: " << tri_mesh_pick_result->get_barycentric_coordinates();
336 if(result->get_intersection_info_class() == nv::index::IIntersection_highlight_pick_result::IID() )
338 mi::base::Handle<const nv::index::IIntersection_highlight_pick_result> highlight_pick_result(
339 result->get_interface<
const nv::index::IIntersection_highlight_pick_result>());
340 if(highlight_pick_result.get())
342 INFO_LOG <<
"Intersection highlight specific pick results:" <<
"\n"
343 <<
"\t Intersection shape: " << highlight_pick_result->get_intersection_shape();
346 if(result->get_intersection_info_class() == nv::index::IPlane_pick_result::IID() )
348 mi::base::Handle<const nv::index::IPlane_pick_result> compute_pick_result(
349 result->get_interface<
const nv::index::IPlane_pick_result>());
350 if(compute_pick_result.get())
352 INFO_LOG <<
"Compute plane specific pick results:" <<
"\n"
353 <<
"\t Texture color values: " << compute_pick_result->get_texture_color();
358 if(triangle_index>-1)
360 INFO_LOG <<
"Query the triangle details for triangle id: " << triangle_index <<
".";
362 mi::base::Handle<nv::index::IScene_lookup_result> entry_lookup_result(
363 iindex_query->entry_lookup(
364 static_cast<mi::Uint64
>(triangle_index),
365 result->get_scene_element(),
366 m_session_tag, dice_transaction.get()));
368 mi::base::Handle<const nv::index::ITriangle_mesh_lookup_result> tri_mesh_lookup_result(
369 entry_lookup_result->get_interface<
const nv::index::ITriangle_mesh_lookup_result>());
370 if(tri_mesh_lookup_result.get())
372 INFO_LOG <<
"Receiving the following per-vertex attributes:";
373 mi::math::Vector_struct<mi::Float32, 3> v0;
374 mi::math::Vector_struct<mi::Float32, 3> v1;
375 mi::math::Vector_struct<mi::Float32, 3> v2;
376 tri_mesh_lookup_result->get_vertices(v0, v1, v2);
377 INFO_LOG <<
"\tVertices: (" << v0 <<
',' << v1 <<
',' << v2 <<
')';
379 tri_mesh_lookup_result->get_normals(v0, v1, v2);
380 INFO_LOG <<
"\tNormals: (" << v0 <<
',' << v1 <<
',' << v2 <<
')';
382 mi::math::Vector_struct<mi::Float32, 2> st0;
383 mi::math::Vector_struct<mi::Float32, 2> st1;
384 mi::math::Vector_struct<mi::Float32, 2> st2;
385 tri_mesh_lookup_result->get_texture_coordinates(st0, st1, st2);
386 INFO_LOG <<
"\tTexture coordinates: (" << st0 <<
',' << st1 <<
',' << st2 <<
')';
388 mi::math::Color_struct c0;
389 mi::math::Color_struct c1;
390 mi::math::Color_struct c2;
391 tri_mesh_lookup_result->get_colors(c0, c1, c2);
392 INFO_LOG <<
"\tColors: (" << c0 <<
',' << c1 <<
',' << c2 <<
')';
394 mi::Uint32 cm0, cm1, cm2;
395 tri_mesh_lookup_result->get_color_indices(cm0, cm1, cm2);
396 INFO_LOG <<
"\tColor index values: (" << cm0 <<
',' << cm1 <<
',' << cm2 <<
')';
404 dice_transaction->commit();
413 const std::string com_name = sdict.get(
"command:",
"<unknown_command>");
414 m_is_unittest = nv::index::app::get_bool(sdict.get(
"unittest",
"false"));
418 if (nv::index::app::get_bool(sdict.get(
"is_call_from_test",
"false")))
420 sdict.insert(
"is_dump_comparison_image_when_failed",
"0");
422 sdict.insert(
"outfname",
"");
423 sdict.insert(
"dice::verbose",
"2");
426 m_outfname = sdict.get(
"outfname");
427 m_verify_image_fname = sdict.get(
"verify_image_fname");
428 m_mesh_file_0 = sdict.get(
"mesh_file_0");
429 m_mesh_file_1 = sdict.get(
"mesh_file_1");
430 m_roi_0 = nv::index::app::get_bbox_from_string<mi::Float32,3>(sdict.get(
"roi_0"));
431 m_roi_1 = nv::index::app::get_bbox_from_string<mi::Float32,3>(sdict.get(
"roi_1"));
432 m_supersampling = nv::index::app::get_bool(sdict.get(
"supersampling",
"false"));
433 m_is_large_translate = nv::index::app::get_bool(sdict.get(
"is_large_translate",
"false"));
434 m_mesh_mat_opacity = nv::index::app::get_float32(sdict.get(
"mesh_mat_opacity"));
435 m_mesh_set_pickable = nv::index::app::get_bool(sdict.get(
"mesh_set_pickable",
"false"));
437 info_cout(std::string(
"running ") + com_name, sdict);
438 info_cout(std::string(
"outfname = [") + m_outfname +
439 "], verify_image_fname = [" + m_verify_image_fname +
440 "], dice::verbose = " + sdict.get(
"dice::verbose"), sdict);
443 if(sdict.is_defined(
"h"))
446 <<
"info: Usage: " << com_name <<
" [option]\n"
448 <<
" printout this message\n"
450 <<
" [-dice::verbose severity_level]\n"
451 <<
" verbose severity level (3 is info.). (default: " + sdict.get(
"dice::verbose")
454 <<
" [-mesh_file_0 string]\n"
455 <<
" name of a triangle mesh file (in .bin-format). When empty, the default triangle mesh file will be used.\n"
456 <<
" (default: [" << m_mesh_file_0 <<
"])\n"
458 <<
" [-mesh_file_1 string]\n"
459 <<
" name of a triangle mesh file (in .bin-format). When empty, the default triangle mesh file will be used.\n"
460 <<
" (default: [" << m_mesh_file_1 <<
"])\n"
462 <<
" [-roi_0 \"float float float float float float\"]\n"
463 <<
" the bounding box representing the region of interest (roi) for mesh_file_0.\n"
464 <<
" (default: [" << m_roi_0 <<
"])\n"
466 <<
" [-roi_1 \"float float float float float float\"]\n"
467 <<
" the bounding box representing the region of interest (roi) for mesh_file_1.\n"
468 <<
" (default: [" << m_roi_1 <<
"])\n"
470 <<
" [-outfname string]\n"
471 <<
" name of the output ppm image file. When empty, no image file will be written.\n"
472 <<
" A frame number and the extension (.ppm) will be added.\n"
473 <<
" (default: [" << m_outfname <<
"])\n"
475 <<
" [-verify_image_fname [image_fname]]\n"
476 <<
" when image_fname exist, verify the rendering image. (default: ["
477 << m_verify_image_fname <<
"])\n"
479 <<
" [-supersampling bool]\n"
480 <<
" when true then supersampling is enabled."
481 <<
" (default: " << m_supersampling <<
")\n"
483 <<
" [-is_large_translate bool]\n"
484 <<
" on/off large translation mode."
485 <<
"(default: " << m_is_large_translate <<
")\n"
487 <<
" [-mesh_mat_opacity float]\n"
488 <<
" mesh material opacity."
489 <<
"(default: " << m_mesh_mat_opacity <<
")\n"
491 <<
" [-mesh_set_pickable bool]\n"
492 <<
" enable/disable picking for the mesh."
493 <<
"(default: " << m_mesh_set_pickable <<
")\n"
495 <<
" [-unittest bool]\n"
496 <<
" when true, unit test mode."
497 <<
" (default: " << m_is_unittest <<
")"
505bool Intersection_highlighting_trianglemesh::create_scene(
506 const std::string& mesh_file_0,
507 const mi::math::Bbox<mi::Float32, 3>& mesh_bbox_0,
508 const std::string& mesh_file_1,
509 const mi::math::Bbox<mi::Float32, 3>& mesh_bbox_1,
510 nv::index::IScene* scene_edit,
511 mi::neuraylib::IDice_transaction* dice_transaction)
517 mi::base::Handle<nv::index::IDirectional_headlight> headlight(
518 scene_edit->create_attribute<nv::index::IDirectional_headlight>());
520 headlight->set_direction(mi::math::Vector<mi::Float32, 3>(0.5f, 0.f, -1.f));
521 const mi::neuraylib::Tag headlight_tag = dice_transaction->store(headlight.get());
523 scene_edit->append(headlight_tag, dice_transaction);
526 mi::base::Handle<nv::index::IPhong_gl> phong_1(scene_edit->create_attribute<nv::index::IPhong_gl>());
528 phong_1->set_ambient(mi::math::Color(0.1f, 0.1f, 0.1f, 1.0f));
529 phong_1->set_diffuse(mi::math::Color(0.8f, 0.3f, 0.3f, 1.0f));
530 phong_1->set_specular(mi::math::Color(0.75f, 0.8f, 0.75f, 1.0f));
531 if(m_mesh_mat_opacity < 0.99f)
533 INFO_LOG <<
"Material opacity is less than 1.0 (" << m_mesh_mat_opacity <<
")";
535 phong_1->set_opacity(m_mesh_mat_opacity);
536 phong_1->set_shininess(85);
537 const mi::neuraylib::Tag phong_1_tag = dice_transaction->store(phong_1.get());
539 scene_edit->append(phong_1_tag, dice_transaction);
542 mi::neuraylib::Tag mesh_tag_0;
545 nv::index::app::String_dict triangle_mesh_opt;
546 triangle_mesh_opt.insert(
"args::type",
"triangle_mesh");
547 triangle_mesh_opt.insert(
"args::importer",
"nv::index::plugin::base_importer.Triangle_mesh_importer");
548 triangle_mesh_opt.insert(
"args::input_file", mesh_file_0);
549 std::stringstream sstr;
550 sstr << mesh_bbox_0.min.x <<
" " << mesh_bbox_0.min.y <<
" " << mesh_bbox_0.min.z <<
" "
551 << mesh_bbox_0.max.x <<
" " << mesh_bbox_0.max.y <<
" " << mesh_bbox_0.max.z;
552 triangle_mesh_opt.insert(
"args::bbox", sstr.str());
553 nv::index::IDistributed_data_import_callback* importer_callback =
554 get_importer_from_application_layer(
555 get_application_layer_interface(),
556 "nv::index::plugin::base_importer.Triangle_mesh_importer",
560 mi::base::Handle<nv::index::ITriangle_mesh_scene_element> mesh(
561 scene_edit->create_triangle_mesh(mesh_bbox_0, importer_callback, dice_transaction));
565 mesh->set_enabled(
true);
567 mesh->set_pickable(m_mesh_set_pickable);
570 mesh_tag_0 = dice_transaction->store_for_reference_counting(mesh.get());
574 mi::base::Handle<nv::index::IStatic_scene_group> static_group(
575 scene_edit->create_scene_group<nv::index::IStatic_scene_group>());
579 static_group->append(mesh_tag_0, dice_transaction);
581 mi::neuraylib::Tag static_group_tag = dice_transaction->store(static_group.get());
585 scene_edit->append(static_group_tag, dice_transaction);
588 mi::neuraylib::Tag mesh_tag_1;
591 nv::index::app::String_dict triangle_mesh_opt;
592 triangle_mesh_opt.insert(
"args::type",
"triangle_mesh");
593 triangle_mesh_opt.insert(
"args::importer",
"nv::index::plugin::base_importer.Triangle_mesh_importer");
594 triangle_mesh_opt.insert(
"args::input_file", mesh_file_1);
595 std::stringstream sstr;
596 sstr << mesh_bbox_1.min.x <<
" " << mesh_bbox_1.min.y <<
" " << mesh_bbox_1.min.z <<
" "
597 << mesh_bbox_1.max.x <<
" " << mesh_bbox_1.max.y <<
" " << mesh_bbox_1.max.z;
598 triangle_mesh_opt.insert(
"args::bbox", sstr.str());
599 nv::index::IDistributed_data_import_callback* importer_callback =
600 get_importer_from_application_layer(
601 get_application_layer_interface(),
602 "nv::index::plugin::base_importer.Triangle_mesh_importer",
606 mi::base::Handle<nv::index::ITriangle_mesh_scene_element> mesh(
607 scene_edit->create_triangle_mesh(mesh_bbox_1, importer_callback, dice_transaction));
611 mesh->set_enabled(
false);
613 mesh->set_pickable(m_mesh_set_pickable);
616 mesh_tag_1 = dice_transaction->store_for_reference_counting(mesh.get());
620 mi::base::Handle<nv::index::IStatic_scene_group> static_group(
621 scene_edit->create_scene_group<nv::index::IStatic_scene_group>());
625 static_group->append(mesh_tag_1, dice_transaction);
627 mi::neuraylib::Tag static_group_tag = dice_transaction->store(static_group.get());
631 scene_edit->append(static_group_tag, dice_transaction);
636 mi::base::Handle<nv::index::IIntersection_highlighting> highlighting_0(scene_edit->create_attribute<nv::index::IIntersection_highlighting>());
638 highlighting_0->set_intersection_shape(mesh_tag_0);
639 highlighting_0->set_width(12.0f);
640 highlighting_0->set_smoothness(0.5f);
641 highlighting_0->set_color(mi::math::Color(0.0f, 1.0f, 0.5f));
642 mi::neuraylib::Tag highlighting_tag_0 = dice_transaction->store_for_reference_counting(highlighting_0.get());
644 scene_edit->append(highlighting_tag_0, dice_transaction);
647 mi::base::Handle<nv::index::IIntersection_highlighting> highlighting_1(scene_edit->create_attribute<nv::index::IIntersection_highlighting>());
649 highlighting_1->set_intersection_shape(mesh_tag_1);
650 highlighting_1->set_width(20.0f);
651 highlighting_1->set_smoothness(0.5f);
652 highlighting_1->set_color(mi::math::Color(0.0f, 0.5f, 1.0f));
653 mi::neuraylib::Tag highlighting_tag_1 = dice_transaction->store_for_reference_counting(highlighting_1.get());
655 scene_edit->append(highlighting_tag_1, dice_transaction);
658 const mi::math::Vector<mi::Float32, 2> plane_extent(300.f, 3000.f);
660 mi::base::Handle<nv::index::ITexture_filter_mode> tex_filter(
661 scene_edit->create_attribute<nv::index::ITexture_filter_mode_nearest_neighbor>());
663 mi::neuraylib::Tag tex_filter_tag = dice_transaction->store_for_reference_counting(tex_filter.get());
665 scene_edit->append(tex_filter_tag, dice_transaction);
668 mi::base::Handle<nv::index::app::data_analysis_and_processing::IData_analysis_and_processing> processing(
669 get_application_layer_interface()->get_api_component<nv::index::app::data_analysis_and_processing::IData_analysis_and_processing>());
673 mi::base::Handle<nv::index::IDistributed_compute_technique> mapping(
674 processing->get_sample_tool_set()->create_checker_board_2d_technique(
676 nv::index::IDistributed_compute_destination_buffer_2d_texture:
:FORMAT_RGBA_FLOAT32,
677 mi::math::Color(0.9f, 0.2f, 0.15f, 0.7f),
678 mi::math::Color(0.2f, 0.2f, 0.8f, 1.0f)));
680 mi::neuraylib::Tag mapping_tag = dice_transaction->store_for_reference_counting(mapping.get());
682 scene_edit->append(mapping_tag, dice_transaction);
685 mi::base::Handle<nv::index::IPlane> plane_0(scene_edit->create_shape<nv::index::IPlane>());
687 const mi::math::Vector<mi::Float32, 3> plane_point_0(30.f, 30.f, 600.0f);
688 const mi::math::Vector<mi::Float32, 3> plane_normal_0(0.f, 0.f, 1.f);
689 const mi::math::Vector<mi::Float32, 3> plane_up_0(0.f, 1.f, 0.f);
690 plane_0->set_point(plane_point_0);
691 plane_0->set_normal(plane_normal_0);
692 plane_0->set_up(plane_up_0);
693 plane_0->set_extent(plane_extent);
695 mi::neuraylib::Tag plane_tag_0 = dice_transaction->store_for_reference_counting(plane_0.get());
697 scene_edit->append(plane_tag_0, dice_transaction);
700 mi::base::Handle<nv::index::IPlane> plane_1(scene_edit->create_shape<nv::index::IPlane>());
702 const mi::math::Vector<mi::Float32, 3> plane_point_1(80.f, 30.f, 760.0f);
703 const mi::math::Vector<mi::Float32, 3> plane_normal_1(1.f, 0.f, 1.f);
704 const mi::math::Vector<mi::Float32, 3> plane_up_1(0.f, 1.f, 0.f);
705 plane_1->set_point(plane_point_1);
706 plane_1->set_normal(plane_normal_1);
707 plane_1->set_up(plane_up_1);
708 plane_1->set_extent(plane_extent);
710 mi::neuraylib::Tag plane_tag_1 = dice_transaction->store_for_reference_counting(plane_1.get());
712 scene_edit->append(plane_tag_1, dice_transaction);
719void Intersection_highlighting_trianglemesh::setup_camera(nv::index::IPerspective_camera* cam)
const
724 const mi::math::Vector< mi::Float32, 3 > from( 0.0f, 0.0f,-5.0f);
725 const mi::math::Vector< mi::Float32, 3 > to ( 0.0f, 0.0f, 0.0f);
726 const mi::math::Vector< mi::Float32, 3 > up ( 0.0f, 1.0f, 0.0f);
727 mi::math::Vector<mi::Float32, 3> viewdir = to - from;
730 cam->set(from, viewdir, up);
731 cam->set_aperture(0.033f);
732 cam->set_aspect(1.0f);
733 cam->set_focal(0.03f);
734 cam->set_clip_min(10.0f);
735 cam->set_clip_max(5000.0f);
739void Intersection_highlighting_trianglemesh::view_all_bbox(
740 const mi::math::Vector<mi::Float32, 3>& from,
741 const mi::math::Vector<mi::Float32, 3>& up,
742 const mi::math::Bbox< mi::Float32, 3 >& bbox,
743 const mi::neuraylib::Tag& camera_tag,
744 const mi::neuraylib::Tag& scene_tag,
745 mi::neuraylib::IDice_transaction* dice_transaction)
const
749 WARN_LOG <<
"Un-initialized bounding box and not updating the camera settings.";
754 mi::base::Handle<nv::index::IPerspective_camera> camera(dice_transaction->edit<nv::index::IPerspective_camera>(camera_tag));
757 mi::base::Handle<const nv::index::IScene> scene(dice_transaction->access<
const nv::index::IScene>(scene_tag));
761 const mi::math::Bbox< mi::Float32, 3 >& global_roi_bbox = scene->get_clipped_bounding_box();
762 const mi::math::Matrix<mi::Float32, 4, 4>& transform_mat = scene->get_transform_matrix();
763 const mi::math::Vector<mi::Float32, 3> new_min(mi::math::transform_point(transform_mat, global_roi_bbox.min));
764 const mi::math::Vector<mi::Float32, 3> new_max(mi::math::transform_point(transform_mat, global_roi_bbox.max));
765 const mi::math::Bbox< mi::Float32, 3 > transformed_bbox(new_min, new_max);
766 const mi::math::Vector<mi::Float32, 3>& min = transformed_bbox.min;
767 const mi::math::Vector<mi::Float32, 3>& max = transformed_bbox.max;
768 const mi::math::Vector<mi::Float32, 3>& center = transformed_bbox.center();
769 const mi::Float32 rad = mi::math::euclidean_distance(max, min) / 2.0f;
771 const mi::Float32 fov_rad_2 =
static_cast<mi::Float32
>(camera->get_fov_y_rad() / 2.0);
772 const mi::Float32 dist =
static_cast<mi::Float32
>(rad / tan(fov_rad_2));
774 const mi::math::Vector<mi::Float32, 3> eyepos = -(0.7f * dist * from) + center;
775 camera->set_eye_point(eyepos);
776 camera->set_up_direction(up);
778 const mi::Float32 clip_min = 0.1f * dist;
779 const mi::Float32 clip_max = 10.0f * 1.f * dist;
781 camera->set_clip_min(clip_min);
782 camera->set_clip_max(clip_max);
783 mi::math::Vector<mi::Float32, 3> viewdir = center - eyepos;
785 camera->set_view_direction(viewdir);
790void Intersection_highlighting_trianglemesh::setup_extreme_transformed_camera(nv::index::IPerspective_camera* cam)
const
795 mi::math::Vector< mi::Float32, 3 >
const from( 1805060.125f + 8192.0f, 9978520.0f + 16384.0f, 16384.0f);
796 mi::math::Vector< mi::Float32, 3 >
const to ( 1805060.125f + 8192.0f, 9978520.0f + 8292.0f, -256.0f);
797 mi::math::Vector< mi::Float32, 3 >
const up ( 0.0f, 1.0f, 0.0f);
798 mi::math::Vector<mi::Float32, 3> viewdir = to - from;
801 cam->set(from, viewdir, up);
802 cam->set_aperture(0.033f);
803 cam->set_aspect(1.71520f);
804 cam->set_focal(0.03f);
805 cam->set_clip_min(124.485f);
806 cam->set_clip_max(17585.6f);
809 INFO_LOG <<
"Set camera extreme mode";
813mi::math::Matrix<mi::Float32, 4, 4> Intersection_highlighting_trianglemesh::get_extreme_transformed_matrix()
const
821 mi::math::Matrix<mi::Float32, 4, 4> transform_mat(
822 20.61f, 0.0f, 0.0f, 0.0f,
823 0.0f, 20.61f, 0.0f, 0.0f,
824 0.0f, 0.0f, -4.0f, 0.0f,
825 1805060.0f, 9978520.0f, 0.0f, 1.0f
827 return transform_mat;
831nv::index::IFrame_results* Intersection_highlighting_trianglemesh::render_frame(
832 const std::string& output_fname)
const
837 m_image_file_canvas->set_rgba_file_name(output_fname.c_str());
841 mi::base::Handle<mi::neuraylib::IDice_transaction> dice_transaction(
842 m_global_scope->create_transaction<mi::neuraylib::IDice_transaction>());
845 m_index_session->update(m_session_tag, dice_transaction.get());
847 mi::base::Handle<nv::index::IFrame_results> frame_results(
848 m_index_rendering->render(
850 m_image_file_canvas.get(),
851 dice_transaction.get()));
854 dice_transaction->commit();
856 frame_results->retain();
857 return frame_results.get();
862int main(
int argc,
const char* argv[])
864 nv::index::app::String_dict sdict;
865 sdict.insert(
"dice::verbose",
"3");
866 sdict.insert(
"mesh_file_0",
"../intersection_highlighting_trianglemesh/box.ts.bin");
867 sdict.insert(
"mesh_file_1",
"../intersection_highlighting_trianglemesh/box.ts.bin");
868 sdict.insert(
"highlight_color_0",
"0 1 0.5");
869 sdict.insert(
"highlight_color_1",
"0 0.5 1");
870 sdict.insert(
"roi_0",
"0 0 0 330 311 760");
871 sdict.insert(
"roi_1",
"100 100 127 300 300 611");
872 sdict.insert(
"outfname",
"frame_intersection_highlighting_trianglemesh");
873 sdict.insert(
"verify_image_fname",
"");
874 sdict.insert(
"unittest",
"0");
875 sdict.insert(
"supersampling",
"0");
877 sdict.insert(
"is_large_translate",
"0");
878 sdict.insert(
"mesh_mat_opacity",
"0.7");
879 sdict.insert(
"mesh_set_pickable",
"1");
880 sdict.insert(
"is_dump_comparison_image_when_failed",
"1");
881 sdict.insert(
"is_call_from_test",
"0");
884 sdict.insert(
"dice::network::mode",
"OFF");
887 sdict.insert(
"index::config::set_monitor_performance_values",
"true");
888 sdict.insert(
"index::service",
"rendering_and_compositing");
889 sdict.insert(
"index::cuda_debug_checks",
"false");
892 sdict.insert(
"index::app::components::application_layer::component_name_list",
893 "canvas_infrastructure image io data_analysis_and_processing");
894 sdict.insert(
"index::app::plugins::base_importer::enabled",
"true");
898 intersection_highlighting_trianglemesh.initialize(argc, argv, sdict);
899 check_success(intersection_highlighting_trianglemesh.is_initialized());
902 const mi::Sint32 exit_code = intersection_highlighting_trianglemesh.
launch();
903 INFO_LOG <<
"Shutting down ...";
virtual ~Intersection_highlighting_trianglemesh()
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
Intersection_highlighting_trianglemesh()
int main(int argc, const char *argv[])
#define check_success(expr)