Skip to content


# ComplexV

VTKEx/Cxx/Visualization/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.

Info

See Figure 6-13 in Chapter 6 the VTK Textbook.

Other languages

See (Python), (Java)

Question

If you have a simple question about this example contact us at VTKExProject If your question is more complex and may require extended discussion, 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 <vtkOutlineFilter.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkProperty.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkRenderer.h>
    #include <vtkSmartPointer.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;
      }

      vtkSmartPointer<vtkNamedColors> colors =
        vtkSmartPointer<vtkNamedColors>::New();

      vtkSmartPointer<vtkStructuredPointsReader> reader =
        vtkSmartPointer<vtkStructuredPointsReader>::New();
      reader->SetFileName(argv[1]);

      vtkSmartPointer<vtkHedgeHog> hhog =
        vtkSmartPointer<vtkHedgeHog>::New();
      hhog->SetInputConnection(reader->GetOutputPort());
      hhog->SetScaleFactor(0.3);

      vtkSmartPointer<vtkLookupTable> lut =
        vtkSmartPointer<vtkLookupTable>::New();
    //  lut->SetHueRange(.667, 0.0);
      lut->Build();

      vtkSmartPointer<vtkPolyDataMapper> hhogMapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
      hhogMapper->SetInputConnection(hhog->GetOutputPort());
      hhogMapper->SetScalarRange(50, 550);
      hhogMapper->SetLookupTable(lut);

      vtkSmartPointer<vtkActor> hhogActor =
        vtkSmartPointer<vtkActor>::New();
      hhogActor->SetMapper(hhogMapper);

      vtkSmartPointer<vtkOutlineFilter> outline =
        vtkSmartPointer<vtkOutlineFilter>::New();
      outline->SetInputConnection(reader->GetOutputPort());

      vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
      outlineMapper->SetInputConnection(outline->GetOutputPort());

      vtkSmartPointer<vtkActor> outlineActor =
        vtkSmartPointer<vtkActor>::New();
      outlineActor->SetMapper(outlineMapper);
      outlineActor->GetProperty()->SetColor(0, 0, 0);

      vtkSmartPointer<vtkRenderer> aRenderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderWindow> aRenderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
      aRenderWindow->AddRenderer(aRenderer);
      vtkSmartPointer<vtkRenderWindowInteractor> anInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      anInteractor->SetRenderWindow(aRenderWindow);
      aRenderWindow->SetSize(640, 480);

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

      aRenderer->SetBackground(colors->GetColor3d("Gray").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.3 FATAL_ERROR)

    project(ComplexV)

    find_package(VTK COMPONENTS
      vtkCommonColor
      vtkCommonCore
      vtkFiltersCore
      vtkFiltersModeling
      vtkIOLegacy
      vtkInteractionStyle
      vtkRenderingContextOpenGL2
      vtkRenderingCore
      vtkRenderingFreeType
      vtkRenderingGL2PSOpenGL2
      vtkRenderingOpenGL2 QUIET)
    if (NOT VTK_FOUND)
      message("Skipping ComplexV: ${VTK_NOT_FOUND_MESSAGE}")
      return ()
    endif()
    message (STATUS "VTK_VERSION: ${VTK_VERSION}")
    if (VTK_VERSION VERSION_LESS "8.90.0")
      # old system
      include(${VTK_USE_FILE})
      add_executable(ComplexV MACOSX_BUNDLE ComplexV.cxx )
      target_link_libraries(ComplexV PRIVATE ${VTK_LIBRARIES})
    else ()
      # include all components
      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}
        )
    endif ()

### 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.