Re: Visualizing normal vectors

mozendi <[email protected]>
Newsgroups gmane.comp.lib.vtk.user
Message-ID <[email protected]>
Dear Andaharoo,
Thank you for your recommendation. I tried to modify my codes according to
your recommendations, my code is getting compiled successfully. However,
when I run it I am getting an error message. The screenshot and my code are
below. Could you please tell me what is wrong with my code?
Thanks in advance
<http://vtk.1045678.n5.nabble.com/file/t341822/vtk_error_message.png> 


#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 "vtkGlyph3DMapper.h"
#include <vtkOpenGLGlyph3DMapper.h>
#include <vector>


int main(int argc, char* argv[])
{
	vtkSmartPointer<vtkDelimitedTextReader> reader =
vtkSmartPointer<vtkDelimitedTextReader>::New();
	reader->SetFileName("points_and_normals.xyz");
	reader->DetectNumericColumnsOn();
	reader->SetFieldDelimiterCharacters(" ");
	reader->Update();

	vtkTable* table = reader->GetOutput();
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	vtkSmartPointer<vtkDoubleArray> normals =
vtkSmartPointer<vtkDoubleArray>::New();
	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);
	Glyph3D->SetOrientationArray("normals");
	Glyph3D->SetScaleFactor(.5);
	Glyph3D->Update();
		
	vtkSmartPointer<vtkActor> glyph3DActor =	vtkSmartPointer<vtkActor>::New();
	glyph3DActor->SetMapper(Glyph3D);
	glyph3DActor->GetProperty()->SetColor(0.8900, 0.8100, 0.3400);

	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
_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.