Are the coordinate systems of sphere and polyline different?

Hello, I’m a user who just started using VTK.
A problem occurred while trying to create a line and connect it to the center of the sphere. Here’s what happened:

poly line
RED ( 0,0,-50 ) ~ ( 5,0,-50 )
BLUE ( 0,0,-50 ) ~ ( -10,0,-50 )

SPHERE
origin ( 5,0,-50 ) / ( -5,0,-50)
radius 5

I think the red line should reach the sphere of gravity (5,0-50), but if you actually render it, it looks like an image.

I looked for the reason, but couldn’t find the exact answer. Does anyone know the answer to this answer?

Are your spheres from vtkSphereSource, or did you use some other method to create them?

1 Like

thank you for reply!
please it makes me crazy…

I just use vtkSphereSource and vtkPolyLine.
Here is my code

{
// Sphere
vtkSmartPointer sphereSource = vtkSmartPointer::New();
sphereSource->SetCenter(5, 0, -50);
sphereSource->SetRadius(5);
// Make the surface smooth.
sphereSource->SetPhiResolution(phi);
sphereSource->SetThetaResolution(theta);

// Mapper
vtkSmartPointer<vtkPolyDataMapper> polyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
polyDataMapper->SetInputConnection(sphereSource->GetOutputPort());

vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();

// actor->SetForceOpaque(false);

actor->SetMapper(polyDataMapper);
actor->GetProperty()->SetOpacity(1);
actor->GetProperty()->BackfaceCullingOn();
_modelRenderer->AddActor(actor);
// Target Sphere End

}
{
double origin[3] = { 0, 0, -50};
double p0[3] = { 5, 0, -50 };

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(origin);
points->InsertNextPoint(p0);

vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
polyLine->GetPointIds()->SetNumberOfIds(2);
for (unsigned int i = 0; i < 2; i++)
	polyLine->GetPointIds()->SetId(i, i);

vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(polyLine);

vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();

polyData->SetPoints(points);
polyData->SetLines(cells);

vtkSmartPointer<vtkPolyDataMapper> polyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
polyDataMapper->SetInputData(polyData);

vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();

actor->SetMapper(polyDataMapper);
actor->GetProperty()->SetLineWidth(2);
_modelRenderer->AddActor(actor);

}

Unfortunately your code isn’t displayed properly. Can you edit your post and put all the code into a “code block”? Like this:

```c++
vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New()
```

From what I can read in your code, there is only one sphere, which is different from the image where you show two spheres.

Thank you for reply.

I hope you had a good weekend.
I am sorry for my immature use of the community, and thank you for your explanation

I’m trying to put the objects I’m going to draw in a vector called “_modelDataBindInfoVector” and draw them all at once.

// Main
AddLine(_renderData, 0, 0, -50, 20, 0, -50, 255, 0, 0);
AddTarget(_renderData, 20 ,0, -50,5, 20, 20);

// AddLine
void AddLine(std::shared_ptr<RenderData> renderData, double startX, double startY, double startZ, double vectorX, double vectorY, double vectorZ, int r, int g, int b)
{
	double origin[3] = { startX, startY, startZ };
	double p0[3] = { vectorX, vectorY, vectorZ };
	
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	points->InsertNextPoint(origin);
	points->InsertNextPoint(p0);

	vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
	polyLine->GetPointIds()->SetNumberOfIds(2);
	for (unsigned int i = 0; i < 2; i++)
		polyLine->GetPointIds()->SetId(i, i);

	vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
	cells->InsertNextCell(polyLine);

	vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();

	polyData->SetPoints(points);
	polyData->SetLines(cells);

	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper->SetInputData(polyData);

	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();

	actor->SetMapper(polyDataMapper);
	actor->GetProperty()->SetColor(r, g, b);
	actor->GetProperty()->SetLineWidth(2);
	actor->SetPosition(0, 0, 0);
	SetStippledLineTexture(actor, 0xAAAA, 1);
	actor->GetProperty()->SetLineStipplePattern(0xf0f0);
	_modelRenderer->AddActor(actor);

	renderData->AddLine(startX, startY, startZ, vectorX, vectorY, vectorZ);
	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetLine(startX, startY, startZ, vectorX, vectorY, vectorZ), actor));
}

// AddTarget
void RenderBox::AddTarget(std::shared_ptr<RenderData> renderData, double centerX, double centerY, double centerZ, double radius, int phi, int theta)
{
	// Target Sphere
	vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
	sphereSource->SetCenter(0, 0, 0);
	sphereSource->SetRadius(radius);
	sphereSource->SetPhiResolution(phi);
	sphereSource->SetThetaResolution(theta);
	
	// Mapper
	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper->SetInputConnection(sphereSource->GetOutputPort());

	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(polyDataMapper);
	actor->SetPosition(centerX, centerY, centerZ);
	actor->GetProperty()->SetOpacity(0.3);
	actor->GetProperty()->SetColor(1.0, 0, 0);
	actor->GetProperty()->BackfaceCullingOn();
	_modelRenderer->AddActor(actor);
	// Target Sphere End

	// Inner Sphere
	vtkSmartPointer<vtkSphereSource> sphereSource2 = vtkSmartPointer<vtkSphereSource>::New();
	sphereSource2->SetCenter(0, 0, 0);
	sphereSource2->SetRadius(radius * 1.3);
	sphereSource2->SetPhiResolution(phi);
	sphereSource2->SetThetaResolution(theta);

	// Mapper
	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper2->SetInputConnection(sphereSource2->GetOutputPort());

	vtkSmartPointer<vtkActor> actor2 = vtkSmartPointer<vtkActor>::New();
	actor2->SetMapper(polyDataMapper2);
	actor2->SetPosition(centerX, centerY, centerZ);
	actor2->GetProperty()->SetOpacity(0.2);
	actor2->GetProperty()->BackfaceCullingOn();

	_modelRenderer->AddActor(actor2);
	// Inner Sphere End

	// Outter Sphere
	vtkSmartPointer<vtkSphereSource> sphereSource3 = vtkSmartPointer<vtkSphereSource>::New();
	sphereSource3->SetCenter(0, 0, 0);
	sphereSource3->SetRadius(radius * 2.0);
	sphereSource3->SetPhiResolution(phi);
	sphereSource3->SetThetaResolution(theta);

	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper3 = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper3->SetInputConnection(sphereSource3->GetOutputPort());
	vtkSmartPointer<vtkActor> actor3 = vtkSmartPointer<vtkActor>::New();
	//	actor3->SetForceOpaque(false);

	actor3->SetPosition(centerX, centerY, centerZ);
	actor3->SetMapper(polyDataMapper3);
	actor3->GetProperty()->SetOpacity(0.1);
	actor3->GetProperty()->BackfaceCullingOn();
	_modelRenderer->AddActor(actor3);

	// Outter Sphere End


	std::array<double, 3> pos = { centerX ,centerY,centerZ  };
	renderData->AddTargetSphere(pos,radius);

	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetTargetSphere(pos)[0], actor));
	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetTargetSphere(pos)[1], actor2));
	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetTargetSphere(pos)[2], actor3));
}

The image as a little hard to see. Can you do a screen grab (with the “Print Screen” button, for example) instead of taking a picture with your phone?

I don’t think it is a problem with the coordinate systems. The problem is the opacity. The line is hidden because it is inside the sphere, and this might be a bug.

In your original post, the blue line looked correct, but the red line looked wrong. What was the difference between how you drew the red line vs. the blue line?

Thank you for your kind attention.
Radius x 1 in the red center circle.
The outer circle has Radius x 1.3 and Radius x 2 respectively.

The blue line is twice as long as the red line. The coordinates are marked on the code.

AddLine(_renderData, 0, 0, -50, 20, 0, -50, 255, 0, 0); 
AddTarget(_renderData, 20 ,0, -50,5, 20, 20);          

AddLine(_renderData, 0, 0, -50, -40, 0, -50, 0, 0, 255);
AddTarget(_renderData, -20, 0, -50, 5, 20, 20);

If you look at the blue line, it doesn’t look like the line is covered by the skin. So it’s even more confusing.

I see. It’s as if only half of the line is drawn. What happens if you do not stipple the line? Maybe the stipple is causing problems with the rendering.

I’m glad you understood. Thank you.

The other parts are all the same and only the stipple sections are annotated.
The length of the line does not seem to change.

As a test, try converting the polyline into a polygonal tube with vtkTubeFilter. If the problem disappears with vtkTubeFilter, then it is definitely a problem with rendering lines.

Okay, I’ll test it right away. Thank you.

Unfortunately, there seems to be no difference in length.

That doesn’t look like the output of vtkTubeFilter. Please make sure the output from vtkTubeFilter goes into the mapper.

I did what you said. But the problem that happened doesn’t seem to have been solved.

Look at this.
In the existing code, Line and Sphere were created by putting them all in a function, not separately.
That’s how the picture was drawn, as intended. But I still don’t know why this is happening.

AddLine(_renderData, 0, 0, -50, 10, 0, -50, 255, 0, 0);

void RenderBox::AddLine(std::shared_ptr<RenderData> renderData, double startX, double startY, double startZ, double vectorX, double vectorY, double vectorZ, int r, int g, int b)
{
	// Target Sphere
	vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
	sphereSource->SetCenter(startX, startY, startZ);
	sphereSource->SetRadius(5);
	sphereSource->SetPhiResolution(40);
	sphereSource->SetThetaResolution(20);

	// Mapper
	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper0 = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper0->SetInputConnection(sphereSource->GetOutputPort());

	vtkSmartPointer<vtkActor> actor0 = vtkSmartPointer<vtkActor>::New();
	actor0->SetMapper(polyDataMapper0);
	actor0->SetPosition(0, 0, 0);
	actor0->GetProperty()->SetOpacity(0.3);
	actor0->GetProperty()->SetColor(1.0, 0, 0);
	actor0->GetProperty()->BackfaceCullingOn();
	_modelRenderer->AddActor(actor0);
	// Target Sphere End

	// Inner Sphere
	vtkSmartPointer<vtkSphereSource> sphereSource2 = vtkSmartPointer<vtkSphereSource>::New();
	sphereSource2->SetCenter(startX, startY, startZ);
	sphereSource2->SetRadius(5 * 1.3);
	sphereSource2->SetPhiResolution(40);
	sphereSource2->SetThetaResolution(20);

	// Mapper
	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper2->SetInputConnection(sphereSource2->GetOutputPort());

	vtkSmartPointer<vtkActor> actor2 = vtkSmartPointer<vtkActor>::New();
	actor2->SetMapper(polyDataMapper2);
	actor2->SetPosition(0,0,0);
	actor2->GetProperty()->SetOpacity(0.2);
	actor2->GetProperty()->BackfaceCullingOn();

	_modelRenderer->AddActor(actor2);
	// Inner Sphere End

	// Outter Sphere
	vtkSmartPointer<vtkSphereSource> sphereSource3 = vtkSmartPointer<vtkSphereSource>::New();
	sphereSource3->SetCenter(startX, startY, startZ);
	sphereSource3->SetRadius(5 * 2.0);
	sphereSource3->SetPhiResolution(40);
	sphereSource3->SetThetaResolution(20);

	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper3 = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper3->SetInputConnection(sphereSource3->GetOutputPort());
	vtkSmartPointer<vtkActor> actor3 = vtkSmartPointer<vtkActor>::New();

	actor3->SetPosition(0,0,0);
	actor3->SetMapper(polyDataMapper3);
	actor3->GetProperty()->SetOpacity(0.1);
	actor3->GetProperty()->BackfaceCullingOn();
	_modelRenderer->AddActor(actor3);

	// Outter Sphere End

	std::array<double, 3> pos = { startX ,startY,startZ };
	renderData->AddTargetSphere(pos, 5);

	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetTargetSphere(pos)[0], actor0));
	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetTargetSphere(pos)[1], actor2));
	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetTargetSphere(pos)[2], actor3));


	double origin[3] = { startX, startY, startZ };
	double p0[3] = { vectorX, vectorY, vectorZ };
	
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	points->InsertNextPoint(origin);
	points->InsertNextPoint(p0);

	vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
	polyLine->GetPointIds()->SetNumberOfIds(2);
	for (unsigned int i = 0; i < 2; i++)
		polyLine->GetPointIds()->SetId(i, i);

	vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
	cells->InsertNextCell(polyLine);

	vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();

	polyData->SetPoints(points);
	polyData->SetLines(cells);

	vtkSmartPointer<vtkPolyDataMapper> polyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyDataMapper->SetInputData(polyData);

	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(polyDataMapper);
	actor->GetProperty()->SetColor(r, g, b);
	actor->GetProperty()->SetLineWidth(2);
	actor->SetPosition(0, 0, 0);
	//	SetStippledLineTexture(actor, 0xAAAA, 1);
		_modelRenderer->AddActor(actor);
	renderData->AddLine(startX, startY, startZ, vectorX, vectorY, vectorZ);
	_modelDataBindInfoVector.emplace_back(std::pair<std::weak_ptr<RenderData::ObjectData>, vtkSmartPointer<vtkActor>>(renderData->GetLine(startX, startY, startZ, vectorX, vectorY, vectorZ), actor));
}