Ejemplo n.º 1
0
static PyObject*
memoryview_get_extents_info(PyObject *self, PyObject *args)
{
    int i;
    Py_ssize_t *shape_ary = NULL;
    Py_ssize_t *strides_ary = NULL;
    PyObject *shape_tuple = NULL;
    PyObject *strides_tuple = NULL;
    PyObject *shape = NULL, *strides = NULL;
    Py_ssize_t itemsize = 0;
    int ndim = 0;
    PyObject* res = NULL;

    if (!PyArg_ParseTuple(args, "OOin", &shape, &strides, &ndim, &itemsize))
        goto cleanup;

    if (ndim < 0) {
        PyErr_SetString(PyExc_ValueError, "ndim is negative");
        goto cleanup;
    }

    if (itemsize <= 0) {
        PyErr_SetString(PyExc_ValueError, "ndim <= 0");
        goto cleanup;
    }

    shape_ary = malloc(sizeof(Py_ssize_t) * ndim + 1);
    strides_ary = malloc(sizeof(Py_ssize_t) * ndim + 1);

    shape_tuple = PySequence_Fast(shape, "shape is not a sequence");
    if (!shape_tuple) goto cleanup;

    for (i = 0; i < ndim; ++i) {
        shape_ary[i] = PyNumber_AsSsize_t(
                           PySequence_Fast_GET_ITEM(shape_tuple, i),
                           PyExc_OverflowError);
    }

    strides_tuple = PySequence_Fast(strides, "strides is not a sequence");
    if (!strides_tuple) goto cleanup;

    for (i = 0; i < ndim; ++i) {
        strides_ary[i] = PyNumber_AsSsize_t(
                           PySequence_Fast_GET_ITEM(strides_tuple, i),
                           PyExc_OverflowError);
    }

    res = get_extents(shape_ary, strides_ary, ndim, itemsize, 0);
cleanup:
    free(shape_ary);
    free(strides_ary);
    Py_XDECREF(shape_tuple);
    Py_XDECREF(strides_tuple);
    return res;
}
Ejemplo n.º 2
0
void
offset2(const Slic3r::Polygons &polygons, ClipperLib::Paths* retval, const float delta1,
    const float delta2, const ClipperLib::JoinType joinType, const double miterLimit)
{
    if (delta1 * delta2 >= 0) {
        // Both deltas are the same signum
        offset(polygons, retval, delta1 + delta2, joinType, miterLimit);
        return;
    }
#ifdef CLIPPER_UTILS_DEBUG
    BoundingBox bbox = get_extents(polygons);
    coordf_t stroke_width = scale_(0.005);
    static int iRun = 0;
    ++ iRun;
    bool flipY = false;
    SVG svg(debug_out_path("offset2-%d.svg", iRun), bbox, scale_(1.), flipY);
    for (Slic3r::Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++ it)
        svg.draw(it->lines(), "gray", stroke_width);
#endif /* CLIPPER_UTILS_DEBUG */

    // read input
    ClipperLib::Paths input;
    Slic3rMultiPoints_to_ClipperPaths(polygons, &input);
    
    // scale input
    scaleClipperPolygons(input);
    
    // prepare ClipperOffset object
    ClipperLib::ClipperOffset co;
    if (joinType == jtRound) {
        co.ArcTolerance = miterLimit * double(CLIPPER_OFFSET_SCALE);
    } else {
        co.MiterLimit = miterLimit;
    }
    
    // perform first offset
    ClipperLib::Paths output1;
    co.AddPaths(input, joinType, ClipperLib::etClosedPolygon);
    co.Execute(output1, delta1 * float(CLIPPER_OFFSET_SCALE));
#ifdef CLIPPER_UTILS_DEBUG
    svg.draw(output1, 1. / double(CLIPPER_OFFSET_SCALE), "red", stroke_width);
#endif /* CLIPPER_UTILS_DEBUG */
    
    // perform second offset
    co.Clear();
    co.AddPaths(output1, joinType, ClipperLib::etClosedPolygon);
    co.Execute(*retval, delta2 * float(CLIPPER_OFFSET_SCALE));
#ifdef CLIPPER_UTILS_DEBUG
    svg.draw(*retval, 1. / double(CLIPPER_OFFSET_SCALE), "green", stroke_width);
#endif /* CLIPPER_UTILS_DEBUG */

    // unscale output
    unscaleClipperPolygons(*retval);
}
//*********************************my_atk_text_get_character_extents*****************
void my_atk_text_get_character_extents(AtkText* text, gint offset, gint *x, gint *y,
    gint *width, gint *height, AtkCoordType coord_type)
{
    AtkTextRectangle result;
    gint relative_offset, line;
    line = get_character_line((MyAtkText*)text, offset, &relative_offset);
    get_extents((MyAtkText*)text, line, relative_offset, &result);
    *x = result.x;
    *y = result.y;
    *width = result.width;
    *height = result.height;
}
Ejemplo n.º 4
0
void SVG::export_expolygons(const char *path, const std::vector<std::pair<Slic3r::ExPolygons, ExPolygonAttributes>> &expolygons_with_attributes)
{
    if (expolygons_with_attributes.empty())
        return;

    BoundingBox bbox = get_extents(expolygons_with_attributes.front().first);
    for (size_t i = 0; i < expolygons_with_attributes.size(); ++ i)
        bbox.merge(get_extents(expolygons_with_attributes[i].first));

    SVG svg(path, bbox);
    for (const auto &exp_with_attr : expolygons_with_attributes)
        svg.draw(exp_with_attr.first, exp_with_attr.second.color_fill, exp_with_attr.second.fill_opacity);
    for (const auto &exp_with_attr : expolygons_with_attributes) {
        std::string color_contour = exp_with_attr.second.color_contour;
        if (color_contour.empty())
            color_contour = exp_with_attr.second.color_fill;
        std::string color_holes = exp_with_attr.second.color_holes;
        if (color_holes.empty())
            color_holes = color_contour;
        svg.draw_outline(exp_with_attr.first, color_contour, color_holes, exp_with_attr.second.outline_width);
    }
    svg.Close();
}
Ejemplo n.º 5
0
Vector<Vector3> BoxShape::_gen_debug_mesh_lines() {


	Vector<Vector3> lines;
	AABB aabb;
	aabb.pos=-get_extents();
	aabb.size=aabb.pos*-2;

	for(int i=0;i<12;i++) {
		Vector3 a,b;
		aabb.get_edge(i,a,b);
		lines.push_back(a);
		lines.push_back(b);
	}


	return lines;
}
Ejemplo n.º 6
0
void Layer::export_region_fill_surfaces_to_svg(const char *path) const
{
    BoundingBox bbox;
    for (const auto *region : m_regions)
        for (const auto &surface : region->slices.surfaces)
            bbox.merge(get_extents(surface.expolygon));
    Point legend_size = export_surface_type_legend_to_svg_box_size();
    Point legend_pos(bbox.min(0), bbox.max(1));
    bbox.merge(Point(std::max(bbox.min(0) + legend_size(0), bbox.max(0)), bbox.max(1) + legend_size(1)));

    SVG svg(path, bbox);
    const float transparency = 0.5f;
    for (const auto *region : m_regions)
        for (const auto &surface : region->slices.surfaces)
            svg.draw(surface.expolygon, surface_type_to_color_name(surface.surface_type), transparency);
    export_surface_type_legend_to_svg(svg, legend_pos);
    svg.Close();
}
Ejemplo n.º 7
0
void SurfaceCollection::export_to_svg(const char *path, bool show_labels) 
{
    BoundingBox bbox;
    for (Surfaces::const_iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface)
        bbox.merge(get_extents(surface->expolygon));
    Point legend_size = export_surface_type_legend_to_svg_box_size();
    Point legend_pos(bbox.min.x, bbox.max.y);
    bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y));

    SVG svg(path, bbox);
    const float transparency = 0.5f;
    for (Surfaces::const_iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) {
        svg.draw(surface->expolygon, surface_type_to_color_name(surface->surface_type), transparency);
        if (show_labels) {
            int idx = int(surface - this->surfaces.begin());
            char label[64];
            sprintf(label, "%d", idx);
            svg.draw_text(surface->expolygon.contour.points.front(), label, "black");
        }
    }
    export_surface_type_legend_to_svg(svg, legend_pos);
    svg.Close();
}
Ejemplo n.º 8
0
static PyObject*
memoryview_get_extents(PyObject *self, PyObject *args)
{
    PyObject *obj = NULL;
    PyObject *ret = NULL;
    Py_buffer b;
    const void * ptr = NULL;
    Py_ssize_t bufptr, buflen;
    if (!PyArg_ParseTuple(args, "O", &obj))
        return NULL;

    if (!get_buffer(obj, &b, 0)) { /* new buffer api */
        ret = get_extents(b.shape, b.strides, b.ndim, b.itemsize,
                          (Py_ssize_t)b.buf);
        free_buffer(&b);
    } else { /* old buffer api */
        PyErr_Clear();
        if (-1 == PyObject_AsReadBuffer(obj, &ptr, &buflen)) return NULL;
        bufptr = (Py_ssize_t)ptr;
        ret = Py_BuildValue("nn", bufptr, bufptr + buflen);
    }
    return ret;
}
Ejemplo n.º 9
0
 static void export_expolygons(const std::string &path, const Slic3r::ExPolygons &expolygons, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0) 
     { export_expolygons(path.c_str(), get_extents(expolygons), expolygons, stroke_outer, stroke_holes, stroke_width); }
Ejemplo n.º 10
0
/* this is the intersection of mem_regions */
vector<mem_regions_t *> merge_instrace_and_dump_regions(vector<mem_regions_t *> &total_regions, 
	vector<mem_info_t *> mem_info, vector<mem_regions_t *> mem_regions){

	vector<mem_regions_t *> final_regions;

	DEBUG_PRINT(("merge_instrace_and_dump_regions...\n"), 2);

	bool * merged_mem_info = new bool[mem_info.size()];
	for (int i = 0; i < mem_info.size(); i++){
		merged_mem_info[i] = false;
	}

	/* mem regions are from dumps and check whether they overlap with instrace regions */
	for (int i = 0; i < mem_regions.size(); i++){
		for (int j = 0; j < mem_info.size(); j++){
			if (is_overlapped(mem_regions[i]->start,mem_regions[i]->end,mem_info[j]->start,mem_info[j]->end)){

				merged_mem_info[j] = true;
				mem_regions[i]->type = 0;


				if ((mem_info[j]->direction  & MEM_INPUT) == MEM_INPUT){ cout << "image input" << endl;  mem_regions[i]->type |= IMAGE_INPUT; }
				if ((mem_info[j]->direction & MEM_OUTPUT) == MEM_OUTPUT){ cout << "image output" << endl;  mem_regions[i]->type |= IMAGE_OUTPUT; }

				/* debug information about the merging */
				if (debug && debug_level >= 2){
					cout << "mem region:" << endl;
					cout << "start : " << hex << mem_regions[i]->start << " end : " << mem_regions[i]->end << endl;
					cout << dec << "strides : ";
					for (int k = 0; k < mem_regions[i]->dimensions; k++) cout << mem_regions[i]->strides[k] << ",";
					cout << endl;
					cout << "mem instrace:" << endl;
					cout << "start : " << hex << mem_info[j]->start << " end : " << mem_info[j]->end << endl;

				}


				/* ok if the memory region is completely contained in the region constructed by meminfo */
				if ( (mem_regions[i]->start >= mem_info[j]->start) && (mem_regions[i]->end <= mem_info[j]->end) ){
				
					/* how much to the left of start is the meminfo spread? */
					uint64_t start = mem_regions[i]->start;
					vector<uint32_t> left_spread;
					for (int k = mem_regions[i]->dimensions - 1; k >= 0; k--){
						uint32_t spread = (start - mem_info[j]->start) / mem_regions[i]->strides[k];
						start = mem_regions[i]->start - spread * mem_regions[i]->strides[k];
						left_spread.push_back(spread);
					}

					/* printing out the spreads */
					cout << dec << "left spread: "; 
					for (int k = 0; k < left_spread.size(); k++){
						cout << left_spread[k] << ",";
					}
					cout << endl;

					/* how much to the right of the end of the meminfo are we spread? */
					uint64_t end = mem_regions[i]->end;
					vector<uint32_t> right_spread;
					for (int k = mem_regions[i]->dimensions - 1; k >= 0; k--){
						uint32_t spread = (mem_info[j]->end - end) / mem_regions[i]->strides[k];
						end = mem_regions[i]->end + spread * mem_regions[i]->strides[k];
						right_spread.push_back(spread);
					}

					/* printing out the spreads */
					cout << "right spread: ";
					for (int k = 0; k < right_spread.size(); k++){
						cout << right_spread[k] << ",";
					}
					cout << endl;

					cout << "--------------------------" << endl;

					mem_regions[i]->start = mem_info[j]->start;
					mem_regions[i]->end = mem_info[j]->end;

				}

				final_regions.push_back(mem_regions[i]);
				total_regions.push_back(mem_regions[i]);
				break;

			}
		}
	}

	/* create new mem_regions for the remaining mem_info which of type MEM_HEAP - postpone the implementation; these are intermediate nodes */
	for (int i = 0; i < mem_info.size(); i++){
		if (merged_mem_info[i] == false){ /* if not merged */
			if (mem_info[i]->type = MEM_HEAP_TYPE){
				mem_regions_t * mem = new mem_regions_t;

				mem->start = mem_info[i]->start;
				mem->end = mem_info[i]->end;
				mem->dimensions = get_number_dimensions(mem_info[i]); /* we don't know the dimensions of this yet */
				mem->bytes_per_pixel = mem_info[i]->prob_stride;
				for (int j = 1; j <= mem->dimensions; j++){
					mem->strides[j - 1] = get_stride(mem_info[i], j, mem->dimensions);
					mem->extents[j - 1] = get_extents(mem_info[i], j, mem->dimensions);
				}
				//mem->strides[0] = mem_info[i]->prob_stride;
				//mem->extents[0] = (mem->end - mem->start + 1)/ mem->strides[0];
				mem->padding_filled = 0;
				
				mem->type = 0;
				if ((mem_info[i]->direction  & MEM_INPUT) == MEM_INPUT){ mem->type |= IMAGE_INPUT; }
				if ((mem_info[i]->direction & MEM_OUTPUT) == MEM_OUTPUT){ mem->type |= IMAGE_OUTPUT; }

				total_regions.push_back(mem);
				
			}
		}
	}


	/* naming the memory regions */
	int inputs = 0;
	int intermediates = 0;
	int outputs = 0;

	for (int i = 0; i < total_regions.size(); i++){
		if (total_regions[i]->type == IMAGE_INPUT){
			total_regions[i]->name = "input_" + to_string(++inputs);
		}
		else if (total_regions[i]->type == IMAGE_OUTPUT){
			total_regions[i]->name = "output_" + to_string(++outputs);
		}
		else if (total_regions[i]->type == IMAGE_INTERMEDIATE){
			total_regions[i]->name = "inter_" + to_string(++intermediates);
		}
	}


	DEBUG_PRINT((" no of image mem regions after merging - %d\n", final_regions.size()), 2);
	DEBUG_PRINT((" total number of mem regions (from instrace) - %d\n", total_regions.size()), 2);

	DEBUG_PRINT((" merge_instrace_and_dump_regions - done\n"), 2);

	return final_regions;
}