VTK8.2 VS 2017 Windows 10 C++インストール

18479 ワード

1、インストール
  • まずはhttps://vtk.org/download/公式にパッケージをダウンロードし、解凍します.
  • なかったらcmake、インストールcmakeソフト、WindowsでのcmakeGUIがあれば使えて便利です.
  • 開くcmake選択vtkのルートディレクトリ(あるCMakeLists.txtファイル)をsourceディレクトリとして新規作成cmakebuildプロジェクトを格納するディレクトリとしてフォルダをどこに置いても良いのでおすすめsource同級ディレクトリに置く
  • クリックconfig配置を行い、ここではVS2017を使用するので、VS2017とデフォルトのコンパイラを選択します.

  • ここでデフォルトはwin 32、つまり32ビットのプロジェクトですが、x 64のプロジェクトが必要な場合は、x 64プラットフォームを選択し続けてください.そうしないと、win 32のプロジェクトで変更すると多くの問題が発生します.例えば最初はこの問題に気づかなかったのですが、QT 64ビットを使うので、プロジェクトをx 64に変更した結果、多くの問題が発生しました.例えば “X64” “X86” 、これはcmake生成プロジェクトを開始するときにwin 32が配置されていたためです.その後、x 64を変更する多くの構成が変更されていない(一つ一つ修正するのも難しい)ので、手動で少し修正するよりも、cmakeの時にx 64を生産するプロジェクトを指定すると、多くの問題が解決します.
  • 構成が完了すると、赤い選択肢がたくさん出てくるので、もう一度注文config赤い選択肢が消えてしまう.多くの選択肢がありますが、特別な需要がなければ一時的にデフォルトでいいので、注意してください.一つの選択肢はCMAKE_INSTALL_PREFIX、後ろの経路は私たちがコンパイルした.hlibdllファイルを保存して、カスタマイズして設定することができます.それから、generateエントリを生成して、完成したらプロジェクトが生成して、cmakeの役割が終わります.
  • 新規の格納を見つけるbuild後ファイルのディレクトリを開く.slnファイルを開き、ソリューションを生成(時間が少し長い)してからInstallプロジェクトを生成する.これにより、必要なすべてのライブラリファイルがCMAKE_INSTALL_PREFIX指定されたファイルフォルダ内に生成される.
  • 2、配置
  • 空の項目C++項目を新規作成する.
  • プロジェクト->属性->構成属性->VC++ディレクトリ->含むディレクトリに追加vtkincludeフォルダ.
  • プロジェクト->プロパティ->構成プロパティ->リンクアタッチメントライブラリディレクトリに追加vtklibフォルダ.
  • vtklibフォルダ内に新規txtファイルを作成し、DIR *.lib /B >LIBLIST.TXTファイルを書き込み保存し、接尾辞を変更.txt.batとして実行する.これはディレクトリに新たな.txtファイルが生成され、ファイルはすべてlibファイルの名前が格納されている.
  • 編集項目->属性->構成属性->リンク->追加依存項目を入力し、4.生成されたすべてのlibファイルの名前を貼り付けます.
  • プロジェクト->属性->構成属性->デバッグ環境に書き込むPATH= vtk dll (bin )VSファイルを見つけるdllファイル、またはdllファイルをすべてプロジェクトにコピーし、具体的に検索することができます.

  • これで.h,lib,dllファイルが配置されてコードが書けるようになりました.
    3、テスト
    付録は公式サイトが与えた例(c++)、すべてのケースのウェブサイトですhttps://lorensen.github.io/VTKExamples/site/Cxx/最初の部分では公式とは異なり、主に
    #include 
    VTK_MODULE_INIT(vtkRenderingOpenGL2);
    VTK_MODULE_INIT(vtkInteractionStyle);
    

    これは、公式にcmakelistsファイルが与えられていて、cmakeで構築されたアイテムで、ここに直接貼り付けられたコードが、若干異なっているため、初期化操作を行う必要があります.
    Error: no override found for 'vtkPolyDataMapper'.
    

    多くの人が案に遭遇し、以下のように説明しています.https://stackoverflow.com/questions/18642155/no-override-found-for-vtkpolydatamapper正常に実行すると、円柱が表示されます.
    4、付録
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    VTK_MODULE_INIT(vtkRenderingOpenGL2);//          ,    
    VTK_MODULE_INIT(vtkInteractionStyle);
    int main(int, char *[]) {
      vtkSmartPointer<vtkNamedColors> colors =
          vtkSmartPointer<vtkNamedColors>::New();
    
      // Set the background color.
      std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
      colors->SetColor("BkgColor", bkg.data());
    
      // This creates a polygonal cylinder model with eight circumferential facets
      // (i.e, in practice an octagonal prism).
      vtkSmartPointer<vtkCylinderSource> cylinder =
          vtkSmartPointer<vtkCylinderSource>::New();
      cylinder->SetResolution(8);
    
      // The mapper is responsible for pushing the geometry into the graphics
      // library. It may also do color mapping, if scalars or other attributes are
      // defined.
      vtkSmartPointer<vtkPolyDataMapper> cylinderMapper =
          vtkSmartPointer<vtkPolyDataMapper>::New();
      cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
    
      // The actor is a grouping mechanism: besides the geometry (mapper), it
      // also has a property, transformation matrix, and/or texture map.
      // Here we set its color and rotate it around the X and Y axes.
      vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
      cylinderActor->SetMapper(cylinderMapper);
      cylinderActor->GetProperty()->SetColor(
          colors->GetColor4d("Tomato").GetData());
      cylinderActor->RotateX(30.0);
      cylinderActor->RotateY(-45.0);
    
      // The renderer generates the image
      // which is then displayed on the render window.
      // It can be thought of as a scene to which the actor is added
      vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
      renderer->AddActor(cylinderActor);
      renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
      // Zoom in a little by accessing the camera and invoking its "Zoom" method.
      renderer->ResetCamera();
      renderer->GetActiveCamera()->Zoom(1.5);
    
      // The render window is the actual GUI window
      // that appears on the computer screen
      vtkSmartPointer<vtkRenderWindow> renderWindow =
          vtkSmartPointer<vtkRenderWindow>::New();
      renderWindow->SetSize(300, 300);
      renderWindow->AddRenderer(renderer);
      renderWindow->SetWindowName("Cylinder");
    
      // The render window interactor captures mouse events
      // and will perform appropriate camera or actor manipulation
      // depending on the nature of the events.
      vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
          vtkSmartPointer<vtkRenderWindowInteractor>::New();
      renderWindowInteractor->SetRenderWindow(renderWindow);
    
      // This starts the event loop and as a side effect causes an initial render.
      renderWindowInteractor->Start();
    
      return EXIT_SUCCESS;
    }