2 MITK测试代码step4

1 官网教程
http://docs.mitk.org/2016.11/Step04Page.html

2 Step4.cpp

/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "QmitkRegisterClasses.h"
#include "QmitkRenderWindow.h"
#include "QmitkSliceWidget.h"

#include "mitkNodePredicateDataType.h"
#include "mitkProperties.h"
#include "mitkRenderingManager.h"
#include "mitkStandaloneDataStorage.h"
#include <mitkIOUtil.h>

#include <QApplication>
#include <QHBoxLayout>
#include <itksys/SystemTools.hxx>
#include <mitkImage.h>

//##Documentation
//## @brief Use several views to explore data
//##
//## As in Step2 and Step3, load one or more data sets (many image,
//## surface and other formats), but create 3 views on the data.
//## The QmitkRenderWindow is used for displaying a 3D view as in Step3,
//## but without volume-rendering.
//## Furthermore, we create two 2D views for slicing through the data.
//## We use the class QmitkSliceWidget, which is based on the class
//## QmitkRenderWindow, but additionally provides sliders
//## to slice through the data. We create two instances of
//## QmitkSliceWidget, one for axial and one for sagittal slicing.
//## The two slices are also shown at their correct position in 3D as
//## well as intersection-line, each in the other 2D view.
int main(int argc, char *argv[])
{
  QApplication qtapplication(argc, argv);

  if (argc < 2)
  {
    fprintf(
      stderr, "Usage:   %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str());
    return 1;
  }

  // Register Qmitk-dependent global instances
  QmitkRegisterClasses();

  //*************************************************************************
  // Part I: Basic initialization
  //*************************************************************************

  // Create a DataStorage
  mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New();

  //*************************************************************************
  // Part II: Create some data by reading files
  //*************************************************************************
  int i;
  for (i = 1; i < argc; ++i)
  {
    // For testing
    if (strcmp(argv[i], "-testing") == 0)
      continue;

    //*********************************************************************
    // Part III: Put the data into the datastorage
    //*********************************************************************
    // Load datanode (eg. many image formats, surface formats, etc.)
    mitk::IOUtil::Load(argv[i], *ds);
  }

  //*************************************************************************
  // Part IV: Create windows and pass the tree to it
  //*************************************************************************

  // Create toplevel widget with horizontal layout
  QWidget toplevelWidget;
  QHBoxLayout layout;
  layout.setSpacing(2);
  layout.setMargin(0);
  toplevelWidget.setLayout(&layout);

  //*************************************************************************
  // Part IVa: 3D view
  //*************************************************************************

  // Create a renderwindow
  QmitkRenderWindow renderWindow(&toplevelWidget);
  layout.addWidget(&renderWindow);

  // Tell the renderwindow which (part of) the datastorage to render
  renderWindow.GetRenderer()->SetDataStorage(ds);

  // Use it as a 3D view
  renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D);

  // Reposition the camera to include all visible actors
  renderWindow.GetRenderer()->GetVtkRenderer()->ResetCamera();

  // *******************************************************
  // ****************** START OF NEW PART ******************
  // *******************************************************

  //*************************************************************************
  // Part IVb: 2D view for slicing axially
  //*************************************************************************

  // Create QmitkSliceWidget, which is based on the class
  // QmitkRenderWindow, but additionally provides sliders
  QmitkSliceWidget view2(&toplevelWidget);
  layout.addWidget(&view2);
  view2.SetLevelWindowEnabled(true);
  // Tell the QmitkSliceWidget which (part of) the tree to render.
  // By default, it slices the data axially
  view2.SetDataStorage(ds);

  // Get the image from the data storage. A predicate (mitk::NodePredicateBase)
  // is used to get only nodes of the type mitk::Image.
  mitk::DataStorage::SetOfObjects::ConstPointer rs = ds->GetSubset(mitk::TNodePredicateDataType<mitk::Image>::New());

  view2.SetData(rs->Begin(), mitk::SliceNavigationController::Axial);
  // We want to see the position of the slice in 2D and the
  // slice itself in 3D: add it to the datastorage!
  ds->Add(view2.GetRenderer()->GetCurrentWorldGeometry2DNode());

  //*************************************************************************
  // Part IVc: 2D view for slicing sagitally
  //*************************************************************************

  // Create QmitkSliceWidget, which is based on the class
  // QmitkRenderWindow, but additionally provides sliders
  QmitkSliceWidget view3(&toplevelWidget);
  layout.addWidget(&view3);
  view3.SetDataStorage(ds);
  // Tell the QmitkSliceWidget which (part of) the datastorage to render
  // and to slice sagitally
  view3.SetData(rs->Begin(), mitk::SliceNavigationController::Sagittal);
  // We want to see the position of the slice in 2D and the
  // slice itself in 3D: add it to the datastorage!
  ds->Add(view3.GetRenderer()->GetCurrentWorldGeometry2DNode());

  // *******************************************************
  // ******************* END OF NEW PART *******************
  // *******************************************************

  //*************************************************************************
  // Part V: Qt-specific initialization
  //*************************************************************************
  toplevelWidget.show();

// for testing
#include "QtTesting.h"
  if (strcmp(argv[argc - 1], "-testing") != 0)
    return qtapplication.exec();
  else
    return QtTesting();
}

/**
\example Step4.cpp
*/

3 CMakeLists.txt

cmake_minimum_required(VERSION 2.8.4)
project(Step4) # 这里改成你的项目名

find_package(MITK REQUIRED)

# Check that MITK has been build with Qt support
#if(NOT MITK_USE_QT)
#  message(SEND_ERROR "MITK needs to be built with MITK_USE_QT set to ON")
#endif()

# Check prerequisites for this application.
# We need the Qmitk module.
#MITK_CHECK_MODULE(result Qmitk)
#if(result)
#  message(SEND_ERROR "MITK module(s) \"${result}\" not available from the MITK build at ${MITK_DIR}")
#endif()

# Set-up the build system to use the Qmitk module
#MITK_USE_MODULE(Qmitk)
include_directories(${ALL_INCLUDE_DIRECTORIES})
link_directories(${ALL_LIBRARY_DIRS})
mitk_create_executable(${PROJECT_NAME} DEPENDS MitkQtWidgetsExt) 
#add_executable(${PROJECT_NAME} Step4.cpp) # 这里改成你的源文件名
target_link_libraries(${PROJECT_NAME} ${ALL_LIBRARIES})

4 files.cmake

# List all source files  
set(CPP_FILES Step4.cpp)  

编译及生成请参考第一篇,然后下载俩个数据,一个三维的,一个二维的。

5 编辑D:\myproj\mitk\step4_bin下Step4_debug.bat代码(仅供参考,请根据自己路径修改)

PATH=/plugins/debug;D:/MITK-bin-win/MITK-build/bin/debug;D:/MITK-bin-win/MITK-build/bin/plugins/debug;D:/MITK-bin-win/MITK-build/lib/debug;D:/MITK-bin-win/MITK-build/lib/plugins/debug;D:/MITK-bin-win/ep/bin;D:/MITK-bin-win/ep/lib;C:/Qt/Qt5.6.2/5.6/msvc2013_64/bin;D:/MITK-bin-win/ep/lib/cmake/ITK-4.9/bin;D:/MITK-bin-win/ep/src/CTK-build/CTK-build/bin/debug;D:/MITK-bin-win/ep/src/CTK-build/qRestAPI-build/debug;%PATH%
debug\Step4.exe D:\data\Pic3D.nrrd D:\data\lungs.vtk
pause

6 运行效果

这里写图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值