├── .clang-format ├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── THIRD-PARTY-LICENSES ├── UnitTests ├── .gitignore ├── CMakeLists.txt ├── TestInputs │ ├── P3D.rdx │ ├── Texture.png │ ├── TextureJ.jpeg │ ├── align.aln │ ├── aln_toofew.aln │ ├── aln_toomany.aln │ ├── bunnyFloat_nolod.sprt │ ├── bunnyFloat_wlod.sprt │ ├── coordsTest1.dp │ ├── coordsTest2.dp │ ├── density_anisotropic_0.rls │ ├── density_anisotropic_1.rls │ ├── density_anisotropic_2.rls │ ├── density_metaball_0.rls │ ├── density_metaball_1.rls │ ├── density_metaball_2.rls │ ├── density_union_of_spheres_0.rls │ ├── density_union_of_spheres_1.rls │ ├── density_union_of_spheres_2.rls │ ├── density_zhu_bridson_0.rls │ ├── density_zhu_bridson_1.rls │ ├── density_zhu_bridson_2.rls │ ├── doubleFloat.e57 │ ├── doubleFloat.prt │ ├── float16.csv │ ├── hdri_colors.csv │ ├── infinite_loop.rsp │ ├── intColor.e57 │ ├── intColor.prt │ ├── loadSingleScan.e57 │ ├── loadSingleScan.prt │ ├── loadSingleScanT.e57 │ ├── loadSingleScanT.prt │ ├── malicious_whitespace_after_quote.csv │ ├── massive_chunk_divisible.prt │ ├── massive_chunk_indivisible.prt │ ├── negative_eight.prt │ ├── noNormals.e57 │ ├── noNormals.prt │ ├── ot_35120B4116B_1.laz │ ├── project.rsp │ ├── prt_fractal_for_krscene.prt │ ├── pts_inconsistent_channels.pts │ ├── rgb_magnitude_127.las │ ├── scale_offset_las.las │ ├── scale_offset_laz.laz │ ├── scaledInteger.e57 │ ├── scaledInteger.prt │ ├── simple_xyzrgb_pts.pts │ ├── simple_xyzrgb_ptx.ptx │ ├── singleplusoffset.csv │ ├── transforms.e57 │ ├── transforms.prt │ ├── twoScans.e57 │ ├── twoScans.prt │ ├── variety.aln │ ├── wnormals.e57 │ └── wnormals.prt ├── TestOutputs │ └── .empty ├── gtest-helper.cpp ├── gtest-helper.h ├── gtest_main.cc ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── test_channels │ ├── test_channel_map.cpp │ ├── test_channel_map_weighted_sum.cpp │ ├── test_named_channel_data.cpp │ └── test_property_map.cpp ├── test_files │ ├── files_test_utils.hpp │ ├── test_aln.cpp │ ├── test_csv_io.cpp │ ├── test_filename_pattern.cpp │ ├── test_files_background_serializer.cpp │ ├── test_files_path_manipulation.cpp │ ├── test_files_sequence_cache.cpp │ └── test_scoped_file_cleanup.cpp ├── test_geometry │ ├── test_dcel.cpp │ ├── test_dcel_mesh_interface.cpp │ ├── test_delegated_const_mesh_interface.cpp │ ├── test_edge_topology.cpp │ ├── test_fractional_mesh_interface.cpp │ ├── test_generic_mesh_kdtree.cpp │ ├── test_geometry.cpp │ ├── test_geometry_changing_outputs_to_mesh_seq_saver.cpp │ ├── test_geometry_mesh.cpp │ ├── test_mesh_interface.cpp │ ├── test_mesh_interface_utils.cpp │ ├── test_mesh_measurement.cpp │ ├── test_mesh_merging.cpp │ ├── test_mixed_kdtree.cpp │ ├── test_obj_io.cpp │ ├── test_ply_io.cpp │ ├── test_polygon_utils.cpp │ ├── test_polymesh3.cpp │ ├── test_polymesh3_interface.cpp │ ├── test_stl_io.cpp │ ├── test_trimesh3.cpp │ ├── test_xmesh_sequence_saver.cpp │ └── test_xmesh_standard_mesh_interface.cpp ├── test_graphics │ ├── test_alpha3f.cpp │ ├── test_boundbox3f.cpp │ ├── test_camera.cpp │ ├── test_color3f.cpp │ ├── test_graphics.cpp │ ├── test_graphics_utils.cpp │ ├── test_plane3f.cpp │ ├── test_quat4f.cpp │ ├── test_ray3f.cpp │ ├── test_transform4f.cpp │ ├── test_units.cpp │ └── test_vector3f.cpp ├── test_graphics2d │ ├── test_boundrect2f.cpp │ ├── test_framebuffer.cpp │ ├── test_image_channel.cpp │ ├── test_mipmap.cpp │ ├── test_rasterization.cpp │ └── test_vector2f.cpp ├── test_hashing │ └── test_hashing.cpp ├── test_locale │ └── test_locale.cpp ├── test_math │ ├── test_math.cpp │ └── test_math_utils.cpp ├── test_misc │ ├── test_indexer.cpp │ ├── test_range_segmentation.cpp │ └── test_string_functions.cpp ├── test_os │ └── test_environment_variables.cpp ├── test_particles │ ├── e57_generator │ │ └── e57_generator.cpp │ ├── test_e57_io.cpp │ ├── test_e57_ostream.cpp │ ├── test_las_istream.cpp │ ├── test_laz_istream.cpp │ ├── test_particles.cpp │ ├── test_particles_dart_throw.cpp │ ├── test_particles_grid_tree.cpp │ ├── test_particles_kdtree.cpp │ ├── test_particles_sph.cpp │ ├── test_ply_particle_io.cpp │ ├── test_prt2_streams.cpp │ ├── test_prt_file_header.cpp │ ├── test_ptg_io.cpp │ ├── test_pts_io.cpp │ ├── test_ptx_io.cpp │ ├── test_surface_particle_istream.cpp │ └── test_time_interpolation_particle_istream.cpp ├── test_process │ └── test_child_process.cpp ├── test_projection │ ├── test_texture_baking.cpp │ └── test_texture_projection.cpp ├── test_prtfile │ ├── test_prt2_io.cpp │ ├── test_prt2_with_position_offset.cpp │ ├── test_prt_io.cpp │ └── test_prt_metadata.cpp ├── test_rendering │ └── test_attenuation_io.cpp ├── test_simd │ ├── test_float_v.cpp │ ├── test_float_v_scalar.cpp │ ├── test_int_v.cpp │ └── test_int_v_scalar.cpp ├── test_tinyxml │ └── test_tinyxml_utility.cpp ├── test_volumetrics │ ├── test_implicit_surface_to_trimesh3.cpp │ ├── test_marching_cubes.cpp │ ├── test_particle_implicit_surface_policy_density.cpp │ ├── test_populate_mesh_channels.cpp │ ├── test_rle_index_spec.cpp │ ├── test_rle_level_set.cpp │ ├── test_rle_level_set_create_staggered_volume_channel.cpp │ ├── test_rle_reinitialization.cpp │ ├── test_volumetrics.cpp │ └── test_xyzr_packet_array.cpp ├── test_win32 │ └── test_utility.cpp └── utilities │ ├── e57_generator.hpp │ ├── mesh_generators.cpp │ ├── mesh_generators.hpp │ └── scoped_temp_file.hpp ├── build.py ├── conanfile.py ├── frantic ├── caches │ └── lru_cache.hpp ├── channels │ ├── channel_accessor.hpp │ ├── channel_buffer.hpp │ ├── channel_buffer_iterator.hpp │ ├── channel_column_map.hpp │ ├── channel_map.hpp │ ├── channel_map_adaptor.hpp │ ├── channel_map_const_iterator.hpp │ ├── channel_map_lerp.hpp │ ├── channel_map_weighted_sum.hpp │ ├── channel_operation_compiler.hpp │ ├── channel_operation_nodes.hpp │ ├── channel_propagation_policy.hpp │ ├── named_channel_data.hpp │ └── property_map.hpp ├── diagnostics │ ├── assert_macros.hpp │ ├── profiling_manager.hpp │ ├── profiling_section.hpp │ └── timeout_tracker.hpp ├── files │ ├── aln.hpp │ ├── background_serializer.hpp │ ├── compression_stream.hpp │ ├── csv_files.hpp │ ├── file_sequence.hpp │ ├── filename_sequence.hpp │ ├── files.hpp │ ├── legacy_flood_file_io.hpp │ ├── paths.hpp │ ├── pipelined_ifstream.hpp │ ├── pipelined_ofstream.hpp │ ├── scoped_file_cleanup.hpp │ ├── sequence_cache.hpp │ └── zlib_reader.hpp ├── fluids │ ├── boundary_condition.hpp │ ├── rle_staggered_vel_accessor.hpp │ ├── rle_voxel_field.hpp │ └── velocity_advection.hpp ├── geometry │ ├── animated_trimesh3_cache.hpp │ ├── connected_components.hpp │ ├── const_shared_polymesh3_builder.hpp │ ├── dcel.hpp │ ├── dcel_construction.hpp │ ├── dcel_iterators.hpp │ ├── dcel_mesh_interface.hpp │ ├── dcel_surface_iterators.hpp │ ├── delegated_const_mesh_interface.hpp │ ├── edge_topology.hpp │ ├── fractional_mesh_interface.hpp │ ├── generic_mesh_kdtree.hpp │ ├── generic_mesh_kdtree_impl.hpp │ ├── matte_geometry_interface.hpp │ ├── mesh_conversion.hpp │ ├── mesh_file_io_factory.hpp │ ├── mesh_interface.hpp │ ├── mesh_interface_file_io.hpp │ ├── mesh_interface_utils.hpp │ ├── mesh_measurement.hpp │ ├── mesh_merging.hpp │ ├── mixed_kdtree.hpp │ ├── mixed_kdtree_detail.hpp │ ├── mixed_kdtree_trimesh3.hpp │ ├── parameterization │ │ └── parameterization_chart.hpp │ ├── particle_collision_detector.hpp │ ├── ply_reader.hpp │ ├── polygon_utils.hpp │ ├── polymesh3.hpp │ ├── polymesh3_accessors.hpp │ ├── polymesh3_builder.hpp │ ├── polymesh3_file_io.hpp │ ├── polymesh3_interface.hpp │ ├── primitive_kdtree.hpp │ ├── primitive_kdtree_node.hpp │ ├── quickhull2.hpp │ ├── quickhull_generic.hpp │ ├── raytraced_geometry_collection.hpp │ ├── raytracing.hpp │ ├── relaxation.hpp │ ├── rply.hpp │ ├── transformed_mesh_interface.hpp │ ├── triangle_utils.hpp │ ├── trimesh3.hpp │ ├── trimesh3_degeneracy_removal.hpp │ ├── trimesh3_file_io.hpp │ ├── trimesh3_interface.hpp │ ├── trimesh3_kdtree.hpp │ ├── trimesh3_kdtree_node.hpp │ ├── trimesh3_named_channels.hpp │ ├── trimesh3_scan_conversion.hpp │ ├── trimesh3_utils.hpp │ ├── u3d │ │ ├── u3d_common.hpp │ │ └── u3d_shading.hpp │ ├── u3d_writer.hpp │ ├── volume_collection.hpp │ ├── xmesh_channels.hpp │ ├── xmesh_metadata.hpp │ ├── xmesh_reader.hpp │ ├── xmesh_sequence_saver.hpp │ ├── xmesh_standard_mesh_interface.hpp │ └── xmesh_writer.hpp ├── graphics │ ├── aligned_array.hpp │ ├── alpha1f.hpp │ ├── alpha3f.hpp │ ├── boundbox3.hpp │ ├── boundbox3f.hpp │ ├── camera.hpp │ ├── color3f.hpp │ ├── color3h.hpp │ ├── color_base.hpp │ ├── color_converter.hpp │ ├── color_rgb3a_f.hpp │ ├── color_rgb_f.hpp │ ├── color_rgba_f.hpp │ ├── color_rgba_h.hpp │ ├── color_with_alpha.hpp │ ├── cubeface.hpp │ ├── dart_thrower.hpp │ ├── graphics_utils.hpp │ ├── motion_blurred_transform.hpp │ ├── plane3f.hpp │ ├── poisson_sphere.hpp │ ├── quat4f.hpp │ ├── raw_byte_buffer.hpp │ ├── ray3f.hpp │ ├── size3.hpp │ ├── size3f.hpp │ ├── spherical_coords.hpp │ ├── transform4f.hpp │ ├── units.hpp │ ├── vector3.hpp │ ├── vector3f.hpp │ └── vector4f.hpp ├── graphics2d │ ├── boundrect2.hpp │ ├── boundrect2f.hpp │ ├── boundrect2t.hpp │ ├── file_io │ │ └── dpx_file_io.hpp │ ├── framebuffer.hpp │ ├── framebufferiterator.hpp │ ├── image │ │ ├── algorithms.hpp │ │ ├── convert.hpp │ │ ├── filter.hpp │ │ ├── image_file_io.hpp │ │ └── pixel.hpp │ ├── image_channel.hpp │ ├── image_channel_base.hpp │ ├── mipmap.hpp │ ├── rasterization.hpp │ ├── size2.hpp │ ├── size2f.hpp │ ├── size2t.hpp │ ├── spherical_distortion.hpp │ ├── strideiterator.hpp │ ├── vector2.hpp │ ├── vector2f.hpp │ └── vector2t.hpp ├── hashing │ ├── blake2_hash.hpp │ └── hashing.hpp ├── locale │ └── locale.hpp ├── logging │ ├── console_progress_logger.hpp │ ├── global_progress_logger.hpp │ ├── logging_level.hpp │ ├── progress_logger.hpp │ └── render_progress_logger.hpp ├── math │ ├── bob_jenkins_hash.h │ ├── differentiable_noise_generator.hpp │ ├── eigen.hpp │ ├── exact_predicates.h │ ├── filters.hpp │ ├── fractions.hpp │ ├── hash.hpp │ ├── iterative_root_solve.hpp │ ├── master_noise_generator.hpp │ ├── math_array.hpp │ ├── morton_code.hpp │ ├── perlin_noise_generator.hpp │ ├── polynomial_roots.hpp │ ├── radian.hpp │ ├── reconstruction_filters.hpp │ ├── splines │ │ └── bezier_spline.hpp │ ├── uint128.hpp │ └── utils.hpp ├── misc │ ├── algorithm.hpp │ ├── exception_stream.hpp │ ├── functor.hpp │ ├── hybrid_assert.hpp │ ├── indexer.hpp │ ├── iterator.hpp │ ├── property_container.hpp │ ├── range_segmentation.hpp │ ├── string_functions.hpp │ └── utility.hpp ├── os │ ├── child_process.hpp │ └── environment.hpp ├── particles │ ├── csv_metadata.hpp │ ├── particle_array.hpp │ ├── particle_array_iterator.hpp │ ├── particle_classes.hpp │ ├── particle_cursor.hpp │ ├── particle_deque.hpp │ ├── particle_deque_iterator.hpp │ ├── particle_file_metadata.hpp │ ├── particle_file_stream_factory.hpp │ ├── particle_grid_tree.hpp │ ├── particle_istream_iterator.hpp │ ├── particle_kdtree.hpp │ ├── particle_kdtree_implementation.hpp │ ├── particle_kmeans.hpp │ ├── particle_step.hpp │ ├── particle_utilities.hpp │ ├── proxy_particle_cursor.hpp │ ├── prt_file_header.hpp │ ├── prt_metadata.hpp │ ├── sph │ │ └── sph_kernel_functions.hpp │ └── streams │ │ ├── age_culled_particle_istream.hpp │ │ ├── apply_function_particle_istream.hpp │ │ ├── channel_operation_particle_istream.hpp │ │ ├── channel_range_map_particle_istream.hpp │ │ ├── channel_scale_particle_istream.hpp │ │ ├── concatenated_parallel_particle_istream.hpp │ │ ├── concatenated_particle_istream.hpp │ │ ├── csv_particle_istream.hpp │ │ ├── csv_particle_ostream.hpp │ │ ├── culling_particle_istream.hpp │ │ ├── density_scale_particle_istream.hpp │ │ ├── duplicate_channel_particle_istream.hpp │ │ ├── e57_particle_istream.hpp │ │ ├── e57_particle_mutex.hpp │ │ ├── e57_particle_ostream.hpp │ │ ├── empty_particle_istream.hpp │ │ ├── fractional_by_id_particle_istream.hpp │ │ ├── fractional_particle_istream.hpp │ │ ├── functor_particle_istream.hpp │ │ ├── id_culled_particle_istream.hpp │ │ ├── instancing_particle_istream.hpp │ │ ├── las_particle_istream.hpp │ │ ├── particle_array_particle_istream.hpp │ │ ├── particle_container_particle_istream.hpp │ │ ├── particle_istream.hpp │ │ ├── particle_ostream.hpp │ │ ├── ply_particle_istream.hpp │ │ ├── ply_particle_ostream.hpp │ │ ├── prt2_particle_istream.hpp │ │ ├── prt2_particle_ostream.hpp │ │ ├── prt_particle_istream.hpp │ │ ├── prt_particle_ostream.hpp │ │ ├── ptg_particle_istream.hpp │ │ ├── pts_particle_istream.hpp │ │ ├── ptx_particle_istream.hpp │ │ ├── realflow_bin_particle_istream.hpp │ │ ├── realflow_bin_particle_ostream.hpp │ │ ├── realflow_rpc_particle_istream.hpp │ │ ├── rle_levelset_particle_istream.hpp │ │ ├── selection_culled_particle_istream.hpp │ │ ├── set_channel_particle_istream.hpp │ │ ├── shared_particle_container_particle_istream.hpp │ │ ├── spline_view_adaptive_particle_istream.hpp │ │ ├── surface_culled_particle_istream.hpp │ │ ├── surface_particle_istream.hpp │ │ ├── time_interpolation_particle_istream.hpp │ │ ├── transformed_particle_istream.hpp │ │ └── volume_culled_particle_istream.hpp ├── prtfile │ ├── prt2_common.hpp │ ├── prt2_reader.hpp │ ├── prt2_writer.hpp │ └── sprt_common.hpp ├── rendering │ ├── deep_attenuation_loaders.hpp │ ├── deep_attenuation_savers.hpp │ ├── depthbuffer_cubeface.hpp │ ├── depthbuffer_singleface.hpp │ ├── environment_map_provider.hpp │ ├── framebuffer_cubeface.hpp │ ├── geometry_renderer.hpp │ ├── lights │ │ ├── directedlight_interface.hpp │ │ ├── directlight.hpp │ │ ├── light_list.hpp │ │ ├── lightinterface.hpp │ │ ├── pointlight.hpp │ │ └── spotlight.hpp │ ├── lights_accessor.hpp │ └── shadow_generator.hpp ├── shading │ └── highlights.hpp ├── simd │ ├── detect.hpp │ ├── float_v.hpp │ ├── float_v_impl.hpp │ ├── int_v.hpp │ ├── int_v_impl.hpp │ └── sse │ │ └── floor.hpp ├── sort │ └── sort.hpp ├── sstream │ └── tsstream.hpp ├── strings │ ├── to_string_classic.hpp │ ├── tstring.hpp │ └── utf8.hpp ├── threads │ ├── buffered_producer_consumer.hpp │ └── synchronizedqueue.hpp ├── tinyxml │ ├── frantic_tinyxml_graphics.hpp │ └── frantic_tinyxml_utility.hpp ├── unix │ ├── child_process.hpp │ ├── process_handle.hpp │ └── process_priority.hpp ├── volumetrics │ ├── field_interface.hpp │ ├── grid_tree_base.hpp │ ├── hash_grid.hpp │ ├── implicitsurface │ │ ├── calculate_particle_anisotropic_params.hpp │ │ ├── detail │ │ │ └── xyzr_packet_array.hpp │ │ ├── implicit_surface_to_rle_level_set.hpp │ │ ├── implicit_surface_to_trimesh3.hpp │ │ ├── level_set_implicit_surface_policies.hpp │ │ ├── marching_cubes_table.hpp │ │ └── particle_implicit_surface_policies.hpp │ ├── levelset │ │ ├── dense_level_set.hpp │ │ ├── dense_level_set_named_channels.hpp │ │ ├── geometry_to_levelset.hpp │ │ ├── level_set_fast_marching_reinitialization.hpp │ │ ├── level_set_marching_extrapolation.hpp │ │ ├── level_set_utils.hpp │ │ ├── rle_defined_and_adj_iterator.hpp │ │ ├── rle_defined_box_iterator.hpp │ │ ├── rle_defined_iterator.hpp │ │ ├── rle_general_block_iterator.hpp │ │ ├── rle_index_spec.hpp │ │ ├── rle_index_spec_adjacency.hpp │ │ ├── rle_index_spec_block_iterator_x.hpp │ │ ├── rle_level_set.hpp │ │ ├── rle_level_set_file_io.hpp │ │ ├── rle_level_set_impl.hpp │ │ ├── rle_named_channels.hpp │ │ ├── rle_pairwise_run_iterator.hpp │ │ ├── rle_run_iterator.hpp │ │ ├── rle_scanline_iteration_primitives.hpp │ │ └── rle_trilerp.hpp │ ├── rle_plane.hpp │ ├── rle_weno_interpolation.hpp │ ├── run_tree.hpp │ ├── tree_voxel_field2d.hpp │ ├── tree_voxel_field2d_block_iterator.hpp │ ├── volumetric_scattering_functions.hpp │ ├── voxel_coord_system.hpp │ ├── voxel_edge_stepper.hpp │ ├── voxel_field_visualization.hpp │ ├── voxel_grid_tree.hpp │ └── voxel_sampler_interface.hpp └── win32 │ ├── child_process.hpp │ ├── cregkey.hpp │ ├── invoke_queue.hpp │ ├── log_window.hpp │ ├── utility.hpp │ └── wrap.hpp ├── src ├── channels │ ├── channel_buffer.cpp │ ├── channel_column_map.cpp │ ├── channel_map.cpp │ ├── channel_map_adaptor.cpp │ ├── channel_map_lerp.cpp │ ├── channel_map_weighted_sum.cpp │ ├── channel_operation_compiler.cpp │ ├── channel_operation_nodes.cpp │ ├── named_channel_data.cpp │ └── property_map.cpp ├── files │ ├── aln.cpp │ ├── compression_stream.cpp │ ├── csv_files.cpp │ ├── filename_pattern.cpp │ ├── filename_sequence.cpp │ ├── files.cpp │ ├── frame_set.cpp │ ├── legacy_flood_file_io.cpp │ ├── paths.cpp │ ├── pipelined_ifstream.cpp │ ├── pipelined_ofstream.cpp │ ├── scoped_file_cleanup.cpp │ └── zlib_reader.cpp ├── fluids │ ├── boundary_condition.cpp │ ├── rle_voxel_field.cpp │ └── velocity_advection.cpp ├── geometry │ ├── connected_components.cpp │ ├── const_shared_polymesh3_builder.cpp │ ├── dcel.cpp │ ├── dcel_construction.cpp │ ├── dcel_mesh_interface.cpp │ ├── delegated_const_mesh_interface.cpp │ ├── edge_topology.cpp │ ├── fractional_mesh_interface.cpp │ ├── mesh_conversion.cpp │ ├── mesh_file_io_factory.cpp │ ├── mesh_interface_file_io.cpp │ ├── mesh_interface_utils.cpp │ ├── mesh_measurement.cpp │ ├── mesh_merging.cpp │ ├── mixed_kdtree.cpp │ ├── mixed_kdtree_trimesh3.cpp │ ├── parameterization │ │ └── parameterization_chart.cpp │ ├── ply_reader.cpp │ ├── polygon_utils.cpp │ ├── polymesh3.cpp │ ├── polymesh3_builder.cpp │ ├── polymesh3_file_io.cpp │ ├── polymesh3_interface.cpp │ ├── relaxation.cpp │ ├── rply.cpp │ ├── transformed_mesh_interface.cpp │ ├── trimesh3.cpp │ ├── trimesh3_degeneracy_removal.cpp │ ├── trimesh3_file_io.cpp │ ├── trimesh3_interface.cpp │ ├── trimesh3_kdtree.cpp │ ├── trimesh3_kdtree_greedySAH_nlogn.cpp │ ├── trimesh3_scan_conversion.cpp │ ├── u3d │ │ └── u3d_common.cpp │ ├── u3d_writer.cpp │ ├── xmesh_metadata.cpp │ ├── xmesh_reader.cpp │ ├── xmesh_sequence_saver.cpp │ ├── xmesh_standard_mesh_interface.cpp │ └── xmesh_writer.cpp ├── graphics │ ├── boundbox3f.cpp │ ├── color_converter.cpp │ ├── color_rgb3a_f.cpp │ ├── color_rgb_f.cpp │ ├── color_rgba_f.cpp │ ├── color_rgba_h.cpp │ ├── raw_byte_buffer.cpp │ ├── ray3f.cpp │ └── units.cpp ├── graphics2d │ ├── file_io │ │ └── dpx_file_io.cpp │ ├── image │ │ └── image_file_io.cpp │ └── spherical_distortion.cpp ├── hashing │ ├── blake2_hash.cpp │ └── hashing.cpp ├── locale │ └── locale.cpp ├── logging │ ├── global_progress_logger.cpp │ └── logging_level.cpp ├── math │ ├── hash.cpp │ ├── perlin_noise_generator.cpp │ └── splines │ │ └── bezier_spline.cpp ├── os │ └── environment.cpp ├── particles │ ├── csv_metadata.cpp │ ├── particle_file_metadata.cpp │ ├── particle_file_stream_factory.cpp │ ├── particle_grid_tree.cpp │ ├── particle_utilities.cpp │ ├── prt_file_header.cpp │ ├── prt_metadata.cpp │ └── streams │ │ ├── age_culled_particle_istream.cpp │ │ ├── concatenated_particle_istream.cpp │ │ ├── csv_particle_istream.cpp │ │ ├── e57_particle_istream.cpp │ │ ├── e57_particle_mutex.cpp │ │ ├── e57_particle_ostream.cpp │ │ ├── ply_particle_istream.cpp │ │ ├── ply_particle_ostream.cpp │ │ ├── prt2_particle_istream.cpp │ │ ├── prt2_particle_ostream.cpp │ │ ├── pts_particle_istream.cpp │ │ ├── rle_levelset_particle_istream.cpp │ │ ├── surface_particle_istream.cpp │ │ └── time_interpolation_particle_istream.cpp ├── prtfile │ ├── prt2_common.cpp │ ├── prt2_reader.cpp │ └── prt2_writer.cpp ├── rendering │ ├── deep_attenuation_loaders.cpp │ └── deep_attenuation_savers.cpp ├── strings │ ├── tstring.cpp │ └── utf8.cpp ├── unix │ └── child_process.cpp ├── volumetrics │ ├── hash_grid.cpp │ ├── implicitsurface │ │ ├── calculate_particle_anisotropic_params.cpp │ │ ├── detail │ │ │ └── xyzr_packet_array.cpp │ │ ├── implicit_surface_to_trimesh3.cpp │ │ ├── level_set_implicit_surface_policies.cpp │ │ ├── marching_cubes_table.cpp │ │ └── particle_implicit_surface_policies.cpp │ ├── levelset │ │ ├── dense_level_set.cpp │ │ ├── geometry_to_levelset.cpp │ │ ├── level_set_fast_marching_reinitialization.cpp │ │ ├── level_set_marching_extrapolation.cpp │ │ ├── level_set_utils.cpp │ │ ├── rle_defined_and_adj_iterator.cpp │ │ ├── rle_defined_iterator.cpp │ │ ├── rle_index_spec.cpp │ │ ├── rle_index_spec_adjacency.cpp │ │ ├── rle_index_spec_axis_permutation.cpp │ │ ├── rle_level_set.cpp │ │ ├── rle_level_set_file_io.cpp │ │ ├── rle_level_set_operations.cpp │ │ ├── rle_pairwise_run_iterator.cpp │ │ ├── rle_run_iterator.cpp │ │ ├── rle_scanline_iteration_primitives.cpp │ │ └── rle_trilerp.cpp │ ├── rle_weno_interpolation.cpp │ ├── tree_voxel_field2d.cpp │ ├── voxel_field_visualization.cpp │ └── voxel_grid_tree.cpp └── win32 │ ├── child_process.cpp │ ├── invoke_queue.cpp │ ├── log_window.cpp │ ├── win32.cpp │ └── wrap.cpp ├── stdafx.cpp └── stdafx.h /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | Standard: c++17 3 | UseTab: Never 4 | ColumnLimit: 120 5 | IndentWidth: 4 6 | BreakBeforeBraces: Attach 7 | NamespaceIndentation: None 8 | AlwaysBreakTemplateDeclarations: true 9 | SpacesInParentheses: true 10 | SpaceBeforeParens: Never 11 | BreakConstructorInitializersBeforeComma: true 12 | PointerAlignment: Left 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.rsp 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | ThinkboxLibrary 2 | Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ThinkboxLibrary 2 | 3 | ## Overview 4 | 5 | ThinkboxLibrary is a general purpose C++ library with a focus on computer graphics. It makes up the backbone of all of Thinkbox's 3D Graphics Tools. 6 | 7 | ## Table of Contents 8 | 9 | - [Reporting Bugs/Feature Requests](#reporting-bugs/feature-requests) 10 | - [Security issue notifications](#security-issue-notifications) 11 | - [Contributing](#contributing) 12 | - [Code of Conduct](#code-of-conduct) 13 | - [Licensing](#licensing) 14 | 15 | ## Reporting Bugs/Feature Requests 16 | 17 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 18 | 19 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 20 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 21 | 22 | - A reproducible test case or series of steps 23 | - The version of our code being used 24 | - Any modifications you've made relevant to the bug 25 | - Anything unusual about your environment or deployment 26 | 27 | ## Security issue notifications 28 | 29 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 30 | 31 | ## Contributing 32 | 33 | Contributions to ThinkboxLibrary are encouraged. If you want to fix a problem, or want to enhance the library in any way, then 34 | we are happy to accept your contribution. Information on contributing to ThinkboxLibrary can be found 35 | [in CONTRIBUTING.md](CONTRIBUTING.md). 36 | 37 | ## Code of Conduct 38 | 39 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 40 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 41 | opensource-codeofconduct@amazon.com with any additional questions or comments. 42 | 43 | ## Licensing 44 | 45 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 46 | 47 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 48 | -------------------------------------------------------------------------------- /UnitTests/.gitignore: -------------------------------------------------------------------------------- 1 | TestOutputs/ 2 | -------------------------------------------------------------------------------- /UnitTests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | cmake_minimum_required( VERSION 3.15 FATAL_ERROR ) 4 | 5 | project( ThinkboxLibraryTest ) 6 | 7 | find_package( thinkboxcmlibrary REQUIRED ) 8 | include( PrecompiledHeader) 9 | include( ThinkboxCMLibrary) 10 | 11 | add_executable( test_thinkboxlibrary "" ) 12 | 13 | set_property( TARGET test_thinkboxlibrary PROPERTY CXX_STANDARD 17 ) 14 | 15 | target_include_directories( test_thinkboxlibrary 16 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) 17 | 18 | # Treat warnings as errors 19 | if( WIN32 ) 20 | target_compile_options(test_thinkboxlibrary PRIVATE "/W3" "/WX") 21 | endif() 22 | 23 | target_include_directories( test_thinkboxlibrary PRIVATE "../include" ) 24 | target_link_libraries( test_thinkboxlibrary PRIVATE thinkboxlibrary ) 25 | 26 | find_package( GTest REQUIRED ) 27 | target_include_directories( test_thinkboxlibrary PRIVATE ${GTest_INCLUDE_DIRS} ) 28 | target_link_libraries( test_thinkboxlibrary PRIVATE GTest::GTest ) 29 | 30 | # The Conan version of Boost was built with this, and it changes the library names. 31 | # As a result, we need to set this to tell Boost to look for the right libraries to 32 | # link against. 33 | # target_compile_definitions( test_thinkboxlibrary PUBLIC BOOST_AUTO_LINK_SYSTEM ) 34 | 35 | file( GLOB_RECURSE H_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 36 | "*.h" 37 | "*.hpp" 38 | ) 39 | 40 | file( GLOB_RECURSE CXX_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 41 | "*.cpp" 42 | "*.cc" 43 | ) 44 | 45 | target_sources( test_thinkboxlibrary PRIVATE 46 | stdafx.cpp 47 | stdafx.h 48 | ${H_FILES} 49 | ${CXX_FILES} 50 | ) 51 | 52 | frantic_common_platform_setup( test_thinkboxlibrary ) 53 | frantic_default_source_groups( test_thinkboxlibrary ) 54 | frantic_link_apple_core_libraries( test_thinkboxlibrary ) 55 | 56 | add_precompiled_header( test_thinkboxlibrary stdafx.h SOURCE_CXX stdafx.cpp ) 57 | 58 | # Disable optimization for the RelWithDebInfo configuration on Windows. 59 | # This allows breakpoints to be hit reliably when debugging in Visual Studio. 60 | if( WIN32 ) 61 | target_compile_options( test_thinkboxlibrary PRIVATE "$<$:/O2>$<$:/Od>" ) 62 | endif() 63 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/P3D.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/P3D.rdx -------------------------------------------------------------------------------- /UnitTests/TestInputs/Texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/Texture.png -------------------------------------------------------------------------------- /UnitTests/TestInputs/TextureJ.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/TextureJ.jpeg -------------------------------------------------------------------------------- /UnitTests/TestInputs/align.aln: -------------------------------------------------------------------------------- 1 | 2 2 | hdri_colors.csv 3 | # 4 | -1 0 0 0 5 | 0 1 0 0 6 | 0 0 1 0 7 | 0 0 0 1 8 | singleplusoffset.csv 9 | # 10 | -1 0 0 2 11 | 0 -1 0 -4 12 | 0 0 -1 7 13 | 0 0 0 1 14 | 0 15 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/aln_toofew.aln: -------------------------------------------------------------------------------- 1 | 3 2 | hdri_colors.csv 3 | # 4 | -1 0 0 0 5 | 0 1 0 0 6 | 0 0 1 0 7 | 0 0 0 1 8 | singleplusoffset.csv 9 | # 10 | -1 0 0 2 11 | 0 -1 0 -4 12 | 0 0 -1 7 13 | 0 0 0 1 14 | 0 15 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/aln_toomany.aln: -------------------------------------------------------------------------------- 1 | 2 2 | hdri_colors.csv 3 | # 4 | -1 0 0 0 5 | 0 1 0 0 6 | 0 0 1 0 7 | 0 0 0 1 8 | singleplusoffset.csv 9 | # 10 | -1 0 0 2 11 | 0 -1 0 -4 12 | 0 0 -1 7 13 | 0 0 0 1 14 | singleplusoffset.csv 15 | # 16 | 1 0 0 10 17 | 0 -1 0 6 18 | 0 0 -1 0 19 | 0 0 0 1 20 | 0 21 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/bunnyFloat_nolod.sprt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/bunnyFloat_nolod.sprt -------------------------------------------------------------------------------- /UnitTests/TestInputs/bunnyFloat_wlod.sprt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/bunnyFloat_wlod.sprt -------------------------------------------------------------------------------- /UnitTests/TestInputs/coordsTest1.dp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/coordsTest1.dp -------------------------------------------------------------------------------- /UnitTests/TestInputs/coordsTest2.dp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/coordsTest2.dp -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_anisotropic_0.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_anisotropic_0.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_anisotropic_1.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_anisotropic_1.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_anisotropic_2.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_anisotropic_2.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_metaball_0.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_metaball_0.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_metaball_1.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_metaball_1.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_metaball_2.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_metaball_2.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_union_of_spheres_0.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_union_of_spheres_0.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_union_of_spheres_1.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_union_of_spheres_1.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_union_of_spheres_2.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_union_of_spheres_2.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_zhu_bridson_0.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_zhu_bridson_0.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_zhu_bridson_1.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_zhu_bridson_1.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/density_zhu_bridson_2.rls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/density_zhu_bridson_2.rls -------------------------------------------------------------------------------- /UnitTests/TestInputs/doubleFloat.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/doubleFloat.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/doubleFloat.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/doubleFloat.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/float16.csv: -------------------------------------------------------------------------------- 1 | float16 Position,float16 Position,float16 Position 2 | 11,12,44 3 | 27,5,55 4 | 46,12.4,22 5 | 14,4.1,33.1 6 | 12,3,10 7 | 1,85,70 8 | 0,3,65 9 | 99,10.1,38 10 | 54,21,91 11 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/hdri_colors.csv: -------------------------------------------------------------------------------- 1 | Position, Position, Position, Color, Color, Color 2 | 0, 0, 0, 5, 3, 1 3 | 1, 0, 0, 0.001, 0.002, 0.0005 4 | 0, 1, 0, 0.5, 1.0, 0.4 5 | 0, 0, 1, 0.8, 1.2, 0.8 6 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/infinite_loop.rsp: -------------------------------------------------------------------------------- 1 | ? -------------------------------------------------------------------------------- /UnitTests/TestInputs/intColor.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/intColor.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/intColor.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/intColor.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/loadSingleScan.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/loadSingleScan.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/loadSingleScan.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/loadSingleScan.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/loadSingleScanT.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/loadSingleScanT.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/loadSingleScanT.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/loadSingleScanT.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/malicious_whitespace_after_quote.csv: -------------------------------------------------------------------------------- 1 | "" 2 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/massive_chunk_divisible.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/massive_chunk_divisible.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/massive_chunk_indivisible.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/massive_chunk_indivisible.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/negative_eight.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/negative_eight.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/noNormals.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/noNormals.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/noNormals.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/noNormals.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/ot_35120B4116B_1.laz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/ot_35120B4116B_1.laz -------------------------------------------------------------------------------- /UnitTests/TestInputs/prt_fractal_for_krscene.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/prt_fractal_for_krscene.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/pts_inconsistent_channels.pts: -------------------------------------------------------------------------------- 1 | 7 2 | -140.91592 89.39589 54.28458 210 70 57 49 3 | -140.76392 89.40089 54.23358 249 59 50 41 4 | -140.32067 89.34737 53.43675 0 136 133 98 5 | -140.31792 89.35763 53.47004 255 136 133 98 6 | -125.36589 90.0983 62.40685 255 7 | -124.96689 89.8673 62.31185 0 8 | -141.53115 89.22539 55.13645 27 104 109 129 9 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/rgb_magnitude_127.las: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/rgb_magnitude_127.las -------------------------------------------------------------------------------- /UnitTests/TestInputs/scale_offset_las.las: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/scale_offset_las.las -------------------------------------------------------------------------------- /UnitTests/TestInputs/scale_offset_laz.laz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/scale_offset_laz.laz -------------------------------------------------------------------------------- /UnitTests/TestInputs/scaledInteger.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/scaledInteger.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/scaledInteger.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/scaledInteger.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/simple_xyzrgb_pts.pts: -------------------------------------------------------------------------------- 1 | 5 2 | 0 0 0 0 0 0 3 | 1 0 0 128 255 255 4 | 0 1 0 255 128 0 5 | 0 0 1 0 255 128 6 | 2 3 4 63 128 255 7 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/simple_xyzrgb_ptx.ptx: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 0 0 0 4 | 1 0 0 5 | 0 1 0 6 | 0 0 1 7 | 1 0 0 0 8 | 0 1 0 0 9 | 0 0 1 0 10 | 0 0 0 1 11 | 0 0 0 255 0 128 12 | 1 0 0 64 192 255 13 | 0 1 0 50 90 100 14 | 0 0 1 12 22 250 15 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/singleplusoffset.csv: -------------------------------------------------------------------------------- 1 | float64 Position,float64 Position,float64 Position,Color,Color,Color 2 | 100000000,400,401000001,1,0.66666,0.2 3 | 100000001,500,401000000,0.33333,1,0.1 4 | 100000010,600,401000002,0.12345,0.54321,1 5 | 100000100,700,401000003,1,1,1 6 | 100000000,900,401000004,0,0,0.0001 7 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/transforms.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/transforms.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/transforms.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/transforms.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/twoScans.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/twoScans.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/twoScans.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/twoScans.prt -------------------------------------------------------------------------------- /UnitTests/TestInputs/variety.aln: -------------------------------------------------------------------------------- 1 | 6 2 | intColor.prt 3 | # 4 | 717.1969444082445 326.69458919274257 -647.617699401002 -406.9242697290574 5 | 954.5372303016541 209.8710170122074 -930.1021600843956 901.5319708453505 6 | -121.32680845462392 490.7905621404634 -585.677279722057 -210.86889162471368 7 | 501.4218330272854 272.31519910961765 859.2444155562719 116.40924282311926 8 | scale_offset_las.las 9 | # 10 | -638.4616140774733 -43.983628320985304 501.4727786741853 486.53724482047346 11 | -775.6111858930155 224.62615588950052 324.721600726783 -929.2668937895945 12 | -433.32686291981975 358.8467232765372 764.658555590504 -300.26329198458154 13 | 868.0703744984751 231.61573297133532 296.9875966928348 -686.9035639865401 14 | pts_inconsistent_channels.pts 15 | # 16 | -70.50402526766368 -96.55087768653425 -428.37609341833956 -220.5565932560669 17 | 216.03507836695394 -386.89903398933984 373.9322301850568 625.5427621271613 18 | -394.20353572310887 -22.323114007633194 11.17992561891333 -358.93937542514334 19 | -235.09740818014245 286.7448485441296 845.6884294431557 -508.99853381760596 20 | bunnyFloat_wlod.sprt 21 | # 22 | -143.9299971833252 -900.0755749296745 88.8513525753383 924.2281160751047 23 | 463.4312547106458 -819.9498082622945 -207.56634201010309 -435.8655640213933 24 | 363.49353131727753 -38.055306469356765 979.0353561480686 55.527618719156635 25 | -749.8229199248912 226.70452494176152 103.71354414726375 154.06840964133153 26 | hdri_colors.csv 27 | # 28 | -937.114160904982 907.8036620211371 -661.0550732641842 5.453083443112973 29 | -810.5345416466141 444.69723455904114 469.54638840798316 -637.8326506154287 30 | -76.66969015601398 -635.1160898894836 237.93248665477563 282.4855555695624 31 | 74.52991470102756 -317.3180783159828 -937.144805229146 809.4780975471595 32 | wnormals.e57 33 | # 34 | -891.1280813532369 758.9904178188804 93.53572629705718 -745.4208916778937 35 | -181.6040461628603 923.9285520155013 787.7624143398384 -223.2669876565734 36 | -337.0265665480101 504.08057930309224 -697.6268496448448 221.82619107676896 37 | 500.2995113067045 612.9204821600688 -76.94768439802704 532.0635043106622 38 | 0 39 | -------------------------------------------------------------------------------- /UnitTests/TestInputs/wnormals.e57: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/wnormals.e57 -------------------------------------------------------------------------------- /UnitTests/TestInputs/wnormals.prt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-library/baa76215a112d1521336cb434495b1a5ac8a7b61/UnitTests/TestInputs/wnormals.prt -------------------------------------------------------------------------------- /UnitTests/TestOutputs/.empty: -------------------------------------------------------------------------------- 1 | File here to make sure the folder exists, because git. 2 | -------------------------------------------------------------------------------- /UnitTests/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // clang-format off 31 | #include "stdafx.h" 32 | // clang-format on 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | namespace fs = boost::filesystem; 40 | 41 | GTEST_API_ int main( int argc, char** argv ) { 42 | printf( "Running main() from gtest_main.cc\n" ); 43 | 44 | // Search up the directory tree until we find FranticLibrary, 45 | // then descend into FranticLibrary/UnitTests. This will run 46 | // the tests in the correct directory from various build directory 47 | // choices. 48 | while( !fs::is_directory( "ThinkboxFranticLibrary" ) ) { 49 | fs::current_path( ".." ); 50 | } 51 | fs::current_path( "ThinkboxFranticLibrary/UnitTests" ); 52 | 53 | testing::InitGoogleTest( &argc, argv ); 54 | return RUN_ALL_TESTS(); 55 | } 56 | -------------------------------------------------------------------------------- /UnitTests/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.cpp : source file that includes just the standard includes 4 | // FranticTestExperimental.pch will be the pre-compiled header 5 | // stdafx.obj will contain the pre-compiled type information 6 | 7 | // clang-format off 8 | #include "stdafx.h" 9 | // clang-format on 10 | 11 | // TODO: reference any additional headers you need in STDAFX.H 12 | // and not in this file 13 | -------------------------------------------------------------------------------- /UnitTests/stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.h : include file for standard system include files, 4 | // or project specific include files that are used frequently, but 5 | // are changed infrequently 6 | // 7 | 8 | #define _VARIADIC_MAX 10 9 | #define GTEST_HAS_TR1_TUPLE 0 10 | 11 | #ifndef _USE_MATH_DEFINES 12 | #define _USE_MATH_DEFINES 13 | #endif 14 | 15 | #include "targetver.h" 16 | 17 | #ifdef _WIN32 18 | #include 19 | 20 | #ifndef NOMINMAX 21 | #define NOMINMAX 22 | #endif 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "gtest/gtest.h" 32 | 33 | // Eigen SIMD is ICEing on MSVC 2008 34 | #if defined( _MSC_VER ) && _MSC_VER < 1600 35 | #define EIGEN_DONT_VECTORIZE 36 | #endif 37 | -------------------------------------------------------------------------------- /UnitTests/targetver.h: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | // Including SDKDDKVer.h defines the highest available Windows platform. 6 | 7 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 8 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 9 | 10 | #if defined( _WIN32 ) || defined( _WIN64 ) 11 | #include 12 | #endif 13 | -------------------------------------------------------------------------------- /UnitTests/test_channels/test_named_channel_data.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | #if defined( _MSC_VER ) 10 | #pragma warning( push ) 11 | // TODO: this is to get rid of all the 'deprecated' warnings about getenv and such 12 | #pragma warning( disable : 4996 ) 13 | #endif 14 | 15 | using namespace frantic::channels; 16 | 17 | template 18 | class OffsetInputWeightedSumCombine : public ::testing::Test {}; 19 | 20 | typedef ::testing::Types 22 | NumericChannelDataTypes; 23 | 24 | TYPED_TEST_CASE( OffsetInputWeightedSumCombine, NumericChannelDataTypes ); 25 | 26 | TYPED_TEST( OffsetInputWeightedSumCombine, Offset1Arity1 ) { 27 | const std::size_t arity = 1; 28 | 29 | float weights[2] = { 0, 1 }; 30 | 31 | TypeParam a[arity + 2] = { 1, 2, 3 }; 32 | TypeParam b[arity + 2] = { 4, 5, 6 }; 33 | const char* data[] = { reinterpret_cast( a ), reinterpret_cast( b ) }; 34 | 35 | TypeParam out[arity + 1] = { 0, 0 }; 36 | 37 | const data_type_t dataType = channel_data_type_traits::data_type(); 38 | 39 | offset_input_channel_weighted_sum_combine_function_t f = 40 | offset_input_channel_weighted_sum_combine_function( dataType ); 41 | 42 | f( weights, sizeof( TypeParam ), data, 2, arity, reinterpret_cast( out ) ); 43 | 44 | EXPECT_EQ( 5, out[0] ); 45 | EXPECT_EQ( 0, out[1] ); 46 | } 47 | 48 | TYPED_TEST( OffsetInputWeightedSumCombine, Offset1Arity2 ) { 49 | const std::size_t arity = 2; 50 | 51 | float weights[2] = { 1, 0 }; 52 | 53 | TypeParam a[arity + 2] = { 1, 2, 3, 4 }; 54 | TypeParam b[arity + 2] = { 5, 6, 7, 8 }; 55 | const char* data[] = { reinterpret_cast( a ), reinterpret_cast( b ) }; 56 | 57 | TypeParam out[arity + 1] = { 0, 0, 0 }; 58 | 59 | const data_type_t dataType = channel_data_type_traits::data_type(); 60 | 61 | offset_input_channel_weighted_sum_combine_function_t f = 62 | offset_input_channel_weighted_sum_combine_function( dataType ); 63 | 64 | f( weights, sizeof( TypeParam ), data, 2, arity, reinterpret_cast( out ) ); 65 | 66 | EXPECT_EQ( 2, out[0] ); 67 | EXPECT_EQ( 3, out[1] ); 68 | EXPECT_EQ( 0, out[2] ); 69 | } 70 | -------------------------------------------------------------------------------- /UnitTests/test_files/test_filename_pattern.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | // SPDX-License-Identifier: Apache-2.0 4 | // clang-format off 5 | #include "stdafx.h" 6 | // clang-format on 7 | 8 | #include 9 | 10 | #include "gtest/gtest.h" 11 | 12 | TEST( FilesTest, FilenamePattern ) { 13 | // This is just a regression test to make sure the int to string conversion 14 | // in frantic::files::filename_pattern::build_whole_frame_seq_string 15 | // still works correctly after changing it to use a safer implementation. 16 | frantic::files::filename_pattern pattern( _T( "seq_####.exr" ) ); 17 | ASSERT_EQ(pattern[0], _T( "seq_0000.exr" ) ); 18 | ASSERT_EQ(pattern[1], _T( "seq_0001.exr" ) ); 19 | ASSERT_EQ(pattern[10], _T( "seq_0010.exr" ) ); 20 | ASSERT_EQ(pattern[10000], _T( "seq_10000.exr" ) ); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /UnitTests/test_geometry/test_dcel_mesh_interface.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include "utilities/mesh_generators.hpp" 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace frantic::geometry; 15 | namespace { 16 | 17 | polymesh3_ptr make_single_vertex_polymesh() { 18 | // Create the polymesh3 to test 19 | polymesh3_builder builder; 20 | builder.add_vertex( 0, 0, 0 ); 21 | 22 | polymesh3_ptr polymesh = builder.finalize(); 23 | EXPECT_TRUE( bool( polymesh ) ); 24 | 25 | return polymesh; 26 | } 27 | } // anonymous namespace 28 | 29 | TEST( DCELInterface, VertAdjacency ) { 30 | using namespace boost; 31 | 32 | polymesh3_ptr triangle = make_triangle_polymesh(); 33 | polymesh3_ptr vertex = make_single_vertex_polymesh(); 34 | dcel adjacency; 35 | polymesh3_to_dcel( triangle, adjacency ); 36 | mesh_interface_ptr connected = 37 | boost::shared_ptr( new dcel_mesh_interface( boost::move( adjacency ) ) ); 38 | frantic::geometry::vertex_iterator vIt; 39 | EXPECT_TRUE( connected->init_vertex_iterator( vIt, 0 ) ); 40 | 41 | polymesh3_to_dcel( vertex, adjacency ); 42 | mesh_interface_ptr unconnected = 43 | boost::shared_ptr( new dcel_mesh_interface( boost::move( adjacency ) ) ); 44 | 45 | EXPECT_FALSE( unconnected->init_vertex_iterator( vIt, 0 ) ); 46 | } 47 | -------------------------------------------------------------------------------- /UnitTests/test_geometry/test_delegated_const_mesh_interface.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | TEST( DelegatedConstMeshInterface, OneTriangle ) { 13 | frantic::geometry::trimesh3 mesh; 14 | 15 | mesh.add_vertex( 0, 0, 0 ); 16 | mesh.add_vertex( 1, 0, 0 ); 17 | mesh.add_vertex( 1, 1, 1 ); 18 | 19 | frantic::geometry::mesh_interface::ptr_type a( 20 | frantic::geometry::trimesh3_interface::create_instance( boost::move( mesh ) ).release() ); 21 | 22 | frantic::geometry::mesh_interface::ptr_type b( new frantic::geometry::delegated_const_mesh_interface( a.get() ) ); 23 | 24 | ASSERT_TRUE( bool( b ) ); 25 | ASSERT_TRUE( b->is_valid() ); 26 | 27 | EXPECT_TRUE( frantic::geometry::is_equal( a, b ) ); 28 | } 29 | -------------------------------------------------------------------------------- /UnitTests/test_geometry/test_mixed_kdtree.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | #include 9 | 10 | #include "gtest/gtest.h" 11 | 12 | #include 13 | #include 14 | 15 | TEST(GeometryTest, MixedKDTreePointData) { 16 | // We're interested in testing mixed_kdtree_point_data::set_my_data_from 17 | // which is called by the overload of the constructor that takes raw data. 18 | // We're primarily interested in testing against buffer overflows caused by off-by-one errors 19 | // when the mixed_kdtree_point_data is in its static data mode (size <= 80). 20 | 21 | // Create an std::vector of length 80 that starts with 'a', ends with 'z', and is 22 | // otherwise filled with 'b'. 23 | constexpr std::size_t size{ 80 }; 24 | std::array data; 25 | data[0] = 'a'; 26 | std::fill( data.begin() + 1, data.end(), 'b' ); 27 | data[size - 1] = 'z'; 28 | 29 | // Initialize a mixed_kdtree_point_data such that set_my_data_from is called 30 | frantic::graphics::vector3f origin; 31 | frantic::geometry::mixed_kdtree_point_data point_data( origin, 0., origin, nullptr, data.data(), data.size() ); 32 | 33 | // Get the primitive data 34 | const char* primitive_data = point_data.get_primitive_data(); 35 | const std::size_t primitive_data_size = point_data.get_primitive_data_size(); 36 | 37 | // Check to make sure the data we get back is as expected. 38 | ASSERT_EQ( primitive_data[0],'a' ); 39 | for( std::size_t i = 1ull; i < primitive_data_size - 1; ++i ) { 40 | ASSERT_EQ( primitive_data[i], 'b' ); 41 | } 42 | ASSERT_EQ( primitive_data[size - 1], 'z' ); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /UnitTests/test_graphics/test_alpha3f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | using frantic::graphics::alpha3f; 12 | 13 | TEST( alpha3f, to_inverse ) { 14 | const alpha3f original( 0.25f, 0.5f, 0.75f ); 15 | EXPECT_EQ( alpha3f( 0.75f, 0.5f, 0.25f ), original.to_inverse() ); 16 | } 17 | 18 | TEST( alpha3f, subtraction ) { 19 | const alpha3f a( 1.f ); 20 | const alpha3f b( 0.5f ); 21 | 22 | EXPECT_EQ( b, a - b ); 23 | } 24 | -------------------------------------------------------------------------------- /UnitTests/test_graphics/test_graphics_utils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace frantic::graphics; 14 | 15 | TEST( GraphicsUtils, GetTriangleAngle ) { 16 | const vector3f a( 0, 1, 0 ); 17 | const vector3f b( 0, 0, 0 ); 18 | const vector3f c( 1, 0, 0 ); 19 | 20 | const float angle = get_triangle_angle( a, b, c ); 21 | 22 | EXPECT_EQ( boost::math::constants::pi() / 2, angle ); 23 | } 24 | -------------------------------------------------------------------------------- /UnitTests/test_graphics/test_units.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | using std::numeric_limits; 12 | using namespace frantic::graphics; 13 | using frantic::graphics::length_unit::format_autoscale; 14 | 15 | TEST( Units, FormatAutoScale ) { 16 | double nan = numeric_limits::quiet_NaN(); 17 | double inf = numeric_limits::infinity(); 18 | // Infinity/NaN cases 19 | EXPECT_EQ( _T("nan"), format_autoscale( nan, length_unit::invalid, 2 ) ); 20 | EXPECT_EQ( _T("inf"), format_autoscale( inf, length_unit::invalid, 2 ) ); 21 | EXPECT_EQ( _T("-inf"), format_autoscale( -inf, length_unit::invalid, 2 ) ); 22 | EXPECT_EQ( _T("nan"), format_autoscale( nan, length_unit::meters, 2 ) ); 23 | EXPECT_EQ( _T("inf"), format_autoscale( inf, length_unit::meters, 2 ) ); 24 | EXPECT_EQ( _T("-inf"), format_autoscale( -inf, length_unit::meters, 2 ) ); 25 | // Without a unit specified 26 | EXPECT_EQ( _T("3.14"), format_autoscale( 3.141, length_unit::invalid, 3 ) ); 27 | EXPECT_EQ( _T("3.141"), format_autoscale( 3.141, length_unit::invalid, 4 ) ); 28 | // Reasonable values should stick to the specified unit 29 | EXPECT_EQ( _T("3.14 mm"), format_autoscale( 3.141, length_unit::millimeters, 3 ) ); 30 | EXPECT_EQ( _T("3.14 cm"), format_autoscale( 3.141, length_unit::centimeters, 3 ) ); 31 | EXPECT_EQ( _T("3.14 in"), format_autoscale( 3.141, length_unit::inches, 3 ) ); 32 | EXPECT_EQ( _T("3.14 ft"), format_autoscale( 3.141, length_unit::feet, 3 ) ); 33 | EXPECT_EQ( _T("3.14 yd"), format_autoscale( 3.141, length_unit::yards, 3 ) ); 34 | // Large/small values should autoscale to different unit 35 | EXPECT_EQ( _T("3.14 m"), format_autoscale( 3141, length_unit::millimeters, 3 ) ); 36 | EXPECT_EQ( _T("3.14 km"), format_autoscale( 3141000, length_unit::millimeters, 3 ) ); 37 | EXPECT_EQ( _T("3.14 mm"), format_autoscale( 0.003141, length_unit::meters, 3 ) ); 38 | EXPECT_EQ( _T("3.14 m"), format_autoscale( 0.003141, length_unit::kilometers, 3 ) ); 39 | EXPECT_EQ( _T("3.14 mm"), format_autoscale( 0.000003141, length_unit::kilometers, 3 ) ); 40 | EXPECT_EQ( _T("3.14 m"), format_autoscale( 3141, length_unit::millimeters, 3 ) ); 41 | // note: The std::ostream formatting doesn't quite give enough control, might want to roll our own... 42 | EXPECT_EQ( _T("1 in"), format_autoscale( 1.0 / 12.0, length_unit::feet, 2 ) ); 43 | EXPECT_EQ( _T("3 in"), format_autoscale( 3.0 / 12.0 / 3.0, length_unit::yards, 2 ) ); 44 | } -------------------------------------------------------------------------------- /UnitTests/test_graphics2d/test_boundrect2f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | TEST( Boundrect2f, AreaIntersectingLineSegment ) { 12 | using namespace std; 13 | using namespace frantic::graphics2d; 14 | 15 | boundrect2f br( vector2f( 0, 0 ), vector2f( 1, 1 ) ); 16 | 17 | EXPECT_TRUE( br.is_area_intersecting_line_segment( vector2f( -100, 1 ), vector2f( 100, 0.99999f ) ) ); 18 | EXPECT_TRUE( br.is_area_intersecting_line_segment( vector2f( -10, 0.5f ), vector2f( 10, 0.5f ) ) ); 19 | EXPECT_TRUE( br.is_area_intersecting_line_segment( vector2f( 10, 0.5f ), vector2f( -10, 0.5f ) ) ); 20 | EXPECT_TRUE( br.is_area_intersecting_line_segment( vector2f( 0, -10 ), vector2f( 1, 10 ) ) ); 21 | EXPECT_TRUE( br.is_area_intersecting_line_segment( vector2f( 0.4999f, 10 ), vector2f( 0.5f, -10 ) ) ); 22 | 23 | EXPECT_TRUE( br.is_area_intersecting_line_segment( vector2f( 0, 1.9f ), vector2f( 2, 0 ) ) ); 24 | EXPECT_TRUE( !br.is_area_intersecting_line_segment( vector2f( 0, 2.1f ), vector2f( 2, 0 ) ) ); 25 | EXPECT_TRUE( !br.is_area_intersecting_line_segment( vector2f( -100, .5f ), vector2f( 0.5f, 1.01f ) ) ); 26 | EXPECT_TRUE( br.is_area_intersecting_line_segment( vector2f( -100, .5f ), vector2f( 0.5f, 1.001f ) ) ); 27 | } 28 | -------------------------------------------------------------------------------- /UnitTests/test_graphics2d/test_image_channel.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | using namespace frantic::graphics2d; 12 | 13 | struct test_function { 14 | inline float operator()( const float& left, const float& right ) { return left * 10.f + right; } 15 | }; 16 | 17 | TEST( ImageChannel, ApplyFunction ) { 18 | image_channel leftChannel; 19 | leftChannel.resize( size2( 2, 2 ) ); 20 | leftChannel.set_pixel( 0, 0, 0.f ); 21 | leftChannel.set_pixel( 0, 1, 1.f ); 22 | leftChannel.set_pixel( 1, 0, 2.f ); 23 | leftChannel.set_pixel( 1, 1, 3.f ); 24 | 25 | image_channel rightChannel; 26 | rightChannel.resize( size2( 2, 2 ) ); 27 | rightChannel.set_pixel( 0, 0, 4.f ); 28 | rightChannel.set_pixel( 0, 1, 5.f ); 29 | rightChannel.set_pixel( 1, 0, 6.f ); 30 | rightChannel.set_pixel( 1, 1, 7.f ); 31 | 32 | leftChannel.apply_function( rightChannel, test_function() ); 33 | 34 | EXPECT_EQ( 4.f, leftChannel.get_pixel( 0, 0 ) ); 35 | EXPECT_EQ( 15.f, leftChannel.get_pixel( 0, 1 ) ); 36 | EXPECT_EQ( 26.f, leftChannel.get_pixel( 1, 0 ) ); 37 | EXPECT_EQ( 37.f, leftChannel.get_pixel( 1, 1 ) ); 38 | } 39 | -------------------------------------------------------------------------------- /UnitTests/test_graphics2d/test_vector2f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | TEST( Vector2f, TriangleMethods ) { 12 | using namespace std; 13 | using namespace frantic::graphics2d; 14 | vector2f a, b, c; 15 | a = vector2f( 0, 0 ); 16 | b = vector2f( 1, 0 ); 17 | c = vector2f( 0, 1 ); 18 | EXPECT_LT( fabsf( 0.5f - vector2f::triangle_area( a, b, c ) ), 0.0001f ); 19 | EXPECT_LT( 0, vector2f::triangle_curvature( a, b, c ) ); 20 | EXPECT_LT( vector2f::triangle_curvature( c, b, a ), 0 ); 21 | } 22 | -------------------------------------------------------------------------------- /UnitTests/test_locale/test_locale.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | TEST( Locale, SetLocaleInScope ) { 14 | #ifdef _WIN32 15 | #if defined( _MSC_VER ) && _MSC_VER >= 1700 16 | const char* german = "de-DE"; 17 | #else 18 | const char* german = "German"; 19 | #endif 20 | #else 21 | const char* german = "de_DE.UTF-8"; 22 | #endif 23 | 24 | { // test in German locale 25 | frantic::locale::set_locale_in_scope setLocale( german ); 26 | 27 | EXPECT_EQ( "0,5", boost::lexical_cast( 0.5 ) ); 28 | } 29 | 30 | { // back to "C" locale 31 | EXPECT_EQ( "0.5", boost::lexical_cast( 0.5 ) ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /UnitTests/test_math/test_math.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | TEST( Math, Utils ) { 14 | double zero = 0.0; 15 | double inf = numeric_limits::infinity(); 16 | double nan = numeric_limits::quiet_NaN(); 17 | // is_finite 18 | EXPECT_TRUE( frantic::math::is_finite( zero ) ); 19 | EXPECT_FALSE( frantic::math::is_finite( inf ) ); 20 | EXPECT_FALSE( frantic::math::is_finite( -inf ) ); 21 | EXPECT_FALSE( frantic::math::is_infinite( nan ) ); 22 | // is_infinite 23 | EXPECT_FALSE( frantic::math::is_infinite( zero ) ); 24 | EXPECT_TRUE( frantic::math::is_infinite( inf ) ); 25 | EXPECT_TRUE( frantic::math::is_infinite( -inf ) ); 26 | EXPECT_FALSE( frantic::math::is_infinite( nan ) ); 27 | // is_nan 28 | EXPECT_FALSE( frantic::math::is_nan( zero ) ); 29 | EXPECT_FALSE( frantic::math::is_nan( inf ) ); 30 | EXPECT_FALSE( frantic::math::is_nan( -inf ) ); 31 | EXPECT_TRUE( frantic::math::is_nan( nan ) ); 32 | } 33 | -------------------------------------------------------------------------------- /UnitTests/test_math/test_math_utils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | using namespace frantic::math; 10 | 11 | TEST( MathUtils, Log2Uint32 ) { 12 | const boost::uint32_t lsb = 1; 13 | EXPECT_EQ( 0, log2_uint32( lsb ) ); 14 | 15 | const boost::uint32_t msb = 0xFFFFFFFF; 16 | EXPECT_EQ( 31, log2_uint32( msb ) ); 17 | } 18 | 19 | TEST( MathUtils, IsPowerOfTwo ) { 20 | EXPECT_FALSE( is_power_of_two( 0 ) ); 21 | EXPECT_TRUE( is_power_of_two( 1 ) ); 22 | EXPECT_TRUE( is_power_of_two( 2 ) ); 23 | EXPECT_FALSE( is_power_of_two( 3 ) ); 24 | EXPECT_TRUE( is_power_of_two( 4 ) ); 25 | } 26 | -------------------------------------------------------------------------------- /UnitTests/test_misc/test_indexer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | TEST( Indexer, Simple2dIndexer ) { 12 | using namespace frantic; 13 | 14 | indexer idx = make_indexer( 5, 5 ); 15 | 16 | std::vector coverage( 5 * 5, false ); 17 | 18 | size_t currentIndex = 0; 19 | 20 | for( size_t x0 = 0; x0 < 5; ++x0 ) { 21 | for( size_t x1 = 0; x1 < 5; ++x1 ) { 22 | size_t index = idx.address( x0, x1 ); 23 | ASSERT_GT( coverage.size(), index ); 24 | EXPECT_EQ( currentIndex, index ); 25 | EXPECT_FALSE( coverage[index] ); 26 | coverage[index] = true; 27 | ++currentIndex; 28 | } 29 | } 30 | } 31 | 32 | TEST( Indexer, Simple3dIndexer ) { 33 | using namespace frantic; 34 | 35 | indexer idx = make_indexer( 5, 5, 5 ); 36 | 37 | std::vector coverage( 5 * 5 * 5, false ); 38 | 39 | size_t currentIndex = 0; 40 | 41 | for( size_t x0 = 0; x0 < 5; ++x0 ) { 42 | for( size_t x1 = 0; x1 < 5; ++x1 ) { 43 | for( size_t x2 = 0; x2 < 5; ++x2 ) { 44 | size_t index = idx.address( x0, x1, x2 ); 45 | ASSERT_GT( coverage.size(), index ); 46 | EXPECT_EQ( currentIndex, index ); 47 | EXPECT_FALSE( coverage[index] ); 48 | coverage[index] = true; 49 | ++currentIndex; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /UnitTests/test_misc/test_range_segmentation.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | TEST( MeshSegmentation, InitializeSingleChart ) { 16 | using namespace frantic; 17 | 18 | const size_t numFaces = 50; 19 | 20 | // all faces in single subset 21 | std::vector segments( numFaces, 0 ); 22 | 23 | range_segmentation seg( segments.begin(), segments.end(), 1 ); 24 | 25 | EXPECT_EQ( 1, seg.get_num_subsets() ); 26 | EXPECT_EQ( numFaces, seg.get_subset_size( 0 ) ); 27 | } 28 | 29 | namespace { 30 | 31 | void make_modulus_segmentation( size_t numFaces, size_t numCharts, frantic::range_segmentation& segmentation ) { 32 | std::vector segments( numFaces, 0 ); 33 | 34 | for( size_t i = 0; i < segments.size(); ++i ) { 35 | segments[i] = i % numCharts; 36 | } 37 | 38 | segmentation.assign( segments.begin(), segments.end(), numCharts ); 39 | } 40 | 41 | } // namespace 42 | 43 | TEST( MeshSegmentation, InitializeMultiChart ) { 44 | using namespace frantic; 45 | 46 | const size_t numFaces = 64; 47 | const size_t numCharts = 4; 48 | 49 | range_segmentation seg; 50 | make_modulus_segmentation( numFaces, numCharts, seg ); 51 | 52 | EXPECT_EQ( 4, seg.get_num_subsets() ); 53 | for( size_t subset = 0; subset < numCharts; ++subset ) { 54 | EXPECT_EQ( numFaces / numCharts, seg.get_subset_size( subset ) ); 55 | } 56 | 57 | for( size_t i = 0; i < numFaces; ++i ) { 58 | EXPECT_EQ( i % numCharts, seg.get_face_subset( i ) ); 59 | } 60 | } 61 | 62 | TEST( MeshSegmentation, MergeSubChart ) { 63 | using namespace frantic; 64 | 65 | const size_t numFaces = 64; 66 | const size_t numSubCharts = 4; 67 | const size_t numChartsPerSubChart = 4; 68 | 69 | range_segmentation inputSeg; 70 | make_modulus_segmentation( numFaces, numSubCharts, inputSeg ); 71 | 72 | range_segmentation resultSeg( numFaces ); 73 | 74 | for( size_t i = 0; i < numSubCharts; ++i ) { 75 | range_segmentation subSeg; 76 | make_modulus_segmentation( numFaces / numSubCharts, numChartsPerSubChart, subSeg ); 77 | 78 | resultSeg.merge_from_subrange_segmentation( subSeg, inputSeg.subset_begin( i ), inputSeg.subset_end( i ) ); 79 | } 80 | 81 | for( size_t i = 0; i < numFaces; ++i ) { 82 | EXPECT_EQ( ( ( i % numSubCharts ) * 4 ) + ( ( i / numSubCharts ) % numChartsPerSubChart ), 83 | resultSeg.get_face_subset( i ) ); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /UnitTests/test_misc/test_string_functions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "gtest/gtest.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | TEST( ZeroPad, PositiveInteger ) { 19 | // The given integer should be converted to a string and padded with zeros until it contains 20 | // at least pad_to characters. 21 | const int pad_to = 4; 22 | const int number = 1; 23 | 24 | const frantic::tstring result = frantic::strings::zero_pad( number, pad_to ); 25 | 26 | EXPECT_EQ( _T( "0001" ), result ); 27 | } 28 | 29 | TEST( ZeroPad, BiggerThanPadding ) { 30 | // A number that is larger than the desired padding should not be truncated. 31 | const int pad_to = 4; 32 | const int number = 99999; 33 | 34 | const frantic::tstring result = frantic::strings::zero_pad( number, pad_to ); 35 | 36 | EXPECT_EQ( _T( "99999" ), result ); 37 | } 38 | 39 | TEST( ZeroPad, NegativeInteger ) { 40 | // When padding a negative number, we want the sign character to be included in the padding count. 41 | const int pad_to = 4; 42 | const int number = -1; 43 | 44 | const frantic::tstring result = frantic::strings::zero_pad( number, pad_to ); 45 | 46 | EXPECT_EQ( _T( "-001" ), result ); 47 | } 48 | 49 | TEST( ZeroPad, NegativeIntegerZeroSize ) { 50 | // Test the edge case where padding is zero. 51 | // This is mainly to ensure bugs aren't introduced due to swapping out 52 | // singed for unsigned types in the implementation and arithmetic operations then causing overflow 53 | const int pad_to = 0; 54 | const int number = -1; 55 | 56 | const frantic::tstring result = frantic::strings::zero_pad( number, pad_to ); 57 | 58 | EXPECT_EQ( _T( "-1" ), result ); 59 | } 60 | -------------------------------------------------------------------------------- /UnitTests/test_os/test_environment_variables.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest-helper.h" 8 | 9 | #include 10 | 11 | using namespace frantic::os; 12 | 13 | TEST( EnvironmentVariables, SetEnvironmentVariable ) { 14 | frantic::tstring key = _T("MY_KEY"); 15 | frantic::tstring value = _T("MY_VALUE"); 16 | 17 | set_environment_variable( key, value ); 18 | set_environment_variable( key, value ); 19 | } 20 | 21 | TEST( EnvironmentVariables, GetEnvironmentVariable ) { 22 | frantic::tstring firstKey = _T("MY_FIRST_KEY"); 23 | frantic::tstring secondKey = _T("MY_SECOND_KEY"); 24 | frantic::tstring firstValue = _T("MY_FIRST_VALUE"); 25 | frantic::tstring secondValue = _T("MY_SECOND_VALUE"); 26 | 27 | set_environment_variable( firstKey, firstValue ); 28 | EXPECT_EQ( firstValue, get_environment_variable( firstKey ) ); 29 | 30 | set_environment_variable( firstKey, secondValue ); 31 | EXPECT_EQ( secondValue, get_environment_variable( firstKey ) ); 32 | 33 | EXPECT_EQ( _T(""), get_environment_variable( secondKey ) ); 34 | } 35 | -------------------------------------------------------------------------------- /UnitTests/test_particles/test_particles_sph.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | TEST( Particle_SPH, Evaluation ) { 28 | using namespace frantic::particles; 29 | using namespace frantic::graphics; 30 | using namespace frantic::volumetrics; 31 | using namespace frantic::volumetrics::levelset; 32 | 33 | channel_map pcm; 34 | pcm.define_channel( _T("Position") ); 35 | pcm.define_channel( _T("Velocity") ); 36 | pcm.define_channel( _T("Acceleration") ); 37 | pcm.define_channel( _T("Density") ); 38 | pcm.define_channel( _T("GradDensity") ); 39 | pcm.define_channel( _T("InelasticCollisionWeightedMass") ); 40 | pcm.define_channel( _T("InelasticCollisionCOMPos") ); 41 | pcm.define_channel( _T("InelasticCollisionCOMVel") ); 42 | pcm.define_channel( _T("InelasticCollisionMomentumTransfer") ); 43 | pcm.define_channel( _T("AccGravityTerm") ); 44 | pcm.define_channel( _T("AccPressureTerm") ); 45 | pcm.define_channel( _T("GhostGradDensityTerm") ); 46 | pcm.define_channel( _T("VelInelasticPrtTerm") ); 47 | pcm.define_channel( _T("VelInelasticOccTerm") ); 48 | pcm.define_channel( _T("VelEulerIntTerm") ); 49 | pcm.end_channel_definition(); 50 | 51 | boundbox3f bounds( vector3f(), vector3f( 20 ) ); 52 | 53 | particle_grid_tree pgt( pcm, frantic::volumetrics::voxel_coord_system() ); 54 | } -------------------------------------------------------------------------------- /UnitTests/test_process/test_child_process.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | using std::string; 10 | 11 | TEST( ChildProcess, EchoHelloWorld ) { 12 | frantic::process::child_process process; 13 | process.set_controlStdOut( true ); 14 | #ifdef _WIN32 15 | process.launch( _T( "cmd" ), _T( "/C echo Hello World" ) ); 16 | #else 17 | process.launch( "echo", "Hello World" ); 18 | #endif 19 | 20 | string output = ""; 21 | EXPECT_TRUE( process.getstdoutline( -1, output ) ); 22 | EXPECT_EQ( "Hello World", output ); 23 | bool complete = process.waitforexit(); 24 | ASSERT_TRUE( complete ); 25 | int exitcode = process.getexitcode(); 26 | EXPECT_EQ( 0, exitcode ); 27 | } 28 | -------------------------------------------------------------------------------- /UnitTests/test_tinyxml/test_tinyxml_utility.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "gtest/gtest.h" 8 | 9 | #include 10 | 11 | TEST( TinyXMLUtility, InfiniteLoop ) { 12 | // Test to make sure calling remove_unsupported_xml_elements() doesn't cause an infinite loop. 13 | // This was know to happen previously when the first character was a '?' or '!' and there was no 14 | //'<' in the file. 15 | boost::filesystem::path filename( _T("TestInputs/infinite_loop.rsp") ); 16 | // If the test fails, this call will cause an infinite loop. 17 | // The test will either timeout if run in the context of CI, or 18 | // otherwise need to be manually stopped. 19 | ASSERT_THROW( frantic::tinyxml::remove_unsupported_xml_elements( filename ), std::runtime_error ); 20 | } 21 | -------------------------------------------------------------------------------- /UnitTests/test_win32/test_utility.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #if defined( _WIN32 ) 8 | 9 | #include 10 | #include 11 | 12 | #include "gtest/gtest.h" 13 | 14 | #include 15 | #include 16 | 17 | TEST( WIN_32, GetUUID ) { 18 | /** 19 | * Tests that get_win32_computer_system_uuid returns the same UUID as 'wmic path win32_computersystemproduct get 20 | * uuid' 21 | */ 22 | frantic::process::child_process cp; 23 | cp.set_terminateOnExit( true ); 24 | cp.set_controlStdOut( true ); 25 | cp.set_hideWindow( true ); 26 | 27 | /** 28 | * wmic is installed on all windows operating systems 29 | * https://docs.microsoft.com/en-us/windows/win32/wmisdk/operating-system-availability-of-wmi-components 30 | * With win32_computersystemproduct being on operating systems Windows Vista and higher 31 | * https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystemproduct 32 | */ 33 | cp.launch( _T("cmd"), _T("/C wmic path win32_computersystemproduct get uuid"), _T("./") ); 34 | 35 | std::string output; 36 | // first line of command output is "UUID" 37 | EXPECT_TRUE( cp.getstdoutline( 1000, output ) ); 38 | // second line of command output is a blank line 39 | EXPECT_TRUE( cp.getstdoutline( 1000, output ) ); 40 | // third line of command output is the actual UUID value such as "EC2AE145-D1DC-13B2-94ED-01234ABCDEF " 41 | EXPECT_TRUE( cp.getstdoutline( 1000, output ) ); 42 | 43 | // the UUID has spaces on the end, trim them off 44 | boost::trim_right( output ); 45 | 46 | frantic::win32::get_win32_computer_system_uuid get_uuid; 47 | const std::wstring uuid = get_uuid.get(); 48 | boost::uuids::string_generator gen; 49 | EXPECT_EQ( gen( uuid ), gen( output ) ); 50 | EXPECT_EQ( gen( uuid ), 51 | gen( output ) ); // calling again to ensure CoInitializeEx and CoUninitialize were called correctly 52 | } 53 | #endif -------------------------------------------------------------------------------- /UnitTests/utilities/e57_generator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | void generate_files( const std::string& fileName, bool hasIntensity, bool hasColor, bool hasNormal, bool posIsDouble, 8 | int numScans, bool posIsScaledInt = false, bool hasTransform = false, bool colorIsInt = false ); -------------------------------------------------------------------------------- /UnitTests/utilities/scoped_temp_file.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | class scoped_temp_file : boost::noncopyable { 10 | public: 11 | scoped_temp_file( boost::filesystem::path extension ) 12 | : m_path( boost::filesystem::unique_path( 13 | ( boost::filesystem::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%." ).replace_extension( extension ) ) ) { 14 | } 15 | 16 | ~scoped_temp_file() { 17 | boost::system::error_code ec; 18 | boost::filesystem::remove( m_path, ec ); 19 | } 20 | 21 | frantic::tstring get_path() const { return frantic::files::to_tstring( m_path ); } 22 | 23 | private: 24 | boost::filesystem::path m_path; 25 | }; -------------------------------------------------------------------------------- /build.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | from __future__ import annotations 4 | from typing import Any 5 | 6 | import argparse 7 | import platform 8 | import pprint 9 | 10 | from cpt.packager import ConanMultiPackager 11 | 12 | COMMON_PACKAGER_ARGS: dict[str, Any] = { 13 | 'build_types': ['Release'], 14 | 'archs': ['x86_64'], 15 | 'build_policy': 'missing' 16 | } 17 | 18 | WINDOWS_PACKAGER_ARGS: dict[str, Any] = { 19 | 'visual_versions': ['15', '16'], 20 | 'visual_runtimes': ['MD'] 21 | } 22 | 23 | LINUX_PACKAGER_ARGS: dict[str, Any] = { 24 | 'gcc_versions': '7' 25 | } 26 | 27 | MACOS_PACKAGER_ARGS: dict[str, Any] = { 28 | 'apple_clang_versions': ['10.0', '12.0'] 29 | } 30 | 31 | def parse_arguments() -> argparse.Namespace: 32 | parser = argparse.ArgumentParser() 33 | parser.add_argument('-u', '--username', default=None, help='The Conan username to use for the built package.') 34 | parser.add_argument('-c', '--channel', default=None, help='The Conan channel to use for the built package.') 35 | parser.add_argument('-o', '--option', action='append', dest='options', help='Specify package options to be used by the build.') 36 | parser.add_argument('--dry-run', action='store_true', help='Print the configurations that would be built without actually building them.') 37 | return parser.parse_args() 38 | 39 | def main() -> None: 40 | args = parse_arguments() 41 | 42 | packager_args = { 43 | 'username': args.username, 44 | 'channel': args.channel, 45 | 'options': args.options 46 | } 47 | packager_args.update(COMMON_PACKAGER_ARGS) 48 | 49 | if platform.system() == 'Windows': 50 | packager_args.update(WINDOWS_PACKAGER_ARGS) 51 | elif platform.system() == 'Linux': 52 | packager_args.update(LINUX_PACKAGER_ARGS) 53 | elif platform.system() == 'Darwin': 54 | packager_args.update(MACOS_PACKAGER_ARGS) 55 | else: 56 | raise Exception('Platform not supported.') 57 | 58 | builder = ConanMultiPackager(**packager_args) 59 | builder.add_common_builds(pure_c=False) 60 | 61 | # Remove the legacy libstdc++ build. 62 | if platform.system() == 'Linux': 63 | builder.remove_build_if(lambda build: build.settings['compiler.libcxx'] == 'libstdc++') 64 | 65 | if args.dry_run: 66 | pprint.pprint(builder.builds, indent=4) 67 | else: 68 | builder.run() 69 | 70 | 71 | if __name__ == '__main__': 72 | main() 73 | -------------------------------------------------------------------------------- /frantic/diagnostics/assert_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | // macros for nice error messages 8 | // if the assert condition fails, 9 | // FRANTIC_ASSERT_THROW() will throw a standard runtime error 10 | // with the message "FileName:LineNumber FunctionName(): assert condition " + 11 | // a string representation of the assert condition + " failed: " + the message you supply. 12 | namespace frantic { 13 | namespace diagnostics { 14 | namespace detail { 15 | 16 | inline void assert_throw_runtime_error( bool assert_condition, std::string assert_condition_string, 17 | std::string failure_message, std::string file_name, std::string line_number, 18 | std::string function_name ) { 19 | if( !assert_condition ) { 20 | std::string err_message = file_name.substr( file_name.find_last_of( '\\' ) + 1 ) + ":" + line_number + " " + 21 | function_name + "() assert condition " + assert_condition_string + 22 | " failed: " + failure_message; 23 | throw std::runtime_error( err_message ); 24 | } 25 | } 26 | 27 | } // namespace detail 28 | } // namespace diagnostics 29 | } // namespace frantic 30 | 31 | #define FRANTIC_INTERNAL_STRINGIFY( x ) #x 32 | #define FRANTIC_INTERNAL_TOSTRING( x ) FRANTIC_INTERNAL_STRINGIFY( x ) 33 | 34 | #define FRANTIC_ASSERT_THROW( assert_condition, failure_message ) \ 35 | frantic::diagnostics::detail::assert_throw_runtime_error( assert_condition, #assert_condition, failure_message, \ 36 | __FILE__, FRANTIC_INTERNAL_TOSTRING( __LINE__ ), \ 37 | __FUNCTION__ ) 38 | 39 | // a debug version for asserts not wanted in the release version 40 | #ifdef NDEBUG 41 | #define FRANTIC_DEBUG_ASSERT_THROW( assert_condition, failure_message ) 42 | #else 43 | #define FRANTIC_DEBUG_ASSERT_THROW( assert_condition, failure_message ) \ 44 | frantic::diagnostics::detail::assert_throw_runtime_error( assert_condition, #assert_condition, failure_message, \ 45 | __FILE__, FRANTIC_INTERNAL_TOSTRING( __LINE__ ), \ 46 | __FUNCTION__ ) 47 | #endif 48 | -------------------------------------------------------------------------------- /frantic/diagnostics/profiling_manager.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace diagnostics { 9 | 10 | class profiling_manager { 11 | private: 12 | std::vector m_profs; 13 | template 14 | friend std::basic_ostream& operator<<( std::basic_ostream&, const profiling_manager& ); 15 | 16 | public: 17 | profiling_manager() {} 18 | int new_profiling_section( const frantic::tstring& name ) { 19 | int result = (int)m_profs.size(); 20 | m_profs.push_back( profiling_section( name ) ); 21 | return result; 22 | } 23 | 24 | void enter_section( int i ) { m_profs[i].enter(); } 25 | 26 | void exit_section( int i ) { m_profs[i].exit(); } 27 | }; 28 | 29 | template 30 | inline std::basic_ostream& operator<<( std::basic_ostream& o, const profiling_manager& pfm ) { 31 | for( int i = 0; i < (int)pfm.m_profs.size(); ++i ) 32 | o << pfm.m_profs[i] << "\n"; 33 | return o; 34 | } 35 | 36 | } // namespace diagnostics 37 | } // namespace frantic 38 | -------------------------------------------------------------------------------- /frantic/files/file_sequence.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | // TODO: Delete this file, its functionality is taken over by the filename_sequence class. 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace frantic { 14 | namespace files { 15 | 16 | #ifdef _WIN32 17 | // This function will take a filename pattern of prefix + #### + .extension where #### is any length of digits. 18 | // It will scan the directory designated in the pattern for all files matching the pattern and differing in only 19 | // the digits. It returns an interval consisting of the lowest and highest frame found. 20 | // For example: 21 | // If there are files in some directory c:\blah\, like test0004.tif, test0005.tif, test0007.tif 22 | // get_sequence_range( "c:\\blah\\test0000.tif" ) will return the pair (4,7). 23 | inline std::pair get_sequence_range( const frantic::tstring& inFilePattern ) { 24 | frantic::tstring ext; 25 | frantic::tstring prefix; 26 | int numDigits; 27 | int seqNum; 28 | 29 | int lowestFrame = ( std::numeric_limits::max )(); // Arbitrarily high value 30 | int highestFrame = -1; 31 | 32 | HANDLE fsHandle; 33 | WIN32_FIND_DATA fsData; 34 | frantic::tstring searchPattern; 35 | 36 | split_sequence_path( inFilePattern, prefix, numDigits, seqNum, ext ); 37 | 38 | searchPattern = prefix + _T("*") + ext; 39 | 40 | fsHandle = FindFirstFile( searchPattern.c_str(), &fsData ); 41 | if( fsHandle != INVALID_HANDLE_VALUE ) { 42 | do { 43 | try { 44 | seqNum = extract_sequence_number( frantic::tstring( fsData.cFileName ) ); 45 | } catch( const std::exception& ) { 46 | seqNum = lowestFrame; 47 | } 48 | 49 | if( seqNum < lowestFrame ) 50 | lowestFrame = seqNum; 51 | else if( seqNum > highestFrame ) 52 | highestFrame = seqNum; 53 | 54 | } while( FindNextFile( fsHandle, &fsData ) ); 55 | } 56 | 57 | // if(lowestFrame > highestFrame) 58 | // lowestFrame = highestFrame; 59 | 60 | return std::pair( lowestFrame, highestFrame ); 61 | } //~get_sequence_range() 62 | 63 | #else 64 | inline std::pair get_sequence_range( const frantic::tstring& /*inFilePattern*/ ) { 65 | throw std::runtime_error( "get_sequence_range has not been implemented for unix yet." ); 66 | } 67 | #endif 68 | /*framenumbers::frame_set get_frame_set_from_files(const std::string & inFilePattern){ 69 | 70 | }*/ 71 | } // namespace files 72 | } // namespace frantic 73 | -------------------------------------------------------------------------------- /frantic/files/pipelined_ifstream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #ifdef _WIN32 8 | #ifndef WIN32_LEAN_AND_MEAN 9 | #define WIN32_LEAN_AND_MEAN 10 | #endif 11 | #ifndef NOMINMAX 12 | #define NOMINMAX 13 | #endif 14 | #include 15 | #endif 16 | 17 | #include 18 | 19 | namespace frantic { 20 | namespace files { 21 | 22 | class pipelined_ifstream { 23 | private: 24 | FILE* m_fin; 25 | char* m_buffer; 26 | std::size_t m_bufferSize; 27 | 28 | volatile char* m_writeBuffer; 29 | volatile std::size_t m_writeBufferSize; 30 | 31 | #ifdef _WIN32 32 | HANDLE m_threadHandle; 33 | HANDLE m_threadCloseEvent; 34 | HANDLE m_bufferAvailableEvent; 35 | HANDLE m_outputAvailableEvent; 36 | 37 | static unsigned long __stdcall thread_proc( void* pData ); 38 | #endif 39 | 40 | public: 41 | pipelined_ifstream(); 42 | pipelined_ifstream( FILE* f, std::size_t bufferSize ); 43 | ~pipelined_ifstream(); 44 | 45 | void open( FILE* f, std::size_t bufferSize ); 46 | void close(); 47 | 48 | std::pair read(); 49 | }; 50 | 51 | } // namespace files 52 | } // namespace frantic 53 | -------------------------------------------------------------------------------- /frantic/files/pipelined_ofstream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #ifdef _WIN32 8 | #ifndef WIN32_LEAN_AND_MEAN 9 | #define WIN32_LEAN_AND_MEAN 10 | #endif 11 | #ifndef NOMINMAX 12 | #define NOMINMAX 13 | #endif 14 | #include 15 | #endif 16 | 17 | #include 18 | 19 | namespace frantic { 20 | namespace files { 21 | 22 | class pipelined_ofstream { 23 | private: 24 | FILE* m_fout; 25 | char* m_buffer; 26 | std::size_t m_bufferSize; 27 | 28 | volatile char* m_writeBuffer; 29 | volatile std::size_t m_writeBufferSize; 30 | 31 | volatile int m_ioError; 32 | volatile int m_ioSysError; 33 | 34 | #ifdef _WIN32 35 | HANDLE m_threadHandle; 36 | HANDLE m_threadCloseEvent; 37 | HANDLE m_outputAvailableEvent; // Indicates that the output buffer has been filled 38 | HANDLE m_bufferAvailableEvent; // Indicates that the output has completed 39 | 40 | static unsigned long __stdcall thread_proc( void* pData ); 41 | #endif 42 | 43 | public: 44 | pipelined_ofstream(); 45 | pipelined_ofstream( FILE* f, std::size_t bufferSize ); 46 | ~pipelined_ofstream(); 47 | 48 | void open( FILE* f, std::size_t bufferSize ); 49 | void close(); 50 | 51 | // Writes the user buffer (ie. the one returned by get_write_buffer) to file 52 | void write( std::size_t numBytes ); 53 | 54 | // Returns the current buffer that is available to the user. 55 | char* get_write_buffer(); 56 | 57 | // Returns the size of the buffer available to the user. 58 | std::size_t get_write_buffer_size() const { return m_bufferSize; } 59 | }; 60 | 61 | } // namespace files 62 | } // namespace frantic 63 | -------------------------------------------------------------------------------- /frantic/files/scoped_file_cleanup.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace frantic { 13 | namespace files { 14 | 15 | /** 16 | * A simple RAII class to ensure temporary files are deleted when a function goes 17 | * out of scope. A replacemen 18 | * 19 | * To consider: 20 | * - make this movable-but-non-copyable 21 | * - make this mergable (allow a number of tasks to create temp files, and then delete them all when the operation is 22 | * complete) 23 | */ 24 | class scoped_file_cleanup { 25 | private: 26 | // for now at least, non-copyable 27 | scoped_file_cleanup( const scoped_file_cleanup& ); 28 | scoped_file_cleanup operator=( const scoped_file_cleanup& ); 29 | 30 | public: 31 | scoped_file_cleanup(); 32 | ~scoped_file_cleanup(); 33 | 34 | void reset(); 35 | 36 | void add( const frantic::tstring& filePath ); 37 | void add( const boost::filesystem::path& filePath ); 38 | 39 | void cleanup_files(); 40 | 41 | private: 42 | std::vector m_deletionPaths; 43 | }; 44 | 45 | } // namespace files 46 | } // namespace frantic 47 | -------------------------------------------------------------------------------- /frantic/geometry/connected_components.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace frantic { 12 | namespace geometry { 13 | 14 | /** 15 | * Assocates to each face a positive integer, such that faces in the same connected component will share the same value 16 | * 17 | * @param mesh The mesh to run the search on 18 | * @param outFaceLabels output array containing the component id of each face 19 | */ 20 | void get_face_connected_components( const frantic::geometry::mesh_interface* mesh, std::vector& outFaceLabels ); 21 | void get_face_connected_components( const frantic::geometry::mesh_interface_ptr mesh, 22 | std::vector& outFaceLabels ); 23 | 24 | /** 25 | * Given a set of face component labels (as computed by 'get_face_connected_components'), gather all connected 26 | *components' faces 27 | * together into a set of lists. 28 | * 29 | * @param faceLabels the list of connected component labels, one per face 30 | * @param outFaceLists storage for the list of component faces 31 | * @param outListOffsets contains the offsets for each component's set of faces, such that 32 | * outFaceLists[outListOffsets[c]..outListOffsets[c+1]] will contain the faces for component 'c' 33 | * @remark the length of outListOffsets will be 1 plus the number of connected components 34 | */ 35 | void group_face_components( const std::vector& faceLabels, std::vector& outFaceLists, 36 | std::vector& outListOffsets ); 37 | 38 | /** 39 | * Modify a set of face labels such that all subsets are entirely face-connected 40 | * 41 | * @param edgeStructure a DCEL representing the desired topology 42 | * @param faceLabels array to be modified containing the segment id of each face 43 | */ 44 | void separate_segmentation_components( const dcel& edgeStructure, std::vector& faceLabels ); 45 | 46 | /** 47 | * Modify a face segmentation such that all subsets are entirely face-connected 48 | * 49 | * @param edgeStructure a DCEL representing the desired topology 50 | * @param initialSegmentation input face segmentation 51 | * @param outSegmentation output face segmentation 52 | */ 53 | void separate_segmentation_components( const mesh_interface* mesh, const range_segmentation& initialSegmentation, 54 | range_segmentation& outSegmentation ); 55 | void separate_segmentation_components( const mesh_interface* mesh, range_segmentation& inoutSegmentation ); 56 | 57 | } // namespace geometry 58 | } // namespace frantic 59 | -------------------------------------------------------------------------------- /frantic/geometry/dcel_construction.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace frantic { 15 | namespace geometry { 16 | 17 | void trimesh3_to_dcel( const trimesh3& mesh, dcel& out ); 18 | 19 | void dcel_to_trimesh3( const dcel& input, const std::vector& vertices, trimesh3& outMesh ); 20 | 21 | void polymesh3_to_dcel( const_polymesh3_ptr polymesh, dcel& out ); 22 | 23 | void mesh_interface_to_dcel( const mesh_interface_ptr meshInterface, dcel& out ); 24 | 25 | void mesh_interface_to_dcel( const mesh_interface* meshInterface, dcel& out ); 26 | 27 | void mesh_channel_to_dcel( const mesh_channel* meshChannel, dcel& out ); 28 | 29 | void parameterization_chart_to_dcel( const parameterization::parameterization_chart& chart, dcel& out ); 30 | 31 | } // namespace geometry 32 | } // namespace frantic 33 | -------------------------------------------------------------------------------- /frantic/geometry/dcel_surface_iterators.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include 4 | 5 | #include 6 | 7 | // These methods are a little more complex, this involve finding (if present) a surface (non-boundary) range around a 8 | // vertex Note that the assumption is that there is at most one boundary range at each vertex (the alternative is not 9 | // disallowed, but is really wonky and shouldn't happen in general) 10 | 11 | namespace frantic { 12 | namespace geometry { 13 | 14 | /** 15 | * Returns the next boundary edge after the current vertex reference halfedge 16 | * 17 | * @param vertexRef a halfedge handle pointing to the current vertex 18 | * @return a halfedge handle to the first boundary handle pointing to the current vertex, or an invalid halfedge if 19 | * there is no boundary on the current vertex 20 | */ 21 | template 22 | Halfedge_t next_boundary_edge( const Halfedge_t& vertexRef ) { 23 | BOOST_FOREACH( dcel::halfedge_handle he, dcel_vertex_cycle_range( vertexRef ) ) { 24 | if( he.is_boundary_face() ) { 25 | return he; 26 | } 27 | } 28 | return dcel::INVALID_HALFEDGE_HANDLE; 29 | } 30 | 31 | /** 32 | * Return the start of a range around the vertex which iterates through a contiguous set of surface faces 33 | */ 34 | template 35 | inline typename halfedge_iterator_traits::vertex_iterator_t 36 | dcel_vertex_surface_begin( const Halfedge_t& vertexRef ) { 37 | BOOST_FOREACH( dcel::halfedge_handle he, dcel_vertex_cycle_range( vertexRef ) ) { 38 | if( he.twin().is_boundary_face() ) { 39 | return dcel_vertex_begin( he ); 40 | } 41 | } 42 | 43 | return dcel_vertex_begin( vertexRef ); 44 | } 45 | 46 | template 47 | inline typename halfedge_iterator_traits::vertex_iterator_t 48 | dcel_vertex_surface_end( const Halfedge_t& vertexRef ) { 49 | Halfedge_t nextBoundary = next_boundary_edge( vertexRef ); 50 | 51 | if( nextBoundary != dcel::INVALID_HALFEDGE_HANDLE ) { 52 | return dcel_vertex_end( nextBoundary ); 53 | } else { 54 | return dcel_vertex_cycle_end( vertexRef ); 55 | } 56 | } 57 | 58 | template 59 | inline typename halfedge_iterator_traits::vertex_range_t 60 | dcel_vertex_surface_range( const Halfedge_t& vertexRef ) { 61 | Halfedge_t nextBoundary = next_boundary_edge( vertexRef ); 62 | 63 | if( nextBoundary != dcel::INVALID_HALFEDGE_HANDLE ) { 64 | return boost::make_iterator_range( dcel_vertex_begin( nextBoundary.vertex_next() ), 65 | dcel_vertex_end( nextBoundary ) ); 66 | } else { 67 | return dcel_vertex_cycle_range( vertexRef ); 68 | } 69 | } 70 | 71 | } // namespace geometry 72 | } // namespace frantic 73 | -------------------------------------------------------------------------------- /frantic/geometry/matte_geometry_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace frantic { 11 | namespace geometry { 12 | 13 | class matte_geometry_interface { 14 | public: 15 | virtual void rebuild( float motionSegmentTime ) = 0; 16 | virtual bool is_visible( const frantic::graphics::ray3f& ray, double tMin, double tMax ) const = 0; 17 | virtual bool is_visible( const frantic::graphics::ray3f& ray, double tMin, double tMax, int& outLayer ) const = 0; 18 | virtual void generate_depth_map( const frantic::graphics::camera& cam, float motionSegmentTime, 19 | frantic::graphics2d::framebuffer& outBuffer, int numThreads = 0, 20 | bool forLight = false ) const = 0; 21 | virtual void generate_depth_map( const frantic::graphics::transform4f& camTM, float motionSegmentTime, 22 | frantic::rendering::framebuffer_cubeface& outBuffer, int numThreads = 0, 23 | bool forLight = true ) const = 0; 24 | }; 25 | 26 | } // namespace geometry 27 | } // namespace frantic 28 | -------------------------------------------------------------------------------- /frantic/geometry/mesh_conversion.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace frantic { 10 | namespace geometry { 11 | 12 | /** 13 | * Builds a polymesh3 from a trimesh. 14 | * 15 | * @param inMesh a trimesh to use as the template 16 | * @return a newly constructed polymesh3 17 | */ 18 | polymesh3_ptr trimesh3_to_polymesh3( const trimesh3& inMesh ); 19 | 20 | } // namespace geometry 21 | } // namespace frantic 22 | -------------------------------------------------------------------------------- /frantic/geometry/ply_reader.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace geometry { 9 | 10 | // forward declaration 11 | class ply_reader_header; 12 | 13 | class ply_reader : boost::noncopyable { 14 | public: 15 | typedef std::pair channel_type_t; 16 | 17 | ply_reader( const frantic::tstring& filename ); 18 | 19 | const frantic::tstring& get_filename() const; 20 | 21 | std::size_t get_vertex_count() const; 22 | std::size_t get_face_count() const; 23 | 24 | void get_vertex_channel_names( std::vector& outNames ) const; 25 | 26 | channel_type_t get_vertex_channel_type( const frantic::tstring& name ) const; 27 | 28 | frantic::geometry::polymesh3_ptr read_polymesh3() const; 29 | 30 | private: 31 | ply_reader_header& get_header() const; 32 | 33 | frantic::tstring m_filename; 34 | 35 | boost::shared_ptr m_header; 36 | }; 37 | 38 | } // namespace geometry 39 | } // namespace frantic 40 | -------------------------------------------------------------------------------- /frantic/geometry/polymesh3_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace frantic { 9 | namespace geometry { 10 | 11 | class polymesh3_interface : public mesh_interface { 12 | public: 13 | // TODO: take ownership of the mesh? 14 | static std::unique_ptr create_instance( frantic::geometry::polymesh3_ptr mesh ); 15 | 16 | /** 17 | * @param mesh the mesh to create a read-only interface for. 18 | * @return a read-only interface for the mesh. 19 | */ 20 | static std::unique_ptr create_const_instance( frantic::geometry::const_polymesh3_ptr mesh ); 21 | 22 | virtual ~polymesh3_interface() {} 23 | }; 24 | 25 | } // namespace geometry 26 | } // namespace frantic 27 | -------------------------------------------------------------------------------- /frantic/geometry/transformed_mesh_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace geometry { 9 | 10 | /* 11 | * Transforms a mesh with a given transform4f 12 | * create_instance will return a transformed_mesh_interface of a mesh to access the transformed data 13 | * The returned mesh is read only 14 | * Warning: changing the base mesh may cause undefined behaviour in the translated mesh as 15 | * it does not make a deep copy of the base mesh 16 | */ 17 | class transformed_mesh_interface : public mesh_interface { 18 | public: 19 | static std::unique_ptr create_instance( frantic::geometry::mesh_interface_ptr mesh, 20 | const frantic::graphics::transform4f& xform ); 21 | 22 | virtual ~transformed_mesh_interface() {} 23 | }; 24 | } // namespace geometry 25 | } // namespace frantic 26 | -------------------------------------------------------------------------------- /frantic/geometry/trimesh3_file_io.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace frantic { 9 | namespace geometry { 10 | 11 | // This loads an .obj file into a trimesh3 12 | void load_obj_mesh_file( const frantic::tstring& objFile, trimesh3& mesh ); 13 | void write_obj_mesh_file( const frantic::tstring& destFile, const trimesh3& mesh ); 14 | 15 | // Detect extension/format 16 | void load_mesh_file( const frantic::tstring& srcFile, trimesh3& mesh ); 17 | void write_mesh_file( const frantic::tstring& destFile, const trimesh3& mesh ); 18 | 19 | /** 20 | * Attempt to load an approximate bounding box from the specified mesh file. 21 | * This will succeed only with .xmesh files which have a \ element. 22 | * Such bounding boxes are intended for use as a proxy to avoid loading the 23 | * entire mesh or its vertices. 24 | * 25 | * @param srcFile name of the file from which to attempt to load an approximate 26 | * bounding box. 27 | * @param[out] outBoundBox if the function returns true, then this is the 28 | * bounding box which was loaded from the specified filename. 29 | * @param showWarnings if true and the boundbox data could not be interpreted 30 | * correctly, then a warning will be sent to FF_LOG(warning). 31 | * @return true if a bounding box metadata could be read from the file, 32 | * otherwise false. 33 | */ 34 | bool try_load_boundbox_metadata( const frantic::tstring& srcFile, boundbox3f& outBoundBox, 35 | const bool showWarnings = false ); 36 | 37 | } // namespace geometry 38 | } // namespace frantic 39 | -------------------------------------------------------------------------------- /frantic/geometry/trimesh3_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace frantic { 11 | namespace geometry { 12 | 13 | class trimesh3_interface : public mesh_interface { 14 | public: 15 | static std::unique_ptr create_instance( const trimesh3* mesh ); 16 | static std::unique_ptr create_instance( BOOST_RV_REF( trimesh3 ) mesh ); 17 | 18 | virtual ~trimesh3_interface() {} 19 | 20 | virtual const trimesh3& get_trimesh() const = 0; 21 | }; 22 | 23 | } // namespace geometry 24 | } // namespace frantic 25 | -------------------------------------------------------------------------------- /frantic/geometry/trimesh3_scan_conversion.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace frantic { 9 | namespace geometry { 10 | 11 | class trimesh3; // forward declaration 12 | 13 | /** 14 | * This class holds the data for one intersection 15 | * 16 | */ 17 | struct scan_conversion_intersection { 18 | // The z coordinate of this intersection 19 | float z; 20 | // The face index and barycentric coordinates of this intersection 21 | int faceIndex; 22 | graphics::vector3f barycentricCoord; 23 | // Whether the normal of this face is pointing towards positive Z 24 | bool normalFacingZPositive; 25 | 26 | /** 27 | * First sort by ascending Z, and if the Z values are equal, consider 28 | * the ones with normal facing towards negative Z as smaller than the ones with normal 29 | * facing towards positive Z. 30 | * 31 | */ 32 | bool operator<( const scan_conversion_intersection& rhs ) const { 33 | if( z == rhs.z ) 34 | return !normalFacingZPositive && ( normalFacingZPositive != rhs.normalFacingZPositive ); 35 | else 36 | return z < rhs.z; 37 | } 38 | }; 39 | 40 | /** 41 | * Scan converts an input triangle mesh into a series of surface depths. All the triangles are converted into samples 42 | * on the grid defined by the input parameters, and added to the appropriate elements of the outIntersectionDepths 43 | * array.

Once the scan conversion is complete, each subarray is sorted in the ascending Z direction. 44 | * 45 | * @param xform The transform matrix which should place the input mesh in the correct position for scan 46 | * conversion. 47 | * @param mesh The input mesh to be scan converted. 48 | * @param dimensions The XY dimensions of the output intersection depths. The scan conversion operates in the space 49 | * from [0,0,-infinity] to [dimensions.xsize,dimensions.ysize,+infinity]. The actual coordinates 50 | * sampled are at the middle of the squares, so for instance index 0 in the output array refers to the line 51 | * [0.5,0.5,-infinity] to [0,5,0,5,+infinity]. 52 | * @param outIntersectionDepths This output parameter is where all the scan converted samples are placed. When the 53 | * function is called, it should already be initialized to the right size. Each element of this array consists of the 54 | * Z coordinate of the surface, as well as true if the normal of the surface is pointing 55 | * upwards. 56 | */ 57 | void trimesh3_scan_convert( const graphics::transform4f& xform, const trimesh3& mesh, graphics2d::size2 dimensions, 58 | std::vector>& outIntersectionDepths ); 59 | 60 | } // namespace geometry 61 | } // namespace frantic 62 | -------------------------------------------------------------------------------- /frantic/geometry/trimesh3_utils.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace geometry { 9 | float get_mesh_max_velocity_magnitude( const trimesh3& mesh ) { 10 | 11 | if( !mesh.has_vertex_channel( _T("Velocity") ) ) 12 | return 0.f; 13 | 14 | float maxMagnitudeSquared = 0, tempMagnitudeSquared = 0; 15 | 16 | const_trimesh3_vertex_channel_accessor velAcc = 17 | mesh.get_vertex_channel_accessor( _T("Velocity") ); 18 | 19 | for( unsigned int vertexCount = 0; vertexCount < mesh.vertex_count(); vertexCount++ ) { 20 | tempMagnitudeSquared = velAcc[vertexCount].get_magnitude_squared(); 21 | if( tempMagnitudeSquared > maxMagnitudeSquared ) 22 | maxMagnitudeSquared = tempMagnitudeSquared; 23 | } 24 | 25 | return sqrt( maxMagnitudeSquared ); 26 | } 27 | } // namespace geometry 28 | } // namespace frantic 29 | -------------------------------------------------------------------------------- /frantic/geometry/xmesh_standard_mesh_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace geometry { 9 | 10 | /** 11 | * Create a read-only mesh_interface that contains only standard XMesh 12 | * channels. 13 | * 14 | * To handle non-standard mesh channels: 15 | * 16 | * - Channels with a non-standard data type will be converted to a 17 | * standard data type (if such type conversion is not possible, an 18 | * exception will be thrown; TODO: something else?). 19 | * - Channels with a non-standard arity will have their values 20 | * zero-padded or truncated to the standard arity. 21 | * - Channels with unknown names will be removed. 22 | * 23 | */ 24 | std::unique_ptr create_xmesh_standard_mesh_interface( const mesh_interface* meshInterface ); 25 | 26 | } // namespace geometry 27 | } // namespace frantic 28 | -------------------------------------------------------------------------------- /frantic/graphics/alpha1f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace frantic { 10 | namespace graphics { 11 | 12 | // This represents and rgb opacity. Adding alpha1f's together is the same as occluding the alpha 13 | // values in front of each other. Multiplying alpha1f's by floating point values scales the transparency 14 | class alpha1f { 15 | public: 16 | float a; 17 | 18 | enum { Channels = 1 }; 19 | 20 | ////////////// 21 | // Constructors 22 | ////////////// 23 | 24 | alpha1f( float alpha ) { a = alpha; } 25 | 26 | explicit alpha1f( int I ) { a = (float)I; } 27 | 28 | alpha1f() { a = 0; } 29 | 30 | ////////////// 31 | // Queries 32 | ////////////// 33 | 34 | float component_sum() const { return a; } 35 | 36 | static alpha1f abs( const alpha1f& c ) { return alpha1f( fabsf( c.to_float() ) ); } 37 | 38 | ////////////// 39 | // Operators 40 | ////////////// 41 | 42 | float to_float() const { return a; } 43 | 44 | color3f occlude( const color3f& c ) const { return color3f( ( 1 - a ) * c.r, ( 1 - a ) * c.g, ( 1 - a ) * c.b ); } 45 | 46 | color3f premultiply( const color3f& c ) const { return color3f( a * c.r, a * c.g, a * c.b ); } 47 | 48 | void blend_over( const alpha1f& alpha ) { a = 1 - ( 1 - a ) * ( 1 - alpha.a ); } 49 | 50 | void blend_under( const alpha1f& alpha ) { a = 1 - ( 1 - a ) * ( 1 - alpha.a ); } 51 | 52 | alpha1f& operator+=( const alpha1f& alpha ) { 53 | a += alpha.a; 54 | return *this; 55 | } 56 | 57 | alpha1f& operator*=( float x ) { 58 | a *= x; 59 | return *this; 60 | } 61 | 62 | alpha1f& operator/=( float x ) { 63 | a /= x; 64 | return *this; 65 | } 66 | 67 | bool operator!=( const alpha1f& other ) { return a != other.a; } 68 | 69 | bool operator==( const alpha1f& other ) { return a == other.a; } 70 | }; 71 | 72 | inline alpha1f operator+( const alpha1f& alpha, const alpha1f& beta ) { return alpha1f( alpha.a + beta.a ); } 73 | 74 | inline alpha1f operator*( const alpha1f& alpha, float k ) { return alpha1f( alpha.a * k ); } 75 | 76 | inline alpha1f operator*( float k, const alpha1f& alpha ) { return alpha1f( k * alpha.a ); } 77 | 78 | inline alpha1f operator/( const alpha1f& alpha, float k ) { return alpha1f( alpha.a / k ); } 79 | 80 | inline std::ostream& operator<<( std::ostream& out, const alpha1f& alpha ) { 81 | out << "(alpha " << alpha.a << " )"; 82 | return out; 83 | } 84 | 85 | } // namespace graphics 86 | } // namespace frantic 87 | -------------------------------------------------------------------------------- /frantic/graphics/color_converter.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include "frantic/channels/named_channel_data.hpp" 6 | 7 | namespace frantic { 8 | namespace graphics { 9 | 10 | using frantic::channels::data_type_t; 11 | /** 12 | * This class handles the conversion from one pixel type to another, and is primarily used 13 | * by frantic::channels::generic_channel_buffer_iterator. There are some caveats to using the 14 | * generic interface for pixel data that you must be aware of. 15 | * 16 | * frantic::graphics::color_rgb_f do not alter the alpha if the destination has an alpha channel. 17 | * Instead, the existing alpha value is premultiplied into the rgb values, and the resulting value 18 | * is stored. The opposite applies an alpha division, and retains the existing alpha channel. 19 | * 20 | */ 21 | class color_converter { 22 | public: 23 | static void ( *get_conversion_function( const frantic::tstring& s, data_type_t sType, const frantic::tstring& d, 24 | data_type_t dType ) )( void*, void* ); 25 | }; 26 | 27 | } // namespace graphics 28 | } // namespace frantic 29 | -------------------------------------------------------------------------------- /frantic/graphics/color_rgb3a_f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include "frantic/channels/channel_map.hpp" 6 | #include "frantic/channels/named_channel_data.hpp" 7 | #include "frantic/graphics/color_base.hpp" 8 | 9 | namespace frantic { 10 | namespace graphics { 11 | 12 | // using frantic::channels::channel_map; 13 | using frantic::channels::data_type_t; 14 | 15 | /** 16 | * A pixel with a Red, Green, Blue, and an Alpha channel for each colour 17 | * 18 | * @author Brian McKinnon 19 | * @since Apr 25, 2007 20 | */ 21 | class color_rgb3a_f : public color_base { 22 | public: 23 | color_rgb3a_f( float c = 0.0f, float a = 1.0f ) { 24 | set_r( c ); 25 | set_g( c ); 26 | set_b( c ); 27 | set_ar( a ); 28 | set_ag( a ); 29 | set_ab( a ); 30 | } 31 | color_rgb3a_f( float r, float g, float b, float ar = 1.0f, float ag = 1.0f, float ab = 1.0f ) { 32 | set_r( r ); 33 | set_g( g ); 34 | set_b( b ); 35 | set_ar( ar ); 36 | set_ag( ag ); 37 | set_ab( ab ); 38 | } 39 | 40 | float get_r() const { return this->get_color().get_data( 0 ); } 41 | float get_g() const { return this->get_color().get_data( 1 ); } 42 | float get_b() const { return this->get_color().get_data( 2 ); } 43 | float get_ar() const { return this->get_alpha().get_data( 0 ); } 44 | float get_ag() const { return this->get_alpha().get_data( 1 ); } 45 | float get_ab() const { return this->get_alpha().get_data( 2 ); } 46 | 47 | void set_r( float r ) { this->get_color().set_data( 0, r ); } 48 | void set_g( float g ) { this->get_color().set_data( 1, g ); } 49 | void set_b( float b ) { this->get_color().set_data( 2, b ); } 50 | void set_ar( float ar ) { this->get_alpha().set_data( 0, ar ); } 51 | void set_ag( float ag ) { this->get_alpha().set_data( 1, ag ); } 52 | void set_ab( float ab ) { this->get_alpha().set_data( 2, ab ); } 53 | 54 | static channel_map get_channel_map(); 55 | static void add_to_channel_map( channel_map* channelMap ); 56 | static data_type_t get_data_type() { return frantic::channels::data_type_float32; } 57 | static frantic::tstring get_name() { return _T("R_G_B_AR_AG_AB"); } 58 | }; 59 | 60 | inline std::ostream& operator<<( std::ostream& out, const color_rgb3a_f& p ) { 61 | out << "color_rgb3a_f( " << p.get_r() << ", " << p.get_g() << ", " << p.get_b() << ", " << p.get_ar() << ", " 62 | << p.get_ag() << ", " << p.get_ab() << " )"; 63 | return out; 64 | } 65 | 66 | } // namespace graphics 67 | } // namespace frantic 68 | -------------------------------------------------------------------------------- /frantic/graphics/color_rgb_f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include "frantic/channels/channel_map.hpp" 6 | #include "frantic/channels/named_channel_data.hpp" 7 | #include "frantic/graphics/color_base.hpp" 8 | 9 | namespace frantic { 10 | namespace graphics { 11 | 12 | /** 13 | * A pixel with a Red, Green, Blue channel 14 | * 15 | * @author Brian McKinnon 16 | * @since Apr 25, 2007 17 | */ 18 | class color_rgb_f : public color_base { 19 | public: 20 | color_rgb_f( float c = 0.0f ) { 21 | set_r( c ); 22 | set_g( c ); 23 | set_b( c ); 24 | } 25 | color_rgb_f( float r, float g, float b ) { 26 | set_r( r ); 27 | set_g( g ); 28 | set_b( b ); 29 | } 30 | 31 | float get_r() const { return this->get_color().get_data( 0 ); } 32 | float get_g() const { return this->get_color().get_data( 1 ); } 33 | float get_b() const { return this->get_color().get_data( 2 ); } 34 | 35 | void set_r( float r ) { this->get_color().set_data( 0, r ); } 36 | void set_g( float g ) { this->get_color().set_data( 1, g ); } 37 | void set_b( float b ) { this->get_color().set_data( 2, b ); } 38 | 39 | static frantic::channels::channel_map get_channel_map(); 40 | static void add_to_channel_map( frantic::channels::channel_map* channelMap ); 41 | static frantic::channels::data_type_t get_data_type() { return frantic::channels::data_type_float32; } 42 | static frantic::tstring get_name() { return _T("R_G_B"); } 43 | }; 44 | 45 | inline std::ostream& operator<<( std::ostream& out, const color_rgb_f& p ) { 46 | out << "color_rgb_f( " << p.get_r() << ", " << p.get_g() << ", " << p.get_b() << " )"; 47 | return out; 48 | } 49 | 50 | inline color_rgb_f operator*( float s, const color_rgb_f& c ) { 51 | return color_rgb_f( s * c.get_r(), s * c.get_g(), s * c.get_b() ); 52 | } 53 | 54 | inline color_rgb_f operator*( const color_rgb_f& c, float s ) { 55 | return color_rgb_f( s * c.get_r(), s * c.get_g(), s * c.get_b() ); 56 | } 57 | 58 | } // namespace graphics 59 | } // namespace frantic 60 | 61 | namespace frantic { 62 | namespace channels { 63 | 64 | template <> 65 | struct channel_data_type_traits { 66 | typedef frantic::graphics::color_rgb_f value_type; 67 | inline static size_t arity() { return 3; } 68 | inline static data_type_t data_type() { return data_type_float32; } 69 | inline static frantic::tstring type_str() { return channel_data_type_str( arity(), data_type() ); } 70 | inline static value_type barycentric_combine( const frantic::graphics::vector3f& barycentricCoords, value_type a, 71 | value_type b, value_type c ) { 72 | return barycentricCoords.x * a + barycentricCoords.y * b + barycentricCoords.z * c; 73 | } 74 | }; 75 | 76 | } // namespace channels 77 | } // namespace frantic 78 | -------------------------------------------------------------------------------- /frantic/graphics/color_rgba_h.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include "frantic/channels/channel_map.hpp" 6 | #include "frantic/channels/named_channel_data.hpp" 7 | #include "frantic/graphics/color_base.hpp" 8 | #include 9 | 10 | namespace frantic { 11 | namespace graphics { 12 | 13 | // using frantic::channels::channel_map; 14 | using frantic::channels::data_type_t; 15 | 16 | /** 17 | * A pixel with a Red, Green, Blue, and Alpha channel store in an Imf half 18 | * 19 | * @author Brian McKinnon 20 | * @since May 2, 2007 21 | */ 22 | class color_rgba_h : public color_base { 23 | public: 24 | color_rgba_h( half c = 0.0f, half a = 0.0f ) { 25 | set_r( c ); 26 | set_g( c ); 27 | set_b( c ); 28 | set_a( a ); 29 | } 30 | color_rgba_h( half r, half g, half b, half a = 0.0f ) { 31 | set_r( r ); 32 | set_g( g ); 33 | set_b( b ); 34 | set_a( a ); 35 | } 36 | 37 | half get_r() const { return this->get_color().get_data( 0 ); } 38 | half get_g() const { return this->get_color().get_data( 1 ); } 39 | half get_b() const { return this->get_color().get_data( 2 ); } 40 | half get_a() const { return this->get_alpha().get_data( 0 ); } 41 | 42 | void set_r( half r ) { this->get_color().set_data( 0, r ); } 43 | void set_g( half g ) { this->get_color().set_data( 1, g ); } 44 | void set_b( half b ) { this->get_color().set_data( 2, b ); } 45 | void set_a( half a ) { this->get_alpha().set_data( 0, a ); } 46 | 47 | static channel_map get_channel_map(); 48 | static void add_to_channel_map( channel_map* channelMap ); 49 | static data_type_t get_data_type() { return frantic::channels::data_type_float16; } 50 | static frantic::tstring get_name() { return _T("R_G_B_A"); } 51 | }; 52 | 53 | inline std::ostream& operator<<( std::ostream& out, const color_rgba_h& p ) { 54 | out << "color_rgba_h( " << p.get_r() << ", " << p.get_g() << ", " << p.get_b() << ", " << p.get_a() << " )"; 55 | return out; 56 | } 57 | 58 | } // namespace graphics 59 | } // namespace frantic 60 | -------------------------------------------------------------------------------- /frantic/graphics2d/boundrect2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace frantic { 11 | namespace graphics2d { 12 | 13 | class boundrect2 : public boundrect2t { 14 | public: 15 | ////////////////// 16 | // Constructors // 17 | ////////////////// 18 | 19 | boundrect2() 20 | : boundrect2t( vector2( 1, 1 ), vector2( 0, 0 ) ) {} 21 | explicit boundrect2( const vector2& position ) 22 | : boundrect2t( position ) {} 23 | boundrect2( int xmin, int xmax, int ymin, int ymax ) 24 | : boundrect2t( xmin, xmax, ymin, ymax ) {} 25 | boundrect2( const vector2& min, const vector2& max ) 26 | : boundrect2t( min, max ) {} 27 | boundrect2( const vector2& min, const size2& size ) 28 | : boundrect2t( 29 | min, vector2( min.get_x() + size.get_xsize() - 1, min.get_y() + size.get_ysize() - 1 ) ) {} 30 | 31 | value_type xsize() const { return m_maximum.x - m_minimum.x + 1; } 32 | value_type ysize() const { return m_maximum.y - m_minimum.y + 1; } 33 | 34 | void set_to_point( const vector2& position ) { 35 | m_minimum = position; 36 | m_maximum = position; 37 | } 38 | void set_empty() { 39 | m_minimum = vector2( 1, 1 ); 40 | m_maximum = vector2( 0, 0 ); 41 | } 42 | 43 | bool is_square() const { return xsize() == ysize(); } 44 | }; 45 | 46 | } // namespace graphics2d 47 | } // namespace frantic 48 | -------------------------------------------------------------------------------- /frantic/graphics2d/framebufferiterator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // This class provides a 2D iterator for an image. 5 | 6 | #pragma once 7 | 8 | #include "frantic/graphics2d/strideiterator.hpp" 9 | #include 10 | 11 | namespace frantic { 12 | namespace graphics2d { 13 | 14 | template 15 | class framebuffer; 16 | 17 | template 18 | class framebufferiterator : public strideiterator { 19 | public: 20 | framebufferiterator( framebuffer* img, int borderWidth = 0, int borderHeight = 0 ); 21 | 22 | void print( std::string header = "framebufferiterator info" ) const; 23 | 24 | private: 25 | framebuffer* _img; 26 | }; 27 | 28 | } // namespace graphics2d 29 | } // namespace frantic 30 | 31 | #include "frantic/graphics2d/framebuffer.hpp" 32 | 33 | namespace frantic { 34 | namespace graphics2d { 35 | 36 | template 37 | framebufferiterator::framebufferiterator( framebuffer* img, int borderWidth, int borderHeight ) 38 | : strideiterator( &( img->data() ), img->xsize(), img->ysize(), borderWidth, borderHeight ) { 39 | assert( img != NULL ); 40 | _img = img; 41 | } 42 | 43 | template 44 | void framebufferiterator::print( std::string header ) const { 45 | std::cout << header << ":" << std::endl; 46 | std::cout << "\tframebuffer addr: " << std::hex << _img << std::dec << std::endl; 47 | std::cout << "\t\tDimensions: ( " << _img->width() << ", " << _img->height() << " )" << std::endl; 48 | strideiterator::print(); 49 | } 50 | 51 | } // namespace graphics2d 52 | } // namespace frantic 53 | -------------------------------------------------------------------------------- /frantic/graphics2d/image_channel_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | namespace frantic { 7 | namespace graphics2d { 8 | // This should never be done, importing a namespace into another is a bad idea. 9 | // using namespace std; 10 | 11 | class image_channel_base { 12 | 13 | protected: 14 | image_channel_base* m_parent; 15 | size2 m_size; 16 | std::string m_name; 17 | 18 | image_channel_base( image_channel_base* parent, const std::string& name = "UNNAMED" ) 19 | : m_parent( parent ) 20 | , m_size() 21 | , m_name( name ) { 22 | if( !m_parent ) 23 | throw std::runtime_error( "frantic::graphics2d::image_channel_base() : invalid parent" ); 24 | } 25 | 26 | //--------------------------------------------------------------------------------------------------------- 27 | //--------------------------------------------------------------------------------------------------------- 28 | public: 29 | image_channel_base( const std::string& name = "UNNAMED" ) 30 | : m_parent( 0 ) 31 | , m_size( 0, 0 ) 32 | , m_name( name ) {} 33 | image_channel_base( size2 size ) 34 | : m_parent( 0 ) 35 | , m_size( size ) 36 | , m_name( "UNNAMED" ) {} 37 | image_channel_base( const std::string& name, size2 size ) 38 | : m_parent( 0 ) 39 | , m_size( size ) 40 | , m_name( name ) {} 41 | 42 | virtual ~image_channel_base() {} 43 | 44 | const size2& size() const { return m_size; } 45 | 46 | frantic::graphics2d::size2f size2f() const { return frantic::graphics2d::size2f( m_size ); } 47 | 48 | int xsize() const { return m_size.xsize; } 49 | 50 | int ysize() const { return m_size.ysize; } 51 | 52 | const std::string& name() const { return m_name; } 53 | }; 54 | } // namespace graphics2d 55 | } // namespace frantic 56 | -------------------------------------------------------------------------------- /frantic/graphics2d/size2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace frantic { 10 | namespace graphics2d { 11 | 12 | class size2 : public size2t { 13 | public: 14 | size2() 15 | : size2t( 0, 0 ) {} 16 | explicit size2( int w ) 17 | : size2t( w, w ) {} 18 | size2( int w, int h ) 19 | : size2t( w, h ) {} 20 | template 21 | explicit size2( const size2t& s ) 22 | : size2t( (T)s.xsize, (T)s.ysize ) {} 23 | 24 | typedef vector2 vector_type; 25 | 26 | bool contains( const vector_type& coord ) const { 27 | // Do all 4 comparisons in 2 by using unsigned numbers. If coord.x < 0, then its unsigned representation will 28 | // be bigger than xsize. Note that this only works for integers. 29 | return (unsigned)coord.x < (unsigned)xsize && (unsigned)coord.y < (unsigned)ysize; 30 | } 31 | 32 | bool contains( int x, int y ) const { 33 | // Do all 4 comparisons in 2 by using unsigned numbers. If x < 0, then its unsigned representation will 34 | // be bigger than xsize. Note that this only works for integers. 35 | return (unsigned)x < (unsigned)xsize && (unsigned)y < (unsigned)ysize; 36 | } 37 | 38 | bool is_coord_valid( const vector_type& coord ) const { return contains( coord ); } 39 | 40 | bool is_index_valid( int ix, int iy ) const { return contains( ix, iy ); } 41 | 42 | // Gets the index corresponding to the vector 43 | int get_index( const vector_type& vec ) const { 44 | if( !contains( vec.x, vec.y ) ) 45 | throw std::runtime_error( "size2.get_index: Tried to get the index of an out of bounds vector: " + 46 | vec.str() + ", " + this->str() ); 47 | return vec.x + xsize * vec.y; 48 | } 49 | 50 | // Gets the index corresponding to the vector 51 | int get_index( int x, int y ) const { 52 | if( !contains( x, y ) ) 53 | throw std::runtime_error( "size2.get_index: Tried to get the index of an out of bounds vector: " + 54 | vector2( x, y ).str() + ", " + this->str() ); 55 | return x + xsize * y; 56 | } 57 | 58 | // Gets the vector corresponding to the index 59 | vector2 get_coord( int index ) const { return vector2( index % xsize, ( index / xsize ) % ysize ); } 60 | 61 | int area() const { return xsize * ysize; } 62 | }; 63 | 64 | inline size2 operator*( const size2& lhs, int rhs ) { return size2( lhs.xsize * rhs, lhs.ysize * rhs ); } 65 | 66 | inline size2 operator*( int lhs, const size2& rhs ) { return size2( rhs.xsize * lhs, rhs.ysize * lhs ); } 67 | 68 | } // namespace graphics2d 69 | } // namespace frantic 70 | -------------------------------------------------------------------------------- /frantic/graphics2d/size2f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace frantic { 10 | namespace graphics2d { 11 | 12 | class size2f : public size2t { 13 | public: 14 | size2f() 15 | : size2t( 0.0f, 0.0f ) {} 16 | size2f( float w ) 17 | : size2t( w, w ) {} 18 | size2f( float w, float h ) 19 | : size2t( w, h ) {} 20 | template 21 | explicit size2f( const size2t& s ) 22 | : size2t( (float)s.xsize, (float)s.ysize ) {} 23 | 24 | typedef vector2f vector_type; 25 | 26 | bool contains( const vector_type& coord ) const { 27 | return 0 <= coord.x && coord.x < xsize && 0 <= coord.y && coord.y < ysize; 28 | } 29 | 30 | static size2f from_bounds( const vector2f& minimum, const vector2f& maximum ) { 31 | size2f result( maximum.x - minimum.x, maximum.y - minimum.y ); 32 | if( result.xsize < 0 || result.ysize < 0 ) { 33 | result.xsize = 0; 34 | result.ysize = 0; 35 | } 36 | return result; 37 | } 38 | }; 39 | 40 | } // namespace graphics2d 41 | } // namespace frantic 42 | -------------------------------------------------------------------------------- /frantic/hashing/blake2_hash.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #pragma warning( push ) 6 | #pragma warning( disable : 4804 ) 7 | #include 8 | #pragma warning( pop ) 9 | 10 | namespace frantic { 11 | namespace hashing { 12 | 13 | /* 14 | * BLAKE2s is optimized for 8- to 32-bit platforms and produces digests 15 | * of any size between 1 and 32 bytes 16 | */ 17 | class blake2s_hash { 18 | public: 19 | enum { hash_size = BLAKE2S_OUTBYTES }; 20 | 21 | blake2s_hash(); 22 | void update( const void* in, boost::uint64_t inlen ); 23 | void final_value( unsigned char* out ); 24 | 25 | private: 26 | blake2s_state m_state; 27 | }; 28 | 29 | /* 30 | * BLAKE2b (or just BLAKE2) is optimized for 64-bit platforms - including 31 | * NEON-enabled ARMs - and produces digests of any size between 1 and 64 bytes 32 | */ 33 | class blake2b_hash { 34 | public: 35 | enum { hash_size = BLAKE2B_OUTBYTES }; 36 | 37 | blake2b_hash(); 38 | void update( const void* in, boost::uint64_t inlen ); 39 | void final_value( unsigned char* out ); 40 | 41 | private: 42 | blake2b_state m_state; 43 | }; 44 | 45 | /* 46 | * 8-way parallel BLAKE2sp 47 | */ 48 | class blake2sp_hash { 49 | public: 50 | enum { hash_size = BLAKE2S_OUTBYTES }; 51 | 52 | blake2sp_hash(); 53 | void update( const void* in, boost::uint64_t inlen ); 54 | void final_value( unsigned char* out ); 55 | 56 | private: 57 | blake2sp_state m_state; 58 | }; 59 | 60 | /* 61 | * 4-way parallel BLAKE2bp 62 | */ 63 | class blake2bp_hash { 64 | public: 65 | enum { hash_size = BLAKE2B_OUTBYTES }; 66 | 67 | blake2bp_hash(); 68 | void update( const void* in, boost::uint64_t inlen ); 69 | void final_value( unsigned char* out ); 70 | 71 | private: 72 | blake2bp_state m_state; 73 | }; 74 | 75 | } // namespace hashing 76 | } // namespace frantic 77 | -------------------------------------------------------------------------------- /frantic/hashing/hashing.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | namespace frantic { 6 | namespace hashing { 7 | 8 | /** 9 | * \param out a pointer to hash_size bytes to be uses as output 10 | * \param in a pointer to the bytes you want to hash 11 | * \param inlen the number of bytes to hash 12 | */ 13 | template 14 | inline void get_hash( unsigned char* out, const void* in, std::size_t inlen ) { 15 | HashAlgorithm h; 16 | h.update( in, inlen ); 17 | h.final_value( out ); 18 | } 19 | 20 | template 21 | inline std::string get_hash( const void* in, std::size_t inlen ) { 22 | unsigned char* out = (unsigned char*)alloca( HashAlgorithm::hash_size ); 23 | get_hash( out, in, inlen ); 24 | return hash_to_string( out, HashAlgorithm::hash_size ); 25 | } 26 | 27 | /** 28 | * Convert a hexadecimal hash to a string. 29 | * 30 | * @param in a pointer to the bytes to hash. 31 | * @param inSize the number of bytes in the hash. 32 | */ 33 | std::string hash_to_string( unsigned char* in, std::size_t inSize ); 34 | 35 | } // namespace hashing 36 | } // namespace frantic 37 | -------------------------------------------------------------------------------- /frantic/locale/locale.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #ifndef _WIN32 6 | #include 7 | #include 8 | #include 9 | #endif 10 | 11 | namespace frantic { 12 | namespace locale { 13 | 14 | /** 15 | * Convert string to double, using the "C" locale. 16 | * 17 | * The "C" locale is useful here because it always uses a '.' decimal 18 | * separator. Other locales may use a different decimal separator. 19 | * For example, the German locale uses a ',', which causes problems when 20 | * parsing floating point numbers in a comma-separated value (CSV) file. 21 | */ 22 | #if defined( _WIN32 ) 23 | double strtod_c( const char* str, char** endptr ); 24 | #else 25 | inline double strtod_c( const char* str, char** endptr ) { 26 | #if defined( __APPLE__ ) 27 | // From the xlocale(3) manpage: 28 | // "If a NULL locale_t is passed, the C locale will be used." 29 | return strtod_l( str, endptr, NULL ); 30 | #else 31 | locale_t loc = newlocale( LC_ALL, "C", NULL ); 32 | const double result = strtod_l( str, endptr, loc ); 33 | freelocale( loc ); 34 | return result; 35 | #endif 36 | } 37 | 38 | #endif 39 | 40 | /** 41 | * Write formatted string to a file, using the "C" locale. 42 | */ 43 | #if defined( _WIN32 ) 44 | int fprintf_c( FILE* stream, const char* format, ... ); 45 | #else 46 | inline int fprintf_c( FILE* stream, const char* format, ... ) { 47 | #if defined( __APPLE__ ) 48 | va_list varargs; 49 | va_start( varargs, format ); 50 | 51 | const int result = vfprintf_l( stream, NULL, format, varargs ); 52 | 53 | va_end( varargs ); 54 | 55 | return result; 56 | #else 57 | locale_t loc = newlocale( LC_ALL, "C", NULL ); 58 | locale_t oldLoc = uselocale( loc ); 59 | 60 | va_list varargs; 61 | va_start( varargs, format ); 62 | 63 | const int result = vfprintf( stream, format, varargs ); 64 | 65 | va_end( varargs ); 66 | 67 | uselocale( oldLoc ); 68 | freelocale( loc ); 69 | 70 | return result; 71 | #endif 72 | } 73 | #endif 74 | 75 | /** 76 | * Convert the value to a string, using the "C" locale. 77 | */ 78 | std::string to_string_c( double value ); 79 | 80 | /** 81 | * Set the program locale by calling setlocale(). 82 | * This operation is typically per-process, and not thread safe. 83 | * 84 | * @note This is intended for use in test suites only. 85 | */ 86 | class set_locale_in_scope { 87 | public: 88 | set_locale_in_scope( const char* locale ); 89 | ~set_locale_in_scope(); 90 | 91 | private: 92 | std::string m_oldLocale; 93 | }; 94 | 95 | } // namespace locale 96 | } // namespace frantic 97 | -------------------------------------------------------------------------------- /frantic/logging/console_progress_logger.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace frantic { 10 | namespace logging { 11 | 12 | // Prints out progress information to the console. 13 | class console_progress_logger : public progress_logger { 14 | frantic::diagnostics::timeout_tracker m_progressTimeout; 15 | std::string m_title; 16 | 17 | void print_progress( long long completed, long long maximum, float progress ) { 18 | std::cout << "\r" << m_title << "Progress: "; 19 | if( completed == 0 && maximum == 0 ) { 20 | std::cout << get_adjusted_progress( progress ) << "% "; 21 | } else { 22 | std::cout << completed << "/" << maximum << " (" << get_adjusted_progress( progress ) 23 | << "%) "; 24 | } 25 | std::cout.flush(); 26 | } 27 | 28 | public: 29 | console_progress_logger( float progressStart = 0, float progressEnd = 100 ) 30 | : progress_logger( progressStart, progressEnd ) 31 | , m_title( "" ) { 32 | // print_progress( 0, 0, 0 ); 33 | // Print progress 5 times a second 34 | m_progressTimeout.restart_timeout( 200 ); 35 | } 36 | virtual ~console_progress_logger() { 37 | if( is_logging_progress() ) 38 | std::cout << std::endl; 39 | } 40 | 41 | // This won't become active until the next progress update 42 | void set_title( const frantic::tstring& title ) { 43 | if( title != _T("") ) 44 | m_title = frantic::strings::to_string( title ) + " - "; 45 | else 46 | m_title = ""; 47 | } 48 | 49 | void update_progress( long long completed, long long maximum ) { 50 | if( is_logging_progress() && ( completed == maximum || m_progressTimeout.timed_out() ) ) { 51 | if( maximum == 0 ) 52 | print_progress( completed, maximum, 0 ); 53 | else 54 | print_progress( completed, maximum, (float)completed * 100.f / maximum ); 55 | // Print progress 5 times a second 56 | m_progressTimeout.restart_timeout( 200 ); 57 | } 58 | } 59 | 60 | void update_progress( float progressPercent ) { 61 | if( is_logging_progress() && ( progressPercent >= 100 || m_progressTimeout.timed_out() ) ) { 62 | print_progress( 0, 0, progressPercent ); 63 | // Print progress 5 times a second 64 | m_progressTimeout.restart_timeout( 200 ); 65 | } 66 | } 67 | }; 68 | 69 | } // namespace logging 70 | } // namespace frantic 71 | -------------------------------------------------------------------------------- /frantic/logging/global_progress_logger.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | /** 8 | * This macro provides an efficient way to log global progress. By making a call such as: 9 | * FF_GLOBAL_PROGRESS().update_progress( 123, 999 ); 10 | * This will only call update_progress(long,long) if global progress is actually active. Compared to: 11 | * get_global_progress_logger().update_progress( 123, 999 ); 12 | * which has to call a virtual function even if logging is disabled (albeit to a null_progress_logger which just 13 | * returns.) 14 | */ 15 | #define FF_GLOBAL_PROGRESS() \ 16 | if( frantic::logging::is_global_progress_active() ) \ 17 | frantic::logging::detail::get_global_progress_impl() 18 | 19 | namespace frantic { 20 | namespace logging { 21 | 22 | namespace detail { 23 | // This global object is exposed for returning from get_global_progress_logger() when progress is disabled. 24 | extern frantic::logging::null_progress_logger g_nullProgress; 25 | 26 | // This global bool is exposed for use by is_global_progress_active() 27 | extern bool g_isGlobalProgressActive; 28 | 29 | /** 30 | * Returns a progress_logger object for use by clients. The result of this is undefined if g_isGlobalProgressActive is 31 | * false 32 | * @return A reference to a thread-safe global progress logger. 33 | */ 34 | frantic::logging::progress_logger& get_global_progress_impl(); 35 | 36 | void set_global_progress_impl( frantic::logging::progress_logger& progressLogger, bool isThreadSafe ); 37 | void reset_global_progress_impl(); 38 | } // namespace detail 39 | 40 | inline bool is_global_progress_active() { return detail::g_isGlobalProgressActive; } 41 | 42 | inline frantic::logging::progress_logger& get_global_progress_logger() { 43 | if( is_global_progress_active() ) 44 | return detail::get_global_progress_impl(); 45 | return detail::g_nullProgress; 46 | } 47 | 48 | inline void check_global_abort() { FF_GLOBAL_PROGRESS().check_for_abort(); } 49 | 50 | class scoped_global_progress_section { 51 | public: 52 | scoped_global_progress_section( frantic::logging::progress_logger& progressLogger, bool isThreadSafe = false ) { 53 | detail::set_global_progress_impl( progressLogger, isThreadSafe ); 54 | } 55 | 56 | ~scoped_global_progress_section() { detail::reset_global_progress_impl(); } 57 | }; 58 | 59 | } // namespace logging 60 | } // namespace frantic 61 | -------------------------------------------------------------------------------- /frantic/logging/render_progress_logger.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace frantic { 9 | namespace logging { 10 | 11 | // This adds framebuffer update functions to the progress logger. 12 | class render_progress_logger : public progress_logger { 13 | public: 14 | render_progress_logger( float progressStart = 0, float progressEnd = 100 ) 15 | : progress_logger( progressStart, progressEnd ) {} 16 | virtual ~render_progress_logger() {} 17 | 18 | // Frame buffer update functions 19 | virtual void update_frame_buffer( frantic::graphics2d::framebuffer& buffer ) = 0; 20 | // TODO: Add variants for updating individual rectangle regions, buckets, etc. 21 | }; 22 | 23 | // A null logger for situations where logging is just not required. 24 | class null_render_progress_logger : public render_progress_logger { 25 | void set_title( const frantic::tstring& /*title*/ ) {} 26 | 27 | void update_progress( long long /*completed*/, long long /*maximum*/ ) {} 28 | void update_progress( float /*percent*/ ) {} 29 | void update_frame_buffer( frantic::graphics2d::framebuffer& /*buffer*/ ) {} 30 | }; 31 | 32 | } // namespace logging 33 | } // namespace frantic 34 | -------------------------------------------------------------------------------- /frantic/math/exact_predicates.h: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #define FRANTIC_EXACT_PREDICATES 6 | 7 | namespace frantic { 8 | namespace math { 9 | 10 | extern "C" { 11 | // Any program seeking to use the exact arithmetic predicates must call this function to initialize some 12 | // eror bounds information. 13 | extern void exactinit(); 14 | 15 | extern float insphere( float* pa, float* pb, float* pc, float* pd, float* pe ); 16 | extern float incircle( float* pa, float* pb, float* pc, float* pd ); 17 | extern float orient3d( float* pa, float* pb, float* pc, float* pd ); 18 | extern float orient2d( float* pa, float* pb, float* pc ); 19 | 20 | /*extern double insphere_double(double* pa, double* pb, double* pc, double* pd, double* pe); 21 | extern double incircle_double(double* pa, double* pb, double* pc, double* pd); 22 | extern double orient3d_double(double* pa, double* pb, double* pc, double* pd); 23 | extern double orient2d_double(double* pa, double* pb, double* pc);*/ 24 | } 25 | 26 | } // namespace math 27 | } // namespace frantic 28 | -------------------------------------------------------------------------------- /frantic/math/fractions.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace math { 9 | 10 | /** 11 | * This function computes a rational number that is guaranteed to be a better approximation for the given 12 | * floating point argument than any other rational number with a smaller denominator. 13 | * It uses continued fractions to iteratively generate the rational number and stops once the numerator or 14 | * denominator exceeds the supplied value (minNumDenom) or 100 continued fraction terms, whichever occurs first. 15 | * The result is a rational number, returned as a numerator/denominator pair. 16 | */ 17 | inline std::pair 18 | get_rational_representation( double d, boost::int64_t minNumDenom = ( 1 << 24 ) ) { 19 | boost::int64_t pPrev = 0, pCur = 1, qPrev = 1, qCur = 0; 20 | double val = std::abs( d ); 21 | for( int i = 0; i < 100; ++i ) { 22 | boost::int64_t a = static_cast( val ); 23 | 24 | // Make sure to handle overflows gracefully. For small input values, a can become very large so (a * qCur) 25 | // overflows. 26 | // TODO: 'a' can only be 0 on the first iteration. If this loop is unrolled, this check can be eliminated. 27 | // HACK: This does not prevent an integer overflow from the addition in the recurrence relation!!!! 28 | if( a != 0 ) { 29 | boost::int64_t maxVal = std::numeric_limits::max() / a; 30 | if( qCur > maxVal || pCur > maxVal ) 31 | break; 32 | } 33 | 34 | boost::int64_t pNext = a * pCur + pPrev; 35 | boost::int64_t qNext = a * qCur + qPrev; 36 | 37 | pPrev = pCur; 38 | pCur = pNext; 39 | qPrev = qCur; 40 | qCur = qNext; 41 | 42 | // Break if the desired denominator accuracy has been reached. 43 | // Also, break if the numerator is large to prevent overflow. 44 | if( pCur > minNumDenom || qCur > minNumDenom ) 45 | break; 46 | 47 | double trunc = ( val - std::floor( val ) ); 48 | if( trunc <= 0.0 ) // Should this use an epsilon? 49 | break; 50 | 51 | val = 1.0 / trunc; 52 | } 53 | 54 | if( d < 0 ) 55 | return std::make_pair( -pCur, qCur ); 56 | return std::make_pair( pCur, qCur ); 57 | } 58 | 59 | } // namespace math 60 | } // namespace frantic 61 | -------------------------------------------------------------------------------- /frantic/math/hash.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | // These are the functions from Bob Jenkins' public domain hash program 8 | extern "C" { 9 | 10 | /* 11 | -------------------------------------------------------------------- 12 | This works on all machines. To be useful, it requires 13 | -- that the key be an array of uint32_t's, and 14 | -- that the length be the number of uint32_t's in the key 15 | 16 | The function hashword() is identical to hashlittle() on little-endian 17 | machines, and identical to hashbig() on big-endian machines, 18 | except that the length has to be measured in uint32_ts rather than in 19 | bytes. hashlittle() is more complicated than hashword() only because 20 | hashlittle() has to dance around fitting the key bytes into registers. 21 | -------------------------------------------------------------------- 22 | */ 23 | boost::uint32_t hashword( const boost::uint32_t* k, /* the key, an array of uint32_t values */ 24 | size_t length, /* the length of the key, in uint32_ts */ 25 | boost::uint32_t initval ); /* the previous hash, or an arbitrary value */ 26 | 27 | void hashword2( const boost::uint32_t* k, /* the key, an array of uint32_t values */ 28 | size_t length, /* the length of the key, in uint32_ts */ 29 | boost::uint32_t* pc, /* IN: seed OUT: primary hash value */ 30 | boost::uint32_t* pb ); /* IN: more seed OUT: secondary hash value */ 31 | 32 | boost::uint32_t hashlittle( const void* key, size_t length, boost::uint32_t initval ); 33 | 34 | void hashlittle2( const void* key, /* the key to hash */ 35 | size_t length, /* length of the key */ 36 | boost::uint32_t* pc, /* IN: primary initval, OUT: primary hash */ 37 | boost::uint32_t* pb ); /* IN: secondary initval, OUT: secondary hash */ 38 | 39 | } // extern "C" 40 | 41 | // Provide the same hashword function for 64 bit 42 | inline boost::uint64_t hashword64( const boost::uint32_t* key, size_t length, boost::uint64_t initval ) { 43 | boost::uint32_t pb = ( boost::uint32_t )( initval >> 32 ), pc = (boost::uint32_t)initval; 44 | hashword2( key, length, &pc, &pb ); 45 | return pc + ( ( (boost::uint64_t)pb ) << 32 ); 46 | } 47 | 48 | // Provide the same hashlittle function for 64 bit 49 | inline boost::uint64_t hashlittle64( const void* key, size_t length, boost::uint64_t initval ) { 50 | boost::uint32_t pb = ( boost::uint32_t )( initval >> 32 ), pc = (boost::uint32_t)initval; 51 | hashlittle2( key, length, &pc, &pb ); 52 | return pc + ( ( (boost::uint64_t)pb ) << 32 ); 53 | } 54 | -------------------------------------------------------------------------------- /frantic/misc/functor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /** 4 | * @file 5 | * @author Stephen Kiazyk 6 | * 7 | * A collection of some functors I've found useful at some point or another 8 | */ 9 | #pragma once 10 | 11 | #if defined( _MSC_VER ) 12 | #pragma warning( push ) 13 | // Disable warning C4800: '' : forcing value to bool 'true' or 'false' (performance warning) 14 | #pragma warning( disable : 4800 ) 15 | #endif 16 | 17 | namespace frantic { 18 | 19 | template 20 | class array_functor { 21 | private: 22 | array_functor& operator=( const array_functor& other ); 23 | const A& m_array; 24 | 25 | public: 26 | array_functor( const A& a ) 27 | : m_array( a ) {} 28 | array_functor( const array_functor& other ) 29 | : m_array( other.m_array ) {} 30 | R operator()( size_t i ) const { return static_cast( m_array[i] ); } 31 | }; 32 | 33 | template 34 | array_functor make_bool_array_functor( const A& a ) { 35 | return array_functor( a ); 36 | } 37 | 38 | } // namespace frantic 39 | 40 | #if defined( _MSC_VER ) 41 | #pragma warning( pop ) 42 | #endif 43 | -------------------------------------------------------------------------------- /frantic/misc/hybrid_assert.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | // (and therefire ) are unique in that they are designed to be included multiple times and can 6 | // change the meaning of the assert macro depending on the state of the NDEBUG macro. 7 | // 8 | // This file will temporarily disable NDEBUG so that asserts are enabled (if FRANTIC_HYBRID is defined at the time of 9 | // inclusion) 10 | 11 | #ifdef FRANTIC_HYBRID 12 | #ifdef NDEBUG 13 | #undef NDEBUG 14 | #define FRANTIC_HYBRID_NDEBUG_TRUE 15 | #endif 16 | 17 | #include 18 | 19 | #ifdef FRANTIC_HYBRID_NDEBUG_TRUE 20 | #undef FRANTIC_HYBRID_NDEBUG_TRUE 21 | #define NDEBUG 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /frantic/misc/utility.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /** 4 | * @file 5 | * @author Stephen Kiazyk 6 | * 7 | * Potentially useful extensions to the header 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace frantic { 16 | 17 | /** 18 | * Returns a homogeneous pair that is in 'sorted' order. 19 | * This is useful if you need a pair type as elements of a set. 20 | */ 21 | template 22 | std::pair make_sorted_pair( const T& u, const T& v ) { 23 | return std::make_pair( std::min( u, v ), std::max( u, v ) ); 24 | } 25 | 26 | template 27 | inline void clear_with_swap( std::vector& v ) { 28 | std::vector temp; 29 | v.swap( temp ); 30 | } 31 | 32 | template 33 | inline void shrink_to_fit( std::vector& v ) { 34 | std::vector temp( v.begin(), v.end() ); 35 | v.swap( temp ); 36 | } 37 | 38 | } // namespace frantic 39 | -------------------------------------------------------------------------------- /frantic/os/child_process.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #ifdef _WIN32 6 | #include 7 | #else 8 | #include 9 | #endif 10 | -------------------------------------------------------------------------------- /frantic/os/environment.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace os { 9 | 10 | /** 11 | * Set the environment variable with name key to value for the duration of current process. 12 | * 13 | * @param key the name of the environment variable 14 | * @param value the value to store 15 | * 16 | * Will throw a runtime error if it failed to set the environment variable. 17 | */ 18 | void set_environment_variable( const frantic::tstring& key, const frantic::tstring& value ); 19 | 20 | /** 21 | * Return the environment variable with name key. 22 | * 23 | * @param key the name of the environment variable 24 | * 25 | * @return the value stored in the environment variable if it's set, an empty string otherwise 26 | */ 27 | frantic::tstring get_environment_variable( const frantic::tstring& key ); 28 | 29 | /** 30 | * Return the environment variable with name key. 31 | * 32 | * Unlike get_environment_variable, this will attempt to read the most up to date environment variable to account 33 | * for them changing while the program is running. It is less efficient than get_environment_variable as it needs 34 | * to construct the updated list of variables and iterate through it to find the entry. 35 | * 36 | * This is only implemented for Windows. On other OSs, it just calls get_environment_variable. 37 | * 38 | * If the environment block could not be initialized, it will call get_environment_variable. 39 | * 40 | * @param key the name of the environment variable 41 | * @param outIsFromOS if not NULL, this is set to true if it tried to read the value from the OS environment 42 | * variable block. Otherwise it is set to false. 43 | * 44 | * @return the value stored in the environment variable if it's set, an empty string otherwise 45 | */ 46 | frantic::tstring get_environment_variable_from_os_scope( const frantic::tstring& key, bool* outIsFromOS = NULL ); 47 | 48 | } // namespace os 49 | } // namespace frantic 50 | -------------------------------------------------------------------------------- /frantic/particles/particle_file_metadata.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace frantic { 11 | namespace particles { 12 | 13 | class particle_file_metadata { 14 | 15 | private: 16 | frantic::channels::property_map m_generalMetadata; 17 | typedef std::map channel_metadata_t; 18 | channel_metadata_t m_channelMetadata; 19 | 20 | public: 21 | particle_file_metadata(); 22 | particle_file_metadata( const frantic::channels::property_map& generalMetadata ); 23 | particle_file_metadata( const frantic::channels::property_map& generalMetadata, 24 | const channel_metadata_t& channelMetadata ); 25 | 26 | void clear(); 27 | 28 | bool empty() const; 29 | 30 | void get_channels_with_metadata( std::vector& outNames ) const; 31 | 32 | const frantic::channels::property_map& get_general_metadata() const; 33 | frantic::channels::property_map& get_general_metadata(); 34 | const frantic::channels::property_map* get_channel_metadata( const frantic::tstring& channelName ) const; 35 | frantic::channels::property_map* get_channel_metadata( const frantic::tstring& channelName, 36 | bool autoCreate = false ); 37 | const channel_metadata_t& get_all_channel_metadata() const; 38 | channel_metadata_t& get_all_channel_metadata(); 39 | 40 | void set_general_metadata( const frantic::channels::property_map& metadata ); 41 | void set_channel_metadata( const frantic::tstring& channelName, const frantic::channels::property_map& metadata ); 42 | 43 | void append( const particle_file_metadata& other, bool noRepeats = true ); 44 | void append_general_metadata( const frantic::channels::property_map& metadata, bool noRepeats = true ); 45 | void append_channel_metadata( const frantic::tstring& channelName, const frantic::channels::property_map& metadata, 46 | bool noRepeats = true ); 47 | }; 48 | 49 | } // namespace particles 50 | } // namespace frantic 51 | -------------------------------------------------------------------------------- /frantic/particles/particle_step.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | namespace frantic { 18 | namespace particles { 19 | 20 | class particle_step { 21 | // constant old values 22 | const frantic::graphics::vector3f& m_oldVelocity; 23 | const frantic::graphics::vector3f& m_oldPosition; 24 | 25 | int m_startTime; 26 | int m_endTime; 27 | float m_timeStep; 28 | 29 | // new values that can be set 30 | boost::uint32_t& m_flag; 31 | frantic::graphics::vector3f& m_newVelocity; 32 | frantic::graphics::vector3f& m_newPosition; 33 | 34 | // Make the assignment operator private so no one can use it. 35 | particle_step& operator=( const particle_step& ) {} 36 | 37 | public: 38 | particle_step( const frantic::graphics::vector3f& oldVelocity, const frantic::graphics::vector3f& oldPosition, 39 | frantic::graphics::vector3f& newVelocity, frantic::graphics::vector3f& newPosition, 40 | boost::uint32_t& flag, int startTime, int endTime, float timeStep ) 41 | : m_oldVelocity( oldVelocity ) 42 | , m_oldPosition( oldPosition ) 43 | , m_newVelocity( newVelocity ) 44 | , m_newPosition( newPosition ) 45 | , m_flag( flag ) { 46 | m_startTime = startTime; 47 | m_endTime = endTime; 48 | m_timeStep = timeStep; 49 | } 50 | 51 | void set( const frantic::graphics::vector3f& position, const frantic::graphics::vector3f& velocity ) { 52 | m_newPosition = position; 53 | m_newVelocity = velocity; 54 | m_flag = m_flag | frantic::particles::PRT_FLG_MODIFIED; // set the modified flag within the ID number 55 | } 56 | 57 | const frantic::graphics::vector3f& oldPosition() const { return m_oldPosition; } 58 | const frantic::graphics::vector3f& oldVelocity() const { return m_oldVelocity; } 59 | 60 | frantic::graphics::vector3f& newPosition() const { return m_newPosition; } 61 | frantic::graphics::vector3f& newVelocity() const { return m_newVelocity; } 62 | 63 | int start_time() const { return m_startTime; } 64 | int end_time() const { return m_endTime; } 65 | float time_step() const { return m_timeStep; } 66 | boost::uint32_t flag() const { return m_flag; } 67 | }; 68 | 69 | } // namespace particles 70 | } // namespace frantic 71 | -------------------------------------------------------------------------------- /frantic/particles/sph/sph_kernel_functions.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace particles { 9 | namespace sph { 10 | 11 | /** 12 | * "Poly 6" kernel function used in SPH 13 | */ 14 | class poly6_kernel { 15 | private: 16 | float m_poly6Scale; 17 | float m_poly6DerivScale; 18 | float m_compactSupportSquared; 19 | 20 | public: 21 | poly6_kernel() {} 22 | poly6_kernel( float compactSupport ) { 23 | // formula for the poly6 kernel function is m_poly6Scale * ( m_compactSupportSquared - distanceSquared )^3. (see 24 | // papers on the topic) 25 | m_poly6Scale = 315.0f / ( 64.0f * (float)M_PI * powf( compactSupport, 9.0f ) ); 26 | m_poly6DerivScale = 945.0f / ( 32.0f * (float)M_PI * powf( compactSupport, 9.0f ) ); 27 | m_compactSupportSquared = compactSupport * compactSupport; 28 | } 29 | 30 | float kernel( float distanceSquared ) { 31 | float difference = m_compactSupportSquared - distanceSquared; 32 | if( difference < 0.0f ) 33 | return 0.0f; 34 | return m_poly6Scale * difference * difference * difference; 35 | } 36 | 37 | frantic::graphics::vector3f kernel_gradient( frantic::graphics::vector3f distanceVector ) { 38 | float difference = m_compactSupportSquared - distanceVector.get_magnitude_squared(); 39 | if( difference < 0.0f ) 40 | return frantic::graphics::vector3f( 0.0f ); 41 | return ( m_poly6DerivScale * difference * difference ) * distanceVector; 42 | } 43 | }; 44 | 45 | /** 46 | * "Spiky" kernel function used in SPH 47 | */ 48 | class spiky_kernel { 49 | private: 50 | float m_spikyScale; 51 | float m_spikyDerivScale; 52 | float m_compactSupport; 53 | 54 | public: 55 | spiky_kernel() {} 56 | spiky_kernel( float compactSupport ) { 57 | m_spikyScale = 15.0f / ( (float)M_PI * powf( compactSupport, 6.0f ) ); 58 | m_spikyDerivScale = -45.0f / ( (float)M_PI * powf( compactSupport, 6.0f ) ); 59 | m_compactSupport = compactSupport; 60 | } 61 | 62 | float kernel( float distance ) { 63 | float difference = m_compactSupport - distance; 64 | if( difference < 0.0f ) 65 | return 0.0f; 66 | return m_spikyScale * difference * difference * difference; 67 | } 68 | 69 | frantic::graphics::vector3f kernel_gradient( frantic::graphics::vector3f distanceVector ) { 70 | float difference = m_compactSupport - distanceVector.get_magnitude(); 71 | if( difference < 0.0f ) 72 | return frantic::graphics::vector3f( 0.0f ); 73 | return ( m_spikyDerivScale * difference * difference ) * distanceVector; 74 | } 75 | }; 76 | 77 | } // namespace sph 78 | } // namespace particles 79 | } // namespace frantic 80 | -------------------------------------------------------------------------------- /frantic/particles/streams/age_culled_particle_istream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace frantic { 13 | namespace particles { 14 | namespace streams { 15 | 16 | class age_culled_particle_istream : public frantic::particles::streams::delegated_particle_istream { 17 | boost::int64_t m_particleIndex; 18 | 19 | public: 20 | age_culled_particle_istream( particle_istream_ptr pDelegate, float minAge ); 21 | 22 | static particle_istream_ptr apply_to_stream( particle_istream_ptr pin, float minAge ); 23 | 24 | virtual std::size_t particle_size() const { return this->get_channel_map().structure_size(); } 25 | virtual boost::int64_t particle_count() const { return -1; } 26 | virtual boost::int64_t particle_index() const { return m_particleIndex; } 27 | virtual boost::int64_t particle_count_left() const { return -1; } 28 | virtual boost::int64_t particle_progress_count() const { return m_delegate->particle_progress_count(); } 29 | virtual boost::int64_t particle_progress_index() const { return m_delegate->particle_progress_index(); } 30 | virtual boost::int64_t particle_count_guess() const { return m_delegate->particle_count_guess(); } 31 | 32 | virtual void set_channel_map( const frantic::channels::channel_map& particleChannelMap ); 33 | virtual void set_default_particle( char* rawParticleBuffer ); 34 | virtual const frantic::channels::channel_map& get_channel_map() const; 35 | 36 | virtual bool get_particle( char* pBuffer ); 37 | virtual bool get_particles( char* pBuffer, std::size_t& numParticles ); 38 | 39 | private: 40 | class culling_body; 41 | 42 | typedef std::vector, tbb::tbb_allocator>> 43 | vector_type; 44 | 45 | void cull_particles1( char* pBuffer, const tbb::blocked_range& range, 46 | vector_type& outValidRanges ) const; 47 | void cull_particles2( char* pOutBuffer, const char* pBuffer, const vector_type& outValidRanges, 48 | std::size_t& outCount ) const; 49 | 50 | bool cull( char* pParticle ) const; 51 | 52 | void set_channel_map_impl( const frantic::channels::channel_map& channelMap ); 53 | 54 | private: 55 | frantic::channels::channel_map_adaptor m_adaptor; 56 | frantic::channels::channel_map m_outMap; 57 | frantic::channels::channel_cvt_accessor m_ageAccessor; 58 | 59 | float m_minAge; 60 | }; 61 | 62 | } // namespace streams 63 | } // namespace particles 64 | } // namespace frantic 65 | -------------------------------------------------------------------------------- /frantic/particles/streams/channel_scale_particle_istream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace frantic { 10 | namespace particles { 11 | namespace streams { 12 | 13 | // A particle stream that scales the density by a provided constant. 14 | class channel_scale_particle_istream : public delegated_particle_istream { 15 | private: 16 | float m_channelScale; 17 | 18 | frantic::tstring m_channelName; 19 | bool m_hasChannel; 20 | frantic::channels::channel_general_accessor m_channel; 21 | 22 | void prepare_accessors() { 23 | const frantic::channels::channel_map& pcm = m_delegate->get_channel_map(); 24 | 25 | m_hasChannel = pcm.has_channel( m_channelName ); 26 | if( m_hasChannel ) 27 | m_channel = pcm.get_general_accessor( m_channelName ); 28 | } 29 | 30 | public: 31 | channel_scale_particle_istream( const boost::shared_ptr& istream, 32 | const frantic::tstring& channelName, float channelScale ) 33 | : delegated_particle_istream( istream ) 34 | , m_channelName( channelName ) 35 | , m_channelScale( channelScale ) { 36 | prepare_accessors(); 37 | } 38 | 39 | virtual ~channel_scale_particle_istream() {} 40 | 41 | void set_channel_map( const frantic::channels::channel_map& particleChannelMap ) { 42 | m_delegate->set_channel_map( particleChannelMap ); 43 | prepare_accessors(); 44 | } 45 | 46 | bool get_particle( char* rawParticleBuffer ) { 47 | bool result = m_delegate->get_particle( rawParticleBuffer ); 48 | if( result ) { 49 | if( m_hasChannel ) { 50 | 51 | char* data = m_channel.get_channel_data_pointer( rawParticleBuffer ); 52 | m_channel.weighted_sum( &m_channelScale, &data, 1, data ); 53 | } 54 | } 55 | return result; 56 | } 57 | 58 | bool get_particles( char* buffer, std::size_t& outSize ) { 59 | std::size_t particleSize = m_delegate->get_channel_map().structure_size(); 60 | for( std::size_t i = 0; i < outSize; ++i, buffer += particleSize ) { 61 | if( !get_particle( buffer ) ) { 62 | outSize = i; 63 | return false; 64 | } 65 | } 66 | 67 | return true; 68 | } 69 | }; 70 | 71 | } // namespace streams 72 | } // namespace particles 73 | } // namespace frantic 74 | -------------------------------------------------------------------------------- /frantic/particles/streams/e57_particle_mutex.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace particles { 9 | namespace streams { 10 | /// Mutex to ensure that only one thread calls the e57::ImageFile constructor at a time. The ImageFile constructor 11 | /// calls xercesc::XMLPlatforumUtils::Initialize() and Terminate(), which are not thread safe, and can cause a crash 12 | /// if multiple threads create an e57_particle_ostream simultaneously. 13 | extern boost::mutex g_e57ImageFileConstructorMutex; 14 | } // namespace streams 15 | } // namespace particles 16 | } // namespace frantic 17 | -------------------------------------------------------------------------------- /frantic/particles/streams/empty_particle_istream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace frantic { 9 | namespace particles { 10 | namespace streams { 11 | 12 | // An empty particle_istream. Useful as a return value for a function that has had an internal error, 13 | // but still needs to produce a particle_istream. 14 | class empty_particle_istream : public particle_istream { 15 | frantic::channels::channel_map m_particleChannelMap; 16 | frantic::channels::channel_map m_nativeMap; 17 | 18 | public: 19 | // NOTE: We don't provide a default constructor, because that's too error-prone. 20 | empty_particle_istream( const frantic::channels::channel_map& particleChannelMap ) 21 | : m_particleChannelMap( particleChannelMap ) 22 | , m_nativeMap( particleChannelMap ) {} 23 | 24 | // This is the preferred usage of empty_particle_istream 25 | empty_particle_istream( const frantic::channels::channel_map& particleChannelMap, 26 | const frantic::channels::channel_map& nativeMap ) 27 | : m_particleChannelMap( particleChannelMap ) 28 | , m_nativeMap( nativeMap ) {} 29 | 30 | virtual ~empty_particle_istream() {} 31 | 32 | void close() {} 33 | 34 | std::size_t particle_size() const { return m_particleChannelMap.structure_size(); } 35 | 36 | frantic::tstring name() const { return _T("Empty Particle Input Stream"); } 37 | boost::int64_t particle_count() const { return 0; } 38 | boost::int64_t particle_index() const { return -1; } 39 | boost::int64_t particle_count_left() const { return 0; } 40 | boost::int64_t particle_progress_count() const { return 0; } 41 | boost::int64_t particle_progress_index() const { return -1; } 42 | 43 | const frantic::channels::channel_map& get_channel_map() const { return m_particleChannelMap; } 44 | 45 | const frantic::channels::channel_map& get_native_channel_map() const { return m_nativeMap; } 46 | 47 | void set_default_particle( char* /*buffer*/ ) {} 48 | 49 | void set_channel_map( const frantic::channels::channel_map& particleChannelMap ) { 50 | m_particleChannelMap = particleChannelMap; 51 | } 52 | 53 | bool get_particle( char* /*rawParticleBuffer*/ ) { return false; } 54 | 55 | bool get_particles( char* /*particleBuffer*/, std::size_t& numParticles ) { 56 | numParticles = 0; 57 | return false; 58 | } 59 | }; 60 | 61 | } // namespace streams 62 | } // namespace particles 63 | } // namespace frantic 64 | -------------------------------------------------------------------------------- /frantic/particles/streams/particle_ostream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace frantic { 11 | namespace particles { 12 | namespace streams { 13 | 14 | using frantic::graphics::color3f; 15 | using frantic::graphics::vector3f; 16 | 17 | using frantic::channels::channel_map; 18 | 19 | ////////////////////// 20 | // PARTICLE OUTPUT STREAM BASE CLASS 21 | ////////////////////// 22 | 23 | class particle_ostream { 24 | public: 25 | particle_ostream() {} 26 | 27 | // Virtual destructor so that we can use allocated pointers (generally with boost::shared_ptr) 28 | virtual ~particle_ostream() {} 29 | 30 | // This is the particle channel map which specifies the byte layout of the particle structure. 31 | virtual const channel_map& get_channel_map() const = 0; 32 | 33 | // This allows you to change the particle layout that's being saved on the fly, in case it couldn't 34 | // be set correctly at creation time. 35 | virtual void set_channel_map( const channel_map& particleChannelMap ) = 0; 36 | 37 | // This is the size of the particle structure which should be passed to put_particle. It corresponds to 38 | // get_channel_map().structure_size() 39 | virtual std::size_t particle_size() const = 0; 40 | 41 | virtual void close() = 0; 42 | 43 | virtual void put_particle( const char* rawParticleData ) = 0; 44 | 45 | // Convenience function for std::vector 46 | void put_particle( const std::vector& rawParticleData ) { 47 | // TODO: In a debug mode, we could confirm that the vector is big enough to hold the particle. 48 | put_particle( &rawParticleData[0] ); 49 | } 50 | }; 51 | 52 | typedef boost::shared_ptr particle_ostream_ptr; 53 | 54 | } // namespace streams 55 | 56 | using streams::particle_ostream_ptr; 57 | 58 | } // namespace particles 59 | } // namespace frantic 60 | -------------------------------------------------------------------------------- /frantic/particles/streams/ply_particle_istream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace frantic { 12 | namespace particles { 13 | namespace streams { 14 | 15 | class ply_particle_istream : public particle_istream { 16 | public: 17 | ply_particle_istream( const frantic::tstring& filename ); 18 | 19 | ~ply_particle_istream(); 20 | 21 | void close(); 22 | 23 | std::size_t particle_size() const; 24 | 25 | frantic::tstring name() const; 26 | 27 | boost::int64_t particle_count() const; 28 | boost::int64_t particle_index() const; 29 | boost::int64_t particle_count_left() const; 30 | 31 | boost::int64_t particle_progress_count() const; 32 | boost::int64_t particle_progress_index() const; 33 | 34 | void set_channel_map( const frantic::channels::channel_map& channelMap ); 35 | 36 | const frantic::channels::channel_map& get_channel_map() const; 37 | 38 | const frantic::channels::channel_map& get_native_channel_map() const; 39 | 40 | void set_default_particle( char* rawParticleBuffer ); 41 | 42 | bool get_particle( char* rawParticleBuffer ); 43 | 44 | bool get_particles( char* rawParticleBuffer, std::size_t& numParticles ); 45 | 46 | private: 47 | bool m_isOpen; 48 | frantic::particles::particle_array m_particles; 49 | boost::int64_t m_particleIndex; 50 | frantic::channels::channel_map_adaptor m_channelMapAdaptor; 51 | std::vector m_defaultParticle; 52 | frantic::channels::channel_map m_channelMap; 53 | frantic::geometry::ply_reader m_reader; 54 | }; 55 | 56 | } // namespace streams 57 | } // namespace particles 58 | } // namespace frantic 59 | -------------------------------------------------------------------------------- /frantic/particles/streams/ply_particle_ostream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace frantic { 11 | namespace particles { 12 | namespace streams { 13 | 14 | class ply_particle_ostream : public particle_ostream { 15 | public: 16 | /** 17 | * @param filename .ply file to write to. 18 | * @param channelMap channel layout of the buffer that will be passed to 19 | * put_particle(). 20 | * @param diskChannelMap channels to write to disk. Only the Position, 21 | * Color, TextureCoord, and Normal channels are saved. These channels 22 | * are always saved as float32[3]; their data type in the channel map 23 | * is ignored. All other channels are ignored. 24 | */ 25 | ply_particle_ostream( const frantic::tstring& filename, const frantic::channels::channel_map& channelMap, 26 | const frantic::channels::channel_map& diskChannelMap ); 27 | 28 | ~ply_particle_ostream(); 29 | 30 | const channel_map& get_channel_map() const; 31 | 32 | void set_channel_map( const channel_map& channelMap ); 33 | 34 | std::size_t particle_size() const; 35 | 36 | /** 37 | * Close the stream, and write all of the particles to disk. 38 | * 39 | * Unlike most others, this stream does not keep a file open while you 40 | * insert particles. Instead, the particles are added to a buffer in 41 | * memory, and they are written to disk by this close() function. I do 42 | * this because the PLY IO library we're using requires the particle count 43 | * before we begin to write the particle data. (As an alternative, I 44 | * think we could write our own IO code, reserve space for the particle 45 | * count using a comment, and write the particle count when we close the 46 | * file.) 47 | * 48 | * @note No particles will be written to disk unless you call close(). 49 | */ 50 | void close(); 51 | 52 | void put_particle( const char* rawParticleData ); 53 | 54 | private: 55 | bool m_isClosed; 56 | 57 | frantic::particles::particle_array m_particles; 58 | 59 | // convert from m_channelMap to the m_particles channel map 60 | frantic::channels::channel_map_adaptor m_channelMapAdaptor; 61 | 62 | frantic::channels::channel_map m_channelMap; 63 | 64 | frantic::tstring m_filename; 65 | }; 66 | 67 | } // namespace streams 68 | } // namespace particles 69 | } // namespace frantic 70 | -------------------------------------------------------------------------------- /frantic/particles/streams/shared_particle_container_particle_istream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include 4 | #include 5 | 6 | namespace frantic { 7 | namespace particles { 8 | namespace streams { 9 | 10 | template 11 | class shared_particle_container_particle_istream 12 | : public frantic::particles::streams::particle_container_particle_istream { 13 | private: 14 | boost::shared_ptr m_particles; 15 | 16 | public: 17 | shared_particle_container_particle_istream( boost::shared_ptr particles ) 18 | : particle_container_particle_istream( particles->begin(), particles->end(), 19 | particles->get_channel_map() ) 20 | , m_particles( particles ) {} 21 | 22 | virtual ~shared_particle_container_particle_istream() {} 23 | }; 24 | 25 | } // namespace streams 26 | } // namespace particles 27 | } // namespace frantic 28 | -------------------------------------------------------------------------------- /frantic/particles/streams/volume_culled_particle_istream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace frantic { 11 | namespace particles { 12 | namespace streams { 13 | 14 | class volume_culling_policy : public culling_policy_base { 15 | boost::shared_ptr m_volume; 16 | frantic::channels::channel_accessor m_posAccessor; 17 | bool m_cullOutside; 18 | 19 | public: 20 | typedef boost::tuples::tuple, bool> args_type; 21 | 22 | volume_culling_policy( const args_type& args, const frantic::channels::channel_map& pcm ) 23 | : m_volume( args.get<0>() ) 24 | , m_cullOutside( args.get<1>() ) { 25 | set_channel_map( pcm ); 26 | } 27 | 28 | // Need a splitting constructor to support TBB 29 | volume_culling_policy( const volume_culling_policy& lhs, tbb::split ) 30 | : m_volume( lhs.m_volume ) 31 | , m_cullOutside( lhs.m_cullOutside ) 32 | , m_posAccessor( lhs.m_posAccessor ) {} 33 | 34 | void set_channel_map( const frantic::channels::channel_map& pcm ) { 35 | m_posAccessor = pcm.get_accessor( _T("Position") ); 36 | } 37 | 38 | bool cull( char* particle ) const { 39 | return m_volume->is_point_in_volume( m_posAccessor.get( particle ) ) != m_cullOutside; 40 | } 41 | }; 42 | 43 | typedef culling_particle_istream volume_culled_particle_istream; 44 | 45 | } // namespace streams 46 | } // namespace particles 47 | } // namespace frantic 48 | -------------------------------------------------------------------------------- /frantic/prtfile/sprt_common.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | // NOTE: This here is assuming a little-endian machine, as do the PRT and PRT2 I/O routines. 6 | 7 | // {0xC0, 't', 's', 't', '\r', '\n', 0x1A, '\n'}; 8 | #define SPRT1_MAGIC_NUMBER ( 0x0A1A0A0D747374C0ULL ) 9 | 10 | namespace frantic { 11 | namespace prtfile { 12 | 13 | inline bool has_sprt1_magic_number( const frantic::tstring& filename ) { 14 | std::ifstream fin( filename.c_str(), std::ios::in | std::ios::binary ); 15 | boost::uint64_t magic; 16 | fin.read( reinterpret_cast( &magic ), 8u ); 17 | return ( !fin.fail() && magic == SPRT1_MAGIC_NUMBER ); 18 | } 19 | 20 | inline std::size_t get_expected_number_of_octree_levels( boost::uint64_t totalCount, boost::uint64_t lowestDetailTotal, 21 | std::size_t levelCountMultiplier ) { 22 | std::size_t numLevels; 23 | if( totalCount <= lowestDetailTotal ) { 24 | numLevels = 1; 25 | } else { 26 | numLevels = static_cast( std::ceil( 27 | ( std::log( static_cast( totalCount ) ) - std::log( static_cast( lowestDetailTotal ) ) ) / 28 | std::log( static_cast( levelCountMultiplier ) ) ) ); 29 | } 30 | return numLevels; 31 | } 32 | 33 | } // namespace prtfile 34 | } // namespace frantic 35 | -------------------------------------------------------------------------------- /frantic/rendering/shadow_generator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | #pragma once 5 | 6 | namespace frantic { 7 | namespace rendering { 8 | // using frantic::graphics::vector3f; 9 | 10 | class shadow_generator { 11 | public: 12 | virtual ~shadow_generator() {} 13 | 14 | float compute_attenuation( const frantic::graphics::vector3f& /*start*/, 15 | const frantic::graphics::vector3f& /*end*/ ) { 16 | return 1; 17 | } 18 | }; 19 | 20 | // The shadow combiner class has three levels of shadow complexity. 21 | // Geometry shadows feature quick shadow computation and have a good chance of causing complete 22 | // attenuation. 23 | // Fast volumetric shadows feature quick shadow computation. An example of this is a constant density 24 | // volumetric. 25 | // Volumetric shadows are everything else. An example of this is a varying density volumetric with 26 | // a raymarching shadow calculation. 27 | class shadow_combiner { 28 | std::vector> m_geometryShadows; 29 | std::vector> m_fastVolumetricshadows; 30 | std::vector> m_volumetricShadows; 31 | 32 | public: 33 | void add_geometry_shadow( const boost::shared_ptr& shadow ) { 34 | m_geometryShadows.push_back( shadow ); 35 | } 36 | 37 | void add_fast_volumetric_shadow( const boost::shared_ptr& shadow ) { 38 | m_fastVolumetricshadows.push_back( shadow ); 39 | } 40 | 41 | void add_volumetric_shadow( const boost::shared_ptr& shadow ) { 42 | m_volumetricShadows.push_back( shadow ); 43 | } 44 | 45 | float compute_attenuation( const frantic::graphics::vector3f& start, 46 | const frantic::graphics::vector3f& end ) const { 47 | float attenuation = 1; 48 | std::vector>::const_iterator i; 49 | for( i = m_geometryShadows.begin(); i != m_geometryShadows.end(); ++i ) { 50 | attenuation *= ( *i )->compute_attenuation( start, end ); 51 | if( attenuation == 0 ) 52 | return 0; 53 | } 54 | for( i = m_fastVolumetricshadows.begin(); i != m_fastVolumetricshadows.end(); ++i ) { 55 | attenuation *= ( *i )->compute_attenuation( start, end ); 56 | if( attenuation == 0 ) 57 | return 0; 58 | } 59 | for( i = m_volumetricShadows.begin(); i != m_volumetricShadows.end(); ++i ) { 60 | attenuation *= ( *i )->compute_attenuation( start, end ); 61 | if( attenuation == 0 ) 62 | return 0; 63 | } 64 | return attenuation; 65 | } 66 | }; 67 | 68 | } // namespace rendering 69 | } // namespace frantic 70 | -------------------------------------------------------------------------------- /frantic/simd/detect.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #ifndef FRANTIC_DISABLE_SIMD 4 | #if defined( __SSE2__ ) || defined( _M_X64 ) || ( defined( _M_IX86_FP ) && _M_IX86_FP >= 2 ) 5 | #define FRANTIC_HAS_SSE2 6 | #endif 7 | #endif 8 | 9 | #ifdef FRANTIC_HAS_SSE2 10 | #define FRANTIC_SIMD_NAMESPACE sse2 11 | #else 12 | #define FRANTIC_SIMD_NAMESPACE scalar 13 | #endif 14 | -------------------------------------------------------------------------------- /frantic/simd/int_v.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | #ifdef FRANTIC_HAS_SSE2 10 | #include 11 | #endif 12 | 13 | namespace frantic { 14 | namespace simd { 15 | namespace FRANTIC_SIMD_NAMESPACE { 16 | 17 | class float_v; 18 | 19 | class int_v { 20 | public: 21 | typedef boost::int32_t value_type; 22 | typedef std::size_t size_type; 23 | 24 | #ifdef FRANTIC_HAS_SSE2 25 | typedef __m128i native_type; 26 | enum { static_size = 4 }; 27 | #else 28 | typedef boost::int32_t native_type; 29 | enum { static_size = 1 }; 30 | #endif 31 | 32 | int_v(); 33 | 34 | int_v( value_type a ); 35 | 36 | #ifdef FRANTIC_HAS_SSE2 37 | int_v( value_type a, value_type b, value_type c, value_type d ); 38 | 39 | int_v( const native_type& a ); 40 | #endif // #ifdef FRANTIC_HAS_SSE2 41 | 42 | explicit int_v( const float_v& a ); 43 | 44 | value_type operator[]( std::size_t i ) const; 45 | 46 | const native_type& native() const; 47 | 48 | int_v& operator&=( const int_v& a ); 49 | int_v& and_not( const int_v& a ); 50 | 51 | static int_v reinterpret( const float_v& a ); 52 | 53 | static int_v select( const int_v& a, const int_v& b, const int_v& mask ); 54 | 55 | private: 56 | native_type m_native; 57 | }; 58 | 59 | int_v operator&( const int_v& a, const int_v& b ); 60 | 61 | int_v operator+( const int_v& a, const int_v& b ); 62 | int_v operator-( const int_v& a, const int_v& b ); 63 | 64 | int_v operator<( const int_v& a, const int_v& b ); 65 | int_v operator>( const int_v& a, const int_v& b ); 66 | int_v operator<=( const int_v& a, const int_v& b ); 67 | int_v operator>=( const int_v& a, const int_v& b ); 68 | 69 | bool operator==( const int_v& a, const int_v& b ); 70 | 71 | template 72 | std::basic_ostream& operator<<( std::basic_ostream& out, const int_v& v ); 73 | 74 | } // namespace FRANTIC_SIMD_NAMESPACE 75 | 76 | using namespace FRANTIC_SIMD_NAMESPACE; 77 | 78 | } // namespace simd 79 | } // namespace frantic 80 | 81 | namespace std { 82 | 83 | frantic::simd::int_v max( const frantic::simd::int_v& a, const frantic::simd::int_v& b ); 84 | frantic::simd::int_v min( const frantic::simd::int_v& a, const frantic::simd::int_v& b ); 85 | 86 | } // namespace std 87 | 88 | #include 89 | -------------------------------------------------------------------------------- /frantic/simd/sse/floor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace frantic { 6 | namespace simd { 7 | namespace sse { 8 | 9 | /** 10 | * Round down to the nearest integer. 11 | * 12 | * Implementation based on: 13 | * 14 | * Stephanie Rancourt, "Pre SSE 4.1 floor/ceil/round functions (+modulo bonus)" 15 | * http://dss.stephanierct.com/DevBlog/?p=8 16 | * Licensed under Boost Software License 17 | */ 18 | inline __m128 floor( const __m128& a ) { 19 | // Keep the original value if it's too large to round 20 | __m128 aAbs = _mm_and_ps( a, _mm_castsi128_ps( _mm_set1_epi32( 0x7fffffff ) ) ); 21 | __m128 largeMask = _mm_set1_ps( 8388608.f ); 22 | __m128 mask = _mm_cmple_ps( aAbs, largeMask ); 23 | 24 | __m128 aRoundTrip = _mm_cvtepi32_ps( _mm_cvttps_epi32( a ) ); 25 | __m128 roundTripIncreased = _mm_cmpgt_ps( aRoundTrip, a ); 26 | __m128 correction = _mm_cvtepi32_ps( _mm_castps_si128( roundTripIncreased ) ); 27 | __m128 aFloor = _mm_add_ps( aRoundTrip, correction ); 28 | 29 | return _mm_or_ps( _mm_and_ps( mask, aFloor ), _mm_andnot_ps( mask, a ) ); 30 | } 31 | 32 | } // namespace sse 33 | } // namespace simd 34 | } // namespace frantic 35 | -------------------------------------------------------------------------------- /frantic/sstream/tsstream.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace frantic { 11 | namespace tsstream { 12 | #ifdef FRANTIC_USE_WCHAR 13 | typedef std::wostringstream tostringstream; 14 | #else 15 | typedef std::ostringstream tostringstream; 16 | #endif 17 | } // namespace tsstream 18 | 19 | using frantic::tsstream::tostringstream; 20 | } // namespace frantic -------------------------------------------------------------------------------- /frantic/strings/to_string_classic.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace strings { 9 | 10 | /** 11 | * boost::lexical_cast() uses the current C++ locale. 12 | * This is a problem for certain locales that cause integers >999 to 13 | * have commas inserted into them (eg 1000 -> 1,000). 14 | * We do not want to set the locale ourselves, since this is not thread safe. 15 | * This should be used as a safer alternative to boost::lexical_cast() 16 | * when converting integers to strings. 17 | */ 18 | template 19 | T to_string_classic( I input ) { 20 | std::basic_ostringstream ss; 21 | ss.imbue( std::locale::classic() ); 22 | ss << input; 23 | return ss.str(); 24 | } 25 | 26 | } // namespace strings 27 | } // namespace frantic 28 | -------------------------------------------------------------------------------- /frantic/strings/utf8.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | namespace frantic { 6 | namespace strings { 7 | 8 | bool is_valid_utf8( const char* sbegin, const char* send ); 9 | bool is_valid_utf8( const char* s ); 10 | bool is_valid_utf8( const std::string& s ); 11 | 12 | std::wstring wstring_from_utf8( const char* s ); 13 | std::wstring wstring_from_utf8( const std::string& s ); 14 | 15 | std::string to_utf8( const char* s ); 16 | std::string to_utf8( const std::string& s ); 17 | 18 | std::string to_utf8( const wchar_t* s ); 19 | std::string to_utf8( const std::wstring& s ); 20 | 21 | } // namespace strings 22 | } // namespace frantic 23 | -------------------------------------------------------------------------------- /frantic/threads/synchronizedqueue.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #ifndef SYNCHRONIZED_QUEUE_HPP 4 | #define SYNCHRONIZED_QUEUE_HPP 5 | 6 | #include 7 | 8 | // pronounced "deck" ! 9 | #include 10 | 11 | namespace frantic { 12 | namespace threads { 13 | 14 | template 15 | class SynchronizedQueue { 16 | // TODO: should there be a copy constructor/assignment operator? 17 | SynchronizedQueue( const SynchronizedQueue& ); 18 | SynchronizedQueue& operator=( const SynchronizedQueue& ); 19 | 20 | public: 21 | typedef Ttype value_type; 22 | SynchronizedQueue() {} 23 | ~SynchronizedQueue() {} 24 | 25 | // adds an item to the queue 26 | void enter( Ttype value ) { 27 | boost::mutex::scoped_lock lock( m_mutex ); 28 | m_queue.push_back( value ); 29 | } 30 | // removes an item from the queue. 31 | // returns false if the queue is empty. 32 | bool leave( Ttype& result ) { 33 | boost::mutex::scoped_lock lock( m_mutex ); 34 | 35 | if( m_queue.empty() ) 36 | return false; 37 | 38 | result = m_queue.front(); 39 | m_queue.pop_front(); 40 | 41 | return true; 42 | } 43 | 44 | std::size_t size() { 45 | boost::mutex::scoped_lock lock( m_mutex ); 46 | return m_queue.size(); 47 | } 48 | 49 | bool empty() { 50 | boost::mutex::scoped_lock lock( m_mutex ); 51 | return m_queue.empty(); 52 | } 53 | 54 | void clear() { 55 | boost::mutex::scoped_lock lock( m_mutex ); 56 | m_queue.clear(); 57 | } 58 | 59 | protected: 60 | boost::mutex m_mutex; 61 | std::deque m_queue; 62 | }; 63 | 64 | } // namespace threads 65 | } // namespace frantic 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /frantic/unix/process_handle.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | // UNIX 6 | 7 | typedef void* HANDLE; 8 | -------------------------------------------------------------------------------- /frantic/unix/process_priority.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | // UNIX 6 | 7 | enum PROCESS_PRIORITY { REALTIME = -20, HIGH = -10, ABOVE_NORMAL = -5, NORMAL = 0, BELOW_NORMAL = 10, LOW = 19 }; 8 | -------------------------------------------------------------------------------- /frantic/volumetrics/field_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace frantic { 9 | namespace volumetrics { 10 | 11 | class field_interface { 12 | public: 13 | virtual ~field_interface() {} 14 | 15 | /** 16 | * Evaluates the field at the specified location, storing the result in the supplied buffer. The buffer must adhere 17 | * to the layout described by the channel_map retrieved via get_channel_map(). 18 | * 19 | * @note This member function is const in order to suggest a thread-safe approach to its implementation. 20 | * 21 | * @param dest The results of evaluating the field at 'pos' will be stored in this buffer. 22 | * @param pos The location to evaluate the field at. This location is local to the field and has no global meaning. 23 | * @return Returns false if the field is undefined at the given location. 24 | */ 25 | virtual bool evaluate_field( void* dest, const frantic::graphics::vector3f& pos ) const = 0; 26 | 27 | /** 28 | * Returns the description of the data produced by each evaluation of the field. The pointer passed to 29 | * evaluate_field() must point to a memory region adhering to the layout described by this map. 30 | */ 31 | virtual const frantic::channels::channel_map& get_channel_map() const = 0; 32 | 33 | // TODO: We can support these consider extending the interface to support derivative calculations. I imagine we will 34 | // want to 35 | // support derivative calculation on a per-channel basis instead of the entire list of channels. 36 | 37 | /** 38 | * Declares whether the field can calculate a better derivative than the usual finite differences approach. This 39 | * means the implementations of evaluate_jacobian(), evaluate_gradient(), evaluate_divergence() & evaluate_curl() 40 | * are more meaningful than if calculated via finite differences at some small, reasonable offset. 41 | * @return True if explicit derivatives will be calculated. 42 | */ 43 | /*virtual bool supports_derivatives() const = 0; 44 | 45 | virtual bool evaluate_gradient( void* dest, const frantic::graphics::vector3f& pos, std::size_t channelNum = 0 ) 46 | const = 0; 47 | 48 | virtual bool evaluate_divergence( void* dest, const frantic::graphics::vector3f& pos, std::size_t channelNum = 0 ) 49 | const = 0; 50 | 51 | virtual bool evaluate_curl( void* dest, const frantic::graphics::vector3f& pos, std::size_t channelNum = 0 ) const = 52 | 0; 53 | 54 | virtual bool evaluate_jacobian( void* dest, const frantic::graphics::vector3f& pos, std::size_t channelNum = 0 ) 55 | const = 0;*/ 56 | }; 57 | 58 | } // namespace volumetrics 59 | } // namespace frantic 60 | -------------------------------------------------------------------------------- /frantic/volumetrics/hash_grid.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace frantic { 12 | namespace graphics { 13 | inline std::size_t hash_value( const frantic::graphics::vector3& vec ) { 14 | const std::size_t p1 = 73856093; 15 | const std::size_t p2 = 19349663; 16 | const std::size_t p3 = 83492791; 17 | 18 | return ( vec.x * p1 ) ^ ( vec.y * p2 ) ^ ( vec.z * p3 ); 19 | } 20 | } // namespace graphics 21 | } // namespace frantic 22 | 23 | namespace frantic { 24 | namespace volumetrics { 25 | 26 | class hash_grid { 27 | frantic::channels::channel_map m_channelMap; 28 | 29 | typedef frantic::graphics::vector3 voxel_coord; 30 | typedef boost::unordered_map hashtable_type; 31 | 32 | hashtable_type m_hashTable; 33 | 34 | public: 35 | hash_grid() {} 36 | 37 | hash_grid( const frantic::channels::channel_map& channels ); 38 | 39 | void reset( const frantic::channels::channel_map& channels ); 40 | 41 | const frantic::channels::channel_map& get_channel_map() const; 42 | 43 | char* get_or_make_voxel_ptr( const voxel_coord& vc ); 44 | 45 | void get_or_make_voxel_ptrs( const voxel_coord& vc, int filterWidth, char* outPtrs[] ); 46 | 47 | const char* get_voxel_ptr( const voxel_coord& vc ) const; 48 | 49 | void get_voxel_ptrs( const voxel_coord& vc, int filterWidth, const char* outPtrs[] ) const; 50 | }; 51 | } // namespace volumetrics 52 | } // namespace frantic 53 | -------------------------------------------------------------------------------- /frantic/volumetrics/levelset/rle_defined_iterator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace frantic { 9 | namespace volumetrics { 10 | namespace levelset { 11 | 12 | // Forward declaration of the rle_index_spec classes. 13 | class rle_index_spec; 14 | struct run_data; 15 | 16 | /** 17 | * This rle_index_spec iterator is designed to provide convenient iteration over all the defined 18 | * voxels in the rle_index_spec. 19 | */ 20 | class rle_defined_iterator { 21 | rle_scanline_defined_iteration_primitive m_rsip; 22 | const rle_index_spec* m_ris; 23 | frantic::graphics::vector3 m_coord; 24 | boost::int32_t m_dataIndex, m_b, m_c; 25 | 26 | public: 27 | /** 28 | * Constructor which creates an iterator starting at the beginning. 29 | * 30 | * @param ris The rle_index_spec for iteration. 31 | * @param pastTheEnd If false, creates an iterator at the start, otherwise creates an iterator past the end. 32 | */ 33 | rle_defined_iterator( const rle_index_spec& ris, bool pastTheEnd = false ); 34 | 35 | /** 36 | * Pre-increments the iterator. 37 | */ 38 | rle_defined_iterator& operator++(); 39 | 40 | /** 41 | * Post-increments the iterator. Void return value as allowed by input iterator concept. 42 | */ 43 | void operator++( int ); 44 | 45 | /** 46 | * For equality comparison, we don't check everything. But, the subset of what we 47 | * check is enough to determine equality. Note that we're checking the things most likely 48 | * to be different first, to be able to return false as quickly as possible in the common 49 | * cases. 50 | */ 51 | bool operator==( const rle_defined_iterator& iter ) const { return m_dataIndex == iter.m_dataIndex; } 52 | 53 | bool operator!=( const rle_defined_iterator& iter ) const { return !operator==( iter ); } 54 | 55 | /** 56 | * Returns the voxel coordinate of our current iterator. 57 | * Remember, this coordinate defines the bottom, left, front of the voxel (not center). 58 | */ 59 | const frantic::graphics::vector3& get_coord() const { return m_coord; } 60 | 61 | int get_bc_index() const; 62 | 63 | int get_data_index() const { return m_dataIndex; } 64 | }; 65 | 66 | } // namespace levelset 67 | } // namespace volumetrics 68 | } // namespace frantic 69 | -------------------------------------------------------------------------------- /frantic/volumetrics/volumetric_scattering_functions.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace frantic { 9 | namespace volumetrics { 10 | 11 | using frantic::graphics::color3f; 12 | using frantic::graphics::vector3f; 13 | 14 | inline float isotropic_scattering() { return 1 / ( 4.f * (float)M_PI ); } 15 | 16 | // Henyey-Greenstein phase function. 17 | // The incoming and outgoing vectors should be normalized. 18 | inline float phase_hg( const vector3f& w, const vector3f& wp, float g ) { 19 | float costheta = vector3f::dot( w, wp ); 20 | return 1.0f / ( 4.0f * (float)M_PI ) * ( 1.0f - g * g ) / powf( 1.0f + g * g - 2.0f * g * costheta, 1.5f ); 21 | } 22 | 23 | inline color3f phase_hg( const vector3f& w, const vector3f& wp, const color3f& g ) { 24 | return color3f( phase_hg( w, wp, g.r ), phase_hg( w, wp, g.g ), phase_hg( w, wp, g.b ) ); 25 | } 26 | 27 | // Schlick phase function (approximates Henyey-Greenstein) 28 | // The incoming and outgoing vectors should be normalized. 29 | inline float phase_schlick( const vector3f& w, const vector3f& wp, float g ) { 30 | float k = 1.55f * g - .55f * g * g * g; 31 | float kcostheta = k * vector3f::dot( w, wp ); 32 | return 1.0f / ( 4.0f * (float)M_PI ) * ( 1.0f - k * k ) / ( ( 1.0f - kcostheta ) * ( 1.0f - kcostheta ) ); 33 | } 34 | 35 | inline color3f phase_schlick( const vector3f& w, const vector3f& wp, const color3f& g ) { 36 | return color3f( phase_schlick( w, wp, g.r ), phase_schlick( w, wp, g.g ), phase_schlick( w, wp, g.b ) ); 37 | } 38 | 39 | } // namespace volumetrics 40 | } // namespace frantic 41 | -------------------------------------------------------------------------------- /frantic/volumetrics/voxel_grid_tree.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace frantic { 11 | namespace volumetrics { 12 | 13 | const int VGT_SL = 3; 14 | 15 | class voxel_grid_tree_leaf_data { 16 | boost::shared_array m_data; 17 | 18 | public: 19 | voxel_grid_tree_leaf_data() {} 20 | 21 | voxel_grid_tree_leaf_data( std::size_t dataSize ); 22 | 23 | void reset( std::size_t dataSize ); 24 | 25 | char* get_data(); 26 | 27 | const char* get_data() const; 28 | }; 29 | 30 | class voxel_grid_tree : public frantic::volumetrics::grid_tree_base { 31 | frantic::channels::channel_map m_channelMap; 32 | 33 | private: 34 | typedef frantic::volumetrics::grid_tree_base_node node_type; 35 | 36 | public: 37 | typedef frantic::graphics::vector3 voxel_coord; 38 | 39 | public: 40 | voxel_grid_tree() {} 41 | 42 | voxel_grid_tree( const frantic::channels::channel_map& channels ); 43 | 44 | void reset( const frantic::channels::channel_map& channels ); 45 | 46 | const frantic::channels::channel_map& get_channel_map() const; 47 | 48 | char* get_or_make_voxel_ptr( const voxel_coord& vc ); 49 | 50 | const char* get_voxel_ptr( const voxel_coord& vc ) const; 51 | }; 52 | 53 | } // namespace volumetrics 54 | } // namespace frantic -------------------------------------------------------------------------------- /frantic/volumetrics/voxel_sampler_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace frantic { 11 | namespace volumetrics { 12 | 13 | class voxel_sampler_interface { 14 | public: 15 | typedef boost::shared_ptr ptr_type; 16 | 17 | virtual void update_for_voxel( const frantic::graphics::vector3& voxel ) = 0; 18 | virtual bool get_next_position( frantic::graphics::vector3f& outPosition, float& outCompensationFactor ) = 0; 19 | }; 20 | 21 | typedef voxel_sampler_interface::ptr_type voxel_sampler_interface_ptr; 22 | 23 | } // namespace volumetrics 24 | } // namespace frantic 25 | -------------------------------------------------------------------------------- /src/files/compression_stream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // clang-format off 5 | #include "stdafx.h" 6 | // clang-format on 7 | 8 | #include 9 | 10 | #if defined( _MSC_VER ) 11 | #pragma warning( disable : 4244 4800 ) 12 | #endif 13 | 14 | using namespace std; 15 | -------------------------------------------------------------------------------- /src/files/scoped_file_cleanup.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace frantic { 12 | namespace files { 13 | 14 | scoped_file_cleanup::scoped_file_cleanup() {} 15 | 16 | scoped_file_cleanup::~scoped_file_cleanup() { cleanup_files(); } 17 | 18 | void scoped_file_cleanup::reset() { m_deletionPaths.clear(); } 19 | 20 | void scoped_file_cleanup::add( const frantic::tstring& filePath ) { add( boost::filesystem::path( filePath ) ); } 21 | 22 | void scoped_file_cleanup::add( const boost::filesystem::path& filePath ) { m_deletionPaths.push_back( filePath ); } 23 | 24 | void scoped_file_cleanup::cleanup_files() { 25 | for( size_t i = 0; i < m_deletionPaths.size(); ++i ) { 26 | if( boost::filesystem::exists( m_deletionPaths[i] ) ) { 27 | boost::filesystem::remove_all( m_deletionPaths[i] ); 28 | } 29 | } 30 | 31 | m_deletionPaths.clear(); 32 | } 33 | 34 | } // namespace files 35 | } // namespace frantic 36 | -------------------------------------------------------------------------------- /src/geometry/const_shared_polymesh3_builder.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace frantic { 12 | namespace geometry { 13 | 14 | const_shared_polymesh3_builder::const_shared_polymesh3_builder( polymesh3_channel_data& vertData, 15 | polymesh3_channel_faces& geomPolyIndices, 16 | polymesh3_channel_faces& geomPolyEndIndices ) { 17 | m_mesh = new polymesh3( vertData, geomPolyIndices, geomPolyEndIndices ); 18 | } 19 | 20 | void const_shared_polymesh3_builder::add_vertex_channel( const frantic::tstring& channel, 21 | polymesh3_channel_data& inVertexBuffer, 22 | polymesh3_channel_faces* pInFaceBuffer ) { 23 | m_mesh->add_vertex_channel( channel, inVertexBuffer, pInFaceBuffer ); 24 | } 25 | 26 | void const_shared_polymesh3_builder::add_face_channel( const frantic::tstring& channel, 27 | polymesh3_channel_data& inFaceBuffer ) { 28 | m_mesh->add_face_channel( channel, inFaceBuffer ); 29 | } 30 | 31 | const_polymesh3_ptr const_shared_polymesh3_builder::finalize() { return m_mesh; } 32 | 33 | } // namespace geometry 34 | } // namespace frantic 35 | -------------------------------------------------------------------------------- /src/geometry/mesh_conversion.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace frantic { 13 | namespace geometry { 14 | 15 | polymesh3_ptr trimesh3_to_polymesh3( const trimesh3& inMesh ) { 16 | // its simpler to just use the existing method 17 | std::unique_ptr reference( trimesh3_interface::create_instance( &inMesh ) ); 18 | return create_polymesh3( reference.get() ); 19 | } 20 | 21 | } // namespace geometry 22 | } // namespace frantic 23 | -------------------------------------------------------------------------------- /src/graphics/color_rgb3a_f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "frantic/graphics/color_rgb3a_f.hpp" 8 | 9 | using namespace std; 10 | using namespace frantic; 11 | using namespace channels; 12 | using namespace graphics; 13 | 14 | channel_map color_rgb3a_f::get_channel_map() { 15 | assert( sizeof( color_rgb3a_f ) == 4 * 6 ); 16 | 17 | channel_map channelMap; 18 | 19 | channelMap.define_channel( get_name(), 6, frantic::channels::data_type_float32 ); 20 | channelMap.end_channel_definition(); 21 | 22 | return channelMap; 23 | } 24 | 25 | void color_rgb3a_f::add_to_channel_map( channel_map* channelMap ) { 26 | assert( sizeof( color_rgb3a_f ) == 4 * 6 ); 27 | 28 | if( !channelMap->has_channel( get_name() ) ) 29 | channelMap->define_channel( get_name(), 6, frantic::channels::data_type_float32 ); 30 | } 31 | -------------------------------------------------------------------------------- /src/graphics/color_rgb_f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "frantic/graphics/color_rgb_f.hpp" 8 | 9 | using namespace std; 10 | using namespace frantic; 11 | using namespace channels; 12 | using namespace graphics; 13 | 14 | channel_map color_rgb_f::get_channel_map() { 15 | assert( sizeof( color_rgb_f ) == 4 * 3 ); 16 | 17 | channel_map channelMap; 18 | 19 | channelMap.define_channel( get_name(), 3, data_type_float32 ); 20 | channelMap.end_channel_definition(); 21 | 22 | return channelMap; 23 | } 24 | 25 | void color_rgb_f::add_to_channel_map( channel_map* channelMap ) { 26 | assert( sizeof( color_rgb_f ) == 4 * 3 ); 27 | 28 | if( !channelMap->has_channel( get_name() ) ) 29 | channelMap->define_channel( get_name(), 3, data_type_float32 ); 30 | } 31 | -------------------------------------------------------------------------------- /src/graphics/color_rgba_f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "frantic/graphics/color_rgba_f.hpp" 8 | 9 | using namespace std; 10 | using namespace frantic; 11 | using namespace channels; 12 | using namespace graphics; 13 | 14 | channel_map color_rgba_f::get_channel_map( frantic::tstring name ) { 15 | assert( sizeof( color_rgba_f ) == 4 * 4 ); 16 | 17 | channel_map channelMap; 18 | 19 | channelMap.define_channel( name, 4, frantic::channels::data_type_float32 ); 20 | channelMap.end_channel_definition(); 21 | 22 | return channelMap; 23 | } 24 | 25 | void color_rgba_f::add_to_channel_map( channel_map* channelMap, frantic::tstring name ) { 26 | assert( sizeof( color_rgba_f ) == 4 * 4 ); 27 | 28 | if( !channelMap->has_channel( name ) ) 29 | channelMap->define_channel( name, 4, frantic::channels::data_type_float32 ); 30 | } 31 | -------------------------------------------------------------------------------- /src/graphics/color_rgba_h.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include "frantic/graphics/color_rgba_h.hpp" 8 | 9 | using namespace std; 10 | using namespace frantic; 11 | using namespace channels; 12 | using namespace graphics; 13 | 14 | channel_map color_rgba_h::get_channel_map() { 15 | assert( sizeof( color_rgba_h ) == 2 * 4 ); 16 | 17 | channel_map channelMap; 18 | 19 | channelMap.define_channel( get_name(), 4, frantic::channels::data_type_float16 ); 20 | channelMap.end_channel_definition(); 21 | 22 | return channelMap; 23 | } 24 | 25 | void color_rgba_h::add_to_channel_map( channel_map* channelMap ) { 26 | assert( sizeof( color_rgba_h ) == 2 * 4 ); 27 | 28 | if( !channelMap->has_channel( get_name() ) ) 29 | channelMap->define_channel( get_name(), 4, frantic::channels::data_type_float16 ); 30 | } 31 | -------------------------------------------------------------------------------- /src/hashing/hashing.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | namespace frantic { 10 | namespace hashing { 11 | 12 | namespace { 13 | 14 | char get_hex_char_from_nybble( unsigned char nybble ) { 15 | assert( nybble < 16 ); 16 | const char lut[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 17 | return lut[nybble]; 18 | } 19 | 20 | } // anonymous namespace 21 | 22 | std::string hash_to_string( unsigned char* in, std::size_t inSize ) { 23 | std::string result; 24 | result.resize( 2 * inSize ); 25 | 26 | for( std::size_t i = 0; i < inSize; i++ ) { 27 | const unsigned char c = in[i]; 28 | result[2 * i] = get_hex_char_from_nybble( c >> 4 ); 29 | result[2 * i + 1] = get_hex_char_from_nybble( c & 0x0F ); 30 | } 31 | 32 | return result; 33 | } 34 | 35 | } // namespace hashing 36 | } // namespace frantic 37 | -------------------------------------------------------------------------------- /src/math/hash.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // clang-format off 5 | #include "stdafx.h" 6 | // clang-format on 7 | 8 | #include 9 | 10 | #if defined( _MSC_VER ) 11 | #pragma warning( disable : 4244 4800 4127 4101 4245 ) 12 | #endif 13 | 14 | using namespace std; 15 | using namespace boost; 16 | 17 | // Include Bob Jenkins' hash function 18 | extern "C" { 19 | #include 20 | } 21 | -------------------------------------------------------------------------------- /src/particles/particle_utilities.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace frantic { 13 | namespace particles { 14 | 15 | bool is_csv_particle_file( const frantic::tstring& filename ) { 16 | 17 | particle_file_stream_factory_object factory; 18 | 19 | bool found = false; 20 | 21 | frantic::tstring ext = frantic::files::extension_from_path( filename ); 22 | boost::to_lower( ext ); 23 | 24 | // Method 1: check the extension (presumably this could be extended to other known csv format extensions) 25 | found = ( ext == _T(".csv") ); 26 | 27 | if( !found ) { 28 | 29 | try { 30 | // Method 2: check if the stream returned is a csv_particle_istream 31 | particle_istream_ptr p = factory.create_istream( filename ); 32 | found = dynamic_cast( p.get() ) != NULL; 33 | } catch( std::runtime_error& ) { 34 | found = false; 35 | } 36 | } 37 | 38 | return found; 39 | } 40 | 41 | bool is_binary_particle_file( const frantic::tstring& filename ) { 42 | frantic::tstring ext = frantic::files::extension_from_path( filename ); 43 | boost::to_lower( ext ); 44 | 45 | bool isBinary = ext == _T( ".prt" ) || ext == _T( ".sprt" ) || 46 | #if defined( E57_AVAILABLE ) 47 | ext == _T( ".e57" ) || 48 | #endif 49 | ext == _T( ".las" ) || ext == _T( ".ptg" ) || ext == _T( ".bin" ) || ext == _T( ".rpc" ); 50 | 51 | return isBinary; 52 | } 53 | 54 | } // namespace particles 55 | } // namespace frantic 56 | -------------------------------------------------------------------------------- /src/particles/streams/concatenated_particle_istream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | namespace frantic { 10 | namespace particles { 11 | namespace streams { 12 | 13 | concatenated_particle_istream::concatenated_particle_istream( 14 | const std::vector>& pins ) { 15 | // Using a member initializer list here seems to induce a crash on GCC 5.2.1 on Ubuntu 15.10 under -O2 16 | m_delegates = pins; 17 | if( m_delegates.empty() ) 18 | throw std::runtime_error( 19 | "concatenated_particle_istream() - The provided particle_istream array was empty. It " 20 | "should contain at least one stream." ); 21 | 22 | init_streams(); 23 | } 24 | } // namespace streams 25 | } // namespace particles 26 | } // namespace frantic 27 | -------------------------------------------------------------------------------- /src/particles/streams/e57_particle_mutex.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | #include 9 | 10 | boost::mutex frantic::particles::streams::g_e57ImageFileConstructorMutex; 11 | -------------------------------------------------------------------------------- /src/volumetrics/levelset/rle_run_iterator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | using namespace boost; 12 | 13 | namespace frantic { 14 | namespace volumetrics { 15 | namespace levelset { 16 | 17 | rle_run_iterator::rle_run_iterator( const rle_index_spec& ris, int b, int c ) { 18 | m_exteriorRegionCode = ris.get_exterior_region_code(); 19 | 20 | if( (unsigned)b < (unsigned)ris.m_abcCoordSize.ysize() && (unsigned)c < (unsigned)ris.m_abcCoordSize.zsize() ) { 21 | int bcIndex = b + c * ris.m_abcCoordSize.ysize(); 22 | int32_t runIndexStart = ris.m_bcToRunIndex[bcIndex]; 23 | const run_data* rd = &ris.m_runData[runIndexStart]; 24 | m_xStart = rd->x; 25 | m_xSize = ( rd + 1 )->x - m_xStart; 26 | if( m_xSize != 0 ) { 27 | m_dataIndex = rd->dataIndex; 28 | m_rd = rd; 29 | m_rdEnd = rd + ( ris.m_bcToRunIndex[bcIndex + 1] - 1 - runIndexStart ); 30 | // In this case, there is a non-empty run, so we're good to go 31 | return; 32 | } 33 | } 34 | 35 | // If we didn't initialize the data and return above, initialize to past-the-end. 36 | m_xStart = 0; 37 | m_xSize = 0; 38 | m_dataIndex = m_exteriorRegionCode; 39 | m_rd = 0; 40 | m_rdEnd = 0; 41 | } 42 | 43 | rle_run_iterator::rle_run_iterator() { 44 | // the exterior region code doesnt really matter for the end iterator 45 | m_exteriorRegionCode = -1; 46 | 47 | // Initialize to past-the-end. 48 | m_xStart = 0; 49 | m_xSize = 0; 50 | m_dataIndex = m_exteriorRegionCode; 51 | m_rd = 0; 52 | m_rdEnd = 0; 53 | } 54 | 55 | rle_run_iterator& rle_run_iterator::operator++() { 56 | if( m_rd != 0 ) { // if we are past the end, don't move anything 57 | if( ++m_rd != m_rdEnd ) { 58 | m_xStart = m_rd->x; 59 | m_xSize = ( m_rd + 1 )->x - m_xStart; 60 | m_dataIndex = m_rd->dataIndex; 61 | } else { 62 | // get_xmin() gives the one-past-the-end X value after iteration is complete 63 | m_xStart = m_rd->x; 64 | m_xSize = 0; 65 | m_dataIndex = m_exteriorRegionCode; 66 | m_rd = 0; 67 | m_rdEnd = 0; 68 | } 69 | } 70 | return *this; 71 | } 72 | 73 | } // namespace levelset 74 | } // namespace volumetrics 75 | } // namespace frantic 76 | -------------------------------------------------------------------------------- /src/volumetrics/voxel_grid_tree.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // clang-format off 4 | #include "stdafx.h" 5 | // clang-format on 6 | 7 | #include 8 | 9 | using namespace frantic::volumetrics; 10 | 11 | voxel_grid_tree_leaf_data::voxel_grid_tree_leaf_data( std::size_t dataSize ) { 12 | m_data.reset( new char[dataSize] ); 13 | memset( m_data.get(), 0, dataSize ); 14 | } 15 | 16 | void voxel_grid_tree_leaf_data::reset( std::size_t dataSize ) { 17 | m_data.reset( new char[dataSize] ); 18 | memset( m_data.get(), 0, dataSize ); 19 | } 20 | 21 | char* voxel_grid_tree_leaf_data::get_data() { return m_data.get(); } 22 | 23 | const char* voxel_grid_tree_leaf_data::get_data() const { return m_data.get(); } 24 | 25 | voxel_grid_tree::voxel_grid_tree( const frantic::channels::channel_map& channels ) { m_channelMap = channels; } 26 | 27 | void voxel_grid_tree::reset( const frantic::channels::channel_map& channels ) { 28 | clear(); 29 | m_channelMap = channels; 30 | } 31 | 32 | const frantic::channels::channel_map& voxel_grid_tree::get_channel_map() const { return m_channelMap; } 33 | 34 | char* voxel_grid_tree::get_or_make_voxel_ptr( const voxel_coord& vc ) { 35 | const int LEAFSIZE = 5; 36 | 37 | voxel_coord quotient = frantic::graphics::size3( LEAFSIZE ).get_quotient_coord( vc ); 38 | voxel_coord kernel = 39 | voxel_coord( vc.x - LEAFSIZE * quotient.x, vc.y - LEAFSIZE * quotient.y, vc.z - LEAFSIZE * quotient.z ); 40 | 41 | node_type* node = navigate_to_leaf_with_create( quotient ); 42 | if( node->leafData == NULL ) 43 | node->leafData = 44 | new voxel_grid_tree_leaf_data( ( LEAFSIZE * LEAFSIZE * LEAFSIZE ) * m_channelMap.structure_size() ); 45 | 46 | return node->leafData->get_data() + 47 | ( kernel.x + LEAFSIZE * ( kernel.y + LEAFSIZE * kernel.z ) ) * m_channelMap.structure_size(); 48 | } 49 | 50 | const char* voxel_grid_tree::get_voxel_ptr( const voxel_coord& vc ) const { 51 | const int LEAFSIZE = 5; 52 | 53 | voxel_coord quotient = frantic::graphics::size3( LEAFSIZE ).get_quotient_coord( vc ); 54 | voxel_coord kernel = 55 | voxel_coord( vc.x - LEAFSIZE * quotient.x, vc.y - LEAFSIZE * quotient.y, vc.z - LEAFSIZE * quotient.z ); 56 | 57 | node_type* node = navigate_to_leaf( quotient ); 58 | if( !node || node->leafData == NULL ) 59 | return NULL; 60 | 61 | return node->leafData->get_data() + 62 | ( kernel.x + LEAFSIZE * ( kernel.y + LEAFSIZE * kernel.z ) ) * m_channelMap.structure_size(); 63 | } 64 | -------------------------------------------------------------------------------- /stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.cpp : source file that includes just the standard includes 4 | // FranticLibrary.pch will be the pre-compiled header 5 | // stdafx.obj will contain the pre-compiled type information 6 | 7 | #include "stdafx.h" 8 | 9 | // reference any additional headers you need in STDAFX.H 10 | // and not in this file 11 | -------------------------------------------------------------------------------- /stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.h : include file for standard system include files, 4 | // or project specific include files that are used frequently, but 5 | // are changed infrequently 6 | // 7 | 8 | #if defined( _MSC_VER ) 9 | // Disables deprecated function warnings 10 | #pragma warning( disable : 4996 ) 11 | 12 | // Disables unreachable code warnings 13 | #pragma warning( disable : 4702 ) 14 | #endif 15 | 16 | #if defined( _WIN32 ) || defined( _WIN64 ) 17 | #ifndef _WIN32_WINNT 18 | #define _WIN32_WINNT 0x0501 19 | #endif 20 | #ifndef WIN32_LEAN_AND_MEAN 21 | #define WIN32_LEAN_AND_MEAN 22 | #endif 23 | 24 | #ifndef NOMINMAX 25 | #define NOMINMAX 26 | #endif 27 | #include 28 | #include 29 | #endif 30 | 31 | // All the standard C++ headers we need 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #if defined( __GNUC__ ) && __GNUC__ < 3 45 | #include 46 | #else 47 | #include 48 | #endif 49 | //#include 50 | 51 | // Because 3ds max irresponsibly defines lower-case preprocessor macros, 52 | // we need to do this here instead of elsewhere. 53 | #include 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | #include 60 | 61 | // Eigen SIMD is ICEing on MSVC 2008 62 | #if defined( _MSC_VER ) && _MSC_VER < 1600 63 | #define EIGEN_DONT_VECTORIZE 64 | #endif 65 | 66 | // Avoid error C2719 (parameter with __declspec(align('16')) won't be aligned) 67 | // when building src/geometry/quadtree.cpp 68 | #if defined( _MSC_VER ) && _MSC_VER < 1700 && defined( _M_IX86 ) 69 | #define EIGEN_DONT_ALIGN 70 | #endif 71 | 72 | #include 73 | --------------------------------------------------------------------------------