When I give for example graph display B[576] #576, I can see the array values, 576 values from array B[576]. But I can't understand the display result seen below. What does the first element 0 <225x> mean? Does it mean 225 zero values?
Yes, its showing that the value is repeated 225 times.
Using GDB, an array value that is repeated 10 or more times is
displayed only once. The value is shown with a postfix added,
where n is the number of times the value is repeated. Thus, the
display 0x0 <30x> stands for 30 array elements, each with the value
0x0. This saves a lot of display space, especially with homogeneous
arrays. (source)
Related
I have two curves. One handdrawn and one is a smoothed version of the handdrawn.
The data of each curve is stored in 2 seperate vector arrays.
Time Delta is also stored in the handdrawn curve vector, so i can replay the drawing process and so that it looks natural.
Now i need to transfer the Time Delta from Curve 1 (Raw input) to Curve 2 (already smoothed curve).
Sometimes the size of the first vector is larger and sometimes smaller than the second vector.
(Depends on the input draw speed)
So my question is: How do i fill vector PenSmoot.time with the correct values?
Case 1: Input vector is larger
PenInput.time[0] = 0 PenSmoot.time[0] = 0
PenInput.time[1] = 5 PenSmoot.time[1] = ?
PenInput.time[2] = 12 PenSmoot.time[2] = ?
PenInput.time[3] = 2 PenSmoot.time[3] = ?
PenInput.time[4] = 50 PenSmoot.time[4] = ?
PenInput.time[5] = 100
PenInput.time[6] = 20
PenInput.time[7] = 3
PenInput.time[8] = 9
PenInput.time[9] = 33
Case 2: Input vector is smaller
PenInput.time[0] = 0 PenSmoot.time[0] = 0
PenInput.time[1] = 5 PenSmoot.time[1] = ?
PenInput.time[2] = 12 PenSmoot.time[2] = ?
PenInput.time[3] = 2 PenSmoot.time[3] = ?
PenInput.time[4] = 50 PenSmoot.time[4] = ?
PenSmoot.time[5] = ?
PenSmoot.time[6] = ?
PenSmoot.time[7] = ?
PenSmoot.time[8] = ?
PenSmoot.time[9] = ?
Simplyfied representation:
PenInput holds the whole data of a drawn curve (Raw Input)
PenInput.x // X coordinate)
PenInput.y // Y coordinate)
PenInput.pressure // The pressure of the pen)
PenInput.timetotl // Total elapsed time)
PenInput.timepart // Time fragments)
PenSmoot holds the data of the massaged (smoothed,evenly distributed) curve of PenInput
PenSmoot.x // X coordinate)
PenSmoot.y // Y coordinate)
PenSmoot.pressure // Unknown - The pressure of the pen)
PenSmoot.timetotl // Unknown - Total elapsed time)
PenSmoot.timepart // Unknown - Time fragments)
This is the struct that i have.
struct Pencil
{
sf::VertexArray vertices;
std::vector<int> pressure;
std::vector<sf::Int32> timetotl;
std::vector<sf::Int32> timepart;
};
[This answer has been extensively revised based on editing to the question.]
Okay, it seems to me that you just about need to interpolate the time stamps in parallel with the points.
I'm going to guess that the incoming data is something on the order of an array of points (e.g., X, Y coordinates) and an array of time deltas with the same number of each, so time-delta N tells you the time it took to get from point N-1 to point N.
When you interpolate the points, you're probably going to want to do it intelligently. For example, in the shape shown in the question, we have what look like two nearly straight lines, one with positive slope, and the other with negative slope. According to the picture, that's composed of 263 points. We could reduce that to three points and still have a fairly reasonable representation of the original shape by choosing the two end-points plus one point where the two lines meet.
We probably don't need to go quite that far though. Especially taking time into account, we'd probably want to use at least 7 points for the output--one for each end-point of each colored segment. That would give us 6 straight line segments. Let's say those are at points 0, 30, 140, 180, 200, 250, and 263.
We'd then use exactly the same segmentation on the time deltas. Add up the deltas from 0 to 30 to get an average speed for the first segment. Add up the deltas for 31 through 140 to get an average speed for the second segment (and so on to the end).
Increasing the number of points works out roughly the same way. We need to look at exactly which input points were used to create a pair of output points. For a simplistic example, let's assume we produced output that was precisely double the number of input points. We'd then interpolate time deltas exactly halfway between each pair of input points.
In the case shown in the question, we start with unevenly distributed inputs, but produce evenly distributed outputs. So the second output point might be an average of the first four input points. The next output point might be an average of three input points (and so on). In many cases, it's likely that neither end-point of a segment in the output corresponds precisely to any point in the input.
That's fine too. We interpolate between two points of the input to figure out the time hack for the starting point of the output segment. Likewise for the ending point. Then we can compute the total time it should have taken to travel between them based on the time delta between the points.
If you want to get fancy, you could use a higher order interpolation instead of linear. That does require more input points per interpolation, but it looks like you probably have plenty to do something like a quadratic or cubic interpolation (in most cases). This is likely to make the most differences at transitions--places the "pen" was accelerating or decelerating quickly. In such an place, linear interpolation can give somewhat misleading results (though, given the number of points you seem to be working with, it may not make enough difference to notice).
As an illustration, let's consider a straight line. We're going to start from 5 input points, and produce 7 output points.
So, the input points are [0, 2, 7, 10, 15], and the associated time deltas are [0, 1, 4, 8, 3].
So, out total distance traveled is 16, and we want our output points to be evenly distributed. So, the distance between output points will be 16/7 = (roughly) 2.29.
So, obviously the first output point and time are both 0. The second output point is 2.29. To compute the output time, we take the entirety of the time to the first input point (0->2), plus .29 / (7-2) * (4-1). That interpolated section gives 1.37, so our first output time delta is 2.37.
The next output point should be at a distance of 4.58. Since the second input segment goes from 2 to 7, our entire second output segment will lie within the second input segment. So, we take 2.29 / (7-2), telling use that this output segment occupies .458 of the input segment. We then multiply that by the time for the second input segment to get the time delta for the second output segment: .458 * (4-1) = 1.374.
[...and it continues on the same way until we reach the end.]
I have a Tkinter Toplevel window with three columns. All three columns are configured to have equal weight. Inside column 0 and 2 are sub-frames, inside which are Listbox widgets. Inside column 1 is a set of buttons. For some reason, despite the fact that my 3 columns have equal weight, these Listboxes 'force' their columns to occupy more space.
I've written,
window.columnconfigure(0,weight=1)
window.columnconfigure(1,weight=1)
window.columnconfigure(2,weight=1)
But I get:
I've also given column 1 weights of 3 and 5, but it still remains small. However, having done this, it seems that columns 0 and 2 have some minimum size, then after subtracting that from the real width, the leftover width is used and divided by weight.
Is this a bug? Is there something I need to do to my lists? Might I be forgetting something?
It is not a bug. weight determines how extra space is allocated. It doesn't make any guarantees about the size of a row or column.
If you want columns to have a uniform width, use the uniform option and make them all be part of the same uniform group.
window.columnconfigure(0,weight=1, uniform='third')
window.columnconfigure(1,weight=1, uniform='third')
window.columnconfigure(2,weight=1, uniform='third')
Note: there is nothing special about 'third' -- it can be any string as long as it's the same string for all three columns.
I've been scratching my head for ages trying to work out why my 2d vectors look like they're storing things in the wrong order, and have twice as many entries as they should. I'm watching them in debug mode using the "watches" window in codeblocks.
When I just outputted all the data to the terminal, it is infact in the correct order.
Why's it showing up so wrong in the watches window? Is it something to do with how it's actually stored?
EDIT:
here is an image of my Watches window showing the 2d vector. It is mostly empty, but I've just noticed that it says length = 12, capacity = 12 at the top. So it clearly knows it's not actually that long. The way the vectors constructed, ints between 0 and 999 should be in element 0, ints between 1000 and 1999 in element 1, ints between 2000 and 2999 in element 2, and so on until ints between 11000 to 11999 in element 11. So that int 6019 should definately not be in element 1! And isn't if I cout to terminal.
Can someone explain the last line of this MatLab expression? I need to convert this to C++ and I do not have any experience in matlab syntax.
LUT = zeros(fix(Max - Min),1);
Bin= 1+LUT(round(Image));
Image is an input image, Min and Max are image minimum and maximum grey levels.
Is Bin going to be an array? What shall it contain? What are the dimensions, same as LUT or Image? What is the '1' stands for (add 1 to each member of array or a shift in array positions? I cannot find any example of this.
Thanks in advance.
LUT is a column vector that has a number of entries that is equal to the difference in maximum and minimum intensities in your image. LUT(round(Image)) retrieves the entries in your vector LUT which are given by the command round(Image). The dimension of Bin will be equal to the size of your matrix Image, and the entries will be equal to the corresponding indices from the LUT vector. So, say you have a 3x3 matrix Image, whose rounded values are as follows:
1 2 3
2 2 4
1 5 1
Then LUT(round(Image)) will return:
LUT(1) LUT(2) LUT(3)
LUT(2) LUT(2) LUT(4)
LUT(1) LUT(5) LUT(1)
And 1+LUT(round(Image)) will return:
1+LUT(1) 1+LUT(2) 1+LUT(3)
1+LUT(2) 1+LUT(2) 1+LUT(4)
1+LUT(1) 1+LUT(5) 1+LUT(1)
Note that this only works if all entries in round(Image) are positive, because you can't use zero/negative indexing in the LUT vector (or any MATLAB matrix/vector, for that matter).
I'm making a mfc application to make a somewhat drawing mechanism. Using a polyline the user can draw figures, and on pressing the enter key the current point of the line is joined to the starting point[to form a closed polygon]. I think you get the idea. Now, I'm using an STL array to store each vertex of the polygon- in simple words, every point at which the left-mouse button is clicked while drawing the figure is stored in the array.
std::array<CPoint,11> v; //vertices
I'm using the following mechanism to output the elements of this array, i.e the points:
for(int j=0 ; j<v.size() ; j++ )
{
s.Format(L"%d %d\n",v[j].x, v[j].y);
aDC.TextOutW(x+=20,y+=20,s ); //each time print the coordinates
s=" "; //at a different location
}
During execution, when the user draws the figure by clicking points around the screen, those points are stored in the array. The array's declared with 12 elements, but rarely does a shape have 12 vertices. The rest of the element(the empty ones) remain (0,0)- and yet these are outputted in the loop. So what I get printed is 3-4 coordinates and a lots of (0,0)s. Is there a way to print only those elements in which the vertices are stored(I hope you get what I mean). Something like vertices[n]=/*some character that signifies the last element*/ . My question is, what will this character be? like a '\0' in a string.
It does not look like there is a good candidate for an "end marker" in a CPoint structure: every pair of {x,y} represents a legal point, at least theoretically.
If you insist on using a fixed array (presumably, for performance reasons), you can also store the number of polygon vertices in a separate variable (continuing your string analogy, that would be a "Pascal string" of points, rather than a "C string" of points).
If using an array is not essential, you may want to switch to a std::vector<CPoint>, a container that is better suited for representing structures of variable size, such as polygons.
Finally, you could designate one point as illegal (say, at {std::numeric_limits<long>::max(), std::numeric_limits<long>::max()}), create an instance of that point statically, and use it as an end-of-sequence marker. In this case, consider expanding your array by one, and use the end marker as a sentinel.
Well, if you intend to use the (0; 0) point as invalid, you can just check a point for being at (0; 0):
if (vertices[i].x != 0 && vertices[i].y != 0) {
// valid
}