The Language

Transcription

The Language
Praktikum im Bereich Praktische Informatik
Entwicklung eines Ray-Tracing Systems
computer graphics & visualization
Organizational
 Weekly Assignments + Preliminary discussion:
 Tuesdays 15:30 - 17:00 in room MI 02.13.010
 Assignment deadline on Monday at 23:59
Closing date has to be met strictly !
 Preferably groups of 2 students
 Group arrangements by the 22th of April the latest
 Hard-/software available in room MI 02.13.008
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Organizational
 If you have a question:
1.
2.
3.
4.
Use the discussion forum on the course homepage
Visit the weekly question time (appointment ?)
Contact us per eMail
Appear in person at our office
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Organizational
 To pass the course / obtain a certificate
 Orderly solution to all assignments on schedule !
 Your grade will be determined by the quality of
your solutions and a small oral examination at
the end of the semester
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Organizational
 Comment the code in your solutions in detail !
 Use #region-tags or comments to help us localizing
assignment specific part in your sourcecode. e.g:
 //A1_2b (for subtask 2b of assignment 1) or
 #region A1_2b //your code here #endregion
 Use XML (documentation) comments to describe
methods and their parameters in detail !
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
–Framework: Objectives
Provide:
 Consistent
object-oriented
programming
environment
no matter how the locally stored object code is executed:
(locally, locally but Internet-distributed, or remotely).
 Code-execution environment that:
 minimizes software deployment and versioning conflicts
 promotes safe execution of code
 eliminates performance problems of scripted/interpreted environments
Ensure:
– Integrability of the .NET Framework code with any other code
according to industry standards
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
–Framework in context
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
–Framework components
.Net Framework
Common Language Runtime
Web Services
XML Support
Base Classes
Code Management
Memory Management
Web Forms
(ASP.NET)
Windows Forms
(GDI+)
Data
(ADO.NET)
IL-JIT-Compiler
Security System
Developer services
Type management
Process management
COM interop
Common Language Runtime (CLR)
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
–Framework
VB.NET
sourcecode
C#
sourcecode
other
.NET-capable
languages
VB.NET
Compiler
C#
Compiler
Compiler
Other not
.NET-capable
languages
C++
sourcecode
VC++
Compiler 7.0 Unmanaged code
Compiler
Managed
code
Managed
code
Managed
code
Managed
code
MSIL-code
Microsoft Intermediate Language (MSIL)
[File]
Just-In-Time-Compiler (JIT)
(poart of the Common Language Runtime)
Native Code
(NativeImage)
[File]
Native Code
[RAM]
Native Code
[File]
Operating system
See http://www.dotnetframework.de/default2.aspx?start=http://www.dotnetframework.de/dotnet/DOTNET_Framework_Einfuehrung.asp
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
CLI/CTS: Common type system
Types
Value Types
Reference Types
Self Describing
Types
Pointer
Enumerations
Interfaces
User Value Types
Classes
System Value Types
Delegates
Stack
User-Defined
Arrays
Boxed values
Heap
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
vs. JAVA(J2EE) : Portability
 Java:
 multi platform (available for every OS)
 „not really“ multi language
 .NET:
 „not really“ multi platform (ROTOR, MONO)
 multi language (C++, C#, J#, Visual Basic, Delphi,…)
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
vs. Native Code: Performance
 .NET, the JIT
 compiles every used method once per program execution
 knows the target machine well
 knows the programs behaviour
 Native code, the compiler




usually compiles everything only once
has much time to optimize code
has „no idea“ of the target machine
can‘t do runtime optimization on it‘s own
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
C#: The prefered .NET language
 C# is a type-safe object-oriented language.
 Curly-brace syntax is very similar to C, C++ or Java
 C# syntax simplifies many of the complexities of C++
 C# provides powerful features:
 nullable value types, enumerations, delegates,
anonymous methods and direct memory access.
 supports generic methods, types, and iterators
 C# supports encapsulation, inheritance and polymorphism.
 A class may inherit directly from one parent class, but it may implement any
number of interfaces.
 In C#, a struct is a „lightweight class“, which can implement interfaces but
does not support inheritance (located on the stack).
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
C#...
 Use process "Interop." to interact with other Windows software (e.g. COM
objects, native Win32 DLLs)
 „Interop.“ enables C# programs to do just about anything that a native C++
application can do
 C# supports pointers and the concept of "unsafe" code
(for those cases in which direct memory access is absolutely critical)
 C# build process is simple (vs. C, C++), flexible (vs. Java)
 There are no separate header files, and no strict order for methods and types
 C# source files may define any number of classes, structs, interfaces, events
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
C#: familiarize with new constructs !
 Properties, which serve as accessors for private member variables (set/get)
 http://msdn2.microsoft.com/en-us/library/x9fsa0sw(VS.80).aspx
 Inline XML documentation comments ( Doc / intellisense)
 http://msdn2.microsoft.com/de-de/magazine/cc302121(en-us).aspx
 Attributes, which provide declarative metadata about types at run time
 http://msdn2.microsoft.com/en-us/library/aa288059(VS.71).aspx
 Encapsulated method signatures called delegates, which enable type-safe
event notifications (comparable to function pointer in C++ !)
 http://msdn2.microsoft.com/de-de/library/ms173171(VS.80).aspx
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
vs. JAVA (J2EE): Keywords
C# Keyword
Java Keyword
base
super
bool
boolean
is
instanceof
lock
synchronized
namespace
package
sealed
final
using
import
internal
private
:
extends
:
implements
n.a
native
n.a
transient
All .NET 3.0 keywords: http://msdn2.microsoft.com/en-us/library/x53a06bb(VS.85).aspx
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Hello World
using System;
namespace HelloWorldApplication
{
/// <summary>
/// This class is really boring since it only prints „Hello World“
/// </summary>
class HelloWorld
{
/// <summary>
/// The Main Method is the entry point for the app
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
}
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Hello World Form
using
using
using
using
using
using
System;
System.Drawing;
System.Collections;
System.ComponentModel;
System.Windows.Forms;
System.Data;
namespace HelloWorldForm
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
label1.Text = "Hello World";
}
protected override void Dispose( bool disposing )
{
if( disposing )
if (components != null)
components.Dispose();
base.Dispose( disposing );
}
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Hello World Form
private void InitializeComponent()
{
label1 = new System.Windows.Forms.Label();
SuspendLayout();
label1.Location = new System.Drawing.Point(164, 68);
label1.Name = "label1";
label1.TabIndex = 0;
label1.Text = "label1";
AutoScaleBaseSize = new System.Drawing.Size(5, 13);
ClientSize = new System.Drawing.Size(420, 158);
Controls.Add(label1);
Name = "Form1";
Text = "Hello Application";
ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Exercise 1 : Class Designer
Create a new project (Visual C#  Class-Library), and prepare your workspace:
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Exercise 1
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Exercise 2: GUI
 Create a new Windows-Application for C# within Visual Studio
 Add following control elements to the main window:
 Two Panel components
 Six TextBox components
 One PictureBox component
 Two RadioButton components
 Six Button components
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Exercise 2: exemplary GUI
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Exercise 2
 Add a new structure to the namespace to store the textbox values
 Add properties to access the private data fields
 Add a constructor and 2 methods LoadValues(), SaveValues()
 This struct will be used to easily store application
parameters in a configuration file !
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Exercise 2
 Add methods for the TextBoxes to process user input
 Parse a TextBox content whenever it‘s edited (catch invalid input !)
 Convert the input to double and set the corresponding struct value
 Set the TextBox.Text, use following code to ensure a consistent decimal delimiter


TextBox.Text = TextBox.Text .Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator);
TextBox.Text = TextBox.Text .Replace(„,", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator);
 Add „onClick“ events for the Save/Load buttons and call the the
corresponding LoadValues(), SaveValues() methods of the parameter
structure.
 Close the window if the button „Close“ is pressed.
 Restore TextBox and struct values to default parameters when the
„Reset“ button is pressed
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
Exercise 2: XML Serialization
Familiarize yourself with following namespaces:
 System.Xml.Serialization provides methods to store/read
member values of a class instances in/from XML-Documents
 System.IO provides read write operations to disc
 Add content to the FragmentParameters struct methods
SaveValues() and LoadValues() using XmlSerializer and
StreamWriter/StreamReader to serialize its content to/from a
XML configuration file.
e.g: http://www.devtrain.de/artikel_798.aspx
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization
References
 C# documentation / literature
 http://msdn2.microsoft.com/de-de/library/kx37x362(VS.80).aspx
 http://www.dotnetframework.de/dotnet/start.aspx
 http://www-alt.uni-trier.de/urt/user/baltes/docs/csharp/csharp.htm
 D. Marshall, Visual C# 2005: The Language, Microsoft Press, 2006.
 H. Mössenböck, Introduction to C#, University of Linz, Austria.
 H. Mössenböck, Advanced C#, University of Linz, Austria.
 …
C# Praktikum SS08 – Entwicklung eines Ray-Tracing Systems
K. Bürger, R. Fraedrich, Prof. Dr. Westermann
computer graphics & visualization