Hello,
I created a function to rotate my mesh but it isn’t working. I wanto to rotate the resulting mesh of the smooth discrete marching cubes filter.
Thank you,
vtkSmartPointer<vtkPolyData> RotationFilter::RotateMesh(vtkPolyData* inputMesh, double angle, double axisX, double axisY, double axisZ) {
// Create a vtkTransform for rotation
vtkNew<vtkTransform> rotationTransform ;
rotationTransform->RotateWXYZ(angle, axisX, axisY, axisZ);
// Create a vtkTransformPolyDataFilter and set the input mesh and rotation transform
vtkNew<vtkTransformPolyDataFilter> transformFilter;
transformFilter->SetInputData(inputMesh);
transformFilter->SetTransform(rotationTransform);
transformFilter->Update();
// Get the rotated mesh
vtkSmartPointer<vtkPolyData> rotatedMesh = transformFilter->GetOutput();
return rotatedMesh;
}
// VTK DISCRETE SMOOTH MARCHING CUBES
int number_of_tissues = 10;
vtkNew<vtkDiscreteMarchingCubes> discrete_smooth_mesher;
vtkImageData* imported_image = vtkImporter->GetOutput();
discrete_smooth_mesher->SetInputData(imported_image);
discrete_smooth_mesher->GenerateValues(number_of_tissues, 1, number_of_tissues);
discrete_smooth_mesher->Update();
vtkPolyData* polyDataOutput_mesureer = discrete_smooth_mesher->GetOutput();
if (polyDataOutput_mesureer)
{
double bounds[6];
polyDataOutput_mesureer->GetBounds(bounds);
std::cerr << "Output Bounds: "
<< "MinX: " << bounds[0] << ", MaxX: " << bounds[1] << ", "
<< "MinY: " << bounds[2] << ", MaxY: " << bounds[3] << ", "
<< "MinZ: " << bounds[4] << ", MaxZ: " << bounds[5] << std::endl;
}
else
{
std::cerr << "Error: vtkPolyData output not available." << std::endl;
}
discrete_smooth_mesher->Update();
vtkNew<vtkWindowedSincPolyDataFilter> smoother_cubes_mesher;
smoother_cubes_mesher->SetInputConnection(discrete_smooth_mesher->GetOutputPort());
smoother_cubes_mesher->SetNumberOfIterations(smoothingIterations);
smoother_cubes_mesher->BoundarySmoothingOff();
smoother_cubes_mesher->FeatureEdgeSmoothingOff();
smoother_cubes_mesher->SetFeatureAngle(featureAngle);
smoother_cubes_mesher->SetPassBand(passBand);
smoother_cubes_mesher->NonManifoldSmoothingOn();
smoother_cubes_mesher->NormalizeCoordinatesOn();
smoother_cubes_mesher->Update();
vtkPolyData* full_mesh = smoother_cubes_mesher->GetOutput();
vtkSmartPointer<vtkPolyData> rotated_mesh;
RotationFilter Rotator;
rotated_mesh = Rotator.RotateMesh(full_mesh, 0.0, 180.0, 0.0, 0.0);
vtkSmartPointer<vtkLookupTable> lut_mesher = MakeColors_Tissues(number_of_tissues);
vtkNew<vtkPolyDataMapper> mapper_cubes_mesher;
mapper_cubes_mesher->SetInputData(rotated_mesh);
mapper_cubes_mesher->SetLookupTable(lut_mesher);
mapper_cubes_mesher->SetScalarRange(0, number_of_tissues-1);
vtkNew<vtkRenderer> ren_mesher;
vtkNew<vtkEGLRenderWindow> renWin_mesher;
renWin_mesher->OffScreenRenderingOn();
renWin_mesher->SetShowWindow(false);
renWin_mesher->WindowInitialize();
renWin_mesher->AddRenderer(ren_mesher);
renWin_mesher->SetWindowName("SmoothDiscreteMarchingCubes");
vtkNew<vtkRenderWindowInteractor> iren_mesher;
iren_mesher->SetRenderWindow(renWin_mesher);
vtkNew<vtkActor> actor_cubes_mesher;
actor_cubes_mesher->SetMapper(mapper_cubes_mesher);
ren_mesher->AddActor(actor_cubes_mesher);
vtkNew<vtkNamedColors> colors_cubes_mesher;
ren_mesher->SetBackground(colors_cubes_mesher->GetColor3d("White").GetData());
renWin_mesher->SetWindowName("EarthSource");
renWin_mesher->Render();
std::cerr << "Render Ok" << std::endl;
vtkNew<vtkWindowToImageFilter> windowToImageFilter_mesher;
windowToImageFilter_mesher->SetInput(renWin_mesher);
windowToImageFilter_mesher->Update();
std::cerr << "Render-Window to image Ok" << std::endl;
vtkNew<vtkPNGWriter> writer_cubes_mesher;
writer_cubes_mesher->SetFileName("Mesh 2D Representation.png");
writer_cubes_mesher->SetInputConnection(windowToImageFilter_mesher->GetOutputPort());
writer_cubes_mesher->Write();