I am writing a program that renders fractal images. It takes time to generate these images, and I want to monitor the progress of the program in real time.
Here is the structure of how I imagine my code should be structured:
// create a window to display the image as it gets rendered
CreateDisplayWindow();
// as long as you are not finished rendering the image,
while(!doneRendering)
{
// render a bit more of the image.
RenderASmallPartOfMyImage();
// update the screen if it has been too long since the last time it was updated.
if(timeSinceLastDisplayUpdate >= displayUpdatePeriod) UpdateDisplayWindow();
}
I have searched google and MSDN for hours trying to find a simple way of achieving this. I only find complicated answers. I imagine that the right answer will be very simple.
To summarize my question: How Do I create a "display window" that can be periodically updated that will not block the execution of my while(!doneRendering) loop?
Related
I am working on a research project which needs precise timing/synchronize between the on screen display and a trigger from parallel port in Unity.
What I am trying to do is to flash the screen to white while sending a trigger to the parellel port at the same time (desired difference is within 10ms).
I mesured the screen flash with a photodiode to determine the exact time it turns white, and synchronize it with the trigger from parellel port. I always observed a delay of 40 - 70ms between the trigger and the flash (the flash arrived slower) which is my main problem.
What I have tried so far:
- Update the flash and send the trigger in the same frame (bigger delay)
- Update the flash -> WaitForEndOfFrame() -> send trigger (lower delay but still big). Below is a sample code:
IEnumerator UpdateParallelPort()
{
while (true)
{
yield return new WaitForEndOfFrame();
if (flashed == FlashState.ToWhite)
{
parallelPort.SendTrigger();
}
}
}
I also tested if the flash take multiple frames to be rendered by using ReadPixels to determine at what frame the screen turn white, but it was not the case, it was in the same frame when I issued the command. So I guess the delay comes from the time the buffer being sent to screen ? If that is the case, is there anyway to determine/synchronize the exact timing, or to minimize it ?
This is my first post in Stackoverflow, hope that I explained it clear enough. Thank you in advance for your help!
which needs precise timing
I have bad news, completely forget it.
Unity is a game engine through-and-through.
The whole entire raison d'etre, the most fundamental aspects of it, is that it lets you render mesh of dinosaurs etc, with "total compromise" of granular time, and reasonable overall perceptive time.
Unfortunately, you literally could not choose a worse milieu for the project! Sorry! :O
I am looking to animate a set of images and perform different actions dependent on which images are showing.
There are 13 images (ball1, ball2, ..., ball13), once the series reaches 'ball6' I need to a graphic to be created from the centre of the image. After that has happened it will need to pause/hold/wait for maybe 2 seconds and then follow onto 'ball7' (this is why a .gif hasn't been used). The animation needs to continue until the end (ball13) then create a different graphic and finally pause again for 2 seconds before restart the cycle...
I am poor with graphics and I am looking to learn this field so as much information as possible is appreciated.
Edits
Sorry, using WinForms at present, willing to convert for simplicity as this is start of newest project.
I loaded the application again, re-imported images using WinForms as that supports .gif files. You can simply switch between the .Image file for each .gif at any point with one line of code; using a bool if it fits nicely which it did for me.
This isn't correct code, just draft.
bool picswitch = false;
_For Loop here_
{
if (picswitch = false)
{pictureBox1.image (*.png)}
else if (picswitch = true)
{pictureBox1.image (*.png)}
}
Okay, so I started developing a game. The first thing I wanted to set up was an extensive Debug viewer, which can ultimately show things like buttons pressed (only those that I want to listen to of course) and a graph containing information about frametime, a histogram of sorts. However, I wanted to do this the correct way. It occurred to me that I wanted to use the DrawableGameComponent class for the debugviewer, and draw the debug information there. However it seems that it can't measure the Update and Draw times correctly, as I start the update timer at the beginning of the update and end the update at the beginning of the draw. However, I shortly thereafter realized that first the main game is executed (update - draw - wait) and then are all the other components executed (update component 1, draw component 1), so they aren't intertwined. This means that I can't calculate the elapsedtime (for both Update, Draw and overhead). As we can read in this blog it's better to measure frametime as opposed to frames per seconds.
So enough with the back story and on to my main question: How do I measure the frametimes needed for both the Update, the Draw and the overhead from the main game in another DrawableGameComponent, or should I just use a class and update that in the game?
I hope that everything is clear, have a great day.
i found this http://gamedevwithoutacause.com/?p=876 which explaines exactly what you need.
If you can't measure the Update and Draw times correctly, using the update timer, can't you simply use DateTime.Now? You get it at the beginning of your Update, then every next cycle (after Update, Draw and overhead) you just subtract the DateTime.Now measured previously.
I would like to know if is there some good web solutions to show charts for "huge data sets", I've tried amcharts and Highcharts Stock (jquery solutions) without success.
At the beginning they were working, but at the moment the "chrome" is telling me that the javascript memory is full and the page crashes.
I've times where I need to show more than 20 lines, each one with more than 100.000 points, so in the end I can have gigantic jquery arrays that sure will crash the internet browser.
At the moment I am open to change to some flash, silverlight or other solution (not java applet because I am using C#).
What do you guys recommend?
UPDATE #1
For example: one purpose of this application is to see ECG channels.
The person will carry a device with several "sensors" (lets define 10 or 12, more or less), the device will save the data each second (or sometimes even in shorter intervals). And there can be cases that the person will use this system for 3 days).
Minimum data:
60 seconds * 60 minutes * 24 hours * 3 days = 259.200 points per line.
8 lines or more => 2.073.600 total points
Usability:
Well, in this health area normally the "readings" will be similar, no highs or lows enough to be recognized in a 3 days data. So for this example the best would be to load the data just when it is needed > the pan/zoom slide is showing just 1hour and when it moves to other, then AJAX get the rest of the DATA. Sure this is the way to go. BUT this is not the only case in my system.
I've other type or devices where the "highs and lows" are HUGE and the user would like to see ALL data in just one "chart" without zoom in. So, in this situations just from a simple look it is easy to see that something happened on the readings, then the user can make zoom in and since the data is already on memory no need to make more AJAX calls and refresh the chart.
Smart way to go: process the data in a way to do "reduce" the number of points when we are looking at a bigger "scale". Sure, this is the wise way to go, but once again, there are times when the result of some processing math will "fake" and hide the real readings and in the end there are some "behaviors" that will not show up on the chart.
So, for now I really need to find a way to display all of this points.
Note: I really appreciate all the feedback of you guys.
I think I'm with Neil here...there must be some way that this data can be processed before display...I mean, how can this amount of data even be displayed in a window? You say a line has 100000 points...if each of those points was unique in the X,Y plane, 100000 points would completely fill a 300x300 display window. 20 lines like this would completely saturate a normal 1024x1280 display.
Presumably, that can't be what you are looking for, so I'm assuming there must be a lot of cases where the points overlap. Preprocessing the data, to eliminate duplicate data points would help reduce the data size considerably.
It's hard to know exactly how this answer fits, or to give more precise instructions without further details, but if you have questions or clarifications, edit your question and I'll modify my answer (or delete it, if I've misinterpreted.)
Response to Edit 1:
I think that the way to approach the thinking for this is to recognize that for any given view, you can only show as many data points as you have horizontal resolution, so you can limit your data download to that.
From what I'm hearing (and I grant that I have very few details) this problem can be reduced to:
Figuring out how many points to get (based on horizontal resolution)
Calculating those points based on the data, horizontal scroll, zoom, and any heuristics.
Dynamically downloading that data
That sounds not too bad, and your original problem (of too much data crashing the system) disappears. That leaves you with secondary problem of how to calculate the height of the downloaded data.
I've other type or devices where the "highs and lows" are HUGE and the
user would like to see ALL data in just one "chart" without zoom in.
So, in this situations just from a simple look it is easy to see that
something happened on the readings...
There are a number of potential difficulties that I can see here...
If the timescale for these events is too short, they won't be visible on a naively drawn graph. If you have 100000 points in a particular line graph and your default viewing area is 1000 pixels wide with no zooming, you're only seeing 1 out of 100 datapoints. If some spike lasts for 10 of the datapoints, for example, unless you do something special, there's a good chance it won't be visible on the graph (so the user won't know to "zoom in" for more resolution). And how do you determine the height at which to plot the point? The actual datapoint at a specific spot? An average of the 100 data points that pixel covers? A rolling average? If don't average, you could miss spikes entirely. If you do average, you could lower the amplitude of the spikes or troughs if they are of short duration.
This, I think (and, again, I'm doing a lot of guesswork) sounds like the real challenge. Trying to find some way to display the graph which will definitely not be able to show all of the data at one time, but may be able to have some way to highlight points of interest dynamically (calculating, noting, and marking peaks and troughs with notations on the graph...things like that.)
Try out the Zoom Line chart from the FusionCharts stables.
I've myself created charts with 27,000 datapoints; and beyond the initial loading times, the chart worked smoothly.
Here is a blog post about the zoom line chart - http://blog.fusioncharts.com/2011/10/stuck-between-massive-historical-data-and-daily-intricacies-zoom-line-chart-to-the-rescue/
As a bonus, you can render the chart in pure JavaScript or Flash.
And it also works well with server-side languages. Check out their docs for more reading material - http://docs.fusioncharts.com/
I'm building a line chart control in Silverlight using PolyLineSegment and points. It works just as expected, but the application freezes for a long time when there's too much data that needs to be visualized (too many points). I can't move my code on a separate thread for an obvious reason - it deals with UI elements directly, so when I try to call them from a separate thread it results in exception (even if UI elements are not yet rendered).
Is there any way to create UI elements dynamically on a background thread and then pass them to the UI thread to be rendered? And if not, what would be the possible solution? I'm thinking of creating an Bitmap image instead of actual controls, but there won't be much interactivity in this case.
It sounds like you need to get a faster way of rendering your points. If you have 800k samples and only say, 800 pixels to display them in you're wasting 1000 points per pixel of calculations if you just load it into a PolyLineSegment.
I would revisit 'interpolating' the points (this is really coalescing for your large dataset). You want to make sure you capture the dynamic range of the function in each pixel correctly:
Figure out how many pixels wide the graph should be
Determine how many points per pixel in the X direction
For each chunk of points:
Build a histogram of the points
Draw a vertical line from max->min on your graph at the X where these points will map to. This captures the full range represented in the chunk.
If your points/pixel gets close to 1 you'll want to switch to the easy rendering to give better visual results as well.
For displaying a waveform (in your case PCM audio data) with "millions of points" you would be better off writing directly to a WritableBitmap. You then have only one render object.
You have already said there is not much processing in your calculations. Trying to use individual UIElements is way too big an overhead (IMHO). Point display is trivial to a bitmap and there are plenty of line drawing algorithms out there, optimised for speed, to do any line segments.
You can plot your points on a background thread and them update an image's ImageSource at the end of the processing to display it.
You certainly can do your compute work on background thread(s) and pass the finished results up to the UI tread with
Deployment.Current.Dispatcher.BeginInvoke
which is discussed here