//! main constructor Panel(point_type p0, point_type p1, point_type p2) : BC(POTENTIAL) { vertices.resize(3); vertices[0] = p0; vertices[1] = p1; vertices[2] = p2; // get the center center = (p0+p1+p2)/3; // area & normal point_type L0 = p2-p0; point_type L1 = p1-p0; point_type c = point_type(L0[1]*L1[2]-L0[2]*L1[1], -(L0[0]*L1[2]-L0[2]*L1[0]), L0[0]*L1[1]-L0[1]*L1[0]); Area = 0.5*norm(c); normal = c/2/Area; // generate the quadrature points // assume K = 3 for now auto Config = BEMConfig::Instance(); unsigned k = Config->getK(); auto& points = Config->GaussPoints(); quad_points.resize(k); // loop over K points performing matvecs for (unsigned i=0; i<k; i++) { double x = vertices[0][0]*points[i][0]+vertices[1][0]*points[i][1]+vertices[2][0]*points[i][2]; double y = vertices[0][1]*points[i][0]+vertices[1][1]*points[i][1]+vertices[2][1]*points[i][2]; double z = vertices[0][2]*points[i][0]+vertices[1][2]*points[i][1]+vertices[2][2]*points[i][2]; quad_points[i] = point_type(x,y,z); } }
void curve4_div::recursive_bezier(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, unsigned level) { if(level > curve_recursion_limit) { return; } float x12 = (x1 + x2) / 2; float y12 = (y1 + y2) / 2; float x23 = (x2 + x3) / 2; float y23 = (y2 + y3) / 2; float x34 = (x3 + x4) / 2; float y34 = (y3 + y4) / 2; float x123 = (x12 + x23) / 2; float y123 = (y12 + y23) / 2; float x234 = (x23 + x34) / 2; float y234 = (y23 + y34) / 2; float x1234 = (x123 + x234) / 2; float y1234 = (y123 + y234) / 2; float dx = x4 - x1; float dy = y4 - y1; float d2 = fabs(((x2 - x4) * dy) - ((y2 - y4) * dx)); float d3 = fabs(((x3 - x4) * dy) - ((y3 - y4) * dx)); switch((int(d2 > curve_collinearity_epsilon) << 1) + int(d3 > curve_collinearity_epsilon)) { case 0: if (fabs(x1 + x3 - x2 - x2) + fabs(y1 + y3 - y2 - y2) + fabs(x2 + x4 - x3 - x3) + fabs(y2 + y4 - y3 - y3) <= m_distance_tolerance_manhattan) { m_points.add(point_type(x1234, y1234, path_flags_jr)); return; } break; case 1: if ((d3 * d3) <= (m_distance_tolerance_square * ((dx * dx) + (dy * dy)))) { m_points.add(point_type(x23, y23, path_flags_jr)); return; } break; case 2: if ((d2 * d2) <= (m_distance_tolerance_square * ((dx * dx) + (dy * dy)))) { m_points.add(point_type(x23, y23, path_flags_jr)); return; } break; case 3: if (((d2 + d3) * (d2 + d3)) <= (m_distance_tolerance_square * ((dx * dx) + (dy * dy)))) { m_points.add(point_type(x23, y23, path_flags_jr)); return; } break; } recursive_bezier(x1, y1, x12, y12, x123, y123, x1234, y1234, level + 1); recursive_bezier(x1234, y1234, x234, y234, x34, y34, x4, y4, level + 1); }
void curve4_div::bezier(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { m_points.add(point_type(x1, y1)); recursive_bezier(x1, y1, x2, y2, x3, y3, x4, y4, 0); m_points.add(point_type(x4, y4)); }
Detail::PointType3D<CoordT1, CoordT2> operator-(const Point3D<CoordT1>& lhs, const Point3D<CoordT2>& rhs) { using point_type = Detail::PointType3D<CoordT1, CoordT2>; return point_type( lhs.m_x - rhs.m_x, lhs.m_y - rhs.m_y, lhs.m_z - rhs.m_z); }
void ReadVertFace(const char *vert_file, const char *face_file, std::vector<triangle_type>& elements) { std::ifstream vert(vert_file); std::ifstream face(face_file); std::string str; // mesh info int num_vertices = 0, num_faces = 0; std::vector<point_type> vertices; // get first line of vertices -- # vertices std::getline(vert, str); num_vertices = atoi(str.c_str()); vertices.resize(num_vertices); printf("# vertices: %d\n",num_vertices); std::vector<std::string> split_str; // read all vertices for (int i=0; i<num_vertices; i++) { split_str.clear(); std::getline(vert, str); split(str.c_str(), split_str); double x, y, z; x = atof(split_str[0].c_str()); y = atof(split_str[1].c_str()); z = atof(split_str[2].c_str()); vertices[i] = point_type(x,y,z); } // finished reading vertices vert.close(); // get first line of faces -- # faces std::getline(face, str); num_faces = atoi(str.c_str()); elements.resize(num_faces); printf("# elements: %d\n",num_faces); // read all faces for (int i=0; i<num_faces; i++) { split_str.clear(); std::getline(face, str); split(str.c_str(), split_str); int v1, v2, v3; // read vertex numbers, taking into account 1-indexing v1 = atoi(split_str[0].c_str()) - 1; v2 = atoi(split_str[1].c_str()) - 1; v3 = atoi(split_str[2].c_str()) - 1; elements[i] = triangle_type(vertices[v1],vertices[v2],vertices[v3]); } face.close(); }
//------------------------------------------------------------------------ void vcgen_bspline::add_vertex(double x, double y, unsigned cmd) { m_status = initial; if(is_move_to(cmd)) { m_src_vertices.modify_last(point_type(x, y)); } else { if(is_vertex(cmd)) { m_src_vertices.add(point_type(x, y)); } else { m_closed = get_close_flag(cmd); } } }
inline bool pointmesh2d<point_t>::equals ( pointmesh2d const& o, value_type const& epsilon ) const { /*if ( o.size() != size() || _points.empty() ) { return false; } else */ { // heuristic : if min + max + mean + #poinst meshes are equal point_type mean_a = std::accumulate ( _points.begin(), _points.end(), point_type() ); point_type mean_b = std::accumulate ( o._points.begin(), o._points.end(), point_type() ); axis_aligned_boundingbox<point_type> box_a ( _points.begin(), _points.end() ); axis_aligned_boundingbox<point_type> box_b ( o._points.begin(), o._points.end() ); return mean_a.distance(mean_b) < epsilon && box_a.min.distance(box_b.min) < epsilon && box_a.max.distance(box_b.max) < epsilon; } }
network user_settings_io::read_network_from_csv_file(const std::string& file_path) { std::ifstream csv(file_path); if(!csv.is_open()) { LOG(logger::critical, invalid_file_type); throw std::runtime_error(invalid_file_type); } std::string line; node_positions_type nodes; while(std::getline(csv, line)) { std::vector<std::string> parts; boost::split(parts, line, boost::is_any_of(" \t"), boost::token_compress_on); if(parts.size() < 4) { LOG(logger::critical, invalid_format); throw std::runtime_error(invalid_format); } try { double x = std::stod(parts[0]); double y = std::stod(parts[1]); double z = std::stod(parts[2]); int type = std::stod(parts[3]); if(1 != type) { continue; } nodes.push_back(point_type(x, y, z)); } catch(const std::invalid_argument& err) { //TODO maybe process? LOG(logger::critical, invalid_format); throw std::runtime_error(invalid_format); } } network net(nodes.size()); for(std::size_t i = 0; i < nodes.size(); ++i) { net.set_node_position(i, nodes[i]); } return net; }
Detail::PointType2D<CoordT1, CoordT2> operator+(const Point2D<CoordT1>& lhs, const Point2D<CoordT2>& p2) { using point_type = Detail::PointType2D<CoordT1, CoordT2>; return point_type(lhs.m_x + rhs.m_x, lhs.m_y + rhs.m_y); }
point_type app_viewer::get_error_pnt() const { return point_type(-get_wnd()->width() / 2 + 10, -get_wnd()->height() / 2 + 50); }
point_type app_viewer::get_legend_pnt() const { return point_type(-get_wnd()->width() / 2 + 10, -get_wnd()->height() / 2 + 30); }
BoundBox& operator-= (const point_type& rhs) { this->offset(point_type(-rhs.x, -rhs.y)); return *this; }
BoundBox operator- (const point_type& rhs) const { BoundBox result = *this; result.offset(point_type(-rhs.x, -rhs.y)); return result; }
point_type get_center() const { return point_type(get_xcenter(), get_ycenter()); }