[vtkusers] tdinar at gmail.com
Utkarsh Ayachit
utkarsh.ayachit at kitware.com
Wed Jul 22 15:41:36 EDT 2015
Can you try replacing the vtkGeometryFilter with vtkDataSetSurfaceFilter? I
suspect the vtkGeometryFilter doesn't handle polyhedral elements.
Utkarsh
On Wed, Jul 22, 2015 at 1:13 AM tariq <tdinar at gmail.com> wrote:
> Hi, I am a newbie to vtk, and I have been trying to visualize an
> unstructured
> grid with the aid of vtkGeometryFilter to convert a polyhedron
> (unStructuredGrid) into vtkPolyData. Then compute the Normals and use a
> Lookup table to plot the data. The one polyhedron in my code would not show
> up. The code is pasted below and I am all ears. Thanks. TQ.
>
> #include <vtkSmartPointer.h>
> #include <vtkRenderer.h>
> #include <vtkUnstructuredGrid.h>
> #include <vtkPolyhedron.h>
> #include <vtkCellArray.h>
> #include <vtkPointData.h>
> #include <vtkCellData.h>
> #include <vtkIdList.h>
> #include <vtkPoints.h>
> #include <vtkDataArray.h>
> #include <vtkConnectivityFilter.h>
> #include <vtkGeometryFilter.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkPolyDataNormals.h>
> #include <vtkActor.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkLookupTable.h>
>
>
>
> int main( int, char*[] )
> {
> // create polyhedron (cube)
> vtkIdType pointIds[8] = {0, 1, 2, 3, 4, 5, 6, 7};
>
> vtkSmartPointer<vtkPoints> points =
> vtkSmartPointer<vtkPoints>::New();
> points->InsertNextPoint(-1.0,-1.0,-1.0);
> points->InsertNextPoint( 1.0,-1.0,-1.0);
> points->InsertNextPoint( 1.0, 1.0,-1.0);
> points->InsertNextPoint(-1.0, 1.0,-1.0);
> points->InsertNextPoint(-1.0,-1.0, 1.0);
> points->InsertNextPoint( 1.0,-1.0, 1.0);
> points->InsertNextPoint( 1.0, 1.0, 1.0);
> points->InsertNextPoint(-1.0, 1.0, 1.0);
>
> vtkSmartPointer<vtkCellArray> faces =
> vtkSmartPointer<vtkCellArray>::New();
> vtkIdType face0[4] = {0, 3, 2, 1};
> vtkIdType face1[4] = {0, 4, 7, 3};
> vtkIdType face2[4] = {4, 5, 6, 7};
> vtkIdType face3[4] = {5, 1, 2, 6};
> vtkIdType face4[4] = {0, 1, 5, 4};
> vtkIdType face5[4] = {2, 3, 7, 6};
>
> faces->InsertNextCell(4, face0);
> faces->InsertNextCell(4, face1);
> faces->InsertNextCell(4, face2);
> faces->InsertNextCell(4, face3);
> faces->InsertNextCell(4, face4);
> faces->InsertNextCell(4, face5);
>
> vtkSmartPointer<vtkUnstructuredGrid> ugrid =
> vtkSmartPointer<vtkUnstructuredGrid>::New();
> ugrid->SetPoints(points);
> ugrid->InsertNextCell(
> VTK_POLYHEDRON, 8, pointIds,
> 6, faces->GetPointer());
> // Extract poly data from unsturctured Grid
>
> vtkSmartPointer<vtkConnectivityFilter> Filter1=
> vtkSmartPointer<vtkConnectivityFilter>::New();
>
> Filter1->SetInputData(ugrid);
> Filter1->Update(0);
>
> vtkSmartPointer<vtkGeometryFilter> Filter2=
> vtkSmartPointer<vtkGeometryFilter>::New();
>
>
> Filter2->SetInputConnection(0,Filter1->GetOutputPort(0));
> Filter2->Update(0);
>
> // Calculate normals
>
> vtkSmartPointer<vtkPolyDataNormals> normals =
> vtkSmartPointer<vtkPolyDataNormals>::New();
>
> normals->SetFeatureAngle(60);
>
> normals->SetInputConnection(0,Filter2->GetOutputPort(0));
>
> normals->Update(0);
>
> //Setup lookup table
> vtkSmartPointer<vtkLookupTable> lut=
> vtkSmartPointer<vtkLookupTable>::New();
>
> lut->SetHueRange(0.0, 100);
>
> // initiate mapper
>
> vtkSmartPointer<vtkPolyDataMapper> mapper=
> vtkSmartPointer<vtkPolyDataMapper>::New();
>
> mapper->SetInputConnection(0,normals->GetOutputPort(0));
> mapper->SetLookupTable(lut);
> mapper->SetScalarRange(0.12, 0.6);
>
>
> vtkSmartPointer<vtkActor> actor=
> vtkSmartPointer<vtkActor>::New();
>
> // Initiate Actor
>
> actor->SetMapper(mapper);
> actor->SetPosition(0.0, 0.0, 0.0);
>
> // Create a renderer, render window, and interactor
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> renderer->ResetCamera();
> renderer->ResetCameraClippingRange();
>
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
>
> renderWindow->AddRenderer(renderer);
>
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> renderWindowInteractor->SetRenderWindow(renderWindow);
>
> // Add the actor to the scene
> renderer->AddActor(actor);
> renderer->SetBackground(.2, .3, .4);
>
> // Render and interact
> renderWindow->Render();
> renderWindowInteractor->Start();
>
>
>
> return EXIT_SUCCESS;
> }
>
>
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/tdinar-gmail-com-tp5733035.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150722/20df1969/attachment.html>
More information about the vtkusers
mailing list