미리 컴파일된 헤더 만들기/사용하기

카테고리 없음 2015. 1. 26. 17:19

미리 컴파일된 헤더라는 것은 자주 변경되지 않는 헤더파일들을 미리 컴파일하여 코드가 수정될 때마다 이러한 헤더파일들이 재컴파일되는 것을 방지할 수 있는 좋은 방법이다. (컴파일 속도를 빠르게..)

이것의 설정은 프로젝트 설정의 C++ 에서 미리컴파일된 헤더 탭에서 설정이 가능하며, 이 때 먼저 "만들기" 옵션을 통해 미리컴파일을 해야한다. 결과물로서는 pch파일이 생성되며, 이것은 다음부터 다시 똑같은 설정 탭에서 "사용" 으로 바꿈으로써 사용 가능해진다.

자세한 설명은 아래 참조를 확인하면 더욱 좋다.

※ 그리고, 개발을 하면서 느낀 것인데 debug에서 이미 같은 이름으로 pch파일을 만들었다면 release에서는 컴파일 에러가 발생한다. 따라서 위 설정탭에서 출력파일의 이름 뒤에 debug용을 구분할 수 있도록 d를 붙여주도록 하자. (이미 컴파일 에러가 발생했다면, pch파일을 지우고 다시 빌드하면 빌드가 될 것이다. )

* 참조 : 

[1] http://www.gamedevforever.com/134

[2] http://pros2.tistory.com/81

[3] http://minjang.egloos.com/1956289



설정

트랙백

댓글

What is homogeneous transform?

Research/Mathmatics 2015. 1. 16. 18:37

우선 homogeneous coordinate이 무엇인 지 생각해보자.

일례로, homogeneous coordinate에서는 (x, y)라는 하나의 포인트를 (x, y, 1)이라는 포인트로 표현한다.

이것은 projective plane 상의 점으로 생각하는 것이다. 조금 더 일반적으로 표현하자면 (wx, wy, w)로 표현할 수 있다. (하나의 표현으로 딱 정해진 것은 아님)

아래 페이지들을 보면 정말 설명이 잘 되어있기 때문에 나중에 다시 정리하도록 하자..


* Ref

http://blog.daum.net/shksjy/229

http://darkpgmr.tistory.com/78




Pose is described by just 3 numbers:

    • Offset in the x-direction
    • Offset in the y-direction
    • A rotation angle

The homogeneous transformation is inefficient in this respect, requiring three times as many numbers as actually required. Some of those 9 numbers have fixed values like 0 or 1, and others repeated or repeated with a different sign. Its advantage is the ability to compound poses by matrix-matrix multiplication, or transform vectors by matrix-vector multiplication. These operations are very convenient to express in an environment like MATLAB, and with modern computers the extra computation required is almost insignificant.








In homogeneous coordinates a point and a line, on a plane, can both be represented by a 3-element vector.

An advantage of using the homogenous form is that it’s very easy to represent a line that is vertical where in Cartesian coordinates, that means that the grading of the line is equal to infinity. In homogeneous form, we treat that situation very simply and conveniently. We don’t need to introduce any infinities.

We also might be interested in how to describe a line that joins two points. So here we have two points and here’s a line that passes through those two points. Then the homogenous representation of the line which remember is the three vector is given simply by the cross-product of the two points that lie on the line. So a very, very simple way of finding the equation of a line that joins two points much, much more conveniently than it is for Cartesian coordinates.




* Ref :

[1] https://moocs.qut.edu.au/courses/814/learn

[2] https://moocs.qut.edu.au/courses/791/learn

'Research > Mathmatics' 카테고리의 다른 글

Skew symmetric matrix  (0) 2015.04.15
Eigen Vectors and Eigen Values  (0) 2015.02.27
Atan2 에 대하여.. (what is atan2?)  (0) 2015.01.08
Fourier Transform (푸리에 변환)  (0) 2014.12.02

설정

트랙백

댓글

error C3867 in AfxBeginThread

카테고리 없음 2015. 1. 15. 13:42

you can't pass the address of a member function to the AfxBeginThread function. The function should be either a static member function or a global function. The difference is that the prototypes are different: with a member function, an implicit parameter is passed to the function (the this pointer, which identifies to which class instance it belongs to).

 

You'll get another problem then: you won't be able to access non-static member variables. The solution to the problem is to pass the pointer of the instance to the thread function (through the pParam parameter) and cast it back in the thread function.

 

One more thing: you shouldn't use TerminateThread because it terminates the thread brutally without cleaning anything. You should instead rely on other mechanisms (like using a flag that you set to true when the thread should terminate and check that flag inside your thread function).


*Ref

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/81b28e62-cb7d-40af-a064-62de0039effc/error-c3867function-call-missing-argument-list

설정

트랙백

댓글

[Assertion failed] wincore.cpp error line 952

Skills/Programming 2015. 1. 15. 13:29

MFC does not support calling a window from a thread that did not create the window. Your call to OnIdle violates that restriction.

Each thread uses a separate message queue, so it is also a bad idea to attempt to use the main message queue from your thread.

Why are you creating windows in your thread? It is best to create all windows in the main thread, and use secondary threads for non-GUI processing.

When you create a thread in an MFC program you are supposed to use AfxBeginThread, not the CreateThread API.  AfxBeginThread will call CreateThread for you, after doing whatever MFC needs in order to work properly.


* Ref

https://social.msdn.microsoft.com/Forums/vstudio/en-US/38f58a71-2d5f-44fd-b3a1-37bafa6e54bd/assert-in-multithread-program-with-function-onidle0?forum=vcgeneral


설정

트랙백

댓글

Transformation matrix에서 Euler angle 구하기

카테고리 없음 2015. 1. 9. 13:57

아래 pdf에 보면, 12가지의 Euler angle 표현 방식에 대해 계산하는 법이 잘 설명되어 있다!

EulerAngles.pdf


설정

트랙백

댓글

Atan2 에 대하여.. (what is atan2?)

Research/Mathmatics 2015. 1. 8. 11:53

아래 내용은 끄적이는 것들이기 때문에 지속적으로 수정될 수 있음..

연구를 하다보면 삼각함수를 사용하게 될 경우가 많다. 

특히 기구학 등을 analytic하게 풀기 위해서는 반드시 필요한 문제가 되겠다.

이 때 sin, cos 과 함께 자주 사용되는 녀석은 atan 함수라고 할 수 잇다.

이 문제는 일례로 HTransform matrix를 통해 roll, pitch, yaw로 표현되는 orientation을 구할 때 발생할 수 있다.

생각해보자. tangent함수는 pi를 주기로 반복되는 함수다. (그림은 구글에서 퍼왔음)


따라서 2pi 범위 내에서는 해가 두 가지 존재할 수 있겠다! 

이것을 구분해 주는 방법이 필요하다는 사실을 직감할 수 있다!

(그렇지 않으면 아래와 같은 문제가 발생하겠지..)


그리고 또 한가지, tan함수는 불연속적으로 반복된다! pi/2 마다 infinite로 발산하고 있는 것을 알 수 있다.

이로 인해 우리가 고려해야 할 부분이 있다.atan의 인자로 사용되는 sin과 cos의 조합으로는 충분히 발생할 수 있는 문제가 있다는 것!

바로 분모가 0 이 되어 무한대가 발생하는 것!!

하지만 수학적으로 분모가 0이 된다는 것은 말이 되지 않는다. 

그래서 우리는 알고리즘적으로 분모가 0에 매우 가까울 경우에는 atan의 값이 ' +-(2n-1)pi/2 , n은 정수 '라고 가정할 수 있겠다!

그래서 atan을 정상적으로 사용하기 위해서는 아래와 같은 가정이 필요하게 된다.


하지만 이 모든 알고리즘을 내포하고 있는 것이 바로 atan2가 되시겠다. 짜잔!! 대단하다.

 다만 dx와 dy가 모두 0일 때에는 값이 정의되지 않음에 유의하자!

아래의 설명을 첨부한다. 굉장히 잘 설명하고 있다.





'Research > Mathmatics' 카테고리의 다른 글

Skew symmetric matrix  (0) 2015.04.15
Eigen Vectors and Eigen Values  (0) 2015.02.27
What is homogeneous transform?  (0) 2015.01.16
Fourier Transform (푸리에 변환)  (0) 2014.12.02

설정

트랙백

댓글

C++ 반전 연산자~와 논리 연산자 !의 차이

Skills/Programming 2014. 12. 16. 14:51

case CMD_TELEOPERATION:    

{

bETRI_Tele = !bETRI_Tele;

cout<<"bETRI_Tele : "<<bETRI_Tele<<endl;

}

MFC 다이얼로그를 통해 버튼을 누르면 위의 코드에 들어가게 해 두었다.

그런데 이상한 점 발견! 


bETRI_Tele = ~bETRI_Tele; 로 할 때에는 cout이 계속 1의 값을 반환한다는 것이다!

그러나 bETRI_Tele = !bETRI_Tele; 로 할 때에는 버튼을 누를 때마다 0과 1의 값이 반복되면서 제대로 잘 나온다.


일단, 그 원인은 ~가 bit 연산자라는 것에 있을 것으로 판단되고 boolean이 bit로 보았을 때에는 단순한 1과 0 이 아닐 것이라는 추측이 된다.

설정

트랙백

댓글

Sampling의 기본 개념

지난 시간 리뷰.

아래와 같은 정현파 신호가 있을 떄, 

주기적일 필요충분 조건은 f가 유리수이고, f가 k/n으로 표시되고 k와 n이 서로 소 일 때, n이 주기 값을 갖게 된다. 

그렇다면 아래와 같이 두 개의 정현파 신호의 선형 조합으로서 신호가 구성되어 있다면, 

그리고, 처음에 말한 필요충분 조건을 만족한다고 했을 때, f1 과 f2 의 최소 공배수를 주기로 갖는다.



어차피 fk는 f0와 동일한 이산시간 주파수를 갖는다. 이 때, fk는 f0의 alias 성분이라고 한다.

f가 특정한 범위 안에 있지 않은 값들은 특정한 범위 안에 있는 값으로 재해석 될 필요가 있다.

fundamental frequency 벗어나면 더 이상 unique한 표현식을 갖지 못한다.

이 fundamental frequency의 범위는 아래와 같고, 몹시 중요하다.



그런데 이 것을 잘 생각해보면, 

즉, 여기에서 우리는 아래와 같은 중요한 개념을 구할 수 있다.

sampling frequency는 최대 주파수 성분의 2배 이상이어야 한다. 

그래야 적절한 analog 신호와 이산신호 시간 사이의 관계를 구축할 수 있다. 




몇 가지 예제를 통해 점검해 보자.

우선 첫 번쨰 예제.

x1(t)는 10Hz의 주파수, x2(t)는 50Hz의 주파수를 갖는다.

이 때, sampling frequency가 100Hz는 되어야 할 텐데 40Hz밖에 되지 않는다.

즉, 문제가 발생한다는 것인데 어떻게 될 지 살펴보자.

x1(t)의 f1은 1/4, x2(t)의 f2는 5/4가 된다.  (f는 -1/2와 1/2 사이여야 하는데 f2는 이 범위 밖에 있다.)

(*이 떄, Fs/F는 샘플링 된 신호의 주파수.. 이산신호 주파수임(원래는 F라는 주파수를 갖는 아날로그 신호))

이렇게, 어떤 신호가 fundamental frequency의 범위 밖에 있을 때 (sampling frequency * 0.5)

와 같이 fundamental 주파수 내의 값과 정수의 합 표현으로 나타내면 된다.

즉, x2(t)는 5/4의 f2를 갖지만 사실은 1+1/4로 표현되어 1/4이 된다. 

즉, 이것을 물리적인 의미로 설명하자면.. x1과 x2 두 analog 신호를 40Hz로 sampling 했더니 동일한 이산시간 주파수를 갖는다는 것이다. (충분한 sampling frequency를 갖지 못했으므로... 그래서 F2는 F1의 alias 성분이 된 것이다.) 

이 현상을 주파수 도메인에서 다시 해석해보자. 

이 때, folding frequency라는 개념이 등장한다.

그리고 2번째 예제에서 볼 수 있듯, analog signal에서 이산신호로 적절히 sampling하기 위한 최소한의 주파수를 Nyquist frequency라고 한다. 


마지막 예제를 보자.


위 처럼, Fs가 충분하지 않게 sampling이 되면 다시 D/A를 했을 때 복원된 신호가 달라지게 된다. 

중간에는 fundamental frequency의 영역을 벗어난 주파수가 조절되는 과정이 있다.




'Research > Digital Signal Processing' 카테고리의 다른 글

정현파 신호  (0) 2014.12.11
주파수(frequency)란?  (0) 2014.12.11
Sampling Theorem  (0) 2014.12.11
A/D conversion (Analog to Digital) 과정  (0) 2014.12.11
신호(signal)란 무엇인가  (0) 2014.12.10

설정

트랙백

댓글

공유 메모리를 이용한 IPC

Skills/Programming 2014. 12. 15. 16:49

IPC (Inter Process Communication)란, 프로세스 간에 정보를 주고받을 수 있도록 하는 통신 기법

32bit 시스템에서는 각 프로세스에 제공되는 연속적인 4GB의 가상 메모리를 사용하는데, 가상 메모리 중 절반은 사용자 모드(스택, 힙)에 사용하고 나머지 절반은 커널 모드(운영체제가 관리)에 사용한다.

공유 메모리를 이용한 IPC는 커널 모드의 메모리 영역을 활용하여 프로세스 간에 서로 통신하는 기법임.


* Ref  (or copied from)

[1] 열혈강의 VISUAL C++ 2008 MFC 윈도우 프로그래밍, 최호성, 2009.

설정

트랙백

댓글

MFC dialog에서 콘솔(console)로 디버깅하기

Skills/Programming 2014. 12. 15. 15:09

MFC 다이얼로그를 이용하다 보면, 콘솔 응용프로그램을 코딩할 때처럼 printf 나 cout 같은 것으로 디버깅하고 싶을 때가 있다.. 그럴  떄 아래와 같은 방법으로 해결할 수 있다.


방법 1
App의 InitInstance에서 AllocConsole()을 호출한다.
디버그 모드에서만 동작할 것이므로 간단히 다음과 같이 할 수 있겠다.

#ifdef _DEBUG
    if( !AllocConsole() )
    {
        AfxMessage(_T("Failed to create the console!"), MB_ICONEXCLAMATION);
    }
#endif

해제하기 위해서는 ExitInstance에서 FreeColsole()을 호출한다.
이전과 마찬가지로 다음과 같이 쓰면 된다.

#ifdef _DEBUG
    if( !FreeConsole() )
    {
        AfxMessage(_T("Failed to free the console!"), MB_ICONEXCLAMATION);
    }
#endif

방법 2
stdafx.h에서 다음과 같이 입력한다.

#ifdef _DEBUG
#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console")
#endif


출력은 일반적인 콘솔 프로그램과 같이 cout이나 printf 등을 사용하면 된다.

설정

트랙백

댓글