Skip to content

ComplexV

Repository source: ComplexV


Description

ComplexV from the VTK Textbook. The original example was written in TCL.

The example shows 167,000 3D vectors (using oriented and scaled lines) in the region of the human carotid artery. The larger vectors lie inside the arteries, the smaller vectors lie outside the arteries and are randomly oriented (measurement error) but small in magnitude. Clearly the details of the vector field are not discernible from this image.

Other languages

See (Python), (Java)

Question

If you have a question about this example, please use the VTK Discourse Forum

Code

ComplexV.cxx

#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkHedgeHog.h>
#include <vtkLookupTable.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkOutlineFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkStructuredPointsReader.h>

int main(int argc, char* argv[])
{
  if (argc < 2)
  {
    std::cout << "Usage: " << argv[0] << " carotid.vtk" << std::endl;
    return EXIT_SUCCESS;
  }

  vtkNew<vtkNamedColors> colors;

  vtkNew<vtkStructuredPointsReader> reader;
  reader->SetFileName(argv[1]);

  vtkNew<vtkHedgeHog> hhog;
  hhog->SetInputConnection(reader->GetOutputPort());
  hhog->SetScaleFactor(0.3);

  vtkNew<vtkLookupTable> lut;
  //  lut->SetHueRange(.667, 0.0);
  lut->Build();

  vtkNew<vtkPolyDataMapper> hhogMapper;
  hhogMapper->SetInputConnection(hhog->GetOutputPort());
  hhogMapper->SetScalarRange(50, 550);
  hhogMapper->SetLookupTable(lut);

  vtkNew<vtkActor> hhogActor;
  hhogActor->SetMapper(hhogMapper);

  vtkNew<vtkOutlineFilter> outline;
  outline->SetInputConnection(reader->GetOutputPort());

  vtkNew<vtkPolyDataMapper> outlineMapper;
  outlineMapper->SetInputConnection(outline->GetOutputPort());

  vtkNew<vtkActor> outlineActor;
  outlineActor->SetMapper(outlineMapper);
  outlineActor->GetProperty()->SetColor(colors->GetColor3d("Black").GetData());

  vtkNew<vtkRenderer> aRenderer;
  vtkNew<vtkRenderWindow> aRenderWindow;
  aRenderWindow->AddRenderer(aRenderer);

  vtkNew<vtkRenderWindowInteractor> anInteractor;
  anInteractor->SetRenderWindow(aRenderWindow);
  aRenderWindow->SetSize(640, 480);
  aRenderWindow->SetWindowName("ComplexV");

  aRenderer->AddActor(outlineActor);
  aRenderer->AddActor(hhogActor);

  aRenderer->SetBackground(colors->GetColor3d("SlateGray").GetData());

  // Generate an interesting view

  aRenderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
  aRenderer->GetActiveCamera()->SetPosition(1, 0, 0);
  aRenderer->GetActiveCamera()->SetViewUp(0, 0, 1);
  aRenderer->ResetCamera();

  aRenderer->GetActiveCamera()->Azimuth(60);
  aRenderer->GetActiveCamera()->Elevation(30);
  aRenderer->GetActiveCamera()->Dolly(1.1);
  aRenderer->ResetCameraClippingRange();

  aRenderWindow->Render();

  // interact with data
  anInteractor->Start();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(ComplexV)

find_package(VTK COMPONENTS 
  CommonColor
  CommonCore
  FiltersCore
  FiltersModeling
  IOLegacy
  InteractionStyle
  RenderingContextOpenGL2
  RenderingCore
  RenderingFreeType
  RenderingGL2PSOpenGL2
  RenderingOpenGL2
)

if (NOT VTK_FOUND)
  message(FATAL_ERROR "ComplexV: Unable to find the VTK build folder.")
endif()

# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(ComplexV MACOSX_BUNDLE ComplexV.cxx )
  target_link_libraries(ComplexV PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
  TARGETS ComplexV
  MODULES ${VTK_LIBRARIES}
)

Download and Build ComplexV

Click here to download ComplexV and its CMakeLists.txt file. Once the tarball ComplexV.tar has been downloaded and extracted,

cd ComplexV/build

If VTK is installed:

cmake ..

If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:

cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

make

and run it:

./ComplexV

WINDOWS USERS

Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.