[vtkusers] WarpScalar - Problem about normal
lilymo
lilymagic2005 at yahoo.com.hk
Mon Aug 31 22:59:10 EDT 2015
I ve got a new version of the code, as I debugged the code that the old
version didn't get a valid number of points of the polydata.
#include <vtkVersion.h>
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
#include <vtkFloatArray.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataNormals.h>
#include <vtkPointData.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkWarpScalar.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkProperty.h>
void TestPointNormals(vtkPolyData* polydata);
void TestCellNormals(vtkPolyData* polydata);
bool GetPointNormals(vtkPolyData* polydata);
bool GetCellNormals(vtkPolyData* polydata);
int main(int argc, char *argv[])
{
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName("model.vtp");
reader->Update();
polydata->DeepCopy(reader->GetOutput());
std::cout << "PolyData address: " << polydata << std::endl;
std::cout << "In TestPointNormals: " << polydata->GetNumberOfPoints() <<
std::endl;
vtkSmartPointer<vtkDoubleArray> scalars =
vtkSmartPointer<vtkDoubleArray>::New();
reader->GetOutput()->GetPointData()->SetScalars(scalars);
vtkSmartPointer<vtkWarpScalar> warpScalar =
vtkSmartPointer<vtkWarpScalar>::New();
warpScalar->SetInputConnection(reader->GetOutputPort());
warpScalar->SetScaleFactor(1); // use the scalars themselves
int numOfPoints = polydata->GetNumberOfPoints();
scalars->SetNumberOfTuples(numOfPoints);
for(vtkIdType i = 0; i < (polydata->GetNumberOfPoints()); ++i)
{
scalars->SetTuple1(i,200);
}
//warpScalar->GetUseNormal();
warpScalar->Update();
// Create a mapper and actor
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);
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> smapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
smapper->SetInputConnection(reader->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); // Background color white
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/WarpScalar-Problem-about-normal-tp5733689p5733700.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list