How to scale an object based off of Text size and length in Unreal? - unreal-engine4

This maybe an easy question maybe not. Essentially, I am creating a VR application and I am also making a 3D UI system for it. I have the basics of creating a 3D button and clicking it done already. What I want to do now is scale my button in order to fit my custom text inside of it. Is there a way to automatically scale the object based off of the size of another? I'll attach some pictures to maybe describe the problem and what I want to accomplish.
Currently,
What I want to happen in something like the ConstructionScript:

https://api.unrealengine.com/INT/BlueprintAPI/Widget/GetDesiredSize/index.html
Try something like this , you call if from text variable, it return struct with X and Y float , hope it may give u starting point.
Edit :
You can get Text render TextlocalSize or TextworldSize .

Related

Visio shape drop size

I have custom stencils, and the shapes are all sized relative to each other. I want to know if there is a way to change the size that they drop onto the page? So if I set the multiplier to 1.5 then every shape will drop onto the page 1.5x larger than the master shape specifies. I don't want to have to resize later.
you could use the ondrop cell of the shapesheet.
setf(getref(width), width.thepage!prop.scale)+setf(getref(height), height.thepage!prop.scale)
I wonder however if you wouldn't go better by modifiying the scale of your page directly?

matlab preview of live video and a circle reference at the centre of frame

I have used matlab's preview window in the following syntax:
figure('Name', 'My Custom Preview Window');uicontrol('String', 'Close', 'Callback', 'close(gcf)');
I am able to successfully get the video stream. Now I want to have a small circle as a region of interest to return the average pixel value within this circle. I want this to be stored and named after a click of a button and recalled later for the further processing.
Could anyone guide me where I can start with?
Please note I dont want user to define ROI instead its always fixed as a small circle at the centre of field view. Whatever the colours comes within the circle I want mean values to be calculated and stored as a reference.
Ps: I am not sure I am correct in calling ROI its simple circle in the field view
You might want to try using a Matlab gui instead of a simple figure. Then you could try something like this.

Get image width and height in pixels

so i have looked at a couple other questions like this and from what i saw none of the answers seemed to answer my question. I created a program that creates ASCII art, which is basically a picture of text instead of colors. the way i have the program set up at the moment you have to manually set the Width and Height of the pixels. If the width and height of the pixels is too large it simply wont work. so basically what i want to do is have a function to automatically set the width and height to the size of the picture. http://www.mediafire.com/?3nb8jfb8bhj8d is the link to the program now. I looked into pixel grabber but the constructor methods all needed a range of pixels. I also have another folder for the classes, http://www.mediafire.com/?2u7qt21xhbwtp
on another note this program is incredibly inefficient, i know that it is inefficient in the grayscaleValue() method, but i dont know if there is any better way to do this. Any suggestions on this program would be awesome too. Thanks in advance! (this program was all done on eclipse)
After you read the image into your BufferedImage, you can call getWidth() and getHeight() on it to get this information dynamically. See the JavaDocs. Also, Use a constructor for GetPixelColor to create the BufferedImage once and for all. This will avoid reading the entire file from disk for each channel of each pixel.
For further code clean up, change series of if statements to a switch construct, or an index into an array, whichever is more natural. See this for an explanation of the switch construct.
One last comment: anything inside a class that logically represents the state of an object should be declared non static. If, say, you wanted to render two images side by side, you would need to create to instances if GetPixelColor, and each one should have its own height and width attributes. Since they're currently declared static, each instance would be sharing the same data, which is clearly not desireable behavior.

Object detection in matlab

I want to write a code in matlab in which i would like to detect color objects in a given image and return the result as found the custom image or not found. i have an image of the custom object separately. im new to matlab... can anyone tell me how to proceed...
i have a pre defined image of an object say an lcd tv.... a given image which may or may not contain the object in it. i need a method to chek and find if the pre defined image is present or not in the given image... is it possible in matlab?
The I suggest you start researching. Stack Overflow is not a great place to ask such generalized questions.
1) Anything that you can do in any programming language is possible in matlab, you are limited by three things:
a) How fast do you want it to work
b) how much coding do you want to do
c) how much of your memory is matlab going to eatup
2) If I am understanding your question correctly you are: Looking to match an image that is fit inside a larger image
Solution: shift your image across the other image, calulate the difference between all the pixels. The set of pixels that is closest to your desired image should be zero.

how to efficiently find a rect # some x,y point with iphone sdk

I am looking for an efficient way to handle the image/frame detection from touch methods. Let's say i am building a keyboard or similar to this. I have 'n' number of images placed on the UI. When someone touches an alphabet (which is an image), i can do the following to detect the corresponding letter
1) CGRectIntersectsRect(..,..) : if i use this, then i need to check each & every letter to find out what letter exists at that touch point (let's say 100,100). This becomes O(n). If i move my finger accross the screen, then i will get m points & all corresponding image detection becomes O(n*m) which is not good.
2) Other way is building a hash for each & every x,y position so that the look up will be simply O(1). But again this will be a memory constraint as i need to store 300*300 ( assuming i am using 300*300 screen size). if i reshuffle my letters, then everything needs to calculated again. So this is not good
In other words, i need some thing like , given a point (x,y), i need some way of finding which rectangle is covering that point efficiently.
Sorry for long post & any help would be grateful.
Thanks
If there are in a regular grid, then integer division by the grid size. Assuming you've a small, fixed screen size, a bucket array gives as similar gain ( a 2D grid, where each entry is a list of the rectangles which intersect that part of the grid ) is very fast if tuned correctly so the lists only have a few members. For unbounded or large spaces, KD trees can be used.
It's useful to have the rects you want as final targets set up as subviews as a larger UIView (or subclass) where you expect all these related hits to occur. For example, if you're building your own keyboard, you could add a bunch of UIButton objects as subviews and hit test those.
So, the easy and traditional way of hit testing a bunch of subviews is to simply have code triggered by someone hitting those buttons. For example, you could add the subviews as UIControl objects (which is a subclass of UIView that adds some useful methods for catching user touch events), and call addTarget:action:forControlEvents: to specify some method to be triggered when the user does something in the rect of that UIControl. For example, you can catch things like UIControlEventTouchDown or UIControlEventTouchDragEnter. You can read the complete list in the UIControl class reference.
Now, it sounds like you might be going for something even more customized. If you really want to start with a random (x,y) coordinate and know which rect it's in, you can also use the hitTest:withEvent: method of UIView. This method takes a point in a view, and finds the most detailed (lowest in the hierarchy) subview which contains that point.
If you want to use these subviews purely for hit testing and not for displaying, then you can set their background color to [UIColor clearColor], but don't hide them (i.e. set the hidden property to YES), disable user interaction with them (via the userInteractionEnabled BOOL property), or set the alpha below 0.1, since any of those things will cause the hitTest:withEvent: method to skip over that subview. But you can still use an invisible subview with this method call, as long as it meets these criteria.
Look at UIView's tag property. If your images are in UIViews or subviews of UIView, then you can set each tag and use the tag to look up in an array.
If not, then you can improve the speed by dividing your array of rectangles into sets that fit into larger rectangles. Test the outer rectangles first, then the inner rectangles. 25 rectangles would need only 10 tests worst case as 5 sets of 5.
Thanks Pete Kirkham & Tyler for your answers which are really helpful. Lets say i dont wanna use buttons as i am mainly displaying images as a small rectangles. To check for the rect # (x,y) , i can trigger that easily by making my grid as a square & finding
gridcolumn = Math.floor(pos.x / cellwidth); gridrow = Math.floor(pos.y / cellheight);
But my problem is with touchesMoved. Lets say i started # grid-1 & dragged till grid-9 (in a 3*3 matrix), in this case, i am assuming i will get 100-300 (x,y) positions, so everytime i need to run above formula to determine corresponding grid. This results in 300 calculations which might effect the performance.
So when i display an image as a rect, can i associate some id for that image? so that i can simply just save the ids in a list (from grid-1 to grid-9) so that i can avoid the above calculation.
Thanks for your help