I am following libgdx tutuorial on texture atlases. This is an excerpt from a texture atlas file. What is the meaning of index parameter and in what situations it is useful to the programmer? All texture region have it and it is the same namely -1, in all of them.
prehistoric.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
background
rotate: false
xy: 2, 2
size: 1280, 720
orig: 1280, 720
offset: 0, 0
index: -1
trex
rotate: false
xy: 1286, 479
size: 179, 243
orig: 179, 243
offset: 0, 0
index: -1
caveman
rotate: false
xy: 1286, 319
size: 83, 156
orig: 83, 156
offset: 0, 0
index: -1
From the Javadoc:
The number at the end of the original image file name, or -1 if none.
When sprites are packed, if the original file name ends with a number, it is stored >as the index and is not considered as part of the sprite's name.
I should also add, that this index is also used on findRegion(String name, int index) method which returns the first region found with the specified name and index.
It's typically used for animations. You can append frame numbers to the file names of each frame of animation before you pack them into the atlas, i.e. run0.png, run1.png, run2.png, etc. During texture packing, the number is removed from the sprite's name and used as its index. Then you can load the animation all at once:
animation = new Animation(0.1f, atlas.findRegions("run"));
The index is -1 when the original file name did not end in a number.
Related
My problem is that I have TIFF images with multiple levels (40x,20x,10x,5x) but some only have 40x level and I need all of them. My question is if there is any way to get 20x or other levels from 40x level images. I read about a library called vips but I don't understand how to use it to my specific problem.
Yes, libvips can compute the missing levels for you. For example:
$ vips copy k2.tif x.tif[pyramid]
The [pyramid] is an option to the libvips TIFF writer to enable pyramid output. You can check the result with tiffinfo:
$ tiffinfo x.tif
TIFF Directory at offset 0x9437192 (900008)
Image Width: 1450 Image Length: 2048
Tile Width: 128 Tile Length: 128
Resolution: 72.009, 72.009 pixels/inch
Bits/Sample: 8
Sample Format: unsigned integer
Compression Scheme: None
Photometric Interpretation: RGB color
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
TIFF Directory at offset 0x11797866 (b4056a)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 725 Image Length: 1024
Tile Width: 128 Tile Length: 128
Resolution: 72.009, 72.009 pixels/inch
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
TIFF Directory at offset 0x12388198 (bd0766)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 362 Image Length: 512
Tile Width: 128 Tile Length: 128
Resolution: 72.009, 72.009 pixels/inch
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
TIFF Directory at offset 0x12585098 (c0088a)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 181 Image Length: 256
Tile Width: 128 Tile Length: 128
Resolution: 72.009, 72.009 pixels/inch
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
TIFF Directory at offset 0x12634494 (c0c97e)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 90 Image Length: 128
Tile Width: 128 Tile Length: 128
Resolution: 72.009, 72.009 pixels/inch
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
You can see it's written a five level pyramid, with each level being a tiled TIFF with 128 x 128 pixel tiles. That might or might not be correct for your application, you'd need to give a lot more information. For example:
$ vips copy k2.tif x.tif[pyramid,compression=jpeg,Q=85,tile-width=256,tile-height=256]
Might be better. Check the docs.
I have some data that I think would work best as a dictionary or JSON. The data has an initial category, a, b...z, and five bands within each category.
What I want to be able to do is give a function a category and a value and for the function to return the corresponding band.
I tried to create a dictionary like this where the values of each band are the lower threshold i.e. for category a, Band 1 is between 0 and 89:
bandings = {
'a' :
{
'Band 1' : 0,
'Band 2': 90,
'Band 3': 190,
'Band 4': 420,
'Band 5': 500
},
'b' :
{
'Band 1' : 0,
'Band 2': 500,
'Band 3': 1200,
'Band 4': 1700,
'Band 5': 2000
}
}
So if I was to run a function:
lookup_band(category='a', value=100)
it would return 'Band 3' as 100 is between 90 and 189 in category a
I also experimented with settings keys as ranges but struggled with how to handle a range of > max value in Band 5.
I can change the structure of the dictionary or use a different way of referencing the data.
Any ideas, please?
You can structure your data a little bit differently (using sorted lists instead of dictionaries) and use bisect module. For example:
from bisect import bisect
bandings = {
'a': [0, 90, 190, 420, 500],
'b': [0, 500, 1200, 1700, 2000]
}
def lookup_band(bandings, band, value):
return 'Band {}'.format(bisect(bandings[band], value))
print(lookup_band(bandings, 'a', 100)) # Band 2
print(lookup_band(bandings, 'b', 1700)) # Band 4
print(lookup_band(bandings, 'b', 9999)) # Band 5
I am trying to develop a libgdx game. i want to implement a selection screen. Till now i have implemented horizontal scrollpane and it is working fine.
Now i want to implement scrolling on the click on the button. You can check the image attached.
Try instead to use json pack
This works for me:
_skin = new Skin();
TextureAtlas buttonAtlas = new TextureAtlas("images/buttons.pack");
_skin.addRegions(buttonAtlas);
_textButtonStyle = new TextButtonStyle();
_textButtonStyle.font = _game.getFont();
_textButtonStyle.up = _skin.getDrawable("button-orange");
_textButtonStyle.down = _skin.getDrawable("button-blue");
buttons.pack:
buttons.png
size: 234,195
format: RGBA8888
filter: Nearest,Nearest
repeat: none
button-orange
rotate: false
xy: 0, 0
size: 236, 67
split: 25, 25, 14, 14
orig: 236, 67
offset: 0, 0
index: -1
button-blue
rotate: false
xy: 0, 67
size: 236, 67
split: 25, 25, 14, 14
orig: 236, 67
offset: 0, 0
index: -1
button-navy
rotate: false
xy: 0, 134
size: 236, 67
split: 25, 25, 14, 14
orig: 236, 67
offset: 0, 0
index: -1
Try in create method
yourImage = new Image(new Texture("images/image.png"));
stage.add(yourImage);
Try in render method
yourImage.setPosition(yourX, yourY)
for the answer look this link https://github.com/krustnic/HorizontalSlidingPane
I have an N x 2 table of integers called games[ , ]. The table of nodes/edges is converted to a graph:
net <- graph.data.frame(as.data.frame(games), directed=FALSE)
deg.net <- degree(net, mode='total', loops=FALSE)
(I realize that not all options are necessary.)
The problem I am having is that the degree distribution seems to be for in-degree only. For example, the games file has the lines:
103 86
24 103
103 2
92 103
87 103
103 101
103 44
and yet igraph indicates that the degree for node 103 is '3' when it should be '7'.
Any insight in what I am missing would be appreciated.
One thing that you should keep in mind is that most igraph functions refer to the vertices by their IDs, which are simply integers from 0 to N-1 where N is the number of vertices in the graph. If you have an N x 2 table of integers (containing zero-based vertex indices) and you want igraph to use the integers as the vertex IDs, you can simply use the graph constructor after having flattened the matrix into a vector by rows. When you use graph.data.frame, the first two columns of the data frame are assumed to contain symbolic vertex names (i.e. there is no requirement that they must be integers); these will be assigned to the name vertex attribute, and igraph will simply make up the IDs from 0 to N-1.
So, let's assume that you have an N x 2 matrix, one row per each edge:
> edges <- matrix(c(103, 86, 24, 103, 103, 2, 92, 103, 87, 103, 103, 101, 103, 44), ncol=2, byrow=T)
First we create a graph out of it after flattening the matrix by rows:
> g <- graph(as.vector(t(edges)))
This gives you a directed graph with 7 edges and the out/in-degrees of vertex 103 will be as expected:
> ecount(g)
7
> degree(g, 103, mode="out")
4
> degree(g, 103, mode="in")
3
> degree(g, 103, mode="all")
7
If you use graph.data.frame with the above matrix, igraph will construct a graph where the numbers in the matrix are stored in the name vertex attribute:
> g <- graph.data.frame(as.data.frame(edges))
> V(g)$name
[1] "103" "24" "92" "87" "86" "2" "101" "44"
This shows you that the vertex with the name 103 actually became vertex zero in the graph:
> degree(g, 0, mode="out")
4
> degree(g, 0, mode="in")
3
> degree(g, 0, mode="all")
7
As far as I know, degree is also able to work with the vertex names directly if there is a vertex attribute called name in the graph, so you can also do this:
> degree(g, "103", mode="in")
3
Hope this helps.
You created a undirected graph. There is no in and out degree in such a graph. From the igraph documentation link you can get the general idea. Your deg.net will return a vector with all the degrees(per node) on your graph, similar to this:
[1] 2 1 1 1 1 1 1
If you want to get the degree of a specific node(in our example it's 103) you have to specify the node(appearence_order-1). In your example you are looking for the (1st_node-1), it's node 0. So you must type:
degree(net,0, mode='total', loops=FALSE)
Which will return the degree of node 0, "7".
I'm trying to manually (no libs such as Three.js) load a JSON 3D model into my webGL code just for fun but I'm having a hard time when my models have more than 1 texture.
In a OBJ->JSON converted file, how do I know which texture is the "active" for the faces that follow? OBJ files use 'usemtl' tag to identify the texture/material in use but I can't seem to find that kind of pointer when working with JSONs.
In time, I'm using the OBJ->JSON converter written by alteredq
Thanks a bunch,
Rod
Take a look at this file: three.js / src / extras / loaders / JSONLoader.js.
The first element of each face in the faces array of the JSON file is a bit field. The first bit says if that face have three o four indices. And the second bit says if that face has a material assigned. Material index, if any, appears after indices.
Example: faces: [2, 46, 44, 42, 0, 1, 45, 46, 48, 3, ...
First face (triangle with material):
Type: 2 (00000010b)
Indices: 46, 44, 42
Material index: 0
Second face (quad without material):
Type: 1 (00000001b)
Indices: 45, 46, 48
Third face (quad with material):
Type: 3 (00000011b)
Indices: ...
Check source code for full meaning of that bit field.
In the OBJ->JSON converter I have written for the KickJS game engine, each material has its own range of indices.
This means a simple OBJ model such as
mtllib plane.mtl
o Plane
v 1.000000 0.000000 -1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 1.000000
v -1.000000 0.000000 -1.000000
usemtl Material
s 1
f 2 3 4
usemtl Material.001
f 1 2 4
Would be translated into this (With two indices; one for each material):
[
{
"vertex": [1,0,1,-1,0,1,-1,0,-1,1,0,-1],
"name": "Plane mesh",
"normal": [0,-1,0,0,-1,0,0,-1,0,0,0,0],
"indices0": [0,1,2],
"indices1": [3,0,2]
}
]
Use the online model viewer for the convertion:
http://www.kickjs.org/example/model_viewer/model_viewer.html