示例#1
0
void subdivide_collection(Strand_collection *children, Strand_collection *parents,
                          double strand_r_final) {
    
    int parent_i;
    int ubound_num_children1, ubound_num_control_points, ubound_num_cols, ubound_num_rows,
            ubound_new_children;
    
    ubound_num_children1 = 0;    //An upper bound on the number of children that could be generated
    ubound_num_control_points = 0;    //An upper bound on the total number of points that could be generated for these children.
            
    for (parent_i = 0; parent_i < parents->num_strands; parent_i++) {
        
        ubound_num_cols = 2 * floor(parents->strands[parent_i].radius / strand_r_final) + 1;
        ubound_num_rows = floor(
                                  2.0 * parents->strands[parent_i].radius / (sqrt(3)
                                          * strand_r_final))
                          + 1;
        
        ubound_new_children = ubound_num_rows * ubound_num_cols;
        
        ubound_num_children1 += ubound_new_children;
        
        /* add 10 (should only need to add 1) just to be sure and allow leeway for future modifications of the subdivide_strand function */
        ubound_num_control_points += ubound_new_children
                * (parents->strands[parent_i].num_control_points + 10);
        
    }
    
    collection_alloc(children, ubound_num_children1, ubound_num_control_points,
            parents->num_isotropic_regions);
    copy_isotropic_regions(children, parents->isotropic_regions, parents->num_isotropic_regions);
    
    children->num_strands = 0;
    children->num_control_points = 0;
    
    for (parent_i = 0; parent_i < parents->num_strands; parent_i++) {
        
        subdivide_strand(&(parents->strands[parent_i]), children, strand_r_final);
        
    }
    
    //TODO:need to check whether these values actually have been allocated before reallocated, otherwise it throws an error.
    children->strand_r = (double*) realloc(children->strand_r,
            sizeof(double) * children->num_strands);
    children->num_strand_control_points = (int*) realloc(children->num_strand_control_points,
            sizeof(int) * children->num_strands);
    children->control_points = (double*) realloc(children->control_points,
            sizeof(double) * 3 * children->num_control_points);
    children->control_points_grad = (double*) realloc(children->control_points_grad,
            sizeof(double) * children->num_control_points);
    children->start_points = (double*) realloc(children->start_points,
            sizeof(double) * 3 * children->num_strands);
    children->end_points = (double*) realloc(children->end_points,
            sizeof(double) * 3 * children->num_strands);
    children->pre_points = (double*) realloc(children->pre_points,
            sizeof(double) * 3 * children->num_strands);
    children->post_points = (double*) realloc(children->post_points,
            sizeof(double) * 3 * children->num_strands);
    children->strands = (Strand*) realloc(children->strands,
            sizeof(Strand) * children->num_strands);
    children->segments = (Segment*) realloc(children->segments,
            sizeof(Segment) * (children->num_control_points + 3 * children->num_strands));
    
}
示例#2
0
Strand_collection* convert_mr_to_nfg(Strand_collection* c, FTS::Fibre::Track::Set& tracks,
                                     std::vector<FTS::Triple<double> >& pre_points,
                                     std::vector<FTS::Triple<double> >& post_points) {
    
    if (tracks.size() == 0)
        throw FTS::Exception(
                "Track set supplied to FTSTrix to NFG conversion function does not have any tracks in it.");
    
    if (!tracks.has_extend_elem_prop(FTS::Fibre::Track::RADIUS_PROP))
        tracks.add_extend_elem_prop(FTS::Fibre::Track::RADIUS_PROP, "0.03");
    
    size_t total_num_control_points = 0;
    
    for (size_t tck_i = 0; tck_i < tracks.size(); ++tck_i)
        total_num_control_points += tracks[tck_i].size() - 2;
    
    collection_alloc(c, tracks.size(), total_num_control_points, 0);
    
    size_t control_point_count = 0;
    
    for (size_t strand_i = 0; strand_i < tracks.size(); strand_i++) {
        
        FTS::Fibre::Track tck = tracks[strand_i];
        
        c->num_strand_control_points[strand_i] = tck.size() - 2;    //Start and end points are not included.
                
        c->strand_r[strand_i] = atof(
                tracks.get_extend_elem_prop(FTS::Fibre::Track::RADIUS_PROP, strand_i).c_str());
        
        size_t bundle_i;
        if (tracks.has_extend_elem_prop(FTS::Fibre::Track::BUNDLE_INDEX_EPROP))
            bundle_i =
                    atoi(
                            tracks.get_extend_elem_prop(FTS::Fibre::Track::BUNDLE_INDEX_EPROP,
                                    strand_i).c_str());
        else
            bundle_i = strand_i;
        
        c->bundle_i_of_strand[strand_i] = bundle_i;
        
        pre_points[strand_i].copy_to(&(c->pre_points[strand_i * 3]));
        post_points[strand_i].copy_to(&(c->post_points[strand_i * 3]));
        
        tck[0].copy_to(&(c->start_points[strand_i * 3]));
        
        size_t point_i;
        
        for (point_i = 1; point_i < (tck.size() - 1); point_i++)
            tck[point_i].copy_to(&(c->control_points[(control_point_count + point_i - 1) * 3]));
        
        tck[point_i].copy_to(&(c->end_points[strand_i * 3]));
        
        construct_strand(&(c->strands[strand_i]), strand_i, bundle_i,
                &(c->control_points[control_point_count * 3]), &(c->start_points[strand_i * 3]),
                &(c->end_points[strand_i * 3]), &(c->pre_points[strand_i * 3]),
                &(c->post_points[strand_i * 3]), &(c->segments[control_point_count + 3 * strand_i]),
                c->num_strand_control_points[strand_i], 0.0, c->strand_r[strand_i]);
        
        control_point_count += c->num_strand_control_points[strand_i];
        
    }
    
    c->num_bundles = construct_bundles(c->bundles, c->bundle_i_of_strand, c->num_strands,
            c->strands);
    
    return c;
}