 |
|
 |
This simple code adds nice mouse interaction to allow moving the graph (left mouse button dragging), rotating it (right mouse button dragging) and zooming it (shift + mouse wheel):
public partial class Plot3DMainForm : Form {
Surface3DRenderer sr;
Boolean isMouseLeftButtonDown = false;
Boolean isMouseRightButtonDown = false;
Boolean isShiftDown = false;
double zoom = 0.5;
Point mouseLocation;
Point screenXY = new Point(0, 0);
Point3D observableXYZ = new Point3D(70, 35, 40);
public Plot3DMainForm() {
InitializeComponent();
sr = new Surface3DRenderer(observableXYZ.x, observableXYZ.y, observableXYZ.z, screenXY.X, screenXY.Y, ClientRectangle.Width, ClientRectangle.Height, zoom, 0, 0);
sr.ColorSchema = new ColorSchema(tbHue.Value);
sr.SetFunction("sin(x1)*cos(x2)/(sqrt(sqrt(x1*x1+x2*x2))+1)*10");
ResizeRedraw = true;
DoubleBuffered = true;
this.KeyPreview=true;
ReCalculateTransformations();
this.Resize += (s, e) => { ReCalculateTransformations(); };
this.Paint += (s, e) => {
e.Graphics.Clear(BackColor);
sr.RenderSurface(e.Graphics);
};
this.KeyDown += (s, e) => { isShiftDown = e.Shift; this.Text = isShiftDown.ToString(); };
this.KeyUp += (s, e) => { isShiftDown = e.Shift; this.Text = isShiftDown.ToString(); };
this.MouseDown += (s, e) => {
mouseLocation = e.Location;
if(e.Button == MouseButtons.Left) isMouseLeftButtonDown = true;
if(e.Button == MouseButtons.Right) isMouseRightButtonDown = true;
};
this.MouseUp += (s, e) => {
if(isMouseLeftButtonDown && (e.Button == MouseButtons.Left)) isMouseLeftButtonDown = false;
if(isMouseRightButtonDown && (e.Button == MouseButtons.Right)) isMouseRightButtonDown = false;
};
tbHue.MouseWheel += (s, e) => {
if(isShiftDown) {
zoom += (e.Delta > 0 ? 1 : -1) * 0.04;
ReCalculateTransformations();
}
};
tbHue.Scroll += (s, e) => {
sr.ColorSchema = new ColorSchema(tbHue.Value);
this.Invalidate();
};
this.MouseMove += (s, e) => {
if(isMouseLeftButtonDown) {
screenXY.X += e.Location.X - mouseLocation.X;
screenXY.Y += e.Location.Y - mouseLocation.Y;
}
if(isMouseRightButtonDown) {
double xDelta = e.Location.X - mouseLocation.X;
double yDelta = e.Location.Y - mouseLocation.Y;
observableXYZ.y -= xDelta;
observableXYZ.z += yDelta;
}
mouseLocation = e.Location;
if(isMouseLeftButtonDown || isMouseRightButtonDown) ReCalculateTransformations();
};
}
private void ReCalculateTransformations() {
sr.ReCalculateTransformationsCoeficients(observableXYZ.x, observableXYZ.y, observableXYZ.z, screenXY.X, screenXY.Y, ClientRectangle.Width, ClientRectangle.Height, zoom, 0, 0);
this.Invalidate();
}
}
|
|
|
|
 |
|
 |
thanks for your code. Could you please provide sample application?
Michał Bryłka
Theory is when you know something, but it doesn't work.
Practice is when something works, but you don't know why.
Programmers combine theory and practice: Nothing works and they don't know why.
|
|
|
|
 |
|
|
 |
|
 |
Hey Guys
This is good stuff, but i found some wired rendering result while this using in my program.
The point is while I set the obsX value to a value smaller than zero (i.e negative value), then part of the graphics rendered as some "inverse image" or displayed of fragments.
Is it means the formula in Project(double x, double y, double z) need some modifications?
Or where could I found a more generalized 3D projection function?
Thanks in advance.
|
|
|
|
 |
|
 |
will I be able to drag a data point thereby changing its value at runtime?
or maybe select a point?
or drill down ?
Everything else I need I think I will be able to do.
|
|
|
|
 |
|
 |
Thank you for your hard work.
What license is this code available under?
|
|
|
|
 |
|
 |
Excuse me for my English, I speak English bad.
Can you say me how to get a begginings coordinates of plot. I want to draw coordinate lines.
|
|
|
|
 |
|
 |
you can't get those, becouse there are none
you have to transform 3D coordinates of coordinate lines into 2D using my procedures. i.e. X line has coordinates of (x1, 0, 0) to (x2, 0, 0)
Michał Bryłka
Theory is when you know something, but it doesn't work.
Practice is when something works, but you don't know why.
Programmers combine theory and practice: Nothing works and they don't know why.
|
|
|
|
 |
|
 |
Thank you but your answer was very long to wait. So I found solution of this problem yet.
I use Opengl now in my programs. In Opengl I draw plot by three demission vector
( x , y , f(x,y) ). And there are procedures in OpenGl such as rotation and translation.
I solve my problem. Thank you one more time.
|
|
|
|
 |
|
 |
Hi. This is a nice application and as other user commented it would be very good to add rotation. I know of course this is implicit from the OBSx OBSy and OBSz values. However, since the transformation is not entirely spherical it is difficult to modify these values. Could you give us a reference to the transformation used? Thanks a lot.
|
|
|
|
 |
|
 |
Dear Michal,
After I read your passage, I think you can give me some inspirations.
Would you please give me some hints?
I wanna display a path within a graph, which shows x,y,z axis clearly, but I don't want to do this task by matlab.
The most important thing is how to show the path form the first point to the second point until the last point which resembles animation.
In addition, the x, y, z coordinates of various points are stored in three txt files where each of the txt file contains the coordinates of one axis only.
Thank you very much!
Best regards,
John
|
|
|
|
 |
|
 |
Please can you share how you generated the static color schemes (especially,
the lines, pink, flag, colorcube)?
I could not get copper and some working. Do you know how to generate the bone color scheme in matlab[^]?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
 |
This aspect is full presented in code attached to this article. About Matlab, try the following line:
[x, y] =meshgrid(-2:.2:2);
surf(x,y,sin(x)+cos(y))
colormap bone
Regards
Michał Bryłka
|
|
|
|
 |
|
 |
Thanks for the reply.
Sorry, I could not explain it well.
You had some list of color schemes, such as the ColorSchema.Jet,
ColorSchema.Lines etc.
Did you create this by programming or by hand? If by programming,
I wish you could share that part of the code with me.
The link I provide was to give you a picture of the matlab bone
colormap. I wish to generate that color schema by codes too, but could not.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
 |
Hi,
Everything about my color schemata can be found in enclosed "ColorSchema.cs" file.
As far as Matlab is concerned, bone color map should only be used in medical imaging, because it doesn't look good in other applications. However one can use it everywhere, like in code I've provided in my last previous reply. Did it solve your problem?
Regards
Michał Bryłka
|
|
|
|
 |
|
 |
Michal Brylka wrote: Everything about my color schemata can be found in enclosed "ColorSchema.cs" file.
Sorry for the inconvenience, I still could not found the method to generate the list of colors, for example listed in the ColorSchema.Colorcube of the "ColorSchema.cs", and still do not understand how you did it.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
 |
ok, look at this:
public static readonly ColorSchema Autumn =
new ColorSchema(...
this invokes the following class constructor:
protected ColorSchema(byte[,] schema, string schemaName)
{
this.schema = new Color[schema.GetLength(0)];
for (int i = 0; i < this.schema.Length; i++)
{
this.schema[i] = Color.FromArgb(schema[i, 0], schema[i, 1], schema[i, 2]);
}
this.schemaName = schemaName;
}
thus filling static field with values. Problem solved ?
Regards
Michał Bryłka
|
|
|
|
 |
|
 |
Again sorry for the inconvenience, I mean how did you generate that "byte[,] schema" for the Autumn, etc?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
 |
aha, now I see what you mean.
Few years ago, I've been using Matlab on my classes of Optimization Methods. I was amazed too how those color schema were generated. It turned out that it's simply 3xN matrix. Try this one in Matlab:
a = jet
I believe that this solved your problem fully.
Regards
Michał Bryłka
|
|
|
|
 |
|
 |
Thanks, it solves the problem.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Actually, I've written this class because libraries like ZedGraph or nPlot were lacking them.
So the idea of merging it with ZedGraph is tempting and I'll try to contact the its author.
Since you're a site builder, could you please answer why I'm getting the following errors in many parts of the screen:
Error: Invalid procedure call or argument
Script: /useritems/surfacePloter.asp
Source: Microsoft VBScript runtime error
Line: 0
Col: 0
Maybe there is a bug somewhere in scripts. It all started happening like a week ago. Sometimes I can't even access my profile.
Thanks in advance
Michał Bryłka
|
|
|
|
 |
|
 |
Wow, great to hear! Thanks for the info, Michał!
"Site builder" means that I contributed scripts long time ago (e.g. the forum we are using here).
Unfortunately, I have no direct access to any part of the internals. BTW I'm getting this error, too. In the past things like this happened from time to time. I'm sure Chris is aware of this and tries to fix it!
Cheers
Uwe
|
|
|
|
 |
|
 |
Hi,
Are you able to integrate your control to ZedGraph?
Cheers
Mandy
|
|
|
|
 |