Custom line caps? - actionscript-3

As in this adobe documentation, there is only three types of caps for drawing lines:
square, round, none.
Isn't there a custom shape for caps style? anyone knows? : )

There's only 3 types of CapsStyle available in actionscript-3.
However if you want another types of CapsStyle you have to extend a class where you want to implement.
For example if you want to implement on graphics.lineTo() function then you have to extend graphics class to your own yourgraphics class and override the lineTo method and add another capsstyle type.
Pretty much complex I guess.

Related

Detectron2 Mask-Rcnn keep same color segmentation for same object class

I am using detectron2 implementation of Mask-Rcnn on video, the problem is that on each frame, the segmentation color of a same object change.
Is there any parameter that can allow me to keep a single color for an object class.
I already tried detectron2.utils.visualizer.ColorMode(1) and it doesn't work
ColorMode(1) only has an effect if the metadata passed to the Visualizer has thing_colors defined. From the documentation for ColorMode,
SEGMENTATION= 1
Let instances of the same category have similar colors
(from metadata.thing_colors), and overlay them with high opacity. This
provides more attention on the quality of segmentation.
So, you need to add a list of pre-defined colors (one for each class) to your metadata. From here,
thing_colors (list[tuple(r, g, b)]): Pre-defined color (in [0, 255]) for each thing category. Used for visualization. If not given, random colors will be used.
Now, the actual colors used may not be the exact same ones as specified in thing_colors. In Visualizer.draw_instance_predictions(), each specified color is jittered by adding a random value to it, so the overlaid color is a slightly different one. This use of a random value means that you will still see class colors change between frames. Depending on the colors you specify, this change may or may not be visually obvious.
A simple solution to this might be to subclass Visualizer and override the _jitter() method so that it returns the color as is.
class MyVisualizer(Visualizer):
def _jitter(self, color):
return color
However, _jitter() is intended to be an internal method, so this is a hacky solution, and might break sometime down the line.
A better solution might be to override draw_instance_predictions() and customize the drawing to your needs.
Try to add the following lines
from detectron2.utils.visualizer import Visualizer , GenericMask , ColorMode
MetadataCatalog.get(cfg.DATASETS.TRAIN[0]).thing_classes = clss
MetadataCatalog.get(cfg.DATASETS.TRAIN[0]).thing_colors = [(255,255,0),(0,0,255),(0,255,0),(255,0,255),(156,225,242)]
class MyVisualizer(Visualizer):
def _jitter(self, color ):
return color
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2,instance_mode=ColorMode.SEGMENTATION)
v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
img = cv2.resize(v.get_image()[:, :, ::-1], (1220, 780))

POO Propperty getter / setter vs Function (Theory)

So if a getter is finally a function, why not use just a function? I guess to enforce using that function to set/get a value any time needed, any other reason?
A getter is a function (as far as POO languages I know).
The idea is to delegate the ability to modify or to get an attribute to only one function by class, in case of there were special checks to perform before applying the getter or setter.
Properties are used just to improve readability or ease the API, without breaking encapsulation. For example, if you have a Rectangle class and you want to increase by 10 the width of an instance, without properties, you would do something like:
rect.setWidth(rect.getWidth() + 10)
While, using properties, you could just write:
rect.width += 10
Which is clearer. And because properties are functions, you can do all the checks that you need. Moreover, it doesn't even matter if the width is actually stored in the class; maybe the rectangle is stored as a pair of points (i.e. upper-left and lower-right), but the property would handle it. Additionally, you could write properties that access the same data in different ways: for example, you could have width, height, top, bottom, left and right properties, and all of them would affect the same internal data of the class, but would make it easier to use and more readable.

LibGDX - Dynamically change particle emitter's Atlas Region?

Is it possible to dynamically change the Atlas Region used by a particle emitter?
I've tried...
effect.getEmitters().get(0).setImagePath("[someAtlasRegionName]");
...but it continues to use the original region the effect was loaded with.
There appears to be a .setSprite(Sprite) method but it doesn't work with TextureAtlas.
Thanks.
Editing the Sprite's fields to set it to the TextureRegion works (Sprite extends TextureRegion, so it has all the relevant fields):
Sprite s = effect.getEmitters().get(0).getSprite();
s.setTexture(vessel.getTexture());
s.setU (someAtlasRegion.getU());
s.setU2(someAtlasRegion.getU2());
s.setV (someAtlasRegion.getV());
s.setV2(someAtlasRegion.getV2());
effect.getEmitters.get(0).setImagePath(someRegionName);
Edit: I don't know if ParticleEmitter.setImagePath() matters or not, but I'd include that as well just in case - it definitely won't hurt. So I added that as well.

fancy tooltips in Swing

I have a JTable that I would like to display a fancy tooltip (basically a JTextArea) for particular cells in a column. I am using a custom cell renderer, so it would be easy if I could figure out how to popup a window when I hover over the cell renderer's component.
Are there any examples of how to do this?
You can use HTML in tooltips, if you use the <html> and </html> tags around the content.
Use HTML to format the tooltip. Using colored (<font>) and multi-line (<br>) tooltips is now easy.
Creating and overwriting the default JToolTip is a bit harder. Every component has a JToolTip instance and you can retrieve this one with JComponent.createToolTip(). To create a custom tooltip, extend the cell renderer and override it's createToolTip to implement your custom functionality (return a custom extended version of JToolTip).
I'm not sure I totally am clear on what sort of customizations specifically you're hoping to do, so I'll be general here.
There is a class, UIManager, that controls the look and feel of components, including the swing ToolTip class. The simple way to make an easy change is to call a method in UIManager to set properties for the tooltips. Doing this you could do things like use BorderFactory to add a decorative border, or change the background color, etc.
Here are some examples of changing some of these properties:
UIManager.put("ToolTip.background", new ColorUIResource(255, 247, 200)); // The color is #fff7c8.
Border border = BorderFactory.createLineBorder(new Color(76,79,83)); // The color is #4c4f53.
UIManager.put("ToolTip.border", border);
ToolTipManager.sharedInstance().setDismissDelay(15000);// 15 seconds
If you want to change a whole bunch of things about their look and feel, it is better to extend your current look and feel with a class implementing custom tooltip look and feel. A full example of this can be found in this blog post by a former Sun developer.
You might also have a look at this Stack Overflow question on how to set the insets on a tooltip.

AS3 Custom Depth Control

I am trying to create a way of controlling movieclip depths, which movieclip is show above another, so that I can set the depth of a movieclip to any number and they will be displayed with higher values above lower values.
I was thinking of creating a MovieClipDepth class that extends MovieClip with the added property depth, and a Container class that extends DisplayObjectContainer which all objects will be placed inside of.
The Container class will override the addChild method to update the child display order when a child is added.
What I need help with is how do I reorder the children according to
their depth value?
As you can read in the comment below your question, there are several methods for this.
But actually, what you asked "set the depth of a movieclip to any number" can't really be done in AS3. If i'm correct, you could do this in AS2, so...
... how was it ...
_root.createEmptyMovieClip("mc", -1000);
or
_root.createEmptyMovieClip("mc1", 1);
_root.createEmptyMovieClip("mc2", 10);
worked, but does not work in AS3. In AS3 depth starts with 0 and you can't force a DisplayObject to sit on a level what is not continous from zero.
So the depths' of 3 movieclips in a container is only possible with these values: 0, 1, 2.
Depth can't be a negative number for example.
Now, if you want to build a custom depth manager, you can do that, but you have to consider these facts.
So to say, you could create virtual depths.
So I guess, you could override the addChildAt method for example. At the moment, if you would give a wrong number: negative, or higher then the number of children, flash would give back the error:
RangeError: Error #2006: The supplied index is out of bounds.
So mc.addChildAt(newchild, -1000) gives an arror.
But with overriding the method, you could make a trick, so you could store the depths in an array. You could store any numbers and then transform that order for the needs of AS3.
Like pairing the depths with the added children, sorting the array by the depths, then manage the children according to the order.
If you have more questions, feel free to ask, hope this gets you closer to the solution.
I suggest you take a look at this tutorial :
A Tour of Depths Management Methods on the website http://www.flashandmath.com/. I presume you not a newbie .
The link is this:
http://www.flashandmath.com/intermediate/depths/index.html