/** * Create the augmented knots vector and fill in matrix Xt with the spline basis vectors */ void basis_splines_endreps_local_v2(float *knots, int n_knots, int order, int *boundaries, int n_boundaries, Eigen::MatrixXf &Xt) { assert(n_boundaries == 2 && boundaries[0] < boundaries[1]); int n_rows = boundaries[1] - boundaries[0]; // this is frames so evaluate at each frame we'll need int n_cols = n_knots + order; // number of basis vectors we'll have at end Xt.resize(n_cols, n_rows); // swapped to transpose later. This order lets us use it as a scratch space Xt.fill(0); int n_std_knots = n_knots + 2 * order; float std_knots[n_std_knots]; // Repeat the boundary knots on there to ensure linear out side of knots for (int i = 0; i < order; i++) { std_knots[i] = boundaries[0]; } // Our original boundary knots here for (int i = 0; i < n_knots; i++) { std_knots[i+order] = knots[i]; } // Repeat the boundary knots on there to ensure linear out side of knots for (int i = 0; i < order; i++) { std_knots[i+order+n_knots] = boundaries[1]; } // Evaluate our basis splines at each frame. for (int i = boundaries[0]; i < boundaries[1]; i++) { int idx = -1; // find index such that i >= knots[idx] && i < knots[idx+1] float *val = std::upper_bound(std_knots, std_knots + n_std_knots - 1, 1.0f * i); idx = val - std_knots - 1; assert(idx >= 0); float *f = Xt.data() + i * n_cols + idx - (order - 1); //column offset basis_spline_xi_v2(std_knots, n_std_knots, order, idx, i, f); } // Put in our conventional format where each column is a basis vector Xt.transposeInPlace(); }
void readLDRFile(const std::string& file, Eigen::MatrixXf& data) { std::ifstream in(file.c_str(), std::ios::in | std::ios::binary); in.seekg(0, std::ios::end); int size = in.tellg(); in.seekg(0, std::ios::beg); int num_floats = size / (sizeof(float) / sizeof (char)); int num_rows = num_floats / 6; data.resize(6, num_rows); float* row_arr = new float[num_floats]; in.read((char*)(row_arr), size); float* data_arr = data.data(); for (int k = 0; k < num_floats; k++) data_arr[k] = row_arr[k]; data.transposeInPlace(); in.close(); }