[vtkusers] WarpScalar - Problem about normal
lilymo
lilymagic2005 at yahoo.com.hk
Mon Aug 31 05:30:26 EDT 2015
By referencing the example of WarpScalar (
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/WarpScalar
<http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/WarpScalar> ), I use a
.vtp file instead of the sphere in the example, and I have edited some parts
of it, mainly for the normal part.
However, it seems that the point only offset towards the same normal, which
results in a translation only.
If I use vtkSphereSource, the following code can offset the points by its
own normal, but not the same normal for all the points at the same time.
What should I do? Thanks!
#include <vtkActor.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkWarpScalar.h>
#include <vtkMath.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkCylinderSource.h>
#include <vtkUnsignedCharArray.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkProperty.h>
int main(int, char *[])
{
vtkSmartPointer<vtkXMLPolyDataReader> sphereSource =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
sphereSource->SetFileName("test.vtp");
// Create Scalars
vtkSmartPointer<vtkDoubleArray> scalars =
vtkSmartPointer<vtkDoubleArray>::New();
int numberOfPoints = sphereSource->GetOutput()->GetNumberOfPoints();
sphereSource->GetOutput()->GetPointData()->SetScalars(scalars);
vtkSmartPointer<vtkWarpScalar> warpScalar =
vtkSmartPointer<vtkWarpScalar>::New();
warpScalar->SetInputConnection(sphereSource->GetOutputPort());
warpScalar->SetScaleFactor(1); // use the scalars themselves
scalars->SetNumberOfTuples(numberOfPoints);
for(vtkIdType i = 0; i < numberOfPoints; ++i)
{
scalars->SetTuple1(i,20);
}
//???
warpScalar->GetUseNormal();
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->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> sactor =
vtkSmartPointer<vtkActor>::New();
sactor->GetProperty()->SetColor(1.0, 0.0, 1.0);
sactor->SetMapper(smapper);
//--------------------------------------------------------------------
// Visualize
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->AddActor(sactor);
renderer->SetBackground(1,1,1);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/WarpScalar-Problem-about-normal-tp5733689.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list