How to draw arrow for cell normal(not point normal)

Hello,use these code:

/*
 * @Creator		 : alex 
 * @Create at	 : Jan 6, 2022 5:53:08 PM
 * @Modified by : alex
 * @Modified at : Jan 6, 2022 5:53:08 PM
 * @Description :	SphereCellNormal.cpp
 */
#include <vtkVersion.h>
#include <vtkSmartPointer.h>

#include <vtkSurfaceReconstructionFilter.h>
#include <vtkProgrammableSource.h>
#include <vtkContourFilter.h>
#include <vtkReverseSense.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkPolyData.h>
#include <vtkCamera.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSphereSource.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetMapper.h>
#include <vtkPolyDataNormals.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
#include <vtkArrowSource.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkGlyph3D.h>
#include <vtkOBJReader.h>

int main(int argc, char *argv[]) {
	vtkSmartPointer<vtkSphereSource> source = vtkSmartPointer<vtkSphereSource>::New();
	source->SetPhiResolution(10);
	source->SetThetaResolution(10);

//	std::string filePath = "/home/alex/workspace/Geometry-Python/files/cube_ball.obj";
//	auto source = vtkSmartPointer<vtkOBJReader>::New();
//	source->SetFileName(filePath.c_str());

	source->Update();

	vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputConnection(source->GetOutputPort());
	mapper->Update();

	vtkSmartPointer<vtkActor> surfaceActor = vtkSmartPointer<vtkActor>::New();
	surfaceActor->SetMapper(mapper);

	vtkSmartPointer<vtkPolyDataNormals> pdNormals = vtkSmartPointer<vtkPolyDataNormals>::New();
	pdNormals->SetInputConnection(source->GetOutputPort());
	pdNormals->SplittingOff();
	pdNormals->FlipNormalsOff();
//	pdNormals->ComputePointNormalsOn();
//	pdNormals->ComputePointNormalsOff();
	pdNormals->ComputeCellNormalsOn();
	pdNormals->ConsistencyOn();
	pdNormals->AutoOrientNormalsOn();
	pdNormals->Update();

	auto arrow = vtkSmartPointer<vtkArrowSource>::New();
	arrow->SetTipResolution(8);
	arrow->SetTipLength(0.3);
	arrow->SetTipRadius(0.1);

	vtkSmartPointer<vtkGlyph3D> glyph = vtkSmartPointer<vtkGlyph3D>::New();
	glyph->SetSourceConnection(arrow->GetOutputPort());
	glyph->SetVectorModeToUseNormal();
	glyph->SetInputData(pdNormals->GetOutput());
	glyph->SetScaleFactor(0.2);
	glyph->OrientOn();
	glyph->SetScaleModeToDataScalingOff();
	glyph->Update();

	vtkSmartPointer<vtkPolyDataMapper> spikeMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	spikeMapper->SetInputConnection(glyph->GetOutputPort());

	vtkSmartPointer<vtkActor> spikeActor = vtkSmartPointer<vtkActor>::New();
	spikeActor->SetMapper(spikeMapper);
	spikeActor->GetProperty()->SetColor(0.0, 0.79, 0.34);

	// Create the RenderWindow, Renderer and both Actors
	vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
	renWin->AddRenderer(ren);
	vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
	iren->SetRenderWindow(renWin);

	// Add the actors to the renderer, set the background and size
	ren->AddActor(surfaceActor);
	ren->AddActor(spikeActor);
	ren->SetBackground(.2, .3, .4);

	surfaceActor->GetProperty()->EdgeVisibilityOn();
	surfaceActor->GetProperty()->SetColor(0, 0, 1);
	surfaceActor->GetProperty()->SetEdgeColor(1, 1, 1);

	renWin->Render();
	iren->Start();

	return EXIT_SUCCESS;
}

I can draw arrows to represent point normal?Questions is:

How to draw arrow for cell normal?
I mean each cell has only one arrow from the center of the cell,not 3(or N) arrows from each point.

Hi,

What happens if you enable pdNormals->ComputePointNormalsOff(); along pdNormals->ComputeCellNormalsOn()?

regards,

PC

vtkCellCenters is a filter that takes as input any dataset and generates on output points at the center of the cells in the dataset. These points can be used for placing glyphs (vtkGlyph3D) or labeling (vtkLabeledDataMapper). (The center is the parametric center of the cell, not necessarily the geometric or bounding box center.) The cell attributes will be associated with the points on output.

This will get you halfway there.

1 Like

After these, all arrows poin toward to the right.