[vtkusers] vtkCutter not working properly

Meisam Aliroteh meisam.aliroteh at gmail.com
Wed Jul 4 20:04:30 EDT 2007


Hi Sajendra,

Thanks for replying. Below is a simple C++ program that demonstrates the
vtkCutter problem I've encountered (looking forward to your feedback) :


#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkProperty.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkPlane.h"
#include "vtkCutter.h"

vtkPolyData *makeTestMesh()
{
    vtkPolyData *pd = vtkPolyData::New();
    vtkPoints *pnts = vtkPoints::New();
    vtkCellArray *polys = vtkCellArray::New();

    pnts->InsertNextPoint(0,0,0);
    pnts->InsertNextPoint(10,0,0);
    pnts->InsertNextPoint(10,10,0);
    pnts->InsertNextPoint(0,10,0);

    int tri1[] = { 0, 1, 2 };
    int tri2[] = { 0, 2, 3 };
    polys->InsertNextCell(3, tri1);
    polys->InsertNextCell(3, tri2);

    pd->SetPoints(pnts);
    pd->SetPolys(polys);
    return pd;
}

int main( int argc, char *argv[] )
{
    vtkRenderer *ren1 = vtkRenderer::New();
    ren1->SetViewport(0.0, 0.0, 0.5, 1.0);
    ren1->SetBackground(0.1,0.2,0.4);

    vtkRenderer *ren2 = vtkRenderer::New();
    ren2->SetViewport(0.5, 0.0, 1.0, 1.0);
    ren2->SetBackground(0.1,0.2,0.4);

    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->SetSize(800,400);
    renWin->AddRenderer(ren1);
    renWin->AddRenderer(ren2);

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetInteractorStyle( vtkInteractorStyleTrackballCamera::New() );
    iren->SetRenderWindow(renWin);

    vtkPolyData *pd1 = makeTestMesh();
    vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
    mapper1->SetInput( pd1 );
    vtkActor *actor1 = vtkActor::New();
    actor1->SetMapper( mapper1 );
    actor1->GetProperty()->SetColor(1,0,0);
    actor1->GetProperty()->SetRepresentationToWireframe();
    ren1->AddActor(actor1);

    vtkPlane *cutPlane = vtkPlane::New();
    cutPlane->SetOrigin(0,0,0);
    cutPlane->SetNormal(0,0,1);

    vtkCutter *cutter = vtkCutter::New();
    cutter->SetCutFunction(cutPlane);
    cutter->SetInput(pd1);

    vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
    mapper2->SetInput( cutter->GetOutput() );
    vtkActor *actor2 = vtkActor::New();
    actor2->SetMapper( mapper2 );
    actor2->GetProperty()->SetColor(0,0,1);
    ren2->AddActor(actor2);

    iren->Initialize();
    iren->Start();
    return 0;
}



On 7/4/07, Nithiananthan, Sajendra <Sajendra.Nithiananthan at rmp.uhn.on.ca>
wrote:
>
> Meisam,
>
> From your description its not quite clear what is happening.
> Could you perhaps provide a small example that reproduces your problem?
>
> -Sajendra N.
>
> -----Original Message-----
> From: vtkusers-bounces+sajendra.nithiananthan=rmp.uhn.on.ca at vtk.org
> [mailto:vtkusers-bounces+sajendra.nithiananthan=rmp.uhn.on.ca at vtk.org]On
> Behalf Of Meisam Aliroteh
> Sent: Friday, June 29, 2007 10:23 PM
> To: vtkusers at vtk.org
> Subject: [vtkusers] vtkCutter not working properly
>
>
> Hi,
>
> I've tried vtkCutter to get the contour of a polydata and I am getting
> weird
> results.
>
> In first case I cut a sphere with and the cutter does generate a circular
> contour. In the second case I try to cut through a bunch of triangles and
> are all coplanar and I try to cut them to get their contour but I get an
> empty polydata back from the cutter.
>
> Basically, I need to get the contour of a flat shape ( the shape is made
> of
> of triangles and all triangles are coplanar and I only need the outer
> lines
> which form the parameter of the shape, not any of the interior/shared
> triangle edges ). I though I could use vtkCutter since it is simple to use
> and is fast but it doesn't return anything !!! It just return a polydata
> which no cells, or polys, or lines etc.
>
> Can anyone tell me how to fix this, or is there a better way of doing this
> ?
>
> thanks
>
> This e-mail may contain confidential and/or privileged information for the
> sole use of the intended recipient. Any review or distribution by anyone
> other than the person for whom it was originally intended is strictly
> prohibited. If you have received this e-mail in error, please contact the
> sender and delete all copies. Opinions, conclusions or other information
> contained in this e-mail may not be that of the organization.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070704/c4dfc8b3/attachment.htm>


More information about the vtkusers mailing list