static PyObject * vectors_get_strokes(PyGimpVectors *self, void *closure) { int *strokes; int i, num_strokes; PyObject *ret; strokes = gimp_vectors_get_strokes(self->ID, &num_strokes); ret = PyList_New(num_strokes); if (ret == NULL) return NULL; for (i = 0; i < num_strokes; i++) PyList_SetItem(ret, i, vectors_bezier_stroke_new(self, strokes[i])); g_free(strokes); return ret; }
/* ------------------------------------------ * p_capture_4_vector_points * ------------------------------------------ * capture the first 4 points of the 1st stroke in the active path vectors * pointOrder POINT_ORDER_MODE_31_42 : order 0,1,2,3 compatible with the exactAligner script * POINT_ORDER_MODE_21_43 : order 0,2,1,3 */ static gint p_capture_4_vector_points(gint32 imageId, AlingCoords *alingCoords, gint32 pointOrder) { gint32 activeVectorsId; PixelCoords *coordPtr[4]; gint ii; gint countVaildPoints; if (pointOrder == POINT_ORDER_MODE_31_42) { coordPtr[0] = &alingCoords->startCoords; coordPtr[1] = &alingCoords->startCoords2; coordPtr[2] = &alingCoords->currCoords; coordPtr[3] = &alingCoords->currCoords2; } else { coordPtr[0] = &alingCoords->startCoords; coordPtr[2] = &alingCoords->startCoords2; coordPtr[1] = &alingCoords->currCoords; coordPtr[3] = &alingCoords->currCoords2; } countVaildPoints = 0; for(ii=0; ii < 4; ii++) { coordPtr[ii]->px = -1; coordPtr[ii]->py = -1; coordPtr[ii]->valid = FALSE; } activeVectorsId = gimp_image_get_active_vectors(imageId); if(activeVectorsId >= 0) { gint num_strokes; gint *strokes; strokes = gimp_vectors_get_strokes (activeVectorsId, &num_strokes); if(strokes) { if(num_strokes > 0) { gdouble *points; gint num_points; gboolean closed; GimpVectorsStrokeType type; points = NULL; type = gimp_vectors_stroke_get_points(activeVectorsId, strokes[0], &num_points, &points, &closed); if(gap_debug) { gint ii; for(ii=0; ii < MIN(24, num_points); ii++) { printf ("point[%d] = %.3f\n", ii, points[ii]); } } if (type == GIMP_VECTORS_STROKE_TYPE_BEZIER) { if(num_points >= 6) { coordPtr[0]->px = points[0]; coordPtr[0]->py = points[1]; coordPtr[0]->valid = TRUE; countVaildPoints++; } if(num_points >= 12) { coordPtr[1]->px = points[6]; coordPtr[1]->py = points[7]; coordPtr[1]->valid = TRUE; countVaildPoints++; } if(num_points >= 18) { coordPtr[2]->px = points[12]; coordPtr[2]->py = points[13]; coordPtr[2]->valid = TRUE; countVaildPoints++; } if(num_points >= 24) { coordPtr[3]->px = points[18]; coordPtr[3]->py = points[19]; coordPtr[3]->valid = TRUE; countVaildPoints++; } } if(points) { g_free(points); } } g_free(strokes); } } return(countVaildPoints); } /* end p_capture_4_vector_points */
/* ------------------------------- * p_set_2_vector_points * ------------------------------- * remove all strokes from the active path vectors * and set a new stroke containing targetCoords (one or 2 depend on the valid flag) * For better visualisation set guide lines crossing at the first target coords. */ static void p_set_2_vector_points(gint32 imageId, PixelCoords *targetCoords, PixelCoords *targetCoords2) { gint32 activeVectorsId; /* gint newStrokeId; */ gdouble *points; gint num_points; gboolean closed; GimpVectorsStrokeType type; gimp_image_add_hguide(imageId, targetCoords->py); gimp_image_add_vguide(imageId, targetCoords->px); activeVectorsId = gimp_image_get_active_vectors(imageId); if(activeVectorsId >= 0) { gint num_strokes; gint *strokes; strokes = gimp_vectors_get_strokes (activeVectorsId, &num_strokes); if(strokes) { if(num_strokes > 0) { gint ii; for(ii=0; ii < num_strokes; ii++) { gimp_vectors_remove_stroke(activeVectorsId, strokes[ii]); } } g_free(strokes); } if (targetCoords->valid) { closed = FALSE; num_points = 6; if (targetCoords2->valid) { num_points = 12; } points = g_new (gdouble, num_points); points[0] = targetCoords->px; points[1] = targetCoords->py; points[2] = targetCoords->px; points[3] = targetCoords->py; points[4] = targetCoords->px; points[5] = targetCoords->py; if(targetCoords2->valid) { points[6] = targetCoords2->px; points[7] = targetCoords2->py; points[8] = targetCoords2->px; points[9] = targetCoords2->py; points[10] = targetCoords2->px; points[11] = targetCoords2->py; } type = GIMP_VECTORS_STROKE_TYPE_BEZIER; /* newStrokeId = */ gimp_vectors_stroke_new_from_points (activeVectorsId , type , num_points , points , closed ); g_free(points); } } } /* end p_set_2_vector_points */
void fill_stop_path_buffer_from_path(gint32 path_id) { int i,j,num_strokes; gint stroke_id; #ifdef DEBUG g_warning("fill_stop_path_buffer_from_path with path_id = %d, previewWidth = %d, height = %d",path_id, interface_vals.previewWidth,interface_vals.previewHeight ); #endif for (i = 0; i < interface_vals.previewWidth * interface_vals.previewHeight; i++) interface_vals.previewStopPath[i] = 0; #ifdef DEBUG g_warning("fill_stop_path_buffer_from_path init finish",path_id); #endif if (path_id <= 0) return; if (!gimp_vectors_is_valid(path_id)) { g_error("selected path is not valid!"); } stroke_id = gimp_vectors_get_strokes(path_id,&num_strokes)[0]; #ifdef DEBUG g_warning("vectors has %d strokes, using stroke_id = %d",stroke_id); #endif if (num_strokes > 0) { gboolean closed; gdouble *coords; gint num_coords; #ifdef DEBUG g_warning("going to interpolate"); #endif coords = gimp_vectors_stroke_interpolate(path_id,stroke_id,1.0,&num_coords,&closed); #ifdef DEBUG g_warning("got %d interpolation points",num_coords/2); #endif if (coords) { gint oldx,oldy; for (i = 0; i < num_coords; i+=2) { gint x = coords[i] - interface_vals.selectionX0; gint y = coords[i+1] - interface_vals.selectionY0; #ifdef DEBUG g_warning("%d: putting in point x,y = %d,%d",i/2,x,y); #endif if (x >= 0 && y >= 0 && x < interface_vals.previewWidth && y < interface_vals.previewHeight) { interface_vals.previewStopPath[y * interface_vals.previewWidth + x] = 1; if (i>0) { gdouble len = sqrt((gdouble)(x-oldx)*(x-oldx) + (gdouble)(y-oldy)*(y-oldy)); if (len > 1) { gdouble xcoeff = (gdouble)(x-oldx) / len; gdouble ycoeff = (gdouble)(y-oldy) / len; for (j = 0; j < floor(len); ++j) { gint xtmp = ROUND(oldx + xcoeff*j); gint ytmp = ROUND(oldy + ycoeff*j); interface_vals.previewStopPath[ytmp * interface_vals.previewWidth + xtmp] = 1; } } } } oldx = x; oldy = y; } g_free(coords); } } #ifdef DEBUG g_warning("fill_stop_path_buffer_from_path finished"); #endif }
/* ------------------------------------------ * p_capture_2_vector_points * ------------------------------------------ * capture the first 2 points of the 1st stroke in the active path vectors */ static void p_capture_2_vector_points(gint32 imageId, PixelCoords *coordPtr, PixelCoords *coordPtr2) { gint32 activeVectorsId; gint32 gx1; gint32 gy1; gint32 gx2; gint32 gy2; gx1 = -1; gy1 = -1; gx2 = -1; gy2 = -1; activeVectorsId = gimp_image_get_active_vectors(imageId); if(activeVectorsId >= 0) { gint num_strokes; gint *strokes; strokes = gimp_vectors_get_strokes (activeVectorsId, &num_strokes); if(strokes) { if(num_strokes > 0) { gdouble *points; gint num_points; gboolean closed; GimpVectorsStrokeType type; points = NULL; type = gimp_vectors_stroke_get_points(activeVectorsId, strokes[0], &num_points, &points, &closed); if(gap_debug) { gint ii; for(ii=0; ii < MIN(12, num_points); ii++) { printf ("point[%d] = %.3f\n", ii, points[ii]); } } if (type == GIMP_VECTORS_STROKE_TYPE_BEZIER) { if(num_points >= 6) { gx1 = points[0]; gy1 = points[1]; } if(num_points >= 12) { gx2 = points[6]; gy2 = points[7]; } } if(points) { g_free(points); } } g_free(strokes); } } coordPtr->valid = FALSE; coordPtr2->valid = FALSE; if((gx1 >= 0) && (gy1 >= 0)) { if(gap_debug) { printf("\nPathPoints: x1=%d; y1=%d x2=%d; y2=%d\n" , gx1 , gy1 , gx2 , gy2 ); } coordPtr->px = gx1; coordPtr->py = gy1; coordPtr->valid = TRUE; if((gx2 != gx1) || (gy2 != gy1)) { if ((gx2 >= 0) && (gy2 >= 0)) { coordPtr2->px = gx2; coordPtr2->py = gy2; coordPtr2->valid = TRUE; } } } } /* end p_capture_2_vector_points */