d_surf * f_triangulate::get_method_surf() { vec * x = create_vec(); vec * y = create_vec(); vec * z = create_vec(); size_t NN = method_grid->getCountX(); size_t MM = method_grid->getCountY(); size_t size = NN*MM; size_t i; for (i = 0; i < size; i++) { if (method_mask_solved->get(i) == false) continue; REAL X, Y, Z; size_t I, J; one2two(i, I, J, NN, MM); method_grid->getCoordNode(I, J, X, Y); Z = (*method_X)(i); x->push_back(X); y->push_back(Y); z->push_back(Z); } d_points * pnts = create_points(x, y, z); d_surf * res = triangulate_points(pnts, method_grid); pnts->release(); return res; };
GRAPH *create_graph(void){ GRAPH *temp=malloc(1*sizeof(GRAPH)); if(temp==NULL){ perror("MALLOC GRAPH"); exit(1); } temp->size=get_size_of_vertex(); temp->labels=create_points(temp); temp->edges=alloc_edges(temp); add_edges(temp); view_edges(temp); return temp; }
/** * wrapper func to validate the block of points being processed and to * call the appropriate handler. */ int process_group(point_line_t **plta, int count) { int valid_count = 0; if (!plta) { printf("WARNING: Unexpected call to process_multi_group with a NULL point array\n"); return 0; } bu_log("processing a group!\n"); /* resort the list, put nulls at the end */ valid_count = condense_points(plta, count); /* ignore insufficient counts */ if (valid_count <= 2) switch ((*plta)[0].code) { case(PLATE): /* need at least 3 (triangle) */ /* printf("IGNORING PLATE POINT DUPLICATE(S)\n"); */ return 0; case(ARB): /* need 8 */ /* printf("IGNORING ARB POINT DUPLICATE(S)\n");*/ return 0; case(CYLINDER): /* need at least 3 (2 for length + diam) */ /* printf("IGNORING CYLINDER POINT DUPLICATE(S)\n"); */ return 0; } /* FIXME: callbacks should really be registered in the lexer or parser when a point-line of that particular type is encountered */ switch ((*plta)[0].code) { case(PLATE): return create_plate(plta, valid_count); case(ARB): return create_arb(plta, valid_count); case(CYLINDER): return create_cylinder(plta, valid_count); case(CYL): return create_cyl(plta, valid_count); case(POINTS): #if PRINT_ARRAY static int print_counter = 0; if (print_counter == 0) { bu_log("--- POINTS ---\n"); print_array(plta, count); } #endif return create_points(plta, valid_count); case(SYMMETRY): return create_points(plta, valid_count); case(PIPE): return create_pipe(plta, valid_count); case(SPHERE): return create_sphere(plta, valid_count); } printf("WARNING, unsupported point code encountered (%d)\n", (*plta)[0].code); return 0; }
gint main (gint argc, gchar ** argv) { gint ret = 0; VsgVector2d lb = {-1., -1.}; VsgVector2d ub = {1., 1.}; NodeCounter counter = {0, 0}; const guint n = 1000; Pt points[n]; VsgPRTree2d *tree; gint i; if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0) { g_print ("%s\n", PACKAGE_VERSION); return 0; } vsg_init_gdouble (); /* create the tree */ tree = vsg_prtree2d_new (&lb, &ub, NULL, 1); vsg_prtree2d_set_node_data (tree, TYPE_NODE_COUNTER, &counter); /* create the points */ create_points (points, n); /* insert the points into the tree */ for (i=0; i<n; i++) { vsg_prtree2d_insert_point (tree, &points[i]); } /* accumulate the point counts across the tree */ vsg_prtree2d_traverse (tree, G_POST_ORDER, (VsgPRTree2dFunc) up, NULL); /* do some near/far traversal */ vsg_prtree2d_near_far_traversal (tree, (VsgPRTree2dFarInteractionFunc) far, (VsgPRTree2dInteractionFunc) near, &ret); /* distribute back the point counts across the tree */ vsg_prtree2d_traverse (tree, G_PRE_ORDER, (VsgPRTree2dFunc) down, NULL); /* check the results */ for (i=0; i<n; i++) { if (points[i].count != n) { g_printerr ("ERROR: wrong count on point %d: %d (should be %d).\n", i, points[i].count, n); ret ++; } } /* remove the points */ for (i=0; i<n; i++) { vsg_prtree2d_remove_point (tree, &points[i]); } /* destroy the tree */ vsg_prtree2d_free (tree); return ret; }
d_points * discretize_pcntr(const d_cntr * pcrv, d_grid * grd, const char * task_name) { if (!pcrv) return NULL; // using modified brezengham algorithm size_t qq; REAL X2, X1, Y2, Y1, Z1, Z2; std::vector<pos_s> * data = new std::vector<pos_s>(); for (qq = 0; qq < pcrv->size()-1; qq++) { X1 = (*(pcrv->X))(qq); Y1 = (*(pcrv->Y))(qq); Z1 = (*(pcrv->Z))(qq); X2 = (*(pcrv->X))(qq + 1); Y2 = (*(pcrv->Y))(qq + 1); Z2 = (*(pcrv->Z))(qq + 1); int x1 = grd->get_i(X1); int x2 = grd->get_i(X2); int y1 = grd->get_j(Y1); int y2 = grd->get_j(Y2); int dx, dy, i1, i2, i, kx, ky; int d; // "отклонение" int x, y; int flag; dy = y2 - y1; dx = x2 - x1; REAL DY = Y2-Y1; REAL DX = X2-X1; if (dx == 0 && dy == 0) // only one point { add_square_val(grd, x1, y1, X1, Y1, Z1, X2, Y2, Z2, data); continue; } kx = 1; // шаг по x ky = 1; // шаг по y // Выбор тактовой оси if ( dx < 0 ) { dx = -dx; kx = -1; // Y } else { if(dx == 0) kx = 0; // X } if (dy < 0) { dy = -dy; ky = -1; } if (dx < dy) { flag = 0; d = dx; dx = dy; dy = d; } else flag = 1; i1 = dy + dy; d = i1 - dx; i2 = d - dx; x = x1; y = y1; for ( i = 0; i < dx; i++ ) { add_square_val(grd, x, y, X1, Y1, Z1, X2, Y2, Z2, data); if (flag) x += kx; // шаг по такт. оси else y += ky; if( d < 0 ) {// горизонтальный шаг d += i1; } else { // диагональный шаг int x_0; int x_1; int y_0; int y_1; if (flag) { x_0 = x-kx; x_1 = x; y_0 = y; y_1 = y+ky; } else { y_0 = y-ky; y_1 = y; x_0 = x; x_1 = x+kx; } REAL X_0 = grd->getCoordNodeX(x_0); REAL X_1 = grd->getCoordNodeX(x_1); REAL Y_0 = grd->getCoordNodeY(y_0); REAL Y_1 = grd->getCoordNodeY(y_1); if (flag) { if (fabs( DY*(X_0-X1) + DX*(Y1-Y_1) ) - fabs( DY*(X_1-X1) + DX*(Y1-Y_0)) < 0) { bool change = true; x -= kx; y += ky; add_square_val(grd, x, y, X1, Y1, Z1, X2, Y2, Z2, data); x += kx; } else { add_square_val(grd, x, y, X1, Y1, Z1, X2, Y2, Z2, data); y += ky; // прирост высоты } } else { if (fabs( DX*(Y_0-Y1) + DY*(X1-X_1) ) - fabs( DX*(Y_1-Y1) + DY*(X1-X_0)) < 0) { y -= ky; x += kx; add_square_val(grd, x, y, X1, Y1, Z1, X2, Y2, Z2, data); y += ky; } else { add_square_val(grd, x, y, X1, Y1, Z1, X2, Y2, Z2, data); x += kx; } } d += i2; } } add_square_val(grd, x, y, X1, Y1, Z1, X2, Y2, Z2, data); // последняя точка } std::sort(data->begin(), data->end(), ptr_pos_s_less); vec * points_x = create_vec(); vec * points_y = create_vec(); vec * points_z = create_vec(); points_x->reserve(data->size()); points_y->reserve(data->size()); points_z->reserve(data->size()); size_t prev_pos = UINT_MAX; pos_s elem; REAL total_weight = 0; REAL sum_val = 0; size_t NN = grd->getCountX(); for (qq = 0; qq < data->size(); qq++) { elem = (*data)[qq]; if (prev_pos == elem.pos) { sum_val += elem.s; } else { // write if (prev_pos != UINT_MAX) { size_t pos_x = prev_pos % NN; size_t pos_y = (prev_pos - pos_x)/NN; REAL x, y, z; grd->getCoordNode(pos_x, pos_y, x, y); z = sum_val; points_x->push_back(x); points_y->push_back(y); points_z->push_back(z); } // sum_val = elem.s; } prev_pos = elem.pos; }; size_t pos_x = prev_pos % NN; size_t pos_y = (prev_pos - pos_x)/NN; REAL x, y, z; grd->getCoordNode(pos_x, pos_y, x, y); z = sum_val; points_x->push_back(x); points_y->push_back(y); points_z->push_back(z); points_x->resize(points_x->size()); points_y->resize(points_y->size()); points_z->resize(points_z->size()); delete data; d_points * res = create_points(points_x, points_y, points_z, task_name); return res; };
d_points * _pnts_load_shp(const char * filename, const char * pntsname, const char * param) { SHPHandle hSHP; DBFHandle hDBF; hSHP = SHPOpen(filename, "rb"); if( hSHP == NULL ) { writelog(LOG_ERROR, "Unable to open:%s", filename ); return NULL; } int shpType; int Entities; SHPGetInfo(hSHP, &Entities, &shpType, NULL, NULL); if (shpType != SHPT_POINT) { SHPClose( hSHP ); writelog(LOG_ERROR, "%s : Wrong shape type!", filename); return NULL; } hDBF = DBFOpen(filename, "rb"); if( hDBF == NULL ) { SHPClose(hSHP); writelog(LOG_ERROR, "Unable to open DBF for %s", filename ); return NULL; } int name_field = DBFGetFieldIndex( hDBF, "NAME" ); if (name_field == -1) writelog(LOG_WARNING,"can't find field named \"NAME\""); int val_field = DBFGetFieldIndex( hDBF, param ); if (val_field == -1) writelog(LOG_WARNING, "Cannot find parameter \"%s\" in DBF file", param); int dbf_records = DBFGetRecordCount( hDBF ); Entities = MIN(dbf_records, Entities); vec * X = create_vec(Entities, 0, 0); vec * Y = create_vec(Entities, 0, 0); int i; for (i = 0; i < Entities; i++) { SHPObject * shpObject = SHPReadObject( hSHP, i ); if (shpObject == NULL) continue; const char * name = NULL; if (name_field != -1) { name = DBFReadStringAttribute( hDBF, i, name_field ); if (pntsname != NULL) { if ( StringMatch(pntsname, name) == false ) continue; } } (*X)(i) = *(shpObject->padfX); (*Y)(i) = *(shpObject->padfY); SHPDestroyObject(shpObject); } vec * Z = create_vec(Entities, 0, 0); for (i = 0; i < Entities; i++) { if (val_field != -1) (*Z)(i) = DBFReadDoubleAttribute( hDBF, i, val_field ); else (*Z)(i) = 0; } DBFClose( hDBF ); SHPClose( hSHP ); char * fname = get_name(filename); d_points * res = create_points(X, Y, Z, fname); sstuff_free_char(fname); return res; };