• vtkExampleWarpVector和vtkWarpScalar


    vtkWarpVector :

    deform geometry with vector data

    vtkWarpVector is a filter that modifies point coordinates by moving points along vector times the scale factor. Useful for showing flow profiles or mechanical deformation.

    The filter passes both its point data and cell data to its output.

    Examples:
    vtkWarpVector (Examples)
    Tests:
    vtkWarpVector (Tests)

    示例程序1:

    #ifndef INITIAL_OPENGL
    #define INITIAL_OPENGL
    #include <vtkAutoInit.h>
    VTK_MODULE_INIT(vtkRenderingOpenGL)
    VTK_MODULE_INIT(vtkInteractionStyle)
    #endif
    #include <iostream>
    using namespace std;
    #include <vtkVersion.h>
    #include <vtkActor.h>
    #include <vtkCellArray.h>
    #include <vtkDoubleArray.h>
    #include <vtkLine.h>
    #include <vtkPointData.h>
    #include <vtkPoints.h>
    #include <vtkPolyData.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkRenderer.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkSmartPointer.h>
    #include <vtkWarpVector.h>
    
    int main()
    {
        ///沿x轴方向创建5个点,x坐标分别为0、1、2、3、4。
        /// 所有点的y、z坐标为0。即初始的5个点在水平线上
        vtkSmartPointer<vtkPoints>points=vtkSmartPointer<vtkPoints>::New();
        points->InsertNextPoint(0,0,0);
        points->InsertNextPoint(1,0,0);
        points->InsertNextPoint(2,0,0);
        points->InsertNextPoint(3,0,0);
        points->InsertNextPoint(4,0,0);
        //将以上5个点,连成4段线
        vtkSmartPointer<vtkCellArray> lines=vtkSmartPointer<vtkCellArray>::New();
        vtkSmartPointer<vtkLine> line=vtkSmartPointer<vtkLine>::New();
        for(int i=0;i<4;i++)
        {
            line->GetPointIds()->SetId(0,i);
            line->GetPointIds()->SetId(1,i+1);
            lines->InsertNextCell(line);
        }
    
        vtkSmartPointer<vtkDoubleArray> warpData=vtkSmartPointer<vtkDoubleArray>::New();
        warpData->SetNumberOfComponents(3);
        warpData->SetName("warpData");
        //第1个点不动
        double warp[3]={0,0,0};
        warp[1]=0.0;
        warpData->InsertNextTuple(warp);
        //第2个点沿y轴移动0.5
        warp[1]=0.5;
        warpData->InsertNextTuple(warp);
        //第3个点沿y轴移动0.3
        warp[1]=0.3;
        warpData->InsertNextTuple(warp);
    //第4个点沿y轴移动0.0
        warp[1] = 0.0;
        warpData->InsertNextTuple(warp);
        //第5个点沿y轴移动0.1
        warp[1] = 0.1;
        warpData->InsertNextTuple(warp);
    
        //创建PolyData对象
        vtkSmartPointer<vtkPolyData> polydata=vtkSmartPointer<vtkPolyData>::New();
        polydata->SetPoints(points);
        polydata->SetLines(lines);
        polydata->GetPointData()->AddArray(warpData);
        polydata->GetPointData()->SetActiveVectors(warpData->GetName());
        //WarpVector will use the array marked as active vector in polydata
          //it has to be a 3 component array
          //with the same number of tuples as points in polydata
          vtkSmartPointer<vtkWarpVector> warpVector =vtkSmartPointer<vtkWarpVector>::New();
        warpVector->SetInputData(polydata);
        warpVector->Update();
    
        vtkSmartPointer<vtkPolyDataMapper>mapper=vtkSmartPointer<vtkPolyDataMapper>::New();
        mapper->SetInputData(warpVector->GetPolyDataOutput());
    
        vtkSmartPointer<vtkActor> actor=vtkSmartPointer<vtkActor>::New();
        actor->SetMapper(mapper);
    
        vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();
          renderer->AddActor(actor);
          renderer->SetBackground(.3, .6, .3);
    
          vtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();
          renderWindow->AddRenderer(renderer);
    
          vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =vtkSmartPointer<vtkRenderWindowInteractor>::New();
          renderWindowInteractor->SetRenderWindow(renderWindow);
          renderWindow->Render();
          renderWindowInteractor->Start();
        return 0;
    }

     vtkWarpScalar 

    vtkWarpVector 是根据矢量数据移动指定的点。vtkWarpScalar则是根据设定法向量normal和标量Scalar,移动变形点。

    vtkWarpScalar is a filter that modifies point coordinates by moving points along point normals by the scalar amount times the scale factor. Useful for creating carpet or x-y-z plots.

    If normals are not present in data, the Normal instance variable will be used as the direction along which to warp the geometry. If normals are present but you would like to use the Normal instance variable, set the UseNormal boolean to true.

    If XYPlane boolean is set true, then the z-value is considered to be a scalar value (still scaled by scale factor), and the displacement is along the z-axis. If scalars are also present, these are copied through and can be used to color the surface.

    Note that the filter passes both its point data and cell data to its output, except for normals, since these are distorted by the warping.

    Examples:
    vtkWarpScalar (Examples)
    Tests:
    vtkWarpScalar (Tests)

    vtkWarpScalar示例:

     

    #ifndef INITIAL_OPENGL
    #define INITIAL_OPENGL
    #include <vtkAutoInit.h>
    VTK_MODULE_INIT(vtkRenderingOpenGL)
    VTK_MODULE_INIT(vtkInteractionStyle)
    #endif
    #include <iostream>
    using namespace std;
    #include "vtkSmartPointer.h"
    #include "vtkActor.h"
    #include "vtkCamera.h"
    #include "vtkDataSetMapper.h"
    #include "vtkDebugLeaks.h"
    #include "vtkFloatArray.h"
    #include "vtkPlaneSource.h"
    #include "vtkPointData.h"
    #include "vtkPoints.h"
    #include "vtkPolyData.h"
    #include "vtkRenderWindow.h"
    #include "vtkRenderWindowInteractor.h"
    #include "vtkRenderer.h"
    #include "vtkTransform.h"
    #include "vtkTransformPolyDataFilter.h"
    #include "vtkWarpScalar.h"
    int main()
    {
        int i, numPts;
         double x[3];
         double r, deriv;
    
         vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
         vtkSmartPointer<vtkRenderWindow> renWin =vtkSmartPointer<vtkRenderWindow>::New();
         renWin->AddRenderer(ren);
    
         vtkSmartPointer<vtkRenderWindowInteractor> iren =vtkSmartPointer<vtkRenderWindowInteractor>::New();
         iren->SetRenderWindow(renWin);
    
         // create plane to warp
         vtkSmartPointer<vtkPlaneSource> plane =vtkSmartPointer<vtkPlaneSource>::New();
         plane->SetResolution (300,300);
    
         vtkSmartPointer<vtkTransform> transform =vtkSmartPointer<vtkTransform>::New();
         transform->Scale(10.0,10.0,1.0);
    
         vtkSmartPointer<vtkTransformPolyDataFilter> transF =vtkSmartPointer<vtkTransformPolyDataFilter>::New();
         transF->SetInputConnection(plane->GetOutputPort());
         transF->SetTransform(transform);
         transF->Update();
    
         // compute Bessel function and derivatives. This portion could be
         // encapsulated into source or filter object.
         //
         vtkSmartPointer<vtkPolyData> input = transF->GetOutput();
         numPts = input->GetNumberOfPoints();
    
         vtkSmartPointer<vtkPoints> newPts =vtkSmartPointer<vtkPoints>::New();
         newPts->SetNumberOfPoints(numPts);
    
         vtkSmartPointer<vtkFloatArray> derivs =vtkSmartPointer<vtkFloatArray>::New();
         derivs->SetNumberOfTuples(numPts);
    
         vtkSmartPointer<vtkPolyData> bessel =vtkSmartPointer<vtkPolyData>::New();
         bessel->CopyStructure(input);
         bessel->SetPoints(newPts);
         bessel->GetPointData()->SetScalars(derivs);
    
         for (i=0; i<numPts; i++)
         {
           input->GetPoint(i,x);
           r = sqrt(static_cast<double>(x[0]*x[0]) + x[1]*x[1]);
           x[2] = exp(-r) * cos (10.0*r);
           newPts->SetPoint(i,x);
           deriv = -exp(-r) * (cos(10.0*r) + 10.0*sin(10.0*r));
           derivs->SetValue(i,deriv);
         }
    
         // warp plane
         vtkSmartPointer<vtkWarpScalar> warp =vtkSmartPointer<vtkWarpScalar>::New();
         warp->SetInputData(bessel);
         warp->XYPlaneOn();
         warp->SetScaleFactor(0.5);
    
         // mapper and actor
         vtkSmartPointer<vtkDataSetMapper> mapper =vtkSmartPointer<vtkDataSetMapper>::New();
         mapper->SetInputConnection(warp->GetOutputPort());
         double tmp[2];
         bessel->GetScalarRange(tmp);
         mapper->SetScalarRange(tmp[0],tmp[1]);
    
         vtkSmartPointer<vtkActor> carpet =vtkSmartPointer<vtkActor>::New();
         carpet->SetMapper(mapper);
    
         // assign our actor to the renderer
         ren->AddActor(carpet);
         ren->SetBackground(1,1,1);
         renWin->SetSize(300,300);
    
         // draw the resulting scene
         ren->ResetCamera();
         ren->GetActiveCamera()->Zoom(1.4);
         ren->GetActiveCamera()->Elevation(-55);
         ren->GetActiveCamera()->Azimuth(25);
         ren->ResetCameraClippingRange();
         renWin->Render();
    
         iren->Start();
        return 0;
    }

     

  • 相关阅读:
    mojoportal中弹出窗口
    css 层居中
    mojoportal中添加自定义javascript
    C#执行cmd [转载]
    异步委托 学习笔记
    Windows Sysinternals
    有关int,Int32的疑惑解答
    WEB Debug tools汇总
    规范很重要
    [笔记]VGA 接口电阻网络阻抗
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6270276.html
Copyright © 2020-2023  润新知