I'm using path_drawing package to get a path from an SVG in Flutter. After extracting path from SVG Data, it returns it to ClipPath widget which uses that path to clip the Container. After that, I increase the width and height of the Container which doesn't increase the size of SVG.
How do I alter the size of SVG?
import 'package:flutter/material.dart';
import 'package:path_drawing/path_drawing.dart';
void main() => runApp(MaterialApp(
home: MyApp(),
));
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
//Container enclosed in ClipPath which uses Practice Clip as a clipper
child: ClipPath(
clipper: PracticeClip(),
child: Container(
//Container color
color: Colors.red,
//width and height of container
width: 100.0,
height: 100.0,
)),
),
);
}
}
class PracticeClip extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
//parseSvgPathData comes from a package
//Library link: https://pub.dev/packages/path_drawing (Library link)
//parseSvgPathData returns a Path object
//extracting path from SVG data
path = parseSvgPathData(
"M12.007.48C5.391.485.005 5.831 0 12.399v.03l2.042 1.191.028-.019a5.821 5.821 0 0 1 3.308-1.02c.371 0 .734.034 1.086.1l-.036-.006a5.69 5.69 0 0 1 2.874 1.431l-.004-.003.35.326.198-.434c.192-.42.414-.814.66-1.173.099-.144.208-.29.332-.446l.205-.257-.252-.211a8.33 8.33 0 0 0-3.836-1.807l-.052-.008a8.566 8.566 0 0 0-4.081.251l.061-.016c.971-4.257 4.714-7.224 9.133-7.227a9.31 9.31 0 0 1 6.601 2.713 9.197 9.197 0 0 1 2.508 4.499 8.386 8.386 0 0 0-2.498-.379h-.154c-.356.006-.7.033-1.037.078l.045-.005-.042.006a8.104 8.104 0 0 0-.39.06c-.057.01-.114.022-.17.033a8.103 8.103 0 0 0-.392.089l-.138.035a9.21 9.21 0 0 0-.483.144l-.029.01c-.355.12-.709.268-1.051.439l-.027.014c-.152.076-.305.16-.469.256l-.036.022a8.217 8.217 0 0 0-2.108 1.801l-.011.013-.075.092a8.346 8.346 0 0 0-.378.503c-.088.13-.177.269-.288.452l-.06.104a8.986 8.986 0 0 0-.234.432l-.016.029c-.17.341-.317.698-.44 1.063l-.017.053a8.053 8.053 0 0 0-.411 2.717v-.007l.001.112c.006.158.013.295.023.431l-.002-.037a11.677 11.677 0 0 0 .042.412l.005.042.013.103c.018.127.038.252.062.378.241 1.266.845 2.532 1.745 3.66l.041.051.042-.05c.359-.424 1.249-1.77 1.325-2.577l.001-.015-.007-.013a5.56 5.56 0 0 1-.64-2.595v-.001c0-3.016 2.371-5.521 5.397-5.702l.199-.007a5.93 5.93 0 0 1 3.47 1.025l.028.019 2.041-1.187v-.03a11.771 11.771 0 0 0-3.511-8.424A11.963 11.963 0 0 0 12.008.48z");
return path;// path is returned to ClipPath clipper
}
#override
bool shouldReclip(PracticeClip oldClipper) => false;
}
I believe you want to scale the path. Something like:
class PracticeClip extends CustomClipper<Path> {
#override
Path getClip(Size size) {
//parseSvgPathData comes from a package
//Library link: https://pub.dev/packages/path_drawing (Library link)
//parseSvgPathData returns a Path object
//extracting path from SVG data
final Path path = parseSvgPathData(
"M12.007.48C5.391.485.005 5.831 0 12.399v.03l2.042 1.191.028-.019a5.821 5.821 0 0 1 3.308-1.02c.371 0 .734.034 1.086.1l-.036-.006a5.69 5.69 0 0 1 2.874 1.431l-.004-.003.35.326.198-.434c.192-.42.414-.814.66-1.173.099-.144.208-.29.332-.446l.205-.257-.252-.211a8.33 8.33 0 0 0-3.836-1.807l-.052-.008a8.566 8.566 0 0 0-4.081.251l.061-.016c.971-4.257 4.714-7.224 9.133-7.227a9.31 9.31 0 0 1 6.601 2.713 9.197 9.197 0 0 1 2.508 4.499 8.386 8.386 0 0 0-2.498-.379h-.154c-.356.006-.7.033-1.037.078l.045-.005-.042.006a8.104 8.104 0 0 0-.39.06c-.057.01-.114.022-.17.033a8.103 8.103 0 0 0-.392.089l-.138.035a9.21 9.21 0 0 0-.483.144l-.029.01c-.355.12-.709.268-1.051.439l-.027.014c-.152.076-.305.16-.469.256l-.036.022a8.217 8.217 0 0 0-2.108 1.801l-.011.013-.075.092a8.346 8.346 0 0 0-.378.503c-.088.13-.177.269-.288.452l-.06.104a8.986 8.986 0 0 0-.234.432l-.016.029c-.17.341-.317.698-.44 1.063l-.017.053a8.053 8.053 0 0 0-.411 2.717v-.007l.001.112c.006.158.013.295.023.431l-.002-.037a11.677 11.677 0 0 0 .042.412l.005.042.013.103c.018.127.038.252.062.378.241 1.266.845 2.532 1.745 3.66l.041.051.042-.05c.359-.424 1.249-1.77 1.325-2.577l.001-.015-.007-.013a5.56 5.56 0 0 1-.64-2.595v-.001c0-3.016 2.371-5.521 5.397-5.702l.199-.007a5.93 5.93 0 0 1 3.47 1.025l.028.019 2.041-1.187v-.03a11.771 11.771 0 0 0-3.511-8.424A11.963 11.963 0 0 0 12.008.48z");
final Rect pathBounds = path.getBounds();
final Matrix4 matrix4 = Matrix4.identity();
matrix4.scale(size.width / pathBounds.width, size.height / pathBounds.height);
return path.transform(matrix4.storage);// path is returned to ClipPath clipper
}
#override
bool shouldReclip(PracticeClip oldClipper) => false;
}
Should get you started.
Related
I have this shell.nix:
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "env";
nativeBuildInputs = [ pkg-config ];
buildInputs = [
xorg.libX11
xorg.libX11.dev
xorg.libXi
xorg.libXext
libGL
];
}
Then I enter the shell with nix-shell shell.nix and
$ npm install gl
It builds correctly I think.
I have created index.js with example from project's home README
// Create context
var width = 64
var height = 64
var gl = require('gl')(width, height, { preserveDrawingBuffer: true })
//Clear screen to red
gl.clearColor(1, 0, 0, 1)
gl.clear(gl.COLOR_BUFFER_BIT)
//Write output as a PPM formatted image
var pixels = new Uint8Array(width * height * 4)
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
process.stdout.write(['P3\n# gl.ppm\n', width, " ", height, '\n255\n'].join(''))
for(var i = 0; i < pixels.length; i += 4) {
for(var j = 0; j < 3; ++j) {
process.stdout.write(pixels[i + j] + ' ')
}
}
when I run this:
$ node index.js
I got error:
\/home/roman/personal_projects/nixos/nixos-headless-gl-error-no-webgl/index.js:20
gl.clearColor(1, 0, 0, 1)
^
TypeError: Cannot read property 'clearColor' of null
at Object.<anonymous> (/home/roman/personal_projects/nixos/nixos-headless-gl-error-no-webgl/index.js:20:4)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
Works. Now I have run.nix:
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "env";
APPEND_LIBRARY_PATH = "${lib.makeLibraryPath [ libGL libuuid ]}";
shellHook = ''
export LD_LIBRARY_PATH="$APPEND_LIBRARY_PATH:$LD_LIBRARY_PATH"
'';
}
and nix-shell run.nix and
$ nix-shell run.nix
$ echo $LD_LIBRARY_PATH | tr ':' '\n'
/nix/store/hwnjiqml5vvlngdj9nrnwg0qzglhgk2r-util-linux-2.36.2/lib
/nix/store/c35w5n0prvq4v4priyi8fiiq361pmyvp-libGL-1.3.3/lib
/nix/store/a1xkyw98lgj38kymim78a7xjk50wqg6k-telepathy-glib-0.24.2/lib
/nix/store/nzp3cc7bsj83dn23b4vvrvsp9psgg50m-telepathy-logger-0.8.2/lib
$ node index.js
P3
# gl.ppm
64 64
255
255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0
...
I'm trying to write pixel_array data and patientID from multiple Dicom files to a CSV.
The pixel arrays, which are np arrays get saved like this;
[[0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]\n ...\n [0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]]
how do I get back the original np array?
if you could pls give me some advice on writing these properly to CSV so the np arrays are preserved as they are?
Below is the loop
def tryer(a, b):
if b == 'pixel_array':
return(a.pixel_array)
else:
try:
return(getattr(a, b))
except AttributeError:
return('No')
tryer is as defined above;
a_list = ['PatientID', 'pixel_array']
with open('imgs_n_patied_train1.csv', 'w', newline = '') as f:
thewriter = writer(f)
thewriter.writerow(['PatientID', 'pixel_array\n'])
for i in imgs:
#iterating through each file and writing all the metadata to a csv row-wise
a = dicom.read_file(r'pathto\stage_2_train_images' + '\\' + i, force = True)
app = []
for j in a_list:
app.append(tryy.tryer(a, j))
thewriter.writerow(app)
I am using choco to solve a CSP , and one of my constraints is that the sum of one variables (X[i][j]) is less than N=10, and i=j=1....N.
How do I accomplish this? thank you for your help.
sum(X[i][j]) = 1 for i=j=1....N
You need a 1d array and call model.sum():
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.variables.BoolVar;
public class SumBooleans {
private final static int N = 10;
public static void main(String[] args) {
Model model = new Model("Boolean sum");
BoolVar[][] vars = new BoolVar[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
vars[i][j] = model.boolVar("vars[" + i + "][" + j + "]");
}
}
BoolVar[] flatArray = new BoolVar[N * N];
for (int index = 0; index < N * N; index++) {
int i = index / N;
int j = index % N;
flatArray[index] = vars[i][j];
}
model.sum(flatArray, "=", 1).post();
//model.sum(flatArray, "<", N).post();
//model.sum(flatArray, ">=", 8).post();
Solver solver = model.getSolver();
if (solver.solve()) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
System.out.print(vars[i][j].getValue() + " ");
}
System.out.println();
}
}
}
}
Output:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Running uWSGI with
$ cat /etc/uwsgi/uwsgi.cfg
[uwsgi]
callable = app
socket = /var/run/arivale-service/uwsgi.sock
chmod-socket = 666
pidfile = /var/run/arivale-service/uwsgi.pid
master = true
enable-threads = true
single-interpreter = true
thunder-lock
need-app
processes = 4
Without lazy-apps enabled, a request to the calling following endpoint hangs
import boto3
# ...irrelevant imports
from multiprocessing.dummy import Pool as ThreadPool
POOL = ThreadPool(6)
# ...irrelevant setup
def get_ecs_task_definitions(service_name):
ecs_service_name, _ = get_ecs_service_name_and_cluster(service_name)
def get_task_definition(task_definition_arn):
formatted_task_definition = {}
task_definition = ECS.describe_task_definition(taskDefinition=task_definition_arn)['taskDefinition']
# ...
# build formatted_task_definition from task_definition
# ...
return formatted_task_definition
task_definition_arns = ECS.list_task_definitions(
familyPrefix=ecs_service_name, status='ACTIVE')['taskDefinitionArns']
return POOL.map(get_task_definition, task_definition_arns)
#service.api('/api/services/<service_name>/ecs/task-definitions')
def get_task_definitions(service_name):
return {'service_name': service_name, 'task_definitions': get_ecs_task_definitions(service_name)}
NGINX is balancing uWSGI apps, and this is what it says in error.log (NGINX):
Jun 10 03:54:26 93e04e04e2cf nginx_error: 2017/06/10 03:54:26 [error] 49#49: *33 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 172.16.254.95, server: localhost, request: "GET /api/services/data-analysis-service/ecs/task-definitions HTTP/1.1",upstream: "uwsgi://unix:/var/run/arivale-service/uwsgi.sock", host: "devops-service.arivale.com"
Each request to the endpoint hangs a worker (below is the output of uwsgitop after 2 requests):
uwsgi-2.0.15 - Sat Jun 10 21:26:10 2017 - req: 0 - RPS: 0 - lq: 0 - tx: 0
node: localhost - cwd: /var/www/arivale-service/web - uid: 0 - gid: 0 - masterpid: 45
WID % PID REQ RPS EXC SIG STATUS AVG RSS VSZ TX ReSpwn HC RunT LastSpwn
1 0.0 74 0 0 0 0 busy 0ms 0 0 0 1 0 0 21:23:20
2 0.0 75 0 0 0 0 busy 0ms 0 0 0 1 0 0 21:23:20
3 0.0 76 0 0 0 0 idle 0ms 0 0 0 1 0 0 21:23:20
4 0.0 77 0 0 0 0 idle 0ms 0 0 0 1 0 0 21:23:20
Enabling lazy-apps fixes the issue. Does anyone know with certainty why?
This happened because uWSGI workers were unable to access the thread pool created in the master, see https://stackoverflow.com/a/39890941/2419669.
Using #postfork fixes this:
global THREAD_POOL = None
#postfork
def _make_thread_pool():
global THREAD_POOL
THREAD_POOL = ThreadPool(8)
I have connected a MCP23017 I2C GPIO Expander chip to RPi. I use the this device driver and the mcp23017.dtbo overlay file.
I am trying to check the interrupt handling with the gpio pins. I did the following to connect the pins to interrupt(496 is the base which is GPA0 of MCP23017):
echo "496" > /sys/class/gpio/export
echo "both" > /sys/class/gpio/gpio496/edge
and then to trigger:
cat gpio496/value
But when i check /proc/interrupts it always shows 0 interrupts:
root#raspberrypi:/sys/class/gpio# cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
16: 0 0 0 0 bcm2836-timer 0 Edge arch_timer
17: 41827 52799 8260 86838 bcm2836-timer 1 Edge arch_timer
23: 67 0 0 0 ARMCTRL-level 1 Edge 3f00b880.mailbox
24: 248 0 0 0 ARMCTRL-level 2 Edge VCHIQ doorbell
46: 0 0 0 0 ARMCTRL-level 48 Edge bcm2708_fb dma
48: 4125 0 0 0 ARMCTRL-level 50 Edge DMA IRQ
50: 0 0 0 0 ARMCTRL-level 52 Edge DMA IRQ
62: 415706 0 0 0 ARMCTRL-level 64 Edge dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
79: 0 0 0 0 ARMCTRL-level 81 Edge 3f200000.gpio:bank0
80: 0 0 0 0 ARMCTRL-level 82 Edge 3f200000.gpio:bank1
83: 945 0 0 0 ARMCTRL-level 85 Edge 3f804000.i2c
86: 502 0 0 0 ARMCTRL-level 88 Edge mmc0
87: 5032 0 0 0 ARMCTRL-level 89 Edge uart-pl011
92: 6828 0 0 0 ARMCTRL-level 94 Edge mmc1
170: 0 0 0 0 pinctrl-bcm2835 4 Edge 1-0020, 1-0021, 1-0022, 1-0023
220: 0 0 0 0 gpio-mcp23xxx 0 Edge gpiolib
Also, when the overlay is loaded, the probe funtion is called and i get the following message:
genirq: irq 170 uses trigger mode 8; requested 2
I could not figure out the problem. I am not sure if there is something wrong in the overlay file. Below is the .dts overlay file:
// Definitions for MCP23017 Gpio Extender from Microchip Semiconductor
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment#0 {
target = <&i2c1>;
__overlay__ {
status = "okay";
};
};
fragment#1 {
target = <&gpio>;
__overlay__ {
mcp23017_pins: mcp23017_pins {
brcm,pins = <4>;
brcm,function = <0>;
};
};
};
fragment#2 {
target = <&i2c1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
mcp20:mcp23017#20 {
compatible = "microchip,mcp23017";
reg = <0x20>;
gpio-controller;
#gpio-cells = <2>;
interrupt-parent = <&gpio>;
interrupts = <4 2>;
interrupt-controller;
#interrupt-cells=<2>;
microchip,irq-mirror;
status = "okay";
};
};
};
__overrides__ {
gpiopin = <&mcp23017_pins>,"brcm,pins:0",
<&mcp20>,"interrupts:0";
addr = <&mcp20>,"reg:0";
};
};