void triangulate_visitor::copy_face( mesh_model_t& model, const shape_t& shape, std::size_t index, boost::uint32_t face_start_index, mesh_model_t& new_model, shape_t& new_shape) { arrays::const_array_ref_t<boost::uint32_t> verts_per_face( model.const_verts_per_face_array()); arrays::const_array_ref_t<boost::uint32_t> face_vert_indices( model.const_face_vert_indices_array()); arrays::array_ref_t<boost::uint32_t> new_verts_per_face( new_model.verts_per_face_array()); arrays::array_ref_t<boost::uint32_t> new_face_vert_indices( new_model.face_vert_indices_array()); int num_verts = verts_per_face[index]; new_verts_per_face.push_back( num_verts); for( int i = 0; i < num_verts; ++i) { int vertex_num = face_vert_indices[face_start_index +i]; new_face_vert_indices.push_back( vertex_num); new_shape.attributes().vertex().push_back_attribute_values_copy( shape.attributes().vertex(), vertex_num); } // copy face attributes new_shape.attributes().primitive().push_back_attribute_values_copy( shape.attributes().primitive(), index); }
virtual void visit( visitable_t& model, shape_t& shape) { detail::transform_dictionary( shape.attributes().constant() , xform_); detail::transform_attribute_table( shape.attributes().primitive(), xform_); detail::transform_attribute_table( shape.attributes().vertex() , xform_); detail::transform_attribute_table( shape.attributes().point() , xform_); }
void compute_face_normals_visitor::do_visit( mesh_model_t& model, shape_t& shape) { if( !shape.attributes().point().has_attribute( g_P_name)) throw core::runtime_error( core::string8_t( "No P attribute found in compute face normals visitor")); // create the N array, if it does not exist. if( shape.attributes().primitive().has_attribute( g_N_name)) { arrays::array_t N( core::normalf_k); N.reserve( model.num_faces()); shape.attributes().primitive().insert( g_N_name, N); } arrays::const_array_ref_t<math::point3f_t> points( shape.attributes().point().const_array( g_P_name)); arrays::const_array_ref_t<boost::uint32_t> verts_per_face( model.const_verts_per_face_array()); arrays::const_array_ref_t<boost::uint32_t> face_vert_indices( model.const_face_vert_indices_array()); arrays::array_ref_t<math::normalf_t> normals( shape.attributes().primitive().array( g_N_name)); boost::uint32_t face_start_index = 0; for( int i = 0, e = model.num_faces(); i < e; ++i) { boost::uint32_t num_verts = verts_per_face[i]; boost::optional<math::normalf_t> n = newell_polygon_normal( boost::make_permutation_iterator( points.begin(), face_vert_indices.begin() + face_start_index), boost::make_permutation_iterator( points.begin(), face_vert_indices.begin() + face_start_index + num_verts)); if( n) normals[i] = n.get(); face_start_index += num_verts; } }
static void get_shape(object obj, shape_t& shape) { shape.clear(); object py_shape = obj.attr("shape"); const std::size_t N = len( py_shape ); for( std::size_t i = 0; N != i; ++i ) shape.push_back( extract<std::size_t >(py_shape[i])); }
BOOST_FOREACH( shape_t& s, shapes()) { if( !s.parent()) { if( motion_blur_only && !s.motion_blur()) continue; s.update_xforms( motion_blur_only); } }
void scene_renderer_t::convert_to_path( const shape_t& s, agg::path_storage& path, const Imath::V2i& offset, int subsample) const { path.remove_all(); Imath::V2f p0, p1, p2; Imath::V2f shape_offset = s.offset(); Imath::M33f m( s.global_xform()); p0 = transform_point( s.triples()[0].p1(), shape_offset, m, subsample, offset); path.move_to( p0.x, p0.y); for( int i = 0; i < s.triples().size() - 1; ++i) { p2 = transform_point( s.triples()[i].p2(), shape_offset, m, subsample, offset); p0 = transform_point( s.triples()[i+1].p0(), shape_offset, m, subsample, offset); p1 = transform_point( s.triples()[i+1].p1(), shape_offset, m, subsample, offset); path.curve4( p2.x, p2.y, p0.x, p0.y, p1.x, p1.y); } // last segment p2 = transform_point( s.triples()[s.triples().size()-1].p2(), shape_offset, m, subsample, offset); p0 = transform_point( s.triples()[0].p0(), shape_offset, m, subsample, offset); p1 = transform_point( s.triples()[0].p1(), shape_offset, m, subsample, offset); path.curve4( p2.x, p2.y, p0.x, p0.y, p1.x, p1.y); path.close_polygon(); }
void triangulate_visitor::visit( subd_mesh_model_t& model, shape_t& shape) { if( !shape.attributes().point().has_attribute( g_P_name)) throw core::runtime_error( core::string8_t( "No P attribute found in triangulate visitor")); shape_t new_shape( shape_t::create_subd_mesh()); subd_mesh_model_t& new_model( shape_cast<subd_mesh_model_t>( new_shape)); do_visit( model, shape, new_model, new_shape); }
void triangulate_visitor::do_visit( mesh_model_t& model, shape_t& shape, mesh_model_t& new_model, shape_t& new_shape) { // copy attributes new_shape.attributes().point() = shape.attributes().point(); new_shape.attributes().constant() = shape.attributes().constant(); new_shape.attributes().vertex() = attribute_table_t::create_empty_with_same_attributes( shape.attributes().vertex()); new_shape.attributes().primitive() = attribute_table_t::create_empty_with_same_attributes( shape.attributes().primitive()); arrays::const_array_ref_t<math::point3f_t> points( shape.attributes().point().const_array( g_P_name)); arrays::const_array_ref_t<boost::uint32_t> verts_per_face( model.const_verts_per_face_array()); arrays::const_array_ref_t<boost::uint32_t> face_vert_indices( model.const_face_vert_indices_array()); boost::uint32_t face_start_index = 0; for( int i = 0, e = model.num_faces(); i < e; ++i) { boost::uint32_t num_verts = verts_per_face[i]; if( num_verts == 3) copy_face( model, shape, i, face_start_index, new_model, new_shape); else { if( num_verts == 4) { if( keep_quads_) copy_face( model, shape, i, face_start_index, new_model, new_shape); else triangulate_quad( model, shape, i, face_start_index, new_model, new_shape); } else { // TODO: triangulate polygon here throw core::not_implemented(); } } face_start_index += num_verts; } shape.swap( new_shape); throw core::not_implemented(); }
void scene_renderer_t::render_and_filter_shape( const shape_t& s, int bbox_index) { RAMEN_ASSERT( bbox_index >= 0 && bbox_index <= filtered_bboxes_.size()); boost::gil::fill_pixels( boost::gil::view( buf_), image::gray_pixel_t( 0)); boost::gil::fill_pixels( boost::gil::view( tmp_), image::gray_pixel_t( 0)); ren_base_type ren_base; agg::scanline_u8 sl; agg::rasterizer_scanline_aa<> ras; renderer_type ren; ren_base.set_view( boost::gil::view( buf_)); ren.attach( ren_base); ras.gamma( agg::gamma_none()); convert_to_path( s, path_, filtered_bboxes_[bbox_index].min, subsample_); agg::conv_curve<agg::path_storage> cpath( path_); ras.add_path( cpath); ras.filling_rule( agg::fill_non_zero); ren.color( color_type( 1.0f, 1.0f)); agg::render_scanlines( ras, sl, ren); image::gray_image_view_t buf_view( boost::gil::view( buf_)); float g = s.grow(); if( g != 0.0f) { /* image::gray_image_view_t subbuf_view( boost::gil::subimage_view( buf_view, bboxes_[bbox_index].min.x - filtered_bboxes_[bbox_index].min.x, bboxes_[bbox_index].min.y - filtered_bboxes_[bbox_index].min.y, bboxes_[bbox_index].size().x + 1, bboxes_[bbox_index].size().y + 1)); image::dilate( subbuf_view, boost::gil::view( tmp_), subbuf_view, g / aspect_ / subsample_, g / subsample_); */ boost::gil::fill_pixels( boost::gil::view( tmp_), image::gray_pixel_t( 0)); image::dilate( buf_view, boost::gil::view( tmp_), buf_view, g / aspect_ / subsample_, g / subsample_); } Imath::V2f blur = s.blur(); if( blur.x != 0.0f || blur.y != 0.0f) { boost::gil::fill_pixels( boost::gil::view( tmp_), image::gray_pixel_t( 0)); image::box_blur_gray( buf_view, boost::gil::view( tmp_), buf_view, blur.x / aspect_ / subsample_, blur.y / subsample_, 1); } Imath::Box2i common_area = ImathExt::intersect( area_, filtered_bboxes_[bbox_index]); if( !common_area.isEmpty()) { image::gray_image_view_t bg_view( boost::gil::subimage_view( boost::gil::view( pixels_), common_area.min.x - area_.min.x, common_area.min.y - area_.min.y, common_area.size().x, common_area.size().y)); boost::gil::tbb_transform2_pixels( boost::gil::subimage_view( buf_view, common_area.min.x - filtered_bboxes_[bbox_index].min.x, common_area.min.y - filtered_bboxes_[bbox_index].min.y, common_area.size().x, common_area.size().y), bg_view, bg_view, composite_layer( s.color(), s.opacity())); } }
void const_shape_visitor::visit( const visitable_t& model, const shape_t& shape) { throw bad_shape_type( shape.type()); }
void shape_visitor::visit( visitable_t& model, shape_t& shape) { throw bad_shape_type( shape.type()); }
void triangulate_visitor::triangulate_quad( mesh_model_t& model, const shape_t& shape, std::size_t index, boost::uint32_t face_start_index, mesh_model_t& new_model, shape_t& new_shape) { arrays::const_array_ref_t<boost::uint32_t> verts_per_face( model.const_verts_per_face_array()); arrays::const_array_ref_t<boost::uint32_t> face_vert_indices( model.const_face_vert_indices_array()); arrays::array_ref_t<boost::uint32_t> new_verts_per_face( new_model.verts_per_face_array()); arrays::array_ref_t<boost::uint32_t> new_face_vert_indices( new_model.face_vert_indices_array()); assert( verts_per_face[index] == 4); // First triangle new_verts_per_face.push_back( 3); new_face_vert_indices.push_back( face_vert_indices[face_start_index]); new_shape.attributes().vertex().push_back_attribute_values_copy( shape.attributes().vertex(), face_start_index); new_face_vert_indices.push_back( face_vert_indices[face_start_index + 1]); new_shape.attributes().vertex().push_back_attribute_values_copy( shape.attributes().vertex(), face_start_index + 1); new_face_vert_indices.push_back( face_vert_indices[face_start_index + 3]); new_shape.attributes().vertex().push_back_attribute_values_copy( shape.attributes().vertex(), face_start_index + 3); new_shape.attributes().primitive().push_back_attribute_values_copy( shape.attributes().primitive(), index); // Second triangle new_verts_per_face.push_back( 3); new_face_vert_indices.push_back( face_vert_indices[face_start_index + 1]); new_shape.attributes().vertex().push_back_attribute_values_copy( shape.attributes().vertex(), face_start_index + 1); new_face_vert_indices.push_back( face_vert_indices[face_start_index + 2]); new_shape.attributes().vertex().push_back_attribute_values_copy( shape.attributes().vertex(), face_start_index + 2); new_face_vert_indices.push_back( face_vert_indices[face_start_index + 3]); new_shape.attributes().vertex().push_back_attribute_values_copy( shape.attributes().vertex(), face_start_index + 3); new_shape.attributes().primitive().push_back_attribute_values_copy( shape.attributes().primitive(), index); }