Skip to content

SpatioTemporalHarmonicsSource

Repository source: SpatioTemporalHarmonicsSource


Description

Generate image data containing spatio-temporal harmonic data.

This source allows you to specify the uniform grid extent. It also lets you choose the harmonics you want.

The source has an embedded filter allowing you to add mutiple harmonics defined by their amplitude, temporal frequency, wave vector, and phase. The sum of these will be computed using the sine function for each point. Note that there is no cosine in this function. If no harmonic is specified, values will be null.

The source can also generate time steps by specifying time values.

Other languages

See (PythonicAPI)

Question

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

Code

SpatioTemporalHarmonicsSource.cxx

#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCameraOrientationWidget.h>
#include <vtkDataSetMapper.h>
#include <vtkInteractorStyleSwitch.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSpatioTemporalHarmonicsSource.h>

int main(int, char*[])
{

  vtkNew<vtkNamedColors> colors;

  // Create the source.
  const int MAX_EXTENT = 10;
  vtkNew<vtkSpatioTemporalHarmonicsSource> source;
  source->SetWholeExtent(-MAX_EXTENT, MAX_EXTENT,
                         -MAX_EXTENT, MAX_EXTENT,
                         -MAX_EXTENT, MAX_EXTENT);

  source->ClearHarmonics();
  source->AddHarmonic(1.0, 1.0, 1.0, 0.0, 0.0, 0.0);
  source->AddHarmonic(2.0, 1.0, 0.0, 1.0, 0.0, 0.0);
  source->AddHarmonic(4.0, 1.0, 0.0, 0.0, 1.0, 0.0);

  source->ClearTimeStepValues();
  source->AddTimeStepValue(0.0);
  source->AddTimeStepValue(1.0);
  source->AddTimeStepValue(2.0);

  // Create the mapper and actor.
  vtkNew<vtkDataSetMapper> mapper;
  mapper->SetInputConnection(source->GetOutputPort());
  mapper->SetScalarRange(-6.0, 6.0);

  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper);

  // Create a renderer, render window, and interactor.
  vtkNew<vtkRenderer> ren;
  ren->SetBackground(colors->GetColor3d("Gray").GetData());
  vtkNew<vtkRenderWindow> renWin;
  renWin->SetWindowName("SpatioTemporalHarmonicsSource");
  renWin->SetSize(600, 600);
  renWin->AddRenderer(ren);
  vtkNew<vtkRenderWindowInteractor> iRen;
  iRen->SetRenderWindow(renWin);
  auto is = vtkInteractorStyleSwitch::SafeDownCast(iRen->GetInteractorStyle());
  if (is)
  {
    is->SetCurrentStyleToTrackballCamera();
  }

  ren->ResetCamera();
  ren->GetActiveCamera()->SetPosition(50.0, 40.0, 30.0);
  ren->GetActiveCamera()->SetFocalPoint(0.0, 0.0, 0.0);
  ren->ResetCameraClippingRange();

  // Add the actor, render and interact.
  ren->AddActor(actor);
  renWin->Render();

  vtkNew<vtkCameraOrientationWidget> cow;
  cow->SetParentRenderer(ren);
  // Enable the widget.
  cow->On();

  iRen->Start();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(SpatioTemporalHarmonicsSource)

find_package(VTK COMPONENTS 
  CommonColor
  CommonCore
  FiltersSources
  InteractionStyle
  InteractionWidgets
  RenderingContextOpenGL2
  RenderingCore
  RenderingFreeType
  RenderingGL2PSOpenGL2
  RenderingOpenGL2
)

if (NOT VTK_FOUND)
  message(FATAL_ERROR "SpatioTemporalHarmonicsSource: 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(SpatioTemporalHarmonicsSource MACOSX_BUNDLE SpatioTemporalHarmonicsSource.cxx )
  target_link_libraries(SpatioTemporalHarmonicsSource PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
  TARGETS SpatioTemporalHarmonicsSource
  MODULES ${VTK_LIBRARIES}
)

Download and Build SpatioTemporalHarmonicsSource

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

cd SpatioTemporalHarmonicsSource/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:

./SpatioTemporalHarmonicsSource

WINDOWS USERS

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