Code Planet

为了发现更大的世界


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

ITK与VTK对象的互相转化

发表于 2014-01-17 | 更新于 2015-08-15 | 分类于 itk , vtk
ITK的数据流采用如图1所示流水线(pipeline)作业方式。遵循此方式,所处理的数据来龙去脉清晰明了。在图1中,数据流左边的ImageFile代表待处理的图像文件,而右边ImageFile则代表处理后的图像文件。ImageFileReade:将存贮图像文件读人到内存,形成Image,再调用所希望处理的Fileter算法(比如滤波、分割、配准等具体算法),将对读人的图像数据进行处理。最后,ImageFileWriter将处理的图像数据结果保存,或输人给图形显示系统(如VTK),进行数据可视化。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2014/01/wpid-6a95d74385b0102f698795abc3ba226b_ITKliucheng1.jpg)
VTK是C++语言开发的、公开源码的、面向对象的数据可视化软件开发包,并不单纯用于医学图像数据的可视化。VTK支持跨平台的编译,可以应用于Windows,Linux等系统。VTK支持包括数量、向量、张量、结构和测定体积等方法一系列可视化算法,VTK还支持包括建模。VTK的数据流同样采用流水线作业方式,如图2所示。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2014/01/wpid-6a95d74385b0102f698795abc3ba226b_VTKliucheng1.jpg)
vtkSource为整个可视化流的开始,比如读取、生成数据等。vtkFilte对输入源数据进行各种处理,与ITK的Fileter类似。原始数据经过各种Filte:的处理后,再由vtkMappe:转换(或映射)成可供其它算法模块直接使用的数据形式,比如为几何数据。vtkActor类用来描述绘制场景中一个实体,即绘制场景的某个角色(Actor)。通过SetMapper()方法,可以将几何数据的属性传递给Actor,再由vtkRenderer类将处理后的数据结果显示出来。
由于ITK和VTK的数据流都是采用流水线作业形式,比较方便地利用类库本身提供的类型转换类来实现,如图3所示。通过ITKtoVTKImageFilter类操作将ITK和VTK的图像数据连接了起来,VTK负责图像数据的显示,而ITK负责图像的处理,其中VTK的Image Viewe:是一个很方便实现的图像显示类,它在内部管理着vtkImageWindow, vtkRenderer, vtkActor2D和vtkImageMapper等图象类,实现图像查看、显示和可视化功能。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2014/01/wpid-6a95d74385b0102f698795abc3ba226b_ITKtoVTK1.jpg)
阅读全文 »

VTK Callbacks

发表于 2014-01-11 | 更新于 2015-08-15 | 分类于 vtk
简介:
回调函数就是命令/观察者模式中的观察者。VTK对象状态发生变化时,它就会发出一个命令通知所有观察家该事件。
为了捕获这个事件,你需要做下面几件事:
1\. 声明一个如下形式的函数:
**void** func(vtkObject*, **unsigned** **long** eid, **void*** clientdata, **void** *calldata)
2\. 创建一个vtkCallbackCommand对象,并将其回调函数设置为你自己创建的函数:
vtkSmartPointer<vtkCallbackCommand> keypressCallback = vtkSmartPointer<vtkCallbackCommand>::New(); keypressCallback->SetCallback ( func );
或者
2\. 创建一个vtkCallbackCommand并重写execute函数:
virtual void Execute(vtkObject *caller, unsigned long, void*)
它会在创建CallbackCommand对象后自动当成callback被执行
vtkSmartPointer<vtkCallbackCommand> keypressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
3\. 注册callback,监听命令
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow);renderWindowInteractor->AddObserver ( vtkCommand::KeyPressEvent, keypressCallback );
在这个例子中,vtkRenderWindowInteractor用来监听KeyPressEvent事件。
**caller**
vtkObject对象caller是观察者的指针。在例子中,因为我们是绑定vtkCallbackCommand在vtkRenderWindowInteractor对象上,所以我们可以强制类型转换caller到vtkRenderWindowInteractor类型。
**void** KeypressCallbackFunction ( vtkObject* caller, **long** **unsigned** **int** eventId, **void*** clientData, **void*** callData ) { cout << "Keypress callback" <<endl;vtkRenderWindowInteractor *iren = **static_cast**<vtkRenderWindowInteractor*>(caller); cout << "Pressed: " << iren->GetKeySym() << endl; }
**clientdata**
clientdata提供了一种方法来提供对数据的访问,将必要的回调函数。你可以使用vtkCallbackCommand函数的SetClientData方法设置该数据。假如,您想要访问回调函数的vtkProgrammableFilter实例,你可以这么做:
vtkSmartPointer<vtkProgrammableFilter> filter = vtkSmartPointer<vtkProgrammableFilter>::New();vtkSmartPointer<vtkCallbackCommand> timerCallback = vtkSmartPointer<vtkCallbackCommand>::New(); timerCallback->SetCallback ( func ); timerCallback->SetClientData(filter);
然后再回调函数中,你可以这样使用该数据:
**void** func ( vtkObject* caller, **long** **unsigned** **int** eventId, **void*** clientData, **void*** callData ) { vtkSmartPointer<vtkProgrammableFilter> programmableFilter = **reinterpret_cast**<vtkProgrammableFilter*>(clientData); }
完整范例:
#**include** <vtkPolyDataMapper.h> #**include** <vtkActor.h> #**include** <vtkSmartPointer.h> #**include** <vtkRenderWindow.h> #**include** <vtkRenderer.h> #**include** <vtkRenderWindowInteractor.h> #**include** <vtkPolyData.h> #**include** <vtkSphereSource.h> #**include** <vtkCallbackCommand.h> #**include** <vtkCommand.h>**static** **void** KeypressCallbackFunction ( vtkObject* caller, **long** **unsigned** **int** eventId, **void*** clientData, **void*** callData ); **int** main(**int**, **char** *[]) { // Create a sphere vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); sphereSource->SetCenter(0.0, 0.0, 0.0); sphereSource->SetRadius(5.0); sphereSource->Update(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(sphereSource->GetOutputPort()); // Create an actor vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); // A renderer and render window vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); // An interactor vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow); vtkSmartPointer<vtkCallbackCommand> keypressCallback = vtkSmartPointer<vtkCallbackCommand>::New(); // Allow the observer to access the sphereSource **keypressCallback->SetClientData(sphereSource);//设置clientdata对象** ** keypressCallback->SetCallback(KeypressCallbackFunction );//将回调命令与callback函数绑定** **renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent, keypressCallback);//监听keypress事件,绑定回调命令** renderer->AddActor(actor); renderer->SetBackground(1,1,1); // Background color white renderWindow->Render(); renderWindowInteractor->Start(); **return** EXIT_SUCCESS; } **void** KeypressCallbackFunction(vtkObject* caller, **long** **unsigned** **int** vtkNotUsed(eventId), **void*** clientData, **void*** vtkNotUsed(callData) ) { // Prove that we can access the sphere source ** vtkSphereSource* sphereSource = static_cast<vtkSphereSource*>(clientData);//强制类型转换为原来的对象** std::cout << "Radius is " << sphereSource->GetRadius() << std::endl; }
**calldata**
calldata是通过callback传递的数据。例如,当ProgressEvent事件被发送时,进程值可以作为calldata被一同发送。
完整范例:在这里例子中,我们创建一个自定义的VTK过滤器来调用我们绑定的带有calldata值的事件。我们使用一个定制的计时器来更新过滤器以便事件可以自动重复触发。更新过程为vtkMyTestFilter更新-> vtkCallbackCommand-> CallbackFunction
#**include** "vtkObjectFactory.h" #**include** "vtkCommand.h" #**include** "vtkCallbackCommand.h" #**include** "vtkStreamingDemandDrivenPipeline.h" #**include** "vtkInformationVector.h" #**include** "vtkInformation.h" #**include** "vtkDataObject.h" #**include** "vtkSmartPointer.h" #**include** "vtkAppendPolyData.h" #**include** "vtkSphereSource.h" #**include** "vtkPolyDataAlgorithm.h" #**include** "vtkRenderer.h" #**include** "vtkRenderWindow.h" #**include** "vtkRenderWindowInteractor.h" **class** vtkMyTestFilter : **public** vtkPolyDataAlgorithm { **public**: vtkTypeMacro(vtkMyTestFilter,vtkPolyDataAlgorithm); **static** vtkMyTestFilter *New(); **int** RefreshEvent; **protected**: vtkMyTestFilter() { **this**->SetNumberOfInputPorts(0); **this**->RefreshEvent = vtkCommand::UserEvent + 1; **this**->Counter = 0; } **int** RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) { **this**->InvokeEvent(**this**->RefreshEvent, &**this**->Counter); **this**->Counter++; **return** 1; } **private**: vtkMyTestFilter(**const** vtkMyTestFilter&); // Not implemented. **void** **operator**=(**const** vtkMyTestFilter&); // Not implemented. **unsigned** **int** Counter; }; vtkStandardNewMacro(vtkMyTestFilter); **static** **void** CallbackFunction(vtkObject* caller, **long** **unsigned** **int** eventId, **void*** clientData, **void*** callData ); **class** vtkTimerCallback : **public** vtkCommand { **public**: **static** vtkTimerCallback *New() { vtkTimerCallback *cb = **new** vtkTimerCallback; **return** cb; } **virtual** **void** Execute(vtkObject *vtkNotUsed(caller), **unsigned** **long** vtkNotUsed(eventId), **void** *vtkNotUsed(callData)) { TestFilter->Modified(); TestFilter->Update(); } vtkMyTestFilter* TestFilter; }; **int** main(**int**, **char** *[]) { // Create a renderer, render window, and interactor vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow); vtkSmartPointer<vtkMyTestFilter> testFilter = vtkSmartPointer<vtkMyTestFilter>::New(); vtkSmartPointer<vtkCallbackCommand> callback = vtkSmartPointer<vtkCallbackCommand>::New(); **callback->SetCallback(CallbackFunction );** **testFilter->AddObserver(testFilter->RefreshEvent, callback);//将callback函数绑定testFilter的更新事件** testFilter->Update(); renderWindow->Render(); renderWindowInteractor->Initialize(); // Sign up to receive TimerEvent vtkSmartPointer<vtkTimerCallback> timerCallback = vtkSmartPointer<vtkTimerCallback>::New(); timerCallback->TestFilter = testFilter; renderWindowInteractor->AddObserver(vtkCommand::TimerEvent, timerCallback); renderWindowInteractor->CreateRepeatingTimer(100); renderWindowInteractor->Start(); **return** EXIT_SUCCESS; } **void** CallbackFunction(vtkObject* vtkNotUsed(caller), **long** **unsigned** **int** vtkNotUsed(eventId), **void*** vtkNotUsed(clientData), **void*** callData ) { **unsigned** **int*** callDataCasted = **reinterpret_cast**<**unsigned** **int***>(callData); std::cout << *callDataCasted << std::endl; }

Command and Observer

发表于 2014-01-11 | 更新于 2015-08-15 | 分类于 design pattern

1.Observer(观察者模式)

主题对象管理某些数据,当主题内的数据发生改变,就通知观察者,观察者已经注册主题便会在主题数据发生改变时能够收到更新。一旦数据改变,新的数据会以某种形式送到观察者手上。
观察者模式定义了对象之间的一对多关系,当一个对象改变状态时,它的所有依赖者都会收到通知并自动更新。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2014/01/wpid-4056175e6cecd785cac776067999cc1e_obsv1.jpg)
例子:
#**include** <iostream> #**include** <set> #**include** <string> **using** **namespace** std; /////////////////////抽象模式定义 **class** CObservable; //观察者,纯虚基类 **class** CObserver { **public**: CObserver::CObserver(){}; **virtual** CObserver::~CObserver(){}; //当被观察的目标发生变化时,通知调用该方法 //来自被观察者pObs, 扩展参数为pArg **virtual** **void** Update(CObservable* pObs, **void*** pArg = NULL) = 0; }; //被观察者,即Subject **class** CObservable { **public**: CObservable() : m_bChanged(**false**) {}; **virtual** ~CObservable() {}; //注册观察者 **void** Attach(CObserver* pObs); //注销观察者 **void** Detach(CObserver* pObs); //注销所有观察者 **void** DetachAll(); //若状态变化,则遍历观察者,逐个通知更新 **void** Notify(**void*** pArg = NULL); //测试目标状态是否变化 **bool** HasChanged(); //获取观察者数量 **int** GetObserversCount(); **protected**: //设置状态变化!!!必须继承CObservable才能设置目标状态 **void** SetChanged(); //初始化目标为未变化状态 **void** ClearChanged(); **private**: **bool** m_bChanged; //状态 set<CObserver*> m_setObs; //set保证目标唯一性 }; /////////////////////抽象模式实现 **void** CObservable::Attach(CObserver* pObs) { **if** (!pObs) **return**; m_setObs.insert(pObs); } **void** CObservable::Detach(CObserver* pObs) { **if** (!pObs) **return**; m_setObs.erase(pObs); } **void** CObservable::DetachAll() { m_setObs.clear(); } **void** CObservable::SetChanged() { m_bChanged = **true**; } **void** CObservable::ClearChanged() { m_bChanged = **false**; } **bool** CObservable::HasChanged() { **return** m_bChanged; } **int** CObservable::GetObserversCount() { **return** m_setObs.size(); } **void** CObservable::Notify(**void*** pArg /* = NULL */) { **if** (!HasChanged()) **return**; cout << "notify observers…" << endl; ClearChanged(); set<CObserver*>::iterator itr = m_setObs.begin(); **for** (; itr != m_setObs.end(); itr++) { (*itr)->Update(**this**, pArg); } } /////////////////////具体应用类定义和实现 //bloger是发布者,即被观察者(subject) **class** CBloger : **public** CObservable { **public**: **void** Publish(**const** string &strContent) { cout << "bloger publish, content: " << strContent << endl; SetChanged(); Notify(**const_cast**<**char***>(strContent.c_str())); } }; //portal是发布者,即被观察者(subject) **class** CPortal : **public** CObservable { **public**: **void** Publish(**const** string &strContent) { cout << "portal publish, content: " << strContent << endl; SetChanged(); Notify(**const_cast**<**char***>(strContent.c_str())); } }; //RSS阅读器,观察者 **class** CRSSReader : **public** CObserver { **public**: CRSSReader(**const** string &strName) : m_strName(strName){} **virtual** **void** Update(CObservable* pObs, **void*** pArg = NULL) { **char*** pContent = **static_cast**<**char***>(pArg); //观察多个目标 **if** (**dynamic_cast**<CBloger*>(pObs)) { cout << m_strName << " updated from bloger, content: " << pContent << endl; } **else** **if** (**dynamic_cast**<CPortal*>(pObs)) { cout << m_strName << " updated from portal, content: " << pContent << endl; } } **private**: string m_strName; }; //Mail阅读器,观察者 **class** CMailReader : **public** CObserver { **public**: CMailReader(**const** string &strName) : m_strName(strName){} **virtual** **void** Update(CObservable* pObs, **void*** pArg = NULL) { **char*** pContent = **static_cast**<**char***>(pArg); **if** (**dynamic_cast**<CBloger*>(pObs)) { cout << m_strName << " updated from bloger, content: " << pContent << endl; } **if** (**dynamic_cast**<CPortal*>(pObs)) { cout << m_strName << " updated from portal, content: " << pContent << endl; } } **private**: string m_strName; }; /////////////////Main **int** main() { //目标(被观察者) CBloger* pBloger = **new** CBloger(); CPortal* pPortal = **new** CPortal(); //观察者. 一个观察者可以观察多个目标 CRSSReader* pRssReader = **new** CRSSReader("rss reader"); CMailReader* pMailReader = **new** CMailReader("mail reader"); pBloger->Attach(pRssReader); //bloger注册观察者 pBloger->Attach(pMailReader); //bloger注册观察者 pPortal->Attach(pRssReader); //portal注册观察者 pPortal->Attach(pMailReader); //portal注册观察者 //博客发布信息 pBloger->Publish("博客分享设计模式"); cout << endl; //门户发布信息 pPortal->Publish("门户分享设计模式"); cout << "\nportal detached mail reader" << endl; pPortal->Detach(pMailReader); cout << "portal observers count: " << pPortal->GetObserversCount() << endl << endl; pPortal->Publish("门户分享设计模式"); system("pause"); **return** 0; }
**2.Command(命令模式)**
命令模式通俗的例子:在餐厅,顾客订餐,把订单交给女招待,女招待拿了订单,交给厨师,厨师根据订单准备食物。一张订单封装了准备食物的请求。女招待的工作就是接受订单,然后调用订单的orderUp()方法。
命令模式,将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤消的操作。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2014/01/wpid-4056175e6cecd785cac776067999cc1e_cmd1.jpg)
示例代码:
#**include** <iostream> #**include** <vector> **using** **namespace**std;// 烤肉师傅 **class** RoastCook { **public**: **void** MakeMutton() { cout << "烤羊肉" <<endl; }**void** MakeChickenWing() { cout << "烤鸡翅膀" << endl; } }; // 抽象命令类 **class** Command { **public**: Command(RoastCook* temp) { receiver = temp; } **virtual** **void** ExecuteCmd() = 0; **protected**: RoastCook* receiver; }; // 烤羊肉命令 **class** MakeMuttonCmd : **public** Command { **public**: MakeMuttonCmd(RoastCook* temp) : Command(temp) {} **virtual** **void** ExecuteCmd() { receiver->MakeMutton(); } }; // 烤鸡翅膀命令 **class** MakeChickenWingCmd : **public** Command { **public**: MakeChickenWingCmd(RoastCook* temp) : Command(temp) {} **virtual** **void** ExecuteCmd() { receiver->MakeChickenWing(); } }; // 服务员类 **class** Waiter { **public**: **void** SetCmd(Command* temp); // 通知执行 **void** Notify(); **protected**: vector<Command*> m_commandList; }; **void** Waiter::SetCmd(Command* temp) { m_commandList.push_back(temp); cout << "增加订单" << endl; } **void** Waiter::Notify() { vector<Command*>::iterator it; **for** (it=m_commandList.begin(); it!=m_commandList.end(); ++it) { (*it)->ExecuteCmd(); } } **int** main() { // 店里添加烤肉师傅、菜单、服务员等顾客 RoastCook* cook = **new** RoastCook(); Command* cmd1 = **new** MakeMuttonCmd(cook); Command* cmd2 = **new** MakeChickenWingCmd(cook); Waiter* girl = **new** Waiter(); // 点菜 girl->SetCmd(cmd1); girl->SetCmd(cmd2); // 服务员通知 girl->Notify(); system("pause"); **return** 0; }
**3.Command 和 Observer 的一些区别**
1.Command封装一个请求对象,Observer定义一种一对多的依赖关系;
2.Command通过对象解耦,Observer可以通过消息解耦;
3.Command可以有执行和撤消操作,所以从某种意义上来说,Command是有序的,Observer是无序的;
4.Command是在主类中通过接口调用各客户端子类的功能,Observer支持主类将更新通知给客户端,然后由客户端自行处理。
[参考]:http://www.cnblogs.com/Random/archive/2012/03/21/2409090.html

VTK交互器类

发表于 2014-01-10 | 更新于 2015-08-15 | 分类于 vtk
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2014/01/wpid-a1f1b74175b38a31db58e3eaaa7a9c9f_188999571.png)
[vtkInteractorStyle](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyle.html) Provide event-driven interface to the rendering window (defines trackball mode)
[vtkInteractorStyleAreaSelectHover](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleAreaSelectHover.html) An interactor style for an area tree view
[vtkInteractorStyleFlight](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleFlight.html) Flight motion routines
[vtkInteractorStyleImage](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleImage.html) Interactive manipulation of the camera specialized for images
[vtkInteractorStyleJoystickActor](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleJoystickActor.html) Manipulate objects in the scene independently of one another
[vtkInteractorStyleJoystickCamera](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleJoystickCamera.html) Interactive manipulation of the camera
[vtkInteractorStyleRubberBand2D](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleRubberBand2D.html) A rubber band interactor for a 2D view
[vtkInteractorStyleRubberBand3D](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleRubberBand3D.html) A rubber band interactor for a 3D view
[vtkInteractorStyleRubberBandPick](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleRubberBandPick.html) Like TrackBallCamera, but this can pick props underneath a rubber band selection rectangle
[vtkInteractorStyleRubberBandZoom](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleRubberBandZoom.html) Zoom in by amount indicated by rubber band box
[vtkInteractorStyleSwitch](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleSwitch.html) Class to swap between interactory styles
[vtkInteractorStyleTerrain](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleTerrain.html) Manipulate camera in scene with natural view up (e.g., terrain)
[vtkInteractorStyleTrackball](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleTrackball.html) Trackball motion control
[vtkInteractorStyleTrackballActor](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleTrackballActor.html) Manipulate objects in the scene independent of each other
[vtkInteractorStyleTrackballCamera](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleTrackballCamera.html) Interactive manipulation of the camera
[vtkInteractorStyleTreeMapHover](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleTreeMapHover.html) An interactor style for a tree map view
[vtkInteractorStyleUnicam](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleUnicam.html) Unicam navigation style
[vtkInteractorStyleUser](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleUser.html) Customizable interaction routines
**vtkImageViewer2**类中包含的交互方式为vtkInteractorStyleImage
具体操作如下:
[vtkInteractorStyleImage](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleImage.html "interactive manipulation of the camera specialized for images") allows the user to interactively manipulate (rotate, pan, zoom etc.) the camera. [vtkInteractorStyleImage](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleImage.html "interactive manipulation of the camera specialized for images") is specially designed to work with images that are being rendered with [vtkImageActor](http://www.vtk.org/doc/release/5.10/html/classvtkImageActor.html "draw an image in a rendered 3D scene"). Several events are overloaded from its superclass [vtkInteractorStyle](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyle.html "provide event-driven interface to the rendering window (defines trackball mode)"), hence the mouse bindings are different. (The bindings keep the camera's view plane normal perpendicular to the x-y plane.) In summary the mouse events for 2D image interaction are as follows:
* Left Mouse button triggers window level events * CTRL Left Mouse spins the camera around its view plane normal * SHIFT Left Mouse pans the camera * CTRL SHIFT Left Mouse dollys (a positional zoom) the camera * Middle mouse button pans the camera * Right mouse button dollys the camera. * SHIFT Right Mouse triggers pick events If [SetInteractionModeToImageSlicing()](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleImage.html#a3897a9aafe8321ae5334b853f027c594) is called, then some of the mouse events are changed as follows: * CTRL Left Mouse slices through the image * SHIFT Middle Mouse slices through the image * CTRL Right Mouse spins the camera If [SetInteractionModeToImage3D()](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleImage.html#ac31daacacca6214771212d71413d72e0) is called, then some of the mouse events are changed as follows: * SHIFT Left Mouse rotates the camera for oblique slicing * SHIFT Middle Mouse slices through the image * CTRL Right Mouse also slices through the image In all modes, the following key bindings are in effect: * R Reset the Window/Level * X Reset to a sagittal view * Y Reset to a coronal view * Z Reset to an axial view Note that the renderer's actors are not moved; instead the camera is moved. **QVTKWidget**是qt类中图像显示控件,其中也包含vtkInteractorStyleTrackballCamera交互方式
具体功能如下:
[vtkInteractorStyleTrackballCamera](http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyleTrackballCamera.html "interactive manipulation of the camera") allows the user to interactively manipulate (rotate, pan, etc.) the camera, the viewpoint of the scene. In trackball interaction, the magnitude of the mouse motion is proportional to the camera motion associated with a particular mouse binding. For example, small left-button motions cause small changes in the rotation of the camera around its focal point. For a 3-button mouse, the left button is for rotation, the right button for zooming, the middle button for panning, and ctrl + left button for spinning. (With fewer mouse buttons, ctrl + shift + left button is for zooming, and shift + left button is for panning.)

机器学习经典书籍

发表于 2014-01-10 | 更新于 2015-08-15 | 分类于 machine learning

入门书单

  1. 《数学之美》 PDF作者吴军大家都很熟悉。以极为通俗的语言讲述了数学在机器学习和自然语言处理等领域的应用。
  2. 《Programming Collective Intelligence》(《集体智慧编程》)PDF作者Toby Segaran也是《BeautifulData : The Stories Behind Elegant Data Solutions》(《数据之美:解密优雅数据解决方案背后的故事》)的作者。这本书最大的优势就是里面没有理论推导和复杂的数学公式,是很不错的入门书。目前中文版已经脱销,对于有志于这个领域的人来说,英文的pdf是个不错的选择,因为后面有很多经典书的翻译都较差,只能看英文版,不如从这个入手。还有,这本书适合于快速看完,因为据评论,看完一些经典的带有数学推导的书后会发现这本书什么都没讲,只是举了很多例子而已。
  3. 《Algorithms of the Intelligent Web》(《智能web算法》)PDF作者Haralambos Marmanis、Dmitry Babenko。这本书中的公式比《集体智慧编程》要略多一点,里面的例子多是互联网上的应用,看名字就知道。不足的地方在于里面的配套代码是BeanShell而不是python或其他。总起来说,这本书还是适合初学者,与上一本一样需要快速读完,如果读完上一本的话,这一本可以不必细看代码,了解算法主要思想就行了。
  4. 《统计学习方法》 PDF作者李航,是国内机器学习领域的几个大家之一,曾在MSRA任高级研究员,现在华为诺亚方舟实验室。书中写了十个算法,每个算法的介绍都很干脆,直接上公式,是彻头彻尾的“干货书”。每章末尾的参考文献也方便了想深入理解算法的童鞋直接查到经典论文;本书可以与上面两本书互为辅助阅读。
  5. 《Machine Learning》(《机器学习》) PDF作者Tom Mitchell是CMU的大师,有机器学习和半监督学习的网络课程视频。这本书是领域内翻译的较好的书籍,讲述的算法也比《统计学习方法》的范围要大很多。据评论这本书主要在于启发,讲述公式为什么成立而不是推导;不足的地方在于出版年限较早,时效性不如PRML。但有些基础的经典还是不会过时的,所以这本书现在几乎是机器学习的必读书目。
  6. 《Mining of Massive Datasets》(《大数据》) PDF作者Anand Rajaraman[3]、Jeffrey David Ullman,Anand是Stanford的PhD。这本书介绍了很多算法,也介绍了这些算法在数据规模比较大的时候的变形。但是限于篇幅,每种算法都没有展开讲的感觉,如果想深入了解需要查其他的资料,不过这样的话对算法进行了解也足够了。还有一点不足的地方就是本书原文和翻译都有许多错误,勘误表比较长,读者要用心了。
  7. 《Data Mining: Practical Machine Learning Tools and Techniques》(《数据挖掘:实用机器学习技术》) PDF作者Ian H. Witten 、Eibe Frank是weka的作者、新西兰怀卡托大学教授。他们的《ManagingGigabytes》[4]也是信息检索方面的经典书籍。这本书最大的特点是对weka的使用进行了介绍,但是其理论部分太单薄,作为入门书籍还可,但是,经典的入门书籍如《集体智慧编程》、《智能web算法》已经很经典,学习的话不宜读太多的入门书籍,建议只看一些上述两本书没讲到的算法。
  8. 《机器学习及其应用》周志华、杨强主编。来源于“机器学习及其应用研讨会”的文集。该研讨会由复旦大学智能信息处理实验室发起,目前已举办了十届,国内的大牛如李航、项亮、王海峰、刘铁岩、余凯等都曾在该会议上做过讲座。这本书讲了很多机器学习前沿的具体的应用,需要有基础的才能看懂。如果想了解机器学习研究趋势的可以浏览一下这本书。关注领域内的学术会议是发现研究趋势的方法嘛。
  9. 《Managing Gigabytes》(深入搜索引擎)PDF信息检索不错的书。
  10. 《Modern Information Retrieval》 PDFRicardo Baeza-Yates et al. 1999。貌似第一本完整讲述IR的书。可惜IR这些年进展迅猛,这本书略有些过时了。翻翻做参考还是不错的。另外,Ricardo同学现在是Yahoo Research for Europe and Latin Ameria的头头。
  11. 《推荐系统实践》 PDF项亮,不错的入门读物

深入

  1. 《Pattern Classification》(《模式分类》第二版) PDF作者Richard O. Duda[5]、Peter E. Hart、David。模式识别的奠基之作,但对最近呈主导地位的较好的方法SVM、Boosting方法没有介绍,被评“挂一漏万之嫌”。
  2. 《Pattern Recognition And Machine Learning》 PDF作者Christopher M. Bishop[6];简称PRML,侧重于概率模型,是贝叶斯方法的扛鼎之作,据评“具有强烈的工程气息,可以配合stanford 大学 Andrew Ng 教授的 Machine Learning 视频教程一起来学,效果翻倍。”
  3. 《The Elements of Statistical Learning : Data Mining, Inference, andPrediction》,(《统计学习基础:数据挖掘、推理与预测》第二版) PDF作者RobertTibshirani、Trevor Hastie、Jerome Friedman。“这本书的作者是Boosting方法最活跃的几个研究人员,发明的Gradient Boosting提出了理解Boosting方法的新角度,极大扩展了Boosting方法的应用范围。这本书对当前最为流行的方法有比较全面深入的介绍,对工程人员参考价值也许要更大一点。另一方面,它不仅总结了已经成熟了的一些技术,而且对尚在发展中的一些议题也有简明扼要的论述。让读者充分体会到机器学习是一个仍然非常活跃的研究领域,应该会让学术研究人员也有常读常新的感受。”[7]
  4. 《Data Mining:Concepts andTechniques》(《数据挖掘:概念与技术》第三版) PDF作者(美)Jiawei Han[8]、(加)Micheline Kamber、(加)Jian Pei,其中第一作者是华裔。本书毫无疑问是数据挖掘方面的的经典之作,不过翻译版总是被喷,没办法,大部分翻译过来的书籍都被喷,想要不吃别人嚼过的东西,就好好学习英文吧。
  5. 《AI, Modern Approach 2nd》 PDFPeter Norvig,无争议的领域经典。
  6. 《Foundations of Statistical Natural Language Processing》 PDF自然语言处理领域公认经典。
  7. 《Information Theory:Inference and Learning Algorithms》 PDF
  8. 《Statistical Learning Theory》 PDFVapnik的大作,统计学界的权威,本书将理论上升到了哲学层面,他的另一本书《The Nature ofStatistical Learning Theory》也是统计学习研究不可多得的好书,但是这两本书都比较深入,适合有一定基础的读者。

数学基础

  1. 《矩阵分析》 PDFRoger Horn。矩阵分析领域无争议的经典
  2. 《概率论及其应用》 PDF威廉·费勒。极牛的书,可数学味道太重,不适合做机器学习的
  3. 《All Of Statistics》 PDF 扫描版 PDF 高清版机器学习这个方向,统计学也一样非常重要。推荐All of statistics,这是CMU的一本很简洁的教科书,注重概念,简化计算,简化与Machine Learning无关的概念和统计内容,可以说是很好的快速入门材料。
  4. 《Nonlinear Programming, 2nd》 PDF最优化方法,非线性规划的参考书。
  5. 《Convex Optimization》 PDF 配套代码Boyd的经典书籍,被引用次数超过14000次,面向实际应用,并且有配套代码,是一本不可多得的好书。
  6. 《Numerical Optimization》 PDF第二版,Nocedal著,非常适合非数值专业的学生和工程师参考,算法流程清晰详细,原理清楚。
  7. 《Introduction to Mathematical Statistics》 PDF第六版,Hogg著,本书介绍了概率统计的基本概念以及各种分布,以及ML,Bayesian方法等内容。
  8. 《An Introduction to Probabilistic Graphical Models》 PDFJordan著,本书介绍了条件独立、分解、混合、条件混合等图模型中的基本概念,对隐变量(潜在变量)也做了详细介绍,相信大家在隐马尔科夫链和用Gaussian混合模型来实现EM算法时遇到过这个概念。
  9. 《Probabilistic Graphical Models-Principles and Techniques》 PDFKoller著,一本很厚很全面的书,理论性很强,可以作为参考书使用。
  10. 具体数学 PDF经典

【来源】http://suanfazu.com/discussion/109/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E7%BB%8F%E5%85%B8%E4%B9%A6%E7%B1%8D

机器学习经典论文/survey合集

发表于 2014-01-10 | 更新于 2015-08-15 | 分类于 machine learning

Active Learning

  • Two Faces of Active Learning, Dasgupta, 2011
  • Active Learning Literature Survey, Settles, 2010
    Applications

  • A Survey of Emerging Approaches to Spam Filtering, Caruana, 2012

  • Ambient Intelligence: A Survey, Sadri, 2011
  • A Survey of Online Failure Prediction Methods, Salfner, 2010
  • Anomaly Detection: A Survey, Chandola, 2009
  • Mining Data Streams: A Review, Gaber, 2005
  • Workflow Mining: A Survey of Issues and Approaches, Aalst, 2003
    Biology

  • Support Vector Machines in Bioinformatics: a Survey, Chicco, 2012

  • Computational Epigenetics: The New Scientific Paradigm , Lim, 2010
  • Automated Protein Structure Classification: A Survey, Hassanzadeh, 2009
  • Chemoinformatics - An Introduction for Computer Scientists, Brown, 2009
  • Computational Challenges in Systems Biology, Heath, 2009
  • Computational Epigenetics , Bock, 2008
  • Progress and Challenges in Protein Structure Prediction, Zhang, 2008
  • A Review of Feature Selection in Bioinformatics, Saeys, 2007
  • Machine Learning in Bioinformatics: A Brief Survey and Recommendations for Practitioners, Bhaskar, 2006
  • Bioinformatics - An Introduction for Computer Scientists, Cohen, 2004
  • Computational Systems Biology, Kitano, 2002
  • Protein Structure Prediction and Structural Genomics, Baker, 2001
  • Recent Developments and Future Directions in Computational Genomics, Tsoka, 2000
  • Molecular Biology for Computer Scientists, Hunter, 1993
    Classification

  • Supervised Machine Learning: A Review of Classification Techniques, Kotsiantis, 2007
    Clustering

  • XML Data Clustering: An Overview, Algergawy, 2011

  • Data Clustering: 50 Years Beyond K-Means, Jain, 2010
  • Clustering Stability: An Overview, Luxburg, 2010
  • Parallel Clustering Algorithms: A Survey, Kim, 2009
  • A Survey: Clustering Ensembles Techniques, Ghaemi, 2009
  • A Tutorial on Spectral Clustering, Luxburg, 2007
  • Survey of Clustering Data Mining Techniques, Berkhin, 2006
  • Survey of Clustering Algorithms, Xu, 2005
  • Clustering of Time Series Data - A Survey, Liao, 2005
  • Clustering Methods, Rokach, 2005
  • Recent Advances in Clustering: A Brief Survey, Kotsiantis, 2004
  • Subspace Clustering for High Dimensional Data: A Review, Parsons, 2004
  • Unsupervised and Semi-supervised Clustering: a Brief Survey, Grira, 2004
  • Clustering in Life Sciences, Zhao, 2002
  • On Clustering Validation Techniques, Halkidi, 2001
  • Data Clustering: A Review, Jain, 1999
  • A Survey of Fuzzy Clustering, Yang, 1993
    Computer Vision

  • Pedestrian Detection: An Evaluation of the State of the Art, Dollar, 2012

  • A Comparative Study of Palmprint Recognition Algorithms, Zhang, 2012
  • Human Activity Analysis: A Review, Aggarwal, 2011
  • Subspace Methods for Face Recognition, Rao, 2010
  • Context Based Object Categorization: A Critical Survey, Galleguillos, 2010
  • Object tracking: A Survey, Yilmaz, 2006
  • Detecting Faces in Images: A Survey, Yang, 2002
    Databases

  • Data Fusion, Bleiholder, 2008

  • Duplicate Record Detection: A Survey, Elmagarmid, 2007
  • Overview of Record Linkage and Current Research Directions, Winkler, 2006
  • A Survey of Schema-based Matching Approaches, Shvaiko, 2005
    Deep Learning

  • Representation Learning: A Review and New Perspectives, Bengio, 2012
    Dimension Reduction

  • Dimensionality Reduction: A Comparative Review, Maaten, 2009

  • Dimension Reduction: A Guided Tour, Burges, 2009
  • A Survey of Manifold-Based Learning Methods, Huo, 2007
  • Toward Integrating Feature Selection Algorithms for Classification and Clustering, Liu, 2005
  • An Introduction to Variable and Feature Selection, Guyon, 2003
  • A Survey of Dimension Reduction Techniques, Fodor, 2002
    Economics

  • Auctions and Bidding: A Guide for Computer Scientists, Parsons, 2011

  • Computational Sustainability, Gomes, 2009
  • Computational Finance, Tsang, 2004
    Game Theory

  • Computer Poker: A Review, Rubin, 2011
    Graphical Models

  • An Introduction to Variational Methods for Graphical Models, Jordan, 1999
    Kernel Methods

  • Kernels for Vector-Valued Functions: a Review, Alvarez, 2012
    Learning Theory

  • Introduction to Statistical Learning Theory, Bousquet, 2004
    Machine Learning

  • A Few Useful Things to Know about Machine Learning, Domingos, 2012

  • A Tutorial on Bayesian Nonparametric Models, Blei, 2011
  • Decision Forests for Classification, Regression, Density Estimation, Manifold Learning and Semi-Supervised Learning, Criminisi, 2011
  • Top 10 Algorithms in Data Mining, Wu, 2008
  • Semi-Supervised Learning Literature Survey, Zhu, 2007
  • Interestingness Measures for Data Mining: A Survey, Geng, 2006
  • A Survey of Interestingness Measures for Knowledge Discovery, McGarry, 2005
  • A Tutorial on the Cross-Entropy Method, Boer, 2005
  • A Survey of Kernels for Structured Data, Gartner, 2003
  • Survey on Frequent Pattern Mining, Goethals, 2003
  • The Boosting Approach to Machine Learning: An Overview, Schapire, 2003
  • A Survey on Wavelet Applications in Data Mining, Li, 2002
    Mathematics

  • Topology and Data, Carlsson, 2009
    Multi-armed Bandit

  • Regret Analysis of Stochastic and Nonstochastic Multi-armed Bandit Problems, Bubeck, 2012
    Natural Computing

  • Reservoir Computing Approaches to Recurrent Neural Network Training, Jaeger, 2009

  • Artificial Immune Systems, Aickelin, 2005
  • A Survey of Evolutionary Algorithms for Data Mining and Knowledge Discovery, Freitasï¾ , 2003
  • Data Mining in Soft Computing Framework: A Survey, Mitra, 2002
  • Neural Networks for Classification: A Survey, Zhang, 2000
    Natural Language Processing

  • Probabilistic Topic Models, Blei, 2012

  • Ontology Learning From Text: A Look Back And Into The Future, Wong, 2012
  • Machine Transliteration Survey, Karimi, 2011
  • Translation Techniques in Cross-Language Information Retrieval, Zhou, 2011
  • Comprehensive Review of Opinion Summarization, Kim, 2011
  • A Survey on Sentiment Detection of Reviews, Tang, 2009
  • Word Sense Desambiguation: A Survey, Navigli, 2009
  • Topic Models, Blei, 2009
  • Opinion Mining and Sentiment Analysis, Pang, 2008
  • Information Extraction, Sarawagi, 2008
  • Statistical Machine Translation, Lopez, 2008
  • A Survey of Named Entity Recognition and Classification, Nadeau, 2007
  • Adaptive Information Extraction, Turmo, 2006
  • Survey of Text Clustering, Jing, 2005
  • Machine Learning in Automated Text Categorization, Sebastiani, 2002
  • Web Mining Research: A Survey, Kosala, 2000
    Networks

  • Community Detection in Graphs, Fortunato, 2010

  • A Survey of Statistical Network Models, Goldenberg, 2010
  • Communities in Networks, Porter, 2009
  • Graph Clustering, Schaeffer, 2007
  • Graph Mining: Laws, Generators, and Algorithms, Chakrabarti, 2006
  • Comparing Community Structure Identification, Danon, 2005
  • Link Mining: A Survey, Getoor, 2005
  • Detecting Community Structure in Networks, Newman, 2004
  • Link Mining: A New Data Mining Challenge, Getoor, 2003
    On-Line Learning

  • On-Line Algorithms in Machine Learning, Blum, 1998
    Others

  • A Survey of Very Large-Scale Neighborhood Search Techniques, Ahuja, 2001
    Planning and Scheduling

  • A Review of Machine Learning for Automated Planning, Jimenez, 2009
    Probabilistic

  • Approximate Policy Iteration: A Survey and Some New Methods, Bertsekas, 2011

  • An Introduction to MCMC for Machine Learning, Andrieu, 2003
    Probabilistic Models

  • An Introduction to Conditional Random Fields, Sutton, 2010
    Randomized Algorithms

  • Randomized Algorithms for Matrices and Data, Mahoney, 2011
    Recommender Systems

  • Recent advances in Personalized Recommender Systems, Liu, 2009

  • Matrix Factorization Techniques for Recommender Systems, Koren, 2009
  • A Survey of Collaborative Filtering Techniques, Su, 2009
    Regression

  • Ensemble Approaches for Regression: a Survey, Moreira, 2012
    Reinforcement Learning

  • A Survey of Reinforcement Learning in Relational Domains, Otterlo, 2005

  • Reinforcement Learning: A Survey, Kaelbling, 1996
    Rule Learning

  • Association Mining, Ceglar, 2006

  • Algorithms for Association Rule Mining - A General Survey and Comparison, Hipp, 2000
    Testing

  • Controlled Experiments on the Web: Survey and Practical Guide, Kohavi, 2009
    Time Series

  • Time-Series Data Mining, Esling, 2012

  • A Review on Time Series Data Mining, Fu, 2011
  • Discrete Wavelet Transform-Based Time Series Analysis and Mining, Chaovalit, 2011
    Transfer Learning

  • A Survey on Transfer Learning, Pan, 2010
    Web Mining

  • A Taxonomy of Sequential Pattern Mining Algorithms, Mabroukeh, 2010

  • A Survey of Web Clustering Engines, Carpineto, 2009
  • Web Page Classification: Features and Algorithms, Qi, 2009
  • Mining Interesting Knowledge from Weblogs: A Survey, Facca, 2005
  • An Overview of Web Data Clustering Practices, Vakali, 2005
  • A Survey of Web Metrics, Dhyani, 2002
  • Data Mining for Hypertext: A Tutorial Survey, Chakrabarti, 2000
    http://www.mlsurveys.com/

vtk鼠标交互三例

发表于 2014-01-07 | 更新于 2015-08-15 | 分类于 vtk
例一:
显示Dicom序列,通过鼠标滚轮切换,并能显示操作提示。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2014/01/wpid-dba777faf79c359dba7237c21485c07f_ad8eb3a0ec7af9eb9189cc2b97ad6c68.jpg)
`
阅读全文 »

2014计划(想到再加)

发表于 2014-01-01 | 更新于 2015-08-15 | 分类于 essay

1.2. 更多阅读;

  1. 练习长跑;
  2. 学习摄影;
  3. 增加社交;
  4. 走更多的路;
  5. 打上主力;
  6. 坚持写博客;
  7. 学习DL;
  8. 贡献代码;
  9. 学习公开课;

【转】C++模板”>>”编译问题与词法消歧设计

发表于 2013-12-29 | 更新于 2015-08-15 | 分类于 c/cpp

在编译理论中,通常将编译过程抽象为5个主要阶段:词法分析(Lexical Analysis),语法分析(Parsing),语义分析(Semantic Analysis),优化(Optimization),代码生成(Code Generation)。这5个阶段类似Unix管道模型,上一个阶段的输出作为下一个阶段的输入。其中,词法分析是根据输入源代码文本流,分割出词,识别类别,产生词法元素(Token)流,如:

1
`int` `a = 10;`
经过词法分析会得到[(Type, "int"), (Identifier, "a"), (AssignOperator, "="), (IntLiteral, 10)],在后续的语法分析阶段,就会根据这些词法元素匹配相应的语法规则。在我学习编译原理时,教科书中对于词法分析的介绍主要是基于正则表达式的,言下之意就是普通语言的词法规则是可以通过正则表达式描述的。比如,C语言的变量名规则是“包含字母、数字或下划线,并且以字母或下划线开头”,这就可以用正则表达式`[a-zA-Z_][a-zA-Z0-9_]*`表达。但是,在实践中我发现不管是主流语言,还是自己设计的DSL都大量存在不能简单通过正则表达式进行词法分析的例子。来看C++98的模版例子:
1
`map<``int``, vector<``int``>>`
上面这段代码会被C++98编译器中报语法错误,原因在于它把“>>”识别成了位右移运算符而不是两个模版右括号,在C++98中必须在两个括号中间加空格,写成  
1
`map<``int``, vector<``int``> >`
除此了C++模版,据我所知,经典的FORTRAN语言的语法规则更是大量存在词法歧义。 ![](http://pieces365.duapp.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif "更多...") 我认为从本质上讲,这类问题的根源在于词法分析的依据只是简单的词法规则,并不具备所有的语法信息,而词法歧义必须提升一层在语法规则中消除。所以,在我自己设计一些DSL的时候干脆就把词法分析和语法分析合二为一了,相当于让语法分析在字符层次上去进行,而不是经典的词法元素层次上,这就是所谓的[Scannerless Parsing](http://en.wikipedia.org/wiki/Scannerless_parsing "Scannerless Parsing")。采用这种方法的例子并不少见,TeX, Wiki, Makefile和Perl 6等语言的语法分析器都属此类。 Scannerless Parsing方法弥补了词法规则无法消歧的问题,但是同时也破坏了词法和语法分析简单清晰的管道结构,总体上增加了实现和理解的复杂度。另外,像C++这样大型的语言,如果开始是有词法分析的,稍微碰到一个歧义就整个转成Scannerless Parsing未免也显得太夸张了。这个问题困扰了我很久,直到最近才找到了一个满意的解决方案。还是以上面”>>”为例,我们知道现在C++11已经允许不加空格了,那么C++11编译器是如何处理这个词法歧义的呢?答案是:词法分析阶段既然分析不好”>>”,干脆就不分析了,直接把”>” “>”交给语法分析器来分析,其他没有词法歧义的照旧。当我知道这个方案的时候不由得感叹:妙!理论上,词法分析是可以什么也不做的,全部把字符一一交给语法分析器也没有问题,所以,干脆让词法分析只做有把握的部分,解决不了的交给语法分析器,这样就既保留了管道结构,又解决了词法歧义。 下面我们再来看看C++11规范关于这个问题的定义: > 14.2 Names of template specializations [temp.names] ### > > > After name lookup (3.4) finds that a name is a template-name or that an operator-function-id or a literal-operator-id refers to a set of overloaded functions any member of which is a function template if this is followed by a <, the < is always taken as the delimiter of a template-argument-list and never as the less-than operator. When parsing a template-argument-list, the first non-nested > is taken as the ending delimiter rather than a greater-than operator. Similarly, the first non-nested >> is treated as two consecutive but distinct > tokens, the first of which is taken as the end of the template-argument-list and completes the template-id. [ Note: The second > token produced by this replacement rule may terminate an enclosing template-id construct or it may be part of a different construct (e.g. a cast).—end note ] 可见,在C++11中,词法分析器是把”>>”直接当成两个”>”传给了语法分析器,然后在语法分析中如果匹配了template-argument-lis语法,第一个”>”符号会被直接认为是模版结束符,而不是大于,也不是位移符号。根据这个定义,我构造了一个例子:
1
2
3
4
5
`template``<``int` `N>`
`class` `Foo {`
`};`
`Foo<3>>1> foo;`
这个例子在C++98中是能正确编译的,”>>”被解释成了位移运算,但是它反而不能在C++11中编译了,因为根据规范第一个”>”被解释成了模版参数结束符。如果要在C++11中编译,需要显式地加上括号:
1
`Foo<(3>>1)> foo;`
转自酷壳:http://coolshell.cn/articles/10449.html

ITK无法生成IO对象问题

发表于 2013-12-29 | 更新于 2015-08-15 | 分类于 itk

 

当使用VS生成项目时,读取图像时容易出现ImageFileReaderException的问题。

</header>

报错是说: Could not create IO object for file 1.jpg. Tried to create one of the following: You probably failed to set a file suffix, or set the suffix to an unsupported type. 这是由于没有加入ITKIO的预处理器。 解决方法: 属性 -> 配置属性 -> C/C++ -> 预处理器 预处理器定义中加入:**ITK_IO_FACTORY_REGISTER_MANAGER**
1…8910…12
Lu Xiaohua

Lu Xiaohua

116 日志
33 分类
86 标签
GitHub E-Mail
© 2019 Lu Xiaohua
由 Hexo 强力驱动 v3.8.0
|
主题 – NexT.Muse v7.0.0