Hello,
I am trying to put together an ellipsoid source and a set of points into one scene, write it to a .ply file and display it using paraview. I am having trouble combining two polyData, one from ellipsoid and another of the set of points.
The following code is for ellipsoid source:
vtkSmartPointer<vtkParametricEllipsoid> ellipsoid = vtkSmartPointer<vtkParametricEllipsoid>::New();
// set ellipsoid parameters
ellipsoid->SetXRadius(ellipseParams[0]);
ellipsoid->SetYRadius(ellipseParams[1]);
ellipsoid->SetZRadius(ellipseParams[2]);
// set ellipsoid center
vtkSmartPointer<vtkParametricFunctionSource> ellipsoidSource = vtkSmartPointer<vtkParametricFunctionSource>::New();
ellipsoidSource->SetParametricFunction(ellipsoid);
ellipsoidSource->SetUResolution(50);
ellipsoidSource->SetVResolution(50);
ellipsoidSource->SetWResolution(50);
ellipsoidSource->Update();
vtkSmartPointer<vtkPolyData> scene = vtkSmartPointer<vtkPolyData>::New();
scene->ShallowCopy(ellipsoidSource->GetOutput());
The code for creating another polyData with the set of points is:
// Create another polydata with control points
auto pointSet = vtkSmartPointer<vtkPoints>::New();
int numControl = controlp.size();
pointSet->SetNumberOfPoints(numControl);
for(vtkIdType i = 0; i < numControl; i++)
{
double point[3];
point[0] = controlp[i][0];
point[1] = controlp[i][1];
point[2] = controlp[i][2];
pointSet->SetPoint(i,point);
}
auto sceneControl = vtkSmartPointer<vtkPolyData>::New();
sceneControl->SetPoints(pointSet);
// pass through vertex glyph filter and save into new polydata
auto vertexGlyph = vtkSmartPointer<vtkVertexGlyphFilter>::New();
vertexGlyph->SetInputData(sceneControl);
vertexGlyph->Update();
auto scenePoints = vtkSmartPointer<vtkPolyData>::New();
scenePoints->ShallowCopy(vertexGlyph->GetOutput());
Where, the vector ‘controlP’ is a set of 3D points whose z-coordinate is 0 for all points. x-coordinate ranges from [-4,4] in steps of 0.5. the value of y-coordinate is either 3 or 4.
The I try to merge both the polydata using appendFilter and write the output to a file:
// Combine both poly data
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
appendFilter->SetInputData(scene);
appendFilter->SetInputData(scenePoints);
appendFilter->Update();
auto cleanFilter = vtkSmartPointer<vtkCleanPolyData>::New();
cleanFilter->SetInputConnection(appendFilter->GetOutputPort());
cleanFilter->Update();
// write to file
vtkSmartPointer<vtkPLYWriter> outWrite = vtkSmartPointer<vtkPLYWriter>::New();
std::string fileName = folderPath+"ellipse_test.ply";
outWrite->SetFileName(fileName.c_str());
//outWrite->SetInputData(scenePoints);
outWrite->SetInputConnection(cleanFilter->GetOutputPort());
outWrite->Write();
When I write ‘scene’ polydata to the file, I see an ellipsoid when I view the file in paraview. Similarly when I write the ‘sceneControl’ or ‘scenePoints’, I can view the points in 2D when I select the option to display as ‘points gaussian’ in paraview. The problem is when I write the output of ‘cleanFilter’ to the file. I do not see any output when I load the file into paraview. But, when I select ‘points gaussian’ visualization, I see only the points but not the ellipsoid. I want to display both together, and also add lines to the scene in the future. How can i resolve this issue?
Edit: ellipsoid parameters are (a=2,b=2,c=1) and I assume ‘ellipsoidSource’ class places the center at (0,0,0)