[vtkusers] Visualizing normal vectors
mozendi
mozendi at gmail.com
Fri Dec 21 03:29:54 EST 2018
Dear Andaharoo,
Thank you very much for recommendations. My code works successfully and it
runs quite fast.
I have one more question. Is it possible to set width of arrows? I can scale
it using SetScaleFactor(). I tried SetTipLength and SetTipRadius but
dimensions did not change.
Thanks in advance
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkDelimitedTextReader.h>
#include <vtkDoubleArray.h>
#include <vtkTable.h>
#include <vtkPointData.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkArrowSource.h>
#include <vtkGlyph3D.h>
#include <vtkPointSource.h>
# include "vtkGlyph3DMapper.h"
#include <vtkOpenGLGlyph3DMapper.h>
#include <vector>
int main(int argc, char* argv[])
{
vtkSmartPointer<vtkDelimitedTextReader> reader =
vtkSmartPointer<vtkDelimitedTextReader>::New();
reader->SetFileName("dene_sil.xyz");
reader->DetectNumericColumnsOn();
reader->SetFieldDelimiterCharacters(" ");
reader->Update();
vtkTable* table = reader->GetOutput();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkDoubleArray> normals =
vtkSmartPointer<vtkDoubleArray>::New();
normals->SetName("NORMALS");
normals->SetNumberOfComponents(3); //3d normals (ie x,y,z)
std::cout << "Table has " << table->GetNumberOfRows()
<< " rows." << std::endl;
std::cout << "Table has " << table->GetNumberOfColumns()
<< " columns." << std::endl;
for (vtkIdType i = 0; i < table->GetNumberOfRows(); i++)
{
points->InsertNextPoint((table->GetValue(i, 0)).ToDouble(),
(table->GetValue(i, 1)).ToDouble(),
(table->GetValue(i, 2)).ToDouble());
double n[3];
n[0] = (table->GetValue(i, 3)).ToDouble();
n[1] = (table->GetValue(i, 4)).ToDouble();
n[2] = (table->GetValue(i, 5)).ToDouble();
normals->InsertNextTuple(n);
}
std::cout << "There are " << points->GetNumberOfPoints()
<< " points." << std::endl;
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
//polydata->GetPointData()->SetNormals(normals);
polydata->GetPointData()->AddArray(normals);
vtkSmartPointer<vtkOpenGLGlyph3DMapper> Glyph3D =
vtkSmartPointer<vtkOpenGLGlyph3DMapper>::New();
Glyph3D->SetInputData(polydata);
double pp[3];
polydata->GetPoint(1, pp);
std::cout << "deneme = " << 1 << " : (" << pp[0] << " " << pp[1] << " " <<
pp[2] << ")" << std::endl;
std::cout << "There are " << polydata->GetPointData()->GetNumberOfArrays()
<< " arrays." << std::endl;
std::cout << "name: " << polydata->GetPointData()->GetArrayName(0) <<
std::endl;
vtkSmartPointer<vtkArrowSource> glyphSource =
vtkSmartPointer<vtkArrowSource>::New();
glyphSource->Update();
//glyphSource->SetTipResolution(5);
glyphSource->SetTipLength(0.01);
glyphSource->SetTipRadius(0.01);
vtkSmartPointer<vtkActor> glyph3DActor = vtkSmartPointer<vtkActor>::New();
glyph3DActor->SetMapper(Glyph3D);
glyph3DActor->GetProperty()->SetColor(0.8900, 0.8100, 0.3400);
glyph3DActor->GetProperty()->SetLineWidth(0.01);
Glyph3D->SetSourceData(glyphSource->GetOutput());
Glyph3D->OrientOn();
Glyph3D->SetOrientationArray("NORMALS");
Glyph3D->SetScaleFactor(0.03);
Glyph3D->Update();
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(glyph3DActor);
renderer->SetBackground(.5, .5, .5);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list