2010年6月24日 星期四

Trick for releasing memory for C++ vector

For C++ vector, there's a huge problem that when you use either clear() or erase(), it won't release the memory for you. And there is "NO" direct way doing so. I searched on the internet and find one trick does that by using swap(). Here is the sample code by Tiyano (a student from Taiwan) explaining how it works.

#include
#include
using std::vector;
int main(void) {
vector A, B;
vector *C;
A.resize(1000);
printf("%d %d\n", A.size(), A.capacity());
A.clear();
printf("%d %d\n", A.size(), A.capacity());
A = B;
printf("%d %d\n", A.size(), A.capacity());
A.swap(B);
printf("%d %d\n", A.size(), A.capacity());
C = new vector;
C->resize(1000);
printf("%d %d\n", C->size(), C->capacity());
delete C;
C = new vector;
printf("%d %d\n", C->size(), C->capacity());
return 0;
}

The second method (new and delete) I'm not 100% sure it works, cuz in my case, the elements are pointers, so I adopt the first method which works.


2010年6月22日 星期二

[VTK]Volume Rendering

Intro:
VTK (Visualization toolkit) is an open source toolkit to do visualization.

I'm now using it to do volume rendering.
It's fine to do it with 1 scalar per point, but I can't find a way to do it with RGBA dataset.
Bellow is what I found on the internet related to this topic.


Here is a link I found which might help with volume rendering data input.

This is a thread for converting SimpleRayCast example from tcl to C++


Yeah!! Found a thread that is really useful. Confirmed by one of the author of vtk, they support 4-component data.
Here is the thread:
http://markmail.org/message/7abjuh22f7eywxty#query:vtk%20imagedata%204%20components+page:1+mid:7abjuh22f7eywxty+state:results

And here is my final solution.
Use vtkFixedPointVolumeRayCastMapper (vtkVolumeTextureMapper3D doesn't work on my computer) and also set the independentComponentOff for the volumeProperty. The first three components will be read as RGB and the fourth channel data will through the opacity function mapping.

SSE Implementation

This is the introduction from Toshiya which tells you how to implement the ray tracer with SSE.

My experiment:

Add two float[4] together for 10e8 times and compare it with add two __m128 with _mm_add().

Here is what I found through my experiment:
1. If you want the SSE implementation really to work, you have to optimize it (set optimize level when you compile it with gcc.) The performance can be at most nearly 4 times as fast as the implementation without SSE.

2. For my experiment, there is no big difference between using __m128 directly or using __m128* and allocate the memory with _mm_malloc(sizeof(__m128),16).
(From Toshiya: it's no difference between those two. The only thing matters is how to load the data (non-__m128 data). Using _mm_load + _mm_malloc will be compiled as faster instructions)


2009年3月27日 星期五

4/12 大小聚會

就是明明是小聚會又不小心邀請了太多人

主辦&主題:
Mr. 張宸銘花了一整年在準備GRE,已於4/1考完,為慶祝他的勝利,特集合大家慶祝他傲視群雄的成績。

時間:
4/12 中午12:00




台北市大安區忠孝東路4段170巷6弄10號


檢視較大的地圖
請仔細看清楚,我去了一次,表面還挺難找的。

邀請名單:
如果名單上有你不認識的人,那就是你都排擠大家,下次要多跟大家連絡。如果有你很想看到的人且他不在名單上,請通知我。我有可能會邀請他。相對的,如果有你很不想見到的人,交集我也很不想見到他,那我們就可以偷偷跟他說取消了。

聯絡:
有問題可以直接問我,謝謝

Sleep Coach Conference















This is my third project in
 CAE.CE@NTU, called Sleep Coach.

Basically, it's a device for people having sleep problem.
This device can record the sleep status (like keeping a diary). When users turn to professional helps (like a psychiatrist), doctor can easily diagnose the patient with sufficient data (not just some data come up with few moments before the appointment.) Besides, the device can control the environment for user for a better and suitable surrounding.

I take charge of the technical part of this device including UI, sensor, data processing.




















This is Dr. Powell, a famous pro
fessor in Sleep Technology in Stanford University. This conference is for sign MOU with him along with his team.















All members (Of course except some 
unimportant people like me) in this project which involves many different fields like psychology, engineering, design ...















One scenario of this project. (A patient and a  doctor)

2009年3月1日 星期日

SimuSurvey with Geography Demo



This is the current version of SimuSurvey.
Resulting from my display card and the recording software, the demo clip is a little defective.
Welcome to my office to see how the software run and its performance.

3/7 聚會地點資訊

我想就定這裡好了,

台大活動中心NASSAS

時間:3/7 , 11:30AM 


收費:

介紹:

地圖:


對地點有意見請回覆,我只吃過一次。
但如果你說你不能來那就真的很機車,我很早就約了。
就這樣