2017-12-12 30 views
0

Linux에서 VTK-6.2, C++ (gcc-4.7.2)를 사용하고 VTK 파이프 라인을 다음과 같이 설정합니다 (구현, 세부 사항 및 파이프 라인에 집중하지 마십시오 : cone-> filter-> mapper- > 배우) :VTK 파이프 라인 업데이트

// cone/initialize 
vtkConeSource cone; 

// add cone(s) to filter 
vtkAppendFilter filter; 
filter.AddInputData(cone.GetOutput()); 

// add filter to mapper 
vtkDataSetMapper mapper; 
mapper.SetInputData(filter->GetOutput()); 

// actor 
vtkActor actor; 
actor.SetMapper(mapper); 

장면이 잘 표현됩니다.

문제점

I는 원래의 데이터 (즉, 콘) 및 액터 올바르게 렌더링 할 업데이트하려는.

  • 액터가있는 경우 원본 콘 데이터에 어떻게 액세스합니까? 액터가 업데이트된다는 보장이 있습니까? 왜냐하면 포인터를 통해 원본 데이터를 추적하기로 결정했을 때 전체 구현이 vtkSmartPointer으로 이루어 졌기 때문에 파이프 라인이 업데이트되지 않았기 때문입니다. 자동으로 업데이트하면 안됩니까?

  • (I (예를 들어 자신의 가시성을) 배우를 변경하면 장면이 잘 렌더링)

나를 용서, 나는 VTK 전문가가 아니다 및 파이프 라인 혼란이다. 아마도 한 가지 방법은 내 파이프 라인을 단순화하는 것입니다. 합니다 (vtkAppendFilter 첨가시 vtkUnstructuredGrid로)과 유사한 포스트 this 않음 따르면

감사

[업데이트]

원래 데이터 ( vtkConeSource)는 변형된다 그래서 추적해도 원래 데이터의 변경은 쓸모가 없습니다.

답변

0

VTK 파이프 라인은 수요 기반 파이프 라인입니다. 파이프 라인 요소 중 하나가 수정 된 경우에도 자동으로 업데이트되지 않습니다. 파이프 라인의 마지막 vtkAlgorithm (또는 파생 클래스 개체)에서 Update() 함수를 명시 적으로 호출하여 전체 파이프 라인을 업데이트해야합니다. 우리가 다음 우리가 포인터를 사용하여 파이프 라인을 업데이트 할 수 있습니다

currAlgoObj->SetInputConnection(prevAlgoObj->GetOutputPort()) 

대신

currAlgoObj->SetInputData(prevAlgo->GetOutput()) 

사용 vtkAlgorithm 유형에서됩니다 파생 된 두 개체를 연결하는 경우 파이프 라인을 설정하는 올바른 방법은 아래 예제와 같이 actor->GetMapper()->Update()을 수행하여 액터 개체를 만듭니다.

이 예제에서는 원뿔 소스를 만들고 vtkAppendFilter을 통과시킨 다음 원본 원뿔 소스의 높이를 변경하고 다른 창에서 렌더링하여 업데이트 된 원뿔을 확인합니다. (두 번째 창에서 업데이트 된 원뿔을 보려면 첫 번째 렌더링 창을 닫아야합니다.)

#include <vtkConeSource.h> 
#include <vtkDataSetMapper.h> 
#include <vtkActor.h> 
#include <vtkRenderer.h> 
#include <vtkRenderWindow.h> 
#include <vtkRenderWindowInteractor.h> 
#include <vtkSmartPointer.h> 
#include <vtkAppendFilter.h> 

int main(int, char *[]) 
{ 
    // Set up the data pipeline 
    auto cone = vtkSmartPointer<vtkConeSource>::New(); 
    cone->SetHeight(1.0); 

    auto appf = vtkSmartPointer<vtkAppendFilter>::New(); 
    appf->SetInputConnection(cone->GetOutputPort()); 

    auto coneMapper = vtkSmartPointer<vtkDataSetMapper>::New(); 
    coneMapper->SetInputConnection(appf->GetOutputPort()); 

    auto coneActor = vtkSmartPointer<vtkActor>::New(); 
    coneActor->SetMapper(coneMapper); 

    // We need to update the pipeline otherwise nothing will be rendered 
    coneActor->GetMapper()->Update(); 

    // Connect to the rendering portion of the pipeline 
    auto renderer = vtkSmartPointer<vtkRenderer>::New(); 
    renderer->AddActor(coneActor); 
    renderer->SetBackground(0.1, 0.2, 0.4); 

    auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); 
    renderWindow->SetSize(200, 200); 
    renderWindow->AddRenderer(renderer); 

    auto renderWindowInteractor = 
      vtkSmartPointer<vtkRenderWindowInteractor>::New(); 
    renderWindowInteractor->SetRenderWindow(renderWindow); 
    renderWindowInteractor->Start(); 

    // Change cone property 
    cone->SetHeight(10.0); 

    //Update the pipeline using the actor object 
    coneActor->GetMapper()->Update(); 

    auto renderer2 = vtkSmartPointer<vtkRenderer>::New(); 
    renderer2->AddActor(coneActor); 
    renderer2->SetBackground(0.1, 0.2, 0.4); 

    auto renderWindow2 = vtkSmartPointer<vtkRenderWindow>::New(); 
    renderWindow2->SetSize(200, 200); 
    renderWindow2->AddRenderer(renderer2); 

    auto renderWindowInteractor2 = 
      vtkSmartPointer<vtkRenderWindowInteractor>::New(); 
    renderWindowInteractor2->SetRenderWindow(renderWindow2); 

    renderWindowInteractor2->Start(); 

    return EXIT_SUCCESS; 
} 
+0

철저한 답안과 예제 Amit을 주셔서 감사합니다. 앞에서 언급했듯이이 문제는 실제로''SetInputConnection'' 대신에''SetInputData''를 사용하고 있습니다 (제 경우''AddInputData''가''AddInputConnection''로 변경되었습니다) –

+0

Ok. 나는'AddInputData'에 주목하고 싶었지만 기뻤다. –