Posts Tagged ‘C#’

Currently i need to obtain depth map using stereo images and  Block Matching Algorithm in OpenCV painfully requires many parameter adjustments.  Then i found out Stereo BM Tuner by Martin Perris (http://blog.martinperis.com/2011/08/opencv-stereo-matching.html) is quite handy and useful. The only problem he developed this tool using Linux and Gtk+ (Ok, i am Visual Studio user XD ) so i need to port it to Windows.

Actually the porting was not that difficult, and after 2 hours of googling i found the solution:

First you need to download Gtk+ fow Windows 32bit and you should download the all-in-one bundle version (http://www.gtk.org/download/win32.php, dependencies included), zipped version, contains all dll, lib, and include files.

Open your Project through Visual Studio and right click–> Project Properties –> C/C++ section –> Additional Include Directories:

{your gtk+ bundle directory}\include;
{your gtk+ bundle directory}\include\gtk-2.0;
{your gtk+ bundle directory}\include\atk-1.0;
{your gtk+ bundle directory}\include\freetype2;
{your gtk+ bundle directory}\include\gail-1.0;
{your gtk+ bundle directory}\include\gdk-pixbuf-2.0;
{your gtk+ bundle directory}\include\gio-win32-2.0;
{your gtk+ bundle directory}\include\glib-2.0;
{your gtk+ bundle directory}\include\pango-1.0;
{your gtk+ bundle directory}\lib\glib-2.0\include;
{your gtk+ bundle directory}\include\cairo;
{your gtk+ bundle directory}\lib\gtk-2.0\include;

Project Properties –> Linker –> General –> Additional Library Directories:

{your gtk+ bundle directory}\lib

Project Properties –> Linker –> Input –> Additional Dependencies:

atk-1.0.lib
cairo.lib
expat.lib
fontconfig.lib
freetype.lib
gailutil.lib
gdk_pixbuf-2.0.lib
gdk-win32-2.0.lib
gio-2.0.lib
glib-2.0.lib
gmodule-2.0.lib
gobject-2.0.lib
gthread-2.0.lib
gtk-win32-2.0.lib
intl.lib
libpng.lib
pango-1.0.lib
pangocairo-1.0.lib
pangoft2-1.0.lib
pangowin32-1.0.lib
zdll.lib

And don’t forget Project Properties –> Linker –>System –>  SubSystem should be set as Console (/SUBSYSTEM:CONSOLE)

Then we need to modify every callback function, for example:

extern "C" __declspec(dllexport)
G_MODULE_EXPORT void on_adjustment1_value_changed( GtkAdjustment *adjustment, ChData *data )
{
    ...
}

Last step you need to copy the .glade file and all of files in {your gtk+ bundle directory}\bin (except the .exe files) on the binary folder (bin\Debug or bin\Release)

std::vector

Posted: October 17, 2011 in C/C++, Programming
Tags: , ,

vector, in C++ can act as a ArrayList,  similar to Java or C#. vector itself is included as a part of STL. In this article i just introduce some basic usage of vector, the rest can read here.

Here’s the instantiation of vector:

std::vector<AnObject*> objectList;

To add a member, we can use push_back()

objectList.push_back(anObject);

vector’s size it very simple to be obtained:

objectList.size();

The fun part of using vector when we’re accessing its member, it’s same as we use array :D

objectList[a]->aMethod();

To delete a member, it is little different, we should use iterator:

objectList.erase(objectList.begin() + a);

When a is the index of a member we want to delete and objectList.begin() is a method to obtain the initial iterator.

Goblin XNA is an open source platform for creating 3D user interface especially for augmented reality application. It has BSD licence and written using C# language under .NET Framework. Currently, Goblin XNA ver 3.5.1 just supports .NET 3.1 and XNA 3.5 (Goblin XNA ver 4.0 for XNA 4.0 will be released in this year). Goblin XNA is a framework to create graphics system for manipulating scene and rendering that blend realilty and virtual objects. In addition, Goblin XNA supports for 2D components.

Goblin XNA works with video stream from camera or webcam as input. With this video stream, Goblin XNA will detect for marker in physical environment using tracking system. After marker is detected, Goblin XNA will generate transformation matrix from marker’s relative position to camera.

Goblin XNA is not pattern recognition libary for marker tracking. Therefore it uses ALVAR Wrapper for its marker tracking feature. ALVAR is marker-based augmented reality library created by VTT of Finland. ALVAR Wrapper is default marker tracker for Goblin XNA but developers is able to use customized tracker library such as ARTag or ARToolkit.

Goblin XNA’s system takes form of scene graph which very similar to OpenSG (http://www.opensg.org/). Scene Graph is groups of nodes that form n-tree hierarchy. This hierarchy will create parent-child relationship for each node. Every node only has one parent (root node is the only exception) and it is possible to have 0-n children(s).

In this article, i will create a simple application that which implements NHibernate, in database side, i will use SQL Server 2008. What is NHibernate ? I will not explain it in there,  there are lot of explanations in the internet, like in here.

You can download latest NHibernate version here.

First, i will create a simple database that have just one table (and i added some record in there):

This is the DDL (Data Definition Language)

create table ACCOUNT (
   ACCID                int         identity(1,1)       not null,
   USERNAME             varchar(50)                     null,
   PASS                 varchar(50)                     null,
   constraint PK_ACCOUNT primary key nonclustered (ACCID)
)

Hmm.. what does this Identity(1,1)  mean ??? It is mean we will set ACCID attribute, the primary key, to become autonumbered, the value will be added automatically incrementing from 1, 2, 3, … and so on.

Next step, we will create simple solution in Visual Studio 2008 SP1 (remember … to connect to SQL Server 2008, your Visual Studio 2008 must be Service Pack 1 ).

Add some references

  1. NHibernate.dll (NHibernate library)
  2. NHibernate.ByteCode.LinFu.dll (for lazy loading)
  3. System.configuration

(more…)

Abstract
This document contains coding conventions and style guidelines that will ensure that C# code will be of consistent and superior quality. It includes general coding guidelines as well as discussions on naming, formatting, and language usage patterns.

Purpose
The purpose of this document is to provide coding style standards for the development of source code written in C#. Adhering to a coding style standard is an industry proven best-practice for making team development more efficient and application maintenance more cost-effective. While not comprehensive, these guidelines represent the minimum level of standardization expected in the source code of projects written in C#.

Scope
This document provides guidance on the formatting, commenting, naming, and programming style of C# source code and is applicable to component libraries. web services, web sites, and rich client applications.

Document Conventions
Example code is shown using the Code font and shows syntax as it would be color coded in Visual Studio’s code editor.

Download Full Document Here

INVADERZ – My First XNA Game

Posted: December 1, 2009 in C#, Game Programming, Programming, XNA
Tags: , , ,

xna_logo

Game Title : INVADERZ

Genre : Shoot ‘em up

Type : Game 3D

Framework : XNA Game Studio 3.1

Tool :

–    Visual Studio 2008 Professional SP 1
–    SpriteFont 1.2


DOWNLOAD HERE

 

Judul Game     : INVADERZ

Genre              : Shoot ‘em up

Jenis                : Game 3D

Framework      : XNA Game Studio 3.1

Tool                 :

Visual Studio 2008 Professional SP 1

SpriteFont 1.2

Problem yang pertama adalah mengenai longest common subsequence dengan menggunakan tiga sekuen. Algoritma ini memiliki tujuan untuk mendapatkan subsekuen yang sama secara berurutan dan tentunya yang paling panjang dari ketiga subsekuen.

Contoh :

Sekuen Pertama : SURABAYA
Sekuen Kedua : SURAKARTA
Sekuen Ketiga : PASURUAN
Hasil : SURA

Algoritma

Algoritma solusi menggunakan solusi dynamic programming. Sebenarnya LCS dengan tiga sekuen sama saja dengan LCS menggunakan dua sekuen. Namun bedanya disini, dalam mengelesaikan LCS dengan tiga string, dibutuhkan array tiga dimensi yang volumenya adalah X.Y.Z dimana X, Y, dan Z adalah panjang dari ketiga sekuen.
Solusi optimal yang dihasilkan akan didapatkan di elemen array yang terakhir, yaitu array dengan indeks X-1, Y-1, dan Z-1
Petbedaan lainnya dalam LCS menggunakan tiga sekuen, arah/direction yang perlu di-cek adalah sebanyak tujuh arah. Tujuh arah tersebut yang direpresentasikan dengan angka adalah sebagai berikut :

0 menuju ke c[i – 1, j – 1, k – 1]
1 menuju ke c[i – 1, j – 1, k]
2 menuju ke c[i – 1, j, k – 1]
3 menuju ke c[i, j – 1, k – 1]
4 menuju ke c[i, j, k – 1]
5 menuju ke c[i, j – 1, k]
6 menuju ke c[i – 1, j, k]

(more…)

C# Preprocessor

Posted: August 1, 2009 in C#, Programming
Tags: , ,

These commands never translated and included into the executable file but these are very useful for compilation process. Using preprocessors, we can stop the compiler from compiling certain potion of code. This is very helpful in the situation where you are planning to release two versions of software one basic version which has less features and one advance version which has more features. The preprocessor directives are all starts with the # symbol in the beginning of them.

C# actually has almost all the standard preprocessor directives – it just happens to be that the functionality of some of them . The one notable directive that is missing is #include – and it makes sense that C# wouldn’t have it, because C# gets the same sort of functionality from the using statements (although there is the fact that #include refers to files and using refers to assemblies – so they are definitely not equivalent).

Rules

  1. Preprocessor directives must be on separate line
  2. Must not terminate with semicolon compared to normal C# statements
  3. Starts with # character
  4. End of line comments are not allowed
  5. Delimited comments are not allowed

blog

(more…)

Function for Query
ex : SELECT

        public DataSet ExecuteQuery(string sql)
        {
            DataSet dsResult = new DataSet();

            try
            {
                OracleDataAdapter daAdapter = new OracleDataAdapter(sql, conn);
                daAdapter.Fill(dsResult);
            }
            catch (OracleException oex)
            {
                if (oex.Number == 2292)
                    MessageBox.Show("crash from a data from other table");
                else
                    MessageBox.Show(oex.Message);

                CloseConnection();
                OpenConnection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                CloseConnection();
                OpenConnection();
            }

            return dsResult;
        }

Function for DML
ex : UPDATE, DELETE


        public int ExecuteSQL(string sql)
        {
            int isAffectedRows = 0;

            try
            {
                OracleTransaction oTransaction = conn.BeginTransaction();
                OracleCommand oCmd = conn.CreateCommand();
                oCmd.CommandText = sql;
                isAffectedRows = oCmd.ExecuteNonQuery();
                oTransaction.Commit();
            }
            catch (OracleException oex)
            {
                if (oex.Number == 2292)
                {
                    MessageBox.Show("crash from a data from other table");
                }
                else
                {
                    MessageBox.Show(oex.Message);
                }

                CloseConnection();
                OpenConnection();

                return 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                CloseConnection();
                OpenConnection();

                return 0;
            }

            return isAffectedRows;  // if success return value not 0
        }

what we must do first :

private OracleConnection conn;
private string connString = "Data Source=(DESCRIPTION="
             + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.126.11.15)(PORT=1521)))"
             + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORAPBD9)));"
             + "User Id=joe;Password=joe;";

for opening connection :

public bool OpenConnection()
{
            bool success = true;

            try
            {
                conn = new OracleConnection(connString);
                conn.Open();
            }
            catch (Exception ex)
            {
                success = false;
            }

            return success;
}

closing….

public void CloseConnection()
{
        conn.Close();
        conn.Dispose();
}