[vtkusers] Why can't I warp vtkCubeSource ?|
Cory Quammen
cory.quammen at kitware.com
Mon Oct 30 10:10:52 EDT 2017
To fundamentally change the shape from a cube, you'll need to discretize
the cube to have more than just the 6 faces that define the initial cube.
First, triangulate the cube with vtkTriangleFilter, then use
vtkLinearSubdivisionFilter to add triangles. You should have better luck.
HTH,
Cory
On Fri, Oct 27, 2017 at 7:55 PM, alican <alican1812 at hotmail.com> wrote:
> I need to apply kind of "pinch" to vtkCubeSource, to make it look like
> half
> cylinder. I have thought to use warpScalar for that, however, no matter
> what
> I try I just can't get it working. The cube remains exactly as it was.
>
> Can anybody spot a problem in my code? Thanks,
> AC
>
> void warpTest()
> {
> vtkSmartPointer<vtkCubeSource> cubeSource =
> vtkSmartPointer<vtkCubeSource>::New();
> cubeSource->SetXLength(50);
> cubeSource->SetYLength(10);
> cubeSource->SetZLength(1);
> cubeSource->SetCenter(0,0,0);
> cubeSource->Update();
> vtkPolyData* polydata = cubeSource->GetOutput();
>
> vtkSmartPointer<vtkDoubleArray> scalars =
> vtkSmartPointer<vtkDoubleArray>::New();
> polydata->GetPointData()->SetScalars(scalars);
> int numOfPoints = polydata->GetNumberOfPoints();
> scalars->SetNumberOfTuples(numOfPoints);
> for (vtkIdType i = 0; i < numOfPoints ; ++i)
> {
> scalars->SetTuple1(i, 200);
> }
>
> vtkSmartPointer<vtkPolyDataNormals> normalGenerator =
> vtkSmartPointer<vtkPolyDataNormals>::New();
> normalGenerator->SetInputData(polydata);
> normalGenerator->ComputePointNormalsOn();
> normalGenerator->ComputeCellNormalsOff();
> normalGenerator->Update();
>
> vtkSmartPointer<vtkWarpScalar> warpScalar =
> vtkSmartPointer<vtkWarpScalar>::New();
> warpScalar->SetInputData(normalGenerator->GetOutput());
> warpScalar->SetScaleFactor(1); // use the scalars themselves
> warpScalar->Update();
>
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputConnection(warpScalar->GetOutputPort());
>
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::
> New();
> actor->GetProperty()->SetColor(1.0, 1.0, 0.0);
> actor->SetMapper(mapper);
>
> vtkSmartPointer<vtkPolyDataMapper> smapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> smapper->SetInputData(polydata);
>
> vtkSmartPointer<vtkActor> sactor = vtkSmartPointer<vtkActor>::
> New();
> sactor->GetProperty()->SetColor(1.0, 0.0, 1.0);
> sactor->SetMapper(smapper);
>
> // Visualize
> getRenderer()->AddActor(actor);
> getRenderer()->AddActor(sactor);
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> 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
>
--
Cory Quammen
Staff R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171030/93d25766/attachment.html>
More information about the vtkusers
mailing list