2011年7月25日 星期一

推廣太陽能發電 愛護地球

一般的家庭用戶需要安裝多少片的太陽能光電板才夠呢?需要多少價錢?這要看一個家庭的電力需求來決定,一般的家庭電力需求約為4千瓦,以使用日本三洋電機功率195瓦的太陽能光電板為例(長130公分、寬90公分、厚3.5公分),需21片,每片面積為1.27平方公尺,故總架設面積為26.67平方公尺(約7坪)。含安裝電能轉換器與施工總價約需120萬元,但可向政府單位申請一半價錢的補助,因此只需60萬元即可安裝。
那需多久才能回收安裝成本呢?若以每日6小時的日照量來計算,4千瓦的太陽能板每日可發24度電(1千瓦小時為1度),那麼一年就可發8760度電。
在政府鼓勵民間興建電廠及高價回收的政策下,可以3倍的價錢(每度約8.5元)回賣給台電,因此一年可賣出74460元,約8年即可回收成本。在20年的使用期間內約可賺進90萬元,是個很划算的投資,且可作為環保尖兵,何樂而不為?

2011年7月20日 星期三

Read Write BMP pixel

//============================================

// 將 BMP imagedata 放入 image buffer 中
//============================================
Gdiplus::Color pixelColor;
int myPixLocation;
unsigned char *imageBuffer = (unsigned char *)malloc(640*480*4);
for(int ix=0; ix<640; ix++)
{
for(int iy=0; iy<480; iy++)
{
pBitmap->GetPixel(ix, iy, &pixelColor);
myPixLocation = (iy*640+ix)*4;
imageBuffer[myPixLocation+0] = (unsigned char)pixelColor.GetR();
imageBuffer[myPixLocation+1] = (unsigned char)pixelColor.GetG();
imageBuffer[myPixLocation+2] = (unsigned char)pixelColor.GetB();
}
}

int myTmpPixLoc;
unsigned char *myOutBuffer = (unsigned char *)imageOut;
for(int ix=0; ix<640; ix++)
{
for(int iy=0; iy<480; iy++)
{
myTmpPixLoc = (iy*640+ix)*4;
pBitmap->SetPixel(ix, iy, Gdiplus::Color(myOutBuffer[myTmpPixLoc], myOutBuffer[myTmpPixLoc+1], myOutBuffer[myTmpPixLoc+2]) );
}
}

2011年7月19日 星期二

OpenCL clCreateImage2D Sample

//================================
// OpenCL Kernel Function for element by element pixel access
//================================
__kernel void VidCapPixelAccess(__read_only image2d_t imageIn,__write_only image2d_t imageOut)
{
  const sampler_t sampler=CLK_NORMALIZED_COORDS_FALSE
  CLK_ADDRESS_CLAMP
  CLK_FILTER_NEAREST;

  int gid0 = get_global_id(0); // x
  int gid1 = get_global_id(1); // y

  uint4 pixel;

  pixel=read_imageui(imageIn,sampler,(int2)(gid0,gid1));
  write_imageui (imageOut,(int2)(gid0,gid1),pixel);
}



//================================
// OpenCL Main Program Segment
//================================
void *imageIn;
//void *imageOut;
cl_mem myClImageInBuffer;
cl_mem myClImageOutBuffer;
//imageOut = (void *)malloc(8 * (640*480*4));

//====> Allocate the OpenCL buffer memory object IMAGE
cl_image_format format;
format.image_channel_order = CL_RGBA;
format.image_channel_data_type = CL_UNSIGNED_INT8;

cl_mem_flags flags1 = CL_MEM_READ_ONLY;
myClImageInBuffer = clCreateImage2D (
  cxGPUContext,
  flags1,
  &format,
  640,
  480,
  0,
  0, //imageIn
  &ciErr1);

cl_mem_flags flags2 = CL_MEM_READ_WRITE;
myClImageOutBuffer = clCreateImage2D (
  cxGPUContext,
  flags2,
  &format,
  640,
  480,
  0,
  0, //imageOut
  &ciErr2);
ciErr1 = clSetKernelArg( ckKernel, 0, sizeof(cl_mem), (void*)&myClImageInBuffer);
ciErr1 = clSetKernelArg( ckKernel, 1, sizeof(cl_mem), (void*)&myClImageOutBuffer);

// 將 BMP imagedata 放入 image buffer 中
Rect rect(0, 0, 640, 480);
BitmapData* pBitmapData = new BitmapData;
pBitmap->LockBits(
  &rect,
  ImageLockModeRead,
  PixelFormat32bppARGB,
  pBitmapData
);
imageIn = pBitmapData->Scan0;
size_t origin[3] = {0, 0, 0};
size_t region[3] = {640, 480, 1}; //width, height depth

// Asynchronous write of data to GPU device (將來源:imageBuffer 放入 GPU: myClImageInBuffer)
// The row pitch is the number of bytes in each row
// Thus: width * 4 bytes each * sizeof(byte)
ciErr1 = clEnqueueWriteImage(
    cqCommandQueue, // command queue
    myClImageInBuffer, // to which buffer
    CL_TRUE, // whether is a blocking or non-blocking read
    origin, // const size_t origin[3]
    region, // const size_t region[3]
    640*sizeof(unsigned char) * 4, //width is bytes
    0,
    imageIn,
    0, // number events in wait list
    NULL, // event wait list pointer
    NULL); // event pointer

size_t szGlobalWorkSize[] = {640, 480};
size_t szLocalWorkSize[] = {16, 16};
// Launch kernel
// clEnqueueNDRangeKernel 會把執行一個 kernel 的動作加到 command queue 裡面
ciErr1 = clEnqueueNDRangeKernel(
    cqCommandQueue, // command queue
    ckKernel, // Which Kernel
    2, // Choose if we are using 1D, 2D or 3D work-items and work-group
    NULL, // Global work offset
    szGlobalWorkSize, // The total number of work-items (must have work_dim dimensions)
    szLocalWorkSize, // The number of work-items per work-group (must have work_dim dimensions)
    0, // number events in wait list
    NULL, // event wait list pointer
    NULL); // event pointer

// Synchronous/blocking read of results, and check accumulated errors
// 將 image buffer 放入 BMP imagedata 中
if (pOutBitmap == 0)
  pOutBitmap = ::new Gdiplus::Bitmap(640, 480, PixelFormat32bppRGB); //PixelFormat32bppARGB
BitmapData* pOutBitmapData = new BitmapData;
Rect outRect(0, 0, 640, 480);
pOutBitmap->LockBits(
  &outRect,
  ImageLockModeWrite,
  PixelFormat32bppARGB,
  pOutBitmapData
);

// clEnqueueReadBuffer 函式會把「將記憶體資料從 OpenCL 裝置複製到主記憶體」的動作加到 command queue 中
// The row pitch is the number of bytes in each row
// Thus: width * 4 bytes each * sizeof(byte)
ciErr1 = clEnqueueReadImage( cqCommandQueue, // command queue
  myClImageOutBuffer, // to which buffer
  CL_TRUE, // whether is a blocking or non-blocking read
  origin, // const size_t origin[3]
  region, // const size_t region[3]
  640*sizeof(unsigned char) * 4, //width is bytes
  0,
  pOutBitmapData->Scan0, //imageOut
  0, // number events in wait list
  NULL, // event wait list pointer
  NULL); // event pointer
pOutBitmap->UnlockBits(pOutBitmapData);

g.DrawImage(pOutBitmap, Gdiplus::Rect(0, 0, r.right, r.bottom));

//==== DONE ====

2011年7月13日 星期三

加州info

http://tw.myblog.yahoo.com/wanchen-lee/archive?l=f&id=36

http://chingfangwu.blogspot.com/2009/08/blog-post_28.html

http://home.gamer.com.tw/creationDetail.php?sn=1345148


关于学区,房子查询的网站

这个网站提供了灵活的学区的查询,当选定了学校以后,相应学区的边界会在地图上显示,然后就可以锁定那个区域进行房屋查找,对卖房,租房都适用。
http://schoolandhousing.com/home/index.html

矽谷生活
http://www.bayareadragon.com/forum/index.php

矽谷天空Blog
http://blog.yam.com/emilyml/category/2330678/page=1

2011年7月3日 星期日

OpenCL sample

http://enja.org/2010/07/20/adventures-in-opencl-part-1-5-cpp-bindings/

http://code.google.com/p/bullet/source/browse/branches/OpenCL/Demos/SpheresOpenCL/Shared/btIntegrationDemoDynamicsWorld.cpp?r=1756

Working Opencl CreateImage2D sample:
http://www.cse.ohio-state.edu/~suttmill/Float_2D_Texture_files/CPlusPlusCode.txt

Bitmap format:
http://www.fileformat.info/mirror/egff/ch03_04.htm


A test using opencl and openframeworks=>5000 particles interact with each other and mouse cursor.
this runs easily at 30fps but snapz killed the framerate a little
this is running only on cpu and letting opencl do its thing.
source for this can be downloaded here: code.google.com/​p/​ruisource/​
it includes a slightly modified version of the ofxOpenCL addon by Memo Akten.


OpenCL in openFrameworks example - 1 milion particles @ 100-200fps
This example is based on Rui's opencl example at http://vimeo.com/7298380.
Discussion on the matter at http://www.openframeworks.cc/forum/viewtopic.php?f=10&t=2728&p=15107#p15...
source code for ofxOpenCL and the above example at
http://code.google.com/p/ofxmsaof/downloads/list


__kernel void updateParticleWithoutCollision(__global Particle* pIn, __global float2* pOut, const float2 mousePos, const float2 dimensions){
int id = get_global_id(0);
__global Particle *p = &pIn[id];

float2 diff = mousePos - pOut[id];
float invDistSQ = 1.0f / dot(diff, diff);
diff *= 300.0f * invDistSQ;

p->vel += (dimensions*0.5 - pOut[id]) * CENTER_FORCE2 - diff* p->mass;
pOut[id] += p->vel;
p->vel *= DAMP2;

float speed2 = dot(p->vel, p->vel);
if(speed2mass);
}