本文整理汇总了C++中MatrixFr::row方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixFr::row方法的具体用法?C++ MatrixFr::row怎么用?C++ MatrixFr::row使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixFr
的用法示例。
在下文中一共展示了MatrixFr::row方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply_correction_to_in_plane_edge
void GeometryCorrectionTable::apply_correction_to_in_plane_edge(
const Vector3F& edge_dir, MatrixFr& loop) {
VectorF bbox_min = loop.colwise().minCoeff();
VectorF bbox_max = loop.colwise().maxCoeff();
VectorF bbox_center = 0.5 * (bbox_min + bbox_max);
size_t num_vts = loop.rows();
size_t dim = loop.cols();
assert(dim == 3);
MatrixFr proj_loop(num_vts, dim);
for (size_t i=0; i<num_vts; i++) {
const VectorF& v = loop.row(i) - bbox_center.transpose();
proj_loop.row(i) = Vector3F(v[0], v[1], 0.0);
}
Float target_half_height = 1e3; // Something huge to represent inf
Float target_half_width = proj_loop.row(0).norm();
Vector2F correction_1 = lookup(target_half_width, target_half_height);
Vector2F correction_2 = lookup(target_half_height, target_half_width);
Float half_width = 0.5 * (correction_1[0] + correction_2[1])
+ 0.05 * num_offset_pixel;
half_width = std::max(half_width, min_thickness);
for (size_t i=0; i<num_vts; i++) {
loop.row(i) += proj_loop.row(i) *
(-target_half_width + half_width) / target_half_width;
}
}
示例2: apply_z_correction
void GeometryCorrectionTable::apply_z_correction(
const Vector3F& edge_dir, MatrixFr& loop) {
//const Float max_z_error = 0.125;
//const Float max_z_error = 0.09;
const Float max_z_error = 0.00;
VectorF bbox_min = loop.colwise().minCoeff();
VectorF bbox_max = loop.colwise().maxCoeff();
VectorF bbox_center = 0.5 * (bbox_min + bbox_max);
Vector3F side_dir = edge_dir.cross(Vector3F::UnitZ());
Float sin_val = side_dir.norm();
if (sin_val < 1e-3) return;
const size_t num_vts = loop.rows();
for (size_t i=0; i<num_vts; i++) {
Vector3F v = loop.row(i) - bbox_center.transpose();
Float side_component = side_dir.dot(v) / sin_val;
Vector3F proj_v = v - side_component * side_dir / sin_val;
Float proj_component = proj_v.norm();
if (proj_component > 1e-3) {
proj_v -= proj_v / proj_component * (sin_val * max_z_error);
}
loop.row(i) = bbox_center + proj_v + side_component * side_dir / sin_val;
}
}
示例3: reorientate_triangles
void reorientate_triangles(const MatrixFr& vertices, MatrixIr& faces,
const VectorF& n) {
assert(vertices.cols() == 3);
assert(faces.cols() == 3);
const VectorI& f = faces.row(0);
const Vector3F& v0 = vertices.row(f[0]);
const Vector3F& v1 = vertices.row(f[1]);
const Vector3F& v2 = vertices.row(f[2]);
Float projected_area = (v1-v0).cross(v2-v0).dot(n);
if (projected_area < 0) {
faces.col(2).swap(faces.col(1));
}
}
示例4: remove_duplicated_vertices
void TilerEngine::remove_duplicated_vertices(WireNetwork& wire_network, Float tol) {
const size_t num_input_vertices = wire_network.get_num_vertices();
DuplicatedVertexRemoval remover(wire_network.get_vertices(), wire_network.get_edges());
remover.run(tol);
MatrixFr vertices = remover.get_vertices();
MatrixIr edges = remover.get_faces();
VectorI index_map = remover.get_index_map();
assert(num_input_vertices == index_map.size());
wire_network.set_vertices(vertices);
wire_network.set_edges(edges);
const size_t num_output_vertices = wire_network.get_num_vertices();
std::vector<std::string> attr_names = wire_network.get_attribute_names();
for (auto itr : attr_names) {
const std::string& name = itr;
if (wire_network.is_vertex_attribute(name)) {
MatrixFr values = wire_network.get_attribute(name);
MatrixFr updated_values = MatrixFr::Zero(num_output_vertices, values.cols());
VectorF count = VectorF::Zero(num_output_vertices);
for (size_t i=0; i<num_input_vertices; i++) {
size_t j = index_map[i];
updated_values.row(j) += values.row(i);
count[j] += 1;
}
for (size_t i=0; i<num_output_vertices; i++) {
assert(count[i] > 0);
updated_values.row(i) /= count[i];
}
wire_network.set_attribute(name, updated_values);
}
}
}
示例5: create_mesh
CarveMeshPtr create_mesh(const MatrixFr& vertices, const MatrixIr& faces) {
const size_t num_vertices = vertices.rows();
const size_t num_faces = faces.rows();
if (vertices.cols() != 3) {
throw NotImplementedError("Only 3D mesh is supported.");
}
if (faces.cols() != 3) {
throw NotImplementedError("Only triangle mesh is supported.");
}
std::vector<CarveVector> points;
for (size_t i=0; i<num_vertices; i++) {
const auto& v = vertices.row(i);
CarveVector p;
p.v[0] = v[0];
p.v[1] = v[1];
p.v[2] = v[2];
points.push_back(p);
}
std::vector<int> raw_faces;
raw_faces.reserve(num_faces * 4);
for (size_t i=0; i<num_faces; i++) {
raw_faces.push_back(3);
raw_faces.push_back(faces(i,0));
raw_faces.push_back(faces(i,1));
raw_faces.push_back(faces(i,2));
}
return CarveMeshPtr(new CarveMesh(points, num_faces, raw_faces));
}
示例6: generate_end_loops
void SimpleInflator::generate_end_loops() {
const size_t num_edges = m_wire_network->get_num_edges();
const MatrixFr vertices = m_wire_network->get_vertices();
const MatrixIr edges = m_wire_network->get_edges();
const MatrixFr edge_thickness = get_edge_thickness();
for (size_t i=0; i<num_edges; i++) {
const VectorI& edge = edges.row(i);
const VectorF& v1 = vertices.row(edge[0]);
const VectorF& v2 = vertices.row(edge[1]);
Float edge_len = (v2 - v1).norm();
MatrixFr loop_1 = m_profile->place(v1, v2,
m_end_loop_offsets[edge[0]],
edge_thickness(i, 0),
m_rel_correction, m_abs_correction, m_correction_cap,
m_spread_const);
assert(loop_is_valid(loop_1, v1, v2));
MatrixFr loop_2 = m_profile->place(v1, v2,
edge_len - m_end_loop_offsets[edge[1]],
edge_thickness(i, 1),
m_rel_correction, m_abs_correction, m_correction_cap,
m_spread_const);
assert(loop_is_valid(loop_2, v1, v2));
m_end_loops.push_back(std::make_pair(loop_1, loop_2));
}
}
示例7: process_roi
void VertexIsotropicOffsetParameter::process_roi() {
const size_t dim = m_wire_network->get_dim();
MatrixFr vertices = m_wire_network->get_vertices();
VectorF center = m_wire_network->center();
m_transforms.clear();
IsotropicTransforms iso_trans(dim);
size_t roi_size = m_roi.size();
size_t seed_vertex_index = m_roi.minCoeff();
VectorF seed_dir = vertices.row(seed_vertex_index).transpose() - center;
for (size_t i=0; i<roi_size; i++) {
VectorF v_dir = vertices.row(m_roi[i]).transpose() - center;
MatrixF trans = iso_trans.fit(seed_dir, v_dir);
m_transforms.push_back(trans);
}
}
示例8: compute_vertex_grid
HashGrid::Ptr compute_vertex_grid(const MatrixFr& vertices, Float cell_size) {
const size_t dim = vertices.cols();
const size_t num_vertices = vertices.rows();
HashGrid::Ptr grid = HashGrid::create(cell_size, dim);
for (size_t i=0; i<num_vertices; i++) {
const VectorF& v = vertices.row(i);
grid->insert(i, v);
}
return grid;
}
示例9: extract_mesh
void extract_mesh(const C3t3& c3t3,
MatrixFr& vertices, MatrixIr& faces, MatrixIr& voxels) {
const Tr& tr = c3t3.triangulation();
size_t num_vertices = tr.number_of_vertices();
size_t num_faces = c3t3.number_of_facets_in_complex();
size_t num_voxels = c3t3.number_of_cells_in_complex();
vertices.resize(num_vertices, 3);
faces.resize(num_faces, 3);
voxels.resize(num_voxels, 4);
std::map<Tr::Vertex_handle, int> V;
size_t inum = 0;
for(auto vit = tr.finite_vertices_begin();
vit != tr.finite_vertices_end(); ++vit) {
V[vit] = inum;
const auto& p = vit->point();
vertices.row(inum) = Vector3F(p.x(), p.y(), p.z()).transpose();
assert(inum < num_vertices);
inum++;
}
assert(inum == num_vertices);
size_t face_count = 0;
for(auto fit = c3t3.facets_in_complex_begin();
fit != c3t3.facets_in_complex_end(); ++fit) {
assert(face_count < num_faces);
for (int i=0; i<3; i++) {
if (i != fit->second) {
const auto& vh = (*fit).first->vertex(i);
assert(V.find(vh) != V.end());
const int vid = V[vh];
faces(face_count, i) = vid;
}
}
face_count++;
}
assert(face_count == num_faces);
size_t voxel_count = 0;
for(auto cit = c3t3.cells_in_complex_begin() ;
cit != c3t3.cells_in_complex_end(); ++cit ) {
assert(voxel_count < num_voxels);
for (int i=0; i<4; i++) {
assert(V.find(cit->vertex(i)) != V.end());
const size_t vid = V[cit->vertex(i)];
voxels(voxel_count, i) = vid;
}
voxel_count++;
}
assert(voxel_count == num_voxels);
}
示例10: RuntimeError
void CGALConvexHull3D::run(const MatrixFr& points) {
std::list<Point_3> cgal_pts;
const size_t num_pts = points.rows();
const size_t dim = points.cols();
if (dim != 3) {
std::stringstream err_msg;
err_msg << "Invalid dim: " << dim << " Expect dim=3.";
throw RuntimeError(err_msg.str());
}
for (size_t i=0; i<num_pts; i++) {
const VectorF& p = points.row(i);
cgal_pts.push_back(Point_3(p[0], p[1], p[2]));
}
Polyhedron_3 hull;
CGAL::convex_hull_3(cgal_pts.begin(), cgal_pts.end(), hull);
assert(hull.is_closed());
assert(hull.is_pure_triangle());
const size_t num_vertices = hull.size_of_vertices();
const size_t num_faces = hull.size_of_facets();
m_vertices.resize(num_vertices, dim);
m_faces.resize(num_faces, 3);
size_t vertex_count=0;
for (auto itr=hull.vertices_begin(); itr!=hull.vertices_end(); itr++) {
const Point_3& p = itr->point();
m_vertices.coeffRef(vertex_count, 0) = p.x();
m_vertices.coeffRef(vertex_count, 1) = p.y();
m_vertices.coeffRef(vertex_count, 2) = p.z();
itr->id() = vertex_count;
vertex_count++;
}
size_t face_count=0;
for (auto f_itr=hull.facets_begin(); f_itr!=hull.facets_end(); f_itr++) {
size_t edge_count=0;
auto h_itr = f_itr->facet_begin();
do {
m_faces.coeffRef(face_count, edge_count) = h_itr->vertex()->id();
edge_count++;
h_itr++;
} while (h_itr != f_itr->facet_begin());
face_count++;
}
compute_index_map(points);
reorient_faces();
}
示例11: locate
void PointLocator::locate(const MatrixFr& points) {
const Float eps = 1e-6;
const size_t num_pts = points.rows();
m_voxel_idx = VectorI::Zero(num_pts);
m_barycentric_coords = MatrixFr::Zero(num_pts, m_vertex_per_element);
for (size_t i=0; i<num_pts; i++) {
VectorF v = points.row(i);
VectorI candidate_elems = m_grid->get_items_near_point(v);
VectorF barycentric_coord;
VectorF best_barycentric_coord;
bool found = false;
Float least_negative_coordinate = -std::numeric_limits<Float>::max();
const size_t num_candidates = candidate_elems.size();
for (size_t j=0; j<num_candidates; j++) {
barycentric_coord = compute_barycentric_coord(
v, candidate_elems[j]);
Float min_barycentric_coord = barycentric_coord.minCoeff();
if (min_barycentric_coord > least_negative_coordinate) {
found = true;
least_negative_coordinate = min_barycentric_coord;
m_voxel_idx[i] = candidate_elems[j];
best_barycentric_coord = barycentric_coord;
if (min_barycentric_coord >= -eps) {
break;
}
}
}
if (!found) {
std::stringstream err_msg;
err_msg << "Point ( ";
for (size_t i=0; i<m_mesh->get_dim(); i++) {
err_msg << v[i] << " ";
}
err_msg << ") is not inside of any voxels" << std::endl;
throw RuntimeError(err_msg.str());
}
m_barycentric_coords.row(i) = best_barycentric_coord;
}
}
示例12: is_periodic
bool MeshValidation::is_periodic(
const MatrixFr& vertices, const MatrixIr& faces) {
const Float EPS = 1e-6;
HashGrid::Ptr grid = compute_vertex_grid(vertices, EPS);
Vector3F bbox_min = vertices.colwise().minCoeff();
Vector3F bbox_max = vertices.colwise().maxCoeff();
Vector3F bbox_size = bbox_max - bbox_min;
Vector3F offsets[] = {
Vector3F( bbox_size[0], 0.0, 0.0),
Vector3F(-bbox_size[0], 0.0, 0.0),
Vector3F(0.0, bbox_size[1], 0.0),
Vector3F(0.0,-bbox_size[1], 0.0),
Vector3F(0.0, 0.0, bbox_size[2]),
Vector3F(0.0, 0.0,-bbox_size[2])
};
bool result = true;
const size_t num_vertices = vertices.rows();
for (size_t i=0; i<num_vertices; i++) {
const VectorF& v = vertices.row(i);
if (fabs(v[0] - bbox_min[0]) < EPS) {
result = result && match(grid, v + offsets[0]);
}
if (fabs(v[0] - bbox_max[0]) < EPS) {
result = result && match(grid, v + offsets[1]);
}
if (fabs(v[1] - bbox_min[1]) < EPS) {
result = result && match(grid, v + offsets[2]);
}
if (fabs(v[1] - bbox_max[1]) < EPS) {
result = result && match(grid, v + offsets[3]);
}
if (fabs(v[2] - bbox_min[2]) < EPS) {
result = result && match(grid, v + offsets[4]);
}
if (fabs(v[2] - bbox_max[2]) < EPS) {
result = result && match(grid, v + offsets[5]);
}
}
return result;
}
示例13: compute_importance_level
VectorI MeshCleaner::compute_importance_level(const MatrixFr& vertices) {
VectorF bbox_min = vertices.colwise().minCoeff();
VectorF bbox_max = vertices.colwise().maxCoeff();
BoxChecker checker(bbox_min, bbox_max);
const size_t num_vertices = vertices.rows();
VectorI level = VectorI::Zero(num_vertices);
for (size_t i=0; i<num_vertices; i++) {
const VectorF& v = vertices.row(i);
if (checker.is_on_boundary_corners(v)) {
level[i] = 3;
} else if (checker.is_on_boundary_edges(v)) {
level[i] = 2;
} else if (checker.is_on_boundary(v)) {
level[i] = 1;
}
}
return level;
}
示例14: compute_derivative
MatrixFr VertexIsotropicOffsetParameter::compute_derivative() const {
const VectorF center = m_wire_network->center();
const VectorF bbox_max = m_wire_network->get_bbox_max();
const size_t dim = m_wire_network->get_dim();
const size_t num_vertices = m_wire_network->get_num_vertices();
const size_t roi_size = m_roi.size();
const MatrixFr& vertices = m_wire_network->get_vertices();
assert(roi_size == m_transforms.size());
size_t seed_vertex_index = m_roi.minCoeff();
VectorF seed_vertex = vertices.row(seed_vertex_index);
VectorF seed_offset = VectorF::Zero(dim);
seed_offset = (bbox_max - center).cwiseProduct(m_dof_dir);
MatrixFr derivative = MatrixFr::Zero(num_vertices, dim);
for (size_t i=0; i<roi_size; i++) {
size_t v_idx = m_roi[i];
assert(v_idx < num_vertices);
const MatrixF& trans = m_transforms[i];
derivative.row(v_idx) = trans * seed_offset;
}
return derivative;
}
示例15: apply_correction_to_out_plane_edge
void GeometryCorrectionTable::apply_correction_to_out_plane_edge(
const Vector3F& edge_dir, MatrixFr& loop) {
const Float EPS = 1e-3;
assert(fabs(edge_dir[2]) > 0.0);
VectorF bbox_min = loop.colwise().minCoeff();
VectorF bbox_max = loop.colwise().maxCoeff();
VectorF bbox_center = 0.5 * (bbox_min + bbox_max);
size_t num_vts = loop.rows();
size_t dim = loop.cols();
assert(dim == 3);
MatrixFr proj_loop(num_vts, 3);
Vector3F proj_edge_dir(edge_dir[0], edge_dir[1], 0.0);
if (loop.rows() != 4) {
throw NotImplementedError(
"Geometry correction supports only square wires");
}
for (size_t i=0; i<num_vts; i++) {
VectorF v = loop.row(i) - bbox_center.transpose();
Float edge_dir_offset = v[2] / edge_dir[2];
VectorF proj_v = v - edge_dir * edge_dir_offset;
proj_loop.row(i) = proj_v;
assert(fabs(proj_v[2]) < EPS);
}
Float dist_01 = (proj_loop.row(0) - proj_loop.row(1)).norm();
Float dist_12 = (proj_loop.row(1) - proj_loop.row(2)).norm();
if (dist_01 > dist_12) {
proj_edge_dir = (proj_loop.row(0) - proj_loop.row(1)) / dist_01;
} else {
proj_edge_dir = (proj_loop.row(1) - proj_loop.row(2)) / dist_12;
}
const VectorF& corner = proj_loop.row(0);
Float target_half_height = proj_edge_dir.dot(corner);
Float target_half_width =
(corner - proj_edge_dir * target_half_height).norm();
target_half_height = fabs(target_half_height);
Vector2F correction_1 = lookup(target_half_width, target_half_height);
Vector2F correction_2 = lookup(target_half_height, target_half_width);
Float half_width = 0.5 * (correction_1[0] + correction_2[1])
+ 0.05 * num_offset_pixel;
Float half_height = 0.5 * (correction_1[1] + correction_2[0])
+ 0.05 * num_offset_pixel;
half_width = std::max(half_width, min_thickness);
half_height = std::max(half_height, min_thickness);
for (size_t i=0; i<num_vts; i++) {
const VectorF& proj_v = proj_loop.row(i);
Float height = proj_edge_dir.dot(proj_v);
VectorF width_dir = (proj_v - proj_edge_dir * height).normalized();
assert(!isnan(width_dir[0]));
assert(!isnan(width_dir[1]));
assert(!isnan(width_dir[2]));
Float height_sign = (height < 0.0)? -1: 1;
proj_loop.row(i) = proj_edge_dir * height_sign * half_height
+ width_dir * half_width;
}
for (size_t i=0; i<num_vts; i++) {
const VectorF& proj_v = proj_loop.row(i);
loop.row(i) = (bbox_center + proj_v - edge_dir *
edge_dir.dot(proj_v)).transpose();
}
}