VTK:剪切并不总是适用于圆柱/球体/锥体

时间:2014-02-04 10:19:04

标签: vtk clipping bounding-box clip

我有一个奇怪的错误:

在我的程序中,我创建了一些对象并将它们剪切在我的边界框的两侧。

这适用于立方体(甚至是旋转的立方体),但只有一些圆柱体,球体和圆锥体。

在某些平面上剪裁按照我的意愿工作,但是有一些平面,裁剪不起作用。

首先,我为一个立方体的六个面创建一个带有六个平面的vtkPlaneCollection:

 // create the plane-collection
vtkPlaneCollection *planeCol = vtkPlaneCollection::New();

// create some planes and add them

// YZ-PLANE
// yz-plane at xMin
vtkPlane *xMin = vtkPlane::New();
xMin->SetOrigin(0,
                0,
                0);
xMin->SetNormal(1,
                0,
                0);
planeCol->AddItem(xMin);
std::cout << "yz-plane at xMin added" << std::endl;
// yz-plane at xMax
vtkPlane *xMax = vtkPlane::New();
xMax->SetOrigin(1,
                0,
                0);
xMax->SetNormal(-1,
                0,
                0);
planeCol->AddItem(xMax);
std::cout << "yz-plane at xMax added" << std::endl;


// XZ-PLANE
// xz-plane at yMin
vtkPlane *yMin = vtkPlane::New();
yMin->SetOrigin(0,
                0,
                0);
yMin->SetNormal(0,
                1,
                0);
planeCol->AddItem(yMin);
std::cout << "xz-plane at yMin added" << std::endl;
// xz-plane at yMax
vtkPlane *yMax = vtkPlane::New();
yMax->SetOrigin(0,
                1,
                0);
yMax->SetNormal(0,
                -1,
                0);
planeCol->AddItem(yMax);
std::cout << "xz-plane at yMax added" << std::endl;


// XY-PLANE
// xy-plane at zMin
vtkPlane *zMin = vtkPlane::New();
zMin->SetOrigin(0,
                0,
                0);
zMin->SetNormal(0,
                0,
                1);
planeCol->AddItem(zMin);
std::cout << "xy-plane at zMin added" << std::endl;
// xy-plane at zMax
vtkPlane *zMax = vtkPlane::New();
zMax->SetOrigin(0,
                0,
                1);
zMax->SetNormal(0,
                0,
                -1);
planeCol->AddItem(zMax);
std::cout << "xy-plane at zMax added" << std::endl;


return planeCol;

并将其交给vtkClipConvexPolyData

    vtkClipConvexPolyData *clipper = vtkClipConvexPolyData::New();

    // set the clipping-planes as planes
    clipper->SetPlanes(_planeCol);

    // return the clipper
    return clipper;

当我创建一个对象时,我创建了一个新的剪切器(我是否需要为每个对象创建一个剪切器,或者只有一个剪切器才能正常工作?)并在旋转后剪切对象

vtkCylinderSource *cylinder = vtkCylinderSource::New();
cylinder->SetRadius(r);         // set radius
cylinder->SetHeight(h);         // set height
// set resolution
cylinder->SetResolution(res);


/* TRANSFORM THE OBJECT */
// create a new transformation
vtkTransform *transform = vtkTransform::New();
transform->PostMultiply();


// rotate around z-axis by phi (= angles[0])
transform->RotateZ(- angles[0]);
// rotate around x-axis by theta (= angles[1])
transform->RotateX(- angles[1]);
// rotate around z-axis by psi (= angles[2])
transform->RotateZ(- angles[2]);
// translate the object
transform->Translate(x, y, z);

// create transforamtion-filter
vtkTransformPolyDataFilter *transFilter = vtkTransformPolyDataFilter::New();
// link it to the cylinder
transFilter->SetInputConnection(cylinder->GetOutputPort());
// link to transformation
transFilter->SetTransform(transform);
// update filter
transFilter->Update();


/* CLIP THE OBJECT */
// clip it
// create clipper
vtkClipConvexPolyData *clipper = _clipCreator->getNewClipper();
clipper->SetInputConnection(transFilter->GetOutputPort());
clipper->Update();


/* WRAP THE OBJECT IN A MAPPER */
// cube -> mapper
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
//    mapper->SetInputConnection(transFilter->GetOutputPort());
mapper->SetInput(clipper->GetOutput());


/* WRAP THE MAPPER IN AN ACTOR */
// mapper -> actor
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);

每个actor都被添加到vtkRenderer中。其他对象的创建方式相同。

正如我所说,这对立方体工作正常,但是当我创建一个圆柱体时,剪裁在我的xMin平面上工作,但不在xMax平面上。

我不知道,我应该改变什么,我不知道,为什么它适用于立方体......

0 个答案:

没有答案