2010年10月31日星期日

To install CGAL 3.6 on Visual Studio 2010, Win 7

1. install cmake (using latest 2.8.1)
1.1. There is remark that you need to change CMakeVS10FindMake.cmake
where is that ?
If using Binary distribution, it will be $(CMAKE_DIR)\share\cmake-2.8\Modules

If you like to complie by yourself, it will be &(CMAKE_DIR)\Modules

1.2 To complie by yourself, you need to change the file first, and download cmake Binary to make project(it sounds wired but please see Installing CMake).

1.3 After making project, you can use Visual Studio 2010 to make binary
Sample open .sln file and run release

2. Configure your "system envirnoment", add $(CMAKE_DIR)\bin in "path" for you can execute cmake anytime.
For Binary ditribution: $(CMAKE_DIR)\bin (example)
For src compiled: $(CMAKE_DIR)\bin\$(OUTDIR)

3. Install Boost (latest 1.43.0)
because boostpro do not support vs 2010, you have to compile by yourself.

3.1 download Boost http://www.boost.org/users/download/

3.2 for build Boost "Boost Jam" http://sourceforge.net/projects/boost/files/boost-jam/3.1.18/

3.3 copy bjam.exe to $(boost_DIR)

3.4 run bjam --build-dir="d:\build-boost" --build-type=complete msvc

build-dir: is the dir to work

build-type=complete means to build all
remark: I have try skip this, and it works.

it takes about 1 hr to build complete, and about 20 min to do default
after building, file will in $(BOOST_DIR)/stage/lib

3.5 add "system environment" in "path" add "$(BOOST_DIR)"
this for CGAL know where is BOOST


4. Install Exact Arithmetic
CGAL support GMP+MPFR, MPFI, LEDA

This time the program I use only needs GMP + MPFR
CGAL said they provide precompile GMP + MPFR, but they do not support 2010 at this time.
Everything have do by yourself.
GMP is not support visual Studio. (may they don't like M$)
Luckly, there is someone porting to visual studio call MPIR

4.1 install MPIR
download from http://www.mpir.org/#release
they even have visual studio 2010 version very cool.
Sample unzip and open .sln
run release.

copy all ".h" file in the $(outdir) to $(CGAL)/auxiliary/gmp/include
copy all .lib and ".dll" file in the $(outdir) to $(CGAL)/auxiliary/gmp/lib

4.2 install MPFR
again, MPFR does not support VS
you can find someone provide vs 2008 project file here http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php
just download here

4.2.1 download MPFR http://www.mpfr.org/
because the project support 2.4.1 only, I use version 2.4.1
4.2.2 copy vs 2009 project file to $(MPFR_DIR)

4.2.3 copy all MPIR in $(OUT_DIR) files to $(MPFR_DIR)/../mpir

4.2.4 run $(MPFR_DIR)/build.vc9/lib_mpfr.sln

vs2010 will convert for you. it takes about 2 mins

change the lib_mpfr property... / configuration Property / Librarian /

additional Dependencies

../../mpir/....... -> ../../mpir/mpir.lib (or the path you put mpir.lib)

and run release..

4.2.5 run $(MPFR_DIR)/build.vc9/dll_mpfr.sln

change the dll_mpfr property... / configuration Property / Linker /

additional Dependencies

../../mpir/....... -> ../../mpir/mpir.lib (or the path you put mpir.lib)

and run release..

4.2.6 copy all ".h" file in the $(outdir) to $(CGAL)/auxiliary/gmp/include
copy all .lib and ".dll" file in the $(outdir) to $(CGAL)/auxiliary/gmp/lib
copy $(mpfr)/mpfr.h to $(CGAL)/auxiliary/gmp/include


5. Visualization
5.1 install Qt
Qt is going to support windows 7 and visual Studio 2010 at version Qt 4.7
so I download Qt 4.7 beta filename: qt-everywhere-opensource-src-4.7.0-beta1

5.2 unzip and set environments
environments set PATH += $(QT_DIR)/bin
set LIB += C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
set Include += C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include

5.3 fix some error
in $(QTDIR)\src\3rdparty\webkit\JavaScriptCore\runtime

at line 171
transitionTable()->add(key, Transition(structure, 0));
change to
transitionTable()->add(key, Transition(structure, nullptr));

at line 178
transitionTable()->add(key, Transition(0, structure));
change to
transitionTable()->add(key, Transition(nullptr, structure));

5.4 run configure at $(QT_DIR) using Visual Studio Command Prompt

because Qt didn't support vs2010, just use vs2008 setting

configure.exe -platform win32-msvc2008 -fast

on internet there is simple run command (less warning and no error): http://stackoverflow.com/questions/1644172/building-qt-4-5-with-visual-c-2010

configure.exe -platform win32-msvc2008 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast

you can choose any one is ok.

5.5 nmake

it takes long time if there is no error.

5.6 you finish installing QT

6. Miscellaneous
I didn't use this, so Skip this part

7. install CGAL
7.1 download CGAL http://www.cgal.org/download.html

7.2 unzip

7.3 fix cmake files
7.3.1 in $(CGAL)/cmake/modules/FindBoost.cmake

at line 569

if (MSVC90)
SET (_boost_COMPILER "-vc90")

add after that

elseif (MSVC10)
SET (_boost_COMPILER "-vc100")

7.3.2 in $(CGAL)/cmake/modules/CGAL_GeneratorSpecificSettings.cmake

at line 11

if ( MSVC90 )
set(CGAL_TOOLSET "vc90")
message( STATUS "Using VC90 compiler." )

add after that
elseif ( MSVC10 )
set(CGAL_TOOLSET "vc100")
message( STATUS "Using VC100 compiler." )


7.4 change GMP and MPFR lib name

CGAL will find GMP and MPFR lib name like $()-vc??-mt.lib
so please change "mpir.lib" to "gmp-vc100-mt.lib"
"mpfr.lib" to "mpfr-vc100-mt.lib"

7.5 use cmd.exe
and go to $(CGAL_DIR)
run cmake .

7.6 There si small bug in mpfr.h
at line 298 add #include
it fixed at version 2.4.2, however, i did not try this one.

7.6 open $(CGAL_DIR)/CGAL.sln
run release

7.7 fix auto_link.h
at $(CGAL_DIR)/include/CGAL/auto_link/auto_link.h
at line 141
original:

#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1500)

// vc90:
# define CGAL_LIB_TOOLSET "vc90"


change to:
#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1500)

// vc90:
# define CGAL_LIB_TOOLSET "vc90"

#elif defined(BOOST_MSVC) && (BOOST_MSVC > 1500)
// vc10:
# define CGAL_LIB_TOOLSET "vc100"

congratulations!! you finish installing CGAL

you can run some example from there
http://acg.cs.tau.ac.il/cgal-at-tau/installing-cgal-and-related-programs-on-windows

snapshot of the example



good luck!

note:
if your program can not find mpir.dll, just copy mpir.dll to your root of program

Boost及CGAL安装配置指南

1, 首先安装Boost,下载最新的boost ,解压到某个目录

首先要编译生成boost安装工具bjam
进入boost目录执行:
./bootstrap.sh
然后执行刚生成的
./bjam
编译开始,大约半小时,全部编译结束。
./bjam install 将当前目录下编译好的头文件拷贝到相应位置:在/usr/local/include下有头文件夹boost,在/usr/local/lib下有boost的库

2, 安装MPFR、GMP、geomview(可视化)和 libQGLViewer

sudo apt-get install libgmp3-dev libmpfr-dev
sudo apt-get install geomview


 下载 libqglviewer-devel_2.3.5_i386.deb(头文件及文档)和 libqglviewer_2.3.5_i386.deb(库文件),鼠标点击安装即可。 这时要重新做一个库文件的符号链接,

cd /usr/lib/
ln -sf libQGLViewer.so.2.3.4  libqglviewer.so


3, 安装qt3, qt4

sudo apt-get install libqt4-dev
sudo apt-get install libqt3-disigner


4, 下载最新的 CGAL, 它要要求boost要1.34.1以上。

cmake-gui .
make 
sudo make install


默认头文件装在 usr/local/include/,  库文件装在 usr/local/lib/. 



5,使用CGAL编译代码
复制scripts/cgal_create_cmake_script到你的工程目录,运行下列命令,将地址替换成你当前的工作目录
cmake -DCGAL_DIR=$HOME/CGAL-3.5
然后运行make,即可生成可执行文件

2010年10月26日星期二

虚函数

       虚函数的作用是实现动态联编,也就是在程序的运行阶段动态地选择合适的成员函数,在定义了虚函数后,可以在基类的派生类中对虚函数重新定义,在派生类中重新定义的函数应与虚函数具有相同的形参个数和形参类型。以实现统一的接口,不同定义过程。如果在派生类中没有对虚函数重新定义,则它继承其基类的虚函数。
  当程序发现虚函数名前的关键字virtual后,会自动将其作为动态联编处理,即在程序运行时动态地选择合适的成员函数。
  动态联编规定,只能通过指向基类的指针或基类对象的引用来调用虚函数,其格式:
  指向基类的指针变量名->虚函数名(实参表)
  或 基类对象的引用名. 虚函数名(实参表)
  虚函数是C++多态的一种表现
  例如:子类继承了父类的一个函数(方法),而我们把父类的指针指向子类,则必须把父类的该函数(方法)设为virtual(虚函数)。
  使用虚函数,我们可以灵活的进行动态绑定,当然是以一定的开销为代价。 如果父类的函数(方法)根本没有必要或者无法实现,完全要依赖子类去实现的话,可以把此函数(方法)设为virtual 函数名=0 我们把这样的函数(方法)称为纯虚函数。
  如果一个类包含了纯虚函数,称此类为抽象类 。

虚函数的实例

#include<iostream.h>
class Cshape
{ public: void SetColor( int color) { m_nColor=color;}
void virtual Display( void) { cout<<"Cshape"<<endl; }
private:
int m_nColor;
};
class Crectangle: public Cshape
{
public:
void virtual Display( void) { cout<<"Crectangle"<<endl; }
};
class Ctriangle: public Cshape
{
void virtual Display( void) { cout<<"Ctriangle"<<endl; }
};
class Cellipse :public Cshape
{
public: void virtual Display(void) { cout<<"Cellipse"<<endl;}
};
void main()
{
Cshape obShape;
Cellipse obEllipse;
Ctriangle obTriangle;
Crectangle obRectangle;
Cshape * pShape[4]=
{ &obShape, &obEllipse,&obTriangle, & obRectangle };
for( int I= 0; I< 4; I++)
pShape[I]->Display( );
}
本程序运行结果:
Cshape
Cellipse
Ctriangle
Crectangle

条件

所以,从以上程序分析,实现动态联编需要三个条件:
1、 必须把动态联编的行为定义为类的虚函数。
2、 类之间存在子类型关系,一般表现为一个类从另一个类公有派生而来。
3、 必须先使用基类指针指向子类型的对象,然后直接或者间接使用基类指针调用虚函数。

2010年10月21日星期四

ubuntu 卸载Ibus输入法,安装fcitx输入法及美化方案

卸载Ibus输入法
代码:sudo apt-get remove ibus
编译安装fcitx输入法
代码:
sudo apt-get install im-switch fcitx
sudo im-switch -s fcitx -z default
im-switch -s fcitx -z default
重启。
切换默认输入法:
im-switch -c

打开终端输入:gedit ~/.fcitx/config
[界面]
候选词个数=5
主窗口是否使用3D界面=0
输入条使用3D界面=0
主窗口隐藏模式=1
显示虚拟键盘=0
是否自动隐藏输入条=1
输入条是否居中=0
首次显示输入条=1
#输入条固定宽度(仅适用于码表输入法),0表示不固定宽度
输入条固定宽度=0
输入条偏移量X=0
输入条偏移量Y=12
序号后加点=1
显示打字速度=1
显示版本=1
光标色=102 159 66
主窗口背景色=255 255 255
主窗口线条色=255 255 255
主窗口输入法名称色=153 153 153 102 159 66 56 134 230
输入窗背景色=255 255 255
输入窗提示色=2 89 196
输入窗用户输入色=255 0 132
输入窗序号色=0 66 200
输入窗第一个候选字色=0 99 200
#该颜色值只用于拼音中的用户自造词
输入窗用户词组色=0 99 200
输入窗提示编码色=255 0 132
#五笔、拼音的单字/系统词组均使用该颜色
输入窗其它文本色=56 134 230
输入窗线条色=255 255 255
输入窗箭头色=193 227 151
虚拟键盘窗背景色=220 220 220
虚拟键盘窗字母色=80 0 0
虚拟键盘窗符号色=0 0 0

Ubuntu pdf中文方块问题

某些软件中文字体显示为方块的问题:

sudo gedit /etc/fonts/conf.d/49-sansserif.conf

找到倒数第4行的 sans-serif,将横杠替换为空格,即可解决。

<string>sans serif</string>

或者替换为

<string>WenQuanYi Zen Hei</string>

2010年10月20日星期三

Ubuntu 10.10硬盘安装方法

下载grub4dos 和Ubuntu10.10 ,将Ubuntu.iso和从其中解压出来的vmlinuz initrd.lz放在U盘。
然后,配置Grub引导:

           1、下载最新的grub4dos。
           2、解压,将grldr和grldr.mbr这两个文件复制到C盘根目录下。
           3、建立boot.ini文件:


          注:在vista或win7下必须要引号。
重启进入 Grub> 界面。
输入find /ubuntu.iso 显示为(hd1.0)
输入kernel (hd1,0)/vmlinuz boot=casper noacpi iso-scan/filename=/ubuntu.iso ro quiet splash
输入initrd (hd1,0)/initrd.lz
输入boot