vtk 06 提取RGB分量

#include "vtkSmartPointer.h"

#include "vtkMetaImageReader.h"

#include "vtkJPEGReader.h"

#include "vtkPNGReader.h"

#include "vtkImageExtractComponents.h"

#include "vtkImageActor.h"

#include "vtkRenderer.h"

#include "vtkRenderWindow.h"

#include "vtkImageViewer2.h"

#include "vtkImageBlend.h"

#include "vtkRenderWindowInteractor.h"

#include "vtkInteractorStyleTrackballCamera.h"

#include "vtkAutoInit.h"


VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2

VTK_MODULE_INIT(vtkInteractionStyle);


int main()

{

    vtkSmartPointer<vtkJPEGReader> reader =

        vtkSmartPointer<vtkJPEGReader>::New();

    reader->SetFileName("test1.jpg");

    reader->Update();


    vtkSmartPointer<vtkImageExtractComponents> extractRedFilter =

        vtkSmartPointer<vtkImageExtractComponents>::New();

    extractRedFilter->SetInputConnection(reader->GetOutputPort());

    extractRedFilter->SetComponents(0);

    extractRedFilter->Update();


    vtkSmartPointer<vtkImageExtractComponents> extractGreenFilter =

        vtkSmartPointer<vtkImageExtractComponents>::New();

    extractGreenFilter->SetInputConnection(reader->GetOutputPort());

    extractGreenFilter->SetComponents(1);

    extractGreenFilter->Update();


    vtkSmartPointer<vtkImageExtractComponents> extractBlueFilter =

        vtkSmartPointer<vtkImageExtractComponents>::New();

    extractBlueFilter->SetInputConnection(reader->GetOutputPort());

    extractBlueFilter->SetComponents(2);

    extractBlueFilter->Update();


    // Create actors

    vtkSmartPointer<vtkImageActor> inputActor =

        vtkSmartPointer<vtkImageActor>::New();

    inputActor->SetInputData(reader->GetOutput());


    vtkSmartPointer<vtkImageActor> redActor =

        vtkSmartPointer<vtkImageActor>::New();

    redActor->SetInputData(extractRedFilter->GetOutput());


    vtkSmartPointer<vtkImageActor> greenActor =

        vtkSmartPointer<vtkImageActor>::New();

    greenActor->SetInputData(extractGreenFilter->GetOutput());


    vtkSmartPointer<vtkImageActor> blueActor =

        vtkSmartPointer<vtkImageActor>::New();

    blueActor->SetInputData(extractBlueFilter->GetOutput());


    double inputViewport[4] = { 0.0, 0.0, 0.25, 1.0 };

    double redViewport[4] = { 0.25, 0.0, 0.5, 1.0 };

    double greenViewport[4] = { 0.5, 0.0, 0.75, 1.0 };

    double blueViewport[4] = { 0.75, 0.0, 1.0, 1.0 };


    vtkSmartPointer<vtkRenderer> inputRenderer =

        vtkSmartPointer<vtkRenderer>::New();

    inputRenderer->SetViewport(inputViewport);

    inputRenderer->AddActor(inputActor);

    inputRenderer->ResetCamera();

    inputRenderer->SetBackground(1.0, 1.0, 1.0);


    vtkSmartPointer<vtkRenderer> redRenderer =

        vtkSmartPointer<vtkRenderer>::New();

    redRenderer->SetViewport(redViewport);

    redRenderer->AddActor(redActor);

    redRenderer->ResetCamera();

    redRenderer->SetBackground(1.0, 1.0, 1.0);


    vtkSmartPointer<vtkRenderer> greenRenderer =

        vtkSmartPointer<vtkRenderer>::New();

    greenRenderer->SetViewport(greenViewport);

    greenRenderer->AddActor(greenActor);

    greenRenderer->ResetCamera();

    greenRenderer->SetBackground(1.0, 1.0, 1.0);


    vtkSmartPointer<vtkRenderer> blueRenderer =

        vtkSmartPointer<vtkRenderer>::New();

    blueRenderer->SetViewport(blueViewport);

    blueRenderer->AddActor(blueActor);

    blueRenderer->ResetCamera();

    blueRenderer->SetBackground(1.0, 1.0, 1.0);


    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();

    renderWindow->AddRenderer(inputRenderer);

    renderWindow->AddRenderer(redRenderer);

    renderWindow->AddRenderer(greenRenderer);

    renderWindow->AddRenderer(blueRenderer);


    renderWindow->SetSize(1200, 300);

    renderWindow->Render();

    renderWindow->SetWindowName("ImageExtractComponentsExample");


    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =

        vtkSmartPointer<vtkRenderWindowInteractor>::New();

    /*vtkSmartPointer<vtkInteractorStyleImage> style =

        vtkSmartPointer<vtkInteractorStyleImage>::New();


    renderWindowInteractor->SetInteractorStyle(style);*/

    renderWindowInteractor->SetRenderWindow(renderWindow);

    renderWindowInteractor->Initialize();

    renderWindowInteractor->Start();


}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值